aliyun-rtc-sdk 6.11.1 → 6.11.2

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.
@@ -1,14 +1,14 @@
1
- var Zn=Object.defineProperty,Qn=Object.defineProperties;var eo=Object.getOwnPropertyDescriptors;var Bt=Object.getOwnPropertySymbols,to=Object.getPrototypeOf,Js=Object.prototype.hasOwnProperty,Ys=Object.prototype.propertyIsEnumerable,io=Reflect.get;var Pi=(I,y,L)=>y in I?Zn(I,y,{enumerable:!0,configurable:!0,writable:!0,value:L}):I[y]=L,x=(I,y)=>{for(var L in y||(y={}))Js.call(y,L)&&Pi(I,L,y[L]);if(Bt)for(var L of Bt(y))Ys.call(y,L)&&Pi(I,L,y[L]);return I},He=(I,y)=>Qn(I,eo(y));var Xs=(I,y)=>{var L={};for(var j in I)Js.call(I,j)&&y.indexOf(j)<0&&(L[j]=I[j]);if(I!=null&&Bt)for(var j of Bt(I))y.indexOf(j)<0&&Ys.call(I,j)&&(L[j]=I[j]);return L};var c=(I,y,L)=>(Pi(I,typeof y!="symbol"?y+"":y,L),L);var Ci=(I,y,L)=>io(to(I),L,y);var S=(I,y,L)=>new Promise((j,nt)=>{var U=pe=>{try{A(L.next(pe))}catch(fe){nt(fe)}},ie=pe=>{try{A(L.throw(pe))}catch(fe){nt(fe)}},A=pe=>pe.done?j(pe.value):Promise.resolve(pe.value).then(U,ie);A((L=L.apply(I,y)).next())});(function(I,y){typeof exports=="object"&&typeof module!="undefined"?y(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"],y):(I=typeof globalThis!="undefined"?globalThis:I||self,y(I.AliRtcEngine={},I.AliyunRts,I.UserAgentUtil,I.EventEmitter,I.BrowserLogReporter))})(this,function(I,y,L,j,nt){var T;"use strict";var U=(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))(U||{}),ie=(i=>(i.Local="local-device-status-change",i.Remote="remote-device-status-change",i))(ie||{}),A=(i=>(i.Audio="sophon_audio",i.VideoLarge="sophon_video_camera_large",i.VideoSmall="sophon_video_camera_small",i.Screen="sophon_video_screen_share",i))(A||{}),pe=(i=>(i.Audio="rts audio",i.VideoLarge="rts video",i))(pe||{}),fe=(i=>(i[i.Camera=0]="Camera",i[i.Screen=1]="Screen",i[i.Image=2]="Image",i))(fe||{}),ot=(i=>(i[i.Microphone=0]="Microphone",i[i.Screen=1]="Screen",i[i.Mixed=2]="Mixed",i))(ot||{}),ct=(i=>(i.prod="rs.rtn.aliyuncs.com",i.pre="prs.rtn.aliyuncs.com",i))(ct||{});const We="6.11.1",ki="web";class _e{static getVersionNumber(){let s=We.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 L.Guid.create(8)+"-"+L.Guid.create(4)+"-4"+L.Guid.create(3)+"-"+L.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=ct.prod,{onLine:e}=navigator;if(!e)return!1;try{return yield fetch(`https://${s}/roomserver/v1/ws/version`),!0}catch(t){return!1}})}}var Ht=(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))(Ht||{});class le{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: "+le.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=L.LocalStorage.uuid+"-"+Date.now(),this.traceId="",this.logArray=[],this.enable=!0,this.lastRequestTime=0,this.onTimer()}static toString(s){let e;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=le.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=le.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=le.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=le.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=le.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=le.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=le.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=le.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=le.toString(s[t]);e+=r}return e}}class _{static getLogger(){return this.logger||(this.logger=new le("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("[RTC API]",...s)}static interfaceResult(s,e,t,...r){t?this.getLogger().ar("[RTC APIRES]",s,e,...r):this.getLogger().ae("[RTC APIRES]",s,e,...r)}static event(...s){this.getLogger().ev("[RTC EVENT]",...s)}static debug(...s){this.getLogger().d("[RTC DEBUG]",...s)}static info(...s){this.getLogger().i("[RTC INFO]",...s)}static warn(...s){this.getLogger().w("[RTC WARN]",...s)}static error(...s){this.getLogger().e("[RTC ERR]",...s)}}c(_,"logger");const Zs=i=>S(this,null,function*(){const s=new y.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()&&!y.AliRTS.SystenUtil.isAndroid&&!y.AliRTS.SystenUtil.isIos,e.detail.isSendMediaExtensionMsgSupported=s.checkWebRtcSupport()&&s.checkEncodedTransformSupport(),e});var we=(i=>(i.pre="pre",i.prod="prod",i))(we||{}),Ie=(i=>(i.AliRtcSdkCommunication="communication",i.AliRtcSdkInteractiveLive="interactive_live",i.AliRtcSdkInteractiveWithLowLatencyLive="cdn_live",i))(Ie||{}),Ee=(i=>(i.AliRtcSdkInteractive="interactive",i.AliRtcSdkLive="live",i))(Ee||{}),ee=(i=>(i[i.AliRtcSdkStreamTypeCapture=0]="AliRtcSdkStreamTypeCapture",i[i.AliRtcSdkStreamTypeScreen=1]="AliRtcSdkStreamTypeScreen",i))(ee||{}),be=(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))(be||{}),Z=(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))(Z||{}),F=(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))(F||{}),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||{}),Wt=(i=>(i[i.AliRtcUserOfflineQuit=0]="AliRtcUserOfflineQuit",i[i.AliRtcUserOfflineDropped=1]="AliRtcUserOfflineDropped",i[i.AliRtcUserOfflineBecomeAudience=2]="AliRtcUserOfflineBecomeAudience",i))(Wt||{}),Ne=(i=>(i[i.AliRtcAudioTrackNo=0]="AliRtcAudioTrackNo",i[i.AliRtcAudioTrackMic=1]="AliRtcAudioTrackMic",i[i.AliRtcAudioTrackDual=2]="AliRtcAudioTrackDual",i))(Ne||{}),V=(i=>(i[i.AliRtcVideoTrackNo=0]="AliRtcVideoTrackNo",i[i.AliRtcVideoTrackCamera=1]="AliRtcVideoTrackCamera",i[i.AliRtcVideoTrackScreen=2]="AliRtcVideoTrackScreen",i[i.AliRtcVideoTrackBoth=3]="AliRtcVideoTrackBoth",i))(V||{}),k=(i=>(i[i.AliRtcStatePublishIdle=0]="AliRtcStatePublishIdle",i[i.AliRtcStateNoPublish=1]="AliRtcStateNoPublish",i[i.AliRtcStatePublishing=2]="AliRtcStatePublishing",i[i.AliRtcStatePublished=3]="AliRtcStatePublished",i))(k||{}),K=(i=>(i[i.AliRtcStateSubscribeIdle=0]="AliRtcStateSubscribeIdle",i[i.AliRtcStateNoSubscribe=1]="AliRtcStateNoSubscribe",i[i.AliRtcStateSubscribing=2]="AliRtcStateSubscribing",i[i.AliRtcStateSubscribed=3]="AliRtcStateSubscribed",i))(K||{}),oe=(i=>(i[i.AliRtcVideoStreamTypeNone=0]="AliRtcVideoStreamTypeNone",i[i.AliRtcVideoStreamTypeHigh=1]="AliRtcVideoStreamTypeHigh",i[i.AliRtcVideoStreamTypeLow=2]="AliRtcVideoStreamTypeLow",i))(oe||{}),je=(i=>(i[i.CAMERA_INVALID=-1]="CAMERA_INVALID",i[i.CAMERA_REAR=0]="CAMERA_REAR",i[i.CAMERA_FRONT=1]="CAMERA_FRONT",i))(je||{}),Oi=(i=>(i[i.PRE_PROCESSER=0]="PRE_PROCESSER",i[i.POST_PROCESSER=1]="POST_PROCESSER",i))(Oi||{}),ut=(i=>(i[i.AUDIO=0]="AUDIO",i[i.VIDEO=1]="VIDEO",i[i.BOTH=2]="BOTH",i))(ut||{});class Ve extends j{constructor(e,t=ee.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 Ge=(i=>(i[i.LiveTranscodingSingle=0]="LiveTranscodingSingle",i[i.LiveTranscodingMix=1]="LiveTranscodingMix",i))(Ge||{}),jt=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingAudio=1]="LiveTranscodingAudio",i[i.LiveTranscodingVideo=2]="LiveTranscodingVideo",i))(jt||{}),De=(i=>(i[i.LiveTranscodingCamera=0]="LiveTranscodingCamera",i[i.LiveTranscodingShareScreen=1]="LiveTranscodingShareScreen",i))(De||{});const qe={0:"camera",1:"shareScreen"};var Gt=(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))(Gt||{});const Qs={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 ht=(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))(ht||{}),$e=(i=>(i[i.LiveTranscodingNoBody=0]="LiveTranscodingNoBody",i[i.LiveTranscodingBody=1]="LiveTranscodingBody",i))($e||{}),Ke=(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))(Ke||{}),qt=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingCrop=1]="LiveTranscodingCrop",i[i.LiveTranscodingFill=2]="LiveTranscodingFill",i))(qt||{}),lt=(i=>(i[i.LiveTranscodingNormal=0]="LiveTranscodingNormal",i[i.LiveTranscodingVirtualBackground=1]="LiveTranscodingVirtualBackground",i))(lt||{}),$t=(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))($t||{}),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||{}),Kt=(i=>(i[i.TrascodingPublishTaskStatusStart=0]="TrascodingPublishTaskStatusStart",i[i.TrascodingPublishTaskStatusUpdate=1]="TrascodingPublishTaskStatusUpdate",i[i.TrascodingPublishTaskStatusStop=2]="TrascodingPublishTaskStatusStop",i))(Kt||{}),ce=(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))(ce||{});const er={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 zt{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",ht.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 Jt=i=>((i&16711680)>>16)+(i&65280)+((i&255)<<16),de=(i=0,s)=>{if(s==0)return 0;let e=i/s;return e<0&&(e=0),e>1&&(e=1),e};class dt{constructor(s,e,t){c(this,"mixMode",Ge.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===ce.MPU_TASK_TRANSACTION_POLLING||s===ce.MPU_TASK_TRANSACTION_LIST||s===ce.MPU_TASK_TRANSACTION_ACKNOWLEDGE)return s===ce.MPU_TASK_TRANSACTION_ACKNOWLEDGE&&(n.messageid=a),n;if(n.taskid=t,s!==ce.MPU_TASK_TRANSACTION_STOP){if(n.mixmode=this.mixMode,r&&(n.streamurl=r),this.mixMode===Ge.LiveTranscodingSingle){const o=this.singleParam;if(o){n.streamtype=o.streamType,o.sourceType===De.LiveTranscodingShareScreen?n.sourcetype=qe[o.sourceType]:n.sourcetype=qe[De.LiveTranscodingCamera];const u=[];o.userId&&u.push(o.userId),n.subspecusers=u}}else if(s===ce.MPU_TASK_TRANSACTION_START||s===ce.MPU_TASK_TRANSACTION_UPDATE){const o=this.mixParam;if(o){o.taskProfile&&(n.taskprofile=Qs[o.taskProfile]);const u=o.encodeParam||new zt(1280,720);let h=u.videoWidth,l=u.videoHeight;const p={};Object.keys(u).forEach(g=>{const m=u[g];m>0&&(p[g.toLowerCase()]=m)}),p.lowbitratehighquality=0,n.encodeparam=p,n.backgrounds=o.backgrounds.map(g=>g.toJson(h,l)),n.watermarks=o.watermarks.map(g=>g.toJson(h,l)),n.clockwidgets=o.clockWidgets.map(g=>g.toJson(h,l));const d=o.users.map(g=>g.userId);n.subspecusers=[...new Set(d)],n.layouts=[{audiomixcount:o.users.length,panes:o.users.map((g,m)=>g.toJson(m,h,l,o.mediaProcessMode))}],n.layoutids=["0"],n.cropmode=o.cropMode,n.backgroundcolor=Jt(o.backgroundColor),n.taskmode=o.mediaProcessMode}}}return n}}const Mi=10,Ni=5e3;class tr extends j{constructor(e){super();c(this,"ws");c(this,"socketStatus",0);c(this,"wsUrl","");c(this,"lastConnectStartTime",0);c(this,"maxConnectRetryCount",Mi);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:Mi,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*(){if(this.socketStatus!==0||this.connectRetryCount)if(yield _e.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>=Ni?this.reconnect():window.setTimeout(()=>{this.reconnect()},Ni)}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)}}var te=(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))(te||{});class ir{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=_e.getVersionNumber().toString(),s.header.platform=ki,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=_e.getVersionNumber().toString(),e.header.platform=ki,e.data=x(x({},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:L.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 R=(i=>(i[i.ERROR_SIGNALING_CONNECT_FAIL=20100]="ERROR_SIGNALING_CONNECT_FAIL",i[i.ERROR_SIGNALING_RECONNECT_ERROR=20101]="ERROR_SIGNALING_RECONNECT_ERROR",i[i.ERROR_JOIN_SIGNALING_ERROR=20102]="ERROR_JOIN_SIGNALING_ERROR",i[i.ERROR_JOIN_FAIL=20103]="ERROR_JOIN_FAIL",i[i.ERROR_LEAVE_SIGNALING_ERROR=20104]="ERROR_LEAVE_SIGNALING_ERROR",i[i.ERROR_SET_CLIENT_ROLE_FAIL=20200]="ERROR_SET_CLIENT_ROLE_FAIL",i[i.ERROR_LIVE_ROLE_CANNOT_PUB=20201]="ERROR_LIVE_ROLE_CANNOT_PUB",i[i.ERROR_SET_CHANNEL_PROFILE_FAIL=20202]="ERROR_SET_CHANNEL_PROFILE_FAIL",i[i.ERROR_SET_AUDIO_ONLY_FAIL=20203]="ERROR_SET_AUDIO_ONLY_FAIL",i[i.ERROR_REFRESH_PUSH_URL_FAIL=20300]="ERROR_REFRESH_PUSH_URL_FAIL",i[i.ERROR_PUBLISH_SIGNALING_ERROR=20400]="ERROR_PUBLISH_SIGNALING_ERROR",i[i.ERROR_PUBLISH_NO_PUBLISHER_FAIL=20401]="ERROR_PUBLISH_NO_PUBLISHER_FAIL",i[i.ERROR_PUBLISH_FAIL=20402]="ERROR_PUBLISH_FAIL",i[i.ERROR_PUBLISH_ADD_FAIL=20403]="ERROR_PUBLISH_ADD_FAIL",i[i.ERROR_PUBLISH_STOP_FAIL=20404]="ERROR_PUBLISH_STOP_FAIL",i[i.ERROR_PUBLISH_REPLACE_TRACKS_FAIL=20405]="ERROR_PUBLISH_REPLACE_TRACKS_FAIL",i[i.ERROR_PUBLISH_DELETE_TRACKS_FAIL=20406]="ERROR_PUBLISH_DELETE_TRACKS_FAIL",i[i.ERROR_UNPUBLISH_SIGNALING_ERROR=20407]="ERROR_UNPUBLISH_SIGNALING_ERROR",i[i.ERROR_UNPUBLISH_FAIL=20408]="ERROR_UNPUBLISH_FAIL",i[i.ERROR_PUBLISH_NEEDED=20409]="ERROR_PUBLISH_NEEDED",i[i.ERROR_SUBSCRIBE_FAIL=20500]="ERROR_SUBSCRIBE_FAIL",i[i.ERROR_SUBSCRIBE_ADD_FAIL=20501]="ERROR_SUBSCRIBE_ADD_FAIL",i[i.ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL=20502]="ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL",i[i.ERROR_SUBSCRIBE_STOP_FAIL=20503]="ERROR_SUBSCRIBE_STOP_FAIL",i[i.ERROR_LOCAL_STREAM_NOT_EXIST=20600]="ERROR_LOCAL_STREAM_NOT_EXIST",i[i.ERROR_LOCAL_STREAM_PREVIEW_FAIL=20601]="ERROR_LOCAL_STREAM_PREVIEW_FAIL",i[i.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST=20602]="ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST",i[i.ERROR_LOCAL_STREAM_CREATE_FAIL=20603]="ERROR_LOCAL_STREAM_CREATE_FAIL",i[i.ERROR_LOCAL_STREAM_STOP_FAIL=20604]="ERROR_LOCAL_STREAM_STOP_FAIL",i[i.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL=20605]="ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL",i[i.ERROR_REMOTE_STREAM_PLAY_FAIL=20700]="ERROR_REMOTE_STREAM_PLAY_FAIL",i[i.ERROR_REMOTE_STREAM_STOP_PLAY_FAIL=20701]="ERROR_REMOTE_STREAM_STOP_PLAY_FAIL",i[i.ERROR_NETWORK_ERROR=20800]="ERROR_NETWORK_ERROR",i[i.ERROR_PREVIEW_ELEMENT_INVALID=20900]="ERROR_PREVIEW_ELEMENT_INVALID",i[i.ERROR_SET_VIEW_CONFIG_INVALID=20901]="ERROR_SET_VIEW_CONFIG_INVALID",i[i.ERROR_REMOTE_USER_NOT_FOUND=21e3]="ERROR_REMOTE_USER_NOT_FOUND",i))(R||{});const G={[R.ERROR_SIGNALING_CONNECT_FAIL]:"Signaling connect fail",[R.ERROR_JOIN_SIGNALING_ERROR]:"Join signaling error",[R.ERROR_JOIN_FAIL]:"Join failed",[R.ERROR_LIVE_ROLE_CANNOT_PUB]:"Live role cannot publish",[R.ERROR_SET_CLIENT_ROLE_FAIL]:"Set client role failed",[R.ERROR_SET_CHANNEL_PROFILE_FAIL]:"Set channel profile failed",[R.ERROR_SET_AUDIO_ONLY_FAIL]:"Set audio only mode failed",[R.ERROR_REFRESH_PUSH_URL_FAIL]:"Refresh push url failed",[R.ERROR_PUBLISH_SIGNALING_ERROR]:"Publish signaling error",[R.ERROR_PUBLISH_FAIL]:"Publish failed",[R.ERROR_PUBLISH_NO_PUBLISHER_FAIL]:"Have no publisher",[R.ERROR_PUBLISH_ADD_FAIL]:"PublishAdd failed",[R.ERROR_PUBLISH_STOP_FAIL]:"PublishStop failed",[R.ERROR_PUBLISH_REPLACE_TRACKS_FAIL]:"PublishReplaceTracks failed",[R.ERROR_PUBLISH_DELETE_TRACKS_FAIL]:"PublishDeleteTracks failed",[R.ERROR_UNPUBLISH_FAIL]:"UnPublish failed",[R.ERROR_SUBSCRIBE_FAIL]:"Subscribe failed",[R.ERROR_SUBSCRIBE_ADD_FAIL]:"SubscribeAdd failed",[R.ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL]:"SubscribeDeleteTracks failed",[R.ERROR_SUBSCRIBE_STOP_FAIL]:"SubscribeStop failed",[R.ERROR_REMOTE_STREAM_PLAY_FAIL]:"RemoteStream play failed",[R.ERROR_REMOTE_STREAM_STOP_PLAY_FAIL]:"RemoteStream stop play failed",[R.ERROR_LOCAL_STREAM_NOT_EXIST]:"Have no local stream",[R.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST]:"preview element not exist",[R.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL]:"Set camera direaction by invalid value",[R.ERROR_LOCAL_STREAM_PREVIEW_FAIL]:"LocalStream preview failed",[R.ERROR_NETWORK_ERROR]:"Network Error",[R.ERROR_PREVIEW_ELEMENT_INVALID]:"Preview element invalid",[R.ERROR_SET_VIEW_CONFIG_INVALID]:"Set view config invalid",[R.ERROR_REMOTE_USER_NOT_FOUND]:"Remote user not found"};class E extends Error{constructor(e=0,t="",r){let a=t;!a&&G[e]&&(a=G[e]);super(a);c(this,"_code");c(this,"_extra");this._code=e,this._extra=r}static fromError(e,t=-1,r=""){return new E(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 sr=3e4;class rr 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 ir(e,t),this.channelProfile=r,this.clientRole=a,this.wsClient=new tr(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=x(He(x({},t.data),{sessionid:t.header.sessionid}),e),this.sendPackage(t)}refreshAuthInfo(e){this.authInfo=e,this.packageCreater.refreshAuthInfo(e)}close(){_.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){[te.KEEPALIVE,te.RECONNECT,te.JOINCHANNEL].includes(e.msgtype)||this.packageCache.set(e.tid,e),this.wsClient.send(e)}updateReconnectData(e){this.reconnectData=e}onOpen(){if(_.info("[roomsigcenter] onOpen"),this.isFirstConnect){let e=this.packageCreater.createJoinPackage();e.data.configure={channelprofile:this.channelProfile},(this.channelProfile===Ie.AliRtcSdkInteractiveLive||this.channelProfile===Ie.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){_.error("[roomsigcenter] onMessage err",t,e)}}onError(e){_.error("[roomsigcenter] onError",e),this.isFirstConnect&&this.onConnectFail()}onConnectFail(){_.error("[roomsigcenter] onConnectFail");const e=new E(R.ERROR_SIGNALING_CONNECT_FAIL,G[R.ERROR_SIGNALING_CONNECT_FAIL]);this.isFirstConnect?this.emit("onJoinChannelResult",e):this.emit("onConnectFail",e)}onAuthInvalid(){_.error("[roomsigcenter] onAuthInvalid"),this.isFirstConnect&&this.emit("onAuthInvalid")}onNetworkError(){_.error("[roomsigcenter] onNetworkError");const e=new E(R.ERROR_SIGNALING_CONNECT_FAIL,"Network error, signaling connect failed.");this.emit("onNetworkError",e)}onClose(e){_.info("[roomsigcenter] onClose",e),this.stopKeepAlive()}onKeepAliveRsp(){this.emit("onKeepAliveRsp"),this.checkAlive()}onReconnectStart(){this.emit("onReconnectStart")}onReconnectFail(){this.emit("onReconnectFail",new E(R.ERROR_SIGNALING_RECONNECT_ERROR,""))}checkAlive(){window.clearTimeout(this.aliveChecker),this.aliveChecker=window.setTimeout(()=>{_.info("[roomsigcenter] not alive, reconnect"),this.stopKeepAlive(),this.emit("onReconnectStart"),this.wsClient.reconnect()},sr)}onRecvMessage(e){switch(e.msgtype!==te.KEEPALIVE&&_.info("[roomsigcenter] recv msg "+e.msgtype),e.msgtype){case te.JOINCHANNEL:this.onJoinResult(e);break;case te.KEEPALIVE:this.onKeepAliveRsp();break;case te.PUBLISH:this.onPublishResult(e);break;case te.NOTIFYJOIN:this.onNotifyJoin(e);break;case te.NOTIFYSTATUS:this.onNotifyStatus(e);break;case te.LEAVECHANNEL:this.onLeaveResult(e);break;case te.NOTIFYLEAVE:this.onNotifyLeave(e);break;case te.NOTIFYPUBLISH:this.onNotifyPublish(e);break;case te.STATUSREPORT:this.onStatusReport(e);break;case te.BYE:this.onBye(e);break;case te.ROLEUPDATE:this.onRoleUpdateResult(e);break;case te.REFRESHURL:this.onRefreshUrlResult(e);break;case te.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 E(R.ERROR_SIGNALING_RECONNECT_ERROR,`reconnect fail, 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 v=(i=!1)=>(s,e,t)=>{const r=t.value;return t.value=function(...a){var h;const n=`${i?"__g__":""}${((h=s.constructor)==null?void 0:h.logName)||""}`,o=Date.now();_.interface(n,e,...a);const u=r.apply(this,a);return Promise.resolve(u).then(l=>l).catch(l=>l).then(l=>{_.interfaceResult(n,e,!(l instanceof Error),`${Date.now()-o}ms`,l)}),u},t};var ar=Object.defineProperty,nr=Object.getOwnPropertyDescriptor,or=(i,s,e,t)=>{for(var r=t>1?void 0:t?nr(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&&ar(s,e,r),r};class Yt extends j{constructor(e,t,r=we.prod){super();c(this,"messageCenter");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"reconnectData");c(this,"roomServerUri","");_.info("[roomsig] ctor"),this.channelProfile=e,this.clientRole=t,this.reconnectData={role:{channelprofile:e,clientrole:t}};const a=r===we.pre?ct.pre:ct.prod;this.roomServerUri=`wss://${a}/roomserver/v1/ws`}updateReconnectData(e){var t;this.reconnectData=e,(t=this.messageCenter)==null||t.updateReconnectData(this.reconnectData)}reset(){_.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)=>{_.setTraceID(e.channelId+"-"+e.callid),_.info("request gslb .."),this.authInfo=e,this.userName=t,this.messageCenter=new rr(e,t,this.channelProfile,this.clientRole,r),this.initMessageCenter(),this.messageCenter.once("onJoinChannelResult",u=>{var h,l;if(_.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,R.ERROR_JOIN_SIGNALING_ERROR))}),this.messageCenter.once("onAuthInvalid",()=>{this.reset(),n(new E(R.ERROR_JOIN_SIGNALING_ERROR,`${G[R.ERROR_JOIN_SIGNALING_ERROR]} because authentication failed`))}),_.info("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:L.Guid.create(32)};e.role&&(o.tokenrole=e.role),this.messageCenter.start(this.roomServerUri+"?"+_e.queryingParam(o))})})}leave(){return _.info("[roomsig] leave .."),new Promise((e,t)=>{this.messageCenter?(this.messageCenter.on("onLeaveResult",(r,a)=>{_.info("recv leave response "+r),r===200?(this.updateReconnectData(),this.reset(),e({tid:a})):t(this.handleSignalError(r,"",R.ERROR_LEAVE_SIGNALING_ERROR))}),_.info("send leave request"),this.messageCenter.leave()):(_.info("no message center, ok to leave"),e({tid:""}))})}publish(e){return _.info("[roomsig] publish .."),new Promise((t,r)=>{var a;this.messageCenter?(this.messageCenter.once("onPublishResult",(n,o,u)=>{_.info("recv pubish response "+n),n===200?(this.updateReconnectData(He(x({},this.reconnectData),{publish:{users:[e]}})),t({tid:o})):r(this.handleSignalError(n,u,R.ERROR_PUBLISH_SIGNALING_ERROR))}),this.authInfo&&(e.sessionid=(a=this.authInfo.callid)!=null?a:""),e.callid=L.Guid.create(32),_.info("assign callid "+e.callid+" and send publish request"),this.messageCenter.publish(e)):r(new E(R.ERROR_PUBLISH_SIGNALING_ERROR,`${G[R.ERROR_PUBLISH_SIGNALING_ERROR]} because no messageCenter`))})}roleUpdate(e){return _.info("[roomsig] roleUpdate to "+e),new Promise((t,r)=>{if(!this.messageCenter){r(new E(R.ERROR_SET_CLIENT_ROLE_FAIL,`${G[R.ERROR_SET_CLIENT_ROLE_FAIL]} because no messageCenter`));return}this.messageCenter.on("onRoleUpdateResult",(a,n,o)=>{var u,h;_.info("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,o,R.ERROR_SET_CLIENT_ROLE_FAIL))}),_.info("send role update request"),this.messageCenter.roleUpdate(e)})}setChannelProfile(e){this.channelProfile=e}refreshUrl(e){return _.info("[roomsig] refreshUrl .."),new Promise((t,r)=>{if(!this.messageCenter){r(new E(R.ERROR_REFRESH_PUSH_URL_FAIL,`${G[R.ERROR_REFRESH_PUSH_URL_FAIL]} because no messageCenter`));return}this.messageCenter.on("onRefreshUrlResult",a=>{const{code:n,description:o,data:u={}}=a||{};_.info("recv refresh url response "+n),n===200?t(u):r(this.handleSignalError(n,o,R.ERROR_REFRESH_PUSH_URL_FAIL))}),_.info("send refresh url request"),this.messageCenter.refreshUrl(e)})}reportStatus(e){return _.info("[roomsig] reportStatus "+e),new Promise((t,r)=>{this.messageCenter?(this.messageCenter.once("onStatusReport",(a,n)=>{a===200?t():r(new E(a,n))}),this.messageCenter.reportStatus(e)):r(new E(-1,"No messageCenter"))})}handleSignalError(e,t,r){const a=`code: ${e}; description: ${t}`;return new E(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,g;(e=this.messageCenter)==null||e.on("onKeepAliveRsp",()=>{this.emit("onKeepAliveRsp")}),(t=this.messageCenter)==null||t.on("onNotifyJoin",m=>{this.emit("onNotifyJoin",m)}),(r=this.messageCenter)==null||r.on("onNotifyStatus",m=>{this.emit("onNotifyStatus",m)}),(a=this.messageCenter)==null||a.on("onNotifyLeave",m=>{this.emit("onNotifyLeave",m)}),(n=this.messageCenter)==null||n.on("onNotifyPublish",m=>{this.emit("onNotifyPublish",m)}),(o=this.messageCenter)==null||o.on("onBye",(m,f)=>{this.emit("onBye",m,f)}),(u=this.messageCenter)==null||u.on("onReconnectStart",()=>{this.emit("onReconnectStart")}),(h=this.messageCenter)==null||h.on("onReconnectSuccess",m=>{this.emit("onReconnectSuccess",m)}),(l=this.messageCenter)==null||l.on("onReconnectFail",m=>{this.emit("onReconnectFail",m)}),(p=this.messageCenter)==null||p.on("onConnectFail",m=>{this.emit("onConnectFail",m),this.reset()}),(d=this.messageCenter)==null||d.on("onNetworkError",m=>{this.emit("onNetworkError",m)}),(g=this.messageCenter)==null||g.on("onAuthInvalid",()=>{this.emit("onAuthInvalid")})}}c(Yt,"logName","RoomServerSignaling"),or([v()],Yt.prototype,"join",1);class cr extends j{constructor(e,t,r=we.prod){super();c(this,"signaling");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"env",we.prod);c(this,"maxConnectRetryCount");this.channelProfile=e,this.clientRole=t,this.env=r}reset(){var e;_.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 E(R.ERROR_JOIN_FAIL,"already logged in")):(_.info("[signalingmanager] create signaling"),this.signaling=new Yt(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 E(R.ERROR_PUBLISH_FAIL,"no signaling"))})}reportStatus(e){return new Promise((t,r)=>{this.signaling?this.signaling.reportStatus(e).then(()=>{t()}).catch(a=>{r(a)}):r(new E(-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 E(R.ERROR_REFRESH_PUSH_URL_FAIL,"no signaling"))}refreshAuthInfo(e){return S(this,null,function*(){var t;try{this.authInfo&&(this.authInfo=x(x({},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,g,m;(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)),(g=this.signaling)==null||g.on("onAuthInvalid",this.onAuthInvalid.bind(this)),(m=this.signaling)==null||m.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 Me=class Me{static getInstance(){return Me.instance||(Me.instance=new AudioContext),Me.instance.resume(),Me.instance}};c(Me,"instance");let Xt=Me;function ur(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((g,m)=>g+m)/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 hr extends j{constructor(){super();c(this,"audioContext");c(this,"stream");c(this,"sourceNode");c(this,"analyser");this.audioContext=Xt.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=ur(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 Vi 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 hr}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 Di{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 Ui="customVideoProfile",xi="customScreenProfile",ze={width:1280,height:720,frameRate:30,maxBitrate:2e3},Je={width:1920,height:1080,frameRate:30,maxBitrate:2600},lr={1e4:Z.AliEngineLocalDeviceExceptionTypeUnknown,2e4:Z.AliEngineLocalDeviceExceptionTypeUnknown,10001:Z.AliEngineLocalDeviceExceptionTypeMicNotAvailable,10002:Z.AliEngineLocalDeviceExceptionTypeMicAuthFail,10003:Z.AliEngineLocalDeviceExceptionTypeMicOpenFail,10005:Z.AliEngineLocalDeviceExceptionTypeCameraAuthFail,10004:Z.AliEngineLocalDeviceExceptionTypeVideoDeviceException,10006:Z.AliEngineLocalDeviceExceptionTypeCameraOpenFail,10010:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10011:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10012:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10013:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10014:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10019:Z.AliEngineLocalDeviceExceptionTypeDisplayException};var dr=Object.defineProperty,pr=Object.getOwnPropertyDescriptor,Q=(i,s,e,t)=>{for(var r=t>1?void 0:t?pr(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&&dr(s,e,r),r};class pt extends j{constructor(){super();c(this,"state");c(this,"time");this.state=k.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 Ct=class Ct extends Vi{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",L.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 pt,this.audioPubState.on("change",(h,l,p)=>{this.emit("audioPublishStateChanged",h,l,p)}),this.videoPubState=new pt,this.videoPubState.on("change",(h,l,p)=>{this.emit("videoPublishStateChanged",h,l,p)}),this.videoSmallPubState=new pt,this.videoSmallPubState.on("change",(h,l,p)=>{this.emit("dualStreamPublishStateChanged",h,l,p)}),this.screenPubState=new pt,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===A.VideoLarge))}get hasCameraDualTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===A.VideoSmall))}get hasScreenTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===A.Screen))}get hasAudioTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="audio"&&t&&a===A.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===je.CAMERA_FRONT)this.streamManager.setCameraVideoConstraints({facingMode:"user"});else if(e===je.CAMERA_REAR)this.streamManager.setCameraVideoConstraints({facingMode:"environment"});else throw new E(R.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL,`${G[R.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL]} ${e}`)}setCameraDeviceId(e){this.streamManager.setCameraVideoConstraints({deviceId:e})}setMicrophoneDeviceId(e){this.streamManager.setMicAudioConstraints({deviceId:e})}updatePubId(){this.publishId=L.Guid.create(16)}clearPublishState(){this.streamTracks=void 0}clear(){return S(this,null,function*(){Ci(Ct.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)&&(e.srcObject=null,this.previewElements.splice(this.previewElements.indexOf(e),1)),this.screenPreviewElements.includes(e)&&(e.srcObject=null,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===null){t===V.AliRtcVideoTrackCamera?this.stopPreview({primary:!0,screen:!1}):this.stopPreview({primary:!1,screen:!0});return}if(![V.AliRtcVideoTrackCamera,V.AliRtcVideoTrackScreen].includes(t))throw new E(R.ERROR_SET_VIEW_CONFIG_INVALID,G[R.ERROR_SET_VIEW_CONFIG_INVALID],{track:t});e.forEach(r=>{this.setPreviewElement({videoElement:r,screen:t===V.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 E(R.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST,G[R.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST],{videoElement:r});if(!n)throw new E(R.ERROR_LOCAL_STREAM_NOT_EXIST,G[R.ERROR_LOCAL_STREAM_NOT_EXIST],{screen:a});return _.info(`[${this.moduleName}/${t}]`,{screen:a,stream:n,videoElement:r}),yield n.play(r),this.setPreviewElement(e),n.mediaStream}catch(n){const o=R.ERROR_LOCAL_STREAM_PREVIEW_FAIL;throw E.fromError(n,o,G[o])}})}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=>{n.pause(),n.srcObject=null}),a&&this.screenPreviewElements.forEach(n=>{n.pause(),n.srcObject=null});else{const n=this.previewElements.findIndex(o=>o===t);if(n>=0)this.previewElements.splice(n,1),t.pause(),t.srcObject=null;else{const o=this.screenPreviewElements.findIndex(u=>u===t);o>=0&&(this.screenPreviewElements.splice(o,1),t.pause(),t.srcObject=null)}}}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=lr[t.errorCode];throw r&&(e.audio?this.emit("localDeviceException",be.AliEngineLocalDeviceTypeMic,r,""):e.video?this.emit("localDeviceException",be.AliEngineLocalDeviceTypeCamera,r,""):e.screen?this.emit("localDeviceException",be.AliEngineLocalDeviceTypeDisplay,r,""):this.emit("localDeviceException",be.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===A.Audio?u.audio=!0:r===A.VideoLarge||r===A.VideoSmall?(u.video=!0,u.vMsid=r):r===A.Screen&&(u.screen=!0),yield this.publishDeleteTracks(u)}const a={};if(t!=null&&t.hasVideo&&(a.isScreen=r===A.Screen,a.vMsid=r),t!=null&&t.hasAudio&&(a.aMsid=r),!e&&t)return yield this.publishAdd(t,!1,a);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(k.AliRtcStatePublishing),a&&this.videoPubState.setState(k.AliRtcStatePublishing),n&&this.videoSmallPubState.setState(k.AliRtcStatePublishing),o&&this.screenPubState.setState(k.AliRtcStatePublishing),this.publishPromise=this.rtsManager.publish(this.url);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(k.AliRtcStatePublished),a&&this.videoPubState.setState(k.AliRtcStatePublished),n&&this.videoSmallPubState.setState(k.AliRtcStatePublished),o&&this.screenPubState.setState(k.AliRtcStatePublished)}catch(u){throw r&&this.audioPubState.setState(k.AliRtcStateNoPublish),a&&this.videoPubState.setState(k.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),o&&this.screenPubState.setState(k.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:M,type:H,msid:P})=>H==="audio"&&M&&P===A.Audio),l=yield this.compareAndPublish(h,e.audio,A.Audio);l&&(t=l);const p=(n=this.streamTracks)==null?void 0:n.find(({ssrc:M,type:H,msid:P})=>H==="video"&&M&&P===A.VideoLarge),d=yield this.compareAndPublish(p,e.video,A.VideoLarge);d&&(t=d);const g=(o=this.streamTracks)==null?void 0:o.find(({ssrc:M,type:H,msid:P})=>H==="video"&&M&&P===A.VideoSmall),m=yield this.compareAndPublish(g,e.videoSmall,A.VideoSmall);m&&(t=m);const f=(u=this.streamTracks)==null?void 0:u.find(({ssrc:M,type:H,msid:P})=>H==="video"&&M&&P===A.Screen),b=yield this.compareAndPublish(f,e.screen,A.Screen);if(b&&(t=b),!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){const d=R.ERROR_PUBLISH_FAIL,g=G[d];throw new E(d,`${g} because there is 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 E(R.ERROR_REFRESH_PUSH_URL_FAIL,G[R.ERROR_REFRESH_PUSH_URL_FAIL]),t=this.url;try{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}catch(r){throw r}})}publishAdd(e,t=!1,r,a=0){return S(this,null,function*(){const n=R.ERROR_PUBLISH_ADD_FAIL,o=G[R.ERROR_PUBLISH_ADD_FAIL],u=(r==null?void 0:r.aMsid)===A.Audio,h=(r==null?void 0:r.vMsid)===A.VideoLarge,l=(r==null?void 0:r.vMsid)===A.VideoSmall,p=(r==null?void 0:r.vMsid)===A.Screen;u&&this.audioPubState.setState(k.AliRtcStatePublishing),h&&this.videoPubState.setState(k.AliRtcStatePublishing),l&&this.videoSmallPubState.setState(k.AliRtcStatePublishing),p&&this.screenPubState.setState(k.AliRtcStatePublishing);try{const d=yield this.rtsManager.publishAdd(this.url,e,r);u&&this.audioPubState.setState(k.AliRtcStatePublished),h&&this.videoPubState.setState(k.AliRtcStatePublished),l&&this.videoSmallPubState.setState(k.AliRtcStatePublished),p&&this.screenPubState.setState(k.AliRtcStatePublished),this.streamTracks=this.rtsManager.publishingTracks;const g={userid:this.userId,sessionid:"",displayname:this.name,pubid:this.publishId,resume:t,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks,traceid:d};return this.reportSelfDeviceStatus(),g}catch(d){if(u&&this.audioPubState.setState(k.AliRtcStateNoPublish),h&&this.videoPubState.setState(k.AliRtcStateNoPublish),l&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),p&&this.screenPubState.setState(k.AliRtcStateNoPublish),d.errorCode===15006&&a<3)return this.publishAdd(e,t,r,a+1);throw E.fromError(d,n,o)}})}publishReplace(e,t){return S(this,null,function*(){const r=R.ERROR_PUBLISH_REPLACE_TRACKS_FAIL,a=G[r],{isScreen:n}=t!=null?t:{};if(n&&!this.hasScreenTrackInMS)throw new E(r,`${a} because previous localStream is required for replacing tracks`);try{yield this.rtsManager.publishReplace(this.url,e,t),this.traceId="",this.streamTracks=this.rtsManager.publishingTracks;const o={userid:this.userId,sessionid:"",pubid:this.publishId,displayname:this.name,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks};return this.reportSelfDeviceStatus(),o}catch(o){throw E.fromError(o,r,a)}})}publishDeleteTracks(e){return S(this,null,function*(){const t=R.ERROR_PUBLISH_DELETE_TRACKS_FAIL,r=G[t],a={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(k.AliRtcStateNoPublish),e.video&&(e.vMsid===A.VideoSmall?this.videoSmallPubState.setState(k.AliRtcStateNoPublish):this.videoPubState.setState(k.AliRtcStateNoPublish)),e.screen&&this.screenPubState.setState(k.AliRtcStateNoPublish),this.traceId="",a.tracks=this.streamTracks,this.reportSelfDeviceStatus(),a}catch(n){throw E.fromError(n,t,r)}})}publishStop(){return S(this,null,function*(){const e="publishStop",t=R.ERROR_PUBLISH_STOP_FAIL,r=G[t];if(!this._isPublishing)throw new E(t,`${r} because previous localStream is required for publishing stopping`);_.info(`[${this.moduleName}/${e}]`,{url:this.url});const a=new Date().getTime();try{const n=this.hasAudioTrackInMS,o=this.hasCameraTrackInMS,u=this.hasCameraDualTrackInMS,h=this.hasScreenTrackInMS;yield this.rtsManager.publishStop(this.url),n&&this.audioPubState.setState(k.AliRtcStateNoPublish),o&&this.videoPubState.setState(k.AliRtcStateNoPublish),u&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),h&&this.screenPubState.setState(k.AliRtcStateNoPublish),this.traceId="",this.streamTracks=[];const l={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};return this.syncPublishToRoomServer(l,{},a),l}catch(n){throw E.fromError(n,t,r)}})}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(k.AliRtcStateNoPublish),a&&this.videoPubState.setState(k.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),o&&this.screenPubState.setState(k.AliRtcStateNoPublish),this._isPublishing=!1,this.traceId="",this.clearStream()}return this.reporter.reportUnpublish(this.callid||"",e,0,""),t}catch(r){throw E.fromError(r,R.ERROR_UNPUBLISH_FAIL,G[R.ERROR_UNPUBLISH_FAIL])}})}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),Di.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(k.AliRtcStatePublishIdle),this.videoPubState.setState(k.AliRtcStatePublishIdle),this.videoSmallPubState.setState(k.AliRtcStatePublishIdle),this.screenPubState.setState(k.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:Ne.AliRtcAudioTrackMic})}const t=[];if(this.hasCameraTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,A.VideoLarge);r&&t.push({track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:r})}if(this.hasCameraDualTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,A.VideoSmall);r&&t.push({track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:r})}if(this.hasScreenTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,A.Screen);r&&t.push({track:V.AliRtcVideoTrackScreen,stats:r})}return{audio:e,video:t}})}};c(Ct,"logName","LocalUser");let z=Ct;Q([v()],z.prototype,"initInfo",1),Q([v()],z.prototype,"clearPublishState",1),Q([v()],z.prototype,"clear",1),Q([v()],z.prototype,"setViewConfig",1),Q([v()],z.prototype,"preview",1),Q([v()],z.prototype,"stopPreview",1),Q([v()],z.prototype,"resumePublish",1),Q([v()],z.prototype,"createLocalStream",1),Q([v()],z.prototype,"stopLocalStream",1),Q([v()],z.prototype,"compareAndPublish",1),Q([v()],z.prototype,"startPublish",1),Q([v()],z.prototype,"publishUpdate",1),Q([v()],z.prototype,"syncPublishToRoomServer",1),Q([v()],z.prototype,"refreshPushStreamUrl",1),Q([v()],z.prototype,"publishAdd",1),Q([v()],z.prototype,"publishReplace",1),Q([v()],z.prototype,"publishDeleteTracks",1),Q([v()],z.prototype,"publishStop",1),Q([v()],z.prototype,"unPublish",1),Q([v()],z.prototype,"sendSEI",1);var Pe=(i=>(i.OPUS="opus",i.H264="H264",i.UNKONWN="",i))(Pe||{}),Ce=(i=>(i.VideoTrackEnded="videoTrackEnded",i.AudioTrackEnded="audioTrackEnded",i.ScreenTrackEnded="screenTrackEnded",i))(Ce||{});const gr=i=>{const s=new MediaStream;return s.addTrack(i),s},Fi=i=>S(this,null,function*(){return yield y.AliRTS.createStream({custom:!0,mediaStream:i})}),Ye=i=>S(this,null,function*(){const s=gr(i);return yield Fi(s)}),mr=i=>{const{audio:s,video:e,screen:t}=i;if(e&&t)throw new E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"create stream error, cannot create video && screen together");return!(!e&&!s&&!t)},Sr=i=>i===A.Audio||i===pe.Audio,fr=i=>i===A.VideoLarge||i===pe.VideoLarge,br=i=>i===A.VideoSmall,Rr=i=>i===A.Screen;var vr=Object.defineProperty,_r=Object.getOwnPropertyDescriptor,Ir=(i,s,e,t)=>{for(var r=t>1?void 0:t?_r(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&&vr(s,e,r),r};class gt extends j{constructor(){super();c(this,"audioInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.UNKONWN});c(this,"videoLargeInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.UNKONWN});c(this,"videoSmallInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.UNKONWN});c(this,"screenInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.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:Pe.UNKONWN}get audioTrackInfo(){return this.hasAudio?Ne.AliRtcAudioTrackMic:Ne.AliRtcAudioTrackNo}get videoTrackInfo(){return this.hasVideo&&this.hasScreen?V.AliRtcVideoTrackBoth:this.hasVideo?V.AliRtcVideoTrackCamera:this.hasScreen?V.AliRtcVideoTrackScreen:V.AliRtcVideoTrackNo}updateTracks(e){let t="",r="",a="",n="";return e?(e.forEach(o=>{var l;let u=Pe.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)}Sr(o.msid)?(t=o.ssrc,this.audioInfo.msid=o.msid,this.audioInfo.codec=u,h&&(this.audioInfo.subscribed=!1)):br(o.msid)?(a=o.ssrc,this.videoSmallInfo.msid=o.msid,this.videoSmallInfo.codec=u,h&&(this.videoSmallInfo.subscribed=!1)):fr(o.msid)?(r=o.ssrc,this.videoLargeInfo.msid=o.msid,this.videoLargeInfo.codec=u,h&&(this.videoLargeInfo.subscribed=!1)):Rr(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=Di.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?U.MuteAudio:U.UnmuteAudio)),this.userStatus.videoDisable!=a&&(this.userStatus.videoDisable=a,this.emit(ie.Remote,a?U.MuteVideo:U.UnmuteVideo)),this.userStatus.screenDisable!=n&&(this.userStatus.screenDisable=n,this.emit(ie.Remote,n?U.MuteScreen:U.UnmuteScreen))):(this.userStatus=t,this.emit(ie.Remote,r?U.MuteAudio:U.UnmuteAudio),this.emit(ie.Remote,a?U.MuteVideo:U.UnmuteVideo),this.emit(ie.Remote,n?U.MuteScreen:U.UnmuteScreen)),!1}}c(gt,"logName","RemoteStreamInfo"),Ir([v()],gt.prototype,"updateRemoteTrackSubState",1);const Ar=i=>i.getAudioTracks()[0];function Bi(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 E(R.ERROR_PREVIEW_ELEMENT_INVALID,`${G[R.ERROR_PREVIEW_ELEMENT_INVALID]}, element need HtmlVideoElement`)}else throw new E(R.ERROR_PREVIEW_ELEMENT_INVALID,`${G[R.ERROR_PREVIEW_ELEMENT_INVALID]}, not found htmlelement`)}else throw new E(R.ERROR_PREVIEW_ELEMENT_INVALID,`${G[R.ERROR_PREVIEW_ELEMENT_INVALID]}, element id need string`)}function Zt(i){var e;const s=[];if(Array.isArray(i))i.forEach(t=>{try{s.push(Bi(t))}catch(r){}});else if(typeof i=="string"||((e=i==null?void 0:i.nodeName)==null?void 0:e.toLowerCase())==="video")try{s.push(Bi(i))}catch(t){}return s}function mt(i){return new Promise(s=>setTimeout(s,i))}var wr=Object.defineProperty,Er=Object.getOwnPropertyDescriptor,X=(i,s,e,t)=>{for(var r=t>1?void 0:t?Er(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 Xe extends j{constructor(){super();c(this,"state");c(this,"time");c(this,"_enabled");this.state=K.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 kt=class kt extends Vi{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,"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 Xe);c(this,"videoSmallSubState",new Xe);c(this,"screenSubState");c(this,"streamInfo");c(this,"streamUrl","");this.streamInfo=new gt,this.streamInfo.on(ie.Remote,g=>{this.emit(ie.Remote,g,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 Xe,this.audioSubState.on("change",(g,m,f)=>{this.emit("audioSubscribeStateChanged",this.uid,g,m,f)}),this.videoSubState=new Xe,this.videoSubState.on("change",(g,m,f)=>{this.emit("videoSubscribeStateChanged",this.uid,g,m,f)}),this.screenSubState=new Xe,this.screenSubState.on("change",(g,m,f)=>{this.emit("screenSubscribeStateChanged",this.uid,g,m,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)}get hasAudioTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasAudio)}get hasVideoTrack(){var e;return!!((e=this.streamInfo)!=null&&e.hasVideo)}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 getCameraStream(){return this.stream}get getScreenStream(){return this.screenStream}setViewConfig(e,t){if(t!==V.AliRtcVideoTrackScreen&&t!==V.AliRtcVideoTrackCamera)throw new Error("track is not AliRtcVideoTrackScreen or AliRtcVideoTrackCamera");e?Zt(e).forEach(a=>{a.setAttribute("playsinline",""),L.BrowserUtil.isMicroMessenger&&(a.setAttribute("x5-video-player-type","h5-page"),a.setAttribute("x5-playsinline",""),L.SystemUtil.isAndroid||L.SystemUtil.isIos&&a.setAttribute("x-webkit-airplay","allow")),t===V.AliRtcVideoTrackScreen?this.viewMap.screenViews.push(a):this.viewMap.cameraViews.push(a),this.play(a,t===V.AliRtcVideoTrackScreen)}):(this.stopPlayAll(t===V.AliRtcVideoTrackScreen),t===V.AliRtcVideoTrackScreen?this.viewMap.screenViews=[]:this.viewMap.cameraViews=[])}clear(e=!0){return S(this,null,function*(){var t;e&&this.doStopSubscribe(this.streamUrl),Ci(kt.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 gt),(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(K.AliRtcStateSubscribing),e.video&&(this.videoSubState.currentState===K.AliRtcStateSubscribeIdle||this.videoSubState.currentState===K.AliRtcStateNoSubscribe)&&this.videoSubState.setState(K.AliRtcStateSubscribing),e.screen&&this.screenSubState.setState(K.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(K.AliRtcStateSubscribed),this.audioSubState.getEnabled()||this.toggleAudio(!1)}e.video&&(e.vMsid===A.VideoSmall?this.videoSmallSubState.setState(K.AliRtcStateSubscribed):this.videoLargeSubState.setState(K.AliRtcStateSubscribed),this.videoSubState.setState(K.AliRtcStateSubscribed),this.videoSubState.getEnabled()||this.toggleVideo(!1),this.updateStream(h,this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing)),e.screen&&(this.screenSubState.setState(K.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;throw this.webTrackingClient.reportPull("","",!1,!1,!1,!1,u.code,h,a,r,(o=this.streamUrl)!=null?o:"",t),u}})}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(K.AliRtcStateNoSubscribe)),e.video===!0&&(a.video=!1,e.vMsid===A.VideoSmall?(this.videoSmallSubState.setState(K.AliRtcStateNoSubscribe),(this.videoLargeSubState.currentState===K.AliRtcStateNoSubscribe||this.videoLargeSubState.currentState===K.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(K.AliRtcStateNoSubscribe)):(this.videoLargeSubState.setState(K.AliRtcStateNoSubscribe),(this.videoSmallSubState.currentState===K.AliRtcStateNoSubscribe||this.videoSmallSubState.currentState===K.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(K.AliRtcStateNoSubscribe))),e.screen===!0&&(a.screen=!1,this.screenSubState.setState(K.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){const r=R.ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL;throw E.fromError(t,r,G[r])}})}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===V.AliRtcVideoTrackCamera||e===V.AliRtcVideoTrackBoth)return this.playAll();if(!e||e===V.AliRtcVideoTrackScreen||e===V.AliRtcVideoTrackBoth)return this.playAll(!0)})}resumePlay(){this.playAudio(),this.playAll(),this.playAll(!0)}stopSubscribe(e){return S(this,null,function*(){var p,d,g,m,f,b,M;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&&!((g=e==null?void 0:e.screen)==null||g);e?this.reporter.reportSubscribeInvoked(this.userId,o,u,h,n):this.reporter.reportUnsubscribeInvoked(this.userId);let l=new Date().getTime();try{let H;e?H=yield this.subscribeDeleteTracks(e):H=yield this.doStopSubscribe(this.streamUrl),e?this.reporter.reportSubscribe((m=H==null?void 0:H.callid)!=null?m:"",this.userId,o,u,h,n,0,"",new Date().getTime()-l,(f=this.localUserId)!=null?f:""):this.reporter.reportUnsubscribe((b=H==null?void 0:H.callid)!=null?b:"",this.userId,new Date().getTime()-l,0,"")}catch(H){throw e?this.reporter.reportSubscribe("",this.userId,o,u,h,n,H.code,"",new Date().getTime()-l,(M=this.localUserId)!=null?M:""):this.reporter.reportUnsubscribe("",this.userId,new Date().getTime()-l,0,""),H}})}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{try{yield this.rtsManager.subscibeStop(e),this.restore()}catch(l){if(((u=(o=(n=(a=l==null?void 0:l.extraInfo)==null?void 0:a.parsedData)==null?void 0:n.streams)==null?void 0:o[0])==null?void 0:u.res_code)!==404)throw l}return{callid:t,remoteCallid:r,remoteStream:this.stream}}catch(h){const l=R.ERROR_SUBSCRIBE_STOP_FAIL;throw E.fromError(h,l,G[l])}})}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=()=>{_.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.srcObject=e.mediaStream}else r(!0);a=window.setTimeout(()=>{_.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=A.VideoSmall):!this.isVideoLargeSubscribing&&((u=this.streamInfo)!=null&&u.hasVideoLarge)&&!(this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoSmallSubscribing)&&(e.video=!0,e.vMsid=A.VideoLarge),this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&this.streamInfo.hasVideoSmall?(t.video=!0,t.vMsid=A.VideoLarge):this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeHigh&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&(t.video=!0,t.vMsid=A.VideoSmall)):(!this.wantSubVideo||!((h=this.streamInfo)!=null&&h.hasVideo))&&this.isVideoSubscribing&&(t.video=!0,t.vMsid=this.streamInfo.isVideoSmallSubscribing?A.VideoSmall:A.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=()=>{this.play(e,t===V.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),L.SystemUtil.isIos&&parseInt(L.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;if(!e||!r||!r.mediaStream)return;e.srcObject=r.mediaStream;const a=()=>S(this,null,function*(){e.play().catch(()=>{this.handleVideoPlayFailded(e,t?V.AliRtcVideoTrackScreen:V.AliRtcVideoTrackCamera)})});if(L.BrowserUtil.isMicroMessenger){const n=window.top!==window.self,o=window.WeixinJSBridge||window.top.WeixinJSBridge;o?o.invoke("getNetworkType",{},()=>{a()}):(n?window.top.document:document).addEventListener("WeixinJSBridgeReady",()=>{o.invoke("getNetworkType",{},()=>{a()})})}else a()}stopPlayAll(e=!1){e?this.viewMap.screenViews.forEach(t=>{t.pause(),t.srcObject=null}):this.viewMap.cameraViews.forEach(t=>{t.pause(),t.srcObject=null})}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:Ne.AliRtcAudioTrackMic,stats:n})}const t=[];if((r=this.streamInfo)!=null&&r.isVideoLargeSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,A.VideoLarge);n&&t.push({uid:this.uid,track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:n})}if((a=this.streamInfo)!=null&&a.isVideoSmallSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,A.VideoSmall);n&&t.push({uid:this.uid,track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:n})}if(this.isScreenSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,A.Screen);n&&t.push({uid:this.uid,track:V.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(kt,"logName","RemoteUser");let $=kt;X([v()],$.prototype,"setRemoteDefaultVideoStreamType",1),X([v()],$.prototype,"clear",1),X([v()],$.prototype,"updateRemoteUserDeviceStatus",1),X([v()],$.prototype,"updateRemoteTracks",1),X([v()],$.prototype,"subscribe",1),X([v()],$.prototype,"subscribeProxy",1),X([v()],$.prototype,"subscribeDeleteTracks",1),X([v()],$.prototype,"subscribeDeleteProxy",1),X([v()],$.prototype,"restore",1),X([v()],$.prototype,"stopSubscribe",1),X([v()],$.prototype,"doStopSubscribe",1),X([v()],$.prototype,"clearStream",1),X([v()],$.prototype,"clearScreenStream",1),X([v()],$.prototype,"updateSubscribe",1),X([v()],$.prototype,"playAudio",1),X([v()],$.prototype,"stopPlayAudio",1),X([v()],$.prototype,"playAll",1),X([v()],$.prototype,"play",1),X([v()],$.prototype,"stopPlayAll",1),X([v()],$.prototype,"toggleAudio",1),X([v()],$.prototype,"toggleVideo",1),X([v()],$.prototype,"toggleScreen",1);class Tr extends j{constructor(){super(...arguments);c(this,"plugins",new Map)}add(e,t){if(this.plugins.has(e.name))throw new Error(`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 Error(`Plugin ${e} not found`);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())}}const yr=i=>{if(typeof i!="function")throw new TypeError("Callback must be a function");typeof Promise!="undefined"?Promise.resolve().then(i).catch(s=>console.error(s)):setTimeout(i,0)};var Lr=Object.defineProperty,Pr=Object.getOwnPropertyDescriptor,ue=(i,s,e,t)=>{for(var r=t>1?void 0:t?Pr(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&&Lr(s,e,r),r};class Cr{constructor(s){c(this,"queue");c(this,"queue2");c(this,"batchFunc");this.queue=[],this.queue2=[],this.batchFunc=s}add(s){return yr(this.flush.bind(this)),new Promise((e,t)=>{this.queue.find(r=>r.config.url===s.url)?this.queue2.push({config:s,resolve:e,reject:t}):this.queue.push({config:s,resolve:e,reject:t})})}flush(){if(this.queue.length===0&&this.queue2.length===0)return;const s=this.queue.map(t=>t),e=this.queue2.map(t=>t);this.queue=[],this.queue2=[],[s,e].map(t=>{if(t.length>0)try{this.batchFunc(t.map(r=>r.config)).then(r=>{r.forEach(a=>{const n=t.find(o=>o.config.url===a.url);n&&n.resolve(a)})})}catch(r){t.forEach(a=>a.reject(r))}})}}class ae 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",[]);c(this,"subscribeAddBatcher");this.rts=y.AliRTS.createClient(),this.localStreamManager=e,this.subscribeAddBatcher=new Cr(this.rts.subscribeAdd.bind(this.rts)),this.rts.on("connectStatusChange",t=>{_.event("rts connectStatusChange to:",t.status),(t.status===y.EConnectStatus.CONNECT_STATUS_RECONNECTING||t.status===y.EConnectStatus.CONNECT_STATUS_DISCONNECTED)&&this.setConnected(!1)}),this.rts.on("datachannelStatusChange",t=>{_.event("rts datachannelStatusChange to:",t.status),t.status===y.EDatachannelStatus.DATACHANNEL_STATUS_OPEN?this.dcResolve&&this.dcResolve(!0):t.status===y.EDatachannelStatus.DATACHANNEL_STATUS_CLOSE&&(this.dcConnectingPromise=new Promise(r=>{this.dcResolve=r}),console.warn("DC DisConnected"))}),this.rts.on("connectStatusChange",t=>{t.status===y.EConnectStatus.CONNECT_STATUS_RECONNECTING?this.emit("reconnecting"):t.status===y.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:A.Audio]),e.hasScreen&&(n.vMsid=[A.Screen]),e.hasVideo&&(n.vMsid=[a!=null?a:t!=null&&t.isScreen?A.Screen:A.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});y.AliRTS.SystenUtil.isIos&&(u.tcpOnly=!0),u.retryTimes=0,this.encodedInsertableStreams&&(u.encodedInsertableStreams=!0);try{this.startConnect();const h=yield this.rts.publish(e,r,u);return this.setConnected(!0),this._publishingTracks=this.rts.getPublishTrackInfoList(),a&&(yield this.publishAdd(e,a,{vMsid:A.VideoSmall},t)),n&&(yield this.publishAdd(e,n,{vMsid:A.Screen},t)),h}catch(h){throw this.setConnected(!1),h}})}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){return S(this,null,function*(){try{yield this.dcConnectingPromise;const o=yield this.rts.publishAdd([x({url:e,stream:t,updateSourceStream:!1},this.getPubMsid(t,r))]);if(o){const[u]=o;return this.updatePublishingTracks(u.trackInfoList),u.traceId||""}}catch(o){if(o.errorCode===15006&&n<3)return yield this.publishAdd(e,t,r,a,n+1);throw o}return""})}publishDelete(e,t){return S(this,null,function*(){var l,p,d,g,m,f;yield this.dcConnectingPromise;const r=(p=(l=this.publishingTracks)==null?void 0:l.find(({msid:b})=>b===A.Audio))==null?void 0:p.msid,a=(g=(d=this.publishingTracks)==null?void 0:d.find(({msid:b})=>b===A.VideoLarge))==null?void 0:g.msid,n=(f=(m=this.publishingTracks)==null?void 0:m.find(({msid:b})=>b===A.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 this.updatePublishingTracks(h.trackInfoList),""})}publishReplace(e,t,r){return S(this,null,function*(){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),""})}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)||A.Audio]),r.video?r.vMsid?a.vMsid=[r.vMsid]:e!=null&&e.hasVideoLarge?a.vMsid=[(e==null?void 0:e.getVideoLargeInfo().msid)||A.VideoLarge]:e!=null&&e.hasVideoSmall?a.vMsid=[(e==null?void 0:e.getVideoSmallInfo().msid)||A.VideoSmall]:a.vMsid=[A.VideoLarge]:r.screen&&e!=null&&e.hasScreen&&(a.vMsid=[(e==null?void 0:e.getScreenInfo().msid)||A.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);y.AliRTS.SystenUtil.isIos&&(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=He(x({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.subscribeAddBatcher.add(a)}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}return null})}subscibeDelete(e){return S(this,null,function*(){var n,o,u,h;yield this.dcConnectingPromise;const{remoteUser:t,options:r}=e,a=He(x({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){return S(this,null,function*(){let t="";if(this.connecting&&(yield this.connectingPromise),this.connected){yield this.dcConnectingPromise;const{audio:r,video:a,videoSmall:n,screen:o}=this.localStreamManager.publishStreams;r&&(t=yield this.publishAdd(e,r,{aMsid:A.Audio}),yield mt(100)),a&&(t=yield this.publishAdd(e,a,{vMsid:A.VideoLarge}),yield mt(100)),n&&(t=yield this.publishAdd(e,n,{vMsid:A.VideoSmall}),yield mt(100)),o&&(t=yield this.publishAdd(e,o,{isScreen:!0,vMsid:A.Screen}))}else t=yield this.httpPublish(e);return t})}subscribe(e){return S(this,null,function*(){const{options:t}=e;if(t.video&&t.screen)throw new E(R.ERROR_SUBSCRIBE_FAIL,"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:A.VideoLarge,data:t,repeatCount:r,payloadType:a})})}}c(ae,"logName","RtsManager"),ue([v()],ae.prototype,"updatePublishingTracks",1),ue([v()],ae.prototype,"httpPublish",1),ue([v()],ae.prototype,"publishAdd",1),ue([v()],ae.prototype,"publishDelete",1),ue([v()],ae.prototype,"publishReplace",1),ue([v()],ae.prototype,"publishStop",1),ue([v()],ae.prototype,"unpublish",1),ue([v()],ae.prototype,"httpSubscribe",1),ue([v()],ae.prototype,"subscribeAdd",1),ue([v()],ae.prototype,"subscibeDelete",1),ue([v()],ae.prototype,"subscibeStop",1),ue([v()],ae.prototype,"publish",1),ue([v()],ae.prototype,"subscribe",1),ue([v()],ae.prototype,"sendSEI",1);class Qt{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 Hi extends j{constructor(e){super();c(this,"type");c(this,"originVideoTrack");c(this,"videoSource");c(this,"originAudioTrack");c(this,"audioSource");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!==fe.Camera)throw new Error("VideoStreamSource is required");if(n&&!r&&r!==ot.Microphone)throw new Error("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===ee.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)})}process(e){return S(this,null,function*(){var t,r,a,n,o,u,h,l,p,d,g;this._targetAudioTrack=this.originAudioTrack,this._targetVideoTrack=this.originVideoTrack;for(const m of this.plugins)try{yield m.execute(this,e)}catch(f){console.error(`error in plugin-${m.name}, error: ${f}`)}this._targetVideoTrack?((r=(t=this._publishVideoStream)==null?void 0:t.videoTrack)==null?void 0:r.id)!==this._targetVideoTrack.id&&(this._publishVideoStream=yield Ye(this._targetVideoTrack),(a=this.profileManager)==null||a.setVideoProfile(this.originVideoTrack,this._publishVideoStream,!0),this.previewStream?(n=this.previewStream)==null||n.mergeStream(this._publishVideoStream):this._previewStream=yield Ye(this._targetVideoTrack)):(this._publishVideoStream=void 0,(o=this.previewStream)==null||o.deleteTracks({video:!0})),this._targetDualVideoTrack?((h=(u=this._publishDualVideoStream)==null?void 0:u.videoTrack)==null?void 0:h.id)!==this._targetDualVideoTrack.id&&(this._publishDualVideoStream=yield Ye(this._targetDualVideoTrack)):this._publishDualVideoStream=void 0,this._targetAudioTrack?((p=(l=this._publishAudioStream)==null?void 0:l.audioTrack)==null?void 0:p.id)!==this._targetAudioTrack.id&&(this._publishAudioStream=yield Ye(this._targetAudioTrack),this.previewStream?(d=this.previewStream)==null||d.mergeStream(this._publishAudioStream):this._previewStream=yield Ye(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 Qt),e&&this._profileManager.updateProfile(e,t),yield this._profileManager.setVideoProfile(this.originVideoTrack,this._publishVideoStream,this.type===ee.AliRtcSdkStreamTypeScreen)})}get videoProfile(){var e;return(e=this.profileManager)==null?void 0:e.videoProfile}setVideoContentHint(e){this._profileManager||(this._profileManager=new Qt),this._profileManager.setContentHint(this.originVideoTrack,e)}updateAudioProfile(e){return S(this,null,function*(){this._profileManager||(this._profileManager=new Qt),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 Ue=(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))(Ue||{}),kr=Object.defineProperty,Or=Object.getOwnPropertyDescriptor,St=(i,s,e,t)=>{for(var r=t>1?void 0:t?Or(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 xe extends j{constructor(e){super();c(this,"pluginManager");c(this,"publishingCameraVideoStream");c(this,"publishingScreenVideoStream");c(this,"cameraStreamInfo",new Hi(ee.AliRtcSdkStreamTypeCapture));c(this,"screenStreamInfo",new Hi(ee.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(!r.isSupported("6.11.1")){console.warn(`${r.name} is not supported!!!`),r.emit("unsupported");return}try{yield r.init()}catch(a){r.emit("error",E.fromError(a,Ue.AliRtcPluginErrorInitError))}r.streamType===ee.AliRtcSdkStreamTypeCapture&&(this.cameraStreamInfo.addPlugin(r),yield this.cameraStreamInfo.process(this.streamInfos)),r.streamType===ee.AliRtcSdkStreamTypeScreen&&(this.screenStreamInfo.addPlugin(r),yield this.screenStreamInfo.process(this.streamInfos)),this.emit("publishupdate")});this.cameraStreamInfo.updateVideoProfile(Ui,ze),this.cameraStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({video:!0}),this.emit("trackended",Ce.VideoTrackEnded)})),this.cameraStreamInfo.on("audiotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({audio:!0}),this.emit("trackended",Ce.AudioTrackEnded)})),this.screenStreamInfo.updateVideoProfile(xi,Je),this.screenStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({screen:!0}),this.emit("trackended",Ce.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}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 y.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 y.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=mr(e);let l;if(h){if(o===!0&&this.cameraStreamInfo.cameraVideoConstraints?(yield this.setAvailableCameraDeviceId(),o=x({},this.cameraStreamInfo.cameraVideoConstraints)):typeof o=="object"&&(yield this.setAvailableCameraDeviceId(),o=x(x({},o),this.cameraStreamInfo.cameraVideoConstraints)),u===void 0&&this.audioCaptureDisabled?u=!1:u&&(u===!0&&this.cameraStreamInfo.micAudioConstraints?(yield this.setAvailableMicrophoneDeviceId(),u=x({},this.cameraStreamInfo.micAudioConstraints)):typeof u=="object"&&(yield this.setAvailableMicrophoneDeviceId(),u=x(x({},u),this.cameraStreamInfo.micAudioConstraints)),this._audioCaptureDisabled=!1),l=yield y.AliRTS.createStream({audio:u,video:o,screen:t,custom:!!r,mediaStream:r,skipProfile:!0}),t)yield this.screenStreamInfo.updateSource(l,fe.Screen,ot.Screen),yield this.setScreenProfile(n),this.setScreenContentHint(),this.publishingScreenVideoStream=void 0;else if(yield this.cameraStreamInfo.updateSource(l,fe.Camera,ot.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 y.AliRTS.SystenUtil.isIos&&y.AliRTS.SystenUtil.compareVersion("15.1")&&!y.AliRTS.SystenUtil.compareVersion("15.2")&&(yield mt(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 E(R.ERROR_PUBLISH_FAIL,"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=A.Screen,d.addTrack((p=o.screen)==null?void 0:p.videoTrack),t=!0),e=yield Fi(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=x(x({},(t=this.cameraStreamInfo.cameraVideoConstraints)!=null?t:{}),e)}setMicAudioConstraints(e){var t;this.cameraStreamInfo.micAudioConstraints=x(x({},(t=this.cameraStreamInfo.micAudioConstraints)!=null?t:{}),e)}}c(xe,"logName","LocalStreamManager"),St([v()],xe.prototype,"createLocalStream",1),St([v()],xe.prototype,"stopLocalStream",1),St([v()],xe.prototype,"createHTTPPublishStream",1),St([v()],xe.prototype,"stop",1);var Mr=Object.defineProperty,Nr=Object.getOwnPropertyDescriptor,ge=(i,s,e,t)=>{for(var r=t>1?void 0:t?Nr(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 he 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 Tr,this.localStreamManager=new xe(this.pluginManager),this.rtsManager=new ae(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=>{_.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=Zt(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;if(!t)return(n=this.userMap[e])==null?void 0:n.setViewConfig(null,r);const a=Zt(t);a.length!==0&&a.forEach(o=>{var u,h;(u=this.publisher)==null||u.resetElement(o),Object.values(this.usersViewMap).forEach(({cameraViews:l=[],screenViews:p=[]})=>{l.includes(o)&&l.splice(l.indexOf(o),1),p.includes(o)&&p.splice(p.indexOf(o),1)}),(h=this.userMap[e])==null||h.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 $({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(U.PullStreamStats,this.onRemoteStatReport.bind(this)),r.on(U.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.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===U.MuteAudio?this.emit("userAudioMuted",t,!0):e===U.UnmuteAudio?this.emit("userAudioMuted",t,!1):e===U.MuteVideo?this.emit("userVideoMuted",t,!0):e===U.UnmuteVideo?this.emit("userVideoMuted",t,!1):e===U.MuteScreen?this.emit("userScreenMuted",t,!0):e===U.UnmuteScreen&&this.emit("userScreenMuted",t,!1)}onRemoteStatReport(e,t,r){this.emit(U.PullStreamStats,e,t,r)}onSubscribeExceeds(e,t){this.emit(U.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:Wt.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 E(R.ERROR_REMOTE_USER_NOT_FOUND);r.setWantSubAudio(t),t?r.updateSubscribe():r.stopSubscribe({audio:!0})}updateVideoWant(e,t){const r=this.userMap[e];if(!r)throw new E(R.ERROR_REMOTE_USER_NOT_FOUND);r.setWantSubVideo(t),t?r.updateSubscribe():r.stopSubscribe({video:!0})}updateScreenWant(e,t){const r=this.userMap[e];if(!r)throw new E(R.ERROR_REMOTE_USER_NOT_FOUND);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=x(x({},this.authInfo),e)),e.userId&&((t=this.self)==null||t.refreshUserInfo(e.userId))}setEnableMediaExtensionMsg(e){this.rtsManager.setEncodedInsertableStreams(e)}}c(he,"logName","UserManager"),ge([v()],he.prototype,"init",1),ge([v()],he.prototype,"clear",1),ge([v()],he.prototype,"addUser",1),ge([v()],he.prototype,"removeLeftUser",1),ge([v()],he.prototype,"updateUsers",1),ge([v()],he.prototype,"updateAudioWant",1),ge([v()],he.prototype,"updateVideoWant",1),ge([v()],he.prototype,"updateScreenWant",1),ge([v()],he.prototype,"stopIndication",1),ge([v()],he.prototype,"startIndication",1),ge([v()],he.prototype,"enableAudioVolumeIndication",1);const ei=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 Vr{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=er[s],n={appid:t.appId,userid:t.userId,channelid:t.channelId,timestamp:t.timestamp,token:t.token,requestid:_e.createCallid(),tokensid:!1,session:(h=t.callid)!=null?h:_e.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 Error(l.statusText)):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 ei(s.split("?")[0]),r=ce.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=ce.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 ei(s.split("?")[0]),r=ce.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=ce.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 ei(s.split("?")[0]),t=ce.MPU_TASK_TRANSACTION_STOP,r=new dt().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=ce.MPU_TASK_TRANSACTION_STOP,t=new dt().toJson(e,this.authInfo,s);return this.doRequest(e,JSON.stringify(t))}refreshAuthInfo(s){this.authInfo&&this.setAuthInfo(x(x({},this.authInfo),s))}}var Wi=(i,s,e)=>{if(!s.has(i))throw TypeError("Cannot "+e)},ft=(i,s,e)=>(Wi(i,s,"read from private field"),e?e.call(i):s.get(i)),ti=(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)},ii=(i,s,e,t)=>(Wi(i,s,"write to private field"),t?t.call(i,e):s.set(i,e),e),Dr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},w={},ke={};const Ur="SLS_CLIENT";var ji=(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))(ji||{}),Gi=(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))(Gi||{});const xr={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},Fr="sls-trace-uid";var qi=(i=>(i.OK="OK",i.ERROR="ERROR",i.UNSET="UNSET",i))(qi||{});ke.InternalPlugin=Gi,ke.InternalPluginPriority=xr,ke.OTStatusCode=qi,ke.SLS_CLIENT_NAME=Ur,ke.SLS_TRACE_UID_KEY=Fr,ke.WebEventType=ji;var me=ke;function si(i,s,e){Object.defineProperty(i,s,{writable:!0,enumerable:!0,configurable:!0,value:e})}function Br(i,s,e,t){t?t(()=>{si(i,s,e)}):si(i,s,e)}class Hr{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 Ze(i,s,e){try{return i.apply(s,e)}catch(t){return}}function Wr(i){return function(){return Ze(i,this,arguments)}}let jr=!1;function Gr(){return jr}function $i(...i){}var qr=Object.defineProperty,$r=Object.defineProperties,Kr=Object.getOwnPropertyDescriptors,Ki=Object.getOwnPropertySymbols,zr=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,zi=(i,s,e)=>s in i?qr(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Yr=(i,s)=>{for(var e in s||(s={}))zr.call(s,e)&&zi(i,e,s[e]);if(Ki)for(var e of Ki(s))Jr.call(s,e)&&zi(i,e,s[e]);return i},Xr=(i,s)=>$r(i,Kr(s));const Ji=1e3,Yi=60*Ji,Xi=60*Yi,Zi=24*Xi,Qi=365*Zi,Zr=1024,es="0.1.0";function Qr(){}function ts(i){return typeof i=="number"}function ea(i){return Object.prototype.toString.call(i)==="[object String]"}function ta(i){return Object.prototype.toString.call(i)==="[object Error]"}function is(i,s){return+i.toFixed(s)}function ia(i,s){return i.indexOf(s)!==-1}function sa(i,s){return i==null?s:!!i}function bt(i){return i?(parseInt(i,10)^Math.random()*16>>parseInt(i,10)/4).toString(16):`10000000-1000-4000-8000-${1e11}`.replace(/[018]/g,bt)}function ss(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 ra(i){return i!==0&&Math.random()<=i}function Rt(i,s){return(...e)=>{try{return i(...e)}catch(t){console.error(s,t)}}}function rs(i){return"https://"+i.project+"."+i.host+"/logstores/"+i.logstore+"/track"}function aa(i,s){return s?i.includes(rs(s)):i.includes("/track?APIVersion=0.6.0")}const as=/^(?:([^:\/?#]+):\/\/)?((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i;function na(i){try{return decodeURIComponent(i)}catch(s){return unescape(i)}}function oa(i){return typeof i=="string"&&as.test(i)}function ca(i){var s=na(i||"").match(as);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 ua(i,s,e,t){const r={url:i,method:s,status_code:e};return t==null?r:Xr(Yr({},r),{host:t.host,scheme:t.protocol})}function ha(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 la(i,s,e){return i===!1?!1:i===!0||i==="error"&&!e?!0:typeof i=="function"?Rt(i,"call shouldTrackBody failed")(s):!1}function da(i){return{relative:i,timeStamp:ns(i)}}function ns(i){const s=Date.now()-performance.now();return s>Qe()?Math.round(s+i):cs(i)}function pa(){return Math.round(Date.now()-(Qe()+performance.now()))}function ga(i){return ts(i)?is(i*1e6,0):i}function ri(){return Date.now()}function os(){return performance.now()}function ma(){return{relative:os(),timeStamp:ri()}}function Sa(){return{relative:0,timeStamp:Qe()}}function fa(i,s){return s-i}function ba(i){return i-Qe()}function cs(i){return Math.round(Qe()+i)}function Ra(i){return i<Qi}let vt;function Qe(){return vt===void 0&&(vt=performance.timing.navigationStart),vt}function va(){vt=void 0}const Oe="?";function et(i,s){let e;const t=s===void 0?0:+s;try{if(e=Ia(i),e)return e}catch(r){}try{if(e=_a(i),e)return e}catch(r){}try{if(e=Aa(i),e)return e}catch(r){}try{if(e=us(i,t+1),e)return e}catch(r){}return{message:ne(i,"message"),name:ne(i,"name"),stack:[]}}function _a(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 g=0,m=u.length;g<m;g+=1){if(e.exec(u[g])){p=e.exec(u[g]);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]||Oe,line:p[3]?+p[3]:void 0,url:f?void 0:p[2]}}else if(r.exec(u[g]))p=r.exec(u[g]),d={args:[],column:p[4]?+p[4]:void 0,func:p[1]||Oe,line:+p[3],url:p[2]};else if(t.exec(u[g]))p=t.exec(u[g]),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):g===0&&!p[5]&&!Ta(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]||Oe,line:p[4]?+p[4]:void 0,url:p[3]};else continue;!d.func&&d.line&&(d.func=Oe),h.push(d)}if(h.length)return{stack:h,message:ne(i,"message"),name:ne(i,"name")}}function Ia(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=Oe),u.context=[r[o+1]],a.push(u))}if(a.length)return{stack:a,message:ne(i,"message"),name:ne(i,"name")}}function Aa(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)Ea(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=Oe),p.context=[e[l+1]],n.push(p))}if(n.length)return{stack:n,message:e[0],name:ne(i,"name")}}function wa(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 us(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=us.caller;h&&!a;h=h.caller)h!==et&&(o={args:[],column:void 0,func:Oe,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 wa(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 Ea(i,s){return Object.prototype.hasOwnProperty.call(i,s)}function Ta(i){return typeof i>"u"}function hs(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 ai(i,s,{before:e,after:t}){return hs(i,s,r=>function(){const a=arguments;let n;return e&&Ze(e,this,a),typeof r=="function"&&(n=r.apply(this,a)),t&&Ze(t,this,a),n})}const ya=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function La(i){const{stop:s}=Pa(i),{stop:e}=Ca(i);return{stop:()=>{s(),e()}}}function Pa(i){return ai(window,"onerror",{before(s,e,t,r,a){let n;if(a)n=et(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=ya.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 Ca(i){return ai(window,"onunhandledrejection",{before(s){const e=s.reason||"Empty reason",t=et(e);i(t,e)}})}function ls(i){return`${i.name||"Error"}: ${i.message}`}function ds(i){return i.filter(s=>s.url==null||!s.url.includes("sls-rum.js"))}function ni(i){let s=ls(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 ka(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:bt()};i!=null&&i.stack&&t&&(i.stack=ds(i.stack));const a=(r=i==null?void 0:i.stack)==null?void 0:r[0];return{message:encodeURIComponent(i.message||"Empty message"),stacktrace:ni(i),type:i.name,col:a?a.column:void 0,line:a?a.line:void 0,file:encodeURIComponent(a&&a.url?a.url:""),id:bt()}}function Oa(){const i=new Error;let s;return Ze(()=>{const e=et(i);e!=null&&e.stack&&(e.stack=ds(e.stack)),s=ni(e)}),s}const Ma=8,Na=16,oi="b3",ci="traceparent",ui="uber-trace-id",_t=Array(32);function ps(i){for(let s=0;s<i*2;s++)_t[s]=Math.floor(Math.random()*16)+48,_t[s]>=58&&(_t[s]+=39);return String.fromCharCode.apply(null,_t.slice(0,i*2))}function gs(){return ps(Na)}function hi(){return ps(Ma)}function It(i,s){return`${i}-${s}-1`}function At(i,s){return`00-${i}-${s}-01`}function wt(i,s){return`${i}:${s}:0:1`}const Et={b3:{name:oi,getter:It},traceparent:{name:ci,getter:At},uber:{name:ui,getter:wt}};function Va(i,s,e,t){var r;const a=t!=null?t:{};a.headers=(r=a.headers)!=null?r:{},a.headers[oi]=It(i,s),a.headers[ci]=At(i,s),a.headers[ui]=wt(i,s);try{if(e)for(const[n,o]of Object.entries(e))Et[o]&&(a.headers[n]=Et[o].getter(i,s))}catch(n){}return a}function Da(i,s,e,t){i.setRequestHeader(oi,It(s,e)),i.setRequestHeader(ci,At(s,e)),i.setRequestHeader(ui,wt(s,e));try{if(t)for(const[r,a]of Object.entries(t))Et[a]&&i.setRequestHeader(r,Et[a].getter(s,e))}catch(r){}}function tt(i,s,e){i!=null&&Object.keys(i).map(t=>{e==null||e==""?s[t]=i[t]:s[`${e}.${t}`]=i[t]})}var Ua=Object.defineProperty,xa=Object.defineProperties,Fa=Object.getOwnPropertyDescriptors,ms=Object.getOwnPropertySymbols,Ba=Object.prototype.hasOwnProperty,Ha=Object.prototype.propertyIsEnumerable,Ss=(i,s,e)=>s in i?Ua(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Wa=(i,s)=>{for(var e in s||(s={}))Ba.call(s,e)&&Ss(i,e,s[e]);if(ms)for(var e of ms(s))Ha.call(s,e)&&Ss(i,e,s[e]);return i},ja=(i,s)=>xa(i,Fa(s));function Ga(){return{name:me.InternalPlugin.BASE_TRANSFORM,run:function(){this.subscribe("*",(i,s)=>{const{otBase:e,extra:t}=i;e.attribute=ja(Wa({},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),tt(this.options.custom,e.attribute,"custom"),tt({env:this.options.env,version:this.options.version},e.attribute),tt({sdk_version:es,workspace:this.options.workspace},e.resource);const r={otBase:e,extra:t};$i(me.InternalPlugin.BASE_TRANSFORM,r),s(r)},me.InternalPluginPriority[me.InternalPlugin.BASE_TRANSFORM])}}}function qa(){return{name:me.InternalPlugin.LOG_SEND,run:function(){}}}function fs(i,s,e){if(s<0)return;const t=a=>{fs(i,s-1,a)},r=i[s];Rt(()=>{r.callback.call(void 0,e,t)},"plugin notify run error")()}class $a{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:[];fs(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 Ka(){const i=gs();let s=hi();return{getSessionId:()=>i,getPageId:()=>s,refreshPageId:()=>{s=hi()}}}var za=Object.defineProperty,Ja=Object.defineProperties,Ya=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,Xa=Object.prototype.hasOwnProperty,Za=Object.prototype.propertyIsEnumerable,Rs=(i,s,e)=>s in i?za(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Qa=(i,s)=>{for(var e in s||(s={}))Xa.call(s,e)&&Rs(i,e,s[e]);if(bs)for(var e of bs(s))Za.call(s,e)&&Rs(i,e,s[e]);return i},en=(i,s)=>Ja(i,Ya(s));const tn=["uid","nickname","env","service","version","custom"];class sn{constructor(s){this.isInit=!1,this.pendingPlugins=[],this.pluginMap={},this.session=Ka();var e,t;this.options=s,this.use(qa()),this.use(Ga()),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=en(Qa({},this.context),{subscribe:(t,r,a)=>{this.sub.subscribe(s.name,t,r,a)},notify:t=>{this.sub.notify(s.name,t)}});Rt(()=>s.run.call(e),`plugin ${s.name} init failed`)()}addLog(s){if(this.isInit){const e={t:me.WebEventType.LOG};tt(s,e,me.WebEventType.LOG);const t={start:ri()*1e3,attribute:e,resource:{}};this.sub.notify(me.InternalPlugin.LOG_SEND,{otBase:t,extra:{}})}else console.error("log should call after start")}setOptions(s){this.isInit?tn.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(me.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(me.SLS_TRACE_UID_KEY)),(s==null||s==="")&&(s=ss())),this.options.uid=s,typeof this.setLocalStorage=="function"&&this.setLocalStorage(me.SLS_TRACE_UID_KEY,s);const e=this.pendingPlugins.map(t=>t==null?void 0:t.name).filter(t=>t!=null);this.sub=new $a(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 rn=Object.defineProperty,vs=Object.getOwnPropertySymbols,an=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable,_s=(i,s,e)=>s in i?rn(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,on=(i,s)=>{for(var e in s||(s={}))an.call(s,e)&&_s(i,e,s[e]);if(vs)for(var e of vs(s))nn.call(s,e)&&_s(i,e,s[e]);return i};function cn(i,s){var e;const t={current:void 0},r=[];let a={};return typeof s=="function"&&(a=(e=s(t))!=null?e:{}),on({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 un{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)}})}}w.ONE_DAY=Zi,w.ONE_HOUR=Xi,w.ONE_KILO_BYTE=Zr,w.ONE_MINUTE=Yi,w.ONE_SECOND=Ji,w.ONE_YEAR=Qi,w.Observable=Hr,w.SDK_VERSION=es,w.SLSClient=sn,w.Subscribe=un,w.assembleOTAttribute=tt,w.buildHttpInfo=ua,w.callMonitored=Ze,w.catchUserErrors=Rt,w.clocksNow=ma,w.clocksOrigin=Sa,w.computeStackTrace=et,w.createHandlingStack=Oa,w.currentDrift=pa,w.debugLog=$i,w.defineGlobal=Br,w.defineGlobalValue=si,w.elapsed=fa,w.formatErrorMessage=ls,w.formatUnknownError=ka,w.genUid=ss,w.generateSpanId=hi,w.generateTraceId=gs,w.generateUUID=bt,w.getB3Header=It,w.getConsoleLogStatus=Gr,w.getCorrectedTimeStamp=ns,w.getJaegerTraceHeaderr=wt,w.getRelativeTime=ba,w.getTimeStamp=cs,w.getTrackUrl=rs,w.getW3CTraceHeader=At,w.includes=ia,w.instrumentMethod=hs,w.instrumentMethodAndCallOriginal=ai,w.isError=ta,w.isInternalUrl=aa,w.isNumber=ts,w.isString=ea,w.isURL=oa,w.looksLikeRelativeTime=Ra,w.makeWebPublicApi=cn,w.matchCondition=ha,w.matchSample=ra,w.matchWithDefault=sa,w.monitor=Wr,w.noop=Qr,w.parseUri=ca,w.patchHeaderOnRequest=Va,w.patchHeaderOnXhr=Da,w.relativeNow=os,w.relativeToClocks=da,w.resetNavigationStart=va,w.round=is,w.shouldTrackBody=la,w.startUnhandledErrorCollection=La,w.timeStampNow=ri,w.toServerDuration=ga,w.toStackTraceString=ni;var hn=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()}},ln=w,dn=hn;function pn(i,s){return navigator&&navigator.sendBeacon?navigator.sendBeacon(`${i}?APIVersion=0.6.0`,s):!1}function gn(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 mn(i,s){try{pn(i,s)||gn(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 Is extends dn{constructor(s){const e=Object.assign({},s,{installUnloadHook:t=>{window.addEventListener("beforeunload",()=>{t()})},sendPayload:(t,r)=>{mn(t,r)}});super(e)}}ln.defineGlobal(window,"SLS_Tracker",Is);var Sn=Is,Tt={},fn={get exports(){return Tt},set exports(i){Tt=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",g="name",m="type",f="vendor",b="version",M="architecture",H="console",P="mobile",N="tablet",re="smarttv",Te="wearable",Ri="embedded",vi=350,Ot="Amazon",st="Apple",Us="ASUS",xs="BlackBerry",Fe="Browser",Mt="Chrome",zn="Edge",Nt="Firefox",Vt="Google",Fs="Huawei",_i="LG",Ii="Microsoft",Bs="Motorola",Dt="Opera",Ai="Samsung",Hs="Sharp",Ut="Sony",wi="Xiaomi",Ei="Zebra",Ws="Facebook",js="Chromium OS",Gs="Mac OS",Jn=function(D,W){var O={};for(var q in D)W[q]&&W[q].length%2===0?O[q]=W[q].concat(D[q]):O[q]=D[q];return O},xt=function(D){for(var W={},O=0;O<D.length;O++)W[D[O].toUpperCase()]=D[O];return W},qs=function(D,W){return typeof D===l?rt(W).indexOf(rt(D))!==-1:!1},rt=function(D){return D.toLowerCase()},Yn=function(D){return typeof D===l?D.replace(/[^\d\.]/g,a).split(".")[0]:t},Ti=function(D,W){if(typeof D===l)return D=D.replace(/^\s\s*/,a),typeof W===u?D:D.substring(0,vi)},at=function(D,W){for(var O=0,q,ye,ve,B,C,Ae;O<W.length&&!C;){var Li=W[O],zs=W[O+1];for(q=ye=0;q<Li.length&&!C&&Li[q];)if(C=Li[q++].exec(D),C)for(ve=0;ve<zs.length;ve++)Ae=C[++ye],B=zs[ve],typeof B===h&&B.length>0?B.length===2?typeof B[1]==o?this[B[0]]=B[1].call(this,Ae):this[B[0]]=B[1]:B.length===3?typeof B[1]===o&&!(B[1].exec&&B[1].test)?this[B[0]]=Ae?B[1].call(this,Ae,B[2]):t:this[B[0]]=Ae?Ae.replace(B[1],B[2]):t:B.length===4&&(this[B[0]]=Ae?B[3].call(this,Ae.replace(B[1],B[2])):t):this[B]=Ae||t;O+=2}},yi=function(D,W){for(var O in W)if(typeof W[O]===h&&W[O].length>0){for(var q=0;q<W[O].length;q++)if(qs(W[O][q],D))return O===n?t:O}else if(qs(W[O],D))return O===n?t:O;return D},Xn={"1.0":"/8","1.2":"/1","1.3":"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"},$s={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"},Ks={browser:[[/\b(?:crmo|crios)\/([\w\.]+)/i],[b,[g,"Chrome"]],[/edg(?:e|ios|a)?\/([\w\.]+)/i],[b,[g,"Edge"]],[/(opera mini)\/([-\w\.]+)/i,/(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i,/(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i],[g,b],[/opios[\/ ]+([\w\.]+)/i],[b,[g,Dt+" Mini"]],[/\bopr\/([\w\.]+)/i],[b,[g,Dt]],[/(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],[g,b],[/(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i],[b,[g,"UC"+Fe]],[/microm.+\bqbcore\/([\w\.]+)/i,/\bqbcore\/([\w\.]+).+microm/i],[b,[g,"WeChat(Win) Desktop"]],[/micromessenger\/([\w\.]+)/i],[b,[g,"WeChat"]],[/konqueror\/([\w\.]+)/i],[b,[g,"Konqueror"]],[/trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i],[b,[g,"IE"]],[/ya(?:search)?browser\/([\w\.]+)/i],[b,[g,"Yandex"]],[/(avast|avg)\/([\w\.]+)/i],[[g,/(.+)/,"$1 Secure "+Fe],b],[/\bfocus\/([\w\.]+)/i],[b,[g,Nt+" Focus"]],[/\bopt\/([\w\.]+)/i],[b,[g,Dt+" Touch"]],[/coc_coc\w+\/([\w\.]+)/i],[b,[g,"Coc Coc"]],[/dolfin\/([\w\.]+)/i],[b,[g,"Dolphin"]],[/coast\/([\w\.]+)/i],[b,[g,Dt+" Coast"]],[/miuibrowser\/([\w\.]+)/i],[b,[g,"MIUI "+Fe]],[/fxios\/([-\w\.]+)/i],[b,[g,Nt]],[/\bqihu|(qi?ho?o?|360)browser/i],[[g,"360 "+Fe]],[/(oculus|samsung|sailfish|huawei)browser\/([\w\.]+)/i],[[g,/(.+)/,"$1 "+Fe],b],[/(comodo_dragon)\/([\w\.]+)/i],[[g,/_/g," "],b],[/(electron)\/([\w\.]+) safari/i,/(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i,/m?(qqbrowser|baiduboxapp|2345Explorer)[\/ ]?([\w\.]+)/i],[g,b],[/(metasr)[\/ ]?([\w\.]+)/i,/(lbbrowser)/i,/\[(linkedin)app\]/i],[g],[/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i],[[g,Ws],b],[/(kakao(?:talk|story))[\/ ]([\w\.]+)/i,/(naver)\(.*?(\d+\.[\w\.]+).*\)/i,/safari (line)\/([\w\.]+)/i,/\b(line)\/([\w\.]+)\/iab/i,/(chromium|instagram)[\/ ]([-\w\.]+)/i],[g,b],[/\bgsa\/([\w\.]+) .*safari\//i],[b,[g,"GSA"]],[/musical_ly(?:.+app_?version\/|_)([\w\.]+)/i],[b,[g,"TikTok"]],[/headlesschrome(?:\/([\w\.]+)| )/i],[b,[g,Mt+" Headless"]],[/ wv\).+(chrome)\/([\w\.]+)/i],[[g,Mt+" WebView"],b],[/droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i],[b,[g,"Android "+Fe]],[/(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i],[g,b],[/version\/([\w\.\,]+) .*mobile\/\w+ (safari)/i],[b,[g,"Mobile Safari"]],[/version\/([\w(\.|\,)]+) .*(mobile ?safari|safari)/i],[b,g],[/webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i],[g,[b,yi,Xn]],[/(webkit|khtml)\/([\w\.]+)/i],[g,b],[/(navigator|netscape\d?)\/([-\w\.]+)/i],[[g,"Netscape"],b],[/mobile vr; rv:([\w\.]+)\).+firefox/i],[b,[g,Nt+" 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],[g,b],[/(cobalt)\/([\w\.]+)/i],[g,[b,/master.|lts./,""]]],cpu:[[/(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i],[[M,"amd64"]],[/(ia32(?=;))/i],[[M,rt]],[/((?:i[346]|x)86)[;\)]/i],[[M,"ia32"]],[/\b(aarch64|arm(v?8e?l?|_?64))\b/i],[[M,"arm64"]],[/\b(arm(?:v[67])?ht?n?[fl]p?)\b/i],[[M,"armhf"]],[/windows (ce|mobile); ppc;/i],[[M,"arm"]],[/((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i],[[M,/ower/,a,rt]],[/(sun4\w)[;\)]/i],[[M,"sparc"]],[/((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i],[[M,rt]]],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,Ai],[m,N]],[/\b((?:s[cgp]h|gt|sm)-\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,/samsung[- ]([-\w]+)/i,/sec-(sgh\w+)/i],[d,[f,Ai],[m,P]],[/(?:\/|\()(ip(?:hone|od)[\w, ]*)(?:\/|;)/i],[d,[f,st],[m,P]],[/\((ipad);[-\w\),; ]+apple/i,/applecoremedia\/[\w\.]+ \((ipad)/i,/\b(ipad)\d\d?,\d\d?[;\]].+ios/i],[d,[f,st],[m,N]],[/(macintosh);/i],[d,[f,st]],[/\b(sh-?[altvz]?\d\d[a-ekm]?)/i],[d,[f,Hs],[m,P]],[/\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i],[d,[f,Fs],[m,N]],[/(?:huawei|honor)([-\w ]+)[;\)]/i,/\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i],[d,[f,Fs],[m,P]],[/\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,wi],[m,P]],[/\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i],[[d,/_/g," "],[f,wi],[m,N]],[/; (\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"],[m,P]],[/vivo (\w+)(?: bui|\))/i,/\b(v[12]\d{3}\w?[at])(?: bui|;)/i],[d,[f,"Vivo"],[m,P]],[/\b(rmx[12]\d{3})(?: bui|;|\))/i],[d,[f,"Realme"],[m,P]],[/\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,Bs],[m,P]],[/\b(mz60\d|xoom[2 ]{0,2}) build\//i],[d,[f,Bs],[m,N]],[/((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i],[d,[f,_i],[m,N]],[/(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,/\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,/\blg-?([\d\w]+) bui/i],[d,[f,_i],[m,P]],[/(ideatab[-\w ]+)/i,/lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i],[d,[f,"Lenovo"],[m,N]],[/(?:maemo|nokia).*(n900|lumia \d+)/i,/nokia[-_ ]?([-\w\.]*)/i],[[d,/_/g," "],[f,"Nokia"],[m,P]],[/(pixel c)\b/i],[d,[f,Vt],[m,N]],[/droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i],[d,[f,Vt],[m,P]],[/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,Ut],[m,P]],[/sony tablet [ps]/i,/\b(?:sony)?sgp\w+(?: bui|\))/i],[[d,"Xperia Tablet"],[f,Ut],[m,N]],[/ (kb2005|in20[12]5|be20[12][59])\b/i,/(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i],[d,[f,"OnePlus"],[m,P]],[/(alexa)webm/i,/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i,/(kf[a-z]+)( bui|\)).+silk\//i],[d,[f,Ot],[m,N]],[/((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i],[[d,/(.+)/g,"Fire Phone $1"],[f,Ot],[m,P]],[/(playbook);[-\w\),; ]+(rim)/i],[d,f,[m,N]],[/\b((?:bb[a-f]|st[hv])100-\d)/i,/\(bb10; (\w+)/i],[d,[f,xs],[m,P]],[/(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i],[d,[f,Us],[m,N]],[/ (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i],[d,[f,Us],[m,P]],[/(nexus 9)/i],[d,[f,"HTC"],[m,N]],[/(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i,/(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,/(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i],[f,[d,/_/g," "],[m,P]],[/droid.+; ([ab][1-7]-?[0178a]\d\d?)/i],[d,[f,"Acer"],[m,N]],[/droid.+; (m[1-5] note) bui/i,/\bmz-([-\w]{2,})/i],[d,[f,"Meizu"],[m,P]],[/(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,[m,P]],[/(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,[m,N]],[/(surface duo)/i],[d,[f,Ii],[m,N]],[/droid [\d\.]+; (fp\du?)(?: b|\))/i],[d,[f,"Fairphone"],[m,P]],[/(u304aa)/i],[d,[f,"AT&T"],[m,P]],[/\bsie-(\w*)/i],[d,[f,"Siemens"],[m,P]],[/\b(rct\w+) b/i],[d,[f,"RCA"],[m,N]],[/\b(venue[\d ]{2,7}) b/i],[d,[f,"Dell"],[m,N]],[/\b(q(?:mv|ta)\w+) b/i],[d,[f,"Verizon"],[m,N]],[/\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i],[d,[f,"Barnes & Noble"],[m,N]],[/\b(tm\d{3}\w+) b/i],[d,[f,"NuVision"],[m,N]],[/\b(k88) b/i],[d,[f,"ZTE"],[m,N]],[/\b(nx\d{3}j) b/i],[d,[f,"ZTE"],[m,P]],[/\b(gen\d{3}) b.+49h/i],[d,[f,"Swiss"],[m,P]],[/\b(zur\d{3}) b/i],[d,[f,"Swiss"],[m,N]],[/\b((zeki)?tb.*\b) b/i],[d,[f,"Zeki"],[m,N]],[/\b([yr]\d{2}) b/i,/\b(dragon[- ]+touch |dt)(\w{5}) b/i],[[f,"Dragon Touch"],d,[m,N]],[/\b(ns-?\w{0,9}) b/i],[d,[f,"Insignia"],[m,N]],[/\b((nxa|next)-?\w{0,9}) b/i],[d,[f,"NextBook"],[m,N]],[/\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i],[[f,"Voice"],d,[m,P]],[/\b(lvtel\-)?(v1[12]) b/i],[[f,"LvTel"],d,[m,P]],[/\b(ph-1) /i],[d,[f,"Essential"],[m,P]],[/\b(v(100md|700na|7011|917g).*\b) b/i],[d,[f,"Envizen"],[m,N]],[/\b(trio[-\w\. ]+) b/i],[d,[f,"MachSpeed"],[m,N]],[/\btu_(1491) b/i],[d,[f,"Rotor"],[m,N]],[/(shield[\w ]+) b/i],[d,[f,"Nvidia"],[m,N]],[/(sprint) (\w+)/i],[f,d,[m,P]],[/(kin\.[onetw]{3})/i],[[d,/\./g," "],[f,Ii],[m,P]],[/droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i],[d,[f,Ei],[m,N]],[/droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i],[d,[f,Ei],[m,P]],[/smart-tv.+(samsung)/i],[f,[m,re]],[/hbbtv.+maple;(\d+)/i],[[d,/^/,"SmartTV"],[f,Ai],[m,re]],[/(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i],[[f,_i],[m,re]],[/(apple) ?tv/i],[f,[d,st+" TV"],[m,re]],[/crkey/i],[[d,Mt+"cast"],[f,Vt],[m,re]],[/droid.+aft(\w)( bui|\))/i],[d,[f,Ot],[m,re]],[/\(dtv[\);].+(aquos)/i,/(aquos-tv[\w ]+)\)/i],[d,[f,Hs],[m,re]],[/(bravia[\w ]+)( bui|\))/i],[d,[f,Ut],[m,re]],[/(mitv-\w{5}) bui/i],[d,[f,wi],[m,re]],[/Hbbtv.*(technisat) (.*);/i],[f,d,[m,re]],[/\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i,/hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i],[[f,Ti],[d,Ti],[m,re]],[/\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i],[[m,re]],[/(ouya)/i,/(nintendo) ([wids3utch]+)/i],[f,d,[m,H]],[/droid.+; (shield) bui/i],[d,[f,"Nvidia"],[m,H]],[/(playstation [345portablevi]+)/i],[d,[f,Ut],[m,H]],[/\b(xbox(?: one)?(?!; xbox))[\); ]/i],[d,[f,Ii],[m,H]],[/((pebble))app/i],[f,d,[m,Te]],[/(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i],[d,[f,st],[m,Te]],[/droid.+; (glass) \d/i],[d,[f,Vt],[m,Te]],[/droid.+; (wt63?0{2,3})\)/i],[d,[f,Ei],[m,Te]],[/(quest( 2| pro)?)/i],[d,[f,Ws],[m,Te]],[/(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i],[f,[m,Ri]],[/(aeobc)\b/i],[d,[f,Ot],[m,Ri]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+? mobile safari/i],[d,[m,P]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i],[d,[m,N]],[/\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i],[[m,N]],[/(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i],[[m,P]],[/(android[-\w\. ]{0,9});.+buil/i],[d,[f,"Generic"]]],engine:[[/windows.+ edge\/([\w\.]+)/i],[b,[g,zn+"HTML"]],[/webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i],[b,[g,"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],[g,b],[/rv\:([\w\.]{1,9})\b.+(gecko)/i],[b,g]],os:[[/microsoft (windows) (vista|xp)/i],[g,b],[/(windows) nt 6\.2; (arm)/i,/(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i,/(windows)[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i],[g,[b,yi,$s]],[/(win(?=3|9|n)|win 9x )([nt\d\.]+)/i],[[g,"Windows"],[b,yi,$s]],[/ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i,/ios;fbsv\/([\d\.]+)/i,/cfnetwork\/.+darwin/i],[[b,/_/g,"."],[g,"iOS"]],[/(mac os x) ?([\w\. ]*)/i,/(macintosh|mac_powerpc\b)(?!.+haiku)/i],[[g,Gs],[b,/_/g,"."]],[/droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i],[b,g],[/(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,/(blackberry)\w*\/([\w\.]*)/i,/(tizen|kaios)[\/ ]([\w\.]+)/i,/\((series40);/i],[g,b],[/\(bb(10);/i],[b,[g,xs]],[/(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i],[b,[g,"Symbian"]],[/mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i],[b,[g,Nt+" OS"]],[/web0s;.+rt(tv)/i,/\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i],[b,[g,"webOS"]],[/watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i],[b,[g,"watchOS"]],[/crkey\/([\d\.]+)/i],[b,[g,Mt+"cast"]],[/(cros) [\w]+(?:\)| ([\w\.]+)\b)/i],[[g,js],b],[/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],[g,b],[/(sunos) ?([\w\.\d]*)/i],[[g,"Solaris"],b],[/((?:open)?solaris)[-\/ ]?([\w\.]*)/i,/(aix) ((\d)(?=\.|\)| )[\w\.])*/i,/\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux|serenityos)/i,/(unix) ?([\w\.]*)/i],[g,b]]},Se=function(D,W){if(typeof D===h&&(W=D,D=t),!(this instanceof Se))return new Se(D,W).getResult();var O=typeof e!==u&&e.navigator?e.navigator:t,q=D||(O&&O.userAgent?O.userAgent:a),ye=O&&O.userAgentData?O.userAgentData:t,ve=W?Jn(Ks,W):Ks,B=O&&O.userAgent==q;return this.getBrowser=function(){var C={};return C[g]=t,C[b]=t,at.call(C,q,ve.browser),C[p]=Yn(C[b]),B&&O&&O.brave&&typeof O.brave.isBrave==o&&(C[g]="Brave"),C},this.getCPU=function(){var C={};return C[M]=t,at.call(C,q,ve.cpu),C},this.getDevice=function(){var C={};return C[f]=t,C[d]=t,C[m]=t,at.call(C,q,ve.device),B&&!C[m]&&ye&&ye.mobile&&(C[m]=P),B&&C[d]=="Macintosh"&&O&&typeof O.standalone!==u&&O.maxTouchPoints&&O.maxTouchPoints>2&&(C[d]="iPad",C[m]=N),C},this.getEngine=function(){var C={};return C[g]=t,C[b]=t,at.call(C,q,ve.engine),C},this.getOS=function(){var C={};return C[g]=t,C[b]=t,at.call(C,q,ve.os),B&&!C[g]&&ye&&ye.platform!="Unknown"&&(C[g]=ye.platform.replace(/chrome os/i,js).replace(/macos/i,Gs)),C},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(C){return q=typeof C===l&&C.length>vi?Ti(C,vi):C,this},this.setUA(q),this};Se.VERSION=r,Se.BROWSER=xt([g,b,p]),Se.CPU=xt([M]),Se.DEVICE=xt([d,f,m,H,P,re,N,Te,Ri]),Se.ENGINE=Se.OS=xt([g,b]),i.exports&&(s=i.exports=Se),s.UAParser=Se;var Be=typeof e!==u&&(e.jQuery||e.Zepto);if(Be&&!Be.ua){var Ft=new Se;Be.ua=Ft.getResult(),Be.ua.get=function(){return Ft.getUA()},Be.ua.set=function(D){Ft.setUA(D);var W=Ft.getResult();for(var O in W)Be.ua[O]=W[O]}}})(typeof window=="object"?window:Dr)})(fn,Tt);let yt;const bn=new Uint8Array(16);function Rn(){if(!yt&&(yt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!yt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return yt(bn)}const se=[];for(let i=0;i<256;++i)se.push((i+256).toString(16).slice(1));function vn(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 _n=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),As={randomUUID:_n};function In(i,s,e){if(As.randomUUID&&!s&&!i)return As.randomUUID();i=i||{};const t=i.random||(i.rng||Rn)();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 vn(t)}var li={},An={get exports(){return li},set exports(i){li=i}},di={},wn={get exports(){return di},set exports(i){di=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}};wn.exports=s})();var pi={utf8:{stringToBytes:function(i){return pi.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(pi.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("")}}},ws=pi;/*!
1
+ var Xn=Object.defineProperty,Zn=Object.defineProperties;var Qn=Object.getOwnPropertyDescriptors;var Bt=Object.getOwnPropertySymbols,eo=Object.getPrototypeOf,Ys=Object.prototype.hasOwnProperty,Xs=Object.prototype.propertyIsEnumerable,to=Reflect.get;var Ci=(I,y,L)=>y in I?Xn(I,y,{enumerable:!0,configurable:!0,writable:!0,value:L}):I[y]=L,x=(I,y)=>{for(var L in y||(y={}))Ys.call(y,L)&&Ci(I,L,y[L]);if(Bt)for(var L of Bt(y))Xs.call(y,L)&&Ci(I,L,y[L]);return I},He=(I,y)=>Zn(I,Qn(y));var Zs=(I,y)=>{var L={};for(var j in I)Ys.call(I,j)&&y.indexOf(j)<0&&(L[j]=I[j]);if(I!=null&&Bt)for(var j of Bt(I))y.indexOf(j)<0&&Xs.call(I,j)&&(L[j]=I[j]);return L};var c=(I,y,L)=>(Ci(I,typeof y!="symbol"?y+"":y,L),L);var ki=(I,y,L)=>to(eo(I),L,y);var S=(I,y,L)=>new Promise((j,nt)=>{var D=pe=>{try{A(L.next(pe))}catch(fe){nt(fe)}},ie=pe=>{try{A(L.throw(pe))}catch(fe){nt(fe)}},A=pe=>pe.done?j(pe.value):Promise.resolve(pe.value).then(D,ie);A((L=L.apply(I,y)).next())});(function(I,y){typeof exports=="object"&&typeof module!="undefined"?y(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"],y):(I=typeof globalThis!="undefined"?globalThis:I||self,y(I.AliRtcEngine={},I.AliyunRts,I.UserAgentUtil,I.EventEmitter,I.BrowserLogReporter))})(this,function(I,y,L,j,nt){var T;"use strict";var D=(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))(D||{}),ie=(i=>(i.Local="local-device-status-change",i.Remote="remote-device-status-change",i))(ie||{}),A=(i=>(i.Audio="sophon_audio",i.VideoLarge="sophon_video_camera_large",i.VideoSmall="sophon_video_camera_small",i.Screen="sophon_video_screen_share",i))(A||{}),pe=(i=>(i.Audio="rts audio",i.VideoLarge="rts video",i))(pe||{}),fe=(i=>(i[i.Camera=0]="Camera",i[i.Screen=1]="Screen",i[i.Image=2]="Image",i))(fe||{}),ot=(i=>(i[i.Microphone=0]="Microphone",i[i.Screen=1]="Screen",i[i.Mixed=2]="Mixed",i))(ot||{}),ct=(i=>(i.prod="rs.rtn.aliyuncs.com",i.pre="prs.rtn.aliyuncs.com",i))(ct||{});const We="6.11.2",Oi="web";class _e{static getVersionNumber(){let s=We.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 L.Guid.create(8)+"-"+L.Guid.create(4)+"-4"+L.Guid.create(3)+"-"+L.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=ct.prod,{onLine:e}=navigator;if(!e)return!1;try{return yield fetch(`https://${s}/roomserver/v1/ws/version`),!0}catch(t){return!1}})}}var Ht=(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))(Ht||{});class le{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: "+le.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=L.LocalStorage.uuid+"-"+Date.now(),this.traceId="",this.logArray=[],this.enable=!0,this.lastRequestTime=0,this.onTimer()}static toString(s){let e;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=le.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=le.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=le.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=le.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=le.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=le.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=le.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=le.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=le.toString(s[t]);e+=r}return e}}class _{static getLogger(){return this.logger||(this.logger=new le("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("[RTC API]",...s)}static interfaceResult(s,e,t,...r){t?this.getLogger().ar("[RTC APIRES]",s,e,...r):this.getLogger().ae("[RTC APIRES]",s,e,...r)}static event(...s){this.getLogger().ev("[RTC EVENT]",...s)}static debug(...s){this.getLogger().d("[RTC DEBUG]",...s)}static info(...s){this.getLogger().i("[RTC INFO]",...s)}static warn(...s){this.getLogger().w("[RTC WARN]",...s)}static error(...s){this.getLogger().e("[RTC ERR]",...s)}}c(_,"logger");const Qs=i=>S(this,null,function*(){const s=new y.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()&&!y.AliRTS.SystenUtil.isAndroid&&!y.AliRTS.SystenUtil.isIos,e.detail.isSendMediaExtensionMsgSupported=s.checkWebRtcSupport()&&s.checkEncodedTransformSupport(),e});var we=(i=>(i.pre="pre",i.prod="prod",i))(we||{}),Ie=(i=>(i.AliRtcSdkCommunication="communication",i.AliRtcSdkInteractiveLive="interactive_live",i.AliRtcSdkInteractiveWithLowLatencyLive="cdn_live",i))(Ie||{}),Ee=(i=>(i.AliRtcSdkInteractive="interactive",i.AliRtcSdkLive="live",i))(Ee||{}),ee=(i=>(i[i.AliRtcSdkStreamTypeCapture=0]="AliRtcSdkStreamTypeCapture",i[i.AliRtcSdkStreamTypeScreen=1]="AliRtcSdkStreamTypeScreen",i))(ee||{}),be=(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))(be||{}),Z=(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))(Z||{}),F=(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))(F||{}),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||{}),Wt=(i=>(i[i.AliRtcUserOfflineQuit=0]="AliRtcUserOfflineQuit",i[i.AliRtcUserOfflineDropped=1]="AliRtcUserOfflineDropped",i[i.AliRtcUserOfflineBecomeAudience=2]="AliRtcUserOfflineBecomeAudience",i))(Wt||{}),Ne=(i=>(i[i.AliRtcAudioTrackNo=0]="AliRtcAudioTrackNo",i[i.AliRtcAudioTrackMic=1]="AliRtcAudioTrackMic",i[i.AliRtcAudioTrackDual=2]="AliRtcAudioTrackDual",i))(Ne||{}),V=(i=>(i[i.AliRtcVideoTrackNo=0]="AliRtcVideoTrackNo",i[i.AliRtcVideoTrackCamera=1]="AliRtcVideoTrackCamera",i[i.AliRtcVideoTrackScreen=2]="AliRtcVideoTrackScreen",i[i.AliRtcVideoTrackBoth=3]="AliRtcVideoTrackBoth",i))(V||{}),k=(i=>(i[i.AliRtcStatePublishIdle=0]="AliRtcStatePublishIdle",i[i.AliRtcStateNoPublish=1]="AliRtcStateNoPublish",i[i.AliRtcStatePublishing=2]="AliRtcStatePublishing",i[i.AliRtcStatePublished=3]="AliRtcStatePublished",i))(k||{}),K=(i=>(i[i.AliRtcStateSubscribeIdle=0]="AliRtcStateSubscribeIdle",i[i.AliRtcStateNoSubscribe=1]="AliRtcStateNoSubscribe",i[i.AliRtcStateSubscribing=2]="AliRtcStateSubscribing",i[i.AliRtcStateSubscribed=3]="AliRtcStateSubscribed",i))(K||{}),oe=(i=>(i[i.AliRtcVideoStreamTypeNone=0]="AliRtcVideoStreamTypeNone",i[i.AliRtcVideoStreamTypeHigh=1]="AliRtcVideoStreamTypeHigh",i[i.AliRtcVideoStreamTypeLow=2]="AliRtcVideoStreamTypeLow",i))(oe||{}),je=(i=>(i[i.CAMERA_INVALID=-1]="CAMERA_INVALID",i[i.CAMERA_REAR=0]="CAMERA_REAR",i[i.CAMERA_FRONT=1]="CAMERA_FRONT",i))(je||{}),Mi=(i=>(i[i.PRE_PROCESSOR=0]="PRE_PROCESSOR",i[i.POST_PROCESSOR=1]="POST_PROCESSOR",i))(Mi||{}),ut=(i=>(i[i.AUDIO=0]="AUDIO",i[i.VIDEO=1]="VIDEO",i[i.BOTH=2]="BOTH",i))(ut||{});class Ve extends j{constructor(e,t=ee.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 Ge=(i=>(i[i.LiveTranscodingSingle=0]="LiveTranscodingSingle",i[i.LiveTranscodingMix=1]="LiveTranscodingMix",i))(Ge||{}),jt=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingAudio=1]="LiveTranscodingAudio",i[i.LiveTranscodingVideo=2]="LiveTranscodingVideo",i))(jt||{}),Ue=(i=>(i[i.LiveTranscodingCamera=0]="LiveTranscodingCamera",i[i.LiveTranscodingShareScreen=1]="LiveTranscodingShareScreen",i))(Ue||{});const $e={0:"camera",1:"shareScreen"};var Gt=(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))(Gt||{});const er={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 ht=(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))(ht||{}),qe=(i=>(i[i.LiveTranscodingNoBody=0]="LiveTranscodingNoBody",i[i.LiveTranscodingBody=1]="LiveTranscodingBody",i))(qe||{}),Ke=(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))(Ke||{}),$t=(i=>(i[i.LiveTranscodingOrigin=0]="LiveTranscodingOrigin",i[i.LiveTranscodingCrop=1]="LiveTranscodingCrop",i[i.LiveTranscodingFill=2]="LiveTranscodingFill",i))($t||{}),lt=(i=>(i[i.LiveTranscodingNormal=0]="LiveTranscodingNormal",i[i.LiveTranscodingVirtualBackground=1]="LiveTranscodingVirtualBackground",i))(lt||{}),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||{}),Kt=(i=>(i[i.TrascodingPublishTaskStatusStart=0]="TrascodingPublishTaskStatusStart",i[i.TrascodingPublishTaskStatusUpdate=1]="TrascodingPublishTaskStatusUpdate",i[i.TrascodingPublishTaskStatusStop=2]="TrascodingPublishTaskStatusStop",i))(Kt||{}),ce=(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))(ce||{});const tr={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 zt{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",ht.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 Jt=i=>((i&16711680)>>16)+(i&65280)+((i&255)<<16),de=(i=0,s)=>{if(s==0)return 0;let e=i/s;return e<0&&(e=0),e>1&&(e=1),e};class dt{constructor(s,e,t){c(this,"mixMode",Ge.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===ce.MPU_TASK_TRANSACTION_POLLING||s===ce.MPU_TASK_TRANSACTION_LIST||s===ce.MPU_TASK_TRANSACTION_ACKNOWLEDGE)return s===ce.MPU_TASK_TRANSACTION_ACKNOWLEDGE&&(n.messageid=a),n;if(n.taskid=t,s!==ce.MPU_TASK_TRANSACTION_STOP){if(n.mixmode=this.mixMode,r&&(n.streamurl=r),this.mixMode===Ge.LiveTranscodingSingle){const o=this.singleParam;if(o){n.streamtype=o.streamType,o.sourceType===Ue.LiveTranscodingShareScreen?n.sourcetype=$e[o.sourceType]:n.sourcetype=$e[Ue.LiveTranscodingCamera];const u=[];o.userId&&u.push(o.userId),n.subspecusers=u}}else if(s===ce.MPU_TASK_TRANSACTION_START||s===ce.MPU_TASK_TRANSACTION_UPDATE){const o=this.mixParam;if(o){o.taskProfile&&(n.taskprofile=er[o.taskProfile]);const u=o.encodeParam||new zt(1280,720);let h=u.videoWidth,l=u.videoHeight;const p={};Object.keys(u).forEach(g=>{const m=u[g];m>0&&(p[g.toLowerCase()]=m)}),p.lowbitratehighquality=0,n.encodeparam=p,n.backgrounds=o.backgrounds.map(g=>g.toJson(h,l)),n.watermarks=o.watermarks.map(g=>g.toJson(h,l)),n.clockwidgets=o.clockWidgets.map(g=>g.toJson(h,l));const d=o.users.map(g=>g.userId);n.subspecusers=[...new Set(d)],n.layouts=[{audiomixcount:o.users.length,panes:o.users.map((g,m)=>g.toJson(m,h,l,o.mediaProcessMode))}],n.layoutids=["0"],n.cropmode=o.cropMode,n.backgroundcolor=Jt(o.backgroundColor),n.taskmode=o.mediaProcessMode}}}return n}}const Ni=10,Vi=5e3;class ir extends j{constructor(e){super();c(this,"ws");c(this,"socketStatus",0);c(this,"wsUrl","");c(this,"lastConnectStartTime",0);c(this,"maxConnectRetryCount",Ni);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:Ni,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*(){if(this.socketStatus!==0||this.connectRetryCount)if(yield _e.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>=Vi?this.reconnect():window.setTimeout(()=>{this.reconnect()},Vi)}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)}}var te=(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))(te||{});class sr{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=_e.getVersionNumber().toString(),s.header.platform=Oi,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=_e.getVersionNumber().toString(),e.header.platform=Oi,e.data=x(x({},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:L.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 R=(i=>(i[i.ERROR_SIGNALING_CONNECT_FAIL=20100]="ERROR_SIGNALING_CONNECT_FAIL",i[i.ERROR_SIGNALING_RECONNECT_ERROR=20101]="ERROR_SIGNALING_RECONNECT_ERROR",i[i.ERROR_JOIN_SIGNALING_ERROR=20102]="ERROR_JOIN_SIGNALING_ERROR",i[i.ERROR_JOIN_FAIL=20103]="ERROR_JOIN_FAIL",i[i.ERROR_LEAVE_SIGNALING_ERROR=20104]="ERROR_LEAVE_SIGNALING_ERROR",i[i.ERROR_SET_CLIENT_ROLE_FAIL=20200]="ERROR_SET_CLIENT_ROLE_FAIL",i[i.ERROR_LIVE_ROLE_CANNOT_PUB=20201]="ERROR_LIVE_ROLE_CANNOT_PUB",i[i.ERROR_SET_CHANNEL_PROFILE_FAIL=20202]="ERROR_SET_CHANNEL_PROFILE_FAIL",i[i.ERROR_SET_AUDIO_ONLY_FAIL=20203]="ERROR_SET_AUDIO_ONLY_FAIL",i[i.ERROR_REFRESH_PUSH_URL_FAIL=20300]="ERROR_REFRESH_PUSH_URL_FAIL",i[i.ERROR_PUBLISH_SIGNALING_ERROR=20400]="ERROR_PUBLISH_SIGNALING_ERROR",i[i.ERROR_PUBLISH_NO_PUBLISHER_FAIL=20401]="ERROR_PUBLISH_NO_PUBLISHER_FAIL",i[i.ERROR_PUBLISH_FAIL=20402]="ERROR_PUBLISH_FAIL",i[i.ERROR_PUBLISH_ADD_FAIL=20403]="ERROR_PUBLISH_ADD_FAIL",i[i.ERROR_PUBLISH_STOP_FAIL=20404]="ERROR_PUBLISH_STOP_FAIL",i[i.ERROR_PUBLISH_REPLACE_TRACKS_FAIL=20405]="ERROR_PUBLISH_REPLACE_TRACKS_FAIL",i[i.ERROR_PUBLISH_DELETE_TRACKS_FAIL=20406]="ERROR_PUBLISH_DELETE_TRACKS_FAIL",i[i.ERROR_UNPUBLISH_SIGNALING_ERROR=20407]="ERROR_UNPUBLISH_SIGNALING_ERROR",i[i.ERROR_UNPUBLISH_FAIL=20408]="ERROR_UNPUBLISH_FAIL",i[i.ERROR_PUBLISH_NEEDED=20409]="ERROR_PUBLISH_NEEDED",i[i.ERROR_SUBSCRIBE_FAIL=20500]="ERROR_SUBSCRIBE_FAIL",i[i.ERROR_SUBSCRIBE_ADD_FAIL=20501]="ERROR_SUBSCRIBE_ADD_FAIL",i[i.ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL=20502]="ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL",i[i.ERROR_SUBSCRIBE_STOP_FAIL=20503]="ERROR_SUBSCRIBE_STOP_FAIL",i[i.ERROR_LOCAL_STREAM_NOT_EXIST=20600]="ERROR_LOCAL_STREAM_NOT_EXIST",i[i.ERROR_LOCAL_STREAM_PREVIEW_FAIL=20601]="ERROR_LOCAL_STREAM_PREVIEW_FAIL",i[i.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST=20602]="ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST",i[i.ERROR_LOCAL_STREAM_CREATE_FAIL=20603]="ERROR_LOCAL_STREAM_CREATE_FAIL",i[i.ERROR_LOCAL_STREAM_STOP_FAIL=20604]="ERROR_LOCAL_STREAM_STOP_FAIL",i[i.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL=20605]="ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL",i[i.ERROR_REMOTE_STREAM_PLAY_FAIL=20700]="ERROR_REMOTE_STREAM_PLAY_FAIL",i[i.ERROR_REMOTE_STREAM_STOP_PLAY_FAIL=20701]="ERROR_REMOTE_STREAM_STOP_PLAY_FAIL",i[i.ERROR_NETWORK_ERROR=20800]="ERROR_NETWORK_ERROR",i[i.ERROR_PREVIEW_ELEMENT_INVALID=20900]="ERROR_PREVIEW_ELEMENT_INVALID",i[i.ERROR_SET_VIEW_CONFIG_INVALID=20901]="ERROR_SET_VIEW_CONFIG_INVALID",i[i.ERROR_REMOTE_USER_NOT_FOUND=21e3]="ERROR_REMOTE_USER_NOT_FOUND",i))(R||{});const G={[R.ERROR_SIGNALING_CONNECT_FAIL]:"Signaling connect fail",[R.ERROR_JOIN_SIGNALING_ERROR]:"Join signaling error",[R.ERROR_JOIN_FAIL]:"Join failed",[R.ERROR_LIVE_ROLE_CANNOT_PUB]:"Live role cannot publish",[R.ERROR_SET_CLIENT_ROLE_FAIL]:"Set client role failed",[R.ERROR_SET_CHANNEL_PROFILE_FAIL]:"Set channel profile failed",[R.ERROR_SET_AUDIO_ONLY_FAIL]:"Set audio only mode failed",[R.ERROR_REFRESH_PUSH_URL_FAIL]:"Refresh push url failed",[R.ERROR_PUBLISH_SIGNALING_ERROR]:"Publish signaling error",[R.ERROR_PUBLISH_FAIL]:"Publish failed",[R.ERROR_PUBLISH_NO_PUBLISHER_FAIL]:"Have no publisher",[R.ERROR_PUBLISH_ADD_FAIL]:"PublishAdd failed",[R.ERROR_PUBLISH_STOP_FAIL]:"PublishStop failed",[R.ERROR_PUBLISH_REPLACE_TRACKS_FAIL]:"PublishReplaceTracks failed",[R.ERROR_PUBLISH_DELETE_TRACKS_FAIL]:"PublishDeleteTracks failed",[R.ERROR_UNPUBLISH_FAIL]:"UnPublish failed",[R.ERROR_SUBSCRIBE_FAIL]:"Subscribe failed",[R.ERROR_SUBSCRIBE_ADD_FAIL]:"SubscribeAdd failed",[R.ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL]:"SubscribeDeleteTracks failed",[R.ERROR_SUBSCRIBE_STOP_FAIL]:"SubscribeStop failed",[R.ERROR_REMOTE_STREAM_PLAY_FAIL]:"RemoteStream play failed",[R.ERROR_REMOTE_STREAM_STOP_PLAY_FAIL]:"RemoteStream stop play failed",[R.ERROR_LOCAL_STREAM_NOT_EXIST]:"Have no local stream",[R.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST]:"preview element not exist",[R.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL]:"Set camera direaction by invalid value",[R.ERROR_LOCAL_STREAM_PREVIEW_FAIL]:"LocalStream preview failed",[R.ERROR_NETWORK_ERROR]:"Network Error",[R.ERROR_PREVIEW_ELEMENT_INVALID]:"Preview element invalid",[R.ERROR_SET_VIEW_CONFIG_INVALID]:"Set view config invalid",[R.ERROR_REMOTE_USER_NOT_FOUND]:"Remote user not found"};class E extends Error{constructor(e=0,t="",r){let a=t;!a&&G[e]&&(a=G[e]);super(a);c(this,"_code");c(this,"_extra");this._code=e,this._extra=r}static fromError(e,t=-1,r=""){return new E(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 rr=3e4;class ar 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 sr(e,t),this.channelProfile=r,this.clientRole=a,this.wsClient=new ir(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=x(He(x({},t.data),{sessionid:t.header.sessionid}),e),this.sendPackage(t)}refreshAuthInfo(e){this.authInfo=e,this.packageCreater.refreshAuthInfo(e)}close(){_.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){[te.KEEPALIVE,te.RECONNECT,te.JOINCHANNEL].includes(e.msgtype)||this.packageCache.set(e.tid,e),this.wsClient.send(e)}updateReconnectData(e){this.reconnectData=e}onOpen(){if(_.info("[roomsigcenter] onOpen"),this.isFirstConnect){let e=this.packageCreater.createJoinPackage();e.data.configure={channelprofile:this.channelProfile},(this.channelProfile===Ie.AliRtcSdkInteractiveLive||this.channelProfile===Ie.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){_.error("[roomsigcenter] onMessage err",t,e)}}onError(e){_.error("[roomsigcenter] onError",e),this.isFirstConnect&&this.onConnectFail()}onConnectFail(){_.error("[roomsigcenter] onConnectFail");const e=new E(R.ERROR_SIGNALING_CONNECT_FAIL,G[R.ERROR_SIGNALING_CONNECT_FAIL]);this.isFirstConnect?this.emit("onJoinChannelResult",e):this.emit("onConnectFail",e)}onAuthInvalid(){_.error("[roomsigcenter] onAuthInvalid"),this.isFirstConnect&&this.emit("onAuthInvalid")}onNetworkError(){_.error("[roomsigcenter] onNetworkError");const e=new E(R.ERROR_SIGNALING_CONNECT_FAIL,"Network error, signaling connect failed.");this.emit("onNetworkError",e)}onClose(e){_.info("[roomsigcenter] onClose",e),this.stopKeepAlive()}onKeepAliveRsp(){this.emit("onKeepAliveRsp"),this.checkAlive()}onReconnectStart(){this.emit("onReconnectStart")}onReconnectFail(){this.emit("onReconnectFail",new E(R.ERROR_SIGNALING_RECONNECT_ERROR,""))}checkAlive(){window.clearTimeout(this.aliveChecker),this.aliveChecker=window.setTimeout(()=>{_.info("[roomsigcenter] not alive, reconnect"),this.stopKeepAlive(),this.emit("onReconnectStart"),this.wsClient.reconnect()},rr)}onRecvMessage(e){switch(e.msgtype!==te.KEEPALIVE&&_.info("[roomsigcenter] recv msg "+e.msgtype),e.msgtype){case te.JOINCHANNEL:this.onJoinResult(e);break;case te.KEEPALIVE:this.onKeepAliveRsp();break;case te.PUBLISH:this.onPublishResult(e);break;case te.NOTIFYJOIN:this.onNotifyJoin(e);break;case te.NOTIFYSTATUS:this.onNotifyStatus(e);break;case te.LEAVECHANNEL:this.onLeaveResult(e);break;case te.NOTIFYLEAVE:this.onNotifyLeave(e);break;case te.NOTIFYPUBLISH:this.onNotifyPublish(e);break;case te.STATUSREPORT:this.onStatusReport(e);break;case te.BYE:this.onBye(e);break;case te.ROLEUPDATE:this.onRoleUpdateResult(e);break;case te.REFRESHURL:this.onRefreshUrlResult(e);break;case te.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 E(R.ERROR_SIGNALING_RECONNECT_ERROR,`reconnect fail, 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 v=(i=!1)=>(s,e,t)=>{const r=t.value;return t.value=function(...a){var h;const n=`${i?"__g__":""}${((h=s.constructor)==null?void 0:h.logName)||""}`,o=Date.now();_.interface(n,e,...a);const u=r.apply(this,a);return Promise.resolve(u).then(l=>l).catch(l=>l).then(l=>{_.interfaceResult(n,e,!(l instanceof Error),`${Date.now()-o}ms`,l)}),u},t};var nr=Object.defineProperty,or=Object.getOwnPropertyDescriptor,cr=(i,s,e,t)=>{for(var r=t>1?void 0:t?or(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&&nr(s,e,r),r};class Yt extends j{constructor(e,t,r=we.prod){super();c(this,"messageCenter");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"reconnectData");c(this,"roomServerUri","");_.info("[roomsig] ctor"),this.channelProfile=e,this.clientRole=t,this.reconnectData={role:{channelprofile:e,clientrole:t}};const a=r===we.pre?ct.pre:ct.prod;this.roomServerUri=`wss://${a}/roomserver/v1/ws`}updateReconnectData(e){var t;this.reconnectData=e,(t=this.messageCenter)==null||t.updateReconnectData(this.reconnectData)}reset(){_.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)=>{_.setTraceID(e.channelId+"-"+e.callid),_.info("request gslb .."),this.authInfo=e,this.userName=t,this.messageCenter=new ar(e,t,this.channelProfile,this.clientRole,r),this.initMessageCenter(),this.messageCenter.once("onJoinChannelResult",u=>{var h,l;if(_.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,R.ERROR_JOIN_SIGNALING_ERROR))}),this.messageCenter.once("onAuthInvalid",()=>{this.reset(),n(new E(R.ERROR_JOIN_SIGNALING_ERROR,`${G[R.ERROR_JOIN_SIGNALING_ERROR]} because authentication failed`))}),_.info("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:L.Guid.create(32)};e.role&&(o.tokenrole=e.role),this.messageCenter.start(this.roomServerUri+"?"+_e.queryingParam(o))})})}leave(){return _.info("[roomsig] leave .."),new Promise((e,t)=>{this.messageCenter?(this.messageCenter.on("onLeaveResult",(r,a)=>{_.info("recv leave response "+r),r===200?(this.updateReconnectData(),this.reset(),e({tid:a})):t(this.handleSignalError(r,"",R.ERROR_LEAVE_SIGNALING_ERROR))}),_.info("send leave request"),this.messageCenter.leave()):(_.info("no message center, ok to leave"),e({tid:""}))})}publish(e){return _.info("[roomsig] publish .."),new Promise((t,r)=>{var a;this.messageCenter?(this.messageCenter.once("onPublishResult",(n,o,u)=>{_.info("recv pubish response "+n),n===200?(this.updateReconnectData(He(x({},this.reconnectData),{publish:{users:[e]}})),t({tid:o})):r(this.handleSignalError(n,u,R.ERROR_PUBLISH_SIGNALING_ERROR))}),this.authInfo&&(e.sessionid=(a=this.authInfo.callid)!=null?a:""),e.callid=L.Guid.create(32),_.info("assign callid "+e.callid+" and send publish request"),this.messageCenter.publish(e)):r(new E(R.ERROR_PUBLISH_SIGNALING_ERROR,`${G[R.ERROR_PUBLISH_SIGNALING_ERROR]} because no messageCenter`))})}roleUpdate(e){return _.info("[roomsig] roleUpdate to "+e),new Promise((t,r)=>{if(!this.messageCenter){r(new E(R.ERROR_SET_CLIENT_ROLE_FAIL,`${G[R.ERROR_SET_CLIENT_ROLE_FAIL]} because no messageCenter`));return}this.messageCenter.on("onRoleUpdateResult",(a,n,o)=>{var u,h;_.info("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,o,R.ERROR_SET_CLIENT_ROLE_FAIL))}),_.info("send role update request"),this.messageCenter.roleUpdate(e)})}setChannelProfile(e){this.channelProfile=e}refreshUrl(e){return _.info("[roomsig] refreshUrl .."),new Promise((t,r)=>{if(!this.messageCenter){r(new E(R.ERROR_REFRESH_PUSH_URL_FAIL,`${G[R.ERROR_REFRESH_PUSH_URL_FAIL]} because no messageCenter`));return}this.messageCenter.on("onRefreshUrlResult",a=>{const{code:n,description:o,data:u={}}=a||{};_.info("recv refresh url response "+n),n===200?t(u):r(this.handleSignalError(n,o,R.ERROR_REFRESH_PUSH_URL_FAIL))}),_.info("send refresh url request"),this.messageCenter.refreshUrl(e)})}reportStatus(e){return _.info("[roomsig] reportStatus "+e),new Promise((t,r)=>{this.messageCenter?(this.messageCenter.once("onStatusReport",(a,n)=>{a===200?t():r(new E(a,n))}),this.messageCenter.reportStatus(e)):r(new E(-1,"No messageCenter"))})}handleSignalError(e,t,r){const a=`code: ${e}; description: ${t}`;return new E(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,g;(e=this.messageCenter)==null||e.on("onKeepAliveRsp",()=>{this.emit("onKeepAliveRsp")}),(t=this.messageCenter)==null||t.on("onNotifyJoin",m=>{this.emit("onNotifyJoin",m)}),(r=this.messageCenter)==null||r.on("onNotifyStatus",m=>{this.emit("onNotifyStatus",m)}),(a=this.messageCenter)==null||a.on("onNotifyLeave",m=>{this.emit("onNotifyLeave",m)}),(n=this.messageCenter)==null||n.on("onNotifyPublish",m=>{this.emit("onNotifyPublish",m)}),(o=this.messageCenter)==null||o.on("onBye",(m,f)=>{this.emit("onBye",m,f)}),(u=this.messageCenter)==null||u.on("onReconnectStart",()=>{this.emit("onReconnectStart")}),(h=this.messageCenter)==null||h.on("onReconnectSuccess",m=>{this.emit("onReconnectSuccess",m)}),(l=this.messageCenter)==null||l.on("onReconnectFail",m=>{this.emit("onReconnectFail",m)}),(p=this.messageCenter)==null||p.on("onConnectFail",m=>{this.emit("onConnectFail",m),this.reset()}),(d=this.messageCenter)==null||d.on("onNetworkError",m=>{this.emit("onNetworkError",m)}),(g=this.messageCenter)==null||g.on("onAuthInvalid",()=>{this.emit("onAuthInvalid")})}}c(Yt,"logName","RoomServerSignaling"),cr([v()],Yt.prototype,"join",1);class ur extends j{constructor(e,t,r=we.prod){super();c(this,"signaling");c(this,"authInfo");c(this,"userName");c(this,"channelProfile");c(this,"clientRole");c(this,"env",we.prod);c(this,"maxConnectRetryCount");this.channelProfile=e,this.clientRole=t,this.env=r}reset(){var e;_.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 E(R.ERROR_JOIN_FAIL,"already logged in")):(_.info("[signalingmanager] create signaling"),this.signaling=new Yt(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 E(R.ERROR_PUBLISH_FAIL,"no signaling"))})}reportStatus(e){return new Promise((t,r)=>{this.signaling?this.signaling.reportStatus(e).then(()=>{t()}).catch(a=>{r(a)}):r(new E(-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 E(R.ERROR_REFRESH_PUSH_URL_FAIL,"no signaling"))}refreshAuthInfo(e){return S(this,null,function*(){var t;try{this.authInfo&&(this.authInfo=x(x({},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,g,m;(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)),(g=this.signaling)==null||g.on("onAuthInvalid",this.onAuthInvalid.bind(this)),(m=this.signaling)==null||m.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 Me=class Me{static getInstance(){return Me.instance||(Me.instance=new AudioContext),Me.instance.resume(),Me.instance}};c(Me,"instance");let Xt=Me;function hr(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((g,m)=>g+m)/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 lr extends j{constructor(){super();c(this,"audioContext");c(this,"stream");c(this,"sourceNode");c(this,"analyser");this.audioContext=Xt.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=hr(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 Ui 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 lr}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 Di{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 xi="customVideoProfile",Fi="customScreenProfile",ze={width:1280,height:720,frameRate:30,maxBitrate:2e3},Je={width:1920,height:1080,frameRate:30,maxBitrate:2600},dr={1e4:Z.AliEngineLocalDeviceExceptionTypeUnknown,2e4:Z.AliEngineLocalDeviceExceptionTypeUnknown,10001:Z.AliEngineLocalDeviceExceptionTypeMicNotAvailable,10002:Z.AliEngineLocalDeviceExceptionTypeMicAuthFail,10003:Z.AliEngineLocalDeviceExceptionTypeMicOpenFail,10005:Z.AliEngineLocalDeviceExceptionTypeCameraAuthFail,10004:Z.AliEngineLocalDeviceExceptionTypeVideoDeviceException,10006:Z.AliEngineLocalDeviceExceptionTypeCameraOpenFail,10010:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10011:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10012:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10013:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10014:Z.AliEngineLocalDeviceExceptionTypeDisplayException,10019:Z.AliEngineLocalDeviceExceptionTypeDisplayException};var pr=Object.defineProperty,gr=Object.getOwnPropertyDescriptor,Q=(i,s,e,t)=>{for(var r=t>1?void 0:t?gr(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};class pt extends j{constructor(){super();c(this,"state");c(this,"time");this.state=k.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 Ct=class Ct extends Ui{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",L.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 pt,this.audioPubState.on("change",(h,l,p)=>{this.emit("audioPublishStateChanged",h,l,p)}),this.videoPubState=new pt,this.videoPubState.on("change",(h,l,p)=>{this.emit("videoPublishStateChanged",h,l,p)}),this.videoSmallPubState=new pt,this.videoSmallPubState.on("change",(h,l,p)=>{this.emit("dualStreamPublishStateChanged",h,l,p)}),this.screenPubState=new pt,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===A.VideoLarge))}get hasCameraDualTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===A.VideoSmall))}get hasScreenTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="video"&&t&&a===A.Screen))}get hasAudioTrackInMS(){var e;return!!((e=this.streamTracks)!=null&&e.find(({ssrc:t,type:r,msid:a})=>r==="audio"&&t&&a===A.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===je.CAMERA_FRONT)this.streamManager.setCameraVideoConstraints({facingMode:"user"});else if(e===je.CAMERA_REAR)this.streamManager.setCameraVideoConstraints({facingMode:"environment"});else throw new E(R.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL,`${G[R.ERROR_LOCAL_STREAM_SET_CAMERA_DIRECTION_FAIL]} ${e}`)}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=L.Guid.create(16)}clearPublishState(){this.streamTracks=void 0}clear(){return S(this,null,function*(){ki(Ct.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)&&(e.srcObject=null,this.previewElements.splice(this.previewElements.indexOf(e),1)),this.screenPreviewElements.includes(e)&&(e.srcObject=null,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===null){t===V.AliRtcVideoTrackCamera?this.stopPreview({primary:!0,screen:!1}):this.stopPreview({primary:!1,screen:!0});return}if(![V.AliRtcVideoTrackCamera,V.AliRtcVideoTrackScreen].includes(t))throw new E(R.ERROR_SET_VIEW_CONFIG_INVALID,G[R.ERROR_SET_VIEW_CONFIG_INVALID],{track:t});e.forEach(r=>{this.setPreviewElement({videoElement:r,screen:t===V.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 E(R.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST,G[R.ERROR_LOCAL_STREAM_PREVIEW_ELEMENT_NOT_EXIST],{videoElement:r});if(!n)throw new E(R.ERROR_LOCAL_STREAM_NOT_EXIST,G[R.ERROR_LOCAL_STREAM_NOT_EXIST],{screen:a});return _.info(`[${this.moduleName}/${t}]`,{screen:a,stream:n,videoElement:r}),yield n.play(r),this.setPreviewElement(e),n.mediaStream}catch(n){const o=R.ERROR_LOCAL_STREAM_PREVIEW_FAIL;throw E.fromError(n,o,G[o])}})}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=>{n.pause(),n.srcObject=null}),a&&this.screenPreviewElements.forEach(n=>{n.pause(),n.srcObject=null});else{const n=this.previewElements.findIndex(o=>o===t);if(n>=0)this.previewElements.splice(n,1),t.pause(),t.srcObject=null;else{const o=this.screenPreviewElements.findIndex(u=>u===t);o>=0&&(this.screenPreviewElements.splice(o,1),t.pause(),t.srcObject=null)}}}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=dr[t.errorCode];throw r&&(e.audio?this.emit("localDeviceException",be.AliEngineLocalDeviceTypeMic,r,""):e.video?this.emit("localDeviceException",be.AliEngineLocalDeviceTypeCamera,r,""):e.screen?this.emit("localDeviceException",be.AliEngineLocalDeviceTypeDisplay,r,""):this.emit("localDeviceException",be.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===A.Audio?u.audio=!0:r===A.VideoLarge||r===A.VideoSmall?(u.video=!0,u.vMsid=r):r===A.Screen&&(u.screen=!0),yield this.publishDeleteTracks(u)}const a={};if(t!=null&&t.hasVideo&&(a.isScreen=r===A.Screen,a.vMsid=r),t!=null&&t.hasAudio&&(a.aMsid=r),!e&&t)return yield this.publishAdd(t,!1,a);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(k.AliRtcStatePublishing),a&&this.videoPubState.setState(k.AliRtcStatePublishing),n&&this.videoSmallPubState.setState(k.AliRtcStatePublishing),o&&this.screenPubState.setState(k.AliRtcStatePublishing),this.publishPromise=this.rtsManager.publish(this.url);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(k.AliRtcStatePublished),a&&this.videoPubState.setState(k.AliRtcStatePublished),n&&this.videoSmallPubState.setState(k.AliRtcStatePublished),o&&this.screenPubState.setState(k.AliRtcStatePublished)}catch(u){throw r&&this.audioPubState.setState(k.AliRtcStateNoPublish),a&&this.videoPubState.setState(k.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),o&&this.screenPubState.setState(k.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:M,type:H,msid:P})=>H==="audio"&&M&&P===A.Audio),l=yield this.compareAndPublish(h,e.audio,A.Audio);l&&(t=l);const p=(n=this.streamTracks)==null?void 0:n.find(({ssrc:M,type:H,msid:P})=>H==="video"&&M&&P===A.VideoLarge),d=yield this.compareAndPublish(p,e.video,A.VideoLarge);d&&(t=d);const g=(o=this.streamTracks)==null?void 0:o.find(({ssrc:M,type:H,msid:P})=>H==="video"&&M&&P===A.VideoSmall),m=yield this.compareAndPublish(g,e.videoSmall,A.VideoSmall);m&&(t=m);const f=(u=this.streamTracks)==null?void 0:u.find(({ssrc:M,type:H,msid:P})=>H==="video"&&M&&P===A.Screen),b=yield this.compareAndPublish(f,e.screen,A.Screen);if(b&&(t=b),!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){const d=R.ERROR_PUBLISH_FAIL,g=G[d];throw new E(d,`${g} because there is 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 E(R.ERROR_REFRESH_PUSH_URL_FAIL,G[R.ERROR_REFRESH_PUSH_URL_FAIL]),t=this.url;try{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}catch(r){throw r}})}publishAdd(e,t=!1,r,a=0){return S(this,null,function*(){const n=R.ERROR_PUBLISH_ADD_FAIL,o=G[R.ERROR_PUBLISH_ADD_FAIL],u=(r==null?void 0:r.aMsid)===A.Audio,h=(r==null?void 0:r.vMsid)===A.VideoLarge,l=(r==null?void 0:r.vMsid)===A.VideoSmall,p=(r==null?void 0:r.vMsid)===A.Screen;u&&this.audioPubState.setState(k.AliRtcStatePublishing),h&&this.videoPubState.setState(k.AliRtcStatePublishing),l&&this.videoSmallPubState.setState(k.AliRtcStatePublishing),p&&this.screenPubState.setState(k.AliRtcStatePublishing);try{const d=yield this.rtsManager.publishAdd(this.url,e,r);u&&this.audioPubState.setState(k.AliRtcStatePublished),h&&this.videoPubState.setState(k.AliRtcStatePublished),l&&this.videoSmallPubState.setState(k.AliRtcStatePublished),p&&this.screenPubState.setState(k.AliRtcStatePublished),this.streamTracks=this.rtsManager.publishingTracks;const g={userid:this.userId,sessionid:"",displayname:this.name,pubid:this.publishId,resume:t,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks,traceid:d};return this.reportSelfDeviceStatus(),g}catch(d){if(u&&this.audioPubState.setState(k.AliRtcStateNoPublish),h&&this.videoPubState.setState(k.AliRtcStateNoPublish),l&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),p&&this.screenPubState.setState(k.AliRtcStateNoPublish),d.errorCode===15006&&a<3)return this.publishAdd(e,t,r,a+1);throw E.fromError(d,n,o)}})}publishReplace(e,t){return S(this,null,function*(){const r=R.ERROR_PUBLISH_REPLACE_TRACKS_FAIL,a=G[r],{isScreen:n}=t!=null?t:{};if(n&&!this.hasScreenTrackInMS)throw new E(r,`${a} because previous localStream is required for replacing tracks`);try{yield this.rtsManager.publishReplace(this.url,e,t),this.traceId="",this.streamTracks=this.rtsManager.publishingTracks;const o={userid:this.userId,sessionid:"",pubid:this.publishId,displayname:this.name,subscribe:{signal:"",pullstreamurl:this.url},callid:this.callid,tracks:this.streamTracks};return this.reportSelfDeviceStatus(),o}catch(o){throw E.fromError(o,r,a)}})}publishDeleteTracks(e){return S(this,null,function*(){const t=R.ERROR_PUBLISH_DELETE_TRACKS_FAIL,r=G[t],a={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(k.AliRtcStateNoPublish),e.video&&(e.vMsid===A.VideoSmall?this.videoSmallPubState.setState(k.AliRtcStateNoPublish):this.videoPubState.setState(k.AliRtcStateNoPublish)),e.screen&&this.screenPubState.setState(k.AliRtcStateNoPublish),this.traceId="",a.tracks=this.streamTracks,this.reportSelfDeviceStatus(),a}catch(n){throw E.fromError(n,t,r)}})}publishStop(){return S(this,null,function*(){const e="publishStop",t=R.ERROR_PUBLISH_STOP_FAIL,r=G[t];if(!this._isPublishing)throw new E(t,`${r} because previous localStream is required for publishing stopping`);_.info(`[${this.moduleName}/${e}]`,{url:this.url});const a=new Date().getTime();try{const n=this.hasAudioTrackInMS,o=this.hasCameraTrackInMS,u=this.hasCameraDualTrackInMS,h=this.hasScreenTrackInMS;yield this.rtsManager.publishStop(this.url),n&&this.audioPubState.setState(k.AliRtcStateNoPublish),o&&this.videoPubState.setState(k.AliRtcStateNoPublish),u&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),h&&this.screenPubState.setState(k.AliRtcStateNoPublish),this.traceId="",this.streamTracks=[];const l={userid:this.userId,sessionid:"",displayname:this.displayname,callid:this.callid,pubid:this.publishId,subscribe:{signal:"",pullstreamurl:this.url},tracks:[]};return this.syncPublishToRoomServer(l,{},a),l}catch(n){throw E.fromError(n,t,r)}})}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(k.AliRtcStateNoPublish),a&&this.videoPubState.setState(k.AliRtcStateNoPublish),n&&this.videoSmallPubState.setState(k.AliRtcStateNoPublish),o&&this.screenPubState.setState(k.AliRtcStateNoPublish),this._isPublishing=!1,this.traceId="",this.clearStream()}return this.reporter.reportUnpublish(this.callid||"",e,0,""),t}catch(r){throw E.fromError(r,R.ERROR_UNPUBLISH_FAIL,G[R.ERROR_UNPUBLISH_FAIL])}})}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),Di.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(k.AliRtcStatePublishIdle),this.videoPubState.setState(k.AliRtcStatePublishIdle),this.videoSmallPubState.setState(k.AliRtcStatePublishIdle),this.screenPubState.setState(k.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:Ne.AliRtcAudioTrackMic})}const t=[];if(this.hasCameraTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,A.VideoLarge);r&&t.push({track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:r})}if(this.hasCameraDualTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,A.VideoSmall);r&&t.push({track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:r})}if(this.hasScreenTrackInMS){const r=yield this.rtsManager.getPublishVideoStats(this.url,A.Screen);r&&t.push({track:V.AliRtcVideoTrackScreen,stats:r})}return{audio:e,video:t}})}};c(Ct,"logName","LocalUser");let z=Ct;Q([v()],z.prototype,"initInfo",1),Q([v()],z.prototype,"clearPublishState",1),Q([v()],z.prototype,"clear",1),Q([v()],z.prototype,"setViewConfig",1),Q([v()],z.prototype,"preview",1),Q([v()],z.prototype,"stopPreview",1),Q([v()],z.prototype,"resumePublish",1),Q([v()],z.prototype,"createLocalStream",1),Q([v()],z.prototype,"stopLocalStream",1),Q([v()],z.prototype,"compareAndPublish",1),Q([v()],z.prototype,"startPublish",1),Q([v()],z.prototype,"publishUpdate",1),Q([v()],z.prototype,"syncPublishToRoomServer",1),Q([v()],z.prototype,"refreshPushStreamUrl",1),Q([v()],z.prototype,"publishAdd",1),Q([v()],z.prototype,"publishReplace",1),Q([v()],z.prototype,"publishDeleteTracks",1),Q([v()],z.prototype,"publishStop",1),Q([v()],z.prototype,"unPublish",1),Q([v()],z.prototype,"sendSEI",1);var Pe=(i=>(i.OPUS="opus",i.H264="H264",i.UNKONWN="",i))(Pe||{}),Ce=(i=>(i.VideoTrackEnded="videoTrackEnded",i.AudioTrackEnded="audioTrackEnded",i.ScreenTrackEnded="screenTrackEnded",i))(Ce||{});const mr=i=>{const s=new MediaStream;return s.addTrack(i),s},Bi=i=>S(this,null,function*(){return yield y.AliRTS.createStream({custom:!0,mediaStream:i})}),Ye=i=>S(this,null,function*(){const s=mr(i);return yield Bi(s)}),Sr=i=>{const{audio:s,video:e,screen:t}=i;if(e&&t)throw new E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"create stream error, cannot create video && screen together");return!(!e&&!s&&!t)},fr=i=>i===A.Audio||i===pe.Audio,br=i=>i===A.VideoLarge||i===pe.VideoLarge,Rr=i=>i===A.VideoSmall,vr=i=>i===A.Screen;var _r=Object.defineProperty,Ir=Object.getOwnPropertyDescriptor,Ar=(i,s,e,t)=>{for(var r=t>1?void 0:t?Ir(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&&_r(s,e,r),r};class gt extends j{constructor(){super();c(this,"audioInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.UNKONWN});c(this,"videoLargeInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.UNKONWN});c(this,"videoSmallInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.UNKONWN});c(this,"screenInfo",{subscribed:!1,ssrc:"",msid:"",pt:0,red:0,codec:Pe.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:Pe.UNKONWN}get audioTrackInfo(){return this.hasAudio?Ne.AliRtcAudioTrackMic:Ne.AliRtcAudioTrackNo}get videoTrackInfo(){return this.hasVideo&&this.hasScreen?V.AliRtcVideoTrackBoth:this.hasVideo?V.AliRtcVideoTrackCamera:this.hasScreen?V.AliRtcVideoTrackScreen:V.AliRtcVideoTrackNo}updateTracks(e){let t="",r="",a="",n="";return e?(e.forEach(o=>{var l;let u=Pe.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)}fr(o.msid)?(t=o.ssrc,this.audioInfo.msid=o.msid,this.audioInfo.codec=u,h&&(this.audioInfo.subscribed=!1)):Rr(o.msid)?(a=o.ssrc,this.videoSmallInfo.msid=o.msid,this.videoSmallInfo.codec=u,h&&(this.videoSmallInfo.subscribed=!1)):br(o.msid)?(r=o.ssrc,this.videoLargeInfo.msid=o.msid,this.videoLargeInfo.codec=u,h&&(this.videoLargeInfo.subscribed=!1)):vr(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=Di.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?D.MuteAudio:D.UnmuteAudio)),this.userStatus.videoDisable!=a&&(this.userStatus.videoDisable=a,this.emit(ie.Remote,a?D.MuteVideo:D.UnmuteVideo)),this.userStatus.screenDisable!=n&&(this.userStatus.screenDisable=n,this.emit(ie.Remote,n?D.MuteScreen:D.UnmuteScreen))):(this.userStatus=t,this.emit(ie.Remote,r?D.MuteAudio:D.UnmuteAudio),this.emit(ie.Remote,a?D.MuteVideo:D.UnmuteVideo),this.emit(ie.Remote,n?D.MuteScreen:D.UnmuteScreen)),!1}}c(gt,"logName","RemoteStreamInfo"),Ar([v()],gt.prototype,"updateRemoteTrackSubState",1);const wr=i=>i.getAudioTracks()[0];function Hi(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 E(R.ERROR_PREVIEW_ELEMENT_INVALID,`${G[R.ERROR_PREVIEW_ELEMENT_INVALID]}, element need HtmlVideoElement`)}else throw new E(R.ERROR_PREVIEW_ELEMENT_INVALID,`${G[R.ERROR_PREVIEW_ELEMENT_INVALID]}, not found htmlelement`)}else throw new E(R.ERROR_PREVIEW_ELEMENT_INVALID,`${G[R.ERROR_PREVIEW_ELEMENT_INVALID]}, element id need string`)}function Zt(i){var e;const s=[];if(Array.isArray(i))i.forEach(t=>{try{s.push(Hi(t))}catch(r){}});else if(typeof i=="string"||((e=i==null?void 0:i.nodeName)==null?void 0:e.toLowerCase())==="video")try{s.push(Hi(i))}catch(t){}return s}function mt(i){return new Promise(s=>setTimeout(s,i))}class Wi{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 Er=Object.defineProperty,Tr=Object.getOwnPropertyDescriptor,X=(i,s,e,t)=>{for(var r=t>1?void 0:t?Tr(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&&Er(s,e,r),r};class Xe extends j{constructor(){super();c(this,"state");c(this,"time");c(this,"_enabled");this.state=K.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 kt=class kt extends Ui{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 Xe);c(this,"videoSmallSubState",new Xe);c(this,"screenSubState");c(this,"streamInfo");c(this,"streamUrl","");this.streamInfo=new gt,this.remoteUserInfo=new Wi(this),this.streamInfo.on(ie.Remote,g=>{this.emit(ie.Remote,g,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 Xe,this.audioSubState.on("change",(g,m,f)=>{this.emit("audioSubscribeStateChanged",this.uid,g,m,f)}),this.videoSubState=new Xe,this.videoSubState.on("change",(g,m,f)=>{this.emit("videoSubscribeStateChanged",this.uid,g,m,f)}),this.screenSubState=new Xe,this.screenSubState.on("change",(g,m,f)=>{this.emit("screenSubscribeStateChanged",this.uid,g,m,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!==V.AliRtcVideoTrackScreen&&t!==V.AliRtcVideoTrackCamera)throw new Error("track is not AliRtcVideoTrackScreen or AliRtcVideoTrackCamera");e?Zt(e).forEach(a=>{a.setAttribute("playsinline",""),L.BrowserUtil.isMicroMessenger&&(a.setAttribute("x5-video-player-type","h5-page"),a.setAttribute("x5-playsinline",""),L.SystemUtil.isAndroid||L.SystemUtil.isIos&&a.setAttribute("x-webkit-airplay","allow")),t===V.AliRtcVideoTrackScreen?this.viewMap.screenViews.push(a):this.viewMap.cameraViews.push(a),this.play(a,t===V.AliRtcVideoTrackScreen)}):(this.stopPlayAll(t===V.AliRtcVideoTrackScreen),t===V.AliRtcVideoTrackScreen?this.viewMap.screenViews=[]:this.viewMap.cameraViews=[])}clear(e=!0){return S(this,null,function*(){var t;e&&this.doStopSubscribe(this.streamUrl),ki(kt.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 gt),(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(K.AliRtcStateSubscribing),e.video&&(this.videoSubState.currentState===K.AliRtcStateSubscribeIdle||this.videoSubState.currentState===K.AliRtcStateNoSubscribe)&&this.videoSubState.setState(K.AliRtcStateSubscribing),e.screen&&this.screenSubState.setState(K.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(K.AliRtcStateSubscribed),this.audioSubState.getEnabled()||this.toggleAudio(!1)}e.video&&(e.vMsid===A.VideoSmall?this.videoSmallSubState.setState(K.AliRtcStateSubscribed):this.videoLargeSubState.setState(K.AliRtcStateSubscribed),this.videoSubState.setState(K.AliRtcStateSubscribed),this.videoSubState.getEnabled()||this.toggleVideo(!1),this.updateStream(h,this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing)),e.screen&&(this.screenSubState.setState(K.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;throw this.webTrackingClient.reportPull("","",!1,!1,!1,!1,u.code,h,a,r,(o=this.streamUrl)!=null?o:"",t),u}})}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(K.AliRtcStateNoSubscribe)),e.video===!0&&(a.video=!1,e.vMsid===A.VideoSmall?(this.videoSmallSubState.setState(K.AliRtcStateNoSubscribe),(this.videoLargeSubState.currentState===K.AliRtcStateNoSubscribe||this.videoLargeSubState.currentState===K.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(K.AliRtcStateNoSubscribe)):(this.videoLargeSubState.setState(K.AliRtcStateNoSubscribe),(this.videoSmallSubState.currentState===K.AliRtcStateNoSubscribe||this.videoSmallSubState.currentState===K.AliRtcStateSubscribeIdle)&&this.videoSubState.setState(K.AliRtcStateNoSubscribe))),e.screen===!0&&(a.screen=!1,this.screenSubState.setState(K.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){const r=R.ERROR_SUBSCRIBE_DELETE_TRACKS_FAIL;throw E.fromError(t,r,G[r])}})}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===V.AliRtcVideoTrackCamera||e===V.AliRtcVideoTrackBoth)return this.playAll();if(!e||e===V.AliRtcVideoTrackScreen||e===V.AliRtcVideoTrackBoth)return this.playAll(!0)})}resumePlay(){this.playAudio(),this.playAll(),this.playAll(!0)}stopSubscribe(e){return S(this,null,function*(){var p,d,g,m,f,b,M;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&&!((g=e==null?void 0:e.screen)==null||g);e?this.reporter.reportSubscribeInvoked(this.userId,o,u,h,n):this.reporter.reportUnsubscribeInvoked(this.userId);let l=new Date().getTime();try{let H;e?H=yield this.subscribeDeleteTracks(e):H=yield this.doStopSubscribe(this.streamUrl),e?this.reporter.reportSubscribe((m=H==null?void 0:H.callid)!=null?m:"",this.userId,o,u,h,n,0,"",new Date().getTime()-l,(f=this.localUserId)!=null?f:""):this.reporter.reportUnsubscribe((b=H==null?void 0:H.callid)!=null?b:"",this.userId,new Date().getTime()-l,0,"")}catch(H){throw e?this.reporter.reportSubscribe("",this.userId,o,u,h,n,H.code,"",new Date().getTime()-l,(M=this.localUserId)!=null?M:""):this.reporter.reportUnsubscribe("",this.userId,new Date().getTime()-l,0,""),H}})}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{try{yield this.rtsManager.subscibeStop(e),this.restore()}catch(l){if(((u=(o=(n=(a=l==null?void 0:l.extraInfo)==null?void 0:a.parsedData)==null?void 0:n.streams)==null?void 0:o[0])==null?void 0:u.res_code)!==404)throw l}return{callid:t,remoteCallid:r,remoteStream:this.stream}}catch(h){const l=R.ERROR_SUBSCRIBE_STOP_FAIL;throw E.fromError(h,l,G[l])}})}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=()=>{_.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.srcObject=e.mediaStream}else r(!0);a=window.setTimeout(()=>{_.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=A.VideoSmall):!this.isVideoLargeSubscribing&&((u=this.streamInfo)!=null&&u.hasVideoLarge)&&!(this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoSmallSubscribing)&&(e.video=!0,e.vMsid=A.VideoLarge),this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeLow&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&this.streamInfo.hasVideoSmall?(t.video=!0,t.vMsid=A.VideoLarge):this.defaultVideoStreamType===oe.AliRtcVideoStreamTypeHigh&&this.isVideoLargeSubscribing&&this.isVideoSmallSubscribing&&(t.video=!0,t.vMsid=A.VideoSmall)):(!this.wantSubVideo||!((h=this.streamInfo)!=null&&h.hasVideo))&&this.isVideoSubscribing&&(t.video=!0,t.vMsid=this.streamInfo.isVideoSmallSubscribing?A.VideoSmall:A.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=()=>{this.play(e,t===V.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),L.SystemUtil.isIos&&parseInt(L.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;if(!e||!r||!r.mediaStream)return;e.srcObject=r.mediaStream;const a=()=>S(this,null,function*(){e.play().catch(()=>{this.handleVideoPlayFailded(e,t?V.AliRtcVideoTrackScreen:V.AliRtcVideoTrackCamera)})});if(L.BrowserUtil.isMicroMessenger){const n=window.top!==window.self,o=window.WeixinJSBridge||window.top.WeixinJSBridge;o?o.invoke("getNetworkType",{},()=>{a()}):(n?window.top.document:document).addEventListener("WeixinJSBridgeReady",()=>{o.invoke("getNetworkType",{},()=>{a()})})}else a()}stopPlayAll(e=!1){e?this.viewMap.screenViews.forEach(t=>{t.pause(),t.srcObject=null}):this.viewMap.cameraViews.forEach(t=>{t.pause(),t.srcObject=null})}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:Ne.AliRtcAudioTrackMic,stats:n})}const t=[];if((r=this.streamInfo)!=null&&r.isVideoLargeSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,A.VideoLarge);n&&t.push({uid:this.uid,track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeHigh,stats:n})}if((a=this.streamInfo)!=null&&a.isVideoSmallSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,A.VideoSmall);n&&t.push({uid:this.uid,track:V.AliRtcVideoTrackCamera,streamType:oe.AliRtcVideoStreamTypeLow,stats:n})}if(this.isScreenSubscribing){const n=yield this.rtsManager.getSubscribeVideoStats(this.streamUrl,A.Screen);n&&t.push({uid:this.uid,track:V.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(kt,"logName","RemoteUser");let q=kt;X([v()],q.prototype,"setRemoteDefaultVideoStreamType",1),X([v()],q.prototype,"clear",1),X([v()],q.prototype,"updateRemoteUserDeviceStatus",1),X([v()],q.prototype,"updateRemoteTracks",1),X([v()],q.prototype,"subscribe",1),X([v()],q.prototype,"subscribeProxy",1),X([v()],q.prototype,"subscribeDeleteTracks",1),X([v()],q.prototype,"subscribeDeleteProxy",1),X([v()],q.prototype,"restore",1),X([v()],q.prototype,"stopSubscribe",1),X([v()],q.prototype,"doStopSubscribe",1),X([v()],q.prototype,"clearStream",1),X([v()],q.prototype,"clearScreenStream",1),X([v()],q.prototype,"updateSubscribe",1),X([v()],q.prototype,"playAudio",1),X([v()],q.prototype,"stopPlayAudio",1),X([v()],q.prototype,"playAll",1),X([v()],q.prototype,"play",1),X([v()],q.prototype,"stopPlayAll",1),X([v()],q.prototype,"toggleAudio",1),X([v()],q.prototype,"toggleVideo",1),X([v()],q.prototype,"toggleScreen",1);class yr extends j{constructor(){super(...arguments);c(this,"plugins",new Map)}add(e,t){if(this.plugins.has(e.name))throw new Error(`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 Error(`Plugin ${e} not found`);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 Lr=Object.defineProperty,Pr=Object.getOwnPropertyDescriptor,ue=(i,s,e,t)=>{for(var r=t>1?void 0:t?Pr(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&&Lr(s,e,r),r};class ae 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=y.AliRTS.createClient(),this.localStreamManager=e,this.rts.on("connectStatusChange",t=>{_.event("rts connectStatusChange to:",t.status),(t.status===y.EConnectStatus.CONNECT_STATUS_RECONNECTING||t.status===y.EConnectStatus.CONNECT_STATUS_DISCONNECTED)&&this.setConnected(!1)}),this.rts.on("datachannelStatusChange",t=>{_.event("rts datachannelStatusChange to:",t.status),t.status===y.EDatachannelStatus.DATACHANNEL_STATUS_OPEN?this.dcResolve&&this.dcResolve(!0):t.status===y.EDatachannelStatus.DATACHANNEL_STATUS_CLOSE&&(this.dcConnectingPromise=new Promise(r=>{this.dcResolve=r}),console.warn("DC DisConnected"))}),this.rts.on("connectStatusChange",t=>{t.status===y.EConnectStatus.CONNECT_STATUS_RECONNECTING?this.emit("reconnecting"):t.status===y.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:A.Audio]),e.hasScreen&&(n.vMsid=[A.Screen]),e.hasVideo&&(n.vMsid=[a!=null?a:t!=null&&t.isScreen?A.Screen:A.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});y.AliRTS.SystenUtil.isIos&&(u.tcpOnly=!0),u.retryTimes=0,this.encodedInsertableStreams&&(u.encodedInsertableStreams=!0);try{this.startConnect();const h=yield this.rts.publish(e,r,u);return this.setConnected(!0),this._publishingTracks=this.rts.getPublishTrackInfoList(),a&&(yield this.publishAdd(e,a,{vMsid:A.VideoSmall},t)),n&&(yield this.publishAdd(e,n,{vMsid:A.Screen},t)),h}catch(h){throw this.setConnected(!1),h}})}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){return S(this,null,function*(){try{yield this.dcConnectingPromise;const o=yield this.rts.publishAdd([x({url:e,stream:t,updateSourceStream:!1},this.getPubMsid(t,r))]);if(o){const[u]=o;return this.updatePublishingTracks(u.trackInfoList),u.traceId||""}}catch(o){if(o.errorCode===15006&&n<3)return yield this.publishAdd(e,t,r,a,n+1);throw o}return""})}publishDelete(e,t){return S(this,null,function*(){var l,p,d,g,m,f;yield this.dcConnectingPromise;const r=(p=(l=this.publishingTracks)==null?void 0:l.find(({msid:b})=>b===A.Audio))==null?void 0:p.msid,a=(g=(d=this.publishingTracks)==null?void 0:d.find(({msid:b})=>b===A.VideoLarge))==null?void 0:g.msid,n=(f=(m=this.publishingTracks)==null?void 0:m.find(({msid:b})=>b===A.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 this.updatePublishingTracks(h.trackInfoList),""})}publishReplace(e,t,r){return S(this,null,function*(){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),""})}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)||A.Audio]),r.video?r.vMsid?a.vMsid=[r.vMsid]:e!=null&&e.hasVideoLarge?a.vMsid=[(e==null?void 0:e.getVideoLargeInfo().msid)||A.VideoLarge]:e!=null&&e.hasVideoSmall?a.vMsid=[(e==null?void 0:e.getVideoSmallInfo().msid)||A.VideoSmall]:a.vMsid=[A.VideoLarge]:r.screen&&e!=null&&e.hasScreen&&(a.vMsid=[(e==null?void 0:e.getScreenInfo().msid)||A.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);y.AliRTS.SystenUtil.isIos&&(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=He(x({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}return null})}subscibeDelete(e){return S(this,null,function*(){var n,o,u,h;yield this.dcConnectingPromise;const{remoteUser:t,options:r}=e,a=He(x({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){return S(this,null,function*(){let t="";if(this.connecting&&(yield this.connectingPromise),this.connected){yield this.dcConnectingPromise;const{audio:r,video:a,videoSmall:n,screen:o}=this.localStreamManager.publishStreams;r&&(t=yield this.publishAdd(e,r,{aMsid:A.Audio}),yield mt(100)),a&&(t=yield this.publishAdd(e,a,{vMsid:A.VideoLarge}),yield mt(100)),n&&(t=yield this.publishAdd(e,n,{vMsid:A.VideoSmall}),yield mt(100)),o&&(t=yield this.publishAdd(e,o,{isScreen:!0,vMsid:A.Screen}))}else t=yield this.httpPublish(e);return t})}subscribe(e){return S(this,null,function*(){const{options:t}=e;if(t.video&&t.screen)throw new E(R.ERROR_SUBSCRIBE_FAIL,"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:A.VideoLarge,data:t,repeatCount:r,payloadType:a})})}}c(ae,"logName","RtsManager"),ue([v()],ae.prototype,"updatePublishingTracks",1),ue([v()],ae.prototype,"httpPublish",1),ue([v()],ae.prototype,"publishAdd",1),ue([v()],ae.prototype,"publishDelete",1),ue([v()],ae.prototype,"publishReplace",1),ue([v()],ae.prototype,"publishStop",1),ue([v()],ae.prototype,"unpublish",1),ue([v()],ae.prototype,"httpSubscribe",1),ue([v()],ae.prototype,"subscribeAdd",1),ue([v()],ae.prototype,"subscibeDelete",1),ue([v()],ae.prototype,"subscibeStop",1),ue([v()],ae.prototype,"publish",1),ue([v()],ae.prototype,"subscribe",1),ue([v()],ae.prototype,"sendSEI",1);class Qt{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 ei 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!==fe.Camera)throw new Error("VideoStreamSource is required");if(n&&!r&&r!==ot.Microphone)throw new Error("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===ee.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,g;this._targetAudioTrack=this.originAudioTrack,this._targetVideoTrack=this.originVideoTrack;for(const m of this.plugins)try{yield m.execute(this,e)}catch(f){console.error(`error in plugin-${m.name}, error: ${f}`)}this._targetVideoTrack?((r=(t=this._publishVideoStream)==null?void 0:t.videoTrack)==null?void 0:r.id)!==this._targetVideoTrack.id&&(this._publishVideoStream=yield Ye(this._targetVideoTrack),this.setVideoMuted(this._videoMuted),(a=this.profileManager)==null||a.setVideoProfile(this.originVideoTrack,this._publishVideoStream,!0),this.previewStream?(n=this.previewStream)==null||n.mergeStream(this._publishVideoStream):this._previewStream=yield Ye(this._targetVideoTrack)):(this._publishVideoStream=void 0,(o=this.previewStream)==null||o.deleteTracks({video:!0})),this._targetDualVideoTrack?((h=(u=this._publishDualVideoStream)==null?void 0:u.videoTrack)==null?void 0:h.id)!==this._targetDualVideoTrack.id&&(this._publishDualVideoStream=yield Ye(this._targetDualVideoTrack),this._videoMuted?this._publishDualVideoStream.disableVideo():this._publishDualVideoStream.enableVideo()):this._publishDualVideoStream=void 0,this._targetAudioTrack?((p=(l=this._publishAudioStream)==null?void 0:l.audioTrack)==null?void 0:p.id)!==this._targetAudioTrack.id&&(this._publishAudioStream=yield Ye(this._targetAudioTrack),this.setAudioMuted(this._audioMuted),this.previewStream?(d=this.previewStream)==null||d.mergeStream(this._publishAudioStream):this._previewStream=yield Ye(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 Qt),e&&this._profileManager.updateProfile(e,t),yield this._profileManager.setVideoProfile(this.originVideoTrack,this._publishVideoStream,this.type===ee.AliRtcSdkStreamTypeScreen)})}get videoProfile(){var e;return(e=this.profileManager)==null?void 0:e.videoProfile}setVideoContentHint(e){this._profileManager||(this._profileManager=new Qt),this._profileManager.setContentHint(this.originVideoTrack,e)}updateAudioProfile(e){return S(this,null,function*(){this._profileManager||(this._profileManager=new Qt),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 De=(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))(De||{}),Cr=Object.defineProperty,kr=Object.getOwnPropertyDescriptor,St=(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&&Cr(s,e,r),r};class xe extends j{constructor(e){super();c(this,"pluginManager");c(this,"publishingCameraVideoStream");c(this,"publishingScreenVideoStream");c(this,"cameraStreamInfo",new ei(ee.AliRtcSdkStreamTypeCapture));c(this,"screenStreamInfo",new ei(ee.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(!r.isSupported("6.11.2")){console.warn(`${r.name} is not supported!!!`),r.emit("unsupported");return}try{yield r.init()}catch(a){r.emit("error",E.fromError(a,De.AliRtcPluginErrorInitError))}r.streamType===ee.AliRtcSdkStreamTypeCapture&&(this.cameraStreamInfo.addPlugin(r),yield this.cameraStreamInfo.process(this.streamInfos)),r.streamType===ee.AliRtcSdkStreamTypeScreen&&(this.screenStreamInfo.addPlugin(r),yield this.screenStreamInfo.process(this.streamInfos)),this.emit("publishupdate")});this.cameraStreamInfo.updateVideoProfile(xi,ze),this.cameraStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({video:!0}),this.emit("trackended",Ce.VideoTrackEnded)})),this.cameraStreamInfo.on("audiotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({audio:!0}),this.emit("trackended",Ce.AudioTrackEnded)})),this.screenStreamInfo.updateVideoProfile(Fi,Je),this.screenStreamInfo.on("videotrackended",()=>S(this,null,function*(){yield this.stopLocalStream({screen:!0}),this.emit("trackended",Ce.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 y.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 y.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=Sr(e);let l;if(h){if(o===!0&&this.cameraStreamInfo.cameraVideoConstraints?(yield this.setAvailableCameraDeviceId(),o=x({},this.cameraStreamInfo.cameraVideoConstraints)):typeof o=="object"&&(yield this.setAvailableCameraDeviceId(),o=x(x({},o),this.cameraStreamInfo.cameraVideoConstraints)),u===void 0&&this.audioCaptureDisabled?u=!1:u&&(u===!0&&this.cameraStreamInfo.micAudioConstraints?(yield this.setAvailableMicrophoneDeviceId(),u=x({},this.cameraStreamInfo.micAudioConstraints)):typeof u=="object"&&(yield this.setAvailableMicrophoneDeviceId(),u=x(x({},u),this.cameraStreamInfo.micAudioConstraints)),this._audioCaptureDisabled=!1),l=yield y.AliRTS.createStream({audio:u,video:o,screen:t,custom:!!r,mediaStream:r,skipProfile:!0}),t)yield this.screenStreamInfo.updateSource(l,fe.Screen,ot.Screen),yield this.setScreenProfile(n),this.setScreenContentHint(),this.publishingScreenVideoStream=void 0;else if(yield this.cameraStreamInfo.updateSource(l,fe.Camera,ot.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 y.AliRTS.SystenUtil.isIos&&y.AliRTS.SystenUtil.compareVersion("15.1")&&!y.AliRTS.SystenUtil.compareVersion("15.2")&&(yield mt(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 E(R.ERROR_PUBLISH_FAIL,"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=A.Screen,d.addTrack((p=o.screen)==null?void 0:p.videoTrack),t=!0),e=yield Bi(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=x(x({},(t=this.cameraStreamInfo.cameraVideoConstraints)!=null?t:{}),e)}setMicAudioConstraints(e){var t;this.cameraStreamInfo.micAudioConstraints=x(x({},(t=this.cameraStreamInfo.micAudioConstraints)!=null?t:{}),e)}}c(xe,"logName","LocalStreamManager"),St([v()],xe.prototype,"createLocalStream",1),St([v()],xe.prototype,"stopLocalStream",1),St([v()],xe.prototype,"createHTTPPublishStream",1),St([v()],xe.prototype,"stop",1);var Or=Object.defineProperty,Mr=Object.getOwnPropertyDescriptor,ge=(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&&Or(s,e,r),r};class he 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 yr,this.localStreamManager=new xe(this.pluginManager),this.rtsManager=new ae(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=>{_.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=Zt(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;if(!t)return(n=this.userMap[e])==null?void 0:n.setViewConfig(null,r);const a=Zt(t);a.length!==0&&a.forEach(o=>{var u,h;(u=this.publisher)==null||u.resetElement(o),Object.values(this.usersViewMap).forEach(({cameraViews:l=[],screenViews:p=[]})=>{l.includes(o)&&l.splice(l.indexOf(o),1),p.includes(o)&&p.splice(p.indexOf(o),1)}),(h=this.userMap[e])==null||h.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 q({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(D.PullStreamStats,this.onRemoteStatReport.bind(this)),r.on(D.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.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===D.MuteAudio?this.emit("userAudioMuted",t,!0):e===D.UnmuteAudio?this.emit("userAudioMuted",t,!1):e===D.MuteVideo?this.emit("userVideoMuted",t,!0):e===D.UnmuteVideo?this.emit("userVideoMuted",t,!1):e===D.MuteScreen?this.emit("userScreenMuted",t,!0):e===D.UnmuteScreen&&this.emit("userScreenMuted",t,!1)}onRemoteStatReport(e,t,r){this.emit(D.PullStreamStats,e,t,r)}onSubscribeExceeds(e,t){this.emit(D.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:Wt.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 E(R.ERROR_REMOTE_USER_NOT_FOUND);r.setWantSubAudio(t),t?r.updateSubscribe():r.stopSubscribe({audio:!0})}updateVideoWant(e,t){const r=this.userMap[e];if(!r)throw new E(R.ERROR_REMOTE_USER_NOT_FOUND);r.setWantSubVideo(t),t?r.updateSubscribe():r.stopSubscribe({video:!0})}updateScreenWant(e,t){const r=this.userMap[e];if(!r)throw new E(R.ERROR_REMOTE_USER_NOT_FOUND);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=x(x({},this.authInfo),e)),e.userId&&((t=this.self)==null||t.refreshUserInfo(e.userId))}setEnableMediaExtensionMsg(e){this.rtsManager.setEncodedInsertableStreams(e)}}c(he,"logName","UserManager"),ge([v()],he.prototype,"init",1),ge([v()],he.prototype,"clear",1),ge([v()],he.prototype,"addUser",1),ge([v()],he.prototype,"removeLeftUser",1),ge([v()],he.prototype,"updateUsers",1),ge([v()],he.prototype,"updateAudioWant",1),ge([v()],he.prototype,"updateVideoWant",1),ge([v()],he.prototype,"updateScreenWant",1),ge([v()],he.prototype,"stopIndication",1),ge([v()],he.prototype,"startIndication",1),ge([v()],he.prototype,"enableAudioVolumeIndication",1);const ti=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 Nr{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=tr[s],n={appid:t.appId,userid:t.userId,channelid:t.channelId,timestamp:t.timestamp,token:t.token,requestid:_e.createCallid(),tokensid:!1,session:(h=t.callid)!=null?h:_e.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 Error(l.statusText)):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 ti(s.split("?")[0]),r=ce.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=ce.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 ti(s.split("?")[0]),r=ce.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=ce.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 ti(s.split("?")[0]),t=ce.MPU_TASK_TRANSACTION_STOP,r=new dt().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=ce.MPU_TASK_TRANSACTION_STOP,t=new dt().toJson(e,this.authInfo,s);return this.doRequest(e,JSON.stringify(t))}refreshAuthInfo(s){this.authInfo&&this.setAuthInfo(x(x({},this.authInfo),s))}}var ji=(i,s,e)=>{if(!s.has(i))throw TypeError("Cannot "+e)},ft=(i,s,e)=>(ji(i,s,"read from private field"),e?e.call(i):s.get(i)),ii=(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)},si=(i,s,e,t)=>(ji(i,s,"write to private field"),t?t.call(i,e):s.set(i,e),e),Vr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},w={},ke={};const Ur="SLS_CLIENT";var Gi=(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))(Gi||{}),$i=(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))($i||{});const Dr={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},xr="sls-trace-uid";var qi=(i=>(i.OK="OK",i.ERROR="ERROR",i.UNSET="UNSET",i))(qi||{});ke.InternalPlugin=$i,ke.InternalPluginPriority=Dr,ke.OTStatusCode=qi,ke.SLS_CLIENT_NAME=Ur,ke.SLS_TRACE_UID_KEY=xr,ke.WebEventType=Gi;var me=ke;function ri(i,s,e){Object.defineProperty(i,s,{writable:!0,enumerable:!0,configurable:!0,value:e})}function Fr(i,s,e,t){t?t(()=>{ri(i,s,e)}):ri(i,s,e)}class Br{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 Ze(i,s,e){try{return i.apply(s,e)}catch(t){return}}function Hr(i){return function(){return Ze(i,this,arguments)}}let Wr=!1;function jr(){return Wr}function Ki(...i){}var Gr=Object.defineProperty,$r=Object.defineProperties,qr=Object.getOwnPropertyDescriptors,zi=Object.getOwnPropertySymbols,Kr=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable,Ji=(i,s,e)=>s in i?Gr(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Jr=(i,s)=>{for(var e in s||(s={}))Kr.call(s,e)&&Ji(i,e,s[e]);if(zi)for(var e of zi(s))zr.call(s,e)&&Ji(i,e,s[e]);return i},Yr=(i,s)=>$r(i,qr(s));const Yi=1e3,Xi=60*Yi,Zi=60*Xi,Qi=24*Zi,es=365*Qi,Xr=1024,ts="0.1.0";function Zr(){}function is(i){return typeof i=="number"}function Qr(i){return Object.prototype.toString.call(i)==="[object String]"}function ea(i){return Object.prototype.toString.call(i)==="[object Error]"}function ss(i,s){return+i.toFixed(s)}function ta(i,s){return i.indexOf(s)!==-1}function ia(i,s){return i==null?s:!!i}function bt(i){return i?(parseInt(i,10)^Math.random()*16>>parseInt(i,10)/4).toString(16):`10000000-1000-4000-8000-${1e11}`.replace(/[018]/g,bt)}function rs(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 sa(i){return i!==0&&Math.random()<=i}function Rt(i,s){return(...e)=>{try{return i(...e)}catch(t){console.error(s,t)}}}function as(i){return"https://"+i.project+"."+i.host+"/logstores/"+i.logstore+"/track"}function ra(i,s){return s?i.includes(as(s)):i.includes("/track?APIVersion=0.6.0")}const ns=/^(?:([^:\/?#]+):\/\/)?((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i;function aa(i){try{return decodeURIComponent(i)}catch(s){return unescape(i)}}function na(i){return typeof i=="string"&&ns.test(i)}function oa(i){var s=aa(i||"").match(ns);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 ca(i,s,e,t){const r={url:i,method:s,status_code:e};return t==null?r:Yr(Jr({},r),{host:t.host,scheme:t.protocol})}function ua(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 ha(i,s,e){return i===!1?!1:i===!0||i==="error"&&!e?!0:typeof i=="function"?Rt(i,"call shouldTrackBody failed")(s):!1}function la(i){return{relative:i,timeStamp:os(i)}}function os(i){const s=Date.now()-performance.now();return s>Qe()?Math.round(s+i):us(i)}function da(){return Math.round(Date.now()-(Qe()+performance.now()))}function pa(i){return is(i)?ss(i*1e6,0):i}function ai(){return Date.now()}function cs(){return performance.now()}function ga(){return{relative:cs(),timeStamp:ai()}}function ma(){return{relative:0,timeStamp:Qe()}}function Sa(i,s){return s-i}function fa(i){return i-Qe()}function us(i){return Math.round(Qe()+i)}function ba(i){return i<es}let vt;function Qe(){return vt===void 0&&(vt=performance.timing.navigationStart),vt}function Ra(){vt=void 0}const Oe="?";function et(i,s){let e;const t=s===void 0?0:+s;try{if(e=_a(i),e)return e}catch(r){}try{if(e=va(i),e)return e}catch(r){}try{if(e=Ia(i),e)return e}catch(r){}try{if(e=hs(i,t+1),e)return e}catch(r){}return{message:ne(i,"message"),name:ne(i,"name"),stack:[]}}function va(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 g=0,m=u.length;g<m;g+=1){if(e.exec(u[g])){p=e.exec(u[g]);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]||Oe,line:p[3]?+p[3]:void 0,url:f?void 0:p[2]}}else if(r.exec(u[g]))p=r.exec(u[g]),d={args:[],column:p[4]?+p[4]:void 0,func:p[1]||Oe,line:+p[3],url:p[2]};else if(t.exec(u[g]))p=t.exec(u[g]),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):g===0&&!p[5]&&!Ea(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]||Oe,line:p[4]?+p[4]:void 0,url:p[3]};else continue;!d.func&&d.line&&(d.func=Oe),h.push(d)}if(h.length)return{stack:h,message:ne(i,"message"),name:ne(i,"name")}}function _a(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=Oe),u.context=[r[o+1]],a.push(u))}if(a.length)return{stack:a,message:ne(i,"message"),name:ne(i,"name")}}function Ia(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)wa(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=Oe),p.context=[e[l+1]],n.push(p))}if(n.length)return{stack:n,message:e[0],name:ne(i,"name")}}function Aa(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 hs(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=hs.caller;h&&!a;h=h.caller)h!==et&&(o={args:[],column:void 0,func:Oe,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 Aa(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 wa(i,s){return Object.prototype.hasOwnProperty.call(i,s)}function Ea(i){return typeof i>"u"}function ls(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 ni(i,s,{before:e,after:t}){return ls(i,s,r=>function(){const a=arguments;let n;return e&&Ze(e,this,a),typeof r=="function"&&(n=r.apply(this,a)),t&&Ze(t,this,a),n})}const Ta=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function ya(i){const{stop:s}=La(i),{stop:e}=Pa(i);return{stop:()=>{s(),e()}}}function La(i){return ni(window,"onerror",{before(s,e,t,r,a){let n;if(a)n=et(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=Ta.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 Pa(i){return ni(window,"onunhandledrejection",{before(s){const e=s.reason||"Empty reason",t=et(e);i(t,e)}})}function ds(i){return`${i.name||"Error"}: ${i.message}`}function ps(i){return i.filter(s=>s.url==null||!s.url.includes("sls-rum.js"))}function oi(i){let s=ds(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 Ca(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:bt()};i!=null&&i.stack&&t&&(i.stack=ps(i.stack));const a=(r=i==null?void 0:i.stack)==null?void 0:r[0];return{message:encodeURIComponent(i.message||"Empty message"),stacktrace:oi(i),type:i.name,col:a?a.column:void 0,line:a?a.line:void 0,file:encodeURIComponent(a&&a.url?a.url:""),id:bt()}}function ka(){const i=new Error;let s;return Ze(()=>{const e=et(i);e!=null&&e.stack&&(e.stack=ps(e.stack)),s=oi(e)}),s}const Oa=8,Ma=16,ci="b3",ui="traceparent",hi="uber-trace-id",_t=Array(32);function gs(i){for(let s=0;s<i*2;s++)_t[s]=Math.floor(Math.random()*16)+48,_t[s]>=58&&(_t[s]+=39);return String.fromCharCode.apply(null,_t.slice(0,i*2))}function ms(){return gs(Ma)}function li(){return gs(Oa)}function It(i,s){return`${i}-${s}-1`}function At(i,s){return`00-${i}-${s}-01`}function wt(i,s){return`${i}:${s}:0:1`}const Et={b3:{name:ci,getter:It},traceparent:{name:ui,getter:At},uber:{name:hi,getter:wt}};function Na(i,s,e,t){var r;const a=t!=null?t:{};a.headers=(r=a.headers)!=null?r:{},a.headers[ci]=It(i,s),a.headers[ui]=At(i,s),a.headers[hi]=wt(i,s);try{if(e)for(const[n,o]of Object.entries(e))Et[o]&&(a.headers[n]=Et[o].getter(i,s))}catch(n){}return a}function Va(i,s,e,t){i.setRequestHeader(ci,It(s,e)),i.setRequestHeader(ui,At(s,e)),i.setRequestHeader(hi,wt(s,e));try{if(t)for(const[r,a]of Object.entries(t))Et[a]&&i.setRequestHeader(r,Et[a].getter(s,e))}catch(r){}}function tt(i,s,e){i!=null&&Object.keys(i).map(t=>{e==null||e==""?s[t]=i[t]:s[`${e}.${t}`]=i[t]})}var Ua=Object.defineProperty,Da=Object.defineProperties,xa=Object.getOwnPropertyDescriptors,Ss=Object.getOwnPropertySymbols,Fa=Object.prototype.hasOwnProperty,Ba=Object.prototype.propertyIsEnumerable,fs=(i,s,e)=>s in i?Ua(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Ha=(i,s)=>{for(var e in s||(s={}))Fa.call(s,e)&&fs(i,e,s[e]);if(Ss)for(var e of Ss(s))Ba.call(s,e)&&fs(i,e,s[e]);return i},Wa=(i,s)=>Da(i,xa(s));function ja(){return{name:me.InternalPlugin.BASE_TRANSFORM,run:function(){this.subscribe("*",(i,s)=>{const{otBase:e,extra:t}=i;e.attribute=Wa(Ha({},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),tt(this.options.custom,e.attribute,"custom"),tt({env:this.options.env,version:this.options.version},e.attribute),tt({sdk_version:ts,workspace:this.options.workspace},e.resource);const r={otBase:e,extra:t};Ki(me.InternalPlugin.BASE_TRANSFORM,r),s(r)},me.InternalPluginPriority[me.InternalPlugin.BASE_TRANSFORM])}}}function Ga(){return{name:me.InternalPlugin.LOG_SEND,run:function(){}}}function bs(i,s,e){if(s<0)return;const t=a=>{bs(i,s-1,a)},r=i[s];Rt(()=>{r.callback.call(void 0,e,t)},"plugin notify run error")()}class $a{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:[];bs(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 qa(){const i=ms();let s=li();return{getSessionId:()=>i,getPageId:()=>s,refreshPageId:()=>{s=li()}}}var Ka=Object.defineProperty,za=Object.defineProperties,Ja=Object.getOwnPropertyDescriptors,Rs=Object.getOwnPropertySymbols,Ya=Object.prototype.hasOwnProperty,Xa=Object.prototype.propertyIsEnumerable,vs=(i,s,e)=>s in i?Ka(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,Za=(i,s)=>{for(var e in s||(s={}))Ya.call(s,e)&&vs(i,e,s[e]);if(Rs)for(var e of Rs(s))Xa.call(s,e)&&vs(i,e,s[e]);return i},Qa=(i,s)=>za(i,Ja(s));const en=["uid","nickname","env","service","version","custom"];class tn{constructor(s){this.isInit=!1,this.pendingPlugins=[],this.pluginMap={},this.session=qa();var e,t;this.options=s,this.use(Ga()),this.use(ja()),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=Qa(Za({},this.context),{subscribe:(t,r,a)=>{this.sub.subscribe(s.name,t,r,a)},notify:t=>{this.sub.notify(s.name,t)}});Rt(()=>s.run.call(e),`plugin ${s.name} init failed`)()}addLog(s){if(this.isInit){const e={t:me.WebEventType.LOG};tt(s,e,me.WebEventType.LOG);const t={start:ai()*1e3,attribute:e,resource:{}};this.sub.notify(me.InternalPlugin.LOG_SEND,{otBase:t,extra:{}})}else console.error("log should call after start")}setOptions(s){this.isInit?en.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(me.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(me.SLS_TRACE_UID_KEY)),(s==null||s==="")&&(s=rs())),this.options.uid=s,typeof this.setLocalStorage=="function"&&this.setLocalStorage(me.SLS_TRACE_UID_KEY,s);const e=this.pendingPlugins.map(t=>t==null?void 0:t.name).filter(t=>t!=null);this.sub=new $a(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 sn=Object.defineProperty,_s=Object.getOwnPropertySymbols,rn=Object.prototype.hasOwnProperty,an=Object.prototype.propertyIsEnumerable,Is=(i,s,e)=>s in i?sn(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,nn=(i,s)=>{for(var e in s||(s={}))rn.call(s,e)&&Is(i,e,s[e]);if(_s)for(var e of _s(s))an.call(s,e)&&Is(i,e,s[e]);return i};function on(i,s){var e;const t={current:void 0},r=[];let a={};return typeof s=="function"&&(a=(e=s(t))!=null?e:{}),nn({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 cn{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)}})}}w.ONE_DAY=Qi,w.ONE_HOUR=Zi,w.ONE_KILO_BYTE=Xr,w.ONE_MINUTE=Xi,w.ONE_SECOND=Yi,w.ONE_YEAR=es,w.Observable=Br,w.SDK_VERSION=ts,w.SLSClient=tn,w.Subscribe=cn,w.assembleOTAttribute=tt,w.buildHttpInfo=ca,w.callMonitored=Ze,w.catchUserErrors=Rt,w.clocksNow=ga,w.clocksOrigin=ma,w.computeStackTrace=et,w.createHandlingStack=ka,w.currentDrift=da,w.debugLog=Ki,w.defineGlobal=Fr,w.defineGlobalValue=ri,w.elapsed=Sa,w.formatErrorMessage=ds,w.formatUnknownError=Ca,w.genUid=rs,w.generateSpanId=li,w.generateTraceId=ms,w.generateUUID=bt,w.getB3Header=It,w.getConsoleLogStatus=jr,w.getCorrectedTimeStamp=os,w.getJaegerTraceHeaderr=wt,w.getRelativeTime=fa,w.getTimeStamp=us,w.getTrackUrl=as,w.getW3CTraceHeader=At,w.includes=ta,w.instrumentMethod=ls,w.instrumentMethodAndCallOriginal=ni,w.isError=ea,w.isInternalUrl=ra,w.isNumber=is,w.isString=Qr,w.isURL=na,w.looksLikeRelativeTime=ba,w.makeWebPublicApi=on,w.matchCondition=ua,w.matchSample=sa,w.matchWithDefault=ia,w.monitor=Hr,w.noop=Zr,w.parseUri=oa,w.patchHeaderOnRequest=Na,w.patchHeaderOnXhr=Va,w.relativeNow=cs,w.relativeToClocks=la,w.resetNavigationStart=Ra,w.round=ss,w.shouldTrackBody=ha,w.startUnhandledErrorCollection=ya,w.timeStampNow=ai,w.toServerDuration=pa,w.toStackTraceString=oi;var un=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()}},hn=w,ln=un;function dn(i,s){return navigator&&navigator.sendBeacon?navigator.sendBeacon(`${i}?APIVersion=0.6.0`,s):!1}function pn(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 gn(i,s){try{dn(i,s)||pn(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 As extends ln{constructor(s){const e=Object.assign({},s,{installUnloadHook:t=>{window.addEventListener("beforeunload",()=>{t()})},sendPayload:(t,r)=>{gn(t,r)}});super(e)}}hn.defineGlobal(window,"SLS_Tracker",As);var mn=As,Tt={},Sn={get exports(){return Tt},set exports(i){Tt=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",g="name",m="type",f="vendor",b="version",M="architecture",H="console",P="mobile",N="tablet",re="smarttv",Te="wearable",vi="embedded",_i=350,Ot="Amazon",st="Apple",xs="ASUS",Fs="BlackBerry",Fe="Browser",Mt="Chrome",Kn="Edge",Nt="Firefox",Vt="Google",Bs="Huawei",Ii="LG",Ai="Microsoft",Hs="Motorola",Ut="Opera",wi="Samsung",Ws="Sharp",Dt="Sony",Ei="Xiaomi",Ti="Zebra",js="Facebook",Gs="Chromium OS",$s="Mac OS",zn=function(U,W){var O={};for(var $ in U)W[$]&&W[$].length%2===0?O[$]=W[$].concat(U[$]):O[$]=U[$];return O},xt=function(U){for(var W={},O=0;O<U.length;O++)W[U[O].toUpperCase()]=U[O];return W},qs=function(U,W){return typeof U===l?rt(W).indexOf(rt(U))!==-1:!1},rt=function(U){return U.toLowerCase()},Jn=function(U){return typeof U===l?U.replace(/[^\d\.]/g,a).split(".")[0]:t},yi=function(U,W){if(typeof U===l)return U=U.replace(/^\s\s*/,a),typeof W===u?U:U.substring(0,_i)},at=function(U,W){for(var O=0,$,ye,ve,B,C,Ae;O<W.length&&!C;){var Pi=W[O],Js=W[O+1];for($=ye=0;$<Pi.length&&!C&&Pi[$];)if(C=Pi[$++].exec(U),C)for(ve=0;ve<Js.length;ve++)Ae=C[++ye],B=Js[ve],typeof B===h&&B.length>0?B.length===2?typeof B[1]==o?this[B[0]]=B[1].call(this,Ae):this[B[0]]=B[1]:B.length===3?typeof B[1]===o&&!(B[1].exec&&B[1].test)?this[B[0]]=Ae?B[1].call(this,Ae,B[2]):t:this[B[0]]=Ae?Ae.replace(B[1],B[2]):t:B.length===4&&(this[B[0]]=Ae?B[3].call(this,Ae.replace(B[1],B[2])):t):this[B]=Ae||t;O+=2}},Li=function(U,W){for(var O in W)if(typeof W[O]===h&&W[O].length>0){for(var $=0;$<W[O].length;$++)if(qs(W[O][$],U))return O===n?t:O}else if(qs(W[O],U))return O===n?t:O;return U},Yn={"1.0":"/8","1.2":"/1","1.3":"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"},Ks={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"},zs={browser:[[/\b(?:crmo|crios)\/([\w\.]+)/i],[b,[g,"Chrome"]],[/edg(?:e|ios|a)?\/([\w\.]+)/i],[b,[g,"Edge"]],[/(opera mini)\/([-\w\.]+)/i,/(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i,/(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i],[g,b],[/opios[\/ ]+([\w\.]+)/i],[b,[g,Ut+" Mini"]],[/\bopr\/([\w\.]+)/i],[b,[g,Ut]],[/(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],[g,b],[/(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i],[b,[g,"UC"+Fe]],[/microm.+\bqbcore\/([\w\.]+)/i,/\bqbcore\/([\w\.]+).+microm/i],[b,[g,"WeChat(Win) Desktop"]],[/micromessenger\/([\w\.]+)/i],[b,[g,"WeChat"]],[/konqueror\/([\w\.]+)/i],[b,[g,"Konqueror"]],[/trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i],[b,[g,"IE"]],[/ya(?:search)?browser\/([\w\.]+)/i],[b,[g,"Yandex"]],[/(avast|avg)\/([\w\.]+)/i],[[g,/(.+)/,"$1 Secure "+Fe],b],[/\bfocus\/([\w\.]+)/i],[b,[g,Nt+" Focus"]],[/\bopt\/([\w\.]+)/i],[b,[g,Ut+" Touch"]],[/coc_coc\w+\/([\w\.]+)/i],[b,[g,"Coc Coc"]],[/dolfin\/([\w\.]+)/i],[b,[g,"Dolphin"]],[/coast\/([\w\.]+)/i],[b,[g,Ut+" Coast"]],[/miuibrowser\/([\w\.]+)/i],[b,[g,"MIUI "+Fe]],[/fxios\/([-\w\.]+)/i],[b,[g,Nt]],[/\bqihu|(qi?ho?o?|360)browser/i],[[g,"360 "+Fe]],[/(oculus|samsung|sailfish|huawei)browser\/([\w\.]+)/i],[[g,/(.+)/,"$1 "+Fe],b],[/(comodo_dragon)\/([\w\.]+)/i],[[g,/_/g," "],b],[/(electron)\/([\w\.]+) safari/i,/(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i,/m?(qqbrowser|baiduboxapp|2345Explorer)[\/ ]?([\w\.]+)/i],[g,b],[/(metasr)[\/ ]?([\w\.]+)/i,/(lbbrowser)/i,/\[(linkedin)app\]/i],[g],[/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i],[[g,js],b],[/(kakao(?:talk|story))[\/ ]([\w\.]+)/i,/(naver)\(.*?(\d+\.[\w\.]+).*\)/i,/safari (line)\/([\w\.]+)/i,/\b(line)\/([\w\.]+)\/iab/i,/(chromium|instagram)[\/ ]([-\w\.]+)/i],[g,b],[/\bgsa\/([\w\.]+) .*safari\//i],[b,[g,"GSA"]],[/musical_ly(?:.+app_?version\/|_)([\w\.]+)/i],[b,[g,"TikTok"]],[/headlesschrome(?:\/([\w\.]+)| )/i],[b,[g,Mt+" Headless"]],[/ wv\).+(chrome)\/([\w\.]+)/i],[[g,Mt+" WebView"],b],[/droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i],[b,[g,"Android "+Fe]],[/(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i],[g,b],[/version\/([\w\.\,]+) .*mobile\/\w+ (safari)/i],[b,[g,"Mobile Safari"]],[/version\/([\w(\.|\,)]+) .*(mobile ?safari|safari)/i],[b,g],[/webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i],[g,[b,Li,Yn]],[/(webkit|khtml)\/([\w\.]+)/i],[g,b],[/(navigator|netscape\d?)\/([-\w\.]+)/i],[[g,"Netscape"],b],[/mobile vr; rv:([\w\.]+)\).+firefox/i],[b,[g,Nt+" 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],[g,b],[/(cobalt)\/([\w\.]+)/i],[g,[b,/master.|lts./,""]]],cpu:[[/(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i],[[M,"amd64"]],[/(ia32(?=;))/i],[[M,rt]],[/((?:i[346]|x)86)[;\)]/i],[[M,"ia32"]],[/\b(aarch64|arm(v?8e?l?|_?64))\b/i],[[M,"arm64"]],[/\b(arm(?:v[67])?ht?n?[fl]p?)\b/i],[[M,"armhf"]],[/windows (ce|mobile); ppc;/i],[[M,"arm"]],[/((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i],[[M,/ower/,a,rt]],[/(sun4\w)[;\)]/i],[[M,"sparc"]],[/((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i],[[M,rt]]],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,wi],[m,N]],[/\b((?:s[cgp]h|gt|sm)-\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,/samsung[- ]([-\w]+)/i,/sec-(sgh\w+)/i],[d,[f,wi],[m,P]],[/(?:\/|\()(ip(?:hone|od)[\w, ]*)(?:\/|;)/i],[d,[f,st],[m,P]],[/\((ipad);[-\w\),; ]+apple/i,/applecoremedia\/[\w\.]+ \((ipad)/i,/\b(ipad)\d\d?,\d\d?[;\]].+ios/i],[d,[f,st],[m,N]],[/(macintosh);/i],[d,[f,st]],[/\b(sh-?[altvz]?\d\d[a-ekm]?)/i],[d,[f,Ws],[m,P]],[/\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i],[d,[f,Bs],[m,N]],[/(?:huawei|honor)([-\w ]+)[;\)]/i,/\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i],[d,[f,Bs],[m,P]],[/\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,Ei],[m,P]],[/\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i],[[d,/_/g," "],[f,Ei],[m,N]],[/; (\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"],[m,P]],[/vivo (\w+)(?: bui|\))/i,/\b(v[12]\d{3}\w?[at])(?: bui|;)/i],[d,[f,"Vivo"],[m,P]],[/\b(rmx[12]\d{3})(?: bui|;|\))/i],[d,[f,"Realme"],[m,P]],[/\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,Hs],[m,P]],[/\b(mz60\d|xoom[2 ]{0,2}) build\//i],[d,[f,Hs],[m,N]],[/((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i],[d,[f,Ii],[m,N]],[/(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,/\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,/\blg-?([\d\w]+) bui/i],[d,[f,Ii],[m,P]],[/(ideatab[-\w ]+)/i,/lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i],[d,[f,"Lenovo"],[m,N]],[/(?:maemo|nokia).*(n900|lumia \d+)/i,/nokia[-_ ]?([-\w\.]*)/i],[[d,/_/g," "],[f,"Nokia"],[m,P]],[/(pixel c)\b/i],[d,[f,Vt],[m,N]],[/droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i],[d,[f,Vt],[m,P]],[/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,Dt],[m,P]],[/sony tablet [ps]/i,/\b(?:sony)?sgp\w+(?: bui|\))/i],[[d,"Xperia Tablet"],[f,Dt],[m,N]],[/ (kb2005|in20[12]5|be20[12][59])\b/i,/(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i],[d,[f,"OnePlus"],[m,P]],[/(alexa)webm/i,/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i,/(kf[a-z]+)( bui|\)).+silk\//i],[d,[f,Ot],[m,N]],[/((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i],[[d,/(.+)/g,"Fire Phone $1"],[f,Ot],[m,P]],[/(playbook);[-\w\),; ]+(rim)/i],[d,f,[m,N]],[/\b((?:bb[a-f]|st[hv])100-\d)/i,/\(bb10; (\w+)/i],[d,[f,Fs],[m,P]],[/(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i],[d,[f,xs],[m,N]],[/ (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i],[d,[f,xs],[m,P]],[/(nexus 9)/i],[d,[f,"HTC"],[m,N]],[/(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i,/(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,/(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i],[f,[d,/_/g," "],[m,P]],[/droid.+; ([ab][1-7]-?[0178a]\d\d?)/i],[d,[f,"Acer"],[m,N]],[/droid.+; (m[1-5] note) bui/i,/\bmz-([-\w]{2,})/i],[d,[f,"Meizu"],[m,P]],[/(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,[m,P]],[/(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,[m,N]],[/(surface duo)/i],[d,[f,Ai],[m,N]],[/droid [\d\.]+; (fp\du?)(?: b|\))/i],[d,[f,"Fairphone"],[m,P]],[/(u304aa)/i],[d,[f,"AT&T"],[m,P]],[/\bsie-(\w*)/i],[d,[f,"Siemens"],[m,P]],[/\b(rct\w+) b/i],[d,[f,"RCA"],[m,N]],[/\b(venue[\d ]{2,7}) b/i],[d,[f,"Dell"],[m,N]],[/\b(q(?:mv|ta)\w+) b/i],[d,[f,"Verizon"],[m,N]],[/\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i],[d,[f,"Barnes & Noble"],[m,N]],[/\b(tm\d{3}\w+) b/i],[d,[f,"NuVision"],[m,N]],[/\b(k88) b/i],[d,[f,"ZTE"],[m,N]],[/\b(nx\d{3}j) b/i],[d,[f,"ZTE"],[m,P]],[/\b(gen\d{3}) b.+49h/i],[d,[f,"Swiss"],[m,P]],[/\b(zur\d{3}) b/i],[d,[f,"Swiss"],[m,N]],[/\b((zeki)?tb.*\b) b/i],[d,[f,"Zeki"],[m,N]],[/\b([yr]\d{2}) b/i,/\b(dragon[- ]+touch |dt)(\w{5}) b/i],[[f,"Dragon Touch"],d,[m,N]],[/\b(ns-?\w{0,9}) b/i],[d,[f,"Insignia"],[m,N]],[/\b((nxa|next)-?\w{0,9}) b/i],[d,[f,"NextBook"],[m,N]],[/\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i],[[f,"Voice"],d,[m,P]],[/\b(lvtel\-)?(v1[12]) b/i],[[f,"LvTel"],d,[m,P]],[/\b(ph-1) /i],[d,[f,"Essential"],[m,P]],[/\b(v(100md|700na|7011|917g).*\b) b/i],[d,[f,"Envizen"],[m,N]],[/\b(trio[-\w\. ]+) b/i],[d,[f,"MachSpeed"],[m,N]],[/\btu_(1491) b/i],[d,[f,"Rotor"],[m,N]],[/(shield[\w ]+) b/i],[d,[f,"Nvidia"],[m,N]],[/(sprint) (\w+)/i],[f,d,[m,P]],[/(kin\.[onetw]{3})/i],[[d,/\./g," "],[f,Ai],[m,P]],[/droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i],[d,[f,Ti],[m,N]],[/droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i],[d,[f,Ti],[m,P]],[/smart-tv.+(samsung)/i],[f,[m,re]],[/hbbtv.+maple;(\d+)/i],[[d,/^/,"SmartTV"],[f,wi],[m,re]],[/(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i],[[f,Ii],[m,re]],[/(apple) ?tv/i],[f,[d,st+" TV"],[m,re]],[/crkey/i],[[d,Mt+"cast"],[f,Vt],[m,re]],[/droid.+aft(\w)( bui|\))/i],[d,[f,Ot],[m,re]],[/\(dtv[\);].+(aquos)/i,/(aquos-tv[\w ]+)\)/i],[d,[f,Ws],[m,re]],[/(bravia[\w ]+)( bui|\))/i],[d,[f,Dt],[m,re]],[/(mitv-\w{5}) bui/i],[d,[f,Ei],[m,re]],[/Hbbtv.*(technisat) (.*);/i],[f,d,[m,re]],[/\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i,/hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i],[[f,yi],[d,yi],[m,re]],[/\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i],[[m,re]],[/(ouya)/i,/(nintendo) ([wids3utch]+)/i],[f,d,[m,H]],[/droid.+; (shield) bui/i],[d,[f,"Nvidia"],[m,H]],[/(playstation [345portablevi]+)/i],[d,[f,Dt],[m,H]],[/\b(xbox(?: one)?(?!; xbox))[\); ]/i],[d,[f,Ai],[m,H]],[/((pebble))app/i],[f,d,[m,Te]],[/(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i],[d,[f,st],[m,Te]],[/droid.+; (glass) \d/i],[d,[f,Vt],[m,Te]],[/droid.+; (wt63?0{2,3})\)/i],[d,[f,Ti],[m,Te]],[/(quest( 2| pro)?)/i],[d,[f,js],[m,Te]],[/(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i],[f,[m,vi]],[/(aeobc)\b/i],[d,[f,Ot],[m,vi]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+? mobile safari/i],[d,[m,P]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i],[d,[m,N]],[/\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i],[[m,N]],[/(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i],[[m,P]],[/(android[-\w\. ]{0,9});.+buil/i],[d,[f,"Generic"]]],engine:[[/windows.+ edge\/([\w\.]+)/i],[b,[g,Kn+"HTML"]],[/webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i],[b,[g,"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],[g,b],[/rv\:([\w\.]{1,9})\b.+(gecko)/i],[b,g]],os:[[/microsoft (windows) (vista|xp)/i],[g,b],[/(windows) nt 6\.2; (arm)/i,/(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i,/(windows)[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i],[g,[b,Li,Ks]],[/(win(?=3|9|n)|win 9x )([nt\d\.]+)/i],[[g,"Windows"],[b,Li,Ks]],[/ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i,/ios;fbsv\/([\d\.]+)/i,/cfnetwork\/.+darwin/i],[[b,/_/g,"."],[g,"iOS"]],[/(mac os x) ?([\w\. ]*)/i,/(macintosh|mac_powerpc\b)(?!.+haiku)/i],[[g,$s],[b,/_/g,"."]],[/droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i],[b,g],[/(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,/(blackberry)\w*\/([\w\.]*)/i,/(tizen|kaios)[\/ ]([\w\.]+)/i,/\((series40);/i],[g,b],[/\(bb(10);/i],[b,[g,Fs]],[/(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i],[b,[g,"Symbian"]],[/mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i],[b,[g,Nt+" OS"]],[/web0s;.+rt(tv)/i,/\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i],[b,[g,"webOS"]],[/watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i],[b,[g,"watchOS"]],[/crkey\/([\d\.]+)/i],[b,[g,Mt+"cast"]],[/(cros) [\w]+(?:\)| ([\w\.]+)\b)/i],[[g,Gs],b],[/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],[g,b],[/(sunos) ?([\w\.\d]*)/i],[[g,"Solaris"],b],[/((?:open)?solaris)[-\/ ]?([\w\.]*)/i,/(aix) ((\d)(?=\.|\)| )[\w\.])*/i,/\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux|serenityos)/i,/(unix) ?([\w\.]*)/i],[g,b]]},Se=function(U,W){if(typeof U===h&&(W=U,U=t),!(this instanceof Se))return new Se(U,W).getResult();var O=typeof e!==u&&e.navigator?e.navigator:t,$=U||(O&&O.userAgent?O.userAgent:a),ye=O&&O.userAgentData?O.userAgentData:t,ve=W?zn(zs,W):zs,B=O&&O.userAgent==$;return this.getBrowser=function(){var C={};return C[g]=t,C[b]=t,at.call(C,$,ve.browser),C[p]=Jn(C[b]),B&&O&&O.brave&&typeof O.brave.isBrave==o&&(C[g]="Brave"),C},this.getCPU=function(){var C={};return C[M]=t,at.call(C,$,ve.cpu),C},this.getDevice=function(){var C={};return C[f]=t,C[d]=t,C[m]=t,at.call(C,$,ve.device),B&&!C[m]&&ye&&ye.mobile&&(C[m]=P),B&&C[d]=="Macintosh"&&O&&typeof O.standalone!==u&&O.maxTouchPoints&&O.maxTouchPoints>2&&(C[d]="iPad",C[m]=N),C},this.getEngine=function(){var C={};return C[g]=t,C[b]=t,at.call(C,$,ve.engine),C},this.getOS=function(){var C={};return C[g]=t,C[b]=t,at.call(C,$,ve.os),B&&!C[g]&&ye&&ye.platform!="Unknown"&&(C[g]=ye.platform.replace(/chrome os/i,Gs).replace(/macos/i,$s)),C},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 $},this.setUA=function(C){return $=typeof C===l&&C.length>_i?yi(C,_i):C,this},this.setUA($),this};Se.VERSION=r,Se.BROWSER=xt([g,b,p]),Se.CPU=xt([M]),Se.DEVICE=xt([d,f,m,H,P,re,N,Te,vi]),Se.ENGINE=Se.OS=xt([g,b]),i.exports&&(s=i.exports=Se),s.UAParser=Se;var Be=typeof e!==u&&(e.jQuery||e.Zepto);if(Be&&!Be.ua){var Ft=new Se;Be.ua=Ft.getResult(),Be.ua.get=function(){return Ft.getUA()},Be.ua.set=function(U){Ft.setUA(U);var W=Ft.getResult();for(var O in W)Be.ua[O]=W[O]}}})(typeof window=="object"?window:Vr)})(Sn,Tt);let yt;const fn=new Uint8Array(16);function bn(){if(!yt&&(yt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!yt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return yt(fn)}const se=[];for(let i=0;i<256;++i)se.push((i+256).toString(16).slice(1));function Rn(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 vn=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ws={randomUUID:vn};function _n(i,s,e){if(ws.randomUUID&&!s&&!i)return ws.randomUUID();i=i||{};const t=i.random||(i.rng||bn)();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 Rn(t)}var di={},In={get exports(){return di},set exports(i){di=i}},pi={},An={get exports(){return pi},set exports(i){pi=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}};An.exports=s})();var gi={utf8:{stringToBytes:function(i){return gi.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(gi.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("")}}},Es=gi;/*!
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 En=function(i){return i!=null&&(Es(i)||Tn(i)||!!i._isBuffer)};function Es(i){return!!i.constructor&&typeof i.constructor.isBuffer=="function"&&i.constructor.isBuffer(i)}function Tn(i){return typeof i.readFloatLE=="function"&&typeof i.slice=="function"&&Es(i.slice(0,0))}(function(){var i=di,s=ws.utf8,e=En,t=ws.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,g=0;g<o.length;g++)o[g]=(o[g]<<8|o[g]>>>24)&16711935|(o[g]<<24|o[g]>>>8)&4278255360;o[u>>>5]|=128<<u%32,o[(u+64>>>9<<4)+14]=u;for(var m=r._ff,f=r._gg,b=r._hh,M=r._ii,g=0;g<o.length;g+=16){var H=h,P=l,N=p,re=d;h=m(h,l,p,d,o[g+0],7,-680876936),d=m(d,h,l,p,o[g+1],12,-389564586),p=m(p,d,h,l,o[g+2],17,606105819),l=m(l,p,d,h,o[g+3],22,-1044525330),h=m(h,l,p,d,o[g+4],7,-176418897),d=m(d,h,l,p,o[g+5],12,1200080426),p=m(p,d,h,l,o[g+6],17,-1473231341),l=m(l,p,d,h,o[g+7],22,-45705983),h=m(h,l,p,d,o[g+8],7,1770035416),d=m(d,h,l,p,o[g+9],12,-1958414417),p=m(p,d,h,l,o[g+10],17,-42063),l=m(l,p,d,h,o[g+11],22,-1990404162),h=m(h,l,p,d,o[g+12],7,1804603682),d=m(d,h,l,p,o[g+13],12,-40341101),p=m(p,d,h,l,o[g+14],17,-1502002290),l=m(l,p,d,h,o[g+15],22,1236535329),h=f(h,l,p,d,o[g+1],5,-165796510),d=f(d,h,l,p,o[g+6],9,-1069501632),p=f(p,d,h,l,o[g+11],14,643717713),l=f(l,p,d,h,o[g+0],20,-373897302),h=f(h,l,p,d,o[g+5],5,-701558691),d=f(d,h,l,p,o[g+10],9,38016083),p=f(p,d,h,l,o[g+15],14,-660478335),l=f(l,p,d,h,o[g+4],20,-405537848),h=f(h,l,p,d,o[g+9],5,568446438),d=f(d,h,l,p,o[g+14],9,-1019803690),p=f(p,d,h,l,o[g+3],14,-187363961),l=f(l,p,d,h,o[g+8],20,1163531501),h=f(h,l,p,d,o[g+13],5,-1444681467),d=f(d,h,l,p,o[g+2],9,-51403784),p=f(p,d,h,l,o[g+7],14,1735328473),l=f(l,p,d,h,o[g+12],20,-1926607734),h=b(h,l,p,d,o[g+5],4,-378558),d=b(d,h,l,p,o[g+8],11,-2022574463),p=b(p,d,h,l,o[g+11],16,1839030562),l=b(l,p,d,h,o[g+14],23,-35309556),h=b(h,l,p,d,o[g+1],4,-1530992060),d=b(d,h,l,p,o[g+4],11,1272893353),p=b(p,d,h,l,o[g+7],16,-155497632),l=b(l,p,d,h,o[g+10],23,-1094730640),h=b(h,l,p,d,o[g+13],4,681279174),d=b(d,h,l,p,o[g+0],11,-358537222),p=b(p,d,h,l,o[g+3],16,-722521979),l=b(l,p,d,h,o[g+6],23,76029189),h=b(h,l,p,d,o[g+9],4,-640364487),d=b(d,h,l,p,o[g+12],11,-421815835),p=b(p,d,h,l,o[g+15],16,530742520),l=b(l,p,d,h,o[g+2],23,-995338651),h=M(h,l,p,d,o[g+0],6,-198630844),d=M(d,h,l,p,o[g+7],10,1126891415),p=M(p,d,h,l,o[g+14],15,-1416354905),l=M(l,p,d,h,o[g+5],21,-57434055),h=M(h,l,p,d,o[g+12],6,1700485571),d=M(d,h,l,p,o[g+3],10,-1894986606),p=M(p,d,h,l,o[g+10],15,-1051523),l=M(l,p,d,h,o[g+1],21,-2054922799),h=M(h,l,p,d,o[g+8],6,1873313359),d=M(d,h,l,p,o[g+15],10,-30611744),p=M(p,d,h,l,o[g+6],15,-1560198380),l=M(l,p,d,h,o[g+13],21,1309151649),h=M(h,l,p,d,o[g+4],6,-145523070),d=M(d,h,l,p,o[g+11],10,-1120210379),p=M(p,d,h,l,o[g+2],15,718787259),l=M(l,p,d,h,o[g+9],21,-343485551),h=h+H>>>0,l=l+P>>>0,p=p+N>>>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,An.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 yn(i){return i?i.toLowerCase().indexOf("android")>=0||i.toLowerCase().indexOf("ios")>=0?"h5":"pc":"unknown"}function Ln(i){const s=li(i),e=localStorage.getItem(s);if(e&&e.length===36)return e;const t=In();return localStorage.setItem(s,t),t}var Lt,Pt,it;class Ts{constructor(s){ti(this,Lt,void 0),ti(this,Pt,void 0),ti(this,it,void 0);const u=s,{commonParams:e,version:t}=u,r=Xs(u,["commonParams","version"]);ii(this,Lt,new Sn(r)),ii(this,it,Ln(r.project));const a=new Tt;a.setUA(window.navigator.userAgent);const n=a.getResult(),o=x({av:t,os:n.os.name,ov:n.os.version,bt:n.browser.name,bv:n.browser.version,tt:yn(n.os.name),uuid:ft(this,it),host:window.location.host},e);ii(this,Pt,o)}getUUID(){return ft(this,it)}send(s,e,t){ft(this,Lt).send(x(x({msgId:String(s),args:typeof e=="string"?e:new URLSearchParams(e).toString(),pu:window.location.href,ct:Date.now().toString()},ft(this,Pt)),t))}}Lt=new WeakMap,Pt=new WeakMap,it=new WeakMap;class Pn{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 Ts({version:We,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=He(x({},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,g=a/p,m=n/p,f=n/a;this.report(10080,{calid:"",rmtid:s,tckid:u,ssrc:t,codec:l,rbr:d,pr:g,pl:m,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:g,totalInterFrameDelay:m,codec:f}=e,b=m,M=r/b,H=n/b,P=o/b,N=d/b,re=g/b,Te=g/d;this.report(10080,{calid:"",rmtid:s,tckid:a,ssrc:t,codec:f,rbr:M,dfps:H,rfps:P,rh:u,rw:h,ns:l,jd:p,pr:N,pl:re,plr:Te})}report(s,e,t){var r;this.enable&&((r=this.tracker)==null||r.send(s,e,x(x({},this.commonParams),t!=null?t:{})))}static reportCheck(s,e){new Ts({version:We,host:"cn-hangzhou.log.aliyuncs.com",project:"web-rtc-grtn",logstore:"client",time:5,count:10,source:e!=null?e:""}).send(100001,s)}}class Cn{constructor(){c(this,"reporter");c(this,"param");c(this,"msgCacheArr",[]);c(this,"index",0)}start(s){this.initParam(s),this.reporter=new nt.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){_.info(s),this.msgCacheArr.length===0&&this.param?this.realSendReport(s):this.msgCacheArr.push(s)}initParam(s){this.param||(this.param={osn:L.SystemUtil.systemName,osv:L.SystemUtil.systemVersion,udid:L.LocalStorage.uuid,statsvrs:"0.6.1",sdkvrs:We,dm:L.BrowserUtil.domain,bt:L.BrowserUtil.browserName,bv:L.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 kn{constructor(){c(this,"logClient");this.logClient=new Cn}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 ys{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(ys,"LEVEL",0);class On{constructor(){c(this,"logger",new ys("AudioMixer"));c(this,"audioContext",new AudioContext);c(this,"audioDestination",this.audioContext.createMediaStreamDestination());c(this,"audioTrack",Ar(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 Mn=4;class Nn extends Ve{constructor(){super("audioMixer",ee.AliRtcSdkStreamTypeCapture,ut.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!==ee.AliRtcSdkStreamTypeCapture)return!1;const r=t.find(u=>u.type===ee.AliRtcSdkStreamTypeCapture),a=t.find(u=>u.type===ee.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===ee.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 On),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<=Mn}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 gi{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 Vn extends gi{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 Dn=`
11
+ */var wn=function(i){return i!=null&&(Ts(i)||En(i)||!!i._isBuffer)};function Ts(i){return!!i.constructor&&typeof i.constructor.isBuffer=="function"&&i.constructor.isBuffer(i)}function En(i){return typeof i.readFloatLE=="function"&&typeof i.slice=="function"&&Ts(i.slice(0,0))}(function(){var i=pi,s=Es.utf8,e=wn,t=Es.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,g=0;g<o.length;g++)o[g]=(o[g]<<8|o[g]>>>24)&16711935|(o[g]<<24|o[g]>>>8)&4278255360;o[u>>>5]|=128<<u%32,o[(u+64>>>9<<4)+14]=u;for(var m=r._ff,f=r._gg,b=r._hh,M=r._ii,g=0;g<o.length;g+=16){var H=h,P=l,N=p,re=d;h=m(h,l,p,d,o[g+0],7,-680876936),d=m(d,h,l,p,o[g+1],12,-389564586),p=m(p,d,h,l,o[g+2],17,606105819),l=m(l,p,d,h,o[g+3],22,-1044525330),h=m(h,l,p,d,o[g+4],7,-176418897),d=m(d,h,l,p,o[g+5],12,1200080426),p=m(p,d,h,l,o[g+6],17,-1473231341),l=m(l,p,d,h,o[g+7],22,-45705983),h=m(h,l,p,d,o[g+8],7,1770035416),d=m(d,h,l,p,o[g+9],12,-1958414417),p=m(p,d,h,l,o[g+10],17,-42063),l=m(l,p,d,h,o[g+11],22,-1990404162),h=m(h,l,p,d,o[g+12],7,1804603682),d=m(d,h,l,p,o[g+13],12,-40341101),p=m(p,d,h,l,o[g+14],17,-1502002290),l=m(l,p,d,h,o[g+15],22,1236535329),h=f(h,l,p,d,o[g+1],5,-165796510),d=f(d,h,l,p,o[g+6],9,-1069501632),p=f(p,d,h,l,o[g+11],14,643717713),l=f(l,p,d,h,o[g+0],20,-373897302),h=f(h,l,p,d,o[g+5],5,-701558691),d=f(d,h,l,p,o[g+10],9,38016083),p=f(p,d,h,l,o[g+15],14,-660478335),l=f(l,p,d,h,o[g+4],20,-405537848),h=f(h,l,p,d,o[g+9],5,568446438),d=f(d,h,l,p,o[g+14],9,-1019803690),p=f(p,d,h,l,o[g+3],14,-187363961),l=f(l,p,d,h,o[g+8],20,1163531501),h=f(h,l,p,d,o[g+13],5,-1444681467),d=f(d,h,l,p,o[g+2],9,-51403784),p=f(p,d,h,l,o[g+7],14,1735328473),l=f(l,p,d,h,o[g+12],20,-1926607734),h=b(h,l,p,d,o[g+5],4,-378558),d=b(d,h,l,p,o[g+8],11,-2022574463),p=b(p,d,h,l,o[g+11],16,1839030562),l=b(l,p,d,h,o[g+14],23,-35309556),h=b(h,l,p,d,o[g+1],4,-1530992060),d=b(d,h,l,p,o[g+4],11,1272893353),p=b(p,d,h,l,o[g+7],16,-155497632),l=b(l,p,d,h,o[g+10],23,-1094730640),h=b(h,l,p,d,o[g+13],4,681279174),d=b(d,h,l,p,o[g+0],11,-358537222),p=b(p,d,h,l,o[g+3],16,-722521979),l=b(l,p,d,h,o[g+6],23,76029189),h=b(h,l,p,d,o[g+9],4,-640364487),d=b(d,h,l,p,o[g+12],11,-421815835),p=b(p,d,h,l,o[g+15],16,530742520),l=b(l,p,d,h,o[g+2],23,-995338651),h=M(h,l,p,d,o[g+0],6,-198630844),d=M(d,h,l,p,o[g+7],10,1126891415),p=M(p,d,h,l,o[g+14],15,-1416354905),l=M(l,p,d,h,o[g+5],21,-57434055),h=M(h,l,p,d,o[g+12],6,1700485571),d=M(d,h,l,p,o[g+3],10,-1894986606),p=M(p,d,h,l,o[g+10],15,-1051523),l=M(l,p,d,h,o[g+1],21,-2054922799),h=M(h,l,p,d,o[g+8],6,1873313359),d=M(d,h,l,p,o[g+15],10,-30611744),p=M(p,d,h,l,o[g+6],15,-1560198380),l=M(l,p,d,h,o[g+13],21,1309151649),h=M(h,l,p,d,o[g+4],6,-145523070),d=M(d,h,l,p,o[g+11],10,-1120210379),p=M(p,d,h,l,o[g+2],15,718787259),l=M(l,p,d,h,o[g+9],21,-343485551),h=h+H>>>0,l=l+P>>>0,p=p+N>>>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,In.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 Tn(i){return i?i.toLowerCase().indexOf("android")>=0||i.toLowerCase().indexOf("ios")>=0?"h5":"pc":"unknown"}function yn(i){const s=di(i),e=localStorage.getItem(s);if(e&&e.length===36)return e;const t=_n();return localStorage.setItem(s,t),t}var Lt,Pt,it;class ys{constructor(s){ii(this,Lt,void 0),ii(this,Pt,void 0),ii(this,it,void 0);const u=s,{commonParams:e,version:t}=u,r=Zs(u,["commonParams","version"]);si(this,Lt,new mn(r)),si(this,it,yn(r.project));const a=new Tt;a.setUA(window.navigator.userAgent);const n=a.getResult(),o=x({av:t,os:n.os.name,ov:n.os.version,bt:n.browser.name,bv:n.browser.version,tt:Tn(n.os.name),uuid:ft(this,it),host:window.location.host},e);si(this,Pt,o)}getUUID(){return ft(this,it)}send(s,e,t){ft(this,Lt).send(x(x({msgId:String(s),args:typeof e=="string"?e:new URLSearchParams(e).toString(),pu:window.location.href,ct:Date.now().toString()},ft(this,Pt)),t))}}Lt=new WeakMap,Pt=new WeakMap,it=new WeakMap;class Ln{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 ys({version:We,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=He(x({},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,g=a/p,m=n/p,f=n/a;this.report(10080,{calid:"",rmtid:s,tckid:u,ssrc:t,codec:l,rbr:d,pr:g,pl:m,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:g,totalInterFrameDelay:m,codec:f}=e,b=m,M=r/b,H=n/b,P=o/b,N=d/b,re=g/b,Te=g/d;this.report(10080,{calid:"",rmtid:s,tckid:a,ssrc:t,codec:f,rbr:M,dfps:H,rfps:P,rh:u,rw:h,ns:l,jd:p,pr:N,pl:re,plr:Te})}report(s,e,t){var r;this.enable&&((r=this.tracker)==null||r.send(s,e,x(x({},this.commonParams),t!=null?t:{})))}static reportCheck(s,e){new ys({version:We,host:"cn-hangzhou.log.aliyuncs.com",project:"web-rtc-grtn",logstore:"client",time:5,count:10,source:e!=null?e:""}).send(100001,s)}}class Pn{constructor(){c(this,"reporter");c(this,"param");c(this,"msgCacheArr",[]);c(this,"index",0)}start(s){this.initParam(s),this.reporter=new nt.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){_.info(s),this.msgCacheArr.length===0&&this.param?this.realSendReport(s):this.msgCacheArr.push(s)}initParam(s){this.param||(this.param={osn:L.SystemUtil.systemName,osv:L.SystemUtil.systemVersion,udid:L.LocalStorage.uuid,statsvrs:"0.6.1",sdkvrs:We,dm:L.BrowserUtil.domain,bt:L.BrowserUtil.browserName,bv:L.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 Cn{constructor(){c(this,"logClient");this.logClient=new Pn}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 Ls{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(Ls,"LEVEL",0);class kn{constructor(){c(this,"logger",new Ls("AudioMixer"));c(this,"audioContext",new AudioContext);c(this,"audioDestination",this.audioContext.createMediaStreamDestination());c(this,"audioTrack",wr(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 On=4;class Mn extends Ve{constructor(){super("audioMixer",ee.AliRtcSdkStreamTypeCapture,ut.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!==ee.AliRtcSdkStreamTypeCapture)return!1;const r=t.find(u=>u.type===ee.AliRtcSdkStreamTypeCapture),a=t.find(u=>u.type===ee.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===ee.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 kn),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<=On}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 mi{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 Nn extends mi{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 Vn=`
12
12
  attribute vec2 a_position;
13
13
  attribute vec2 a_texCoord;
14
14
 
@@ -38,7 +38,7 @@ uniform sampler2D u_texture;
38
38
  void main() {
39
39
  gl_FragColor = texture2D(u_texture, v_texCoord);
40
40
  }
41
- `;function xn(){let i;try{const s=document.createElement("canvas");s.width=1,s.height=1;const e={alpha:!1,depth:!1,stencil:!1,antialias:!1,preferLowPowerToHighPerformance:!0};i=s.getContext("webgl2",e)}catch(s){return!1}return!!i}function Fn(i){const s=i.createTexture();return i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),s}function Ls(i,s,e){const t=i.createShader(s);if(!t){console.error("create sahder fail");return}return i.shaderSource(t,e),i.compileShader(t),i.getShaderParameter(t,i.COMPILE_STATUS)?t:(console.error(`An error occurred compiling the shaders: ${i.getShaderInfoLog(t)}`),i.deleteShader(t),null)}function Bn(i,s,e){const t=Ls(i,i.VERTEX_SHADER,s),r=Ls(i,i.FRAGMENT_SHADER,e),a=i.createProgram();if(!(!a||!t||!r))return i.attachShader(a,t),i.attachShader(a,r),i.linkProgram(a),i.getProgramParameter(a,i.LINK_STATUS)?a:(console.error(`Unable to initialize the shader program: ${i.getProgramInfoLog(a)}`),null)}function Hn(i,s,e,t=0,r=0){const a=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,a);const n=t,o=r,u=s+t,h=e+r,l=[n,o,u,o,n,h,n,h,u,o,u,h];return i.bufferData(i.ARRAY_BUFFER,new Float32Array(l),i.STATIC_DRAW),a}class Ps extends gi{constructor(e,t){super(e,t);c(this,"targetCtx");c(this,"targetTexture");c(this,"locationMap");this.targetCtx=this.targetCanvas.getContext("webgl2"),this.locationMap={},this.startRender=this.startRender.bind(this),this.stopRender=this.startRender.bind(this),this.updateBuffer=this.updateBuffer.bind(this),this.initGL(),this.initStream(e)}static isSupport(){return xn()}initGL(){const e=this.targetCtx;if(!e)return;this.targetTexture=Fn(e);const t=Bn(e,Dn,Un);if(!t){console.log("[ScalerWebGL] program is null.");return}e.useProgram(t);const r=e.getAttribLocation(t,"a_position"),a=e.getAttribLocation(t,"a_texCoord"),n=e.getUniformLocation(t,"u_resolution");if(!n){console.log("[ScalerWebGL] resolutionLocation is null.");return}const o=e.getUniformLocation(t,"u_texture");if(!o){console.log("[ScalerWebGL] textureLocation is null.");return}this.locationMap={program:t,positionLocation:r,texCoordLocation:a,resolutionLocation:n,textureLocation:o},this.updateBuffer()}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),this.originVideo.addEventListener("resize",this.updateBuffer)}startRender(){this.cancelAnimation();const e=()=>{this.targetCtx&&(this.renderTexture(),!this.originVideo.paused&&!this.originVideo.ended&&(this.animationFrameId=requestAnimationFrame(e)))};e()}updateBuffer(){const e=this.targetCtx,t=this.locationMap.positionLocation,r=this.locationMap.texCoordLocation,a=this.locationMap.resolutionLocation;if(!e||!this.originVideo.videoWidth||!this.originVideo.videoHeight)return;const n=this.getPositionAndSize(this.originVideo.videoWidth,this.originVideo.videoHeight,this.targetWidth,this.targetHeight),o=Hn(e,n.width,n.height,n.x,n.y);e.enableVertexAttribArray(t),e.bindBuffer(e.ARRAY_BUFFER,o),e.vertexAttribPointer(t,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(r);const u=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,u),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,u),e.vertexAttribPointer(r,2,e.FLOAT,!1,0,0),e.uniform2f(a,this.targetWidth,this.targetHeight)}renderTexture(){const e=this.targetTexture,t=this.targetCtx,r=this.locationMap.textureLocation;!e||!t||(t.bindTexture(t.TEXTURE_2D,e),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,this.originVideo),t.useProgram(this.locationMap.program),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),t.uniform1i(r,0),t.viewport(0,0,t.canvas.width,t.canvas.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.drawArrays(t.TRIANGLES,0,6))}stopRender(){this.cancelAnimation()}updateOptions(e){super.updateOptions(e),this.updateBuffer()}dispose(){this.stopRender(),this.originVideo.removeEventListener("play",this.startRender),this.originVideo.removeEventListener("pause",this.stopRender),this.originVideo.removeEventListener("ended",this.stopRender),this.originVideo.removeEventListener("resize",this.updateBuffer),this.originVideo.pause(),this.originVideo.srcObject=null}}const Wn=`
41
+ `;function Dn(){let i;try{const s=document.createElement("canvas");s.width=1,s.height=1;const e={alpha:!1,depth:!1,stencil:!1,antialias:!1,preferLowPowerToHighPerformance:!0};i=s.getContext("webgl2",e)}catch(s){return!1}return!!i}function xn(i){const s=i.createTexture();return i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),s}function Ps(i,s,e){const t=i.createShader(s);if(!t){console.error("create sahder fail");return}return i.shaderSource(t,e),i.compileShader(t),i.getShaderParameter(t,i.COMPILE_STATUS)?t:(console.error(`An error occurred compiling the shaders: ${i.getShaderInfoLog(t)}`),i.deleteShader(t),null)}function Fn(i,s,e){const t=Ps(i,i.VERTEX_SHADER,s),r=Ps(i,i.FRAGMENT_SHADER,e),a=i.createProgram();if(!(!a||!t||!r))return i.attachShader(a,t),i.attachShader(a,r),i.linkProgram(a),i.getProgramParameter(a,i.LINK_STATUS)?a:(console.error(`Unable to initialize the shader program: ${i.getProgramInfoLog(a)}`),null)}function Bn(i,s,e,t=0,r=0){const a=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,a);const n=t,o=r,u=s+t,h=e+r,l=[n,o,u,o,n,h,n,h,u,o,u,h];return i.bufferData(i.ARRAY_BUFFER,new Float32Array(l),i.STATIC_DRAW),a}class Cs extends mi{constructor(e,t){super(e,t);c(this,"targetCtx");c(this,"targetTexture");c(this,"locationMap");this.targetCtx=this.targetCanvas.getContext("webgl2"),this.locationMap={},this.startRender=this.startRender.bind(this),this.stopRender=this.startRender.bind(this),this.updateBuffer=this.updateBuffer.bind(this),this.initGL(),this.initStream(e)}static isSupport(){return Dn()}initGL(){const e=this.targetCtx;if(!e)return;this.targetTexture=xn(e);const t=Fn(e,Vn,Un);if(!t){console.log("[ScalerWebGL] program is null.");return}e.useProgram(t);const r=e.getAttribLocation(t,"a_position"),a=e.getAttribLocation(t,"a_texCoord"),n=e.getUniformLocation(t,"u_resolution");if(!n){console.log("[ScalerWebGL] resolutionLocation is null.");return}const o=e.getUniformLocation(t,"u_texture");if(!o){console.log("[ScalerWebGL] textureLocation is null.");return}this.locationMap={program:t,positionLocation:r,texCoordLocation:a,resolutionLocation:n,textureLocation:o},this.updateBuffer()}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),this.originVideo.addEventListener("resize",this.updateBuffer)}startRender(){this.cancelAnimation();const e=()=>{this.targetCtx&&(this.renderTexture(),!this.originVideo.paused&&!this.originVideo.ended&&(this.animationFrameId=requestAnimationFrame(e)))};e()}updateBuffer(){const e=this.targetCtx,t=this.locationMap.positionLocation,r=this.locationMap.texCoordLocation,a=this.locationMap.resolutionLocation;if(!e||!this.originVideo.videoWidth||!this.originVideo.videoHeight)return;const n=this.getPositionAndSize(this.originVideo.videoWidth,this.originVideo.videoHeight,this.targetWidth,this.targetHeight),o=Bn(e,n.width,n.height,n.x,n.y);e.enableVertexAttribArray(t),e.bindBuffer(e.ARRAY_BUFFER,o),e.vertexAttribPointer(t,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(r);const u=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,u),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,u),e.vertexAttribPointer(r,2,e.FLOAT,!1,0,0),e.uniform2f(a,this.targetWidth,this.targetHeight)}renderTexture(){const e=this.targetTexture,t=this.targetCtx,r=this.locationMap.textureLocation;!e||!t||(t.bindTexture(t.TEXTURE_2D,e),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,this.originVideo),t.useProgram(this.locationMap.program),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),t.uniform1i(r,0),t.viewport(0,0,t.canvas.width,t.canvas.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.drawArrays(t.TRIANGLES,0,6))}stopRender(){this.cancelAnimation()}updateOptions(e){super.updateOptions(e),this.updateBuffer()}dispose(){this.stopRender(),this.originVideo.removeEventListener("play",this.startRender),this.originVideo.removeEventListener("pause",this.stopRender),this.originVideo.removeEventListener("ended",this.stopRender),this.originVideo.removeEventListener("resize",this.updateBuffer),this.originVideo.pause(),this.originVideo.srcObject=null}}const Hn=`
42
42
  var targetOptions={
43
43
  width: 320,
44
44
  height: 180,
@@ -123,4 +123,4 @@ onmessage = function(evt) {
123
123
  break;
124
124
  }
125
125
  }
126
- `;class Cs extends gi{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([Wn],{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(x({type:"updateOptions"},e))}dispose(){try{this.processor.readable.cancel(),this.trackGenerator.writable.close()}catch(e){}}getVideoTrack(){return this.trackGenerator}}class mi{static isSupport(){return typeof HTMLCanvasElement.prototype.captureStream=="function"}static getInstance(s,e){return Cs.isSupport()?new Cs(s,e):Ps.isSupport()?new Ps(s,e):new Vn(s,e)}}class jn extends Ve{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 mi.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=mi.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()}}var Si=(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_BAD_PARAM=16974081]="ERR_JOIN_BAD_PARAM",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_HEARTBEAT_TIMEOUT=16908812]="ERR_ICE_CONNECTION_HEARTBEAT_TIMEOUT",i[i.ERR_SDK_INVALID_STATE=17170689]="ERR_SDK_INVALID_STATE",i[i.ERR_SESSION_REMOVED=17170690]="ERR_SESSION_REMOVED",i[i.ERR_INNER=-1]="ERR_INNER",i))(Si||{});class fi{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 E(Si.ERR_JOIN_BAD_PARAM,"no authInfo");if(s){if(!s.appId)return e.message="no appId",e;if(!s.channelId)return e.message="no channelId",e;if(s.timestamp){if(!fi.checkNumber(s.timestamp))return e.message="timestamp need number",e}else return e.message="no timestamp",e;return s.token?s.userId?s.role!==void 0&&!["pub","sub","relay"].includes(s.role)?(e.message="set client role failed",e):null:(e.message="no userId",e):(e.message="no token",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 ks{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 Os{constructor(s,e,t){c(this,"userId");c(this,"streamType");c(this,"sourceType");this.userId=s,this.streamType=e,this.sourceType=t}}class Ms{constructor(s,e,t,r=0,a=16777215,n=Ke.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:de(this.x,s),y:de(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:Jt(this.fontColor),zorder:this.zOrder}}}var Ns=(i=>(i[i.NOT_DISPLAY=0]="NOT_DISPLAY",i[i.ALWAYS=1]="ALWAYS",i[i.WHEN_NO_VIDEO=2]="WHEN_NO_VIDEO",i))(Ns||{});class bi{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:de(this.x,s),y:de(this.y,e),width:de(this.width,s),height:de(this.height,e),zorder:this.zOrder}}}c(bi,"DisplayType",Ns);class Vs{constructor(s,e,t,r,a=0,n=16777215,o=Ke.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:de(this.x,s),y:de(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:Jt(this.fontColor),zorder:this.zOrder}}}class Ds{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",$e.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:de(this.x,e),y:de(this.y,t),width:de(this.width,e),height:de(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&&qe[this.sourceType]?a.sourcetype=qe[this.sourceType]:a.sourcetype=qe[De.LiveTranscodingCamera],this.segmentType&&r===lt.LiveTranscodingVirtualBackground?a.segmenttype=this.segmentType:a.segmenttype=$e.LiveTranscodingNoBody,a}}class Gn extends Ve{constructor(){super("AliRtcScreenStandardize",ee.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===fe.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!==fe.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 g=yield n.handleFrame(p,e);yield d.enqueue(g),g==null||g.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,$n=Object.getOwnPropertyDescriptor,Y=(i,s,e,t)=>{for(var r=t>1?void 0:t?$n(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 J=(T=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",F.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 Pn(e==null?void 0:e.webTrack),this.reporter=new kn,this.channelProfile=Ie.AliRtcSdkCommunication,this.clientRole=Ee.AliRtcSdkLive,this.liveTranscoding=new Vr,this.signalingManager=new cr(this.channelProfile,this.clientRole,(e==null?void 0:e.env)===we.pre?we.pre:we.prod),this.addSignalingManagerListeners(),this.maxSignalingConnectRetryCount=e==null?void 0:e.maxSignalingConnectRetryCount,this.userManager=new he({reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager}),this.addUserManagerListeners(),this.addPublisherListeners(),this.audioMixerPlugin=new Nn,this.enablePlugin(this.audioMixerPlugin),this.dualVideoPlugin=new jn("dualVideoPlugin"),this.enablePlugin(new Gn)}static getSdkVersion(){return We}static setLogLevel(e){_.setLogLevel(e)}static getInstance(e){return T._instance||(T._instance=new T(e)),T._instance}destroy(){T._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===Ie.AliRtcSdkCommunication||this.clientRole===Ee.AliRtcSdkInteractive}resetState(){return S(this,null,function*(){yield this.userManager.clear(),this.connectState=F.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=>{_.event("[Publisher] Device Status Change",p),this.onLocalDeviceStatusChange(p)}),(t=this.publisher)==null||t.on(Ce.VideoTrackEnded,()=>{_.event("[Publisher] VideoTrack Ended"),this.emit("localDeviceException",be.AliEngineLocalDeviceTypeCamera,Z.AliEngineLocalDeviceExceptionTypeCameraInterrupt,"")}),(r=this.publisher)==null||r.on(Ce.ScreenTrackEnded,()=>{_.event("[Publisher] ScreenTrack Ended"),this.emit("localDeviceException",be.AliEngineLocalDeviceTypeDisplay,Z.AliEngineLocalDeviceExceptionTypeDisplayException,"")}),(a=this.publisher)==null||a.on(Ce.AudioTrackEnded,()=>{_.event("[Publisher] AudioTrack Ended"),this.emit("localDeviceException",be.AliEngineLocalDeviceTypeMic,Z.AliEngineLocalDeviceExceptionTypeMicInterrupt,"")}),(n=this.publisher)==null||n.on("localDeviceException",(p,d,g="")=>{this.emit("localDeviceException",p,d,g)}),(o=this.publisher)==null||o.on("audioPublishStateChanged",(p,d,g)=>{var m;this.emit("audioPublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")}),(u=this.publisher)==null||u.on("videoPublishStateChanged",(p,d,g)=>{var m;this.emit("videoPublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")}),(h=this.publisher)==null||h.on("dualStreamPublishStateChanged",(p,d,g)=>{var m;this.emit("dualStreamPublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")}),(l=this.publisher)==null||l.on("screenPublishStateChanged",(p,d,g)=>{var m;this.emit("screenSharePublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")})}addUserManagerListeners(){this.userManager.rtsManager.on("reconnecting",()=>S(this,null,function*(){!this.networkError&&!(yield _e.isNetworkAvailable())&&this.onNetworkError()})),this.userManager.rtsManager.on("disconnected",()=>S(this,null,function*(){_.event("[UserManager] RTS Disconnected"),(yield _e.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)=>{_.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)})}addSignalingManagerListeners(){this.signalingManager.on("onKeepAliveRsp",()=>{this.networkError&&_.event("[Signaling] Receive KeepAlive Response",`networkError: ${this.networkError}`),this.networkError&&this.onNetworkRecovery()}),this.signalingManager.on("onNotifyJoin",e=>{_.event("[Signaling] Notify Join ",e),this.handleUsersJoin(e),e.forEach(t=>{this.emit("remoteUserOnLineNotify",t.userid,0)})}),this.signalingManager.on("onNotifyStatus",e=>{_.event("[Signaling] Notify Status ",e),e.forEach(t=>{this.userManager.updateRemoteUserDeviceStatus(t)})}),this.signalingManager.on("onNotifyLeave",e=>{_.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)=>{_.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=>{_.event("[Signaling] Connect Fail ",e),this.onError(e),this.backToUnpublishStatus(),this.connectState=F.AliRtcConnectionStatusFailed,this.emit("connectionStatusChange",F.AliRtcConnectionStatusFailed,Le.AliRtcConnectionChangedNetworkInterrupted)}),this.signalingManager.on("onNetworkError",e=>{_.event("[Signaling] Network error ",e),this.onNetworkError()}),this.signalingManager.on("onAuthInvalid",()=>{_.event("[Signaling] Auth Invalid")}),this.signalingManager.on("onReconnectStart",()=>{_.event("[Signaling] Reconnect Start "),this.connectState=F.AliRtcConnectionStatusReconnecting,this.emit("connectionStatusChange",F.AliRtcConnectionStatusReconnecting,Le.AliRtcConnectionSignalingConnecting)}),this.signalingManager.on("onReconnectSuccess",e=>{_.event("[Signaling] Reconnect Success ",e),this.onNetworkRecovery(e)}),this.signalingManager.on("onReconnectFail",e=>{_.event("[Signaling] Reconnect Fail ",e),e.code===403&&this.emit("authInfoExpired")}),this.signalingManager.on("onError",e=>{_.event("[Signaling] Error ",e),this.onError(e)})}backToUnpublishStatus(){var e,t;this.connectState=F.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);_.event(this.moduleName,U.UserJoined,a)}})}onLocalDeviceStatusChange(e){_.event(this.moduleName,ie.Local,e),this.signalingManager.reportStatus(e).then(()=>{_.debug("[signaling] reportStatus suc")}).catch(t=>{_.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;_.event(this.moduleName,"onNetworkRecovery",{users:e}),this.networkError&&(this.networkError=!1,(t=this.publisher)==null||t.reportSelfDeviceStatus(),yield this.resumePublishForNetworkRecovery(),this.connectState=F.AliRtcConnectionStatusConnected,this.emit("connectionStatusChange",F.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);_.info(`[${this.moduleName}/${t}]`,{joinList:r,leaveList:a,presentList:n}),this.handleUsersJoin(r),a.forEach(o=>{_.event(this.moduleName,U.UserLeft,o.userid,o.reason),this.emit("remoteUserOffLineNotify",o.userid,Wt.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===F.AliRtcConnectionStatusConnected&&(this.networkError||(this.connectState=F.AliRtcConnectionStatusDisconnected,this.emit("connectionStatusChange",F.AliRtcConnectionStatusDisconnected,Le.AliRtcConnectionChangedNetworkInterrupted)),this.networkError=!0)}onError(e){this.reporter.reportError(e),_.event(this.moduleName,U.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 E(R.ERROR_LOCAL_STREAM_NOT_EXIST,G[R.ERROR_LOCAL_STREAM_NOT_EXIST])}getCurrentMicDeviceId(){var e;return(e=this.publisher)==null?void 0:e.getCurrentMicDeviceId()}setChannelProfile(e){if(![F.AliRtcConnectionStatusInit,F.AliRtcConnectionStatusDisconnected,F.AliRtcConnectionStatusFailed].includes(this.connectState)){const t=R.ERROR_SET_CHANNEL_PROFILE_FAIL,r=G[t];throw new E(t,`${r}, cannot set channel profile in call`)}this.channelProfile=e,this.channelProfile===Ie.AliRtcSdkCommunication&&(this.clientRole=Ee.AliRtcSdkLive),this.signalingManager.setChannelProfile(e)}setClientRole(e){return S(this,null,function*(){var a,n,o,u,h;const t=R.ERROR_SET_CLIENT_ROLE_FAIL,r=G[t];try{if(this.channelProfile===Ie.AliRtcSdkCommunication)return;if(!Object.values(Ee).includes(e))throw new E(t,`${r}, role value(${e}) is invalid`);if(this.clientRole===e)return;this.isInCall()?this.clientRole===Ee.AliRtcSdkInteractive?(this.userManager.isSubscribing?(yield this.stopPublish(),yield(a=this.publisher)==null?void 0:a.clearStream()):yield(n=this.publisher)==null?void 0:n.unPublish(),yield this.signalingManager.setClientRole(e)):(yield this.signalingManager.setClientRole(e),yield this.startDefaultDevicesCapture(),(o=this.publisher)!=null&&o.isPublishing||(yield(u=this.publisher)==null?void 0:u.startPublish()),yield(h=this.publisher)==null?void 0:h.previewAll()):yield this.signalingManager.setClientRole(e),this.clientRole=e}catch(l){throw l.code===403&&this.emit("authInfoExpired"),l}})}getCurrentClientRole(){return this.clientRole}setAudioOnlyMode(e){if(this.isInCall())throw new E(R.ERROR_SET_AUDIO_ONLY_FAIL,`${G[R.ERROR_SET_AUDIO_ONLY_FAIL]}, cannot not change audioOnly mode after joining channel`);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 T.getCameraList(),t=yield T.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=fi.checkAuthInfo(e);if(this.webTrackingClient.updateAuthInfo(e),this.webTrackingClient.reportJoinChannel(e),F.AliRtcConnectionStatusInit===this.connectState||F.AliRtcConnectionStatusDisconnected===this.connectState||F.AliRtcConnectionStatusFailed===this.connectState){if(this.connectState=F.AliRtcConnectionStatusConnecting,a)throw this.connectState=F.AliRtcConnectionStatusFailed,this.webTrackingClient.reportJoinChannelRes(a.code,a.message,0),this.reporter.reportJoin(0,a.code,a.message),a;e.callid=_e.createCallid(),this.reporter.start(e);try{const d=yield this.signalingManager.join(e,t,this.maxSignalingConnectRetryCount);this.connectState=F.AliRtcConnectionStatusConnected,(n=this.publisher)==null||n.reportSelfDeviceStatus();let g=new Date().getTime()-r;this.webTrackingClient.reportJoinChannelRes(0,"",g),this.reporter.reportJoin(g,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(m=>m)&&(yield(h=this.publisher)==null?void 0:h.startPublish(),yield(l=this.publisher)==null?void 0:l.previewAll())),this.remoteUsers.forEach(m=>{m.updateSubscribe()}),this.liveTranscoding.setAuthInfo(e)}catch(d){let g=new Date().getTime()-r;const m=(p=d.code)!=null?p:-1,f=d.reason||d.message||"";throw this.webTrackingClient.reportJoinChannelRes(m,f,g),this.connectState=F.AliRtcConnectionStatusDisconnected,this.reporter.reportJoin(g,m,""),new E(m,f)}}else{const d=new E(Si.ERR_JOIN_ALREADY_JOINED,"Already logged in");throw this.connectState===F.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(F.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:""),_.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,""),_.setFlushMode(!0);return}})}isInCall(){return this.connectState===F.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===F.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 Error;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===F.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 E(R.ERROR_REMOTE_USER_NOT_FOUND);r&&(t===V.AliRtcVideoTrackScreen||t===V.AliRtcVideoTrackBoth)?n.setWantSubScreen(!0):n.setWantSubScreen(!1),r&&(t===V.AliRtcVideoTrackCamera||t===V.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){return this.userManager.getRemoteUser(e)}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=Je.frameRate,bitrate:r=Je.maxBitrate}=e;yield(a=this.publisher)==null?void 0:a.setScreenProfile(xi,{width:Je.width,height:Je.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===F.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 Error;this.audioMixerPlugin.setOptions({screen:Math.max(0,Math.min(e,400))/100})}enableAudioVolumeIndication(e){this.userManager.enableAudioVolumeIndication(e)}muteLocalMic(e=!1){var t,r;this.hadPushStream(this.publishAudioStream),this.isPublishing&&this.onLocalDeviceStatusChange(e?U.MuteAudio:U.UnmuteAudio),e?(t=this.publishAudioStream)==null||t.disableAudio():(r=this.publishAudioStream)==null||r.enableAudio()}muteRemoteAudioPlaying(e,t=!1){const r=this.userManager.getRemoteUser(e);if(!r)throw new E(R.ERROR_REMOTE_USER_NOT_FOUND);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),this.isPublishing&&!((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 Error;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,a;if(!e)return(r=this.publisher)==null?void 0:r.audioTrack;const t=this.userManager.getRemoteUser(e);return(a=t==null?void 0:t.getCameraStream)==null?void 0:a.audioTrack})}setLocalViewConfig(e,t){return S(this,null,function*(){var r,a,n;if(this._audioOnlyMode)throw new E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"Cannot set local view in audio only mode");(r=this.userManager)==null||r.setLocalViewConfig(e,t),t===V.AliRtcVideoTrackCamera&&((a=this.publisher)!=null&&a.hasCamera)?yield this.startPreview():t===V.AliRtcVideoTrackScreen&&((n=this.publisher)!=null&&n.hasScreenShare)&&(yield this.startPreviewScreen())})}setCameraCapturerConfiguration(e){return S(this,null,function*(){var h,l,p;const{width:t=ze.width,height:r=ze.height,frameRate:a=ze.frameRate,bitrate:n=ze.maxBitrate,cameraDirection:o,deviceId:u}=e;yield(h=this.publisher)==null?void 0:h.setVideoProfile(Ui,{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,g;if(this._audioOnlyMode)throw new E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"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 m={video:!0};yield(d=this.publisher)==null?void 0:d.startCameraCapture(m)}else yield(g=this.publisher)==null?void 0:g.stopCameraCapture()})}muteLocalCamera(e){return S(this,null,function*(){var t,r,a,n,o,u;this.hadPushStream((r=(t=this.publisher)==null?void 0:t.publishStreams)==null?void 0:r.video),this.isPublishing&&this.onLocalDeviceStatusChange(e?U.MuteVideo:U.UnmuteVideo),e?(n=(a=this.publisher)==null?void 0:a.publishStreams.video)==null||n.disableVideo():(u=(o=this.publisher)==null?void 0:o.publishStreams.video)==null||u.enableVideo()})}muteLocalScreen(e){return S(this,null,function*(){var t,r,a,n,o,u,h,l;this.hadPushStream((r=(t=this.publisher)==null?void 0:t.publishStreams)==null?void 0:r.screen),this.isPublishing&&this.onLocalDeviceStatusChange(e?U.MuteScreen:U.UnmuteScreen),e?(o=(n=(a=this.publisher)==null?void 0:a.publishStreams)==null?void 0:n.screen)==null||o.disableVideo():(l=(h=(u=this.publisher)==null?void 0:u.publishStreams)==null?void 0:h.screen)==null||l.enableVideo()})}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,g,m,f;if(this._audioOnlyMode)throw new E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"Cannot switch camera in audio only mode");const t={};e?t.deviceId=e:t.cameraDirection=((r=this.publisher)==null?void 0:r.cameraDirection)==="environment"?je.CAMERA_FRONT:je.CAMERA_REAR,yield this.setCameraCapturerConfiguration(t),this.isPublishing&&!((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(),(m=(g=(d=(p=this.publisher)==null?void 0:p.publishStreams)==null?void 0:d.video)==null?void 0:g.videoTrack)==null||m.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 E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"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 E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"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===ee.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===ee.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)})}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 E(R.ERROR_PUBLISH_NEEDED,"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 E(Ue.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 E(Ue.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 E(Ue.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 E(Ue.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");const r={segmentBackgroundProcess:{type:0,enable:e}};e&&(r.setSegmentBackgroundImage={type:0,backgroundImgUrl:""}),t.setOptions(r)}},c(T,"logName","AliRtcEngine"),c(T,"isSupported",Zs),c(T,"isDualVideoStreamSupported",mi.isSupport),c(T,"getCameraList",()=>S(T,null,function*(){return(yield y.AliRTS.getCameraList()).filter(t=>t.deviceId)})),c(T,"getMicrophoneList",()=>S(T,null,function*(){return(yield y.AliRTS.getMicList()).filter(t=>t.deviceId)})),c(T,"getSpeakerList",()=>S(T,null,function*(){return(yield y.AliRTS.getSpeakerList()).filter(t=>t.deviceId)})),c(T,"_instance"),c(T,"AliRtcSdkChannelProfile",Ie),c(T,"AliRtcSdkClientRole",Ee),c(T,"AliRtcVideoStreamType",oe),c(T,"AliRtcVideoTrack",V),c(T,"AliRtcAudioTrack",Ne),c(T,"AliRtcPublishState",k),c(T,"AliRtcSubscribeState",K),c(T,"AliRtcRawDataStreamType",ee),c(T,"AliRtcLogLevel",Ht),c(T,"AliRtcEngineLocalDeviceType",be),c(T,"AliRtcEngineLocalDeviceExceptionType",Z),c(T,"AliRtcConnectionStatus",F),c(T,"AliRtcConnectionStatusChangeReason",Le),c(T,"AliRtcPlugin",Ve),c(T,"AliRtcPluginTrackType",ut),c(T,"AliRtcLiveTranscodingParam",dt),c(T,"AliRtcLiveTranscodingEncodeParam",zt),c(T,"AliRtcLiveTranscodingMixParam",ks),c(T,"AliRtcLiveTranscodingSingleParam",Os),c(T,"AliRtcTranscodingClockWidget",Ms),c(T,"AliRtcTranscodingImage",bi),c(T,"AliRtcTranscodingText",Vs),c(T,"AliRtcTranscodingUser",Ds),c(T,"AliRtcLiveTranscodingMixMode",Ge),c(T,"AliRtcLiveTranscodingStreamType",jt),c(T,"AliRtcLiveTranscodingSourceType",De),c(T,"AliRtcLiveTranscodingTaskProfile",Gt),c(T,"AliRtcLiveTranscodingAudioSampleRate",ht),c(T,"AliRtcLiveTranscodingSegmentType",$e),c(T,"AliRtcLiveTranscodingFontType",Ke),c(T,"AliRtcLiveTranscodingCropMode",qt),c(T,"AliRtcLiveTranscodingMediaProcessMode",lt),c(T,"AliRtcLiveTranscodingState",$t),c(T,"AliRtcLiveTranscodingErrorCode",Re),c(T,"AliRtcTrascodingPublishTaskStatus",Kt),c(T,"Plugin",Ve),T);Y([v()],J.prototype,"stopPublish",1),Y([v()],J.prototype,"resumeSubList",1),Y([v()],J.prototype,"setEnableDualVideoStream",1),Y([v()],J.prototype,"setChannelProfile",1),Y([v()],J.prototype,"setClientRole",1),Y([v()],J.prototype,"joinChannel",1),Y([v()],J.prototype,"leaveChannel",1),Y([v()],J.prototype,"publishLocalVideoStream",1),Y([v()],J.prototype,"startScreenShare",1),Y([v()],J.prototype,"setScreenShareConfiguration",1),Y([v()],J.prototype,"publishLocalScreenShareStream",1),Y([v()],J.prototype,"enableAudioVolumeIndication",1),Y([v()],J.prototype,"muteLocalMic",1),Y([v()],J.prototype,"startAudioCapture",1),Y([v()],J.prototype,"switchMicrophone",1),Y([v()],J.prototype,"setAudioProfile",1),Y([v()],J.prototype,"setLocalViewConfig",1),Y([v()],J.prototype,"setCameraCapturerConfiguration",1),Y([v()],J.prototype,"enableLocalVideo",1),Y([v()],J.prototype,"muteLocalCamera",1),Y([v()],J.prototype,"muteLocalScreen",1),Y([v()],J.prototype,"setRemoteViewConfig",1),Y([v()],J.prototype,"switchCamera",1);let Kn=J;I.AliRtcConnectionStatus=F,I.AliRtcConnectionStatusChangeReason=Le,I.AliRtcEngineLocalDeviceExceptionType=Z,I.AliRtcEngineLocalDeviceType=be,I.AliRtcLiveTranscodingAudioSampleRate=ht,I.AliRtcLiveTranscodingCropMode=qt,I.AliRtcLiveTranscodingEncodeParam=zt,I.AliRtcLiveTranscodingErrorCode=Re,I.AliRtcLiveTranscodingFontType=Ke,I.AliRtcLiveTranscodingMediaProcessMode=lt,I.AliRtcLiveTranscodingMixMode=Ge,I.AliRtcLiveTranscodingMixParam=ks,I.AliRtcLiveTranscodingParam=dt,I.AliRtcLiveTranscodingSegmentType=$e,I.AliRtcLiveTranscodingSingleParam=Os,I.AliRtcLiveTranscodingSourceType=De,I.AliRtcLiveTranscodingState=$t,I.AliRtcLiveTranscodingStreamType=jt,I.AliRtcLiveTranscodingTaskProfile=Gt,I.AliRtcLogLevel=Ht,I.AliRtcPlugin=Ve,I.AliRtcPluginTrackType=ut,I.AliRtcPluginType=Oi,I.AliRtcPublishState=k,I.AliRtcRawDataStreamType=ee,I.AliRtcSdkChannelProfile=Ie,I.AliRtcSdkClientRole=Ee,I.AliRtcSubscribeState=K,I.AliRtcTranscodingClockWidget=Ms,I.AliRtcTranscodingImage=bi,I.AliRtcTranscodingText=Vs,I.AliRtcTranscodingUser=Ds,I.AliRtcTrascodingPublishTaskStatus=Kt,I.AliRtcVideoStreamType=oe,I.AliRtcVideoTrack=V,I.default=Kn,Object.defineProperties(I,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
126
+ `;class ks extends mi{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([Hn],{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(x({type:"updateOptions"},e))}dispose(){try{this.processor.readable.cancel(),this.trackGenerator.writable.close()}catch(e){}}getVideoTrack(){return this.trackGenerator}}class Si{static isSupport(){return typeof HTMLCanvasElement.prototype.captureStream=="function"}static getInstance(s,e){return ks.isSupport()?new ks(s,e):Cs.isSupport()?new Cs(s,e):new Nn(s,e)}}class Wn extends Ve{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 Si.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=Si.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()}}var fi=(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_BAD_PARAM=16974081]="ERR_JOIN_BAD_PARAM",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_HEARTBEAT_TIMEOUT=16908812]="ERR_ICE_CONNECTION_HEARTBEAT_TIMEOUT",i[i.ERR_SDK_INVALID_STATE=17170689]="ERR_SDK_INVALID_STATE",i[i.ERR_SESSION_REMOVED=17170690]="ERR_SESSION_REMOVED",i[i.ERR_INNER=-1]="ERR_INNER",i))(fi||{});class bi{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 E(fi.ERR_JOIN_BAD_PARAM,"no authInfo");if(s){if(!s.appId)return e.message="no appId",e;if(!s.channelId)return e.message="no channelId",e;if(s.timestamp){if(!bi.checkNumber(s.timestamp))return e.message="timestamp need number",e}else return e.message="no timestamp",e;return s.token?s.userId?s.role!==void 0&&!["pub","sub","relay"].includes(s.role)?(e.message="set client role failed",e):null:(e.message="no userId",e):(e.message="no token",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 Os{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 Ms{constructor(s,e,t){c(this,"userId");c(this,"streamType");c(this,"sourceType");this.userId=s,this.streamType=e,this.sourceType=t}}class Ns{constructor(s,e,t,r=0,a=16777215,n=Ke.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:de(this.x,s),y:de(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:Jt(this.fontColor),zorder:this.zOrder}}}var Vs=(i=>(i[i.NOT_DISPLAY=0]="NOT_DISPLAY",i[i.ALWAYS=1]="ALWAYS",i[i.WHEN_NO_VIDEO=2]="WHEN_NO_VIDEO",i))(Vs||{});class Ri{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:de(this.x,s),y:de(this.y,e),width:de(this.width,s),height:de(this.height,e),zorder:this.zOrder}}}c(Ri,"DisplayType",Vs);class Us{constructor(s,e,t,r,a=0,n=16777215,o=Ke.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:de(this.x,s),y:de(this.y,e),fonttype:this.fontType,fontsize:this.fontSize,fontcolor:Jt(this.fontColor),zorder:this.zOrder}}}class Ds{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",qe.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:de(this.x,e),y:de(this.y,t),width:de(this.width,e),height:de(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&&$e[this.sourceType]?a.sourcetype=$e[this.sourceType]:a.sourcetype=$e[Ue.LiveTranscodingCamera],this.segmentType&&r===lt.LiveTranscodingVirtualBackground?a.segmenttype=this.segmentType:a.segmenttype=qe.LiveTranscodingNoBody,a}}class jn extends Ve{constructor(){super("AliRtcScreenStandardize",ee.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===fe.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!==fe.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 g=yield n.handleFrame(p,e);yield d.enqueue(g),g==null||g.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 Gn=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,Y=(i,s,e,t)=>{for(var r=t>1?void 0:t?$n(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&&Gn(s,e,r),r};const J=(T=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",F.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 Ln(e==null?void 0:e.webTrack),this.reporter=new Cn,this.channelProfile=Ie.AliRtcSdkCommunication,this.clientRole=Ee.AliRtcSdkLive,this.liveTranscoding=new Nr,this.signalingManager=new ur(this.channelProfile,this.clientRole,(e==null?void 0:e.env)===we.pre?we.pre:we.prod),this.addSignalingManagerListeners(),this.maxSignalingConnectRetryCount=e==null?void 0:e.maxSignalingConnectRetryCount,this.userManager=new he({reporter:this.reporter,webTrackingClient:this.webTrackingClient,signalingManager:this.signalingManager}),this.addUserManagerListeners(),this.addPublisherListeners(),this.audioMixerPlugin=new Mn,this.enablePlugin(this.audioMixerPlugin),this.dualVideoPlugin=new Wn("dualVideoPlugin"),this.enablePlugin(new jn)}static getSdkVersion(){return We}static setLogLevel(e){_.setLogLevel(e)}static getInstance(e){return T._instance||(T._instance=new T(e)),T._instance}destroy(){T._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===Ie.AliRtcSdkCommunication||this.clientRole===Ee.AliRtcSdkInteractive}resetState(){return S(this,null,function*(){yield this.userManager.clear(),this.connectState=F.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=>{_.event("[Publisher] Device Status Change",p),this.onLocalDeviceStatusChange(p)}),(t=this.publisher)==null||t.on(Ce.VideoTrackEnded,()=>{_.event("[Publisher] VideoTrack Ended"),this.emit("localDeviceException",be.AliEngineLocalDeviceTypeCamera,Z.AliEngineLocalDeviceExceptionTypeCameraInterrupt,"")}),(r=this.publisher)==null||r.on(Ce.ScreenTrackEnded,()=>{_.event("[Publisher] ScreenTrack Ended"),this.emit("localDeviceException",be.AliEngineLocalDeviceTypeDisplay,Z.AliEngineLocalDeviceExceptionTypeDisplayException,"")}),(a=this.publisher)==null||a.on(Ce.AudioTrackEnded,()=>{_.event("[Publisher] AudioTrack Ended"),this.emit("localDeviceException",be.AliEngineLocalDeviceTypeMic,Z.AliEngineLocalDeviceExceptionTypeMicInterrupt,"")}),(n=this.publisher)==null||n.on("localDeviceException",(p,d,g="")=>{this.emit("localDeviceException",p,d,g)}),(o=this.publisher)==null||o.on("audioPublishStateChanged",(p,d,g)=>{var m;this.emit("audioPublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")}),(u=this.publisher)==null||u.on("videoPublishStateChanged",(p,d,g)=>{var m;this.emit("videoPublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")}),(h=this.publisher)==null||h.on("dualStreamPublishStateChanged",(p,d,g)=>{var m;this.emit("dualStreamPublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")}),(l=this.publisher)==null||l.on("screenPublishStateChanged",(p,d,g)=>{var m;this.emit("screenSharePublishStateChanged",p,d,g,(m=this.channel)!=null?m:"")})}addUserManagerListeners(){this.userManager.rtsManager.on("reconnecting",()=>S(this,null,function*(){!this.networkError&&!(yield _e.isNetworkAvailable())&&this.onNetworkError()})),this.userManager.rtsManager.on("disconnected",()=>S(this,null,function*(){_.event("[UserManager] RTS Disconnected"),(yield _e.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)=>{_.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)})}addSignalingManagerListeners(){this.signalingManager.on("onKeepAliveRsp",()=>{this.networkError&&_.event("[Signaling] Receive KeepAlive Response",`networkError: ${this.networkError}`),this.networkError&&this.onNetworkRecovery()}),this.signalingManager.on("onNotifyJoin",e=>{_.event("[Signaling] Notify Join ",e),this.handleUsersJoin(e),e.forEach(t=>{this.emit("remoteUserOnLineNotify",t.userid,0)})}),this.signalingManager.on("onNotifyStatus",e=>{_.event("[Signaling] Notify Status ",e),e.forEach(t=>{this.userManager.updateRemoteUserDeviceStatus(t)})}),this.signalingManager.on("onNotifyLeave",e=>{_.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)=>{_.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=>{_.event("[Signaling] Connect Fail ",e),this.onError(e),this.backToUnpublishStatus(),this.connectState=F.AliRtcConnectionStatusFailed,this.emit("connectionStatusChange",F.AliRtcConnectionStatusFailed,Le.AliRtcConnectionChangedNetworkInterrupted)}),this.signalingManager.on("onNetworkError",e=>{_.event("[Signaling] Network error ",e),this.onNetworkError()}),this.signalingManager.on("onAuthInvalid",()=>{_.event("[Signaling] Auth Invalid")}),this.signalingManager.on("onReconnectStart",()=>{_.event("[Signaling] Reconnect Start "),this.connectState=F.AliRtcConnectionStatusReconnecting,this.emit("connectionStatusChange",F.AliRtcConnectionStatusReconnecting,Le.AliRtcConnectionSignalingConnecting)}),this.signalingManager.on("onReconnectSuccess",e=>{_.event("[Signaling] Reconnect Success ",e),this.onNetworkRecovery(e)}),this.signalingManager.on("onReconnectFail",e=>{_.event("[Signaling] Reconnect Fail ",e),e.code===403&&this.emit("authInfoExpired")}),this.signalingManager.on("onError",e=>{_.event("[Signaling] Error ",e),this.onError(e)})}backToUnpublishStatus(){var e,t;this.connectState=F.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);_.event(this.moduleName,D.UserJoined,a)}})}onLocalDeviceStatusChange(e){_.event(this.moduleName,ie.Local,e),this.signalingManager.reportStatus(e).then(()=>{_.debug("[signaling] reportStatus suc")}).catch(t=>{_.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;_.event(this.moduleName,"onNetworkRecovery",{users:e}),this.networkError&&(this.networkError=!1,(t=this.publisher)==null||t.reportSelfDeviceStatus(),yield this.resumePublishForNetworkRecovery(),this.connectState=F.AliRtcConnectionStatusConnected,this.emit("connectionStatusChange",F.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);_.info(`[${this.moduleName}/${t}]`,{joinList:r,leaveList:a,presentList:n}),this.handleUsersJoin(r),a.forEach(o=>{_.event(this.moduleName,D.UserLeft,o.userid,o.reason),this.emit("remoteUserOffLineNotify",o.userid,Wt.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===F.AliRtcConnectionStatusConnected&&(this.networkError||(this.connectState=F.AliRtcConnectionStatusDisconnected,this.emit("connectionStatusChange",F.AliRtcConnectionStatusDisconnected,Le.AliRtcConnectionChangedNetworkInterrupted)),this.networkError=!0)}onError(e){this.reporter.reportError(e),_.event(this.moduleName,D.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 E(R.ERROR_LOCAL_STREAM_NOT_EXIST,G[R.ERROR_LOCAL_STREAM_NOT_EXIST])}getCurrentMicDeviceId(){var e;return(e=this.publisher)==null?void 0:e.getCurrentMicDeviceId()}setChannelProfile(e){if(![F.AliRtcConnectionStatusInit,F.AliRtcConnectionStatusDisconnected,F.AliRtcConnectionStatusFailed].includes(this.connectState)){const t=R.ERROR_SET_CHANNEL_PROFILE_FAIL,r=G[t];throw new E(t,`${r}, cannot set channel profile in call`)}this.channelProfile=e,this.channelProfile===Ie.AliRtcSdkCommunication&&(this.clientRole=Ee.AliRtcSdkLive),this.signalingManager.setChannelProfile(e)}setClientRole(e){return S(this,null,function*(){var a,n,o,u,h;const t=R.ERROR_SET_CLIENT_ROLE_FAIL,r=G[t];try{if(this.channelProfile===Ie.AliRtcSdkCommunication)return;if(!Object.values(Ee).includes(e))throw new E(t,`${r}, role value(${e}) is invalid`);if(this.clientRole===e)return;this.isInCall()?this.clientRole===Ee.AliRtcSdkInteractive?(this.userManager.isSubscribing?(yield this.stopPublish(),yield(a=this.publisher)==null?void 0:a.clearStream()):yield(n=this.publisher)==null?void 0:n.unPublish(),yield this.signalingManager.setClientRole(e)):(yield this.signalingManager.setClientRole(e),yield this.startDefaultDevicesCapture(),(o=this.publisher)!=null&&o.isPublishing||(yield(u=this.publisher)==null?void 0:u.startPublish()),yield(h=this.publisher)==null?void 0:h.previewAll()):yield this.signalingManager.setClientRole(e),this.clientRole=e}catch(l){throw l.code===403&&this.emit("authInfoExpired"),l}})}getCurrentClientRole(){return this.clientRole}setAudioOnlyMode(e){if(this.isInCall())throw new E(R.ERROR_SET_AUDIO_ONLY_FAIL,`${G[R.ERROR_SET_AUDIO_ONLY_FAIL]}, cannot not change audioOnly mode after joining channel`);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 T.getCameraList(),t=yield T.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=bi.checkAuthInfo(e);if(this.webTrackingClient.updateAuthInfo(e),this.webTrackingClient.reportJoinChannel(e),F.AliRtcConnectionStatusInit===this.connectState||F.AliRtcConnectionStatusDisconnected===this.connectState||F.AliRtcConnectionStatusFailed===this.connectState){if(this.connectState=F.AliRtcConnectionStatusConnecting,a)throw this.connectState=F.AliRtcConnectionStatusFailed,this.webTrackingClient.reportJoinChannelRes(a.code,a.message,0),this.reporter.reportJoin(0,a.code,a.message),a;e.callid=_e.createCallid(),this.reporter.start(e);try{const d=yield this.signalingManager.join(e,t,this.maxSignalingConnectRetryCount);this.connectState=F.AliRtcConnectionStatusConnected,(n=this.publisher)==null||n.reportSelfDeviceStatus();let g=new Date().getTime()-r;this.webTrackingClient.reportJoinChannelRes(0,"",g),this.reporter.reportJoin(g,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(m=>m)&&(yield(h=this.publisher)==null?void 0:h.startPublish(),yield(l=this.publisher)==null?void 0:l.previewAll())),this.remoteUsers.forEach(m=>{m.updateSubscribe()}),this.liveTranscoding.setAuthInfo(e)}catch(d){let g=new Date().getTime()-r;const m=(p=d.code)!=null?p:-1,f=d.reason||d.message||"";throw this.webTrackingClient.reportJoinChannelRes(m,f,g),this.connectState=F.AliRtcConnectionStatusDisconnected,this.reporter.reportJoin(g,m,""),new E(m,f)}}else{const d=new E(fi.ERR_JOIN_ALREADY_JOINED,"Already logged in");throw this.connectState===F.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(F.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:""),_.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,""),_.setFlushMode(!0);return}})}isInCall(){return this.connectState===F.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===F.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 Error;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===F.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 E(R.ERROR_REMOTE_USER_NOT_FOUND);r&&(t===V.AliRtcVideoTrackScreen||t===V.AliRtcVideoTrackBoth)?n.setWantSubScreen(!0):n.setWantSubScreen(!1),r&&(t===V.AliRtcVideoTrackCamera||t===V.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=Je.frameRate,bitrate:r=Je.maxBitrate}=e;yield(a=this.publisher)==null?void 0:a.setScreenProfile(Fi,{width:Je.width,height:Je.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===F.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 Error;this.audioMixerPlugin.setOptions({screen:Math.max(0,Math.min(e,400))/100})}enableAudioVolumeIndication(e){this.userManager.enableAudioVolumeIndication(e)}muteLocalMic(e=!1){var t;this.hadPushStream(this.publishAudioStream),this.isPublishing&&this.onLocalDeviceStatusChange(e?D.MuteAudio:D.UnmuteAudio),(t=this.publisher)==null||t.muteLocalMic(e)}muteRemoteAudioPlaying(e,t=!1){const r=this.userManager.getRemoteUser(e);if(!r)throw new E(R.ERROR_REMOTE_USER_NOT_FOUND);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 Error;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 E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"Cannot set local view in audio only mode");(r=this.userManager)==null||r.setLocalViewConfig(e,t),t===V.AliRtcVideoTrackCamera&&((a=this.publisher)!=null&&a.hasCamera)?yield this.startPreview():t===V.AliRtcVideoTrackScreen&&((n=this.publisher)!=null&&n.hasScreenShare)&&(yield this.startPreviewScreen())})}setCameraCapturerConfiguration(e){return S(this,null,function*(){var h,l,p;const{width:t=ze.width,height:r=ze.height,frameRate:a=ze.frameRate,bitrate:n=ze.maxBitrate,cameraDirection:o,deviceId:u}=e;yield(h=this.publisher)==null?void 0:h.setVideoProfile(xi,{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,g;if(this._audioOnlyMode)throw new E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"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 m={video:!0};yield(d=this.publisher)==null?void 0:d.startCameraCapture(m)}else yield(g=this.publisher)==null?void 0:g.stopCameraCapture()})}muteLocalCamera(e){return S(this,null,function*(){var t,r,a;this.hadPushStream((r=(t=this.publisher)==null?void 0:t.publishStreams)==null?void 0:r.video),this.isPublishing&&this.onLocalDeviceStatusChange(e?D.MuteVideo:D.UnmuteVideo),(a=this.publisher)==null||a.muteLocalCamera(e)})}muteLocalScreen(e){return S(this,null,function*(){var t,r,a;this.hadPushStream((r=(t=this.publisher)==null?void 0:t.publishStreams)==null?void 0:r.screen),this.isPublishing&&this.onLocalDeviceStatusChange(e?D.MuteScreen:D.UnmuteScreen),(a=this.publisher)==null||a.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,g,m,f;if(this._audioOnlyMode)throw new E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"Cannot switch camera in audio only mode");const t={};e?t.deviceId=e:t.cameraDirection=((r=this.publisher)==null?void 0:r.cameraDirection)==="environment"?je.CAMERA_FRONT:je.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(),(m=(g=(d=(p=this.publisher)==null?void 0:p.publishStreams)==null?void 0:d.video)==null?void 0:g.videoTrack)==null||m.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 E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"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 E(R.ERROR_LOCAL_STREAM_CREATE_FAIL,"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===ee.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===ee.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 E(R.ERROR_PUBLISH_NEEDED,"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 E(De.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 E(De.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 E(De.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 E(De.AliRtcPluginErrorNoFindPlugin,"you should enable beautyPlugin first");const r={segmentBackgroundProcess:{type:0,enable:e}};e&&(r.setSegmentBackgroundImage={type:0,backgroundImgUrl:""}),t.setOptions(r)}},c(T,"logName","AliRtcEngine"),c(T,"isSupported",Qs),c(T,"isDualVideoStreamSupported",Si.isSupport),c(T,"getCameraList",()=>S(T,null,function*(){return(yield y.AliRTS.getCameraList()).filter(t=>t.deviceId)})),c(T,"getMicrophoneList",()=>S(T,null,function*(){return(yield y.AliRTS.getMicList()).filter(t=>t.deviceId)})),c(T,"getSpeakerList",()=>S(T,null,function*(){return(yield y.AliRTS.getSpeakerList()).filter(t=>t.deviceId)})),c(T,"_instance"),c(T,"AliRtcSdkChannelProfile",Ie),c(T,"AliRtcSdkClientRole",Ee),c(T,"AliRtcVideoStreamType",oe),c(T,"AliRtcVideoTrack",V),c(T,"AliRtcAudioTrack",Ne),c(T,"AliRtcPublishState",k),c(T,"AliRtcSubscribeState",K),c(T,"AliRtcRawDataStreamType",ee),c(T,"AliRtcLogLevel",Ht),c(T,"AliRtcEngineLocalDeviceType",be),c(T,"AliRtcEngineLocalDeviceExceptionType",Z),c(T,"AliRtcConnectionStatus",F),c(T,"AliRtcConnectionStatusChangeReason",Le),c(T,"AliRtcPlugin",Ve),c(T,"AliRtcPluginTrackType",ut),c(T,"AliRtcLiveTranscodingParam",dt),c(T,"AliRtcLiveTranscodingEncodeParam",zt),c(T,"AliRtcLiveTranscodingMixParam",Os),c(T,"AliRtcLiveTranscodingSingleParam",Ms),c(T,"AliRtcTranscodingClockWidget",Ns),c(T,"AliRtcTranscodingImage",Ri),c(T,"AliRtcTranscodingText",Us),c(T,"AliRtcTranscodingUser",Ds),c(T,"AliRtcLiveTranscodingMixMode",Ge),c(T,"AliRtcLiveTranscodingStreamType",jt),c(T,"AliRtcLiveTranscodingSourceType",Ue),c(T,"AliRtcLiveTranscodingTaskProfile",Gt),c(T,"AliRtcLiveTranscodingAudioSampleRate",ht),c(T,"AliRtcLiveTranscodingSegmentType",qe),c(T,"AliRtcLiveTranscodingFontType",Ke),c(T,"AliRtcLiveTranscodingCropMode",$t),c(T,"AliRtcLiveTranscodingMediaProcessMode",lt),c(T,"AliRtcLiveTranscodingState",qt),c(T,"AliRtcLiveTranscodingErrorCode",Re),c(T,"AliRtcTrascodingPublishTaskStatus",Kt),c(T,"Plugin",Ve),T);Y([v()],J.prototype,"stopPublish",1),Y([v()],J.prototype,"resumeSubList",1),Y([v()],J.prototype,"setEnableDualVideoStream",1),Y([v()],J.prototype,"setChannelProfile",1),Y([v()],J.prototype,"setClientRole",1),Y([v()],J.prototype,"joinChannel",1),Y([v()],J.prototype,"leaveChannel",1),Y([v()],J.prototype,"publishLocalVideoStream",1),Y([v()],J.prototype,"startScreenShare",1),Y([v()],J.prototype,"setScreenShareConfiguration",1),Y([v()],J.prototype,"publishLocalScreenShareStream",1),Y([v()],J.prototype,"enableAudioVolumeIndication",1),Y([v()],J.prototype,"muteLocalMic",1),Y([v()],J.prototype,"startAudioCapture",1),Y([v()],J.prototype,"switchMicrophone",1),Y([v()],J.prototype,"setAudioProfile",1),Y([v()],J.prototype,"setLocalViewConfig",1),Y([v()],J.prototype,"setCameraCapturerConfiguration",1),Y([v()],J.prototype,"enableLocalVideo",1),Y([v()],J.prototype,"muteLocalCamera",1),Y([v()],J.prototype,"muteLocalScreen",1),Y([v()],J.prototype,"setRemoteViewConfig",1),Y([v()],J.prototype,"switchCamera",1);let qn=J;I.AliRtcConnectionStatus=F,I.AliRtcConnectionStatusChangeReason=Le,I.AliRtcEngineLocalDeviceExceptionType=Z,I.AliRtcEngineLocalDeviceType=be,I.AliRtcLiveTranscodingAudioSampleRate=ht,I.AliRtcLiveTranscodingCropMode=$t,I.AliRtcLiveTranscodingEncodeParam=zt,I.AliRtcLiveTranscodingErrorCode=Re,I.AliRtcLiveTranscodingFontType=Ke,I.AliRtcLiveTranscodingMediaProcessMode=lt,I.AliRtcLiveTranscodingMixMode=Ge,I.AliRtcLiveTranscodingMixParam=Os,I.AliRtcLiveTranscodingParam=dt,I.AliRtcLiveTranscodingSegmentType=qe,I.AliRtcLiveTranscodingSingleParam=Ms,I.AliRtcLiveTranscodingSourceType=Ue,I.AliRtcLiveTranscodingState=qt,I.AliRtcLiveTranscodingStreamType=jt,I.AliRtcLiveTranscodingTaskProfile=Gt,I.AliRtcLocalStreamInfo=ei,I.AliRtcLogLevel=Ht,I.AliRtcPlugin=Ve,I.AliRtcPluginTrackType=ut,I.AliRtcPluginType=Mi,I.AliRtcPublishState=k,I.AliRtcRawDataStreamType=ee,I.AliRtcRemoteUserInfo=Wi,I.AliRtcSdkChannelProfile=Ie,I.AliRtcSdkClientRole=Ee,I.AliRtcSubscribeState=K,I.AliRtcTranscodingClockWidget=Ns,I.AliRtcTranscodingImage=Ri,I.AliRtcTranscodingText=Us,I.AliRtcTranscodingUser=Ds,I.AliRtcTrascodingPublishTaskStatus=Kt,I.AliRtcVideoStreamType=oe,I.AliRtcVideoTrack=V,I.default=qn,Object.defineProperties(I,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});