trtc-cloud-js-sdk 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/trtc-cloud-js-sdk.js +1 -1
package/package.json
CHANGED
package/trtc-cloud-js-sdk.js
CHANGED
|
@@ -12,4 +12,4 @@ var global,factory;global=this,factory=function(e,t,i){function r(e){return e&&"
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function s(e,t){function i(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var n,c,l,u,h,d,m,T,p=function(){return p=Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++)for(var o in t=arguments[i])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},p.apply(this,arguments)};function v(e,t,i,r){return new(i||(i=Promise))((function(o,a){function s(e){try{c(r.next(e))}catch(t){a(t)}}function n(e){try{c(r.throw(e))}catch(t){a(t)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,n)}c((r=r.apply(e,t||[])).next())}))}function S(e,t){var i,r,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function n(a){return function(n){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(n){a=[6,n],r=0}finally{i=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,n])}}}e.TRTCVideoResolution=void 0,(n=e.TRTCVideoResolution||(e.TRTCVideoResolution={}))[n.TRTCVideoResolution_120_120=1]="TRTCVideoResolution_120_120",n[n.TRTCVideoResolution_160_160=3]="TRTCVideoResolution_160_160",n[n.TRTCVideoResolution_270_270=5]="TRTCVideoResolution_270_270",n[n.TRTCVideoResolution_480_480=7]="TRTCVideoResolution_480_480",n[n.TRTCVideoResolution_160_120=50]="TRTCVideoResolution_160_120",n[n.TRTCVideoResolution_240_180=52]="TRTCVideoResolution_240_180",n[n.TRTCVideoResolution_280_210=54]="TRTCVideoResolution_280_210",n[n.TRTCVideoResolution_320_240=56]="TRTCVideoResolution_320_240",n[n.TRTCVideoResolution_400_300=58]="TRTCVideoResolution_400_300",n[n.TRTCVideoResolution_480_360=60]="TRTCVideoResolution_480_360",n[n.TRTCVideoResolution_640_480=62]="TRTCVideoResolution_640_480",n[n.TRTCVideoResolution_960_720=64]="TRTCVideoResolution_960_720",n[n.TRTCVideoResolution_160_90=100]="TRTCVideoResolution_160_90",n[n.TRTCVideoResolution_256_144=102]="TRTCVideoResolution_256_144",n[n.TRTCVideoResolution_320_180=104]="TRTCVideoResolution_320_180",n[n.TRTCVideoResolution_480_270=106]="TRTCVideoResolution_480_270",n[n.TRTCVideoResolution_640_360=108]="TRTCVideoResolution_640_360",n[n.TRTCVideoResolution_960_540=110]="TRTCVideoResolution_960_540",n[n.TRTCVideoResolution_1280_720=112]="TRTCVideoResolution_1280_720",n[n.TRTCVideoResolution_1920_1080=114]="TRTCVideoResolution_1920_1080",e.TRTCVideoStreamType=void 0,(c=e.TRTCVideoStreamType||(e.TRTCVideoStreamType={}))[c.TRTCVideoStreamTypeBig=0]="TRTCVideoStreamTypeBig",c[c.TRTCVideoStreamTypeSmall=1]="TRTCVideoStreamTypeSmall",c[c.TRTCVideoStreamTypeSub=2]="TRTCVideoStreamTypeSub",e.TRTCVideoFillMode=void 0,(l=e.TRTCVideoFillMode||(e.TRTCVideoFillMode={}))[l.TRTCVideoFillMode_Fill=0]="TRTCVideoFillMode_Fill",l[l.TRTCVideoFillMode_Fit=1]="TRTCVideoFillMode_Fit",e.TRTCVideoMirrorType=void 0,(u=e.TRTCVideoMirrorType||(e.TRTCVideoMirrorType={}))[u.TRTCVideoMirrorType_Auto=0]="TRTCVideoMirrorType_Auto",u[u.TRTCVideoMirrorType_Enable=1]="TRTCVideoMirrorType_Enable",u[u.TRTCVideoMirrorType_Disable=2]="TRTCVideoMirrorType_Disable",e.TRTCBeautyStyle=void 0,(h=e.TRTCBeautyStyle||(e.TRTCBeautyStyle={}))[h.TRTCBeautyStyleSmooth=0]="TRTCBeautyStyleSmooth",h[h.TRTCBeautyStyleNature=1]="TRTCBeautyStyleNature",e.TRTCAppScene=void 0,(d=e.TRTCAppScene||(e.TRTCAppScene={}))[d.TRTCAppSceneVideoCall=0]="TRTCAppSceneVideoCall",d[d.TRTCAppSceneLIVE=1]="TRTCAppSceneLIVE",d[d.TRTCAppSceneAudioCall=2]="TRTCAppSceneAudioCall",d[d.TRTCAppSceneVoiceChatRoom=3]="TRTCAppSceneVoiceChatRoom",e.TRTCRoleType=void 0,(m=e.TRTCRoleType||(e.TRTCRoleType={}))[m.TRTCRoleAnchor=20]="TRTCRoleAnchor",m[m.TRTCRoleAudience=21]="TRTCRoleAudience",e.TRTCAudioQuality=void 0,(T=e.TRTCAudioQuality||(e.TRTCAudioQuality={}))[T.TRTCAudioQualityDefault=0]="TRTCAudioQualityDefault",T[T.TRTCAudioQualitySpeech=1]="TRTCAudioQualitySpeech",T[T.TRTCAudioQualityMusic=3]="TRTCAudioQualityMusic";var R,f,y=function(e,t,i,r,o){void 0===e&&(e=""),void 0===t&&(t=""),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=""),this.deviceId=e,this.deviceName=t,this.kind=i,this.label=r,this.groupId=o};e.TRTCDeviceState=void 0,(R=e.TRTCDeviceState||(e.TRTCDeviceState={}))[R.TRTCDeviceStateAdd=0]="TRTCDeviceStateAdd",R[R.TRTCDeviceStateRemove=1]="TRTCDeviceStateRemove",R[R.TRTCDeviceStateActive=2]="TRTCDeviceStateActive",e.TRTCDeviceType=void 0,(f=e.TRTCDeviceType||(e.TRTCDeviceType={}))[f.TRTCDeviceTypeUnknow=-1]="TRTCDeviceTypeUnknow",f[f.TRTCDeviceTypeMic=0]="TRTCDeviceTypeMic",f[f.TRTCDeviceTypeSpeaker=1]="TRTCDeviceTypeSpeaker",f[f.TRTCDeviceTypeCamera=2]="TRTCDeviceTypeCamera";var C,g=function(t,i,r,o,a,s,n,c,l,u,h){void 0===t&&(t=0),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=0),void 0===a&&(a=""),void 0===s&&(s=e.TRTCRoleType.TRTCRoleAnchor),void 0===n&&(n=null),void 0===l&&(l=null),void 0===u&&(u=null),void 0===h&&(h=30),this.sdkAppId=t,this.userId=i,this.userSig=r,this.roomId=o,this.strRoomId=a,this.role=s,this.privateMapKey=n,this.streamId=l,this.userDefineRecordId=u,this.frameWorkType=h},b=function(t,i,r){void 0===t&&(t=e.TRTCVideoResolution.TRTCVideoResolution_640_360),void 0===i&&(i=15),void 0===r&&(r=550),this.videoResolution=t,this.videoFps=i,this.videoBitrate=r};e.TRTCVideoRotation=void 0,(C=e.TRTCVideoRotation||(e.TRTCVideoRotation={}))[C.TRTCVideoRotation0=0]="TRTCVideoRotation0",C[C.TRTCVideoRotation90=1]="TRTCVideoRotation90",C[C.TRTCVideoRotation180=2]="TRTCVideoRotation180",C[C.TRTCVideoRotation270=3]="TRTCVideoRotation270";var A,V=function(t,i,r){void 0===t&&(t=e.TRTCVideoRotation.TRTCVideoRotation0),void 0===i&&(i=e.TRTCVideoFillMode.TRTCVideoFillMode_Fit),void 0===r&&(r=e.TRTCVideoMirrorType.TRTCVideoMirrorType_Disable),this.rotation=t,this.fillMode=i,this.mirrorType=r};e.TRTCQuality=void 0,(A=e.TRTCQuality||(e.TRTCQuality={}))[A.TRTCQuality_Unknown=0]="TRTCQuality_Unknown",A[A.TRTCQuality_Excellent=1]="TRTCQuality_Excellent",A[A.TRTCQuality_Good=2]="TRTCQuality_Good",A[A.TRTCQuality_Poor=3]="TRTCQuality_Poor",A[A.TRTCQuality_Bad=4]="TRTCQuality_Bad",A[A.TRTCQuality_Vbad=5]="TRTCQuality_Vbad",A[A.TRTCQuality_Down=6]="TRTCQuality_Down";var _,P,I,w=function(t,i){void 0===t&&(t=""),void 0===i&&(i=e.TRTCQuality.TRTCQuality_Unknown),this.userId=t,this.quality=i},E=function(e,t){void 0===e&&(e=""),void 0===t&&(t=0),this.userId=e,this.volume=t},M=function(e,t,i){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=null),this.appId=e,this.bizId=t,this.url=i},D=function(t,i,r,o,a,s,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=0),void 0===a&&(a=0),void 0===s&&(s=0),void 0===n&&(n=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig),this.width=t,this.height=i,this.frameRate=r,this.videoBitrate=o,this.audioSampleRate=a,this.audioBitrate=s,this.streamType=n},L=function(e,t,i,r,o,a,s,n,c,l){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=0),void 0===a&&(a=0),void 0===s&&(s=0),void 0===n&&(n=[]),void 0===c&&(c=0),void 0===l&&(l=0),this.upLoss=e,this.downLoss=t,this.appCpu=i,this.systemCpu=r,this.rtt=o,this.receivedBytes=a,this.sentBytes=s,this.localStatisticsArray=n,this.localStatisticsArraySize=c,this.remoteStatisticsArraySize=l};e.TRTCVideoResolutionMode=void 0,(_=e.TRTCVideoResolutionMode||(e.TRTCVideoResolutionMode={}))[_.TRTCVideoResolutionModeLandscape=0]="TRTCVideoResolutionModeLandscape",_[_.TRTCVideoResolutionModePortrait=1]="TRTCVideoResolutionModePortrait",e.TRTCVideoQosPreference=void 0,(P=e.TRTCVideoQosPreference||(e.TRTCVideoQosPreference={}))[P.TRTCVideoQosPreferenceSmooth=1]="TRTCVideoQosPreferenceSmooth",P[P.TRTCVideoQosPreferenceClear=2]="TRTCVideoQosPreferenceClear",e.TRTCQosControlMode=void 0,(I=e.TRTCQosControlMode||(e.TRTCQosControlMode={}))[I.TRTCQosControlModeClient=0]="TRTCQosControlModeClient",I[I.TRTCQosControlModeServer=1]="TRTCQosControlModeServer";var U,k=function(t,i){void 0===t&&(t=e.TRTCVideoQosPreference.TRTCVideoQosPreferenceClear),void 0===i&&(i=e.TRTCQosControlMode.TRTCQosControlModeServer),this.preference=t,this.controlMode=i},O=function(e,t,i,r){void 0===e&&(e=new ArrayBuffer(0)),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),this.buffer=e,this.length=t,this.width=i,this.height=r};e.TRTCScreenCaptureSourceType=void 0,(U=e.TRTCScreenCaptureSourceType||(e.TRTCScreenCaptureSourceType={}))[U.TRTCScreenCaptureSourceTypeUnknown=-1]="TRTCScreenCaptureSourceTypeUnknown",U[U.TRTCScreenCaptureSourceTypeWindow=0]="TRTCScreenCaptureSourceTypeWindow",U[U.TRTCScreenCaptureSourceTypeScreen=1]="TRTCScreenCaptureSourceTypeScreen",U[U.TRTCScreenCaptureSourceTypeCustom=2]="TRTCScreenCaptureSourceTypeCustom";var F,N=function(t,i,r,o,a,s){void 0===t&&(t=e.TRTCScreenCaptureSourceType.TRTCScreenCaptureSourceTypeUnknown),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=new O),void 0===a&&(a=new O),void 0===s&&(s=!1),this.type=t,this.sourceId=i,this.sourceName=r,this.thumbBGRA=o,this.iconBGRA=a,this.isMinimizeWindow=s},Q=function(e,t,i,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),this.left=e,this.top=t,this.right=i,this.bottom=r},B={DEFAULT:"default",VIDEO:"video",AUDIO:"audio",ON_ERROR:"onError",MAIN:"main",RTC:"rtc",LIVE:"live",ANCHOR:"anchor",AUDIENCE:"audience",AUDIO_STANDARD:"standard",AUDIO_HIGH:"high",AUDIO_STANDARD_STEREO:"standard_stereo",AUDIO_HIGH_STEREO:"high_stereo",SMALL:"small",BIG:"big",AUXILIARY:"auxiliary",SCREEN_SHARE_USER_ID_PREFIX:"share_",NUMBER:"number",STRING:"string"},x={20:B.ANCHOR,21:B.AUDIENCE},J={0:B.RTC,1:B.LIVE,2:B.RTC,3:B.LIVE},H={0:B.AUDIO_STANDARD,1:B.AUDIO_HIGH,2:B.AUDIO_STANDARD_STEREO,3:B.AUDIO_HIGH_STEREO},j={0:B.BIG,1:B.SMALL,2:B.AUXILIARY};function z(){return Math.floor(performance.now())}!function(e){e[e.ActiveExitRoom=0]="ActiveExitRoom",e[e.KickedExitRoom=1]="KickedExitRoom"}(F||(F={}));var W=function(e){return void 0===e};function X(e){return"".concat(e,"-").concat(B.MAIN)}function G(e){return"".concat(e,"-").concat(B.AUXILIARY)}function Y(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var i=function(){for(var t=0,i=e;t<i.length;t++)K(this,new(0,i[t])(this))},r=i.prototype,o=0,a=e;o<a.length;o++){var s=a[o];K(i,s),K(r,s.prototype)}return i}function K(e,t){for(var i=0,r=Reflect.ownKeys(t);i<r.length;i++){var o=r[i];if("constructor"!==o&&"prototype"!==o&&"name"!==o){var a=Object.getOwnPropertyDescriptor(t,o)||"";Object.defineProperty(e,o,a)}}}function q(e,t){return void 0===e&&(e=""),t==="share_".concat(e)}function Z(e){return e&&null!==e.getVideoTrack()}function $(e){return e&&null!==e.getAudioTrack()}var ee=function(t){function i(){var i=t.call(this)||this;return i.startJoinTimestamp=0,i.joinedTimestamp=0,i.playViewMap=new Map,i.cameraList=[],i.micList=[],i.speakerList=[],i.currentCameraId="",i.currentMicId="",i.currentSpeakerId="",i.isJoining=!1,i.isJoined=!1,i.isExiting=!1,i.isPublishing=!1,i.isPublished=!1,i.isSubscribed=!1,i.userId="",i.userSig="",i.roomId=0,i.strRoomId="",i.useStringRoomId=!1,i.realRoomId=0,i.mode=B.RTC,i.role=B.ANCHOR,i.privateMapKey="255",i.streamId="",i.isSmallStreamSupported=!1,i.isStaringLocalPreview=!1,i.isStartedLocalPreview=!1,i.isStaringLocalAudio=!1,i.isStartedLocalAudio=!1,i.isVideoMute_=!1,i.isAudioMute_=!1,i.shareUserId="",i.shareUserSig="",i.isSharing_=!1,i.isShareClientJoined=!1,i.isShareStreamPublished_=!1,i.isShareClientLeaving=!1,i.defaultShareWidth_=1920,i.defaultShareHeight_=1080,i.defaultShareFrameRate_=15,i.defaultShareBitrate_=1500,i.defaultVideoWidth=640,i.defaultVideoHeight=480,i.defaultVideoFps=15,i.defaultVideoBitRate=900,i.prevLocalVideoStats={bytesSent:0,packetsSent:0,framesEncoded:0,framesSent:0,frameWidth:0,frameHeight:0},i.beautyDefaultBeauty=.5,i.beautyDefaultBrightness=.5,i.beautyDefaultRuddy=.5,i.TRTC=o.default,i.audioQuality=e.TRTCAudioQuality.TRTCAudioQualityDefault,i.priorRemoteVideoStreamType=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig,i.remoteStreamMap=new Map,i.isSmallStreamSupported=o.default&&o.default.isSmallStreamSupported()||!1,i.videoEncodeParam={width:i.defaultVideoWidth,height:i.defaultVideoHeight,frameRate:i.defaultVideoFps,bitrate:i.defaultVideoBitRate},i.screenShareParams_={width:i.defaultShareWidth_,height:i.defaultShareHeight_,frameRate:i.defaultShareFrameRate_,bitrate:i.defaultShareBitrate_},i}return s(i,t),i.prototype.promiseRetry=function(e){var t=this,i=e.retryFunction,r=e.settings,o=e.onError,a=e.onRetrying,s=e.context;return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var c=r.retries||5,l=0,u=-1,h=0,d=function(n,m){return v(t,void 0,void 0,(function(){var t,T,p,v,R;return S(this,(function(S){switch(S.label){case 0:return S.trys.push([0,2,,3]),t=s||this,[4,i.apply(t,e)];case 1:return T=S.sent(),l=0,n(T),[3,3];case 2:return p=S.sent(),v=function(){clearTimeout(u),l=0,h=2,m(p)},R=function(){2!==h&&l<c?(l++,h=1,a&&a(l,v),u=window.setTimeout((function(){u=-1,d(n,m)}),void 0===r.timeout?1e3:r.timeout)):v()},o?o(p,R,m):R(),[3,3];case 3:return[2]}}))}))};return new Promise(d)}},i}(t.EventEmitter),te=-1e3,ie={code:-1001,message:"参数错误, 请检查参数格式、是否非空等"},re={code:-1002,message:"进房失败:进房中或已进房"},oe={code:-1003,message:"退房失败:未进房或退房中"},ae={code:-1004,message:"调用该函数所需要条件不满足"},se={code:-1005,message:"not supported"},ne={code:-1006,message:"not supported before join room"},ce={code:-1007,message:"进房 userId 不能包含前缀 share_"},le={code:-1009,message:"不支持小流推屏幕分享"},ue=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t.prototype.startPublishing=function(e,t){return v(this,void 0,void 0,(function(){var t,i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.isPublished?this.client?(t={streamId:e},[4,this.client.startPublishCDNStream(t)]):(this.log_.error("(startPublishing) failed - ".concat(this.client)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - client = ").concat(this.client)}),[2]):(this.log_.error("(startPublishing) failed - ".concat(this.isPublished)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - isPublished = ").concat(this.isPublished)}),[2]);case 1:return r.sent(),[3,3];case 2:return i=r.sent(),this.callFunctionErrorManage(i,"startPublishing"),[3,3];case 3:return[2]}}))}))},t.prototype.stopPublishing=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),this.client?[4,this.client.stopPublishCDNStream()]:(this.log_.error("(stopPublishing) failed - ".concat(this.client)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - client = ").concat(this.client)}),[2]);case 1:return t.sent(),[3,3];case 2:return e=t.sent(),this.callFunctionErrorManage(e,"stopPublishing"),[3,3];case 3:return[2]}}))}))},t.prototype.startPublishCDNStream=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o,a;return S(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=e.appId,i=e.bizId,r=e.url,t&&i&&r?(o={appId:t,bizId:i,url:r},[4,this.client.startPublishCDNStream(o)]):[3,2];case 1:return s.sent(),[3,3];case 2:this.log_.error("(startPublishCDNStream) failed - ".concat(JSON.stringify(e))),this.emitError(ie),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),this.callFunctionErrorManage(a,"startPublishCDNStream"),[3,5];case 5:return[2]}}))}))},t.prototype.stopPublishCDNStream=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),this.client?[4,this.client.stopPublishCDNStream()]:(this.log_.error("(stopPublishCDNStream) failed - ".concat(this.client)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - client = ").concat(this.client)}),[2]);case 1:return t.sent(),[3,3];case 2:return e=t.sent(),this.callFunctionErrorManage(e,"stopPublishCDNStream"),[3,3];case 3:return[2]}}))}))},t}(Y(ee)),he=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.startLocalPreview=function(t){return v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:this.log_.info("(startLocalPreview) start - start local preview",t,this.localStream),r.label=1;case 1:return r.trys.push([1,3,,4]),this.localStreamHasVideoOrAudio(B.VIDEO)?(this.playStream(this.localStream,t),[2]):[4,this.promiseRetry({retryFunction:this.doStartLocalPreview,settings:{retries:6,timeout:1e3}})(t)];case 2:return r.sent(),this.handleOnFirstVideoFrame("",e.TRTCVideoStreamType.TRTCVideoStreamTypeBig,t),[3,4];case 3:return i=r.sent(),this.isStaringLocalPreview=!1,this.callFunctionErrorManage(i,"startLocalPreview"),[3,4];case 4:return[2]}}))}))},i.prototype.doStartLocalPreview=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:if(this.isStaringLocalAudio)throw new Error("startLocalAudio is under implementation.");return this.isStaringLocalPreview=!0,W(e)?[3,11]:null===e?[3,10]:(t={userId:this.client&&"".concat(this.client.getUserId()," video")||"video undefined",video:!0,audio:!1,screenAudio:!1},this.currentCameraId&&(t.cameraId=this.currentCameraId),[4,this.generateLocalPlayStream(t)]);case 1:return o.sent(),this.localStream?(i=this.TRTC.createStream(t),this.videoEncodeParam?[4,i.setVideoProfile(this.videoEncodeParam)]:[3,3]):[3,6];case 2:o.sent(),o.label=3;case 3:return[4,i.initialize()];case 4:return o.sent(),r=i.getVideoTrack(),[4,this.localStream.addTrack(r)];case 5:return o.sent(),[3,8];case 6:return[4,this.initStream(t)];case 7:o.sent(),o.label=8;case 8:return this.isStartedLocalPreview=!0,this.localPlayStream&&(this.playStream(this.localPlayStream,e,this.localStreamRenderParams),this.clearTempAudioContainer("localAudio")),[4,this.publishLocalStream()];case 9:o.sent(),this.muteLocalVideo(this.isVideoMute_),this.isStaringLocalPreview=!1,o.label=10;case 10:return[3,12];case 11:this.emitError(ie),this.log_.error("(startLocalPreview) failed - ".concat(ie.message,": ").concat(e)),o.label=12;case 12:return[2]}}))}))},i.prototype.stopLocalPreview=function(){return v(this,void 0,void 0,(function(){var e=this;return S(this,(function(t){return this.log_.info("(stopLocalPreview) stop - stop local preview"),this.isStartedLocalPreview?[2,new Promise((function(t,i){return v(e,void 0,void 0,(function(){var e,r;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),[4,this.stopLocalPlayStreamTrack(B.VIDEO)];case 1:return o.sent(),this.localStream?this.localStream.getAudioTrack()?((e=this.localStream.getVideoTrack())&&this.localStream.removeTrack(e).then((function(){e.stop(),t(1)})),[3,4]):[3,2]:[3,4];case 2:return[4,this.unPublishStream()];case 3:o.sent(),this.localStream.stop(),this.localStream.close(),this.localStream=null,t(1),o.label=4;case 4:return[3,6];case 5:return r=o.sent(),this.callFunctionErrorManage(r,"stopLocalPreview"),i(r),[3,6];case 6:return[2]}}))}))}))]:(this.log_.info("(stopLocalPreview) stop - local preview has not been started"),[2])}))}))},i.prototype.muteLocalVideo=function(e){void 0===e&&(e=!1),this.isVideoMute_=e;try{this.localStream&&(e?this.localStream.muteVideo():this.localStream.unmuteVideo())}catch(t){this.callFunctionErrorManage(t,"muteLocalVideo")}},i.prototype.startRemoteView=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:return l.trys.push([0,7,,8]),t&&!W(i)&&r in e.TRTCVideoStreamType?(o=r,a=X(t),r===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?(a=G("".concat(B.SCREEN_SHARE_USER_ID_PREFIX).concat(t)),this.remoteStreamMap.has(a)||(a=G(t)),o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig):this.isSmallStreamSupported||(o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig),s=j[o],this.remoteStreamMap.has(a)?(n=this.remoteStreamMap.get(a),s===B.AUXILIARY?[3,3]:this.client?[4,this.client.setRemoteVideoStreamType(n,o)]:[3,2]):[3,6]):(this.emitError(ie),this.log_.error("(startRemoteView) failed - ".concat(ie.message,": ").concat(i)),[2]);case 1:l.sent(),l.label=2;case 2:l.label=3;case 3:return n?[4,this.client.subscribe(n,{audio:!0,video:!0})]:[3,6];case 4:return l.sent(),[4,this.playStream(n,i)];case 5:l.sent(),this.handleOnFirstVideoFrame(t,r,i),this.clearTempAudioContainer("".concat(a,"_dom")),l.label=6;case 6:return[3,8];case 7:return c=l.sent(),this.callFunctionErrorManage(c,"startRemoteView"),[3,8];case 8:return[2]}}))}))},i.prototype.stopRemoteView=function(t,i){return v(this,void 0,void 0,(function(){var r,o,a,s;return S(this,(function(n){switch(n.label){case 0:return n.trys.push([0,4,,5]),r=X(t),o=i,W(i)||(o=this.priorRemoteVideoStreamType),console.log("stopRemoteView streamType: ",o),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(r=G("".concat(B.SCREEN_SHARE_USER_ID_PREFIX).concat(t)),this.remoteStreamMap.has(r)||(r=G(t))),this.remoteStreamMap.has(r)?(a=this.remoteStreamMap.get(r),i!==e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?[3,1]:[3,3]):[3,3];case 1:return[4,this.client.subscribe(a,{audio:!0,video:!1})];case 2:n.sent(),n.label=3;case 3:return[3,5];case 4:return s=n.sent(),this.callFunctionErrorManage(s,"stopRemoteView"),[3,5];case 5:return[2]}}))}))},i.prototype.muteRemoteVideoStream=function(e,t){void 0===t&&(t=!1);try{if(!e)return this.emitError(ie),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(ie.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(X(e));i&&(t?i.muteVideo():i.unmuteVideo())}catch(r){this.callFunctionErrorManage(r,"stopRemoteView")}},i.prototype.setVideoEncoderParam=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),t=this.videoEncodeParam,e.videoResolution&&(i=this.getResolution(e.videoResolution),t.width=i.width,t.height=i.height),e.videoFps&&(t.frameRate=e.videoFps),e.videoBitrate&&(t.bitrate=e.videoBitrate),this.videoEncodeParam=t,[4,this.setStreamVideoParam(this.videoEncodeParam)];case 1:return o.sent(),[3,3];case 2:return r=o.sent(),this.callFunctionErrorManage(r,"setVideoEncoderParam"),[3,3];case 3:return[2]}}))}))},i.prototype.setLocalRenderParams=function(t){return v(this,void 0,void 0,(function(){var i,r,o,a;return S(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),i={},t.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Enable&&(i.mirror=!0),t.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Disable&&(i.mirror=!1),t.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fill&&(i.objectFit="cover"),t.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fit&&(i.objectFit="contain"),this.localStreamRenderParams=i,this.localStream?(r=this.playViewMap.get("".concat(this.localPlayStream.getUserId(),"-").concat(this.localPlayStream.getType())),[4,this.playStream(this.localPlayStream,r,i)]):[3,2];case 1:s.sent(),s.label=2;case 2:return this.testCameraStream&&(o=this.playViewMap.get("".concat(this.testCameraStream.getUserId(),"-").concat(this.testCameraStream.getType())),this.playStream(this.testCameraStream,o,i)),[3,4];case 3:return a=s.sent(),this.callFunctionErrorManage(a,"setLocalRenderParams"),[3,4];case 4:return[2]}}))}))},i.prototype.setRemoteRenderParams=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),o={},r.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Enable&&(o.mirror=!0),r.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Disable&&(o.mirror=!1),r.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fill&&(o.objectFit="cover"),r.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fit&&(o.objectFit="contain"),a=X(t),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(a=G(t)),s=this.playViewMap.get(a),(n=this.remoteStreamMap.get(a))?[4,this.playStream(n,s,o)]:[3,2];case 1:l.sent(),l.label=2;case 2:return[3,4];case 3:return c=l.sent(),this.callFunctionErrorManage(c,"setRemoteRenderParams"),[3,4];case 4:return[2]}}))}))},i.prototype.startCameraDeviceTest=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:return this.log_.info("(startCameraDeviceTest) start - start test camera Device",e),null===e?[3,2]:(t={userId:"test camera",video:!0,audio:!1,screenAudio:!1},this.currentCameraId&&(t.cameraId=this.currentCameraId),this.testCameraStream=this.TRTC.createStream(t),this.videoEncodeParam&&this.testCameraStream.setVideoProfile(this.videoEncodeParam),[4,this.testCameraStream.initialize()]);case 1:i.sent(),this.playStream(this.testCameraStream,e,this.localStreamRenderParams),i.label=2;case 2:return[2]}}))}))},i.prototype.stopCameraDeviceTest=function(){this.testCameraStream&&(this.testCameraStream.stop(),this.testCameraStream.close(),this.testCameraStream=null)},i}(Y(ee)),de=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.startLocalAudio=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:this.log_.info("(startLocalAudio) start - start local audio"),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.promiseRetry({retryFunction:this.doStartLocalAudio,settings:{retries:6,timeout:1e3}})(e)];case 2:return i.sent(),this.handleOnMicDidReady(),[3,4];case 3:return t=i.sent(),this.callFunctionErrorManage(t,"startLocalAudio"),[3,4];case 4:return[2]}}))}))},i.prototype.doStartLocalAudio=function(t){return v(this,void 0,void 0,(function(){var i,r,o,a,s,n;return S(this,(function(c){switch(c.label){case 0:if(this.isStaringLocalPreview)throw new Error("startLocalPreview is under implementation.");c.label=1;case 1:return c.trys.push([1,11,,12]),i=t,W(t)||(i=this.audioQuality),r={userId:this.client&&"".concat(this.client.getUserId()," audio")||"audio undefined",video:!1,audio:!0,screenAudio:!1},this.currentMicId&&(r.microphoneId=this.currentMicId),(o=this.TRTC.createStream(r)).setAudioProfile(H[i||e.TRTCAudioQuality.TRTCAudioQualityDefault]),[4,o.initialize()];case 2:return c.sent(),a=o.getAudioTrack(),[4,this.generateLocalPlayStream(r,t)];case 3:return c.sent(),this.localStream?this.localStream.getAudioTrack()?[4,this.localStream.replaceTrack(a)]:[3,5]:[3,8];case 4:return c.sent(),[3,7];case 5:return[4,this.localStream.addTrack(a)];case 6:c.sent(),c.label=7;case 7:return[3,9];case 8:this.localStream=o,s=this.generateTempAudioContainer("localAudio"),this.localPlayStream&&this.localPlayStream.play(s),c.label=9;case 9:return this.isStaringLocalAudio||(n=this.generateTempAudioContainer("localPublishAudio"),this.localStream&&this.localStream.play(n)),this.isStartedLocalAudio=!0,[4,this.publishLocalStream()];case 10:return c.sent(),this.muteLocalAudio(this.isAudioMute_),this.isStaringLocalAudio=!1,this.isPublished||this.getLocalStreamAudioLevel(),[3,12];case 11:throw c.sent();case 12:return[2]}}))}))},i.prototype.getLocalStreamAudioLevel=function(){var e=this;this.enableAudioVolumeInterval&&(this.enableAudioVolumeTimer=setInterval((function(){var t=[],i=Math.floor(100*e.localStream.getAudioLevel());t.push({userId:"",volume:i}),e.emit("onUserVoiceVolume",t,t.length)}),this.enableAudioVolumeInterval))},i.prototype.generateTempAudioContainer=function(e){var t=document.createElement("div");return t.id=e,t.style.width="0",t.style.height="0",document.getElementsByTagName("body")[0].appendChild(t),t},i.prototype.clearTempAudioContainer=function(e){var t=document.getElementById(e);t&&document.getElementsByTagName("body")[0].removeChild(t)},i.prototype.stopLocalAudio=function(){return v(this,void 0,void 0,(function(){var e=this;return S(this,(function(t){return this.log_.info("(stopLocalAudio) stop - stop local audio"),this.isStartedLocalAudio?[2,new Promise((function(t,i){return v(e,void 0,void 0,(function(){var e,r,o;return S(this,(function(a){switch(a.label){case 0:return a.trys.push([0,5,,6]),[4,this.stopLocalPlayStreamTrack(B.AUDIO)];case 1:return a.sent(),this.localStream?(this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),e=this.localStream.getVideoTrack(),this.clearTempAudioContainer("localPublishAudio"),e?((r=this.localStream.getAudioTrack())&&(this.muteLocalAudio(!0),r.stop(),t(1)),[3,4]):[3,2]):[3,4];case 2:return[4,this.unPublishStream()];case 3:a.sent(),this.localStream.stop(),this.localStream.close(),this.clearTempAudioContainer("localAudio"),this.localStream=null,t(1),a.label=4;case 4:return[3,6];case 5:return o=a.sent(),this.callFunctionErrorManage(o,"stopLocalAudio"),i(o),[3,6];case 6:return[2]}}))}))}))]:(this.log_.info("(stopLocalAudio) stop - local audio has not been started"),[2])}))}))},i.prototype.muteLocalAudio=function(e){void 0===e&&(e=!1),this.isAudioMute_=e;try{this.localStream&&(e?(this.localStream.muteAudio(),this.localPlayStream.muteAudio()):(this.localStream.unmuteAudio(),this.localPlayStream.unmuteAudio()))}catch(t){this.callFunctionErrorManage(t,"muteLocalAudio")}},i.prototype.muteRemoteAudio=function(e,t){void 0===t&&(t=!1);try{if(!e)return this.emitError(ie),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(ie.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(X(e));i&&(t?i.muteAudio():i.unmuteAudio())}catch(r){this.callFunctionErrorManage(r,"muteRemoteAudio")}},i.prototype.muteAllRemoteAudio=function(e){try{this.remoteStreamMap.size>0&&Array.from(this.remoteStreamMap,(function(e){return e[1]})).forEach((function(t){t&&(e?t.muteAudio():t.unmuteAudio())}))}catch(t){this.callFunctionErrorManage(t,"muteAllRemoteAudio")}},i.prototype.setRemoteAudioVolume=function(e,t){try{if(!e||t<0)return this.emitError(ie),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(ie.message,": userId = ").concat(e,", volume = ").concat(t));var i=this.remoteStreamMap.get(X(e));if(i){var r=t>100?1:t/100;i.setAudioVolume(r)}}catch(o){this.callFunctionErrorManage(o,"setRemoteAudioVolume")}},i.prototype.getAudioCaptureVolume=function(){try{return this.localStream?100*this.localStream.getAudioLevel():(this.log_.warn("(getAudioCaptureVolume) failed - localStream = ".concat(this.localStream)),0)}catch(e){return this.callFunctionErrorManage(e,"getAudioCaptureVolume"),0}},i}(Y(ee)),me=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.getCameraDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return S(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.TRTC.getCameras()];case 1:return e=i.sent(),this.cameraList=e.map((function(e){return p(p({},e),{deviceName:e.label})})),[2,Promise.resolve(this.cameraList)];case 2:return t=i.sent(),this.callFunctionErrorManage(t,"getCameraDevicesList"),this.cameraList=[],[2,Promise.resolve([])];case 3:return[2]}}))}))},i.prototype.setCurrentCameraDevice=function(t){return v(this,void 0,Promise,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,7,,8]),t?this.currentCameraId===t?[2,Promise.resolve(!0)]:(this.currentCameraId=t||"",Z(this.localStream)?[4,this.localStream.switchDevice(B.VIDEO,t)]:[3,2]):[2,Promise.resolve(!1)];case 1:r.sent(),r.label=2;case 2:return Z(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.VIDEO,t)]:[3,4];case 3:r.sent(),r.label=4;case 4:return Z(this.testCameraStream)?[4,this.testCameraStream.switchDevice("video",t)]:[3,6];case 5:r.sent(),r.label=6;case 6:return this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeCamera,e.TRTCDeviceState.TRTCDeviceStateActive),[2,Promise.resolve(!0)];case 7:return i=r.sent(),this.callFunctionErrorManage(i,"setCurrentCameraDevice"),this.cameraList=[],[2,Promise.resolve(!1)];case 8:return[2]}}))}))},i.prototype.getCurrentCameraDevice=function(){var e=this;return(this.cameraList||[]).filter((function(t){return t.deviceId===e.currentCameraId}))[0]||{}},i}(Y(ee)),Te=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.getMicDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return S(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.TRTC.getMicrophones()];case 1:return e=i.sent(),this.micList=e.map((function(e){return p(p({},e),{deviceName:e.label})})),[2,Promise.resolve(this.micList)];case 2:return t=i.sent(),this.callFunctionErrorManage(t,"getMicDevicesList"),[2,Promise.resolve([])];case 3:return[2]}}))}))},i.prototype.getCurrentMicDevice=function(){var e=this;return this.currentMicId?(this.micList||[]).filter((function(t){return t.deviceId===e.currentMicId}))[0]||{}:new y},i.prototype.setCurrentMicDevice=function(t){return v(this,void 0,Promise,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,5,,6]),t?this.currentMicId===t?[2,Promise.resolve(!0)]:(this.currentMicId=t||"",$(this.localStream)?[4,this.localStream.switchDevice(B.AUDIO,t)]:[3,2]):[2,Promise.resolve(!1)];case 1:r.sent(),r.label=2;case 2:return $(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.AUDIO,t)]:[3,4];case 3:r.sent(),r.label=4;case 4:return this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeMic,e.TRTCDeviceState.TRTCDeviceStateActive),[2,Promise.resolve(!0)];case 5:return i=r.sent(),this.callFunctionErrorManage(i,"setCurrentMicDevice"),[2,Promise.resolve(!1)];case 6:return[2]}}))}))},i.prototype.getSpeakerDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return S(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.TRTC.getSpeakers()];case 1:return e=i.sent(),this.speakerList=e.map((function(e){return p(p({},e),{deviceName:e.label})})),[2,Promise.resolve(this.speakerList)];case 2:return t=i.sent(),this.callFunctionErrorManage(t,"getSpeakerDevicesList"),[2,Promise.resolve([])];case 3:return[2]}}))}))},i.prototype.getCurrentSpeakerDevice=function(){var e=this;return this.currentSpeakerId?(this.speakerList||[]).filter((function(t){return t.deviceId===e.currentSpeakerId}))[0]||{}:new y},i.prototype.setCurrentSpeakerDevice=function(e){return v(this,void 0,Promise,(function(){var t,i,r=this;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),e?(this.currentSpeakerId=e||"",this.remoteStreamMap.size>0?(t=this.getRemoteStreamList(),[4,Promise.all(t.map((function(e){return v(r,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return[4,e.setAudioOutput(this.currentSpeakerId)];case 1:return[2,t.sent()]}}))}))})))]):[3,2]):[2,Promise.resolve(!1)];case 1:o.sent(),o.label=2;case 2:return[2,Promise.resolve(!0)];case 3:return i=o.sent(),this.callFunctionErrorManage(i,"setCurrentSpeakerDevice"),[2,Promise.resolve(!1)];case 4:return[2]}}))}))},i}(Y(ee)),pe=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.startScreenCapture=function(){this.emitError(se)},i.prototype.pauseScreenCapture=function(){this.emitError(se)},i.prototype.resumeScreenCapture=function(){this.emitError(se)},i.prototype.getScreenCaptureSources=function(){this.emitError(se)},i.prototype.selectScreenCaptureTarget=function(){this.emitError(se)},i.prototype.startScreenShare=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c,l,u,h,d;return S(this,(function(m){switch(m.label){case 0:if(!this.isJoined||this.isJoining)return this.emitError(ne),[2];if(i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSmall)return this.emitError(le),[2];o=i||e.TRTCVideoStreamType.TRTCVideoStreamTypeSub,s=(a=r||{}).videoResolution,n=a.videoFps,c=a.videoBitrate,l=a.screenAudio,u=void 0!==l&&l,s&&(h=this.getResolution(s),this.screenShareParams_.width=h.width,this.screenShareParams_.height=h.height),n&&(this.screenShareParams_.frameRate=n),c&&(this.screenShareParams_.bitrate=c),m.label=1;case 1:return m.trys.push([1,4,,5]),[4,this.initShareStream_(!!u)];case 2:return m.sent(),[4,this.shareStreamPublish_(o)];case 3:return m.sent(),t&&this.shareStream_&&this.playStream(this.shareStream_,t),this.isSharing_=!0,[3,5];case 4:throw d=m.sent(),console.error("Start share screen error:",d),d;case 5:return[2]}}))}))},i.prototype.setSubStreamEncoderParam=function(e){var t=e.videoResolution,i=e.videoFps,r=e.videoBitrate;try{var o=this.getResolution(t);this.screenShareParams_={width:o.width,height:o.height,frameRate:i,bitrate:r}}catch(a){throw a}},i.prototype.stopScreenShare=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:if(!this.isShareStreamPublished_)return console.warn("ShareClient cannot unpublish() - you have not published yet"),[2];t.label=1;case 1:return t.trys.push([1,4,,5]),this.shareStream_?[4,this.client.unpublish(this.shareStream_)]:[3,3];case 2:t.sent(),this.shareStream_.close(),t.label=3;case 3:return this.isShareStreamPublished_=!1,this.shareStream_=null,this.isSharing_=!1,console.log("Unpublish ShareStream success"),[3,5];case 4:throw e=t.sent(),console.error("unpublish failed",e),e;case 5:return[2]}}))}))},i.prototype.initShareStream_=function(e){return v(this,void 0,void 0,(function(){var t,i=this;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.shareStream_=this.TRTC.createStream({audio:!1,screen:!0,userId:this.userId,screenAudio:e}),this.shareStream_.setScreenProfile(this.screenShareParams_),[4,this.shareStream_.initialize()];case 1:return r.sent(),this.shareStream_.on("screen-sharing-stopped",(function(){console.log("ShareStream video track ended"),i.emit("onWebScreenSharingStopped"),i.stopScreenShare()})),[2,this.shareStream_];case 2:throw t=r.sent(),console.error("ShareStream failed to initialize. Error: ".concat(t)),t;case 3:return[2]}}))}))},i.prototype.shareStreamPublish_=function(t){return v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:if(this.isShareStreamPublished_)return console.warn("ShareClient duplicate publish() observed"),[2];r.label=1;case 1:return r.trys.push([1,6,,7]),t!==e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?[3,3]:[4,this.client.publish(this.shareStream_,{isAuxiliary:!0})];case 2:return r.sent(),[3,5];case 3:return[4,this.client.publish(this.shareStream_)];case 4:r.sent(),r.label=5;case 5:return console.log("ShareStream is published successfully"),this.isShareStreamPublished_=!0,[3,7];case 6:throw i=r.sent(),console.error("ShareStream is failed to publish. Error: ".concat(i)),i;case 7:return[2]}}))}))},i}(Y(ee)),ve=null,Se=function(t){function i(){var e,i,r,o=t.call(this)||this;return o.enableAudioVolumeInterval=0,o.enableAudioVolumeTimer=-1,o.frameWorkType=30,o.component=0,o.VERSION="1.0.7",o.log_=o.TRTC.Logger.loggerManager,o.handleError=o.handleError.bind(o),o.handlePeerJoin=o.handlePeerJoin.bind(o),o.handlePeerLeave=o.handlePeerLeave.bind(o),o.handleStreamAdded_=o.handleStreamAdded_.bind(o),o.handleStreamSubscribed=o.handleStreamSubscribed.bind(o),o.handleStreamRemoved_=o.handleStreamRemoved_.bind(o),o.handleStreamUpdated_=o.handleStreamUpdated_.bind(o),o.handleMuteAudio=o.handleMuteAudio.bind(o),o.handleUnmuteAudio=o.handleUnmuteAudio.bind(o),o.handleMuteVideo=o.handleMuteVideo.bind(o),o.handleUnmuteVideo=o.handleUnmuteVideo.bind(o),o.handleAudioVolume=o.handleAudioVolume.bind(o),o.handleNetworkQuality=o.handleNetworkQuality.bind(o),o.handleDeviceChange=o.handleDeviceChange.bind(o),navigator&&navigator.mediaDevices&&navigator.mediaDevices.addEventListener("devicechange",(e=o.handleDeviceChange,i=30,function(){for(var t=this,o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];r>0&&clearTimeout(r),r=window.setTimeout((function(){e.apply(t,o),r=-1}),i)})),o.TRTC.getMicrophones().then((function(e){o.micList=e||[]})).catch((function(e){o.log_.error("getMicrophones error observed ".concat(e))})),o.TRTC.getCameras().then((function(e){o.cameraList=e||[]})).catch((function(e){o.log_.error("getCameras error observed ".concat(e))})),o.TRTC.getSpeakers().then((function(e){o.speakerList=e||[]})).catch((function(e){o.log_.error("getSpeakers error observed ".concat(e))})),o}return s(i,t),i.getTRTCShareInstance=function(){return ve||(ve=new i),ve},i.destroyTRTCShareInstance=function(){ve&&(ve.destroy(),ve=null)},i.prototype.getSDKVersion=function(){return this.VERSION||""},i.prototype.off=function(e,t){void 0===t&&(t=function(){});try{"*"===e?this.removeAllListeners():this.removeListener(e,t)}catch(i){console.log("off error ",i)}},i.prototype.enterRoom=function(e,t){return v(this,void 0,void 0,(function(){var i,r,o,a,s,n,c,l,u,h,d,m,T,v;return S(this,(function(S){switch(S.label){case 0:if(i=e.sdkAppId,r=e.userId,o=e.userSig,a=e.roomId,s=e.strRoomId,n=e.role,c=e.privateMapKey,l=e.streamId,u=e.frameWorkType,h=e.component,d=void 0===h?0:h,!(i&&r&&o))return[3,6];if(this.sdkAppId=i,this.userId=r,this.userSig=o,this.roomId=a,this.strRoomId=s,this.useStringRoomId=Boolean(!a&&s),this.realRoomId=a||s,this.mode=J[t],this.role=x[n],this.remoteUserAvailable=new Map,u&&typeof u===B.NUMBER&&(this.frameWorkType=u),d&&typeof d===B.NUMBER&&(this.component=d),this.isSharedStream(r))return this.log_.error("(enterRoom) failed - ".concat(ce.message," userId: ").concat(this.userId)),this.emitError(ce),[2];if(this.isJoining||this.isJoined)return this.log_.error("(enterRoom) failed - ".concat(re.message," isJoining: ").concat(this.isJoining,", isJoined: ").concat(this.isJoined)),this.emitError(re),[2];S.label=1;case 1:return S.trys.push([1,4,,5]),this.isJoining=!0,m={sdkAppId:i,userId:r,userSig:o,mode:this.mode,useStringRoomId:this.useStringRoomId,frameWorkType:this.frameWorkType,component:this.component},m=c?p(p({},m),{privateMapKey:c}):m,m=l?p(p({},m),{streamId:l}):m,this.initClient(m),this.startJoinTimestamp=z(),[4,this.client.join({roomId:this.realRoomId,role:this.role})];case 2:return S.sent(),this.isJoined=!0,this.isJoining=!1,this.joinedTimestamp=z(),T=this.joinedTimestamp-this.startJoinTimestamp,this.emit("onEnterRoom",T),this.log_.info("(enterRoom) success - enter room"),[4,this.publishLocalStream()];case 3:return S.sent(),[3,5];case 4:return v=S.sent(),this.isJoining=!1,this.emit("onEnterRoom",-1),this.callFunctionErrorManage(v,"enterRoom"),[3,5];case 5:return[3,7];case 6:this.emitError(ie),this.log_.error("(enterRoom) failed - ".concat(ie.message,": ").concat(JSON.stringify(e))),S.label=7;case 7:return[2]}}))}))},i.prototype.exitRoom=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:this.log_.info("(exitRoom) exitRoom, isJoined: ".concat(this.isJoined,"; isPublished: ").concat(this.isPublished)),t.label=1;case 1:return t.trys.push([1,7,,8]),!this.isJoined||this.isExiting?(this.log_.error("(exitRoom) failed - ".concat(oe.message," isJoined: ").concat(this.isJoined," isExiting: ").concat(this.isExiting)),this.emitError(oe),[2]):(this.isExiting=!0,this.isSharing_?[4,this.stopScreenShare()]:[3,3]);case 2:t.sent(),t.label=3;case 3:return this.isPublished?[4,this.unPublishStream()]:[3,5];case 4:t.sent(),this.destroyLocalStream(),t.label=5;case 5:return this.emit("onExitRoom",F.ActiveExitRoom),[4,this.client.leave()];case 6:return t.sent(),this.resetStatus(),this.destroy(),this.log_.info("(exitRoom) success - exit room"),[3,8];case 7:return e=t.sent(),this.isExiting=!1,this.callFunctionErrorManage(e,"exitRoom"),[3,8];case 8:return[2]}}))}))},i.prototype.switchRole=function(t){return v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,8,,9]),this.mode===B.RTC?(this.log_.info("(publishLocalStream) failed - mode = ".concat(this.mode,", role = ").concat(t)),this.handleOnSwitchRole(-1,"(publishLocalStream) failed - mode = ".concat(this.mode,", role = ").concat(t)),[2]):this.client?t===e.TRTCRoleType.TRTCRoleAnchor||t===e.TRTCRoleType.TRTCRoleAudience?[3,1]:(this.handleOnSwitchRole(-1,"please pass valid role parameter, role = ".concat(t,", type = ").concat(typeof t)),[3,5]):[3,6];case 1:return[4,this.client.switchRole(x[t])];case 2:return r.sent(),this.role=x[t],this.isPublished=!1,t===e.TRTCRoleType.TRTCRoleAnchor&&this.localStream?[4,this.publishLocalStream()]:[3,4];case 3:r.sent(),r.label=4;case 4:this.handleOnSwitchRole(0,"switch role success, role = ".concat(t,", ").concat(x[t])),r.label=5;case 5:return[3,7];case 6:this.handleOnSwitchRole(-1,"switch role failed, client = ".concat(this.client)),r.label=7;case 7:return[3,9];case 8:return i=r.sent(),this.handleOnSwitchRole(-1,JSON.stringify(i)),[3,9];case 9:return[2]}}))}))},i.prototype.enableAudioVolumeEvaluation=function(e){this.client?this.client.enableAudioVolumeEvaluation(e):e<=0&&this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),this.enableAudioVolumeInterval=e},i.prototype.callFunctionErrorManage=function(e,t){e&&e.getCode&&e.getCode()?(this.emit(B.ON_ERROR,e.getCode(),e.message_),this.log_.error("(".concat(t,") failed - ").concat(e.message_))):(this.emit(B.ON_ERROR,te,e.message),this.log_.error("(".concat(t,") failed - ").concat(e.message)))},i.prototype.resetStatus=function(){this.isExiting=!1,this.isJoining=!1,this.isJoined=!1,this.isPublishing=!1,this.isPublished=!1,this.isSubscribed=!1,this.isVideoMute_=!1,this.isAudioMute_=!1,this._enableAudioVolumeTimer=-1,this.remoteStreamMap.clear(),this.videoEncodeParam={width:this.defaultVideoWidth,height:this.defaultVideoHeight,frameRate:this.defaultVideoFps,bitrate:this.defaultVideoBitRate},this.screenShareParams_={width:this.defaultShareWidth_,height:this.defaultShareHeight_,frameRate:this.defaultShareFrameRate_,bitrate:this.defaultShareBitrate_}},i.prototype.publishLocalStream=function(){return v(this,void 0,void 0,(function(){var e,t,i,r,o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:if(t=(e=this).mode,i=e.role,r=e.isJoined,o=e.isPublishing,a=e.isPublished,s=e.localStream,n=e.client,t===B.LIVE&&i===B.AUDIENCE)return this.log_.info("(publishLocalStream) failed - mode = ".concat(t,", role = ").concat(i)),[2];if(!r||o||a||!s||!n)return this.log_.info("(publishLocalStream) failed - isJoined = ".concat(r,",\n isPublishing = ").concat(o,", isPublished = ").concat(a,", localStream = ").concat(s,", client.userId = ").concat(n?n.getUserId():null)),[2];if(this.log_.info("(publishLocalStream) start - publish stream"),!r||a)return[3,6];this.isPublishing=!0,l.label=1;case 1:return l.trys.push([1,5,,6]),[4,this.setStreamVideoParam(this.videoEncodeParam)];case 2:return l.sent(),this.localStream?[4,this.client.publish(this.localStream)]:[3,4];case 3:l.sent(),this.isPublished=!0,this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),this.log_.info("(publishLocalStream) success - publish stream"),l.label=4;case 4:return this.isPublishing=!1,[3,6];case 5:return c=l.sent(),this.isPublishing=!1,this.callFunctionErrorManage(c,"publishLocalStream"),[3,6];case 6:return[2]}}))}))},i.prototype.unPublishStream=function(){return v(this,void 0,void 0,(function(){return S(this,(function(e){switch(e.label){case 0:return this.log_.info("(unPublishStream) unPublishStream",this.localStream),this.isPublished&&this.localStream?[4,this.client.unpublish(this.localStream)]:[3,2];case 1:e.sent(),this.isPublished=!1,e.label=2;case 2:return[2]}}))}))},i.prototype.setStreamVideoParam=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,6,,10]),this.localStream?(t=this.localStream.getVideoTrack())?[4,this.localStream.setVideoProfile(e)]:[2]:[3,2];case 1:return o.sent(),(t=this.localStream.getVideoTrack())&&(i=t.getSettings(),console.log("分辨率:".concat(i.width," * ").concat(i.height,", 帧率:").concat(i.frameRate))),[3,3];case 2:this.videoEncodeParam=e,o.label=3;case 3:return this.localPlayStream&&this.localPlayStream.hasVideo()?[4,this.localPlayStream.setVideoProfile(e)]:[3,5];case 4:o.sent(),o.label=5;case 5:return[3,10];case 6:return"OverconstrainedError"!==o.sent().name?[3,8]:(console.error("当前摄像头不支持该 profile"),[4,(r=this.TRTC.createStream({video:!0,audio:!1})).initialize()]);case 7:return o.sent(),this.localStream.replaceTrack(r.getVideoTrack()),[3,9];case 8:console.error("当前浏览器不支持动态调用该接口"),o.label=9;case 9:return[3,10];case 10:return[2]}}))}))},i.prototype.destroyLocalStream=function(){this.localStream&&(this.localStream.stop(),this.localStream&&this.localStream.close(),this.localStream=null)},i.prototype.destroy=function(){this.unbindEvents(),this.client&&(this.client=null)},i.prototype.initStream=function(e){return v(this,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.localStream=this.TRTC.createStream(e),this.videoEncodeParam&&this.localStream&&this.localStream.setVideoProfile(this.videoEncodeParam),[4,this.localStream.initialize()];case 1:return t.sent(),[2]}}))}))},i.prototype.localStreamHasVideoOrAudio=function(e){if(e&&"string"==typeof e||this.emitError(ie),!this.localStream)return!1;switch(e){case B.VIDEO:return!!this.localStream.getVideoTrack();case B.AUDIO:return!!this.localStream.getAudioTrack();default:return!1}},i.prototype.playStream=function(e,t,i){return v(this,void 0,void 0,(function(){var r,o,a;return S(this,(function(s){if(!t||!e)return this.log_.error("(playStream) failed - dom = ".concat(t,", stream = ").concat(e)),[2];if(!(r="string"==typeof t?document.getElementById(t):t))return this.log_.error("(playStream) failed - dom = ".concat(t,", stream = ").concat(e)),[2];try{e.play(r,i)}catch(n){}return o=e.getUserId(),o=this.isSharedStream(o)?o.slice(6):o,a=e.getType(),this.playViewMap.set("".concat(o,"-").concat(a),t),[2]}))}))},i.prototype.initClient=function(e){this.client=this.TRTC.createClient(e),this.enableAudioVolumeInterval&&this.client.enableAudioVolumeEvaluation(this.enableAudioVolumeInterval),this.bindEvents()},i.prototype.bindEvents=function(){var e=this;this.client.on("error",this.handleError),this.client.on("peer-join",this.handlePeerJoin),this.client.on("peer-leave",this.handlePeerLeave),this.client.on("stream-added",this.handleStreamAdded_),this.client.on("stream-subscribed",this.handleStreamSubscribed),this.client.on("stream-removed",this.handleStreamRemoved_),this.client.on("stream-updated",this.handleStreamUpdated_),this.client.on("mute-audio",this.handleMuteAudio),this.client.on("unmute-audio",this.handleUnmuteAudio),this.client.on("mute-video",this.handleMuteVideo),this.client.on("unmute-video",this.handleUnmuteVideo),this.client.on("client-banned",(function(t){e.log_.error("client has been banned for ".concat(t)),e.emit("onExitRoom",F.KickedExitRoom)})),this.client.on("audio-volume",this.handleAudioVolume),this.client.on("network-quality",this.handleNetworkQuality)},i.prototype.unbindEvents=function(){this.client&&this.client.off("*")},i.prototype.emitError=function(e){e&&this.emit&&this.emit(B.ON_ERROR,e.code,e.message)},i.prototype.handleError=function(e){this.log_.error("handle error observed ".concat(e)),this.emit(B.ON_ERROR,e.getCode(),e.message)},i.prototype.handleEnterRoom=function(){},i.prototype.handleExitRoom=function(){},i.prototype.handlePeerJoin=function(e){var t=e.userId;if(!this.isSharedStream(t)||!this.remoteUserAvailable.has(t)){var i=Array.from(this.remoteUserAvailable.keys())||[];this.remoteUserAvailable.set(t,{isAudioAvailable:!1,isVideoAvailable:!1}),q(this.userId,t)||(i.filter((function(e){return q(e,t)}))||[]).length>0||this.isSharedStream(t)||this.emit("onRemoteUserEnterRoom",t)}},i.prototype.handlePeerLeave=function(e){var t=e.userId,i=void 0===t?"":t;this.isSharedStream(i)||this.emit("onRemoteUserLeaveRoom",i,0)},i.prototype.handleOnUserAudioAvailable=function(e,t,i){return v(this,void 0,void 0,(function(){var r;return S(this,(function(o){switch(o.label){case 0:return this.remoteUserAvailable.get(e).isAudioAvailable=t,this.emit("onUserAudioAvailable",e,t?1:0),t?this.remoteStreamMap.get("".concat(e,"-").concat(i)).isPlaying()?[3,3]:(r=this.generateTempAudioContainer("".concat(e,"-").concat(i,"_dom")),[4,this.remoteStreamMap.get("".concat(e,"-").concat(i)).play(r)]):[3,4];case 1:return o.sent(),[4,this.remoteStreamMap.get("".concat(e,"-").concat(i)).setAudioOutput(this.currentSpeakerId)];case 2:o.sent(),o.label=3;case 3:return[3,5];case 4:this.clearTempAudioContainer("".concat(e,"-").concat(i,"_dom")),o.label=5;case 5:return[2]}}))}))},i.prototype.handleOnUserVideoAvailable=function(e,t){this.remoteUserAvailable.get(e).isVideoAvailable=t,this.emit("onUserVideoAvailable",e,t?1:0)},i.prototype.handleOnUserSubStreamAvailable=function(e,t){try{this.remoteUserAvailable.get(e).isVideoAvailable=t;var i=e;if(this.isSharedStream(e)&&(i=e.slice(6))===this.userId)return;this.emit("onUserSubStreamAvailable",i,t?1:0)}catch(r){this.emitError(ie)}},i.prototype.handleOnSwitchRole=function(e,t){this.emit("onSwitchRole",e,t)},i.prototype.handleAudioVolume=function(e){var t=this,i=e.result||[];i=(i=i.map((function(e){return{userId:e.userId===t.userId?"":e.userId,volume:e.audioVolume}}))||[]).filter((function(e){return!t.isSharedStream(e.userId)})),this.emit("onUserVoiceVolume",i,i.length)},i.prototype.handleOnFirstVideoFrame=function(e,t,i){var r=i.offsetWidth,o=i.offsetHeight;this.emit("onFirstVideoFrame",e,t,r,o)},i.prototype.handleOnMicDidReady=function(){this.emit("onMicDidReady")},i.prototype.handleStreamAdded_=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:return t=e.stream,i=t.getUserId(),r=t.getType(),this.remoteStreamMap.set("".concat(i,"-").concat(r),e.stream),r!==B.AUXILIARY?[3,1]:(this.handleOnUserSubStreamAvailable(i,!0),[3,4]);case 1:return t.hasAudio()?[4,this.handleOnUserAudioAvailable(i,!0,r)]:[3,3];case 2:o.sent(),o.label=3;case 3:t.hasVideo()&&this.handleOnUserVideoAvailable(i,!0),o.label=4;case 4:return this.handleSubscribe(e.stream),[2]}}))}))},i.prototype.handleSubscribe=function(e,t){return void 0===t&&(t={audio:!0,video:!0}),v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.client.subscribe(e,{audio:!!W(t.audio)||t.audio,video:!!W(t.video)||t.video})];case 1:return r.sent(),[3,3];case 2:return i=r.sent(),console.error("subscribe ".concat(e.getUserId()," with audio: ").concat(t.audio," video: ").concat(t.video," error"),i),[3,3];case 3:return[2]}}))}))},i.prototype.handleStreamSubscribed=function(){this.isSubscribed=!0},i.prototype.handleStreamRemoved_=function(e){return v(this,void 0,void 0,(function(){var t,i;return S(this,(function(r){switch(r.label){case 0:return t=e.stream.getUserId(),(i=e.stream.getType())!==B.MAIN?[3,2]:[4,this.handleOnUserAudioAvailable(t,!1,i)];case 1:return r.sent(),this.handleOnUserVideoAvailable(t,!1),[3,3];case 2:i===B.AUXILIARY&&this.handleOnUserSubStreamAvailable(t,!1),r.label=3;case 3:return this.remoteStreamMap.delete("".concat(t,"-").concat(i)),[2]}}))}))},i.prototype.handleStreamUpdated_=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o;return S(this,(function(a){switch(a.label){case 0:return t=e.stream,i=t.getUserId(),(r=t.getType())===B.AUXILIARY?[2]:(o=this.remoteStreamMap.get("".concat(i,"-").concat(r))).hasAudio()||!t.hasAudio()||this.remoteUserAvailable.get(i).isAudioAvailable?[3,2]:[4,this.handleOnUserAudioAvailable(i,!0,r)];case 1:a.sent(),a.label=2;case 2:return o.hasVideo()||!t.hasVideo()||this.remoteUserAvailable.get(i).isVideoAvailable||this.handleOnUserVideoAvailable(i,!0),[2]}}))}))},i.prototype.handleMuteAudio=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:return t=e.userId,this.isSharedStream(t)?[2]:t?[4,this.handleOnUserAudioAvailable(t,!1,B.MAIN)]:[3,2];case 1:i.sent(),i.label=2;case 2:return[2]}}))}))},i.prototype.handleUnmuteAudio=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:return t=e.userId,this.isSharedStream(t)?[2]:!t||this.remoteUserAvailable.get(t).isAudioAvailable?[3,2]:[4,this.handleOnUserAudioAvailable(t,!0,B.MAIN)];case 1:i.sent(),i.label=2;case 2:return[2]}}))}))},i.prototype.handleMuteVideo=function(e){var t=e.userId;this.isSharedStream(t)||t&&this.handleOnUserVideoAvailable(t,!1)},i.prototype.handleUnmuteVideo=function(e){var t=e.userId;if(!this.isSharedStream(t)&&t&&!this.remoteUserAvailable.get(t).isVideoAvailable){if(((Array.from(this.remoteUserAvailable.keys())||[]).filter((function(e){return q(e,t)}))||[]).length>0)return void this.handleOnUserSubStreamAvailable(t,!0);if(this.isSharedStream(t)&&t.slice(6)===this.userId)return;this.handleOnUserVideoAvailable(t,!0)}},i.prototype.getLocalStatistics=function(){var t=this;return this.client.getLocalVideoStats().then((function(i){var r=i[t.client.getUserId()],o=r.bytesSent-t.prevLocalVideoStats.bytesSent,a=r.framesEncoded-t.prevLocalVideoStats.framesEncoded,s=r.frameWidth,n=r.frameHeight;o<0&&(o=0),a<0&&(a=0),t.prevLocalVideoStats=r;var c=Number((8*o/1e3/2).toFixed()),l=Number((a/2).toFixed()),u=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig;return new D(s,n,l,c,0,0,u)}))},i.prototype.handleNetworkQuality=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o,a,s,n,c,l,u,h;return S(this,(function(d){switch(d.label){case 0:return t=e.uplinkNetworkQuality,i=e.downlinkNetworkQuality,r=e.uplinkRTT,o=e.uplinkLoss,a=e.downlinkLoss,s=this.client?this.client.getUserId():"",n=new w(s,t),this.remoteStreamMap.size>0&&(c=(c=Array.from(this.remoteStreamMap.keys())).map((function(e){return e.includes("-".concat(B.MAIN))?e.split("-".concat(B.MAIN))[0]:e.includes("-".concat(B.AUXILIARY))?e.split("-".concat(B.AUXILIARY))[0]:""})),c=Array.from(new Set(c.filter((function(e){return e})))),l=c.map((function(e){return{userId:e,quality:i}})),this.emit("onNetworkQuality",n,l)),[4,this.getLocalStatistics()];case 1:return u=d.sent(),h=new L(o,a,0,0,r,0,0,[u]),this.emit("onStatistics",h),[2]}}))}))},i.prototype.handleDeviceChange=function(){return v(this,void 0,void 0,(function(){var t=this;return S(this,(function(i){return this.TRTC.getCameras().then((function(i){return v(t,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.cameraList.length===i.length?[2]:[4,this.deviceChangeManage(this.cameraList,i,e.TRTCDeviceType.TRTCDeviceTypeCamera)];case 1:return t.sent(),this.cameraList=i,[2]}}))}))})),this.TRTC.getMicrophones().then((function(i){return v(t,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.micList.length===i.length?[2]:[4,this.deviceChangeManage(this.micList,i,e.TRTCDeviceType.TRTCDeviceTypeMic)];case 1:return t.sent(),this.micList=i,[2]}}))}))})),this.TRTC.getSpeakers().then((function(i){return v(t,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.speakerList.length===i.length?[2]:[4,this.deviceChangeManage(this.speakerList,i,e.TRTCDeviceType.TRTCDeviceTypeSpeaker)];case 1:return t.sent(),this.speakerList=i,[2]}}))}))})),[2]}))}))},i.prototype.emitOnDeviceChange=function(e,t,i){this.emit("onDeviceChange",e,t,i)},i.prototype.deviceChangeManage=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:return t.length===i.length?[3,8]:(o=(i||[]).map((function(e){return e.deviceId})),a=new y,s=e.TRTCDeviceState.TRTCDeviceStateAdd,t.length>i.length&&(a=t.filter((function(e){return!o.includes(e.deviceId)}))[0]||{},s=e.TRTCDeviceState.TRTCDeviceStateRemove),t.length<i.length&&(o=(t||[]).map((function(e){return e.deviceId})),a=i.filter((function(e){return!o.includes(e.deviceId)}))[0]||{}),n=a.deviceId,this.emitOnDeviceChange(n,r,s),s!==e.TRTCDeviceState.TRTCDeviceStateAdd?[3,2]:[4,this.autoChangeDevice(r,s,n)]);case 1:return l.sent(),[3,8];case 2:return s!==e.TRTCDeviceState.TRTCDeviceStateRemove?[3,8]:n!==this.currentSpeakerId&&n!==this.currentMicId?[3,5]:(c=this.getDefaultDeviceInfo(i)).deviceId?[4,this.autoChangeDevice(r,s,c.deviceId)]:[3,4];case 3:l.sent(),l.label=4;case 4:l.label=5;case 5:return r!==e.TRTCDeviceType.TRTCDeviceTypeCamera?[3,8]:(c=this.getDefaultDeviceInfo(i)).deviceId?[4,this.autoChangeDevice(r,s,c.deviceId)]:[3,7];case 6:l.sent(),l.label=7;case 7:l.label=8;case 8:return[2]}}))}))},i.prototype.autoChangeDevice=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a=this;return S(this,(function(s){switch(s.label){case 0:return t!==e.TRTCDeviceType.TRTCDeviceTypeCamera||i!==e.TRTCDeviceState.TRTCDeviceStateRemove?[3,5]:(this.currentCameraId=r,Z(this.localStream)?[4,this.localStream.switchDevice(B.VIDEO,r)]:[3,2]);case 1:s.sent(),s.label=2;case 2:return Z(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.VIDEO,r)]:[3,4];case 3:s.sent(),s.label=4;case 4:this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),s.label=5;case 5:return t!==e.TRTCDeviceType.TRTCDeviceTypeMic?[3,10]:$(this.localStream)?[4,this.localStream.switchDevice(B.AUDIO,r)]:[3,7];case 6:s.sent(),s.label=7;case 7:return $(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.AUDIO,r)]:[3,9];case 8:s.sent(),s.label=9;case 9:this.currentMicId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),s.label=10;case 10:return t!==e.TRTCDeviceType.TRTCDeviceTypeSpeaker?[3,13]:this.remoteStreamMap.size>0?(o=this.getRemoteStreamList(),[4,Promise.all(o.map((function(e){return v(a,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return[4,e.setAudioOutput(r)];case 1:return[2,t.sent()]}}))}))})))]):[3,12];case 11:s.sent(),s.label=12;case 12:this.currentSpeakerId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),s.label=13;case 13:return[2]}}))}))},i.prototype.getRemoteStreamList=function(){var e=[];return this.remoteStreamMap.size>0&&Array.from(this.remoteStreamMap,(function(e){return e[1]})).forEach((function(t){t&&e.push(t)})),e},i.prototype.getDefaultDeviceInfo=function(e){var t=new y;if(0===e.length)return t;var i=e.filter((function(e){return"default"===e.deviceId}));if(i.length>0){var r=i[0].groupId;t=e.filter((function(e){return e.groupId===r})).filter((function(e){return e.deviceId!==B.DEFAULT}))[0]}else t=e[0];return t},i.prototype.getResolution=function(t){var i=(e.TRTCVideoResolution[t]||"").split("_");return{width:i.length>1&&i[1],height:i.length>2&&i[2]}},i.prototype.getStreamType=function(e){if(!e)return"";var t=e.getUserId(),i=e&&e.getType();return this.isSharedStream(t)&&i===B.MAIN&&(i=B.AUXILIARY),i},i.prototype.isSharedStream=function(e){return e.slice(0,6)===B.SCREEN_SHARE_USER_ID_PREFIX},i.prototype.generateLocalPlayStream=function(t,i){return v(this,void 0,void 0,(function(){var r,o,a,s,n;return S(this,(function(c){switch(c.label){case 0:return r=t.audio,o=t.video,this.localPlayStream&&this.localPlayStream.hasVideo()&&o||this.localPlayStream&&this.localPlayStream.hasAudio()&&r?[2]:((a=this.TRTC.createStream(t)).setAudioProfile(H[i||e.TRTCAudioQuality.TRTCAudioQualityDefault]),this.videoEncodeParam?[4,a.setVideoProfile(this.videoEncodeParam)]:[3,2]);case 1:c.sent(),c.label=2;case 2:return[4,a.initialize()];case 3:return c.sent(),r?(s=a.getAudioTrack(),this.localPlayStream?this.localPlayStream.hasAudio()?[4,this.localPlayStream.replaceTrack(s)]:[3,5]:[3,8]):[3,9];case 4:return c.sent(),[3,7];case 5:return[4,this.localPlayStream.addTrack(s)];case 6:c.sent(),c.label=7;case 7:return[3,9];case 8:this.localPlayStream=a,c.label=9;case 9:return o?(n=a.getVideoTrack(),this.localPlayStream?this.localPlayStream.hasVideo()?[4,this.localPlayStream.replaceTrack(n)]:[3,11]:[3,14]):[3,15];case 10:return c.sent(),[3,13];case 11:return[4,this.localPlayStream.addTrack(n)];case 12:c.sent(),c.label=13;case 13:return[3,15];case 14:this.localPlayStream=a,c.label=15;case 15:return[2]}}))}))},i.prototype.stopLocalPlayStreamTrack=function(e){return v(this,void 0,void 0,(function(){var t,i;return S(this,(function(r){switch(r.label){case 0:return this.localPlayStream?e!==B.VIDEO?[3,5]:this.localPlayStream.hasAudio()?(t=this.localPlayStream.getVideoTrack())?[4,this.localPlayStream.removeTrack(t)]:[3,2]:[3,3]:[3,6];case 1:r.sent(),t.stop(),r.label=2;case 2:return[3,4];case 3:this.localPlayStream.stop(),this.localPlayStream.close(),this.localPlayStream=null,r.label=4;case 4:this.isStartedLocalPreview=!1,r.label=5;case 5:e===B.AUDIO&&(this.localPlayStream.hasVideo()?(i=this.localPlayStream.getAudioTrack())&&(this.muteLocalAudio(!0),i.stop()):(this.localPlayStream.stop(),this.localPlayStream.close(),this.localPlayStream=null),this.isStartedLocalAudio=!1),r.label=6;case 6:return[2]}}))}))},i}(Y(t.EventEmitter,ee,ue,he,de,me,Te,pe));e.Rect=Q,e.TRTCDeviceInfo=y,e.TRTCImageBuffer=O,e.TRTCLocalStatistics=D,e.TRTCNetworkQosParam=k,e.TRTCParams=g,e.TRTCPublishCDNParam=M,e.TRTCQualityInfo=w,e.TRTCRenderParams=V,e.TRTCScreenCaptureSourceInfo=N,e.TRTCStatistics=L,e.TRTCVideoEncParam=b,e.TRTCVolumeInfo=E,e.default=Se,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("events"),require("trtc-js-sdk")):"function"==typeof define&&define.amd?define(["exports","events","trtc-js-sdk"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).TRTC={},global.events,global.TRTC);
|
|
15
|
+
***************************************************************************** */function s(e,t){function i(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var n,c,l,u,h,d,m,T,p=function(){return p=Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++)for(var o in t=arguments[i])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},p.apply(this,arguments)};function v(e,t,i,r){return new(i||(i=Promise))((function(o,a){function s(e){try{c(r.next(e))}catch(t){a(t)}}function n(e){try{c(r.throw(e))}catch(t){a(t)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,n)}c((r=r.apply(e,t||[])).next())}))}function S(e,t){var i,r,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function n(a){return function(n){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(n){a=[6,n],r=0}finally{i=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,n])}}}e.TRTCVideoResolution=void 0,(n=e.TRTCVideoResolution||(e.TRTCVideoResolution={}))[n.TRTCVideoResolution_120_120=1]="TRTCVideoResolution_120_120",n[n.TRTCVideoResolution_160_160=3]="TRTCVideoResolution_160_160",n[n.TRTCVideoResolution_270_270=5]="TRTCVideoResolution_270_270",n[n.TRTCVideoResolution_480_480=7]="TRTCVideoResolution_480_480",n[n.TRTCVideoResolution_160_120=50]="TRTCVideoResolution_160_120",n[n.TRTCVideoResolution_240_180=52]="TRTCVideoResolution_240_180",n[n.TRTCVideoResolution_280_210=54]="TRTCVideoResolution_280_210",n[n.TRTCVideoResolution_320_240=56]="TRTCVideoResolution_320_240",n[n.TRTCVideoResolution_400_300=58]="TRTCVideoResolution_400_300",n[n.TRTCVideoResolution_480_360=60]="TRTCVideoResolution_480_360",n[n.TRTCVideoResolution_640_480=62]="TRTCVideoResolution_640_480",n[n.TRTCVideoResolution_960_720=64]="TRTCVideoResolution_960_720",n[n.TRTCVideoResolution_160_90=100]="TRTCVideoResolution_160_90",n[n.TRTCVideoResolution_256_144=102]="TRTCVideoResolution_256_144",n[n.TRTCVideoResolution_320_180=104]="TRTCVideoResolution_320_180",n[n.TRTCVideoResolution_480_270=106]="TRTCVideoResolution_480_270",n[n.TRTCVideoResolution_640_360=108]="TRTCVideoResolution_640_360",n[n.TRTCVideoResolution_960_540=110]="TRTCVideoResolution_960_540",n[n.TRTCVideoResolution_1280_720=112]="TRTCVideoResolution_1280_720",n[n.TRTCVideoResolution_1920_1080=114]="TRTCVideoResolution_1920_1080",e.TRTCVideoStreamType=void 0,(c=e.TRTCVideoStreamType||(e.TRTCVideoStreamType={}))[c.TRTCVideoStreamTypeBig=0]="TRTCVideoStreamTypeBig",c[c.TRTCVideoStreamTypeSmall=1]="TRTCVideoStreamTypeSmall",c[c.TRTCVideoStreamTypeSub=2]="TRTCVideoStreamTypeSub",e.TRTCVideoFillMode=void 0,(l=e.TRTCVideoFillMode||(e.TRTCVideoFillMode={}))[l.TRTCVideoFillMode_Fill=0]="TRTCVideoFillMode_Fill",l[l.TRTCVideoFillMode_Fit=1]="TRTCVideoFillMode_Fit",e.TRTCVideoMirrorType=void 0,(u=e.TRTCVideoMirrorType||(e.TRTCVideoMirrorType={}))[u.TRTCVideoMirrorType_Auto=0]="TRTCVideoMirrorType_Auto",u[u.TRTCVideoMirrorType_Enable=1]="TRTCVideoMirrorType_Enable",u[u.TRTCVideoMirrorType_Disable=2]="TRTCVideoMirrorType_Disable",e.TRTCBeautyStyle=void 0,(h=e.TRTCBeautyStyle||(e.TRTCBeautyStyle={}))[h.TRTCBeautyStyleSmooth=0]="TRTCBeautyStyleSmooth",h[h.TRTCBeautyStyleNature=1]="TRTCBeautyStyleNature",e.TRTCAppScene=void 0,(d=e.TRTCAppScene||(e.TRTCAppScene={}))[d.TRTCAppSceneVideoCall=0]="TRTCAppSceneVideoCall",d[d.TRTCAppSceneLIVE=1]="TRTCAppSceneLIVE",d[d.TRTCAppSceneAudioCall=2]="TRTCAppSceneAudioCall",d[d.TRTCAppSceneVoiceChatRoom=3]="TRTCAppSceneVoiceChatRoom",e.TRTCRoleType=void 0,(m=e.TRTCRoleType||(e.TRTCRoleType={}))[m.TRTCRoleAnchor=20]="TRTCRoleAnchor",m[m.TRTCRoleAudience=21]="TRTCRoleAudience",e.TRTCAudioQuality=void 0,(T=e.TRTCAudioQuality||(e.TRTCAudioQuality={}))[T.TRTCAudioQualityDefault=0]="TRTCAudioQualityDefault",T[T.TRTCAudioQualitySpeech=1]="TRTCAudioQualitySpeech",T[T.TRTCAudioQualityMusic=3]="TRTCAudioQualityMusic";var R,f,y=function(e,t,i,r,o){void 0===e&&(e=""),void 0===t&&(t=""),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=""),this.deviceId=e,this.deviceName=t,this.kind=i,this.label=r,this.groupId=o};e.TRTCDeviceState=void 0,(R=e.TRTCDeviceState||(e.TRTCDeviceState={}))[R.TRTCDeviceStateAdd=0]="TRTCDeviceStateAdd",R[R.TRTCDeviceStateRemove=1]="TRTCDeviceStateRemove",R[R.TRTCDeviceStateActive=2]="TRTCDeviceStateActive",e.TRTCDeviceType=void 0,(f=e.TRTCDeviceType||(e.TRTCDeviceType={}))[f.TRTCDeviceTypeUnknow=-1]="TRTCDeviceTypeUnknow",f[f.TRTCDeviceTypeMic=0]="TRTCDeviceTypeMic",f[f.TRTCDeviceTypeSpeaker=1]="TRTCDeviceTypeSpeaker",f[f.TRTCDeviceTypeCamera=2]="TRTCDeviceTypeCamera";var C,b=function(t,i,r,o,a,s,n,c,l,u,h){void 0===t&&(t=0),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=0),void 0===a&&(a=""),void 0===s&&(s=e.TRTCRoleType.TRTCRoleAnchor),void 0===n&&(n=null),void 0===l&&(l=null),void 0===u&&(u=null),void 0===h&&(h=30),this.sdkAppId=t,this.userId=i,this.userSig=r,this.roomId=o,this.strRoomId=a,this.role=s,this.privateMapKey=n,this.streamId=l,this.userDefineRecordId=u,this.frameWorkType=h},g=function(t,i,r){void 0===t&&(t=e.TRTCVideoResolution.TRTCVideoResolution_640_360),void 0===i&&(i=15),void 0===r&&(r=550),this.videoResolution=t,this.videoFps=i,this.videoBitrate=r};e.TRTCVideoRotation=void 0,(C=e.TRTCVideoRotation||(e.TRTCVideoRotation={}))[C.TRTCVideoRotation0=0]="TRTCVideoRotation0",C[C.TRTCVideoRotation90=1]="TRTCVideoRotation90",C[C.TRTCVideoRotation180=2]="TRTCVideoRotation180",C[C.TRTCVideoRotation270=3]="TRTCVideoRotation270";var A,V=function(t,i,r){void 0===t&&(t=e.TRTCVideoRotation.TRTCVideoRotation0),void 0===i&&(i=e.TRTCVideoFillMode.TRTCVideoFillMode_Fit),void 0===r&&(r=e.TRTCVideoMirrorType.TRTCVideoMirrorType_Disable),this.rotation=t,this.fillMode=i,this.mirrorType=r};e.TRTCQuality=void 0,(A=e.TRTCQuality||(e.TRTCQuality={}))[A.TRTCQuality_Unknown=0]="TRTCQuality_Unknown",A[A.TRTCQuality_Excellent=1]="TRTCQuality_Excellent",A[A.TRTCQuality_Good=2]="TRTCQuality_Good",A[A.TRTCQuality_Poor=3]="TRTCQuality_Poor",A[A.TRTCQuality_Bad=4]="TRTCQuality_Bad",A[A.TRTCQuality_Vbad=5]="TRTCQuality_Vbad",A[A.TRTCQuality_Down=6]="TRTCQuality_Down";var _,P,I,w=function(t,i){void 0===t&&(t=""),void 0===i&&(i=e.TRTCQuality.TRTCQuality_Unknown),this.userId=t,this.quality=i},E=function(e,t){void 0===e&&(e=""),void 0===t&&(t=0),this.userId=e,this.volume=t},M=function(e,t,i){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=null),this.appId=e,this.bizId=t,this.url=i},D=function(t,i,r,o,a,s,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=0),void 0===a&&(a=0),void 0===s&&(s=0),void 0===n&&(n=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig),this.width=t,this.height=i,this.frameRate=r,this.videoBitrate=o,this.audioSampleRate=a,this.audioBitrate=s,this.streamType=n},L=function(e,t,i,r,o,a,s,n,c,l){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=0),void 0===a&&(a=0),void 0===s&&(s=0),void 0===n&&(n=[]),void 0===c&&(c=0),void 0===l&&(l=0),this.upLoss=e,this.downLoss=t,this.appCpu=i,this.systemCpu=r,this.rtt=o,this.receivedBytes=a,this.sentBytes=s,this.localStatisticsArray=n,this.localStatisticsArraySize=c,this.remoteStatisticsArraySize=l};e.TRTCVideoResolutionMode=void 0,(_=e.TRTCVideoResolutionMode||(e.TRTCVideoResolutionMode={}))[_.TRTCVideoResolutionModeLandscape=0]="TRTCVideoResolutionModeLandscape",_[_.TRTCVideoResolutionModePortrait=1]="TRTCVideoResolutionModePortrait",e.TRTCVideoQosPreference=void 0,(P=e.TRTCVideoQosPreference||(e.TRTCVideoQosPreference={}))[P.TRTCVideoQosPreferenceSmooth=1]="TRTCVideoQosPreferenceSmooth",P[P.TRTCVideoQosPreferenceClear=2]="TRTCVideoQosPreferenceClear",e.TRTCQosControlMode=void 0,(I=e.TRTCQosControlMode||(e.TRTCQosControlMode={}))[I.TRTCQosControlModeClient=0]="TRTCQosControlModeClient",I[I.TRTCQosControlModeServer=1]="TRTCQosControlModeServer";var k,U=function(t,i){void 0===t&&(t=e.TRTCVideoQosPreference.TRTCVideoQosPreferenceClear),void 0===i&&(i=e.TRTCQosControlMode.TRTCQosControlModeServer),this.preference=t,this.controlMode=i},O=function(e,t,i,r){void 0===e&&(e=new ArrayBuffer(0)),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),this.buffer=e,this.length=t,this.width=i,this.height=r};e.TRTCScreenCaptureSourceType=void 0,(k=e.TRTCScreenCaptureSourceType||(e.TRTCScreenCaptureSourceType={}))[k.TRTCScreenCaptureSourceTypeUnknown=-1]="TRTCScreenCaptureSourceTypeUnknown",k[k.TRTCScreenCaptureSourceTypeWindow=0]="TRTCScreenCaptureSourceTypeWindow",k[k.TRTCScreenCaptureSourceTypeScreen=1]="TRTCScreenCaptureSourceTypeScreen",k[k.TRTCScreenCaptureSourceTypeCustom=2]="TRTCScreenCaptureSourceTypeCustom";var F,N=function(t,i,r,o,a,s){void 0===t&&(t=e.TRTCScreenCaptureSourceType.TRTCScreenCaptureSourceTypeUnknown),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=new O),void 0===a&&(a=new O),void 0===s&&(s=!1),this.type=t,this.sourceId=i,this.sourceName=r,this.thumbBGRA=o,this.iconBGRA=a,this.isMinimizeWindow=s},Q=function(e,t,i,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),this.left=e,this.top=t,this.right=i,this.bottom=r},B={DEFAULT:"default",VIDEO:"video",AUDIO:"audio",ON_ERROR:"onError",MAIN:"main",RTC:"rtc",LIVE:"live",ANCHOR:"anchor",AUDIENCE:"audience",AUDIO_STANDARD:"standard",AUDIO_HIGH:"high",AUDIO_STANDARD_STEREO:"standard_stereo",AUDIO_HIGH_STEREO:"high_stereo",SMALL:"small",BIG:"big",AUXILIARY:"auxiliary",SCREEN_SHARE_USER_ID_PREFIX:"share_",NUMBER:"number",STRING:"string"},x={20:B.ANCHOR,21:B.AUDIENCE},J={0:B.RTC,1:B.LIVE,2:B.RTC,3:B.LIVE},H={0:B.AUDIO_STANDARD,1:B.AUDIO_HIGH,2:B.AUDIO_STANDARD_STEREO,3:B.AUDIO_HIGH_STEREO},j={0:B.BIG,1:B.SMALL,2:B.AUXILIARY};function z(){return Math.floor(performance.now())}!function(e){e[e.ActiveExitRoom=0]="ActiveExitRoom",e[e.KickedExitRoom=1]="KickedExitRoom"}(F||(F={}));var W=function(e){return void 0===e};function X(e){return"".concat(e,"-").concat(B.MAIN)}function G(e){return"".concat(e,"-").concat(B.AUXILIARY)}function Y(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var i=function(){for(var t=0,i=e;t<i.length;t++)K(this,new(0,i[t])(this))},r=i.prototype,o=0,a=e;o<a.length;o++){var s=a[o];K(i,s),K(r,s.prototype)}return i}function K(e,t){for(var i=0,r=Reflect.ownKeys(t);i<r.length;i++){var o=r[i];if("constructor"!==o&&"prototype"!==o&&"name"!==o){var a=Object.getOwnPropertyDescriptor(t,o)||"";Object.defineProperty(e,o,a)}}}function q(e,t){return void 0===e&&(e=""),t==="share_".concat(e)}function Z(e){return e&&null!==e.getVideoTrack()}function $(e){return e&&null!==e.getAudioTrack()}var ee=function(t){function i(){var i=t.call(this)||this;return i.startJoinTimestamp=0,i.joinedTimestamp=0,i.playViewMap=new Map,i.cameraList=[],i.micList=[],i.speakerList=[],i.currentCameraId="",i.currentMicId="",i.currentSpeakerId="",i.isJoining=!1,i.isJoined=!1,i.isExiting=!1,i.isPublishing=!1,i.isPublished=!1,i.isSubscribed=!1,i.userId="",i.userSig="",i.roomId=0,i.strRoomId="",i.useStringRoomId=!1,i.realRoomId=0,i.mode=B.RTC,i.role=B.ANCHOR,i.privateMapKey="255",i.streamId="",i.isSmallStreamSupported=!1,i.isStaringLocalPreview=!1,i.isStartedLocalPreview=!1,i.isStaringLocalAudio=!1,i.isStartedLocalAudio=!1,i.isVideoMute_=!1,i.isAudioMute_=!1,i.shareUserId="",i.shareUserSig="",i.isSharing_=!1,i.isShareClientJoined=!1,i.isShareStreamPublished_=!1,i.isShareClientLeaving=!1,i.defaultShareWidth_=1920,i.defaultShareHeight_=1080,i.defaultShareFrameRate_=15,i.defaultShareBitrate_=1500,i.defaultVideoWidth=640,i.defaultVideoHeight=480,i.defaultVideoFps=15,i.defaultVideoBitRate=900,i.prevLocalVideoStats={bytesSent:0,packetsSent:0,framesEncoded:0,framesSent:0,frameWidth:0,frameHeight:0},i.beautyDefaultBeauty=.5,i.beautyDefaultBrightness=.5,i.beautyDefaultRuddy=.5,i.TRTC=o.default,i.audioQuality=e.TRTCAudioQuality.TRTCAudioQualityDefault,i.priorRemoteVideoStreamType=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig,i.remoteStreamMap=new Map,i.isSmallStreamSupported=o.default&&o.default.isSmallStreamSupported()||!1,i.videoEncodeParam={width:i.defaultVideoWidth,height:i.defaultVideoHeight,frameRate:i.defaultVideoFps,bitrate:i.defaultVideoBitRate},i.screenShareParams_={width:i.defaultShareWidth_,height:i.defaultShareHeight_,frameRate:i.defaultShareFrameRate_,bitrate:i.defaultShareBitrate_},i}return s(i,t),i.prototype.promiseRetry=function(e){var t=this,i=e.retryFunction,r=e.settings,o=e.onError,a=e.onRetrying,s=e.context;return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var c=r.retries||5,l=0,u=-1,h=0,d=function(n,m){return v(t,void 0,void 0,(function(){var t,T,p,v,R;return S(this,(function(S){switch(S.label){case 0:return S.trys.push([0,2,,3]),t=s||this,[4,i.apply(t,e)];case 1:return T=S.sent(),l=0,n(T),[3,3];case 2:return p=S.sent(),v=function(){clearTimeout(u),l=0,h=2,m(p)},R=function(){2!==h&&l<c?(l++,h=1,a&&a(l,v),u=window.setTimeout((function(){u=-1,d(n,m)}),void 0===r.timeout?1e3:r.timeout)):v()},o?o(p,R,m):R(),[3,3];case 3:return[2]}}))}))};return new Promise(d)}},i}(t.EventEmitter),te=-1e3,ie={code:-1001,message:"参数错误, 请检查参数格式、是否非空等"},re={code:-1002,message:"进房失败:进房中或已进房"},oe={code:-1003,message:"退房失败:未进房或退房中"},ae={code:-1004,message:"调用该函数所需要条件不满足"},se={code:-1005,message:"not supported"},ne={code:-1006,message:"not supported before join room"},ce={code:-1007,message:"进房 userId 不能包含前缀 share_"},le={code:-1009,message:"不支持小流推屏幕分享"},ue=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t.prototype.startPublishing=function(e,t){return v(this,void 0,void 0,(function(){var t,i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.isPublished?this.client?(t={streamId:e},[4,this.client.startPublishCDNStream(t)]):(this.log_.error("(startPublishing) failed - ".concat(this.client)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - client = ").concat(this.client)}),[2]):(this.log_.error("(startPublishing) failed - ".concat(this.isPublished)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - isPublished = ").concat(this.isPublished)}),[2]);case 1:return r.sent(),[3,3];case 2:return i=r.sent(),this.callFunctionErrorManage(i,"startPublishing"),[3,3];case 3:return[2]}}))}))},t.prototype.stopPublishing=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),this.client?[4,this.client.stopPublishCDNStream()]:(this.log_.error("(stopPublishing) failed - ".concat(this.client)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - client = ").concat(this.client)}),[2]);case 1:return t.sent(),[3,3];case 2:return e=t.sent(),this.callFunctionErrorManage(e,"stopPublishing"),[3,3];case 3:return[2]}}))}))},t.prototype.startPublishCDNStream=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o,a;return S(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=e.appId,i=e.bizId,r=e.url,t&&i&&r?(o={appId:t,bizId:i,url:r},[4,this.client.startPublishCDNStream(o)]):[3,2];case 1:return s.sent(),[3,3];case 2:this.log_.error("(startPublishCDNStream) failed - ".concat(JSON.stringify(e))),this.emitError(ie),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),this.callFunctionErrorManage(a,"startPublishCDNStream"),[3,5];case 5:return[2]}}))}))},t.prototype.stopPublishCDNStream=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),this.client?[4,this.client.stopPublishCDNStream()]:(this.log_.error("(stopPublishCDNStream) failed - ".concat(this.client)),this.emitError({conditionsError:ae,message:"".concat(ae.message," - client = ").concat(this.client)}),[2]);case 1:return t.sent(),[3,3];case 2:return e=t.sent(),this.callFunctionErrorManage(e,"stopPublishCDNStream"),[3,3];case 3:return[2]}}))}))},t}(Y(ee)),he=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.startLocalPreview=function(t){return v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:this.log_.info("(startLocalPreview) start - start local preview",t,this.localStream),r.label=1;case 1:return r.trys.push([1,3,,4]),this.localStreamHasVideoOrAudio(B.VIDEO)?(this.playStream(this.localStream,t),[2]):[4,this.promiseRetry({retryFunction:this.doStartLocalPreview,settings:{retries:6,timeout:1e3}})(t)];case 2:return r.sent(),this.handleOnFirstVideoFrame("",e.TRTCVideoStreamType.TRTCVideoStreamTypeBig,t),[3,4];case 3:return i=r.sent(),this.isStaringLocalPreview=!1,this.callFunctionErrorManage(i,"startLocalPreview"),[3,4];case 4:return[2]}}))}))},i.prototype.doStartLocalPreview=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:if(this.isStaringLocalAudio)throw new Error("startLocalAudio is under implementation.");return this.isStaringLocalPreview=!0,W(e)?[3,16]:null===e?[3,15]:(t={userId:this.client&&"".concat(this.client.getUserId()," video")||"video undefined",video:!0,audio:!1,screenAudio:!1},this.currentCameraId&&(t.cameraId=this.currentCameraId),[4,this.generateLocalPlayStream(t)]);case 1:return o.sent(),this.localPlayStream&&(this.playStream(this.localPlayStream,e,this.localStreamRenderParams),this.clearTempAudioContainer("localAudio")),i=this.TRTC.createStream(t),this.videoEncodeParam?[4,i.setVideoProfile(this.videoEncodeParam)]:[3,3];case 2:o.sent(),o.label=3;case 3:return[4,i.initialize()];case 4:if(o.sent(),r=i.getVideoTrack(),!this.localStream)return[3,12];o.label=5;case 5:return o.trys.push([5,,10,11]),this.localStream.getVideoTrack()?[4,this.localStream.replaceTrack(r)]:[3,7];case 6:return o.sent(),[3,9];case 7:return[4,this.localStream.addTrack(r)];case 8:o.sent(),o.label=9;case 9:return[3,11];case 10:return i.close(),[7];case 11:return[3,13];case 12:this.localStream=i,o.label=13;case 13:return this.isStartedLocalPreview=!0,[4,this.publishLocalStream()];case 14:o.sent(),this.muteLocalVideo(this.isVideoMute_),this.isStaringLocalPreview=!1,o.label=15;case 15:return[3,17];case 16:this.emitError(ie),this.log_.error("(startLocalPreview) failed - ".concat(ie.message,": ").concat(e)),o.label=17;case 17:return[2]}}))}))},i.prototype.stopLocalPreview=function(){return v(this,void 0,void 0,(function(){var e=this;return S(this,(function(t){return this.log_.info("(stopLocalPreview) stop - stop local preview"),this.isStartedLocalPreview?[2,new Promise((function(t,i){return v(e,void 0,void 0,(function(){var e,r;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),[4,this.stopLocalPlayStreamTrack(B.VIDEO)];case 1:return o.sent(),this.localStream?this.localStream.getAudioTrack()?((e=this.localStream.getVideoTrack())&&this.localStream.removeTrack(e).then((function(){e.stop(),t(1)})),[3,4]):[3,2]:[3,4];case 2:return[4,this.unPublishStream()];case 3:o.sent(),this.localStream.stop(),this.localStream.close(),this.localStream=null,t(1),o.label=4;case 4:return[3,6];case 5:return r=o.sent(),this.callFunctionErrorManage(r,"stopLocalPreview"),i(r),[3,6];case 6:return[2]}}))}))}))]:(this.log_.info("(stopLocalPreview) stop - local preview has not been started"),[2])}))}))},i.prototype.muteLocalVideo=function(e){void 0===e&&(e=!1),this.isVideoMute_=e;try{this.localStream&&(e?this.localStream.muteVideo():this.localStream.unmuteVideo())}catch(t){this.callFunctionErrorManage(t,"muteLocalVideo")}},i.prototype.startRemoteView=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:return l.trys.push([0,7,,8]),t&&!W(i)&&r in e.TRTCVideoStreamType?(o=r,a=X(t),r===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?(a=G("".concat(B.SCREEN_SHARE_USER_ID_PREFIX).concat(t)),this.remoteStreamMap.has(a)||(a=G(t)),o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig):this.isSmallStreamSupported||(o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig),s=j[o],this.remoteStreamMap.has(a)?(n=this.remoteStreamMap.get(a),s===B.AUXILIARY?[3,3]:this.client?[4,this.client.setRemoteVideoStreamType(n,o)]:[3,2]):[3,6]):(this.emitError(ie),this.log_.error("(startRemoteView) failed - ".concat(ie.message,": ").concat(i)),[2]);case 1:l.sent(),l.label=2;case 2:l.label=3;case 3:return n?[4,this.client.subscribe(n,{audio:!0,video:!0})]:[3,6];case 4:return l.sent(),[4,this.playStream(n,i)];case 5:l.sent(),this.handleOnFirstVideoFrame(t,r,i),this.clearTempAudioContainer("".concat(a,"_dom")),l.label=6;case 6:return[3,8];case 7:return c=l.sent(),this.callFunctionErrorManage(c,"startRemoteView"),[3,8];case 8:return[2]}}))}))},i.prototype.stopRemoteView=function(t,i){return v(this,void 0,void 0,(function(){var r,o,a,s;return S(this,(function(n){switch(n.label){case 0:return n.trys.push([0,4,,5]),r=X(t),o=i,W(i)||(o=this.priorRemoteVideoStreamType),console.log("stopRemoteView streamType: ",o),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(r=G("".concat(B.SCREEN_SHARE_USER_ID_PREFIX).concat(t)),this.remoteStreamMap.has(r)||(r=G(t))),this.remoteStreamMap.has(r)?(a=this.remoteStreamMap.get(r),i!==e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?[3,1]:[3,3]):[3,3];case 1:return[4,this.client.subscribe(a,{audio:!0,video:!1})];case 2:n.sent(),n.label=3;case 3:return[3,5];case 4:return s=n.sent(),this.callFunctionErrorManage(s,"stopRemoteView"),[3,5];case 5:return[2]}}))}))},i.prototype.muteRemoteVideoStream=function(e,t){void 0===t&&(t=!1);try{if(!e)return this.emitError(ie),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(ie.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(X(e));i&&(t?i.muteVideo():i.unmuteVideo())}catch(r){this.callFunctionErrorManage(r,"stopRemoteView")}},i.prototype.setVideoEncoderParam=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),t=this.videoEncodeParam,e.videoResolution&&(i=this.getResolution(e.videoResolution),t.width=i.width,t.height=i.height),e.videoFps&&(t.frameRate=e.videoFps),e.videoBitrate&&(t.bitrate=e.videoBitrate),this.videoEncodeParam=t,[4,this.setStreamVideoParam(this.videoEncodeParam)];case 1:return o.sent(),[3,3];case 2:return r=o.sent(),this.callFunctionErrorManage(r,"setVideoEncoderParam"),[3,3];case 3:return[2]}}))}))},i.prototype.setLocalRenderParams=function(t){return v(this,void 0,void 0,(function(){var i,r,o,a;return S(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),i={},t.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Enable&&(i.mirror=!0),t.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Disable&&(i.mirror=!1),t.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fill&&(i.objectFit="cover"),t.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fit&&(i.objectFit="contain"),this.localStreamRenderParams=i,this.localStream?(r=this.playViewMap.get("".concat(this.localPlayStream.getUserId(),"-").concat(this.localPlayStream.getType())),[4,this.playStream(this.localPlayStream,r,i)]):[3,2];case 1:s.sent(),s.label=2;case 2:return this.testCameraStream&&(o=this.playViewMap.get("".concat(this.testCameraStream.getUserId(),"-").concat(this.testCameraStream.getType())),this.playStream(this.testCameraStream,o,i)),[3,4];case 3:return a=s.sent(),this.callFunctionErrorManage(a,"setLocalRenderParams"),[3,4];case 4:return[2]}}))}))},i.prototype.setRemoteRenderParams=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),o={},r.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Enable&&(o.mirror=!0),r.mirrorType===e.TRTCVideoMirrorType.TRTCVideoMirrorType_Disable&&(o.mirror=!1),r.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fill&&(o.objectFit="cover"),r.fillMode===e.TRTCVideoFillMode.TRTCVideoFillMode_Fit&&(o.objectFit="contain"),a=X(t),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(a=G(t)),s=this.playViewMap.get(a),(n=this.remoteStreamMap.get(a))?[4,this.playStream(n,s,o)]:[3,2];case 1:l.sent(),l.label=2;case 2:return[3,4];case 3:return c=l.sent(),this.callFunctionErrorManage(c,"setRemoteRenderParams"),[3,4];case 4:return[2]}}))}))},i.prototype.startCameraDeviceTest=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:return this.log_.info("(startCameraDeviceTest) start - start test camera Device",e),null===e?[3,2]:(t={userId:"test camera",video:!0,audio:!1,screenAudio:!1},this.currentCameraId&&(t.cameraId=this.currentCameraId),this.testCameraStream=this.TRTC.createStream(t),this.videoEncodeParam&&this.testCameraStream.setVideoProfile(this.videoEncodeParam),[4,this.testCameraStream.initialize()]);case 1:i.sent(),this.playStream(this.testCameraStream,e,this.localStreamRenderParams),i.label=2;case 2:return[2]}}))}))},i.prototype.stopCameraDeviceTest=function(){this.testCameraStream&&(this.testCameraStream.stop(),this.testCameraStream.close(),this.testCameraStream=null)},i}(Y(ee)),de=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.startLocalAudio=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:this.log_.info("(startLocalAudio) start - start local audio"),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.promiseRetry({retryFunction:this.doStartLocalAudio,settings:{retries:6,timeout:1e3}})(e)];case 2:return i.sent(),this.handleOnMicDidReady(),[3,4];case 3:return t=i.sent(),this.callFunctionErrorManage(t,"startLocalAudio"),[3,4];case 4:return[2]}}))}))},i.prototype.doStartLocalAudio=function(t){return v(this,void 0,void 0,(function(){var i,r,o,a,s,n;return S(this,(function(c){switch(c.label){case 0:if(this.isStaringLocalPreview)throw new Error("startLocalPreview is under implementation.");c.label=1;case 1:return c.trys.push([1,14,,15]),i=t,W(t)||(i=this.audioQuality),r={userId:this.client&&"".concat(this.client.getUserId()," audio")||"audio undefined",video:!1,audio:!0,screenAudio:!1},this.currentMicId&&(r.microphoneId=this.currentMicId),(o=this.TRTC.createStream(r)).setAudioProfile(H[i||e.TRTCAudioQuality.TRTCAudioQualityDefault]),[4,o.initialize()];case 2:return c.sent(),a=o.getAudioTrack(),[4,this.generateLocalPlayStream(r,t)];case 3:if(c.sent(),!this.localStream)return[3,11];c.label=4;case 4:return c.trys.push([4,,9,10]),this.localStream.getAudioTrack()?[4,this.localStream.replaceTrack(a)]:[3,6];case 5:return c.sent(),[3,8];case 6:return[4,this.localStream.addTrack(a)];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:return o.close(),[7];case 10:return[3,12];case 11:this.localStream=o,s=this.generateTempAudioContainer("localAudio"),this.localPlayStream&&this.localPlayStream.play(s),c.label=12;case 12:return this.isStaringLocalAudio||(n=this.generateTempAudioContainer("localPublishAudio"),this.localStream&&this.localStream.play(n)),this.isStartedLocalAudio=!0,[4,this.publishLocalStream()];case 13:return c.sent(),this.muteLocalAudio(this.isAudioMute_),this.isStaringLocalAudio=!1,this.isPublished||this.getLocalStreamAudioLevel(),[3,15];case 14:throw c.sent();case 15:return[2]}}))}))},i.prototype.getLocalStreamAudioLevel=function(){var e=this;this.enableAudioVolumeInterval&&(this.enableAudioVolumeTimer=setInterval((function(){var t=[],i=Math.floor(100*e.localStream.getAudioLevel());t.push({userId:"",volume:i}),e.emit("onUserVoiceVolume",t,t.length)}),this.enableAudioVolumeInterval))},i.prototype.generateTempAudioContainer=function(e){var t=document.createElement("div");return t.id=e,t.style.width="0",t.style.height="0",document.getElementsByTagName("body")[0].appendChild(t),t},i.prototype.clearTempAudioContainer=function(e){var t=document.getElementById(e);t&&document.getElementsByTagName("body")[0].removeChild(t)},i.prototype.stopLocalAudio=function(){return v(this,void 0,void 0,(function(){var e=this;return S(this,(function(t){return this.log_.info("(stopLocalAudio) stop - stop local audio"),this.isStartedLocalAudio?[2,new Promise((function(t,i){return v(e,void 0,void 0,(function(){var e,r,o;return S(this,(function(a){switch(a.label){case 0:return a.trys.push([0,5,,6]),[4,this.stopLocalPlayStreamTrack(B.AUDIO)];case 1:return a.sent(),this.localStream?(this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),e=this.localStream.getVideoTrack(),this.clearTempAudioContainer("localPublishAudio"),e?((r=this.localStream.getAudioTrack())&&(this.muteLocalAudio(!0),r.stop(),t(1)),[3,4]):[3,2]):[3,4];case 2:return[4,this.unPublishStream()];case 3:a.sent(),this.localStream.stop(),this.localStream.close(),this.clearTempAudioContainer("localAudio"),this.localStream=null,t(1),a.label=4;case 4:return[3,6];case 5:return o=a.sent(),this.callFunctionErrorManage(o,"stopLocalAudio"),i(o),[3,6];case 6:return[2]}}))}))}))]:(this.log_.info("(stopLocalAudio) stop - local audio has not been started"),[2])}))}))},i.prototype.muteLocalAudio=function(e){void 0===e&&(e=!1),this.isAudioMute_=e;try{this.localStream&&(e?(this.localStream.muteAudio(),this.localPlayStream.muteAudio()):(this.localStream.unmuteAudio(),this.localPlayStream.unmuteAudio()))}catch(t){this.callFunctionErrorManage(t,"muteLocalAudio")}},i.prototype.muteRemoteAudio=function(e,t){void 0===t&&(t=!1);try{if(!e)return this.emitError(ie),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(ie.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(X(e));i&&(t?i.muteAudio():i.unmuteAudio())}catch(r){this.callFunctionErrorManage(r,"muteRemoteAudio")}},i.prototype.muteAllRemoteAudio=function(e){try{this.remoteStreamMap.size>0&&Array.from(this.remoteStreamMap,(function(e){return e[1]})).forEach((function(t){t&&(e?t.muteAudio():t.unmuteAudio())}))}catch(t){this.callFunctionErrorManage(t,"muteAllRemoteAudio")}},i.prototype.setRemoteAudioVolume=function(e,t){try{if(!e||t<0)return this.emitError(ie),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(ie.message,": userId = ").concat(e,", volume = ").concat(t));var i=this.remoteStreamMap.get(X(e));if(i){var r=t>100?1:t/100;i.setAudioVolume(r)}}catch(o){this.callFunctionErrorManage(o,"setRemoteAudioVolume")}},i.prototype.getAudioCaptureVolume=function(){try{return this.localStream?100*this.localStream.getAudioLevel():(this.log_.warn("(getAudioCaptureVolume) failed - localStream = ".concat(this.localStream)),0)}catch(e){return this.callFunctionErrorManage(e,"getAudioCaptureVolume"),0}},i}(Y(ee)),me=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.getCameraDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return S(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.TRTC.getCameras()];case 1:return e=i.sent(),this.cameraList=e.map((function(e){return p(p({},e),{deviceName:e.label})})),[2,Promise.resolve(this.cameraList)];case 2:return t=i.sent(),this.callFunctionErrorManage(t,"getCameraDevicesList"),this.cameraList=[],[2,Promise.resolve([])];case 3:return[2]}}))}))},i.prototype.setCurrentCameraDevice=function(t){return v(this,void 0,Promise,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,7,,8]),t?this.currentCameraId===t?[2,Promise.resolve(!0)]:(this.currentCameraId=t||"",Z(this.localStream)?[4,this.localStream.switchDevice(B.VIDEO,t)]:[3,2]):[2,Promise.resolve(!1)];case 1:r.sent(),r.label=2;case 2:return Z(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.VIDEO,t)]:[3,4];case 3:r.sent(),r.label=4;case 4:return Z(this.testCameraStream)?[4,this.testCameraStream.switchDevice("video",t)]:[3,6];case 5:r.sent(),r.label=6;case 6:return this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeCamera,e.TRTCDeviceState.TRTCDeviceStateActive),[2,Promise.resolve(!0)];case 7:return i=r.sent(),this.callFunctionErrorManage(i,"setCurrentCameraDevice"),this.cameraList=[],[2,Promise.resolve(!1)];case 8:return[2]}}))}))},i.prototype.getCurrentCameraDevice=function(){var e=this;return(this.cameraList||[]).filter((function(t){return t.deviceId===e.currentCameraId}))[0]||{}},i}(Y(ee)),Te=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.getMicDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return S(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.TRTC.getMicrophones()];case 1:return e=i.sent(),this.micList=e.map((function(e){return p(p({},e),{deviceName:e.label})})),[2,Promise.resolve(this.micList)];case 2:return t=i.sent(),this.callFunctionErrorManage(t,"getMicDevicesList"),[2,Promise.resolve([])];case 3:return[2]}}))}))},i.prototype.getCurrentMicDevice=function(){var e=this;return this.currentMicId?(this.micList||[]).filter((function(t){return t.deviceId===e.currentMicId}))[0]||{}:new y},i.prototype.setCurrentMicDevice=function(t){return v(this,void 0,Promise,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,5,,6]),t?this.currentMicId===t?[2,Promise.resolve(!0)]:(this.currentMicId=t||"",$(this.localStream)?[4,this.localStream.switchDevice(B.AUDIO,t)]:[3,2]):[2,Promise.resolve(!1)];case 1:r.sent(),r.label=2;case 2:return $(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.AUDIO,t)]:[3,4];case 3:r.sent(),r.label=4;case 4:return this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeMic,e.TRTCDeviceState.TRTCDeviceStateActive),[2,Promise.resolve(!0)];case 5:return i=r.sent(),this.callFunctionErrorManage(i,"setCurrentMicDevice"),[2,Promise.resolve(!1)];case 6:return[2]}}))}))},i.prototype.getSpeakerDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return S(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.TRTC.getSpeakers()];case 1:return e=i.sent(),this.speakerList=e.map((function(e){return p(p({},e),{deviceName:e.label})})),[2,Promise.resolve(this.speakerList)];case 2:return t=i.sent(),this.callFunctionErrorManage(t,"getSpeakerDevicesList"),[2,Promise.resolve([])];case 3:return[2]}}))}))},i.prototype.getCurrentSpeakerDevice=function(){var e=this;return this.currentSpeakerId?(this.speakerList||[]).filter((function(t){return t.deviceId===e.currentSpeakerId}))[0]||{}:new y},i.prototype.setCurrentSpeakerDevice=function(e){return v(this,void 0,Promise,(function(){var t,i,r=this;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),e?(this.currentSpeakerId=e||"",this.remoteStreamMap.size>0?(t=this.getRemoteStreamList(),[4,Promise.all(t.map((function(e){return v(r,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return[4,e.setAudioOutput(this.currentSpeakerId)];case 1:return[2,t.sent()]}}))}))})))]):[3,2]):[2,Promise.resolve(!1)];case 1:o.sent(),o.label=2;case 2:return[2,Promise.resolve(!0)];case 3:return i=o.sent(),this.callFunctionErrorManage(i,"setCurrentSpeakerDevice"),[2,Promise.resolve(!1)];case 4:return[2]}}))}))},i}(Y(ee)),pe=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.startScreenCapture=function(){this.emitError(se)},i.prototype.pauseScreenCapture=function(){this.emitError(se)},i.prototype.resumeScreenCapture=function(){this.emitError(se)},i.prototype.getScreenCaptureSources=function(){this.emitError(se)},i.prototype.selectScreenCaptureTarget=function(){this.emitError(se)},i.prototype.startScreenShare=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c,l,u,h,d;return S(this,(function(m){switch(m.label){case 0:if(!this.isJoined||this.isJoining)return this.emitError(ne),[2];if(i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSmall)return this.emitError(le),[2];o=i||e.TRTCVideoStreamType.TRTCVideoStreamTypeSub,s=(a=r||{}).videoResolution,n=a.videoFps,c=a.videoBitrate,l=a.screenAudio,u=void 0!==l&&l,s&&(h=this.getResolution(s),this.screenShareParams_.width=h.width,this.screenShareParams_.height=h.height),n&&(this.screenShareParams_.frameRate=n),c&&(this.screenShareParams_.bitrate=c),m.label=1;case 1:return m.trys.push([1,4,,5]),[4,this.initShareStream_(!!u)];case 2:return m.sent(),[4,this.shareStreamPublish_(o)];case 3:return m.sent(),t&&this.shareStream_&&this.playStream(this.shareStream_,t),this.isSharing_=!0,[3,5];case 4:throw d=m.sent(),console.error("Start share screen error:",d),d;case 5:return[2]}}))}))},i.prototype.setSubStreamEncoderParam=function(e){var t=e.videoResolution,i=e.videoFps,r=e.videoBitrate;try{var o=this.getResolution(t);this.screenShareParams_={width:o.width,height:o.height,frameRate:i,bitrate:r}}catch(a){throw a}},i.prototype.stopScreenShare=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:if(!this.isShareStreamPublished_)return console.warn("ShareClient cannot unpublish() - you have not published yet"),[2];t.label=1;case 1:return t.trys.push([1,4,,5]),this.shareStream_?[4,this.client.unpublish(this.shareStream_)]:[3,3];case 2:t.sent(),this.shareStream_.close(),t.label=3;case 3:return this.isShareStreamPublished_=!1,this.shareStream_=null,this.isSharing_=!1,console.log("Unpublish ShareStream success"),[3,5];case 4:throw e=t.sent(),console.error("unpublish failed",e),e;case 5:return[2]}}))}))},i.prototype.initShareStream_=function(e){return v(this,void 0,void 0,(function(){var t,i=this;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.shareStream_=this.TRTC.createStream({audio:!1,screen:!0,userId:this.userId,screenAudio:e}),this.shareStream_.setScreenProfile(this.screenShareParams_),[4,this.shareStream_.initialize()];case 1:return r.sent(),this.shareStream_.on("screen-sharing-stopped",(function(){console.log("ShareStream video track ended"),i.emit("onWebScreenSharingStopped"),i.stopScreenShare()})),[2,this.shareStream_];case 2:throw t=r.sent(),console.error("ShareStream failed to initialize. Error: ".concat(t)),t;case 3:return[2]}}))}))},i.prototype.shareStreamPublish_=function(t){return v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:if(this.isShareStreamPublished_)return console.warn("ShareClient duplicate publish() observed"),[2];r.label=1;case 1:return r.trys.push([1,6,,7]),t!==e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?[3,3]:[4,this.client.publish(this.shareStream_,{isAuxiliary:!0})];case 2:return r.sent(),[3,5];case 3:return[4,this.client.publish(this.shareStream_)];case 4:r.sent(),r.label=5;case 5:return console.log("ShareStream is published successfully"),this.isShareStreamPublished_=!0,[3,7];case 6:throw i=r.sent(),console.error("ShareStream is failed to publish. Error: ".concat(i)),i;case 7:return[2]}}))}))},i}(Y(ee)),ve=null,Se=function(t){function i(){var e,i,r,o=t.call(this)||this;return o.enableAudioVolumeInterval=0,o.enableAudioVolumeTimer=-1,o.frameWorkType=30,o.component=0,o.VERSION="1.0.8",o.log_=o.TRTC.Logger.loggerManager,o.handleError=o.handleError.bind(o),o.handlePeerJoin=o.handlePeerJoin.bind(o),o.handlePeerLeave=o.handlePeerLeave.bind(o),o.handleStreamAdded_=o.handleStreamAdded_.bind(o),o.handleStreamSubscribed=o.handleStreamSubscribed.bind(o),o.handleStreamRemoved_=o.handleStreamRemoved_.bind(o),o.handleStreamUpdated_=o.handleStreamUpdated_.bind(o),o.handleMuteAudio=o.handleMuteAudio.bind(o),o.handleUnmuteAudio=o.handleUnmuteAudio.bind(o),o.handleMuteVideo=o.handleMuteVideo.bind(o),o.handleUnmuteVideo=o.handleUnmuteVideo.bind(o),o.handleAudioVolume=o.handleAudioVolume.bind(o),o.handleNetworkQuality=o.handleNetworkQuality.bind(o),o.handleDeviceChange=o.handleDeviceChange.bind(o),navigator&&navigator.mediaDevices&&navigator.mediaDevices.addEventListener("devicechange",(e=o.handleDeviceChange,i=30,function(){for(var t=this,o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];r>0&&clearTimeout(r),r=window.setTimeout((function(){e.apply(t,o),r=-1}),i)})),o.TRTC.getMicrophones().then((function(e){o.micList=e||[]})).catch((function(e){o.log_.error("getMicrophones error observed ".concat(e))})),o.TRTC.getCameras().then((function(e){o.cameraList=e||[]})).catch((function(e){o.log_.error("getCameras error observed ".concat(e))})),o.TRTC.getSpeakers().then((function(e){o.speakerList=e||[]})).catch((function(e){o.log_.error("getSpeakers error observed ".concat(e))})),o}return s(i,t),i.getTRTCShareInstance=function(){return ve||(ve=new i),ve},i.destroyTRTCShareInstance=function(){ve&&(ve.destroy(),ve=null)},i.prototype.getSDKVersion=function(){return this.VERSION||""},i.prototype.off=function(e,t){void 0===t&&(t=function(){});try{"*"===e?this.removeAllListeners():this.removeListener(e,t)}catch(i){console.log("off error ",i)}},i.prototype.enterRoom=function(e,t){return v(this,void 0,void 0,(function(){var i,r,o,a,s,n,c,l,u,h,d,m,T,v;return S(this,(function(S){switch(S.label){case 0:if(i=e.sdkAppId,r=e.userId,o=e.userSig,a=e.roomId,s=e.strRoomId,n=e.role,c=e.privateMapKey,l=e.streamId,u=e.frameWorkType,h=e.component,d=void 0===h?0:h,!(i&&r&&o))return[3,6];if(this.sdkAppId=i,this.userId=r,this.userSig=o,this.roomId=a,this.strRoomId=s,this.useStringRoomId=Boolean(!a&&s),this.realRoomId=a||s,this.mode=J[t],this.role=x[n],this.remoteUserAvailable=new Map,u&&typeof u===B.NUMBER&&(this.frameWorkType=u),d&&typeof d===B.NUMBER&&(this.component=d),this.isSharedStream(r))return this.log_.error("(enterRoom) failed - ".concat(ce.message," userId: ").concat(this.userId)),this.emitError(ce),[2];if(this.isJoining||this.isJoined)return this.log_.error("(enterRoom) failed - ".concat(re.message," isJoining: ").concat(this.isJoining,", isJoined: ").concat(this.isJoined)),this.emitError(re),[2];S.label=1;case 1:return S.trys.push([1,4,,5]),this.isJoining=!0,m={sdkAppId:i,userId:r,userSig:o,mode:this.mode,useStringRoomId:this.useStringRoomId,frameWorkType:this.frameWorkType,component:this.component},m=c?p(p({},m),{privateMapKey:c}):m,m=l?p(p({},m),{streamId:l}):m,this.initClient(m),this.startJoinTimestamp=z(),[4,this.client.join({roomId:this.realRoomId,role:this.role})];case 2:return S.sent(),this.isJoined=!0,this.isJoining=!1,this.joinedTimestamp=z(),T=this.joinedTimestamp-this.startJoinTimestamp,this.emit("onEnterRoom",T),this.log_.info("(enterRoom) success - enter room"),[4,this.publishLocalStream()];case 3:return S.sent(),[3,5];case 4:return v=S.sent(),this.isJoining=!1,this.emit("onEnterRoom",-1),this.callFunctionErrorManage(v,"enterRoom"),[3,5];case 5:return[3,7];case 6:this.emitError(ie),this.log_.error("(enterRoom) failed - ".concat(ie.message,": ").concat(JSON.stringify(e))),S.label=7;case 7:return[2]}}))}))},i.prototype.exitRoom=function(){return v(this,void 0,void 0,(function(){var e;return S(this,(function(t){switch(t.label){case 0:this.log_.info("(exitRoom) exitRoom, isJoined: ".concat(this.isJoined,"; isPublished: ").concat(this.isPublished)),t.label=1;case 1:return t.trys.push([1,7,,8]),!this.isJoined||this.isExiting?(this.log_.error("(exitRoom) failed - ".concat(oe.message," isJoined: ").concat(this.isJoined," isExiting: ").concat(this.isExiting)),this.emitError(oe),[2]):(this.isExiting=!0,this.isSharing_?[4,this.stopScreenShare()]:[3,3]);case 2:t.sent(),t.label=3;case 3:return this.isPublished?[4,this.unPublishStream()]:[3,5];case 4:t.sent(),this.destroyLocalStream(),t.label=5;case 5:return this.emit("onExitRoom",F.ActiveExitRoom),[4,this.client.leave()];case 6:return t.sent(),this.resetStatus(),this.destroy(),this.log_.info("(exitRoom) success - exit room"),[3,8];case 7:return e=t.sent(),this.isExiting=!1,this.callFunctionErrorManage(e,"exitRoom"),[3,8];case 8:return[2]}}))}))},i.prototype.switchRole=function(t){return v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,8,,9]),this.mode===B.RTC?(this.log_.info("(publishLocalStream) failed - mode = ".concat(this.mode,", role = ").concat(t)),this.handleOnSwitchRole(-1,"(publishLocalStream) failed - mode = ".concat(this.mode,", role = ").concat(t)),[2]):this.client?t===e.TRTCRoleType.TRTCRoleAnchor||t===e.TRTCRoleType.TRTCRoleAudience?[3,1]:(this.handleOnSwitchRole(-1,"please pass valid role parameter, role = ".concat(t,", type = ").concat(typeof t)),[3,5]):[3,6];case 1:return[4,this.client.switchRole(x[t])];case 2:return r.sent(),this.role=x[t],this.isPublished=!1,t===e.TRTCRoleType.TRTCRoleAnchor&&this.localStream?[4,this.publishLocalStream()]:[3,4];case 3:r.sent(),r.label=4;case 4:this.handleOnSwitchRole(0,"switch role success, role = ".concat(t,", ").concat(x[t])),r.label=5;case 5:return[3,7];case 6:this.handleOnSwitchRole(-1,"switch role failed, client = ".concat(this.client)),r.label=7;case 7:return[3,9];case 8:return i=r.sent(),this.handleOnSwitchRole(-1,JSON.stringify(i)),[3,9];case 9:return[2]}}))}))},i.prototype.enableAudioVolumeEvaluation=function(e){this.client?this.client.enableAudioVolumeEvaluation(e):e<=0&&this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),this.enableAudioVolumeInterval=e},i.prototype.callFunctionErrorManage=function(e,t){e&&e.getCode&&e.getCode()?(this.emit(B.ON_ERROR,e.getCode(),e.message_),this.log_.error("(".concat(t,") failed - ").concat(e.message_))):(this.emit(B.ON_ERROR,te,e.message),this.log_.error("(".concat(t,") failed - ").concat(e.message)))},i.prototype.resetStatus=function(){this.isExiting=!1,this.isJoining=!1,this.isJoined=!1,this.isPublishing=!1,this.isPublished=!1,this.isSubscribed=!1,this.isVideoMute_=!1,this.isAudioMute_=!1,this._enableAudioVolumeTimer=-1,this.remoteStreamMap.clear(),this.videoEncodeParam={width:this.defaultVideoWidth,height:this.defaultVideoHeight,frameRate:this.defaultVideoFps,bitrate:this.defaultVideoBitRate},this.screenShareParams_={width:this.defaultShareWidth_,height:this.defaultShareHeight_,frameRate:this.defaultShareFrameRate_,bitrate:this.defaultShareBitrate_}},i.prototype.publishLocalStream=function(){return v(this,void 0,void 0,(function(){var e,t,i,r,o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:if(t=(e=this).mode,i=e.role,r=e.isJoined,o=e.isPublishing,a=e.isPublished,s=e.localStream,n=e.client,t===B.LIVE&&i===B.AUDIENCE)return this.log_.info("(publishLocalStream) failed - mode = ".concat(t,", role = ").concat(i)),[2];if(!r||o||a||!s||!n)return this.log_.info("(publishLocalStream) failed - isJoined = ".concat(r,",\n isPublishing = ").concat(o,", isPublished = ").concat(a,", localStream = ").concat(s,", client.userId = ").concat(n?n.getUserId():null)),[2];if(this.log_.info("(publishLocalStream) start - publish stream"),!r||a)return[3,6];this.isPublishing=!0,l.label=1;case 1:return l.trys.push([1,5,,6]),[4,this.setStreamVideoParam(this.videoEncodeParam)];case 2:return l.sent(),this.localStream?[4,this.client.publish(this.localStream)]:[3,4];case 3:l.sent(),this.isPublished=!0,this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),this.log_.info("(publishLocalStream) success - publish stream"),l.label=4;case 4:return this.isPublishing=!1,[3,6];case 5:return c=l.sent(),this.isPublishing=!1,this.callFunctionErrorManage(c,"publishLocalStream"),[3,6];case 6:return[2]}}))}))},i.prototype.unPublishStream=function(){return v(this,void 0,void 0,(function(){return S(this,(function(e){switch(e.label){case 0:return this.log_.info("(unPublishStream) unPublishStream",this.localStream),this.isPublished&&this.localStream?[4,this.client.unpublish(this.localStream)]:[3,2];case 1:e.sent(),this.isPublished=!1,e.label=2;case 2:return[2]}}))}))},i.prototype.setStreamVideoParam=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,6,,10]),this.localStream?(t=this.localStream.getVideoTrack())?[4,this.localStream.setVideoProfile(e)]:[2]:[3,2];case 1:return o.sent(),(t=this.localStream.getVideoTrack())&&(i=t.getSettings(),console.log("分辨率:".concat(i.width," * ").concat(i.height,", 帧率:").concat(i.frameRate))),[3,3];case 2:this.videoEncodeParam=e,o.label=3;case 3:return this.localPlayStream&&this.localPlayStream.hasVideo()?[4,this.localPlayStream.setVideoProfile(e)]:[3,5];case 4:o.sent(),o.label=5;case 5:return[3,10];case 6:return"OverconstrainedError"!==o.sent().name?[3,8]:(console.error("当前摄像头不支持该 profile"),[4,(r=this.TRTC.createStream({video:!0,audio:!1})).initialize()]);case 7:return o.sent(),this.localStream.replaceTrack(r.getVideoTrack()),[3,9];case 8:console.error("当前浏览器不支持动态调用该接口"),o.label=9;case 9:return[3,10];case 10:return[2]}}))}))},i.prototype.destroyLocalStream=function(){this.localStream&&(this.localStream.stop(),this.localStream&&this.localStream.close(),this.localStream=null)},i.prototype.destroy=function(){this.unbindEvents(),this.client&&(this.client=null)},i.prototype.initStream=function(e){return v(this,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.localStream=this.TRTC.createStream(e),this.videoEncodeParam&&this.localStream&&this.localStream.setVideoProfile(this.videoEncodeParam),[4,this.localStream.initialize()];case 1:return t.sent(),[2]}}))}))},i.prototype.localStreamHasVideoOrAudio=function(e){if(e&&"string"==typeof e||this.emitError(ie),!this.localStream)return!1;switch(e){case B.VIDEO:return!!this.localStream.getVideoTrack();case B.AUDIO:return!!this.localStream.getAudioTrack();default:return!1}},i.prototype.playStream=function(e,t,i){return v(this,void 0,void 0,(function(){var r,o,a;return S(this,(function(s){if(!t||!e)return this.log_.error("(playStream) failed - dom = ".concat(t,", stream = ").concat(e)),[2];if(!(r="string"==typeof t?document.getElementById(t):t))return this.log_.error("(playStream) failed - dom = ".concat(t,", stream = ").concat(e)),[2];try{e.play(r,i)}catch(n){}return o=e.getUserId(),o=this.isSharedStream(o)?o.slice(6):o,a=e.getType(),this.playViewMap.set("".concat(o,"-").concat(a),t),[2]}))}))},i.prototype.initClient=function(e){this.client=this.TRTC.createClient(e),this.enableAudioVolumeInterval&&this.client.enableAudioVolumeEvaluation(this.enableAudioVolumeInterval),this.bindEvents()},i.prototype.bindEvents=function(){var e=this;this.client.on("error",this.handleError),this.client.on("peer-join",this.handlePeerJoin),this.client.on("peer-leave",this.handlePeerLeave),this.client.on("stream-added",this.handleStreamAdded_),this.client.on("stream-subscribed",this.handleStreamSubscribed),this.client.on("stream-removed",this.handleStreamRemoved_),this.client.on("stream-updated",this.handleStreamUpdated_),this.client.on("mute-audio",this.handleMuteAudio),this.client.on("unmute-audio",this.handleUnmuteAudio),this.client.on("mute-video",this.handleMuteVideo),this.client.on("unmute-video",this.handleUnmuteVideo),this.client.on("client-banned",(function(t){e.log_.error("client has been banned for ".concat(t)),e.emit("onExitRoom",F.KickedExitRoom)})),this.client.on("audio-volume",this.handleAudioVolume),this.client.on("network-quality",this.handleNetworkQuality)},i.prototype.unbindEvents=function(){this.client&&this.client.off("*")},i.prototype.emitError=function(e){e&&this.emit&&this.emit(B.ON_ERROR,e.code,e.message)},i.prototype.handleError=function(e){this.log_.error("handle error observed ".concat(e)),this.emit(B.ON_ERROR,e.getCode(),e.message)},i.prototype.handleEnterRoom=function(){},i.prototype.handleExitRoom=function(){},i.prototype.handlePeerJoin=function(e){var t=e.userId;if(!this.isSharedStream(t)||!this.remoteUserAvailable.has(t)){var i=Array.from(this.remoteUserAvailable.keys())||[];this.remoteUserAvailable.set(t,{isAudioAvailable:!1,isVideoAvailable:!1}),q(this.userId,t)||(i.filter((function(e){return q(e,t)}))||[]).length>0||this.isSharedStream(t)||this.emit("onRemoteUserEnterRoom",t)}},i.prototype.handlePeerLeave=function(e){var t=e.userId,i=void 0===t?"":t;this.isSharedStream(i)||this.emit("onRemoteUserLeaveRoom",i,0)},i.prototype.handleOnUserAudioAvailable=function(e,t,i){return v(this,void 0,void 0,(function(){var r;return S(this,(function(o){switch(o.label){case 0:return this.remoteUserAvailable.get(e).isAudioAvailable=t,this.emit("onUserAudioAvailable",e,t?1:0),t?this.remoteStreamMap.get("".concat(e,"-").concat(i)).isPlaying()?[3,3]:(r=this.generateTempAudioContainer("".concat(e,"-").concat(i,"_dom")),[4,this.remoteStreamMap.get("".concat(e,"-").concat(i)).play(r)]):[3,4];case 1:return o.sent(),[4,this.remoteStreamMap.get("".concat(e,"-").concat(i)).setAudioOutput(this.currentSpeakerId)];case 2:o.sent(),o.label=3;case 3:return[3,5];case 4:this.clearTempAudioContainer("".concat(e,"-").concat(i,"_dom")),o.label=5;case 5:return[2]}}))}))},i.prototype.handleOnUserVideoAvailable=function(e,t){this.remoteUserAvailable.get(e).isVideoAvailable=t,this.emit("onUserVideoAvailable",e,t?1:0)},i.prototype.handleOnUserSubStreamAvailable=function(e,t){try{this.remoteUserAvailable.get(e).isVideoAvailable=t;var i=e;if(this.isSharedStream(e)&&(i=e.slice(6))===this.userId)return;this.emit("onUserSubStreamAvailable",i,t?1:0)}catch(r){this.emitError(ie)}},i.prototype.handleOnSwitchRole=function(e,t){this.emit("onSwitchRole",e,t)},i.prototype.handleAudioVolume=function(e){var t=this,i=e.result||[];i=(i=i.map((function(e){return{userId:e.userId===t.userId?"":e.userId,volume:e.audioVolume}}))||[]).filter((function(e){return!t.isSharedStream(e.userId)})),this.emit("onUserVoiceVolume",i,i.length)},i.prototype.handleOnFirstVideoFrame=function(e,t,i){var r=i.offsetWidth,o=i.offsetHeight;this.emit("onFirstVideoFrame",e,t,r,o)},i.prototype.handleOnMicDidReady=function(){this.emit("onMicDidReady")},i.prototype.handleStreamAdded_=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return S(this,(function(o){switch(o.label){case 0:return t=e.stream,i=t.getUserId(),r=t.getType(),this.remoteStreamMap.set("".concat(i,"-").concat(r),e.stream),r!==B.AUXILIARY?[3,1]:(this.handleOnUserSubStreamAvailable(i,!0),[3,4]);case 1:return t.hasAudio()?[4,this.handleOnUserAudioAvailable(i,!0,r)]:[3,3];case 2:o.sent(),o.label=3;case 3:t.hasVideo()&&this.handleOnUserVideoAvailable(i,!0),o.label=4;case 4:return this.handleSubscribe(e.stream),[2]}}))}))},i.prototype.handleSubscribe=function(e,t){return void 0===t&&(t={audio:!0,video:!0}),v(this,void 0,void 0,(function(){var i;return S(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.client.subscribe(e,{audio:!!W(t.audio)||t.audio,video:!!W(t.video)||t.video})];case 1:return r.sent(),[3,3];case 2:return i=r.sent(),console.error("subscribe ".concat(e.getUserId()," with audio: ").concat(t.audio," video: ").concat(t.video," error"),i),[3,3];case 3:return[2]}}))}))},i.prototype.handleStreamSubscribed=function(){this.isSubscribed=!0},i.prototype.handleStreamRemoved_=function(e){return v(this,void 0,void 0,(function(){var t,i;return S(this,(function(r){switch(r.label){case 0:return t=e.stream.getUserId(),(i=e.stream.getType())!==B.MAIN?[3,2]:[4,this.handleOnUserAudioAvailable(t,!1,i)];case 1:return r.sent(),this.handleOnUserVideoAvailable(t,!1),[3,3];case 2:i===B.AUXILIARY&&this.handleOnUserSubStreamAvailable(t,!1),r.label=3;case 3:return this.remoteStreamMap.delete("".concat(t,"-").concat(i)),[2]}}))}))},i.prototype.handleStreamUpdated_=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o;return S(this,(function(a){switch(a.label){case 0:return t=e.stream,i=t.getUserId(),(r=t.getType())===B.AUXILIARY?[2]:(o=this.remoteStreamMap.get("".concat(i,"-").concat(r))).hasAudio()||!t.hasAudio()||this.remoteUserAvailable.get(i).isAudioAvailable?[3,2]:[4,this.handleOnUserAudioAvailable(i,!0,r)];case 1:a.sent(),a.label=2;case 2:return o.hasVideo()||!t.hasVideo()||this.remoteUserAvailable.get(i).isVideoAvailable||this.handleOnUserVideoAvailable(i,!0),[2]}}))}))},i.prototype.handleMuteAudio=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:return t=e.userId,this.isSharedStream(t)?[2]:t?[4,this.handleOnUserAudioAvailable(t,!1,B.MAIN)]:[3,2];case 1:i.sent(),i.label=2;case 2:return[2]}}))}))},i.prototype.handleUnmuteAudio=function(e){return v(this,void 0,void 0,(function(){var t;return S(this,(function(i){switch(i.label){case 0:return t=e.userId,this.isSharedStream(t)?[2]:!t||this.remoteUserAvailable.get(t).isAudioAvailable?[3,2]:[4,this.handleOnUserAudioAvailable(t,!0,B.MAIN)];case 1:i.sent(),i.label=2;case 2:return[2]}}))}))},i.prototype.handleMuteVideo=function(e){var t=e.userId;this.isSharedStream(t)||t&&this.handleOnUserVideoAvailable(t,!1)},i.prototype.handleUnmuteVideo=function(e){var t=e.userId;if(!this.isSharedStream(t)&&t&&!this.remoteUserAvailable.get(t).isVideoAvailable){if(((Array.from(this.remoteUserAvailable.keys())||[]).filter((function(e){return q(e,t)}))||[]).length>0)return void this.handleOnUserSubStreamAvailable(t,!0);if(this.isSharedStream(t)&&t.slice(6)===this.userId)return;this.handleOnUserVideoAvailable(t,!0)}},i.prototype.getLocalStatistics=function(){var t=this;return this.client.getLocalVideoStats().then((function(i){var r=i[t.client.getUserId()],o=r.bytesSent-t.prevLocalVideoStats.bytesSent,a=r.framesEncoded-t.prevLocalVideoStats.framesEncoded,s=r.frameWidth,n=r.frameHeight;o<0&&(o=0),a<0&&(a=0),t.prevLocalVideoStats=r;var c=Number((8*o/1e3/2).toFixed()),l=Number((a/2).toFixed()),u=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig;return new D(s,n,l,c,0,0,u)}))},i.prototype.handleNetworkQuality=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o,a,s,n,c,l,u,h;return S(this,(function(d){switch(d.label){case 0:return t=e.uplinkNetworkQuality,i=e.downlinkNetworkQuality,r=e.uplinkRTT,o=e.uplinkLoss,a=e.downlinkLoss,s=this.client?this.client.getUserId():"",n=new w(s,t),this.remoteStreamMap.size>0&&(c=(c=Array.from(this.remoteStreamMap.keys())).map((function(e){return e.includes("-".concat(B.MAIN))?e.split("-".concat(B.MAIN))[0]:e.includes("-".concat(B.AUXILIARY))?e.split("-".concat(B.AUXILIARY))[0]:""})),c=Array.from(new Set(c.filter((function(e){return e})))),l=c.map((function(e){return{userId:e,quality:i}})),this.emit("onNetworkQuality",n,l)),[4,this.getLocalStatistics()];case 1:return u=d.sent(),h=new L(o,a,0,0,r,0,0,[u]),this.emit("onStatistics",h),[2]}}))}))},i.prototype.handleDeviceChange=function(){return v(this,void 0,void 0,(function(){var t=this;return S(this,(function(i){return this.TRTC.getCameras().then((function(i){return v(t,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.cameraList.length===i.length?[2]:[4,this.deviceChangeManage(this.cameraList,i,e.TRTCDeviceType.TRTCDeviceTypeCamera)];case 1:return t.sent(),this.cameraList=i,[2]}}))}))})),this.TRTC.getMicrophones().then((function(i){return v(t,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.micList.length===i.length?[2]:[4,this.deviceChangeManage(this.micList,i,e.TRTCDeviceType.TRTCDeviceTypeMic)];case 1:return t.sent(),this.micList=i,[2]}}))}))})),this.TRTC.getSpeakers().then((function(i){return v(t,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return this.speakerList.length===i.length?[2]:[4,this.deviceChangeManage(this.speakerList,i,e.TRTCDeviceType.TRTCDeviceTypeSpeaker)];case 1:return t.sent(),this.speakerList=i,[2]}}))}))})),[2]}))}))},i.prototype.emitOnDeviceChange=function(e,t,i){this.emit("onDeviceChange",e,t,i)},i.prototype.deviceChangeManage=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a,s,n,c;return S(this,(function(l){switch(l.label){case 0:return t.length===i.length?[3,8]:(o=(i||[]).map((function(e){return e.deviceId})),a=new y,s=e.TRTCDeviceState.TRTCDeviceStateAdd,t.length>i.length&&(a=t.filter((function(e){return!o.includes(e.deviceId)}))[0]||{},s=e.TRTCDeviceState.TRTCDeviceStateRemove),t.length<i.length&&(o=(t||[]).map((function(e){return e.deviceId})),a=i.filter((function(e){return!o.includes(e.deviceId)}))[0]||{}),n=a.deviceId,this.emitOnDeviceChange(n,r,s),s!==e.TRTCDeviceState.TRTCDeviceStateAdd?[3,2]:[4,this.autoChangeDevice(r,s,n)]);case 1:return l.sent(),[3,8];case 2:return s!==e.TRTCDeviceState.TRTCDeviceStateRemove?[3,8]:n!==this.currentSpeakerId&&n!==this.currentMicId?[3,5]:(c=this.getDefaultDeviceInfo(i)).deviceId?[4,this.autoChangeDevice(r,s,c.deviceId)]:[3,4];case 3:l.sent(),l.label=4;case 4:l.label=5;case 5:return r!==e.TRTCDeviceType.TRTCDeviceTypeCamera?[3,8]:(c=this.getDefaultDeviceInfo(i)).deviceId?[4,this.autoChangeDevice(r,s,c.deviceId)]:[3,7];case 6:l.sent(),l.label=7;case 7:l.label=8;case 8:return[2]}}))}))},i.prototype.autoChangeDevice=function(t,i,r){return v(this,void 0,void 0,(function(){var o,a=this;return S(this,(function(s){switch(s.label){case 0:return t!==e.TRTCDeviceType.TRTCDeviceTypeCamera||i!==e.TRTCDeviceState.TRTCDeviceStateRemove?[3,5]:(this.currentCameraId=r,Z(this.localStream)?[4,this.localStream.switchDevice(B.VIDEO,r)]:[3,2]);case 1:s.sent(),s.label=2;case 2:return Z(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.VIDEO,r)]:[3,4];case 3:s.sent(),s.label=4;case 4:this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),s.label=5;case 5:return t!==e.TRTCDeviceType.TRTCDeviceTypeMic?[3,10]:$(this.localStream)?[4,this.localStream.switchDevice(B.AUDIO,r)]:[3,7];case 6:s.sent(),s.label=7;case 7:return $(this.localPlayStream)?[4,this.localPlayStream.switchDevice(B.AUDIO,r)]:[3,9];case 8:s.sent(),s.label=9;case 9:this.currentMicId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),s.label=10;case 10:return t!==e.TRTCDeviceType.TRTCDeviceTypeSpeaker?[3,13]:this.remoteStreamMap.size>0?(o=this.getRemoteStreamList(),[4,Promise.all(o.map((function(e){return v(a,void 0,void 0,(function(){return S(this,(function(t){switch(t.label){case 0:return[4,e.setAudioOutput(r)];case 1:return[2,t.sent()]}}))}))})))]):[3,12];case 11:s.sent(),s.label=12;case 12:this.currentSpeakerId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),s.label=13;case 13:return[2]}}))}))},i.prototype.getRemoteStreamList=function(){var e=[];return this.remoteStreamMap.size>0&&Array.from(this.remoteStreamMap,(function(e){return e[1]})).forEach((function(t){t&&e.push(t)})),e},i.prototype.getDefaultDeviceInfo=function(e){var t=new y;if(0===e.length)return t;var i=e.filter((function(e){return"default"===e.deviceId}));if(i.length>0){var r=i[0].groupId;t=e.filter((function(e){return e.groupId===r})).filter((function(e){return e.deviceId!==B.DEFAULT}))[0]}else t=e[0];return t},i.prototype.getResolution=function(t){var i=(e.TRTCVideoResolution[t]||"").split("_");return{width:i.length>1&&i[1],height:i.length>2&&i[2]}},i.prototype.getStreamType=function(e){if(!e)return"";var t=e.getUserId(),i=e&&e.getType();return this.isSharedStream(t)&&i===B.MAIN&&(i=B.AUXILIARY),i},i.prototype.isSharedStream=function(e){return e.slice(0,6)===B.SCREEN_SHARE_USER_ID_PREFIX},i.prototype.generateLocalPlayStream=function(t,i){return v(this,void 0,void 0,(function(){var r,o,a,s,n;return S(this,(function(c){switch(c.label){case 0:return r=t.audio,o=t.video,this.localPlayStream&&this.localPlayStream.hasVideo()&&o||this.localPlayStream&&this.localPlayStream.hasAudio()&&r?[2]:((a=this.TRTC.createStream(t)).setAudioProfile(H[i||e.TRTCAudioQuality.TRTCAudioQualityDefault]),this.videoEncodeParam?[4,a.setVideoProfile(this.videoEncodeParam)]:[3,2]);case 1:c.sent(),c.label=2;case 2:return[4,a.initialize()];case 3:if(c.sent(),!r)return[3,12];if(s=a.getAudioTrack(),!this.localPlayStream)return[3,11];c.label=4;case 4:return c.trys.push([4,,9,10]),this.localPlayStream.hasAudio()?[4,this.localPlayStream.replaceTrack(s)]:[3,6];case 5:return c.sent(),[3,8];case 6:return[4,this.localPlayStream.addTrack(s)];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:return a.close(),[7];case 10:return[3,12];case 11:this.localPlayStream=a,c.label=12;case 12:if(!o)return[3,21];if(n=a.getVideoTrack(),!this.localPlayStream)return[3,20];c.label=13;case 13:return c.trys.push([13,,18,19]),this.localPlayStream.hasVideo()?[4,this.localPlayStream.replaceTrack(n)]:[3,15];case 14:return c.sent(),[3,17];case 15:return[4,this.localPlayStream.addTrack(n)];case 16:c.sent(),c.label=17;case 17:return[3,19];case 18:return a.close(),[7];case 19:return[3,21];case 20:this.localPlayStream=a,c.label=21;case 21:return[2]}}))}))},i.prototype.stopLocalPlayStreamTrack=function(e){return v(this,void 0,void 0,(function(){var t,i;return S(this,(function(r){switch(r.label){case 0:return this.localPlayStream?e!==B.VIDEO?[3,5]:this.localPlayStream.hasAudio()?(t=this.localPlayStream.getVideoTrack())?[4,this.localPlayStream.removeTrack(t)]:[3,2]:[3,3]:[3,10];case 1:r.sent(),t.stop(),r.label=2;case 2:return[3,4];case 3:this.localPlayStream.stop(),this.localPlayStream.close(),this.localPlayStream=null,r.label=4;case 4:this.isStartedLocalPreview=!1,r.label=5;case 5:return e!==B.AUDIO?[3,10]:this.localPlayStream.hasVideo()?(i=this.localPlayStream.getAudioTrack())?[4,this.localPlayStream.removeTrack(i)]:[3,7]:[3,8];case 6:r.sent(),i.stop(),r.label=7;case 7:return[3,9];case 8:this.localPlayStream.stop(),this.localPlayStream.close(),this.localPlayStream=null,r.label=9;case 9:this.isStartedLocalAudio=!1,r.label=10;case 10:return[2]}}))}))},i}(Y(t.EventEmitter,ee,ue,he,de,me,Te,pe));e.Rect=Q,e.TRTCDeviceInfo=y,e.TRTCImageBuffer=O,e.TRTCLocalStatistics=D,e.TRTCNetworkQosParam=U,e.TRTCParams=b,e.TRTCPublishCDNParam=M,e.TRTCQualityInfo=w,e.TRTCRenderParams=V,e.TRTCScreenCaptureSourceInfo=N,e.TRTCStatistics=L,e.TRTCVideoEncParam=g,e.TRTCVolumeInfo=E,e.default=Se,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("events"),require("trtc-js-sdk")):"function"==typeof define&&define.amd?define(["exports","events","trtc-js-sdk"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).TRTC={},global.events,global.TRTC);
|