trtc-cloud-js-sdk 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -59,4 +59,7 @@ Explore SDK documents:[TRTCCloud SDK](https://web.sdk.qcloud.com/trtc/webrtc/t
59
59
  Default entry file, base on UMD modules, ES6 included.
60
60
 
61
61
  Usage:
62
- - `import TRTCCloud, { TRTCAppScene, TRTCParams } from 'trtc-cloud-js-sdk';`
62
+ - `import TRTCCloud, { TRTCAppScene, TRTCParams } from 'trtc-cloud-js-sdk';`
63
+
64
+ ## Reference Documents
65
+ - [TRTCCloud API](https://web.sdk.qcloud.com/trtc/webrtc/trtcCloud/doc/TRTCCloud.html)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-cloud-js-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Tencent Cloud RTC SDK for Web And Electron",
5
5
  "main": "trtc-cloud-js-sdk.js",
6
6
  "keywords": [
@@ -1 +1 @@
1
- var global,factory;global=this,factory=function(e,t,i){function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(i),n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},n(e,t)};function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var s,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,n){function a(e){try{c(r.next(e))}catch(t){n(t)}}function s(e){try{c(r.throw(e))}catch(t){n(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(a,s)}c((r=r.apply(e,t||[])).next())}))}function f(e,t){var i,r,o,n,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function s(n){return function(s){return function(n){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,r&&(o=2&n[0]?r.return:n[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,n[1])).done)return o;switch(r=0,o&&(n=[2&n[0],o.value]),n[0]){case 0:case 1:o=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,r=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==n[0]&&2!==n[0])){a=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){a.label=n[1];break}if(6===n[0]&&a.label<o[1]){a.label=o[1],o=n;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(n);break}o[2]&&a.ops.pop(),a.trys.pop();continue}n=t.call(e,a)}catch(s){n=[6,s],r=0}finally{i=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,s])}}}e.TRTCVideoResolution=void 0,(s=e.TRTCVideoResolution||(e.TRTCVideoResolution={}))[s.TRTCVideoResolution_120_120=1]="TRTCVideoResolution_120_120",s[s.TRTCVideoResolution_160_160=3]="TRTCVideoResolution_160_160",s[s.TRTCVideoResolution_270_270=5]="TRTCVideoResolution_270_270",s[s.TRTCVideoResolution_480_480=7]="TRTCVideoResolution_480_480",s[s.TRTCVideoResolution_160_120=50]="TRTCVideoResolution_160_120",s[s.TRTCVideoResolution_240_180=52]="TRTCVideoResolution_240_180",s[s.TRTCVideoResolution_280_210=54]="TRTCVideoResolution_280_210",s[s.TRTCVideoResolution_320_240=56]="TRTCVideoResolution_320_240",s[s.TRTCVideoResolution_400_300=58]="TRTCVideoResolution_400_300",s[s.TRTCVideoResolution_480_360=60]="TRTCVideoResolution_480_360",s[s.TRTCVideoResolution_640_480=62]="TRTCVideoResolution_640_480",s[s.TRTCVideoResolution_960_720=64]="TRTCVideoResolution_960_720",s[s.TRTCVideoResolution_160_90=100]="TRTCVideoResolution_160_90",s[s.TRTCVideoResolution_256_144=102]="TRTCVideoResolution_256_144",s[s.TRTCVideoResolution_320_180=104]="TRTCVideoResolution_320_180",s[s.TRTCVideoResolution_480_270=106]="TRTCVideoResolution_480_270",s[s.TRTCVideoResolution_640_360=108]="TRTCVideoResolution_640_360",s[s.TRTCVideoResolution_960_540=110]="TRTCVideoResolution_960_540",s[s.TRTCVideoResolution_1280_720=112]="TRTCVideoResolution_1280_720",s[s.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.WebRTCAudioQuality=void 0,(T=e.WebRTCAudioQuality||(e.WebRTCAudioQuality={}))[T.WebRTCAudioQualityStandard=0]="WebRTCAudioQualityStandard",T[T.WebRTCAudioQualityHigh=1]="WebRTCAudioQualityHigh",T[T.WebRTCAudioQualityStandardStereo=2]="WebRTCAudioQualityStandardStereo",T[T.WebRTCAudioQualityHighStereo=3]="WebRTCAudioQualityHighStereo";var S,C,R=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,(S=e.TRTCDeviceState||(e.TRTCDeviceState={}))[S.TRTCDeviceStateAdd=0]="TRTCDeviceStateAdd",S[S.TRTCDeviceStateRemove=1]="TRTCDeviceStateRemove",S[S.TRTCDeviceStateActive=2]="TRTCDeviceStateActive",e.TRTCDeviceType=void 0,(C=e.TRTCDeviceType||(e.TRTCDeviceType={}))[C.TRTCDeviceTypeUnknow=-1]="TRTCDeviceTypeUnknow",C[C.TRTCDeviceTypeMic=0]="TRTCDeviceTypeMic",C[C.TRTCDeviceTypeSpeaker=1]="TRTCDeviceTypeSpeaker",C[C.TRTCDeviceTypeCamera=2]="TRTCDeviceTypeCamera";var y,b=function(t,i,r,o,n,a,s,c,l,u,h){void 0===t&&(t=0),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=0),void 0===n&&(n=""),void 0===a&&(a=e.TRTCRoleType.TRTCRoleAnchor),void 0===s&&(s=null),void 0===l&&(l=null),void 0===u&&(u=null),void 0===h&&(h=40),this.sdkAppId=t,this.userId=i,this.userSig=r,this.roomId=o,this.strRoomId=n,this.role=a,this.privateMapKey=s,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,(y=e.TRTCVideoRotation||(e.TRTCVideoRotation={}))[y.TRTCVideoRotation0=0]="TRTCVideoRotation0",y[y.TRTCVideoRotation90=1]="TRTCVideoRotation90",y[y.TRTCVideoRotation180=2]="TRTCVideoRotation180",y[y.TRTCVideoRotation270=3]="TRTCVideoRotation270";var V,A=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.TRTCNetQuality=void 0,(V=e.TRTCNetQuality||(e.TRTCNetQuality={}))[V.TRTCNetQuality_Unknown=0]="TRTCNetQuality_Unknown",V[V.TRTCNetQuality_Excellent=1]="TRTCNetQuality_Excellent",V[V.TRTCNetQuality_Good=2]="TRTCNetQuality_Good",V[V.TRTCNetQuality_Poor=3]="TRTCNetQuality_Poor",V[V.TRTCNetQuality_Bad=4]="TRTCNetQuality_Bad",V[V.TRTCNetQuality_Vbad=5]="TRTCNetQuality_Vbad",V[V.TRTCNetQuality_Down=6]="TRTCNetQuality_Down";var w,_,P,I=function(t,i,r,o,n,a,s){void 0===t&&(t=""),void 0===i&&(i=e.TRTCNetQuality.TRTCNetQuality_Unknown),this.userId=t,this.quality=i,this.uplinkNetworkQuality=r,this.uplinkRTT=o,this.uplinkLoss=n,this.downlinkRTT=a,this.downlinkLoss=s},M=function(e,t){void 0===e&&(e=""),void 0===t&&(t=0),this.userId=e,this.volume=t},E=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,n,a,s){void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=0),void 0===n&&(n=0),void 0===a&&(a=0),void 0===s&&(s=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig),this.width=t,this.height=i,this.frameRate=r,this.videoBitrate=o,this.audioSampleRate=n,this.audioBitrate=a,this.streamType=s},L=function(e,t,i,r,o,n,a,s,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===n&&(n=0),void 0===a&&(a=0),void 0===s&&(s=[]),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=n,this.sentBytes=a,this.localStatisticsArray=s,this.localStatisticsArraySize=c,this.remoteStatisticsArraySize=l};e.TRTCAudioQuality=void 0,(w=e.TRTCAudioQuality||(e.TRTCAudioQuality={}))[w.TRTCAudioQualitySpeech=1]="TRTCAudioQualitySpeech",w[w.TRTCAudioQualityDefault=2]="TRTCAudioQualityDefault",w[w.TRTCAudioQualityMusic=3]="TRTCAudioQualityMusic",e.TRTCVideoQosPreference=void 0,(_=e.TRTCVideoQosPreference||(e.TRTCVideoQosPreference={}))[_.TRTCVideoQosPreferenceSmooth=1]="TRTCVideoQosPreferenceSmooth",_[_.TRTCVideoQosPreferenceClear=2]="TRTCVideoQosPreferenceClear",e.TRTCQosControlMode=void 0,(P=e.TRTCQosControlMode||(e.TRTCQosControlMode={}))[P.TRTCQosControlModeClient=0]="TRTCQosControlModeClient",P[P.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},F=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 Q,N=function(t,i,r,o,n,a){void 0===t&&(t=e.TRTCScreenCaptureSourceType.TRTCScreenCaptureSourceTypeUnknown),void 0===i&&(i=""),void 0===r&&(r=""),void 0===o&&(o=new F),void 0===n&&(n=new F),void 0===a&&(a=!1),this.type=t,this.sourceId=i,this.sourceName=r,this.thumbBGRA=o,this.iconBGRA=n,this.isMinimizeWindow=a},O=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",J="video",x="audio",W="onError",j="main",z="rtc",H="live",K="anchor",G="audience",q="auxiliary",X="share_",Y="number",Z={20:K,21:G},$={0:z,1:H,2:z,3:H},ee={0:"standard",1:"high",2:"standard_stereo",3:"high_stereo"},te={0:"big",1:"small",2:q};function ie(){return Math.floor(performance.now())}!function(e){e[e.ActiveExitRoom=0]="ActiveExitRoom",e[e.KickedExitRoom=1]="KickedExitRoom"}(Q||(Q={}));var re=function(e){return void 0===e};function oe(e){return"".concat(e,"-").concat(j)}function ne(e){return"".concat(e,"-").concat(q)}function ae(){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++)se(this,new(0,i[t])(this))},r=i.prototype,o=0,n=e;o<n.length;o++){var a=n[o];se(i,a),se(r,a.prototype)}return i}function se(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 n=Object.getOwnPropertyDescriptor(t,o)||"";Object.defineProperty(e,o,n)}}}function ce(e,t){return void 0===e&&(e=""),t==="share_".concat(e)}var le=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.mode=z,i.role=K,i.privateMapKey="255",i.streamId="",i.isSmallStreamSupported=!1,i.shareUserId="",i.shareUserSig="",i.isSharing=!1,i.isShareClientJoined=!1,i.isShareStreamPublished=!1,i.isShareClientLeaving=!1,i.isStaringLocalPreview=!1,i.isStartedLocalPreview=!1,i.isStaringLocalAudio=!1,i.isStartedLocalAudio=!1,i.defaultVideoWidth=640,i.defaultVideoHeight=480,i.defaultVideoFps=15,i.defaultVideoBitRate=900,i.defaultShareWidth=1920,i.defaultShareHeight=1080,i.defaultShareFrameRate=15,i.defaultShareBitrate=1500,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.WebRTCAudioQuality.WebRTCAudioQualityStandard,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 a(i,t),i.prototype.promiseRetry=function(e){var t=this,i=e.retryFunction,r=e.settings,o=e.onError,n=e.onRetrying,a=e.context;return function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];var c=r.retries||5,l=0,u=-1,h=0,d=function(s,m){return v(t,void 0,void 0,(function(){var t,T,p,v,S;return f(this,(function(f){switch(f.label){case 0:return f.trys.push([0,2,,3]),t=a||this,[4,i.apply(t,e)];case 1:return T=f.sent(),l=0,s(T),[3,3];case 2:return p=f.sent(),v=function(){clearTimeout(u),l=0,h=2,m(p)},S=function(){2!==h&&l<c?(l++,h=1,n&&n(l,v),u=window.setTimeout((function(){u=-1,d(s,m)}),void 0===r.timeout?1e3:r.timeout)):v()},o?o(p,S,m):S(),[3,3];case 3:return[2]}}))}))};return new Promise(d)}},i}(t.EventEmitter),ue=-1e3,he={code:-1001,message:"参数错误, 请检查参数格式、是否非空等"},de={code:-1002,message:"进房失败:进房中或已进房"},me={code:-1003,message:"退房失败:未进房或退房中"},Te={code:-1004,message:"调用该函数所需要条件不满足"},pe={code:-1005,message:"not supported"},ve={code:-1006,message:"not supported before join room"},fe={code:-1007,message:"进房 userId 不能包含前缀 share_"},Se={code:-1008,message:"屏幕分享 userId 必须包含前缀 share_"},Ce=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.startPublishing=function(e,t){return v(this,void 0,void 0,(function(){var t,i;return f(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:Te,message:"".concat(Te.message," - client = ").concat(this.client)}),[2]):(this.log_.error("(startPublishing) failed - ".concat(this.isPublished)),this.emitError({conditionsError:Te,message:"".concat(Te.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 f(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:Te,message:"".concat(Te.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,n;return f(this,(function(a){switch(a.label){case 0:return a.trys.push([0,4,,5]),e instanceof E?(t=e.appId,i=e.bizId,r=e.url,o={appId:t,bizId:i,url:r},[4,this.client.startPublishCDNStream(o)]):[3,2];case 1:return a.sent(),[3,3];case 2:this.log_.error("(startPublishCDNStream) failed - ".concat(JSON.stringify(e))),this.emitError(he),a.label=3;case 3:return[3,5];case 4:return n=a.sent(),this.callFunctionErrorManage(n,"startPublishCDNStream"),[3,5];case 5:return[2]}}))}))},t.prototype.stopPublishCDNStream=function(){return v(this,void 0,void 0,(function(){var e;return f(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:Te,message:"".concat(Te.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}(ae(le)),Re=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return a(i,t),i.prototype.startLocalPreview=function(e){return v(this,void 0,void 0,(function(){var t;return f(this,(function(i){switch(i.label){case 0:this.log_.info("(startLocalPreview) start - start local preview",e),i.label=1;case 1:return i.trys.push([1,3,,4]),this.localStreamHasVideoOrAudio(J)?(this.playStream(this.localStream,e),[2]):[4,this.promiseRetry({retryFunction:this.doStartLocalPreview,settings:{retries:6,timeout:1e3}})(e)];case 2:return i.sent(),[3,4];case 3:return t=i.sent(),this.isStaringLocalPreview=!1,this.callFunctionErrorManage(t,"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 f(this,(function(o){switch(o.label){case 0:if(this.isStaringLocalAudio)throw new Error("startLocalAudio is under implementation.");return this.isStaringLocalPreview=!0,re(e)?[3,10]:null===e?[3,9]:(t={userId:this.client&&"".concat(this.client.getUserId()," video")||"video undefined",video:!0,audio:!1,screenAudio:!1},this.currentCameraId&&(t.cameraId=this.currentCameraId),this.localStream?(i=this.TRTC.createStream(t),this.videoEncodeParam?[4,i.setVideoProfile(this.videoEncodeParam)]:[3,2]):[3,5]);case 1:o.sent(),o.label=2;case 2:return[4,i.initialize()];case 3:return o.sent(),r=i.getVideoTrack(),[4,this.localStream.addTrack(r)];case 4:return o.sent(),[3,7];case 5:return[4,this.initStream(t)];case 6:o.sent(),o.label=7;case 7:return this.isStartedLocalPreview=!0,this.localStream&&(this.playStream(this.localStream,e,this.localStreamRenderParams),this.clearTempAudioContainer("localAudio")),[4,this.publishLocalStream()];case 8:o.sent(),this.isStaringLocalPreview=!1,o.label=9;case 9:return[3,11];case 10:this.emitError(he),this.log_.error("(startLocalPreview) failed - ".concat(he.message,": ").concat(e)),o.label=11;case 11:return[2]}}))}))},i.prototype.stopLocalPreview=function(){return v(this,void 0,void 0,(function(){var e=this;return f(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,o=this;return f(this,(function(n){switch(n.label){case 0:return n.trys.push([0,4,,5]),this.localStream?this.localStream.getAudioTrack()?((e=this.localStream.getVideoTrack())&&this.localStream.removeTrack(e).then((function(){e.stop(),o.isStartedLocalPreview=!1,t(1)})),[3,3]):[3,1]:[3,3];case 1:return[4,this.unPublishStream()];case 2:n.sent(),this.localStream.stop(),this.localStream.close(),this.localStream=null,this.isStartedLocalPreview=!1,t(1),n.label=3;case 3:return[3,5];case 4:return r=n.sent(),this.callFunctionErrorManage(r,"stopLocalPreview"),i(r),[3,5];case 5:return[2]}}))}))}))]:(this.log_.info("(stopLocalPreview) stop - local preview has not been started"),[2])}))}))},i.prototype.muteLocalVideo=function(e){void 0===e&&(e=!1);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,n,a,s,c;return f(this,(function(l){switch(l.label){case 0:return l.trys.push([0,7,,8]),t&&!re(i)&&r in e.TRTCVideoStreamType?(o=r,n=oe(t),r===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?(n=ne("".concat(X).concat(t)),this.remoteStreamMap.has(n)||(n=ne(t)),o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig):this.isSmallStreamSupported||(o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig),a=te[o],this.remoteStreamMap.has(n)?(s=this.remoteStreamMap.get(n),a===q?[3,3]:this.client?[4,this.client.setRemoteVideoStreamType(s,o)]:[3,2]):[3,6]):(this.emitError(he),this.log_.error("(startRemoteView) failed - ".concat(he.message,": ").concat(i)),[2]);case 1:l.sent(),l.label=2;case 2:l.label=3;case 3:return s?[4,this.client.subscribe(s,{audio:!0,video:!0})]:[3,6];case 4:return l.sent(),[4,this.playStream(s,i)];case 5:l.sent(),this.clearTempAudioContainer("".concat(n,"_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,n,a;return f(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),r=oe(t),o=i,re(i)||(o=this.priorRemoteVideoStreamType),console.log("stopRemoteView streamType: ",o),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(r=ne("".concat(X).concat(t)),this.remoteStreamMap.has(r)||(r=ne(t))),this.remoteStreamMap.has(r)?(n=this.remoteStreamMap.get(r),i!==e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?[3,1]:[3,3]):[3,3];case 1:return[4,this.client.subscribe(n,{audio:!0,video:!1})];case 2:s.sent(),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),this.callFunctionErrorManage(a,"stopRemoteView"),[3,5];case 5:return[2]}}))}))},i.prototype.muteRemoteVideoStream=function(e,t){void 0===t&&(t=!1);try{if(!e)return this.emitError(he),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(he.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(oe(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 f(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,n;return f(this,(function(a){switch(a.label){case 0:return a.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.localStream.getUserId(),"-").concat(this.localStream.getType())),[4,this.playStream(this.localStream,r,i)]):[3,2];case 1:a.sent(),a.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 n=a.sent(),this.callFunctionErrorManage(n,"setLocalRenderParams"),[3,4];case 4:return[2]}}))}))},i.prototype.setRemoteRenderParams=function(t,i,r){return v(this,void 0,void 0,(function(){var o,n,a,s,c;return f(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"),n=oe(t),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(n=ne(t)),a=this.playViewMap.get(n),(s=this.remoteStreamMap.get(n))?[4,this.playStream(s,a,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 f(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}(ae(le)),ye=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return a(i,t),i.prototype.startLocalAudio=function(e){return v(this,void 0,void 0,(function(){var t;return f(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(),[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,n,a;return f(this,(function(s){switch(s.label){case 0:if(this.isStaringLocalPreview)throw new Error("startLocalPreview is under implementation.");s.label=1;case 1:return s.trys.push([1,10,,11]),this.isStaringLocalAudio=!0,i=t,re(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(ee[i||e.WebRTCAudioQuality.WebRTCAudioQualityStandard]),[4,o.initialize()];case 2:return s.sent(),n=o.getAudioTrack(),this.localStream?(this.muteLocalAudio(!1),this.localStream.getAudioTrack()?[4,this.localStream.replaceTrack(n)]:[3,4]):[3,7];case 3:return s.sent(),[3,6];case 4:return[4,this.localStream.addTrack(n)];case 5:s.sent(),s.label=6;case 6:return[3,8];case 7:this.localStream=o,a=this.generateTempAudioContainer("localAudio"),this.localStream.play(a),s.label=8;case 8:return this.isStartedLocalAudio=!0,[4,this.publishLocalStream()];case 9:return s.sent(),this.isStaringLocalAudio=!1,this.isPublished||this.getLocalStreamAudioLevel(),[3,11];case 10:throw s.sent();case 11: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 f(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;return f(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),this.localStream?(this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),this.localStream.getVideoTrack()?((e=this.localStream.getAudioTrack())&&(this.muteLocalAudio(!0),e.stop(),this.isStartedLocalAudio=!1,t(1)),[3,3]):[3,1]):[3,3];case 1:return[4,this.unPublishStream()];case 2:o.sent(),this.localStream.stop(),this.localStream.close(),this.clearTempAudioContainer("localAudio"),this.localStream=null,this.isStartedLocalAudio=!1,t(1),o.label=3;case 3:return[3,5];case 4:return r=o.sent(),this.callFunctionErrorManage(r,"stopLocalAudio"),i(r),[3,5];case 5:return[2]}}))}))}))]:(this.log_.info("(stopLocalAudio) stop - local audio has not been started"),[2])}))}))},i.prototype.muteLocalAudio=function(e){void 0===e&&(e=!1);try{this.localStream&&(e?this.localStream.muteAudio():this.localStream.unmuteAudio())}catch(t){this.callFunctionErrorManage(t,"muteLocalAudio")}},i.prototype.muteRemoteAudio=function(e,t){void 0===t&&(t=!1);try{if(!e)return this.emitError(he),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(he.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(oe(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(he),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(he.message,": userId = ").concat(e,", volume = ").concat(t));var i=this.remoteStreamMap.get(oe(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}(ae(le)),be=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return a(i,t),i.prototype.getCameraDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return f(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 f(this,(function(r){switch(r.label){case 0:return r.trys.push([0,5,,6]),t?(this.currentCameraId=t||"",this.localStream?[4,this.localStream.switchDevice(J,t)]:[3,2]):[2,Promise.resolve(!1)];case 1:r.sent(),this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeCamera,e.TRTCDeviceState.TRTCDeviceStateActive),r.label=2;case 2:return this.testCameraStream?[4,this.testCameraStream.switchDevice("video",t)]:[3,4];case 3:r.sent(),r.label=4;case 4:return[2,Promise.resolve(!0)];case 5:return i=r.sent(),this.callFunctionErrorManage(i,"setCurrentCameraDevice"),this.cameraList=[],[2,Promise.resolve(!1)];case 6:return[2]}}))}))},i.prototype.getCurrentCameraDevice=function(){var e=this;return(this.cameraList||[]).filter((function(t){return t.deviceId===e.currentCameraId}))[0]||{}},i}(ae(le)),ge=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return a(i,t),i.prototype.getMicDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return f(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 R},i.prototype.setCurrentMicDevice=function(t){return v(this,void 0,Promise,(function(){var i;return f(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),t?this.localStream?this.localStream&&this.currentMicId!==t?[4,this.localStream.switchDevice(x,t)]:[3,2]:[2,Promise.resolve(!0)]:[2,Promise.resolve(!1)];case 1:return r.sent(),this.currentMicId=t||"",this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeMic,e.TRTCDeviceState.TRTCDeviceStateActive),[2,Promise.resolve(!0)];case 2:return[2,Promise.resolve(!0)];case 3:return i=r.sent(),this.callFunctionErrorManage(i,"setCurrentMicDevice"),[2,Promise.resolve(!1)];case 4:return[2]}}))}))},i.prototype.getSpeakerDevicesList=function(){return v(this,void 0,Promise,(function(){var e,t;return f(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 R},i.prototype.setCurrentSpeakerDevice=function(e){return v(this,void 0,Promise,(function(){var t,i,r=this;return f(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 f(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:return o.sent(),[2,Promise.resolve(!0)];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}(ae(le)),Ve=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.startScreenCapture=function(){this.emitError(pe)},t.prototype.pauseScreenCapture=function(){this.emitError(pe)},t.prototype.resumeScreenCapture=function(){this.emitError(pe)},t.prototype.getScreenCaptureSources=function(){this.emitError(pe)},t.prototype.selectScreenCaptureTarget=function(){this.emitError(pe)},t.prototype.initShareClient=function(e,t){return v(this,void 0,void 0,(function(){var i,r;return f(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),i=this,[4,this.TRTC.createClient({mode:"rtc",sdkAppId:this.sdkAppId,userId:e,userSig:t,autoSubscribe:!1})];case 1:return i.shareClient=o.sent(),console.log("ShareClient [".concat(e,"] created.")),this.installShareClientEventHandlers(),[3,3];case 2:throw r=o.sent(),console.error("Failed to create Client [".concat(e,"].")),r;case 3:return[2]}}))}))},t.prototype.installShareClientEventHandlers=function(){this.shareClient.on("error",this.handleShareClientError.bind(this)),this.shareClient.on("client-banned",this.handleShareClientBanned.bind(this)),this.shareClient.on("stream-subscribed",this.handleShareClientStreamSubscribed.bind(this))},t.prototype.handleShareClientError=function(e){console.error("ShareClient error:",e)},t.prototype.handleShareClientBanned=function(e){console.error("ShareClient has been banned for:",e)},t.prototype.handleShareClientStreamSubscribed=function(e){var t=e.stream,i=t.getId(),r=t.getUserId();console.log("remote stream received and unsubscribed: [".concat(r,"] ID: ").concat(i," type: ").concat(t.getType())),this.shareClient.unsubscribe(t)},t.prototype.initShareStream=function(e){return v(this,void 0,void 0,(function(){var t,i=this;return f(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.shareUserId,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.shareClientLeave()})),[2,this.shareStream];case 2:throw t=r.sent(),console.error("ShareStream failed to initialize. Error: ".concat(t)),t;case 3:return[2]}}))}))},t.prototype.shareClientJoin=function(e,t){return v(this,void 0,void 0,(function(){var i;return f(this,(function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),this.shareClient?[3,2]:[4,this.initShareClient(e,t)];case 1:r.sent(),r.label=2;case 2:return[4,this.shareClient.join({roomId:this.roomId})];case 3:return r.sent(),this.isShareClientJoined=!0,[3,5];case 4:throw i=r.sent(),console.error("ShareClient join room failed:",i),i;case 5:return[2]}}))}))},t.prototype.shareClientPublish=function(){return v(this,void 0,void 0,(function(){var e;return f(this,(function(t){switch(t.label){case 0:if(!this.isShareClientJoined)return console.warn("ShareClient cannot publish() - please join() firstly"),[2];if(this.isShareStreamPublished)return console.warn("ShareClient duplicate publish() observed"),[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.shareClient.publish(this.shareStream)];case 2:return t.sent(),console.log("ShareStream is published successfully"),this.isShareStreamPublished=!0,[3,4];case 3:throw e=t.sent(),console.error("ShareStream is failed to publish. Error: ".concat(e)),e;case 4:return[2]}}))}))},t.prototype.shareClientUnpublish=function(){return v(this,void 0,void 0,(function(){var e;return f(this,(function(t){switch(t.label){case 0:if(!this.isShareClientJoined)return console.warn("ShareClient cannot unpublish() - please join() firstly"),[2];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.shareClient.unpublish(this.shareStream)]:[3,3];case 2:t.sent(),t.label=3;case 3:return this.isShareStreamPublished=!1,console.log("Unpublish ShareStream success"),[3,5];case 4:throw e=t.sent(),console.error("unpublish failed",e),e;case 5:return[2]}}))}))},t.prototype.shareClientLeave=function(){return v(this,void 0,void 0,(function(){var e;return f(this,(function(t){switch(t.label){case 0:return this.isShareClientJoined?this.isShareClientLeaving?(console.warn("ShareClient duplicate leave() observed"),[2]):this.isShareStreamPublished?[4,this.shareClientUnpublish()]:[3,2]:(console.warn("ShareClient cannot leave() - please join() firstly"),[2]);case 1:t.sent(),t.label=2;case 2:return t.trys.push([2,4,,5]),this.isShareClientLeaving=!0,[4,this.shareClient.leave()];case 3:return t.sent(),this.isShareClientJoined=!1,console.log("ShareClient leave room success"),this.shareStream&&(this.shareStream.stop(),this.shareStream.close(),this.shareStream=null),this.isShareClientLeaving=!1,[3,5];case 4:throw e=t.sent(),console.error("ShareClient leave failed:",e),e;case 5:return[2]}}))}))},t.prototype.startScreenShare=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o,n,a,s;return f(this,(function(c){switch(c.label){case 0:if(!this.isJoined||this.isJoining)return this.emitError(ve),[2];if(t=e.shareUserId,i=void 0===t?"":t,r=e.shareUserSig,o=void 0===r?"":r,n=e.screenAudio,a=void 0!==n&&n,!i||!o||i.slice(0,6)!==X)return this.emitError(Se),[2];this.shareUserId=i,this.shareUserSig=o,c.label=1;case 1:return c.trys.push([1,5,,6]),[4,this.initShareStream(!!a)];case 2:return c.sent(),[4,this.shareClientJoin(i,o)];case 3:return c.sent(),[4,this.shareClientPublish()];case 4:return c.sent(),console.log("Start share screen success"),this.isSharing=!0,[3,6];case 5:throw s=c.sent(),console.error("Start share screen error:",s),s;case 6:return[2]}}))}))},t.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(n){throw n}},t.prototype.stopScreenShare=function(){return v(this,void 0,void 0,(function(){var e;return f(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),[4,this.shareClientUnpublish()];case 1:return t.sent(),[4,this.shareClientLeave()];case 2:return t.sent(),this.isSharing=!1,[3,4];case 3:throw e=t.sent(),console.error("Stop screen share error:",e),e;case 4:return[2]}}))}))},t}(ae(le)),Ae=null,we=function(t){function i(){var e,i,r,o=t.call(this)||this;return o.enableAudioVolumeInterval=0,o.enableAudioVolumeTimer=-1,o.frameWorkType=40,o.VERSION="1.0.2",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.mediaDevices.addEventListener("devicechange",(e=o.handleDeviceChange,i=30,function(){for(var t=this,o=[],n=0;n<arguments.length;n++)o[n]=arguments[n];r>0&&clearTimeout(r),r=window.setTimeout((function(){e.apply(t,o),r=-1}),i)})),o.TRTC.getMicrophones().then((function(e){o.micList=e||[];var t=o.getDefaultDeviceInfo(e);o.currentMicId=t.deviceId||""})).catch((function(e){o.log_.error("getMicrophones error observed ".concat(e))})),o.TRTC.getCameras().then((function(e){o.cameraList=e||[];var t=o.getDefaultDeviceInfo(e);o.currentCameraId=t.deviceId||""})).catch((function(e){o.log_.error("getCameras error observed ".concat(e))})),o.TRTC.getSpeakers().then((function(e){o.speakerList=e||[];var t=o.getDefaultDeviceInfo(e);o.currentSpeakerId=t.deviceId||""})).catch((function(e){o.log_.error("getSpeakers error observed ".concat(e))})),o}return a(i,t),i.getTRTCShareInstance=function(){return Ae||(Ae=new i),Ae},i.destroyTRTCShareInstance=function(){Ae&&(Ae.destroy(),Ae=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,n,a,s,c,l,u,h,d,m,T,v;return f(this,(function(f){switch(f.label){case 0:if(!(e instanceof b))return[3,6];if(i=e.sdkAppId,r=e.userId,o=e.userSig,n=e.roomId,a=e.strRoomId,s=e.role,c=e.privateMapKey,l=e.streamId,u=e.frameWorkType,this.sdkAppId=i,this.userId=r,this.userSig=o,this.roomId=n,this.strRoomId=a,this.mode=$[t],this.role=Z[s],this.remoteUserAvailable=new Map,u&&typeof u===Y&&(this.frameWorkType=u),this.isSharedStream(r))return this.log_.error("(enterRoom) failed - ".concat(fe.message," userId: ").concat(this.userId)),this.emitError(fe),[2];if(h=n,d=!1,!n&&a&&(h=a,d=!0),this.isJoining||this.isJoined)return this.log_.error("(enterRoom) failed - ".concat(de.message," isJoining: ").concat(this.isJoining,", isJoined: ").concat(this.isJoined)),this.emitError(de),[2];f.label=1;case 1:return f.trys.push([1,4,,5]),this.isJoining=!0,m={sdkAppId:i,userId:r,userSig:o,mode:this.mode,useStringRoomId:d,frameWorkType:this.frameWorkType},m=c?p(p({},m),{privateMapKey:c}):m,m=l?p(p({},m),{streamId:l}):m,this.initClient(m),this.startJoinTimestamp=ie(),[4,this.client.join({roomId:h,role:this.role})];case 2:return f.sent(),this.isJoined=!0,this.isJoining=!1,this.joinedTimestamp=ie(),T=this.joinedTimestamp-this.startJoinTimestamp,this.emit("onEnterRoom",T),this.log_.info("(enterRoom) success - enter room"),[4,this.publishLocalStream()];case 3:return f.sent(),[3,5];case 4:return v=f.sent(),this.isJoining=!1,this.emit("onEnterRoom",-1),this.callFunctionErrorManage(v,"enterRoom"),[3,5];case 5:return[3,7];case 6:this.emitError(he),this.log_.error("(enterRoom) failed - ".concat(he.message,": ").concat(JSON.stringify(e))),f.label=7;case 7:return[2]}}))}))},i.prototype.exitRoom=function(){return v(this,void 0,void 0,(function(){var e;return f(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(me.message," isJoined: ").concat(this.isJoined," isExiting: ").concat(this.isExiting)),this.emitError(me),[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",Q.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 f(this,(function(r){switch(r.label){case 0:return r.trys.push([0,8,,9]),this.mode===z?(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?Z[t]?[3,1]:(this.handleOnSwitchRole(-1,"please pass valid role parameter, role = ".concat(t)),[3,5]):[3,6];case 1:return[4,this.client.switchRole(Z[t])];case 2:return r.sent(),this.role=Z[t],t===e.TRTCRoleType.TRTCRoleAnchor&&this.localStream?[4,this.client.publish(this.localStream)]:[3,4];case 3:r.sent(),r.label=4;case 4:this.handleOnSwitchRole(0,"switch role success, role = ".concat(t,", ").concat(Z[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(W,e.getCode(),e.message_),this.log_.error("(".concat(t,") failed - ").concat(e.message_))):(this.emit(W,ue,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.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,n,a,s,c;return f(this,(function(l){switch(l.label){case 0:if(t=(e=this).mode,i=e.role,r=e.isJoined,o=e.isPublishing,n=e.isPublished,a=e.localStream,s=e.client,t===H&&i===G)return this.log_.info("(publishLocalStream) failed - mode = ".concat(t,", role = ").concat(i)),[2];if(!r||o||n||!a||!s)return this.log_.info("(publishLocalStream) failed - isJoined = ".concat(r,",\n isPublishing = ").concat(o,", isPublished = ").concat(n,", localStream = ").concat(a,", client.userId = ").concat(s?s.getUserId():null)),[2];if(this.log_.info("(publishLocalStream) start - publish stream"),!r||n)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(),l.label=4;case 4:return this.isPublishing=!1,this.isPublished=!0,this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),this.log_.info("(publishLocalStream) success - publish stream"),[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 f(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 f(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,8]),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[3,8];case 4:return"OverconstrainedError"!==o.sent().name?[3,6]:(console.error("当前摄像头不支持该 profile"),[4,(r=this.TRTC.createStream({video:!0,audio:!1})).initialize()]);case 5:return o.sent(),this.localStream.replaceTrack(r.getVideoTrack()),[3,7];case 6:console.error("当前浏览器不支持动态调用该接口"),o.label=7;case 7:return[3,8];case 8: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 f(this,(function(t){switch(t.label){case 0:return this.localStream=this.TRTC.createStream(e),this.videoEncodeParam&&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(he),!this.localStream)return!1;switch(e){case J:return!!this.localStream.getVideoTrack();case x: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;return f(this,(function(n){return t&&e?(e.play(t,i),r=e.getUserId(),r=this.isSharedStream(r)?r.slice(6):r,o=this.getStreamType(e),this.playViewMap.set("".concat(r,"-").concat(o),t),[2]):(this.log_.error("(playStream) failed - dom = ".concat(t,", stream = ").concat(e)),[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",Q.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(W,e.code,e.message)},i.prototype.handleError=function(e){this.log_.error("handle error observed ".concat(e)),this.emit(W,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}),ce(this.userId,t)||(i.filter((function(e){return ce(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 f(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(he)}},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.handleStreamAdded=function(e){return v(this,void 0,void 0,(function(){var t,i,r;return f(this,(function(o){switch(o.label){case 0:return t=e.stream,i=t.getUserId(),i=this.isSharedStream(i)?i.slice(6):i,r=this.getStreamType(t),this.remoteStreamMap.set("".concat(i,"-").concat(r),e.stream),r!==q?[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:if(t.hasVideo()){if(((Array.from(this.remoteUserAvailable.keys())||[]).filter((function(e){return ce(e,i)}))||[]).length>0)return this.handleOnUserSubStreamAvailable(i,!0),[2];if(this.isSharedStream(i)&&i.slice(6)===this.userId)return[2];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 f(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.client.subscribe(e,{audio:!!re(t.audio)||t.audio,video:!!re(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 f(this,(function(r){switch(r.label){case 0:return t=e.stream.getUserId(),(i=this.getStreamType(e.stream))!==j?[3,2]:((Array.from(this.remoteUserAvailable.keys())||[]).filter((function(e){return ce(e,t)}))||[]).length>0?(this.handleOnUserSubStreamAvailable(t,!1),[2]):[4,this.handleOnUserAudioAvailable(t,!1,i)];case 1:return r.sent(),this.handleOnUserVideoAvailable(t,!1),[3,3];case 2:i===q&&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;return f(this,(function(o){switch(o.label){case 0:return t=e.stream,i=t.getUserId(),(r=this.getStreamType(t))===q?[2]:!t.hasAudio()||this.remoteUserAvailable.get(i).isAudioAvailable?[3,2]:[4,this.handleOnUserAudioAvailable(i,!0,r)];case 1:o.sent(),o.label=2;case 2:if(t.hasVideo()&&!this.remoteUserAvailable.get(i).isVideoAvailable){if(((Array.from(this.remoteUserAvailable.keys())||[]).filter((function(e){return ce(e,i)}))||[]).length>0)return this.handleOnUserSubStreamAvailable(i,!0),[2];if(this.isSharedStream(i)&&i.slice(6)===this.userId)return[2];this.handleOnUserVideoAvailable(i,!0)}return[2]}}))}))},i.prototype.handleMuteAudio=function(e){return v(this,void 0,void 0,(function(){var t;return f(this,(function(i){switch(i.label){case 0:return t=e.userId,this.isSharedStream(t)?[2]:t?[4,this.handleOnUserAudioAvailable(t,!1,j)]:[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 f(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,j)];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 ce(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,n=r.framesEncoded-t.prevLocalVideoStats.framesEncoded,a=r.frameWidth,s=r.frameHeight;o<0&&(o=0),n<0&&(n=0),t.prevLocalVideoStats=r;var c=Number((8*o/1e3/2).toFixed()),l=Number((n/2).toFixed()),u=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig;return new D(a,s,l,c,0,0,u)}))},i.prototype.handleNetworkQuality=function(e){return v(this,void 0,void 0,(function(){var t,i,r,o,n,a,s,c,l;return f(this,(function(u){switch(u.label){case 0:return t=e.uplinkNetworkQuality,i=e.uplinkRTT,r=e.uplinkLoss,o=e.downlinkRTT,n=e.downlinkLoss,a=this.client?this.client.getUserId():"",s=new I(a,t,t,i,r,o,n),this.emit("onNetworkQuality",s),[4,this.getLocalStatistics()];case 1:return c=u.sent(),l=new L(r,n,0,0,i,0,0,[c]),this.emit("onStatistics",l),[2]}}))}))},i.prototype.handleDeviceChange=function(){return v(this,void 0,void 0,(function(){var t=this;return f(this,(function(i){return this.TRTC.getCameras().then((function(i){return v(t,void 0,void 0,(function(){return f(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 f(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 f(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,n,a,s,c;return f(this,(function(l){switch(l.label){case 0:return t.length===i.length?[3,8]:(o=(i||[]).map((function(e){return e.deviceId})),n=new R,a=e.TRTCDeviceState.TRTCDeviceStateAdd,t.length>i.length&&(n=t.filter((function(e){return!o.includes(e.deviceId)}))[0]||{},a=e.TRTCDeviceState.TRTCDeviceStateRemove),t.length<i.length&&(o=(t||[]).map((function(e){return e.deviceId})),n=i.filter((function(e){return!o.includes(e.deviceId)}))[0]||{}),s=n.deviceId,this.emitOnDeviceChange(s,r,a),a!==e.TRTCDeviceState.TRTCDeviceStateAdd?[3,2]:[4,this.autoChangeDevice(r,a,s)]);case 1:return l.sent(),[3,8];case 2:return a!==e.TRTCDeviceState.TRTCDeviceStateRemove?[3,8]:s!==this.currentSpeakerId&&s!==this.currentMicId?[3,5]:(c=this.getDefaultDeviceInfo(i)).deviceId?[4,this.autoChangeDevice(r,a,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,a,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 i,o=this;return f(this,(function(n){switch(n.label){case 0:return t===e.TRTCDeviceType.TRTCDeviceTypeCamera&&(this.currentCameraId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive)),t!==e.TRTCDeviceType.TRTCDeviceTypeMic?[3,3]:this.localStream?[4,this.localStream.switchDevice(x,r)]:[3,2];case 1:n.sent(),n.label=2;case 2:this.currentMicId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),n.label=3;case 3:return t!==e.TRTCDeviceType.TRTCDeviceTypeSpeaker?[3,6]:this.remoteStreamMap.size>0?(i=this.getRemoteStreamList(),[4,Promise.all(i.map((function(e){return v(o,void 0,void 0,(function(){return f(this,(function(t){switch(t.label){case 0:return[4,e.setAudioOutput(r)];case 1:return[2,t.sent()]}}))}))})))]):[3,5];case 4:n.sent(),n.label=5;case 5:this.currentSpeakerId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),n.label=6;case 6: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 R;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}))[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===j&&(i=q),i},i.prototype.isSharedStream=function(e){return e.slice(0,6)===X},i}(ae(t.EventEmitter,le,Ce,Re,ye,be,ge,Ve));e.Rect=O,e.TRTCDeviceInfo=R,e.TRTCImageBuffer=F,e.TRTCLocalStatistics=D,e.TRTCNetQualityInfo=I,e.TRTCNetworkQosParam=U,e.TRTCParams=b,e.TRTCPublishCDNParam=E,e.TRTCRenderParams=A,e.TRTCScreenCaptureSourceInfo=N,e.TRTCStatistics=L,e.TRTCVideoEncParam=g,e.TRTCVolumeInfo=M,e.default=we,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);
1
+ var global,factory;global=this,factory=function(e,t,i){function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(i),a=function(e,t){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},a(e,t)};function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");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 f,R,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,(f=e.TRTCDeviceState||(e.TRTCDeviceState={}))[f.TRTCDeviceStateAdd=0]="TRTCDeviceStateAdd",f[f.TRTCDeviceStateRemove=1]="TRTCDeviceStateRemove",f[f.TRTCDeviceStateActive=2]="TRTCDeviceStateActive",e.TRTCDeviceType=void 0,(R=e.TRTCDeviceType||(e.TRTCDeviceType={}))[R.TRTCDeviceTypeUnknow=-1]="TRTCDeviceTypeUnknow",R[R.TRTCDeviceTypeMic=0]="TRTCDeviceTypeMic",R[R.TRTCDeviceTypeSpeaker=1]="TRTCDeviceTypeSpeaker",R[R.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=40),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 V,A=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,(V=e.TRTCQuality||(e.TRTCQuality={}))[V.TRTCQuality_Unknown=0]="TRTCQuality_Unknown",V[V.TRTCQuality_Excellent=1]="TRTCQuality_Excellent",V[V.TRTCQuality_Good=2]="TRTCQuality_Good",V[V.TRTCQuality_Poor=3]="TRTCQuality_Poor",V[V.TRTCQuality_Bad=4]="TRTCQuality_Bad",V[V.TRTCQuality_Vbad=5]="TRTCQuality_Vbad",V[V.TRTCQuality_Down=6]="TRTCQuality_Down";var _,P,w,M=function(t,i){void 0===t&&(t=""),void 0===i&&(i=e.TRTCQuality.TRTCQuality_Unknown),this.userId=t,this.quality=i},I=function(e,t){void 0===e&&(e=""),void 0===t&&(t=0),this.userId=e,this.volume=t},E=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,(w=e.TRTCQosControlMode||(e.TRTCQosControlMode={}))[w.TRTCQosControlModeClient=0]="TRTCQosControlModeClient",w[w.TRTCQosControlModeServer=1]="TRTCQosControlModeServer";var k,F=function(t,i){void 0===t&&(t=e.TRTCVideoQosPreference.TRTCVideoQosPreferenceClear),void 0===i&&(i=e.TRTCQosControlMode.TRTCQosControlModeServer),this.preference=t,this.controlMode=i},U=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 Q,O=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 U),void 0===a&&(a=new U),void 0===s&&(s=!1),this.type=t,this.sourceId=i,this.sourceName=r,this.thumbBGRA=o,this.iconBGRA=a,this.isMinimizeWindow=s},B=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},x="default",N="video",J="audio",j="onError",z="main",W="rtc",H="live",K="anchor",q="audience",G="auxiliary",X="share_",Y="number",Z={20:K,21:q},$={0:W,1:H,2:W,3:H},ee={0:"standard",1:"high",2:"standard_stereo",3:"high_stereo"},te={0:"big",1:"small",2:G};function ie(){return Math.floor(performance.now())}!function(e){e[e.ActiveExitRoom=0]="ActiveExitRoom",e[e.KickedExitRoom=1]="KickedExitRoom"}(Q||(Q={}));var re=function(e){return void 0===e};function oe(e){return"".concat(e,"-").concat(z)}function ae(e){return"".concat(e,"-").concat(G)}function se(){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++)ne(this,new(0,i[t])(this))},r=i.prototype,o=0,a=e;o<a.length;o++){var s=a[o];ne(i,s),ne(r,s.prototype)}return i}function ne(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 ce(e,t){return void 0===e&&(e=""),t==="share_".concat(e)}var le=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=W,i.role=K,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,f;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)},f=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,f,m):f(),[3,3];case 3:return[2]}}))}))};return new Promise(d)}},i}(t.EventEmitter),ue=-1e3,he={code:-1001,message:"参数错误, 请检查参数格式、是否非空等"},de={code:-1002,message:"进房失败:进房中或已进房"},me={code:-1003,message:"退房失败:未进房或退房中"},Te={code:-1004,message:"调用该函数所需要条件不满足"},pe={code:-1005,message:"not supported"},ve={code:-1006,message:"not supported before join room"},Se={code:-1007,message:"进房 userId 不能包含前缀 share_"},fe={code:-1009,message:"不支持小流推屏幕分享"},Re=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:Te,message:"".concat(Te.message," - client = ").concat(this.client)}),[2]):(this.log_.error("(startPublishing) failed - ".concat(this.isPublished)),this.emitError({conditionsError:Te,message:"".concat(Te.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:Te,message:"".concat(Te.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(he),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:Te,message:"".concat(Te.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}(se(le)),ye=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(N)?(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,re(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(he),this.log_.error("(startLocalPreview) failed - ".concat(he.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(N)];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&&!re(i)&&r in e.TRTCVideoStreamType?(o=r,a=oe(t),r===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub?(a=ae("".concat(X).concat(t)),this.remoteStreamMap.has(a)||(a=ae(t)),o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig):this.isSmallStreamSupported||(o=e.TRTCVideoStreamType.TRTCVideoStreamTypeBig),s=te[o],this.remoteStreamMap.has(a)?(n=this.remoteStreamMap.get(a),s===G?[3,3]:this.client?[4,this.client.setRemoteVideoStreamType(n,o)]:[3,2]):[3,6]):(this.emitError(he),this.log_.error("(startRemoteView) failed - ".concat(he.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=oe(t),o=i,re(i)||(o=this.priorRemoteVideoStreamType),console.log("stopRemoteView streamType: ",o),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(r=ae("".concat(X).concat(t)),this.remoteStreamMap.has(r)||(r=ae(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(he),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(he.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(oe(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=oe(t),i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSub&&(a=ae(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}(se(le)),Ce=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,re(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(ee[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(J)];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(he),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(he.message,": userId = ").concat(e));var i=this.remoteStreamMap.get(oe(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(he),void this.log_.error("(muteRemoteVideoStream) failed - ".concat(he.message,": userId = ").concat(e,", volume = ").concat(t));var i=this.remoteStreamMap.get(oe(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}(se(le)),ge=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||"",this.localStream?[4,this.localStream.switchDevice(N,t)]:[3,2]):[2,Promise.resolve(!1)];case 1:r.sent(),this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeCamera,e.TRTCDeviceState.TRTCDeviceStateActive),r.label=2;case 2:return this.localPlayStream?[4,this.localPlayStream.switchDevice(N,t)]:[3,4];case 3:r.sent(),r.label=4;case 4:return this.testCameraStream?[4,this.testCameraStream.switchDevice("video",t)]:[3,6];case 5:r.sent(),r.label=6;case 6:return[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}(se(le)),be=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.localStream?this.localStream&&this.currentMicId!==t?[4,this.localStream.switchDevice(J,t)]:[3,2]:[2,Promise.resolve(!0)]:[2,Promise.resolve(!1)];case 1:r.sent(),this.currentMicId=t||"",this.emitOnDeviceChange(t,e.TRTCDeviceType.TRTCDeviceTypeMic,e.TRTCDeviceState.TRTCDeviceStateActive),r.label=2;case 2:return this.localPlayStream&&this.currentMicId!==t?[4,this.localPlayStream.switchDevice(J,t)]:[3,4];case 3:r.sent(),r.label=4;case 4:return[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}(se(le)),Ve=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.startScreenCapture=function(){this.emitError(pe)},i.prototype.pauseScreenCapture=function(){this.emitError(pe)},i.prototype.resumeScreenCapture=function(){this.emitError(pe)},i.prototype.getScreenCaptureSources=function(){this.emitError(pe)},i.prototype.selectScreenCaptureTarget=function(){this.emitError(pe)},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(ve),[2];if(i===e.TRTCVideoStreamType.TRTCVideoStreamTypeSmall)return this.emitError(fe),[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}(se(le)),Ae=null,_e=function(t){function i(){var e,i,r,o=t.call(this)||this;return o.enableAudioVolumeInterval=0,o.enableAudioVolumeTimer=-1,o.frameWorkType=40,o.VERSION="1.0.3",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.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 Ae||(Ae=new i),Ae},i.destroyTRTCShareInstance=function(){Ae&&(Ae.destroy(),Ae=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;return S(this,(function(T){switch(T.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,!(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=$[t],this.role=Z[n],this.remoteUserAvailable=new Map,u&&typeof u===Y&&(this.frameWorkType=u),this.isSharedStream(r))return this.log_.error("(enterRoom) failed - ".concat(Se.message," userId: ").concat(this.userId)),this.emitError(Se),[2];if(this.isJoining||this.isJoined)return this.log_.error("(enterRoom) failed - ".concat(de.message," isJoining: ").concat(this.isJoining,", isJoined: ").concat(this.isJoined)),this.emitError(de),[2];T.label=1;case 1:return T.trys.push([1,4,,5]),this.isJoining=!0,h={sdkAppId:i,userId:r,userSig:o,mode:this.mode,useStringRoomId:this.useStringRoomId,frameWorkType:this.frameWorkType},h=c?p(p({},h),{privateMapKey:c}):h,h=l?p(p({},h),{streamId:l}):h,this.initClient(h),this.startJoinTimestamp=ie(),[4,this.client.join({roomId:this.realRoomId,role:this.role})];case 2:return T.sent(),this.isJoined=!0,this.isJoining=!1,this.joinedTimestamp=ie(),d=this.joinedTimestamp-this.startJoinTimestamp,this.emit("onEnterRoom",d),this.log_.info("(enterRoom) success - enter room"),[4,this.publishLocalStream()];case 3:return T.sent(),[3,5];case 4:return m=T.sent(),this.isJoining=!1,this.emit("onEnterRoom",-1),this.callFunctionErrorManage(m,"enterRoom"),[3,5];case 5:return[3,7];case 6:this.emitError(he),this.log_.error("(enterRoom) failed - ".concat(he.message,": ").concat(JSON.stringify(e))),T.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(me.message," isJoined: ").concat(this.isJoined," isExiting: ").concat(this.isExiting)),this.emitError(me),[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",Q.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===W?(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(Z[t])];case 2:return r.sent(),this.role=Z[t],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(Z[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(j,e.getCode(),e.message_),this.log_.error("(".concat(t,") failed - ").concat(e.message_))):(this.emit(j,ue,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===H&&i===q)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(),l.label=4;case 4:return this.isPublishing=!1,this.isPublished=!0,this.enableAudioVolumeTimer&&clearInterval(this.enableAudioVolumeTimer),this.log_.info("(publishLocalStream) success - publish stream"),[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(he),!this.localStream)return!1;switch(e){case N:return!!this.localStream.getVideoTrack();case J: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",Q.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(j,e.code,e.message)},i.prototype.handleError=function(e){this.log_.error("handle error observed ".concat(e)),this.emit(j,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}),ce(this.userId,t)||(i.filter((function(e){return ce(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(he)}},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!==G?[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:!!re(t.audio)||t.audio,video:!!re(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())!==z?[3,2]:[4,this.handleOnUserAudioAvailable(t,!1,i)];case 1:return r.sent(),this.handleOnUserVideoAvailable(t,!1),[3,3];case 2:i===G&&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())===G?[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,z)]:[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,z)];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 ce(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 M(s,t),this.remoteStreamMap.size>0&&(c=(c=Array.from(this.remoteStreamMap.keys())).map((function(e){return e.includes("-".concat(z))?e.split("-".concat(z))[0]:e.includes("-".concat(G))?e.split("-".concat(G))[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 i,o=this;return S(this,(function(a){switch(a.label){case 0:return t===e.TRTCDeviceType.TRTCDeviceTypeCamera&&(this.currentCameraId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive)),t!==e.TRTCDeviceType.TRTCDeviceTypeMic?[3,3]:this.localStream?[4,this.localStream.switchDevice(J,r)]:[3,2];case 1:a.sent(),a.label=2;case 2:this.currentMicId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),a.label=3;case 3:return t!==e.TRTCDeviceType.TRTCDeviceTypeSpeaker?[3,6]:this.remoteStreamMap.size>0?(i=this.getRemoteStreamList(),[4,Promise.all(i.map((function(e){return v(o,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,5];case 4:a.sent(),a.label=5;case 5:this.currentSpeakerId=r,this.emitOnDeviceChange(r,t,e.TRTCDeviceState.TRTCDeviceStateActive),a.label=6;case 6: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!==x}))[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===z&&(i=G),i},i.prototype.isSharedStream=function(e){return e.slice(0,6)===X},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(ee[i||e.TRTCAudioQuality.TRTCAudioQualityDefault]),[4,a.initialize()]);case 1:return c.sent(),r?(s=a.getAudioTrack(),this.localPlayStream?this.localPlayStream.hasAudio()?[4,this.localPlayStream.replaceTrack(s)]:[3,3]:[3,6]):[3,7];case 2:return c.sent(),[3,5];case 3:return[4,this.localPlayStream.addTrack(s)];case 4:c.sent(),c.label=5;case 5:return[3,7];case 6:this.localPlayStream=a,c.label=7;case 7:return o?(n=a.getVideoTrack(),this.localPlayStream?this.localPlayStream.hasVideo()?[4,this.localPlayStream.replaceTrack(n)]:[3,9]:[3,12]):[3,13];case 8:return c.sent(),[3,11];case 9:return[4,this.localPlayStream.addTrack(n)];case 10:c.sent(),c.label=11;case 11:return[3,13];case 12:this.localPlayStream=a,c.label=13;case 13: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!==N?[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===J&&(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}(se(t.EventEmitter,le,Re,ye,Ce,ge,be,Ve));e.Rect=B,e.TRTCDeviceInfo=y,e.TRTCImageBuffer=U,e.TRTCLocalStatistics=D,e.TRTCNetworkQosParam=F,e.TRTCParams=g,e.TRTCPublishCDNParam=E,e.TRTCQualityInfo=M,e.TRTCRenderParams=A,e.TRTCScreenCaptureSourceInfo=O,e.TRTCStatistics=L,e.TRTCVideoEncParam=b,e.TRTCVolumeInfo=I,e.default=_e,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);