quickvo-sdk-js 0.9.8 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +21847 -21539
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -203,4 +203,4 @@ DÙ VààͳÄvÒ2; 5c±-ìÊöª§}Ou¡¡¦îGÇ D
|
|
|
203
203
|
Ùup3q@ݱuXtX07=Mp_¤I¬ø®®[¦ó[ÀRVsX?F^":ha?ØÎeÄQc{Yíz0j¹{b ×c4ö= %¡ì?XÜñÊ,xþÀf©ûyO}:Fà= NuÙO_hÌÍtÝg|ȳ]²(a= TÜøN»j/Ì|éÚ{^ëÐÖ{¡Çzñú_|Åûl*Ztì{8¯a@©¥ZKبc¿i<±üFÇkº-cy5±4§o9Ñ,;KzÌ $à1I=MºôÉ©¤=MêÈ5
|
|
204
204
|
}õíë(ðìÍäWD?£©ÿãª=MäÒ±ì6í)ÏÙtbFÐöÚFÈ´Ù§R1.]¢¦¨ùû,9ïtö»LÂôâ¦qªk{ä(9«4>°»B¶ñ»GÓ½vÃâ£d$°A0ô¼¦d=M¢«£Àß}â$æ0òÊ6¾%¼>3(
-D+ÂÔÂ
o7#æFåEIîkNDÒ_&3iÍHÌúk&@âk1ýîW¶Y¬XÞXáXâ¢XEeØØÈ\gi,Ç~æ{
Ü-ïÈÛx6Û{í8+¾\g¦ñÛírô9³®°3D_åãxQÈxþÚ·/ª= Íu_ÌuL^t^{g9áq?ª(üo!*Írâ&ÃËì÷¨Pd׺ÓG)àþê¤sJ
ñAÉå$AÐNÎçõnD1MøhO¥me Qʸ[F< ^MBÜÛ
|
|
205
205
|
Aãϧüï4î%M°6M
ùtN)FR[¾FqV6¥óðlò©Ë= c»R=}Ù8õ.%BÂIµÃI&æ×U1Q«Ïñ3&ÑóÓÝ»ñ²eL°(ÑòOzBð·Q]üôföê+h.³´)ÅKé¥JR#/GóuÉɾ¯Áõ¿-½ñ'î<·Q¼=MÛ²6+þçYdb_öcHmöôزj¾
nÚ7aÌvØOå¹÷e0FfÂÊÈønØ#?ÁhÊÀcÝåõ(åû)ü)éðк¿ÓÜ¡]qákÈÛÝL·ºrCMmp_ÀÏ Óìcç6®þsosÒÝóô1¬Ã6<2#Ò±C65Q"4B&pç
|
|
206
|
-
gUn
g= !þ+µèm M½Êê½½²¦é%0Yg~´p5.\Ø®zy9%ÔiÜ!ÙcÝŦH>ÓXÿZR[¬&ønÇlÓ_:ïi«ñ<ø"QÚ©yz
®ªOL¥ÎêÌÝi?Ê'/Ne»:2NÅÝ_òspüR Oø!!ù+##üÓkéªX-fpdq[U*]@ ö¨5ÍpÖYhܪ= ÛN3{ü® À)¡9þ-1® ÂcBNö÷0+È6òÒÑ;lÅ^_>ÓÛQ&jðMI줳àlS×j΢@ÈåÕ¢on=M°©xÉûÖäav=MM©²öÖ¹?{ÃßîøyÛ= 0òûÏ4grèNÒíÏqëðð-êö¸á¥$¨Q.Ò4ä¿V$N_Ý><´æë[â²F#T1É'utÿZXÁ(oàx¡Jo"öùSæ÷ÒUFÓs* U¡ÓºUµøGáL¨÷©ASjÕ®'!L¢ÕvC¿m·Gâ¼N¹³OÃã§1T:ê¹\Z£ËZæ.î}ª°O'ãà ¾I;ûÁHÃä&ÃÐÐK@3EÅÓÉ>½e@ã/òi¡|ÃE³{ñSCm
ÎëöÁÐÐ%Ó>d''¶9Á/T.N?äª æÿÀÐÐ%Ó¶ö¾ì¦)ÃÕ÷×"e|ÃþBåýrv¶K6öuâÐÌRÎËýæ×%IOIø¦Ä(HTJ~),ÕDCWWÃö(VwV=M§TsLP³ þV'tT#¡ZLêé;ßù[`});var _e={a:ce};this.setModule=Te=>{q.setModule(EmscriptenWASM,Te)},this.getModule=()=>q.getModule(EmscriptenWASM),this.instantiate=()=>(this.getModule().then(Te=>WebAssembly.instantiate(Te,_e)).then(Te=>{const qe=Te.exports;de(qe),D=qe.g,N(),xe(qe),K()}),this.ready=new Promise(Te=>{K=Te}).then(()=>{this.HEAP=D.buffer,this.malloc=fe,this.free=ve,this.opus_frame_decoder_create=we,this.opus_frame_decode_float_deinterleaved=ge,this.opus_frame_decoder_destroy=me}),this)}function OpusDecoder(q={}){OpusDecoder.errors||Object.defineProperties(OpusDecoder,{errors:{value:new Map([[-1,"OPUS_BAD_ARG: One or more invalid/out of range arguments"],[-2,"OPUS_BUFFER_TOO_SMALL: Not enough bytes allocated in the buffer"],[-3,"OPUS_INTERNAL_ERROR: An internal error was detected"],[-4,"OPUS_INVALID_PACKET: The compressed data passed is corrupted"],[-5,"OPUS_UNIMPLEMENTED: Invalid/unsupported request number"],[-6,"OPUS_INVALID_STATE: An encoder or decoder structure is invalid or already freed"],[-7,"OPUS_ALLOC_FAIL: Memory allocation has failed"]])}}),this._init=()=>new this._WASMAudioDecoderCommon(this).instantiate(this._EmscriptenWASM,this._module).then(Q=>{this._common=Q,this._inputBytes=0,this._outputSamples=0,this._frameNumber=0,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._output=this._common.allocateTypedArray(this._outputChannels*this._outputChannelSize,Float32Array);const ne=this._common.allocateTypedArray(this._channels,Uint8Array);ne.buf.set(this._channelMappingTable),this._decoder=this._common.wasm.opus_frame_decoder_create(this._sampleRate,this._channels,this._streamCount,this._coupledStreamCount,ne.ptr,this._preSkip,this._forceStereo)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.free(),this._common.wasm.opus_frame_decoder_destroy(this._decoder),this._common.wasm.free(this._decoder)},this._decode=Q=>{if(!(Q instanceof Uint8Array))throw Error("Data to decode must be Uint8Array. Instead got "+typeof Q);this._input.buf.set(Q);let ne=this._common.wasm.opus_frame_decode_float_deinterleaved(this._decoder,this._input.ptr,Q.length,this._output.ptr),re;return ne<0&&(re="libopus "+ne+" "+(OpusDecoder.errors.get(ne)||"Unknown Error"),console.error(re),ne=0),{outputBuffer:this._common.getOutputChannels(this._output.buf,this._outputChannels,ne),samplesDecoded:ne,error:re}},this.decodeFrame=Q=>{let ne=[];const re=this._decode(Q);return re.error&&this._common.addError(ne,re.error,Q.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=Q.length,this._outputSamples+=re.samplesDecoded,this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(ne,[re.outputBuffer],this._outputChannels,re.samplesDecoded,this._sampleRate)},this.decodeFrames=Q=>{let ne=[],re=[],te=0,oe=0;for(;oe<Q.length;){const le=Q[oe++],ae=this._decode(le);ne.push(ae.outputBuffer),te+=ae.samplesDecoded,ae.error&&this._common.addError(re,ae.error,le.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=le.length,this._outputSamples+=ae.samplesDecoded}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(re,ne,this._outputChannels,te,this._sampleRate)},this._isWebWorker=OpusDecoder.isWebWorker,this._WASMAudioDecoderCommon=OpusDecoder.WASMAudioDecoderCommon||WASMAudioDecoderCommon,this._EmscriptenWASM=OpusDecoder.EmscriptenWASM||EmscriptenWASM,this._module=OpusDecoder.module;const K=8,F=Q=>typeof Q=="number",Z=q.sampleRate,D=q.channels,N=q.streamCount,O=q.coupledStreamCount,I=q.channelMappingTable,z=q.preSkip,J=q.forceStereo?1:0;if(D>2&&(!F(N)||!F(O)||!Array.isArray(I)))throw new Error("Invalid Opus Decoder Options for multichannel decoding.");return this._sampleRate=[8e3,12e3,16e3,24e3,48e3].includes(Z)?Z:48e3,this._channels=F(D)?D:2,this._streamCount=F(N)?N:1,this._coupledStreamCount=F(O)?O:this._channels-1,this._channelMappingTable=I||(this._channels===2?[0,1]:[0]),this._preSkip=z||0,this._forceStereo=D<=K&&D!=2?J:0,this._inputSize=32e3*.12*this._channels,this._outputChannelSize=120*48,this._outputChannels=this._forceStereo?2:this._channels,this._ready=this._init(),this}class OpusDecoderWebWorker extends WASMAudioDecoderWorker{constructor(K){super(K,"opus-decoder",OpusDecoder,EmscriptenWASM)}async decodeFrame(K){return this.postToDecoder("decodeFrame",K)}async decodeFrames(K){return this.postToDecoder("decodeFrames",K)}}assignNames(OpusDecoder,"OpusDecoder"),assignNames(OpusDecoderWebWorker,"OpusDecoderWebWorker"),new OpusDecoder;class RoomPeer extends RoomUsers{constructor(F){super(F);Ie(this,"getPeerStatsTimer",0);Ie(this,"reports",[]);Ie(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});Ie(this,"initPeer",()=>{var Z;(Z=this.peerIns)==null||Z.close(),this.transceiverMap=new Map,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),Be(this,jn).call(this),Be(this,Jn).call(this);const F=[];this.peerIns.onicecandidate=async D=>{if(D.candidate){const N=await parseCandidate(D.candidate.candidate);F.push(N)}console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: parseCandidate",F)}});Ie(this,"getNatType",async()=>{});Ie(this,"initSendChannel",(F="",Z)=>{});Ie(this,"initReceiveChannel",(F="",Z)=>{});Ie(this,"replaceSenderStream",async(F=[],Z)=>{const{userId:D}=this.options;F.length===0&&(F=mediaType_keys);for(const N of F){const O=this.transceiverMap.get(N);let I;if(O){const{sender:z}=O;Z?I=this.getUserStream(D,N):I=this.getPhoneyStreams(N);const[J]=I.getTracks();J&&await z.replaceTrack(J)}}});Ie(this,"getSenderTracks",async(F=[])=>{const Z=[];for(const D of F){const N=this.transceiverMap.get(D);if(!N)continue;const{mid:O,sender:I}=N,{track:z}=I;if(!z)continue;const{id:J,enabled:Q}=z,ne=mediaType_keys.findIndex(te=>te===D),re={type:ne,enabled:Q,trackName:`web-${ne}-${J}`,location:"local",mid:O};Z.push(re)}return Z});Ie(this,"addSenders",async(F=[])=>{F.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const Z=[];for(const D of F){if(this.transceiverMap.get(D))continue;const O=this.getPhoneyStreams(D),[I]=O.getTracks(),z=this.peerIns.addTransceiver(I,{direction:"sendonly"});this.transceiverMap.set(D,z),Z.push(D)}if(F.length===0||Z.length!==0){const D=await this.peerIns.createOffer();if(this.options.debug){const N=libExports$1.parse(D.sdp),O=dt(N.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:O,sdpJson:N,description:D})}await this.peerIns.setLocalDescription(D)}return Z});Ie(this,"removeSenders",async(F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F)this.transceiverMap.has(Z)&&this.transceiverMap.delete(Z)});Ie(this,"onSubscribeUserTracks",F=>{let Z=0;return new Promise(async D=>{const N=[];for(const O of F){const{tracks:I=[]}=O;for(const z of I){const{trackName:J,mid:Q}=z,[ne]=await this.getUserTrackByTrackName([J]);N.push({...ne,mid:Q})}}{let O=[];const I=async()=>{clearTimeout(Z);const J=new Map;for(const ne of O){const{userId:re,mediaType:te}=ne;if(!re||!te)continue;J.has(re)||J.set(re,{userId:re,tracks:[],updateStreams:{}});const le=J.get(re);le.tracks.push(ne),le.updateStreams[te]=!0}const Q=[...J.values()];for(const ne of Q){const{userId:re,tracks:te}=ne;await this.updateUsertracks(re,te,!0)}await this.emitNotifyUpdateUsersStreams(Q),this.peerIns.removeEventListener("track",z);{const ne=Array.from(N,oe=>oe.trackName),re=Array.from(O,oe=>oe.trackName),te=ne.filter(oe=>!re.includes(oe));D({target:ne,success:re,fail:te})}},z=async J=>{const{streams:Q,transceiver:ne}=J,[re]=Q,{mid:te,receiver:oe}=ne,{track:le}=oe,{id:ae}=le,ce=N.find(fe=>fe.mid===`${te}`);if(!ce)return;const{userId:de,mediaType:we}=ce;if(!(!de||!we)){{const fe={...ce,mid:te,msid:ae};O.push(fe)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${O.length}/${N.length}`,{mediaType:we,mid:te,userTrack:ce,e:J});{const fe=new Audio;if(fe.srcObject=re,await this.initUserMediaStreamContext(de,we,re),we==="microphoneCamera_audio"||we==="screenSharing_audio"){const ge=this.getUserAudioMediaStreamContext(de,we);ge==null||ge.setMute(!1)}}N.length===O.length&&I()}};this.peerIns.addEventListener("track",z),Z=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${O.length}/${N.length})`),I()},5*1e3)}})});st(this,jn,()=>{let F=0;const Z=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.onconnectionstatechange=async D=>{const N=D.target.connectionState;switch(await this.taskQueue.setCondition("ice",!1),clearTimeout(F),N){case"connected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${N}`),await this.taskQueue.setCondition("ice",!0),await this.getNatType(),this.setRoomState("connected");break;case"disconnected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${N}`),F=window.setTimeout(Z,30*1e3);break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${N}`),this.setRoomState("failed");break;case"closed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${N}`),Z();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${N}`);break}}});Ie(this,"closeUserTracks",async(F,Z=[],D=!1)=>{const N=[];for(const J of Z){const{trackName:Q,msid:ne}=J;N.push(Q),ne&&N.push(ne)}const O=J=>N.includes(J),I=this.peerIns.getTransceivers();for(const J of I){const{mid:Q,sender:ne,receiver:re}=J;ne.track&&O(ne.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${Q} is stop.`,J)),re.track&&O(re.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${Q} is stop.`,J))}const z=await this.getUser(F);if(z){for(const J of z.tracks){const{trackName:Q,msid:ne,userId:re,mediaType:te}=J;!re||!te||!O(Q)||(this.removeUserMediaStreamContext(re,te),ne&&delete J.msid)}if(D){const J=z.tracks.filter(({trackName:Q})=>!O(Q));await this.updateUsertracks(F,J,!1)}}});Ie(this,"createOffer",async()=>{const F=await this.peerIns.createOffer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"createAnswer",async()=>{const F=await this.peerIns.createAnswer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"getSdp",()=>{var F;return(F=this.peerIns.localDescription)==null?void 0:F.sdp});Ie(this,"setRemoteDescription",async F=>{if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:D,sdpJson:Z,description:F})}return await this.peerIns.setRemoteDescription(F),F});Ie(this,"setCallStrategy",async(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);let D="balanced";switch(F){case"qualityPriority":D="maintain-resolution";break;case"fluencyPriority":D="maintain-framerate";break;case"balancedDowngrade":D="balanced";break}const N=await this.getSelfInfo(),O=Array.from(N.tracks,({trackName:z})=>z),I=this.peerIns.getSenders();for(const z of I){const{track:J}=z;if(!J||!O.includes(J.id))continue;const Q=z.getParameters();z.setParameters({...Q,degradationPreference:D})}});Ie(this,"setRTCRtpSenderParameters",F=>{try{const Z=this.peerIns.getSenders();for(const D of Z){const N=D.getParameters();D.setParameters({...N,...F})}}catch(Z){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",Z)}});Ie(this,"getReportsByMid",async(F=[])=>F.length===0?this.reports:this.reports.filter(Z=>F.includes(Z.mid)));Ie(this,"getRoomNetwork",()=>this.peerNetwork);Ie(this,"getPeerNetwork",()=>this.peerNetwork);st(this,zn,async()=>{try{const F=await this.peerIns.getStats(),Z=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],N=[...F.values()].filter(ge=>Z.includes(ge.type));let O=0,I=0,z=0,J=0,Q=0,ne=0,re=[],te=[];for(const ge of this.reports){const{packetsSent:me,packetsLost:ve}=ge;me&&(z+=me),ve&&(J+=ve)}this.reports=N;for(const ge of this.reports){const{bytesSent:me,bytesReceived:ve,packetsSent:ke,packetsLost:xe,roundTripTime:_e,jitter:Te}=ge;me&&(I=me),ve&&(O=ve),ke&&(Q+=ke),xe&&(ne+=xe),_e&&re.push((_e*100).toFixed(2)),Te&&te.push(Te.toFixed(2))}te.sort().reverse(),re.sort().reverse();const oe=Q-z,le=ne-J,ae=oe===0?"0.00":(le/oe).toFixed(2),[ce="0"]=re,[de="0"]=te,we={outboundBytes:I,inboundBytes:O,lostRate:ae,roundTripTime:ce,jitter:de};this.peerNetwork=we;const fe=(ge,me,ve)=>{const ke=Number(ge),xe=Number(me),_e=Number(ve);let Te="0";return ke<.03&&xe<100&&_e<.05?Te="5":ke<.06&&xe<160&&_e<.1?Te="4":ke<.1&&xe<250&&_e<.15?Te="3":ke<.15&&xe<400&&_e<.2?Te="2":Te="1",Number(Te)};{const ge=fe(ae,ce,de),me=await this.getSelfInfo(),{network:ve}=me,ke={egress:ge,ingress:ge};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,ke),JSON.stringify(ve)!==JSON.stringify(ke)){this.emitNotifyUpdateUsers();const{userId:Te,roomId:qe}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...ke,userId:Te,roomId:qe}},!1)}},3*1e3)}}catch(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",F)}});st(this,Jn,()=>{const F=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||Be(this,zn).call(this)};this.getPeerStatsTimer=window.setInterval(F,1*1e3)});Ie(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer))}}jn=new WeakMap,zn=new WeakMap,Jn=new WeakMap;class RoomCalls extends RoomPeer{constructor(F){super(F);st(this,On,0);Ie(this,"setLocalStream",(F,Z)=>new Promise(async(D,N)=>{try{typeof F=="string"&&(F=[F]);for(const I of F)this.localStreamsActionMap.set(I,Z);if(Z){if(F.includes("microphoneCamera_audio")&&F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):F.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):F.includes("screenSharing_audio")&&F.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):F.includes("screenSharing_audio")&&!F.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):F.includes("screenSharing_video")&&!F.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),F.includes("screenSharing_audio")){const I=await this.getLocalStream("screenSharing_audio");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if(F.includes("screenSharing_video")){const I=await this.getLocalStream("screenSharing_video");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams(F);const O=await this.getLocalStreams(F);this.cwsIns.emitNotify("onLocalStream",{code:200,data:O,desc:"local stream is change."}),D(O)}catch(O){N(O)}}));Ie(this,"setMediaDeviceKind",(F,Z)=>new Promise(async(D,N)=>{this.setDeviceKind(F,Z);const O=await this.getSelfInfo(),{id:I,tracks:z=[],callActionMap:J}=O,Q=[],ne=async re=>{const te=this.localStreamsActionMap.get(re),oe=z.find(ae=>ae.mediaType===re),le=J[re];if(te){Q.push(re),await this.stopLocalStreams([re]);try{await this.initLocalStream(re)}catch(ae){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initLocalStream is error.",ae),await this.inactiveTracks([re],!1),N(ae)}}if(oe){const ae=await this.getLocalStream(re);ae&&(await this.initUserMediaStreamContext(I,re,ae),le&&await this.replaceSenderStream([re],!0))}{const ae=await this.getLocalStreams(Q);this.cwsIns.emitNotify("onLocalStream",{code:200,data:ae,desc:"local stream is change."}),await this.emitNotifyUpdateUsers(),D(!0)}};F==="audioinput"&&ne("microphoneCamera_audio"),F==="videoinput"&&ne("microphoneCamera_video"),F==="audiooutput"&&(await this.changeAudiooutput(),D(!0))}));Ie(this,"changeScreenSharing",async F=>{const Z=await this.getSelfInfo(),{tracks:D=[],callActionMap:N}=Z;try{await this.setLocalStream(F,!0);for(const O of F)D.find(z=>z.mediaType===O&&N[O])&&await this.replaceSenderStream([O],!0)}catch(O){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",O)}});Ie(this,"createSession",()=>new Promise(async(F,Z)=>{if(["connecting","connected"].includes(this.roomState))return F(!0);this.setRoomState("connecting"),await this.taskQueue.createTask({describe:"createSession",conditionKeys:["createWs","createSession"],changeConditionKeys:["createSession"],func:()=>new Promise(async(D,N)=>{try{await this.addSenders(),this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async O=>{const{code:I=0,desc:z,data:J}=O;if(I!==200)return N(z);const{remoteSdp:Q}=J;await this.taskQueue.setCondition("ice",!1),await this.taskQueue.createTask({describe:"ice",timeout:30*1e3,conditionKeys:["ice"],func:()=>new Promise(ne=>setTimeout(()=>ne(!0),300)),success:async()=>{D(!0)},fail:async ne=>{throw new Error(`ice connection failed: ${ne}`)}}),await this.setRemoteDescription({type:"answer",sdp:Q})})}catch(O){N(O)}}),success:async D=>{F(D)},fail:async D=>{this.reportLogs("ws_c_timeout",D.message||D),Z(D)},complete:()=>{this.taskQueue.setCondition("createSession",!0)}})}));Ie(this,"earlyConnect",(F=[])=>{this.isEarly=!0,Be(this,An).call(this),this.createSession(),F.length===0&&(F=["microphoneCamera_audio","microphoneCamera_video"]),Be(this,$n).call(this,F)});Ie(this,"joinRoom",async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"joinRoom",conditionKeys:["createWs"],changeConditionKeys:["joinRoom"],func:()=>new Promise(async(N,O)=>{try{this.setOptions(F),await Be(this,An).call(this),this.clearUsers();const{roomId:I,userId:z,callType:J,sdkToken:Q}=this.options;this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:J,roomId:I,user:{id:z,tracks:[],callAction:0},token:Q},version:2}).then(async ne=>{const{code:re=0,desc:te="服务器繁忙",data:oe}=ne;if(re!==200)return O(te);const{roomId:le="",roomUsers:ae=[]}=oe;if(le!==I)return O("加入的房间不匹配");this.isInRoom=!0,this.initHeartbeat(),this.createSession(),await this.updateUsers(ae);const ce=[];for(const we of ae){const{id:fe,channelCache:ge}=we,{channels:me=[]}=ge;await this.updateUserBehaviors(fe,we.behavior),await this.updateUserChannels(fe,me,!1),me.length!==0&&ce.push({userId:fe,channels:me})}this.subChannel(ce),await this.emitNotifyUpdateUsers();const de=await this.getUsers();N(de)})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("join_room_error",N.message||N),D(N)},complete:()=>{this.taskQueue.setCondition("joinRoom",!0)}})}));Ie(this,"quitRoom",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,clearInterval(Be(this,On)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),await this.taskQueue.setCondition("closeTrack",!0),this.cwsIns.sendMessage({event:"quitRoom",data:N}),F(!0)}));Ie(this,"quitRoomEx",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:N}),F(!0)}));Ie(this,"syncRoomInfo",()=>new Promise(async(F,Z)=>{const{userId:D}=this.options,N=await this.getUser(D),{id:O=D,callAction:I=0}=N;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:O,callAction:I}}}).then(async z=>{if(z.code!==200)return Z(z.desc);const J=z.data.users;this.clearUsers(),await this.updateUsers(J),await this.updateUsertracks(N.id,N.tracks,!1);{const Q=await this.getUsers();F(Q)}}).catch(z=>Z(z))}));Ie(this,"publish",F=>new Promise(async(Z,D)=>{{const N=await this.getSelfInfo(),{banBehaviorMap:O}=N;let I=!0;for(const z of F)if(O[z]){I=!1;break}if(I===!1)return D("publish is error: prohibited by administrator.")}try{await this.setLocalStream(F,!0)}catch(N){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",N)}await this.taskQueue.createTask({describe:"publish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["publish"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo(),z=[];for(const te of F){{const oe=this.getPhoneyStreams(te);await this.initUserMediaStreamContext(I.id,te,oe)}{const oe=await this.getLocalStream(te);oe?await this.initUserMediaStreamContext(I.id,te,oe):z.push(te)}}const J=F.filter(te=>!z.includes(te)||["microphoneCamera_audio","microphoneCamera_video"].includes(te));await this.replaceSenderStream(F,!1),await Be(this,$n).call(this,J);const Q=await this.getSenderTracks(J),ne=[...I.tracks,...Q];await this.updateUsertracks(I.id,ne,!0);const re=await this.getCallAction(ne);await Be(this,En).call(this,re),z.length!==0&&await this.inactiveTracks(z,!1),J.length!==0&&await this.replaceSenderStream(J,!0),Be(this,Wn).call(this,F);{await this.emitNotifyUpdateUsers();const te=await this.getSelfInfo();N(te)}}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("publish",!0)}})}));Ie(this,"stopPublish",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"stopPublish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo();F.length===0&&(F=mediaType_keys);const z=I.tracks.filter(({mediaType:Q})=>Q&&F.includes(Q)),J=async()=>{this.initMediaPhoneyStreams(F);const Q=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),N(Q)};if(z.length===0)return J();await this.replaceSenderStream(F,!0),await this.closeUserTracks(I.id,z,!0),await this.removeSenders(F);{const Q=await this.getCallAction(I.tracks);await Be(this,En).call(this,Q)}await this.createOffer(),this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{code:ne=0,data:re,desc:te}=Q;if(ne!==200)return O(te);const{remoteSdp:oe}=re;await this.setRemoteDescription({type:"answer",sdp:oe}),J()})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"subscribe",(F=[],Z=3)=>new Promise(async(D,N)=>{const O=await this.taskQueue.createTask({describe:"subscribe",strict:!0,conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["subscribe"],func:()=>new Promise(async(I,z)=>{try{const J=await this.getUsers();let Q=[];for(const te of J){const{isSelf:oe,tracks:le=[]}=te;if(!oe){const ae=le.filter(({trackName:ce,mid:de=""})=>de!==""&&(F.includes(ce)||F.length===0));ae.length!==0&&Q.push({...te,tracks:ae})}}const ne=async(te={})=>{const oe=Array.from(Q,({id:ae})=>ae),le=await this.getUsers(oe);await this.emitNotifyUpdateUsers(),I({users:le,detail:te})};if(Q.length===0)return ne();const re=[];for(const te of Q){const{id:oe,tracks:le}=te,ae=dt(le,["type","trackName"]),ce={id:oe,tracks:ae};re.push(ce)}this.cwsIns.sendMessage({event:"subscribe",data:{users:re}}).then(async te=>{const{code:oe=0,data:le,desc:ae}=te;if(oe!==200)return z(ae);const{remoteSdp:ce,users:de=[]}=le;this.onSubscribeUserTracks(de).then(async we=>{await this.renegotiate().then(()=>ne(we)).catch(fe=>z(fe))}).catch(we=>{z(we)}),await this.setRemoteDescription({type:"offer",sdp:ce})})}catch(J){z(J)}}),success:async I=>{O.clear(),this.taskQueue.setCondition("subscribe",!0),D(I)},fail:async I=>{if(this.options.debug&&console.info("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: subscribe error. surplus count is ${Z}`),Z>0)return await new Promise(z=>setTimeout(()=>z(!0),(3-Z)*1e3)),Z=Z-1,O.retry();O.clear(),this.reportLogs("subscribe_error",I.message||I),this.taskQueue.setCondition("subscribe",!0),N(I)},complete:async()=>{}})}));Ie(this,"renegotiate",()=>new Promise(async(F,Z)=>{try{await this.taskQueue.setCondition("renegotiate",!1),await this.createAnswer(),this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(D=>{const{code:N=0,desc:O}=D;if(N!==200)return Z(O);F(D)}).finally(()=>{this.taskQueue.setCondition("renegotiate",!0)})}catch(D){Z(D)}}));Ie(this,"stopSubscribe",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"closeTrack",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getUsers(),z=[];for(const Q of I){const{tracks:ne=[]}=Q;for(const re of ne){const{type:te,mid:oe,trackName:le,mediaType:ae,msid:ce}=re;if(!(!ae||!ce)&&(F.length===0||F.includes(le))){const de={type:te,mid:oe,trackName:ce};z.push(de),await this.closeUserTracks(Q.id,[re])}}}const J=async()=>{await this.emitNotifyUpdateUsers(),N(!0)};if(z.length===0)return J();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{remoteSdp:ne}=Q.data;await this.setRemoteDescription({type:"answer",sdp:ne})}),J()}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: stopPublish is error.",N),this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"inactiveTracks",async(F,Z)=>new Promise(async D=>{const N=await this.getSelfInfo();if(!N||!N.id)return D(!0);const{tracks:O=[]}=N,I=[...O];for(let J of I){const{mediaType:Q}=J;if(Q&&F.includes(Q)){J.enabled=Z;const ne=await this.getLocalStream(Q);if(!ne)continue;const re=ne.getTracks();for(const te of re)te.enabled=Z}}const z=await this.getCallAction(I);await Be(this,En).call(this,z),await this.replaceSenderStream(F,Z),await this.emitNotifyUpdateUsers(),D(!0)}));Ie(this,"setBanBehaviors",F=>new Promise(async(Z,D)=>{try{const{roomId:N}=this.options,O=[];for(const I of F){const{id:z,banBehaviors:J}=I,Q=Object.keys(J);if(Q.length===0)continue;const ne=[];for(const te of Q){const oe=mediaType_keys.findIndex(ce=>ce===te),le=J[te],ae={type:oe,behavior:le};ne.push(ae)}const re={id:z,behaviors:ne};O.push(re)}this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:N,users:O}}).then(async I=>{const{code:z=0,desc:J}=I;if(z!==200)return D(J);Z(I)}).finally(()=>{})}catch(N){D(N)}}));Ie(this,"pubChannel",()=>new Promise(async(F,Z)=>{const N=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:N}}).then(async O=>{const{code:I=0,data:z,desc:J}=O;if(I!==200)return Z(J);const{channels:Q=[]}=z;for(const ne of Q){const{channels:re=[]}=ne;for(const te of re){const{dataChannelName:oe,id:le}=te;this.initSendChannel(oe,le)}}F(!0)}).catch(O=>{Z(O)})}));Ie(this,"subChannel",(F=[])=>new Promise(async(Z,D)=>{if(F.length===0)return Z(!0);await this.taskQueue.createTask({describe:"subChannel",strict:!0,conditionKeys:["createWs","createSession","ice"],changeConditionKeys:[],func:()=>this.cwsIns.sendMessage({event:"subChannel",data:{channels:F}}).then(async N=>{const{code:O=0,data:I,desc:z}=N;if(O!==200)return D(z);const{channels:J=[]}=I;for(const Q of J){const{channels:ne=[]}=Q;for(const re of ne){const{dataChannelName:te,id:oe}=re;this.initReceiveChannel(te,oe)}}}),success:async N=>{Z(N)},fail:async N=>{D(N)}})}));Ie(this,"debugger",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"shutdown",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"initHeartbeat",()=>{this.stopHeartbeat();const F=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),Z=this.isInRoom?5*1e3:30*1e3;At(this,On,window.setInterval(F,Z)),F()});Ie(this,"stopHeartbeat",()=>{clearInterval(Be(this,On))});st(this,Wn,async F=>{const{roomId:Z}=this.options;if(!Z)return;const{id:D,tracks:N=[]}=await this.getSelfInfo(),O=N.filter(I=>I.mediaType&&F.includes(I.mediaType));O.length!==0&&this.cwsIns.sendMessage({event:"pubNotify",data:{roomId:Z,user:{id:D,tracks:O}}})});st(this,En,async F=>new Promise(async(Z,D)=>{const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O,callAction:F}};await this.cwsIns.sendMessage({event:"updateCall",data:I}).then(async z=>{const{code:J=0}=z;if(J!==200)return D(z);await this.updateUserCallAction(O,F),Z(F)}).catch(z=>D(z))}));st(this,An,()=>new Promise(async(F,Z)=>{try{if(["connecting","connected"].includes(this.cwsIns.state))return F(!0);await this.taskQueue.setCondition("createWs",!1),this.cwsIns.clearEvents(),this.initPeer();const{appid:D,roomId:N,userId:O}=this.options;if(!D)return Z("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const I={c:D,r:N,v:this.sdk_service_version};if(this.isEarly){const J=xt();I.i=J,this.setOptions({earlyId:J})}else I.b=O;this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs",I);const z=btoa(encodeURI(JSON.stringify(I)));await this.cwsIns.connect(z),this.initHeartbeat(),await this.taskQueue.setCondition("createWs",!0),await this.taskQueue.setCondition("createSession",!0),F(!0)}catch(D){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",D),this.reportLogs("ws_c_timeout",D.message||D),Z(D)}}));st(this,$n,async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"createTrack",conditionKeys:["createWs","createSession","ice","createTrack","subscribe","renegotiate","closeTrack"],func:()=>new Promise(async(N,O)=>{try{await this.taskQueue.setCondition("createTrack",!1);const I=await this.addSenders(F),z=await this.getSenderTracks(I);if(z.length===0)return await this.taskQueue.setCondition("createTrack",!0),N(!0);this.cwsIns.sendMessage({event:"publish",data:{sdp:this.getSdp(),tracks:z,callAction:0}}).then(async J=>{const{code:Q=0,desc:ne,data:re}=J;if(Q!==200)return O(ne);const{remoteSdp:te}=re;await this.setRemoteDescription({type:"answer",sdp:te}),N(!0)})}catch(I){await this.removeSenders(F),O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("createTrack",!0)}})}))}}On=new WeakMap,Wn=new WeakMap,En=new WeakMap,An=new WeakMap,$n=new WeakMap;class Room extends RoomCalls{constructor(K){super(K)}}class QuickVO extends Room{constructor(F){super(F);st(this,_n,new Map);Ie(this,"reconstruct",async()=>{if(this.cwsIns.state!=="connected"||this.roomState!=="failed")return;this.setRoomState("ready"),this.initMediaPhoneyStreams(),this.taskQueue.clear(),this.peerIns.close(),await this.syncRoomInfo(),this.initPeer(),this.taskQueue.setCondition("createSession",!0),this.taskQueue.setCondition("ice",!0),await this.createSession();const F=[],Z=[],D=await this.getUsers();for(const N of D){const{isSelf:O,callActionMap:I,tracks:z=[]}=N;if(O)for(const J of mediaType_keys)I[J]&&F.push(J);for(const J of z)J.msid&&Z.push(J.trackName)}await this.subscribe(Z),await this.publish(F)});st(this,Vn,()=>{{const F=async Z=>{const{state:D}=Z.data;if(D==="closed"){const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:I}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}this.reconstruct()};this.cwsIns.addNotify({event:"onRoomState",callback:F},!0)}{const F=async Z=>{const{qualities:D=[]}=Z.data,[N]=D;if(!(N&&N.userId===this.options.userId&&D.length===1)){for(const O of D){const{userId:I,egress:z,ingress:J}=O;this.checkUserInRoom(I)&&await this.updateUserNetwork(I,{egress:z,ingress:J})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:F},!0)}{const F=async Z=>{const D=Z.data.user;await this.updateUsers([D]),await this.updateUsertracks(D.id,D.track,!1),await this.updateUserBehaviors(D.id,D.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:F},!0)}{const F=async Z=>{await this.removeUsers([Z.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,tracks:O=[],callAction:I=0}=D;if(await this.updateUserCallAction(N,I),await this.updateUserPermissions(N,3),await this.updateUsertracks(N,O,!0),this.options.newPublishAutoSubscribe){const z=this.getTrackNamesFormTracks(O);await this.subscribe(z)}else await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onPublish",callback:F},!0)}{const F=async Z=>{const D=[Z.data];this.subChannel(D)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:F},!0)}{const F=async Z=>{const{id:D,tracks:N}=Z.data.user;D!==this.options.userId&&(await this.closeUserTracks(D,N,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:F},!0)}{const F=async Z=>{const{id:D,callAction:N}=Z.data.user;this.checkUserInRoom(D)&&(await this.updateUserCallAction(D,N),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,permissions:O=1}=D;O===1?await this.removeUsers([N]):O===3&&await this.updateUsers([D]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:F},!0)}{const F=async Z=>{const{users:D}=Z.data;for(const N of D){const{id:O,behavior:I}=N;await this.updateUserBehaviors(O,I)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:F},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async F=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});Ie(this,"addNotify",F=>this.cwsIns.addNotify(F));st(this,Zn,()=>{});st(this,Kn,()=>{this.cwsIns.onReconnectSuccess=async()=>{this.reconstruct()}});st(this,Gn,async()=>{this.setRoomState("closed")});Ie(this,"addRequestAnimationFrame",async(F,Z)=>{{const N=Be(this,_n).get(F);N&&cancelAnimationFrame(N)}const D=(N=Date.now())=>{Z(N);const O=requestAnimationFrame(D);Be(this,_n).set(F,O)};D()});Ie(this,"clearRequestAnimationFrame",async(F=[])=>{F.length===0&&(F=[...Be(this,_n).keys()]);const Z=[];for(const D of F){const N=Be(this,_n).get(D);N&&(cancelAnimationFrame(N),Z.push(N))}return Z});Ie(this,"destroy",async()=>{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 销毁SDK"),this.cwsIns.emitNotify("onDestroy",{code:200,data:{},desc:"sdk is destroy."}),this.stopLocalStreams(),await new Promise(F=>setTimeout(()=>F(!0),300)),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.cwsIns.close()});Be(this,Zn).call(this),Be(this,Kn).call(this),Be(this,Gn).call(this),Be(this,Vn).call(this)}}_n=new WeakMap,Vn=new WeakMap,Zn=new WeakMap,Kn=new WeakMap,Gn=new WeakMap,exports.QuickVO=QuickVO,exports.ignoreEvent=ignoreEvent,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|
|
206
|
+
gUn
g= !þ+µèm M½Êê½½²¦é%0Yg~´p5.\Ø®zy9%ÔiÜ!ÙcÝŦH>ÓXÿZR[¬&ønÇlÓ_:ïi«ñ<ø"QÚ©yz
®ªOL¥ÎêÌÝi?Ê'/Ne»:2NÅÝ_òspüR Oø!!ù+##üÓkéªX-fpdq[U*]@ ö¨5ÍpÖYhܪ= ÛN3{ü® À)¡9þ-1® ÂcBNö÷0+È6òÒÑ;lÅ^_>ÓÛQ&jðMI줳àlS×j΢@ÈåÕ¢on=M°©xÉûÖäav=MM©²öÖ¹?{ÃßîøyÛ= 0òûÏ4grèNÒíÏqëðð-êö¸á¥$¨Q.Ò4ä¿V$N_Ý><´æë[â²F#T1É'utÿZXÁ(oàx¡Jo"öùSæ÷ÒUFÓs* U¡ÓºUµøGáL¨÷©ASjÕ®'!L¢ÕvC¿m·Gâ¼N¹³OÃã§1T:ê¹\Z£ËZæ.î}ª°O'ãà ¾I;ûÁHÃä&ÃÐÐK@3EÅÓÉ>½e@ã/òi¡|ÃE³{ñSCm
ÎëöÁÐÐ%Ó>d''¶9Á/T.N?äª æÿÀÐÐ%Ó¶ö¾ì¦)ÃÕ÷×"e|ÃþBåýrv¶K6öuâÐÌRÎËýæ×%IOIø¦Ä(HTJ~),ÕDCWWÃö(VwV=M§TsLP³ þV'tT#¡ZLêé;ßù[`});var _e={a:ce};this.setModule=Te=>{q.setModule(EmscriptenWASM,Te)},this.getModule=()=>q.getModule(EmscriptenWASM),this.instantiate=()=>(this.getModule().then(Te=>WebAssembly.instantiate(Te,_e)).then(Te=>{const qe=Te.exports;de(qe),D=qe.g,N(),xe(qe),K()}),this.ready=new Promise(Te=>{K=Te}).then(()=>{this.HEAP=D.buffer,this.malloc=fe,this.free=ve,this.opus_frame_decoder_create=we,this.opus_frame_decode_float_deinterleaved=ge,this.opus_frame_decoder_destroy=me}),this)}function OpusDecoder(q={}){OpusDecoder.errors||Object.defineProperties(OpusDecoder,{errors:{value:new Map([[-1,"OPUS_BAD_ARG: One or more invalid/out of range arguments"],[-2,"OPUS_BUFFER_TOO_SMALL: Not enough bytes allocated in the buffer"],[-3,"OPUS_INTERNAL_ERROR: An internal error was detected"],[-4,"OPUS_INVALID_PACKET: The compressed data passed is corrupted"],[-5,"OPUS_UNIMPLEMENTED: Invalid/unsupported request number"],[-6,"OPUS_INVALID_STATE: An encoder or decoder structure is invalid or already freed"],[-7,"OPUS_ALLOC_FAIL: Memory allocation has failed"]])}}),this._init=()=>new this._WASMAudioDecoderCommon(this).instantiate(this._EmscriptenWASM,this._module).then(Q=>{this._common=Q,this._inputBytes=0,this._outputSamples=0,this._frameNumber=0,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._output=this._common.allocateTypedArray(this._outputChannels*this._outputChannelSize,Float32Array);const ne=this._common.allocateTypedArray(this._channels,Uint8Array);ne.buf.set(this._channelMappingTable),this._decoder=this._common.wasm.opus_frame_decoder_create(this._sampleRate,this._channels,this._streamCount,this._coupledStreamCount,ne.ptr,this._preSkip,this._forceStereo)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.free(),this._common.wasm.opus_frame_decoder_destroy(this._decoder),this._common.wasm.free(this._decoder)},this._decode=Q=>{if(!(Q instanceof Uint8Array))throw Error("Data to decode must be Uint8Array. Instead got "+typeof Q);this._input.buf.set(Q);let ne=this._common.wasm.opus_frame_decode_float_deinterleaved(this._decoder,this._input.ptr,Q.length,this._output.ptr),re;return ne<0&&(re="libopus "+ne+" "+(OpusDecoder.errors.get(ne)||"Unknown Error"),console.error(re),ne=0),{outputBuffer:this._common.getOutputChannels(this._output.buf,this._outputChannels,ne),samplesDecoded:ne,error:re}},this.decodeFrame=Q=>{let ne=[];const re=this._decode(Q);return re.error&&this._common.addError(ne,re.error,Q.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=Q.length,this._outputSamples+=re.samplesDecoded,this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(ne,[re.outputBuffer],this._outputChannels,re.samplesDecoded,this._sampleRate)},this.decodeFrames=Q=>{let ne=[],re=[],te=0,oe=0;for(;oe<Q.length;){const le=Q[oe++],ae=this._decode(le);ne.push(ae.outputBuffer),te+=ae.samplesDecoded,ae.error&&this._common.addError(re,ae.error,le.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=le.length,this._outputSamples+=ae.samplesDecoded}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(re,ne,this._outputChannels,te,this._sampleRate)},this._isWebWorker=OpusDecoder.isWebWorker,this._WASMAudioDecoderCommon=OpusDecoder.WASMAudioDecoderCommon||WASMAudioDecoderCommon,this._EmscriptenWASM=OpusDecoder.EmscriptenWASM||EmscriptenWASM,this._module=OpusDecoder.module;const K=8,F=Q=>typeof Q=="number",Z=q.sampleRate,D=q.channels,N=q.streamCount,O=q.coupledStreamCount,I=q.channelMappingTable,z=q.preSkip,J=q.forceStereo?1:0;if(D>2&&(!F(N)||!F(O)||!Array.isArray(I)))throw new Error("Invalid Opus Decoder Options for multichannel decoding.");return this._sampleRate=[8e3,12e3,16e3,24e3,48e3].includes(Z)?Z:48e3,this._channels=F(D)?D:2,this._streamCount=F(N)?N:1,this._coupledStreamCount=F(O)?O:this._channels-1,this._channelMappingTable=I||(this._channels===2?[0,1]:[0]),this._preSkip=z||0,this._forceStereo=D<=K&&D!=2?J:0,this._inputSize=32e3*.12*this._channels,this._outputChannelSize=120*48,this._outputChannels=this._forceStereo?2:this._channels,this._ready=this._init(),this}class OpusDecoderWebWorker extends WASMAudioDecoderWorker{constructor(K){super(K,"opus-decoder",OpusDecoder,EmscriptenWASM)}async decodeFrame(K){return this.postToDecoder("decodeFrame",K)}async decodeFrames(K){return this.postToDecoder("decodeFrames",K)}}assignNames(OpusDecoder,"OpusDecoder"),assignNames(OpusDecoderWebWorker,"OpusDecoderWebWorker"),new OpusDecoder;class RoomPeer extends RoomUsers{constructor(F){super(F);Ie(this,"getPeerStatsTimer",0);Ie(this,"reports",[]);Ie(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});Ie(this,"initPeer",()=>{var Z;(Z=this.peerIns)==null||Z.close(),this.transceiverMap=new Map,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),Be(this,jn).call(this),Be(this,Jn).call(this);const F=[];this.peerIns.onicecandidate=async D=>{if(D.candidate){const N=await parseCandidate(D.candidate.candidate);F.push(N)}console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: parseCandidate",F)}});Ie(this,"getNatType",async()=>{});Ie(this,"initSendChannel",(F="",Z)=>{});Ie(this,"initReceiveChannel",(F="",Z)=>{});Ie(this,"replaceSenderStream",async(F=[],Z)=>{const{userId:D}=this.options;F.length===0&&(F=mediaType_keys);for(const N of F){const O=this.transceiverMap.get(N);let I;if(O){const{sender:z}=O;Z?I=this.getUserStream(D,N):I=this.getPhoneyStreams(N);const[J]=I.getTracks();J&&await z.replaceTrack(J)}}});Ie(this,"getSenderTracks",async(F=[])=>{const Z=[];for(const D of F){const N=this.transceiverMap.get(D);if(!N)continue;const{mid:O,sender:I}=N,{track:z}=I;if(!z)continue;const{id:J,enabled:Q}=z,ne=mediaType_keys.findIndex(te=>te===D),re={type:ne,enabled:Q,trackName:`web-${ne}-${J}`,location:"local",mid:O};Z.push(re)}return Z});Ie(this,"addSenders",async(F=[])=>{F.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const Z=[];for(const D of F){if(this.transceiverMap.get(D))continue;const O=this.getPhoneyStreams(D),[I]=O.getTracks(),z=this.peerIns.addTransceiver(I,{direction:"sendonly"});this.transceiverMap.set(D,z),Z.push(D)}if(F.length===0||Z.length!==0){const D=await this.peerIns.createOffer();if(this.options.debug){const N=libExports$1.parse(D.sdp),O=dt(N.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:O,sdpJson:N,description:D})}await this.peerIns.setLocalDescription(D)}return Z});Ie(this,"removeSenders",async(F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F)this.transceiverMap.has(Z)&&this.transceiverMap.delete(Z)});Ie(this,"onSubscribeUserTracks",F=>{let Z=0;return new Promise(async D=>{const N=[];for(const O of F){const{tracks:I=[]}=O;for(const z of I){const{trackName:J,mid:Q}=z,[ne]=await this.getUserTrackByTrackName([J]);N.push({...ne,mid:Q})}}{let O=[];const I=async()=>{clearTimeout(Z);const J=new Map;for(const ne of O){const{userId:re,mediaType:te}=ne;if(!re||!te)continue;J.has(re)||J.set(re,{userId:re,tracks:[],updateStreams:{}});const le=J.get(re);le.tracks.push(ne),le.updateStreams[te]=!0}const Q=[...J.values()];for(const ne of Q){const{userId:re,tracks:te}=ne;await this.updateUsertracks(re,te,!0)}await this.emitNotifyUpdateUsersStreams(Q),this.peerIns.removeEventListener("track",z);{const ne=Array.from(N,oe=>oe.trackName),re=Array.from(O,oe=>oe.trackName),te=ne.filter(oe=>!re.includes(oe));D({target:ne,success:re,fail:te})}},z=async J=>{const{streams:Q,transceiver:ne}=J,[re]=Q,{mid:te,receiver:oe}=ne,{track:le}=oe,{id:ae}=le,ce=N.find(fe=>fe.mid===`${te}`);if(!ce)return;const{userId:de,mediaType:we}=ce;if(!(!de||!we)){{const fe={...ce,mid:te,msid:ae};O.push(fe)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${O.length}/${N.length}`,{mediaType:we,mid:te,userTrack:ce,e:J});{const fe=new Audio;if(fe.srcObject=re,await this.initUserMediaStreamContext(de,we,re),we==="microphoneCamera_audio"||we==="screenSharing_audio"){const ge=this.getUserAudioMediaStreamContext(de,we);ge==null||ge.setMute(!1)}}N.length===O.length&&I()}};this.peerIns.addEventListener("track",z),Z=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${O.length}/${N.length})`),I()},5*1e3)}})});st(this,jn,()=>{let F=0;const Z=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.onconnectionstatechange=async D=>{const N=D.target.connectionState;switch(await this.taskQueue.setCondition("ice",!1),clearTimeout(F),N){case"connected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${N}`),await this.taskQueue.setCondition("ice",!0),await this.getNatType(),this.setRoomState("connected");break;case"disconnected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${N}`),F=window.setTimeout(Z,30*1e3);break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${N}`),this.setRoomState("failed");break;case"closed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${N}`),Z();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${N}`);break}}});Ie(this,"closeUserTracks",async(F,Z=[],D=!1)=>{const N=[];for(const J of Z){const{trackName:Q,msid:ne}=J;N.push(Q),ne&&N.push(ne)}const O=J=>N.includes(J),I=this.peerIns.getTransceivers();for(const J of I){const{mid:Q,sender:ne,receiver:re}=J;ne.track&&O(ne.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${Q} is stop.`,J)),re.track&&O(re.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${Q} is stop.`,J))}const z=await this.getUser(F);if(z){for(const J of z.tracks){const{trackName:Q,msid:ne,userId:re,mediaType:te}=J;!re||!te||!O(Q)||(this.removeUserMediaStreamContext(re,te),ne&&delete J.msid)}if(D){const J=z.tracks.filter(({trackName:Q})=>!O(Q));await this.updateUsertracks(F,J,!1)}}});Ie(this,"createOffer",async()=>{const F=await this.peerIns.createOffer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"createAnswer",async()=>{const F=await this.peerIns.createAnswer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"getSdp",()=>{var F;return(F=this.peerIns.localDescription)==null?void 0:F.sdp});Ie(this,"setRemoteDescription",async F=>{if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:D,sdpJson:Z,description:F})}return await this.peerIns.setRemoteDescription(F),F});Ie(this,"setCallStrategy",async(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);let D="balanced";switch(F){case"qualityPriority":D="maintain-resolution";break;case"fluencyPriority":D="maintain-framerate";break;case"balancedDowngrade":D="balanced";break}const N=await this.getSelfInfo(),O=Array.from(N.tracks,({trackName:z})=>z),I=this.peerIns.getSenders();for(const z of I){const{track:J}=z;if(!J||!O.includes(J.id))continue;const Q=z.getParameters();z.setParameters({...Q,degradationPreference:D})}});Ie(this,"setRTCRtpSenderParameters",F=>{try{const Z=this.peerIns.getSenders();for(const D of Z){const N=D.getParameters();D.setParameters({...N,...F})}}catch(Z){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",Z)}});Ie(this,"getReportsByMid",async(F=[])=>F.length===0?this.reports:this.reports.filter(Z=>F.includes(Z.mid)));Ie(this,"getRoomNetwork",()=>this.peerNetwork);Ie(this,"getPeerNetwork",()=>this.peerNetwork);st(this,zn,async()=>{try{const F=await this.peerIns.getStats(),Z=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],N=[...F.values()].filter(ge=>Z.includes(ge.type));let O=0,I=0,z=0,J=0,Q=0,ne=0,re=[],te=[];for(const ge of this.reports){const{packetsSent:me,packetsLost:ve}=ge;me&&(z+=me),ve&&(J+=ve)}this.reports=N;for(const ge of this.reports){const{bytesSent:me,bytesReceived:ve,packetsSent:ke,packetsLost:xe,roundTripTime:_e,jitter:Te}=ge;me&&(I=me),ve&&(O=ve),ke&&(Q+=ke),xe&&(ne+=xe),_e&&re.push((_e*100).toFixed(2)),Te&&te.push(Te.toFixed(2))}te.sort().reverse(),re.sort().reverse();const oe=Q-z,le=ne-J,ae=oe===0?"0.00":(le/oe).toFixed(2),[ce="0"]=re,[de="0"]=te,we={outboundBytes:I,inboundBytes:O,lostRate:ae,roundTripTime:ce,jitter:de};this.peerNetwork=we;const fe=(ge,me,ve)=>{const ke=Number(ge),xe=Number(me),_e=Number(ve);let Te="0";return ke<.03&&xe<100&&_e<.05?Te="5":ke<.06&&xe<160&&_e<.1?Te="4":ke<.1&&xe<250&&_e<.15?Te="3":ke<.15&&xe<400&&_e<.2?Te="2":Te="1",Number(Te)};{const ge=fe(ae,ce,de),me=await this.getSelfInfo(),{network:ve}=me,ke={egress:ge,ingress:ge};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,ke),JSON.stringify(ve)!==JSON.stringify(ke)){this.emitNotifyUpdateUsers();const{userId:Te,roomId:qe}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...ke,userId:Te,roomId:qe}},!1)}},3*1e3)}}catch(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",F)}});st(this,Jn,()=>{const F=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||Be(this,zn).call(this)};this.getPeerStatsTimer=window.setInterval(F,1*1e3)});Ie(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer))}}jn=new WeakMap,zn=new WeakMap,Jn=new WeakMap;class RoomCalls extends RoomPeer{constructor(F){super(F);st(this,On,0);Ie(this,"setLocalStream",(F,Z)=>new Promise(async(D,N)=>{try{typeof F=="string"&&(F=[F]);for(const I of F)this.localStreamsActionMap.set(I,Z);if(Z){if(F.includes("microphoneCamera_audio")&&F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):F.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):F.includes("screenSharing_audio")&&F.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):F.includes("screenSharing_audio")&&!F.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):F.includes("screenSharing_video")&&!F.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),F.includes("screenSharing_audio")){const I=await this.getLocalStream("screenSharing_audio");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if(F.includes("screenSharing_video")){const I=await this.getLocalStream("screenSharing_video");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams(F);const O=await this.getLocalStreams(F);this.cwsIns.emitNotify("onLocalStream",{code:200,data:O,desc:"local stream is change."}),D(O)}catch(O){N(O)}}));Ie(this,"setMediaDeviceKind",(F,Z)=>new Promise(async(D,N)=>{this.setDeviceKind(F,Z);const O=await this.getSelfInfo(),{id:I,tracks:z=[],callActionMap:J}=O,Q=[],ne=async re=>{const te=this.localStreamsActionMap.get(re),oe=z.find(ae=>ae.mediaType===re),le=J[re];if(te){Q.push(re),await this.stopLocalStreams([re]);try{await this.initLocalStream(re)}catch(ae){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initLocalStream is error.",ae),await this.inactiveTracks([re],!1),N(ae)}}if(oe){const ae=await this.getLocalStream(re);ae&&(await this.initUserMediaStreamContext(I,re,ae),le&&await this.replaceSenderStream([re],!0))}{const ae=await this.getLocalStreams(Q);this.cwsIns.emitNotify("onLocalStream",{code:200,data:ae,desc:"local stream is change."}),await this.emitNotifyUpdateUsers(),D(!0)}};F==="audioinput"&&ne("microphoneCamera_audio"),F==="videoinput"&&ne("microphoneCamera_video"),F==="audiooutput"&&(await this.changeAudiooutput(),D(!0))}));Ie(this,"changeScreenSharing",async F=>{const Z=await this.getSelfInfo(),{tracks:D=[],callActionMap:N}=Z;try{await this.setLocalStream(F,!0);for(const O of F)D.find(z=>z.mediaType===O&&N[O])&&await this.replaceSenderStream([O],!0)}catch(O){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",O)}});Ie(this,"createSession",()=>new Promise(async(F,Z)=>{if(["connecting","connected"].includes(this.roomState))return F(!0);this.setRoomState("connecting"),await this.taskQueue.createTask({describe:"createSession",conditionKeys:["createWs","createSession"],changeConditionKeys:["createSession"],func:()=>new Promise(async(D,N)=>{try{await this.addSenders(),this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async O=>{const{code:I=0,desc:z,data:J}=O;if(I!==200)return N(z);const{remoteSdp:Q}=J;await this.taskQueue.setCondition("ice",!1),await this.taskQueue.createTask({describe:"ice",timeout:30*1e3,conditionKeys:["ice"],func:()=>new Promise(ne=>setTimeout(()=>ne(!0),300)),success:async()=>{D(!0)},fail:async ne=>{throw new Error(`ice connection failed: ${ne}`)}}),await this.setRemoteDescription({type:"answer",sdp:Q})})}catch(O){N(O)}}),success:async D=>{F(D)},fail:async D=>{this.reportLogs("ws_c_timeout",D.message||D),Z(D)},complete:()=>{this.taskQueue.setCondition("createSession",!0)}})}));Ie(this,"earlyConnect",(F=[])=>{this.isEarly=!0,Be(this,An).call(this),this.createSession(),F.length===0&&(F=["microphoneCamera_audio","microphoneCamera_video"]),Be(this,$n).call(this,F)});Ie(this,"joinRoom",async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"joinRoom",conditionKeys:["createWs"],changeConditionKeys:["joinRoom"],func:()=>new Promise(async(N,O)=>{try{this.setOptions(F),await Be(this,An).call(this),this.clearUsers();const{roomId:I,userId:z,callType:J,sdkToken:Q}=this.options;this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:J,roomId:I,user:{id:z,tracks:[],callAction:0},token:Q},version:2}).then(async ne=>{const{code:re=0,desc:te="服务器繁忙",data:oe}=ne;if(re!==200)return O(te);const{roomId:le="",roomUsers:ae=[]}=oe;if(le!==I)return O("加入的房间不匹配");this.isInRoom=!0,this.initHeartbeat(),this.createSession(),await this.updateUsers(ae);const ce=[];for(const we of ae){const{id:fe,channelCache:ge}=we,{channels:me=[]}=ge;await this.updateUserBehaviors(fe,we.behavior),await this.updateUserChannels(fe,me,!1),me.length!==0&&ce.push({userId:fe,channels:me})}this.subChannel(ce),await this.emitNotifyUpdateUsers();const de=await this.getUsers();N(de)})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("join_room_error",N.message||N),D(N)},complete:()=>{this.taskQueue.setCondition("joinRoom",!0)}})}));Ie(this,"quitRoom",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,clearInterval(Be(this,On)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),await this.taskQueue.setCondition("closeTrack",!0),this.cwsIns.sendMessage({event:"quitRoom",data:N}),F(!0)}));Ie(this,"quitRoomEx",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:N}),F(!0)}));Ie(this,"syncRoomInfo",()=>new Promise(async(F,Z)=>{const{userId:D}=this.options,N=await this.getUser(D),{id:O=D,callAction:I=0}=N;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:O,callAction:I}}}).then(async z=>{if(z.code!==200)return Z(z.desc);const J=z.data.users;this.clearUsers(),await this.updateUsers(J),await this.updateUsertracks(N.id,N.tracks,!1);{const Q=await this.getUsers();F(Q)}}).catch(z=>Z(z))}));Ie(this,"publish",F=>new Promise(async(Z,D)=>{{const N=await this.getSelfInfo(),{banBehaviorMap:O}=N;let I=!0;for(const z of F)if(O[z]){I=!1;break}if(I===!1)return D("publish is error: prohibited by administrator.")}try{await this.setLocalStream(F,!0)}catch(N){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",N)}await this.taskQueue.createTask({describe:"publish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["publish"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo(),z=[];for(const te of F){{const oe=this.getPhoneyStreams(te);await this.initUserMediaStreamContext(I.id,te,oe)}{const oe=await this.getLocalStream(te);oe?await this.initUserMediaStreamContext(I.id,te,oe):z.push(te)}}const J=F.filter(te=>!z.includes(te)||["microphoneCamera_audio","microphoneCamera_video"].includes(te));await this.replaceSenderStream(F,!1),await Be(this,$n).call(this,J);const Q=await this.getSenderTracks(J),ne=[...I.tracks,...Q];await this.updateUsertracks(I.id,ne,!0),z.length!==0&&await this.inactiveTracks(z,!1),J.length!==0&&await this.replaceSenderStream(J,!0);const re=await this.getCallAction(ne);await Be(this,En).call(this,re),await new Promise(te=>setTimeout(()=>te(!0),230)),Be(this,Wn).call(this,F);{await this.emitNotifyUpdateUsers();const te=await this.getSelfInfo();N(te)}}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("publish",!0)}})}));Ie(this,"stopPublish",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"stopPublish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo();F.length===0&&(F=mediaType_keys);const z=I.tracks.filter(({mediaType:Q})=>Q&&F.includes(Q)),J=async()=>{this.initMediaPhoneyStreams(F);const Q=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),N(Q)};if(z.length===0)return J();await this.replaceSenderStream(F,!0),await this.closeUserTracks(I.id,z,!0),await this.removeSenders(F);{const Q=await this.getCallAction(I.tracks);await Be(this,En).call(this,Q)}await this.createOffer(),this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{code:ne=0,data:re,desc:te}=Q;if(ne!==200)return O(te);const{remoteSdp:oe}=re;await this.setRemoteDescription({type:"answer",sdp:oe}),J()})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"subscribe",(F=[],Z=3)=>new Promise(async(D,N)=>{const O=await this.taskQueue.createTask({describe:"subscribe",strict:!0,conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["subscribe"],func:()=>new Promise(async(I,z)=>{try{const J=await this.getUsers();let Q=[];for(const te of J){const{isSelf:oe,tracks:le=[]}=te;if(!oe){const ae=le.filter(({trackName:ce,mid:de=""})=>de!==""&&(F.includes(ce)||F.length===0));ae.length!==0&&Q.push({...te,tracks:ae})}}const ne=async(te={})=>{const oe=Array.from(Q,({id:ae})=>ae),le=await this.getUsers(oe);await this.emitNotifyUpdateUsers(),I({users:le,detail:te})};if(Q.length===0)return ne();const re=[];for(const te of Q){const{id:oe,tracks:le}=te,ae=dt(le,["type","trackName"]),ce={id:oe,tracks:ae};re.push(ce)}this.cwsIns.sendMessage({event:"subscribe",data:{users:re}}).then(async te=>{const{code:oe=0,data:le,desc:ae}=te;if(oe!==200)return z(ae);const{remoteSdp:ce,users:de=[]}=le;this.onSubscribeUserTracks(de).then(async we=>{await this.renegotiate().then(()=>ne(we)).catch(fe=>z(fe))}).catch(we=>{z(we)}),await this.setRemoteDescription({type:"offer",sdp:ce})})}catch(J){z(J)}}),success:async I=>{O.clear(),this.taskQueue.setCondition("subscribe",!0),D(I)},fail:async I=>{if(this.options.debug&&console.info("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: subscribe error. surplus count is ${Z}`),Z>0)return await new Promise(z=>setTimeout(()=>z(!0),(3-Z)*1e3)),Z=Z-1,O.retry();O.clear(),this.reportLogs("subscribe_error",I.message||I),this.taskQueue.setCondition("subscribe",!0),N(I)},complete:async()=>{}})}));Ie(this,"renegotiate",()=>new Promise(async(F,Z)=>{try{await this.taskQueue.setCondition("renegotiate",!1),await this.createAnswer(),this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(D=>{const{code:N=0,desc:O}=D;if(N!==200)return Z(O);F(D)}).finally(()=>{this.taskQueue.setCondition("renegotiate",!0)})}catch(D){Z(D)}}));Ie(this,"stopSubscribe",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"closeTrack",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getUsers(),z=[];for(const Q of I){const{tracks:ne=[]}=Q;for(const re of ne){const{type:te,mid:oe,trackName:le,mediaType:ae,msid:ce}=re;if(!(!ae||!ce)&&(F.length===0||F.includes(le))){const de={type:te,mid:oe,trackName:ce};z.push(de),await this.closeUserTracks(Q.id,[re])}}}const J=async()=>{await this.emitNotifyUpdateUsers(),N(!0)};if(z.length===0)return J();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{remoteSdp:ne}=Q.data;await this.setRemoteDescription({type:"answer",sdp:ne})}),J()}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: stopPublish is error.",N),this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"inactiveTracks",async(F,Z)=>new Promise(async D=>{const N=await this.getSelfInfo();if(!N||!N.id)return D(!0);const{tracks:O=[]}=N,I=[...O];for(let J of I){const{mediaType:Q}=J;if(Q&&F.includes(Q)){J.enabled=Z;const ne=await this.getLocalStream(Q);if(!ne)continue;const re=ne.getTracks();for(const te of re)te.enabled=Z}}await this.replaceSenderStream(F,Z);const z=await this.getCallAction(I);await Be(this,En).call(this,z),await this.emitNotifyUpdateUsers(),D(!0)}));Ie(this,"setBanBehaviors",F=>new Promise(async(Z,D)=>{try{const{roomId:N}=this.options,O=[];for(const I of F){const{id:z,banBehaviors:J}=I,Q=Object.keys(J);if(Q.length===0)continue;const ne=[];for(const te of Q){const oe=mediaType_keys.findIndex(ce=>ce===te),le=J[te],ae={type:oe,behavior:le};ne.push(ae)}const re={id:z,behaviors:ne};O.push(re)}this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:N,users:O}}).then(async I=>{const{code:z=0,desc:J}=I;if(z!==200)return D(J);Z(I)}).finally(()=>{})}catch(N){D(N)}}));Ie(this,"pubChannel",()=>new Promise(async(F,Z)=>{const N=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:N}}).then(async O=>{const{code:I=0,data:z,desc:J}=O;if(I!==200)return Z(J);const{channels:Q=[]}=z;for(const ne of Q){const{channels:re=[]}=ne;for(const te of re){const{dataChannelName:oe,id:le}=te;this.initSendChannel(oe,le)}}F(!0)}).catch(O=>{Z(O)})}));Ie(this,"subChannel",(F=[])=>new Promise(async(Z,D)=>{if(F.length===0)return Z(!0);await this.taskQueue.createTask({describe:"subChannel",strict:!0,conditionKeys:["createWs","createSession","ice"],changeConditionKeys:[],func:()=>this.cwsIns.sendMessage({event:"subChannel",data:{channels:F}}).then(async N=>{const{code:O=0,data:I,desc:z}=N;if(O!==200)return D(z);const{channels:J=[]}=I;for(const Q of J){const{channels:ne=[]}=Q;for(const re of ne){const{dataChannelName:te,id:oe}=re;this.initReceiveChannel(te,oe)}}}),success:async N=>{Z(N)},fail:async N=>{D(N)}})}));Ie(this,"debugger",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"shutdown",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"initHeartbeat",()=>{this.stopHeartbeat();const F=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),Z=this.isInRoom?5*1e3:30*1e3;At(this,On,window.setInterval(F,Z)),F()});Ie(this,"stopHeartbeat",()=>{clearInterval(Be(this,On))});st(this,Wn,async F=>{const{roomId:Z}=this.options;if(!Z)return;const{id:D,tracks:N=[]}=await this.getSelfInfo(),O=N.filter(I=>I.mediaType&&F.includes(I.mediaType));O.length!==0&&this.cwsIns.sendMessage({event:"pubNotify",data:{roomId:Z,user:{id:D,tracks:O}}})});st(this,En,async F=>new Promise(async(Z,D)=>{const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O,callAction:F}};await this.cwsIns.sendMessage({event:"updateCall",data:I}).then(async z=>{const{code:J=0}=z;if(J!==200)return D(z);await this.updateUserCallAction(O,F),Z(F)}).catch(z=>D(z))}));st(this,An,()=>new Promise(async(F,Z)=>{try{if(["connecting","connected"].includes(this.cwsIns.state))return F(!0);await this.taskQueue.setCondition("createWs",!1),this.cwsIns.clearEvents(),this.initPeer();const{appid:D,roomId:N,userId:O}=this.options;if(!D)return Z("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const I={c:D,r:N,v:this.sdk_service_version};if(this.isEarly){const J=xt();I.i=J,this.setOptions({earlyId:J})}else I.b=O;this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs",I);const z=btoa(encodeURI(JSON.stringify(I)));await this.cwsIns.connect(z),this.initHeartbeat(),await this.taskQueue.setCondition("createWs",!0),await this.taskQueue.setCondition("createSession",!0),F(!0)}catch(D){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",D),this.reportLogs("ws_c_timeout",D.message||D),Z(D)}}));st(this,$n,async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"createTrack",conditionKeys:["createWs","createSession","ice","createTrack","subscribe","renegotiate","closeTrack"],func:()=>new Promise(async(N,O)=>{try{await this.taskQueue.setCondition("createTrack",!1);const I=await this.addSenders(F),z=await this.getSenderTracks(I);if(z.length===0)return await this.taskQueue.setCondition("createTrack",!0),N(!0);this.cwsIns.sendMessage({event:"publish",data:{sdp:this.getSdp(),tracks:z,callAction:0}}).then(async J=>{const{code:Q=0,desc:ne,data:re}=J;if(Q!==200)return O(ne);const{remoteSdp:te}=re;await this.setRemoteDescription({type:"answer",sdp:te}),N(!0)})}catch(I){await this.removeSenders(F),O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("createTrack",!0)}})}))}}On=new WeakMap,Wn=new WeakMap,En=new WeakMap,An=new WeakMap,$n=new WeakMap;class Room extends RoomCalls{constructor(K){super(K)}}class QuickVO extends Room{constructor(F){super(F);st(this,_n,new Map);Ie(this,"reconstruct",async()=>{if(this.cwsIns.state!=="connected"||this.roomState!=="failed")return;this.setRoomState("ready"),this.initMediaPhoneyStreams(),this.taskQueue.clear(),this.peerIns.close(),await this.syncRoomInfo(),this.initPeer(),this.taskQueue.setCondition("createSession",!0),this.taskQueue.setCondition("ice",!0),await this.createSession();const F=[],Z=[],D=await this.getUsers();for(const N of D){const{isSelf:O,callActionMap:I,tracks:z=[]}=N;if(O)for(const J of mediaType_keys)I[J]&&F.push(J);for(const J of z)J.msid&&Z.push(J.trackName)}await this.subscribe(Z),await this.publish(F)});st(this,Vn,()=>{{const F=async Z=>{const{state:D}=Z.data;if(D==="closed"){const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:I}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}this.reconstruct()};this.cwsIns.addNotify({event:"onRoomState",callback:F},!0)}{const F=async Z=>{const{qualities:D=[]}=Z.data,[N]=D;if(!(N&&N.userId===this.options.userId&&D.length===1)){for(const O of D){const{userId:I,egress:z,ingress:J}=O;this.checkUserInRoom(I)&&await this.updateUserNetwork(I,{egress:z,ingress:J})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:F},!0)}{const F=async Z=>{const D=Z.data.user;await this.updateUsers([D]),await this.updateUsertracks(D.id,D.track,!1),await this.updateUserBehaviors(D.id,D.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:F},!0)}{const F=async Z=>{await this.removeUsers([Z.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,tracks:O=[],callAction:I=0}=D;if(await this.updateUserCallAction(N,I),await this.updateUserPermissions(N,3),await this.updateUsertracks(N,O,!0),this.options.newPublishAutoSubscribe){const z=this.getTrackNamesFormTracks(O);await this.subscribe(z)}else await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onPublish",callback:F},!0)}{const F=async Z=>{const D=[Z.data];this.subChannel(D)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:F},!0)}{const F=async Z=>{const{id:D,tracks:N}=Z.data.user;D!==this.options.userId&&(await this.closeUserTracks(D,N,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:F},!0)}{const F=async Z=>{const{id:D,callAction:N}=Z.data.user;this.checkUserInRoom(D)&&(await this.updateUserCallAction(D,N),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,permissions:O=1}=D;O===1?await this.removeUsers([N]):O===3&&await this.updateUsers([D]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:F},!0)}{const F=async Z=>{const{users:D}=Z.data;for(const N of D){const{id:O,behavior:I}=N;await this.updateUserBehaviors(O,I)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:F},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async F=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});Ie(this,"addNotify",F=>this.cwsIns.addNotify(F));st(this,Zn,()=>{});st(this,Kn,()=>{this.cwsIns.onReconnectSuccess=async()=>{this.reconstruct()}});st(this,Gn,async()=>{this.setRoomState("closed")});Ie(this,"addRequestAnimationFrame",async(F,Z)=>{{const N=Be(this,_n).get(F);N&&cancelAnimationFrame(N)}const D=(N=Date.now())=>{Z(N);const O=requestAnimationFrame(D);Be(this,_n).set(F,O)};D()});Ie(this,"clearRequestAnimationFrame",async(F=[])=>{F.length===0&&(F=[...Be(this,_n).keys()]);const Z=[];for(const D of F){const N=Be(this,_n).get(D);N&&(cancelAnimationFrame(N),Z.push(N))}return Z});Ie(this,"destroy",async()=>{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 销毁SDK"),this.cwsIns.emitNotify("onDestroy",{code:200,data:{},desc:"sdk is destroy."}),this.stopLocalStreams(),await new Promise(F=>setTimeout(()=>F(!0),300)),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.cwsIns.close()});Be(this,Zn).call(this),Be(this,Kn).call(this),Be(this,Gn).call(this),Be(this,Vn).call(this)}}_n=new WeakMap,Vn=new WeakMap,Zn=new WeakMap,Kn=new WeakMap,Gn=new WeakMap,exports.QuickVO=QuickVO,exports.ignoreEvent=ignoreEvent,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|