aliyun-rtc-sdk 6.11.3 → 6.11.4
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/dist/aliyun-rtc-sdk.js +8 -8
- package/dist/plugins/beautyPlugin.d.ts +208 -0
- package/dist/plugins/beautyPlugin.js +1 -19135
- package/dist/types/index.d.ts +3 -0
- package/package.json +4 -40
- package/dist/plugins/Empty-FmFgRqLi.js +0 -1
- package/dist/plugins/queen-FlAAeipC.js +0 -1
- package/dist/plugins/queen-full-DgUzXXaA.js +0 -1
- package/dist/plugins/queen-lite-BcW1Sf7f.js +0 -1
- package/dist/plugins/queen-pro-BF2LwKO0.js +0 -1
- package/dist/plugins/queen-simd-DQQCU-XB.js +0 -1
- package/dist/plugins/queen-simd-full-CgzwfIzl.js +0 -1
- package/dist/plugins/queen-simd-lite-DfCTDs0x.js +0 -1
- package/dist/plugins/queen-simd-pro-Dp0ynTmZ.js +0 -1
package/dist/aliyun-rtc-sdk.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var no=Object.defineProperty,oo=Object.defineProperties;var co=Object.getOwnPropertyDescriptors;var qt=Object.getOwnPropertySymbols,uo=Object.getPrototypeOf,rr=Object.prototype.hasOwnProperty,ar=Object.prototype.propertyIsEnumerable,ho=Reflect.get;var Ui=(_,P,N)=>P in _?no(_,P,{enumerable:!0,configurable:!0,writable:!0,value:N}):_[P]=N,W=(_,P)=>{for(var N in P||(P={}))rr.call(P,N)&&Ui(_,N,P[N]);if(qt)for(var N of qt(P))ar.call(P,N)&&Ui(_,N,P[N]);return _},qe=(_,P)=>oo(_,co(P));var nr=(_,P)=>{var N={};for(var J in _)rr.call(_,J)&&P.indexOf(J)<0&&(N[J]=_[J]);if(_!=null&&qt)for(var J of qt(_))P.indexOf(J)<0&&ar.call(_,J)&&(N[J]=_[J]);return N};var c=(_,P,N)=>(Ui(_,typeof P!="symbol"?P+"":P,N),N);var xi=(_,P,N)=>ho(uo(_),N,P);var S=(_,P,N)=>new Promise((J,dt)=>{var H=ge=>{try{w(N.next(ge))}catch(_e){dt(_e)}},ie=ge=>{try{w(N.throw(ge))}catch(_e){dt(_e)}},w=ge=>ge.done?J(ge.value):Promise.resolve(ge.value).then(H,ie);w((N=N.apply(_,P)).next())});(function(_,P){typeof exports=="object"&&typeof module!="undefined"?P(exports,require("aliyun-rts-sdk"),require("useragent-util"),require("eventemitter3"),require("browser-log-reporter")):typeof define=="function"&&define.amd?define(["exports","aliyun-rts-sdk","useragent-util","eventemitter3","browser-log-reporter"],P):(_=typeof globalThis!="undefined"?globalThis:_||self,P(_.AliRtcEngine={},_.AliyunRts,_.UserAgentUtil,_.EventEmitter,_.BrowserLogReporter))})(this,function(_,P,N,J,dt){var he,Fe,je,y;"use strict";var H=(i=>(i.PullStreamStats="remoteStat",i.RtsSubscribeExceeds="rtsSubscribeExceeds",i.UserJoined="userJoined",i.UserLeft="userLeft",i.Bye="bye",i.MuteAudio="muteAudio",i.UnmuteAudio="unmuteAudio",i.MuteVideo="muteVideo",i.UnmuteVideo="unmuteVideo",i.MuteScreen="muteScreen",i.UnmuteScreen="unmuteScreen",i.Error="error",i))(H||{}),ie=(i=>(i.Local="local-device-status-change",i.Remote="remote-device-status-change",i))(ie||{}),w=(i=>(i.Audio="sophon_audio",i.VideoLarge="sophon_video_camera_large",i.VideoSmall="sophon_video_camera_small",i.Screen="sophon_video_screen_share",i))(w||{}),ge=(i=>(i.Audio="rts audio",i.VideoLarge="rts video",i))(ge||{}),_e=(i=>(i[i.Camera=0]="Camera",i[i.Screen=1]="Screen",i[i.Image=2]="Image",i))(_e||{}),pt=(i=>(i[i.Microphone=0]="Microphone",i[i.Screen=1]="Screen",i[i.Mixed=2]="Mixed",i))(pt||{}),mt=(i=>(i.prod="rs.rtn.aliyuncs.com",i.pre="prs.rtn.aliyuncs.com",i))(mt||{});const Ge="6.11.3",Bi="web";class Ae{static getVersionNumber(){let s=Ge.split("."),e="";return s.forEach(t=>{t.length===1?e+="0"+t:e+=t}),parseInt(e)}static queryingParam(s){let e=[];if(s)for(let t in s)e.push(t+"="+s[t]);return e.join("&")}static getQueryParams(s){const t=window.location.search.substring(1).split("&");for(let r=0;r<t.length;r++){const a=t[r].split("=");if(decodeURIComponent(a[0])===s)return decodeURIComponent(a[1])}}static createCallid(){return N.Guid.create(8)+"-"+N.Guid.create(4)+"-4"+N.Guid.create(3)+"-"+N.Guid.create(4)}static checkSubOptionsValid(s){if(s){const{audio:e,video:t,screen:r}=s;if(e===!1&&t===!1&&r===!1)return!1}return!0}static isNetworkAvailable(){return S(this,null,function*(){const s=mt.prod,{onLine:e}=navigator;if(!e)return!1;try{return yield fetch(`https://${s}/roomserver/v1/ws/version`),!0}catch(t){return!1}})}}var Gt=(i=>(i[i.DEBUG=0]="DEBUG",i[i.INFO=1]="INFO",i[i.API=2]="API",i[i.WARNING=3]="WARNING",i[i.ERROR=4]="ERROR",i[i.NONE=5]="NONE",i))(Gt||{});class de{constructor(s,e,t){c(this,"logLevel");c(this,"outputToConsole");c(this,"maxLogLength");c(this,"maxlogCache");c(this,"uri");c(this,"requestTimeout");c(this,"delay");c(this,"rate");c(this,"hugeBatchCount");c(this,"checkInterval");c(this,"flushModecheckInterval");c(this,"recordOverheadLength");c(this,"httpRequest");c(this,"traceId");c(this,"traceIdPostfix");c(this,"flushMode");c(this,"outputToServer");c(this,"batchCount");c(this,"msgCounter");c(this,"lastRequestTime");c(this,"enable");c(this,"retx");c(this,"lastProfilingTime");c(this,"bytesOut");c(this,"dropped");c(this,"networkdropped");c(this,"lastLogTime",0);c(this,"logArray");c(this,"onTimer",()=>{if(!this.enable)return;this.processCachedLogs();let s=Date.now(),e=s-this.lastLogTime>1e4;if(s-this.lastProfilingTime>=5e3&&!e){let r=this.getProfiling();this.logInternal("[logger] profiling result: "+de.toString(r))}let t=this.flushMode?this.flushModecheckInterval:this.checkInterval;e&&(t=this.checkInterval),setTimeout(this.onTimer,t)});this.logLevel=3,this.maxLogLength=12e3,this.requestTimeout=5e3,this.delay=2e3,this.rate=3,this.maxlogCache=1e3,this.hugeBatchCount=100,this.outputToConsole=!0,this.outputToServer=!1,this.checkInterval=1e3,this.flushModecheckInterval=200,this.recordOverheadLength=120,this.flushMode=!1,this.batchCount=0,this.retx=[],this.lastProfilingTime=Date.now(),this.bytesOut=0,this.dropped=0,this.networkdropped=0,window&&window.location&&window.location.protocol&&window.location.protocol==="http:"?this.uri="http://"+e+"."+s+"/logstores/"+t+"/track":this.uri="https://"+e+"."+s+"/logstores/"+t+"/track",this.httpRequest=null,this.msgCounter=0,this.traceIdPostfix=N.LocalStorage.uuid+"-"+Date.now(),this.traceId="",this.logArray=[],this.enable=!0,this.lastRequestTime=0,this.onTimer()}static toString(s){let e;if(s instanceof Error)e=s.message;else if(typeof s=="string")e=s;else try{e=JSON.stringify(s)}catch(t){e="undefined"}return e}changeConfig(s){s.enable!==void 0&&(this.enable=s.enable,this.enable||this.clear()),s.logLevel!==void 0&&s.logLevel>=0&&s.logLevel<=5&&(this.logLevel=s.logLevel),s.logToConsole!==void 0&&(this.outputToConsole=s.logToConsole),s.logToServer!==void 0&&(this.outputToServer=s.logToServer),s.maxLogLength!==void 0&&s.maxLogLength>10&&(this.maxLogLength=s.maxLogLength),s.maxlogCache!==void 0&&s.maxlogCache>10&&s.maxlogCache<2e4&&(this.maxlogCache=s.maxlogCache),s.requestTimeout!==void 0&&s.requestTimeout>100&&s.requestTimeout<1e5&&(this.requestTimeout=s.requestTimeout),s.delay!==void 0&&s.delay>0&&s.delay<1e5&&(this.delay=s.delay),s.rate!==void 0&&s.rate>0&&s.rate<1e4&&(this.rate=s.rate)}getProfiling(){let s={enable:this.enable,flush:this.flushMode,cache:this.logArray.length,drop:this.dropped,dropNw:this.networkdropped,kbps:0},e=Date.now();return e-this.lastProfilingTime>500?(s.kbps=Math.round(this.bytesOut*8/(e-this.lastProfilingTime)),this.lastProfilingTime=e,this.bytesOut=0):s.kbps=-1,s}clear(){this.retx=[],this.logArray=[]}setFlushMode(s){this.enable&&(this.flushMode=s,this.flushMode&&this.processCachedLogs())}setTraceID(s){s&&(s.length>64&&(s=s.substring(0,64)),this.traceId=s)}d(...s){if(!this.enable||this.logLevel>0)return;let e=this.getCurrentTime();this.outputToConsole&&console.debug(e,...s);let t=de.paramArrayToString(s);this.addLog(0,t,!1,e)}i(...s){if(!this.enable||this.logLevel>1)return;let e=this.getCurrentTime();this.outputToConsole&&console.log(e,...s);let t=de.paramArrayToString(s);this.addLog(1,t,!1,e)}w(...s){if(!this.enable||this.logLevel>3)return;let e=this.getCurrentTime();this.outputToConsole&&console.warn(e,...s);let t=de.paramArrayToString(s);this.addLog(3,t,!1,e)}e(...s){if(!this.enable||this.logLevel>4)return;let e=this.getCurrentTime();this.outputToConsole&&console.error(e,...s);let t=de.paramArrayToString(s);t="<error> "+t,this.addLog(4,t,!1,e)}ev(...s){if(!this.enable||this.logLevel>2)return;let e=this.getCurrentTime();this.outputToConsole&&console.log(e,...s);let t=de.paramArrayToString(s);this.addLog(2,t,!1,e)}a(...s){if(!this.enable||this.logLevel>2)return;let e=this.getCurrentTime();if(this.outputToConsole){if(s.length>2){const r=`${s[1]}`;r.startsWith("__g__")&&console.group(`${r.substring(5)}_${s[2]}`)}console.log(e,...s)}let t=de.paramArrayToString(s);this.addLog(2,t,!1,e)}ar(...s){if(!this.enable||this.logLevel>2)return;let e=this.getCurrentTime();this.outputToConsole&&(console.log(e,...s),s.length>2&&`${s[1]}`.startsWith("__g__")&&console.groupEnd());let t=de.paramArrayToString(s);this.addLog(2,t,!1,e)}ae(...s){if(!this.enable||this.logLevel>4)return;let e=this.getCurrentTime();this.outputToConsole&&(console.error(e,...s),this.logLevel>2&&s.length>2&&console.groupEnd());let t=de.paramArrayToString(s);t="<error> "+t,this.addLog(4,t,!1,e)}logInternal(s){if(!this.enable||this.logLevel>3)return;let e=this.getCurrentTime();this.addLog(2,s,!0,e)}addLog(s,e,t,r){e=r+" "+e,e.length>this.maxLogLength&&(e=e.substring(0,this.maxLogLength));let a=Date.now();t||(this.lastLogTime=a);let n={tm:a.toString(),level:s.toString(),msg:e,count:this.msgCounter.toString(),trace:this.traceId+"-"+this.traceIdPostfix};this.logArray.push(n),this.msgCounter++,this.logArray.length>this.maxlogCache&&this.saveMemory(this.maxlogCache-5)}saveMemory(s){let e=0,t=0;for(;this.logArray.length>s&&e<=4;){for(;t<this.logArray.length;)if(parseInt(this.logArray[t].level)===e){if(this.logArray.splice(t,1),this.dropped++,this.logArray.length<=s)break}else t++;t===this.logArray.length&&(t=0,e++)}}processCachedLogs(){if(!this.outputToServer||this.logArray.length===0&&this.retx.length===0||this.isHttpRequesting()||!this.flushMode&&Date.now()-this.lastRequestTime<this.delay)return;if(this.retx&&this.retx.length>0){let o=this.retx[0].tries?parseInt(this.retx[0].tries)+1:1;if(this.flushMode||this.retx.length<this.hugeBatchCount||o<4){let u=o.toString();for(let h=0;h<this.retx.length;h++)this.retx[h].tries=u;this.batchSend(this.retx);return}else this.retx=[],this.dropped+=this.retx.length,this.networkdropped+=this.retx.length}if(this.logArray.length===0)return;let s=this.flushMode?1.5*1024*1024:this.delay*this.rate,e=0,t=0,r=this.recordOverheadLength;for(let o=0;o<this.logArray.length&&(t+=this.logArray[o].msg.length+r,!(t>s));o++)e=o+1;e===0&&(e=1);let a=this.logArray.splice(0,e);this.batchCount++;let n=this.batchCount.toString();for(let o=0;o<a.length;o++)a[o].batch=n,a[o].tries="0";this.retx=a,this.batchSend(a)}createHttpRequest(){this.httpRequest||window.XMLHttpRequest&&(this.httpRequest=new XMLHttpRequest)}isHttpRequesting(){return this.httpRequest!==null}batchSend(s){if(this.isHttpRequesting())return;this.lastRequestTime=Date.now();let e=this.uri,t=JSON.stringify(s);t='{"__logs__":'+t+"}",this.createHttpRequest(),this.isHttpRequesting()&&(this.bytesOut+=t.length,this.httpRequest.open("POST",e,!0),this.httpRequest.timeout=this.requestTimeout,this.httpRequest.setRequestHeader("x-log-apiversion","0.6.0"),this.httpRequest.setRequestHeader("x-log-bodyrawsize",t.length),this.httpRequest.onload=()=>{this.httpRequest.status!==200&&console.log("Error: failed to post log ",this.httpRequest),this.retx=[],this.lastRequestTime=Date.now(),this.httpRequest=null},this.httpRequest.onerror=()=>{console.log("Error: post log failed"),this.lastRequestTime=Date.now(),this.httpRequest=null},this.httpRequest.onabort=()=>{console.log("Error: post log aborted"),this.lastRequestTime=Date.now(),this.httpRequest=null},this.httpRequest.send(t))}getCurrentTime(){let s=new Date;return s.getFullYear()+"-"+("00"+(s.getMonth()+1)).slice(-2)+"-"+("00"+s.getDate()).slice(-2)+" "+("00"+s.getHours()).slice(-2)+":"+("00"+s.getMinutes()).slice(-2)+":"+("00"+s.getSeconds()).slice(-2)+"."+("000"+s.getMilliseconds()).slice(-3)}static paramArrayToString(s){let e="";for(let t=0;t<s.length;t++){e!==""&&(e+=",");let r=de.toString(s[t]);e+=r}return e}}class I{static getLogger(){return this.logger||(this.logger=new de("cn-shanghai.log.aliyuncs.com","alirtc","client_h5")),this.logger}static setLogLevel(s){this.getLogger().changeConfig({logLevel:s})}static config(s){this.getLogger().changeConfig(s)}static setTraceID(s){this.getLogger().setTraceID(s)}static setFlushMode(s){this.getLogger().setFlushMode(s)}static interface(...s){this.getLogger().a("[API]",...s)}static interfaceResult(s,e,t,...r){t?this.getLogger().ar("[ARE]",s,e,...r):this.getLogger().ae("[ARE]",s,e,...r)}static event(...s){this.getLogger().ev("[EVT]",...s)}static debug(...s){this.getLogger().d("[DBG]",...s)}static info(...s){this.getLogger().i("[INF]",...s)}static warn(...s){this.getLogger().w("[WARN]",...s)}static error(...s){this.getLogger().e("[ERR]",...s)}}c(I,"logger");const or=i=>S(this,null,function*(){const s=new P.AliRTS.SupportUtil;let e={support:!1,detail:{isWebRTCSupported:s.checkMediaDevices()&&s.checkWebRtcSupport(),isH264DecodeSupported:!1,isH264EncodeSupported:!1,isScreenShareSupported:!1,isSendMediaExtensionMsgSupported:!1,isBrowserSupported:s.checkBrowser({errorCode:0,message:""})}};if(e.support=e.detail.isWebRTCSupported&&e.detail.isBrowserSupported,s.checkWebRtcSupport()&&i!=="sendonly"){const t=yield s.checkH264Decode();e.detail.isH264DecodeSupported=t,e.support=e.support&&t}if(s.checkWebRtcSupport()&&i!=="recvonly"){const t=yield s.checkH264Encode();e.detail.isH264EncodeSupported=t,e.support=e.support&&t}return e.detail.isScreenShareSupported=s.checkWebRtcSupport()&&s.checkScreenCapture()&&!P.AliRTS.SystenUtil.isAndroid&&!P.AliRTS.SystenUtil.isIos,e.detail.isSendMediaExtensionMsgSupported=s.checkWebRtcSupport()&&s.checkEncodedTransformSupport(),e});var ye=(i=>(i.pre="pre",i.prod="prod",i))(ye||{}),Te=(i=>(i.AliRtcSdkCommunication="communication",i.AliRtcSdkInteractiveLive="interactive_live",i.AliRtcSdkInteractiveWithLowLatencyLive="cdn_live",i))(Te||{}),Pe=(i=>(i.AliRtcSdkInteractive="interactive",i.AliRtcSdkLive="live",i))(Pe||{}),Q=(i=>(i[i.AliRtcSdkStreamTypeCapture=0]="AliRtcSdkStreamTypeCapture",i[i.AliRtcSdkStreamTypeScreen=1]="AliRtcSdkStreamTypeScreen",i))(Q||{}),we=(i=>(i[i.AliEngineLocalDeviceTypeUnknown=0]="AliEngineLocalDeviceTypeUnknown",i[i.AliEngineLocalDeviceTypeMic=1]="AliEngineLocalDeviceTypeMic",i[i.AliEngineLocalDeviceTypeSpeaker=2]="AliEngineLocalDeviceTypeSpeaker",i[i.AliEngineLocalDeviceTypeAudioDevice=3]="AliEngineLocalDeviceTypeAudioDevice",i[i.AliEngineLocalDeviceTypeCamera=4]="AliEngineLocalDeviceTypeCamera",i[i.AliEngineLocalDeviceTypeDisplay=5]="AliEngineLocalDeviceTypeDisplay",i[i.AliEngineLocalDeviceTypeVideoDevice=6]="AliEngineLocalDeviceTypeVideoDevice",i))(we||{}),X=(i=>(i[i.AliEngineLocalDeviceExceptionTypeUnknown=0]="AliEngineLocalDeviceExceptionTypeUnknown",i[i.AliEngineLocalDeviceExceptionTypeMicOpenFail=1]="AliEngineLocalDeviceExceptionTypeMicOpenFail",i[i.AliEngineLocalDeviceExceptionTypeMicInterrupt=2]="AliEngineLocalDeviceExceptionTypeMicInterrupt",i[i.AliEngineLocalDeviceExceptionTypeMicAuthFail=3]="AliEngineLocalDeviceExceptionTypeMicAuthFail",i[i.AliEngineLocalDeviceExceptionTypeMicNotAvailable=4]="AliEngineLocalDeviceExceptionTypeMicNotAvailable",i[i.AliEngineLocalDeviceExceptionTypeSpeakerOpenFail=5]="AliEngineLocalDeviceExceptionTypeSpeakerOpenFail",i[i.AliEngineLocalDeviceExceptionTypeSpeakerInterrupt=6]="AliEngineLocalDeviceExceptionTypeSpeakerInterrupt",i[i.AliEngineLocalDeviceExceptionTypeSpeakerNotAvailable=7]="AliEngineLocalDeviceExceptionTypeSpeakerNotAvailable",i[i.AliEngineLocalDeviceExceptionTypeAudioDeviceException=8]="AliEngineLocalDeviceExceptionTypeAudioDeviceException",i[i.AliEngineLocalDeviceExceptionTypeCameraOpenFail=9]="AliEngineLocalDeviceExceptionTypeCameraOpenFail",i[i.AliEngineLocalDeviceExceptionTypeCameraInterrupt=10]="AliEngineLocalDeviceExceptionTypeCameraInterrupt",i[i.AliEngineLocalDeviceExceptionTypeCameraAuthFail=11]="AliEngineLocalDeviceExceptionTypeCameraAuthFail",i[i.AliEngineLocalDeviceExceptionTypeDisplayException=12]="AliEngineLocalDeviceExceptionTypeDisplayException",i[i.AliEngineLocalDeviceExceptionTypeVideoDeviceException=13]="AliEngineLocalDeviceExceptionTypeVideoDeviceException",i))(X||{}),K=(i=>(i[i.AliRtcConnectionStatusInit=0]="AliRtcConnectionStatusInit",i[i.AliRtcConnectionStatusDisconnected=1]="AliRtcConnectionStatusDisconnected",i[i.AliRtcConnectionStatusConnecting=2]="AliRtcConnectionStatusConnecting",i[i.AliRtcConnectionStatusConnected=3]="AliRtcConnectionStatusConnected",i[i.AliRtcConnectionStatusReconnecting=4]="AliRtcConnectionStatusReconnecting",i[i.AliRtcConnectionStatusFailed=5]="AliRtcConnectionStatusFailed",i))(K||{}),Le=(i=>(i[i.AliRtcConnectionChangedDummyReason=0]="AliRtcConnectionChangedDummyReason",i[i.AliRtcConnectionMediaPathChanged=1]="AliRtcConnectionMediaPathChanged",i[i.AliRtcConnectionSignalingHeartbeatTimeout=2]="AliRtcConnectionSignalingHeartbeatTimeout",i[i.AliRtcConnectionSignalingHeartbeatAlive=3]="AliRtcConnectionSignalingHeartbeatAlive",i[i.AliRtcConnectionSignalingHttpDnsResolved=4]="AliRtcConnectionSignalingHttpDnsResolved",i[i.AliRtcConnectionSignalingHttpDnsFailure=5]="AliRtcConnectionSignalingHttpDnsFailure",i[i.AliRtcConnectionSignalingGslbFailure=6]="AliRtcConnectionSignalingGslbFailure",i[i.AliRtcConnectionSignalingGslbSuccess=7]="AliRtcConnectionSignalingGslbSuccess",i[i.AliRtcConnectionSignalingJoinRoomFailure=8]="AliRtcConnectionSignalingJoinRoomFailure",i[i.AliRtcConnectionSignalingJoinRoomSuccess=9]="AliRtcConnectionSignalingJoinRoomSuccess",i[i.AliRtcConnectionSignalingLeaveRoom=10]="AliRtcConnectionSignalingLeaveRoom",i[i.AliRtcConnectionSignalingConnecting=11]="AliRtcConnectionSignalingConnecting",i[i.AliRtcConnectionChangedNetworkInterrupted=12]="AliRtcConnectionChangedNetworkInterrupted",i))(Le||{}),zt=(i=>(i[i.AliRtcUserOfflineQuit=0]="AliRtcUserOfflineQuit",i[i.AliRtcUserOfflineDropped=1]="AliRtcUserOfflineDropped",i[i.AliRtcUserOfflineBecomeAudience=2]="AliRtcUserOfflineBecomeAudience",i))(zt||{}),He=(i=>(i[i.AliRtcAudioTrackNo=0]="AliRtcAudioTrackNo",i[i.AliRtcAudioTrackMic=1]="AliRtcAudioTrackMic",i[i.AliRtcAudioTrackDual=2]="AliRtcAudioTrackDual",i))(He||{}),x=(i=>(i[i.AliRtcVideoTrackNo=0]="AliRtcVideoTrackNo",i[i.AliRtcVideoTrackCamera=1]="AliRtcVideoTrackCamera",i[i.AliRtcVideoTrackScreen=2]="AliRtcVideoTrackScreen",i[i.AliRtcVideoTrackBoth=3]="AliRtcVideoTrackBoth",i))(x||{}),V=(i=>(i[i.AliRtcStatePublishIdle=0]="AliRtcStatePublishIdle",i[i.AliRtcStateNoPublish=1]="AliRtcStateNoPublish",i[i.AliRtcStatePublishing=2]="AliRtcStatePublishing",i[i.AliRtcStatePublished=3]="AliRtcStatePublished",i))(V||{}),G=(i=>(i[i.AliRtcStateSubscribeIdle=0]="AliRtcStateSubscribeIdle",i[i.AliRtcStateNoSubscribe=1]="AliRtcStateNoSubscribe",i[i.AliRtcStateSubscribing=2]="AliRtcStateSubscribing",i[i.AliRtcStateSubscribed=3]="AliRtcStateSubscribed",i))(G||{}),oe=(i=>(i[i.AliRtcVideoStreamTypeNone=0]="AliRtcVideoStreamTypeNone",i[i.AliRtcVideoStreamTypeHigh=1]="AliRtcVideoStreamTypeHigh",i[i.AliRtcVideoStreamTypeLow=2]="AliRtcVideoStreamTypeLow",i))(oe||{}),ze=(i=>(i[i.CAMERA_INVALID=-1]="CAMERA_INVALID",i[i.CAMERA_REAR=0]="CAMERA_REAR",i[i.CAMERA_FRONT=1]="CAMERA_FRONT",i))(ze||{}),Fi=(i=>(i[i.PRE_PROCESSOR=0]="PRE_PROCESSOR",i[i.POST_PROCESSOR=1]="POST_PROCESSOR",i))(Fi||{}),gt=(i=>(i[i.AUDIO=0]="AUDIO",i[i.VIDEO=1]="VIDEO",i[i.BOTH=2]="BOTH",i))(gt||{});class We extends J{constructor(e,t=Q.AliRtcSdkStreamTypeCapture,r=1){super();c(this,"name");c(this,"options");c(this,"type",0);c(this,"streamType");c(this,"trackType");c(this,"zIndex",1);c(this,"_isEnable",!0);c(this,"lastInputAudioTrack");c(this,"lastOutputAudioTrack");c(this,"lastInputVideoTrack");c(this,"lastOutputVideoTrack");this.name=e,this.streamType=t,this.trackType=r,this.options=this.initOptions}get initOptions(){return{}}getOptions(){return this.options}init(){return S(this,null,function*(){})}enable(){this._isEnable||(this._isEnable=!0,this.init(),this.emit("enabled"))}disable(){this._isEnable&&(this._isEnable=!1,this.clear(),this.emit("disabled"))}get isEnable(){return this._isEnable}audioUpdated(e){var t,r;return((t=this.lastInputAudioTrack)==null?void 0:t.id)!==((r=e.currentAudioTrack)==null?void 0:r.id)}videoUpdated(e){var t,r;return((t=this.lastInputVideoTrack)==null?void 0:t.id)!==((r=e.currentVideoTrack)==null?void 0:r.id)}execute(e,t){return S(this,null,function*(){const r=this.shouldUpdate(e,t);this.lastInputAudioTrack=e.currentAudioTrack,this.lastInputVideoTrack=e.currentVideoTrack,r?yield this.process(e,t):(this.lastOutputAudioTrack&&(this.trackType===2||this.trackType===0)&&this.lastOutputAudioTrack&&e.updateAudioTrack(this.lastOutputAudioTrack),this.lastOutputVideoTrack&&(this.trackType===2||this.trackType===1)&&this.lastOutputVideoTrack&&e.updateVideoTrack(this.lastOutputVideoTrack)),this.lastOutputAudioTrack=e.currentAudioTrack,this.lastOutputVideoTrack=e.currentVideoTrack})}clear(e){this.lastInputAudioTrack=void 0,this.lastInputVideoTrack=void 0,this.lastOutputAudioTrack=void 0,this.lastOutputVideoTrack=void 0}}var Ye=(i=>(i[i.LiveTranscodingSingle=0]="LiveTranscodingSingle",i[i.LiveTranscodingMix=1]="LiveTranscodingMix",i))(Ye||{}),Yt=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingAudio=1]="LiveTranscodingAudio",i[i.LiveTranscodingVideo=2]="LiveTranscodingVideo",i))(Yt||{}),Ke=(i=>(i[i.LiveTranscodingCamera=0]="LiveTranscodingCamera",i[i.LiveTranscodingShareScreen=1]="LiveTranscodingShareScreen",i))(Ke||{});const Xe={0:"camera",1:"shareScreen"};var Xt=(i=>(i[i.LiveTranscoding_Profile_1IN_1080P=0]="LiveTranscoding_Profile_1IN_1080P",i[i.LiveTranscoding_Profile_1IN_720P=1]="LiveTranscoding_Profile_1IN_720P",i[i.LiveTranscoding_Profile_1IN_360P=2]="LiveTranscoding_Profile_1IN_360P",i[i.LiveTranscoding_Profile_2IN_1080P=3]="LiveTranscoding_Profile_2IN_1080P",i[i.LiveTranscoding_Profile_2IN_720P=4]="LiveTranscoding_Profile_2IN_720P",i[i.LiveTranscoding_Profile_2IN_360P=5]="LiveTranscoding_Profile_2IN_360P",i[i.LiveTranscoding_Profile_4IN_1080P=6]="LiveTranscoding_Profile_4IN_1080P",i[i.LiveTranscoding_Profile_4IN_720P=7]="LiveTranscoding_Profile_4IN_720P",i[i.LiveTranscoding_Profile_4IN_360P=8]="LiveTranscoding_Profile_4IN_360P",i[i.LiveTranscoding_Profile_9IN_1080P=9]="LiveTranscoding_Profile_9IN_1080P",i[i.LiveTranscoding_Profile_9IN_720P=10]="LiveTranscoding_Profile_9IN_720P",i[i.LiveTranscoding_Profile_9IN_360P=11]="LiveTranscoding_Profile_9IN_360P",i[i.LiveTranscoding_Profile_12IN_1080P=12]="LiveTranscoding_Profile_12IN_1080P",i[i.LiveTranscoding_Profile_12IN_720P=13]="LiveTranscoding_Profile_12IN_720P",i[i.LiveTranscoding_Profile_12IN_360P=14]="LiveTranscoding_Profile_12IN_360P",i[i.LiveTranscoding_Profile_16IN_1080P=15]="LiveTranscoding_Profile_16IN_1080P",i[i.LiveTranscoding_Profile_16IN_720P=16]="LiveTranscoding_Profile_16IN_720P",i[i.LiveTranscoding_Profile_16IN_360P=17]="LiveTranscoding_Profile_16IN_360P",i[i.LiveTranscoding_Profile_Mixed=9999]="LiveTranscoding_Profile_Mixed",i))(Xt||{});const cr={0:"1IN_1080P",1:"1IN_720P",2:"1IN_360P",3:"2IN_1080P",4:"2IN_720P",5:"2IN_360P",6:"4IN_1080P",7:"4IN_720P",8:"4IN_360P",9:"9IN_1080P",10:"9IN_720P",11:"9IN_360P",12:"12IN_1080P",13:"12IN_720P",14:"12IN_360P",15:"16IN_1080P",16:"16IN_720P",17:"16IN_360P",9999:"Mixed_Audio"};var St=(i=>(i[i.LiveTranscoding_HZ_48000=48e3]="LiveTranscoding_HZ_48000",i[i.LiveTranscoding_HZ_44100=44100]="LiveTranscoding_HZ_44100",i[i.LiveTranscoding_HZ_32000=32e3]="LiveTranscoding_HZ_32000",i[i.LiveTranscoding_HZ_16000=16e3]="LiveTranscoding_HZ_16000",i[i.LiveTranscoding_HZ_8000=8e3]="LiveTranscoding_HZ_8000",i))(St||{}),Ze=(i=>(i[i.LiveTranscodingNoBody=0]="LiveTranscodingNoBody",i[i.LiveTranscodingBody=1]="LiveTranscodingBody",i))(Ze||{}),Qe=(i=>(i[i.NOTO_SERIF_CJKSC_REGULAR=0]="NOTO_SERIF_CJKSC_REGULAR",i[i.ALIBABA_PUHUITI_REGULAR=1]="ALIBABA_PUHUITI_REGULAR",i[i.ALIBABA_PUHUITI_BOLD=2]="ALIBABA_PUHUITI_BOLD",i[i.ALIBABA_PUHUITI_Heavy=3]="ALIBABA_PUHUITI_Heavy",i[i.ALIBABA_PUHUITI_LIGHT=4]="ALIBABA_PUHUITI_LIGHT",i[i.ALIBABA_PUHUITI_MEDIUM=5]="ALIBABA_PUHUITI_MEDIUM",i))(Qe||{}),Zt=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingCrop=1]="LiveTranscodingCrop",i[i.LiveTranscodingFill=2]="LiveTranscodingFill",i))(Zt||{}),ft=(i=>(i[i.LiveTranscodingNormal=0]="LiveTranscodingNormal",i[i.LiveTranscodingVirtualBackground=1]="LiveTranscodingVirtualBackground",i))(ft||{}),Qt=(i=>(i[i.LiveTranscodingState_IDLE=0]="LiveTranscodingState_IDLE",i[i.LiveTranscodingState_CONNNECT=1]="LiveTranscodingState_CONNNECT",i[i.LiveTranscodingState_RUNNING=2]="LiveTranscodingState_RUNNING",i[i.LiveTranscodingState_RECOVERING=3]="LiveTranscodingState_RECOVERING",i[i.LiveTranscodingState_FAILURE=4]="LiveTranscodingState_FAILURE",i[i.LiveTranscodingState_END=5]="LiveTranscodingState_END",i))(Qt||{}),Re=(i=>(i[i.LiveTranscodingErrorPublishOk=0]="LiveTranscodingErrorPublishOk",i[i.LiveTranscodingErrorStreamNotFound=17825793]="LiveTranscodingErrorStreamNotFound",i[i.LiveTranscodingErrorStreamAlreadyExist=17825794]="LiveTranscodingErrorStreamAlreadyExist",i[i.LiveTranscodingErrorInvalidParam=17825795]="LiveTranscodingErrorInvalidParam",i[i.LiveTranscodingErrorInternalError=17825796]="LiveTranscodingErrorInternalError",i[i.LiveTranscodingErrorRtmpServerError=17825797]="LiveTranscodingErrorRtmpServerError",i[i.LiveTranscodingErrorRtmpStreamUrlError=17825798]="LiveTranscodingErrorRtmpStreamUrlError",i[i.LiveTranscodingErrorPublishTimeout=17825799]="LiveTranscodingErrorPublishTimeout",i[i.LiveTranscodingErrorNotAuthorized=17825800]="LiveTranscodingErrorNotAuthorized",i))(Re||{}),ei=(i=>(i[i.TrascodingPublishTaskStatusStart=0]="TrascodingPublishTaskStatusStart",i[i.TrascodingPublishTaskStatusUpdate=1]="TrascodingPublishTaskStatusUpdate",i[i.TrascodingPublishTaskStatusStop=2]="TrascodingPublishTaskStatusStop",i))(ei||{}),ue=(i=>(i[i.MPU_TASK_TRANSACTION_START=0]="MPU_TASK_TRANSACTION_START",i[i.MPU_TASK_TRANSACTION_UPDATE=1]="MPU_TASK_TRANSACTION_UPDATE",i[i.MPU_TASK_TRANSACTION_STOP=2]="MPU_TASK_TRANSACTION_STOP",i[i.MPU_TASK_TRANSACTION_LIST=3]="MPU_TASK_TRANSACTION_LIST",i[i.MPU_TASK_TRANSACTION_POLLING=4]="MPU_TASK_TRANSACTION_POLLING",i[i.MPU_TASK_TRANSACTION_ACKNOWLEDGE=5]="MPU_TASK_TRANSACTION_ACKNOWLEDGE",i[i.MPU_TASK_TRANSACTION_END=6]="MPU_TASK_TRANSACTION_END",i))(ue||{});const ur={0:"/libra/v1/sdk/start-task",1:"/libra/v1/sdk/update-task",2:"/libra/v1/sdk/stop-task",3:"/libra/v1/sdk/list-task",4:"/libra/v1/sdk/polling",5:"/libra/v1/sdk/acknowledge",6:"/"};class ti{constructor(s,e,t,r,a,n,o,u){c(this,"videoWidth");c(this,"videoHeight");c(this,"videoFramerate",20);c(this,"videoBitrate",2e3);c(this,"videoGop",30);c(this,"audioSamplerate",St.LiveTranscoding_HZ_44100);c(this,"audioBitrate",500);c(this,"audioChannels",1);this.videoWidth=s,this.videoHeight=e,t&&(this.videoFramerate=t),r&&(this.videoBitrate=r),a&&(this.videoGop=a),n&&(this.audioSamplerate=n),o&&(this.audioBitrate=o),u&&(this.audioChannels=u)}}const ii=i=>((i&16711680)>>16)+(i&65280)+((i&255)<<16),pe=(i=0,s)=>{if(s==0)return 0;let e=i/s;return e<0&&(e=0),e>1&&(e=1),e};class bt{constructor(s,e,t){c(this,"mixMode",Ye.LiveTranscodingSingle);c(this,"singleParam");c(this,"mixParam");s&&(this.mixMode=s),e&&(this.singleParam=e),t&&(this.mixParam=t)}toJson(s,e,t,r,a){const n={appid:e.appId,channelid:e.channelId};if(s===ue.MPU_TASK_TRANSACTION_POLLING||s===ue.MPU_TASK_TRANSACTION_LIST||s===ue.MPU_TASK_TRANSACTION_ACKNOWLEDGE)return s===ue.MPU_TASK_TRANSACTION_ACKNOWLEDGE&&(n.messageid=a),n;if(n.taskid=t,s!==ue.MPU_TASK_TRANSACTION_STOP){if(n.mixmode=this.mixMode,r&&(n.streamurl=r),this.mixMode===Ye.LiveTranscodingSingle){const o=this.singleParam;if(o){n.streamtype=o.streamType,o.sourceType===Ke.LiveTranscodingShareScreen?n.sourcetype=Xe[o.sourceType]:n.sourcetype=Xe[Ke.LiveTranscodingCamera];const u=[];o.userId&&u.push(o.userId),n.subspecusers=u}}else if(s===ue.MPU_TASK_TRANSACTION_START||s===ue.MPU_TASK_TRANSACTION_UPDATE){const o=this.mixParam;if(o){o.taskProfile&&(n.taskprofile=cr[o.taskProfile]);const u=o.encodeParam||new ti(1280,720);let h=u.videoWidth,l=u.videoHeight;const p={};Object.keys(u).forEach(m=>{const g=u[m];g>0&&(p[m.toLowerCase()]=g)}),p.lowbitratehighquality=0,n.encodeparam=p,n.backgrounds=o.backgrounds.map(m=>m.toJson(h,l)),n.watermarks=o.watermarks.map(m=>m.toJson(h,l)),n.clockwidgets=o.clockWidgets.map(m=>m.toJson(h,l));const d=o.users.map(m=>m.userId);n.subspecusers=[...new Set(d)],n.layouts=[{audiomixcount:o.users.length,panes:o.users.map((m,g)=>m.toJson(g,h,l,o.mediaProcessMode))}],n.layoutids=["0"],n.cropmode=o.cropMode,n.backgroundcolor=ii(o.backgroundColor),n.taskmode=o.mediaProcessMode}}}return n}}const Hi=10,Wi=5e3,Dt=class Dt extends J{constructor(e){super();c(this,"ws");c(this,"socketStatus",0);c(this,"wsUrl","");c(this,"lastConnectStartTime",0);c(this,"maxConnectRetryCount",Hi);c(this,"connectRetryCount",0);c(this,"gotErr",!1);c(this,"closedByInvoke",!0);c(this,"isReconnecting",!1);c(this,"networkAvailableChecked",!0);this.maxConnectRetryCount=e!=null?e:Hi,this.onOpen=this.onOpen.bind(this),this.onMessage=this.onMessage.bind(this),this.onError=this.onError.bind(this),this.onClose=this.onClose.bind(this)}get connectUrl(){return this.wsUrl}get connectStatus(){return this.socketStatus}start(e){this.wsUrl=e,this.initWebSocket()}send(e){return this.ws&&this.socketStatus===2?(this.ws.send(JSON.stringify(e)),!0):!1}close(){this.closedByInvoke=!0,this.uninitWebscoket()}reconnect(){this.emit("onReconnectStart"),this.isReconnecting=!0,this.initWebSocket()}onOpen(e){this.socketStatus=2,this.connectRetryCount=0,this.networkAvailableChecked=!1,this.closedByInvoke=!1,this.gotErr=!1,this.isReconnecting=!1,this.emit("onOpen",e)}onMessage(e){this.emit("onMessage",e)}onError(e){this.isReconnecting&&this.emit("onReconnectFail",e),this.emit("onError",e),this.isReconnecting=!1,this.gotErr=!0}onClose(e){return S(this,null,function*(){const t=this.socketStatus;if(I.info(Dt.logName,`onClose, status: ${t}, retryCount: ${this.connectRetryCount}`),t!==0||this.connectRetryCount)if(yield Ae.isNetworkAvailable()){if(!this.networkAvailableChecked&&!this.closedByInvoke&&!this.gotErr){this.reconnect();return}this.networkAvailableChecked=!0,this.emit("onAuthInvalid")}else{if(this.connectRetryCount||this.emit("onNetworkError"),this.closedByInvoke)return;this.connectRetryCount+=1,this.connectRetryCount>this.maxConnectRetryCount?this.emit("onConnectFail"):Date.now()-this.lastConnectStartTime>=Wi?this.reconnect():window.setTimeout(()=>{this.reconnect()},Wi)}this.socketStatus=0,this.emit("onClose",e)})}initWebSocket(){this.uninitWebscoket(),this.socketStatus=1,this.lastConnectStartTime=Date.now(),this.ws=new WebSocket(this.wsUrl),this.ws.addEventListener("open",this.onOpen),this.ws.addEventListener("message",this.onMessage),this.ws.addEventListener("error",this.onError),this.ws.addEventListener("close",this.onClose)}uninitWebscoket(){this.ws&&(this.ws.removeEventListener("open",this.onOpen),this.ws.removeEventListener("message",this.onMessage),this.ws.removeEventListener("error",this.onError),this.ws.removeEventListener("close",this.onClose),this.ws.close(),this.ws=void 0,this.socketStatus=0)}};c(Dt,"logName","Socket");let si=Dt;var ee=(i=>(i.KEEPALIVE="keepalive",i.JOINCHANNEL="joinchannel",i.NOTIFYJOIN="notifyjoin",i.NOTIFYSTATUS="notifystatus",i.STATUSREPORT="statusreport",i.LEAVECHANNEL="leavechannel",i.NOTIFYLEAVE="notifyleave",i.NOTIFYPUBLISH="notifypublish",i.BYE="bye",i.RECONNECT="reconnect",i.PUBLISH="publish",i.REFRESHURL="refreshurl",i.UNSUBSCRIBE="unsubscribe",i.ROLEUPDATE="roleupdate",i))(ee||{});class hr{constructor(s,e){c(this,"authInfo");c(this,"userName");c(this,"seqIndex",0);this.authInfo=s,this.userName=e}get roleAuth(){if(this.authInfo.role){const{timestamp:s,nonce:e,token:t,role:r}=this.authInfo;return{timestamp:s,nonce:e,token:t,tokenrole:r}}}refreshAuthInfo(s){this.authInfo=s}getSeqIndex(){return this.seqIndex}createKeepAlivePackage(){return this.createBaseSendPackage("keepalive")}createJoinPackage(){let s=this.createBaseSendPackage("joinchannel");return s.header.displayName=this.userName,s.header.clientversion=Ae.getVersionNumber().toString(),s.header.platform=Bi,this.roleAuth&&(s.data.auth=this.roleAuth),s}crateLeavePackage(){return this.createBaseSendPackage("leavechannel")}createStatusPackage(s){let e=this.createBaseSendPackage("statusreport");return e.header.displayName=this.userName,e.data.status=s,e}createPublishPackage(){let s=this.createBaseSendPackage("publish");return s.data.users=[{}],this.roleAuth&&(s.data.auth=this.roleAuth),s}createRoleUpdatePackage(){let s=this.createBaseSendPackage("roleupdate");return s.header.displayName=this.userName,s}createReconnectPackage(s){let e=this.createBaseSendPackage("reconnect");return e.header.displayName=this.userName,e.header.clientversion=Ae.getVersionNumber().toString(),e.header.platform=Bi,e.data=W(W({},e.data),s!=null?s:{}),this.roleAuth&&(e.data.auth=this.roleAuth),e}createRefreshUrlPackage(){let s=this.createBaseSendPackage("refreshurl");return s.header.displayName=this.userName,s}createResponsePackage(s,e){return{version:1,code:200,tid:s,msgtype:e}}createBaseSendPackage(s){var t;return++this.seqIndex,{version:1,msgtype:s,tid:N.Guid.create(32),header:{appid:this.authInfo.appId,channelid:this.authInfo.channelId,sessionid:(t=this.authInfo.callid)!=null?t:"",userid:this.authInfo.userId},data:{seq:this.seqIndex}}}}var T=(i=>(i[i.ERR_JOIN_ALREADY_JOINED=16843521]="ERR_JOIN_ALREADY_JOINED",i[i.ERR_JOIN_BAD_APPID=33620481]="ERR_JOIN_BAD_APPID",i[i.ERR_JOIN_INVALID_APPID=33620482]="ERR_JOIN_INVALID_APPID",i[i.ERR_JOIN_BAD_CHANNEL=33620484]="ERR_JOIN_BAD_CHANNEL",i[i.ERR_JOIN_INVALID_CHANNEL=33620483]="ERR_JOIN_INVALID_CHANNEL",i[i.ERR_JOIN_BAD_TOKEN=33620485]="ERR_JOIN_BAD_TOKEN",i[i.ERR_JOIN_TIMEOUT=16908804]="ERR_JOIN_TIMEOUT",i[i.ERR_JOIN_ERR_JOIN_BAD_PARAMBAD=16974081]="ERR_JOIN_ERR_JOIN_BAD_PARAMBAD",i[i.ERR_JOIN_CHANNEL_FAILED=16974338]="ERR_JOIN_CHANNEL_FAILED",i[i.ERR_LOG_ALREADY_INIT=16974085]="ERR_LOG_ALREADY_INIT",i[i.ERR_LOG_ROOT_PATH_ERROR=16974086]="ERR_LOG_ROOT_PATH_ERROR",i[i.ERR_MIC_OPEN_FAIL=17040388]="ERR_MIC_OPEN_FAIL",i[i.ERR_SPEAKER_OPEN_FAIL=17040389]="ERR_SPEAKER_OPEN_FAIL",i[i.ERR_MIC_INTERRUPT=17040390]="ERR_MIC_INTERRUPT",i[i.ERR_SPEAKER_INTERRUPT=17040391]="ERR_SPEAKER_INTERRUPT",i[i.ERR_MIC_AUTH_FAIL=17040392]="ERR_MIC_AUTH_FAIL",i[i.ERR_MIC_NOT_AVAILABLE=17040393]="ERR_MIC_NOT_AVAILABLE",i[i.ERR_SPEAKER_NO_AVAILABLE=17040400]="ERR_SPEAKER_NO_AVAILABLE",i[i.ERR_CAMERA_OPEN_FAIL=17039620]="ERR_CAMERA_OPEN_FAIL",i[i.ERR_CAMERA_INTERRUPT=17039622]="ERR_CAMERA_INTERRUPT",i[i.ERR_VIDEO_DISPLAY_OPEN_FAIL=17039873]="ERR_VIDEO_DISPLAY_OPEN_FAIL",i[i.ERR_VIDEO_DISPLAY_INTERRUPT=1064992]="ERR_VIDEO_DISPLAY_INTERRUPT",i[i.ERR_ICE_CONNECTION_CONNECT_FAIL=17105409]="ERR_ICE_CONNECTION_CONNECT_FAIL",i[i.ERR_ICE_CONNECTION_RECONNECT_FAI=17105410]="ERR_ICE_CONNECTION_RECONNECT_FAI",i[i.ERR_ICE_CONNECTION_MOBILITY_FAIL=17105411]="ERR_ICE_CONNECTION_MOBILITY_FAIL",i[i.ERR_ICE_CONNECTION_HEARTBEAT_TIMEOUT=16908812]="ERR_ICE_CONNECTION_HEARTBEAT_TIMEOUT",i[i.ERR_LATENCY_LIVE_COMMUNICATION_FAILED=17235971]="ERR_LATENCY_LIVE_COMMUNICATION_FAILED",i[i.ERR_LATENCY_LIVE_MEIDASETTING_FAILED=17235972]="ERR_LATENCY_LIVE_MEIDASETTING_FAILED",i[i.ERR_LATENCY_LIVE_NONE_BROADCASTER=17235973]="ERR_LATENCY_LIVE_NONE_BROADCASTER",i[i.ERR_LATENCY_LIVE_NEED_RESTART=17235974]="ERR_LATENCY_LIVE_NEED_RESTART",i[i.ERR_LATENCY_LIVE_NEED_RESTART_AGAIN_LATER=17235975]="ERR_LATENCY_LIVE_NEED_RESTART_AGAIN_LATER",i[i.ERR_LATENCY_LIVE_SERVICE_UNAVAILABLE=17235976]="ERR_LATENCY_LIVE_SERVICE_UNAVAILABLE",i[i.ERR_LATENCY_LIVE_MEDIACONNECTION_INTERRUPTION=17235977]="ERR_LATENCY_LIVE_MEDIACONNECTION_INTERRUPTION",i[i.ERR_SDK_PUBLISH_INVAILD=16974597]="ERR_SDK_PUBLISH_INVAILD",i[i.ERR_SDK_PUBLISH_NOT_JOIN_CHANNEL=16843782]="ERR_SDK_PUBLISH_NOT_JOIN_CHANNEL",i[i.ERR_SDK_PUBLISH_AUDIO_STRAM_FAILED=16843856]="ERR_SDK_PUBLISH_AUDIO_STRAM_FAILED",i[i.ERR_SDK_PUBLISH_VIDEO_STRAM_FAILED=16843857]="ERR_SDK_PUBLISH_VIDEO_STRAM_FAILED",i[i.ERR_SDK_PUBLISH_DUAL_STRAM_FAILED=16843858]="ERR_SDK_PUBLISH_DUAL_STRAM_FAILED",i[i.ERR_SDK_PUBLISH_SCEEN_SHARE_FAILED=16843859]="ERR_SDK_PUBLISH_SCEEN_SHARE_FAILED",i[i.ERR_SDK_PUBLISH_SCREEN_SHARE_CONFIG_ERROR=16843860]="ERR_SDK_PUBLISH_SCREEN_SHARE_CONFIG_ERROR",i[i.ERR_SDK_SUBSCRIBE_INVAILD=16974852]="ERR_SDK_SUBSCRIBE_INVAILD",i[i.ERR_SDK_SUBSCRIBE_NOT_JOIN_CHANNEL=16844112]="ERR_SDK_SUBSCRIBE_NOT_JOIN_CHANNEL",i[i.ERR_SDK_SUBSCRIBE_AUDIO_STRAM_FAILED=16844113]="ERR_SDK_SUBSCRIBE_AUDIO_STRAM_FAILED",i[i.ERR_SDK_SUBSCRIBE_VIDEO_STRAM_FAILED=16844114]="ERR_SDK_SUBSCRIBE_VIDEO_STRAM_FAILED",i[i.ERR_SDK_SUBSCRIBE_DUAL_STRAM_FAILED=16844115]="ERR_SDK_SUBSCRIBE_DUAL_STRAM_FAILED",i[i.ERR_SDK_SUBSCRIBE_SCREEN_SHARE_FAILED=16844116]="ERR_SDK_SUBSCRIBE_SCREEN_SHARE_FAILED",i[i.ERR_SDK_INVALID_STATE=16974340]="ERR_SDK_INVALID_STATE",i[i.ERR_INVALID_ARGUMENTS=16974083]="ERR_INVALID_ARGUMENTS",i[i.ERR_SESSION_REMOVED=33620229]="ERR_SESSION_REMOVED",i[i.ERR_SDK_UPDATE_ROLE_CHANNEL=16908801]="ERR_SDK_UPDATE_ROLE_CHANNEL",i[i.ERR_INNER=-1]="ERR_INNER",i[i.ERR_SDK_MPU_TASK_PUBLISH_OK=0]="ERR_SDK_MPU_TASK_PUBLISH_OK",i[i.ERR_SDK_MPU_TASK_STREAM_NOT_FOUND=17825793]="ERR_SDK_MPU_TASK_STREAM_NOT_FOUND",i[i.ERR_SDK_MPU_TASK_STREAM_ALREADY_EXIST=17825794]="ERR_SDK_MPU_TASK_STREAM_ALREADY_EXIST",i[i.ERR_SDK_MPU_TASK_INVALID_PARAM=17825795]="ERR_SDK_MPU_TASK_INVALID_PARAM",i[i.ERR_SDK_MPU_TASK_INTERNAL_ERROR=17825796]="ERR_SDK_MPU_TASK_INTERNAL_ERROR",i[i.ERR_SDK_MPU_TASK_RTMP_SERVER_ERROR=17825797]="ERR_SDK_MPU_TASK_RTMP_SERVER_ERROR",i[i.ERR_SDK_MPU_TASK_RTMP_STREAM_URL_ERROR=17825798]="ERR_SDK_MPU_TASK_RTMP_STREAM_URL_ERROR",i[i.ERR_SDK_MPU_TASK_PUBLISH_TIMEOUT=17825799]="ERR_SDK_MPU_TASK_PUBLISH_TIMEOUT",i[i.ERR_SDK_MPU_TASK_NOT_AUTHORIZED=17825800]="ERR_SDK_MPU_TASK_NOT_AUTHORIZED",i[i.ERR_SDK_CHANNEL_RELAY_STATE_ERROR=18874369]="ERR_SDK_CHANNEL_RELAY_STATE_ERROR",i[i.ERR_SDK_CHANNEL_RELAY_SRC_NOT_ALLOW=18874370]="ERR_SDK_CHANNEL_RELAY_SRC_NOT_ALLOW",i[i.ERR_SDK_CHANNEL_RELAY_JOIN_DEST_FAILED=18874371]="ERR_SDK_CHANNEL_RELAY_JOIN_DEST_FAILED",i[i.ERR_SDK_CHANNEL_RELAY_TOKEN_INVALID=18874372]="ERR_SDK_CHANNEL_RELAY_TOKEN_INVALID",i[i.ERR_SDK_CHANNEL_RELAY_ROLE_ERROR=18874373]="ERR_SDK_CHANNEL_RELAY_ROLE_ERROR",i[i.ERR_SDK_CHANNEL_RELAY_INVALID_PARAM=18874374]="ERR_SDK_CHANNEL_RELAY_INVALID_PARAM",i[i.ERR_SDK_CHANNEL_RELAY_TO_SELF_ERROR=18874375]="ERR_SDK_CHANNEL_RELAY_TO_SELF_ERROR",i))(T||{});class A extends Error{constructor(e,t,r){super(t);c(this,"_code");c(this,"_extra");this._code=e,this._extra=r}static fromError(e,t=-1,r=""){return new A(t,e.message||e.reason||r||"error",e.extraInfo)}get code(){return this._code}set code(e){this._code=e}get reason(){return this.message}get extra(){return this._extra}}const lr=3e4;class dr extends J{constructor(e,t,r,a,n){super();c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"wsClient");c(this,"packageCreater");c(this,"keepAliveTimer",0);c(this,"packageCache",new Map);c(this,"isFirstConnect",!0);c(this,"aliveChecker",0);c(this,"reconnectData");this.authInfo=e,this.userName=t,this.packageCreater=new hr(e,t),this.channelProfile=r,this.clientRole=a,this.wsClient=new si(n),this.wsClient.on("onOpen",this.onOpen.bind(this)),this.wsClient.on("onMessage",this.onMessage.bind(this)),this.wsClient.on("onError",this.onError.bind(this)),this.wsClient.on("onClose",this.onClose.bind(this)),this.wsClient.on("onConnectFail",this.onConnectFail.bind(this)),this.wsClient.on("onAuthInvalid",this.onAuthInvalid.bind(this)),this.wsClient.on("onNetworkError",this.onNetworkError.bind(this)),this.wsClient.on("onReconnectStart",this.onReconnectStart.bind(this)),this.wsClient.on("onReconnectFail",this.onReconnectFail.bind(this))}start(e){this.wsClient.start(e)}startKeepAlive(){this.keepAliveTimer===0&&(this.keepAliveTimer=window.setInterval(()=>{let e=this.packageCreater.createKeepAlivePackage();this.sendPackage(e)},5e3)),this.checkAlive()}stopKeepAlive(){this.keepAliveTimer!==0&&(clearInterval(this.keepAliveTimer),this.keepAliveTimer=0),this.aliveChecker&&(window.clearTimeout(this.aliveChecker),this.aliveChecker=0)}sendPkgCache(){this.packageCache.forEach(e=>{this.wsClient.send(e)})}leave(){let e=this.packageCreater.crateLeavePackage();this.sendPackage(e)}reportStatus(e){let t=this.packageCreater.createStatusPackage(e);this.sendPackage(t)}publish(e){let t=this.packageCreater.createPublishPackage();t.data.users=[],e.subscribe.signal=this.wsClient.connectUrl;const{tracks:r,resume:a}=e;r.forEach(n=>{const{codec:o,ssrc:u}=n;n.userdata=JSON.stringify({codec:o}),n.ssrc=`${u}`,a&&(n.attr={reason:"reconnect"})}),t.data.users.push(e),this.sendPackage(t)}roleUpdate(e){let t=this.packageCreater.createRoleUpdatePackage();t.data.clientrole=e,this.sendPackage(t)}refreshUrl(e){const t=this.packageCreater.createRefreshUrlPackage();t.data=W(qe(W({},t.data),{sessionid:t.header.sessionid}),e),this.sendPackage(t)}refreshAuthInfo(e){this.authInfo=e,this.packageCreater.refreshAuthInfo(e)}close(){I.info("[roomsigcenter] close"),this.stopKeepAlive(),this.wsClient.off("onOpen",this.onOpen.bind(this)),this.wsClient.off("onMessage",this.onMessage.bind(this)),this.wsClient.off("onError",this.onError.bind(this)),this.wsClient.off("onClose",this.onClose.bind(this)),this.wsClient.off("onConnectFail",this.onConnectFail.bind(this)),this.wsClient.off("onAuthInvalid",this.onAuthInvalid.bind(this)),this.wsClient.off("onReconnectStart"),this.wsClient.off("onReconnectFail"),this.wsClient.close()}sendPackage(e){[ee.KEEPALIVE,ee.RECONNECT,ee.JOINCHANNEL].includes(e.msgtype)||this.packageCache.set(e.tid,e),this.wsClient.send(e)}updateReconnectData(e){this.reconnectData=e}onOpen(){if(I.info("[roomsigcenter] onOpen"),this.isFirstConnect){let e=this.packageCreater.createJoinPackage();e.data.configure={channelprofile:this.channelProfile},(this.channelProfile===Te.AliRtcSdkInteractiveLive||this.channelProfile===Te.AliRtcSdkInteractiveWithLowLatencyLive)&&(e.data.configure.clientrole=this.clientRole),this.sendPackage(e)}else{this.stopKeepAlive();const e=this.packageCreater.createReconnectPackage(this.reconnectData);this.sendPackage(e)}}onMessage(e){try{let t=JSON.parse(e.data);this.packageCache.delete(t.tid),this.onRecvMessage(t)}catch(t){I.error("[roomsigcenter] onMessage err",t,e)}}onError(e){I.error("[roomsigcenter] onError",e),this.isFirstConnect&&this.onConnectFail()}onConnectFail(){I.error("[roomsigcenter] onConnectFail");const e=new A(T.ERR_INNER,"Signaling connect failed.");this.isFirstConnect?this.emit("onJoinChannelResult",e):this.emit("onConnectFail",e)}onAuthInvalid(){I.error("[roomsigcenter] onAuthInvalid"),this.isFirstConnect&&this.emit("onAuthInvalid")}onNetworkError(){I.error("[roomsigcenter] onNetworkError");const e=new A(T.ERR_INNER,"Network error, signaling connect failed.");this.emit("onNetworkError",e)}onClose(e){I.info("[roomsigcenter] onClose",e),this.stopKeepAlive()}onKeepAliveRsp(){this.emit("onKeepAliveRsp"),this.checkAlive()}onReconnectStart(){this.emit("onReconnectStart")}onReconnectFail(){this.emit("onReconnectFail",new A(T.ERR_INNER,"signaling reconnect failed."))}checkAlive(){window.clearTimeout(this.aliveChecker),this.aliveChecker=window.setTimeout(()=>{I.info("[roomsigcenter] not alive, reconnect"),this.stopKeepAlive(),this.emit("onReconnectStart"),this.wsClient.reconnect()},lr)}onRecvMessage(e){switch(e.msgtype!==ee.KEEPALIVE&&I.info("[roomsigcenter] recv msg "+e.msgtype),e.msgtype){case ee.JOINCHANNEL:this.onJoinResult(e);break;case ee.KEEPALIVE:this.onKeepAliveRsp();break;case ee.PUBLISH:this.onPublishResult(e);break;case ee.NOTIFYJOIN:this.onNotifyJoin(e);break;case ee.NOTIFYSTATUS:this.onNotifyStatus(e);break;case ee.LEAVECHANNEL:this.onLeaveResult(e);break;case ee.NOTIFYLEAVE:this.onNotifyLeave(e);break;case ee.NOTIFYPUBLISH:this.onNotifyPublish(e);break;case ee.STATUSREPORT:this.onStatusReport(e);break;case ee.BYE:this.onBye(e);break;case ee.ROLEUPDATE:this.onRoleUpdateResult(e);break;case ee.REFRESHURL:this.onRefreshUrlResult(e);break;case ee.RECONNECT:this.onReconnectResult(e);break}}onJoinResult(e){this.isFirstConnect=!1,this.emit("onJoinChannelResult",e)}onLeaveResult(e){this.emit("onLeaveResult",e.code,e.tid)}onPublishResult(e){this.emit("onPublishResult",e.code,e.tid,e.description)}onRoleUpdateResult(e){this.emit("onRoleUpdateResult",e.code,e.tid,e.description)}onRefreshUrlResult(e){this.emit("onRefreshUrlResult",e)}onReconnectResult(e){if(e.code===200)this.sendPkgCache(),this.startKeepAlive(),this.emit("onReconnectSuccess",e.data.users);else{const t=new A(T.ERR_INNER,`reconnect failed, code: ${e.code};description: ${e.description}`);e.code===403&&(t.code=403),this.emit("onReconnectFail",t),this.close()}}onNotifyJoin(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e&&e.data&&e.data.users&&this.emit("onNotifyJoin",e.data.users)}onNotifyStatus(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e.data&&e.data.status&&e.data.status.length&&this.emit("onNotifyStatus",e.data.status)}onNotifyLeave(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e.data&&e.data.users&&e.data.users.length&&this.emit("onNotifyLeave",e.data.users)}onNotifyPublish(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e.data&&e.data.users&&e.data.users.length&&this.emit("onNotifyPublish",e.data.users)}onStatusReport(e){this.emit("onStatusReport",e.code,e.tid,e.description)}onBye(e){this.stopKeepAlive(),this.emit("onBye",e.reason,e.description)}}const b=(i,s)=>(e,t,r)=>{const a=r.value;return r.value=function(...n){var p;const o=`[${((p=e.constructor)==null?void 0:p.logName)||""}]`,u=Date.now();let h=[];i&&(h=i(n)),I.interface(o,t,...h);const l=a.apply(this,n);return Promise.resolve(l).then(d=>d).catch(d=>d).then(d=>{let m="";const g=d instanceof Error;!s&&!g||(g?m=d:s&&(d===void 0?m="":m=s(d)),I.interfaceResult(o,t,!g,`${Date.now()-u}ms`,m))}),l},r},R=i=>i;var pr=Object.defineProperty,mr=Object.getOwnPropertyDescriptor,ri=(i,s,e,t)=>{for(var r=t>1?void 0:t?mr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&pr(s,e,r),r};const vt=(he=class extends J{constructor(e,t,r=ye.prod){super();c(this,"messageCenter");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"reconnectData");c(this,"roomServerUri","");this.channelProfile=e,this.clientRole=t,this.reconnectData={role:{channelprofile:e,clientrole:t}};const a=r===ye.pre?mt.pre:mt.prod;this.roomServerUri=`wss://${a}/roomserver/v1/ws`}updateReconnectData(e){var t;this.reconnectData=e,(t=this.messageCenter)==null||t.updateReconnectData(this.reconnectData)}reset(){I.info("[roomsig] reset"),this.messageCenter&&(this.messageCenter.close(),this.messageCenter=void 0),this.authInfo=void 0}join(e,t,r){return S(this,null,function*(){return new Promise((a,n)=>{I.setTraceID(e.channelId+"-"+e.callid),this.authInfo=e,this.userName=t,this.messageCenter=new dr(e,t,this.channelProfile,this.clientRole,r),this.initMessageCenter(),this.messageCenter.once("onJoinChannelResult",u=>{var h,l;if(I.info("join result: ",u),u.code==200){(h=this.messageCenter)==null||h.sendPkgCache(),(l=this.messageCenter)==null||l.startKeepAlive();let p=u.data;p.tid=u.tid,p.users=u.data.users,p.timestamp=u.timestamp,a(p)}else this.reset(),n(this.handleSignalError(u.code,u.reason,T.ERR_JOIN_CHANNEL_FAILED))}),this.messageCenter.once("onAuthInvalid",()=>{this.reset(),n(new A(T.ERR_JOIN_BAD_TOKEN,"join failed because authentication failed"))}),I.info(`[${he.logName}]`,"start ws connecting roomserver and auto join when connected");const o={appid:this.authInfo.appId,callid:this.authInfo.callid,channelid:this.authInfo.channelId,userid:this.authInfo.userId,nonce:this.authInfo.nonce||"",timestamp:this.authInfo.timestamp,token:this.authInfo.token,authtype:"app",tid:N.Guid.create(32)};e.role&&(o.tokenrole=e.role),this.messageCenter.start(this.roomServerUri+"?"+Ae.queryingParam(o))})})}leave(){return I.info("[roomsig] leave .."),new Promise((e,t)=>{this.messageCenter?(this.messageCenter.on("onLeaveResult",(r,a)=>{I.info(`[${he.logName}]`,"recv leave response "+r),r===200?(this.updateReconnectData(),this.reset(),e({tid:a})):t(this.handleSignalError(r,"leave error"))}),I.info(`[${he.logName}]`,"send leave request"),this.messageCenter.leave()):(I.info(`[${he.logName}]`,"no message center, ok to leave"),e({tid:""}))})}publish(e){return new Promise((t,r)=>{var a;this.messageCenter?(this.messageCenter.once("onPublishResult",(n,o,u)=>{I.info(`[${he.logName}]`,"recv pubish response "+n),n===200?(this.updateReconnectData(qe(W({},this.reconnectData),{publish:{users:[e]}})),t({tid:o})):r(this.handleSignalError(n,`publish error, ${u}`))}),this.authInfo&&(e.sessionid=(a=this.authInfo.callid)!=null?a:""),e.callid=N.Guid.create(32),I.info(`[${he.logName}]`,"assign callid "+e.callid+" and send publish request"),this.messageCenter.publish(e)):r(this.handleSignalError(-1,"publish error, no message center"))})}roleUpdate(e){return new Promise((t,r)=>{if(!this.messageCenter){r(this.handleSignalError(-1,"role update error, no message center"));return}this.messageCenter.on("onRoleUpdateResult",(a,n,o)=>{var u,h;I.info(`[${he.logName}]`,"recv role update response "+a),a===200?((h=(u=this.reconnectData)==null?void 0:u.role)!=null&&h.clientrole&&(this.reconnectData.role.clientrole=e,this.updateReconnectData(this.reconnectData)),t({tid:n})):r(this.handleSignalError(a,`role update error, ${o}`))}),this.messageCenter.roleUpdate(e)})}setChannelProfile(e){this.channelProfile=e}refreshUrl(e){return I.info(`[${he.logName}]`,"refreshUrl .."),new Promise((t,r)=>{if(!this.messageCenter){r(this.handleSignalError(-1,"refresh url error, no message center"));return}this.messageCenter.on("onRefreshUrlResult",a=>{const{code:n,description:o,data:u={}}=a||{};I.info("recv refresh url response "+n),n===200?t(u):r(this.handleSignalError(n,`refresh url error, ${o}`))}),I.info("send refresh url request"),this.messageCenter.refreshUrl(e)})}reportStatus(e){return I.info(`[${he.logName}]`,"reportStatus "+e),new Promise((t,r)=>{this.messageCenter?(this.messageCenter.once("onStatusReport",(a,n)=>{a===200?t():r(new A(a,n))}),this.messageCenter.reportStatus(e)):r(new A(-1,"No messageCenter"))})}handleSignalError(e,t,r=T.ERR_INNER){const a=`signal error: code - ${e}; description - ${t}`;return new A(r,a)}refreshAuthInfo(e){return S(this,null,function*(){var t;this.authInfo&&(this.authInfo=e,(t=this.messageCenter)==null||t.refreshAuthInfo(this.authInfo))})}initMessageCenter(){var e,t,r,a,n,o,u,h,l,p,d,m;(e=this.messageCenter)==null||e.on("onKeepAliveRsp",()=>{this.emit("onKeepAliveRsp")}),(t=this.messageCenter)==null||t.on("onNotifyJoin",g=>{this.emit("onNotifyJoin",g)}),(r=this.messageCenter)==null||r.on("onNotifyStatus",g=>{this.emit("onNotifyStatus",g)}),(a=this.messageCenter)==null||a.on("onNotifyLeave",g=>{this.emit("onNotifyLeave",g)}),(n=this.messageCenter)==null||n.on("onNotifyPublish",g=>{this.emit("onNotifyPublish",g)}),(o=this.messageCenter)==null||o.on("onBye",(g,f)=>{this.emit("onBye",g,f)}),(u=this.messageCenter)==null||u.on("onReconnectStart",()=>{this.emit("onReconnectStart")}),(h=this.messageCenter)==null||h.on("onReconnectSuccess",g=>{this.emit("onReconnectSuccess",g)}),(l=this.messageCenter)==null||l.on("onReconnectFail",g=>{this.emit("onReconnectFail",g)}),(p=this.messageCenter)==null||p.on("onConnectFail",g=>{this.emit("onConnectFail",g),this.reset()}),(d=this.messageCenter)==null||d.on("onNetworkError",g=>{this.emit("onNetworkError",g)}),(m=this.messageCenter)==null||m.on("onAuthInvalid",()=>{this.emit("onAuthInvalid")})}},c(he,"logName","RoomServerSignaling"),he);ri([b()],vt.prototype,"join",1),ri([b()],vt.prototype,"publish",1),ri([b()],vt.prototype,"roleUpdate",1);let gr=vt;class Sr extends J{constructor(e,t,r=ye.prod){super();c(this,"signaling");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"env",ye.prod);c(this,"maxConnectRetryCount");this.channelProfile=e,this.clientRole=t,this.env=r}reset(){var e;I.info("[signalingmanager] reset"),(e=this.signaling)==null||e.reset(),this.signaling=void 0,this.authInfo=void 0}join(e,t=e.userId,r){return this.maxConnectRetryCount=r,this.userName=t,new Promise((a,n)=>{this.signaling?n(new A(T.ERR_JOIN_ALREADY_JOINED,"already joined")):(I.info("[signalingmanager] create signaling"),this.signaling=new gr(this.channelProfile,this.clientRole,this.env),this.initSignaling(),this.signaling.join(e,t,r).then(o=>{this.authInfo=e,a(o)}).catch(o=>{this.reset(),n(o)}))})}retryJoin(){const e=this.authInfo;this.reset(),e&&this.join(e,this.userName,this.maxConnectRetryCount)}leave(){return new Promise((e,t)=>{this.signaling?this.signaling.leave().then(r=>{this.reset(),e(r)}).catch(r=>{t(r)}):e({tid:""})})}publish(e){return new Promise((t,r)=>{var a;this.signaling&&this.authInfo?(e.userid=this.authInfo.userId,e.displayname=(a=this.userName)!=null?a:this.authInfo.userId,this.signaling.publish(e).then(n=>{t(n)}).catch(n=>{r(n)})):r(new A(T.ERR_SDK_PUBLISH_NOT_JOIN_CHANNEL,"no signaling"))})}reportStatus(e){return new Promise((t,r)=>{this.signaling?this.signaling.reportStatus(e).then(()=>{t()}).catch(a=>{r(a)}):r(new A(-1,"no signaling"))})}setClientRole(e){return S(this,null,function*(){if(!this.signaling){this.clientRole=e;return}return yield this.signaling.roleUpdate(e)})}setChannelProfile(e){this.signaling?this.signaling.setChannelProfile(e):this.channelProfile=e}refreshUrl(e){return this.signaling?this.signaling.refreshUrl(e):Promise.reject(new A(T.ERR_SDK_INVALID_STATE,"should join first"))}refreshAuthInfo(e){return S(this,null,function*(){var t;try{this.authInfo&&(this.authInfo=W(W({},this.authInfo),e),(t=this.signaling)==null||t.refreshAuthInfo(this.authInfo))}catch(r){throw r}})}initSignaling(){var e,t,r,a,n,o,u,h,l,p,d,m,g;(e=this.signaling)==null||e.on("onKeepAliveRsp",this.onKeepAliveRsp.bind(this)),(t=this.signaling)==null||t.on("onNotifyJoin",this.onNotifyJoin.bind(this)),(r=this.signaling)==null||r.on("onNotifyStatus",this.onNotifyStatus.bind(this)),(a=this.signaling)==null||a.on("onNotifyLeave",this.onNotifyLeave.bind(this)),(n=this.signaling)==null||n.on("onNotifyPublish",this.onNotifyPublish.bind(this)),(o=this.signaling)==null||o.on("onBye",this.onBye.bind(this)),(u=this.signaling)==null||u.on("onReconnectStart",this.onReconnectStart.bind(this)),(h=this.signaling)==null||h.on("onReconnectSuccess",this.onReconnectSuccess.bind(this)),(l=this.signaling)==null||l.on("onReconnectFail",this.onReconnectFail.bind(this)),(p=this.signaling)==null||p.on("onConnectFail",this.onConnectFail.bind(this)),(d=this.signaling)==null||d.on("onNetworkError",this.onNetworkError.bind(this)),(m=this.signaling)==null||m.on("onAuthInvalid",this.onAuthInvalid.bind(this)),(g=this.signaling)==null||g.on("onError",this.onError.bind(this))}onKeepAliveRsp(){this.emit("onKeepAliveRsp")}onNotifyJoin(e){this.emit("onNotifyJoin",e)}onNotifyStatus(e){this.emit("onNotifyStatus",e)}onNotifyLeave(e){this.emit("onNotifyLeave",e)}onNotifyPublish(e){this.emit("onNotifyPublish",e)}onBye(e,t){this.emit("onBye",e,t)}onConnectFail(e){this.reset(),this.emit("onConnectFail",e)}onNetworkError(e){this.emit("onNetworkError",e)}onAuthInvalid(e){}onReconnectStart(){this.emit("onReconnectStart")}onReconnectSuccess(e){this.emit("onReconnectSuccess",e)}onReconnectFail(e){this.emit("onReconnectFail",e)}onError(e){this.emit("onError",e)}}const Be=class Be{static getInstance(){return Be.instance||(Be.instance=new AudioContext),Be.instance.resume(),Be.instance}};c(Be,"instance");let ai=Be;function fr(i,s,e,t,r){let a=t,n=0,o;const u=i.createAnalyser();u.fftSize=256;const h=new Uint8Array(u.frequencyBinCount);s.connect(u),u.connect(e);const l=()=>{o&&window.clearInterval(o)},p=()=>{o=window.setInterval(()=>{u.getByteFrequencyData(h);let d=Math.round(h.reduce((m,g)=>m+g)/h.length);d=Math.min(100,d),n=d,r&&r(d)},a)};return p(),{updateInterval:d=>{l(),a=d,p()},getLevel:()=>n,dispose:()=>{l(),s.disconnect(),u.disconnect()}}}class br extends J{constructor(){super();c(this,"audioContext");c(this,"stream");c(this,"sourceNode");c(this,"analyser");this.audioContext=ai.getInstance(),this.stream=new MediaStream}getLevel(){return this.analyser?this.analyser.getLevel():0}start(e,t=1e3){this.sourceNode&&this.stop(),this.stream.addTrack(e),this.sourceNode=this.audioContext.createMediaStreamSource(this.stream);const r=this.audioContext.createMediaStreamDestination();this.analyser=fr(this.audioContext,this.sourceNode,r,t,a=>{this.emit("audioLevel",a)})}stop(){this.analyser&&this.analyser.dispose(),this.analyser=void 0,this.sourceNode=void 0,this.stream.getAudioTracks().forEach(e=>{this.stream.removeTrack(e)})}dispose(){this.stop()}}class Ki extends J{constructor(e,t,r,a){super();c(this,"uid");c(this,"name");c(this,"rtsManager");c(this,"callid","");c(this,"audioLevelMonitor");c(this,"audioVolumeIndicationInterval",0);this.uid=e,this.name=t,this.rtsManager=r,this.audioVolumeIndicationInterval=a,this.audioLevelMonitor=new br}get userId(){return this.uid}get displayname(){return this.name}setUserInfo(e,t){this.uid=e,this.name=t}refreshUserInfo(e){this.uid=e}getAudioLevel(){return this.audioLevelMonitor.getLevel()}enableAudioVolumeIndication(e){this.audioVolumeIndicationInterval=e}clear(){this.audioLevelMonitor.dispose()}}class ji{static getCurrentStatus(s){let e=0;s.micOpen&&(e+=1),s.micInterrupted&&(e+=2),s.cameraOpen&&(e+=4),s.screenShare&&(e+=128),s.audioDisable&&(e+=8),s.videoDisable&&(e+=16),s.screenDisable&&(e+=256);let t=e.toString(16);for(;t.length<16;)t="0"+t;return t}static parseStatus(s){let e=parseInt(s,16);return{micOpen:!!(e&1),micInterrupted:!!(e&2),cameraOpen:!!(e&4),screenShare:!!(e&128),audioDisable:!!(e&8),videoDisable:!!(e&16),screenDisable:!!(e&256),backgroundMode:!!(e&32),accompanyPlaying:!!(e&64)}}}const $i="customVideoProfile",Ji="customScreenProfile",et={width:1280,height:720,frameRate:30,maxBitrate:2e3},tt={width:1920,height:1080,frameRate:30,maxBitrate:2600},vr={1e4:X.AliEngineLocalDeviceExceptionTypeUnknown,2e4:X.AliEngineLocalDeviceExceptionTypeUnknown,10001:X.AliEngineLocalDeviceExceptionTypeMicNotAvailable,10002:X.AliEngineLocalDeviceExceptionTypeMicAuthFail,10003:X.AliEngineLocalDeviceExceptionTypeMicOpenFail,10005:X.AliEngineLocalDeviceExceptionTypeCameraAuthFail,10004:X.AliEngineLocalDeviceExceptionTypeVideoDeviceException,10006:X.AliEngineLocalDeviceExceptionTypeCameraOpenFail,10010:X.AliEngineLocalDeviceExceptionTypeDisplayException,10011:X.AliEngineLocalDeviceExceptionTypeDisplayException,10012:X.AliEngineLocalDeviceExceptionTypeDisplayException,10013:X.AliEngineLocalDeviceExceptionTypeDisplayException,10014:X.AliEngineLocalDeviceExceptionTypeDisplayException,10019:X.AliEngineLocalDeviceExceptionTypeDisplayException},_r=i=>i.getAudioTracks()[0];function qi(i){var s;if(((s=i==null?void 0:i.nodeName)==null?void 0:s.toLowerCase())==="video")return i.setAttribute("playsinline",""),i;if(typeof i=="string"){let e=document.getElementById(i);if(e){if(e.nodeName.toLocaleLowerCase()==="video")return e.setAttribute("playsinline",""),e;throw new A(T.ERR_INVALID_ARGUMENTS,"element should be HtmlVideoElement")}else throw new A(T.ERR_INVALID_ARGUMENTS,"element not founded")}else throw new A(T.ERR_INVALID_ARGUMENTS,"element id should be string")}function ni(i){var e;const s=[];if(Array.isArray(i))i.forEach(t=>{try{s.push(qi(t))}catch(r){}});else if(typeof i=="string"||((e=i==null?void 0:i.nodeName)==null?void 0:e.toLowerCase())==="video")try{s.push(qi(i))}catch(t){}return s}function Ve(i){return new Promise(s=>setTimeout(s,i))}const Gi=(i,s)=>{const e=()=>(i.muted=!0,Promise.race([Ve(500),i._playPromise||Promise.resolve()]).catch(()=>{}).then(()=>{let t;return i.srcObject!==s?(i.load(),i.srcObject=s,t=i.play(),i._playPromise=t):t=Promise.resolve(),t}));return new Promise(t=>{if(N.BrowserUtil.isMicroMessenger){const r=window.top!==window.self,a=window.WeixinJSBridge||window.top.WeixinJSBridge;a?a.invoke("getNetworkType",{},()=>{t(e())}):(r?window.top.document:document).addEventListener("WeixinJSBridgeReady",()=>{a.invoke("getNetworkType",{},()=>{t(e())})}),setTimeout(()=>{t(e())},1e3)}else t(e())})},ke=i=>{Promise.race([Ve(100),i._playPromise||Promise.resolve()]).catch(()=>{}).then(()=>{i.srcObject=null,i._playPromise=void 0})};var wr=Object.defineProperty,Rr=Object.getOwnPropertyDescriptor,Z=(i,s,e,t)=>{for(var r=t>1?void 0:t?Rr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&wr(s,e,r),r};class _t extends J{constructor(){super();c(this,"state");c(this,"time");this.state=V.AliRtcStatePublishIdle,this.time=Date.now()}setState(e){const t=this.state,r=this.time;this.state=e,this.time=Date.now(),this.emit("change",t,e,Math.floor((this.time-r)/1e3))}}const Ut=class Ut extends Ki{constructor(e){const{rtsManager:t,localStreamManager:r,reporter:a,webTrackingClient:n,signalingManager:o,audioVolumeIndicationInterval:u}=e;super("","",t,u);c(this,"url","");c(this,"_isPublishing",!1);c(this,"publishPromise",Promise.resolve(""));c(this,"previewElements",[]);c(this,"screenPreviewElements",[]);c(this,"streamManager");c(this,"streamTracks");c(this,"publishId",N.Guid.create(16));c(this,"signalingManager");c(this,"traceId","");c(this,"moduleName","LocalUser");c(this,"monitorTimerId");c(this,"reporter");c(this,"webTrackingClient");c(this,"audioPubState");c(this,"videoPubState");c(this,"videoSmallPubState");c(this,"screenPubState");c(this,"onTrackEnd",e=>{this.emit(e)});this.streamManager=r,this.signalingManager=o,this.reporter=a,this.webTrackingClient=n,this.streamManager.on("trackended",h=>{this.onTrackEnd(h)}),this.streamManager.on("publishupdate",()=>{this.publishUpdate()}),this.audioPubState=new _t,this.audioPubState.on("change",(h,l,p)=>{this.emit("audioPublishStateChanged",h,l,p)}),this.videoPubState=new _t,this.videoPubState.on("change",(h,l,p)=>{this.emit("videoPublishStateChanged",h,l,p)}),this.videoSmallPubState=new _t,this.videoSmallPubState.on("change",(h,l,p)=>{this.emit("dualStreamPublishStateChanged",h,l,p)}),this.screenPubState=new _t,this.screenPubState.on("change",(h,l,p)=>{this.emit("screenPublishStateChanged",h,l,p)})}get joined(){return!!this.uid}get isPublishing(){return this._isPublishing}get publishStreams(){return this.streamManager.publishStreams}get cameraTrack(){return this.streamManager.cameraStreamInfo.originVideoTrack}get screenTrack(){return this.streamManager.screenStreamInfo.originVideoTrack}get audioTrack(){return this.streamManager.cameraStreamInfo.originAudioTrack}get hasCamera(){return!!this.streamManager.cameraStreamInfo.originVideoTrack}get hasMicrophone(){return!!this.streamManager.cameraStreamInfo.originAudioTrack}get hasScreenShare(){return!!this.streamManager.screenStreamInfo.originVideoTrack}get hasCameraTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===w.VideoLarge))}get hasCameraDualTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===w.VideoSmall))}get hasScreenTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===w.Screen))}get hasAudioTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="audio"&&t&&a===w.Audio))}get cameraDirection(){var e,t;return(t=(e=this.streamManager.cameraStreamInfo)==null?void 0:e.cameraVideoConstraints)==null?void 0:t.facingMode}get audioCaptureDisabled(){return this.streamManager.audioCaptureDisabled}get cameraCaptureDisabled(){return this.streamManager.cameraCaptureDisabled}get publishLocalVideoStreamEnabled(){return this.streamManager.publishLocalVideoStreamEnabled}get publishLocalAudioStreamEnabled(){return this.streamManager.publishLocalAudioStreamEnabled}get publishLocalScreenStreamEnabled(){return this.streamManager.publishLocalScreenStreamEnabled}setPublishLocalAudioStreamEnabled(e){this.streamManager.publishLocalAudioStreamEnabled=e}setPublishLocalVideoStreamEnabled(e){this.streamManager.publishLocalVideoStreamEnabled=e}setPublishLocalScreenStreamEnabled(e){this.streamManager.publishLocalScreenStreamEnabled=e}initInfo(e,t){var r;this.setUserInfo(e.userId,e.userId),this.url=t,this.callid=(r=e.callid)!=null?r:"",this.updatePubId()}setVideoProfile(e,t){return S(this,null,function*(){yield this.streamManager.setVideoProfile(e,t)})}setVideoContentHint(e){this.streamManager.setVideoContentHint(e)}setScreenContentHint(e){this.streamManager.setScreenContentHint(e)}setAudioProfile(e){return S(this,null,function*(){yield this.streamManager.setAudioProfile(e)})}setScreenProfile(e,t){return S(this,null,function*(){yield this.streamManager.setScreenProfile(e,t)})}setCameraDirection(e){if(e===ze.CAMERA_FRONT)this.streamManager.setCameraVideoConstraints({facingMode:"user"});else if(e===ze.CAMERA_REAR)this.streamManager.setCameraVideoConstraints({facingMode:"environment"});else throw new A(T.ERR_CAMERA_OPEN_FAIL,`camera direction set to ${e} failed`)}setCameraDeviceId(e){this.streamManager.setCameraVideoConstraints({deviceId:e})}muteLocalCamera(e){this.streamManager.setCameraMuted(e)}muteLocalMic(e){this.streamManager.setAudioMuted(e)}muteLocalScreen(e){this.streamManager.setScreenMuted(e)}setMicrophoneDeviceId(e){this.streamManager.setMicAudioConstraints({deviceId:e})}updatePubId(){this.publishId=N.Guid.create(16)}clearPublishState(){this.streamTracks=void 0}clear(){return S(this,null,function*(){xi(Ut.prototype,this,"clear").call(this),this._isPublishing&&(yield this.unPublish()),this.stopPreview(),this.resetPreviewElements(),this.resetSecondayPreviewElements(),this.clearStream(),this.stopStreamMonitor(),this.streamManager.cameraCaptureDisabled=!1})}resetElement(e){this.previewElements.includes(e)&&(ke(e),this.previewElements.splice(this.previewElements.indexOf(e),1)),this.screenPreviewElements.includes(e)&&(ke(e),this.screenPreviewElements.splice(this.screenPreviewElements.indexOf(e),1))}setPreviewElement(e){const{videoElement:t,screen:r}=e;r?this.screenPreviewElements.includes(t)||this.screenPreviewElements.push(t):this.previewElements.includes(t)||this.previewElements.push(t)}setViewConfig(e,t){if(!e){t===x.AliRtcVideoTrackCamera?this.stopPreview({primary:!0,screen:!1}):this.stopPreview({primary:!1,screen:!0});return}if(![x.AliRtcVideoTrackCamera,x.AliRtcVideoTrackScreen].includes(t))throw new A(T.ERR_INVALID_ARGUMENTS,"set view config invalid track",{track:t});e.forEach(r=>{this.setPreviewElement({videoElement:r,screen:t===x.AliRtcVideoTrackScreen})})}startCameraCapture(e){return S(this,null,function*(){return this.streamManager.cameraCaptureDisabled=!1,yield this.createLocalStream(e)})}stopCameraCapture(){return S(this,null,function*(){this.streamManager.cameraCaptureDisabled=!0,yield this.stopLocalStream({video:!0})})}stopAudioCapture(){return S(this,null,function*(){this.streamManager.audioCaptureDisabled=!0,yield this.stopLocalStream({audio:!0})})}preview(e){return S(this,null,function*(){const t="preview",{videoElement:r,screen:a}=e!=null?e:{};try{let n=a?this.streamManager.screenStreamInfo.previewStream:this.streamManager.cameraStreamInfo.previewStream;if(!r)throw new A(T.ERR_INVALID_ARGUMENTS,"no video element found",{videoElement:r});return n?(I.info(`[${this.moduleName}/${t}]`,{screen:a,stream:n,videoElement:r}),Gi(r,n.mediaStream),this.setPreviewElement(e),n.mediaStream):void 0}catch(n){const o=T.ERR_INNER;throw A.fromError(n,o,"preview failed")}})}previewAll(e){return S(this,null,function*(){const{primary:t=!0,screen:r=!0}=e!=null?e:{};if(t&&this.previewElements.length)for(let a=0;a<this.previewElements.length;a++){const n=this.previewElements[a];yield this.preview({videoElement:n})}if(r&&this.screenPreviewElements.length)for(let a=0;a<this.screenPreviewElements.length;a++){const n=this.screenPreviewElements[a];yield this.preview({videoElement:n,screen:!0})}})}stopPreview(e){const{videoElement:t,primary:r=!0,screen:a=!0}=e||{};if(!t)r&&(this.previewElements.forEach(n=>{ke(n)}),this.previewElements=[]),a&&(this.screenPreviewElements.forEach(n=>{ke(n)}),this.screenPreviewElements=[]);else{const n=this.previewElements.findIndex(o=>o===t);if(n>=0)this.previewElements.splice(n,1),ke(t);else{const o=this.screenPreviewElements.findIndex(u=>u===t);o>=0&&(this.screenPreviewElements.splice(o,1),ke(t))}}}resumePublish(){return S(this,null,function*(){this._isPublishing=!1,yield this.startPublish(!0)})}createLocalStream(e){return S(this,null,function*(){try{const t=yield this.streamManager.createLocalStream(e);return t!=null&&t.audioTrack&&this.audioVolumeIndicationInterval>0&&this.audioLevelMonitor.start(t.audioTrack,this.audioVolumeIndicationInterval),e.video?this.previewAll({primary:!0}):e.screen&&this.previewAll({screen:!0}),t}catch(t){const r=vr[t.errorCode];throw r&&(e.audio?this.emit("localDeviceException",we.AliEngineLocalDeviceTypeMic,r,""):e.video?this.emit("localDeviceException",we.AliEngineLocalDeviceTypeCamera,r,""):e.screen?this.emit("localDeviceException",we.AliEngineLocalDeviceTypeDisplay,r,""):this.emit("localDeviceException",we.AliEngineLocalDeviceTypeUnknown,r,"")),t}})}stopLocalStream(e){return S(this,null,function*(){e.audio&&this.audioLevelMonitor.stop(),yield this.streamManager.stopLocalStream(e)})}compareAndPublish(e,t,r){return S(this,null,function*(){var n,o;if(!e&&!t)return;if(e&&!t){const u={};return r===w.Audio?u.audio=!0:r===w.VideoLarge||r===w.VideoSmall?(u.video=!0,u.vMsid=r):r===w.Screen&&(u.screen=!0),yield this.publishDeleteTracks(u)}const a={};if(t!=null&&t.hasVideo&&(a.isScreen=r===w.Screen,a.vMsid=r),t!=null&&t.hasAudio&&(a.aMsid=r),!e&&t)return yield this.publishAdd(t,a,!1);if(e&&t){const u=e.trackId,h=((n=t.videoTrack)==null?void 0:n.id)||((o=t.audioTrack)==null?void 0:o.id);if(u!==h)return yield this.publishReplace(t,a)}})}startPublish(e=!1){return S(this,null,function*(){if(!this.joined)return;const t=yield this.streamManager.publishStreams,{audio:r,video:a,videoSmall:n,screen:o}=t;try{const u=new Date().getTime();r&&this.audioPubState.setState(V.AliRtcStatePublishing),a&&this.videoPubState.setState(V.AliRtcStatePublishing),n&&this.videoSmallPubState.setState(V.AliRtcStatePublishing),o&&this.screenPubState.setState(V.AliRtcStatePublishing),this.publishPromise=this.rtsManager.publish(this.url,e);const h=yield this.publishPromise;this._isPublishing=!0,this.streamTracks=this.rtsManager.publishingTracks,this.traceId=h;const l={userid:this.userId,sessionid:"",displayname:this.name,pubid:this.publishId,resume:e,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks,traceId:h};yield this.syncPublishToRoomServer(l,t,u),r&&this.audioPubState.setState(V.AliRtcStatePublished),a&&this.videoPubState.setState(V.AliRtcStatePublished),n&&this.videoSmallPubState.setState(V.AliRtcStatePublished),o&&this.screenPubState.setState(V.AliRtcStatePublished)}catch(u){throw r&&this.audioPubState.setState(V.AliRtcStateNoPublish),a&&this.videoPubState.setState(V.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(V.AliRtcStateNoPublish),o&&this.screenPubState.setState(V.AliRtcStateNoPublish),u}})}publishUpdate(){return S(this,null,function*(){var a,n,o,u;if(!this._isPublishing)return;yield this.publishPromise;const e=yield this.streamManager.publishStreams;let t;const r=new Date().getTime();try{const h=(a=this.streamTracks)==null?void 0:a.find(({ssrc:O,type:B,msid:C})=>B==="audio"&&O&&C===w.Audio),l=yield this.compareAndPublish(h,e.audio,w.Audio);l&&(t=l);const p=(n=this.streamTracks)==null?void 0:n.find(({ssrc:O,type:B,msid:C})=>B==="video"&&O&&C===w.VideoLarge),d=yield this.compareAndPublish(p,e.video,w.VideoLarge);d&&(t=d);const m=(o=this.streamTracks)==null?void 0:o.find(({ssrc:O,type:B,msid:C})=>B==="video"&&O&&C===w.VideoSmall),g=yield this.compareAndPublish(m,e.videoSmall,w.VideoSmall);g&&(t=g);const f=(u=this.streamTracks)==null?void 0:u.find(({ssrc:O,type:B,msid:C})=>B==="video"&&O&&C===w.Screen),v=yield this.compareAndPublish(f,e.screen,w.Screen);if(v&&(t=v),!t)return;yield this.syncPublishToRoomServer(t,e,r)}catch(h){const{code:l}=h!=null?h:{},p=this.url;throw l===403&&p&&(yield this.refreshPushStreamUrl(),t=yield this.publishUpdate()),h}return t})}syncPublishToRoomServer(e,t,r){return S(this,null,function*(){var p;if(!e)throw new A(T.ERR_INNER,"sync publish to room server failed because no publishInfo");const a=yield this.signalingManager.publish(e);e.signaltid=a.tid;const n=new Date().getTime()-r,o=!!t.video,u=!1,h=!!t.screen,l=!!t.audio;this.reporter.reportPublish(this.callid||"",o,u,h,l,0,a.tid,n),this.webTrackingClient.reportPush(this.callid||"",o,u,h,l,0,a.tid,n,r,e.traceid||"",this.traceId,(p=this.url)!=null?p:"")})}refreshPushStreamUrl(){return S(this,null,function*(){const e=new A(T.ERR_INNER,"refresh push stream url error"),t=this.url;if(!t)throw e;const r=yield this.signalingManager.refreshUrl({pushstreamurl:t});if(!(r!=null&&r.pushstreamurl))throw e;this.url=r==null?void 0:r.pushstreamurl})}publishAdd(e,t,r=!1,a=0){return S(this,null,function*(){const n=(t==null?void 0:t.aMsid)===w.Audio,o=(t==null?void 0:t.vMsid)===w.VideoLarge,u=(t==null?void 0:t.vMsid)===w.VideoSmall,h=(t==null?void 0:t.vMsid)===w.Screen;n&&this.audioPubState.setState(V.AliRtcStatePublishing),o&&this.videoPubState.setState(V.AliRtcStatePublishing),u&&this.videoSmallPubState.setState(V.AliRtcStatePublishing),h&&this.screenPubState.setState(V.AliRtcStatePublishing);try{const l=yield this.rtsManager.publishAdd(this.url,e,t,!1,0,!0);n&&this.audioPubState.setState(V.AliRtcStatePublished),o&&this.videoPubState.setState(V.AliRtcStatePublished),u&&this.videoSmallPubState.setState(V.AliRtcStatePublished),h&&this.screenPubState.setState(V.AliRtcStatePublished),this.streamTracks=this.rtsManager.publishingTracks;const p={userid:this.userId,sessionid:"",displayname:this.name,pubid:this.publishId,resume:r,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks,traceid:l};return this.reportSelfDeviceStatus(),p}catch(l){let p=T.ERR_SDK_PUBLISH_INVAILD;if(n&&(this.audioPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_AUDIO_STRAM_FAILED),o&&(this.videoPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_VIDEO_STRAM_FAILED),u&&(this.videoSmallPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_DUAL_STRAM_FAILED),h&&(this.screenPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_SCEEN_SHARE_FAILED),l.errorCode===15006&&a<3)return this.publishAdd(e,t,r,a+1);throw A.fromError(l,p,"publish add failed")}})}publishReplace(e,t){return S(this,null,function*(){try{yield this.rtsManager.publishReplace(this.url,e,t),this.traceId="",this.streamTracks=this.rtsManager.publishingTracks;const r={userid:this.userId,sessionid:"",pubid:this.publishId,displayname:this.name,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks};return this.reportSelfDeviceStatus(),r}catch(r){throw A.fromError(r,T.ERR_INNER,`publish replace failed, vMsid: ${t==null?void 0:t.vMsid} aMsid: ${t==null?void 0:t.aMsid}`)}})}publishDeleteTracks(e){return S(this,null,function*(){const t={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};try{return yield this.rtsManager.publishDelete(this.url,e),this.streamTracks=this.rtsManager.publishingTracks,e.audio&&this.audioPubState.setState(V.AliRtcStateNoPublish),e.video&&(e.vMsid===w.VideoSmall?this.videoSmallPubState.setState(V.AliRtcStateNoPublish):this.videoPubState.setState(V.AliRtcStateNoPublish)),e.screen&&this.screenPubState.setState(V.AliRtcStateNoPublish),this.traceId="",t.tracks=this.streamTracks,this.reportSelfDeviceStatus(),t}catch(r){throw A.fromError(r,T.ERR_INNER,"publish delete tracks failed")}})}publishStop(){return S(this,null,function*(){const e="publishStop";if(!this._isPublishing)throw new A(T.ERR_INNER,"publish stop failed, previous localStream is required for publishing stopping");I.info(`[${this.moduleName}/${e}]`,{url:this.url});const t=new Date().getTime();try{const r=this.hasAudioTrackInMS,a=this.hasCameraTrackInMS,n=this.hasCameraDualTrackInMS,o=this.hasScreenTrackInMS;yield this.rtsManager.publishStop(this.url),r&&this.audioPubState.setState(V.AliRtcStateNoPublish),a&&this.videoPubState.setState(V.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(V.AliRtcStateNoPublish),o&&this.screenPubState.setState(V.AliRtcStateNoPublish),this.traceId="",this.streamTracks=[];const u={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};return this.syncPublishToRoomServer(u,{},t),u}catch(r){throw A.fromError(r,T.ERR_INNER,"publish stop failed")}})}unPublish(){return S(this,null,function*(){const e=new Date().getTime();let t={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};try{if(this._isPublishing){const r=this.hasAudioTrackInMS,a=this.hasCameraTrackInMS,n=this.hasCameraDualTrackInMS,o=this.hasScreenTrackInMS;yield this.rtsManager.unpublish(),r&&this.audioPubState.setState(V.AliRtcStateNoPublish),a&&this.videoPubState.setState(V.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(V.AliRtcStateNoPublish),o&&this.screenPubState.setState(V.AliRtcStateNoPublish),this._isPublishing=!1,this.traceId="",this.clearStream()}return this.reporter.reportUnpublish(this.callid||"",e,0,""),t}catch(r){throw A.fromError(r,T.ERR_INNER,"unpublish failed")}})}reportSelfDeviceStatus(){this.emit(ie.Local,this.getDeviceStatus())}getDeviceStatus(){var t,r,a,n;let e={micOpen:!1,micInterrupted:!1,cameraOpen:!1,screenShare:!1,audioDisable:!0,videoDisable:!0,screenDisable:!0,backgroundMode:!1,accompanyPlaying:!1};return e.cameraOpen=this.hasCamera,e.micOpen=this.hasMicrophone,e.screenShare=this.hasScreenShare,e.audioDisable=!((t=this.streamManager.cameraStreamInfo.originAudioTrack)!=null&&t.enabled),e.videoDisable=!((r=this.streamManager.cameraStreamInfo.originVideoTrack)!=null&&r.enabled),e.screenDisable=!this.hasScreenShare||!((n=(a=this.streamManager.screenStreamInfo)==null?void 0:a.originVideoTrack)!=null&&n.enabled),ji.getCurrentStatus(e)}resetPreviewElements(){this.previewElements=[]}resetSecondayPreviewElements(){this.screenPreviewElements=[]}stopStreamMonitor(){this.monitorTimerId&&(clearInterval(this.monitorTimerId),this.monitorTimerId=void 0)}clearStream(){this.streamManager.stop(),this.audioPubState.setState(V.AliRtcStatePublishIdle),this.videoPubState.setState(V.AliRtcStatePublishIdle),this.videoSmallPubState.setState(V.AliRtcStatePublishIdle),this.screenPubState.setState(V.AliRtcStatePublishIdle)}getCurrentCameraDeviceId(){var e;return(e=this.streamManager.cameraStreamInfo.originVideoTrack)==null?void 0:e.getSettings().deviceId}getCurrentMicDeviceId(){var e;return(e=this.streamManager.cameraStreamInfo.originAudioTrack)==null?void 0:e.getSettings().deviceId}enableAudioVolumeIndication(e){this.audioVolumeIndicationInterval!==e&&(this.audioVolumeIndicationInterval>0&&e<=0&&this.audioLevelMonitor.stop(),e>0&&this.streamManager.cameraStreamInfo.originAudioTrack&&this.audioLevelMonitor.start(this.streamManager.cameraStreamInfo.originAudioTrack,e),this.audioVolumeIndicationInterval=e)}sendSEI(e,t,r){return S(this,null,function*(){if(!this.url)return;let a=0;return!t||t<1?a=1:a=t-1,this.rtsManager.sendSEI(this.url,e,a,r)})}getStats(){return S(this,null,function*(){const e=[];if(this.hasAudioTrackInMS){const r=yield this.rtsManager.getPublishAudioStats(this.url);r&&e.push({stats:r,track:He.AliRtcAudioTrackMic})}const t=[];if(this.hasCameraTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,w.VideoLarge);r&&t.push({track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:r})}if(this.hasCameraDualTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,w.VideoSmall);r&&t.push({track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:r})}if(this.hasScreenTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,w.Screen);r&&t.push({track:x.AliRtcVideoTrackScreen,stats:r})}return{audio:e,video:t}})}};c(Ut,"logName","LocalUser");let z=Ut;Z([b()],z.prototype,"clearPublishState",1),Z([b()],z.prototype,"clear",1),Z([b()],z.prototype,"setViewConfig",1),Z([b()],z.prototype,"startCameraCapture",1),Z([b()],z.prototype,"stopCameraCapture",1),Z([b()],z.prototype,"stopAudioCapture",1),Z([b()],z.prototype,"stopPreview",1),Z([b()],z.prototype,"resumePublish",1),Z([b()],z.prototype,"createLocalStream",1),Z([b()],z.prototype,"stopLocalStream",1),Z([b()],z.prototype,"compareAndPublish",1),Z([b(R)],z.prototype,"startPublish",1),Z([b()],z.prototype,"syncPublishToRoomServer",1),Z([b()],z.prototype,"refreshPushStreamUrl",1),Z([b(([i,s,e])=>[JSON.stringify(e)])],z.prototype,"publishAdd",1),Z([b(([i,s])=>[JSON.stringify(s)])],z.prototype,"publishReplace",1),Z([b(R)],z.prototype,"publishDeleteTracks",1),Z([b()],z.prototype,"publishStop",1),Z([b()],z.prototype,"unPublish",1),Z([b(([i,s,e])=>[i.length,s,e])],z.prototype,"sendSEI",1);var Oe=(i=>(i.OPUS="opus",i.H264="H264",i.UNKONWN="",i))(Oe||{}),De=(i=>(i.VideoTrackEnded="videoTrackEnded",i.AudioTrackEnded="audioTrackEnded",i.ScreenTrackEnded="screenTrackEnded",i))(De||{});const Ir=i=>{const s=new MediaStream;return s.addTrack(i),s},zi=i=>S(this,null,function*(){return yield P.AliRTS.createStream({custom:!0,mediaStream:i})}),it=i=>S(this,null,function*(){const s=Ir(i);return yield zi(s)}),Ar=i=>{const{audio:s,video:e,screen:t}=i;if(e&&t)throw new A(T.ERR_INNER,"create stream error, cannot create video && screen together");return!(!e&&!s&&!t)},Tr=i=>i===w.Audio||i===ge.Audio,Er=i=>i===w.VideoLarge||i===ge.VideoLarge,yr=i=>i===w.VideoSmall,Pr=i=>i===w.Screen;var kr=Object.defineProperty,Mr=Object.getOwnPropertyDescriptor,Nr=(i,s,e,t)=>{for(var r=t>1?void 0:t?Mr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&kr(s,e,r),r};class wt extends J{constructor(){super();c(this,"audioInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Oe.UNKONWN});c(this,"videoLargeInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Oe.UNKONWN});c(this,"videoSmallInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Oe.UNKONWN});c(this,"screenInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Oe.UNKONWN});c(this,"audioVolume",1);c(this,"audioMuted",!1);c(this,"userStatus");c(this,"moduleName","RemoteStreamInfo")}getAudioInfo(){return this.audioInfo}getVideoSmallInfo(){return this.videoSmallInfo}getVideoLargeInfo(){return this.videoLargeInfo}getScreenInfo(){return this.screenInfo}get hasAudio(){return this.audioInfo.ssrc!==""}get hasVideo(){return this.videoLargeInfo.ssrc!==""||this.videoSmallInfo.ssrc!==""}get hasVideoLarge(){return this.videoLargeInfo.ssrc!==""}get hasVideoSmall(){return this.videoSmallInfo.ssrc!==""}get hasScreen(){return this.screenInfo.ssrc!==""}get isAudioSubscribing(){return!!this.audioInfo.subscribed}get isVideoSubscribing(){return!!this.videoLargeInfo.subscribed||!!this.videoSmallInfo.subscribed}get isVideoLargeSubscribing(){return!!this.videoLargeInfo.subscribed}get isVideoSmallSubscribing(){return!!this.videoSmallInfo.subscribed}get isScreenSubscribing(){return!!this.screenInfo.subscribed}get audioCodec(){return this.audioInfo.codec}get videoCodec(){return this.hasVideoLarge?this.videoLargeInfo.codec:this.hasVideoSmall?this.videoSmallInfo.codec:this.hasScreen?this.screenInfo.codec:Oe.UNKONWN}get audioTrackInfo(){return this.hasAudio?He.AliRtcAudioTrackMic:He.AliRtcAudioTrackNo}get videoTrackInfo(){return this.hasVideo&&this.hasScreen?x.AliRtcVideoTrackBoth:this.hasVideo?x.AliRtcVideoTrackCamera:this.hasScreen?x.AliRtcVideoTrackScreen:x.AliRtcVideoTrackNo}updateTracks(e){let t="",r="",a="",n="";return e?(e.forEach(o=>{var l;let u=Oe.UNKONWN;const h=((l=o==null?void 0:o.attr)==null?void 0:l.reason)==="reconnect";if(o.userdata){const{codec:p}=JSON.parse(o.userdata);p&&(u=p)}Tr(o.msid)?(t=o.ssrc,this.audioInfo.msid=o.msid,this.audioInfo.codec=u,h&&(this.audioInfo.subscribed=!1)):yr(o.msid)?(a=o.ssrc,this.videoSmallInfo.msid=o.msid,this.videoSmallInfo.codec=u,h&&(this.videoSmallInfo.subscribed=!1)):Er(o.msid)?(r=o.ssrc,this.videoLargeInfo.msid=o.msid,this.videoLargeInfo.codec=u,h&&(this.videoLargeInfo.subscribed=!1)):Pr(o.msid)&&(n=o.ssrc,this.screenInfo.msid=o.msid,this.screenInfo.codec=u,h&&(this.screenInfo.subscribed=!1))}),this.updateRemoteTrackSsrc(t,r,a,n)):this.updateRemoteTrackSsrc(t,r,a,n),{}}updateRemoteTrackSsrc(e,t,r,a){this.audioInfo.ssrc=e,this.videoSmallInfo.ssrc=r,this.videoLargeInfo.ssrc=t,this.screenInfo.ssrc=a}updateRemoteTrackSubState(e){return e.video!==void 0&&((e.vMsid===this.videoSmallInfo.msid||!e.vMsid)&&(this.videoSmallInfo.subscribed=e.video),(e.vMsid===this.videoLargeInfo.msid||!e.vMsid)&&(this.videoLargeInfo.subscribed=e.video)),e.screen!==void 0&&(this.screenInfo.subscribed=e.screen),e.audio!==void 0&&(this.audioInfo.subscribed=e.audio),{audioInfo:this.audioInfo,videoLargeInfo:this.videoLargeInfo,videoSmallInfo:this.videoSmallInfo,screenInfo:this.screenInfo}}updateRemoteUserDeviceStatus(e){let t=ji.parseStatus(e);const{audioDisable:r,videoDisable:a,screenDisable:n}=t;return this.userStatus?(this.userStatus.audioDisable!=r&&(this.userStatus.audioDisable=r,this.emit(ie.Remote,r?H.MuteAudio:H.UnmuteAudio)),this.userStatus.videoDisable!=a&&(this.userStatus.videoDisable=a,this.emit(ie.Remote,a?H.MuteVideo:H.UnmuteVideo)),this.userStatus.screenDisable!=n&&(this.userStatus.screenDisable=n,this.emit(ie.Remote,n?H.MuteScreen:H.UnmuteScreen))):(this.userStatus=t,this.emit(ie.Remote,r?H.MuteAudio:H.UnmuteAudio),this.emit(ie.Remote,a?H.MuteVideo:H.UnmuteVideo),this.emit(ie.Remote,n?H.MuteScreen:H.UnmuteScreen)),!1}}c(wt,"logName","RemoteStreamInfo"),Nr([b()],wt.prototype,"updateRemoteTrackSubState",1);class Yi{constructor(s){c(this,"remoteUser");this.remoteUser=s}get userId(){return this.remoteUser.userId}get displayName(){return this.remoteUser.displayname}get isMuteAudioPlaying(){return this.remoteUser.getAudioMuted()}get hasAudio(){return this.remoteUser.hasAudioTrack}get hasCamera(){return this.remoteUser.hasVideoTrack}get hasCameraLarge(){return this.remoteUser.hasVideoLargeTrack}get hasCameraSmall(){return this.remoteUser.hasVideoSmallTrack}get hasScreenShare(){return this.remoteUser.hasScreenTrack}get isAudioSubscribing(){return this.remoteUser.isAudioSubscribing}get isVideoSubscribing(){return this.remoteUser.isVideoSubscribing}get isVideoLargeSubscribing(){return this.remoteUser.isVideoLargeSubscribing}get isVideoSmallSubscribing(){return this.remoteUser.isVideoSmallSubscribing}get isScreenSubscribing(){return this.remoteUser.isScreenSubscribing}}var Cr=Object.defineProperty,Lr=Object.getOwnPropertyDescriptor,te=(i,s,e,t)=>{for(var r=t>1?void 0:t?Lr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Cr(s,e,r),r};class st extends J{constructor(){super();c(this,"state");c(this,"time");c(this,"_enabled");this.state=G.AliRtcStateSubscribeIdle,this.time=Date.now(),this._enabled=!0}setState(e){if(this.state===e)return;const t=this.state,r=this.time;this.state=e,this.time=Date.now(),this.emit("change",t,e,Math.floor((this.time-r)/1e3))}get currentState(){return this.state}getEnabled(){return this._enabled}setEnabled(e){this._enabled=e}}const xt=class xt extends Ki{constructor(e){var d;const{userId:t,displayName:r,rtsManager:a,usersViewMap:n,reporter:o,webTrackingClient:u,signalingManager:h,localUserId:l,audioVolumeIndicationInterval:p}=e;super(t,r,a,p);c(this,"remoteCallid","");c(this,"remoteUserInfo");c(this,"localUserId");c(this,"lastPubId","");c(this,"stream");c(this,"screenStream");c(this,"viewMap");c(this,"audioTrack");c(this,"audioElement");c(this,"subscribed",!1);c(this,"mediaStream");c(this,"secondaryMediaStream");c(this,"prevSubConfig");c(this,"signalingManager");c(this,"reporter");c(this,"webTrackingClient");c(this,"wantSubAudio",!1);c(this,"wantSubVideo",!1);c(this,"wantSubScreen",!1);c(this,"defaultVideoStreamType",oe.AliRtcVideoStreamTypeHigh);c(this,"audioMuted",!1);c(this,"audioSubState");c(this,"videoSubState");c(this,"videoLargeSubState",new st);c(this,"videoSmallSubState",new st);c(this,"screenSubState");c(this,"streamInfo");c(this,"streamUrl","");this.streamInfo=new wt,this.remoteUserInfo=new Yi(this),this.streamInfo.on(ie.Remote,m=>{this.emit(ie.Remote,m,this.userId)}),this.signalingManager=h,this.viewMap=(d=n[t])!=null?d:{cameraViews:[],screenViews:[]},n[t]=this.viewMap,this.reporter=o,this.webTrackingClient=u,this.localUserId=l,this.audioSubState=new st,this.audioSubState.on("change",(m,g,f)=>{this.emit("audioSubscribeStateChanged",this.uid,m,g,f)}),this.videoSubState=new st,this.videoSubState.on("change",(m,g,f)=>{this.emit("videoSubscribeStateChanged",this.uid,m,g,f)}),this.screenSubState=new st,this.screenSubState.on("change",(m,g,f)=>{this.emit("screenSubscribeStateChanged",this.uid,m,g,f)})}isWantSubAudio(){return this.wantSubAudio}setWantSubAudio(e){this.wantSubAudio=e}isWantSubVideo(){return this.wantSubVideo}setWantSubVideo(e){this.wantSubVideo=e}isWantSubScreen(){return this.wantSubScreen}setWantSubScreen(e){this.wantSubScreen=e}setRemoteDefaultVideoStreamType(e){e!==this.defaultVideoStreamType&&(this.defaultVideoStreamType=e,this.updateSubscribe())}setAudioMuted(e){this.audioMuted=e,this.toggleAudio(!e)}getAudioMuted(){return this.audioMuted}get hasAudioTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasAudio)}get hasVideoTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasVideo)}get hasVideoLargeTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasVideoLarge)}get hasVideoSmallTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasVideoSmall)}get hasScreenTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasScreen)}get isAudioSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isAudioSubscribing)}get isVideoSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isVideoSubscribing)}get isVideoLargeSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isVideoLargeSubscribing)}get isVideoSmallSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isVideoSmallSubscribing)}get isScreenSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isScreenSubscribing)}get audioEnabled(){var e,t;return!!((t=(e=this.stream)==null?void 0:e.audioTrack)!=null&&t.enabled)}get videoEnabled(){var e,t;return!!((t=(e=this.stream)==null?void 0:e.videoTrack)!=null&&t.enabled)}get screenEnabled(){var e,t;return!!((t=(e=this.screenStream)==null?void 0:e.videoTrack)!=null&&t.enabled)}get getAudioTrack(){return this.audioTrack}get getCameraStream(){return this.stream}get getScreenStream(){return this.screenStream}setViewConfig(e,t){if(t!==x.AliRtcVideoTrackScreen&&t!==x.AliRtcVideoTrackCamera)throw new A(T.ERR_INVALID_ARGUMENTS,"track is not AliRtcVideoTrackScreen or AliRtcVideoTrackCamera");e?ni(e).forEach(a=>{a.setAttribute("playsinline",""),N.BrowserUtil.isMicroMessenger&&(a.setAttribute("x5-video-player-type","h5-page"),a.setAttribute("x5-playsinline",""),N.SystemUtil.isAndroid||N.SystemUtil.isIos&&a.setAttribute("x-webkit-airplay","allow")),t===x.AliRtcVideoTrackScreen?this.viewMap.screenViews.push(a):this.viewMap.cameraViews.push(a),this.play(a,t===x.AliRtcVideoTrackScreen)}):(this.stopPlayAll(t===x.AliRtcVideoTrackScreen),t===x.AliRtcVideoTrackScreen?this.viewMap.screenViews=[]:this.viewMap.cameraViews=[])}clear(e=!0){return S(this,null,function*(){var t;e&&this.doStopSubscribe(this.streamUrl),xi(xt.prototype,this,"clear").call(this),this.clearStream(),this.clearScreenStream(),(t=this.streamInfo)==null||t.removeAllListeners(ie.Remote)})}updateRemoteUserDeviceStatus(e){var t;(t=this.streamInfo)==null||t.updateRemoteUserDeviceStatus(e)}updateRemoteTracks(e,t,r,a){return S(this,null,function*(){var o;return this.remoteCallid=e,this.streamUrl=t!=null?t:"",this.callid=e!=null?e:"",this.streamInfo||(this.streamInfo=new wt),(o=this.streamInfo)==null?void 0:o.updateTracks(a)})}subscribe(e){return S(this,null,function*(){var h;e?this.reporter.reportSubscribeInvoked(this.userId,e.video,!1,e.screen,e.audio):this.reporter.reportSubscribeInvoked(this.userId);let t=e;if(!t){const{hasAudio:l,hasVideo:p,hasScreen:d}=(h=this.streamInfo)!=null?h:{};t={audio:this.wantSubAudio&&l,video:this.wantSubVideo&&p,screen:this.wantSubScreen&&d}}const{screen:r,audio:a,video:n,vMsid:o}=t,u=[];(n||a)&&u.push({audio:a,video:n,vMsid:o}),r&&u.push({screen:r}),u.length!==0&&(yield Promise.all(u.map(l=>this.subscribeProxy(l))))})}subscribeProxy(e){return S(this,null,function*(){var n,o;let t=new Date().getTime(),r="",a="";try{e.audio&&this.audioSubState.setState(G.AliRtcStateSubscribing),e.video&&(this.videoSubState.currentState===G.AliRtcStateSubscribeIdle||this.videoSubState.currentState===G.AliRtcStateNoSubscribe)&&this.videoSubState.setState(G.AliRtcStateSubscribing),e.screen&&this.screenSubState.setState(G.AliRtcStateSubscribing);const u=yield this.rtsManager.subscribe({remoteUser:this,options:e});this.streamInfo.updateRemoteTrackSubState(e),r=u;const{stream:h}=u;if(e.audio){const p=h.audioTrack;p&&(this.audioTrack=p,(n=h.mediaStream)==null||n.removeTrack(p),this.playAudio(),this.audioVolumeIndicationInterval&&this.audioLevelMonitor.start(p,this.audioVolumeIndicationInterval)),this.audioSubState.setState(G.AliRtcStateSubscribed),this.audioSubState.getEnabled()||this.toggleAudio(!1)}e.video&&(e.vMsid===w.VideoSmall?this.videoSmallSubState.setState(G.AliRtcStateSubscribed):this.videoLargeSubState.setState(G.AliRtcStateSubscribed),this.videoSubState.setState(G.AliRtcStateSubscribed),this.videoSubState.getEnabled()||this.toggleVideo(!1),this.updateStream(h,this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing)),e.screen&&(this.screenSubState.setState(G.AliRtcStateSubscribed),this.videoSubState.getEnabled()||this.toggleScreen(!1),this.updateScreenStream(h));const l=new Date().getTime()-t;this.webTrackingClient.reportPull(u.callid,u.remoteCallid,u.isVideoLargeSubscribing,u.isVideoSmallSubscribing,u.isScreenSubscribing,u.isAudioSubscribing,0,l,a,r,this.streamUrl,t)}catch(u){const h=new Date().getTime()-t;this.webTrackingClient.reportPull("","",!1,!1,!1,!1,u.code,h,a,r,(o=this.streamUrl)!=null?o:"",t),u&&(u.message=`user(${this.uid}) subscribe error, ${(u==null?void 0:u.message)||""}`);let l=T.ERR_INNER;e.audio&&(l=T.ERR_SDK_SUBSCRIBE_AUDIO_STRAM_FAILED),e.video&&(e.vMsid===w.VideoSmall?l=T.ERR_SDK_SUBSCRIBE_DUAL_STRAM_FAILED:l=T.ERR_SDK_SUBSCRIBE_VIDEO_STRAM_FAILED),e.screen&&(l=T.ERR_SDK_SUBSCRIBE_SCREEN_SHARE_FAILED);const p=A.fromError(u,l);throw this.emit("remoteSubscribeError",p),p}})}subscribeDeleteTracks(e){return S(this,null,function*(){const{audio:t,video:r,screen:a,vMsid:n}=e,o=[];(t||r)&&o.push({audio:t,video:r,vMsid:n}),a&&o.push({screen:a}),o.length!==0&&(yield Promise.all(o.map(u=>this.subscribeDeleteProxy(u))))})}subscribeDeleteProxy(e){return S(this,null,function*(){try{const t=yield this.rtsManager.subscibeDelete({remoteUser:this,options:e}),{stream:r}=t!=null?t:{},a={};e.audio===!0&&(a.audio=!1,this.audioSubState.setState(G.AliRtcStateNoSubscribe)),e.video===!0&&(a.video=!1,e.vMsid===w.VideoSmall?(this.videoSmallSubState.setState(G.AliRtcStateNoSubscribe),(this.videoLargeSubState.currentState===G.AliRtcStateNoSubscribe||this.videoLargeSubState.currentState===G.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(G.AliRtcStateNoSubscribe)):(this.videoLargeSubState.setState(G.AliRtcStateNoSubscribe),(this.videoSmallSubState.currentState===G.AliRtcStateNoSubscribe||this.videoSmallSubState.currentState===G.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(G.AliRtcStateNoSubscribe))),e.screen===!0&&(a.screen=!1,this.screenSubState.setState(G.AliRtcStateNoSubscribe));const{callid:n,remoteCallid:o}=this,u={callid:n,remoteCallid:o,remoteStream:r};return e.audio&&(this.audioLevelMonitor.stop(),this.stopPlayAudio(),this.audioTrack=void 0),this.streamInfo.updateRemoteTrackSubState({audio:e.audio===!0?!1:void 0,video:e.video===!0?!1:void 0,screen:e.screen===!0?!1:void 0,vMsid:e.vMsid}),u}catch(t){throw A.fromError(t,T.ERR_INNER,"subscribe delete failed")}})}restore(){this.clearStream(),this.clearScreenStream(),this.audioTrack=void 0,this.streamInfo.updateRemoteTrackSubState({audio:!1,video:!1,screen:!1})}resumeAudio(){return S(this,null,function*(){var e;return(e=this.audioElement)==null?void 0:e.play()})}resumeVideo(e){return S(this,null,function*(){if(!e||e===x.AliRtcVideoTrackCamera||e===x.AliRtcVideoTrackBoth)return this.playAll();if(!e||e===x.AliRtcVideoTrackScreen||e===x.AliRtcVideoTrackBoth)return this.playAll(!0)})}resumePlay(){this.playAudio(),this.playAll(),this.playAll(!0)}stopSubscribe(e){return S(this,null,function*(){var p,d,m,g,f,v,O;const{isAudioSubscribing:t=!1,isVideoSubscribing:r=!1,isScreenSubscribing:a=!1}=this,n=t&&!((p=e==null?void 0:e.audio)==null||p),o=r&&!((d=e==null?void 0:e.video)==null||d),u=!1,h=a&&!((m=e==null?void 0:e.screen)==null||m);e?this.reporter.reportSubscribeInvoked(this.userId,o,u,h,n):this.reporter.reportUnsubscribeInvoked(this.userId);let l=new Date().getTime();try{let B;e?B=yield this.subscribeDeleteTracks(e):B=yield this.doStopSubscribe(this.streamUrl),e?this.reporter.reportSubscribe((g=B==null?void 0:B.callid)!=null?g:"",this.userId,o,u,h,n,0,"",new Date().getTime()-l,(f=this.localUserId)!=null?f:""):this.reporter.reportUnsubscribe((v=B==null?void 0:B.callid)!=null?v:"",this.userId,new Date().getTime()-l,0,"")}catch(B){throw e?this.reporter.reportSubscribe("",this.userId,o,u,h,n,B.code,"",new Date().getTime()-l,(O=this.localUserId)!=null?O:""):this.reporter.reportUnsubscribe("",this.userId,new Date().getTime()-l,0,""),B}})}doStopSubscribe(e){return S(this,null,function*(){var a,n,o,u;const{callid:t,remoteCallid:r}=this;if((this.isAudioSubscribing||this.isVideoSubscribing||this.isScreenSubscribing)&&e)try{return yield this.rtsManager.subscibeStop(e),this.restore(),{callid:t,remoteCallid:r,remoteStream:this.stream}}catch(h){if(((u=(o=(n=(a=h==null?void 0:h.extraInfo)==null?void 0:a.parsedData)==null?void 0:n.streams)==null?void 0:o[0])==null?void 0:u.res_code)!==404)throw A.fromError(h,T.ERR_INNER,"subscribe stop failed")}})}updateStream(e,t=!1){return S(this,null,function*(){this.stream&&this.stream.videoTrack&&e.mediaStream&&t&&(yield new Promise(r=>{let a,n;if(e.mediaStream){n=document.createElement("video");const o=()=>{I.event(`uid: ${this.userId} new mediaStream canplay`),n&&n.removeEventListener("canplaythrough",o,!1),n=void 0,clearTimeout(a),r(!0)};n.addEventListener("canplaythrough",o,!1),(n._playPromise||Promise.resolve()).then(()=>{n&&e.mediaStream&&(n.srcObject=e.mediaStream)})}else r(!0);a=window.setTimeout(()=>{I.event(`uid: ${this.userId} new mediaStream timeout`),n=void 0,r(!0)},3e3)}),this.updateSubscribe()),this.stream=e,this.playAll(),!this.subscribed&&e&&(this.subscribed=!0),e.hasAudio&&this.isAudioSubscribing&&e.enableAudio(),e.hasVideo&&this.isVideoSubscribing&&e.enableVideo()})}updateScreenStream(e){this.screenStream=e,this.playAll(!0),!this.subscribed&&e&&(this.subscribed=!0),e.hasVideo&&this.isScreenSubscribing&&e.enableVideo()}clearStream(){var e;(e=this.stream)==null||e.stop(),this.stream=void 0}clearScreenStream(){var e;(e=this.screenStream)==null||e.stop(),this.screenStream=void 0}updateSubscribe(){var r,a,n,o,u,h,l,p;const e={},t={};return this.wantSubAudio&&!this.isAudioSubscribing&&((r=this.streamInfo)!=null&&r.hasAudio)?e.audio=!0:(!this.wantSubAudio||!((a=this.streamInfo)!=null&&a.hasAudio))&&this.isAudioSubscribing&&(t.audio=!0),this.wantSubVideo&&((n=this.streamInfo)!=null&&n.hasVideo)?(this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&!this.isVideoSmallSubscribing&&((o=this.streamInfo)!=null&&o.hasVideoSmall)?(e.video=!0,e.vMsid=w.VideoSmall):!this.isVideoLargeSubscribing&&((u=this.streamInfo)!=null&&u.hasVideoLarge)&&!(this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoSmallSubscribing)&&(e.video=!0,e.vMsid=w.VideoLarge),this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&this.streamInfo.hasVideoSmall?(t.video=!0,t.vMsid=w.VideoLarge):this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeHigh&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&(t.video=!0,t.vMsid=w.VideoSmall)):(!this.wantSubVideo||!((h=this.streamInfo)!=null&&h.hasVideo))&&this.isVideoSubscribing&&(t.video=!0,t.vMsid=this.streamInfo.isVideoSmallSubscribing?w.VideoSmall:w.VideoLarge),this.wantSubScreen&&!this.isScreenSubscribing&&((l=this.streamInfo)!=null&&l.hasScreen)?e.screen=!0:(!this.wantSubScreen||!((p=this.streamInfo)!=null&&p.hasScreen))&&this.isScreenSubscribing&&(t.screen=!0),(e.audio||e.video||e.screen)&&this.subscribe(e),t.audio&&t.video&&t.screen?this.stopSubscribe():(t.audio||t.video||t.screen)&&this.subscribeDeleteTracks(t),{addOption:e,deleteOption:t}}handleAutoPlayFailed(){this.emit("remoteAudioAutoPlayFail",this.uid);const e=()=>{this.resumeAudio().then(()=>{document.removeEventListener("click",e,!1),document.removeEventListener("touchstart",e,!1)})};document.addEventListener("click",e,!1),document.addEventListener("touchstart",e,!1)}handleVideoPlayFailded(e,t){this.emit("remoteVideoAutoPlayFail",this.uid,t);const r=()=>{var n;const a=(n=t===x.AliRtcVideoTrackScreen?this.screenStream:this.stream)==null?void 0:n.mediaStream;e.srcObject===a&&this.play(e,t===x.AliRtcVideoTrackScreen),document.removeEventListener("click",r,!1),document.removeEventListener("touchstart",r,!1)};document.addEventListener("click",r,!1),document.addEventListener("touchstart",r,!1)}playAudio(){return S(this,null,function*(){var t,r;if(!this.audioTrack)return;if(this.toggleAudio(!this.audioMuted),this.audioElement||(this.audioElement=document.createElement("audio")),((r=(t=this.audioElement.srcObject)==null?void 0:t.getAudioTracks())==null?void 0:r[0])!==this.audioTrack){let a=this.audioElement.srcObject;a?a.getAudioTracks().forEach(n=>{a.removeTrack(n)}):(a=new MediaStream,this.audioElement.srcObject=a),a.addTrack(this.audioTrack)}this.audioElement.play().catch(()=>{this.handleAutoPlayFailed()});const e=this.audioElement;this.audioElement.addEventListener("playing",function a(){e.removeEventListener("playing",a),N.SystemUtil.isIos&&parseInt(N.SystemUtil.systemVersion)<=14&&(e.muted||(e.pause(),e.play()))})})}stopPlayAudio(){this.audioElement&&(this.audioElement.pause(),this.audioElement.srcObject=null)}playAll(e=!1){e?(this.viewMap.screenViews||[]).forEach(t=>{this.play(t,e)}):(this.viewMap.cameraViews||[]).forEach(t=>{this.play(t,e)})}play(e,t=!1){const r=t?this.screenStream:this.stream;!e||!r||!r.mediaStream||Gi(e,r.mediaStream).catch(a=>{a.code===20||a.name==="AbortError"||this.handleVideoPlayFailded(e,t?x.AliRtcVideoTrackScreen:x.AliRtcVideoTrackCamera)})}stopPlayAll(e=!1){e?this.viewMap.screenViews.forEach(t=>{ke(t)}):this.viewMap.cameraViews.forEach(t=>{ke(t)})}toggleAudio(e=!0){this.audioSubState.setEnabled(e),this.audioTrack&&(this.audioTrack.enabled=e)}toggleVideo(e=!0){this.videoSubState.setEnabled(e),this.stream&&(e?this.stream.enableVideo():this.stream.disableVideo())}toggleScreen(e=!0){this.screenSubState.setEnabled(e),this.screenStream&&(e?this.screenStream.enableVideo():this.screenStream.disableVideo())}getStats(){return S(this,null,function*(){var r,a;const e=[];if(this.isAudioSubscribing){const n=yield this.rtsManager.getSubscribeAudioStats(this.streamUrl);n&&e.push({uid:this.uid,track:He.AliRtcAudioTrackMic,stats:n})}const t=[];if((r=this.streamInfo)!=null&&r.isVideoLargeSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,w.VideoLarge);n&&t.push({uid:this.uid,track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:n})}if((a=this.streamInfo)!=null&&a.isVideoSmallSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,w.VideoSmall);n&&t.push({uid:this.uid,track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:n})}if(this.isScreenSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,w.Screen);n&&t.push({uid:this.uid,track:x.AliRtcVideoTrackScreen,stats:n})}return{audio:e,video:t}})}enableAudioVolumeIndication(e){this.audioVolumeIndicationInterval!==e&&(this.audioVolumeIndicationInterval>0&&e<=0&&this.audioLevelMonitor.stop(),e>0&&this.audioTrack&&this.audioLevelMonitor.start(this.audioTrack,e),this.audioVolumeIndicationInterval=e)}};c(xt,"logName","RemoteUser");let Y=xt;te([b()],Y.prototype,"clear",1),te([b()],Y.prototype,"updateRemoteUserDeviceStatus",1),te([b()],Y.prototype,"updateRemoteTracks",1),te([b(R)],Y.prototype,"subscribe",1),te([b()],Y.prototype,"subscribeProxy",1),te([b(R)],Y.prototype,"subscribeDeleteTracks",1),te([b(R)],Y.prototype,"subscribeDeleteProxy",1),te([b()],Y.prototype,"restore",1),te([b(R)],Y.prototype,"stopSubscribe",1),te([b(R)],Y.prototype,"doStopSubscribe",1),te([b()],Y.prototype,"clearStream",1),te([b()],Y.prototype,"clearScreenStream",1),te([b()],Y.prototype,"updateSubscribe",1),te([b()],Y.prototype,"playAudio",1),te([b()],Y.prototype,"stopPlayAudio",1),te([b(R)],Y.prototype,"playAll",1),te([b()],Y.prototype,"play",1),te([b()],Y.prototype,"stopPlayAll",1);var Me=(i=>(i[i.AliRtcPluginErrorCodeSuccess=0]="AliRtcPluginErrorCodeSuccess",i[i.AliRtcPluginErrorCodeFailed=-1]="AliRtcPluginErrorCodeFailed",i[i.AliRtcPluginErrorNoFindPlugin=-2]="AliRtcPluginErrorNoFindPlugin",i[i.AliRtcPluginErrorParameterError=-3]="AliRtcPluginErrorParameterError",i[i.AliRtcPluginErrorLoadError=-4]="AliRtcPluginErrorLoadError",i[i.AliRtcPluginErrorCreateError=-5]="AliRtcPluginErrorCreateError",i[i.AliRtcPluginErrorInitError=-6]="AliRtcPluginErrorInitError",i[i.AliRtcPluginErrorInitTokenError=-7]="AliRtcPluginErrorInitTokenError",i))(Me||{});class Vr extends J{constructor(){super(...arguments);c(this,"plugins",new Map)}add(e,t){if(this.plugins.has(e.name))throw new A(Me.AliRtcPluginErrorCreateError,`Plugin ${e.name} already exists`);this.plugins.set(e.name,e),t&&e.setOptions(t),this.emit("added",e),e.on("enabled",()=>this.emit("added",e)),e.on("disabled",()=>this.emit("removed",e)),e.on("updated",()=>this.emit("updated",e))}remove(e){const t=this.plugins.get(e);if(!t)throw new A(Me.AliRtcPluginErrorNoFindPlugin,`Plugin ${e} not founded`);this.plugins.delete(e),t.removeAllListeners(),this.emit("removed",t)}get(e){return this.plugins.get(e)}has(e){return!!this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}}var Or=Object.defineProperty,Dr=Object.getOwnPropertyDescriptor,ce=(i,s,e,t)=>{for(var r=t>1?void 0:t?Dr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Or(s,e,r),r};const Rt=([i])=>{const{remoteUser:s,options:e}=i;return[`user(${s.userId})`,e]},ae=(Fe=class extends J{constructor(e){super();c(this,"rts");c(this,"encodedInsertableStreams",!1);c(this,"localStreamManager");c(this,"connecting",!1);c(this,"connected",!1);c(this,"connectionResolve");c(this,"connectingPromise");c(this,"dcResolve");c(this,"dcConnectingPromise");c(this,"_publishingTracks",[]);this.rts=P.AliRTS.createClient(),this.localStreamManager=e,this.rts.on("connectStatusChange",t=>{I.event(`[${Fe.logName}]`,"rts connectStatusChange to:",t.status),(t.status===P.EConnectStatus.CONNECT_STATUS_RECONNECTING||t.status===P.EConnectStatus.CONNECT_STATUS_DISCONNECTED)&&this.setConnected(!1)}),this.rts.on("datachannelStatusChange",t=>{I.event(`[${Fe.logName}]`,"rts datachannelStatusChange to:",t.status),t.status===P.EDatachannelStatus.DATACHANNEL_STATUS_OPEN?this.dcResolve&&this.dcResolve(!0):t.status===P.EDatachannelStatus.DATACHANNEL_STATUS_CLOSE&&(this.dcConnectingPromise=new Promise(r=>{this.dcResolve=r}),console.warn("DC DisConnected"))}),this.rts.on("connectStatusChange",t=>{t.status===P.EConnectStatus.CONNECT_STATUS_RECONNECTING?this.emit("reconnecting"):t.status===P.EConnectStatus.CONNECT_STATUS_DISCONNECTED&&this.emit("disconnected")}),this.rts.on("receivedSEI",t=>{this.emit("seimessage",t.url,t.sei.payloadType,t.sei.data)})}setEncodedInsertableStreams(e){this.encodedInsertableStreams=e}destroy(){this.rts.unpublish()}startConnect(){this.connecting=!0,this.connectingPromise=new Promise(e=>{this.connectionResolve=e}),this.dcConnectingPromise=new Promise(e=>{this.dcResolve=e})}setConnected(e){var t;this.connected=e,this.connecting=!1,(t=this.connectionResolve)==null||t.call(this,!0),e||(this.dcConnectingPromise=new Promise(r=>{this.dcResolve=r}))}get publishingTracks(){return this._publishingTracks}getPubMsid(e,t){const{aMsid:r,vMsid:a}=t!=null?t:{},n={};return e.hasAudio&&(n.aMsid=[r!=null?r:w.Audio]),e.hasScreen&&(n.vMsid=[w.Screen]),e.hasVideo&&(n.vMsid=[a!=null?a:t!=null&&t.isScreen?w.Screen:w.VideoLarge]),n}updatePublishingTracks(e){e&&(this._publishingTracks=e.map(({msid:t,from:r,ssrc:a,codec:n,type:o,trackId:u})=>({msid:t,from:r,type:o,ssrc:`${a}`,codec:n!=null?n:"",trackId:u})))}httpPublish(e,t=!1){return S(this,null,function*(){const{publishStream:r,videoSmallStream:a,screenStream:n,vMsid:o}=yield this.localStreamManager.createHTTPPublishStream();if(!r)return"";const u=this.getPubMsid(r,{vMsid:o});(P.AliRTS.SystenUtil.isIos||P.AliRTS.BrowserUtil.isSafari)&&(u.tcpOnly=!0),u.retryTimes=0,this.encodedInsertableStreams&&(u.encodedInsertableStreams=!0);let h=!r.hasVideo,l=o;try{this.startConnect();const p=yield this.rts.publish(e,r,u);return this.setConnected(!0),this._publishingTracks=this.rts.getPublishTrackInfoList(),a&&(yield this.publishAdd(e,a,{vMsid:w.VideoSmall},t),h=!1,l=w.VideoSmall),n&&(yield this.publishAdd(e,n,{vMsid:w.Screen},t),h=!1,l=w.Screen),yield this.waitPublishSender(e,h,l),p}catch(p){throw this.setConnected(!1),p}})}waitPublishSender(e,t=!1,r){return S(this,null,function*(){const a=(n,o)=>{let u=0;const h=()=>(t?this.rts.getPublishAudioStats(e,r):this.rts.getPublishVideoStats(e,r)).then(p=>!(p.bytesSent>0)&&u<n?(u++,new Promise(m=>setTimeout(()=>m(h()),o))):Promise.resolve());return h()};return Promise.race([Ve(1e3),a(5,100)]).catch(()=>{})})}getPublishVideoStats(e,t){return S(this,null,function*(){return yield this.rts.getPublishVideoStats(e,t)})}getPublishAudioStats(e,t){return S(this,null,function*(){return yield this.rts.getPublishAudioStats(e,t)})}publishAdd(e,t,r,a=!1,n=0,o=!1){return S(this,null,function*(){try{yield this.dcConnectingPromise;const u=yield this.rts.publishAdd([W({url:e,stream:t,updateSourceStream:!1},this.getPubMsid(t,r))]);if(u){const[h]=u;return this.updatePublishingTracks(h.trackInfoList),o&&(yield this.waitPublishSender(e,!t.hasVideo,t.hasVideo?r==null?void 0:r.vMsid:r==null?void 0:r.aMsid)),h.traceId||""}}catch(u){if(u.errorCode===15006&&n<3)return yield this.publishAdd(e,t,r,a,n+1);throw u}return""})}publishDelete(e,t){return S(this,null,function*(){var l,p,d,m,g,f,v,O;yield this.dcConnectingPromise;const r=(p=(l=this.publishingTracks)==null?void 0:l.find(({msid:B})=>B===w.Audio))==null?void 0:p.msid,a=(m=(d=this.publishingTracks)==null?void 0:d.find(({msid:B})=>B===w.VideoLarge))==null?void 0:m.msid,n=(f=(g=this.publishingTracks)==null?void 0:g.find(({msid:B})=>B===w.Screen))==null?void 0:f.msid,o=[];t.screen&&n?o.push(n):t.video&&o.push(t.vMsid||a);const u=[];t.audio&&r&&u.push(r);const[h]=(yield this.rts.publishDeleteTracks([{url:e,aMsid:u,vMsid:o}]))||[];return h&&this.updatePublishingTracks(h.trackInfoList),((O=(v=h==null?void 0:h.trackInfoList)==null?void 0:v[0])==null?void 0:O.trackId)||""})}publishReplace(e,t,r){return S(this,null,function*(){var h,l;yield this.dcConnectingPromise;const{vMsid:a,aMsid:n}=r!=null?r:{},o=yield this.rts.publishReplaceTracks([{url:e,stream:t,updateSourceStream:!1,vMsid:a,aMsid:n}]),[u]=o;return this.updatePublishingTracks(u.trackInfoList),((l=(h=u==null?void 0:u.trackInfoList)==null?void 0:h[0])==null?void 0:l.trackId)||""})}publishStop(e){return S(this,null,function*(){return yield this.rts.publishStop([{url:e}]),this._publishingTracks=[],""})}unpublish(){return S(this,null,function*(){yield this.rts.unpublish(),this.connecting=!1,this.connected=!1})}getSubConfig(e,t){let r=t!=null?t:{};t||(r={audio:!0,video:!0,screen:!0});const a={};return r.audio&&(a.aMsid=[(e==null?void 0:e.getAudioInfo().msid)||w.Audio]),r.video?r.vMsid?a.vMsid=[r.vMsid]:e!=null&&e.hasVideoLarge?a.vMsid=[(e==null?void 0:e.getVideoLargeInfo().msid)||w.VideoLarge]:e!=null&&e.hasVideoSmall?a.vMsid=[(e==null?void 0:e.getVideoSmallInfo().msid)||w.VideoSmall]:a.vMsid=[w.VideoLarge]:r.screen&&e!=null&&e.hasScreen&&(a.vMsid=[(e==null?void 0:e.getScreenInfo().msid)||w.Screen]),a}httpSubscribe(e){return S(this,null,function*(){const{remoteUser:t,options:r}=e;let a=t.streamUrl;r.video||r.screen?r!=null&&r.audio||(a+="@subaudio=no"):a+="@subvideo=no";const n=this.getSubConfig(t.streamInfo,r);(P.AliRTS.SystenUtil.isIos||P.AliRTS.BrowserUtil.isSafari)&&(n.tcpOnly=!0),n.retryTimes=0,this.encodedInsertableStreams&&(n.encodedInsertableStreams=!0);try{this.startConnect();const o=yield this.rts.subscribe(a,n);return this.setConnected(!0),{traceId:o.traceId,stream:o}}catch(o){throw this.setConnected(!1),o}})}subscribeAdd(e){return S(this,null,function*(){var n,o,u,h;yield this.dcConnectingPromise;const{remoteUser:t,options:r}=e,a=qe(W({url:t.streamUrl,subAudio:!!r.audio,subVideo:!!(r.screen||r.video)},this.getSubConfig(t.streamInfo,r)),{targetStream:r.screen?t.getScreenStream:t.getCameraStream});try{return(yield this.rts.subscribeAdd([a]))[0]}catch(l){if(((h=(u=(o=(n=l==null?void 0:l.extraInfo)==null?void 0:n.parsedData)==null?void 0:o.streams)==null?void 0:u[0])==null?void 0:h.res_code)===508)return this.emit("subscribeexceeds"),null;throw A.fromError(l)}return null})}subscibeDelete(e){return S(this,null,function*(){var n,o,u,h;yield this.dcConnectingPromise;const{remoteUser:t,options:r}=e,a=qe(W({url:t.streamUrl,subAudio:!!r.audio,subVideo:!!(r.screen||r.video)},this.getSubConfig(t.streamInfo,r)),{targetStream:r.screen?t.getScreenStream:t.getCameraStream});try{return(yield this.rts.subscribeDeleteTracks([a]))[0]}catch(l){if(((h=(u=(o=(n=l==null?void 0:l.extraInfo)==null?void 0:n.parsedData)==null?void 0:o.streams)==null?void 0:u[0])==null?void 0:h.res_code)===404)return;throw l}})}subscibeStop(e){return S(this,null,function*(){var t,r,a,n;try{yield this.rts.subscribeStop([{url:e}])}catch(o){if(((n=(a=(r=(t=o==null?void 0:o.extraInfo)==null?void 0:t.parsedData)==null?void 0:r.streams)==null?void 0:a[0])==null?void 0:n.res_code)===404)return;throw o}})}publish(e,t=!1){return S(this,null,function*(){let r="";if(this.connecting&&(yield this.connectingPromise),this.connected){yield this.dcConnectingPromise;let a=!1,n;const{audio:o,video:u,videoSmall:h,screen:l}=this.localStreamManager.publishStreams;o&&(r=yield this.publishAdd(e,o,{aMsid:w.Audio},t),a=!0,n=w.Audio,yield Ve(100)),u&&(r=yield this.publishAdd(e,u,{vMsid:w.VideoLarge},t),a=!1,n=w.VideoLarge,yield Ve(100)),h&&(r=yield this.publishAdd(e,h,{vMsid:w.VideoSmall},t),a=!1,n=w.VideoSmall,yield Ve(100)),l&&(r=yield this.publishAdd(e,l,{isScreen:!0,vMsid:w.Screen},t),a=!1,n=w.Screen),n&&(yield this.waitPublishSender(e,a,n))}else r=yield this.httpPublish(e,t);return r})}subscribe(e){return S(this,null,function*(){const{options:t}=e;if(t.video&&t.screen)throw new A(T.ERR_INNER,"subscribe error, video and screen cannot be subscribed at the same time");this.connecting&&(yield this.connectingPromise);let r;return this.connected?(yield this.dcConnectingPromise,r=yield this.subscribeAdd(e)):r=yield this.httpSubscribe(e),r})}getSubscribeVideoStats(e,t){return S(this,null,function*(){return yield this.rts.getSubscribeVideoStats(e,t)})}getSubscribeAudioStats(e,t){return S(this,null,function*(){return yield this.rts.getSubscribeAudioStats(e,t)})}sendSEI(e,t,r,a){return S(this,null,function*(){return this.rts.sendSEI({url:e,vMsid:w.VideoLarge,data:t,repeatCount:r,payloadType:a})})}},c(Fe,"logName","RtsManager"),Fe);ce([b()],ae.prototype,"updatePublishingTracks",1),ce([b(R,R)],ae.prototype,"httpPublish",1),ce([b(R,R)],ae.prototype,"waitPublishSender",1),ce([b(([i,s,e])=>[i,JSON.stringify(e)],R)],ae.prototype,"publishAdd",1),ce([b(R,R)],ae.prototype,"publishDelete",1),ce([b(([i,s,e])=>[i,JSON.stringify(e)])],ae.prototype,"publishReplace",1),ce([b(R)],ae.prototype,"publishStop",1),ce([b()],ae.prototype,"unpublish",1),ce([b(Rt,({traceId:i})=>i)],ae.prototype,"httpSubscribe",1),ce([b(Rt,({traceId:i})=>i)],ae.prototype,"subscribeAdd",1),ce([b(Rt)],ae.prototype,"subscibeDelete",1),ce([b(R)],ae.prototype,"subscibeStop",1),ce([b(R)],ae.prototype,"publish",1),ce([b(Rt)],ae.prototype,"subscribe",1),ce([b()],ae.prototype,"sendSEI",1);let Ur=ae;class oi{constructor(){c(this,"profile");c(this,"profileMap",new Map);c(this,"audioProfile");c(this,"contentHint")}updateProfile(s,e){e&&this.profileMap.set(s,e),this.profile=s}get videoProfile(){return this.profile}updateAudioProfile(s){this.audioProfile=s}setContentHint(s,e){e&&(this.contentHint=e),this.contentHint&&s&&(s.contentHint=this.contentHint)}setVideoProfile(s,e,t=!1){return S(this,null,function*(){if(!this.profile)return;const r=this.profileMap.get(this.profile)||(e==null?void 0:e.VideoProfileMap.get(this.profile));if(r){if(!t&&s&&s.applyConstraints)try{yield s.applyConstraints(r)}catch(a){}e&&(e==null||e.VideoProfileMap.set(this.profile,r),yield e.setVideoProfile(this.profile))}})}}class ci extends J{constructor(e){super();c(this,"type");c(this,"originVideoTrack");c(this,"videoSource");c(this,"_videoMuted",!1);c(this,"originAudioTrack");c(this,"audioSource");c(this,"_audioMuted",!1);c(this,"_targetVideoTrack");c(this,"_targetDualVideoTrack");c(this,"_targetAudioTrack");c(this,"_publishVideoStream");c(this,"_publishDualVideoStream");c(this,"_publishAudioStream");c(this,"_previewStream");c(this,"plugins",[]);c(this,"_profileManager");c(this,"cameraVideoConstraints");c(this,"micAudioConstraints");c(this,"onVideoTrackEnded",()=>{this.emit("videotrackended")});c(this,"onAudioTrackEnded",()=>{this.emit("audiotrackended")});this.type=e}get profileManager(){return this._profileManager}get audioProfile(){var e;return(e=this.profileManager)==null?void 0:e.audioProfile}updateSource(e,t,r){return S(this,null,function*(){var o,u,h,l;const{videoTrack:a,audioTrack:n}=e;if(a&&!t&&t!==_e.Camera)throw new A(T.ERR_INNER,"VideoStreamSource is required");if(n&&!r&&r!==pt.Microphone)throw new A(T.ERR_INNER,"AudioStreamSource is required");a&&((o=this.originVideoTrack)==null||o.removeEventListener("ended",this.onVideoTrackEnded)),n&&((u=this.originAudioTrack)==null||u.removeEventListener("ended",this.onAudioTrackEnded)),this.type===Q.AliRtcSdkStreamTypeScreen?this.stop():(a&&((h=this.originVideoTrack)==null||h.stop()),n&&((l=this.originAudioTrack)==null||l.stop())),a&&(this.originVideoTrack=a,this.originVideoTrack.addEventListener("ended",this.onVideoTrackEnded),this.videoSource=t,this.updateVideoTrack(a)),n&&(this.originAudioTrack=n,this.originAudioTrack.addEventListener("ended",this.onAudioTrackEnded),this.audioSource=r,this.updateAudioTrack(n))})}get currentProfile(){var e;return(e=this.profileManager)==null?void 0:e.profile}get currentVideoTrack(){return this._targetVideoTrack}get currentDualVideoTrack(){return this._targetDualVideoTrack}get publishVideoStream(){return this._publishVideoStream}get publishDualVideoStream(){return this._publishDualVideoStream}get currentAudioTrack(){return this._targetAudioTrack}get publishAudioStream(){return this._publishAudioStream}get previewStream(){return this._previewStream}updateVideoTrack(e,t=!1){return S(this,null,function*(){(this._targetVideoTrack!==e||t)&&(this._targetVideoTrack=e)})}updateDualVideoTrack(e,t=!1){return S(this,null,function*(){(this._targetDualVideoTrack!==e||t)&&(this._targetDualVideoTrack=e)})}updateAudioTrack(e,t=!1){return S(this,null,function*(){(this._targetAudioTrack!==e||t)&&(this._targetAudioTrack=e)})}setAudioMuted(e){var t,r;this._audioMuted=e,e?(t=this.publishAudioStream)==null||t.disableAudio():(r=this.publishAudioStream)==null||r.enableAudio()}get isAudioMuted(){return this._audioMuted}setVideoMuted(e){var t,r;this._videoMuted=e,e?(t=this.publishVideoStream)==null||t.disableVideo():(r=this.publishVideoStream)==null||r.enableVideo()}get isVideoMuted(){return this._videoMuted}process(e){return S(this,null,function*(){var t,r,a,n,o,u,h,l,p,d,m,g;this._targetAudioTrack=this.originAudioTrack,this._targetVideoTrack=this.originVideoTrack;for(const f of this.plugins)try{yield f.execute(this,e)}catch(v){console.error(`error in plugin-${f.name}, error: ${v}`)}this._targetVideoTrack?((r=(t=this._publishVideoStream)==null?void 0:t.videoTrack)==null?void 0:r.id)!==this._targetVideoTrack.id&&(this._publishVideoStream=yield it(this._targetVideoTrack),this.setVideoMuted(this._videoMuted),(a=this.profileManager)==null||a.setVideoProfile(this.originVideoTrack,this._publishVideoStream,!0),(n=this.profileManager)==null||n.setContentHint(this._targetVideoTrack),this.previewStream?(o=this.previewStream)==null||o.mergeStream(this._publishVideoStream):this._previewStream=yield it(this._targetVideoTrack)):(this._publishVideoStream=void 0,(u=this.previewStream)==null||u.deleteTracks({video:!0})),this._targetDualVideoTrack?((l=(h=this._publishDualVideoStream)==null?void 0:h.videoTrack)==null?void 0:l.id)!==this._targetDualVideoTrack.id&&(this._publishDualVideoStream=yield it(this._targetDualVideoTrack),this._videoMuted?this._publishDualVideoStream.disableVideo():this._publishDualVideoStream.enableVideo()):this._publishDualVideoStream=void 0,this._targetAudioTrack?((d=(p=this._publishAudioStream)==null?void 0:p.audioTrack)==null?void 0:d.id)!==this._targetAudioTrack.id&&(this._publishAudioStream=yield it(this._targetAudioTrack),this.setAudioMuted(this._audioMuted),this.previewStream?(m=this.previewStream)==null||m.mergeStream(this._publishAudioStream):this._previewStream=yield it(this._targetAudioTrack)):(this._publishAudioStream=void 0,(g=this.previewStream)==null||g.deleteTracks({audio:!0}))})}stopVideo(){var e,t;this.originVideoTrack&&((e=this.originVideoTrack)==null||e.removeEventListener("ended",this.onAudioTrackEnded),(t=this.originVideoTrack)==null||t.stop(),this.originVideoTrack=void 0),this.updateVideoTrack(void 0)}stopAudio(){var e,t;this.originAudioTrack&&((e=this.originAudioTrack)==null||e.removeEventListener("ended",this.onAudioTrackEnded),(t=this.originAudioTrack)==null||t.stop(),this.originAudioTrack=void 0),this.updateAudioTrack(void 0)}stop(){this.stopVideo(),this.stopAudio()}updateVideoProfile(e,t){return S(this,null,function*(){this._profileManager||(this._profileManager=new oi),e&&this._profileManager.updateProfile(e,t),yield this._profileManager.setVideoProfile(this.originVideoTrack,this._publishVideoStream,this.type===Q.AliRtcSdkStreamTypeScreen)})}get videoProfile(){var e;return(e=this.profileManager)==null?void 0:e.videoProfile}setVideoContentHint(e){this._profileManager||(this._profileManager=new oi),this._profileManager.setContentHint(this.currentVideoTrack,e)}updateAudioProfile(e){return S(this,null,function*(){this._profileManager||(this._profileManager=new oi),this._profileManager.updateAudioProfile(e)})}cloneVideoProfile(e){return S(this,null,function*(){var t;yield(t=this.profileManager)==null?void 0:t.setVideoProfile(void 0,e)})}addPlugin(e){const t=this.plugins.findIndex(r=>r.zIndex>e.zIndex);t>-1?this.plugins.splice(t,0,e):this.plugins.push(e)}removePlugin(e){const t=this.plugins.indexOf(e);return t>-1?(e.clear(this),this.plugins.splice(t,1),!0):!1}}var xr=Object.defineProperty,Br=Object.getOwnPropertyDescriptor,Se=(i,s,e,t)=>{for(var r=t>1?void 0:t?Br(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&xr(s,e,r),r};const me=(je=class extends J{constructor(e){super();c(this,"pluginManager");c(this,"publishingCameraVideoStream");c(this,"publishingScreenVideoStream");c(this,"cameraStreamInfo",new ci(Q.AliRtcSdkStreamTypeCapture));c(this,"screenStreamInfo",new ci(Q.AliRtcSdkStreamTypeScreen));c(this,"streamInfos",[this.cameraStreamInfo,this.screenStreamInfo]);c(this,"_audioCaptureDisabled",!1);c(this,"_cameraCaptureDisabled",!1);c(this,"_publishLocalAudioStreamEnabled",!0);c(this,"_publishLocalVideoStreamEnabled",!0);c(this,"_publishLocalScreenStreamEnabled",!0);this.screenStreamInfo.setVideoContentHint("motion"),this.pluginManager=e;const t=r=>S(this,null,function*(){if(I.info(`[${je.logName}]`,"plugin added",r.name),!r.isSupported("6.11.3")){console.warn(`${r.name} is not supported!!!`),r.emit("unsupported");return}try{yield r.init()}catch(a){r.emit("error",A.fromError(a,Me.AliRtcPluginErrorInitError))}r.streamType===Q.AliRtcSdkStreamTypeCapture&&(this.cameraStreamInfo.addPlugin(r),yield this.cameraStreamInfo.process(this.streamInfos)),r.streamType===Q.AliRtcSdkStreamTypeScreen&&(this.screenStreamInfo.addPlugin(r),yield this.screenStreamInfo.process(this.streamInfos)),this.emit("publishupdate")});this.cameraStreamInfo.updateVideoProfile($i,et),this.cameraStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({video:!0}),this.emit("trackended",De.VideoTrackEnded)})),this.cameraStreamInfo.on("audiotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({audio:!0}),this.emit("trackended",De.AudioTrackEnded)})),this.screenStreamInfo.updateVideoProfile(Ji,tt),this.screenStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({screen:!0}),this.emit("trackended",De.ScreenTrackEnded)})),this.pluginManager.on("added",t),this.pluginManager.on("removed",r=>S(this,null,function*(){this.cameraStreamInfo.removePlugin(r)&&(yield this.cameraStreamInfo.process(this.streamInfos)),this.screenStreamInfo.removePlugin(r)&&(yield this.screenStreamInfo.process(this.streamInfos)),this.emit("publishupdate")})),this.pluginManager.on("updated",()=>S(this,null,function*(){yield this.updateStreams()}))}get hasCamera(){return!!this.cameraStreamInfo.originVideoTrack}get audioCaptureDisabled(){return this._audioCaptureDisabled}set audioCaptureDisabled(e){this._audioCaptureDisabled=e}get cameraCaptureDisabled(){return this._cameraCaptureDisabled}setAudioMuted(e){this.cameraStreamInfo.setAudioMuted(e)}get isAudioMuted(){return this.cameraStreamInfo.isAudioMuted}setCameraMuted(e){this.cameraStreamInfo.setVideoMuted(e)}get isCameraMuted(){return this.cameraStreamInfo.isVideoMuted}setScreenMuted(e){this.screenStreamInfo.setVideoMuted(e)}get isScreenMuted(){return this.screenStreamInfo.isVideoMuted}set cameraCaptureDisabled(e){this._cameraCaptureDisabled=e}get publishLocalAudioStreamEnabled(){return this._publishLocalAudioStreamEnabled}set publishLocalAudioStreamEnabled(e){this._publishLocalAudioStreamEnabled=e}get publishLocalVideoStreamEnabled(){return this._publishLocalVideoStreamEnabled}set publishLocalVideoStreamEnabled(e){this._publishLocalVideoStreamEnabled=e}get publishLocalScreenStreamEnabled(){return this._publishLocalScreenStreamEnabled}set publishLocalScreenStreamEnabled(e){this._publishLocalScreenStreamEnabled=e}updateStreams(){return S(this,null,function*(){yield this.cameraStreamInfo.process(this.streamInfos),yield this.screenStreamInfo.process(this.streamInfos),this.emit("publishupdate")})}setAvailableCameraDeviceId(){return S(this,null,function*(){var e,t,r,a;if((e=this.cameraStreamInfo.cameraVideoConstraints)!=null&&e.deviceId){let n=(t=this.cameraStreamInfo.cameraVideoConstraints)==null?void 0:t.deviceId;const o=yield P.AliRTS.getCameraList();o.find(u=>u.deviceId===n)||(n=(a=(r=o.find(u=>!!u.deviceId))==null?void 0:r.deviceId)!=null?a:""),this.cameraStreamInfo.cameraVideoConstraints.deviceId=n}})}setAvailableMicrophoneDeviceId(){return S(this,null,function*(){var e,t,r,a;if((e=this.cameraStreamInfo.micAudioConstraints)!=null&&e.deviceId){let n=(t=this.cameraStreamInfo.micAudioConstraints)==null?void 0:t.deviceId;const o=yield P.AliRTS.getMicList();o.find(u=>u.deviceId===n)||(n=(a=(r=o.find(u=>!!u.deviceId))==null?void 0:r.deviceId)!=null?a:""),this.cameraStreamInfo.micAudioConstraints.deviceId=n}})}createLocalStream(e){return S(this,null,function*(){const{screen:t,mediaStream:r,videoProfile:a,screenProfile:n}=e;let{video:o,audio:u}=e;const h=Ar(e);let l;if(h){if(o===!0&&this.cameraStreamInfo.cameraVideoConstraints?(yield this.setAvailableCameraDeviceId(),o=W({},this.cameraStreamInfo.cameraVideoConstraints)):typeof o=="object"&&(yield this.setAvailableCameraDeviceId(),o=W(W({},o),this.cameraStreamInfo.cameraVideoConstraints)),u===void 0&&this.audioCaptureDisabled?u=!1:u&&(u===!0&&this.cameraStreamInfo.micAudioConstraints?(yield this.setAvailableMicrophoneDeviceId(),u=W({},this.cameraStreamInfo.micAudioConstraints)):typeof u=="object"&&(yield this.setAvailableMicrophoneDeviceId(),u=W(W({},u),this.cameraStreamInfo.micAudioConstraints)),this._audioCaptureDisabled=!1),l=yield P.AliRTS.createStream({audio:u,video:o,screen:t,custom:!!r,mediaStream:r,skipProfile:!0}),t)yield this.screenStreamInfo.updateSource(l,_e.Screen,pt.Screen),yield this.setScreenProfile(n),this.setScreenContentHint(),this.publishingScreenVideoStream=void 0;else if(yield this.cameraStreamInfo.updateSource(l,_e.Camera,pt.Microphone),l.hasVideo&&(yield this.setVideoProfile(a),this.setVideoContentHint(),this.publishingCameraVideoStream=void 0),l.hasAudio&&typeof u=="boolean"){const p=this.cameraStreamInfo.audioProfile;p&&(yield l.setAudioProfile(p))}}return P.AliRTS.SystenUtil.isIos&&P.AliRTS.SystenUtil.compareVersion("15.1")&&!P.AliRTS.SystenUtil.compareVersion("15.2")&&(yield Ve(1e3)),yield this.updateStreams(),l})}stopLocalStream(e){return S(this,null,function*(){const{screen:t,video:r,audio:a}=e!=null?e:{};let n=!1;r&&this.cameraStreamInfo.originVideoTrack&&(n=!0,this.cameraStreamInfo.stopVideo(),this.publishingCameraVideoStream=void 0),a&&this.cameraStreamInfo.originAudioTrack&&(n=!0,this.cameraStreamInfo.stopAudio()),t&&this.screenStreamInfo.originVideoTrack&&(n=!0,this.screenStreamInfo.stop(),this.publishingScreenVideoStream=void 0),n&&(yield this.updateStreams())})}get publishStreams(){const{publishLocalVideoStreamEnabled:e,publishLocalAudioStreamEnabled:t,publishLocalScreenStreamEnabled:r}=this;return{video:e?this.cameraStreamInfo.publishVideoStream:void 0,videoSmall:e?this.cameraStreamInfo.publishDualVideoStream:void 0,audio:t?this.cameraStreamInfo.publishAudioStream:void 0,screen:r?this.screenStreamInfo.publishVideoStream:void 0}}createHTTPPublishStream(){return S(this,null,function*(){var u,h,l,p;let e,t=!1,r,a,n;const o=yield this.publishStreams;try{if(!o.audio&&!o.video&&!o.videoSmall&&!o.screen)throw new A(T.ERR_SDK_PUBLISH_INVAILD,"no tracks founded");const d=new MediaStream;(u=o.audio)!=null&&u.audioTrack&&d.addTrack(o.audio.audioTrack),(h=o.video)!=null&&h.videoTrack?(d.addTrack(o.video.videoTrack),a=o.videoSmall,n=o.screen):(l=o.screen)!=null&&l.videoTrack&&(r=w.Screen,d.addTrack((p=o.screen)==null?void 0:p.videoTrack),t=!0),e=yield zi(d),t?(this.screenStreamInfo.cloneVideoProfile(e),this.publishingScreenVideoStream=e):(this.cameraStreamInfo.cloneVideoProfile(e),this.publishingCameraVideoStream=e)}catch(d){}return{publishStream:e,videoSmallStream:a,screenStream:n,vMsid:r}})}stop(){this.cameraStreamInfo.stop(),this.screenStreamInfo.stop()}setVideoProfile(e,t){return S(this,null,function*(){yield this.cameraStreamInfo.updateVideoProfile(e,t),this.publishingCameraVideoStream&&this.cameraStreamInfo.cloneVideoProfile(this.publishingCameraVideoStream)})}setVideoContentHint(e){this.cameraStreamInfo.setVideoContentHint(e)}setAudioProfile(e){return S(this,null,function*(){var t;yield this.cameraStreamInfo.updateAudioProfile(e),yield(t=this.publishingCameraVideoStream)==null?void 0:t.setAudioProfile(e)})}setScreenProfile(e,t){return S(this,null,function*(){yield this.screenStreamInfo.updateVideoProfile(e,t),this.publishingScreenVideoStream&&this.screenStreamInfo.cloneVideoProfile(this.publishingScreenVideoStream)})}setScreenContentHint(e){this.screenStreamInfo.setVideoContentHint(e)}setCameraVideoConstraints(e){var t;this.cameraStreamInfo.cameraVideoConstraints=W(W({},(t=this.cameraStreamInfo.cameraVideoConstraints)!=null?t:{}),e)}setMicAudioConstraints(e){var t;this.cameraStreamInfo.micAudioConstraints=W(W({},(t=this.cameraStreamInfo.micAudioConstraints)!=null?t:{}),e)}},c(je,"logName","LocalStreamManager"),je);Se([b(([i])=>{const{audio:s,video:e,screen:t,custom:r,skipProfile:a,videoProfile:n,screenProfile:o}=i;return[{audio:s,video:e,screen:t,custom:r,skipProfile:a,videoProfile:n,screenProfile:o}]})],me.prototype,"createLocalStream",1),Se([b(R)],me.prototype,"stopLocalStream",1),Se([b()],me.prototype,"createHTTPPublishStream",1),Se([b()],me.prototype,"stop",1),Se([b(R)],me.prototype,"setVideoProfile",1),Se([b(R)],me.prototype,"setVideoContentHint",1),Se([b(R)],me.prototype,"setAudioProfile",1),Se([b(R)],me.prototype,"setScreenProfile",1),Se([b(R)],me.prototype,"setScreenContentHint",1),Se([b(R)],me.prototype,"setCameraVideoConstraints",1),Se([b(R)],me.prototype,"setMicAudioConstraints",1);let Fr=me;var Hr=Object.defineProperty,Wr=Object.getOwnPropertyDescriptor,fe=(i,s,e,t)=>{for(var r=t>1?void 0:t?Wr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Hr(s,e,r),r};class le extends J{constructor(e){super();c(this,"self");c(this,"userMap",{});c(this,"usersViewMap",{});c(this,"rtsManager");c(this,"localStreamManager");c(this,"authInfo");c(this,"signalingManager");c(this,"pluginManager");c(this,"reporter");c(this,"webTrackingClient");c(this,"statsMonitorId");c(this,"autoSubAudio",!0);c(this,"autoSubVideo",!0);c(this,"autoSubScreen",!0);c(this,"wantSubAudio",!0);c(this,"wantSubVideo",!0);c(this,"wantSubScreen",!0);c(this,"defaultStreamType",oe.AliRtcVideoStreamTypeHigh);c(this,"audioMuted",!1);c(this,"audioVolumeIndicationInterval",0);c(this,"indicationTimer",0);const{signalingManager:t,reporter:r,webTrackingClient:a}=e;this.signalingManager=t,this.addSignalingManagerListener(),this.reporter=r,this.webTrackingClient=a,this.pluginManager=new Vr,this.localStreamManager=new Fr(this.pluginManager),this.rtsManager=new Ur(this.localStreamManager),this.self=new z({rtsManager:this.rtsManager,localStreamManager:this.localStreamManager,reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager,pluginManager:this.pluginManager,audioVolumeIndicationInterval:this.audioVolumeIndicationInterval})}addSignalingManagerListener(){this.signalingManager.on("onNotifyPublish",e=>{I.event("[Signaling] Notify Publish ",e),e.forEach(t=>{this.onRemotePublishStateChange(t)})})}isAutoSubAudio(){return this.autoSubAudio}setAutoSubAudio(e){this.autoSubAudio=e}isAutoSubVideo(){return this.autoSubVideo}setAutoSubVideo(e){this.autoSubVideo=e}isAutoSubScreen(){return this.autoSubScreen}setAutoSubScreen(e){this.autoSubScreen=e}isWantSubAudio(){return this.wantSubAudio}setWantSubAudio(e){this.wantSubAudio=e,this.remoteUsers.forEach(t=>{t.setWantSubAudio(e),t.updateSubscribe()})}isWantSubVideo(){return this.wantSubVideo}setWantSubVideo(e){this.wantSubVideo=e,this.remoteUsers.forEach(t=>{t.setWantSubVideo(e),t.updateSubscribe()})}isWantSubScreen(){return this.wantSubScreen}setWantSubScreen(e){this.wantSubScreen=e,this.remoteUsers.forEach(t=>{t.setWantSubScreen(e),t.updateSubscribe()})}setRemoteDefaultVideoStreamType(e){this.defaultStreamType=e,this.remoteUsers.forEach(t=>{t.setRemoteDefaultVideoStreamType(e)})}setAudioMuted(e){this.audioMuted=e,this.remoteUsers.forEach(t=>{t.setAudioMuted(e)})}setLocalViewConfig(e,t){var a;if(!e)return(a=this.publisher)==null?void 0:a.setViewConfig(null,t);const r=ni(e);r.length!==0&&r.forEach(n=>{var o,u;(o=this.publisher)==null||o.resetElement(n),Object.values(this.usersViewMap).forEach(({cameraViews:h=[],screenViews:l=[]})=>{h.includes(n)&&h.splice(h.indexOf(n),1),l.includes(n)&&l.splice(l.indexOf(n),1)}),(u=this.publisher)==null||u.setViewConfig(r,t)})}setRemoteViewConfig(e,t,r){var n,o;if(!t)return(n=this.userMap[e])==null?void 0:n.setViewConfig(null,r);const a=ni(t);a.length!==0&&(a.forEach(u=>{var h;(h=this.publisher)==null||h.resetElement(u),Object.values(this.usersViewMap).forEach(({cameraViews:l=[],screenViews:p=[]})=>{l.includes(u)&&l.splice(l.indexOf(u),1),p.includes(u)&&p.splice(p.indexOf(u),1)})}),(o=this.userMap[e])==null||o.setViewConfig(a,r))}get channel(){var e;return(e=this.authInfo)==null?void 0:e.channelId}get userId(){var e;return(e=this.authInfo)==null?void 0:e.userId}get remoteUsers(){return Object.values(this.userMap)}get publisher(){return this.self}get isSubscribing(){var e;return((e=this.remoteUsers)!=null?e:[]).some(t=>{var u;const{isAudioSubscribing:r,isVideoLargeSubscribing:a,isVideoSmallSubscribing:n,isScreenSubscribing:o}=(u=t.streamInfo)!=null?u:{};return r||a||n||o})}onRemotePublishStateChange(e){var d;const{userid:t,callid:r,subscribe:a,pubid:n="",tracks:o}=e,u=(d=a==null?void 0:a.pullstreamurl)!=null?d:"";let h=this.getRemoteUser(t);if(!h)return;const l=h.streamInfo.audioTrackInfo,p=h.streamInfo.videoTrackInfo;h.updateRemoteTracks(r,u,n,o),h.updateSubscribe(),(l!==h.streamInfo.audioTrackInfo||p!==h.streamInfo.videoTrackInfo)&&this.emit("remoteTrackAvailableChange",t,h.streamInfo.audioTrackInfo,h.streamInfo.videoTrackInfo)}init(e,t){var r;this.authInfo=e,this.self||(this.self=new z({rtsManager:this.rtsManager,localStreamManager:this.localStreamManager,reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager,pluginManager:this.pluginManager,audioVolumeIndicationInterval:this.audioVolumeIndicationInterval})),this.self.enableAudioVolumeIndication(this.audioVolumeIndicationInterval),(r=this.self)==null||r.initInfo(e,t.pushstreamurl),t.users.forEach(a=>{const n=a.userid;if(n){const o=this.addUser(n,a.displayname),{callid:u,subscribe:h,tracks:l}=a;o.updateRemoteTracks(u,(h==null?void 0:h.pullstreamurl)||"","",l),this.emit("remoteTrackAvailableChange",n,o.streamInfo.audioTrackInfo,o.streamInfo.videoTrackInfo)}}),this.startStatsMonitor()}clear(){return S(this,null,function*(){var e;this.stopStatsMonitor();for(let t in this.userMap)this.userMap[t]&&(yield this.userMap[t].clear(),delete this.userMap[t]);yield(e=this.self)==null?void 0:e.clear(),this.authInfo=void 0})}startStatsMonitor(){this.statsMonitorId=window.setInterval(()=>S(this,null,function*(){if(this.publisher){const{audio:r,video:a}=yield this.publisher.getStats();r&&r.length>0&&this.emit("rtcLocalAudioStats",r),a&&a.length>0&&this.emit("rtcLocalVideoStats",a)}const e=[],t=[];for(const r of this.remoteUsers){const{audio:a,video:n}=yield r.getStats();a&&a.forEach(o=>{e.push(o)}),n&&n.forEach(o=>{t.push(o)})}e.length>0&&this.emit("rtcRemoteAudioStats",e),t.length>0&&this.emit("rtcRemoteVideoStats",t)}),2e3)}stopStatsMonitor(){this.statsMonitorId&&clearInterval(this.statsMonitorId)}getUser(e,t){return this.addUser(e,t),this.userMap[e]}addUser(e,t){return this.userMap[e]||(this.userMap[e]=this.executeAddUser(e,t)),this.userMap[e]}executeAddUser(e,t){var a;const r=new Y({userId:e,displayName:t,rtsManager:this.rtsManager,signalingManager:this.signalingManager,usersViewMap:this.usersViewMap,reporter:this.reporter,webTrackingClient:this.webTrackingClient,localUserId:(a=this.userId)!=null?a:"",audioVolumeIndicationInterval:this.audioVolumeIndicationInterval});return r.on(ie.Remote,this.onRemoteDeviceStatusChange.bind(this)),r.on(H.PullStreamStats,this.onRemoteStatReport.bind(this)),r.on(H.RtsSubscribeExceeds,this.onSubscribeExceeds.bind(this)),r.on("audioSubscribeStateChanged",(n,o,u,h)=>{this.emit("audioSubscribeStateChanged",n,o,u,h,this.channel||"")}),r.on("videoSubscribeStateChanged",(n,o,u,h)=>{this.emit("videoSubscribeStateChanged",n,o,u,h,this.channel||"")}),r.on("screenSubscribeStateChanged",(n,o,u,h)=>{this.emit("screenSubscribeStateChanged",n,o,u,h,this.channel||"")}),r.on("remoteAudioAutoPlayFail",n=>{this.emit("remoteAudioAutoPlayFail",n)}),r.on("remoteVideoAutoPlayFail",(n,o)=>{this.emit("remoteVideoAutoPlayFail",n,o)}),r.on("remoteSubscribeError",n=>{this.emit("remoteSubscribeError",n)}),r.setWantSubAudio(this.autoSubAudio&&this.wantSubAudio),r.setWantSubVideo(this.autoSubVideo&&this.wantSubVideo),r.setWantSubScreen(this.autoSubScreen&&this.wantSubScreen),r.setRemoteDefaultVideoStreamType(this.defaultStreamType),r.setAudioMuted(this.audioMuted),(this.autoSubAudio||this.autoSubVideo||this.autoSubScreen)&&r.updateSubscribe(),r}onRemoteDeviceStatusChange(e,t){e===H.MuteAudio?this.emit("userAudioMuted",t,!0):e===H.UnmuteAudio?this.emit("userAudioMuted",t,!1):e===H.MuteVideo?this.emit("userVideoMuted",t,!0):e===H.UnmuteVideo?this.emit("userVideoMuted",t,!1):e===H.MuteScreen?this.emit("userScreenMuted",t,!0):e===H.UnmuteScreen&&this.emit("userScreenMuted",t,!1)}onRemoteStatReport(e,t,r){this.emit(H.PullStreamStats,e,t,r)}onSubscribeExceeds(e,t){this.emit(H.RtsSubscribeExceeds,e,t)}removeLeftUser(e){return S(this,null,function*(){e.userid&&this.userMap[e.userid]&&(yield this.userMap[e.userid].clear(!1),delete this.userMap[e.userid])})}updateUsers(e){const t=[],r=[],a={};e.forEach(u=>{u.userid&&(this.userMap[u.userid]?(r.push(u),a[u.userid]=this.userMap[u.userid]):(t.push(u),a[u.userid]=this.executeAddUser(u.userid,u.displayname)))});const n=Object.keys(this.userMap),o=[];return n.forEach(u=>{a[u]||o.push({userid:u,reason:"",leavecode:zt.AliRtcUserOfflineQuit})}),this.userMap=a,{joinList:t,leaveList:o,presentList:r}}getRemoteUser(e){return this.userMap[e]}updateRemoteUserDeviceStatus(e){e&&e.userid&&this.userMap[e.userid]&&this.userMap[e.userid].updateRemoteUserDeviceStatus(e.status)}updateAudioWant(e,t){const r=this.userMap[e];if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.setWantSubAudio(t),t?r.updateSubscribe():r.stopSubscribe({audio:!0})}updateVideoWant(e,t){const r=this.userMap[e];if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.setWantSubVideo(t),t?r.updateSubscribe():r.stopSubscribe({video:!0})}updateScreenWant(e,t){const r=this.userMap[e];if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.setWantSubScreen(t),t?r.updateSubscribe():r.stopSubscribe({screen:!0})}stopIndication(){this.indicationTimer&&window.clearInterval(this.indicationTimer)}startIndication(e){this.stopIndication(),this.indicationTimer=window.setInterval(()=>{var r;const t=this.remoteUsers.map(a=>({userId:a.userId,volume:a.getAudioLevel()||0}));t.unshift({userId:"",volume:((r=this.self)==null?void 0:r.getAudioLevel())||0}),this.emit("audioVolume",t)},e)}enableAudioVolumeIndication(e){var t;this.audioVolumeIndicationInterval!==e&&(this.audioVolumeIndicationInterval>0&&e<=0&&this.stopIndication(),e>0&&this.startIndication(e),this.audioVolumeIndicationInterval=e,this.remoteUsers.forEach(r=>{r.enableAudioVolumeIndication(e)}),(t=this.self)==null||t.enableAudioVolumeIndication(e))}refreshAuthInfo(e){var t;this.authInfo&&(this.authInfo=W(W({},this.authInfo),e)),e.userId&&((t=this.self)==null||t.refreshUserInfo(e.userId))}setEnableMediaExtensionMsg(e){this.rtsManager.setEncodedInsertableStreams(e)}}c(le,"logName","UserManager"),fe([b()],le.prototype,"init",1),fe([b()],le.prototype,"clear",1),fe([b(R)],le.prototype,"addUser",1),fe([b()],le.prototype,"removeLeftUser",1),fe([b()],le.prototype,"updateUsers",1),fe([b(R)],le.prototype,"updateAudioWant",1),fe([b(R)],le.prototype,"updateVideoWant",1),fe([b(R)],le.prototype,"updateScreenWant",1),fe([b()],le.prototype,"stopIndication",1),fe([b()],le.prototype,"startIndication",1),fe([b()],le.prototype,"enableAudioVolumeIndication",1);const ui=i=>S(this,null,function*(){const s=new Uint8Array(160).fill(170),e=new TextEncoder().encode(i),t=yield window.crypto.subtle.importKey("raw",s,{name:"HMAC",hash:{name:"SHA-1"}},!1,["sign"]),r=yield window.crypto.subtle.sign("HMAC",t,e);return Array.from(new Uint8Array(r)).map(a=>a.toString(16).padStart(2,"0")).join("")});class Kr{constructor(){c(this,"authInfo")}doRequest(s,e){var h;const t=this.authInfo;if(!t)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const r="https://gw.rtn.aliyuncs.com",a=ur[s],n={appid:t.appId,userid:t.userId,channelid:t.channelId,timestamp:t.timestamp,token:t.token,requestid:Ae.createCallid(),tokensid:!1,session:(h=t.callid)!=null?h:Ae.createCallid()},o=Object.keys(n).map(l=>`${l}=${encodeURIComponent(n[l])}`).join("&"),u=`${r}${a}?${o}`;return fetch(u,{method:"POST",headers:{"Content-Type":"application/json; charset=UTF-8"},body:e}).then(l=>l.status!==200?Promise.reject(new A(T.ERR_INNER,`transcoding request failed, status: ${l.status}`)):l)}setAuthInfo(s){this.authInfo=s}clear(){this.authInfo=void 0}startPublishLiveStream(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=yield ui(s.split("?")[0]),r=ue.MPU_TASK_TRANSACTION_UPDATE,a=e.toJson(r,this.authInfo,t,s);return this.doRequest(r,JSON.stringify(a))})}startPublishLiveStreamWithTaskId(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=ue.MPU_TASK_TRANSACTION_UPDATE,r=e.toJson(t,this.authInfo,s);return this.doRequest(t,JSON.stringify(r))})}updatePublishLiveStream(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=yield ui(s.split("?")[0]),r=ue.MPU_TASK_TRANSACTION_UPDATE,a=e.toJson(r,this.authInfo,t,s);return this.doRequest(r,JSON.stringify(a))})}updatePublishLiveStreamWithTaskId(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=ue.MPU_TASK_TRANSACTION_UPDATE,r=e.toJson(t,this.authInfo,s);return this.doRequest(t,JSON.stringify(r))})}stopPublishLiveStream(s){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const e=yield ui(s.split("?")[0]),t=ue.MPU_TASK_TRANSACTION_STOP,r=new bt().toJson(t,this.authInfo,e,s);return this.doRequest(t,JSON.stringify(r))})}stopPublishLiveStreamWithTaskId(s){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const e=ue.MPU_TASK_TRANSACTION_STOP,t=new bt().toJson(e,this.authInfo,s);return this.doRequest(e,JSON.stringify(t))}refreshAuthInfo(s){this.authInfo&&this.setAuthInfo(W(W({},this.authInfo),s))}}var Xi=(i,s,e)=>{if(!s.has(i))throw TypeError("Cannot "+e)},It=(i,s,e)=>(Xi(i,s,"read from private field"),e?e.call(i):s.get(i)),hi=(i,s,e)=>{if(s.has(i))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(i):s.set(i,e)},li=(i,s,e,t)=>(Xi(i,s,"write to private field"),t?t.call(i,e):s.set(i,e),e),jr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},E={},Ue={};const $r="SLS_CLIENT";var Zi=(i=>(i.ERROR="error",i.LOG="log",i.LOCATION="pv",i.API="api",i.RESOURCE="res",i.RESOURCE_ERROR="res_err",i.PERF="perf",i.CONSOLE_LOG="console",i))(Zi||{}),Qi=(i=>(i.LOG_SEND="LOG_SEND",i.BROWSER_SEND="BROWSER_SEND",i.BASE_TRANSFORM="BASE_TRANSFORM",i.BROWSER_BASE_TRANSFORM="BROWSER_BASE_TRANSFORM",i.BROWSER_FETCH="BROWSER_FETCH",i.BROWSER_XHR="BROWSER_XHR",i.BROWSER_LOCATION="BROWSER_LOCATION",i.BROWSER_RUNTIME_ERROR="BROWSER_RUNTIME_ERROR",i.BROWSER_CUSTOM_ERROR="BROWSER_CUSTOM_ERROR",i.BROWSER_RESOURCE_ERROR="BROWSER_RESOURCE_ERROR",i.BROWSER_CONSOLE="BROWSER_CONSOLE",i.BROWSER_PERF="BROWSER_PERF",i.BROWSER_RESOURSE="BROWSER_RESOURSE",i.MINI_SEND="MINI_SEND",i.MINI_REQUEST="MINI_REQUEST",i.MINI_BASE_TRANSFORM="MINI_BASE_TRANSFORM",i.MINI_ROUTE="MINI_ROUTE",i))(Qi||{});const Jr={BROWSER_SEND:-1,MINI_SEND:-2,BASE_TRANSFORM:100,BROWSER_BASE_TRANSFORM:100*2,MINI_BASE_TRANSFORM:100*2+1,BROWSER_PERF:100*3+1,BROWSER_FETCH:100*4,BROWSER_XHR:100*4+1,MINI_REQUEST:100*4+2,BROWSER_RUNTIME_ERROR:100*5},qr="sls-trace-uid";var es=(i=>(i.OK="OK",i.ERROR="ERROR",i.UNSET="UNSET",i))(es||{});Ue.InternalPlugin=Qi,Ue.InternalPluginPriority=Jr,Ue.OTStatusCode=es,Ue.SLS_CLIENT_NAME=$r,Ue.SLS_TRACE_UID_KEY=qr,Ue.WebEventType=Zi;var be=Ue;function di(i,s,e){Object.defineProperty(i,s,{writable:!0,enumerable:!0,configurable:!0,value:e})}function Gr(i,s,e,t){t?t(()=>{di(i,s,e)}):di(i,s,e)}class zr{constructor(s){this.onFirstSubscribe=s,this.observers=[]}subscribe(s){return!this.observers.length&&this.onFirstSubscribe&&(this.onLastUnsubscribe=this.onFirstSubscribe()||void 0),this.observers.push(s),{unsubscribe:()=>{this.observers=this.observers.filter(e=>s!==e),!this.observers.length&&this.onLastUnsubscribe&&this.onLastUnsubscribe()}}}notify(s){this.observers.forEach(e=>e(s))}}function rt(i,s,e){try{return i.apply(s,e)}catch(t){return}}function Yr(i){return function(){return rt(i,this,arguments)}}let Xr=!1;function Zr(){return Xr}function ts(...i){}var Qr=Object.defineProperty,ea=Object.defineProperties,ta=Object.getOwnPropertyDescriptors,is=Object.getOwnPropertySymbols,ia=Object.prototype.hasOwnProperty,sa=Object.prototype.propertyIsEnumerable,ss=(i,s,e)=>s in i?Qr(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,ra=(i,s)=>{for(var e in s||(s={}))ia.call(s,e)&&ss(i,e,s[e]);if(is)for(var e of is(s))sa.call(s,e)&&ss(i,e,s[e]);return i},aa=(i,s)=>ea(i,ta(s));const rs=1e3,as=60*rs,ns=60*as,os=24*ns,cs=365*os,na=1024,us="0.1.0";function oa(){}function hs(i){return typeof i=="number"}function ca(i){return Object.prototype.toString.call(i)==="[object String]"}function ua(i){return Object.prototype.toString.call(i)==="[object Error]"}function ls(i,s){return+i.toFixed(s)}function ha(i,s){return i.indexOf(s)!==-1}function la(i,s){return i==null?s:!!i}function At(i){return i?(parseInt(i,10)^Math.random()*16>>parseInt(i,10)/4).toString(16):`10000000-1000-4000-8000-${1e11}`.replace(/[018]/g,At)}function ds(i=20){var s,e;const t=new Array(i),r=Date.now().toString(36).split("");for(;i-- >0;)e=(s=36*Math.random()|0).toString(36),t[i]=s%3?e:e.toUpperCase();for(var a=0;a<8;a++)t.splice(3*a+2,0,r[a]);return t.join("")}function da(i){return i!==0&&Math.random()<=i}function Tt(i,s){return(...e)=>{try{return i(...e)}catch(t){console.error(s,t)}}}function ps(i){return"https://"+i.project+"."+i.host+"/logstores/"+i.logstore+"/track"}function pa(i,s){return s?i.includes(ps(s)):i.includes("/track?APIVersion=0.6.0")}const ms=/^(?:([^:\/?#]+):\/\/)?((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i;function ma(i){try{return decodeURIComponent(i)}catch(s){return unescape(i)}}function ga(i){return typeof i=="string"&&ms.test(i)}function Sa(i){var s=ma(i||"").match(ms);if(s==null)return null;var e=(s[3]||"").split(":"),t=e.length?(s[2]||"").replace(/(.*\@)/,""):s[2];return{uri:s[0],protocol:s[1],host:t,hostname:s[4],port:s[5],auth:s[3],user:e[0],password:e[1],path:s[6],search:s[7],hash:s[8]}}function fa(i,s,e,t){const r={url:i,method:s,status_code:e};return t==null?r:aa(ra({},r),{host:t.host,scheme:t.protocol})}function ba(i,s,...e){return s==null||!Array.isArray(s)?!1:s.some(t=>{if(typeof t=="function")try{return t(i,...e)}catch(r){return console.error("user function callback threw an error:",r),!1}return typeof t=="string"?i.includes(t):Object.prototype.toString.call(t)==="[object RegExp]"?t.test(i):!1})}function va(i,s,e){return i===!1?!1:i===!0||i==="error"&&!e?!0:typeof i=="function"?Tt(i,"call shouldTrackBody failed")(s):!1}function _a(i){return{relative:i,timeStamp:gs(i)}}function gs(i){const s=Date.now()-performance.now();return s>at()?Math.round(s+i):fs(i)}function wa(){return Math.round(Date.now()-(at()+performance.now()))}function Ra(i){return hs(i)?ls(i*1e6,0):i}function pi(){return Date.now()}function Ss(){return performance.now()}function Ia(){return{relative:Ss(),timeStamp:pi()}}function Aa(){return{relative:0,timeStamp:at()}}function Ta(i,s){return s-i}function Ea(i){return i-at()}function fs(i){return Math.round(at()+i)}function ya(i){return i<cs}let Et;function at(){return Et===void 0&&(Et=performance.timing.navigationStart),Et}function Pa(){Et=void 0}const xe="?";function nt(i,s){let e;const t=s===void 0?0:+s;try{if(e=Ma(i),e)return e}catch(r){}try{if(e=ka(i),e)return e}catch(r){}try{if(e=Na(i),e)return e}catch(r){}try{if(e=bs(i,t+1),e)return e}catch(r){}return{message:ne(i,"message"),name:ne(i,"name"),stack:[]}}function ka(i){const s=ne(i,"stack");if(!s)return;const e=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,t=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,r=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;let a;const n=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,o=/\((\S*)(?::(\d+))(?::(\d+))\)/,u=s.split(`
|
|
2
|
-
`),h=[];let l,p,d;for(let m=0,g=u.length;m<g;m+=1){if(e.exec(u[m])){p=e.exec(u[m]);const f=p[2]&&p[2].indexOf("native")===0;a=p[2]&&p[2].indexOf("eval")===0,l=o.exec(p[2]),a&&l&&(p[2]=l[1],p[3]=l[2],p[4]=l[3]),d={args:f?[p[2]]:[],column:p[4]?+p[4]:void 0,func:p[1]||
|
|
3
|
-
`),a=[];let n;for(let o=0;o<r.length;o+=2){let u;e.exec(r[o])?(n=e.exec(r[o]),u={args:[],column:void 0,func:n[3],line:+n[1],url:n[2]}):t.exec(r[o])&&(n=t.exec(r[o]),u={args:n[5]?n[5].split(","):[],column:+n[2],func:n[3]||n[4],line:+n[1],url:n[6]}),u&&(!u.func&&u.line&&(u.func=
|
|
4
|
-
`);if(e.length<4)return;const t=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,r=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,a=/^\s*Line (\d+) of function script\s*$/i,n=[],o=window&&window.document&&window.document.getElementsByTagName("script"),u=[];let h;for(const l in o)La(o,l)&&!o[l].src&&u.push(o[l]);for(let l=2;l<e.length;l+=2){let p;t.exec(e[l])?(h=t.exec(e[l]),p={args:[],column:void 0,func:h[3],line:+h[1],url:h[2]}):r.exec(e[l])?(h=r.exec(e[l]),p={args:[],column:void 0,func:h[4],line:+h[1],url:h[3]}):a.exec(e[l])&&(h=a.exec(e[l]),p={url:window.location.href.replace(/#.*$/,""),args:[],column:void 0,func:"",line:+h[1]}),p&&(p.func||(p.func=
|
|
5
|
-
at ${t}${r} @ ${e.url}${a}${n}`}),encodeURIComponent(s)}function Ba(i,s,e,t=!0){var r;if(!i||i.message===void 0&&!(s instanceof Error))return{message:`${e} ${JSON.stringify(s)}`,stacktrace:"",type:i&&i.name,id:At()};i!=null&&i.stack&&t&&(i.stack=ws(i.stack));const a=(r=i==null?void 0:i.stack)==null?void 0:r[0];return{message:encodeURIComponent(i.message||"Empty message"),stacktrace:gi(i),type:i.name,col:a?a.column:void 0,line:a?a.line:void 0,file:encodeURIComponent(a&&a.url?a.url:""),id:At()}}function Fa(){const i=new Error;let s;return rt(()=>{const e=nt(i);e!=null&&e.stack&&(e.stack=ws(e.stack)),s=gi(e)}),s}const Ha=8,Wa=16,Si="b3",fi="traceparent",bi="uber-trace-id",yt=Array(32);function Rs(i){for(let s=0;s<i*2;s++)yt[s]=Math.floor(Math.random()*16)+48,yt[s]>=58&&(yt[s]+=39);return String.fromCharCode.apply(null,yt.slice(0,i*2))}function Is(){return Rs(Wa)}function vi(){return Rs(Ha)}function Pt(i,s){return`${i}-${s}-1`}function kt(i,s){return`00-${i}-${s}-01`}function Mt(i,s){return`${i}:${s}:0:1`}const Nt={b3:{name:Si,getter:Pt},traceparent:{name:fi,getter:kt},uber:{name:bi,getter:Mt}};function Ka(i,s,e,t){var r;const a=t!=null?t:{};a.headers=(r=a.headers)!=null?r:{},a.headers[Si]=Pt(i,s),a.headers[fi]=kt(i,s),a.headers[bi]=Mt(i,s);try{if(e)for(const[n,o]of Object.entries(e))Nt[o]&&(a.headers[n]=Nt[o].getter(i,s))}catch(n){}return a}function ja(i,s,e,t){i.setRequestHeader(Si,Pt(s,e)),i.setRequestHeader(fi,kt(s,e)),i.setRequestHeader(bi,Mt(s,e));try{if(t)for(const[r,a]of Object.entries(t))Nt[a]&&i.setRequestHeader(r,Nt[a].getter(s,e))}catch(r){}}function ot(i,s,e){i!=null&&Object.keys(i).map(t=>{e==null||e==""?s[t]=i[t]:s[`${e}.${t}`]=i[t]})}var $a=Object.defineProperty,Ja=Object.defineProperties,qa=Object.getOwnPropertyDescriptors,As=Object.getOwnPropertySymbols,Ga=Object.prototype.hasOwnProperty,za=Object.prototype.propertyIsEnumerable,Ts=(i,s,e)=>s in i?$a(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Ya=(i,s)=>{for(var e in s||(s={}))Ga.call(s,e)&&Ts(i,e,s[e]);if(As)for(var e of As(s))za.call(s,e)&&Ts(i,e,s[e]);return i},Xa=(i,s)=>Ja(i,qa(s));function Za(){return{name:be.InternalPlugin.BASE_TRANSFORM,run:function(){this.subscribe("*",(i,s)=>{const{otBase:e,extra:t}=i;e.attribute=Xa(Ya({},e.attribute),{sid:this.session.getSessionId(),pid:this.session.getPageId(),uid:this.options.uid,service:this.options.service}),this.options.nickname&&(e.attribute.nickname=this.options.nickname),ot(this.options.custom,e.attribute,"custom"),ot({env:this.options.env,version:this.options.version},e.attribute),ot({sdk_version:us,workspace:this.options.workspace},e.resource);const r={otBase:e,extra:t};ts(be.InternalPlugin.BASE_TRANSFORM,r),s(r)},be.InternalPluginPriority[be.InternalPlugin.BASE_TRANSFORM])}}}function Qa(){return{name:be.InternalPlugin.LOG_SEND,run:function(){}}}function Es(i,s,e){if(s<0)return;const t=a=>{Es(i,s-1,a)},r=i[s];Tt(()=>{r.callback.call(void 0,e,t)},"plugin notify run error")()}class en{constructor(s){this.subscribeMap={},this.allNotifiers=[],this.allNotifiers=s}subscribeOne(s,e,t,r){var a;const n=(a=this.subscribeMap[e])!=null?a:[];this.subscribeMap[e]=n,n.push({name:s,priority:r,callback:t}),n.sort((o,u)=>o.priority-u.priority)}notify(s,e){var t;const r=(t=this.subscribeMap[s])!=null?t:[];Es(r,r.length-1,e)}subscribe(s,e,t,r){if(e==="*")for(let a=0;a<this.allNotifiers.length;a++){const n=this.allNotifiers[a];this.subscribeOne(s,n,t,r)}else this.subscribeOne(s,e,t,r)}getSubscribeMap(){return this.subscribeMap}}function tn(){const i=Is();let s=vi();return{getSessionId:()=>i,getPageId:()=>s,refreshPageId:()=>{s=vi()}}}var sn=Object.defineProperty,rn=Object.defineProperties,an=Object.getOwnPropertyDescriptors,ys=Object.getOwnPropertySymbols,nn=Object.prototype.hasOwnProperty,on=Object.prototype.propertyIsEnumerable,Ps=(i,s,e)=>s in i?sn(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,cn=(i,s)=>{for(var e in s||(s={}))nn.call(s,e)&&Ps(i,e,s[e]);if(ys)for(var e of ys(s))on.call(s,e)&&Ps(i,e,s[e]);return i},un=(i,s)=>rn(i,an(s));const hn=["uid","nickname","env","service","version","custom"];class ln{constructor(s){this.isInit=!1,this.pendingPlugins=[],this.pluginMap={},this.session=tn();var e,t;this.options=s,this.use(Qa()),this.use(Za()),this.options.env=(e=s.env)!=null?e:"prod",this.options.version=(t=s.version)!=null?t:"-"}initPlugin(s){if(s==null||typeof s!="object"){console.error("plugin is not a object");return}if(s.name==null||s.name===""){console.error("plugin name is required.");return}if(this.pluginMap[s.name]){console.error(`plugin name: ${s.name} is conflict`);return}if(typeof s.run!="function"){console.error("plugin.run is not a function");return}const e=un(cn({},this.context),{subscribe:(t,r,a)=>{this.sub.subscribe(s.name,t,r,a)},notify:t=>{this.sub.notify(s.name,t)}});Tt(()=>s.run.call(e),`plugin ${s.name} init failed`)()}addLog(s){if(this.isInit){const e={t:be.WebEventType.LOG};ot(s,e,be.WebEventType.LOG);const t={start:pi()*1e3,attribute:e,resource:{}};this.sub.notify(be.InternalPlugin.LOG_SEND,{otBase:t,extra:{}})}else console.error("log should call after start")}setOptions(s){this.isInit?hn.forEach(e=>{s[e]!==this.options[e]&&s[e]!=null&&s[e]!=""&&(this.options[e]=s[e],e==="uid"&&typeof this.setLocalStorage=="function"&&this.setLocalStorage(be.SLS_TRACE_UID_KEY,s[e]))}):console.error("setOptions should call after start")}start(){if(!this.isInit){this.isInit=!0;let s=this.options.uid;(s==null||s==="")&&(typeof this.getLocalStorage=="function"&&(s=this.getLocalStorage(be.SLS_TRACE_UID_KEY)),(s==null||s==="")&&(s=ds())),this.options.uid=s,typeof this.setLocalStorage=="function"&&this.setLocalStorage(be.SLS_TRACE_UID_KEY,s);const e=this.pendingPlugins.map(t=>t==null?void 0:t.name).filter(t=>t!=null);this.sub=new en(e),this.context={options:this.options,session:this.session};for(const t of this.pendingPlugins)this.initPlugin(t)}}use(s){this.isInit?console.error(`plugin: ${s==null?void 0:s.name} use should run before start`):this.pendingPlugins.push(s)}}var dn=Object.defineProperty,ks=Object.getOwnPropertySymbols,pn=Object.prototype.hasOwnProperty,mn=Object.prototype.propertyIsEnumerable,Ms=(i,s,e)=>s in i?dn(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,gn=(i,s)=>{for(var e in s||(s={}))pn.call(s,e)&&Ms(i,e,s[e]);if(ks)for(var e of ks(s))mn.call(s,e)&&Ms(i,e,s[e]);return i};function Sn(i,s){var e;const t={current:void 0},r=[];let a={};return typeof s=="function"&&(a=(e=s(t))!=null?e:{}),gn({init:n=>{if(t.current!=null)return;t.current=i(n);const o=t.current;r.forEach(u=>{o.use(u)}),o.start()},use:n=>{r.push(n)},addLog:n=>{t.current.addLog(n)},onReady(n){n()},setOptions:n=>{t.current.setOptions(n)}},a)}class fn{constructor(){this.dep=new Map}subscribe(s,e){const t=this.dep.get(s);if(t){this.dep.set(s,t.concat(e));return}this.dep.set(s,[e])}notify(s,e){const t=this.dep.get(s);!s||!t||t.forEach(r=>{try{r(e)}catch(a){console.error(a)}})}}E.ONE_DAY=os,E.ONE_HOUR=ns,E.ONE_KILO_BYTE=na,E.ONE_MINUTE=as,E.ONE_SECOND=rs,E.ONE_YEAR=cs,E.Observable=zr,E.SDK_VERSION=us,E.SLSClient=ln,E.Subscribe=fn,E.assembleOTAttribute=ot,E.buildHttpInfo=fa,E.callMonitored=rt,E.catchUserErrors=Tt,E.clocksNow=Ia,E.clocksOrigin=Aa,E.computeStackTrace=nt,E.createHandlingStack=Fa,E.currentDrift=wa,E.debugLog=ts,E.defineGlobal=Gr,E.defineGlobalValue=di,E.elapsed=Ta,E.formatErrorMessage=_s,E.formatUnknownError=Ba,E.genUid=ds,E.generateSpanId=vi,E.generateTraceId=Is,E.generateUUID=At,E.getB3Header=Pt,E.getConsoleLogStatus=Zr,E.getCorrectedTimeStamp=gs,E.getJaegerTraceHeaderr=Mt,E.getRelativeTime=Ea,E.getTimeStamp=fs,E.getTrackUrl=ps,E.getW3CTraceHeader=kt,E.includes=ha,E.instrumentMethod=vs,E.instrumentMethodAndCallOriginal=mi,E.isError=ua,E.isInternalUrl=pa,E.isNumber=hs,E.isString=ca,E.isURL=ga,E.looksLikeRelativeTime=ya,E.makeWebPublicApi=Sn,E.matchCondition=ba,E.matchSample=da,E.matchWithDefault=la,E.monitor=Yr,E.noop=oa,E.parseUri=Sa,E.patchHeaderOnRequest=Ka,E.patchHeaderOnXhr=ja,E.relativeNow=Ss,E.relativeToClocks=_a,E.resetNavigationStart=Pa,E.round=ls,E.shouldTrackBody=va,E.startUnhandledErrorCollection=Da,E.timeStampNow=pi,E.toServerDuration=Ra,E.toStackTraceString=gi;var bn=class{constructor(i){this.timer=null,this.time=10,this.count=10,this.arr=[];var s,e;this.time=(s=i.time)!=null?s:10,this.count=(e=i.count)!=null?e:10,this.url="https://"+i.project+"."+i.host+"/logstores/"+i.logstore+"/track",this.opt=i,i.installUnloadHook&&typeof i.installUnloadHook=="function"&&i.installUnloadHook(()=>{this.sendImmediateInner()})}assemblePayload(i=this.arr){const s={__logs__:i};return this.opt.tags&&(s.__tags__=this.opt.tags),this.opt.topic&&(s.__topic__=this.opt.topic),this.opt.source&&(s.__source__=this.opt.source),JSON.stringify(s)}platformSend(){if(this.opt.sendPayload&&typeof this.opt.sendPayload=="function"){const i=this.assemblePayload();this.opt.sendPayload(this.url,i)}}transString(i){let s={};for(let e in i)typeof i[e]=="object"?s[e]=JSON.stringify(i[e]):s[e]=String(i[e]);return s}sendImmediateInner(){this.arr&&this.arr.length>0&&(this.platformSend(),this.timer!=null&&(clearTimeout(this.timer),this.timer=null),this.arr=[])}sendInner(){if(this.timer)this.arr.length>=this.count&&(clearTimeout(this.timer),this.timer=null,this.sendImmediateInner());else{const i=this;this.arr.length>=this.count||this.time<=0?this.sendImmediateInner():this.timer=setTimeout(function(){i.sendImmediateInner()},this.time*1e3)}}send(i){const s=this.transString(i);this.arr.push(s),this.sendInner()}sendImmediate(i){const s=this.transString(i);this.arr.push(s),this.sendImmediateInner()}sendBatchLogs(i){const s=i.map(e=>this.transString(e));this.arr.push(...s),this.sendInner()}sendBatchLogsImmediate(i){const s=i.map(e=>this.transString(e));this.arr.push(...s),this.sendImmediateInner()}},vn=E,_n=bn;function wn(i,s){return navigator&&navigator.sendBeacon?navigator.sendBeacon(`${i}?APIVersion=0.6.0`,s):!1}function Rn(i,s){const e=new window.XMLHttpRequest;e.open("POST",i,!0),e.setRequestHeader("x-log-apiversion","0.6.0"),e.setRequestHeader("x-log-bodyrawsize",s.length.toString());const t=new Blob([s],{type:"application/x-protobuf"});e.send(t)}function In(i,s){try{wn(i,s)||Rn(i,s)}catch(e){window&&window.console&&typeof window.console.error=="function"&&(console.error(`Failed to log to ali log service because of this exception:
|
|
6
|
-
`+e),console.error("Failed log data:",i))}}class Ns extends _n{constructor(s){const e=Object.assign({},s,{installUnloadHook:t=>{window.addEventListener("beforeunload",()=>{t()})},sendPayload:(t,r)=>{In(t,r)}});super(e)}}vn.defineGlobal(window,"SLS_Tracker",Ns);var An=Ns,Ct={},Tn={get exports(){return Ct},set exports(i){Ct=i}};(function(i,s){(function(e,t){var r="1.0.35",a="",n="?",o="function",u="undefined",h="object",l="string",p="major",d="model",m="name",g="type",f="vendor",v="version",O="architecture",B="console",C="mobile",U="tablet",re="smarttv",Ne="wearable",yi="embedded",Pi=350,Bt="Amazon",ut="Apple",Js="ASUS",qs="BlackBerry",$e="Browser",Ft="Chrome",io="Edge",Ht="Firefox",Wt="Google",Gs="Huawei",ki="LG",Mi="Microsoft",zs="Motorola",Kt="Opera",Ni="Samsung",Ys="Sharp",jt="Sony",Ci="Xiaomi",Li="Zebra",Xs="Facebook",Zs="Chromium OS",Qs="Mac OS",so=function(F,$){var D={};for(var q in F)$[q]&&$[q].length%2===0?D[q]=$[q].concat(F[q]):D[q]=F[q];return D},$t=function(F){for(var $={},D=0;D<F.length;D++)$[F[D].toUpperCase()]=F[D];return $},er=function(F,$){return typeof F===l?ht($).indexOf(ht(F))!==-1:!1},ht=function(F){return F.toLowerCase()},ro=function(F){return typeof F===l?F.replace(/[^\d\.]/g,a).split(".")[0]:t},Vi=function(F,$){if(typeof F===l)return F=F.replace(/^\s\s*/,a),typeof $===u?F:F.substring(0,Pi)},lt=function(F,$){for(var D=0,q,Ce,Ie,j,L,Ee;D<$.length&&!L;){var Di=$[D],sr=$[D+1];for(q=Ce=0;q<Di.length&&!L&&Di[q];)if(L=Di[q++].exec(F),L)for(Ie=0;Ie<sr.length;Ie++)Ee=L[++Ce],j=sr[Ie],typeof j===h&&j.length>0?j.length===2?typeof j[1]==o?this[j[0]]=j[1].call(this,Ee):this[j[0]]=j[1]:j.length===3?typeof j[1]===o&&!(j[1].exec&&j[1].test)?this[j[0]]=Ee?j[1].call(this,Ee,j[2]):t:this[j[0]]=Ee?Ee.replace(j[1],j[2]):t:j.length===4&&(this[j[0]]=Ee?j[3].call(this,Ee.replace(j[1],j[2])):t):this[j]=Ee||t;D+=2}},Oi=function(F,$){for(var D in $)if(typeof $[D]===h&&$[D].length>0){for(var q=0;q<$[D].length;q++)if(er($[D][q],F))return D===n?t:D}else if(er($[D],F))return D===n?t:D;return F},ao={"1.0":"/8","1.2":"/1","1.3":"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"},tr={ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2e3:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2","8.1":"NT 6.3",10:["NT 6.4","NT 10.0"],RT:"ARM"},ir={browser:[[/\b(?:crmo|crios)\/([\w\.]+)/i],[v,[m,"Chrome"]],[/edg(?:e|ios|a)?\/([\w\.]+)/i],[v,[m,"Edge"]],[/(opera mini)\/([-\w\.]+)/i,/(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i,/(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i],[m,v],[/opios[\/ ]+([\w\.]+)/i],[v,[m,Kt+" Mini"]],[/\bopr\/([\w\.]+)/i],[v,[m,Kt]],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer)[\/ ]?([\w\.]*)/i,/(avant |iemobile|slim)(?:browser)?[\/ ]?([\w\.]*)/i,/(ba?idubrowser)[\/ ]?([\w\.]+)/i,/(?:ms|\()(ie) ([\w\.]+)/i,/(flock|rockmelt|midori|epiphany|silk|skyfire|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon|rekonq|puffin|brave|whale(?!.+naver)|qqbrowserlite|qq|duckduckgo)\/([-\w\.]+)/i,/(heytap|ovi)browser\/([\d\.]+)/i,/(weibo)__([\d\.]+)/i],[m,v],[/(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i],[v,[m,"UC"+$e]],[/microm.+\bqbcore\/([\w\.]+)/i,/\bqbcore\/([\w\.]+).+microm/i],[v,[m,"WeChat(Win) Desktop"]],[/micromessenger\/([\w\.]+)/i],[v,[m,"WeChat"]],[/konqueror\/([\w\.]+)/i],[v,[m,"Konqueror"]],[/trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i],[v,[m,"IE"]],[/ya(?:search)?browser\/([\w\.]+)/i],[v,[m,"Yandex"]],[/(avast|avg)\/([\w\.]+)/i],[[m,/(.+)/,"$1 Secure "+$e],v],[/\bfocus\/([\w\.]+)/i],[v,[m,Ht+" Focus"]],[/\bopt\/([\w\.]+)/i],[v,[m,Kt+" Touch"]],[/coc_coc\w+\/([\w\.]+)/i],[v,[m,"Coc Coc"]],[/dolfin\/([\w\.]+)/i],[v,[m,"Dolphin"]],[/coast\/([\w\.]+)/i],[v,[m,Kt+" Coast"]],[/miuibrowser\/([\w\.]+)/i],[v,[m,"MIUI "+$e]],[/fxios\/([-\w\.]+)/i],[v,[m,Ht]],[/\bqihu|(qi?ho?o?|360)browser/i],[[m,"360 "+$e]],[/(oculus|samsung|sailfish|huawei)browser\/([\w\.]+)/i],[[m,/(.+)/,"$1 "+$e],v],[/(comodo_dragon)\/([\w\.]+)/i],[[m,/_/g," "],v],[/(electron)\/([\w\.]+) safari/i,/(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i,/m?(qqbrowser|baiduboxapp|2345Explorer)[\/ ]?([\w\.]+)/i],[m,v],[/(metasr)[\/ ]?([\w\.]+)/i,/(lbbrowser)/i,/\[(linkedin)app\]/i],[m],[/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i],[[m,Xs],v],[/(kakao(?:talk|story))[\/ ]([\w\.]+)/i,/(naver)\(.*?(\d+\.[\w\.]+).*\)/i,/safari (line)\/([\w\.]+)/i,/\b(line)\/([\w\.]+)\/iab/i,/(chromium|instagram)[\/ ]([-\w\.]+)/i],[m,v],[/\bgsa\/([\w\.]+) .*safari\//i],[v,[m,"GSA"]],[/musical_ly(?:.+app_?version\/|_)([\w\.]+)/i],[v,[m,"TikTok"]],[/headlesschrome(?:\/([\w\.]+)| )/i],[v,[m,Ft+" Headless"]],[/ wv\).+(chrome)\/([\w\.]+)/i],[[m,Ft+" WebView"],v],[/droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i],[v,[m,"Android "+$e]],[/(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i],[m,v],[/version\/([\w\.\,]+) .*mobile\/\w+ (safari)/i],[v,[m,"Mobile Safari"]],[/version\/([\w(\.|\,)]+) .*(mobile ?safari|safari)/i],[v,m],[/webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i],[m,[v,Oi,ao]],[/(webkit|khtml)\/([\w\.]+)/i],[m,v],[/(navigator|netscape\d?)\/([-\w\.]+)/i],[[m,"Netscape"],v],[/mobile vr; rv:([\w\.]+)\).+firefox/i],[v,[m,Ht+" Reality"]],[/ekiohf.+(flow)\/([\w\.]+)/i,/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo browser|minimo|conkeror|klar)[\/ ]?([\w\.\+]+)/i,/(seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([-\w\.]+)$/i,/(firefox)\/([\w\.]+)/i,/(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,/(links) \(([\w\.]+)/i,/panasonic;(viera)/i],[m,v],[/(cobalt)\/([\w\.]+)/i],[m,[v,/master.|lts./,""]]],cpu:[[/(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i],[[O,"amd64"]],[/(ia32(?=;))/i],[[O,ht]],[/((?:i[346]|x)86)[;\)]/i],[[O,"ia32"]],[/\b(aarch64|arm(v?8e?l?|_?64))\b/i],[[O,"arm64"]],[/\b(arm(?:v[67])?ht?n?[fl]p?)\b/i],[[O,"armhf"]],[/windows (ce|mobile); ppc;/i],[[O,"arm"]],[/((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i],[[O,/ower/,a,ht]],[/(sun4\w)[;\)]/i],[[O,"sparc"]],[/((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i],[[O,ht]]],device:[[/\b(sch-i[89]0\d|shw-m380s|sm-[ptx]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i],[d,[f,Ni],[g,U]],[/\b((?:s[cgp]h|gt|sm)-\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,/samsung[- ]([-\w]+)/i,/sec-(sgh\w+)/i],[d,[f,Ni],[g,C]],[/(?:\/|\()(ip(?:hone|od)[\w, ]*)(?:\/|;)/i],[d,[f,ut],[g,C]],[/\((ipad);[-\w\),; ]+apple/i,/applecoremedia\/[\w\.]+ \((ipad)/i,/\b(ipad)\d\d?,\d\d?[;\]].+ios/i],[d,[f,ut],[g,U]],[/(macintosh);/i],[d,[f,ut]],[/\b(sh-?[altvz]?\d\d[a-ekm]?)/i],[d,[f,Ys],[g,C]],[/\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i],[d,[f,Gs],[g,U]],[/(?:huawei|honor)([-\w ]+)[;\)]/i,/\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i],[d,[f,Gs],[g,C]],[/\b(poco[\w ]+)(?: bui|\))/i,/\b; (\w+) build\/hm\1/i,/\b(hm[-_ ]?note?[_ ]?(?:\d\w)?) bui/i,/\b(redmi[\-_ ]?(?:note|k)?[\w_ ]+)(?: bui|\))/i,/\b(mi[-_ ]?(?:a\d|one|one[_ ]plus|note lte|max|cc)?[_ ]?(?:\d?\w?)[_ ]?(?:plus|se|lite)?)(?: bui|\))/i],[[d,/_/g," "],[f,Ci],[g,C]],[/\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i],[[d,/_/g," "],[f,Ci],[g,U]],[/; (\w+) bui.+ oppo/i,/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i],[d,[f,"OPPO"],[g,C]],[/vivo (\w+)(?: bui|\))/i,/\b(v[12]\d{3}\w?[at])(?: bui|;)/i],[d,[f,"Vivo"],[g,C]],[/\b(rmx[12]\d{3})(?: bui|;|\))/i],[d,[f,"Realme"],[g,C]],[/\b(milestone|droid(?:[2-4x]| (?:bionic|x2|pro|razr))?:?( 4g)?)\b[\w ]+build\//i,/\bmot(?:orola)?[- ](\w*)/i,/((?:moto[\w\(\) ]+|xt\d{3,4}|nexus 6)(?= bui|\)))/i],[d,[f,zs],[g,C]],[/\b(mz60\d|xoom[2 ]{0,2}) build\//i],[d,[f,zs],[g,U]],[/((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i],[d,[f,ki],[g,U]],[/(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,/\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,/\blg-?([\d\w]+) bui/i],[d,[f,ki],[g,C]],[/(ideatab[-\w ]+)/i,/lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i],[d,[f,"Lenovo"],[g,U]],[/(?:maemo|nokia).*(n900|lumia \d+)/i,/nokia[-_ ]?([-\w\.]*)/i],[[d,/_/g," "],[f,"Nokia"],[g,C]],[/(pixel c)\b/i],[d,[f,Wt],[g,U]],[/droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i],[d,[f,Wt],[g,C]],[/droid.+ (a?\d[0-2]{2}so|[c-g]\d{4}|so[-gl]\w+|xq-a\w[4-7][12])(?= bui|\).+chrome\/(?![1-6]{0,1}\d\.))/i],[d,[f,jt],[g,C]],[/sony tablet [ps]/i,/\b(?:sony)?sgp\w+(?: bui|\))/i],[[d,"Xperia Tablet"],[f,jt],[g,U]],[/ (kb2005|in20[12]5|be20[12][59])\b/i,/(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i],[d,[f,"OnePlus"],[g,C]],[/(alexa)webm/i,/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i,/(kf[a-z]+)( bui|\)).+silk\//i],[d,[f,Bt],[g,U]],[/((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i],[[d,/(.+)/g,"Fire Phone $1"],[f,Bt],[g,C]],[/(playbook);[-\w\),; ]+(rim)/i],[d,f,[g,U]],[/\b((?:bb[a-f]|st[hv])100-\d)/i,/\(bb10; (\w+)/i],[d,[f,qs],[g,C]],[/(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i],[d,[f,Js],[g,U]],[/ (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i],[d,[f,Js],[g,C]],[/(nexus 9)/i],[d,[f,"HTC"],[g,U]],[/(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i,/(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,/(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i],[f,[d,/_/g," "],[g,C]],[/droid.+; ([ab][1-7]-?[0178a]\d\d?)/i],[d,[f,"Acer"],[g,U]],[/droid.+; (m[1-5] note) bui/i,/\bmz-([-\w]{2,})/i],[d,[f,"Meizu"],[g,C]],[/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[-_ ]?([-\w]*)/i,/(hp) ([\w ]+\w)/i,/(asus)-?(\w+)/i,/(microsoft); (lumia[\w ]+)/i,/(lenovo)[-_ ]?([-\w]+)/i,/(jolla)/i,/(oppo) ?([\w ]+) bui/i],[f,d,[g,C]],[/(kobo)\s(ereader|touch)/i,/(archos) (gamepad2?)/i,/(hp).+(touchpad(?!.+tablet)|tablet)/i,/(kindle)\/([\w\.]+)/i,/(nook)[\w ]+build\/(\w+)/i,/(dell) (strea[kpr\d ]*[\dko])/i,/(le[- ]+pan)[- ]+(\w{1,9}) bui/i,/(trinity)[- ]*(t\d{3}) bui/i,/(gigaset)[- ]+(q\w{1,9}) bui/i,/(vodafone) ([\w ]+)(?:\)| bui)/i],[f,d,[g,U]],[/(surface duo)/i],[d,[f,Mi],[g,U]],[/droid [\d\.]+; (fp\du?)(?: b|\))/i],[d,[f,"Fairphone"],[g,C]],[/(u304aa)/i],[d,[f,"AT&T"],[g,C]],[/\bsie-(\w*)/i],[d,[f,"Siemens"],[g,C]],[/\b(rct\w+) b/i],[d,[f,"RCA"],[g,U]],[/\b(venue[\d ]{2,7}) b/i],[d,[f,"Dell"],[g,U]],[/\b(q(?:mv|ta)\w+) b/i],[d,[f,"Verizon"],[g,U]],[/\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i],[d,[f,"Barnes & Noble"],[g,U]],[/\b(tm\d{3}\w+) b/i],[d,[f,"NuVision"],[g,U]],[/\b(k88) b/i],[d,[f,"ZTE"],[g,U]],[/\b(nx\d{3}j) b/i],[d,[f,"ZTE"],[g,C]],[/\b(gen\d{3}) b.+49h/i],[d,[f,"Swiss"],[g,C]],[/\b(zur\d{3}) b/i],[d,[f,"Swiss"],[g,U]],[/\b((zeki)?tb.*\b) b/i],[d,[f,"Zeki"],[g,U]],[/\b([yr]\d{2}) b/i,/\b(dragon[- ]+touch |dt)(\w{5}) b/i],[[f,"Dragon Touch"],d,[g,U]],[/\b(ns-?\w{0,9}) b/i],[d,[f,"Insignia"],[g,U]],[/\b((nxa|next)-?\w{0,9}) b/i],[d,[f,"NextBook"],[g,U]],[/\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i],[[f,"Voice"],d,[g,C]],[/\b(lvtel\-)?(v1[12]) b/i],[[f,"LvTel"],d,[g,C]],[/\b(ph-1) /i],[d,[f,"Essential"],[g,C]],[/\b(v(100md|700na|7011|917g).*\b) b/i],[d,[f,"Envizen"],[g,U]],[/\b(trio[-\w\. ]+) b/i],[d,[f,"MachSpeed"],[g,U]],[/\btu_(1491) b/i],[d,[f,"Rotor"],[g,U]],[/(shield[\w ]+) b/i],[d,[f,"Nvidia"],[g,U]],[/(sprint) (\w+)/i],[f,d,[g,C]],[/(kin\.[onetw]{3})/i],[[d,/\./g," "],[f,Mi],[g,C]],[/droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i],[d,[f,Li],[g,U]],[/droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i],[d,[f,Li],[g,C]],[/smart-tv.+(samsung)/i],[f,[g,re]],[/hbbtv.+maple;(\d+)/i],[[d,/^/,"SmartTV"],[f,Ni],[g,re]],[/(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i],[[f,ki],[g,re]],[/(apple) ?tv/i],[f,[d,ut+" TV"],[g,re]],[/crkey/i],[[d,Ft+"cast"],[f,Wt],[g,re]],[/droid.+aft(\w)( bui|\))/i],[d,[f,Bt],[g,re]],[/\(dtv[\);].+(aquos)/i,/(aquos-tv[\w ]+)\)/i],[d,[f,Ys],[g,re]],[/(bravia[\w ]+)( bui|\))/i],[d,[f,jt],[g,re]],[/(mitv-\w{5}) bui/i],[d,[f,Ci],[g,re]],[/Hbbtv.*(technisat) (.*);/i],[f,d,[g,re]],[/\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i,/hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i],[[f,Vi],[d,Vi],[g,re]],[/\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i],[[g,re]],[/(ouya)/i,/(nintendo) ([wids3utch]+)/i],[f,d,[g,B]],[/droid.+; (shield) bui/i],[d,[f,"Nvidia"],[g,B]],[/(playstation [345portablevi]+)/i],[d,[f,jt],[g,B]],[/\b(xbox(?: one)?(?!; xbox))[\); ]/i],[d,[f,Mi],[g,B]],[/((pebble))app/i],[f,d,[g,Ne]],[/(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i],[d,[f,ut],[g,Ne]],[/droid.+; (glass) \d/i],[d,[f,Wt],[g,Ne]],[/droid.+; (wt63?0{2,3})\)/i],[d,[f,Li],[g,Ne]],[/(quest( 2| pro)?)/i],[d,[f,Xs],[g,Ne]],[/(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i],[f,[g,yi]],[/(aeobc)\b/i],[d,[f,Bt],[g,yi]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+? mobile safari/i],[d,[g,C]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i],[d,[g,U]],[/\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i],[[g,U]],[/(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i],[[g,C]],[/(android[-\w\. ]{0,9});.+buil/i],[d,[f,"Generic"]]],engine:[[/windows.+ edge\/([\w\.]+)/i],[v,[m,io+"HTML"]],[/webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i],[v,[m,"Blink"]],[/(presto)\/([\w\.]+)/i,/(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,/ekioh(flow)\/([\w\.]+)/i,/(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i,/(icab)[\/ ]([23]\.[\d\.]+)/i,/\b(libweb)/i],[m,v],[/rv\:([\w\.]{1,9})\b.+(gecko)/i],[v,m]],os:[[/microsoft (windows) (vista|xp)/i],[m,v],[/(windows) nt 6\.2; (arm)/i,/(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i,/(windows)[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i],[m,[v,Oi,tr]],[/(win(?=3|9|n)|win 9x )([nt\d\.]+)/i],[[m,"Windows"],[v,Oi,tr]],[/ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i,/ios;fbsv\/([\d\.]+)/i,/cfnetwork\/.+darwin/i],[[v,/_/g,"."],[m,"iOS"]],[/(mac os x) ?([\w\. ]*)/i,/(macintosh|mac_powerpc\b)(?!.+haiku)/i],[[m,Qs],[v,/_/g,"."]],[/droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i],[v,m],[/(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,/(blackberry)\w*\/([\w\.]*)/i,/(tizen|kaios)[\/ ]([\w\.]+)/i,/\((series40);/i],[m,v],[/\(bb(10);/i],[v,[m,qs]],[/(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i],[v,[m,"Symbian"]],[/mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i],[v,[m,Ht+" OS"]],[/web0s;.+rt(tv)/i,/\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i],[v,[m,"webOS"]],[/watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i],[v,[m,"watchOS"]],[/crkey\/([\d\.]+)/i],[v,[m,Ft+"cast"]],[/(cros) [\w]+(?:\)| ([\w\.]+)\b)/i],[[m,Zs],v],[/panasonic;(viera)/i,/(netrange)mmh/i,/(nettv)\/(\d+\.[\w\.]+)/i,/(nintendo|playstation) ([wids345portablevuch]+)/i,/(xbox); +xbox ([^\);]+)/i,/\b(joli|palm)\b ?(?:os)?\/?([\w\.]*)/i,/(mint)[\/\(\) ]?(\w*)/i,/(mageia|vectorlinux)[; ]/i,/([kxln]?ubuntu|debian|suse|opensuse|gentoo|arch(?= linux)|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire)(?: gnu\/linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,/(hurd|linux) ?([\w\.]*)/i,/(gnu) ?([\w\.]*)/i,/\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i,/(haiku) (\w+)/i],[m,v],[/(sunos) ?([\w\.\d]*)/i],[[m,"Solaris"],v],[/((?:open)?solaris)[-\/ ]?([\w\.]*)/i,/(aix) ((\d)(?=\.|\)| )[\w\.])*/i,/\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux|serenityos)/i,/(unix) ?([\w\.]*)/i],[m,v]]},ve=function(F,$){if(typeof F===h&&($=F,F=t),!(this instanceof ve))return new ve(F,$).getResult();var D=typeof e!==u&&e.navigator?e.navigator:t,q=F||(D&&D.userAgent?D.userAgent:a),Ce=D&&D.userAgentData?D.userAgentData:t,Ie=$?so(ir,$):ir,j=D&&D.userAgent==q;return this.getBrowser=function(){var L={};return L[m]=t,L[v]=t,lt.call(L,q,Ie.browser),L[p]=ro(L[v]),j&&D&&D.brave&&typeof D.brave.isBrave==o&&(L[m]="Brave"),L},this.getCPU=function(){var L={};return L[O]=t,lt.call(L,q,Ie.cpu),L},this.getDevice=function(){var L={};return L[f]=t,L[d]=t,L[g]=t,lt.call(L,q,Ie.device),j&&!L[g]&&Ce&&Ce.mobile&&(L[g]=C),j&&L[d]=="Macintosh"&&D&&typeof D.standalone!==u&&D.maxTouchPoints&&D.maxTouchPoints>2&&(L[d]="iPad",L[g]=U),L},this.getEngine=function(){var L={};return L[m]=t,L[v]=t,lt.call(L,q,Ie.engine),L},this.getOS=function(){var L={};return L[m]=t,L[v]=t,lt.call(L,q,Ie.os),j&&!L[m]&&Ce&&Ce.platform!="Unknown"&&(L[m]=Ce.platform.replace(/chrome os/i,Zs).replace(/macos/i,Qs)),L},this.getResult=function(){return{ua:this.getUA(),browser:this.getBrowser(),engine:this.getEngine(),os:this.getOS(),device:this.getDevice(),cpu:this.getCPU()}},this.getUA=function(){return q},this.setUA=function(L){return q=typeof L===l&&L.length>Pi?Vi(L,Pi):L,this},this.setUA(q),this};ve.VERSION=r,ve.BROWSER=$t([m,v,p]),ve.CPU=$t([O]),ve.DEVICE=$t([d,f,g,B,C,re,U,Ne,yi]),ve.ENGINE=ve.OS=$t([m,v]),i.exports&&(s=i.exports=ve),s.UAParser=ve;var Je=typeof e!==u&&(e.jQuery||e.Zepto);if(Je&&!Je.ua){var Jt=new ve;Je.ua=Jt.getResult(),Je.ua.get=function(){return Jt.getUA()},Je.ua.set=function(F){Jt.setUA(F);var $=Jt.getResult();for(var D in $)Je.ua[D]=$[D]}}})(typeof window=="object"?window:jr)})(Tn,Ct);let Lt;const En=new Uint8Array(16);function yn(){if(!Lt&&(Lt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Lt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Lt(En)}const se=[];for(let i=0;i<256;++i)se.push((i+256).toString(16).slice(1));function Pn(i,s=0){return(se[i[s+0]]+se[i[s+1]]+se[i[s+2]]+se[i[s+3]]+"-"+se[i[s+4]]+se[i[s+5]]+"-"+se[i[s+6]]+se[i[s+7]]+"-"+se[i[s+8]]+se[i[s+9]]+"-"+se[i[s+10]]+se[i[s+11]]+se[i[s+12]]+se[i[s+13]]+se[i[s+14]]+se[i[s+15]]).toLowerCase()}const kn=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Cs={randomUUID:kn};function Mn(i,s,e){if(Cs.randomUUID&&!s&&!i)return Cs.randomUUID();i=i||{};const t=i.random||(i.rng||yn)();if(t[6]=t[6]&15|64,t[8]=t[8]&63|128,s){e=e||0;for(let r=0;r<16;++r)s[e+r]=t[r];return s}return Pn(t)}var _i={},Nn={get exports(){return _i},set exports(i){_i=i}},wi={},Cn={get exports(){return wi},set exports(i){wi=i}};(function(){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s={rotl:function(e,t){return e<<t|e>>>32-t},rotr:function(e,t){return e<<32-t|e>>>t},endian:function(e){if(e.constructor==Number)return s.rotl(e,8)&16711935|s.rotl(e,24)&4278255360;for(var t=0;t<e.length;t++)e[t]=s.endian(e[t]);return e},randomBytes:function(e){for(var t=[];e>0;e--)t.push(Math.floor(Math.random()*256));return t},bytesToWords:function(e){for(var t=[],r=0,a=0;r<e.length;r++,a+=8)t[a>>>5]|=e[r]<<24-a%32;return t},wordsToBytes:function(e){for(var t=[],r=0;r<e.length*32;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},bytesToHex:function(e){for(var t=[],r=0;r<e.length;r++)t.push((e[r]>>>4).toString(16)),t.push((e[r]&15).toString(16));return t.join("")},hexToBytes:function(e){for(var t=[],r=0;r<e.length;r+=2)t.push(parseInt(e.substr(r,2),16));return t},bytesToBase64:function(e){for(var t=[],r=0;r<e.length;r+=3)for(var a=e[r]<<16|e[r+1]<<8|e[r+2],n=0;n<4;n++)r*8+n*6<=e.length*8?t.push(i.charAt(a>>>6*(3-n)&63)):t.push("=");return t.join("")},base64ToBytes:function(e){e=e.replace(/[^A-Z0-9+\/]/ig,"");for(var t=[],r=0,a=0;r<e.length;a=++r%4)a!=0&&t.push((i.indexOf(e.charAt(r-1))&Math.pow(2,-2*a+8)-1)<<a*2|i.indexOf(e.charAt(r))>>>6-a*2);return t}};Cn.exports=s})();var Ri={utf8:{stringToBytes:function(i){return Ri.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(Ri.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var s=[],e=0;e<i.length;e++)s.push(i.charCodeAt(e)&255);return s},bytesToString:function(i){for(var s=[],e=0;e<i.length;e++)s.push(String.fromCharCode(i[e]));return s.join("")}}},Ls=Ri;/*!
|
|
1
|
+
var no=Object.defineProperty,oo=Object.defineProperties;var co=Object.getOwnPropertyDescriptors;var qt=Object.getOwnPropertySymbols,uo=Object.getPrototypeOf,rr=Object.prototype.hasOwnProperty,ar=Object.prototype.propertyIsEnumerable,ho=Reflect.get;var Ui=(_,P,N)=>P in _?no(_,P,{enumerable:!0,configurable:!0,writable:!0,value:N}):_[P]=N,W=(_,P)=>{for(var N in P||(P={}))rr.call(P,N)&&Ui(_,N,P[N]);if(qt)for(var N of qt(P))ar.call(P,N)&&Ui(_,N,P[N]);return _},qe=(_,P)=>oo(_,co(P));var nr=(_,P)=>{var N={};for(var J in _)rr.call(_,J)&&P.indexOf(J)<0&&(N[J]=_[J]);if(_!=null&&qt)for(var J of qt(_))P.indexOf(J)<0&&ar.call(_,J)&&(N[J]=_[J]);return N};var c=(_,P,N)=>(Ui(_,typeof P!="symbol"?P+"":P,N),N);var xi=(_,P,N)=>ho(uo(_),N,P);var S=(_,P,N)=>new Promise((J,dt)=>{var H=ge=>{try{R(N.next(ge))}catch(_e){dt(_e)}},ie=ge=>{try{R(N.throw(ge))}catch(_e){dt(_e)}},R=ge=>ge.done?J(ge.value):Promise.resolve(ge.value).then(H,ie);R((N=N.apply(_,P)).next())});(function(_,P){typeof exports=="object"&&typeof module!="undefined"?P(exports,require("aliyun-rts-sdk"),require("useragent-util"),require("eventemitter3"),require("browser-log-reporter")):typeof define=="function"&&define.amd?define(["exports","aliyun-rts-sdk","useragent-util","eventemitter3","browser-log-reporter"],P):(_=typeof globalThis!="undefined"?globalThis:_||self,P(_.AliRtcEngine={},_.AliyunRts,_.UserAgentUtil,_.EventEmitter,_.BrowserLogReporter))})(this,function(_,P,N,J,dt){var he,Ie,je,y;"use strict";var H=(i=>(i.PullStreamStats="remoteStat",i.RtsSubscribeExceeds="rtsSubscribeExceeds",i.UserJoined="userJoined",i.UserLeft="userLeft",i.Bye="bye",i.MuteAudio="muteAudio",i.UnmuteAudio="unmuteAudio",i.MuteVideo="muteVideo",i.UnmuteVideo="unmuteVideo",i.MuteScreen="muteScreen",i.UnmuteScreen="unmuteScreen",i.Error="error",i))(H||{}),ie=(i=>(i.Local="local-device-status-change",i.Remote="remote-device-status-change",i))(ie||{}),R=(i=>(i.Audio="sophon_audio",i.VideoLarge="sophon_video_camera_large",i.VideoSmall="sophon_video_camera_small",i.Screen="sophon_video_screen_share",i))(R||{}),ge=(i=>(i.Audio="rts audio",i.VideoLarge="rts video",i))(ge||{}),_e=(i=>(i[i.Camera=0]="Camera",i[i.Screen=1]="Screen",i[i.Image=2]="Image",i))(_e||{}),pt=(i=>(i[i.Microphone=0]="Microphone",i[i.Screen=1]="Screen",i[i.Mixed=2]="Mixed",i))(pt||{}),mt=(i=>(i.prod="rs.rtn.aliyuncs.com",i.pre="prs.rtn.aliyuncs.com",i))(mt||{});const Ge="6.11.4",Bi="web";class ye{static getVersionNumber(){let s=Ge.split("."),e="";return s.forEach(t=>{t.length===1?e+="0"+t:e+=t}),parseInt(e)}static queryingParam(s){let e=[];if(s)for(let t in s)e.push(t+"="+s[t]);return e.join("&")}static getQueryParams(s){const t=window.location.search.substring(1).split("&");for(let r=0;r<t.length;r++){const a=t[r].split("=");if(decodeURIComponent(a[0])===s)return decodeURIComponent(a[1])}}static createCallid(){return N.Guid.create(8)+"-"+N.Guid.create(4)+"-4"+N.Guid.create(3)+"-"+N.Guid.create(4)}static checkSubOptionsValid(s){if(s){const{audio:e,video:t,screen:r}=s;if(e===!1&&t===!1&&r===!1)return!1}return!0}static isNetworkAvailable(){return S(this,null,function*(){const s=mt.prod,{onLine:e}=navigator;if(!e)return!1;try{return yield fetch(`https://${s}/roomserver/v1/ws/version`),!0}catch(t){return!1}})}}var Gt=(i=>(i[i.DEBUG=0]="DEBUG",i[i.INFO=1]="INFO",i[i.API=2]="API",i[i.WARNING=3]="WARNING",i[i.ERROR=4]="ERROR",i[i.NONE=5]="NONE",i))(Gt||{});class de{constructor(s,e,t){c(this,"logLevel");c(this,"outputToConsole");c(this,"maxLogLength");c(this,"maxlogCache");c(this,"uri");c(this,"requestTimeout");c(this,"delay");c(this,"rate");c(this,"hugeBatchCount");c(this,"checkInterval");c(this,"flushModecheckInterval");c(this,"recordOverheadLength");c(this,"httpRequest");c(this,"traceId");c(this,"traceIdPostfix");c(this,"flushMode");c(this,"outputToServer");c(this,"batchCount");c(this,"msgCounter");c(this,"lastRequestTime");c(this,"enable");c(this,"retx");c(this,"lastProfilingTime");c(this,"bytesOut");c(this,"dropped");c(this,"networkdropped");c(this,"lastLogTime",0);c(this,"logArray");c(this,"onTimer",()=>{if(!this.enable)return;this.processCachedLogs();let s=Date.now(),e=s-this.lastLogTime>1e4;if(s-this.lastProfilingTime>=5e3&&!e){let r=this.getProfiling();this.logInternal("[logger] profiling result: "+de.toString(r))}let t=this.flushMode?this.flushModecheckInterval:this.checkInterval;e&&(t=this.checkInterval),setTimeout(this.onTimer,t)});this.logLevel=3,this.maxLogLength=12e3,this.requestTimeout=5e3,this.delay=2e3,this.rate=3,this.maxlogCache=1e3,this.hugeBatchCount=100,this.outputToConsole=!0,this.outputToServer=!1,this.checkInterval=1e3,this.flushModecheckInterval=200,this.recordOverheadLength=120,this.flushMode=!1,this.batchCount=0,this.retx=[],this.lastProfilingTime=Date.now(),this.bytesOut=0,this.dropped=0,this.networkdropped=0,window&&window.location&&window.location.protocol&&window.location.protocol==="http:"?this.uri="http://"+e+"."+s+"/logstores/"+t+"/track":this.uri="https://"+e+"."+s+"/logstores/"+t+"/track",this.httpRequest=null,this.msgCounter=0,this.traceIdPostfix=N.LocalStorage.uuid+"-"+Date.now(),this.traceId="",this.logArray=[],this.enable=!0,this.lastRequestTime=0,this.onTimer()}static toString(s){let e;if(s instanceof Error)e=s.message;else if(typeof s=="string")e=s;else try{e=JSON.stringify(s)}catch(t){e="undefined"}return e}changeConfig(s){s.enable!==void 0&&(this.enable=s.enable,this.enable||this.clear()),s.logLevel!==void 0&&s.logLevel>=0&&s.logLevel<=5&&(this.logLevel=s.logLevel),s.logToConsole!==void 0&&(this.outputToConsole=s.logToConsole),s.logToServer!==void 0&&(this.outputToServer=s.logToServer),s.maxLogLength!==void 0&&s.maxLogLength>10&&(this.maxLogLength=s.maxLogLength),s.maxlogCache!==void 0&&s.maxlogCache>10&&s.maxlogCache<2e4&&(this.maxlogCache=s.maxlogCache),s.requestTimeout!==void 0&&s.requestTimeout>100&&s.requestTimeout<1e5&&(this.requestTimeout=s.requestTimeout),s.delay!==void 0&&s.delay>0&&s.delay<1e5&&(this.delay=s.delay),s.rate!==void 0&&s.rate>0&&s.rate<1e4&&(this.rate=s.rate)}getProfiling(){let s={enable:this.enable,flush:this.flushMode,cache:this.logArray.length,drop:this.dropped,dropNw:this.networkdropped,kbps:0},e=Date.now();return e-this.lastProfilingTime>500?(s.kbps=Math.round(this.bytesOut*8/(e-this.lastProfilingTime)),this.lastProfilingTime=e,this.bytesOut=0):s.kbps=-1,s}clear(){this.retx=[],this.logArray=[]}setFlushMode(s){this.enable&&(this.flushMode=s,this.flushMode&&this.processCachedLogs())}setTraceID(s){s&&(s.length>64&&(s=s.substring(0,64)),this.traceId=s)}d(...s){if(!this.enable||this.logLevel>0)return;let e=this.getCurrentTime();this.outputToConsole&&console.debug(e,...s);let t=de.paramArrayToString(s);this.addLog(0,t,!1,e)}i(...s){if(!this.enable||this.logLevel>1)return;let e=this.getCurrentTime();this.outputToConsole&&console.log(e,...s);let t=de.paramArrayToString(s);this.addLog(1,t,!1,e)}w(...s){if(!this.enable||this.logLevel>3)return;let e=this.getCurrentTime();this.outputToConsole&&console.warn(e,...s);let t=de.paramArrayToString(s);this.addLog(3,t,!1,e)}e(...s){if(!this.enable||this.logLevel>4)return;let e=this.getCurrentTime();this.outputToConsole&&console.error(e,...s);let t=de.paramArrayToString(s);t="<error> "+t,this.addLog(4,t,!1,e)}ev(...s){if(!this.enable||this.logLevel>2)return;let e=this.getCurrentTime();this.outputToConsole&&console.log(e,...s);let t=de.paramArrayToString(s);this.addLog(2,t,!1,e)}a(...s){if(!this.enable||this.logLevel>2)return;let e=this.getCurrentTime();if(this.outputToConsole){if(s.length>2){const r=`${s[1]}`;r.startsWith("__g__")&&console.group(`${r.substring(5)}_${s[2]}`)}console.log(e,...s)}let t=de.paramArrayToString(s);this.addLog(2,t,!1,e)}ar(...s){if(!this.enable||this.logLevel>2)return;let e=this.getCurrentTime();this.outputToConsole&&(console.log(e,...s),s.length>2&&`${s[1]}`.startsWith("__g__")&&console.groupEnd());let t=de.paramArrayToString(s);this.addLog(2,t,!1,e)}ae(...s){if(!this.enable||this.logLevel>4)return;let e=this.getCurrentTime();this.outputToConsole&&(console.error(e,...s),this.logLevel>2&&s.length>2&&console.groupEnd());let t=de.paramArrayToString(s);t="<error> "+t,this.addLog(4,t,!1,e)}logInternal(s){if(!this.enable||this.logLevel>3)return;let e=this.getCurrentTime();this.addLog(2,s,!0,e)}addLog(s,e,t,r){e=r+" "+e,e.length>this.maxLogLength&&(e=e.substring(0,this.maxLogLength));let a=Date.now();t||(this.lastLogTime=a);let n={tm:a.toString(),level:s.toString(),msg:e,count:this.msgCounter.toString(),trace:this.traceId+"-"+this.traceIdPostfix};this.logArray.push(n),this.msgCounter++,this.logArray.length>this.maxlogCache&&this.saveMemory(this.maxlogCache-5)}saveMemory(s){let e=0,t=0;for(;this.logArray.length>s&&e<=4;){for(;t<this.logArray.length;)if(parseInt(this.logArray[t].level)===e){if(this.logArray.splice(t,1),this.dropped++,this.logArray.length<=s)break}else t++;t===this.logArray.length&&(t=0,e++)}}processCachedLogs(){if(!this.outputToServer||this.logArray.length===0&&this.retx.length===0||this.isHttpRequesting()||!this.flushMode&&Date.now()-this.lastRequestTime<this.delay)return;if(this.retx&&this.retx.length>0){let o=this.retx[0].tries?parseInt(this.retx[0].tries)+1:1;if(this.flushMode||this.retx.length<this.hugeBatchCount||o<4){let u=o.toString();for(let h=0;h<this.retx.length;h++)this.retx[h].tries=u;this.batchSend(this.retx);return}else this.retx=[],this.dropped+=this.retx.length,this.networkdropped+=this.retx.length}if(this.logArray.length===0)return;let s=this.flushMode?1.5*1024*1024:this.delay*this.rate,e=0,t=0,r=this.recordOverheadLength;for(let o=0;o<this.logArray.length&&(t+=this.logArray[o].msg.length+r,!(t>s));o++)e=o+1;e===0&&(e=1);let a=this.logArray.splice(0,e);this.batchCount++;let n=this.batchCount.toString();for(let o=0;o<a.length;o++)a[o].batch=n,a[o].tries="0";this.retx=a,this.batchSend(a)}createHttpRequest(){this.httpRequest||window.XMLHttpRequest&&(this.httpRequest=new XMLHttpRequest)}isHttpRequesting(){return this.httpRequest!==null}batchSend(s){if(this.isHttpRequesting())return;this.lastRequestTime=Date.now();let e=this.uri,t=JSON.stringify(s);t='{"__logs__":'+t+"}",this.createHttpRequest(),this.isHttpRequesting()&&(this.bytesOut+=t.length,this.httpRequest.open("POST",e,!0),this.httpRequest.timeout=this.requestTimeout,this.httpRequest.setRequestHeader("x-log-apiversion","0.6.0"),this.httpRequest.setRequestHeader("x-log-bodyrawsize",t.length),this.httpRequest.onload=()=>{this.httpRequest.status!==200&&console.log("Error: failed to post log ",this.httpRequest),this.retx=[],this.lastRequestTime=Date.now(),this.httpRequest=null},this.httpRequest.onerror=()=>{console.log("Error: post log failed"),this.lastRequestTime=Date.now(),this.httpRequest=null},this.httpRequest.onabort=()=>{console.log("Error: post log aborted"),this.lastRequestTime=Date.now(),this.httpRequest=null},this.httpRequest.send(t))}getCurrentTime(){let s=new Date;return s.getFullYear()+"-"+("00"+(s.getMonth()+1)).slice(-2)+"-"+("00"+s.getDate()).slice(-2)+" "+("00"+s.getHours()).slice(-2)+":"+("00"+s.getMinutes()).slice(-2)+":"+("00"+s.getSeconds()).slice(-2)+"."+("000"+s.getMilliseconds()).slice(-3)}static paramArrayToString(s){let e="";for(let t=0;t<s.length;t++){e!==""&&(e+=",");let r=de.toString(s[t]);e+=r}return e}}class w{static getLogger(){return this.logger||(this.logger=new de("cn-shanghai.log.aliyuncs.com","alirtc","client_h5")),this.logger}static setLogLevel(s){this.getLogger().changeConfig({logLevel:s})}static config(s){this.getLogger().changeConfig(s)}static setTraceID(s){this.getLogger().setTraceID(s)}static setFlushMode(s){this.getLogger().setFlushMode(s)}static interface(...s){this.getLogger().a("[API]",...s)}static interfaceResult(s,e,t,...r){t?this.getLogger().ar("[ARE]",s,e,...r):this.getLogger().ae("[ARE]",s,e,...r)}static event(...s){this.getLogger().ev("[EVT]",...s)}static debug(...s){this.getLogger().d("[DBG]",...s)}static info(...s){this.getLogger().i("[INF]",...s)}static warn(...s){this.getLogger().w("[WARN]",...s)}static error(...s){this.getLogger().e("[ERR]",...s)}}c(w,"logger");const or=i=>S(this,null,function*(){const s=new P.AliRTS.SupportUtil;let e={support:!1,detail:{isWebRTCSupported:s.checkMediaDevices()&&s.checkWebRtcSupport(),isH264DecodeSupported:!1,isH264EncodeSupported:!1,isScreenShareSupported:!1,isSendMediaExtensionMsgSupported:!1,isBrowserSupported:s.checkBrowser({errorCode:0,message:""})}};if(e.support=e.detail.isWebRTCSupported&&e.detail.isBrowserSupported,s.checkWebRtcSupport()&&i!=="sendonly"){const t=yield s.checkH264Decode();e.detail.isH264DecodeSupported=t,e.support=e.support&&t}if(s.checkWebRtcSupport()&&i!=="recvonly"){const t=yield s.checkH264Encode();e.detail.isH264EncodeSupported=t,e.support=e.support&&t}return e.detail.isScreenShareSupported=s.checkWebRtcSupport()&&s.checkScreenCapture()&&!P.AliRTS.SystenUtil.isAndroid&&!P.AliRTS.SystenUtil.isIos,e.detail.isSendMediaExtensionMsgSupported=s.checkWebRtcSupport()&&s.checkEncodedTransformSupport(),e});var Q=(i=>(i[i.AliRtcSdkStreamTypeCapture=0]="AliRtcSdkStreamTypeCapture",i[i.AliRtcSdkStreamTypeScreen=1]="AliRtcSdkStreamTypeScreen",i))(Q||{}),Fi=(i=>(i[i.PRE_PROCESSOR=0]="PRE_PROCESSOR",i[i.POST_PROCESSOR=1]="POST_PROCESSOR",i))(Fi||{}),gt=(i=>(i[i.AUDIO=0]="AUDIO",i[i.VIDEO=1]="VIDEO",i[i.BOTH=2]="BOTH",i))(gt||{});class He extends J{constructor(e,t=Q.AliRtcSdkStreamTypeCapture,r=1){super();c(this,"name");c(this,"options");c(this,"type",0);c(this,"streamType");c(this,"trackType");c(this,"zIndex",1);c(this,"_isEnable",!0);c(this,"lastInputAudioTrack");c(this,"lastOutputAudioTrack");c(this,"lastInputVideoTrack");c(this,"lastOutputVideoTrack");this.name=e,this.streamType=t,this.trackType=r,this.options=this.initOptions}get initOptions(){return{}}getOptions(){return this.options}init(){return S(this,null,function*(){})}enable(){this._isEnable||(this._isEnable=!0,this.init(),this.emit("enabled"))}disable(){this._isEnable&&(this._isEnable=!1,this.clear(),this.emit("disabled"))}get isEnable(){return this._isEnable}audioUpdated(e){var t,r;return((t=this.lastInputAudioTrack)==null?void 0:t.id)!==((r=e.currentAudioTrack)==null?void 0:r.id)}videoUpdated(e){var t,r;return((t=this.lastInputVideoTrack)==null?void 0:t.id)!==((r=e.currentVideoTrack)==null?void 0:r.id)}execute(e,t){return S(this,null,function*(){const r=this.shouldUpdate(e,t);this.lastInputAudioTrack=e.currentAudioTrack,this.lastInputVideoTrack=e.currentVideoTrack,r?yield this.process(e,t):(this.lastOutputAudioTrack&&(this.trackType===2||this.trackType===0)&&this.lastOutputAudioTrack&&e.updateAudioTrack(this.lastOutputAudioTrack),this.lastOutputVideoTrack&&(this.trackType===2||this.trackType===1)&&this.lastOutputVideoTrack&&e.updateVideoTrack(this.lastOutputVideoTrack)),this.lastOutputAudioTrack=e.currentAudioTrack,this.lastOutputVideoTrack=e.currentVideoTrack})}clear(e){this.lastInputAudioTrack=void 0,this.lastInputVideoTrack=void 0,this.lastOutputAudioTrack=void 0,this.lastOutputVideoTrack=void 0}}var ze=(i=>(i[i.LiveTranscodingSingle=0]="LiveTranscodingSingle",i[i.LiveTranscodingMix=1]="LiveTranscodingMix",i))(ze||{}),zt=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingAudio=1]="LiveTranscodingAudio",i[i.LiveTranscodingVideo=2]="LiveTranscodingVideo",i))(zt||{}),We=(i=>(i[i.LiveTranscodingCamera=0]="LiveTranscodingCamera",i[i.LiveTranscodingShareScreen=1]="LiveTranscodingShareScreen",i))(We||{});const Ye={0:"camera",1:"shareScreen"};var Yt=(i=>(i[i.LiveTranscoding_Profile_1IN_1080P=0]="LiveTranscoding_Profile_1IN_1080P",i[i.LiveTranscoding_Profile_1IN_720P=1]="LiveTranscoding_Profile_1IN_720P",i[i.LiveTranscoding_Profile_1IN_360P=2]="LiveTranscoding_Profile_1IN_360P",i[i.LiveTranscoding_Profile_2IN_1080P=3]="LiveTranscoding_Profile_2IN_1080P",i[i.LiveTranscoding_Profile_2IN_720P=4]="LiveTranscoding_Profile_2IN_720P",i[i.LiveTranscoding_Profile_2IN_360P=5]="LiveTranscoding_Profile_2IN_360P",i[i.LiveTranscoding_Profile_4IN_1080P=6]="LiveTranscoding_Profile_4IN_1080P",i[i.LiveTranscoding_Profile_4IN_720P=7]="LiveTranscoding_Profile_4IN_720P",i[i.LiveTranscoding_Profile_4IN_360P=8]="LiveTranscoding_Profile_4IN_360P",i[i.LiveTranscoding_Profile_9IN_1080P=9]="LiveTranscoding_Profile_9IN_1080P",i[i.LiveTranscoding_Profile_9IN_720P=10]="LiveTranscoding_Profile_9IN_720P",i[i.LiveTranscoding_Profile_9IN_360P=11]="LiveTranscoding_Profile_9IN_360P",i[i.LiveTranscoding_Profile_12IN_1080P=12]="LiveTranscoding_Profile_12IN_1080P",i[i.LiveTranscoding_Profile_12IN_720P=13]="LiveTranscoding_Profile_12IN_720P",i[i.LiveTranscoding_Profile_12IN_360P=14]="LiveTranscoding_Profile_12IN_360P",i[i.LiveTranscoding_Profile_16IN_1080P=15]="LiveTranscoding_Profile_16IN_1080P",i[i.LiveTranscoding_Profile_16IN_720P=16]="LiveTranscoding_Profile_16IN_720P",i[i.LiveTranscoding_Profile_16IN_360P=17]="LiveTranscoding_Profile_16IN_360P",i[i.LiveTranscoding_Profile_Mixed=9999]="LiveTranscoding_Profile_Mixed",i))(Yt||{});const cr={0:"1IN_1080P",1:"1IN_720P",2:"1IN_360P",3:"2IN_1080P",4:"2IN_720P",5:"2IN_360P",6:"4IN_1080P",7:"4IN_720P",8:"4IN_360P",9:"9IN_1080P",10:"9IN_720P",11:"9IN_360P",12:"12IN_1080P",13:"12IN_720P",14:"12IN_360P",15:"16IN_1080P",16:"16IN_720P",17:"16IN_360P",9999:"Mixed_Audio"};var St=(i=>(i[i.LiveTranscoding_HZ_48000=48e3]="LiveTranscoding_HZ_48000",i[i.LiveTranscoding_HZ_44100=44100]="LiveTranscoding_HZ_44100",i[i.LiveTranscoding_HZ_32000=32e3]="LiveTranscoding_HZ_32000",i[i.LiveTranscoding_HZ_16000=16e3]="LiveTranscoding_HZ_16000",i[i.LiveTranscoding_HZ_8000=8e3]="LiveTranscoding_HZ_8000",i))(St||{}),Xe=(i=>(i[i.LiveTranscodingNoBody=0]="LiveTranscodingNoBody",i[i.LiveTranscodingBody=1]="LiveTranscodingBody",i))(Xe||{}),Ze=(i=>(i[i.NOTO_SERIF_CJKSC_REGULAR=0]="NOTO_SERIF_CJKSC_REGULAR",i[i.ALIBABA_PUHUITI_REGULAR=1]="ALIBABA_PUHUITI_REGULAR",i[i.ALIBABA_PUHUITI_BOLD=2]="ALIBABA_PUHUITI_BOLD",i[i.ALIBABA_PUHUITI_Heavy=3]="ALIBABA_PUHUITI_Heavy",i[i.ALIBABA_PUHUITI_LIGHT=4]="ALIBABA_PUHUITI_LIGHT",i[i.ALIBABA_PUHUITI_MEDIUM=5]="ALIBABA_PUHUITI_MEDIUM",i))(Ze||{}),Xt=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingCrop=1]="LiveTranscodingCrop",i[i.LiveTranscodingFill=2]="LiveTranscodingFill",i))(Xt||{}),ft=(i=>(i[i.LiveTranscodingNormal=0]="LiveTranscodingNormal",i[i.LiveTranscodingVirtualBackground=1]="LiveTranscodingVirtualBackground",i))(ft||{}),Zt=(i=>(i[i.LiveTranscodingState_IDLE=0]="LiveTranscodingState_IDLE",i[i.LiveTranscodingState_CONNNECT=1]="LiveTranscodingState_CONNNECT",i[i.LiveTranscodingState_RUNNING=2]="LiveTranscodingState_RUNNING",i[i.LiveTranscodingState_RECOVERING=3]="LiveTranscodingState_RECOVERING",i[i.LiveTranscodingState_FAILURE=4]="LiveTranscodingState_FAILURE",i[i.LiveTranscodingState_END=5]="LiveTranscodingState_END",i))(Zt||{}),Re=(i=>(i[i.LiveTranscodingErrorPublishOk=0]="LiveTranscodingErrorPublishOk",i[i.LiveTranscodingErrorStreamNotFound=17825793]="LiveTranscodingErrorStreamNotFound",i[i.LiveTranscodingErrorStreamAlreadyExist=17825794]="LiveTranscodingErrorStreamAlreadyExist",i[i.LiveTranscodingErrorInvalidParam=17825795]="LiveTranscodingErrorInvalidParam",i[i.LiveTranscodingErrorInternalError=17825796]="LiveTranscodingErrorInternalError",i[i.LiveTranscodingErrorRtmpServerError=17825797]="LiveTranscodingErrorRtmpServerError",i[i.LiveTranscodingErrorRtmpStreamUrlError=17825798]="LiveTranscodingErrorRtmpStreamUrlError",i[i.LiveTranscodingErrorPublishTimeout=17825799]="LiveTranscodingErrorPublishTimeout",i[i.LiveTranscodingErrorNotAuthorized=17825800]="LiveTranscodingErrorNotAuthorized",i))(Re||{}),Qt=(i=>(i[i.TrascodingPublishTaskStatusStart=0]="TrascodingPublishTaskStatusStart",i[i.TrascodingPublishTaskStatusUpdate=1]="TrascodingPublishTaskStatusUpdate",i[i.TrascodingPublishTaskStatusStop=2]="TrascodingPublishTaskStatusStop",i))(Qt||{}),ue=(i=>(i[i.MPU_TASK_TRANSACTION_START=0]="MPU_TASK_TRANSACTION_START",i[i.MPU_TASK_TRANSACTION_UPDATE=1]="MPU_TASK_TRANSACTION_UPDATE",i[i.MPU_TASK_TRANSACTION_STOP=2]="MPU_TASK_TRANSACTION_STOP",i[i.MPU_TASK_TRANSACTION_LIST=3]="MPU_TASK_TRANSACTION_LIST",i[i.MPU_TASK_TRANSACTION_POLLING=4]="MPU_TASK_TRANSACTION_POLLING",i[i.MPU_TASK_TRANSACTION_ACKNOWLEDGE=5]="MPU_TASK_TRANSACTION_ACKNOWLEDGE",i[i.MPU_TASK_TRANSACTION_END=6]="MPU_TASK_TRANSACTION_END",i))(ue||{});const ur={0:"/libra/v1/sdk/start-task",1:"/libra/v1/sdk/update-task",2:"/libra/v1/sdk/stop-task",3:"/libra/v1/sdk/list-task",4:"/libra/v1/sdk/polling",5:"/libra/v1/sdk/acknowledge",6:"/"};class ei{constructor(s,e,t,r,a,n,o,u){c(this,"videoWidth");c(this,"videoHeight");c(this,"videoFramerate",20);c(this,"videoBitrate",2e3);c(this,"videoGop",30);c(this,"audioSamplerate",St.LiveTranscoding_HZ_44100);c(this,"audioBitrate",500);c(this,"audioChannels",1);this.videoWidth=s,this.videoHeight=e,t&&(this.videoFramerate=t),r&&(this.videoBitrate=r),a&&(this.videoGop=a),n&&(this.audioSamplerate=n),o&&(this.audioBitrate=o),u&&(this.audioChannels=u)}}const ti=i=>((i&16711680)>>16)+(i&65280)+((i&255)<<16),pe=(i=0,s)=>{if(s==0)return 0;let e=i/s;return e<0&&(e=0),e>1&&(e=1),e};class bt{constructor(s,e,t){c(this,"mixMode",ze.LiveTranscodingSingle);c(this,"singleParam");c(this,"mixParam");s&&(this.mixMode=s),e&&(this.singleParam=e),t&&(this.mixParam=t)}toJson(s,e,t,r,a){const n={appid:e.appId,channelid:e.channelId};if(s===ue.MPU_TASK_TRANSACTION_POLLING||s===ue.MPU_TASK_TRANSACTION_LIST||s===ue.MPU_TASK_TRANSACTION_ACKNOWLEDGE)return s===ue.MPU_TASK_TRANSACTION_ACKNOWLEDGE&&(n.messageid=a),n;if(n.taskid=t,s!==ue.MPU_TASK_TRANSACTION_STOP){if(n.mixmode=this.mixMode,r&&(n.streamurl=r),this.mixMode===ze.LiveTranscodingSingle){const o=this.singleParam;if(o){n.streamtype=o.streamType,o.sourceType===We.LiveTranscodingShareScreen?n.sourcetype=Ye[o.sourceType]:n.sourcetype=Ye[We.LiveTranscodingCamera];const u=[];o.userId&&u.push(o.userId),n.subspecusers=u}}else if(s===ue.MPU_TASK_TRANSACTION_START||s===ue.MPU_TASK_TRANSACTION_UPDATE){const o=this.mixParam;if(o){o.taskProfile&&(n.taskprofile=cr[o.taskProfile]);const u=o.encodeParam||new ei(1280,720);let h=u.videoWidth,l=u.videoHeight;const p={};Object.keys(u).forEach(m=>{const g=u[m];g>0&&(p[m.toLowerCase()]=g)}),p.lowbitratehighquality=0,n.encodeparam=p,n.backgrounds=o.backgrounds.map(m=>m.toJson(h,l)),n.watermarks=o.watermarks.map(m=>m.toJson(h,l)),n.clockwidgets=o.clockWidgets.map(m=>m.toJson(h,l));const d=o.users.map(m=>m.userId);n.subspecusers=[...new Set(d)],n.layouts=[{audiomixcount:o.users.length,panes:o.users.map((m,g)=>m.toJson(g,h,l,o.mediaProcessMode))}],n.layoutids=["0"],n.cropmode=o.cropMode,n.backgroundcolor=ti(o.backgroundColor),n.taskmode=o.mediaProcessMode}}}return n}}var Pe=(i=>(i.pre="pre",i.prod="prod",i))(Pe||{}),Te=(i=>(i.AliRtcSdkCommunication="communication",i.AliRtcSdkInteractiveLive="interactive_live",i.AliRtcSdkInteractiveWithLowLatencyLive="cdn_live",i))(Te||{}),Me=(i=>(i.AliRtcSdkInteractive="interactive",i.AliRtcSdkLive="live",i))(Me||{}),we=(i=>(i[i.AliEngineLocalDeviceTypeUnknown=0]="AliEngineLocalDeviceTypeUnknown",i[i.AliEngineLocalDeviceTypeMic=1]="AliEngineLocalDeviceTypeMic",i[i.AliEngineLocalDeviceTypeSpeaker=2]="AliEngineLocalDeviceTypeSpeaker",i[i.AliEngineLocalDeviceTypeAudioDevice=3]="AliEngineLocalDeviceTypeAudioDevice",i[i.AliEngineLocalDeviceTypeCamera=4]="AliEngineLocalDeviceTypeCamera",i[i.AliEngineLocalDeviceTypeDisplay=5]="AliEngineLocalDeviceTypeDisplay",i[i.AliEngineLocalDeviceTypeVideoDevice=6]="AliEngineLocalDeviceTypeVideoDevice",i))(we||{}),X=(i=>(i[i.AliEngineLocalDeviceExceptionTypeUnknown=0]="AliEngineLocalDeviceExceptionTypeUnknown",i[i.AliEngineLocalDeviceExceptionTypeMicOpenFail=1]="AliEngineLocalDeviceExceptionTypeMicOpenFail",i[i.AliEngineLocalDeviceExceptionTypeMicInterrupt=2]="AliEngineLocalDeviceExceptionTypeMicInterrupt",i[i.AliEngineLocalDeviceExceptionTypeMicAuthFail=3]="AliEngineLocalDeviceExceptionTypeMicAuthFail",i[i.AliEngineLocalDeviceExceptionTypeMicNotAvailable=4]="AliEngineLocalDeviceExceptionTypeMicNotAvailable",i[i.AliEngineLocalDeviceExceptionTypeSpeakerOpenFail=5]="AliEngineLocalDeviceExceptionTypeSpeakerOpenFail",i[i.AliEngineLocalDeviceExceptionTypeSpeakerInterrupt=6]="AliEngineLocalDeviceExceptionTypeSpeakerInterrupt",i[i.AliEngineLocalDeviceExceptionTypeSpeakerNotAvailable=7]="AliEngineLocalDeviceExceptionTypeSpeakerNotAvailable",i[i.AliEngineLocalDeviceExceptionTypeAudioDeviceException=8]="AliEngineLocalDeviceExceptionTypeAudioDeviceException",i[i.AliEngineLocalDeviceExceptionTypeCameraOpenFail=9]="AliEngineLocalDeviceExceptionTypeCameraOpenFail",i[i.AliEngineLocalDeviceExceptionTypeCameraInterrupt=10]="AliEngineLocalDeviceExceptionTypeCameraInterrupt",i[i.AliEngineLocalDeviceExceptionTypeCameraAuthFail=11]="AliEngineLocalDeviceExceptionTypeCameraAuthFail",i[i.AliEngineLocalDeviceExceptionTypeDisplayException=12]="AliEngineLocalDeviceExceptionTypeDisplayException",i[i.AliEngineLocalDeviceExceptionTypeVideoDeviceException=13]="AliEngineLocalDeviceExceptionTypeVideoDeviceException",i))(X||{}),K=(i=>(i[i.AliRtcConnectionStatusInit=0]="AliRtcConnectionStatusInit",i[i.AliRtcConnectionStatusDisconnected=1]="AliRtcConnectionStatusDisconnected",i[i.AliRtcConnectionStatusConnecting=2]="AliRtcConnectionStatusConnecting",i[i.AliRtcConnectionStatusConnected=3]="AliRtcConnectionStatusConnected",i[i.AliRtcConnectionStatusReconnecting=4]="AliRtcConnectionStatusReconnecting",i[i.AliRtcConnectionStatusFailed=5]="AliRtcConnectionStatusFailed",i))(K||{}),Ve=(i=>(i[i.AliRtcConnectionChangedDummyReason=0]="AliRtcConnectionChangedDummyReason",i[i.AliRtcConnectionMediaPathChanged=1]="AliRtcConnectionMediaPathChanged",i[i.AliRtcConnectionSignalingHeartbeatTimeout=2]="AliRtcConnectionSignalingHeartbeatTimeout",i[i.AliRtcConnectionSignalingHeartbeatAlive=3]="AliRtcConnectionSignalingHeartbeatAlive",i[i.AliRtcConnectionSignalingHttpDnsResolved=4]="AliRtcConnectionSignalingHttpDnsResolved",i[i.AliRtcConnectionSignalingHttpDnsFailure=5]="AliRtcConnectionSignalingHttpDnsFailure",i[i.AliRtcConnectionSignalingGslbFailure=6]="AliRtcConnectionSignalingGslbFailure",i[i.AliRtcConnectionSignalingGslbSuccess=7]="AliRtcConnectionSignalingGslbSuccess",i[i.AliRtcConnectionSignalingJoinRoomFailure=8]="AliRtcConnectionSignalingJoinRoomFailure",i[i.AliRtcConnectionSignalingJoinRoomSuccess=9]="AliRtcConnectionSignalingJoinRoomSuccess",i[i.AliRtcConnectionSignalingLeaveRoom=10]="AliRtcConnectionSignalingLeaveRoom",i[i.AliRtcConnectionSignalingConnecting=11]="AliRtcConnectionSignalingConnecting",i[i.AliRtcConnectionChangedNetworkInterrupted=12]="AliRtcConnectionChangedNetworkInterrupted",i))(Ve||{}),ii=(i=>(i[i.AliRtcUserOfflineQuit=0]="AliRtcUserOfflineQuit",i[i.AliRtcUserOfflineDropped=1]="AliRtcUserOfflineDropped",i[i.AliRtcUserOfflineBecomeAudience=2]="AliRtcUserOfflineBecomeAudience",i))(ii||{}),Ke=(i=>(i[i.AliRtcAudioTrackNo=0]="AliRtcAudioTrackNo",i[i.AliRtcAudioTrackMic=1]="AliRtcAudioTrackMic",i[i.AliRtcAudioTrackDual=2]="AliRtcAudioTrackDual",i))(Ke||{}),x=(i=>(i[i.AliRtcVideoTrackNo=0]="AliRtcVideoTrackNo",i[i.AliRtcVideoTrackCamera=1]="AliRtcVideoTrackCamera",i[i.AliRtcVideoTrackScreen=2]="AliRtcVideoTrackScreen",i[i.AliRtcVideoTrackBoth=3]="AliRtcVideoTrackBoth",i))(x||{}),V=(i=>(i[i.AliRtcStatePublishIdle=0]="AliRtcStatePublishIdle",i[i.AliRtcStateNoPublish=1]="AliRtcStateNoPublish",i[i.AliRtcStatePublishing=2]="AliRtcStatePublishing",i[i.AliRtcStatePublished=3]="AliRtcStatePublished",i))(V||{}),G=(i=>(i[i.AliRtcStateSubscribeIdle=0]="AliRtcStateSubscribeIdle",i[i.AliRtcStateNoSubscribe=1]="AliRtcStateNoSubscribe",i[i.AliRtcStateSubscribing=2]="AliRtcStateSubscribing",i[i.AliRtcStateSubscribed=3]="AliRtcStateSubscribed",i))(G||{}),oe=(i=>(i[i.AliRtcVideoStreamTypeNone=0]="AliRtcVideoStreamTypeNone",i[i.AliRtcVideoStreamTypeHigh=1]="AliRtcVideoStreamTypeHigh",i[i.AliRtcVideoStreamTypeLow=2]="AliRtcVideoStreamTypeLow",i))(oe||{}),Qe=(i=>(i[i.CAMERA_INVALID=-1]="CAMERA_INVALID",i[i.CAMERA_REAR=0]="CAMERA_REAR",i[i.CAMERA_FRONT=1]="CAMERA_FRONT",i))(Qe||{});const Hi=10,Wi=5e3,Dt=class Dt extends J{constructor(e){super();c(this,"ws");c(this,"socketStatus",0);c(this,"wsUrl","");c(this,"lastConnectStartTime",0);c(this,"maxConnectRetryCount",Hi);c(this,"connectRetryCount",0);c(this,"gotErr",!1);c(this,"closedByInvoke",!0);c(this,"isReconnecting",!1);c(this,"networkAvailableChecked",!0);this.maxConnectRetryCount=e!=null?e:Hi,this.onOpen=this.onOpen.bind(this),this.onMessage=this.onMessage.bind(this),this.onError=this.onError.bind(this),this.onClose=this.onClose.bind(this)}get connectUrl(){return this.wsUrl}get connectStatus(){return this.socketStatus}start(e){this.wsUrl=e,this.initWebSocket()}send(e){return this.ws&&this.socketStatus===2?(this.ws.send(JSON.stringify(e)),!0):!1}close(){this.closedByInvoke=!0,this.uninitWebscoket()}reconnect(){this.emit("onReconnectStart"),this.isReconnecting=!0,this.initWebSocket()}onOpen(e){this.socketStatus=2,this.connectRetryCount=0,this.networkAvailableChecked=!1,this.closedByInvoke=!1,this.gotErr=!1,this.isReconnecting=!1,this.emit("onOpen",e)}onMessage(e){this.emit("onMessage",e)}onError(e){this.isReconnecting&&this.emit("onReconnectFail",e),this.emit("onError",e),this.isReconnecting=!1,this.gotErr=!0}onClose(e){return S(this,null,function*(){const t=this.socketStatus;if(w.info(Dt.logName,`onClose, status: ${t}, retryCount: ${this.connectRetryCount}`),t!==0||this.connectRetryCount)if(yield ye.isNetworkAvailable()){if(!this.networkAvailableChecked&&!this.closedByInvoke&&!this.gotErr){this.reconnect();return}this.networkAvailableChecked=!0,this.emit("onAuthInvalid")}else{if(this.connectRetryCount||this.emit("onNetworkError"),this.closedByInvoke)return;this.connectRetryCount+=1,this.connectRetryCount>this.maxConnectRetryCount?this.emit("onConnectFail"):Date.now()-this.lastConnectStartTime>=Wi?this.reconnect():window.setTimeout(()=>{this.reconnect()},Wi)}this.socketStatus=0,this.emit("onClose",e)})}initWebSocket(){this.uninitWebscoket(),this.socketStatus=1,this.lastConnectStartTime=Date.now(),this.ws=new WebSocket(this.wsUrl),this.ws.addEventListener("open",this.onOpen),this.ws.addEventListener("message",this.onMessage),this.ws.addEventListener("error",this.onError),this.ws.addEventListener("close",this.onClose)}uninitWebscoket(){this.ws&&(this.ws.removeEventListener("open",this.onOpen),this.ws.removeEventListener("message",this.onMessage),this.ws.removeEventListener("error",this.onError),this.ws.removeEventListener("close",this.onClose),this.ws.close(),this.ws=void 0,this.socketStatus=0)}};c(Dt,"logName","Socket");let si=Dt;var ee=(i=>(i.KEEPALIVE="keepalive",i.JOINCHANNEL="joinchannel",i.NOTIFYJOIN="notifyjoin",i.NOTIFYSTATUS="notifystatus",i.STATUSREPORT="statusreport",i.LEAVECHANNEL="leavechannel",i.NOTIFYLEAVE="notifyleave",i.NOTIFYPUBLISH="notifypublish",i.BYE="bye",i.RECONNECT="reconnect",i.PUBLISH="publish",i.REFRESHURL="refreshurl",i.UNSUBSCRIBE="unsubscribe",i.ROLEUPDATE="roleupdate",i))(ee||{});class hr{constructor(s,e){c(this,"authInfo");c(this,"userName");c(this,"seqIndex",0);this.authInfo=s,this.userName=e}get roleAuth(){if(this.authInfo.role){const{timestamp:s,nonce:e,token:t,role:r}=this.authInfo;return{timestamp:s,nonce:e,token:t,tokenrole:r}}}refreshAuthInfo(s){this.authInfo=s}getSeqIndex(){return this.seqIndex}createKeepAlivePackage(){return this.createBaseSendPackage("keepalive")}createJoinPackage(){let s=this.createBaseSendPackage("joinchannel");return s.header.displayName=this.userName,s.header.clientversion=ye.getVersionNumber().toString(),s.header.platform=Bi,this.roleAuth&&(s.data.auth=this.roleAuth),s}crateLeavePackage(){return this.createBaseSendPackage("leavechannel")}createStatusPackage(s){let e=this.createBaseSendPackage("statusreport");return e.header.displayName=this.userName,e.data.status=s,e}createPublishPackage(){let s=this.createBaseSendPackage("publish");return s.data.users=[{}],this.roleAuth&&(s.data.auth=this.roleAuth),s}createRoleUpdatePackage(){let s=this.createBaseSendPackage("roleupdate");return s.header.displayName=this.userName,s}createReconnectPackage(s){let e=this.createBaseSendPackage("reconnect");return e.header.displayName=this.userName,e.header.clientversion=ye.getVersionNumber().toString(),e.header.platform=Bi,e.data=W(W({},e.data),s!=null?s:{}),this.roleAuth&&(e.data.auth=this.roleAuth),e}createRefreshUrlPackage(){let s=this.createBaseSendPackage("refreshurl");return s.header.displayName=this.userName,s}createResponsePackage(s,e){return{version:1,code:200,tid:s,msgtype:e}}createBaseSendPackage(s){var t;return++this.seqIndex,{version:1,msgtype:s,tid:N.Guid.create(32),header:{appid:this.authInfo.appId,channelid:this.authInfo.channelId,sessionid:(t=this.authInfo.callid)!=null?t:"",userid:this.authInfo.userId},data:{seq:this.seqIndex}}}}var T=(i=>(i[i.ERR_JOIN_ALREADY_JOINED=16843521]="ERR_JOIN_ALREADY_JOINED",i[i.ERR_JOIN_BAD_APPID=33620481]="ERR_JOIN_BAD_APPID",i[i.ERR_JOIN_INVALID_APPID=33620482]="ERR_JOIN_INVALID_APPID",i[i.ERR_JOIN_BAD_CHANNEL=33620484]="ERR_JOIN_BAD_CHANNEL",i[i.ERR_JOIN_INVALID_CHANNEL=33620483]="ERR_JOIN_INVALID_CHANNEL",i[i.ERR_JOIN_BAD_TOKEN=33620485]="ERR_JOIN_BAD_TOKEN",i[i.ERR_JOIN_TIMEOUT=16908804]="ERR_JOIN_TIMEOUT",i[i.ERR_JOIN_ERR_JOIN_BAD_PARAMBAD=16974081]="ERR_JOIN_ERR_JOIN_BAD_PARAMBAD",i[i.ERR_JOIN_CHANNEL_FAILED=16974338]="ERR_JOIN_CHANNEL_FAILED",i[i.ERR_LOG_ALREADY_INIT=16974085]="ERR_LOG_ALREADY_INIT",i[i.ERR_LOG_ROOT_PATH_ERROR=16974086]="ERR_LOG_ROOT_PATH_ERROR",i[i.ERR_MIC_OPEN_FAIL=17040388]="ERR_MIC_OPEN_FAIL",i[i.ERR_SPEAKER_OPEN_FAIL=17040389]="ERR_SPEAKER_OPEN_FAIL",i[i.ERR_MIC_INTERRUPT=17040390]="ERR_MIC_INTERRUPT",i[i.ERR_SPEAKER_INTERRUPT=17040391]="ERR_SPEAKER_INTERRUPT",i[i.ERR_MIC_AUTH_FAIL=17040392]="ERR_MIC_AUTH_FAIL",i[i.ERR_MIC_NOT_AVAILABLE=17040393]="ERR_MIC_NOT_AVAILABLE",i[i.ERR_SPEAKER_NO_AVAILABLE=17040400]="ERR_SPEAKER_NO_AVAILABLE",i[i.ERR_CAMERA_OPEN_FAIL=17039620]="ERR_CAMERA_OPEN_FAIL",i[i.ERR_CAMERA_INTERRUPT=17039622]="ERR_CAMERA_INTERRUPT",i[i.ERR_VIDEO_DISPLAY_OPEN_FAIL=17039873]="ERR_VIDEO_DISPLAY_OPEN_FAIL",i[i.ERR_VIDEO_DISPLAY_INTERRUPT=1064992]="ERR_VIDEO_DISPLAY_INTERRUPT",i[i.ERR_ICE_CONNECTION_CONNECT_FAIL=17105409]="ERR_ICE_CONNECTION_CONNECT_FAIL",i[i.ERR_ICE_CONNECTION_RECONNECT_FAI=17105410]="ERR_ICE_CONNECTION_RECONNECT_FAI",i[i.ERR_ICE_CONNECTION_MOBILITY_FAIL=17105411]="ERR_ICE_CONNECTION_MOBILITY_FAIL",i[i.ERR_ICE_CONNECTION_HEARTBEAT_TIMEOUT=16908812]="ERR_ICE_CONNECTION_HEARTBEAT_TIMEOUT",i[i.ERR_LATENCY_LIVE_COMMUNICATION_FAILED=17235971]="ERR_LATENCY_LIVE_COMMUNICATION_FAILED",i[i.ERR_LATENCY_LIVE_MEIDASETTING_FAILED=17235972]="ERR_LATENCY_LIVE_MEIDASETTING_FAILED",i[i.ERR_LATENCY_LIVE_NONE_BROADCASTER=17235973]="ERR_LATENCY_LIVE_NONE_BROADCASTER",i[i.ERR_LATENCY_LIVE_NEED_RESTART=17235974]="ERR_LATENCY_LIVE_NEED_RESTART",i[i.ERR_LATENCY_LIVE_NEED_RESTART_AGAIN_LATER=17235975]="ERR_LATENCY_LIVE_NEED_RESTART_AGAIN_LATER",i[i.ERR_LATENCY_LIVE_SERVICE_UNAVAILABLE=17235976]="ERR_LATENCY_LIVE_SERVICE_UNAVAILABLE",i[i.ERR_LATENCY_LIVE_MEDIACONNECTION_INTERRUPTION=17235977]="ERR_LATENCY_LIVE_MEDIACONNECTION_INTERRUPTION",i[i.ERR_SDK_PUBLISH_INVAILD=16974597]="ERR_SDK_PUBLISH_INVAILD",i[i.ERR_SDK_PUBLISH_NOT_JOIN_CHANNEL=16843782]="ERR_SDK_PUBLISH_NOT_JOIN_CHANNEL",i[i.ERR_SDK_PUBLISH_AUDIO_STRAM_FAILED=16843856]="ERR_SDK_PUBLISH_AUDIO_STRAM_FAILED",i[i.ERR_SDK_PUBLISH_VIDEO_STRAM_FAILED=16843857]="ERR_SDK_PUBLISH_VIDEO_STRAM_FAILED",i[i.ERR_SDK_PUBLISH_DUAL_STRAM_FAILED=16843858]="ERR_SDK_PUBLISH_DUAL_STRAM_FAILED",i[i.ERR_SDK_PUBLISH_SCEEN_SHARE_FAILED=16843859]="ERR_SDK_PUBLISH_SCEEN_SHARE_FAILED",i[i.ERR_SDK_PUBLISH_SCREEN_SHARE_CONFIG_ERROR=16843860]="ERR_SDK_PUBLISH_SCREEN_SHARE_CONFIG_ERROR",i[i.ERR_SDK_SUBSCRIBE_INVAILD=16974852]="ERR_SDK_SUBSCRIBE_INVAILD",i[i.ERR_SDK_SUBSCRIBE_NOT_JOIN_CHANNEL=16844112]="ERR_SDK_SUBSCRIBE_NOT_JOIN_CHANNEL",i[i.ERR_SDK_SUBSCRIBE_AUDIO_STRAM_FAILED=16844113]="ERR_SDK_SUBSCRIBE_AUDIO_STRAM_FAILED",i[i.ERR_SDK_SUBSCRIBE_VIDEO_STRAM_FAILED=16844114]="ERR_SDK_SUBSCRIBE_VIDEO_STRAM_FAILED",i[i.ERR_SDK_SUBSCRIBE_DUAL_STRAM_FAILED=16844115]="ERR_SDK_SUBSCRIBE_DUAL_STRAM_FAILED",i[i.ERR_SDK_SUBSCRIBE_SCREEN_SHARE_FAILED=16844116]="ERR_SDK_SUBSCRIBE_SCREEN_SHARE_FAILED",i[i.ERR_SDK_INVALID_STATE=16974340]="ERR_SDK_INVALID_STATE",i[i.ERR_INVALID_ARGUMENTS=16974083]="ERR_INVALID_ARGUMENTS",i[i.ERR_SESSION_REMOVED=33620229]="ERR_SESSION_REMOVED",i[i.ERR_SDK_UPDATE_ROLE_CHANNEL=16908801]="ERR_SDK_UPDATE_ROLE_CHANNEL",i[i.ERR_INNER=-1]="ERR_INNER",i[i.ERR_SDK_MPU_TASK_PUBLISH_OK=0]="ERR_SDK_MPU_TASK_PUBLISH_OK",i[i.ERR_SDK_MPU_TASK_STREAM_NOT_FOUND=17825793]="ERR_SDK_MPU_TASK_STREAM_NOT_FOUND",i[i.ERR_SDK_MPU_TASK_STREAM_ALREADY_EXIST=17825794]="ERR_SDK_MPU_TASK_STREAM_ALREADY_EXIST",i[i.ERR_SDK_MPU_TASK_INVALID_PARAM=17825795]="ERR_SDK_MPU_TASK_INVALID_PARAM",i[i.ERR_SDK_MPU_TASK_INTERNAL_ERROR=17825796]="ERR_SDK_MPU_TASK_INTERNAL_ERROR",i[i.ERR_SDK_MPU_TASK_RTMP_SERVER_ERROR=17825797]="ERR_SDK_MPU_TASK_RTMP_SERVER_ERROR",i[i.ERR_SDK_MPU_TASK_RTMP_STREAM_URL_ERROR=17825798]="ERR_SDK_MPU_TASK_RTMP_STREAM_URL_ERROR",i[i.ERR_SDK_MPU_TASK_PUBLISH_TIMEOUT=17825799]="ERR_SDK_MPU_TASK_PUBLISH_TIMEOUT",i[i.ERR_SDK_MPU_TASK_NOT_AUTHORIZED=17825800]="ERR_SDK_MPU_TASK_NOT_AUTHORIZED",i[i.ERR_SDK_CHANNEL_RELAY_STATE_ERROR=18874369]="ERR_SDK_CHANNEL_RELAY_STATE_ERROR",i[i.ERR_SDK_CHANNEL_RELAY_SRC_NOT_ALLOW=18874370]="ERR_SDK_CHANNEL_RELAY_SRC_NOT_ALLOW",i[i.ERR_SDK_CHANNEL_RELAY_JOIN_DEST_FAILED=18874371]="ERR_SDK_CHANNEL_RELAY_JOIN_DEST_FAILED",i[i.ERR_SDK_CHANNEL_RELAY_TOKEN_INVALID=18874372]="ERR_SDK_CHANNEL_RELAY_TOKEN_INVALID",i[i.ERR_SDK_CHANNEL_RELAY_ROLE_ERROR=18874373]="ERR_SDK_CHANNEL_RELAY_ROLE_ERROR",i[i.ERR_SDK_CHANNEL_RELAY_INVALID_PARAM=18874374]="ERR_SDK_CHANNEL_RELAY_INVALID_PARAM",i[i.ERR_SDK_CHANNEL_RELAY_TO_SELF_ERROR=18874375]="ERR_SDK_CHANNEL_RELAY_TO_SELF_ERROR",i))(T||{});class A extends Error{constructor(e,t,r){super(t);c(this,"_code");c(this,"_extra");this._code=e,this._extra=r}static fromError(e,t=-1,r=""){return new A(t,e.message||e.reason||r||"error",e.extraInfo)}get code(){return this._code}set code(e){this._code=e}get reason(){return this.message}get extra(){return this._extra}}const lr=3e4;class dr extends J{constructor(e,t,r,a,n){super();c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"wsClient");c(this,"packageCreater");c(this,"keepAliveTimer",0);c(this,"packageCache",new Map);c(this,"isFirstConnect",!0);c(this,"aliveChecker",0);c(this,"reconnectData");this.authInfo=e,this.userName=t,this.packageCreater=new hr(e,t),this.channelProfile=r,this.clientRole=a,this.wsClient=new si(n),this.wsClient.on("onOpen",this.onOpen.bind(this)),this.wsClient.on("onMessage",this.onMessage.bind(this)),this.wsClient.on("onError",this.onError.bind(this)),this.wsClient.on("onClose",this.onClose.bind(this)),this.wsClient.on("onConnectFail",this.onConnectFail.bind(this)),this.wsClient.on("onAuthInvalid",this.onAuthInvalid.bind(this)),this.wsClient.on("onNetworkError",this.onNetworkError.bind(this)),this.wsClient.on("onReconnectStart",this.onReconnectStart.bind(this)),this.wsClient.on("onReconnectFail",this.onReconnectFail.bind(this))}start(e){this.wsClient.start(e)}startKeepAlive(){this.keepAliveTimer===0&&(this.keepAliveTimer=window.setInterval(()=>{let e=this.packageCreater.createKeepAlivePackage();this.sendPackage(e)},5e3)),this.checkAlive()}stopKeepAlive(){this.keepAliveTimer!==0&&(clearInterval(this.keepAliveTimer),this.keepAliveTimer=0),this.aliveChecker&&(window.clearTimeout(this.aliveChecker),this.aliveChecker=0)}sendPkgCache(){this.packageCache.forEach(e=>{this.wsClient.send(e)})}leave(){let e=this.packageCreater.crateLeavePackage();this.sendPackage(e)}reportStatus(e){let t=this.packageCreater.createStatusPackage(e);this.sendPackage(t)}publish(e){let t=this.packageCreater.createPublishPackage();t.data.users=[],e.subscribe.signal=this.wsClient.connectUrl;const{tracks:r,resume:a}=e;r.forEach(n=>{const{codec:o,ssrc:u}=n;n.userdata=JSON.stringify({codec:o}),n.ssrc=`${u}`,a&&(n.attr={reason:"reconnect"})}),t.data.users.push(e),this.sendPackage(t)}roleUpdate(e){let t=this.packageCreater.createRoleUpdatePackage();t.data.clientrole=e,this.sendPackage(t)}refreshUrl(e){const t=this.packageCreater.createRefreshUrlPackage();t.data=W(qe(W({},t.data),{sessionid:t.header.sessionid}),e),this.sendPackage(t)}refreshAuthInfo(e){this.authInfo=e,this.packageCreater.refreshAuthInfo(e)}close(){w.info("[roomsigcenter] close"),this.stopKeepAlive(),this.wsClient.off("onOpen",this.onOpen.bind(this)),this.wsClient.off("onMessage",this.onMessage.bind(this)),this.wsClient.off("onError",this.onError.bind(this)),this.wsClient.off("onClose",this.onClose.bind(this)),this.wsClient.off("onConnectFail",this.onConnectFail.bind(this)),this.wsClient.off("onAuthInvalid",this.onAuthInvalid.bind(this)),this.wsClient.off("onReconnectStart"),this.wsClient.off("onReconnectFail"),this.wsClient.close()}sendPackage(e){[ee.KEEPALIVE,ee.RECONNECT,ee.JOINCHANNEL].includes(e.msgtype)||this.packageCache.set(e.tid,e),this.wsClient.send(e)}updateReconnectData(e){this.reconnectData=e}onOpen(){if(w.info("[roomsigcenter] onOpen"),this.isFirstConnect){let e=this.packageCreater.createJoinPackage();e.data.configure={channelprofile:this.channelProfile},(this.channelProfile===Te.AliRtcSdkInteractiveLive||this.channelProfile===Te.AliRtcSdkInteractiveWithLowLatencyLive)&&(e.data.configure.clientrole=this.clientRole),this.sendPackage(e)}else{this.stopKeepAlive();const e=this.packageCreater.createReconnectPackage(this.reconnectData);this.sendPackage(e)}}onMessage(e){try{let t=JSON.parse(e.data);this.packageCache.delete(t.tid),this.onRecvMessage(t)}catch(t){w.error("[roomsigcenter] onMessage err",t,e)}}onError(e){w.error("[roomsigcenter] onError",e),this.isFirstConnect&&this.onConnectFail()}onConnectFail(){w.error("[roomsigcenter] onConnectFail");const e=new A(T.ERR_INNER,"Signaling connect failed.");this.isFirstConnect?this.emit("onJoinChannelResult",e):this.emit("onConnectFail",e)}onAuthInvalid(){w.error("[roomsigcenter] onAuthInvalid"),this.isFirstConnect&&this.emit("onAuthInvalid")}onNetworkError(){w.error("[roomsigcenter] onNetworkError");const e=new A(T.ERR_INNER,"Network error, signaling connect failed.");this.emit("onNetworkError",e)}onClose(e){w.info("[roomsigcenter] onClose",e),this.stopKeepAlive()}onKeepAliveRsp(){this.emit("onKeepAliveRsp"),this.checkAlive()}onReconnectStart(){this.emit("onReconnectStart")}onReconnectFail(){this.emit("onReconnectFail",new A(T.ERR_INNER,"signaling reconnect failed."))}checkAlive(){window.clearTimeout(this.aliveChecker),this.aliveChecker=window.setTimeout(()=>{w.info("[roomsigcenter] not alive, reconnect"),this.stopKeepAlive(),this.emit("onReconnectStart"),this.wsClient.reconnect()},lr)}onRecvMessage(e){switch(e.msgtype!==ee.KEEPALIVE&&w.info("[roomsigcenter] recv msg "+e.msgtype),e.msgtype){case ee.JOINCHANNEL:this.onJoinResult(e);break;case ee.KEEPALIVE:this.onKeepAliveRsp();break;case ee.PUBLISH:this.onPublishResult(e);break;case ee.NOTIFYJOIN:this.onNotifyJoin(e);break;case ee.NOTIFYSTATUS:this.onNotifyStatus(e);break;case ee.LEAVECHANNEL:this.onLeaveResult(e);break;case ee.NOTIFYLEAVE:this.onNotifyLeave(e);break;case ee.NOTIFYPUBLISH:this.onNotifyPublish(e);break;case ee.STATUSREPORT:this.onStatusReport(e);break;case ee.BYE:this.onBye(e);break;case ee.ROLEUPDATE:this.onRoleUpdateResult(e);break;case ee.REFRESHURL:this.onRefreshUrlResult(e);break;case ee.RECONNECT:this.onReconnectResult(e);break}}onJoinResult(e){this.isFirstConnect=!1,this.emit("onJoinChannelResult",e)}onLeaveResult(e){this.emit("onLeaveResult",e.code,e.tid)}onPublishResult(e){this.emit("onPublishResult",e.code,e.tid,e.description)}onRoleUpdateResult(e){this.emit("onRoleUpdateResult",e.code,e.tid,e.description)}onRefreshUrlResult(e){this.emit("onRefreshUrlResult",e)}onReconnectResult(e){if(e.code===200)this.sendPkgCache(),this.startKeepAlive(),this.emit("onReconnectSuccess",e.data.users);else{const t=new A(T.ERR_INNER,`reconnect failed, code: ${e.code};description: ${e.description}`);e.code===403&&(t.code=403),this.emit("onReconnectFail",t),this.close()}}onNotifyJoin(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e&&e.data&&e.data.users&&this.emit("onNotifyJoin",e.data.users)}onNotifyStatus(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e.data&&e.data.status&&e.data.status.length&&this.emit("onNotifyStatus",e.data.status)}onNotifyLeave(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e.data&&e.data.users&&e.data.users.length&&this.emit("onNotifyLeave",e.data.users)}onNotifyPublish(e){let t=this.packageCreater.createResponsePackage(e.tid,e.msgtype);this.wsClient.send(t),e.data&&e.data.users&&e.data.users.length&&this.emit("onNotifyPublish",e.data.users)}onStatusReport(e){this.emit("onStatusReport",e.code,e.tid,e.description)}onBye(e){this.stopKeepAlive(),this.emit("onBye",e.reason,e.description)}}const b=(i,s)=>(e,t,r)=>{const a=r.value;return r.value=function(...n){var p;const o=`[${((p=e.constructor)==null?void 0:p.logName)||""}]`,u=Date.now();let h=[];i&&(h=i(n)),w.interface(o,t,...h);const l=a.apply(this,n);return Promise.resolve(l).then(d=>d).catch(d=>d).then(d=>{let m="";const g=d instanceof Error;!s&&!g||(g?m=d:s&&(d===void 0?m="":m=s(d)),w.interfaceResult(o,t,!g,`${Date.now()-u}ms`,m))}),l},r},I=i=>i;var pr=Object.defineProperty,mr=Object.getOwnPropertyDescriptor,ri=(i,s,e,t)=>{for(var r=t>1?void 0:t?mr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&pr(s,e,r),r};const vt=(he=class extends J{constructor(e,t,r=Pe.prod){super();c(this,"messageCenter");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"reconnectData");c(this,"roomServerUri","");this.channelProfile=e,this.clientRole=t,this.reconnectData={role:{channelprofile:e,clientrole:t}};const a=r===Pe.pre?mt.pre:mt.prod;this.roomServerUri=`wss://${a}/roomserver/v1/ws`}updateReconnectData(e){var t;this.reconnectData=e,(t=this.messageCenter)==null||t.updateReconnectData(this.reconnectData)}reset(){w.info("[roomsig] reset"),this.messageCenter&&(this.messageCenter.close(),this.messageCenter=void 0),this.authInfo=void 0}join(e,t,r){return S(this,null,function*(){return new Promise((a,n)=>{w.setTraceID(e.channelId+"-"+e.callid),this.authInfo=e,this.userName=t,this.messageCenter=new dr(e,t,this.channelProfile,this.clientRole,r),this.initMessageCenter(),this.messageCenter.once("onJoinChannelResult",u=>{var h,l;if(w.info("join result: ",u),u.code==200){(h=this.messageCenter)==null||h.sendPkgCache(),(l=this.messageCenter)==null||l.startKeepAlive();let p=u.data;p.tid=u.tid,p.users=u.data.users,p.timestamp=u.timestamp,a(p)}else this.reset(),n(this.handleSignalError(u.code,u.reason,T.ERR_JOIN_CHANNEL_FAILED))}),this.messageCenter.once("onAuthInvalid",()=>{this.reset(),n(new A(T.ERR_JOIN_BAD_TOKEN,"join failed because authentication failed"))}),w.info(`[${he.logName}]`,"start ws connecting roomserver and auto join when connected");const o={appid:this.authInfo.appId,callid:this.authInfo.callid,channelid:this.authInfo.channelId,userid:this.authInfo.userId,nonce:this.authInfo.nonce||"",timestamp:this.authInfo.timestamp,token:this.authInfo.token,authtype:"app",tid:N.Guid.create(32)};e.role&&(o.tokenrole=e.role),this.messageCenter.start(this.roomServerUri+"?"+ye.queryingParam(o))})})}leave(){return w.info("[roomsig] leave .."),new Promise((e,t)=>{this.messageCenter?(this.messageCenter.on("onLeaveResult",(r,a)=>{w.info(`[${he.logName}]`,"recv leave response "+r),r===200?(this.updateReconnectData(),this.reset(),e({tid:a})):t(this.handleSignalError(r,"leave error"))}),w.info(`[${he.logName}]`,"send leave request"),this.messageCenter.leave()):(w.info(`[${he.logName}]`,"no message center, ok to leave"),e({tid:""}))})}publish(e){return new Promise((t,r)=>{var a;this.messageCenter?(this.messageCenter.once("onPublishResult",(n,o,u)=>{w.info(`[${he.logName}]`,"recv pubish response "+n),n===200?(this.updateReconnectData(qe(W({},this.reconnectData),{publish:{users:[e]}})),t({tid:o})):r(this.handleSignalError(n,`publish error, ${u}`))}),this.authInfo&&(e.sessionid=(a=this.authInfo.callid)!=null?a:""),e.callid=N.Guid.create(32),w.info(`[${he.logName}]`,"assign callid "+e.callid+" and send publish request"),this.messageCenter.publish(e)):r(this.handleSignalError(-1,"publish error, no message center"))})}roleUpdate(e){return new Promise((t,r)=>{if(!this.messageCenter){r(this.handleSignalError(-1,"role update error, no message center"));return}this.messageCenter.on("onRoleUpdateResult",(a,n,o)=>{var u,h;w.info(`[${he.logName}]`,"recv role update response "+a),a===200?((h=(u=this.reconnectData)==null?void 0:u.role)!=null&&h.clientrole&&(this.reconnectData.role.clientrole=e,this.updateReconnectData(this.reconnectData)),t({tid:n})):r(this.handleSignalError(a,`role update error, ${o}`))}),this.messageCenter.roleUpdate(e)})}setChannelProfile(e){this.channelProfile=e}refreshUrl(e){return w.info(`[${he.logName}]`,"refreshUrl .."),new Promise((t,r)=>{if(!this.messageCenter){r(this.handleSignalError(-1,"refresh url error, no message center"));return}this.messageCenter.on("onRefreshUrlResult",a=>{const{code:n,description:o,data:u={}}=a||{};w.info("recv refresh url response "+n),n===200?t(u):r(this.handleSignalError(n,`refresh url error, ${o}`))}),w.info("send refresh url request"),this.messageCenter.refreshUrl(e)})}reportStatus(e){return w.info(`[${he.logName}]`,"reportStatus "+e),new Promise((t,r)=>{this.messageCenter?(this.messageCenter.once("onStatusReport",(a,n)=>{a===200?t():r(new A(a,n))}),this.messageCenter.reportStatus(e)):r(new A(-1,"No messageCenter"))})}handleSignalError(e,t,r=T.ERR_INNER){const a=`signal error: code - ${e}; description - ${t}`;return new A(r,a)}refreshAuthInfo(e){return S(this,null,function*(){var t;this.authInfo&&(this.authInfo=e,(t=this.messageCenter)==null||t.refreshAuthInfo(this.authInfo))})}initMessageCenter(){var e,t,r,a,n,o,u,h,l,p,d,m;(e=this.messageCenter)==null||e.on("onKeepAliveRsp",()=>{this.emit("onKeepAliveRsp")}),(t=this.messageCenter)==null||t.on("onNotifyJoin",g=>{this.emit("onNotifyJoin",g)}),(r=this.messageCenter)==null||r.on("onNotifyStatus",g=>{this.emit("onNotifyStatus",g)}),(a=this.messageCenter)==null||a.on("onNotifyLeave",g=>{this.emit("onNotifyLeave",g)}),(n=this.messageCenter)==null||n.on("onNotifyPublish",g=>{this.emit("onNotifyPublish",g)}),(o=this.messageCenter)==null||o.on("onBye",(g,f)=>{this.emit("onBye",g,f)}),(u=this.messageCenter)==null||u.on("onReconnectStart",()=>{this.emit("onReconnectStart")}),(h=this.messageCenter)==null||h.on("onReconnectSuccess",g=>{this.emit("onReconnectSuccess",g)}),(l=this.messageCenter)==null||l.on("onReconnectFail",g=>{this.emit("onReconnectFail",g)}),(p=this.messageCenter)==null||p.on("onConnectFail",g=>{this.emit("onConnectFail",g),this.reset()}),(d=this.messageCenter)==null||d.on("onNetworkError",g=>{this.emit("onNetworkError",g)}),(m=this.messageCenter)==null||m.on("onAuthInvalid",()=>{this.emit("onAuthInvalid")})}},c(he,"logName","RoomServerSignaling"),he);ri([b()],vt.prototype,"join",1),ri([b()],vt.prototype,"publish",1),ri([b()],vt.prototype,"roleUpdate",1);let gr=vt;class Sr extends J{constructor(e,t,r=Pe.prod){super();c(this,"signaling");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"env",Pe.prod);c(this,"maxConnectRetryCount");this.channelProfile=e,this.clientRole=t,this.env=r}reset(){var e;w.info("[signalingmanager] reset"),(e=this.signaling)==null||e.reset(),this.signaling=void 0,this.authInfo=void 0}join(e,t=e.userId,r){return this.maxConnectRetryCount=r,this.userName=t,new Promise((a,n)=>{this.signaling?n(new A(T.ERR_JOIN_ALREADY_JOINED,"already joined")):(w.info("[signalingmanager] create signaling"),this.signaling=new gr(this.channelProfile,this.clientRole,this.env),this.initSignaling(),this.signaling.join(e,t,r).then(o=>{this.authInfo=e,a(o)}).catch(o=>{this.reset(),n(o)}))})}retryJoin(){const e=this.authInfo;this.reset(),e&&this.join(e,this.userName,this.maxConnectRetryCount)}leave(){return new Promise((e,t)=>{this.signaling?this.signaling.leave().then(r=>{this.reset(),e(r)}).catch(r=>{t(r)}):e({tid:""})})}publish(e){return new Promise((t,r)=>{var a;this.signaling&&this.authInfo?(e.userid=this.authInfo.userId,e.displayname=(a=this.userName)!=null?a:this.authInfo.userId,this.signaling.publish(e).then(n=>{t(n)}).catch(n=>{r(n)})):r(new A(T.ERR_SDK_PUBLISH_NOT_JOIN_CHANNEL,"no signaling"))})}reportStatus(e){return new Promise((t,r)=>{this.signaling?this.signaling.reportStatus(e).then(()=>{t()}).catch(a=>{r(a)}):r(new A(-1,"no signaling"))})}setClientRole(e){return S(this,null,function*(){if(!this.signaling){this.clientRole=e;return}return yield this.signaling.roleUpdate(e)})}setChannelProfile(e){this.signaling?this.signaling.setChannelProfile(e):this.channelProfile=e}refreshUrl(e){return this.signaling?this.signaling.refreshUrl(e):Promise.reject(new A(T.ERR_SDK_INVALID_STATE,"should join first"))}refreshAuthInfo(e){return S(this,null,function*(){var t;try{this.authInfo&&(this.authInfo=W(W({},this.authInfo),e),(t=this.signaling)==null||t.refreshAuthInfo(this.authInfo))}catch(r){throw r}})}initSignaling(){var e,t,r,a,n,o,u,h,l,p,d,m,g;(e=this.signaling)==null||e.on("onKeepAliveRsp",this.onKeepAliveRsp.bind(this)),(t=this.signaling)==null||t.on("onNotifyJoin",this.onNotifyJoin.bind(this)),(r=this.signaling)==null||r.on("onNotifyStatus",this.onNotifyStatus.bind(this)),(a=this.signaling)==null||a.on("onNotifyLeave",this.onNotifyLeave.bind(this)),(n=this.signaling)==null||n.on("onNotifyPublish",this.onNotifyPublish.bind(this)),(o=this.signaling)==null||o.on("onBye",this.onBye.bind(this)),(u=this.signaling)==null||u.on("onReconnectStart",this.onReconnectStart.bind(this)),(h=this.signaling)==null||h.on("onReconnectSuccess",this.onReconnectSuccess.bind(this)),(l=this.signaling)==null||l.on("onReconnectFail",this.onReconnectFail.bind(this)),(p=this.signaling)==null||p.on("onConnectFail",this.onConnectFail.bind(this)),(d=this.signaling)==null||d.on("onNetworkError",this.onNetworkError.bind(this)),(m=this.signaling)==null||m.on("onAuthInvalid",this.onAuthInvalid.bind(this)),(g=this.signaling)==null||g.on("onError",this.onError.bind(this))}onKeepAliveRsp(){this.emit("onKeepAliveRsp")}onNotifyJoin(e){this.emit("onNotifyJoin",e)}onNotifyStatus(e){this.emit("onNotifyStatus",e)}onNotifyLeave(e){this.emit("onNotifyLeave",e)}onNotifyPublish(e){this.emit("onNotifyPublish",e)}onBye(e,t){this.emit("onBye",e,t)}onConnectFail(e){this.reset(),this.emit("onConnectFail",e)}onNetworkError(e){this.emit("onNetworkError",e)}onAuthInvalid(e){}onReconnectStart(){this.emit("onReconnectStart")}onReconnectSuccess(e){this.emit("onReconnectSuccess",e)}onReconnectFail(e){this.emit("onReconnectFail",e)}onError(e){this.emit("onError",e)}}const Fe=class Fe{static getInstance(){return Fe.instance||(Fe.instance=new AudioContext),Fe.instance.resume(),Fe.instance}};c(Fe,"instance");let ai=Fe;function fr(i,s,e,t,r){let a=t,n=0,o;const u=i.createAnalyser();u.fftSize=256;const h=new Uint8Array(u.frequencyBinCount);s.connect(u),u.connect(e);const l=()=>{o&&window.clearInterval(o)},p=()=>{o=window.setInterval(()=>{u.getByteFrequencyData(h);let d=Math.round(h.reduce((m,g)=>m+g)/h.length);d=Math.min(100,d),n=d,r&&r(d)},a)};return p(),{updateInterval:d=>{l(),a=d,p()},getLevel:()=>n,dispose:()=>{l(),s.disconnect(),u.disconnect()}}}class br extends J{constructor(){super();c(this,"audioContext");c(this,"stream");c(this,"sourceNode");c(this,"analyser");this.audioContext=ai.getInstance(),this.stream=new MediaStream}getLevel(){return this.analyser?this.analyser.getLevel():0}start(e,t=1e3){this.sourceNode&&this.stop(),this.stream.addTrack(e),this.sourceNode=this.audioContext.createMediaStreamSource(this.stream);const r=this.audioContext.createMediaStreamDestination();this.analyser=fr(this.audioContext,this.sourceNode,r,t,a=>{this.emit("audioLevel",a)})}stop(){this.analyser&&this.analyser.dispose(),this.analyser=void 0,this.sourceNode=void 0,this.stream.getAudioTracks().forEach(e=>{this.stream.removeTrack(e)})}dispose(){this.stop()}}class Ki extends J{constructor(e,t,r,a){super();c(this,"uid");c(this,"name");c(this,"rtsManager");c(this,"callid","");c(this,"audioLevelMonitor");c(this,"audioVolumeIndicationInterval",0);this.uid=e,this.name=t,this.rtsManager=r,this.audioVolumeIndicationInterval=a,this.audioLevelMonitor=new br}get userId(){return this.uid}get displayname(){return this.name}setUserInfo(e,t){this.uid=e,this.name=t}refreshUserInfo(e){this.uid=e}getAudioLevel(){return this.audioLevelMonitor.getLevel()}enableAudioVolumeIndication(e){this.audioVolumeIndicationInterval=e}clear(){this.audioLevelMonitor.dispose()}}class ji{static getCurrentStatus(s){let e=0;s.micOpen&&(e+=1),s.micInterrupted&&(e+=2),s.cameraOpen&&(e+=4),s.screenShare&&(e+=128),s.audioDisable&&(e+=8),s.videoDisable&&(e+=16),s.screenDisable&&(e+=256);let t=e.toString(16);for(;t.length<16;)t="0"+t;return t}static parseStatus(s){let e=parseInt(s,16);return{micOpen:!!(e&1),micInterrupted:!!(e&2),cameraOpen:!!(e&4),screenShare:!!(e&128),audioDisable:!!(e&8),videoDisable:!!(e&16),screenDisable:!!(e&256),backgroundMode:!!(e&32),accompanyPlaying:!!(e&64)}}}const $i="customVideoProfile",Ji="customScreenProfile",et={width:1280,height:720,frameRate:30,maxBitrate:2e3},tt={width:1920,height:1080,frameRate:30,maxBitrate:2600},vr={1e4:X.AliEngineLocalDeviceExceptionTypeUnknown,2e4:X.AliEngineLocalDeviceExceptionTypeUnknown,10001:X.AliEngineLocalDeviceExceptionTypeMicNotAvailable,10002:X.AliEngineLocalDeviceExceptionTypeMicAuthFail,10003:X.AliEngineLocalDeviceExceptionTypeMicOpenFail,10005:X.AliEngineLocalDeviceExceptionTypeCameraAuthFail,10004:X.AliEngineLocalDeviceExceptionTypeVideoDeviceException,10006:X.AliEngineLocalDeviceExceptionTypeCameraOpenFail,10010:X.AliEngineLocalDeviceExceptionTypeDisplayException,10011:X.AliEngineLocalDeviceExceptionTypeDisplayException,10012:X.AliEngineLocalDeviceExceptionTypeDisplayException,10013:X.AliEngineLocalDeviceExceptionTypeDisplayException,10014:X.AliEngineLocalDeviceExceptionTypeDisplayException,10019:X.AliEngineLocalDeviceExceptionTypeDisplayException},_r=i=>i.getAudioTracks()[0];function qi(i){var s;if(((s=i==null?void 0:i.nodeName)==null?void 0:s.toLowerCase())==="video")return i.setAttribute("playsinline",""),i;if(typeof i=="string"){let e=document.getElementById(i);if(e){if(e.nodeName.toLocaleLowerCase()==="video")return e.setAttribute("playsinline",""),e;throw new A(T.ERR_INVALID_ARGUMENTS,"element should be HtmlVideoElement")}else throw new A(T.ERR_INVALID_ARGUMENTS,"element not founded")}else throw new A(T.ERR_INVALID_ARGUMENTS,"element id should be string")}function ni(i){var e;const s=[];if(Array.isArray(i))i.forEach(t=>{try{s.push(qi(t))}catch(r){}});else if(typeof i=="string"||((e=i==null?void 0:i.nodeName)==null?void 0:e.toLowerCase())==="video")try{s.push(qi(i))}catch(t){}return s}function Oe(i){return new Promise(s=>setTimeout(s,i))}const Gi=(i,s)=>{const e=()=>(i.muted=!0,Promise.race([Oe(500),i._playPromise||Promise.resolve()]).catch(()=>{}).then(()=>{let t;return i.srcObject!==s?(i.load(),i.srcObject=s,t=i.play(),i._playPromise=t):t=Promise.resolve(),t}));return new Promise(t=>{if(N.BrowserUtil.isMicroMessenger){const r=window.top!==window.self,a=window.WeixinJSBridge||window.top.WeixinJSBridge;a?a.invoke("getNetworkType",{},()=>{t(e())}):(r?window.top.document:document).addEventListener("WeixinJSBridgeReady",()=>{a.invoke("getNetworkType",{},()=>{t(e())})}),setTimeout(()=>{t(e())},1e3)}else t(e())})},ke=i=>{Promise.race([Oe(100),i._playPromise||Promise.resolve()]).catch(()=>{}).then(()=>{i.srcObject=null,i._playPromise=void 0})};var Rr=Object.defineProperty,wr=Object.getOwnPropertyDescriptor,Z=(i,s,e,t)=>{for(var r=t>1?void 0:t?wr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Rr(s,e,r),r};class _t extends J{constructor(){super();c(this,"state");c(this,"time");this.state=V.AliRtcStatePublishIdle,this.time=Date.now()}setState(e){const t=this.state,r=this.time;this.state=e,this.time=Date.now(),this.emit("change",t,e,Math.floor((this.time-r)/1e3))}}const Ut=class Ut extends Ki{constructor(e){const{rtsManager:t,localStreamManager:r,reporter:a,webTrackingClient:n,signalingManager:o,audioVolumeIndicationInterval:u}=e;super("","",t,u);c(this,"url","");c(this,"_isPublishing",!1);c(this,"publishPromise",Promise.resolve(""));c(this,"previewElements",[]);c(this,"screenPreviewElements",[]);c(this,"streamManager");c(this,"streamTracks");c(this,"publishId",N.Guid.create(16));c(this,"signalingManager");c(this,"traceId","");c(this,"moduleName","LocalUser");c(this,"monitorTimerId");c(this,"reporter");c(this,"webTrackingClient");c(this,"audioPubState");c(this,"videoPubState");c(this,"videoSmallPubState");c(this,"screenPubState");c(this,"onTrackEnd",e=>{this.emit(e)});this.streamManager=r,this.signalingManager=o,this.reporter=a,this.webTrackingClient=n,this.streamManager.on("trackended",h=>{this.onTrackEnd(h)}),this.streamManager.on("publishupdate",()=>{this.publishUpdate()}),this.audioPubState=new _t,this.audioPubState.on("change",(h,l,p)=>{this.emit("audioPublishStateChanged",h,l,p)}),this.videoPubState=new _t,this.videoPubState.on("change",(h,l,p)=>{this.emit("videoPublishStateChanged",h,l,p)}),this.videoSmallPubState=new _t,this.videoSmallPubState.on("change",(h,l,p)=>{this.emit("dualStreamPublishStateChanged",h,l,p)}),this.screenPubState=new _t,this.screenPubState.on("change",(h,l,p)=>{this.emit("screenPublishStateChanged",h,l,p)})}get joined(){return!!this.uid}get isPublishing(){return this._isPublishing}get publishStreams(){return this.streamManager.publishStreams}get cameraTrack(){return this.streamManager.cameraStreamInfo.originVideoTrack}get screenTrack(){return this.streamManager.screenStreamInfo.originVideoTrack}get audioTrack(){return this.streamManager.cameraStreamInfo.originAudioTrack}get hasCamera(){return!!this.streamManager.cameraStreamInfo.originVideoTrack}get hasMicrophone(){return!!this.streamManager.cameraStreamInfo.originAudioTrack}get hasScreenShare(){return!!this.streamManager.screenStreamInfo.originVideoTrack}get hasCameraTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===R.VideoLarge))}get hasCameraDualTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===R.VideoSmall))}get hasScreenTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===R.Screen))}get hasAudioTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="audio"&&t&&a===R.Audio))}get cameraDirection(){var e,t;return(t=(e=this.streamManager.cameraStreamInfo)==null?void 0:e.cameraVideoConstraints)==null?void 0:t.facingMode}get audioCaptureDisabled(){return this.streamManager.audioCaptureDisabled}get cameraCaptureDisabled(){return this.streamManager.cameraCaptureDisabled}get publishLocalVideoStreamEnabled(){return this.streamManager.publishLocalVideoStreamEnabled}get publishLocalAudioStreamEnabled(){return this.streamManager.publishLocalAudioStreamEnabled}get publishLocalScreenStreamEnabled(){return this.streamManager.publishLocalScreenStreamEnabled}setPublishLocalAudioStreamEnabled(e){this.streamManager.publishLocalAudioStreamEnabled=e}setPublishLocalVideoStreamEnabled(e){this.streamManager.publishLocalVideoStreamEnabled=e}setPublishLocalScreenStreamEnabled(e){this.streamManager.publishLocalScreenStreamEnabled=e}initInfo(e,t){var r;this.setUserInfo(e.userId,e.userId),this.url=t,this.callid=(r=e.callid)!=null?r:"",this.updatePubId()}setVideoProfile(e,t){return S(this,null,function*(){yield this.streamManager.setVideoProfile(e,t)})}setVideoContentHint(e){this.streamManager.setVideoContentHint(e)}setScreenContentHint(e){this.streamManager.setScreenContentHint(e)}setAudioProfile(e){return S(this,null,function*(){yield this.streamManager.setAudioProfile(e)})}setScreenProfile(e,t){return S(this,null,function*(){yield this.streamManager.setScreenProfile(e,t)})}setCameraDirection(e){if(e===Qe.CAMERA_FRONT)this.streamManager.setCameraVideoConstraints({facingMode:"user"});else if(e===Qe.CAMERA_REAR)this.streamManager.setCameraVideoConstraints({facingMode:"environment"});else throw new A(T.ERR_CAMERA_OPEN_FAIL,`camera direction set to ${e} failed`)}setCameraDeviceId(e){this.streamManager.setCameraVideoConstraints({deviceId:e})}muteLocalCamera(e){this.streamManager.setCameraMuted(e)}muteLocalMic(e){this.streamManager.setAudioMuted(e)}muteLocalScreen(e){this.streamManager.setScreenMuted(e)}setMicrophoneDeviceId(e){this.streamManager.setMicAudioConstraints({deviceId:e})}updatePubId(){this.publishId=N.Guid.create(16)}clearPublishState(){this.streamTracks=void 0}clear(){return S(this,null,function*(){xi(Ut.prototype,this,"clear").call(this),this._isPublishing&&(yield this.unPublish()),this.stopPreview(),this.resetPreviewElements(),this.resetSecondayPreviewElements(),this.clearStream(),this.stopStreamMonitor(),this.streamManager.cameraCaptureDisabled=!1})}resetElement(e){this.previewElements.includes(e)&&(ke(e),this.previewElements.splice(this.previewElements.indexOf(e),1)),this.screenPreviewElements.includes(e)&&(ke(e),this.screenPreviewElements.splice(this.screenPreviewElements.indexOf(e),1))}setPreviewElement(e){const{videoElement:t,screen:r}=e;r?this.screenPreviewElements.includes(t)||this.screenPreviewElements.push(t):this.previewElements.includes(t)||this.previewElements.push(t)}setViewConfig(e,t){if(!e){t===x.AliRtcVideoTrackCamera?this.stopPreview({primary:!0,screen:!1}):this.stopPreview({primary:!1,screen:!0});return}if(![x.AliRtcVideoTrackCamera,x.AliRtcVideoTrackScreen].includes(t))throw new A(T.ERR_INVALID_ARGUMENTS,"set view config invalid track",{track:t});e.forEach(r=>{this.setPreviewElement({videoElement:r,screen:t===x.AliRtcVideoTrackScreen})})}startCameraCapture(e){return S(this,null,function*(){return this.streamManager.cameraCaptureDisabled=!1,yield this.createLocalStream(e)})}stopCameraCapture(){return S(this,null,function*(){this.streamManager.cameraCaptureDisabled=!0,yield this.stopLocalStream({video:!0})})}stopAudioCapture(){return S(this,null,function*(){this.streamManager.audioCaptureDisabled=!0,yield this.stopLocalStream({audio:!0})})}preview(e){return S(this,null,function*(){const t="preview",{videoElement:r,screen:a}=e!=null?e:{};try{let n=a?this.streamManager.screenStreamInfo.previewStream:this.streamManager.cameraStreamInfo.previewStream;if(!r)throw new A(T.ERR_INVALID_ARGUMENTS,"no video element found",{videoElement:r});return n?(w.info(`[${this.moduleName}/${t}]`,{screen:a,stream:n,videoElement:r}),Gi(r,n.mediaStream),this.setPreviewElement(e),n.mediaStream):void 0}catch(n){const o=T.ERR_INNER;throw A.fromError(n,o,"preview failed")}})}previewAll(e){return S(this,null,function*(){const{primary:t=!0,screen:r=!0}=e!=null?e:{};if(t&&this.previewElements.length)for(let a=0;a<this.previewElements.length;a++){const n=this.previewElements[a];yield this.preview({videoElement:n})}if(r&&this.screenPreviewElements.length)for(let a=0;a<this.screenPreviewElements.length;a++){const n=this.screenPreviewElements[a];yield this.preview({videoElement:n,screen:!0})}})}stopPreview(e){const{videoElement:t,primary:r=!0,screen:a=!0}=e||{};if(!t)r&&(this.previewElements.forEach(n=>{ke(n)}),this.previewElements=[]),a&&(this.screenPreviewElements.forEach(n=>{ke(n)}),this.screenPreviewElements=[]);else{const n=this.previewElements.findIndex(o=>o===t);if(n>=0)this.previewElements.splice(n,1),ke(t);else{const o=this.screenPreviewElements.findIndex(u=>u===t);o>=0&&(this.screenPreviewElements.splice(o,1),ke(t))}}}resumePublish(){return S(this,null,function*(){this._isPublishing=!1,yield this.startPublish(!0)})}createLocalStream(e){return S(this,null,function*(){try{const t=yield this.streamManager.createLocalStream(e);return t!=null&&t.audioTrack&&this.audioVolumeIndicationInterval>0&&this.audioLevelMonitor.start(t.audioTrack,this.audioVolumeIndicationInterval),e.video?this.previewAll({primary:!0}):e.screen&&this.previewAll({screen:!0}),t}catch(t){const r=vr[t.errorCode];throw r&&(e.audio?this.emit("localDeviceException",we.AliEngineLocalDeviceTypeMic,r,""):e.video?this.emit("localDeviceException",we.AliEngineLocalDeviceTypeCamera,r,""):e.screen?this.emit("localDeviceException",we.AliEngineLocalDeviceTypeDisplay,r,""):this.emit("localDeviceException",we.AliEngineLocalDeviceTypeUnknown,r,"")),t}})}stopLocalStream(e){return S(this,null,function*(){e.audio&&this.audioLevelMonitor.stop(),yield this.streamManager.stopLocalStream(e)})}compareAndPublish(e,t,r){return S(this,null,function*(){var n,o;if(!e&&!t)return;if(e&&!t){const u={};return r===R.Audio?u.audio=!0:r===R.VideoLarge||r===R.VideoSmall?(u.video=!0,u.vMsid=r):r===R.Screen&&(u.screen=!0),yield this.publishDeleteTracks(u)}const a={};if(t!=null&&t.hasVideo&&(a.isScreen=r===R.Screen,a.vMsid=r),t!=null&&t.hasAudio&&(a.aMsid=r),!e&&t)return yield this.publishAdd(t,a,!1);if(e&&t){const u=e.trackId,h=((n=t.videoTrack)==null?void 0:n.id)||((o=t.audioTrack)==null?void 0:o.id);if(u!==h)return yield this.publishReplace(t,a)}})}startPublish(e=!1){return S(this,null,function*(){if(!this.joined)return;const t=yield this.streamManager.publishStreams,{audio:r,video:a,videoSmall:n,screen:o}=t;try{const u=new Date().getTime();r&&this.audioPubState.setState(V.AliRtcStatePublishing),a&&this.videoPubState.setState(V.AliRtcStatePublishing),n&&this.videoSmallPubState.setState(V.AliRtcStatePublishing),o&&this.screenPubState.setState(V.AliRtcStatePublishing),this.publishPromise=this.rtsManager.publish(this.url,e);const h=yield this.publishPromise;this._isPublishing=!0,this.streamTracks=this.rtsManager.publishingTracks,this.traceId=h;const l={userid:this.userId,sessionid:"",displayname:this.name,pubid:this.publishId,resume:e,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks,traceId:h};yield this.syncPublishToRoomServer(l,t,u),r&&this.audioPubState.setState(V.AliRtcStatePublished),a&&this.videoPubState.setState(V.AliRtcStatePublished),n&&this.videoSmallPubState.setState(V.AliRtcStatePublished),o&&this.screenPubState.setState(V.AliRtcStatePublished)}catch(u){throw r&&this.audioPubState.setState(V.AliRtcStateNoPublish),a&&this.videoPubState.setState(V.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(V.AliRtcStateNoPublish),o&&this.screenPubState.setState(V.AliRtcStateNoPublish),u}})}publishUpdate(){return S(this,null,function*(){var a,n,o,u;if(!this._isPublishing)return;yield this.publishPromise;const e=yield this.streamManager.publishStreams;let t;const r=new Date().getTime();try{const h=(a=this.streamTracks)==null?void 0:a.find(({ssrc:O,type:B,msid:C})=>B==="audio"&&O&&C===R.Audio),l=yield this.compareAndPublish(h,e.audio,R.Audio);l&&(t=l);const p=(n=this.streamTracks)==null?void 0:n.find(({ssrc:O,type:B,msid:C})=>B==="video"&&O&&C===R.VideoLarge),d=yield this.compareAndPublish(p,e.video,R.VideoLarge);d&&(t=d);const m=(o=this.streamTracks)==null?void 0:o.find(({ssrc:O,type:B,msid:C})=>B==="video"&&O&&C===R.VideoSmall),g=yield this.compareAndPublish(m,e.videoSmall,R.VideoSmall);g&&(t=g);const f=(u=this.streamTracks)==null?void 0:u.find(({ssrc:O,type:B,msid:C})=>B==="video"&&O&&C===R.Screen),v=yield this.compareAndPublish(f,e.screen,R.Screen);if(v&&(t=v),!t)return;yield this.syncPublishToRoomServer(t,e,r)}catch(h){const{code:l}=h!=null?h:{},p=this.url;throw l===403&&p&&(yield this.refreshPushStreamUrl(),t=yield this.publishUpdate()),h}return t})}syncPublishToRoomServer(e,t,r){return S(this,null,function*(){var p;if(!e)throw new A(T.ERR_INNER,"sync publish to room server failed because no publishInfo");const a=yield this.signalingManager.publish(e);e.signaltid=a.tid;const n=new Date().getTime()-r,o=!!t.video,u=!1,h=!!t.screen,l=!!t.audio;this.reporter.reportPublish(this.callid||"",o,u,h,l,0,a.tid,n),this.webTrackingClient.reportPush(this.callid||"",o,u,h,l,0,a.tid,n,r,e.traceid||"",this.traceId,(p=this.url)!=null?p:"")})}refreshPushStreamUrl(){return S(this,null,function*(){const e=new A(T.ERR_INNER,"refresh push stream url error"),t=this.url;if(!t)throw e;const r=yield this.signalingManager.refreshUrl({pushstreamurl:t});if(!(r!=null&&r.pushstreamurl))throw e;this.url=r==null?void 0:r.pushstreamurl})}publishAdd(e,t,r=!1,a=0){return S(this,null,function*(){const n=(t==null?void 0:t.aMsid)===R.Audio,o=(t==null?void 0:t.vMsid)===R.VideoLarge,u=(t==null?void 0:t.vMsid)===R.VideoSmall,h=(t==null?void 0:t.vMsid)===R.Screen;n&&this.audioPubState.setState(V.AliRtcStatePublishing),o&&this.videoPubState.setState(V.AliRtcStatePublishing),u&&this.videoSmallPubState.setState(V.AliRtcStatePublishing),h&&this.screenPubState.setState(V.AliRtcStatePublishing);try{const l=yield this.rtsManager.publishAdd(this.url,e,t,!1,0,!0);n&&this.audioPubState.setState(V.AliRtcStatePublished),o&&this.videoPubState.setState(V.AliRtcStatePublished),u&&this.videoSmallPubState.setState(V.AliRtcStatePublished),h&&this.screenPubState.setState(V.AliRtcStatePublished),this.streamTracks=this.rtsManager.publishingTracks;const p={userid:this.userId,sessionid:"",displayname:this.name,pubid:this.publishId,resume:r,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks,traceid:l};return this.reportSelfDeviceStatus(),p}catch(l){let p=T.ERR_SDK_PUBLISH_INVAILD;if(n&&(this.audioPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_AUDIO_STRAM_FAILED),o&&(this.videoPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_VIDEO_STRAM_FAILED),u&&(this.videoSmallPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_DUAL_STRAM_FAILED),h&&(this.screenPubState.setState(V.AliRtcStateNoPublish),p=T.ERR_SDK_PUBLISH_SCEEN_SHARE_FAILED),l.errorCode===15006&&a<3)return this.publishAdd(e,t,r,a+1);throw A.fromError(l,p,"publish add failed")}})}publishReplace(e,t){return S(this,null,function*(){try{yield this.rtsManager.publishReplace(this.url,e,t),this.traceId="",this.streamTracks=this.rtsManager.publishingTracks;const r={userid:this.userId,sessionid:"",pubid:this.publishId,displayname:this.name,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks};return this.reportSelfDeviceStatus(),r}catch(r){throw A.fromError(r,T.ERR_INNER,`publish replace failed, vMsid: ${t==null?void 0:t.vMsid} aMsid: ${t==null?void 0:t.aMsid}`)}})}publishDeleteTracks(e){return S(this,null,function*(){const t={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};try{return yield this.rtsManager.publishDelete(this.url,e),this.streamTracks=this.rtsManager.publishingTracks,e.audio&&this.audioPubState.setState(V.AliRtcStateNoPublish),e.video&&(e.vMsid===R.VideoSmall?this.videoSmallPubState.setState(V.AliRtcStateNoPublish):this.videoPubState.setState(V.AliRtcStateNoPublish)),e.screen&&this.screenPubState.setState(V.AliRtcStateNoPublish),this.traceId="",t.tracks=this.streamTracks,this.reportSelfDeviceStatus(),t}catch(r){throw A.fromError(r,T.ERR_INNER,"publish delete tracks failed")}})}publishStop(){return S(this,null,function*(){const e="publishStop";if(!this._isPublishing)throw new A(T.ERR_INNER,"publish stop failed, previous localStream is required for publishing stopping");w.info(`[${this.moduleName}/${e}]`,{url:this.url});const t=new Date().getTime();try{const r=this.hasAudioTrackInMS,a=this.hasCameraTrackInMS,n=this.hasCameraDualTrackInMS,o=this.hasScreenTrackInMS;yield this.rtsManager.publishStop(this.url),r&&this.audioPubState.setState(V.AliRtcStateNoPublish),a&&this.videoPubState.setState(V.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(V.AliRtcStateNoPublish),o&&this.screenPubState.setState(V.AliRtcStateNoPublish),this.traceId="",this.streamTracks=[];const u={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};return this.syncPublishToRoomServer(u,{},t),u}catch(r){throw A.fromError(r,T.ERR_INNER,"publish stop failed")}})}unPublish(){return S(this,null,function*(){const e=new Date().getTime();let t={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};try{if(this._isPublishing){const r=this.hasAudioTrackInMS,a=this.hasCameraTrackInMS,n=this.hasCameraDualTrackInMS,o=this.hasScreenTrackInMS;yield this.rtsManager.unpublish(),r&&this.audioPubState.setState(V.AliRtcStateNoPublish),a&&this.videoPubState.setState(V.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(V.AliRtcStateNoPublish),o&&this.screenPubState.setState(V.AliRtcStateNoPublish),this._isPublishing=!1,this.traceId="",this.clearStream()}return this.reporter.reportUnpublish(this.callid||"",e,0,""),t}catch(r){throw A.fromError(r,T.ERR_INNER,"unpublish failed")}})}reportSelfDeviceStatus(){this.emit(ie.Local,this.getDeviceStatus())}getDeviceStatus(){var t,r,a,n;let e={micOpen:!1,micInterrupted:!1,cameraOpen:!1,screenShare:!1,audioDisable:!0,videoDisable:!0,screenDisable:!0,backgroundMode:!1,accompanyPlaying:!1};return e.cameraOpen=this.hasCamera,e.micOpen=this.hasMicrophone,e.screenShare=this.hasScreenShare,e.audioDisable=!((t=this.streamManager.cameraStreamInfo.originAudioTrack)!=null&&t.enabled),e.videoDisable=!((r=this.streamManager.cameraStreamInfo.originVideoTrack)!=null&&r.enabled),e.screenDisable=!this.hasScreenShare||!((n=(a=this.streamManager.screenStreamInfo)==null?void 0:a.originVideoTrack)!=null&&n.enabled),ji.getCurrentStatus(e)}resetPreviewElements(){this.previewElements=[]}resetSecondayPreviewElements(){this.screenPreviewElements=[]}stopStreamMonitor(){this.monitorTimerId&&(clearInterval(this.monitorTimerId),this.monitorTimerId=void 0)}clearStream(){this.streamManager.stop(),this.audioPubState.setState(V.AliRtcStatePublishIdle),this.videoPubState.setState(V.AliRtcStatePublishIdle),this.videoSmallPubState.setState(V.AliRtcStatePublishIdle),this.screenPubState.setState(V.AliRtcStatePublishIdle)}getCurrentCameraDeviceId(){var e;return(e=this.streamManager.cameraStreamInfo.originVideoTrack)==null?void 0:e.getSettings().deviceId}getCurrentMicDeviceId(){var e;return(e=this.streamManager.cameraStreamInfo.originAudioTrack)==null?void 0:e.getSettings().deviceId}enableAudioVolumeIndication(e){this.audioVolumeIndicationInterval!==e&&(this.audioVolumeIndicationInterval>0&&e<=0&&this.audioLevelMonitor.stop(),e>0&&this.streamManager.cameraStreamInfo.originAudioTrack&&this.audioLevelMonitor.start(this.streamManager.cameraStreamInfo.originAudioTrack,e),this.audioVolumeIndicationInterval=e)}sendSEI(e,t,r){return S(this,null,function*(){if(!this.url)return;let a=0;return!t||t<1?a=1:a=t-1,this.rtsManager.sendSEI(this.url,e,a,r)})}getStats(){return S(this,null,function*(){const e=[];if(this.hasAudioTrackInMS){const r=yield this.rtsManager.getPublishAudioStats(this.url);r&&e.push({stats:r,track:Ke.AliRtcAudioTrackMic})}const t=[];if(this.hasCameraTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,R.VideoLarge);r&&t.push({track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:r})}if(this.hasCameraDualTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,R.VideoSmall);r&&t.push({track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:r})}if(this.hasScreenTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,R.Screen);r&&t.push({track:x.AliRtcVideoTrackScreen,stats:r})}return{audio:e,video:t}})}};c(Ut,"logName","LocalUser");let z=Ut;Z([b()],z.prototype,"clearPublishState",1),Z([b()],z.prototype,"clear",1),Z([b()],z.prototype,"setViewConfig",1),Z([b()],z.prototype,"startCameraCapture",1),Z([b()],z.prototype,"stopCameraCapture",1),Z([b()],z.prototype,"stopAudioCapture",1),Z([b()],z.prototype,"stopPreview",1),Z([b()],z.prototype,"resumePublish",1),Z([b()],z.prototype,"createLocalStream",1),Z([b()],z.prototype,"stopLocalStream",1),Z([b(I)],z.prototype,"startPublish",1),Z([b(([i])=>[i])],z.prototype,"syncPublishToRoomServer",1),Z([b()],z.prototype,"refreshPushStreamUrl",1),Z([b(([i,s,e])=>[JSON.stringify(e)])],z.prototype,"publishAdd",1),Z([b(([i,s])=>[JSON.stringify(s)])],z.prototype,"publishReplace",1),Z([b(I)],z.prototype,"publishDeleteTracks",1),Z([b()],z.prototype,"publishStop",1),Z([b()],z.prototype,"unPublish",1),Z([b(([i,s,e])=>[i.length,s,e])],z.prototype,"sendSEI",1);var De=(i=>(i.OPUS="opus",i.H264="H264",i.UNKONWN="",i))(De||{}),Ue=(i=>(i.VideoTrackEnded="videoTrackEnded",i.AudioTrackEnded="audioTrackEnded",i.ScreenTrackEnded="screenTrackEnded",i))(Ue||{});const Ir=i=>{const s=new MediaStream;return s.addTrack(i),s},zi=i=>S(this,null,function*(){return yield P.AliRTS.createStream({custom:!0,mediaStream:i})}),it=i=>S(this,null,function*(){const s=Ir(i);return yield zi(s)}),Ar=i=>{const{audio:s,video:e,screen:t}=i;if(e&&t)throw new A(T.ERR_INNER,"create stream error, cannot create video && screen together");return!(!e&&!s&&!t)},Tr=i=>i===R.Audio||i===ge.Audio,Er=i=>i===R.VideoLarge||i===ge.VideoLarge,yr=i=>i===R.VideoSmall,Pr=i=>i===R.Screen;var Mr=Object.defineProperty,kr=Object.getOwnPropertyDescriptor,Nr=(i,s,e,t)=>{for(var r=t>1?void 0:t?kr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Mr(s,e,r),r};class Rt extends J{constructor(){super();c(this,"audioInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:De.UNKONWN});c(this,"videoLargeInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:De.UNKONWN});c(this,"videoSmallInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:De.UNKONWN});c(this,"screenInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:De.UNKONWN});c(this,"audioVolume",1);c(this,"audioMuted",!1);c(this,"userStatus");c(this,"moduleName","RemoteStreamInfo")}getAudioInfo(){return this.audioInfo}getVideoSmallInfo(){return this.videoSmallInfo}getVideoLargeInfo(){return this.videoLargeInfo}getScreenInfo(){return this.screenInfo}get hasAudio(){return this.audioInfo.ssrc!==""}get hasVideo(){return this.videoLargeInfo.ssrc!==""||this.videoSmallInfo.ssrc!==""}get hasVideoLarge(){return this.videoLargeInfo.ssrc!==""}get hasVideoSmall(){return this.videoSmallInfo.ssrc!==""}get hasScreen(){return this.screenInfo.ssrc!==""}get isAudioSubscribing(){return!!this.audioInfo.subscribed}get isVideoSubscribing(){return!!this.videoLargeInfo.subscribed||!!this.videoSmallInfo.subscribed}get isVideoLargeSubscribing(){return!!this.videoLargeInfo.subscribed}get isVideoSmallSubscribing(){return!!this.videoSmallInfo.subscribed}get isScreenSubscribing(){return!!this.screenInfo.subscribed}get audioCodec(){return this.audioInfo.codec}get videoCodec(){return this.hasVideoLarge?this.videoLargeInfo.codec:this.hasVideoSmall?this.videoSmallInfo.codec:this.hasScreen?this.screenInfo.codec:De.UNKONWN}get audioTrackInfo(){return this.hasAudio?Ke.AliRtcAudioTrackMic:Ke.AliRtcAudioTrackNo}get videoTrackInfo(){return this.hasVideo&&this.hasScreen?x.AliRtcVideoTrackBoth:this.hasVideo?x.AliRtcVideoTrackCamera:this.hasScreen?x.AliRtcVideoTrackScreen:x.AliRtcVideoTrackNo}updateTracks(e){let t="",r="",a="",n="";return e?(e.forEach(o=>{var l;let u=De.UNKONWN;const h=((l=o==null?void 0:o.attr)==null?void 0:l.reason)==="reconnect";if(o.userdata){const{codec:p}=JSON.parse(o.userdata);p&&(u=p)}Tr(o.msid)?(t=o.ssrc,this.audioInfo.msid=o.msid,this.audioInfo.codec=u,h&&(this.audioInfo.subscribed=!1)):yr(o.msid)?(a=o.ssrc,this.videoSmallInfo.msid=o.msid,this.videoSmallInfo.codec=u,h&&(this.videoSmallInfo.subscribed=!1)):Er(o.msid)?(r=o.ssrc,this.videoLargeInfo.msid=o.msid,this.videoLargeInfo.codec=u,h&&(this.videoLargeInfo.subscribed=!1)):Pr(o.msid)&&(n=o.ssrc,this.screenInfo.msid=o.msid,this.screenInfo.codec=u,h&&(this.screenInfo.subscribed=!1))}),this.updateRemoteTrackSsrc(t,r,a,n)):this.updateRemoteTrackSsrc(t,r,a,n),{}}updateRemoteTrackSsrc(e,t,r,a){this.audioInfo.ssrc=e,this.videoSmallInfo.ssrc=r,this.videoLargeInfo.ssrc=t,this.screenInfo.ssrc=a}updateRemoteTrackSubState(e){return e.video!==void 0&&((e.vMsid===this.videoSmallInfo.msid||!e.vMsid)&&(this.videoSmallInfo.subscribed=e.video),(e.vMsid===this.videoLargeInfo.msid||!e.vMsid)&&(this.videoLargeInfo.subscribed=e.video)),e.screen!==void 0&&(this.screenInfo.subscribed=e.screen),e.audio!==void 0&&(this.audioInfo.subscribed=e.audio),{audioInfo:this.audioInfo,videoLargeInfo:this.videoLargeInfo,videoSmallInfo:this.videoSmallInfo,screenInfo:this.screenInfo}}updateRemoteUserDeviceStatus(e){let t=ji.parseStatus(e);const{audioDisable:r,videoDisable:a,screenDisable:n}=t;return this.userStatus?(this.userStatus.audioDisable!=r&&(this.userStatus.audioDisable=r,this.emit(ie.Remote,r?H.MuteAudio:H.UnmuteAudio)),this.userStatus.videoDisable!=a&&(this.userStatus.videoDisable=a,this.emit(ie.Remote,a?H.MuteVideo:H.UnmuteVideo)),this.userStatus.screenDisable!=n&&(this.userStatus.screenDisable=n,this.emit(ie.Remote,n?H.MuteScreen:H.UnmuteScreen))):(this.userStatus=t,this.emit(ie.Remote,r?H.MuteAudio:H.UnmuteAudio),this.emit(ie.Remote,a?H.MuteVideo:H.UnmuteVideo),this.emit(ie.Remote,n?H.MuteScreen:H.UnmuteScreen)),!1}}c(Rt,"logName","RemoteStreamInfo"),Nr([b()],Rt.prototype,"updateRemoteTrackSubState",1);class Yi{constructor(s){c(this,"remoteUser");this.remoteUser=s}get userId(){return this.remoteUser.userId}get displayName(){return this.remoteUser.displayname}get isMuteAudioPlaying(){return this.remoteUser.getAudioMuted()}get hasAudio(){return this.remoteUser.hasAudioTrack}get hasCamera(){return this.remoteUser.hasVideoTrack}get hasCameraLarge(){return this.remoteUser.hasVideoLargeTrack}get hasCameraSmall(){return this.remoteUser.hasVideoSmallTrack}get hasScreenShare(){return this.remoteUser.hasScreenTrack}get isAudioSubscribing(){return this.remoteUser.isAudioSubscribing}get isVideoSubscribing(){return this.remoteUser.isVideoSubscribing}get isVideoLargeSubscribing(){return this.remoteUser.isVideoLargeSubscribing}get isVideoSmallSubscribing(){return this.remoteUser.isVideoSmallSubscribing}get isScreenSubscribing(){return this.remoteUser.isScreenSubscribing}}var Cr=Object.defineProperty,Lr=Object.getOwnPropertyDescriptor,te=(i,s,e,t)=>{for(var r=t>1?void 0:t?Lr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Cr(s,e,r),r};class st extends J{constructor(){super();c(this,"state");c(this,"time");c(this,"_enabled");this.state=G.AliRtcStateSubscribeIdle,this.time=Date.now(),this._enabled=!0}setState(e){if(this.state===e)return;const t=this.state,r=this.time;this.state=e,this.time=Date.now(),this.emit("change",t,e,Math.floor((this.time-r)/1e3))}get currentState(){return this.state}getEnabled(){return this._enabled}setEnabled(e){this._enabled=e}}const xt=class xt extends Ki{constructor(e){var d;const{userId:t,displayName:r,rtsManager:a,usersViewMap:n,reporter:o,webTrackingClient:u,signalingManager:h,localUserId:l,audioVolumeIndicationInterval:p}=e;super(t,r,a,p);c(this,"remoteCallid","");c(this,"remoteUserInfo");c(this,"localUserId");c(this,"lastPubId","");c(this,"stream");c(this,"screenStream");c(this,"viewMap");c(this,"audioTrack");c(this,"audioElement");c(this,"subscribed",!1);c(this,"mediaStream");c(this,"secondaryMediaStream");c(this,"prevSubConfig");c(this,"signalingManager");c(this,"reporter");c(this,"webTrackingClient");c(this,"wantSubAudio",!1);c(this,"wantSubVideo",!1);c(this,"wantSubScreen",!1);c(this,"defaultVideoStreamType",oe.AliRtcVideoStreamTypeHigh);c(this,"audioMuted",!1);c(this,"audioSubState");c(this,"videoSubState");c(this,"videoLargeSubState",new st);c(this,"videoSmallSubState",new st);c(this,"screenSubState");c(this,"streamInfo");c(this,"streamUrl","");this.streamInfo=new Rt,this.remoteUserInfo=new Yi(this),this.streamInfo.on(ie.Remote,m=>{this.emit(ie.Remote,m,this.userId)}),this.signalingManager=h,this.viewMap=(d=n[t])!=null?d:{cameraViews:[],screenViews:[]},n[t]=this.viewMap,this.reporter=o,this.webTrackingClient=u,this.localUserId=l,this.audioSubState=new st,this.audioSubState.on("change",(m,g,f)=>{this.emit("audioSubscribeStateChanged",this.uid,m,g,f)}),this.videoSubState=new st,this.videoSubState.on("change",(m,g,f)=>{this.emit("videoSubscribeStateChanged",this.uid,m,g,f)}),this.screenSubState=new st,this.screenSubState.on("change",(m,g,f)=>{this.emit("screenSubscribeStateChanged",this.uid,m,g,f)})}isWantSubAudio(){return this.wantSubAudio}setWantSubAudio(e){this.wantSubAudio=e}isWantSubVideo(){return this.wantSubVideo}setWantSubVideo(e){this.wantSubVideo=e}isWantSubScreen(){return this.wantSubScreen}setWantSubScreen(e){this.wantSubScreen=e}setRemoteDefaultVideoStreamType(e){e!==this.defaultVideoStreamType&&(this.defaultVideoStreamType=e,this.updateSubscribe())}setAudioMuted(e){this.audioMuted=e,this.toggleAudio(!e)}getAudioMuted(){return this.audioMuted}get hasAudioTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasAudio)}get hasVideoTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasVideo)}get hasVideoLargeTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasVideoLarge)}get hasVideoSmallTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasVideoSmall)}get hasScreenTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasScreen)}get isAudioSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isAudioSubscribing)}get isVideoSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isVideoSubscribing)}get isVideoLargeSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isVideoLargeSubscribing)}get isVideoSmallSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isVideoSmallSubscribing)}get isScreenSubscribing(){var e;return!!((e=this.streamInfo)!=null&&e.isScreenSubscribing)}get audioEnabled(){var e,t;return!!((t=(e=this.stream)==null?void 0:e.audioTrack)!=null&&t.enabled)}get videoEnabled(){var e,t;return!!((t=(e=this.stream)==null?void 0:e.videoTrack)!=null&&t.enabled)}get screenEnabled(){var e,t;return!!((t=(e=this.screenStream)==null?void 0:e.videoTrack)!=null&&t.enabled)}get getAudioTrack(){return this.audioTrack}get getCameraStream(){return this.stream}get getScreenStream(){return this.screenStream}setViewConfig(e,t){if(t!==x.AliRtcVideoTrackScreen&&t!==x.AliRtcVideoTrackCamera)throw new A(T.ERR_INVALID_ARGUMENTS,"track is not AliRtcVideoTrackScreen or AliRtcVideoTrackCamera");e?ni(e).forEach(a=>{a.setAttribute("playsinline",""),N.BrowserUtil.isMicroMessenger&&(a.setAttribute("x5-video-player-type","h5-page"),a.setAttribute("x5-playsinline",""),N.SystemUtil.isAndroid||N.SystemUtil.isIos&&a.setAttribute("x-webkit-airplay","allow")),t===x.AliRtcVideoTrackScreen?this.viewMap.screenViews.push(a):this.viewMap.cameraViews.push(a),this.play(a,t===x.AliRtcVideoTrackScreen)}):(this.stopPlayAll(t===x.AliRtcVideoTrackScreen),t===x.AliRtcVideoTrackScreen?this.viewMap.screenViews=[]:this.viewMap.cameraViews=[])}clear(e=!0){return S(this,null,function*(){var t;e&&this.doStopSubscribe(this.streamUrl),xi(xt.prototype,this,"clear").call(this),this.clearStream(),this.clearScreenStream(),(t=this.streamInfo)==null||t.removeAllListeners(ie.Remote)})}updateRemoteUserDeviceStatus(e){var t;(t=this.streamInfo)==null||t.updateRemoteUserDeviceStatus(e)}updateRemoteTracks(e,t,r,a){return S(this,null,function*(){var o;return this.remoteCallid=e,this.streamUrl=t!=null?t:"",this.callid=e!=null?e:"",this.streamInfo||(this.streamInfo=new Rt),(o=this.streamInfo)==null?void 0:o.updateTracks(a)})}subscribe(e){return S(this,null,function*(){var h;e?this.reporter.reportSubscribeInvoked(this.userId,e.video,!1,e.screen,e.audio):this.reporter.reportSubscribeInvoked(this.userId);let t=e;if(!t){const{hasAudio:l,hasVideo:p,hasScreen:d}=(h=this.streamInfo)!=null?h:{};t={audio:this.wantSubAudio&&l,video:this.wantSubVideo&&p,screen:this.wantSubScreen&&d}}const{screen:r,audio:a,video:n,vMsid:o}=t,u=[];(n||a)&&u.push({audio:a,video:n,vMsid:o}),r&&u.push({screen:r}),u.length!==0&&(yield Promise.all(u.map(l=>this.subscribeProxy(l))))})}subscribeProxy(e){return S(this,null,function*(){var n,o;let t=new Date().getTime(),r="",a="";try{e.audio&&this.audioSubState.setState(G.AliRtcStateSubscribing),e.video&&(this.videoSubState.currentState===G.AliRtcStateSubscribeIdle||this.videoSubState.currentState===G.AliRtcStateNoSubscribe)&&this.videoSubState.setState(G.AliRtcStateSubscribing),e.screen&&this.screenSubState.setState(G.AliRtcStateSubscribing);const u=yield this.rtsManager.subscribe({remoteUser:this,options:e});this.streamInfo.updateRemoteTrackSubState(e),r=u;const{stream:h}=u;if(e.audio){const p=h.audioTrack;p&&(this.audioTrack=p,(n=h.mediaStream)==null||n.removeTrack(p),this.playAudio(),this.audioVolumeIndicationInterval&&this.audioLevelMonitor.start(p,this.audioVolumeIndicationInterval)),this.audioSubState.setState(G.AliRtcStateSubscribed),this.audioSubState.getEnabled()||this.toggleAudio(!1)}e.video&&(e.vMsid===R.VideoSmall?this.videoSmallSubState.setState(G.AliRtcStateSubscribed):this.videoLargeSubState.setState(G.AliRtcStateSubscribed),this.videoSubState.setState(G.AliRtcStateSubscribed),this.videoSubState.getEnabled()||this.toggleVideo(!1),this.updateStream(h,this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing)),e.screen&&(this.screenSubState.setState(G.AliRtcStateSubscribed),this.videoSubState.getEnabled()||this.toggleScreen(!1),this.updateScreenStream(h));const l=new Date().getTime()-t;this.webTrackingClient.reportPull(u.callid,u.remoteCallid,u.isVideoLargeSubscribing,u.isVideoSmallSubscribing,u.isScreenSubscribing,u.isAudioSubscribing,0,l,a,r,this.streamUrl,t)}catch(u){const h=new Date().getTime()-t;this.webTrackingClient.reportPull("","",!1,!1,!1,!1,u.code,h,a,r,(o=this.streamUrl)!=null?o:"",t),u&&(u.message=`user(${this.uid}) subscribe error, ${(u==null?void 0:u.message)||""}`);let l=T.ERR_INNER;e.audio&&(l=T.ERR_SDK_SUBSCRIBE_AUDIO_STRAM_FAILED),e.video&&(e.vMsid===R.VideoSmall?l=T.ERR_SDK_SUBSCRIBE_DUAL_STRAM_FAILED:l=T.ERR_SDK_SUBSCRIBE_VIDEO_STRAM_FAILED),e.screen&&(l=T.ERR_SDK_SUBSCRIBE_SCREEN_SHARE_FAILED);const p=A.fromError(u,l);throw this.emit("remoteSubscribeError",p),p}})}subscribeDeleteTracks(e){return S(this,null,function*(){const{audio:t,video:r,screen:a,vMsid:n}=e,o=[];(t||r)&&o.push({audio:t,video:r,vMsid:n}),a&&o.push({screen:a}),o.length!==0&&(yield Promise.all(o.map(u=>this.subscribeDeleteProxy(u))))})}subscribeDeleteProxy(e){return S(this,null,function*(){try{const t=yield this.rtsManager.subscibeDelete({remoteUser:this,options:e}),{stream:r}=t!=null?t:{},a={};e.audio===!0&&(a.audio=!1,this.audioSubState.setState(G.AliRtcStateNoSubscribe)),e.video===!0&&(a.video=!1,e.vMsid===R.VideoSmall?(this.videoSmallSubState.setState(G.AliRtcStateNoSubscribe),(this.videoLargeSubState.currentState===G.AliRtcStateNoSubscribe||this.videoLargeSubState.currentState===G.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(G.AliRtcStateNoSubscribe)):(this.videoLargeSubState.setState(G.AliRtcStateNoSubscribe),(this.videoSmallSubState.currentState===G.AliRtcStateNoSubscribe||this.videoSmallSubState.currentState===G.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(G.AliRtcStateNoSubscribe))),e.screen===!0&&(a.screen=!1,this.screenSubState.setState(G.AliRtcStateNoSubscribe));const{callid:n,remoteCallid:o}=this,u={callid:n,remoteCallid:o,remoteStream:r};return e.audio&&(this.audioLevelMonitor.stop(),this.stopPlayAudio(),this.audioTrack=void 0),this.streamInfo.updateRemoteTrackSubState({audio:e.audio===!0?!1:void 0,video:e.video===!0?!1:void 0,screen:e.screen===!0?!1:void 0,vMsid:e.vMsid}),u}catch(t){throw A.fromError(t,T.ERR_INNER,"subscribe delete failed")}})}restore(){this.clearStream(),this.clearScreenStream(),this.audioTrack=void 0,this.streamInfo.updateRemoteTrackSubState({audio:!1,video:!1,screen:!1})}resumeAudio(){return S(this,null,function*(){var e;return(e=this.audioElement)==null?void 0:e.play()})}resumeVideo(e){return S(this,null,function*(){if(!e||e===x.AliRtcVideoTrackCamera||e===x.AliRtcVideoTrackBoth)return this.playAll();if(!e||e===x.AliRtcVideoTrackScreen||e===x.AliRtcVideoTrackBoth)return this.playAll(!0)})}resumePlay(){this.playAudio(),this.playAll(),this.playAll(!0)}stopSubscribe(e){return S(this,null,function*(){var p,d,m,g,f,v,O;const{isAudioSubscribing:t=!1,isVideoSubscribing:r=!1,isScreenSubscribing:a=!1}=this,n=t&&!((p=e==null?void 0:e.audio)==null||p),o=r&&!((d=e==null?void 0:e.video)==null||d),u=!1,h=a&&!((m=e==null?void 0:e.screen)==null||m);e?this.reporter.reportSubscribeInvoked(this.userId,o,u,h,n):this.reporter.reportUnsubscribeInvoked(this.userId);let l=new Date().getTime();try{let B;e?B=yield this.subscribeDeleteTracks(e):B=yield this.doStopSubscribe(this.streamUrl),e?this.reporter.reportSubscribe((g=B==null?void 0:B.callid)!=null?g:"",this.userId,o,u,h,n,0,"",new Date().getTime()-l,(f=this.localUserId)!=null?f:""):this.reporter.reportUnsubscribe((v=B==null?void 0:B.callid)!=null?v:"",this.userId,new Date().getTime()-l,0,"")}catch(B){throw e?this.reporter.reportSubscribe("",this.userId,o,u,h,n,B.code,"",new Date().getTime()-l,(O=this.localUserId)!=null?O:""):this.reporter.reportUnsubscribe("",this.userId,new Date().getTime()-l,0,""),B}})}doStopSubscribe(e){return S(this,null,function*(){var a,n,o,u;const{callid:t,remoteCallid:r}=this;if((this.isAudioSubscribing||this.isVideoSubscribing||this.isScreenSubscribing)&&e)try{return yield this.rtsManager.subscibeStop(e),this.restore(),{callid:t,remoteCallid:r,remoteStream:this.stream}}catch(h){if(((u=(o=(n=(a=h==null?void 0:h.extraInfo)==null?void 0:a.parsedData)==null?void 0:n.streams)==null?void 0:o[0])==null?void 0:u.res_code)!==404)throw A.fromError(h,T.ERR_INNER,"subscribe stop failed")}})}updateStream(e,t=!1){return S(this,null,function*(){this.stream&&this.stream.videoTrack&&e.mediaStream&&t&&(yield new Promise(r=>{let a,n;if(e.mediaStream){n=document.createElement("video");const o=()=>{w.event(`uid: ${this.userId} new mediaStream canplay`),n&&n.removeEventListener("canplaythrough",o,!1),n=void 0,clearTimeout(a),r(!0)};n.addEventListener("canplaythrough",o,!1),(n._playPromise||Promise.resolve()).then(()=>{n&&e.mediaStream&&(n.srcObject=e.mediaStream)})}else r(!0);a=window.setTimeout(()=>{w.event(`uid: ${this.userId} new mediaStream timeout`),n=void 0,r(!0)},3e3)}),this.updateSubscribe()),this.stream=e,this.playAll(),!this.subscribed&&e&&(this.subscribed=!0),e.hasAudio&&this.isAudioSubscribing&&e.enableAudio(),e.hasVideo&&this.isVideoSubscribing&&e.enableVideo()})}updateScreenStream(e){this.screenStream=e,this.playAll(!0),!this.subscribed&&e&&(this.subscribed=!0),e.hasVideo&&this.isScreenSubscribing&&e.enableVideo()}clearStream(){var e;(e=this.stream)==null||e.stop(),this.stream=void 0}clearScreenStream(){var e;(e=this.screenStream)==null||e.stop(),this.screenStream=void 0}updateSubscribe(){var r,a,n,o,u,h,l,p;const e={},t={};return this.wantSubAudio&&!this.isAudioSubscribing&&((r=this.streamInfo)!=null&&r.hasAudio)?e.audio=!0:(!this.wantSubAudio||!((a=this.streamInfo)!=null&&a.hasAudio))&&this.isAudioSubscribing&&(t.audio=!0),this.wantSubVideo&&((n=this.streamInfo)!=null&&n.hasVideo)?(this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&!this.isVideoSmallSubscribing&&((o=this.streamInfo)!=null&&o.hasVideoSmall)?(e.video=!0,e.vMsid=R.VideoSmall):!this.isVideoLargeSubscribing&&((u=this.streamInfo)!=null&&u.hasVideoLarge)&&!(this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoSmallSubscribing)&&(e.video=!0,e.vMsid=R.VideoLarge),this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&this.streamInfo.hasVideoSmall?(t.video=!0,t.vMsid=R.VideoLarge):this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeHigh&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&(t.video=!0,t.vMsid=R.VideoSmall)):(!this.wantSubVideo||!((h=this.streamInfo)!=null&&h.hasVideo))&&this.isVideoSubscribing&&(t.video=!0,t.vMsid=this.streamInfo.isVideoSmallSubscribing?R.VideoSmall:R.VideoLarge),this.wantSubScreen&&!this.isScreenSubscribing&&((l=this.streamInfo)!=null&&l.hasScreen)?e.screen=!0:(!this.wantSubScreen||!((p=this.streamInfo)!=null&&p.hasScreen))&&this.isScreenSubscribing&&(t.screen=!0),(e.audio||e.video||e.screen)&&this.subscribe(e),t.audio&&t.video&&t.screen?this.stopSubscribe():(t.audio||t.video||t.screen)&&this.subscribeDeleteTracks(t),{addOption:e,deleteOption:t}}handleAutoPlayFailed(){this.emit("remoteAudioAutoPlayFail",this.uid);const e=()=>{this.resumeAudio().then(()=>{document.removeEventListener("click",e,!1),document.removeEventListener("touchstart",e,!1)})};document.addEventListener("click",e,!1),document.addEventListener("touchstart",e,!1)}handleVideoPlayFailded(e,t){this.emit("remoteVideoAutoPlayFail",this.uid,t);const r=()=>{var n;const a=(n=t===x.AliRtcVideoTrackScreen?this.screenStream:this.stream)==null?void 0:n.mediaStream;e.srcObject===a&&this.play(e,t===x.AliRtcVideoTrackScreen),document.removeEventListener("click",r,!1),document.removeEventListener("touchstart",r,!1)};document.addEventListener("click",r,!1),document.addEventListener("touchstart",r,!1)}playAudio(){return S(this,null,function*(){var t,r;if(!this.audioTrack)return;if(this.toggleAudio(!this.audioMuted),this.audioElement||(this.audioElement=document.createElement("audio")),((r=(t=this.audioElement.srcObject)==null?void 0:t.getAudioTracks())==null?void 0:r[0])!==this.audioTrack){let a=this.audioElement.srcObject;a?a.getAudioTracks().forEach(n=>{a.removeTrack(n)}):(a=new MediaStream,this.audioElement.srcObject=a),a.addTrack(this.audioTrack)}this.audioElement.play().catch(()=>{this.handleAutoPlayFailed()});const e=this.audioElement;this.audioElement.addEventListener("playing",function a(){e.removeEventListener("playing",a),N.SystemUtil.isIos&&parseInt(N.SystemUtil.systemVersion)<=14&&(e.muted||(e.pause(),e.play()))})})}stopPlayAudio(){this.audioElement&&(this.audioElement.pause(),this.audioElement.srcObject=null)}playAll(e=!1){e?(this.viewMap.screenViews||[]).forEach(t=>{this.play(t,e)}):(this.viewMap.cameraViews||[]).forEach(t=>{this.play(t,e)})}play(e,t=!1){const r=t?this.screenStream:this.stream;!e||!r||!r.mediaStream||Gi(e,r.mediaStream).catch(a=>{a.code===20||a.name==="AbortError"||this.handleVideoPlayFailded(e,t?x.AliRtcVideoTrackScreen:x.AliRtcVideoTrackCamera)})}stopPlayAll(e=!1){e?this.viewMap.screenViews.forEach(t=>{ke(t)}):this.viewMap.cameraViews.forEach(t=>{ke(t)})}toggleAudio(e=!0){this.audioSubState.setEnabled(e),this.audioTrack&&(this.audioTrack.enabled=e)}toggleVideo(e=!0){this.videoSubState.setEnabled(e),this.stream&&(e?this.stream.enableVideo():this.stream.disableVideo())}toggleScreen(e=!0){this.screenSubState.setEnabled(e),this.screenStream&&(e?this.screenStream.enableVideo():this.screenStream.disableVideo())}getStats(){return S(this,null,function*(){var r,a;const e=[];if(this.isAudioSubscribing){const n=yield this.rtsManager.getSubscribeAudioStats(this.streamUrl);n&&e.push({uid:this.uid,track:Ke.AliRtcAudioTrackMic,stats:n})}const t=[];if((r=this.streamInfo)!=null&&r.isVideoLargeSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,R.VideoLarge);n&&t.push({uid:this.uid,track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:n})}if((a=this.streamInfo)!=null&&a.isVideoSmallSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,R.VideoSmall);n&&t.push({uid:this.uid,track:x.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:n})}if(this.isScreenSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,R.Screen);n&&t.push({uid:this.uid,track:x.AliRtcVideoTrackScreen,stats:n})}return{audio:e,video:t}})}enableAudioVolumeIndication(e){this.audioVolumeIndicationInterval!==e&&(this.audioVolumeIndicationInterval>0&&e<=0&&this.audioLevelMonitor.stop(),e>0&&this.audioTrack&&this.audioLevelMonitor.start(this.audioTrack,e),this.audioVolumeIndicationInterval=e)}};c(xt,"logName","RemoteUser");let Y=xt;te([b()],Y.prototype,"clear",1),te([b()],Y.prototype,"updateRemoteUserDeviceStatus",1),te([b()],Y.prototype,"updateRemoteTracks",1),te([b(I)],Y.prototype,"subscribe",1),te([b()],Y.prototype,"subscribeProxy",1),te([b(I)],Y.prototype,"subscribeDeleteTracks",1),te([b(I)],Y.prototype,"subscribeDeleteProxy",1),te([b()],Y.prototype,"restore",1),te([b(I)],Y.prototype,"stopSubscribe",1),te([b(I)],Y.prototype,"doStopSubscribe",1),te([b()],Y.prototype,"clearStream",1),te([b()],Y.prototype,"clearScreenStream",1),te([b()],Y.prototype,"updateSubscribe",1),te([b()],Y.prototype,"playAudio",1),te([b()],Y.prototype,"stopPlayAudio",1),te([b(I)],Y.prototype,"playAll",1),te([b()],Y.prototype,"play",1),te([b()],Y.prototype,"stopPlayAll",1);var Ne=(i=>(i[i.AliRtcPluginErrorCodeSuccess=0]="AliRtcPluginErrorCodeSuccess",i[i.AliRtcPluginErrorCodeFailed=-1]="AliRtcPluginErrorCodeFailed",i[i.AliRtcPluginErrorNoFindPlugin=-2]="AliRtcPluginErrorNoFindPlugin",i[i.AliRtcPluginErrorParameterError=-3]="AliRtcPluginErrorParameterError",i[i.AliRtcPluginErrorLoadError=-4]="AliRtcPluginErrorLoadError",i[i.AliRtcPluginErrorCreateError=-5]="AliRtcPluginErrorCreateError",i[i.AliRtcPluginErrorInitError=-6]="AliRtcPluginErrorInitError",i[i.AliRtcPluginErrorInitTokenError=-7]="AliRtcPluginErrorInitTokenError",i))(Ne||{});class Vr extends J{constructor(){super(...arguments);c(this,"plugins",new Map)}add(e,t){if(this.plugins.has(e.name))throw new A(Ne.AliRtcPluginErrorCreateError,`Plugin ${e.name} already exists`);this.plugins.set(e.name,e),t&&e.setOptions(t),this.emit("added",e),e.on("enabled",()=>this.emit("added",e)),e.on("disabled",()=>this.emit("removed",e)),e.on("updated",()=>this.emit("updated",e))}remove(e){const t=this.plugins.get(e);if(!t)throw new A(Ne.AliRtcPluginErrorNoFindPlugin,`Plugin ${e} not founded`);this.plugins.delete(e),t.removeAllListeners(),this.emit("removed",t)}get(e){return this.plugins.get(e)}has(e){return!!this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}}var Or=Object.defineProperty,Dr=Object.getOwnPropertyDescriptor,ce=(i,s,e,t)=>{for(var r=t>1?void 0:t?Dr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Or(s,e,r),r};const wt=([i])=>{const{remoteUser:s,options:e}=i;return[`user(${s.userId})`,e]},ae=(Ie=class extends J{constructor(e){super();c(this,"rts");c(this,"encodedInsertableStreams",!1);c(this,"localStreamManager");c(this,"connecting",!1);c(this,"connected",!1);c(this,"connectionResolve");c(this,"connectingPromise");c(this,"dcResolve");c(this,"dcConnectingPromise");c(this,"_publishingTracks",[]);this.rts=P.AliRTS.createClient(),this.localStreamManager=e,this.rts.on("connectStatusChange",t=>{var r,a,n,o;if(w.event(`[${Ie.logName}]`,"rts connectStatusChange to:",t.status),t.status===P.EConnectStatus.CONNECT_STATUS_DISCONNECTED)this.emit("disconnected"),this.setConnected(!1);else if(t.status===P.EConnectStatus.CONNECT_STATUS_RECONNECTING)this.emit("reconnecting"),this.setConnected(!1);else if(t.status===P.EConnectStatus.CONNECT_STATUS_CONNECTED){this.setConnected(!0);const u=(o=(n=(a=(r=this.rts.commonController)==null?void 0:r.peerCore)==null?void 0:a.getSignal())==null?void 0:n.getDatachannelCore())==null?void 0:o.readyState;w.event(Ie.logName,"dcReadyState:",u),u==="open"&&this.dcResolve&&this.dcResolve(!0),this.emit("connected")}}),this.rts.on("datachannelStatusChange",t=>{w.event(`[${Ie.logName}]`,"rts datachannelStatusChange to:",t.status),t.status===P.EDatachannelStatus.DATACHANNEL_STATUS_OPEN?this.dcResolve&&this.dcResolve(!0):t.status===P.EDatachannelStatus.DATACHANNEL_STATUS_CLOSE&&(this.dcConnectingPromise=new Promise(r=>{this.dcResolve=r}),console.warn("DC DisConnected"))}),this.rts.on("receivedSEI",t=>{this.emit("seimessage",t.url,t.sei.payloadType,t.sei.data)})}setEncodedInsertableStreams(e){this.encodedInsertableStreams=e}destroy(){this.rts.unpublish()}startConnect(){this.connecting=!0,this.connectingPromise=new Promise(e=>{this.connectionResolve=e}),this.dcConnectingPromise=new Promise(e=>{this.dcResolve=e})}setConnected(e){var t;this.connected=e,this.connecting=!1,(t=this.connectionResolve)==null||t.call(this,!0),e||(this.dcConnectingPromise=new Promise(r=>{this.dcResolve=r}))}get isConnecting(){return this.connecting}get isConnected(){return this.connected}get publishingTracks(){return this._publishingTracks}getPubMsid(e,t){const{aMsid:r,vMsid:a}=t!=null?t:{},n={};return e.hasAudio&&(n.aMsid=[r!=null?r:R.Audio]),e.hasScreen&&(n.vMsid=[R.Screen]),e.hasVideo&&(n.vMsid=[a!=null?a:t!=null&&t.isScreen?R.Screen:R.VideoLarge]),n}updatePublishingTracks(e){e&&(this._publishingTracks=e.map(({msid:t,from:r,ssrc:a,codec:n,type:o,trackId:u})=>({msid:t,from:r,type:o,ssrc:`${a}`,codec:n!=null?n:"",trackId:u})))}httpPublish(e,t=!1){return S(this,null,function*(){const{publishStream:r,videoSmallStream:a,screenStream:n,vMsid:o}=yield this.localStreamManager.createHTTPPublishStream();if(!r)return"";const u=this.getPubMsid(r,{vMsid:o});(P.AliRTS.SystenUtil.isIos||P.AliRTS.BrowserUtil.isSafari)&&(u.tcpOnly=!0),u.retryTimes=0,this.encodedInsertableStreams&&(u.encodedInsertableStreams=!0);let h=!r.hasVideo,l=o;try{this.startConnect();const p=yield this.rts.publish(e,r,u);return this.setConnected(!0),this._publishingTracks=this.rts.getPublishTrackInfoList(),a&&(yield this.publishAdd(e,a,{vMsid:R.VideoSmall},t),h=!1,l=R.VideoSmall),n&&(yield this.publishAdd(e,n,{vMsid:R.Screen},t),h=!1,l=R.Screen),yield this.waitPublishSender(e,h,l),p}catch(p){throw this.setConnected(!1),p}})}waitPublishSender(e,t=!1,r){return S(this,null,function*(){const a=(n,o)=>{let u=0;const h=()=>(t?this.rts.getPublishAudioStats(e,r):this.rts.getPublishVideoStats(e,r)).then(p=>!(p.bytesSent>0)&&u<n?(u++,new Promise(m=>setTimeout(()=>m(h()),o))):Promise.resolve());return h()};return Promise.race([Oe(1e3),a(5,100)]).catch(()=>{})})}getPublishVideoStats(e,t){return S(this,null,function*(){return yield this.rts.getPublishVideoStats(e,t)})}getPublishAudioStats(e,t){return S(this,null,function*(){return yield this.rts.getPublishAudioStats(e,t)})}publishAdd(e,t,r,a=!1,n=0,o=!1){return S(this,null,function*(){try{yield this.dcConnectingPromise;const u=yield this.rts.publishAdd([W({url:e,stream:t,updateSourceStream:!1},this.getPubMsid(t,r))]);if(u){const[h]=u;return this.updatePublishingTracks(h.trackInfoList),o&&(yield this.waitPublishSender(e,!t.hasVideo,t.hasVideo?r==null?void 0:r.vMsid:r==null?void 0:r.aMsid)),h.traceId||""}}catch(u){if(u.errorCode===15006&&n<3)return yield this.publishAdd(e,t,r,a,n+1);throw u}return""})}publishDelete(e,t){return S(this,null,function*(){var l,p,d,m,g,f,v,O;yield this.dcConnectingPromise;const r=(p=(l=this.publishingTracks)==null?void 0:l.find(({msid:B})=>B===R.Audio))==null?void 0:p.msid,a=(m=(d=this.publishingTracks)==null?void 0:d.find(({msid:B})=>B===R.VideoLarge))==null?void 0:m.msid,n=(f=(g=this.publishingTracks)==null?void 0:g.find(({msid:B})=>B===R.Screen))==null?void 0:f.msid,o=[];t.screen&&n?o.push(n):t.video&&o.push(t.vMsid||a);const u=[];t.audio&&r&&u.push(r),w.event(Ie.logName,"publishDelete",{streamUrl:e,aMsid:u,vMsid:o});const[h]=(yield this.rts.publishDeleteTracks([{url:e,aMsid:u,vMsid:o}]))||[];return w.event(Ie.logName,"publishDelete",{result:h}),h&&this.updatePublishingTracks(h.trackInfoList),((O=(v=h==null?void 0:h.trackInfoList)==null?void 0:v[0])==null?void 0:O.trackId)||""})}publishReplace(e,t,r){return S(this,null,function*(){var h,l;yield this.dcConnectingPromise;const{vMsid:a,aMsid:n}=r!=null?r:{},o=yield this.rts.publishReplaceTracks([{url:e,stream:t,updateSourceStream:!1,vMsid:a,aMsid:n}]),[u]=o;return this.updatePublishingTracks(u.trackInfoList),((l=(h=u==null?void 0:u.trackInfoList)==null?void 0:h[0])==null?void 0:l.trackId)||""})}publishStop(e){return S(this,null,function*(){return yield this.rts.publishStop([{url:e}]),this._publishingTracks=[],""})}unpublish(){return S(this,null,function*(){yield this.rts.unpublish(),this.connecting=!1,this.connected=!1})}getSubConfig(e,t){let r=t!=null?t:{};t||(r={audio:!0,video:!0,screen:!0});const a={};return r.audio&&(a.aMsid=[(e==null?void 0:e.getAudioInfo().msid)||R.Audio]),r.video?r.vMsid?a.vMsid=[r.vMsid]:e!=null&&e.hasVideoLarge?a.vMsid=[(e==null?void 0:e.getVideoLargeInfo().msid)||R.VideoLarge]:e!=null&&e.hasVideoSmall?a.vMsid=[(e==null?void 0:e.getVideoSmallInfo().msid)||R.VideoSmall]:a.vMsid=[R.VideoLarge]:r.screen&&e!=null&&e.hasScreen&&(a.vMsid=[(e==null?void 0:e.getScreenInfo().msid)||R.Screen]),a}httpSubscribe(e){return S(this,null,function*(){const{remoteUser:t,options:r}=e;let a=t.streamUrl;r.video||r.screen?r!=null&&r.audio||(a+="@subaudio=no"):a+="@subvideo=no";const n=this.getSubConfig(t.streamInfo,r);(P.AliRTS.SystenUtil.isIos||P.AliRTS.BrowserUtil.isSafari)&&(n.tcpOnly=!0),n.retryTimes=0,this.encodedInsertableStreams&&(n.encodedInsertableStreams=!0);try{this.startConnect();const o=yield this.rts.subscribe(a,n);return this.setConnected(!0),{traceId:o.traceId,stream:o}}catch(o){throw this.setConnected(!1),o}})}subscribeAdd(e){return S(this,null,function*(){var n,o,u,h;yield this.dcConnectingPromise;const{remoteUser:t,options:r}=e,a=qe(W({url:t.streamUrl,subAudio:!!r.audio,subVideo:!!(r.screen||r.video)},this.getSubConfig(t.streamInfo,r)),{targetStream:r.screen?t.getScreenStream:t.getCameraStream});try{return(yield this.rts.subscribeAdd([a]))[0]}catch(l){if(((h=(u=(o=(n=l==null?void 0:l.extraInfo)==null?void 0:n.parsedData)==null?void 0:o.streams)==null?void 0:u[0])==null?void 0:h.res_code)===508)return this.emit("subscribeexceeds"),null;throw A.fromError(l)}return null})}subscibeDelete(e){return S(this,null,function*(){var n,o,u,h;yield this.dcConnectingPromise;const{remoteUser:t,options:r}=e,a=qe(W({url:t.streamUrl,subAudio:!!r.audio,subVideo:!!(r.screen||r.video)},this.getSubConfig(t.streamInfo,r)),{targetStream:r.screen?t.getScreenStream:t.getCameraStream});try{return(yield this.rts.subscribeDeleteTracks([a]))[0]}catch(l){if(((h=(u=(o=(n=l==null?void 0:l.extraInfo)==null?void 0:n.parsedData)==null?void 0:o.streams)==null?void 0:u[0])==null?void 0:h.res_code)===404)return;throw l}})}subscibeStop(e){return S(this,null,function*(){var t,r,a,n;try{yield this.rts.subscribeStop([{url:e}])}catch(o){if(((n=(a=(r=(t=o==null?void 0:o.extraInfo)==null?void 0:t.parsedData)==null?void 0:r.streams)==null?void 0:a[0])==null?void 0:n.res_code)===404)return;throw o}})}publish(e,t=!1){return S(this,null,function*(){let r="";if(this.connecting&&(yield this.connectingPromise),this.connected){yield this.dcConnectingPromise;let a=!1,n;const{audio:o,video:u,videoSmall:h,screen:l}=this.localStreamManager.publishStreams;o&&(r=yield this.publishAdd(e,o,{aMsid:R.Audio},t),a=!0,n=R.Audio,yield Oe(100)),u&&(r=yield this.publishAdd(e,u,{vMsid:R.VideoLarge},t),a=!1,n=R.VideoLarge,yield Oe(100)),h&&(r=yield this.publishAdd(e,h,{vMsid:R.VideoSmall},t),a=!1,n=R.VideoSmall,yield Oe(100)),l&&(r=yield this.publishAdd(e,l,{isScreen:!0,vMsid:R.Screen},t),a=!1,n=R.Screen),n&&(yield this.waitPublishSender(e,a,n))}else r=yield this.httpPublish(e,t);return r})}subscribe(e){return S(this,null,function*(){const{options:t}=e;if(t.video&&t.screen)throw new A(T.ERR_INNER,"subscribe error, video and screen cannot be subscribed at the same time");this.connecting&&(yield this.connectingPromise);let r;return this.connected?(yield this.dcConnectingPromise,r=yield this.subscribeAdd(e)):r=yield this.httpSubscribe(e),r})}getSubscribeVideoStats(e,t){return S(this,null,function*(){return yield this.rts.getSubscribeVideoStats(e,t)})}getSubscribeAudioStats(e,t){return S(this,null,function*(){return yield this.rts.getSubscribeAudioStats(e,t)})}sendSEI(e,t,r,a){return S(this,null,function*(){return this.rts.sendSEI({url:e,vMsid:R.VideoLarge,data:t,repeatCount:r,payloadType:a})})}},c(Ie,"logName","RtsManager"),Ie);ce([b()],ae.prototype,"updatePublishingTracks",1),ce([b(I,I)],ae.prototype,"httpPublish",1),ce([b(I,I)],ae.prototype,"waitPublishSender",1),ce([b(([i,s,e])=>[i,JSON.stringify(e)],I)],ae.prototype,"publishAdd",1),ce([b(I,I)],ae.prototype,"publishDelete",1),ce([b(([i,s,e])=>[i,JSON.stringify(e)])],ae.prototype,"publishReplace",1),ce([b(I)],ae.prototype,"publishStop",1),ce([b()],ae.prototype,"unpublish",1),ce([b(wt,({traceId:i})=>i)],ae.prototype,"httpSubscribe",1),ce([b(wt,({traceId:i})=>i)],ae.prototype,"subscribeAdd",1),ce([b(wt)],ae.prototype,"subscibeDelete",1),ce([b(I)],ae.prototype,"subscibeStop",1),ce([b(I)],ae.prototype,"publish",1),ce([b(wt)],ae.prototype,"subscribe",1),ce([b()],ae.prototype,"sendSEI",1);let Ur=ae;class oi{constructor(){c(this,"profile");c(this,"profileMap",new Map);c(this,"audioProfile");c(this,"contentHint")}updateProfile(s,e){e&&this.profileMap.set(s,e),this.profile=s}get videoProfile(){return this.profile}updateAudioProfile(s){this.audioProfile=s}setContentHint(s,e){e&&(this.contentHint=e),this.contentHint&&s&&(s.contentHint=this.contentHint)}setVideoProfile(s,e,t=!1){return S(this,null,function*(){if(!this.profile)return;const r=this.profileMap.get(this.profile)||(e==null?void 0:e.VideoProfileMap.get(this.profile));if(r){if(!t&&s&&s.applyConstraints)try{yield s.applyConstraints(r)}catch(a){}e&&(e==null||e.VideoProfileMap.set(this.profile,r),yield e.setVideoProfile(this.profile))}})}}class ci extends J{constructor(e){super();c(this,"type");c(this,"originVideoTrack");c(this,"videoSource");c(this,"_videoMuted",!1);c(this,"originAudioTrack");c(this,"audioSource");c(this,"_audioMuted",!1);c(this,"_targetVideoTrack");c(this,"_targetDualVideoTrack");c(this,"_targetAudioTrack");c(this,"_publishVideoStream");c(this,"_publishDualVideoStream");c(this,"_publishAudioStream");c(this,"_previewStream");c(this,"plugins",[]);c(this,"_profileManager");c(this,"cameraVideoConstraints");c(this,"micAudioConstraints");c(this,"onVideoTrackEnded",()=>{this.emit("videotrackended")});c(this,"onAudioTrackEnded",()=>{this.emit("audiotrackended")});this.type=e}get profileManager(){return this._profileManager}get audioProfile(){var e;return(e=this.profileManager)==null?void 0:e.audioProfile}updateSource(e,t,r){return S(this,null,function*(){var o,u,h,l;const{videoTrack:a,audioTrack:n}=e;if(a&&!t&&t!==_e.Camera)throw new A(T.ERR_INNER,"VideoStreamSource is required");if(n&&!r&&r!==pt.Microphone)throw new A(T.ERR_INNER,"AudioStreamSource is required");a&&((o=this.originVideoTrack)==null||o.removeEventListener("ended",this.onVideoTrackEnded)),n&&((u=this.originAudioTrack)==null||u.removeEventListener("ended",this.onAudioTrackEnded)),this.type===Q.AliRtcSdkStreamTypeScreen?this.stop():(a&&((h=this.originVideoTrack)==null||h.stop()),n&&((l=this.originAudioTrack)==null||l.stop())),a&&(this.originVideoTrack=a,this.originVideoTrack.addEventListener("ended",this.onVideoTrackEnded),this.videoSource=t,this.updateVideoTrack(a)),n&&(this.originAudioTrack=n,this.originAudioTrack.addEventListener("ended",this.onAudioTrackEnded),this.audioSource=r,this.updateAudioTrack(n))})}get currentProfile(){var e;return(e=this.profileManager)==null?void 0:e.profile}get currentVideoTrack(){return this._targetVideoTrack}get currentDualVideoTrack(){return this._targetDualVideoTrack}get publishVideoStream(){return this._publishVideoStream}get publishDualVideoStream(){return this._publishDualVideoStream}get currentAudioTrack(){return this._targetAudioTrack}get publishAudioStream(){return this._publishAudioStream}get previewStream(){return this._previewStream}updateVideoTrack(e,t=!1){return S(this,null,function*(){(this._targetVideoTrack!==e||t)&&(this._targetVideoTrack=e)})}updateDualVideoTrack(e,t=!1){return S(this,null,function*(){(this._targetDualVideoTrack!==e||t)&&(this._targetDualVideoTrack=e)})}updateAudioTrack(e,t=!1){return S(this,null,function*(){(this._targetAudioTrack!==e||t)&&(this._targetAudioTrack=e)})}setAudioMuted(e){var t,r;this._audioMuted=e,e?(t=this.publishAudioStream)==null||t.disableAudio():(r=this.publishAudioStream)==null||r.enableAudio()}get isAudioMuted(){return this._audioMuted}setVideoMuted(e){var t,r;this._videoMuted=e,e?(t=this.publishVideoStream)==null||t.disableVideo():(r=this.publishVideoStream)==null||r.enableVideo()}get isVideoMuted(){return this._videoMuted}process(e){return S(this,null,function*(){var t,r,a,n,o,u,h,l,p,d,m,g;this._targetAudioTrack=this.originAudioTrack,this._targetVideoTrack=this.originVideoTrack;for(const f of this.plugins)try{yield f.execute(this,e)}catch(v){console.error(`error in plugin-${f.name}, error: ${v}`)}this._targetVideoTrack?((r=(t=this._publishVideoStream)==null?void 0:t.videoTrack)==null?void 0:r.id)!==this._targetVideoTrack.id&&(this._publishVideoStream=yield it(this._targetVideoTrack),this.setVideoMuted(this._videoMuted),(a=this.profileManager)==null||a.setVideoProfile(this.originVideoTrack,this._publishVideoStream,!0),(n=this.profileManager)==null||n.setContentHint(this._targetVideoTrack),this.previewStream?(o=this.previewStream)==null||o.mergeStream(this._publishVideoStream):this._previewStream=yield it(this._targetVideoTrack)):(this._publishVideoStream=void 0,(u=this.previewStream)==null||u.deleteTracks({video:!0})),this._targetDualVideoTrack?((l=(h=this._publishDualVideoStream)==null?void 0:h.videoTrack)==null?void 0:l.id)!==this._targetDualVideoTrack.id&&(this._publishDualVideoStream=yield it(this._targetDualVideoTrack),this._videoMuted?this._publishDualVideoStream.disableVideo():this._publishDualVideoStream.enableVideo()):this._publishDualVideoStream=void 0,this._targetAudioTrack?((d=(p=this._publishAudioStream)==null?void 0:p.audioTrack)==null?void 0:d.id)!==this._targetAudioTrack.id&&(this._publishAudioStream=yield it(this._targetAudioTrack),this.setAudioMuted(this._audioMuted),this.previewStream?(m=this.previewStream)==null||m.mergeStream(this._publishAudioStream):this._previewStream=yield it(this._targetAudioTrack)):(this._publishAudioStream=void 0,(g=this.previewStream)==null||g.deleteTracks({audio:!0}))})}stopVideo(){var e,t;this.originVideoTrack&&((e=this.originVideoTrack)==null||e.removeEventListener("ended",this.onAudioTrackEnded),(t=this.originVideoTrack)==null||t.stop(),this.originVideoTrack=void 0),this.updateVideoTrack(void 0)}stopAudio(){var e,t;this.originAudioTrack&&((e=this.originAudioTrack)==null||e.removeEventListener("ended",this.onAudioTrackEnded),(t=this.originAudioTrack)==null||t.stop(),this.originAudioTrack=void 0),this.updateAudioTrack(void 0)}stop(){this.stopVideo(),this.stopAudio()}updateVideoProfile(e,t){return S(this,null,function*(){this._profileManager||(this._profileManager=new oi),e&&this._profileManager.updateProfile(e,t),yield this._profileManager.setVideoProfile(this.originVideoTrack,this._publishVideoStream,this.type===Q.AliRtcSdkStreamTypeScreen)})}get videoProfile(){var e;return(e=this.profileManager)==null?void 0:e.videoProfile}setVideoContentHint(e){this._profileManager||(this._profileManager=new oi),this._profileManager.setContentHint(this.currentVideoTrack,e)}updateAudioProfile(e){return S(this,null,function*(){this._profileManager||(this._profileManager=new oi),this._profileManager.updateAudioProfile(e)})}cloneVideoProfile(e){return S(this,null,function*(){var t;yield(t=this.profileManager)==null?void 0:t.setVideoProfile(void 0,e)})}addPlugin(e){const t=this.plugins.findIndex(r=>r.zIndex>e.zIndex);t>-1?this.plugins.splice(t,0,e):this.plugins.push(e)}removePlugin(e){const t=this.plugins.indexOf(e);return t>-1?(e.clear(this),this.plugins.splice(t,1),!0):!1}}var xr=Object.defineProperty,Br=Object.getOwnPropertyDescriptor,Se=(i,s,e,t)=>{for(var r=t>1?void 0:t?Br(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&xr(s,e,r),r};const me=(je=class extends J{constructor(e){super();c(this,"pluginManager");c(this,"publishingCameraVideoStream");c(this,"publishingScreenVideoStream");c(this,"cameraStreamInfo",new ci(Q.AliRtcSdkStreamTypeCapture));c(this,"screenStreamInfo",new ci(Q.AliRtcSdkStreamTypeScreen));c(this,"streamInfos",[this.cameraStreamInfo,this.screenStreamInfo]);c(this,"_audioCaptureDisabled",!1);c(this,"_cameraCaptureDisabled",!1);c(this,"_publishLocalAudioStreamEnabled",!0);c(this,"_publishLocalVideoStreamEnabled",!0);c(this,"_publishLocalScreenStreamEnabled",!0);this.screenStreamInfo.setVideoContentHint("motion"),this.pluginManager=e;const t=r=>S(this,null,function*(){if(w.info(`[${je.logName}]`,"plugin added",r.name),!r.isSupported("6.11.4")){console.warn(`${r.name} is not supported!!!`),r.emit("unsupported");return}try{yield r.init()}catch(a){r.emit("error",A.fromError(a,Ne.AliRtcPluginErrorInitError))}r.streamType===Q.AliRtcSdkStreamTypeCapture&&(this.cameraStreamInfo.addPlugin(r),yield this.cameraStreamInfo.process(this.streamInfos)),r.streamType===Q.AliRtcSdkStreamTypeScreen&&(this.screenStreamInfo.addPlugin(r),yield this.screenStreamInfo.process(this.streamInfos)),this.emit("publishupdate")});this.cameraStreamInfo.updateVideoProfile($i,et),this.cameraStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({video:!0}),this.emit("trackended",Ue.VideoTrackEnded)})),this.cameraStreamInfo.on("audiotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({audio:!0}),this.emit("trackended",Ue.AudioTrackEnded)})),this.screenStreamInfo.updateVideoProfile(Ji,tt),this.screenStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({screen:!0}),this.emit("trackended",Ue.ScreenTrackEnded)})),this.pluginManager.on("added",t),this.pluginManager.on("removed",r=>S(this,null,function*(){this.cameraStreamInfo.removePlugin(r)&&(yield this.cameraStreamInfo.process(this.streamInfos)),this.screenStreamInfo.removePlugin(r)&&(yield this.screenStreamInfo.process(this.streamInfos)),this.emit("publishupdate")})),this.pluginManager.on("updated",()=>S(this,null,function*(){yield this.updateStreams()}))}get hasCamera(){return!!this.cameraStreamInfo.originVideoTrack}get audioCaptureDisabled(){return this._audioCaptureDisabled}set audioCaptureDisabled(e){this._audioCaptureDisabled=e}get cameraCaptureDisabled(){return this._cameraCaptureDisabled}setAudioMuted(e){this.cameraStreamInfo.setAudioMuted(e)}get isAudioMuted(){return this.cameraStreamInfo.isAudioMuted}setCameraMuted(e){this.cameraStreamInfo.setVideoMuted(e)}get isCameraMuted(){return this.cameraStreamInfo.isVideoMuted}setScreenMuted(e){this.screenStreamInfo.setVideoMuted(e)}get isScreenMuted(){return this.screenStreamInfo.isVideoMuted}set cameraCaptureDisabled(e){this._cameraCaptureDisabled=e}get publishLocalAudioStreamEnabled(){return this._publishLocalAudioStreamEnabled}set publishLocalAudioStreamEnabled(e){this._publishLocalAudioStreamEnabled=e}get publishLocalVideoStreamEnabled(){return this._publishLocalVideoStreamEnabled}set publishLocalVideoStreamEnabled(e){this._publishLocalVideoStreamEnabled=e}get publishLocalScreenStreamEnabled(){return this._publishLocalScreenStreamEnabled}set publishLocalScreenStreamEnabled(e){this._publishLocalScreenStreamEnabled=e}updateStreams(){return S(this,null,function*(){yield this.cameraStreamInfo.process(this.streamInfos),yield this.screenStreamInfo.process(this.streamInfos),this.emit("publishupdate")})}setAvailableCameraDeviceId(){return S(this,null,function*(){var e,t,r,a;if((e=this.cameraStreamInfo.cameraVideoConstraints)!=null&&e.deviceId){let n=(t=this.cameraStreamInfo.cameraVideoConstraints)==null?void 0:t.deviceId;const o=yield P.AliRTS.getCameraList();o.find(u=>u.deviceId===n)||(n=(a=(r=o.find(u=>!!u.deviceId))==null?void 0:r.deviceId)!=null?a:""),this.cameraStreamInfo.cameraVideoConstraints.deviceId=n}})}setAvailableMicrophoneDeviceId(){return S(this,null,function*(){var e,t,r,a;if((e=this.cameraStreamInfo.micAudioConstraints)!=null&&e.deviceId){let n=(t=this.cameraStreamInfo.micAudioConstraints)==null?void 0:t.deviceId;const o=yield P.AliRTS.getMicList();o.find(u=>u.deviceId===n)||(n=(a=(r=o.find(u=>!!u.deviceId))==null?void 0:r.deviceId)!=null?a:""),this.cameraStreamInfo.micAudioConstraints.deviceId=n}})}createLocalStream(e){return S(this,null,function*(){const{screen:t,mediaStream:r,videoProfile:a,screenProfile:n}=e;let{video:o,audio:u}=e;const h=Ar(e);let l;if(h){if(o===!0&&this.cameraStreamInfo.cameraVideoConstraints?(yield this.setAvailableCameraDeviceId(),o=W({},this.cameraStreamInfo.cameraVideoConstraints)):typeof o=="object"&&(yield this.setAvailableCameraDeviceId(),o=W(W({},o),this.cameraStreamInfo.cameraVideoConstraints)),u===void 0&&this.audioCaptureDisabled?u=!1:u&&(u===!0&&this.cameraStreamInfo.micAudioConstraints?(yield this.setAvailableMicrophoneDeviceId(),u=W({},this.cameraStreamInfo.micAudioConstraints)):typeof u=="object"&&(yield this.setAvailableMicrophoneDeviceId(),u=W(W({},u),this.cameraStreamInfo.micAudioConstraints)),this._audioCaptureDisabled=!1),l=yield P.AliRTS.createStream({audio:u,video:o,screen:t,custom:!!r,mediaStream:r,skipProfile:!0}),t)yield this.screenStreamInfo.updateSource(l,_e.Screen,pt.Screen),yield this.setScreenProfile(n),this.setScreenContentHint(),this.publishingScreenVideoStream=void 0;else if(yield this.cameraStreamInfo.updateSource(l,_e.Camera,pt.Microphone),l.hasVideo&&(yield this.setVideoProfile(a),this.setVideoContentHint(),this.publishingCameraVideoStream=void 0),l.hasAudio&&typeof u=="boolean"){const p=this.cameraStreamInfo.audioProfile;p&&(yield l.setAudioProfile(p))}}return P.AliRTS.SystenUtil.isIos&&P.AliRTS.SystenUtil.compareVersion("15.1")&&!P.AliRTS.SystenUtil.compareVersion("15.2")&&(yield Oe(1e3)),yield this.updateStreams(),l})}stopLocalStream(e){return S(this,null,function*(){const{screen:t,video:r,audio:a}=e!=null?e:{};let n=!1;r&&this.cameraStreamInfo.originVideoTrack&&(n=!0,this.cameraStreamInfo.stopVideo(),this.publishingCameraVideoStream=void 0),a&&this.cameraStreamInfo.originAudioTrack&&(n=!0,this.cameraStreamInfo.stopAudio()),t&&this.screenStreamInfo.originVideoTrack&&(n=!0,this.screenStreamInfo.stop(),this.publishingScreenVideoStream=void 0),n&&(yield this.updateStreams())})}get publishStreams(){const{publishLocalVideoStreamEnabled:e,publishLocalAudioStreamEnabled:t,publishLocalScreenStreamEnabled:r}=this;return{video:e?this.cameraStreamInfo.publishVideoStream:void 0,videoSmall:e?this.cameraStreamInfo.publishDualVideoStream:void 0,audio:t?this.cameraStreamInfo.publishAudioStream:void 0,screen:r?this.screenStreamInfo.publishVideoStream:void 0}}createHTTPPublishStream(){return S(this,null,function*(){var u,h,l,p;let e,t=!1,r,a,n;const o=yield this.publishStreams;try{if(!o.audio&&!o.video&&!o.videoSmall&&!o.screen)throw new A(T.ERR_SDK_PUBLISH_INVAILD,"no tracks founded");const d=new MediaStream;(u=o.audio)!=null&&u.audioTrack&&d.addTrack(o.audio.audioTrack),(h=o.video)!=null&&h.videoTrack?(d.addTrack(o.video.videoTrack),a=o.videoSmall,n=o.screen):(l=o.screen)!=null&&l.videoTrack&&(r=R.Screen,d.addTrack((p=o.screen)==null?void 0:p.videoTrack),t=!0),e=yield zi(d),t?(this.screenStreamInfo.cloneVideoProfile(e),this.publishingScreenVideoStream=e):(this.cameraStreamInfo.cloneVideoProfile(e),this.publishingCameraVideoStream=e)}catch(d){}return{publishStream:e,videoSmallStream:a,screenStream:n,vMsid:r}})}stop(){this.cameraStreamInfo.stop(),this.screenStreamInfo.stop()}setVideoProfile(e,t){return S(this,null,function*(){yield this.cameraStreamInfo.updateVideoProfile(e,t),this.publishingCameraVideoStream&&this.cameraStreamInfo.cloneVideoProfile(this.publishingCameraVideoStream)})}setVideoContentHint(e){this.cameraStreamInfo.setVideoContentHint(e)}setAudioProfile(e){return S(this,null,function*(){var t;yield this.cameraStreamInfo.updateAudioProfile(e),yield(t=this.publishingCameraVideoStream)==null?void 0:t.setAudioProfile(e)})}setScreenProfile(e,t){return S(this,null,function*(){yield this.screenStreamInfo.updateVideoProfile(e,t),this.publishingScreenVideoStream&&this.screenStreamInfo.cloneVideoProfile(this.publishingScreenVideoStream)})}setScreenContentHint(e){this.screenStreamInfo.setVideoContentHint(e)}setCameraVideoConstraints(e){var t;this.cameraStreamInfo.cameraVideoConstraints=W(W({},(t=this.cameraStreamInfo.cameraVideoConstraints)!=null?t:{}),e)}setMicAudioConstraints(e){var t;this.cameraStreamInfo.micAudioConstraints=W(W({},(t=this.cameraStreamInfo.micAudioConstraints)!=null?t:{}),e)}},c(je,"logName","LocalStreamManager"),je);Se([b(([i])=>{const{audio:s,video:e,screen:t,custom:r,skipProfile:a,videoProfile:n,screenProfile:o}=i;return[{audio:s,video:e,screen:t,custom:r,skipProfile:a,videoProfile:n,screenProfile:o}]})],me.prototype,"createLocalStream",1),Se([b(I)],me.prototype,"stopLocalStream",1),Se([b()],me.prototype,"createHTTPPublishStream",1),Se([b()],me.prototype,"stop",1),Se([b(I)],me.prototype,"setVideoProfile",1),Se([b(I)],me.prototype,"setVideoContentHint",1),Se([b(I)],me.prototype,"setAudioProfile",1),Se([b(I)],me.prototype,"setScreenProfile",1),Se([b(I)],me.prototype,"setScreenContentHint",1),Se([b(I)],me.prototype,"setCameraVideoConstraints",1),Se([b(I)],me.prototype,"setMicAudioConstraints",1);let Fr=me;var Hr=Object.defineProperty,Wr=Object.getOwnPropertyDescriptor,fe=(i,s,e,t)=>{for(var r=t>1?void 0:t?Wr(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Hr(s,e,r),r};class le extends J{constructor(e){super();c(this,"self");c(this,"userMap",{});c(this,"usersViewMap",{});c(this,"rtsManager");c(this,"localStreamManager");c(this,"authInfo");c(this,"signalingManager");c(this,"pluginManager");c(this,"reporter");c(this,"webTrackingClient");c(this,"statsMonitorId");c(this,"autoSubAudio",!0);c(this,"autoSubVideo",!0);c(this,"autoSubScreen",!0);c(this,"wantSubAudio",!0);c(this,"wantSubVideo",!0);c(this,"wantSubScreen",!0);c(this,"defaultStreamType",oe.AliRtcVideoStreamTypeHigh);c(this,"audioMuted",!1);c(this,"audioVolumeIndicationInterval",0);c(this,"indicationTimer",0);const{signalingManager:t,reporter:r,webTrackingClient:a}=e;this.signalingManager=t,this.addSignalingManagerListener(),this.reporter=r,this.webTrackingClient=a,this.pluginManager=new Vr,this.localStreamManager=new Fr(this.pluginManager),this.rtsManager=new Ur(this.localStreamManager),this.self=new z({rtsManager:this.rtsManager,localStreamManager:this.localStreamManager,reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager,pluginManager:this.pluginManager,audioVolumeIndicationInterval:this.audioVolumeIndicationInterval})}addSignalingManagerListener(){this.signalingManager.on("onNotifyPublish",e=>{w.event("[Signaling] Notify Publish ",e),e.forEach(t=>{this.onRemotePublishStateChange(t)})})}isAutoSubAudio(){return this.autoSubAudio}setAutoSubAudio(e){this.autoSubAudio=e}isAutoSubVideo(){return this.autoSubVideo}setAutoSubVideo(e){this.autoSubVideo=e}isAutoSubScreen(){return this.autoSubScreen}setAutoSubScreen(e){this.autoSubScreen=e}isWantSubAudio(){return this.wantSubAudio}setWantSubAudio(e){this.wantSubAudio=e,this.remoteUsers.forEach(t=>{t.setWantSubAudio(e),t.updateSubscribe()})}isWantSubVideo(){return this.wantSubVideo}setWantSubVideo(e){this.wantSubVideo=e,this.remoteUsers.forEach(t=>{t.setWantSubVideo(e),t.updateSubscribe()})}isWantSubScreen(){return this.wantSubScreen}setWantSubScreen(e){this.wantSubScreen=e,this.remoteUsers.forEach(t=>{t.setWantSubScreen(e),t.updateSubscribe()})}setRemoteDefaultVideoStreamType(e){this.defaultStreamType=e,this.remoteUsers.forEach(t=>{t.setRemoteDefaultVideoStreamType(e)})}setAudioMuted(e){this.audioMuted=e,this.remoteUsers.forEach(t=>{t.setAudioMuted(e)})}setLocalViewConfig(e,t){var a;if(!e)return(a=this.publisher)==null?void 0:a.setViewConfig(null,t);const r=ni(e);r.length!==0&&r.forEach(n=>{var o,u;(o=this.publisher)==null||o.resetElement(n),Object.values(this.usersViewMap).forEach(({cameraViews:h=[],screenViews:l=[]})=>{h.includes(n)&&h.splice(h.indexOf(n),1),l.includes(n)&&l.splice(l.indexOf(n),1)}),(u=this.publisher)==null||u.setViewConfig(r,t)})}setRemoteViewConfig(e,t,r){var n,o;if(!t)return(n=this.userMap[e])==null?void 0:n.setViewConfig(null,r);const a=ni(t);a.length!==0&&(a.forEach(u=>{var h;(h=this.publisher)==null||h.resetElement(u),Object.values(this.usersViewMap).forEach(({cameraViews:l=[],screenViews:p=[]})=>{l.includes(u)&&l.splice(l.indexOf(u),1),p.includes(u)&&p.splice(p.indexOf(u),1)})}),(o=this.userMap[e])==null||o.setViewConfig(a,r))}get channel(){var e;return(e=this.authInfo)==null?void 0:e.channelId}get userId(){var e;return(e=this.authInfo)==null?void 0:e.userId}get remoteUsers(){return Object.values(this.userMap)}get publisher(){return this.self}get isSubscribing(){var e;return((e=this.remoteUsers)!=null?e:[]).some(t=>{var u;const{isAudioSubscribing:r,isVideoLargeSubscribing:a,isVideoSmallSubscribing:n,isScreenSubscribing:o}=(u=t.streamInfo)!=null?u:{};return r||a||n||o})}onRemotePublishStateChange(e){var d;const{userid:t,callid:r,subscribe:a,pubid:n="",tracks:o}=e,u=(d=a==null?void 0:a.pullstreamurl)!=null?d:"";let h=this.getRemoteUser(t);if(!h)return;const l=h.streamInfo.audioTrackInfo,p=h.streamInfo.videoTrackInfo;h.updateRemoteTracks(r,u,n,o),h.updateSubscribe(),(l!==h.streamInfo.audioTrackInfo||p!==h.streamInfo.videoTrackInfo)&&this.emit("remoteTrackAvailableChange",t,h.streamInfo.audioTrackInfo,h.streamInfo.videoTrackInfo)}init(e,t){var r;this.authInfo=e,this.self||(this.self=new z({rtsManager:this.rtsManager,localStreamManager:this.localStreamManager,reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager,pluginManager:this.pluginManager,audioVolumeIndicationInterval:this.audioVolumeIndicationInterval})),this.self.enableAudioVolumeIndication(this.audioVolumeIndicationInterval),(r=this.self)==null||r.initInfo(e,t.pushstreamurl),t.users.forEach(a=>{const n=a.userid;if(n){const o=this.addUser(n,a.displayname),{callid:u,subscribe:h,tracks:l}=a;o.updateRemoteTracks(u,(h==null?void 0:h.pullstreamurl)||"","",l),this.emit("remoteTrackAvailableChange",n,o.streamInfo.audioTrackInfo,o.streamInfo.videoTrackInfo)}}),this.startStatsMonitor()}clear(){return S(this,null,function*(){var e;this.stopStatsMonitor();for(let t in this.userMap)this.userMap[t]&&(yield this.userMap[t].clear(),delete this.userMap[t]);yield(e=this.self)==null?void 0:e.clear(),this.authInfo=void 0})}startStatsMonitor(){this.statsMonitorId=window.setInterval(()=>S(this,null,function*(){if(this.publisher){const{audio:r,video:a}=yield this.publisher.getStats();r&&r.length>0&&this.emit("rtcLocalAudioStats",r),a&&a.length>0&&this.emit("rtcLocalVideoStats",a)}const e=[],t=[];for(const r of this.remoteUsers){const{audio:a,video:n}=yield r.getStats();a&&a.forEach(o=>{e.push(o)}),n&&n.forEach(o=>{t.push(o)})}e.length>0&&this.emit("rtcRemoteAudioStats",e),t.length>0&&this.emit("rtcRemoteVideoStats",t)}),2e3)}stopStatsMonitor(){this.statsMonitorId&&clearInterval(this.statsMonitorId)}getUser(e,t){return this.addUser(e,t),this.userMap[e]}addUser(e,t){return this.userMap[e]||(this.userMap[e]=this.executeAddUser(e,t)),this.userMap[e]}executeAddUser(e,t){var a;const r=new Y({userId:e,displayName:t,rtsManager:this.rtsManager,signalingManager:this.signalingManager,usersViewMap:this.usersViewMap,reporter:this.reporter,webTrackingClient:this.webTrackingClient,localUserId:(a=this.userId)!=null?a:"",audioVolumeIndicationInterval:this.audioVolumeIndicationInterval});return r.on(ie.Remote,this.onRemoteDeviceStatusChange.bind(this)),r.on(H.PullStreamStats,this.onRemoteStatReport.bind(this)),r.on(H.RtsSubscribeExceeds,this.onSubscribeExceeds.bind(this)),r.on("audioSubscribeStateChanged",(n,o,u,h)=>{this.emit("audioSubscribeStateChanged",n,o,u,h,this.channel||"")}),r.on("videoSubscribeStateChanged",(n,o,u,h)=>{this.emit("videoSubscribeStateChanged",n,o,u,h,this.channel||"")}),r.on("screenSubscribeStateChanged",(n,o,u,h)=>{this.emit("screenSubscribeStateChanged",n,o,u,h,this.channel||"")}),r.on("remoteAudioAutoPlayFail",n=>{this.emit("remoteAudioAutoPlayFail",n)}),r.on("remoteVideoAutoPlayFail",(n,o)=>{this.emit("remoteVideoAutoPlayFail",n,o)}),r.on("remoteSubscribeError",n=>{this.emit("remoteSubscribeError",n)}),r.setWantSubAudio(this.autoSubAudio&&this.wantSubAudio),r.setWantSubVideo(this.autoSubVideo&&this.wantSubVideo),r.setWantSubScreen(this.autoSubScreen&&this.wantSubScreen),r.setRemoteDefaultVideoStreamType(this.defaultStreamType),r.setAudioMuted(this.audioMuted),(this.autoSubAudio||this.autoSubVideo||this.autoSubScreen)&&r.updateSubscribe(),r}onRemoteDeviceStatusChange(e,t){e===H.MuteAudio?this.emit("userAudioMuted",t,!0):e===H.UnmuteAudio?this.emit("userAudioMuted",t,!1):e===H.MuteVideo?this.emit("userVideoMuted",t,!0):e===H.UnmuteVideo?this.emit("userVideoMuted",t,!1):e===H.MuteScreen?this.emit("userScreenMuted",t,!0):e===H.UnmuteScreen&&this.emit("userScreenMuted",t,!1)}onRemoteStatReport(e,t,r){this.emit(H.PullStreamStats,e,t,r)}onSubscribeExceeds(e,t){this.emit(H.RtsSubscribeExceeds,e,t)}removeLeftUser(e){return S(this,null,function*(){e.userid&&this.userMap[e.userid]&&(yield this.userMap[e.userid].clear(!1),delete this.userMap[e.userid])})}updateUsers(e){const t=[],r=[],a={};e.forEach(u=>{u.userid&&(this.userMap[u.userid]?(r.push(u),a[u.userid]=this.userMap[u.userid]):(t.push(u),a[u.userid]=this.executeAddUser(u.userid,u.displayname)))});const n=Object.keys(this.userMap),o=[];return n.forEach(u=>{a[u]||o.push({userid:u,reason:"",leavecode:ii.AliRtcUserOfflineQuit})}),this.userMap=a,{joinList:t,leaveList:o,presentList:r}}getRemoteUser(e){return this.userMap[e]}updateRemoteUserDeviceStatus(e){e&&e.userid&&this.userMap[e.userid]&&this.userMap[e.userid].updateRemoteUserDeviceStatus(e.status)}updateAudioWant(e,t){const r=this.userMap[e];if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.setWantSubAudio(t),t?r.updateSubscribe():r.stopSubscribe({audio:!0})}updateVideoWant(e,t){const r=this.userMap[e];if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.setWantSubVideo(t),t?r.updateSubscribe():r.stopSubscribe({video:!0})}updateScreenWant(e,t){const r=this.userMap[e];if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.setWantSubScreen(t),t?r.updateSubscribe():r.stopSubscribe({screen:!0})}stopIndication(){this.indicationTimer&&window.clearInterval(this.indicationTimer)}startIndication(e){this.stopIndication(),this.indicationTimer=window.setInterval(()=>{var r;const t=this.remoteUsers.map(a=>({userId:a.userId,volume:a.getAudioLevel()||0}));t.unshift({userId:"",volume:((r=this.self)==null?void 0:r.getAudioLevel())||0}),this.emit("audioVolume",t)},e)}enableAudioVolumeIndication(e){var t;this.audioVolumeIndicationInterval!==e&&(this.audioVolumeIndicationInterval>0&&e<=0&&this.stopIndication(),e>0&&this.startIndication(e),this.audioVolumeIndicationInterval=e,this.remoteUsers.forEach(r=>{r.enableAudioVolumeIndication(e)}),(t=this.self)==null||t.enableAudioVolumeIndication(e))}refreshAuthInfo(e){var t;this.authInfo&&(this.authInfo=W(W({},this.authInfo),e)),e.userId&&((t=this.self)==null||t.refreshUserInfo(e.userId))}setEnableMediaExtensionMsg(e){this.rtsManager.setEncodedInsertableStreams(e)}}c(le,"logName","UserManager"),fe([b()],le.prototype,"init",1),fe([b()],le.prototype,"clear",1),fe([b(I)],le.prototype,"addUser",1),fe([b()],le.prototype,"removeLeftUser",1),fe([b()],le.prototype,"updateUsers",1),fe([b(I)],le.prototype,"updateAudioWant",1),fe([b(I)],le.prototype,"updateVideoWant",1),fe([b(I)],le.prototype,"updateScreenWant",1),fe([b()],le.prototype,"stopIndication",1),fe([b()],le.prototype,"startIndication",1),fe([b()],le.prototype,"enableAudioVolumeIndication",1);const ui=i=>S(this,null,function*(){const s=new Uint8Array(160).fill(170),e=new TextEncoder().encode(i),t=yield window.crypto.subtle.importKey("raw",s,{name:"HMAC",hash:{name:"SHA-1"}},!1,["sign"]),r=yield window.crypto.subtle.sign("HMAC",t,e);return Array.from(new Uint8Array(r)).map(a=>a.toString(16).padStart(2,"0")).join("")});class Kr{constructor(){c(this,"authInfo")}doRequest(s,e){var h;const t=this.authInfo;if(!t)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const r="https://gw.rtn.aliyuncs.com",a=ur[s],n={appid:t.appId,userid:t.userId,channelid:t.channelId,timestamp:t.timestamp,token:t.token,nonce:t.nonce?t.nonce:"",requestid:ye.createCallid(),tokensid:!1,session:(h=t.callid)!=null?h:ye.createCallid()},o=Object.keys(n).map(l=>`${l}=${encodeURIComponent(n[l])}`).join("&"),u=`${r}${a}?${o}`;return fetch(u,{method:"POST",headers:{"Content-Type":"application/json; charset=UTF-8"},body:e}).then(l=>l.status!==200?Promise.reject(new A(T.ERR_INNER,`transcoding request failed, status: ${l.status}`)):l)}setAuthInfo(s){this.authInfo=s}clear(){this.authInfo=void 0}startPublishLiveStream(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=yield ui(s.split("?")[0]),r=ue.MPU_TASK_TRANSACTION_UPDATE,a=e.toJson(r,this.authInfo,t,s);return this.doRequest(r,JSON.stringify(a))})}startPublishLiveStreamWithTaskId(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=ue.MPU_TASK_TRANSACTION_UPDATE,r=e.toJson(t,this.authInfo,s);return this.doRequest(t,JSON.stringify(r))})}updatePublishLiveStream(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=yield ui(s.split("?")[0]),r=ue.MPU_TASK_TRANSACTION_UPDATE,a=e.toJson(r,this.authInfo,t,s);return this.doRequest(r,JSON.stringify(a))})}updatePublishLiveStreamWithTaskId(s,e){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const t=ue.MPU_TASK_TRANSACTION_UPDATE,r=e.toJson(t,this.authInfo,s);return this.doRequest(t,JSON.stringify(r))})}stopPublishLiveStream(s){return S(this,null,function*(){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const e=yield ui(s.split("?")[0]),t=ue.MPU_TASK_TRANSACTION_STOP,r=new bt().toJson(t,this.authInfo,e,s);return this.doRequest(t,JSON.stringify(r))})}stopPublishLiveStreamWithTaskId(s){if(!this.authInfo)return Promise.reject(Re.LiveTranscodingErrorInvalidParam);const e=ue.MPU_TASK_TRANSACTION_STOP,t=new bt().toJson(e,this.authInfo,s);return this.doRequest(e,JSON.stringify(t))}refreshAuthInfo(s){this.authInfo&&this.setAuthInfo(W(W({},this.authInfo),s))}}var Xi=(i,s,e)=>{if(!s.has(i))throw TypeError("Cannot "+e)},It=(i,s,e)=>(Xi(i,s,"read from private field"),e?e.call(i):s.get(i)),hi=(i,s,e)=>{if(s.has(i))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(i):s.set(i,e)},li=(i,s,e,t)=>(Xi(i,s,"write to private field"),t?t.call(i,e):s.set(i,e),e),jr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},E={},xe={};const $r="SLS_CLIENT";var Zi=(i=>(i.ERROR="error",i.LOG="log",i.LOCATION="pv",i.API="api",i.RESOURCE="res",i.RESOURCE_ERROR="res_err",i.PERF="perf",i.CONSOLE_LOG="console",i))(Zi||{}),Qi=(i=>(i.LOG_SEND="LOG_SEND",i.BROWSER_SEND="BROWSER_SEND",i.BASE_TRANSFORM="BASE_TRANSFORM",i.BROWSER_BASE_TRANSFORM="BROWSER_BASE_TRANSFORM",i.BROWSER_FETCH="BROWSER_FETCH",i.BROWSER_XHR="BROWSER_XHR",i.BROWSER_LOCATION="BROWSER_LOCATION",i.BROWSER_RUNTIME_ERROR="BROWSER_RUNTIME_ERROR",i.BROWSER_CUSTOM_ERROR="BROWSER_CUSTOM_ERROR",i.BROWSER_RESOURCE_ERROR="BROWSER_RESOURCE_ERROR",i.BROWSER_CONSOLE="BROWSER_CONSOLE",i.BROWSER_PERF="BROWSER_PERF",i.BROWSER_RESOURSE="BROWSER_RESOURSE",i.MINI_SEND="MINI_SEND",i.MINI_REQUEST="MINI_REQUEST",i.MINI_BASE_TRANSFORM="MINI_BASE_TRANSFORM",i.MINI_ROUTE="MINI_ROUTE",i))(Qi||{});const Jr={BROWSER_SEND:-1,MINI_SEND:-2,BASE_TRANSFORM:100,BROWSER_BASE_TRANSFORM:100*2,MINI_BASE_TRANSFORM:100*2+1,BROWSER_PERF:100*3+1,BROWSER_FETCH:100*4,BROWSER_XHR:100*4+1,MINI_REQUEST:100*4+2,BROWSER_RUNTIME_ERROR:100*5},qr="sls-trace-uid";var es=(i=>(i.OK="OK",i.ERROR="ERROR",i.UNSET="UNSET",i))(es||{});xe.InternalPlugin=Qi,xe.InternalPluginPriority=Jr,xe.OTStatusCode=es,xe.SLS_CLIENT_NAME=$r,xe.SLS_TRACE_UID_KEY=qr,xe.WebEventType=Zi;var be=xe;function di(i,s,e){Object.defineProperty(i,s,{writable:!0,enumerable:!0,configurable:!0,value:e})}function Gr(i,s,e,t){t?t(()=>{di(i,s,e)}):di(i,s,e)}class zr{constructor(s){this.onFirstSubscribe=s,this.observers=[]}subscribe(s){return!this.observers.length&&this.onFirstSubscribe&&(this.onLastUnsubscribe=this.onFirstSubscribe()||void 0),this.observers.push(s),{unsubscribe:()=>{this.observers=this.observers.filter(e=>s!==e),!this.observers.length&&this.onLastUnsubscribe&&this.onLastUnsubscribe()}}}notify(s){this.observers.forEach(e=>e(s))}}function rt(i,s,e){try{return i.apply(s,e)}catch(t){return}}function Yr(i){return function(){return rt(i,this,arguments)}}let Xr=!1;function Zr(){return Xr}function ts(...i){}var Qr=Object.defineProperty,ea=Object.defineProperties,ta=Object.getOwnPropertyDescriptors,is=Object.getOwnPropertySymbols,ia=Object.prototype.hasOwnProperty,sa=Object.prototype.propertyIsEnumerable,ss=(i,s,e)=>s in i?Qr(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,ra=(i,s)=>{for(var e in s||(s={}))ia.call(s,e)&&ss(i,e,s[e]);if(is)for(var e of is(s))sa.call(s,e)&&ss(i,e,s[e]);return i},aa=(i,s)=>ea(i,ta(s));const rs=1e3,as=60*rs,ns=60*as,os=24*ns,cs=365*os,na=1024,us="0.1.0";function oa(){}function hs(i){return typeof i=="number"}function ca(i){return Object.prototype.toString.call(i)==="[object String]"}function ua(i){return Object.prototype.toString.call(i)==="[object Error]"}function ls(i,s){return+i.toFixed(s)}function ha(i,s){return i.indexOf(s)!==-1}function la(i,s){return i==null?s:!!i}function At(i){return i?(parseInt(i,10)^Math.random()*16>>parseInt(i,10)/4).toString(16):`10000000-1000-4000-8000-${1e11}`.replace(/[018]/g,At)}function ds(i=20){var s,e;const t=new Array(i),r=Date.now().toString(36).split("");for(;i-- >0;)e=(s=36*Math.random()|0).toString(36),t[i]=s%3?e:e.toUpperCase();for(var a=0;a<8;a++)t.splice(3*a+2,0,r[a]);return t.join("")}function da(i){return i!==0&&Math.random()<=i}function Tt(i,s){return(...e)=>{try{return i(...e)}catch(t){console.error(s,t)}}}function ps(i){return"https://"+i.project+"."+i.host+"/logstores/"+i.logstore+"/track"}function pa(i,s){return s?i.includes(ps(s)):i.includes("/track?APIVersion=0.6.0")}const ms=/^(?:([^:\/?#]+):\/\/)?((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i;function ma(i){try{return decodeURIComponent(i)}catch(s){return unescape(i)}}function ga(i){return typeof i=="string"&&ms.test(i)}function Sa(i){var s=ma(i||"").match(ms);if(s==null)return null;var e=(s[3]||"").split(":"),t=e.length?(s[2]||"").replace(/(.*\@)/,""):s[2];return{uri:s[0],protocol:s[1],host:t,hostname:s[4],port:s[5],auth:s[3],user:e[0],password:e[1],path:s[6],search:s[7],hash:s[8]}}function fa(i,s,e,t){const r={url:i,method:s,status_code:e};return t==null?r:aa(ra({},r),{host:t.host,scheme:t.protocol})}function ba(i,s,...e){return s==null||!Array.isArray(s)?!1:s.some(t=>{if(typeof t=="function")try{return t(i,...e)}catch(r){return console.error("user function callback threw an error:",r),!1}return typeof t=="string"?i.includes(t):Object.prototype.toString.call(t)==="[object RegExp]"?t.test(i):!1})}function va(i,s,e){return i===!1?!1:i===!0||i==="error"&&!e?!0:typeof i=="function"?Tt(i,"call shouldTrackBody failed")(s):!1}function _a(i){return{relative:i,timeStamp:gs(i)}}function gs(i){const s=Date.now()-performance.now();return s>at()?Math.round(s+i):fs(i)}function Ra(){return Math.round(Date.now()-(at()+performance.now()))}function wa(i){return hs(i)?ls(i*1e6,0):i}function pi(){return Date.now()}function Ss(){return performance.now()}function Ia(){return{relative:Ss(),timeStamp:pi()}}function Aa(){return{relative:0,timeStamp:at()}}function Ta(i,s){return s-i}function Ea(i){return i-at()}function fs(i){return Math.round(at()+i)}function ya(i){return i<cs}let Et;function at(){return Et===void 0&&(Et=performance.timing.navigationStart),Et}function Pa(){Et=void 0}const Be="?";function nt(i,s){let e;const t=s===void 0?0:+s;try{if(e=ka(i),e)return e}catch(r){}try{if(e=Ma(i),e)return e}catch(r){}try{if(e=Na(i),e)return e}catch(r){}try{if(e=bs(i,t+1),e)return e}catch(r){}return{message:ne(i,"message"),name:ne(i,"name"),stack:[]}}function Ma(i){const s=ne(i,"stack");if(!s)return;const e=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,t=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,r=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;let a;const n=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,o=/\((\S*)(?::(\d+))(?::(\d+))\)/,u=s.split(`
|
|
2
|
+
`),h=[];let l,p,d;for(let m=0,g=u.length;m<g;m+=1){if(e.exec(u[m])){p=e.exec(u[m]);const f=p[2]&&p[2].indexOf("native")===0;a=p[2]&&p[2].indexOf("eval")===0,l=o.exec(p[2]),a&&l&&(p[2]=l[1],p[3]=l[2],p[4]=l[3]),d={args:f?[p[2]]:[],column:p[4]?+p[4]:void 0,func:p[1]||Be,line:p[3]?+p[3]:void 0,url:f?void 0:p[2]}}else if(r.exec(u[m]))p=r.exec(u[m]),d={args:[],column:p[4]?+p[4]:void 0,func:p[1]||Be,line:+p[3],url:p[2]};else if(t.exec(u[m]))p=t.exec(u[m]),a=p[3]&&p[3].indexOf(" > eval")>-1,l=n.exec(p[3]),a&&l?(p[3]=l[1],p[4]=l[2],p[5]=void 0):m===0&&!p[5]&&!Va(i.columnNumber)&&(h[0].column=i.columnNumber+1),d={args:p[2]?p[2].split(","):[],column:p[5]?+p[5]:void 0,func:p[1]||Be,line:p[4]?+p[4]:void 0,url:p[3]};else continue;!d.func&&d.line&&(d.func=Be),h.push(d)}if(h.length)return{stack:h,message:ne(i,"message"),name:ne(i,"name")}}function ka(i){const s=ne(i,"stacktrace");if(!s)return;const e=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,t=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\((.*)\))? in (.*):\s*$/i,r=s.split(`
|
|
3
|
+
`),a=[];let n;for(let o=0;o<r.length;o+=2){let u;e.exec(r[o])?(n=e.exec(r[o]),u={args:[],column:void 0,func:n[3],line:+n[1],url:n[2]}):t.exec(r[o])&&(n=t.exec(r[o]),u={args:n[5]?n[5].split(","):[],column:+n[2],func:n[3]||n[4],line:+n[1],url:n[6]}),u&&(!u.func&&u.line&&(u.func=Be),u.context=[r[o+1]],a.push(u))}if(a.length)return{stack:a,message:ne(i,"message"),name:ne(i,"name")}}function Na(i){const s=ne(i,"message");if(!s)return;const e=s.split(`
|
|
4
|
+
`);if(e.length<4)return;const t=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,r=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,a=/^\s*Line (\d+) of function script\s*$/i,n=[],o=window&&window.document&&window.document.getElementsByTagName("script"),u=[];let h;for(const l in o)La(o,l)&&!o[l].src&&u.push(o[l]);for(let l=2;l<e.length;l+=2){let p;t.exec(e[l])?(h=t.exec(e[l]),p={args:[],column:void 0,func:h[3],line:+h[1],url:h[2]}):r.exec(e[l])?(h=r.exec(e[l]),p={args:[],column:void 0,func:h[4],line:+h[1],url:h[3]}):a.exec(e[l])&&(h=a.exec(e[l]),p={url:window.location.href.replace(/#.*$/,""),args:[],column:void 0,func:"",line:+h[1]}),p&&(p.func||(p.func=Be),p.context=[e[l+1]],n.push(p))}if(n.length)return{stack:n,message:e[0],name:ne(i,"name")}}function Ca(i,s,e){const t={url:s,line:e?+e:void 0};if(t.url&&t.line){i.incomplete=!1;const r=i.stack;if(r.length>0&&r[0].url===t.url){if(r[0].line===t.line)return!1;if(!r[0].line&&r[0].func===t.func)return r[0].line=t.line,r[0].context=t.context,!1}return r.unshift(t),i.partial=!0,!0}return i.incomplete=!0,!1}function bs(i,s){const e=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,t=[],r={};let a=!1,n,o;for(let h=bs.caller;h&&!a;h=h.caller)h!==nt&&(o={args:[],column:void 0,func:Be,line:void 0,url:void 0},n=e.exec(h.toString()),h.name?o.func=h.name:n&&(o.func=n[1]),typeof o.func>"u"&&(o.func=n?n.input.substring(0,n.input.indexOf("{")):void 0),r[h.toString()]?a=!0:r[h.toString()]=!0,t.push(o));s&&t.splice(0,s);const u={stack:t,message:ne(i,"message"),name:ne(i,"name")};return Ca(u,ne(i,"sourceURL")||ne(i,"fileName"),ne(i,"line")||ne(i,"lineNumber")),u}function ne(i,s){if(typeof i!="object"||!i||!(s in i))return;const e=i[s];return typeof e=="string"?e:void 0}function La(i,s){return Object.prototype.hasOwnProperty.call(i,s)}function Va(i){return typeof i>"u"}function vs(i,s,e){const t=i[s];let r=e(t);const a=function(){return r.apply(this,arguments)};return i[s]=a,{stop:()=>{i[s]===a?i[s]=t:r=t}}}function mi(i,s,{before:e,after:t}){return vs(i,s,r=>function(){const a=arguments;let n;return e&&rt(e,this,a),typeof r=="function"&&(n=r.apply(this,a)),t&&rt(t,this,a),n})}const Oa=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function Da(i){const{stop:s}=Ua(i),{stop:e}=xa(i);return{stop:()=>{s(),e()}}}function Ua(i){return mi(window,"onerror",{before(s,e,t,r,a){let n;if(a)n=nt(a),i(n,a);else{const o={url:e,column:r,line:t};let u,h=s;if({}.toString.call(s)==="[object String]"){const l=Oa.exec(h);l&&(u=l[1],h=l[2])}n={name:u,message:typeof h=="string"?h:void 0,stack:[o]},i(n,s)}}})}function xa(i){return mi(window,"onunhandledrejection",{before(s){const e=s.reason||"Empty reason",t=nt(e);i(t,e)}})}function _s(i){return`${i.name||"Error"}: ${i.message}`}function Rs(i){return i.filter(s=>s.url==null||!s.url.includes("sls-rum.js"))}function gi(i){let s=_s(i);return i.stack.forEach(e=>{const t=e.func==="?"?"<anonymous>":e.func,r=e.args&&e.args.length>0?`(${e.args.join(", ")})`:"",a=e.line?`:${e.line}`:"",n=e.line&&e.column?`:${e.column}`:"";s+=`
|
|
5
|
+
at ${t}${r} @ ${e.url}${a}${n}`}),encodeURIComponent(s)}function Ba(i,s,e,t=!0){var r;if(!i||i.message===void 0&&!(s instanceof Error))return{message:`${e} ${JSON.stringify(s)}`,stacktrace:"",type:i&&i.name,id:At()};i!=null&&i.stack&&t&&(i.stack=Rs(i.stack));const a=(r=i==null?void 0:i.stack)==null?void 0:r[0];return{message:encodeURIComponent(i.message||"Empty message"),stacktrace:gi(i),type:i.name,col:a?a.column:void 0,line:a?a.line:void 0,file:encodeURIComponent(a&&a.url?a.url:""),id:At()}}function Fa(){const i=new Error;let s;return rt(()=>{const e=nt(i);e!=null&&e.stack&&(e.stack=Rs(e.stack)),s=gi(e)}),s}const Ha=8,Wa=16,Si="b3",fi="traceparent",bi="uber-trace-id",yt=Array(32);function ws(i){for(let s=0;s<i*2;s++)yt[s]=Math.floor(Math.random()*16)+48,yt[s]>=58&&(yt[s]+=39);return String.fromCharCode.apply(null,yt.slice(0,i*2))}function Is(){return ws(Wa)}function vi(){return ws(Ha)}function Pt(i,s){return`${i}-${s}-1`}function Mt(i,s){return`00-${i}-${s}-01`}function kt(i,s){return`${i}:${s}:0:1`}const Nt={b3:{name:Si,getter:Pt},traceparent:{name:fi,getter:Mt},uber:{name:bi,getter:kt}};function Ka(i,s,e,t){var r;const a=t!=null?t:{};a.headers=(r=a.headers)!=null?r:{},a.headers[Si]=Pt(i,s),a.headers[fi]=Mt(i,s),a.headers[bi]=kt(i,s);try{if(e)for(const[n,o]of Object.entries(e))Nt[o]&&(a.headers[n]=Nt[o].getter(i,s))}catch(n){}return a}function ja(i,s,e,t){i.setRequestHeader(Si,Pt(s,e)),i.setRequestHeader(fi,Mt(s,e)),i.setRequestHeader(bi,kt(s,e));try{if(t)for(const[r,a]of Object.entries(t))Nt[a]&&i.setRequestHeader(r,Nt[a].getter(s,e))}catch(r){}}function ot(i,s,e){i!=null&&Object.keys(i).map(t=>{e==null||e==""?s[t]=i[t]:s[`${e}.${t}`]=i[t]})}var $a=Object.defineProperty,Ja=Object.defineProperties,qa=Object.getOwnPropertyDescriptors,As=Object.getOwnPropertySymbols,Ga=Object.prototype.hasOwnProperty,za=Object.prototype.propertyIsEnumerable,Ts=(i,s,e)=>s in i?$a(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Ya=(i,s)=>{for(var e in s||(s={}))Ga.call(s,e)&&Ts(i,e,s[e]);if(As)for(var e of As(s))za.call(s,e)&&Ts(i,e,s[e]);return i},Xa=(i,s)=>Ja(i,qa(s));function Za(){return{name:be.InternalPlugin.BASE_TRANSFORM,run:function(){this.subscribe("*",(i,s)=>{const{otBase:e,extra:t}=i;e.attribute=Xa(Ya({},e.attribute),{sid:this.session.getSessionId(),pid:this.session.getPageId(),uid:this.options.uid,service:this.options.service}),this.options.nickname&&(e.attribute.nickname=this.options.nickname),ot(this.options.custom,e.attribute,"custom"),ot({env:this.options.env,version:this.options.version},e.attribute),ot({sdk_version:us,workspace:this.options.workspace},e.resource);const r={otBase:e,extra:t};ts(be.InternalPlugin.BASE_TRANSFORM,r),s(r)},be.InternalPluginPriority[be.InternalPlugin.BASE_TRANSFORM])}}}function Qa(){return{name:be.InternalPlugin.LOG_SEND,run:function(){}}}function Es(i,s,e){if(s<0)return;const t=a=>{Es(i,s-1,a)},r=i[s];Tt(()=>{r.callback.call(void 0,e,t)},"plugin notify run error")()}class en{constructor(s){this.subscribeMap={},this.allNotifiers=[],this.allNotifiers=s}subscribeOne(s,e,t,r){var a;const n=(a=this.subscribeMap[e])!=null?a:[];this.subscribeMap[e]=n,n.push({name:s,priority:r,callback:t}),n.sort((o,u)=>o.priority-u.priority)}notify(s,e){var t;const r=(t=this.subscribeMap[s])!=null?t:[];Es(r,r.length-1,e)}subscribe(s,e,t,r){if(e==="*")for(let a=0;a<this.allNotifiers.length;a++){const n=this.allNotifiers[a];this.subscribeOne(s,n,t,r)}else this.subscribeOne(s,e,t,r)}getSubscribeMap(){return this.subscribeMap}}function tn(){const i=Is();let s=vi();return{getSessionId:()=>i,getPageId:()=>s,refreshPageId:()=>{s=vi()}}}var sn=Object.defineProperty,rn=Object.defineProperties,an=Object.getOwnPropertyDescriptors,ys=Object.getOwnPropertySymbols,nn=Object.prototype.hasOwnProperty,on=Object.prototype.propertyIsEnumerable,Ps=(i,s,e)=>s in i?sn(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,cn=(i,s)=>{for(var e in s||(s={}))nn.call(s,e)&&Ps(i,e,s[e]);if(ys)for(var e of ys(s))on.call(s,e)&&Ps(i,e,s[e]);return i},un=(i,s)=>rn(i,an(s));const hn=["uid","nickname","env","service","version","custom"];class ln{constructor(s){this.isInit=!1,this.pendingPlugins=[],this.pluginMap={},this.session=tn();var e,t;this.options=s,this.use(Qa()),this.use(Za()),this.options.env=(e=s.env)!=null?e:"prod",this.options.version=(t=s.version)!=null?t:"-"}initPlugin(s){if(s==null||typeof s!="object"){console.error("plugin is not a object");return}if(s.name==null||s.name===""){console.error("plugin name is required.");return}if(this.pluginMap[s.name]){console.error(`plugin name: ${s.name} is conflict`);return}if(typeof s.run!="function"){console.error("plugin.run is not a function");return}const e=un(cn({},this.context),{subscribe:(t,r,a)=>{this.sub.subscribe(s.name,t,r,a)},notify:t=>{this.sub.notify(s.name,t)}});Tt(()=>s.run.call(e),`plugin ${s.name} init failed`)()}addLog(s){if(this.isInit){const e={t:be.WebEventType.LOG};ot(s,e,be.WebEventType.LOG);const t={start:pi()*1e3,attribute:e,resource:{}};this.sub.notify(be.InternalPlugin.LOG_SEND,{otBase:t,extra:{}})}else console.error("log should call after start")}setOptions(s){this.isInit?hn.forEach(e=>{s[e]!==this.options[e]&&s[e]!=null&&s[e]!=""&&(this.options[e]=s[e],e==="uid"&&typeof this.setLocalStorage=="function"&&this.setLocalStorage(be.SLS_TRACE_UID_KEY,s[e]))}):console.error("setOptions should call after start")}start(){if(!this.isInit){this.isInit=!0;let s=this.options.uid;(s==null||s==="")&&(typeof this.getLocalStorage=="function"&&(s=this.getLocalStorage(be.SLS_TRACE_UID_KEY)),(s==null||s==="")&&(s=ds())),this.options.uid=s,typeof this.setLocalStorage=="function"&&this.setLocalStorage(be.SLS_TRACE_UID_KEY,s);const e=this.pendingPlugins.map(t=>t==null?void 0:t.name).filter(t=>t!=null);this.sub=new en(e),this.context={options:this.options,session:this.session};for(const t of this.pendingPlugins)this.initPlugin(t)}}use(s){this.isInit?console.error(`plugin: ${s==null?void 0:s.name} use should run before start`):this.pendingPlugins.push(s)}}var dn=Object.defineProperty,Ms=Object.getOwnPropertySymbols,pn=Object.prototype.hasOwnProperty,mn=Object.prototype.propertyIsEnumerable,ks=(i,s,e)=>s in i?dn(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,gn=(i,s)=>{for(var e in s||(s={}))pn.call(s,e)&&ks(i,e,s[e]);if(Ms)for(var e of Ms(s))mn.call(s,e)&&ks(i,e,s[e]);return i};function Sn(i,s){var e;const t={current:void 0},r=[];let a={};return typeof s=="function"&&(a=(e=s(t))!=null?e:{}),gn({init:n=>{if(t.current!=null)return;t.current=i(n);const o=t.current;r.forEach(u=>{o.use(u)}),o.start()},use:n=>{r.push(n)},addLog:n=>{t.current.addLog(n)},onReady(n){n()},setOptions:n=>{t.current.setOptions(n)}},a)}class fn{constructor(){this.dep=new Map}subscribe(s,e){const t=this.dep.get(s);if(t){this.dep.set(s,t.concat(e));return}this.dep.set(s,[e])}notify(s,e){const t=this.dep.get(s);!s||!t||t.forEach(r=>{try{r(e)}catch(a){console.error(a)}})}}E.ONE_DAY=os,E.ONE_HOUR=ns,E.ONE_KILO_BYTE=na,E.ONE_MINUTE=as,E.ONE_SECOND=rs,E.ONE_YEAR=cs,E.Observable=zr,E.SDK_VERSION=us,E.SLSClient=ln,E.Subscribe=fn,E.assembleOTAttribute=ot,E.buildHttpInfo=fa,E.callMonitored=rt,E.catchUserErrors=Tt,E.clocksNow=Ia,E.clocksOrigin=Aa,E.computeStackTrace=nt,E.createHandlingStack=Fa,E.currentDrift=Ra,E.debugLog=ts,E.defineGlobal=Gr,E.defineGlobalValue=di,E.elapsed=Ta,E.formatErrorMessage=_s,E.formatUnknownError=Ba,E.genUid=ds,E.generateSpanId=vi,E.generateTraceId=Is,E.generateUUID=At,E.getB3Header=Pt,E.getConsoleLogStatus=Zr,E.getCorrectedTimeStamp=gs,E.getJaegerTraceHeaderr=kt,E.getRelativeTime=Ea,E.getTimeStamp=fs,E.getTrackUrl=ps,E.getW3CTraceHeader=Mt,E.includes=ha,E.instrumentMethod=vs,E.instrumentMethodAndCallOriginal=mi,E.isError=ua,E.isInternalUrl=pa,E.isNumber=hs,E.isString=ca,E.isURL=ga,E.looksLikeRelativeTime=ya,E.makeWebPublicApi=Sn,E.matchCondition=ba,E.matchSample=da,E.matchWithDefault=la,E.monitor=Yr,E.noop=oa,E.parseUri=Sa,E.patchHeaderOnRequest=Ka,E.patchHeaderOnXhr=ja,E.relativeNow=Ss,E.relativeToClocks=_a,E.resetNavigationStart=Pa,E.round=ls,E.shouldTrackBody=va,E.startUnhandledErrorCollection=Da,E.timeStampNow=pi,E.toServerDuration=wa,E.toStackTraceString=gi;var bn=class{constructor(i){this.timer=null,this.time=10,this.count=10,this.arr=[];var s,e;this.time=(s=i.time)!=null?s:10,this.count=(e=i.count)!=null?e:10,this.url="https://"+i.project+"."+i.host+"/logstores/"+i.logstore+"/track",this.opt=i,i.installUnloadHook&&typeof i.installUnloadHook=="function"&&i.installUnloadHook(()=>{this.sendImmediateInner()})}assemblePayload(i=this.arr){const s={__logs__:i};return this.opt.tags&&(s.__tags__=this.opt.tags),this.opt.topic&&(s.__topic__=this.opt.topic),this.opt.source&&(s.__source__=this.opt.source),JSON.stringify(s)}platformSend(){if(this.opt.sendPayload&&typeof this.opt.sendPayload=="function"){const i=this.assemblePayload();this.opt.sendPayload(this.url,i)}}transString(i){let s={};for(let e in i)typeof i[e]=="object"?s[e]=JSON.stringify(i[e]):s[e]=String(i[e]);return s}sendImmediateInner(){this.arr&&this.arr.length>0&&(this.platformSend(),this.timer!=null&&(clearTimeout(this.timer),this.timer=null),this.arr=[])}sendInner(){if(this.timer)this.arr.length>=this.count&&(clearTimeout(this.timer),this.timer=null,this.sendImmediateInner());else{const i=this;this.arr.length>=this.count||this.time<=0?this.sendImmediateInner():this.timer=setTimeout(function(){i.sendImmediateInner()},this.time*1e3)}}send(i){const s=this.transString(i);this.arr.push(s),this.sendInner()}sendImmediate(i){const s=this.transString(i);this.arr.push(s),this.sendImmediateInner()}sendBatchLogs(i){const s=i.map(e=>this.transString(e));this.arr.push(...s),this.sendInner()}sendBatchLogsImmediate(i){const s=i.map(e=>this.transString(e));this.arr.push(...s),this.sendImmediateInner()}},vn=E,_n=bn;function Rn(i,s){return navigator&&navigator.sendBeacon?navigator.sendBeacon(`${i}?APIVersion=0.6.0`,s):!1}function wn(i,s){const e=new window.XMLHttpRequest;e.open("POST",i,!0),e.setRequestHeader("x-log-apiversion","0.6.0"),e.setRequestHeader("x-log-bodyrawsize",s.length.toString());const t=new Blob([s],{type:"application/x-protobuf"});e.send(t)}function In(i,s){try{Rn(i,s)||wn(i,s)}catch(e){window&&window.console&&typeof window.console.error=="function"&&(console.error(`Failed to log to ali log service because of this exception:
|
|
6
|
+
`+e),console.error("Failed log data:",i))}}class Ns extends _n{constructor(s){const e=Object.assign({},s,{installUnloadHook:t=>{window.addEventListener("beforeunload",()=>{t()})},sendPayload:(t,r)=>{In(t,r)}});super(e)}}vn.defineGlobal(window,"SLS_Tracker",Ns);var An=Ns,Ct={},Tn={get exports(){return Ct},set exports(i){Ct=i}};(function(i,s){(function(e,t){var r="1.0.35",a="",n="?",o="function",u="undefined",h="object",l="string",p="major",d="model",m="name",g="type",f="vendor",v="version",O="architecture",B="console",C="mobile",U="tablet",re="smarttv",Ce="wearable",yi="embedded",Pi=350,Bt="Amazon",ut="Apple",Js="ASUS",qs="BlackBerry",$e="Browser",Ft="Chrome",io="Edge",Ht="Firefox",Wt="Google",Gs="Huawei",Mi="LG",ki="Microsoft",zs="Motorola",Kt="Opera",Ni="Samsung",Ys="Sharp",jt="Sony",Ci="Xiaomi",Li="Zebra",Xs="Facebook",Zs="Chromium OS",Qs="Mac OS",so=function(F,$){var D={};for(var q in F)$[q]&&$[q].length%2===0?D[q]=$[q].concat(F[q]):D[q]=F[q];return D},$t=function(F){for(var $={},D=0;D<F.length;D++)$[F[D].toUpperCase()]=F[D];return $},er=function(F,$){return typeof F===l?ht($).indexOf(ht(F))!==-1:!1},ht=function(F){return F.toLowerCase()},ro=function(F){return typeof F===l?F.replace(/[^\d\.]/g,a).split(".")[0]:t},Vi=function(F,$){if(typeof F===l)return F=F.replace(/^\s\s*/,a),typeof $===u?F:F.substring(0,Pi)},lt=function(F,$){for(var D=0,q,Le,Ae,j,L,Ee;D<$.length&&!L;){var Di=$[D],sr=$[D+1];for(q=Le=0;q<Di.length&&!L&&Di[q];)if(L=Di[q++].exec(F),L)for(Ae=0;Ae<sr.length;Ae++)Ee=L[++Le],j=sr[Ae],typeof j===h&&j.length>0?j.length===2?typeof j[1]==o?this[j[0]]=j[1].call(this,Ee):this[j[0]]=j[1]:j.length===3?typeof j[1]===o&&!(j[1].exec&&j[1].test)?this[j[0]]=Ee?j[1].call(this,Ee,j[2]):t:this[j[0]]=Ee?Ee.replace(j[1],j[2]):t:j.length===4&&(this[j[0]]=Ee?j[3].call(this,Ee.replace(j[1],j[2])):t):this[j]=Ee||t;D+=2}},Oi=function(F,$){for(var D in $)if(typeof $[D]===h&&$[D].length>0){for(var q=0;q<$[D].length;q++)if(er($[D][q],F))return D===n?t:D}else if(er($[D],F))return D===n?t:D;return F},ao={"1.0":"/8","1.2":"/1","1.3":"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"},tr={ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2e3:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2","8.1":"NT 6.3",10:["NT 6.4","NT 10.0"],RT:"ARM"},ir={browser:[[/\b(?:crmo|crios)\/([\w\.]+)/i],[v,[m,"Chrome"]],[/edg(?:e|ios|a)?\/([\w\.]+)/i],[v,[m,"Edge"]],[/(opera mini)\/([-\w\.]+)/i,/(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i,/(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i],[m,v],[/opios[\/ ]+([\w\.]+)/i],[v,[m,Kt+" Mini"]],[/\bopr\/([\w\.]+)/i],[v,[m,Kt]],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer)[\/ ]?([\w\.]*)/i,/(avant |iemobile|slim)(?:browser)?[\/ ]?([\w\.]*)/i,/(ba?idubrowser)[\/ ]?([\w\.]+)/i,/(?:ms|\()(ie) ([\w\.]+)/i,/(flock|rockmelt|midori|epiphany|silk|skyfire|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon|rekonq|puffin|brave|whale(?!.+naver)|qqbrowserlite|qq|duckduckgo)\/([-\w\.]+)/i,/(heytap|ovi)browser\/([\d\.]+)/i,/(weibo)__([\d\.]+)/i],[m,v],[/(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i],[v,[m,"UC"+$e]],[/microm.+\bqbcore\/([\w\.]+)/i,/\bqbcore\/([\w\.]+).+microm/i],[v,[m,"WeChat(Win) Desktop"]],[/micromessenger\/([\w\.]+)/i],[v,[m,"WeChat"]],[/konqueror\/([\w\.]+)/i],[v,[m,"Konqueror"]],[/trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i],[v,[m,"IE"]],[/ya(?:search)?browser\/([\w\.]+)/i],[v,[m,"Yandex"]],[/(avast|avg)\/([\w\.]+)/i],[[m,/(.+)/,"$1 Secure "+$e],v],[/\bfocus\/([\w\.]+)/i],[v,[m,Ht+" Focus"]],[/\bopt\/([\w\.]+)/i],[v,[m,Kt+" Touch"]],[/coc_coc\w+\/([\w\.]+)/i],[v,[m,"Coc Coc"]],[/dolfin\/([\w\.]+)/i],[v,[m,"Dolphin"]],[/coast\/([\w\.]+)/i],[v,[m,Kt+" Coast"]],[/miuibrowser\/([\w\.]+)/i],[v,[m,"MIUI "+$e]],[/fxios\/([-\w\.]+)/i],[v,[m,Ht]],[/\bqihu|(qi?ho?o?|360)browser/i],[[m,"360 "+$e]],[/(oculus|samsung|sailfish|huawei)browser\/([\w\.]+)/i],[[m,/(.+)/,"$1 "+$e],v],[/(comodo_dragon)\/([\w\.]+)/i],[[m,/_/g," "],v],[/(electron)\/([\w\.]+) safari/i,/(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i,/m?(qqbrowser|baiduboxapp|2345Explorer)[\/ ]?([\w\.]+)/i],[m,v],[/(metasr)[\/ ]?([\w\.]+)/i,/(lbbrowser)/i,/\[(linkedin)app\]/i],[m],[/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i],[[m,Xs],v],[/(kakao(?:talk|story))[\/ ]([\w\.]+)/i,/(naver)\(.*?(\d+\.[\w\.]+).*\)/i,/safari (line)\/([\w\.]+)/i,/\b(line)\/([\w\.]+)\/iab/i,/(chromium|instagram)[\/ ]([-\w\.]+)/i],[m,v],[/\bgsa\/([\w\.]+) .*safari\//i],[v,[m,"GSA"]],[/musical_ly(?:.+app_?version\/|_)([\w\.]+)/i],[v,[m,"TikTok"]],[/headlesschrome(?:\/([\w\.]+)| )/i],[v,[m,Ft+" Headless"]],[/ wv\).+(chrome)\/([\w\.]+)/i],[[m,Ft+" WebView"],v],[/droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i],[v,[m,"Android "+$e]],[/(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i],[m,v],[/version\/([\w\.\,]+) .*mobile\/\w+ (safari)/i],[v,[m,"Mobile Safari"]],[/version\/([\w(\.|\,)]+) .*(mobile ?safari|safari)/i],[v,m],[/webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i],[m,[v,Oi,ao]],[/(webkit|khtml)\/([\w\.]+)/i],[m,v],[/(navigator|netscape\d?)\/([-\w\.]+)/i],[[m,"Netscape"],v],[/mobile vr; rv:([\w\.]+)\).+firefox/i],[v,[m,Ht+" Reality"]],[/ekiohf.+(flow)\/([\w\.]+)/i,/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo browser|minimo|conkeror|klar)[\/ ]?([\w\.\+]+)/i,/(seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([-\w\.]+)$/i,/(firefox)\/([\w\.]+)/i,/(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,/(links) \(([\w\.]+)/i,/panasonic;(viera)/i],[m,v],[/(cobalt)\/([\w\.]+)/i],[m,[v,/master.|lts./,""]]],cpu:[[/(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i],[[O,"amd64"]],[/(ia32(?=;))/i],[[O,ht]],[/((?:i[346]|x)86)[;\)]/i],[[O,"ia32"]],[/\b(aarch64|arm(v?8e?l?|_?64))\b/i],[[O,"arm64"]],[/\b(arm(?:v[67])?ht?n?[fl]p?)\b/i],[[O,"armhf"]],[/windows (ce|mobile); ppc;/i],[[O,"arm"]],[/((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i],[[O,/ower/,a,ht]],[/(sun4\w)[;\)]/i],[[O,"sparc"]],[/((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i],[[O,ht]]],device:[[/\b(sch-i[89]0\d|shw-m380s|sm-[ptx]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i],[d,[f,Ni],[g,U]],[/\b((?:s[cgp]h|gt|sm)-\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,/samsung[- ]([-\w]+)/i,/sec-(sgh\w+)/i],[d,[f,Ni],[g,C]],[/(?:\/|\()(ip(?:hone|od)[\w, ]*)(?:\/|;)/i],[d,[f,ut],[g,C]],[/\((ipad);[-\w\),; ]+apple/i,/applecoremedia\/[\w\.]+ \((ipad)/i,/\b(ipad)\d\d?,\d\d?[;\]].+ios/i],[d,[f,ut],[g,U]],[/(macintosh);/i],[d,[f,ut]],[/\b(sh-?[altvz]?\d\d[a-ekm]?)/i],[d,[f,Ys],[g,C]],[/\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i],[d,[f,Gs],[g,U]],[/(?:huawei|honor)([-\w ]+)[;\)]/i,/\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i],[d,[f,Gs],[g,C]],[/\b(poco[\w ]+)(?: bui|\))/i,/\b; (\w+) build\/hm\1/i,/\b(hm[-_ ]?note?[_ ]?(?:\d\w)?) bui/i,/\b(redmi[\-_ ]?(?:note|k)?[\w_ ]+)(?: bui|\))/i,/\b(mi[-_ ]?(?:a\d|one|one[_ ]plus|note lte|max|cc)?[_ ]?(?:\d?\w?)[_ ]?(?:plus|se|lite)?)(?: bui|\))/i],[[d,/_/g," "],[f,Ci],[g,C]],[/\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i],[[d,/_/g," "],[f,Ci],[g,U]],[/; (\w+) bui.+ oppo/i,/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i],[d,[f,"OPPO"],[g,C]],[/vivo (\w+)(?: bui|\))/i,/\b(v[12]\d{3}\w?[at])(?: bui|;)/i],[d,[f,"Vivo"],[g,C]],[/\b(rmx[12]\d{3})(?: bui|;|\))/i],[d,[f,"Realme"],[g,C]],[/\b(milestone|droid(?:[2-4x]| (?:bionic|x2|pro|razr))?:?( 4g)?)\b[\w ]+build\//i,/\bmot(?:orola)?[- ](\w*)/i,/((?:moto[\w\(\) ]+|xt\d{3,4}|nexus 6)(?= bui|\)))/i],[d,[f,zs],[g,C]],[/\b(mz60\d|xoom[2 ]{0,2}) build\//i],[d,[f,zs],[g,U]],[/((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i],[d,[f,Mi],[g,U]],[/(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,/\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,/\blg-?([\d\w]+) bui/i],[d,[f,Mi],[g,C]],[/(ideatab[-\w ]+)/i,/lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i],[d,[f,"Lenovo"],[g,U]],[/(?:maemo|nokia).*(n900|lumia \d+)/i,/nokia[-_ ]?([-\w\.]*)/i],[[d,/_/g," "],[f,"Nokia"],[g,C]],[/(pixel c)\b/i],[d,[f,Wt],[g,U]],[/droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i],[d,[f,Wt],[g,C]],[/droid.+ (a?\d[0-2]{2}so|[c-g]\d{4}|so[-gl]\w+|xq-a\w[4-7][12])(?= bui|\).+chrome\/(?![1-6]{0,1}\d\.))/i],[d,[f,jt],[g,C]],[/sony tablet [ps]/i,/\b(?:sony)?sgp\w+(?: bui|\))/i],[[d,"Xperia Tablet"],[f,jt],[g,U]],[/ (kb2005|in20[12]5|be20[12][59])\b/i,/(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i],[d,[f,"OnePlus"],[g,C]],[/(alexa)webm/i,/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i,/(kf[a-z]+)( bui|\)).+silk\//i],[d,[f,Bt],[g,U]],[/((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i],[[d,/(.+)/g,"Fire Phone $1"],[f,Bt],[g,C]],[/(playbook);[-\w\),; ]+(rim)/i],[d,f,[g,U]],[/\b((?:bb[a-f]|st[hv])100-\d)/i,/\(bb10; (\w+)/i],[d,[f,qs],[g,C]],[/(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i],[d,[f,Js],[g,U]],[/ (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i],[d,[f,Js],[g,C]],[/(nexus 9)/i],[d,[f,"HTC"],[g,U]],[/(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i,/(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,/(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i],[f,[d,/_/g," "],[g,C]],[/droid.+; ([ab][1-7]-?[0178a]\d\d?)/i],[d,[f,"Acer"],[g,U]],[/droid.+; (m[1-5] note) bui/i,/\bmz-([-\w]{2,})/i],[d,[f,"Meizu"],[g,C]],[/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[-_ ]?([-\w]*)/i,/(hp) ([\w ]+\w)/i,/(asus)-?(\w+)/i,/(microsoft); (lumia[\w ]+)/i,/(lenovo)[-_ ]?([-\w]+)/i,/(jolla)/i,/(oppo) ?([\w ]+) bui/i],[f,d,[g,C]],[/(kobo)\s(ereader|touch)/i,/(archos) (gamepad2?)/i,/(hp).+(touchpad(?!.+tablet)|tablet)/i,/(kindle)\/([\w\.]+)/i,/(nook)[\w ]+build\/(\w+)/i,/(dell) (strea[kpr\d ]*[\dko])/i,/(le[- ]+pan)[- ]+(\w{1,9}) bui/i,/(trinity)[- ]*(t\d{3}) bui/i,/(gigaset)[- ]+(q\w{1,9}) bui/i,/(vodafone) ([\w ]+)(?:\)| bui)/i],[f,d,[g,U]],[/(surface duo)/i],[d,[f,ki],[g,U]],[/droid [\d\.]+; (fp\du?)(?: b|\))/i],[d,[f,"Fairphone"],[g,C]],[/(u304aa)/i],[d,[f,"AT&T"],[g,C]],[/\bsie-(\w*)/i],[d,[f,"Siemens"],[g,C]],[/\b(rct\w+) b/i],[d,[f,"RCA"],[g,U]],[/\b(venue[\d ]{2,7}) b/i],[d,[f,"Dell"],[g,U]],[/\b(q(?:mv|ta)\w+) b/i],[d,[f,"Verizon"],[g,U]],[/\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i],[d,[f,"Barnes & Noble"],[g,U]],[/\b(tm\d{3}\w+) b/i],[d,[f,"NuVision"],[g,U]],[/\b(k88) b/i],[d,[f,"ZTE"],[g,U]],[/\b(nx\d{3}j) b/i],[d,[f,"ZTE"],[g,C]],[/\b(gen\d{3}) b.+49h/i],[d,[f,"Swiss"],[g,C]],[/\b(zur\d{3}) b/i],[d,[f,"Swiss"],[g,U]],[/\b((zeki)?tb.*\b) b/i],[d,[f,"Zeki"],[g,U]],[/\b([yr]\d{2}) b/i,/\b(dragon[- ]+touch |dt)(\w{5}) b/i],[[f,"Dragon Touch"],d,[g,U]],[/\b(ns-?\w{0,9}) b/i],[d,[f,"Insignia"],[g,U]],[/\b((nxa|next)-?\w{0,9}) b/i],[d,[f,"NextBook"],[g,U]],[/\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i],[[f,"Voice"],d,[g,C]],[/\b(lvtel\-)?(v1[12]) b/i],[[f,"LvTel"],d,[g,C]],[/\b(ph-1) /i],[d,[f,"Essential"],[g,C]],[/\b(v(100md|700na|7011|917g).*\b) b/i],[d,[f,"Envizen"],[g,U]],[/\b(trio[-\w\. ]+) b/i],[d,[f,"MachSpeed"],[g,U]],[/\btu_(1491) b/i],[d,[f,"Rotor"],[g,U]],[/(shield[\w ]+) b/i],[d,[f,"Nvidia"],[g,U]],[/(sprint) (\w+)/i],[f,d,[g,C]],[/(kin\.[onetw]{3})/i],[[d,/\./g," "],[f,ki],[g,C]],[/droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i],[d,[f,Li],[g,U]],[/droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i],[d,[f,Li],[g,C]],[/smart-tv.+(samsung)/i],[f,[g,re]],[/hbbtv.+maple;(\d+)/i],[[d,/^/,"SmartTV"],[f,Ni],[g,re]],[/(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i],[[f,Mi],[g,re]],[/(apple) ?tv/i],[f,[d,ut+" TV"],[g,re]],[/crkey/i],[[d,Ft+"cast"],[f,Wt],[g,re]],[/droid.+aft(\w)( bui|\))/i],[d,[f,Bt],[g,re]],[/\(dtv[\);].+(aquos)/i,/(aquos-tv[\w ]+)\)/i],[d,[f,Ys],[g,re]],[/(bravia[\w ]+)( bui|\))/i],[d,[f,jt],[g,re]],[/(mitv-\w{5}) bui/i],[d,[f,Ci],[g,re]],[/Hbbtv.*(technisat) (.*);/i],[f,d,[g,re]],[/\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i,/hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i],[[f,Vi],[d,Vi],[g,re]],[/\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i],[[g,re]],[/(ouya)/i,/(nintendo) ([wids3utch]+)/i],[f,d,[g,B]],[/droid.+; (shield) bui/i],[d,[f,"Nvidia"],[g,B]],[/(playstation [345portablevi]+)/i],[d,[f,jt],[g,B]],[/\b(xbox(?: one)?(?!; xbox))[\); ]/i],[d,[f,ki],[g,B]],[/((pebble))app/i],[f,d,[g,Ce]],[/(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i],[d,[f,ut],[g,Ce]],[/droid.+; (glass) \d/i],[d,[f,Wt],[g,Ce]],[/droid.+; (wt63?0{2,3})\)/i],[d,[f,Li],[g,Ce]],[/(quest( 2| pro)?)/i],[d,[f,Xs],[g,Ce]],[/(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i],[f,[g,yi]],[/(aeobc)\b/i],[d,[f,Bt],[g,yi]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+? mobile safari/i],[d,[g,C]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i],[d,[g,U]],[/\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i],[[g,U]],[/(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i],[[g,C]],[/(android[-\w\. ]{0,9});.+buil/i],[d,[f,"Generic"]]],engine:[[/windows.+ edge\/([\w\.]+)/i],[v,[m,io+"HTML"]],[/webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i],[v,[m,"Blink"]],[/(presto)\/([\w\.]+)/i,/(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,/ekioh(flow)\/([\w\.]+)/i,/(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i,/(icab)[\/ ]([23]\.[\d\.]+)/i,/\b(libweb)/i],[m,v],[/rv\:([\w\.]{1,9})\b.+(gecko)/i],[v,m]],os:[[/microsoft (windows) (vista|xp)/i],[m,v],[/(windows) nt 6\.2; (arm)/i,/(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i,/(windows)[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i],[m,[v,Oi,tr]],[/(win(?=3|9|n)|win 9x )([nt\d\.]+)/i],[[m,"Windows"],[v,Oi,tr]],[/ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i,/ios;fbsv\/([\d\.]+)/i,/cfnetwork\/.+darwin/i],[[v,/_/g,"."],[m,"iOS"]],[/(mac os x) ?([\w\. ]*)/i,/(macintosh|mac_powerpc\b)(?!.+haiku)/i],[[m,Qs],[v,/_/g,"."]],[/droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i],[v,m],[/(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,/(blackberry)\w*\/([\w\.]*)/i,/(tizen|kaios)[\/ ]([\w\.]+)/i,/\((series40);/i],[m,v],[/\(bb(10);/i],[v,[m,qs]],[/(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i],[v,[m,"Symbian"]],[/mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i],[v,[m,Ht+" OS"]],[/web0s;.+rt(tv)/i,/\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i],[v,[m,"webOS"]],[/watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i],[v,[m,"watchOS"]],[/crkey\/([\d\.]+)/i],[v,[m,Ft+"cast"]],[/(cros) [\w]+(?:\)| ([\w\.]+)\b)/i],[[m,Zs],v],[/panasonic;(viera)/i,/(netrange)mmh/i,/(nettv)\/(\d+\.[\w\.]+)/i,/(nintendo|playstation) ([wids345portablevuch]+)/i,/(xbox); +xbox ([^\);]+)/i,/\b(joli|palm)\b ?(?:os)?\/?([\w\.]*)/i,/(mint)[\/\(\) ]?(\w*)/i,/(mageia|vectorlinux)[; ]/i,/([kxln]?ubuntu|debian|suse|opensuse|gentoo|arch(?= linux)|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire)(?: gnu\/linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,/(hurd|linux) ?([\w\.]*)/i,/(gnu) ?([\w\.]*)/i,/\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i,/(haiku) (\w+)/i],[m,v],[/(sunos) ?([\w\.\d]*)/i],[[m,"Solaris"],v],[/((?:open)?solaris)[-\/ ]?([\w\.]*)/i,/(aix) ((\d)(?=\.|\)| )[\w\.])*/i,/\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux|serenityos)/i,/(unix) ?([\w\.]*)/i],[m,v]]},ve=function(F,$){if(typeof F===h&&($=F,F=t),!(this instanceof ve))return new ve(F,$).getResult();var D=typeof e!==u&&e.navigator?e.navigator:t,q=F||(D&&D.userAgent?D.userAgent:a),Le=D&&D.userAgentData?D.userAgentData:t,Ae=$?so(ir,$):ir,j=D&&D.userAgent==q;return this.getBrowser=function(){var L={};return L[m]=t,L[v]=t,lt.call(L,q,Ae.browser),L[p]=ro(L[v]),j&&D&&D.brave&&typeof D.brave.isBrave==o&&(L[m]="Brave"),L},this.getCPU=function(){var L={};return L[O]=t,lt.call(L,q,Ae.cpu),L},this.getDevice=function(){var L={};return L[f]=t,L[d]=t,L[g]=t,lt.call(L,q,Ae.device),j&&!L[g]&&Le&&Le.mobile&&(L[g]=C),j&&L[d]=="Macintosh"&&D&&typeof D.standalone!==u&&D.maxTouchPoints&&D.maxTouchPoints>2&&(L[d]="iPad",L[g]=U),L},this.getEngine=function(){var L={};return L[m]=t,L[v]=t,lt.call(L,q,Ae.engine),L},this.getOS=function(){var L={};return L[m]=t,L[v]=t,lt.call(L,q,Ae.os),j&&!L[m]&&Le&&Le.platform!="Unknown"&&(L[m]=Le.platform.replace(/chrome os/i,Zs).replace(/macos/i,Qs)),L},this.getResult=function(){return{ua:this.getUA(),browser:this.getBrowser(),engine:this.getEngine(),os:this.getOS(),device:this.getDevice(),cpu:this.getCPU()}},this.getUA=function(){return q},this.setUA=function(L){return q=typeof L===l&&L.length>Pi?Vi(L,Pi):L,this},this.setUA(q),this};ve.VERSION=r,ve.BROWSER=$t([m,v,p]),ve.CPU=$t([O]),ve.DEVICE=$t([d,f,g,B,C,re,U,Ce,yi]),ve.ENGINE=ve.OS=$t([m,v]),i.exports&&(s=i.exports=ve),s.UAParser=ve;var Je=typeof e!==u&&(e.jQuery||e.Zepto);if(Je&&!Je.ua){var Jt=new ve;Je.ua=Jt.getResult(),Je.ua.get=function(){return Jt.getUA()},Je.ua.set=function(F){Jt.setUA(F);var $=Jt.getResult();for(var D in $)Je.ua[D]=$[D]}}})(typeof window=="object"?window:jr)})(Tn,Ct);let Lt;const En=new Uint8Array(16);function yn(){if(!Lt&&(Lt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Lt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Lt(En)}const se=[];for(let i=0;i<256;++i)se.push((i+256).toString(16).slice(1));function Pn(i,s=0){return(se[i[s+0]]+se[i[s+1]]+se[i[s+2]]+se[i[s+3]]+"-"+se[i[s+4]]+se[i[s+5]]+"-"+se[i[s+6]]+se[i[s+7]]+"-"+se[i[s+8]]+se[i[s+9]]+"-"+se[i[s+10]]+se[i[s+11]]+se[i[s+12]]+se[i[s+13]]+se[i[s+14]]+se[i[s+15]]).toLowerCase()}const Mn=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Cs={randomUUID:Mn};function kn(i,s,e){if(Cs.randomUUID&&!s&&!i)return Cs.randomUUID();i=i||{};const t=i.random||(i.rng||yn)();if(t[6]=t[6]&15|64,t[8]=t[8]&63|128,s){e=e||0;for(let r=0;r<16;++r)s[e+r]=t[r];return s}return Pn(t)}var _i={},Nn={get exports(){return _i},set exports(i){_i=i}},Ri={},Cn={get exports(){return Ri},set exports(i){Ri=i}};(function(){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s={rotl:function(e,t){return e<<t|e>>>32-t},rotr:function(e,t){return e<<32-t|e>>>t},endian:function(e){if(e.constructor==Number)return s.rotl(e,8)&16711935|s.rotl(e,24)&4278255360;for(var t=0;t<e.length;t++)e[t]=s.endian(e[t]);return e},randomBytes:function(e){for(var t=[];e>0;e--)t.push(Math.floor(Math.random()*256));return t},bytesToWords:function(e){for(var t=[],r=0,a=0;r<e.length;r++,a+=8)t[a>>>5]|=e[r]<<24-a%32;return t},wordsToBytes:function(e){for(var t=[],r=0;r<e.length*32;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},bytesToHex:function(e){for(var t=[],r=0;r<e.length;r++)t.push((e[r]>>>4).toString(16)),t.push((e[r]&15).toString(16));return t.join("")},hexToBytes:function(e){for(var t=[],r=0;r<e.length;r+=2)t.push(parseInt(e.substr(r,2),16));return t},bytesToBase64:function(e){for(var t=[],r=0;r<e.length;r+=3)for(var a=e[r]<<16|e[r+1]<<8|e[r+2],n=0;n<4;n++)r*8+n*6<=e.length*8?t.push(i.charAt(a>>>6*(3-n)&63)):t.push("=");return t.join("")},base64ToBytes:function(e){e=e.replace(/[^A-Z0-9+\/]/ig,"");for(var t=[],r=0,a=0;r<e.length;a=++r%4)a!=0&&t.push((i.indexOf(e.charAt(r-1))&Math.pow(2,-2*a+8)-1)<<a*2|i.indexOf(e.charAt(r))>>>6-a*2);return t}};Cn.exports=s})();var wi={utf8:{stringToBytes:function(i){return wi.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(wi.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var s=[],e=0;e<i.length;e++)s.push(i.charCodeAt(e)&255);return s},bytesToString:function(i){for(var s=[],e=0;e<i.length;e++)s.push(String.fromCharCode(i[e]));return s.join("")}}},Ls=wi;/*!
|
|
7
7
|
* Determine if an object is a Buffer
|
|
8
8
|
*
|
|
9
9
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
10
10
|
* @license MIT
|
|
11
|
-
*/var Ln=function(i){return i!=null&&(Vs(i)||Vn(i)||!!i._isBuffer)};function Vs(i){return!!i.constructor&&typeof i.constructor.isBuffer=="function"&&i.constructor.isBuffer(i)}function Vn(i){return typeof i.readFloatLE=="function"&&typeof i.slice=="function"&&Vs(i.slice(0,0))}(function(){var i=wi,s=Ls.utf8,e=Ln,t=Ls.bin,r=function(a,n){a.constructor==String?n&&n.encoding==="binary"?a=t.stringToBytes(a):a=s.stringToBytes(a):e(a)?a=Array.prototype.slice.call(a,0):!Array.isArray(a)&&a.constructor!==Uint8Array&&(a=a.toString());for(var o=i.bytesToWords(a),u=a.length*8,h=1732584193,l=-271733879,p=-1732584194,d=271733878,m=0;m<o.length;m++)o[m]=(o[m]<<8|o[m]>>>24)&16711935|(o[m]<<24|o[m]>>>8)&4278255360;o[u>>>5]|=128<<u%32,o[(u+64>>>9<<4)+14]=u;for(var g=r._ff,f=r._gg,v=r._hh,O=r._ii,m=0;m<o.length;m+=16){var B=h,C=l,U=p,re=d;h=g(h,l,p,d,o[m+0],7,-680876936),d=g(d,h,l,p,o[m+1],12,-389564586),p=g(p,d,h,l,o[m+2],17,606105819),l=g(l,p,d,h,o[m+3],22,-1044525330),h=g(h,l,p,d,o[m+4],7,-176418897),d=g(d,h,l,p,o[m+5],12,1200080426),p=g(p,d,h,l,o[m+6],17,-1473231341),l=g(l,p,d,h,o[m+7],22,-45705983),h=g(h,l,p,d,o[m+8],7,1770035416),d=g(d,h,l,p,o[m+9],12,-1958414417),p=g(p,d,h,l,o[m+10],17,-42063),l=g(l,p,d,h,o[m+11],22,-1990404162),h=g(h,l,p,d,o[m+12],7,1804603682),d=g(d,h,l,p,o[m+13],12,-40341101),p=g(p,d,h,l,o[m+14],17,-1502002290),l=g(l,p,d,h,o[m+15],22,1236535329),h=f(h,l,p,d,o[m+1],5,-165796510),d=f(d,h,l,p,o[m+6],9,-1069501632),p=f(p,d,h,l,o[m+11],14,643717713),l=f(l,p,d,h,o[m+0],20,-373897302),h=f(h,l,p,d,o[m+5],5,-701558691),d=f(d,h,l,p,o[m+10],9,38016083),p=f(p,d,h,l,o[m+15],14,-660478335),l=f(l,p,d,h,o[m+4],20,-405537848),h=f(h,l,p,d,o[m+9],5,568446438),d=f(d,h,l,p,o[m+14],9,-1019803690),p=f(p,d,h,l,o[m+3],14,-187363961),l=f(l,p,d,h,o[m+8],20,1163531501),h=f(h,l,p,d,o[m+13],5,-1444681467),d=f(d,h,l,p,o[m+2],9,-51403784),p=f(p,d,h,l,o[m+7],14,1735328473),l=f(l,p,d,h,o[m+12],20,-1926607734),h=v(h,l,p,d,o[m+5],4,-378558),d=v(d,h,l,p,o[m+8],11,-2022574463),p=v(p,d,h,l,o[m+11],16,1839030562),l=v(l,p,d,h,o[m+14],23,-35309556),h=v(h,l,p,d,o[m+1],4,-1530992060),d=v(d,h,l,p,o[m+4],11,1272893353),p=v(p,d,h,l,o[m+7],16,-155497632),l=v(l,p,d,h,o[m+10],23,-1094730640),h=v(h,l,p,d,o[m+13],4,681279174),d=v(d,h,l,p,o[m+0],11,-358537222),p=v(p,d,h,l,o[m+3],16,-722521979),l=v(l,p,d,h,o[m+6],23,76029189),h=v(h,l,p,d,o[m+9],4,-640364487),d=v(d,h,l,p,o[m+12],11,-421815835),p=v(p,d,h,l,o[m+15],16,530742520),l=v(l,p,d,h,o[m+2],23,-995338651),h=O(h,l,p,d,o[m+0],6,-198630844),d=O(d,h,l,p,o[m+7],10,1126891415),p=O(p,d,h,l,o[m+14],15,-1416354905),l=O(l,p,d,h,o[m+5],21,-57434055),h=O(h,l,p,d,o[m+12],6,1700485571),d=O(d,h,l,p,o[m+3],10,-1894986606),p=O(p,d,h,l,o[m+10],15,-1051523),l=O(l,p,d,h,o[m+1],21,-2054922799),h=O(h,l,p,d,o[m+8],6,1873313359),d=O(d,h,l,p,o[m+15],10,-30611744),p=O(p,d,h,l,o[m+6],15,-1560198380),l=O(l,p,d,h,o[m+13],21,1309151649),h=O(h,l,p,d,o[m+4],6,-145523070),d=O(d,h,l,p,o[m+11],10,-1120210379),p=O(p,d,h,l,o[m+2],15,718787259),l=O(l,p,d,h,o[m+9],21,-343485551),h=h+B>>>0,l=l+C>>>0,p=p+U>>>0,d=d+re>>>0}return i.endian([h,l,p,d])};r._ff=function(a,n,o,u,h,l,p){var d=a+(n&o|~n&u)+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._gg=function(a,n,o,u,h,l,p){var d=a+(n&u|o&~u)+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._hh=function(a,n,o,u,h,l,p){var d=a+(n^o^u)+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._ii=function(a,n,o,u,h,l,p){var d=a+(o^(n|~u))+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._blocksize=16,r._digestsize=16,Nn.exports=function(a,n){if(a==null)throw new Error("Illegal argument "+a);var o=i.wordsToBytes(r(a,n));return n&&n.asBytes?o:n&&n.asString?t.bytesToString(o):i.bytesToHex(o)}})();function On(i){return i?i.toLowerCase().indexOf("android")>=0||i.toLowerCase().indexOf("ios")>=0?"h5":"pc":"unknown"}function Dn(i){const s=_i(i),e=localStorage.getItem(s);if(e&&e.length===36)return e;const t=Mn();return localStorage.setItem(s,t),t}var Vt,Ot,ct;class Os{constructor(s){hi(this,Vt,void 0),hi(this,Ot,void 0),hi(this,ct,void 0);const u=s,{commonParams:e,version:t}=u,r=nr(u,["commonParams","version"]);li(this,Vt,new An(r)),li(this,ct,Dn(r.project));const a=new Ct;a.setUA(window.navigator.userAgent);const n=a.getResult(),o=W({av:t,os:n.os.name,ov:n.os.version,bt:n.browser.name,bv:n.browser.version,tt:On(n.os.name),uuid:It(this,ct),host:window.location.host},e);li(this,Ot,o)}getUUID(){return It(this,ct)}send(s,e,t){It(this,Vt).send(W(W({msgId:String(s),args:typeof e=="string"?e:new URLSearchParams(e).toString(),pu:window.location.href,ct:Date.now().toString()},It(this,Ot)),t))}}Vt=new WeakMap,Ot=new WeakMap,ct=new WeakMap;class Un{constructor(s){c(this,"index",0);c(this,"tracker");c(this,"enable",!0);c(this,"commonParams",{});if(s===!1){this.enable=!1;return}if(typeof s=="object"&&s.extraParams&&typeof s.extraParams=="string")try{this.commonParams={extra:s.extraParams}}catch(e){}this.tracker=new Os({version:Ge,host:"cn-hangzhou.log.aliyuncs.com",project:"web-rtc-grtn",logstore:"client",time:5,count:10,source:typeof s=="object"?s.biz:""})}updateAuthInfo(s){var e,t,r;this.commonParams=qe(W({},this.commonParams),{apid:(e=s==null?void 0:s.appId)!=null?e:"",usrid:(t=s==null?void 0:s.userId)!=null?t:"",channelid:(r=s==null?void 0:s.channelId)!=null?r:""})}reportJoinChannel(s){var t,r,a;const e={jnnonce:(t=s==null?void 0:s.nonce)!=null?t:"",jntoken:(r=s==null?void 0:s.token)!=null?r:"",jntm:(a=s==null?void 0:s.timestamp)!=null?a:""};this.report(70012,e)}reportJoinChannelRes(s,e,t){this.report(70013,{rslt:s,message:e,ct:t})}reportLeaveChannel(){this.report(70015)}reportPush(s,e,t,r,a,n,o,u,h,l,p,d){this.report(10030,{calid:s,isvl:e?1:0,isvs:t?1:0,isvss:r?1:0,isaudio:a?1:0,rslt:n,tid:o,pubtm:u,est:h,dctid:l,httptid:p,url:d})}reportPull(s,e,t,r,a,n,o,u,h,l,p,d){this.report(10050,{calid:s,rmtid:e,isvl:t?1:0,isvs:r?1:0,isvss:a?1:0,isaudio:n?1:0,rslt:o,tid:"",subtm:u,dctid:h,httptid:l,ajsub:1,url:p,est:d})}reportSubscribeAudioStats(s,e){const{ssrc:t,bytesReceived:r,packetsReceived:a,packetsLost:n,jitterBufferDelay:o,trackIdentifier:u,totalSamplesDuration:h,codec:l}=e,p=h,d=r/p,m=a/p,g=n/p,f=n/a;this.report(10080,{calid:"",rmtid:s,tckid:u,ssrc:t,codec:l,rbr:d,pr:m,pl:g,plr:f,jd:o})}reportSubscribeVideoStats(s,e){const{ssrc:t,bytesReceived:r,trackIdentifier:a,framesDecoded:n,framesReceived:o,frameHeight:u,frameWidth:h,nackCount:l,jitterBufferDelay:p,packetsReceived:d,packetsLost:m,totalInterFrameDelay:g,codec:f}=e,v=g,O=r/v,B=n/v,C=o/v,U=d/v,re=m/v,Ne=m/d;this.report(10080,{calid:"",rmtid:s,tckid:a,ssrc:t,codec:f,rbr:O,dfps:B,rfps:C,rh:u,rw:h,ns:l,jd:p,pr:U,pl:re,plr:Ne})}report(s,e,t){var r;this.enable&&((r=this.tracker)==null||r.send(s,e,W(W({},this.commonParams),t!=null?t:{})))}static reportCheck(s,e){new Os({version:Ge,host:"cn-hangzhou.log.aliyuncs.com",project:"web-rtc-grtn",logstore:"client",time:5,count:10,source:e!=null?e:""}).send(100001,s)}}class xn{constructor(){c(this,"reporter");c(this,"param");c(this,"msgCacheArr",[]);c(this,"index",0)}start(s){this.initParam(s),this.reporter=new dt.LogReporter({wsUrl:"wss://logprod.aliyuncs.com/binlog",webtrackingUrl:"",wsConfig:{product:1}});let e=window.setInterval(()=>{this.msgCacheArr.length?this.realSendReport(this.msgCacheArr.shift()):(clearInterval(e),e=0)},200)}stop(){this.reporter&&(this.reporter.close(),this.reporter=void 0)}sendReport(s){I.info("[LogClient]",s),this.msgCacheArr.length===0&&this.param?this.realSendReport(s):this.msgCacheArr.push(s)}initParam(s){this.param||(this.param={osn:N.SystemUtil.systemName,osv:N.SystemUtil.systemVersion,udid:N.LocalStorage.uuid,statsvrs:"0.6.1",sdkvrs:Ge,dm:N.BrowserUtil.domain,bt:N.BrowserUtil.browserName,bv:N.BrowserUtil.browserVersion,envir:"PRODUCT",apid:s.appId,usrid:s.userId,channelid:s.channelId,evetid:0,args:""})}realSendReport(s){var t;let e={};for(let r in this.param)e[r]=this.param[r];for(let r in s)e[r]=s[r];e.idx=this.index,++this.index,(t=this.reporter)==null||t.send(e)}}class Bn{constructor(){c(this,"logClient");this.logClient=new xn}start(s){this.logClient.start(s)}stop(){this.logClient.stop()}reportJoin(s,e,t){this.log({evetid:10010,args:this.data2String({joitm:s,rslt:e,mode:"wss",tid:t,gslbtm:0})})}reportJoinInvoked(s,e,t){this.log({evetid:60010,args:this.data2String({usrid:s,usrn:e,channelid:t,ua:navigator.userAgent})})}reportIceState(s,e,t){this.log({evetid:10011,args:this.data2String({calid:s,icestate:e,evt_seq:t})})}reportLeave(s,e,t){this.log({evetid:10020,args:this.data2String({lvetm:s,rslt:e,tid:t})})}reportLeaveInvoked(){this.log({evetid:60020})}reportPublish(s,e,t,r,a,n,o,u){this.log({evetid:10030,args:this.data2String({callid:s,isvl:e?1:0,isvs:t?1:0,isvss:r?1:0,isaudio:a?1:0,rslt:n,tid:o,pubtm:u})})}reportPublishInvoked(s,e,t,r){this.log({evetid:60030,args:this.data2String({isvl:typeof s=="boolean"?s?1:0:s,isvs:typeof e=="boolean"?e?1:0:e,isvss:typeof t=="boolean"?t?1:0:t,isaudio:typeof r=="boolean"?r?1:0:r})})}reportRepublish(s,e,t,r,a,n,o,u){this.log({evetid:10032,args:this.data2String({calid:s,isvl:e?1:0,isvs:0,isvss:t?1:0,isaudio:r?1:0,rslt:a,tid:n,repubtm:o,msg:u})})}reportRepublishInvoked(s,e,t){this.log({evetid:60032,args:this.data2String({callid:s,st:t,tp:e})})}reportUnpublish(s,e,t,r){this.log({evetid:10040,args:this.data2String({calid:s,unpubtm:e,rslt:t,tid:r})})}reportUnpublishInvoked(){this.log({evetid:60040})}reportSubscribe(s,e,t,r,a,n,o,u,h,l){this.log({evetid:10050,args:this.data2String({calid:s,rmtid:e,isvl:t?1:0,isvs:r?1:0,isvss:a?1:0,isaudio:n?1:0,rslt:o,tid:u,subtm:h,rmtuid:l})})}reportSubscribeInvoked(s="",e,t,r,a){this.log({evetid:60050,args:this.data2String({rmtid:s,isvl:typeof e=="boolean"?e?1:0:e,isvs:typeof t=="boolean"?t?1:0:t,isvss:typeof r=="boolean"?r?1:0:r,isaudio:typeof a=="boolean"?a?1:0:a})})}reportUnsubscribe(s,e,t,r,a){this.log({evetid:10060,args:this.data2String({calid:s,rmtid:e,unsubtm:t,rslt:r,tid:a})})}reportUnsubscribeInvoked(s=""){this.log({evetid:60060,args:this.data2String({rmtid:s})})}reportRoleUpdate(s,e,t,r){this.log({evetid:11040,args:this.data2String({or:s,nr:e,ctm:t,rslt:r})})}reportRoleUpdateInvoked(s){this.log({evetid:61040,args:this.data2String({nr:s})})}reportVideoProfile(s){this.log({evetid:20074,args:this.data2String({pf:s,tckid:"sophon_camera_large"})})}reportScreenProfile(s){this.log({evetid:20074,args:this.data2String({pf:s,tckid:"sophon_screenshare"})})}reportError(s){this.log({evetid:20090,args:this.data2String(s)})}log(s){s&&(s.tm=new Date().getTime()),this.logClient.sendReport(s)}data2String(s){let e="";for(let t in s)e.length&&(e+="&"),e+=t+"="+s[t];return e}}class Ds{constructor(s){c(this,"name","COMMON");this.name=s||this.name}info(...s){}warn(...s){}print(s,...e){const t=s.toLowerCase();t&&console[t](`[${s}][${this.name}]`,...e)}}c(Ds,"LEVEL",0);class Fn{constructor(){c(this,"logger",new Ds("AudioMixer"));c(this,"audioContext",new AudioContext);c(this,"audioDestination",this.audioContext.createMediaStreamDestination());c(this,"audioTrack",_r(this.audioDestination.stream));c(this,"sourceNodeMap",{})}get sourceNodeList(){return Object.values(this.sourceNodeMap).map(s=>s.sourceNode).filter(s=>!!s)}get gainNodeList(){return Object.values(this.sourceNodeMap).map(s=>s.gainNode).filter(s=>!!s)}get sourceCount(){return this.sourceNodeList.length}resume(){var s;return(s=this.audioContext)==null?void 0:s.resume()}addTrack(s){this.connectTrack(s)}hasTrack(s){return!!this.sourceNodeMap[s]}removeTrack(s){const{sourceNode:e,gainNode:t}=this.sourceNodeMap[s]||{};t==null||t.disconnect(),e==null||e.disconnect(),delete this.sourceNodeMap[s],e?this.logger.info("SourceNode disconnected. Active source node:",this.sourceNodeList.length):this.logger.warn(`SourceNode ${s} does not exit. Active source node: ${this.sourceNodeList.length}`)}getAudioTrack(){return this.audioTrack}setVolume(s,e){const{gainNode:t}=this.sourceNodeMap[e]||{};t?(this.logger.info(`Setting node(${e}) volume to ${this.scale(s)}`),t.gain.value=this.scale(s)):this.logger.warn(`GainNode ${e} does not exit.`)}reset(){this.disconnectSourceNode(),this.sourceNodeMap={}}dispose(){var s;this.reset(),(s=this.audioTrack)==null||s.stop(),this.audioDestination.disconnect(),this.audioContext.close()}connectTrack(s){if(!this.audioContext)return this.logger.warn("AudioContext not initialized");let e=new MediaStream;e.addTrack(s);const t=this.audioContext.createMediaStreamSource(e),r=this.audioContext.createGain();r.gain.value=1,t.connect(r),r.connect(this.audioDestination),this.sourceNodeMap[s.id]={track:s,sourceNode:t,gainNode:r},this.logger.info("New sourceNode connected. Active source node:",this.sourceNodeList.length)}disconnectSourceNode(){this.sourceNodeList.forEach(s=>s.disconnect()),this.gainNodeList.forEach(s=>s.disconnect())}scale(s){return s/100}}const Hn=4;class Wn extends We{constructor(){super("audioMixer",Q.AliRtcSdkStreamTypeCapture,gt.AUDIO);c(this,"audioMixer");c(this,"primaryAudioTrackId");c(this,"screenAudioTrackId");c(this,"dirty",!1);this.zIndex=8}get initOptions(){return{audio:1,screen:1}}setOptions(e){Object.entries(e).forEach(([t,r])=>{this.isValidVolume(r)&&(this.options[t]=r)}),this.dirty=!0,this.emit("updated")}isSupported(){return"AudioContext"in window}shouldUpdate(e,t){var n,o;if(e.type!==Q.AliRtcSdkStreamTypeCapture)return!1;const r=t.find(u=>u.type===Q.AliRtcSdkStreamTypeCapture),a=t.find(u=>u.type===Q.AliRtcSdkStreamTypeScreen);return!(this.primaryAudioTrackId===((n=r==null?void 0:r.currentAudioTrack)==null?void 0:n.id)&&this.screenAudioTrackId===((o=a==null?void 0:a.currentAudioTrack)==null?void 0:o.id)&&!this.dirty)}process(e,t){return S(this,null,function*(){var o,u;this.dirty=!1;const r=t.find(h=>h.type===Q.AliRtcSdkStreamTypeScreen),a=e.currentAudioTrack,n=r==null?void 0:r.currentAudioTrack;if(!n&&this.options.audio===1){this.audioMixer&&(this.audioMixer.dispose(),this.audioMixer=void 0),this.primaryAudioTrackId=a==null?void 0:a.id,e.updateAudioTrack(a);return}this.audioMixer||(this.audioMixer=new Fn),yield this.audioMixer.resume(),this.primaryAudioTrackId&&(a==null?void 0:a.id)!==this.primaryAudioTrackId&&((o=this.audioMixer)==null||o.removeTrack(this.primaryAudioTrackId)),a&&!this.audioMixer.hasTrack(a==null?void 0:a.id)&&this.audioMixer.addTrack(a),this.primaryAudioTrackId=a==null?void 0:a.id,this.screenAudioTrackId&&(n==null?void 0:n.id)!==this.screenAudioTrackId&&((u=this.audioMixer)==null||u.removeTrack(this.screenAudioTrackId)),n&&!this.audioMixer.hasTrack(n==null?void 0:n.id)&&this.audioMixer.addTrack(n),this.screenAudioTrackId=n==null?void 0:n.id,this.updateVolume(),e.updateAudioTrack(this.audioMixer.getAudioTrack())})}isValidVolume(e){return e!==void 0&&e>=0&&e<=Hn}updateVolume(){this.audioMixer&&(this.primaryAudioTrackId&&this.audioMixer.setVolume(this.options.audio*100,this.primaryAudioTrackId),this.screenAudioTrackId&&this.audioMixer.setVolume(this.options.screen*100,this.screenAudioTrackId))}clear(e){var t;(t=this.audioMixer)==null||t.dispose(),super.clear(e)}}class Ii{constructor(s,e){c(this,"originTrack");c(this,"originVideo");c(this,"targetWidth");c(this,"targetHeight");c(this,"targetFrameRate");c(this,"targetCanvas");c(this,"animationFrameId");c(this,"resultTrack");this.targetWidth=e.width,this.targetHeight=e.height,this.targetFrameRate=e.frameRate,this.originTrack=s,this.originVideo=document.createElement("video"),this.originVideo.muted=!0,this.originVideo.autoplay=!0,this.originVideo.controls=!1,this.targetCanvas=document.createElement("canvas"),this.targetCanvas.width=this.targetWidth,this.targetCanvas.height=this.targetHeight}updateOptions(s){this.targetWidth=s.width,this.targetHeight=s.height,this.targetFrameRate=s.frameRate,this.targetCanvas.width=this.targetWidth,this.targetCanvas.height=this.targetHeight,this.resultTrack&&this.resultTrack.applyConstraints({frameRate:this.targetFrameRate})}dispose(){}getVideoTrack(){return this.resultTrack||(this.resultTrack=this.targetCanvas.captureStream().getVideoTracks()[0],this.resultTrack.applyConstraints({frameRate:this.targetFrameRate})),this.resultTrack}cancelAnimation(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}getPositionAndSize(s,e,t,r){const a=e/s,n=r/t;let o=t,u=r,h=0,l=0;return n>a?(o=Math.round(u/a),h=Math.round((t-o)/2)):n<a&&(u=Math.round(o*a),l=Math.round((r-u)/2)),{x:h,y:l,width:o,height:u}}}class Kn extends Ii{constructor(e,t){super(e,t);c(this,"targetCtx");this.targetCtx=this.targetCanvas.getContext("2d"),this.startRender=this.startRender.bind(this),this.stopRender=this.startRender.bind(this),this.initStream(e)}initStream(e){const t=new MediaStream;t.addTrack(e),this.originVideo.srcObject=t,this.originVideo.play(),this.originVideo.addEventListener("canplay",this.startRender),this.originVideo.addEventListener("pause",this.stopRender),this.originVideo.addEventListener("ended",this.stopRender)}startRender(){this.cancelAnimation();const e=()=>{if(!this.targetCtx)return;const t=this.getPositionAndSize(this.originVideo.videoWidth,this.originVideo.videoHeight,this.targetWidth,this.targetHeight);this.targetCtx.drawImage(this.originVideo,0,0,this.originVideo.videoWidth,this.originVideo.videoHeight,t.x,t.y,t.width,t.height),!this.originVideo.paused&&!this.originVideo.ended&&(this.animationFrameId=requestAnimationFrame(e))};e()}stopRender(){this.cancelAnimation()}dispose(){this.stopRender(),this.originVideo.removeEventListener("play",this.startRender),this.originVideo.removeEventListener("pause",this.stopRender),this.originVideo.removeEventListener("ended",this.stopRender),this.originVideo.pause(),this.originVideo.srcObject=null}}const jn=`
|
|
11
|
+
*/var Ln=function(i){return i!=null&&(Vs(i)||Vn(i)||!!i._isBuffer)};function Vs(i){return!!i.constructor&&typeof i.constructor.isBuffer=="function"&&i.constructor.isBuffer(i)}function Vn(i){return typeof i.readFloatLE=="function"&&typeof i.slice=="function"&&Vs(i.slice(0,0))}(function(){var i=Ri,s=Ls.utf8,e=Ln,t=Ls.bin,r=function(a,n){a.constructor==String?n&&n.encoding==="binary"?a=t.stringToBytes(a):a=s.stringToBytes(a):e(a)?a=Array.prototype.slice.call(a,0):!Array.isArray(a)&&a.constructor!==Uint8Array&&(a=a.toString());for(var o=i.bytesToWords(a),u=a.length*8,h=1732584193,l=-271733879,p=-1732584194,d=271733878,m=0;m<o.length;m++)o[m]=(o[m]<<8|o[m]>>>24)&16711935|(o[m]<<24|o[m]>>>8)&4278255360;o[u>>>5]|=128<<u%32,o[(u+64>>>9<<4)+14]=u;for(var g=r._ff,f=r._gg,v=r._hh,O=r._ii,m=0;m<o.length;m+=16){var B=h,C=l,U=p,re=d;h=g(h,l,p,d,o[m+0],7,-680876936),d=g(d,h,l,p,o[m+1],12,-389564586),p=g(p,d,h,l,o[m+2],17,606105819),l=g(l,p,d,h,o[m+3],22,-1044525330),h=g(h,l,p,d,o[m+4],7,-176418897),d=g(d,h,l,p,o[m+5],12,1200080426),p=g(p,d,h,l,o[m+6],17,-1473231341),l=g(l,p,d,h,o[m+7],22,-45705983),h=g(h,l,p,d,o[m+8],7,1770035416),d=g(d,h,l,p,o[m+9],12,-1958414417),p=g(p,d,h,l,o[m+10],17,-42063),l=g(l,p,d,h,o[m+11],22,-1990404162),h=g(h,l,p,d,o[m+12],7,1804603682),d=g(d,h,l,p,o[m+13],12,-40341101),p=g(p,d,h,l,o[m+14],17,-1502002290),l=g(l,p,d,h,o[m+15],22,1236535329),h=f(h,l,p,d,o[m+1],5,-165796510),d=f(d,h,l,p,o[m+6],9,-1069501632),p=f(p,d,h,l,o[m+11],14,643717713),l=f(l,p,d,h,o[m+0],20,-373897302),h=f(h,l,p,d,o[m+5],5,-701558691),d=f(d,h,l,p,o[m+10],9,38016083),p=f(p,d,h,l,o[m+15],14,-660478335),l=f(l,p,d,h,o[m+4],20,-405537848),h=f(h,l,p,d,o[m+9],5,568446438),d=f(d,h,l,p,o[m+14],9,-1019803690),p=f(p,d,h,l,o[m+3],14,-187363961),l=f(l,p,d,h,o[m+8],20,1163531501),h=f(h,l,p,d,o[m+13],5,-1444681467),d=f(d,h,l,p,o[m+2],9,-51403784),p=f(p,d,h,l,o[m+7],14,1735328473),l=f(l,p,d,h,o[m+12],20,-1926607734),h=v(h,l,p,d,o[m+5],4,-378558),d=v(d,h,l,p,o[m+8],11,-2022574463),p=v(p,d,h,l,o[m+11],16,1839030562),l=v(l,p,d,h,o[m+14],23,-35309556),h=v(h,l,p,d,o[m+1],4,-1530992060),d=v(d,h,l,p,o[m+4],11,1272893353),p=v(p,d,h,l,o[m+7],16,-155497632),l=v(l,p,d,h,o[m+10],23,-1094730640),h=v(h,l,p,d,o[m+13],4,681279174),d=v(d,h,l,p,o[m+0],11,-358537222),p=v(p,d,h,l,o[m+3],16,-722521979),l=v(l,p,d,h,o[m+6],23,76029189),h=v(h,l,p,d,o[m+9],4,-640364487),d=v(d,h,l,p,o[m+12],11,-421815835),p=v(p,d,h,l,o[m+15],16,530742520),l=v(l,p,d,h,o[m+2],23,-995338651),h=O(h,l,p,d,o[m+0],6,-198630844),d=O(d,h,l,p,o[m+7],10,1126891415),p=O(p,d,h,l,o[m+14],15,-1416354905),l=O(l,p,d,h,o[m+5],21,-57434055),h=O(h,l,p,d,o[m+12],6,1700485571),d=O(d,h,l,p,o[m+3],10,-1894986606),p=O(p,d,h,l,o[m+10],15,-1051523),l=O(l,p,d,h,o[m+1],21,-2054922799),h=O(h,l,p,d,o[m+8],6,1873313359),d=O(d,h,l,p,o[m+15],10,-30611744),p=O(p,d,h,l,o[m+6],15,-1560198380),l=O(l,p,d,h,o[m+13],21,1309151649),h=O(h,l,p,d,o[m+4],6,-145523070),d=O(d,h,l,p,o[m+11],10,-1120210379),p=O(p,d,h,l,o[m+2],15,718787259),l=O(l,p,d,h,o[m+9],21,-343485551),h=h+B>>>0,l=l+C>>>0,p=p+U>>>0,d=d+re>>>0}return i.endian([h,l,p,d])};r._ff=function(a,n,o,u,h,l,p){var d=a+(n&o|~n&u)+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._gg=function(a,n,o,u,h,l,p){var d=a+(n&u|o&~u)+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._hh=function(a,n,o,u,h,l,p){var d=a+(n^o^u)+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._ii=function(a,n,o,u,h,l,p){var d=a+(o^(n|~u))+(h>>>0)+p;return(d<<l|d>>>32-l)+n},r._blocksize=16,r._digestsize=16,Nn.exports=function(a,n){if(a==null)throw new Error("Illegal argument "+a);var o=i.wordsToBytes(r(a,n));return n&&n.asBytes?o:n&&n.asString?t.bytesToString(o):i.bytesToHex(o)}})();function On(i){return i?i.toLowerCase().indexOf("android")>=0||i.toLowerCase().indexOf("ios")>=0?"h5":"pc":"unknown"}function Dn(i){const s=_i(i),e=localStorage.getItem(s);if(e&&e.length===36)return e;const t=kn();return localStorage.setItem(s,t),t}var Vt,Ot,ct;class Os{constructor(s){hi(this,Vt,void 0),hi(this,Ot,void 0),hi(this,ct,void 0);const u=s,{commonParams:e,version:t}=u,r=nr(u,["commonParams","version"]);li(this,Vt,new An(r)),li(this,ct,Dn(r.project));const a=new Ct;a.setUA(window.navigator.userAgent);const n=a.getResult(),o=W({av:t,os:n.os.name,ov:n.os.version,bt:n.browser.name,bv:n.browser.version,tt:On(n.os.name),uuid:It(this,ct),host:window.location.host},e);li(this,Ot,o)}getUUID(){return It(this,ct)}send(s,e,t){It(this,Vt).send(W(W({msgId:String(s),args:typeof e=="string"?e:new URLSearchParams(e).toString(),pu:window.location.href,ct:Date.now().toString()},It(this,Ot)),t))}}Vt=new WeakMap,Ot=new WeakMap,ct=new WeakMap;class Un{constructor(s){c(this,"index",0);c(this,"tracker");c(this,"enable",!0);c(this,"commonParams",{});if(s===!1){this.enable=!1;return}if(typeof s=="object"&&s.extraParams&&typeof s.extraParams=="string")try{this.commonParams={extra:s.extraParams}}catch(e){}this.tracker=new Os({version:Ge,host:"cn-hangzhou.log.aliyuncs.com",project:"web-rtc-grtn",logstore:"client",time:5,count:10,source:typeof s=="object"?s.biz:""})}updateAuthInfo(s){var e,t,r;this.commonParams=qe(W({},this.commonParams),{apid:(e=s==null?void 0:s.appId)!=null?e:"",usrid:(t=s==null?void 0:s.userId)!=null?t:"",channelid:(r=s==null?void 0:s.channelId)!=null?r:""})}reportJoinChannel(s){var t,r,a;const e={jnnonce:(t=s==null?void 0:s.nonce)!=null?t:"",jntoken:(r=s==null?void 0:s.token)!=null?r:"",jntm:(a=s==null?void 0:s.timestamp)!=null?a:""};this.report(70012,e)}reportJoinChannelRes(s,e,t){this.report(70013,{rslt:s,message:e,ct:t})}reportLeaveChannel(){this.report(70015)}reportPush(s,e,t,r,a,n,o,u,h,l,p,d){this.report(10030,{calid:s,isvl:e?1:0,isvs:t?1:0,isvss:r?1:0,isaudio:a?1:0,rslt:n,tid:o,pubtm:u,est:h,dctid:l,httptid:p,url:d})}reportPull(s,e,t,r,a,n,o,u,h,l,p,d){this.report(10050,{calid:s,rmtid:e,isvl:t?1:0,isvs:r?1:0,isvss:a?1:0,isaudio:n?1:0,rslt:o,tid:"",subtm:u,dctid:h,httptid:l,ajsub:1,url:p,est:d})}reportSubscribeAudioStats(s,e){const{ssrc:t,bytesReceived:r,packetsReceived:a,packetsLost:n,jitterBufferDelay:o,trackIdentifier:u,totalSamplesDuration:h,codec:l}=e,p=h,d=r/p,m=a/p,g=n/p,f=n/a;this.report(10080,{calid:"",rmtid:s,tckid:u,ssrc:t,codec:l,rbr:d,pr:m,pl:g,plr:f,jd:o})}reportSubscribeVideoStats(s,e){const{ssrc:t,bytesReceived:r,trackIdentifier:a,framesDecoded:n,framesReceived:o,frameHeight:u,frameWidth:h,nackCount:l,jitterBufferDelay:p,packetsReceived:d,packetsLost:m,totalInterFrameDelay:g,codec:f}=e,v=g,O=r/v,B=n/v,C=o/v,U=d/v,re=m/v,Ce=m/d;this.report(10080,{calid:"",rmtid:s,tckid:a,ssrc:t,codec:f,rbr:O,dfps:B,rfps:C,rh:u,rw:h,ns:l,jd:p,pr:U,pl:re,plr:Ce})}report(s,e,t){var r;this.enable&&((r=this.tracker)==null||r.send(s,e,W(W({},this.commonParams),t!=null?t:{})))}static reportCheck(s,e){new Os({version:Ge,host:"cn-hangzhou.log.aliyuncs.com",project:"web-rtc-grtn",logstore:"client",time:5,count:10,source:e!=null?e:""}).send(100001,s)}}class xn{constructor(){c(this,"reporter");c(this,"param");c(this,"msgCacheArr",[]);c(this,"index",0)}start(s){this.initParam(s),this.reporter=new dt.LogReporter({wsUrl:"wss://logprod.aliyuncs.com/binlog",webtrackingUrl:"",wsConfig:{product:1}});let e=window.setInterval(()=>{this.msgCacheArr.length?this.realSendReport(this.msgCacheArr.shift()):(clearInterval(e),e=0)},200)}stop(){this.reporter&&(this.reporter.close(),this.reporter=void 0)}sendReport(s){w.info("[LogClient]",s),this.msgCacheArr.length===0&&this.param?this.realSendReport(s):this.msgCacheArr.push(s)}initParam(s){this.param||(this.param={osn:N.SystemUtil.systemName,osv:N.SystemUtil.systemVersion,udid:N.LocalStorage.uuid,statsvrs:"0.6.1",sdkvrs:Ge,dm:N.BrowserUtil.domain,bt:N.BrowserUtil.browserName,bv:N.BrowserUtil.browserVersion,envir:"PRODUCT",apid:s.appId,usrid:s.userId,channelid:s.channelId,evetid:0,args:""})}realSendReport(s){var t;let e={};for(let r in this.param)e[r]=this.param[r];for(let r in s)e[r]=s[r];e.idx=this.index,++this.index,(t=this.reporter)==null||t.send(e)}}class Bn{constructor(){c(this,"logClient");this.logClient=new xn}start(s){this.logClient.start(s)}stop(){this.logClient.stop()}reportJoin(s,e,t){this.log({evetid:10010,args:this.data2String({joitm:s,rslt:e,mode:"wss",tid:t,gslbtm:0})})}reportJoinInvoked(s,e,t){this.log({evetid:60010,args:this.data2String({usrid:s,usrn:e,channelid:t,ua:navigator.userAgent})})}reportIceState(s,e,t){this.log({evetid:10011,args:this.data2String({calid:s,icestate:e,evt_seq:t})})}reportLeave(s,e,t){this.log({evetid:10020,args:this.data2String({lvetm:s,rslt:e,tid:t})})}reportLeaveInvoked(){this.log({evetid:60020})}reportPublish(s,e,t,r,a,n,o,u){this.log({evetid:10030,args:this.data2String({callid:s,isvl:e?1:0,isvs:t?1:0,isvss:r?1:0,isaudio:a?1:0,rslt:n,tid:o,pubtm:u})})}reportPublishInvoked(s,e,t,r){this.log({evetid:60030,args:this.data2String({isvl:typeof s=="boolean"?s?1:0:s,isvs:typeof e=="boolean"?e?1:0:e,isvss:typeof t=="boolean"?t?1:0:t,isaudio:typeof r=="boolean"?r?1:0:r})})}reportRepublish(s,e,t,r,a,n,o,u){this.log({evetid:10032,args:this.data2String({calid:s,isvl:e?1:0,isvs:0,isvss:t?1:0,isaudio:r?1:0,rslt:a,tid:n,repubtm:o,msg:u})})}reportRepublishInvoked(s,e,t){this.log({evetid:60032,args:this.data2String({callid:s,st:t,tp:e})})}reportUnpublish(s,e,t,r){this.log({evetid:10040,args:this.data2String({calid:s,unpubtm:e,rslt:t,tid:r})})}reportUnpublishInvoked(){this.log({evetid:60040})}reportSubscribe(s,e,t,r,a,n,o,u,h,l){this.log({evetid:10050,args:this.data2String({calid:s,rmtid:e,isvl:t?1:0,isvs:r?1:0,isvss:a?1:0,isaudio:n?1:0,rslt:o,tid:u,subtm:h,rmtuid:l})})}reportSubscribeInvoked(s="",e,t,r,a){this.log({evetid:60050,args:this.data2String({rmtid:s,isvl:typeof e=="boolean"?e?1:0:e,isvs:typeof t=="boolean"?t?1:0:t,isvss:typeof r=="boolean"?r?1:0:r,isaudio:typeof a=="boolean"?a?1:0:a})})}reportUnsubscribe(s,e,t,r,a){this.log({evetid:10060,args:this.data2String({calid:s,rmtid:e,unsubtm:t,rslt:r,tid:a})})}reportUnsubscribeInvoked(s=""){this.log({evetid:60060,args:this.data2String({rmtid:s})})}reportRoleUpdate(s,e,t,r){this.log({evetid:11040,args:this.data2String({or:s,nr:e,ctm:t,rslt:r})})}reportRoleUpdateInvoked(s){this.log({evetid:61040,args:this.data2String({nr:s})})}reportVideoProfile(s){this.log({evetid:20074,args:this.data2String({pf:s,tckid:"sophon_camera_large"})})}reportScreenProfile(s){this.log({evetid:20074,args:this.data2String({pf:s,tckid:"sophon_screenshare"})})}reportError(s){this.log({evetid:20090,args:this.data2String(s)})}log(s){s&&(s.tm=new Date().getTime()),this.logClient.sendReport(s)}data2String(s){let e="";for(let t in s)e.length&&(e+="&"),e+=t+"="+s[t];return e}}class Ds{constructor(s){c(this,"name","COMMON");this.name=s||this.name}info(...s){}warn(...s){}print(s,...e){const t=s.toLowerCase();t&&console[t](`[${s}][${this.name}]`,...e)}}c(Ds,"LEVEL",0);class Fn{constructor(){c(this,"logger",new Ds("AudioMixer"));c(this,"audioContext",new AudioContext);c(this,"audioDestination",this.audioContext.createMediaStreamDestination());c(this,"audioTrack",_r(this.audioDestination.stream));c(this,"sourceNodeMap",{})}get sourceNodeList(){return Object.values(this.sourceNodeMap).map(s=>s.sourceNode).filter(s=>!!s)}get gainNodeList(){return Object.values(this.sourceNodeMap).map(s=>s.gainNode).filter(s=>!!s)}get sourceCount(){return this.sourceNodeList.length}resume(){var s;return(s=this.audioContext)==null?void 0:s.resume()}addTrack(s){this.connectTrack(s)}hasTrack(s){return!!this.sourceNodeMap[s]}removeTrack(s){const{sourceNode:e,gainNode:t}=this.sourceNodeMap[s]||{};t==null||t.disconnect(),e==null||e.disconnect(),delete this.sourceNodeMap[s],e?this.logger.info("SourceNode disconnected. Active source node:",this.sourceNodeList.length):this.logger.warn(`SourceNode ${s} does not exit. Active source node: ${this.sourceNodeList.length}`)}getAudioTrack(){return this.audioTrack}setVolume(s,e){const{gainNode:t}=this.sourceNodeMap[e]||{};t?(this.logger.info(`Setting node(${e}) volume to ${this.scale(s)}`),t.gain.value=this.scale(s)):this.logger.warn(`GainNode ${e} does not exit.`)}reset(){this.disconnectSourceNode(),this.sourceNodeMap={}}dispose(){var s;this.reset(),(s=this.audioTrack)==null||s.stop(),this.audioDestination.disconnect(),this.audioContext.close()}connectTrack(s){if(!this.audioContext)return this.logger.warn("AudioContext not initialized");let e=new MediaStream;e.addTrack(s);const t=this.audioContext.createMediaStreamSource(e),r=this.audioContext.createGain();r.gain.value=1,t.connect(r),r.connect(this.audioDestination),this.sourceNodeMap[s.id]={track:s,sourceNode:t,gainNode:r},this.logger.info("New sourceNode connected. Active source node:",this.sourceNodeList.length)}disconnectSourceNode(){this.sourceNodeList.forEach(s=>s.disconnect()),this.gainNodeList.forEach(s=>s.disconnect())}scale(s){return s/100}}const Hn=4;class Wn extends He{constructor(){super("audioMixer",Q.AliRtcSdkStreamTypeCapture,gt.AUDIO);c(this,"audioMixer");c(this,"primaryAudioTrackId");c(this,"screenAudioTrackId");c(this,"dirty",!1);this.zIndex=8}get initOptions(){return{audio:1,screen:1}}setOptions(e){Object.entries(e).forEach(([t,r])=>{this.isValidVolume(r)&&(this.options[t]=r)}),this.dirty=!0,this.emit("updated")}isSupported(){return"AudioContext"in window}shouldUpdate(e,t){var n,o;if(e.type!==Q.AliRtcSdkStreamTypeCapture)return!1;const r=t.find(u=>u.type===Q.AliRtcSdkStreamTypeCapture),a=t.find(u=>u.type===Q.AliRtcSdkStreamTypeScreen);return!(this.primaryAudioTrackId===((n=r==null?void 0:r.currentAudioTrack)==null?void 0:n.id)&&this.screenAudioTrackId===((o=a==null?void 0:a.currentAudioTrack)==null?void 0:o.id)&&!this.dirty)}process(e,t){return S(this,null,function*(){var o,u;this.dirty=!1;const r=t.find(h=>h.type===Q.AliRtcSdkStreamTypeScreen),a=e.currentAudioTrack,n=r==null?void 0:r.currentAudioTrack;if(!n&&this.options.audio===1){this.audioMixer&&(this.audioMixer.dispose(),this.audioMixer=void 0),this.primaryAudioTrackId=a==null?void 0:a.id,e.updateAudioTrack(a);return}this.audioMixer||(this.audioMixer=new Fn),yield this.audioMixer.resume(),this.primaryAudioTrackId&&(a==null?void 0:a.id)!==this.primaryAudioTrackId&&((o=this.audioMixer)==null||o.removeTrack(this.primaryAudioTrackId)),a&&!this.audioMixer.hasTrack(a==null?void 0:a.id)&&this.audioMixer.addTrack(a),this.primaryAudioTrackId=a==null?void 0:a.id,this.screenAudioTrackId&&(n==null?void 0:n.id)!==this.screenAudioTrackId&&((u=this.audioMixer)==null||u.removeTrack(this.screenAudioTrackId)),n&&!this.audioMixer.hasTrack(n==null?void 0:n.id)&&this.audioMixer.addTrack(n),this.screenAudioTrackId=n==null?void 0:n.id,this.updateVolume(),e.updateAudioTrack(this.audioMixer.getAudioTrack())})}isValidVolume(e){return e!==void 0&&e>=0&&e<=Hn}updateVolume(){this.audioMixer&&(this.primaryAudioTrackId&&this.audioMixer.setVolume(this.options.audio*100,this.primaryAudioTrackId),this.screenAudioTrackId&&this.audioMixer.setVolume(this.options.screen*100,this.screenAudioTrackId))}clear(e){var t;(t=this.audioMixer)==null||t.dispose(),super.clear(e)}}class Ii{constructor(s,e){c(this,"originTrack");c(this,"originVideo");c(this,"targetWidth");c(this,"targetHeight");c(this,"targetFrameRate");c(this,"targetCanvas");c(this,"animationFrameId");c(this,"resultTrack");this.targetWidth=e.width,this.targetHeight=e.height,this.targetFrameRate=e.frameRate,this.originTrack=s,this.originVideo=document.createElement("video"),this.originVideo.muted=!0,this.originVideo.autoplay=!0,this.originVideo.controls=!1,this.targetCanvas=document.createElement("canvas"),this.targetCanvas.width=this.targetWidth,this.targetCanvas.height=this.targetHeight}updateOptions(s){this.targetWidth=s.width,this.targetHeight=s.height,this.targetFrameRate=s.frameRate,this.targetCanvas.width=this.targetWidth,this.targetCanvas.height=this.targetHeight,this.resultTrack&&this.resultTrack.applyConstraints({frameRate:this.targetFrameRate})}dispose(){}getVideoTrack(){return this.resultTrack||(this.resultTrack=this.targetCanvas.captureStream().getVideoTracks()[0],this.resultTrack.applyConstraints({frameRate:this.targetFrameRate})),this.resultTrack}cancelAnimation(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}getPositionAndSize(s,e,t,r){const a=e/s,n=r/t;let o=t,u=r,h=0,l=0;return n>a?(o=Math.round(u/a),h=Math.round((t-o)/2)):n<a&&(u=Math.round(o*a),l=Math.round((r-u)/2)),{x:h,y:l,width:o,height:u}}}class Kn extends Ii{constructor(e,t){super(e,t);c(this,"targetCtx");this.targetCtx=this.targetCanvas.getContext("2d"),this.startRender=this.startRender.bind(this),this.stopRender=this.startRender.bind(this),this.initStream(e)}initStream(e){const t=new MediaStream;t.addTrack(e),this.originVideo.srcObject=t,this.originVideo.play(),this.originVideo.addEventListener("canplay",this.startRender),this.originVideo.addEventListener("pause",this.stopRender),this.originVideo.addEventListener("ended",this.stopRender)}startRender(){this.cancelAnimation();const e=()=>{if(!this.targetCtx)return;const t=this.getPositionAndSize(this.originVideo.videoWidth,this.originVideo.videoHeight,this.targetWidth,this.targetHeight);this.targetCtx.drawImage(this.originVideo,0,0,this.originVideo.videoWidth,this.originVideo.videoHeight,t.x,t.y,t.width,t.height),!this.originVideo.paused&&!this.originVideo.ended&&(this.animationFrameId=requestAnimationFrame(e))};e()}stopRender(){this.cancelAnimation()}dispose(){this.stopRender(),this.originVideo.removeEventListener("play",this.startRender),this.originVideo.removeEventListener("pause",this.stopRender),this.originVideo.removeEventListener("ended",this.stopRender),this.originVideo.pause(),this.originVideo.srcObject=null}}const jn=`
|
|
12
12
|
attribute vec2 a_position;
|
|
13
13
|
attribute vec2 a_texCoord;
|
|
14
14
|
|
|
@@ -123,4 +123,4 @@ onmessage = function(evt) {
|
|
|
123
123
|
break;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
`;class Bs extends Ii{constructor(e,t){super(e,t);c(this,"processor");c(this,"trackGenerator");c(this,"worker");this.processor=new MediaStreamTrackProcessor({track:e}),this.trackGenerator=new MediaStreamTrackGenerator({kind:"video"}),this.startTransform()}static isSupport(){return"MediaStreamTrackProcessor"in window&&"MediaStreamTrackGenerator"in window&&"TransformStream"in window&&"VideoFrame"in window}startTransform(){const e=new Blob([Yn],{type:"text/javascript"}),r=(window.URL||window.webkitURL).createObjectURL(e);this.worker=new Worker(r);const{readable:a}=this.processor,{writable:n}=this.trackGenerator;this.worker.postMessage({type:"startRender",readable:a,writable:n,width:this.targetWidth,height:this.targetHeight,frameRate:this.targetFrameRate},[a,n])}updateOptions(e){super.updateOptions(e),this.worker&&this.worker.postMessage(W({type:"updateOptions"},e))}dispose(){try{this.processor.readable.cancel(),this.trackGenerator.writable.close()}catch(e){}}getVideoTrack(){return this.trackGenerator}}class Ai{static isSupport(){return typeof HTMLCanvasElement.prototype.captureStream=="function"}static getInstance(s,e){return Bs.isSupport()?new Bs(s,e):xs.isSupport()?new xs(s,e):new Kn(s,e)}}class Xn extends We{constructor(){super(...arguments);c(this,"hasVideoTrack",!1);c(this,"videoScaler")}get initOptions(){return{width:320,height:180,frameRate:15}}setOptions(e){var t;this.options=e,(t=this.videoScaler)==null||t.updateOptions(e)}isSupported(){return Ai.isSupport()}shouldUpdate(e){return this.hasVideoTrack!==!!e.currentVideoTrack}process(e){return S(this,null,function*(){if(e.currentVideoTrack){if(this.hasVideoTrack=!0,!this.videoScaler){const r=this.options||this.initOptions;this.videoScaler=Ai.getInstance(e.currentVideoTrack,r)}const t=this.videoScaler.getVideoTrack();t&&e.updateDualVideoTrack(t)}else e.updateDualVideoTrack(),this.emit("updated"),this.videoScaler&&this.videoScaler.dispose()})}clear(e){super.clear(e),e==null||e.updateDualVideoTrack()}}class Ti{static checkString(s){return typeof s=="string"}static checkNumber(s){return typeof s=="number"}static checkHtmlVideoElement(s){return s&&s.nodeName==="VIDEO"}static checkHtmlAudioElement(s){return s&&s.nodeName==="AUDIO"}static checkAuthInfo(s){let e=new A(T.ERR_JOIN_ERR_JOIN_BAD_PARAMBAD,"no authInfo");if(s){if(!s.appId)return e.message="no appId founded",e;if(!s.channelId)return e.message="no channelId founded",e;if(s.timestamp){if(!Ti.checkNumber(s.timestamp))return e.message="timestamp should be number",e}else return e.message="no timestamp founded",e;return s.token?s.userId?s.role!==void 0&&!["pub","sub","relay"].includes(s.role)?(e.message="role invalid",e):null:(e.message="no userId founded",e):(e.message="no token founded",e)}else return e}static checkMediaStreamTrack(s){return s instanceof MediaStreamTrack}static checkVideoEncoderConfiguration(s){return s&&(s.width||s.height||s.frameRate||s.bitrateMax)}}class Fs{constructor(s){c(this,"taskProfile");c(this,"encodeParam");c(this,"users",[]);c(this,"backgroundColor",0);c(this,"backgrounds",[]);c(this,"watermarks",[]);c(this,"clockWidgets",[]);c(this,"cropMode");c(this,"mediaProcessMode");this.taskProfile=s}}class Hs{constructor(s,e,t){c(this,"userId");c(this,"streamType");c(this,"sourceType");this.userId=s,this.streamType=e,this.sourceType=t}}class Ws{constructor(s,e,t,r=0,a=16777215,n=Qe.NOTO_SERIF_CJKSC_REGULAR){c(this,"x");c(this,"y");c(this,"fontSize");c(this,"zOrder");c(this,"fontColor");c(this,"fontType");this.x=s,this.y=e,this.fontSize=t,this.zOrder=r,this.fontColor=a,this.fontType=n}toJson(s,e){return{x:pe(this.x,s),y:pe(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:ii(this.fontColor),zorder:this.zOrder}}}var Ks=(i=>(i[i.NOT_DISPLAY=0]="NOT_DISPLAY",i[i.ALWAYS=1]="ALWAYS",i[i.WHEN_NO_VIDEO=2]="WHEN_NO_VIDEO",i))(Ks||{});class Ei{constructor(s,e,t,r,a,n=0,o=1,u=1){c(this,"url");c(this,"x");c(this,"y");c(this,"width");c(this,"height");c(this,"alpha");c(this,"display",1);c(this,"zOrder");this.url=s,this.x=e,this.y=t,this.width=r,this.height=a,this.zOrder=n,this.alpha=o,this.display=u}toJson(s,e){return{url:this.url,alpha:this.alpha,display:this.display,x:pe(this.x,s),y:pe(this.y,e),width:pe(this.width,s),height:pe(this.height,e),zorder:this.zOrder}}}c(Ei,"DisplayType",Ks);class js{constructor(s,e,t,r,a=0,n=16777215,o=Qe.NOTO_SERIF_CJKSC_REGULAR){c(this,"text");c(this,"x");c(this,"y");c(this,"fontSize");c(this,"zOrder");c(this,"fontColor");c(this,"fontType");this.text=s,this.x=e,this.y=t,this.fontSize=r,this.zOrder=a,this.fontColor=n,this.fontType=o}toJson(s,e){return{text:this.text,x:pe(this.x,s),y:pe(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:ii(this.fontColor),zorder:this.zOrder}}}class $s{constructor(s,e,t,r,a,n=0,o){c(this,"userId");c(this,"x");c(this,"y");c(this,"width");c(this,"height");c(this,"zOrder");c(this,"sourceType");c(this,"segmentType",Ze.LiveTranscodingNoBody);c(this,"images",[]);c(this,"texts",[]);typeof s=="number"?this.userId=s.toString():this.userId=s,this.x=e,this.y=t,this.width=r,this.height=a,this.zOrder=n,o&&(this.sourceType=o)}toJson(s,e,t,r){const a={paneid:s,majorpane:0,x:pe(this.x,e),y:pe(this.y,t),width:pe(this.width,e),height:pe(this.height,t),zorder:this.zOrder,userid:this.userId,images:this.images.map(n=>n.toJson(e,t)),texts:this.texts.map(n=>n.toJson(e,t))};return this.sourceType&&Xe[this.sourceType]?a.sourcetype=Xe[this.sourceType]:a.sourcetype=Xe[Ke.LiveTranscodingCamera],this.segmentType&&r===ft.LiveTranscodingVirtualBackground?a.segmenttype=this.segmentType:a.segmenttype=Ze.LiveTranscodingNoBody,a}}class Zn extends We{constructor(){super("AliRtcScreenStandardize",Q.AliRtcSdkStreamTypeScreen);c(this,"canvas");c(this,"lastWidth");c(this,"lastHeight");c(this,"hasScreenTrack",!1)}get initOptions(){return{base:4}}setOptions(e){this.options=e}isSupported(){return!(typeof TransformStream=="undefined"||typeof MediaStreamTrackProcessor=="undefined"||typeof MediaStreamTrackGenerator=="undefined")}updateProcessCanvas(e,t){if(this.canvas&&this.lastWidth===e&&this.lastHeight===t)return;const r=Math.ceil(e/this.options.base)*this.options.base,a=Math.ceil(t/this.options.base)*this.options.base;if(this.canvas||(this.canvas=document.createElement("canvas")),this.canvas.width=r,this.canvas.height=a,this.lastWidth&&e>this.lastWidth||this.lastHeight&&t>this.lastHeight){const n=this.canvas.getContext("2d");n&&n.clearRect(0,0,r,a)}this.lastWidth=e,this.lastHeight=t}shouldUpdate(e){return this.hasScreenTrack!==(!!e.originVideoTrack&&e.videoSource===_e.Screen)}handleFrame(e,t){return S(this,null,function*(){var o;const{displayWidth:r,displayHeight:a}=e;if(!r||!a||r%this.options.base===0&&a%this.options.base===0)return this.clear(t),e;this.updateProcessCanvas(r,a);const n=(o=this.canvas)==null?void 0:o.getContext("2d");if(this.canvas&&n){n.drawImage(e,0,0,r,a);const u=new VideoFrame(this.canvas,{timestamp:e.timestamp});return e.close(),u}return e})}process(e){return S(this,null,function*(){var l;if(!e.originVideoTrack||e.videoSource!==_e.Screen){this.clear(e),this.hasScreenTrack=!1;return}const t=new MediaStreamTrackProcessor({track:e.originVideoTrack}),r=new MediaStreamTrackGenerator({kind:"video"}),a=new MediaStream([r]),n=this,o=new TransformStream({transform(p,d){return S(this,null,function*(){const m=yield n.handleFrame(p,e);yield d.enqueue(m),m==null||m.close()})}});t.readable.pipeThrough(o).pipeTo(r.writable);const u=(l=a.getVideoTracks())==null?void 0:l[0];e.updateVideoTrack(u),this.hasScreenTrack=!0})}clear(e){this.canvas=void 0,this.lastWidth=void 0,this.lastHeight=void 0,super.clear(e)}}var Qn=Object.defineProperty,eo=Object.getOwnPropertyDescriptor,M=(i,s,e,t)=>{for(var r=t>1?void 0:t?eo(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Qn(s,e,r),r};const k=(y=class extends J{constructor(e){super();c(this,"channelProfile");c(this,"clientRole");c(this,"signalingManager");c(this,"userManager");c(this,"liveTranscoding");c(this,"maxSignalingConnectRetryCount");c(this,"reporter");c(this,"webTrackingClient");c(this,"connectState",K.AliRtcConnectionStatusInit);c(this,"networkError",!1);c(this,"moduleName","AliRtcEngine");c(this,"audioMixerPlugin");c(this,"dualVideoPlugin");c(this,"_audioOnlyMode",!1);c(this,"_authInfoWillExpireTimer",null);c(this,"_authInfoExpiredTimer",null);c(this,"_serverCheckAuthInfoTimestamp",null);c(this,"_localCheckAuthInfoTimestamp",null);this.webTrackingClient=new Un(e==null?void 0:e.webTrack),this.reporter=new Bn,this.channelProfile=Te.AliRtcSdkCommunication,this.clientRole=Pe.AliRtcSdkLive,this.liveTranscoding=new Kr,this.signalingManager=new Sr(this.channelProfile,this.clientRole,(e==null?void 0:e.env)===ye.pre?ye.pre:ye.prod),this.addSignalingManagerListeners(),this.maxSignalingConnectRetryCount=e==null?void 0:e.maxSignalingConnectRetryCount,this.userManager=new le({reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager}),this.addUserManagerListeners(),this.addPublisherListeners(),this.audioMixerPlugin=new Wn,this.enablePlugin(this.audioMixerPlugin),this.dualVideoPlugin=new Xn("dualVideoPlugin"),this.enablePlugin(new Zn)}static getSdkVersion(){return Ge}static setLogLevel(e){I.setLogLevel(e)}static getInstance(e){return y._instance||(y._instance=new y(e)),y._instance}destroy(){y._instance=void 0}get channel(){return this.userManager.channel}get userId(){return this.userManager.userId}get remoteUsers(){return this.userManager.remoteUsers}get publisher(){return this.userManager.publisher}get publishAudioStream(){var e;return(e=this.publisher)==null?void 0:e.publishStreams.audio}get isPublishing(){const{publisher:e}=this.userManager;return e?e.isPublishing:!1}get currentRoleCanPublish(){return this.channelProfile===Te.AliRtcSdkCommunication||this.clientRole===Pe.AliRtcSdkInteractive}resetState(){return S(this,null,function*(){yield this.userManager.clear(),this.connectState=K.AliRtcConnectionStatusDisconnected,this.networkError=!1,this.signalingManager.reset(),this.liveTranscoding.clear(),this.reporter.stop(),yield this.publishLocalAudioStream(!0),yield this.publishLocalVideoStream(!0),yield this.publishLocalScreenShareStream(!0)})}stopPublish(e){return S(this,null,function*(){var t,r,a;e?yield(t=this.publisher)==null?void 0:t.stopLocalStream(e):(yield(r=this.publisher)==null?void 0:r.publishStop(),(a=this.publisher)==null||a.stopPreview())})}addPublisherListeners(){var e,t,r,a,n,o,u,h,l;(e=this.publisher)==null||e.on(ie.Local,p=>{I.event("[Publisher] Device Status Change",p),this.onLocalDeviceStatusChange(p)}),(t=this.publisher)==null||t.on(De.VideoTrackEnded,()=>{I.event("[Publisher] VideoTrack Ended"),this.emit("localDeviceException",we.AliEngineLocalDeviceTypeCamera,X.AliEngineLocalDeviceExceptionTypeCameraInterrupt,"")}),(r=this.publisher)==null||r.on(De.ScreenTrackEnded,()=>{I.event("[Publisher] ScreenTrack Ended"),this.emit("localDeviceException",we.AliEngineLocalDeviceTypeDisplay,X.AliEngineLocalDeviceExceptionTypeDisplayException,"")}),(a=this.publisher)==null||a.on(De.AudioTrackEnded,()=>{I.event("[Publisher] AudioTrack Ended"),this.emit("localDeviceException",we.AliEngineLocalDeviceTypeMic,X.AliEngineLocalDeviceExceptionTypeMicInterrupt,"")}),(n=this.publisher)==null||n.on("localDeviceException",(p,d,m="")=>{this.emit("localDeviceException",p,d,m)}),(o=this.publisher)==null||o.on("audioPublishStateChanged",(p,d,m)=>{var g;this.emit("audioPublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")}),(u=this.publisher)==null||u.on("videoPublishStateChanged",(p,d,m)=>{var g;this.emit("videoPublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")}),(h=this.publisher)==null||h.on("dualStreamPublishStateChanged",(p,d,m)=>{var g;this.emit("dualStreamPublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")}),(l=this.publisher)==null||l.on("screenPublishStateChanged",(p,d,m)=>{var g;this.emit("screenSharePublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")})}addUserManagerListeners(){this.userManager.rtsManager.on("reconnecting",()=>S(this,null,function*(){!this.networkError&&!(yield Ae.isNetworkAvailable())&&this.onNetworkError()})),this.userManager.rtsManager.on("disconnected",()=>S(this,null,function*(){I.event("[UserManager] RTS Disconnected"),(yield Ae.isNetworkAvailable())?(yield this.resumePublishForNetworkRecovery(),yield this.resumeSubList()):this.onNetworkError()})),this.userManager.rtsManager.on("subscribeexceeds",()=>S(this,null,function*(){yield this.resumePublishForNetworkRecovery(),yield this.resumeSubList()})),this.userManager.rtsManager.on("seimessage",(e,t,r)=>{const a=this.remoteUsers.find(n=>n.streamUrl===e);a&&this.emit("mediaExtensionMsgReceived",a.userId,r,t)}),this.userManager.on(ie.Remote,(e,t)=>{I.event("[UserManager] RemoteUser Device Status Change",e,t)}),this.userManager.on("remoteTrackAvailableChange",(e,t,r)=>{this.emit("remoteTrackAvailableNotify",e,t,r)}),this.userManager.on("audioSubscribeStateChanged",(e,t,r,a,n)=>{this.emit("audioSubscribeStateChanged",e,t,r,a,n)}),this.userManager.on("videoSubscribeStateChanged",(e,t,r,a,n)=>{this.emit("videoSubscribeStateChanged",e,t,r,a,n)}),this.userManager.on("screenSubscribeStateChanged",(e,t,r,a,n)=>{this.emit("screenShareSubscribeStateChanged",e,t,r,a,n)}),this.userManager.on("userAudioMuted",(e,t)=>{this.emit("userAudioMuted",e,t)}),this.userManager.on("userVideoMuted",(e,t)=>{this.emit("userVideoMuted",e,t)}),this.userManager.on("userScreenMuted",(e,t)=>{this.emit("userScreenMuted",e,t)}),this.userManager.on("audioVolume",e=>{this.emit("audioVolume",e)}),this.userManager.on("remoteAudioAutoPlayFail",e=>{this.emit("remoteAudioAutoPlayFail",e)}),this.userManager.on("remoteVideoAutoPlayFail",(e,t)=>{this.emit("remoteVideoAutoPlayFail",e,t)}),this.userManager.on("rtcLocalAudioStats",e=>{this.emit("rtcLocalAudioStats",e)}),this.userManager.on("rtcLocalVideoStats",e=>{this.emit("rtcLocalVideoStats",e)}),this.userManager.on("rtcRemoteAudioStats",e=>{this.emit("rtcRemoteAudioStats",e)}),this.userManager.on("rtcRemoteVideoStats",e=>{this.emit("rtcRemoteVideoStats",e)}),this.userManager.on("remoteSubscribeError",e=>{this.emit("onOccurError",e)})}addSignalingManagerListeners(){this.signalingManager.on("onKeepAliveRsp",()=>{this.networkError&&I.event("[Signaling] Receive KeepAlive Response",`networkError: ${this.networkError}`),this.networkError&&this.onNetworkRecovery()}),this.signalingManager.on("onNotifyJoin",e=>{I.event("[Signaling] Notify Join ",e),this.handleUsersJoin(e),e.forEach(t=>{this.emit("remoteUserOnLineNotify",t.userid,0)})}),this.signalingManager.on("onNotifyStatus",e=>{I.event("[Signaling] Notify Status ",e),e.forEach(t=>{this.userManager.updateRemoteUserDeviceStatus(t)})}),this.signalingManager.on("onNotifyLeave",e=>{I.event("[Signaling] Notify Leave ",e),e.forEach(t=>{this.emit("remoteUserOffLineNotify",t.userid,t.leavecode),this.userManager.removeLeftUser(t)})}),this.signalingManager.on("onBye",(e,t)=>{I.event("[Signaling] Bye ",e,t),this.reporter.reportError({message:`reason: ${e}, description: ${t}`}),this.emit("bye",e),this.leaveChannel(!0)}),this.signalingManager.on("onConnectFail",e=>{I.event("[Signaling] Connect Failed ",e),this.onError(e),this.backToUnpublishStatus(),this.connectState=K.AliRtcConnectionStatusFailed,this.emit("connectionStatusChange",K.AliRtcConnectionStatusFailed,Le.AliRtcConnectionChangedNetworkInterrupted)}),this.signalingManager.on("onNetworkError",e=>{I.event("[Signaling] Network error ",e),this.onNetworkError()}),this.signalingManager.on("onAuthInvalid",()=>{I.event("[Signaling] Auth Invalid")}),this.signalingManager.on("onReconnectStart",()=>{I.event("[Signaling] Reconnect Start "),this.connectState=K.AliRtcConnectionStatusReconnecting,this.emit("connectionStatusChange",K.AliRtcConnectionStatusReconnecting,Le.AliRtcConnectionSignalingConnecting)}),this.signalingManager.on("onReconnectSuccess",e=>{I.event("[Signaling] Reconnect Success ",e),this.onNetworkRecovery(e)}),this.signalingManager.on("onReconnectFail",e=>{I.event("[Signaling] Reconnect Failed ",e),e.code===403&&this.emit("authInfoExpired")}),this.signalingManager.on("onError",e=>{I.event("[Signaling] Error ",e),this.onError(e)})}backToUnpublishStatus(){var e,t;this.connectState=K.AliRtcConnectionStatusDisconnected,(e=this.publisher)!=null&&e.isPublishing&&((t=this.publisher)==null||t.clearPublishState()),this.networkError=!1}handleUsersJoin(e){e.forEach(t=>{const r=t.userid;if(r){const a=this.userManager.addUser(r,t.displayname);I.event(this.moduleName,H.UserJoined,a)}})}onLocalDeviceStatusChange(e){I.event(`[${this.moduleName}]`,ie.Local,e),this.signalingManager.reportStatus(e).then(()=>{I.debug("[signaling] reportStatus suc")}).catch(t=>{I.error("[signaling] reportStatus failed",t)})}resumePublishForNetworkRecovery(){return S(this,null,function*(){var e;try{yield(e=this.publisher)==null?void 0:e.resumePublish()}catch(t){const{code:r}=t;if(r===10205){let n=1;try{yield new Promise((o,u)=>{const h=setInterval(()=>S(this,null,function*(){var l;n>1&&(clearInterval(h),u()),n+=1;try{yield(l=this.publisher)==null?void 0:l.resumePublish(),clearInterval(h),o()}catch(p){const{code:d}=p;d!==10205&&(clearInterval(h),u())}}),1e3)})}catch(o){}}}})}onNetworkRecovery(e){return S(this,null,function*(){var t;I.event(this.moduleName,"onNetworkRecovery",{users:e}),this.networkError&&(this.networkError=!1,(t=this.publisher)==null||t.reportSelfDeviceStatus(),yield this.resumePublishForNetworkRecovery(),this.connectState=K.AliRtcConnectionStatusConnected,this.emit("connectionStatusChange",K.AliRtcConnectionStatusConnected,Le.AliRtcConnectionSignalingHeartbeatAlive)),yield this.resumeSubList(e)})}resumeSubList(e){return S(this,null,function*(){const t="resumeSubList";if(e!=null&&e.length){const{joinList:r,leaveList:a,presentList:n}=this.userManager.updateUsers(e);I.info(`[${this.moduleName}/${t}]`,{joinList:r,leaveList:a,presentList:n}),this.handleUsersJoin(r),a.forEach(o=>{I.event(this.moduleName,H.UserLeft,o.userid,o.reason),this.emit("remoteUserOffLineNotify",o.userid,zt.AliRtcUserOfflineQuit)});for(let o=0;o<n.length;o++){const u=n[o],h=u.userid,l=this.userManager.getRemoteUser(h);this.userManager.onRemotePublishStateChange(u),l==null||l.restore(),l==null||l.updateSubscribe()}}else for(let r=0;r<this.remoteUsers.length;r++){const a=this.remoteUsers[r];try{a.restore(),a.updateSubscribe()}catch(n){}}})}onNetworkError(){this.connectState===K.AliRtcConnectionStatusConnected&&(this.networkError||(this.connectState=K.AliRtcConnectionStatusDisconnected,this.emit("connectionStatusChange",K.AliRtcConnectionStatusDisconnected,Le.AliRtcConnectionChangedNetworkInterrupted)),this.networkError=!0)}onError(e){this.reporter.reportError(e),I.event(this.moduleName,H.Error,e)}setEnableDualVideoStream(e,t){t&&this.dualVideoPlugin.setOptions(t);const r=this.userManager.pluginManager.has(this.dualVideoPlugin.name);e?!r&&this.enablePlugin(this.dualVideoPlugin):r&&this.removePlugin(this.dualVideoPlugin.name)}hadPushStream(e){if(!(this.publisher&&e))throw new A(T.ERR_INNER,"stream is not publishing")}getCurrentMicDeviceId(){var e;return(e=this.publisher)==null?void 0:e.getCurrentMicDeviceId()}setChannelProfile(e){if(![K.AliRtcConnectionStatusInit,K.AliRtcConnectionStatusDisconnected,K.AliRtcConnectionStatusFailed].includes(this.connectState))throw new A(T.ERR_INNER,"cannot set channel profile in call");this.channelProfile=e,this.channelProfile===Te.AliRtcSdkCommunication&&(this.clientRole=Pe.AliRtcSdkLive),this.signalingManager.setChannelProfile(e)}setClientRole(e){return S(this,null,function*(){var t,r,a,n,o;try{if(this.channelProfile===Te.AliRtcSdkCommunication)return;if(!Object.values(Pe).includes(e))throw new A(T.ERR_INVALID_ARGUMENTS,`set client role error, role value(${e}) is invalid`);if(this.clientRole===e)return;this.isInCall()?this.clientRole===Pe.AliRtcSdkInteractive?(this.userManager.isSubscribing?(yield this.stopPublish(),yield(t=this.publisher)==null?void 0:t.clearStream()):yield(r=this.publisher)==null?void 0:r.unPublish(),yield this.signalingManager.setClientRole(e)):(yield this.signalingManager.setClientRole(e),yield this.startDefaultDevicesCapture(),(a=this.publisher)!=null&&a.isPublishing||(yield(n=this.publisher)==null?void 0:n.startPublish()),yield(o=this.publisher)==null?void 0:o.previewAll()):yield this.signalingManager.setClientRole(e),this.clientRole=e}catch(u){throw u.code===403&&this.emit("authInfoExpired"),u}})}getCurrentClientRole(){return this.clientRole}setAudioOnlyMode(e){if(this.isInCall())throw new A(T.ERR_INNER,"cannot not change audioOnly mode in call");this._audioOnlyMode=e}setCheckAuthInfoTimer(e,t){const r=(e-t)*1e3;this._authInfoExpiredTimer=window.setTimeout(()=>{this.emit("authInfoExpired")},r),this._authInfoWillExpireTimer=window.setTimeout(()=>{this.emit("authInfoWillExpire")},r-3e4),this._serverCheckAuthInfoTimestamp=t,this._localCheckAuthInfoTimestamp=+Date.now()/1e3}clearCheckAuthInfoTimer(){this._authInfoExpiredTimer&&window.clearTimeout(this._authInfoExpiredTimer),this._authInfoWillExpireTimer&&window.clearTimeout(this._authInfoWillExpireTimer)}startDefaultDevicesCapture(){return S(this,null,function*(){var r,a;let e,t;try{e=yield y.getCameraList(),t=yield y.getMicrophoneList(),!e.length&&!t.length&&console.warn("No media neither devices can be captured");const{hasCamera:n,hasMicrophone:o,hasScreenShare:u,audioCaptureDisabled:h,publishLocalAudioStreamEnabled:l,publishLocalVideoStreamEnabled:p}=(r=this.publisher)!=null?r:{};if(n||o||u)return;!n&&p&&!this._audioOnlyMode&&e.length&&!((a=this.publisher)!=null&&a.cameraCaptureDisabled)&&(yield this.enableLocalVideo(!0)),!o&&l&&!h&&t.length&&(yield this.startAudioCapture())}catch(n){throw n}})}joinChannel(e,t){return S(this,null,function*(){var n,o,u,h,l,p;let r=new Date().getTime(),a=Ti.checkAuthInfo(e);if(this.webTrackingClient.updateAuthInfo(e),this.webTrackingClient.reportJoinChannel(e),K.AliRtcConnectionStatusInit===this.connectState||K.AliRtcConnectionStatusDisconnected===this.connectState||K.AliRtcConnectionStatusFailed===this.connectState){if(this.connectState=K.AliRtcConnectionStatusConnecting,a)throw this.connectState=K.AliRtcConnectionStatusFailed,this.webTrackingClient.reportJoinChannelRes(a.code,a.message,0),this.reporter.reportJoin(0,a.code,a.message),a;e.callid=Ae.createCallid(),this.reporter.start(e);try{const d=yield this.signalingManager.join(e,t,this.maxSignalingConnectRetryCount);this.connectState=K.AliRtcConnectionStatusConnected,(n=this.publisher)==null||n.reportSelfDeviceStatus();let m=new Date().getTime()-r;this.webTrackingClient.reportJoinChannelRes(0,"",m),this.reporter.reportJoin(m,0,d.tid),this.userManager.init(e,d),this.setCheckAuthInfoTimer(e.timestamp,d.timestamp),this.currentRoleCanPublish&&(yield this.startDefaultDevicesCapture(),Object.values((u=(o=this.publisher)==null?void 0:o.publishStreams)!=null?u:{}).some(g=>g)&&(yield(h=this.publisher)==null?void 0:h.startPublish(),yield(l=this.publisher)==null?void 0:l.previewAll())),this.remoteUsers.forEach(g=>{g.updateSubscribe()}),this.liveTranscoding.setAuthInfo(e)}catch(d){let m=new Date().getTime()-r;const g=(p=d.code)!=null?p:-1,f=d.reason||d.message||"";throw this.webTrackingClient.reportJoinChannelRes(g,f,m),this.connectState=K.AliRtcConnectionStatusDisconnected,this.reporter.reportJoin(m,g,""),new A(g,f)}}else{const d=new A(T.ERR_JOIN_ALREADY_JOINED,"already joined");throw this.connectState===K.AliRtcConnectionStatusConnecting&&(d.message="Repeated operation during login"),this.webTrackingClient.reportJoinChannelRes(d.code,d.message,0),this.reporter.reportJoin(0,d.code,""),d}})}leaveChannel(e=!1){return S(this,null,function*(){var r;this.reporter.reportLeaveInvoked(),this.webTrackingClient.reportLeaveChannel();let t=new Date().getTime();if(K.AliRtcConnectionStatusConnected===this.connectState)try{let a;e||(a=yield this.signalingManager.leave()),this.clearCheckAuthInfoTimer(),yield this.resetState(),this.reporter.reportLeave(new Date().getTime()-t,0,(r=a==null?void 0:a.tid)!=null?r:""),I.setFlushMode(!0);return}catch(a){throw this.reporter.reportLeave(new Date().getTime()-t,a.code,a.reason),a}else{yield this.resetState(),this.reporter.reportLeave(0,0,""),I.setFlushMode(!0);return}})}isInCall(){return this.connectState===K.AliRtcConnectionStatusConnected}refreshAuthInfo(e){return S(this,null,function*(){const{userId:t,nonce:r,timestamp:a,token:n,role:o}=e,u={userId:t,nonce:r,timestamp:a,token:n,role:o};try{yield this.signalingManager.refreshAuthInfo(u),this.userManager.refreshAuthInfo(u),this.liveTranscoding.refreshAuthInfo(u),this.clearCheckAuthInfoTimer(),this._serverCheckAuthInfoTimestamp&&this._localCheckAuthInfoTimestamp&&e.timestamp&&this.setCheckAuthInfoTimer(e.timestamp,this._serverCheckAuthInfoTimestamp+(Date.now()-this._localCheckAuthInfoTimestamp))}catch(h){throw h}})}isAudioOnly(){return this._audioOnlyMode}publishLocalAudioStream(e){return S(this,null,function*(){var t,r,a;(t=this.publisher)==null||t.setPublishLocalAudioStreamEnabled(e),this.connectState===K.AliRtcConnectionStatusConnected&&(e?(r=this.publisher)!=null&&r.hasMicrophone?yield(a=this.publisher)==null?void 0:a.publishUpdate():yield this.startAudioCapture():yield this.stopPublish({audio:!0}))})}isLocalAudioStreamPublished(){var e,t;return(t=(e=this.publisher)==null?void 0:e.publishLocalAudioStreamEnabled)!=null?t:!0}setDefaultSubscribeAllRemoteAudioStreams(e){this.userManager.setAutoSubAudio(e)}subscribeAllRemoteAudioStreams(e){this.userManager.setWantSubAudio(e)}subscribeRemoteAudioStream(e,t){if(t&&!this.userManager.isWantSubAudio)throw new A(T.ERR_INVALID_ARGUMENTS,"subscribeAllRemoteAudioStreams(true) must be called first");this.userManager.updateAudioWant(e,t)}resumeRemoteAudioStream(e){const t=this.userManager.getRemoteUser(e);t&&t.resumeAudio()}publishLocalVideoStream(e){return S(this,null,function*(){var t,r,a;(t=this.publisher)==null||t.setPublishLocalVideoStreamEnabled(e),this.connectState===K.AliRtcConnectionStatusConnected&&(e?(r=this.publisher)!=null&&r.hasCamera?yield(a=this.publisher)==null?void 0:a.publishUpdate():yield this.enableLocalVideo():yield this.stopPublish({video:!0}))})}isLocalVideoStreamPublished(){var e,t;return(t=(e=this.publisher)==null?void 0:e.publishLocalVideoStreamEnabled)!=null?t:!0}setRemoteDefaultVideoStreamType(e){[oe.AliRtcVideoStreamTypeHigh,oe.AliRtcVideoStreamTypeLow].includes(e)&&this.userManager.setRemoteDefaultVideoStreamType(e)}setDefaultSubscribeAllRemoteVideoStreams(e){this.userManager.setAutoSubVideo(e),this.userManager.setAutoSubScreen(e)}subscribeAllRemoteVideoStreams(e){this.userManager.setWantSubVideo(e),this.userManager.setWantSubScreen(e)}subscribeRemoteMediaStream(e,t,r,a){const n=this.userManager.getRemoteUser(e);if(!n)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r&&(t===x.AliRtcVideoTrackScreen||t===x.AliRtcVideoTrackBoth)?n.setWantSubScreen(!0):n.setWantSubScreen(!1),r&&(t===x.AliRtcVideoTrackCamera||t===x.AliRtcVideoTrackBoth)?n.setWantSubVideo(!0):n.setWantSubVideo(!1),n.setWantSubAudio(a),n.updateSubscribe()}resumeRemoteMediaStream(e,t){const r=this.userManager.getRemoteUser(e);r&&r.resumeVideo(t)}getOnlineRemoteUsers(){return this.userManager.remoteUsers.map(e=>e.userId)}getUserInfo(e){var t;return(t=this.userManager.getRemoteUser(e))==null?void 0:t.remoteUserInfo}isUserOnline(e){return!!this.userManager.remoteUsers.find(t=>t.userId===e)}startScreenShare(e){return S(this,null,function*(){var o;const t={video:!1,audio:!1},{audio:r=!1,videoTrack:a,audioTrack:n}=e||{};if(a||n){t.screen=!0;const u=new MediaStream;a&&u.addTrack(a),n&&u.addTrack(n),t.mediaStream=u}else t.screen=r?{audio:!0}:!0;yield(o=this.publisher)==null?void 0:o.createLocalStream(t)})}stopScreenShare(){return S(this,null,function*(){var e;(e=this.publisher)==null||e.stopLocalStream({screen:!0})})}setScreenShareConfiguration(e){return S(this,null,function*(){var a;const{frameRate:t=tt.frameRate,bitrate:r=tt.maxBitrate}=e;yield(a=this.publisher)==null?void 0:a.setScreenProfile(Ji,{width:tt.width,height:tt.height,frameRate:t,maxBitrate:r})})}setScreenShareContentHint(e){return S(this,null,function*(){var t;e&&((t=this.publisher)==null||t.setScreenContentHint(e))})}publishLocalScreenShareStream(e,t){return S(this,null,function*(){var r,a,n;(r=this.publisher)==null||r.setPublishLocalScreenStreamEnabled(e),this.connectState===K.AliRtcConnectionStatusConnected&&(e?(a=this.publisher)!=null&&a.hasScreenShare?yield(n=this.publisher)==null?void 0:n.publishUpdate():yield this.startScreenShare(t):yield this.stopPublish({screen:!0}))})}isScreenSharePublished(){var e,t;return(t=(e=this.publisher)==null?void 0:e.publishLocalScreenStreamEnabled)!=null?t:!0}setAudioShareVolume(e){if(typeof e!="number")throw new A(T.ERR_INVALID_ARGUMENTS,"volume must be a number");this.audioMixerPlugin.setOptions({screen:Math.max(0,Math.min(e,400))/100})}enableAudioVolumeIndication(e){this.userManager.enableAudioVolumeIndication(e)}muteLocalMic(e=!1){var t;this.isPublishing&&this.onLocalDeviceStatusChange(e?H.MuteAudio:H.UnmuteAudio),(t=this.publisher)==null||t.muteLocalMic(e)}muteRemoteAudioPlaying(e,t=!1){const r=this.userManager.getRemoteUser(e);if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.toggleAudio(!t)}muteAllRemoteAudioPlaying(e=!1){this.userManager.setAudioMuted(e)}startAudioCapture(e){return S(this,null,function*(){var r;const t={audio:e||!0};yield(r=this.publisher)==null?void 0:r.createLocalStream(t)})}stopAudioCapture(){var e;(e=this.publisher)==null||e.stopAudioCapture()}switchMicrophone(e){return S(this,null,function*(){var t,r,a;yield(t=this.publisher)==null?void 0:t.setMicrophoneDeviceId(e),(r=this.publisher)!=null&&r.audioCaptureDisabled||(yield(a=this.publisher)==null?void 0:a.createLocalStream({audio:{deviceId:e}}))})}setRecordingVolume(e){if(typeof e!="number")throw new A(T.ERR_INVALID_ARGUMENTS,"volume must be a number");this.audioMixerPlugin.setOptions({audio:Math.max(0,Math.min(e,400))/100})}setAudioProfile(e){return S(this,null,function*(){var t;yield(t=this.publisher)==null?void 0:t.setAudioProfile(e)})}getAudioTrack(e){return S(this,null,function*(){var r;if(!e)return(r=this.publisher)==null?void 0:r.audioTrack;const t=this.userManager.getRemoteUser(e);return t==null?void 0:t.getAudioTrack})}setLocalViewConfig(e,t){return S(this,null,function*(){var r,a,n;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot set local view in audio only mode");(r=this.userManager)==null||r.setLocalViewConfig(e,t),t===x.AliRtcVideoTrackCamera&&((a=this.publisher)!=null&&a.hasCamera)?yield this.startPreview():t===x.AliRtcVideoTrackScreen&&((n=this.publisher)!=null&&n.hasScreenShare)&&(yield this.startPreviewScreen())})}setCameraCapturerConfiguration(e){return S(this,null,function*(){var h,l,p;const{width:t=et.width,height:r=et.height,frameRate:a=et.frameRate,bitrate:n=et.maxBitrate,cameraDirection:o,deviceId:u}=e;yield(h=this.publisher)==null?void 0:h.setVideoProfile($i,{width:t,height:r,frameRate:a,maxBitrate:n}),o!==void 0&&((l=this.publisher)==null||l.setCameraDirection(o)),u&&((p=this.publisher)==null||p.setCameraDeviceId(u))})}setCameraCapturerContentHint(e){return S(this,null,function*(){var t;e&&((t=this.publisher)==null||t.setVideoContentHint(e))})}enableLocalVideo(e=!0){return S(this,null,function*(){var t,r,a,n,o,u,h,l,p,d,m;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot enable local video in audio only mode");if(e){(r=(t=this.publisher)==null?void 0:t.publishStreams)!=null&&r.video&&((o=(n=(a=this.publisher)==null?void 0:a.publishStreams)==null?void 0:n.video)==null||o.disableVideo(),(p=(l=(h=(u=this.publisher)==null?void 0:u.publishStreams)==null?void 0:h.video)==null?void 0:l.videoTrack)==null||p.stop());const g={video:!0};yield(d=this.publisher)==null?void 0:d.startCameraCapture(g)}else yield(m=this.publisher)==null?void 0:m.stopCameraCapture()})}muteLocalCamera(e){return S(this,null,function*(){var t;this.isPublishing&&this.onLocalDeviceStatusChange(e?H.MuteVideo:H.UnmuteVideo),(t=this.publisher)==null||t.muteLocalCamera(e)})}muteLocalScreen(e){return S(this,null,function*(){var t;this.isPublishing&&this.onLocalDeviceStatusChange(e?H.MuteScreen:H.UnmuteScreen),(t=this.publisher)==null||t.muteLocalScreen(e)})}setRemoteViewConfig(e,t,r){this.userManager.setRemoteViewConfig(t,e,r)}isCameraOn(){var e,t;return(t=(e=this.publisher)==null?void 0:e.hasCamera)!=null?t:!1}switchCamera(e){return S(this,null,function*(){var r,a,n,o,u,h,l,p,d,m,g,f;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot switch camera in audio only mode");const t={};e?t.deviceId=e:t.cameraDirection=((r=this.publisher)==null?void 0:r.cameraDirection)==="environment"?ze.CAMERA_FRONT:ze.CAMERA_REAR,yield this.setCameraCapturerConfiguration(t),(a=this.publisher)!=null&&a.cameraCaptureDisabled||((o=(n=this.publisher)==null?void 0:n.publishStreams)!=null&&o.video&&((l=(h=(u=this.publisher)==null?void 0:u.publishStreams)==null?void 0:h.video)==null||l.disableVideo(),(g=(m=(d=(p=this.publisher)==null?void 0:p.publishStreams)==null?void 0:d.video)==null?void 0:m.videoTrack)==null||g.stop()),yield(f=this.publisher)==null?void 0:f.createLocalStream({video:!0}))})}getCurrentCameraDeviceId(){var e;return(e=this.publisher)==null?void 0:e.getCurrentCameraDeviceId()}startPreview(){return S(this,null,function*(){var e,t;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot start preview camera in audio only mode");(e=this.publisher)!=null&&e.hasCamera||(yield this.enableLocalVideo(!0)),yield(t=this.publisher)==null?void 0:t.previewAll({screen:!1})})}startPreviewScreen(e){return S(this,null,function*(){var t,r;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot start preview screen share in audio only mode");(t=this.publisher)!=null&&t.hasScreenShare||(yield this.startScreenShare(e)),yield(r=this.publisher)==null?void 0:r.previewAll({primary:!1})})}stopPreview(){return S(this,null,function*(){var e;yield(e=this.publisher)==null?void 0:e.stopPreview({primary:!0,screen:!1})})}stopPreviewScreen(){return S(this,null,function*(){var e;yield(e=this.publisher)==null?void 0:e.stopPreview({primary:!1,screen:!0})})}getVideoTrack(e){return S(this,null,function*(){var n,o,u,h;const{userId:t,streamType:r}=e;if(!t)return r===Q.AliRtcSdkStreamTypeCapture?(n=this.publisher)==null?void 0:n.cameraTrack:(o=this.publisher)==null?void 0:o.screenTrack;const a=this.userManager.getRemoteUser(t);return r===Q.AliRtcSdkStreamTypeCapture?(u=a==null?void 0:a.getCameraStream)==null?void 0:u.videoTrack:(h=a==null?void 0:a.getScreenStream)==null?void 0:h.videoTrack})}startPublishLiveStream(e,t){return S(this,null,function*(){return this.liveTranscoding.startPublishLiveStream(e,t)})}updatePublishLiveStream(e,t){return S(this,null,function*(){return this.liveTranscoding.updatePublishLiveStream(e,t)})}updatePublishLiveStreamWithTaskId(e,t){return this.liveTranscoding.updatePublishLiveStreamWithTaskId(e,t)}stopPublishLiveStream(e){return S(this,null,function*(){return this.liveTranscoding.stopPublishLiveStream(e)})}stopPublishLiveStreamWithTaskId(e){return this.liveTranscoding.stopPublishLiveStreamWithTaskId(e)}setEnableMediaExtensionMsg(e){var t;(t=this.userManager)==null||t.setEnableMediaExtensionMsg(!!e)}sendMediaExtensionMsg(e,t){return S(this,null,function*(){return this.sendMediaExtensionMsgEx(e,t,5)})}sendMediaExtensionMsgEx(e,t,r){return S(this,null,function*(){var a;if(!this.publisher||!this.isPublishing)throw new A(T.ERR_INNER,"you should publish first");return(a=this.publisher)==null?void 0:a.sendSEI(e,t,r)})}enablePlugin(e,t){this.userManager.pluginManager.add(e,t)}removePlugin(e){this.userManager.pluginManager.remove(e)}setPluginOption(e,t){const r=this.userManager.pluginManager.get(e);r&&t&&r.setOptions(t)}getPluginOption(e){const t=this.userManager.pluginManager.get(e);return t==null?void 0:t.getOptions()}isBeautyAvailable(){return this.userManager.pluginManager.has("AliRtcBeauty")}isBeautyEnabled(){const e=this.userManager.pluginManager.get("AliRtcBeauty");if(!e)throw new A(Me.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");return!!(e!=null&&e.isEnable)}setBeautyEffect(e,t){const r=this.userManager.pluginManager.get("AliRtcBeauty");if(!r)throw new A(Me.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");e?r.enable():r.disable(),r.setOptions({basicBeauty:{skinBuffing:Math.max(Math.min(1,+t.smoothnessLevel),0),whitening:Math.max(Math.min(1,+t.whiteningLevel),0)}})}enableBackgroundExchange(e,t){const r=this.userManager.pluginManager.get("AliRtcBeauty");if(!r||!r.isEnable)throw new A(Me.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");const a={setSegmentBackgroundImage:{backgroundImgUrl:e?t:""}};e&&(a.segmentBackgroundProcess={enable:!1}),r.setOptions(a)}enableBackgroundBlur(e){const t=this.userManager.pluginManager.get("AliRtcBeauty");if(!t||!t.isEnable)throw new A(Me.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");const r={segmentBackgroundProcess:{type:0,enable:e}};e&&(r.setSegmentBackgroundImage={type:0,backgroundImgUrl:""}),t.setOptions(r)}},c(y,"logName","AliRtcEngine"),c(y,"isSupported",or),c(y,"isDualVideoStreamSupported",Ai.isSupport),c(y,"getCameraList",()=>S(y,null,function*(){return(yield P.AliRTS.getCameraList()).filter(t=>t.deviceId)})),c(y,"getMicrophoneList",()=>S(y,null,function*(){return(yield P.AliRTS.getMicList()).filter(t=>t.deviceId)})),c(y,"getSpeakerList",()=>S(y,null,function*(){return(yield P.AliRTS.getSpeakerList()).filter(t=>t.deviceId)})),c(y,"_instance"),c(y,"AliRtcSdkChannelProfile",Te),c(y,"AliRtcSdkClientRole",Pe),c(y,"AliRtcVideoStreamType",oe),c(y,"AliRtcVideoTrack",x),c(y,"AliRtcAudioTrack",He),c(y,"AliRtcPublishState",V),c(y,"AliRtcSubscribeState",G),c(y,"AliRtcRawDataStreamType",Q),c(y,"AliRtcLogLevel",Gt),c(y,"AliRtcEngineLocalDeviceType",we),c(y,"AliRtcEngineLocalDeviceExceptionType",X),c(y,"AliRtcConnectionStatus",K),c(y,"AliRtcConnectionStatusChangeReason",Le),c(y,"AliRtcPlugin",We),c(y,"AliRtcPluginTrackType",gt),c(y,"AliRtcLiveTranscodingParam",bt),c(y,"AliRtcLiveTranscodingEncodeParam",ti),c(y,"AliRtcLiveTranscodingMixParam",Fs),c(y,"AliRtcLiveTranscodingSingleParam",Hs),c(y,"AliRtcTranscodingClockWidget",Ws),c(y,"AliRtcTranscodingImage",Ei),c(y,"AliRtcTranscodingText",js),c(y,"AliRtcTranscodingUser",$s),c(y,"AliRtcLiveTranscodingMixMode",Ye),c(y,"AliRtcLiveTranscodingStreamType",Yt),c(y,"AliRtcLiveTranscodingSourceType",Ke),c(y,"AliRtcLiveTranscodingTaskProfile",Xt),c(y,"AliRtcLiveTranscodingAudioSampleRate",St),c(y,"AliRtcLiveTranscodingSegmentType",Ze),c(y,"AliRtcLiveTranscodingFontType",Qe),c(y,"AliRtcLiveTranscodingCropMode",Zt),c(y,"AliRtcLiveTranscodingMediaProcessMode",ft),c(y,"AliRtcLiveTranscodingState",Qt),c(y,"AliRtcLiveTranscodingErrorCode",Re),c(y,"AliRtcTrascodingPublishTaskStatus",ei),c(y,"Plugin",We),y);M([b(R)],k.prototype,"stopPublish",1),M([b()],k.prototype,"resumeSubList",1),M([b(R)],k.prototype,"setEnableDualVideoStream",1),M([b(R)],k.prototype,"setChannelProfile",1),M([b(R)],k.prototype,"setClientRole",1),M([b(R)],k.prototype,"setAudioOnlyMode",1),M([b(R)],k.prototype,"joinChannel",1),M([b(R)],k.prototype,"leaveChannel",1),M([b(R)],k.prototype,"refreshAuthInfo",1),M([b(R)],k.prototype,"publishLocalAudioStream",1),M([b(R)],k.prototype,"setDefaultSubscribeAllRemoteAudioStreams",1),M([b(R)],k.prototype,"subscribeAllRemoteAudioStreams",1),M([b(R)],k.prototype,"subscribeRemoteAudioStream",1),M([b(R)],k.prototype,"resumeRemoteAudioStream",1),M([b(R)],k.prototype,"publishLocalVideoStream",1),M([b(R)],k.prototype,"setRemoteDefaultVideoStreamType",1),M([b(R)],k.prototype,"setDefaultSubscribeAllRemoteVideoStreams",1),M([b(R)],k.prototype,"subscribeAllRemoteVideoStreams",1),M([b(R)],k.prototype,"subscribeRemoteMediaStream",1),M([b(R)],k.prototype,"resumeRemoteMediaStream",1),M([b(([i])=>[`${i==null?void 0:i.audio}`])],k.prototype,"startScreenShare",1),M([b(R)],k.prototype,"setScreenShareConfiguration",1),M([b(R)],k.prototype,"setScreenShareContentHint",1),M([b()],k.prototype,"publishLocalScreenShareStream",1),M([b(R)],k.prototype,"setAudioShareVolume",1),M([b(R)],k.prototype,"enableAudioVolumeIndication",1),M([b(R)],k.prototype,"muteLocalMic",1),M([b(R)],k.prototype,"muteRemoteAudioPlaying",1),M([b(R)],k.prototype,"muteAllRemoteAudioPlaying",1),M([b(R)],k.prototype,"startAudioCapture",1),M([b()],k.prototype,"stopAudioCapture",1),M([b(R)],k.prototype,"switchMicrophone",1),M([b(R)],k.prototype,"setRecordingVolume",1),M([b(R)],k.prototype,"setAudioProfile",1),M([b(R)],k.prototype,"getAudioTrack",1),M([b(R)],k.prototype,"setLocalViewConfig",1),M([b(R)],k.prototype,"setCameraCapturerConfiguration",1),M([b(R)],k.prototype,"setCameraCapturerContentHint",1),M([b(R)],k.prototype,"enableLocalVideo",1),M([b(R)],k.prototype,"muteLocalCamera",1),M([b(R)],k.prototype,"muteLocalScreen",1),M([b(R)],k.prototype,"setRemoteViewConfig",1),M([b(R)],k.prototype,"switchCamera",1),M([b()],k.prototype,"startPublishLiveStream",1),M([b()],k.prototype,"updatePublishLiveStream",1),M([b()],k.prototype,"updatePublishLiveStreamWithTaskId",1),M([b()],k.prototype,"stopPublishLiveStream",1),M([b()],k.prototype,"stopPublishLiveStreamWithTaskId",1),M([b(R)],k.prototype,"setEnableMediaExtensionMsg",1),M([b(([i,s,e])=>[i.length,s,e])],k.prototype,"sendMediaExtensionMsgEx",1);let to=k;_.AliRtcConnectionStatus=K,_.AliRtcConnectionStatusChangeReason=Le,_.AliRtcEngineLocalDeviceExceptionType=X,_.AliRtcEngineLocalDeviceType=we,_.AliRtcErrorCode=T,_.AliRtcLiveTranscodingAudioSampleRate=St,_.AliRtcLiveTranscodingCropMode=Zt,_.AliRtcLiveTranscodingEncodeParam=ti,_.AliRtcLiveTranscodingErrorCode=Re,_.AliRtcLiveTranscodingFontType=Qe,_.AliRtcLiveTranscodingMediaProcessMode=ft,_.AliRtcLiveTranscodingMixMode=Ye,_.AliRtcLiveTranscodingMixParam=Fs,_.AliRtcLiveTranscodingParam=bt,_.AliRtcLiveTranscodingSegmentType=Ze,_.AliRtcLiveTranscodingSingleParam=Hs,_.AliRtcLiveTranscodingSourceType=Ke,_.AliRtcLiveTranscodingState=Qt,_.AliRtcLiveTranscodingStreamType=Yt,_.AliRtcLiveTranscodingTaskProfile=Xt,_.AliRtcLocalStreamInfo=ci,_.AliRtcLogLevel=Gt,_.AliRtcPlugin=We,_.AliRtcPluginTrackType=gt,_.AliRtcPluginType=Fi,_.AliRtcPublishState=V,_.AliRtcRawDataStreamType=Q,_.AliRtcRemoteUserInfo=Yi,_.AliRtcSdkChannelProfile=Te,_.AliRtcSdkClientRole=Pe,_.AliRtcSubscribeState=G,_.AliRtcTranscodingClockWidget=Ws,_.AliRtcTranscodingImage=Ei,_.AliRtcTranscodingText=js,_.AliRtcTranscodingUser=$s,_.AliRtcTrascodingPublishTaskStatus=ei,_.AliRtcVideoStreamType=oe,_.AliRtcVideoTrack=x,_.default=to,Object.defineProperties(_,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
126
|
+
`;class Bs extends Ii{constructor(e,t){super(e,t);c(this,"processor");c(this,"trackGenerator");c(this,"worker");this.processor=new MediaStreamTrackProcessor({track:e}),this.trackGenerator=new MediaStreamTrackGenerator({kind:"video"}),this.startTransform()}static isSupport(){return"MediaStreamTrackProcessor"in window&&"MediaStreamTrackGenerator"in window&&"TransformStream"in window&&"VideoFrame"in window}startTransform(){const e=new Blob([Yn],{type:"text/javascript"}),r=(window.URL||window.webkitURL).createObjectURL(e);this.worker=new Worker(r);const{readable:a}=this.processor,{writable:n}=this.trackGenerator;this.worker.postMessage({type:"startRender",readable:a,writable:n,width:this.targetWidth,height:this.targetHeight,frameRate:this.targetFrameRate},[a,n])}updateOptions(e){super.updateOptions(e),this.worker&&this.worker.postMessage(W({type:"updateOptions"},e))}dispose(){try{this.processor.readable.cancel(),this.trackGenerator.writable.close()}catch(e){}}getVideoTrack(){return this.trackGenerator}}class Ai{static isSupport(){return typeof HTMLCanvasElement.prototype.captureStream=="function"}static getInstance(s,e){return Bs.isSupport()?new Bs(s,e):xs.isSupport()?new xs(s,e):new Kn(s,e)}}class Xn extends He{constructor(){super(...arguments);c(this,"hasVideoTrack",!1);c(this,"videoScaler")}get initOptions(){return{width:320,height:180,frameRate:15}}setOptions(e){var t;this.options=e,(t=this.videoScaler)==null||t.updateOptions(e)}isSupported(){return Ai.isSupport()}shouldUpdate(e){return this.hasVideoTrack!==!!e.currentVideoTrack}process(e){return S(this,null,function*(){if(e.currentVideoTrack){if(this.hasVideoTrack=!0,!this.videoScaler){const r=this.options||this.initOptions;this.videoScaler=Ai.getInstance(e.currentVideoTrack,r)}const t=this.videoScaler.getVideoTrack();t&&e.updateDualVideoTrack(t)}else e.updateDualVideoTrack(),this.emit("updated"),this.videoScaler&&this.videoScaler.dispose()})}clear(e){super.clear(e),e==null||e.updateDualVideoTrack()}}class Ti{static checkString(s){return typeof s=="string"}static checkNumber(s){return typeof s=="number"}static checkHtmlVideoElement(s){return s&&s.nodeName==="VIDEO"}static checkHtmlAudioElement(s){return s&&s.nodeName==="AUDIO"}static checkAuthInfo(s){let e=new A(T.ERR_JOIN_ERR_JOIN_BAD_PARAMBAD,"no authInfo");if(s){if(!s.appId)return e.message="no appId founded",e;if(!s.channelId)return e.message="no channelId founded",e;if(s.timestamp){if(!Ti.checkNumber(s.timestamp))return e.message="timestamp should be number",e}else return e.message="no timestamp founded",e;return s.token?s.userId?s.role!==void 0&&!["pub","sub","relay"].includes(s.role)?(e.message="role invalid",e):null:(e.message="no userId founded",e):(e.message="no token founded",e)}else return e}static checkMediaStreamTrack(s){return s instanceof MediaStreamTrack}static checkVideoEncoderConfiguration(s){return s&&(s.width||s.height||s.frameRate||s.bitrateMax)}}class Fs{constructor(s){c(this,"taskProfile");c(this,"encodeParam");c(this,"users",[]);c(this,"backgroundColor",0);c(this,"backgrounds",[]);c(this,"watermarks",[]);c(this,"clockWidgets",[]);c(this,"cropMode");c(this,"mediaProcessMode");this.taskProfile=s}}class Hs{constructor(s,e,t){c(this,"userId");c(this,"streamType");c(this,"sourceType");this.userId=s,this.streamType=e,this.sourceType=t}}class Ws{constructor(s,e,t,r=0,a=16777215,n=Ze.NOTO_SERIF_CJKSC_REGULAR){c(this,"x");c(this,"y");c(this,"fontSize");c(this,"zOrder");c(this,"fontColor");c(this,"fontType");this.x=s,this.y=e,this.fontSize=t,this.zOrder=r,this.fontColor=a,this.fontType=n}toJson(s,e){return{x:pe(this.x,s),y:pe(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:ti(this.fontColor),zorder:this.zOrder}}}var Ks=(i=>(i[i.NOT_DISPLAY=0]="NOT_DISPLAY",i[i.ALWAYS=1]="ALWAYS",i[i.WHEN_NO_VIDEO=2]="WHEN_NO_VIDEO",i))(Ks||{});class Ei{constructor(s,e,t,r,a,n=0,o=1,u=1){c(this,"url");c(this,"x");c(this,"y");c(this,"width");c(this,"height");c(this,"alpha");c(this,"display",1);c(this,"zOrder");this.url=s,this.x=e,this.y=t,this.width=r,this.height=a,this.zOrder=n,this.alpha=o,this.display=u}toJson(s,e){return{url:this.url,alpha:this.alpha,display:this.display,x:pe(this.x,s),y:pe(this.y,e),width:pe(this.width,s),height:pe(this.height,e),zorder:this.zOrder}}}c(Ei,"DisplayType",Ks);class js{constructor(s,e,t,r,a=0,n=16777215,o=Ze.NOTO_SERIF_CJKSC_REGULAR){c(this,"text");c(this,"x");c(this,"y");c(this,"fontSize");c(this,"zOrder");c(this,"fontColor");c(this,"fontType");this.text=s,this.x=e,this.y=t,this.fontSize=r,this.zOrder=a,this.fontColor=n,this.fontType=o}toJson(s,e){return{text:this.text,x:pe(this.x,s),y:pe(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:ti(this.fontColor),zorder:this.zOrder}}}class $s{constructor(s,e,t,r,a,n=0,o){c(this,"userId");c(this,"x");c(this,"y");c(this,"width");c(this,"height");c(this,"zOrder");c(this,"sourceType");c(this,"segmentType",Xe.LiveTranscodingNoBody);c(this,"images",[]);c(this,"texts",[]);typeof s=="number"?this.userId=s.toString():this.userId=s,this.x=e,this.y=t,this.width=r,this.height=a,this.zOrder=n,o&&(this.sourceType=o)}toJson(s,e,t,r){const a={paneid:s,majorpane:0,x:pe(this.x,e),y:pe(this.y,t),width:pe(this.width,e),height:pe(this.height,t),zorder:this.zOrder,userid:this.userId,images:this.images.map(n=>n.toJson(e,t)),texts:this.texts.map(n=>n.toJson(e,t))};return this.sourceType&&Ye[this.sourceType]?a.sourcetype=Ye[this.sourceType]:a.sourcetype=Ye[We.LiveTranscodingCamera],this.segmentType&&r===ft.LiveTranscodingVirtualBackground?a.segmenttype=this.segmentType:a.segmenttype=Xe.LiveTranscodingNoBody,a}}class Zn extends He{constructor(){super("AliRtcScreenStandardize",Q.AliRtcSdkStreamTypeScreen);c(this,"canvas");c(this,"lastWidth");c(this,"lastHeight");c(this,"hasScreenTrack",!1)}get initOptions(){return{base:4}}setOptions(e){this.options=e}isSupported(){return!(typeof TransformStream=="undefined"||typeof MediaStreamTrackProcessor=="undefined"||typeof MediaStreamTrackGenerator=="undefined")}updateProcessCanvas(e,t){if(this.canvas&&this.lastWidth===e&&this.lastHeight===t)return;const r=Math.ceil(e/this.options.base)*this.options.base,a=Math.ceil(t/this.options.base)*this.options.base;if(this.canvas||(this.canvas=document.createElement("canvas")),this.canvas.width=r,this.canvas.height=a,this.lastWidth&&e>this.lastWidth||this.lastHeight&&t>this.lastHeight){const n=this.canvas.getContext("2d");n&&n.clearRect(0,0,r,a)}this.lastWidth=e,this.lastHeight=t}shouldUpdate(e){return this.hasScreenTrack!==(!!e.originVideoTrack&&e.videoSource===_e.Screen)}handleFrame(e,t){return S(this,null,function*(){var o;const{displayWidth:r,displayHeight:a}=e;if(!r||!a||r%this.options.base===0&&a%this.options.base===0)return this.clear(t),e;this.updateProcessCanvas(r,a);const n=(o=this.canvas)==null?void 0:o.getContext("2d");if(this.canvas&&n){n.drawImage(e,0,0,r,a);const u=new VideoFrame(this.canvas,{timestamp:e.timestamp});return e.close(),u}return e})}process(e){return S(this,null,function*(){var l;if(!e.originVideoTrack||e.videoSource!==_e.Screen){this.clear(e),this.hasScreenTrack=!1;return}const t=new MediaStreamTrackProcessor({track:e.originVideoTrack}),r=new MediaStreamTrackGenerator({kind:"video"}),a=new MediaStream([r]),n=this,o=new TransformStream({transform(p,d){return S(this,null,function*(){const m=yield n.handleFrame(p,e);yield d.enqueue(m),m==null||m.close()})}});t.readable.pipeThrough(o).pipeTo(r.writable);const u=(l=a.getVideoTracks())==null?void 0:l[0];e.updateVideoTrack(u),this.hasScreenTrack=!0})}clear(e){this.canvas=void 0,this.lastWidth=void 0,this.lastHeight=void 0,super.clear(e)}}var Qn=Object.defineProperty,eo=Object.getOwnPropertyDescriptor,k=(i,s,e,t)=>{for(var r=t>1?void 0:t?eo(s,e):s,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(t?n(s,e,r):n(r))||r);return t&&r&&Qn(s,e,r),r};const M=(y=class extends J{constructor(e){super();c(this,"channelProfile");c(this,"clientRole");c(this,"signalingManager");c(this,"userManager");c(this,"liveTranscoding");c(this,"maxSignalingConnectRetryCount");c(this,"reporter");c(this,"webTrackingClient");c(this,"connectState",K.AliRtcConnectionStatusInit);c(this,"networkError",!1);c(this,"moduleName","AliRtcEngine");c(this,"audioMixerPlugin");c(this,"dualVideoPlugin");c(this,"_audioOnlyMode",!1);c(this,"_authInfoWillExpireTimer",null);c(this,"_authInfoExpiredTimer",null);c(this,"_serverCheckAuthInfoTimestamp",null);c(this,"_localCheckAuthInfoTimestamp",null);this.webTrackingClient=new Un(e==null?void 0:e.webTrack),this.reporter=new Bn,this.channelProfile=Te.AliRtcSdkCommunication,this.clientRole=Me.AliRtcSdkLive,this.liveTranscoding=new Kr,this.signalingManager=new Sr(this.channelProfile,this.clientRole,(e==null?void 0:e.env)===Pe.pre?Pe.pre:Pe.prod),this.addSignalingManagerListeners(),this.maxSignalingConnectRetryCount=e==null?void 0:e.maxSignalingConnectRetryCount,this.userManager=new le({reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager}),this.addUserManagerListeners(),this.addPublisherListeners(),this.audioMixerPlugin=new Wn,this.enablePlugin(this.audioMixerPlugin),this.dualVideoPlugin=new Xn("dualVideoPlugin"),this.enablePlugin(new Zn)}static getSdkVersion(){return Ge}static setLogLevel(e){w.setLogLevel(e)}static getInstance(e){return y._instance||(y._instance=new y(e)),y._instance}destroy(){y._instance=void 0}get channel(){return this.userManager.channel}get userId(){return this.userManager.userId}get remoteUsers(){return this.userManager.remoteUsers}get publisher(){return this.userManager.publisher}get publishAudioStream(){var e;return(e=this.publisher)==null?void 0:e.publishStreams.audio}get isPublishing(){const{publisher:e}=this.userManager;return e?e.isPublishing:!1}get currentRoleCanPublish(){return this.channelProfile===Te.AliRtcSdkCommunication||this.clientRole===Me.AliRtcSdkInteractive}resetState(){return S(this,null,function*(){yield this.userManager.clear(),this.connectState=K.AliRtcConnectionStatusDisconnected,this.networkError=!1,this.signalingManager.reset(),this.liveTranscoding.clear(),this.reporter.stop(),yield this.publishLocalAudioStream(!0),yield this.publishLocalVideoStream(!0),yield this.publishLocalScreenShareStream(!0)})}stopPublish(e){return S(this,null,function*(){var t,r,a;e?yield(t=this.publisher)==null?void 0:t.stopLocalStream(e):(yield(r=this.publisher)==null?void 0:r.publishStop(),(a=this.publisher)==null||a.stopPreview())})}addPublisherListeners(){var e,t,r,a,n,o,u,h,l;(e=this.publisher)==null||e.on(ie.Local,p=>{w.event("[Publisher] Device Status Change",p),this.onLocalDeviceStatusChange(p)}),(t=this.publisher)==null||t.on(Ue.VideoTrackEnded,()=>{w.event("[Publisher] VideoTrack Ended"),this.emit("localDeviceException",we.AliEngineLocalDeviceTypeCamera,X.AliEngineLocalDeviceExceptionTypeCameraInterrupt,"")}),(r=this.publisher)==null||r.on(Ue.ScreenTrackEnded,()=>{w.event("[Publisher] ScreenTrack Ended"),this.emit("localDeviceException",we.AliEngineLocalDeviceTypeDisplay,X.AliEngineLocalDeviceExceptionTypeDisplayException,"")}),(a=this.publisher)==null||a.on(Ue.AudioTrackEnded,()=>{w.event("[Publisher] AudioTrack Ended"),this.emit("localDeviceException",we.AliEngineLocalDeviceTypeMic,X.AliEngineLocalDeviceExceptionTypeMicInterrupt,"")}),(n=this.publisher)==null||n.on("localDeviceException",(p,d,m="")=>{this.emit("localDeviceException",p,d,m)}),(o=this.publisher)==null||o.on("audioPublishStateChanged",(p,d,m)=>{var g;this.emit("audioPublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")}),(u=this.publisher)==null||u.on("videoPublishStateChanged",(p,d,m)=>{var g;this.emit("videoPublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")}),(h=this.publisher)==null||h.on("dualStreamPublishStateChanged",(p,d,m)=>{var g;this.emit("dualStreamPublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")}),(l=this.publisher)==null||l.on("screenPublishStateChanged",(p,d,m)=>{var g;this.emit("screenSharePublishStateChanged",p,d,m,(g=this.channel)!=null?g:"")})}addUserManagerListeners(){this.userManager.rtsManager.on("disconnected",()=>S(this,null,function*(){w.event("[UserManager] RTS Disconnected"),(yield ye.isNetworkAvailable())?this.onNetworkRecovery():this.onNetworkError()})),this.userManager.rtsManager.on("subscribeexceeds",()=>S(this,null,function*(){yield this.resumePublishForNetworkRecovery(),yield this.resumeSubList()})),this.userManager.rtsManager.on("seimessage",(e,t,r)=>{const a=this.remoteUsers.find(n=>n.streamUrl===e);a&&this.emit("mediaExtensionMsgReceived",a.userId,r,t)}),this.userManager.on(ie.Remote,(e,t)=>{w.event("[UserManager] RemoteUser Device Status Change",e,t)}),this.userManager.on("remoteTrackAvailableChange",(e,t,r)=>{this.emit("remoteTrackAvailableNotify",e,t,r)}),this.userManager.on("audioSubscribeStateChanged",(e,t,r,a,n)=>{this.emit("audioSubscribeStateChanged",e,t,r,a,n)}),this.userManager.on("videoSubscribeStateChanged",(e,t,r,a,n)=>{this.emit("videoSubscribeStateChanged",e,t,r,a,n)}),this.userManager.on("screenSubscribeStateChanged",(e,t,r,a,n)=>{this.emit("screenShareSubscribeStateChanged",e,t,r,a,n)}),this.userManager.on("userAudioMuted",(e,t)=>{this.emit("userAudioMuted",e,t)}),this.userManager.on("userVideoMuted",(e,t)=>{this.emit("userVideoMuted",e,t)}),this.userManager.on("userScreenMuted",(e,t)=>{this.emit("userScreenMuted",e,t)}),this.userManager.on("audioVolume",e=>{this.emit("audioVolume",e)}),this.userManager.on("remoteAudioAutoPlayFail",e=>{this.emit("remoteAudioAutoPlayFail",e)}),this.userManager.on("remoteVideoAutoPlayFail",(e,t)=>{this.emit("remoteVideoAutoPlayFail",e,t)}),this.userManager.on("rtcLocalAudioStats",e=>{this.emit("rtcLocalAudioStats",e)}),this.userManager.on("rtcLocalVideoStats",e=>{this.emit("rtcLocalVideoStats",e)}),this.userManager.on("rtcRemoteAudioStats",e=>{this.emit("rtcRemoteAudioStats",e)}),this.userManager.on("rtcRemoteVideoStats",e=>{this.emit("rtcRemoteVideoStats",e)}),this.userManager.on("remoteSubscribeError",e=>{this.emit("onOccurError",e)})}addSignalingManagerListeners(){this.signalingManager.on("onKeepAliveRsp",()=>{this.networkError&&(w.event("[Signaling] Receive KeepAlive Response",`networkError: ${this.networkError}`),this.onNetworkRecovery())}),this.signalingManager.on("onNotifyJoin",e=>{w.event("[Signaling] Notify Join ",e),this.handleUsersJoin(e),e.forEach(t=>{this.emit("remoteUserOnLineNotify",t.userid,0)})}),this.signalingManager.on("onNotifyStatus",e=>{w.event("[Signaling] Notify Status ",e),e.forEach(t=>{this.userManager.updateRemoteUserDeviceStatus(t)})}),this.signalingManager.on("onNotifyLeave",e=>{w.event("[Signaling] Notify Leave ",e),e.forEach(t=>{this.emit("remoteUserOffLineNotify",t.userid,t.leavecode),this.userManager.removeLeftUser(t)})}),this.signalingManager.on("onBye",(e,t)=>{w.event("[Signaling] Bye ",e,t),this.reporter.reportError({message:`reason: ${e}, description: ${t}`}),this.emit("bye",e),this.leaveChannel(!0)}),this.signalingManager.on("onConnectFail",e=>{w.event("[Signaling] Connect Failed ",e),this.onError(e),this.backToUnpublishStatus(),this.connectState=K.AliRtcConnectionStatusFailed,this.emit("connectionStatusChange",K.AliRtcConnectionStatusFailed,Ve.AliRtcConnectionChangedNetworkInterrupted)}),this.signalingManager.on("onNetworkError",e=>{w.event("[Signaling] Network error ",e),this.onNetworkError()}),this.signalingManager.on("onAuthInvalid",()=>{w.event("[Signaling] Auth Invalid")}),this.signalingManager.on("onReconnectStart",()=>{w.event("[Signaling] Reconnect Start "),this.connectState=K.AliRtcConnectionStatusReconnecting,this.emit("connectionStatusChange",K.AliRtcConnectionStatusReconnecting,Ve.AliRtcConnectionSignalingConnecting)}),this.signalingManager.on("onReconnectSuccess",e=>{w.event("[Signaling] Reconnect Success ",e),this.onNetworkRecovery(e)}),this.signalingManager.on("onReconnectFail",e=>{w.event("[Signaling] Reconnect Failed ",e),e.code===403&&this.emit("authInfoExpired")}),this.signalingManager.on("onError",e=>{w.event("[Signaling] Error ",e),this.onError(e)})}backToUnpublishStatus(){var e,t;this.connectState=K.AliRtcConnectionStatusDisconnected,(e=this.publisher)!=null&&e.isPublishing&&((t=this.publisher)==null||t.clearPublishState()),this.networkError=!1}handleUsersJoin(e){e.forEach(t=>{const r=t.userid;if(r){const a=this.userManager.addUser(r,t.displayname);w.event(this.moduleName,H.UserJoined,a)}})}onLocalDeviceStatusChange(e){w.event(`[${this.moduleName}]`,ie.Local,e),this.signalingManager.reportStatus(e).then(()=>{w.debug("[signaling] reportStatus suc")}).catch(t=>{w.error("[signaling] reportStatus failed",t)})}resumePublishForNetworkRecovery(){return S(this,null,function*(){var e;try{yield(e=this.publisher)==null?void 0:e.resumePublish()}catch(t){const{code:r}=t;if(r===10205){let n=1;try{yield new Promise((o,u)=>{const h=setInterval(()=>S(this,null,function*(){var l;n>1&&(clearInterval(h),u()),n+=1;try{yield(l=this.publisher)==null?void 0:l.resumePublish(),clearInterval(h),o()}catch(p){const{code:d}=p;d!==10205&&(clearInterval(h),u())}}),1e3)})}catch(o){}}}})}onNetworkRecovery(e){return S(this,null,function*(){var t;w.event(this.moduleName,"onNetworkRecovery",{users:e}),this.networkError&&(this.networkError=!1,(t=this.publisher)==null||t.reportSelfDeviceStatus(),!this.userManager.rtsManager.isConnected&&this.userManager.rtsManager.isConnecting&&(yield this.resumePublishForNetworkRecovery(),yield this.resumeSubList(e)),this.connectState=K.AliRtcConnectionStatusConnected,this.emit("connectionStatusChange",K.AliRtcConnectionStatusConnected,Ve.AliRtcConnectionSignalingHeartbeatAlive))})}resumeSubList(e){return S(this,null,function*(){const t="resumeSubList";if(e!=null&&e.length){const{joinList:r,leaveList:a,presentList:n}=this.userManager.updateUsers(e);w.info(`[${this.moduleName}/${t}]`,{joinList:r,leaveList:a,presentList:n}),this.handleUsersJoin(r),a.forEach(o=>{w.event(this.moduleName,H.UserLeft,o.userid,o.reason),this.emit("remoteUserOffLineNotify",o.userid,ii.AliRtcUserOfflineQuit)});for(let o=0;o<n.length;o++){const u=n[o],h=u.userid,l=this.userManager.getRemoteUser(h);this.userManager.onRemotePublishStateChange(u),l==null||l.restore(),l==null||l.updateSubscribe()}}else for(let r=0;r<this.remoteUsers.length;r++){const a=this.remoteUsers[r];try{a.restore(),a.updateSubscribe()}catch(n){}}})}onNetworkError(){this.connectState===K.AliRtcConnectionStatusConnected&&(this.networkError||(this.connectState=K.AliRtcConnectionStatusDisconnected,this.emit("connectionStatusChange",K.AliRtcConnectionStatusDisconnected,Ve.AliRtcConnectionChangedNetworkInterrupted)),this.networkError=!0)}onError(e){this.reporter.reportError(e),w.event(this.moduleName,H.Error,e)}setEnableDualVideoStream(e,t){t&&this.dualVideoPlugin.setOptions(t);const r=this.userManager.pluginManager.has(this.dualVideoPlugin.name);e?!r&&this.enablePlugin(this.dualVideoPlugin):r&&this.removePlugin(this.dualVideoPlugin.name)}hadPushStream(e){if(!(this.publisher&&e))throw new A(T.ERR_INNER,"stream is not publishing")}getCurrentMicDeviceId(){var e;return(e=this.publisher)==null?void 0:e.getCurrentMicDeviceId()}setChannelProfile(e){if(![K.AliRtcConnectionStatusInit,K.AliRtcConnectionStatusDisconnected,K.AliRtcConnectionStatusFailed].includes(this.connectState))throw new A(T.ERR_INNER,"cannot set channel profile in call");this.channelProfile=e,this.channelProfile===Te.AliRtcSdkCommunication&&(this.clientRole=Me.AliRtcSdkLive),this.signalingManager.setChannelProfile(e)}setClientRole(e){return S(this,null,function*(){var t,r,a,n,o;try{if(this.channelProfile===Te.AliRtcSdkCommunication)return;if(!Object.values(Me).includes(e))throw new A(T.ERR_INVALID_ARGUMENTS,`set client role error, role value(${e}) is invalid`);if(this.clientRole===e)return;this.isInCall()?this.clientRole===Me.AliRtcSdkInteractive?(this.userManager.isSubscribing?(yield this.stopPublish(),yield(t=this.publisher)==null?void 0:t.clearStream()):yield(r=this.publisher)==null?void 0:r.unPublish(),yield this.signalingManager.setClientRole(e)):(yield this.signalingManager.setClientRole(e),yield this.startDefaultDevicesCapture(),(a=this.publisher)!=null&&a.isPublishing||(yield(n=this.publisher)==null?void 0:n.startPublish()),yield(o=this.publisher)==null?void 0:o.previewAll()):yield this.signalingManager.setClientRole(e),this.clientRole=e}catch(u){throw u.code===403&&this.emit("authInfoExpired"),u}})}getCurrentClientRole(){return this.clientRole}setAudioOnlyMode(e){if(this.isInCall())throw new A(T.ERR_INNER,"cannot not change audioOnly mode in call");this._audioOnlyMode=e}setCheckAuthInfoTimer(e,t){const r=(e-t)*1e3;this._authInfoExpiredTimer=window.setTimeout(()=>{this.emit("authInfoExpired")},r),this._authInfoWillExpireTimer=window.setTimeout(()=>{this.emit("authInfoWillExpire")},r-3e4),this._serverCheckAuthInfoTimestamp=t,this._localCheckAuthInfoTimestamp=+Date.now()/1e3}clearCheckAuthInfoTimer(){this._authInfoExpiredTimer&&window.clearTimeout(this._authInfoExpiredTimer),this._authInfoWillExpireTimer&&window.clearTimeout(this._authInfoWillExpireTimer)}startDefaultDevicesCapture(){return S(this,null,function*(){var r,a;let e=[],t;try{this._audioOnlyMode||(e=yield y.getCameraList(),e.length||console.warn("No media neither devices can be captured")),t=yield y.getMicrophoneList(),t.length||console.warn("No media neither devices can be captured");const{hasCamera:n,hasMicrophone:o,hasScreenShare:u,audioCaptureDisabled:h,publishLocalAudioStreamEnabled:l,publishLocalVideoStreamEnabled:p}=(r=this.publisher)!=null?r:{};if(n||o||u)return;!n&&p&&!this._audioOnlyMode&&e.length&&!((a=this.publisher)!=null&&a.cameraCaptureDisabled)&&(yield this.enableLocalVideo(!0)),!o&&l&&!h&&t.length&&(yield this.startAudioCapture())}catch(n){throw n}})}joinChannel(e,t){return S(this,null,function*(){var n,o,u,h,l,p;let r=new Date().getTime(),a=Ti.checkAuthInfo(e);if(this.webTrackingClient.updateAuthInfo(e),this.webTrackingClient.reportJoinChannel(e),K.AliRtcConnectionStatusInit===this.connectState||K.AliRtcConnectionStatusDisconnected===this.connectState||K.AliRtcConnectionStatusFailed===this.connectState){if(this.connectState=K.AliRtcConnectionStatusConnecting,a)throw this.connectState=K.AliRtcConnectionStatusFailed,this.webTrackingClient.reportJoinChannelRes(a.code,a.message,0),this.reporter.reportJoin(0,a.code,a.message),a;e.callid=ye.createCallid(),this.reporter.start(e);try{const d=yield this.signalingManager.join(e,t,this.maxSignalingConnectRetryCount);this.connectState=K.AliRtcConnectionStatusConnected,(n=this.publisher)==null||n.reportSelfDeviceStatus();let m=new Date().getTime()-r;this.webTrackingClient.reportJoinChannelRes(0,"",m),this.reporter.reportJoin(m,0,d.tid),this.userManager.init(e,d),this.setCheckAuthInfoTimer(e.timestamp,d.timestamp),this.currentRoleCanPublish&&(yield this.startDefaultDevicesCapture(),Object.values((u=(o=this.publisher)==null?void 0:o.publishStreams)!=null?u:{}).some(g=>g)&&(yield(h=this.publisher)==null?void 0:h.startPublish(),yield(l=this.publisher)==null?void 0:l.previewAll())),this.remoteUsers.forEach(g=>{g.updateSubscribe()}),this.liveTranscoding.setAuthInfo(e)}catch(d){let m=new Date().getTime()-r;const g=(p=d.code)!=null?p:-1,f=d.reason||d.message||"";throw this.webTrackingClient.reportJoinChannelRes(g,f,m),this.connectState=K.AliRtcConnectionStatusDisconnected,this.reporter.reportJoin(m,g,""),new A(g,f)}}else{const d=new A(T.ERR_JOIN_ALREADY_JOINED,"already joined");throw this.connectState===K.AliRtcConnectionStatusConnecting&&(d.message="Repeated operation during login"),this.webTrackingClient.reportJoinChannelRes(d.code,d.message,0),this.reporter.reportJoin(0,d.code,""),d}})}leaveChannel(e=!1){return S(this,null,function*(){var r;this.reporter.reportLeaveInvoked(),this.webTrackingClient.reportLeaveChannel();let t=new Date().getTime();if(K.AliRtcConnectionStatusConnected===this.connectState)try{let a;e||(a=yield this.signalingManager.leave()),this.clearCheckAuthInfoTimer(),yield this.resetState(),this.reporter.reportLeave(new Date().getTime()-t,0,(r=a==null?void 0:a.tid)!=null?r:""),w.setFlushMode(!0);return}catch(a){throw this.reporter.reportLeave(new Date().getTime()-t,a.code,a.reason),a}else{yield this.resetState(),this.reporter.reportLeave(0,0,""),w.setFlushMode(!0);return}})}isInCall(){return this.connectState===K.AliRtcConnectionStatusConnected}refreshAuthInfo(e){return S(this,null,function*(){const{userId:t,nonce:r,timestamp:a,token:n,role:o}=e,u={userId:t,nonce:r,timestamp:a,token:n,role:o};try{yield this.signalingManager.refreshAuthInfo(u),this.userManager.refreshAuthInfo(u),this.liveTranscoding.refreshAuthInfo(u),this.clearCheckAuthInfoTimer(),this._serverCheckAuthInfoTimestamp&&this._localCheckAuthInfoTimestamp&&e.timestamp&&this.setCheckAuthInfoTimer(e.timestamp,this._serverCheckAuthInfoTimestamp+(Date.now()-this._localCheckAuthInfoTimestamp))}catch(h){throw h}})}isAudioOnly(){return this._audioOnlyMode}publishLocalAudioStream(e){return S(this,null,function*(){var t,r,a;(t=this.publisher)==null||t.setPublishLocalAudioStreamEnabled(e),this.connectState===K.AliRtcConnectionStatusConnected&&(e?(r=this.publisher)!=null&&r.hasMicrophone?yield(a=this.publisher)==null?void 0:a.publishUpdate():yield this.startAudioCapture():yield this.stopPublish({audio:!0}))})}isLocalAudioStreamPublished(){var e,t;return(t=(e=this.publisher)==null?void 0:e.publishLocalAudioStreamEnabled)!=null?t:!0}setDefaultSubscribeAllRemoteAudioStreams(e){this.userManager.setAutoSubAudio(e)}subscribeAllRemoteAudioStreams(e){this.userManager.setWantSubAudio(e)}subscribeRemoteAudioStream(e,t){if(t&&!this.userManager.isWantSubAudio)throw new A(T.ERR_INVALID_ARGUMENTS,"subscribeAllRemoteAudioStreams(true) must be called first");this.userManager.updateAudioWant(e,t)}resumeRemoteAudioStream(e){const t=this.userManager.getRemoteUser(e);t&&t.resumeAudio()}publishLocalVideoStream(e){return S(this,null,function*(){var t,r,a;(t=this.publisher)==null||t.setPublishLocalVideoStreamEnabled(e),this.connectState===K.AliRtcConnectionStatusConnected&&(e?(r=this.publisher)!=null&&r.hasCamera?yield(a=this.publisher)==null?void 0:a.publishUpdate():yield this.enableLocalVideo():yield this.stopPublish({video:!0}))})}isLocalVideoStreamPublished(){var e,t;return(t=(e=this.publisher)==null?void 0:e.publishLocalVideoStreamEnabled)!=null?t:!0}setRemoteDefaultVideoStreamType(e){[oe.AliRtcVideoStreamTypeHigh,oe.AliRtcVideoStreamTypeLow].includes(e)&&this.userManager.setRemoteDefaultVideoStreamType(e)}setDefaultSubscribeAllRemoteVideoStreams(e){this.userManager.setAutoSubVideo(e),this.userManager.setAutoSubScreen(e)}subscribeAllRemoteVideoStreams(e){this.userManager.setWantSubVideo(e),this.userManager.setWantSubScreen(e)}subscribeRemoteMediaStream(e,t,r,a){const n=this.userManager.getRemoteUser(e);if(!n)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r&&(t===x.AliRtcVideoTrackScreen||t===x.AliRtcVideoTrackBoth)?n.setWantSubScreen(!0):n.setWantSubScreen(!1),r&&(t===x.AliRtcVideoTrackCamera||t===x.AliRtcVideoTrackBoth)?n.setWantSubVideo(!0):n.setWantSubVideo(!1),n.setWantSubAudio(a),n.updateSubscribe()}resumeRemoteMediaStream(e,t){const r=this.userManager.getRemoteUser(e);r&&r.resumeVideo(t)}getOnlineRemoteUsers(){return this.userManager.remoteUsers.map(e=>e.userId)}getUserInfo(e){var t;return(t=this.userManager.getRemoteUser(e))==null?void 0:t.remoteUserInfo}isUserOnline(e){return!!this.userManager.remoteUsers.find(t=>t.userId===e)}startScreenShare(e){return S(this,null,function*(){var o;const t={video:!1,audio:!1},{audio:r=!1,videoTrack:a,audioTrack:n}=e||{};if(a||n){t.screen=!0;const u=new MediaStream;a&&u.addTrack(a),n&&u.addTrack(n),t.mediaStream=u}else t.screen=r?{audio:!0}:!0;yield(o=this.publisher)==null?void 0:o.createLocalStream(t)})}stopScreenShare(){return S(this,null,function*(){var e;(e=this.publisher)==null||e.stopLocalStream({screen:!0})})}setScreenShareConfiguration(e){return S(this,null,function*(){var a;const{frameRate:t=tt.frameRate,bitrate:r=tt.maxBitrate}=e;yield(a=this.publisher)==null?void 0:a.setScreenProfile(Ji,{width:tt.width,height:tt.height,frameRate:t,maxBitrate:r})})}setScreenShareContentHint(e){return S(this,null,function*(){var t;e&&((t=this.publisher)==null||t.setScreenContentHint(e))})}publishLocalScreenShareStream(e,t){return S(this,null,function*(){var r,a,n;(r=this.publisher)==null||r.setPublishLocalScreenStreamEnabled(e),this.connectState===K.AliRtcConnectionStatusConnected&&(e?(a=this.publisher)!=null&&a.hasScreenShare?yield(n=this.publisher)==null?void 0:n.publishUpdate():yield this.startScreenShare(t):yield this.stopPublish({screen:!0}))})}isScreenSharePublished(){var e,t;return(t=(e=this.publisher)==null?void 0:e.publishLocalScreenStreamEnabled)!=null?t:!0}setAudioShareVolume(e){if(typeof e!="number")throw new A(T.ERR_INVALID_ARGUMENTS,"volume must be a number");this.audioMixerPlugin.setOptions({screen:Math.max(0,Math.min(e,400))/100})}enableAudioVolumeIndication(e){this.userManager.enableAudioVolumeIndication(e)}muteLocalMic(e=!1){var t;this.isPublishing&&this.onLocalDeviceStatusChange(e?H.MuteAudio:H.UnmuteAudio),(t=this.publisher)==null||t.muteLocalMic(e)}muteRemoteAudioPlaying(e,t=!1){const r=this.userManager.getRemoteUser(e);if(!r)throw new A(T.ERR_INNER,`no remote user(${e}) founded`);r.toggleAudio(!t)}muteAllRemoteAudioPlaying(e=!1){this.userManager.setAudioMuted(e)}startAudioCapture(e){return S(this,null,function*(){var r;const t={audio:e||!0};yield(r=this.publisher)==null?void 0:r.createLocalStream(t)})}stopAudioCapture(){var e;(e=this.publisher)==null||e.stopAudioCapture()}switchMicrophone(e){return S(this,null,function*(){var t,r,a;yield(t=this.publisher)==null?void 0:t.setMicrophoneDeviceId(e),(r=this.publisher)!=null&&r.audioCaptureDisabled||(yield(a=this.publisher)==null?void 0:a.createLocalStream({audio:{deviceId:e}}))})}setRecordingVolume(e){if(typeof e!="number")throw new A(T.ERR_INVALID_ARGUMENTS,"volume must be a number");this.audioMixerPlugin.setOptions({audio:Math.max(0,Math.min(e,400))/100})}setAudioProfile(e){return S(this,null,function*(){var t;yield(t=this.publisher)==null?void 0:t.setAudioProfile(e)})}getAudioTrack(e){return S(this,null,function*(){var r;if(!e)return(r=this.publisher)==null?void 0:r.audioTrack;const t=this.userManager.getRemoteUser(e);return t==null?void 0:t.getAudioTrack})}setLocalViewConfig(e,t){return S(this,null,function*(){var r,a,n;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot set local view in audio only mode");(r=this.userManager)==null||r.setLocalViewConfig(e,t),t===x.AliRtcVideoTrackCamera&&((a=this.publisher)!=null&&a.hasCamera)?yield this.startPreview():t===x.AliRtcVideoTrackScreen&&((n=this.publisher)!=null&&n.hasScreenShare)&&(yield this.startPreviewScreen())})}setCameraCapturerConfiguration(e){return S(this,null,function*(){var h,l,p;const{width:t=et.width,height:r=et.height,frameRate:a=et.frameRate,bitrate:n=et.maxBitrate,cameraDirection:o,deviceId:u}=e;yield(h=this.publisher)==null?void 0:h.setVideoProfile($i,{width:t,height:r,frameRate:a,maxBitrate:n}),o!==void 0&&((l=this.publisher)==null||l.setCameraDirection(o)),u&&((p=this.publisher)==null||p.setCameraDeviceId(u))})}setCameraCapturerContentHint(e){return S(this,null,function*(){var t;e&&((t=this.publisher)==null||t.setVideoContentHint(e))})}enableLocalVideo(e=!0){return S(this,null,function*(){var t,r,a,n,o,u,h,l,p,d,m;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot enable local video in audio only mode");if(e){(r=(t=this.publisher)==null?void 0:t.publishStreams)!=null&&r.video&&((o=(n=(a=this.publisher)==null?void 0:a.publishStreams)==null?void 0:n.video)==null||o.disableVideo(),(p=(l=(h=(u=this.publisher)==null?void 0:u.publishStreams)==null?void 0:h.video)==null?void 0:l.videoTrack)==null||p.stop());const g={video:!0};yield(d=this.publisher)==null?void 0:d.startCameraCapture(g)}else yield(m=this.publisher)==null?void 0:m.stopCameraCapture()})}muteLocalCamera(e){return S(this,null,function*(){var t;this.isPublishing&&this.onLocalDeviceStatusChange(e?H.MuteVideo:H.UnmuteVideo),(t=this.publisher)==null||t.muteLocalCamera(e)})}muteLocalScreen(e){return S(this,null,function*(){var t;this.isPublishing&&this.onLocalDeviceStatusChange(e?H.MuteScreen:H.UnmuteScreen),(t=this.publisher)==null||t.muteLocalScreen(e)})}setRemoteViewConfig(e,t,r){this.userManager.setRemoteViewConfig(t,e,r)}isCameraOn(){var e,t;return(t=(e=this.publisher)==null?void 0:e.hasCamera)!=null?t:!1}switchCamera(e){return S(this,null,function*(){var r,a,n,o,u,h,l,p,d,m,g,f;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot switch camera in audio only mode");const t={};e?t.deviceId=e:t.cameraDirection=((r=this.publisher)==null?void 0:r.cameraDirection)==="environment"?Qe.CAMERA_FRONT:Qe.CAMERA_REAR,yield this.setCameraCapturerConfiguration(t),(a=this.publisher)!=null&&a.cameraCaptureDisabled||((o=(n=this.publisher)==null?void 0:n.publishStreams)!=null&&o.video&&((l=(h=(u=this.publisher)==null?void 0:u.publishStreams)==null?void 0:h.video)==null||l.disableVideo(),(g=(m=(d=(p=this.publisher)==null?void 0:p.publishStreams)==null?void 0:d.video)==null?void 0:m.videoTrack)==null||g.stop()),yield(f=this.publisher)==null?void 0:f.createLocalStream({video:!0}))})}getCurrentCameraDeviceId(){var e;return(e=this.publisher)==null?void 0:e.getCurrentCameraDeviceId()}startPreview(){return S(this,null,function*(){var e,t;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot start preview camera in audio only mode");(e=this.publisher)!=null&&e.hasCamera||(yield this.enableLocalVideo(!0)),yield(t=this.publisher)==null?void 0:t.previewAll({screen:!1})})}startPreviewScreen(e){return S(this,null,function*(){var t,r;if(this._audioOnlyMode)throw new A(T.ERR_INNER,"Cannot start preview screen share in audio only mode");(t=this.publisher)!=null&&t.hasScreenShare||(yield this.startScreenShare(e)),yield(r=this.publisher)==null?void 0:r.previewAll({primary:!1})})}stopPreview(){return S(this,null,function*(){var e;yield(e=this.publisher)==null?void 0:e.stopPreview({primary:!0,screen:!1})})}stopPreviewScreen(){return S(this,null,function*(){var e;yield(e=this.publisher)==null?void 0:e.stopPreview({primary:!1,screen:!0})})}getVideoTrack(e){return S(this,null,function*(){var n,o,u,h;const{userId:t,streamType:r}=e;if(!t)return r===Q.AliRtcSdkStreamTypeCapture?(n=this.publisher)==null?void 0:n.cameraTrack:(o=this.publisher)==null?void 0:o.screenTrack;const a=this.userManager.getRemoteUser(t);return r===Q.AliRtcSdkStreamTypeCapture?(u=a==null?void 0:a.getCameraStream)==null?void 0:u.videoTrack:(h=a==null?void 0:a.getScreenStream)==null?void 0:h.videoTrack})}startPublishLiveStream(e,t){return S(this,null,function*(){return this.liveTranscoding.startPublishLiveStream(e,t)})}updatePublishLiveStream(e,t){return S(this,null,function*(){return this.liveTranscoding.updatePublishLiveStream(e,t)})}updatePublishLiveStreamWithTaskId(e,t){return this.liveTranscoding.updatePublishLiveStreamWithTaskId(e,t)}stopPublishLiveStream(e){return S(this,null,function*(){return this.liveTranscoding.stopPublishLiveStream(e)})}stopPublishLiveStreamWithTaskId(e){return this.liveTranscoding.stopPublishLiveStreamWithTaskId(e)}setEnableMediaExtensionMsg(e){var t;(t=this.userManager)==null||t.setEnableMediaExtensionMsg(!!e)}sendMediaExtensionMsg(e,t){return S(this,null,function*(){return this.sendMediaExtensionMsgEx(e,t,5)})}sendMediaExtensionMsgEx(e,t,r){return S(this,null,function*(){var a;if(!this.publisher||!this.isPublishing)throw new A(T.ERR_INNER,"you should publish first");return(a=this.publisher)==null?void 0:a.sendSEI(e,t,r)})}enablePlugin(e,t){this.userManager.pluginManager.add(e,t)}removePlugin(e){this.userManager.pluginManager.remove(e)}setPluginOption(e,t){const r=this.userManager.pluginManager.get(e);r&&t&&r.setOptions(t)}getPluginOption(e){const t=this.userManager.pluginManager.get(e);return t==null?void 0:t.getOptions()}isBeautyAvailable(){return this.userManager.pluginManager.has("AliRtcBeauty")}isBeautyEnabled(){const e=this.userManager.pluginManager.get("AliRtcBeauty");if(!e)throw new A(Ne.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");return!!(e!=null&&e.isEnable)}setBeautyEffect(e,t){const r=this.userManager.pluginManager.get("AliRtcBeauty");if(!r)throw new A(Ne.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");e?r.enable():r.disable(),r.setOptions({basicBeauty:{skinBuffing:Math.max(Math.min(1,+t.smoothnessLevel),0),whitening:Math.max(Math.min(1,+t.whiteningLevel),0)}})}enableBackgroundExchange(e,t){const r=this.userManager.pluginManager.get("AliRtcBeauty");if(!r||!r.isEnable)throw new A(Ne.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");const a={setSegmentBackgroundImage:{backgroundImgUrl:e?t:""}};e&&(a.segmentBackgroundProcess={enable:!1}),r.setOptions(a)}enableBackgroundBlur(e){const t=this.userManager.pluginManager.get("AliRtcBeauty");if(!t||!t.isEnable)throw new A(Ne.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");const r={segmentBackgroundProcess:{type:0,enable:e}};e&&(r.setSegmentBackgroundImage={type:0,backgroundImgUrl:""}),t.setOptions(r)}},c(y,"logName","AliRtcEngine"),c(y,"isSupported",or),c(y,"isDualVideoStreamSupported",Ai.isSupport),c(y,"getCameraList",()=>S(y,null,function*(){return(yield P.AliRTS.getCameraList()).filter(t=>t.deviceId)})),c(y,"getMicrophoneList",()=>S(y,null,function*(){return(yield P.AliRTS.getMicList()).filter(t=>t.deviceId)})),c(y,"getSpeakerList",()=>S(y,null,function*(){return(yield P.AliRTS.getSpeakerList()).filter(t=>t.deviceId)})),c(y,"_instance"),c(y,"AliRtcSdkChannelProfile",Te),c(y,"AliRtcSdkClientRole",Me),c(y,"AliRtcVideoStreamType",oe),c(y,"AliRtcVideoTrack",x),c(y,"AliRtcAudioTrack",Ke),c(y,"AliRtcPublishState",V),c(y,"AliRtcSubscribeState",G),c(y,"AliRtcRawDataStreamType",Q),c(y,"AliRtcLogLevel",Gt),c(y,"AliRtcEngineLocalDeviceType",we),c(y,"AliRtcEngineLocalDeviceExceptionType",X),c(y,"AliRtcConnectionStatus",K),c(y,"AliRtcConnectionStatusChangeReason",Ve),c(y,"AliRtcPlugin",He),c(y,"AliRtcPluginTrackType",gt),c(y,"AliRtcLiveTranscodingParam",bt),c(y,"AliRtcLiveTranscodingEncodeParam",ei),c(y,"AliRtcLiveTranscodingMixParam",Fs),c(y,"AliRtcLiveTranscodingSingleParam",Hs),c(y,"AliRtcTranscodingClockWidget",Ws),c(y,"AliRtcTranscodingImage",Ei),c(y,"AliRtcTranscodingText",js),c(y,"AliRtcTranscodingUser",$s),c(y,"AliRtcLiveTranscodingMixMode",ze),c(y,"AliRtcLiveTranscodingStreamType",zt),c(y,"AliRtcLiveTranscodingSourceType",We),c(y,"AliRtcLiveTranscodingTaskProfile",Yt),c(y,"AliRtcLiveTranscodingAudioSampleRate",St),c(y,"AliRtcLiveTranscodingSegmentType",Xe),c(y,"AliRtcLiveTranscodingFontType",Ze),c(y,"AliRtcLiveTranscodingCropMode",Xt),c(y,"AliRtcLiveTranscodingMediaProcessMode",ft),c(y,"AliRtcLiveTranscodingState",Zt),c(y,"AliRtcLiveTranscodingErrorCode",Re),c(y,"AliRtcTrascodingPublishTaskStatus",Qt),c(y,"Plugin",He),y);k([b(I)],M.prototype,"stopPublish",1),k([b()],M.prototype,"resumeSubList",1),k([b(I)],M.prototype,"setEnableDualVideoStream",1),k([b(I)],M.prototype,"setChannelProfile",1),k([b(I)],M.prototype,"setClientRole",1),k([b(I)],M.prototype,"setAudioOnlyMode",1),k([b(I)],M.prototype,"joinChannel",1),k([b(I)],M.prototype,"leaveChannel",1),k([b(I)],M.prototype,"refreshAuthInfo",1),k([b(I)],M.prototype,"publishLocalAudioStream",1),k([b(I)],M.prototype,"setDefaultSubscribeAllRemoteAudioStreams",1),k([b(I)],M.prototype,"subscribeAllRemoteAudioStreams",1),k([b(I)],M.prototype,"subscribeRemoteAudioStream",1),k([b(I)],M.prototype,"resumeRemoteAudioStream",1),k([b(I)],M.prototype,"publishLocalVideoStream",1),k([b(I)],M.prototype,"setRemoteDefaultVideoStreamType",1),k([b(I)],M.prototype,"setDefaultSubscribeAllRemoteVideoStreams",1),k([b(I)],M.prototype,"subscribeAllRemoteVideoStreams",1),k([b(I)],M.prototype,"subscribeRemoteMediaStream",1),k([b(I)],M.prototype,"resumeRemoteMediaStream",1),k([b(([i])=>[`${i==null?void 0:i.audio}`])],M.prototype,"startScreenShare",1),k([b(I)],M.prototype,"setScreenShareConfiguration",1),k([b(I)],M.prototype,"setScreenShareContentHint",1),k([b()],M.prototype,"publishLocalScreenShareStream",1),k([b(I)],M.prototype,"setAudioShareVolume",1),k([b(I)],M.prototype,"enableAudioVolumeIndication",1),k([b(I)],M.prototype,"muteLocalMic",1),k([b(I)],M.prototype,"muteRemoteAudioPlaying",1),k([b(I)],M.prototype,"muteAllRemoteAudioPlaying",1),k([b(I)],M.prototype,"startAudioCapture",1),k([b()],M.prototype,"stopAudioCapture",1),k([b(I)],M.prototype,"switchMicrophone",1),k([b(I)],M.prototype,"setRecordingVolume",1),k([b(I)],M.prototype,"setAudioProfile",1),k([b(I)],M.prototype,"getAudioTrack",1),k([b(I)],M.prototype,"setLocalViewConfig",1),k([b(I)],M.prototype,"setCameraCapturerConfiguration",1),k([b(I)],M.prototype,"setCameraCapturerContentHint",1),k([b(I)],M.prototype,"enableLocalVideo",1),k([b(I)],M.prototype,"muteLocalCamera",1),k([b(I)],M.prototype,"muteLocalScreen",1),k([b(I)],M.prototype,"setRemoteViewConfig",1),k([b(I)],M.prototype,"switchCamera",1),k([b()],M.prototype,"startPublishLiveStream",1),k([b()],M.prototype,"updatePublishLiveStream",1),k([b()],M.prototype,"updatePublishLiveStreamWithTaskId",1),k([b()],M.prototype,"stopPublishLiveStream",1),k([b()],M.prototype,"stopPublishLiveStreamWithTaskId",1),k([b(I)],M.prototype,"setEnableMediaExtensionMsg",1),k([b(([i,s,e])=>[i.length,s,e])],M.prototype,"sendMediaExtensionMsgEx",1);let to=M;_.AliRtcConnectionStatus=K,_.AliRtcConnectionStatusChangeReason=Ve,_.AliRtcEngineLocalDeviceExceptionType=X,_.AliRtcEngineLocalDeviceType=we,_.AliRtcErrorCode=T,_.AliRtcLiveTranscodingAudioSampleRate=St,_.AliRtcLiveTranscodingCropMode=Xt,_.AliRtcLiveTranscodingEncodeParam=ei,_.AliRtcLiveTranscodingErrorCode=Re,_.AliRtcLiveTranscodingFontType=Ze,_.AliRtcLiveTranscodingMediaProcessMode=ft,_.AliRtcLiveTranscodingMixMode=ze,_.AliRtcLiveTranscodingMixParam=Fs,_.AliRtcLiveTranscodingParam=bt,_.AliRtcLiveTranscodingSegmentType=Xe,_.AliRtcLiveTranscodingSingleParam=Hs,_.AliRtcLiveTranscodingSourceType=We,_.AliRtcLiveTranscodingState=Zt,_.AliRtcLiveTranscodingStreamType=zt,_.AliRtcLiveTranscodingTaskProfile=Yt,_.AliRtcLocalStreamInfo=ci,_.AliRtcLogLevel=Gt,_.AliRtcPlugin=He,_.AliRtcPluginTrackType=gt,_.AliRtcPluginType=Fi,_.AliRtcPublishState=V,_.AliRtcRawDataStreamType=Q,_.AliRtcRemoteUserInfo=Yi,_.AliRtcSdkChannelProfile=Te,_.AliRtcSdkClientRole=Me,_.AliRtcSubscribeState=G,_.AliRtcTranscodingClockWidget=Ws,_.AliRtcTranscodingImage=Ei,_.AliRtcTranscodingText=js,_.AliRtcTranscodingUser=$s,_.AliRtcTrascodingPublishTaskStatus=Qt,_.AliRtcVideoStreamType=oe,_.AliRtcVideoTrack=x,_.default=to,Object.defineProperties(_,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|