quickvo-sdk-js 1.0.4 → 1.0.5

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.
Files changed (3) hide show
  1. package/dist/index.js +22391 -22064
  2. package/dist/index.umd.cjs +2 -2
  3. package/package.json +1 -1
@@ -10,7 +10,7 @@ between two successive fields at the output of the decoding process (see the not
10
10
  *
11
11
  * @author Feross Aboukhadijeh <https://feross.org>
12
12
  * @license MIT
13
- */var hasRequiredBuffer;function requireBuffer(){return hasRequiredBuffer||(hasRequiredBuffer=1,function(N){const Z=requireBase64Js(),q=requireIeee754(),J=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;N.Buffer=O,N.SlowBuffer=fe,N.INSPECT_MAX_BYTES=50;const I=2147483647;N.kMaxLength=I,O.TYPED_ARRAY_SUPPORT=D(),!O.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function D(){try{const ae=new Uint8Array(1),Q={foo:function(){return 42}};return Object.setPrototypeOf(Q,Uint8Array.prototype),Object.setPrototypeOf(ae,Q),ae.foo()===42}catch{return!1}}Object.defineProperty(O.prototype,"parent",{enumerable:!0,get:function(){if(O.isBuffer(this))return this.buffer}}),Object.defineProperty(O.prototype,"offset",{enumerable:!0,get:function(){if(O.isBuffer(this))return this.byteOffset}});function a(ae){if(ae>I)throw new RangeError('The value "'+ae+'" is invalid for option "size"');const Q=new Uint8Array(ae);return Object.setPrototypeOf(Q,O.prototype),Q}function O(ae,Q,X){if(typeof ae=="number"){if(typeof Q=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return te(ae)}return F(ae,Q,X)}O.poolSize=8192;function F(ae,Q,X){if(typeof ae=="string")return ne(ae,Q);if(ArrayBuffer.isView(ae))return re(ae);if(ae==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ae);if(Wt(ae,ArrayBuffer)||ae&&Wt(ae.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Wt(ae,SharedArrayBuffer)||ae&&Wt(ae.buffer,SharedArrayBuffer)))return ce(ae,Q,X);if(typeof ae=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const he=ae.valueOf&&ae.valueOf();if(he!=null&&he!==ae)return O.from(he,Q,X);const Te=oe(ae);if(Te)return Te;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof ae[Symbol.toPrimitive]=="function")return O.from(ae[Symbol.toPrimitive]("string"),Q,X);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ae)}O.from=function(ae,Q,X){return F(ae,Q,X)},Object.setPrototypeOf(O.prototype,Uint8Array.prototype),Object.setPrototypeOf(O,Uint8Array);function z(ae){if(typeof ae!="number")throw new TypeError('"size" argument must be of type number');if(ae<0)throw new RangeError('The value "'+ae+'" is invalid for option "size"')}function K(ae,Q,X){return z(ae),ae<=0?a(ae):Q!==void 0?typeof X=="string"?a(ae).fill(Q,X):a(ae).fill(Q):a(ae)}O.alloc=function(ae,Q,X){return K(ae,Q,X)};function te(ae){return z(ae),a(ae<0?0:se(ae)|0)}O.allocUnsafe=function(ae){return te(ae)},O.allocUnsafeSlow=function(ae){return te(ae)};function ne(ae,Q){if((typeof Q!="string"||Q==="")&&(Q="utf8"),!O.isEncoding(Q))throw new TypeError("Unknown encoding: "+Q);const X=ge(ae,Q)|0;let he=a(X);const Te=he.write(ae,Q);return Te!==X&&(he=he.slice(0,Te)),he}function ee(ae){const Q=ae.length<0?0:se(ae.length)|0,X=a(Q);for(let he=0;he<Q;he+=1)X[he]=ae[he]&255;return X}function re(ae){if(Wt(ae,Uint8Array)){const Q=new Uint8Array(ae);return ce(Q.buffer,Q.byteOffset,Q.byteLength)}return ee(ae)}function ce(ae,Q,X){if(Q<0||ae.byteLength<Q)throw new RangeError('"offset" is outside of buffer bounds');if(ae.byteLength<Q+(X||0))throw new RangeError('"length" is outside of buffer bounds');let he;return Q===void 0&&X===void 0?he=new Uint8Array(ae):X===void 0?he=new Uint8Array(ae,Q):he=new Uint8Array(ae,Q,X),Object.setPrototypeOf(he,O.prototype),he}function oe(ae){if(O.isBuffer(ae)){const Q=se(ae.length)|0,X=a(Q);return X.length===0||ae.copy(X,0,0,Q),X}if(ae.length!==void 0)return typeof ae.length!="number"||Gt(ae.length)?a(0):ee(ae);if(ae.type==="Buffer"&&Array.isArray(ae.data))return ee(ae.data)}function se(ae){if(ae>=I)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+I.toString(16)+" bytes");return ae|0}function fe(ae){return+ae!=ae&&(ae=0),O.alloc(+ae)}O.isBuffer=function(Q){return Q!=null&&Q._isBuffer===!0&&Q!==O.prototype},O.compare=function(Q,X){if(Wt(Q,Uint8Array)&&(Q=O.from(Q,Q.offset,Q.byteLength)),Wt(X,Uint8Array)&&(X=O.from(X,X.offset,X.byteLength)),!O.isBuffer(Q)||!O.isBuffer(X))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(Q===X)return 0;let he=Q.length,Te=X.length;for(let $e=0,Ue=Math.min(he,Te);$e<Ue;++$e)if(Q[$e]!==X[$e]){he=Q[$e],Te=X[$e];break}return he<Te?-1:Te<he?1:0},O.isEncoding=function(Q){switch(String(Q).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},O.concat=function(Q,X){if(!Array.isArray(Q))throw new TypeError('"list" argument must be an Array of Buffers');if(Q.length===0)return O.alloc(0);let he;if(X===void 0)for(X=0,he=0;he<Q.length;++he)X+=Q[he].length;const Te=O.allocUnsafe(X);let $e=0;for(he=0;he<Q.length;++he){let Ue=Q[he];if(Wt(Ue,Uint8Array))$e+Ue.length>Te.length?(O.isBuffer(Ue)||(Ue=O.from(Ue)),Ue.copy(Te,$e)):Uint8Array.prototype.set.call(Te,Ue,$e);else if(O.isBuffer(Ue))Ue.copy(Te,$e);else throw new TypeError('"list" argument must be an Array of Buffers');$e+=Ue.length}return Te};function ge(ae,Q){if(O.isBuffer(ae))return ae.length;if(ArrayBuffer.isView(ae)||Wt(ae,ArrayBuffer))return ae.byteLength;if(typeof ae!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof ae);const X=ae.length,he=arguments.length>2&&arguments[2]===!0;if(!he&&X===0)return 0;let Te=!1;for(;;)switch(Q){case"ascii":case"latin1":case"binary":return X;case"utf8":case"utf-8":return Zt(ae).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X*2;case"hex":return X>>>1;case"base64":return tn(ae).length;default:if(Te)return he?-1:Zt(ae).length;Q=(""+Q).toLowerCase(),Te=!0}}O.byteLength=ge;function ue(ae,Q,X){let he=!1;if((Q===void 0||Q<0)&&(Q=0),Q>this.length||((X===void 0||X>this.length)&&(X=this.length),X<=0)||(X>>>=0,Q>>>=0,X<=Q))return"";for(ae||(ae="utf8");;)switch(ae){case"hex":return jt(this,Q,X);case"utf8":case"utf-8":return Je(this,Q,X);case"ascii":return Et(this,Q,X);case"latin1":case"binary":return At(this,Q,X);case"base64":return We(this,Q,X);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Pt(this,Q,X);default:if(he)throw new TypeError("Unknown encoding: "+ae);ae=(ae+"").toLowerCase(),he=!0}}O.prototype._isBuffer=!0;function _e(ae,Q,X){const he=ae[Q];ae[Q]=ae[X],ae[X]=he}O.prototype.swap16=function(){const Q=this.length;if(Q%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let X=0;X<Q;X+=2)_e(this,X,X+1);return this},O.prototype.swap32=function(){const Q=this.length;if(Q%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let X=0;X<Q;X+=4)_e(this,X,X+3),_e(this,X+1,X+2);return this},O.prototype.swap64=function(){const Q=this.length;if(Q%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let X=0;X<Q;X+=8)_e(this,X,X+7),_e(this,X+1,X+6),_e(this,X+2,X+5),_e(this,X+3,X+4);return this},O.prototype.toString=function(){const Q=this.length;return Q===0?"":arguments.length===0?Je(this,0,Q):ue.apply(this,arguments)},O.prototype.toLocaleString=O.prototype.toString,O.prototype.equals=function(Q){if(!O.isBuffer(Q))throw new TypeError("Argument must be a Buffer");return this===Q?!0:O.compare(this,Q)===0},O.prototype.inspect=function(){let Q="";const X=N.INSPECT_MAX_BYTES;return Q=this.toString("hex",0,X).replace(/(.{2})/g,"$1 ").trim(),this.length>X&&(Q+=" ... "),"<Buffer "+Q+">"},J&&(O.prototype[J]=O.prototype.inspect),O.prototype.compare=function(Q,X,he,Te,$e){if(Wt(Q,Uint8Array)&&(Q=O.from(Q,Q.offset,Q.byteLength)),!O.isBuffer(Q))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof Q);if(X===void 0&&(X=0),he===void 0&&(he=Q?Q.length:0),Te===void 0&&(Te=0),$e===void 0&&($e=this.length),X<0||he>Q.length||Te<0||$e>this.length)throw new RangeError("out of range index");if(Te>=$e&&X>=he)return 0;if(Te>=$e)return-1;if(X>=he)return 1;if(X>>>=0,he>>>=0,Te>>>=0,$e>>>=0,this===Q)return 0;let Ue=$e-Te,ct=he-X;const kt=Math.min(Ue,ct),yt=this.slice(Te,$e),It=Q.slice(X,he);for(let St=0;St<kt;++St)if(yt[St]!==It[St]){Ue=yt[St],ct=It[St];break}return Ue<ct?-1:ct<Ue?1:0};function pe(ae,Q,X,he,Te){if(ae.length===0)return-1;if(typeof X=="string"?(he=X,X=0):X>2147483647?X=2147483647:X<-2147483648&&(X=-2147483648),X=+X,Gt(X)&&(X=Te?0:ae.length-1),X<0&&(X=ae.length+X),X>=ae.length){if(Te)return-1;X=ae.length-1}else if(X<0)if(Te)X=0;else return-1;if(typeof Q=="string"&&(Q=O.from(Q,he)),O.isBuffer(Q))return Q.length===0?-1:ye(ae,Q,X,he,Te);if(typeof Q=="number")return Q=Q&255,typeof Uint8Array.prototype.indexOf=="function"?Te?Uint8Array.prototype.indexOf.call(ae,Q,X):Uint8Array.prototype.lastIndexOf.call(ae,Q,X):ye(ae,[Q],X,he,Te);throw new TypeError("val must be string, number or Buffer")}function ye(ae,Q,X,he,Te){let $e=1,Ue=ae.length,ct=Q.length;if(he!==void 0&&(he=String(he).toLowerCase(),he==="ucs2"||he==="ucs-2"||he==="utf16le"||he==="utf-16le")){if(ae.length<2||Q.length<2)return-1;$e=2,Ue/=2,ct/=2,X/=2}function kt(It,St){return $e===1?It[St]:It.readUInt16BE(St*$e)}let yt;if(Te){let It=-1;for(yt=X;yt<Ue;yt++)if(kt(ae,yt)===kt(Q,It===-1?0:yt-It)){if(It===-1&&(It=yt),yt-It+1===ct)return It*$e}else It!==-1&&(yt-=yt-It),It=-1}else for(X+ct>Ue&&(X=Ue-ct),yt=X;yt>=0;yt--){let It=!0;for(let St=0;St<ct;St++)if(kt(ae,yt+St)!==kt(Q,St)){It=!1;break}if(It)return yt}return-1}O.prototype.includes=function(Q,X,he){return this.indexOf(Q,X,he)!==-1},O.prototype.indexOf=function(Q,X,he){return pe(this,Q,X,he,!0)},O.prototype.lastIndexOf=function(Q,X,he){return pe(this,Q,X,he,!1)};function we(ae,Q,X,he){X=Number(X)||0;const Te=ae.length-X;he?(he=Number(he),he>Te&&(he=Te)):he=Te;const $e=Q.length;he>$e/2&&(he=$e/2);let Ue;for(Ue=0;Ue<he;++Ue){const ct=parseInt(Q.substr(Ue*2,2),16);if(Gt(ct))return Ue;ae[X+Ue]=ct}return Ue}function Ie(ae,Q,X,he){return nn(Zt(Q,ae.length-X),ae,X,he)}function be(ae,Q,X,he){return nn(Kt(Q),ae,X,he)}function Se(ae,Q,X,he){return nn(tn(Q),ae,X,he)}function Me(ae,Q,X,he){return nn(fn(Q,ae.length-X),ae,X,he)}O.prototype.write=function(Q,X,he,Te){if(X===void 0)Te="utf8",he=this.length,X=0;else if(he===void 0&&typeof X=="string")Te=X,he=this.length,X=0;else if(isFinite(X))X=X>>>0,isFinite(he)?(he=he>>>0,Te===void 0&&(Te="utf8")):(Te=he,he=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const $e=this.length-X;if((he===void 0||he>$e)&&(he=$e),Q.length>0&&(he<0||X<0)||X>this.length)throw new RangeError("Attempt to write outside buffer bounds");Te||(Te="utf8");let Ue=!1;for(;;)switch(Te){case"hex":return we(this,Q,X,he);case"utf8":case"utf-8":return Ie(this,Q,X,he);case"ascii":case"latin1":case"binary":return be(this,Q,X,he);case"base64":return Se(this,Q,X,he);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Me(this,Q,X,he);default:if(Ue)throw new TypeError("Unknown encoding: "+Te);Te=(""+Te).toLowerCase(),Ue=!0}},O.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function We(ae,Q,X){return Q===0&&X===ae.length?Z.fromByteArray(ae):Z.fromByteArray(ae.slice(Q,X))}function Je(ae,Q,X){X=Math.min(ae.length,X);const he=[];let Te=Q;for(;Te<X;){const $e=ae[Te];let Ue=null,ct=$e>239?4:$e>223?3:$e>191?2:1;if(Te+ct<=X){let kt,yt,It,St;switch(ct){case 1:$e<128&&(Ue=$e);break;case 2:kt=ae[Te+1],(kt&192)===128&&(St=($e&31)<<6|kt&63,St>127&&(Ue=St));break;case 3:kt=ae[Te+1],yt=ae[Te+2],(kt&192)===128&&(yt&192)===128&&(St=($e&15)<<12|(kt&63)<<6|yt&63,St>2047&&(St<55296||St>57343)&&(Ue=St));break;case 4:kt=ae[Te+1],yt=ae[Te+2],It=ae[Te+3],(kt&192)===128&&(yt&192)===128&&(It&192)===128&&(St=($e&15)<<18|(kt&63)<<12|(yt&63)<<6|It&63,St>65535&&St<1114112&&(Ue=St))}}Ue===null?(Ue=65533,ct=1):Ue>65535&&(Ue-=65536,he.push(Ue>>>10&1023|55296),Ue=56320|Ue&1023),he.push(Ue),Te+=ct}return Tt(he)}const Le=4096;function Tt(ae){const Q=ae.length;if(Q<=Le)return String.fromCharCode.apply(String,ae);let X="",he=0;for(;he<Q;)X+=String.fromCharCode.apply(String,ae.slice(he,he+=Le));return X}function Et(ae,Q,X){let he="";X=Math.min(ae.length,X);for(let Te=Q;Te<X;++Te)he+=String.fromCharCode(ae[Te]&127);return he}function At(ae,Q,X){let he="";X=Math.min(ae.length,X);for(let Te=Q;Te<X;++Te)he+=String.fromCharCode(ae[Te]);return he}function jt(ae,Q,X){const he=ae.length;(!Q||Q<0)&&(Q=0),(!X||X<0||X>he)&&(X=he);let Te="";for(let $e=Q;$e<X;++$e)Te+=_n[ae[$e]];return Te}function Pt(ae,Q,X){const he=ae.slice(Q,X);let Te="";for(let $e=0;$e<he.length-1;$e+=2)Te+=String.fromCharCode(he[$e]+he[$e+1]*256);return Te}O.prototype.slice=function(Q,X){const he=this.length;Q=~~Q,X=X===void 0?he:~~X,Q<0?(Q+=he,Q<0&&(Q=0)):Q>he&&(Q=he),X<0?(X+=he,X<0&&(X=0)):X>he&&(X=he),X<Q&&(X=Q);const Te=this.subarray(Q,X);return Object.setPrototypeOf(Te,O.prototype),Te};function _t(ae,Q,X){if(ae%1!==0||ae<0)throw new RangeError("offset is not uint");if(ae+Q>X)throw new RangeError("Trying to access beyond buffer length")}O.prototype.readUintLE=O.prototype.readUIntLE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=this[Q],$e=1,Ue=0;for(;++Ue<X&&($e*=256);)Te+=this[Q+Ue]*$e;return Te},O.prototype.readUintBE=O.prototype.readUIntBE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=this[Q+--X],$e=1;for(;X>0&&($e*=256);)Te+=this[Q+--X]*$e;return Te},O.prototype.readUint8=O.prototype.readUInt8=function(Q,X){return Q=Q>>>0,X||_t(Q,1,this.length),this[Q]},O.prototype.readUint16LE=O.prototype.readUInt16LE=function(Q,X){return Q=Q>>>0,X||_t(Q,2,this.length),this[Q]|this[Q+1]<<8},O.prototype.readUint16BE=O.prototype.readUInt16BE=function(Q,X){return Q=Q>>>0,X||_t(Q,2,this.length),this[Q]<<8|this[Q+1]},O.prototype.readUint32LE=O.prototype.readUInt32LE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),(this[Q]|this[Q+1]<<8|this[Q+2]<<16)+this[Q+3]*16777216},O.prototype.readUint32BE=O.prototype.readUInt32BE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),this[Q]*16777216+(this[Q+1]<<16|this[Q+2]<<8|this[Q+3])},O.prototype.readBigUInt64LE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=X+this[++Q]*2**8+this[++Q]*2**16+this[++Q]*2**24,$e=this[++Q]+this[++Q]*2**8+this[++Q]*2**16+he*2**24;return BigInt(Te)+(BigInt($e)<<BigInt(32))}),O.prototype.readBigUInt64BE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=X*2**24+this[++Q]*2**16+this[++Q]*2**8+this[++Q],$e=this[++Q]*2**24+this[++Q]*2**16+this[++Q]*2**8+he;return(BigInt(Te)<<BigInt(32))+BigInt($e)}),O.prototype.readIntLE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=this[Q],$e=1,Ue=0;for(;++Ue<X&&($e*=256);)Te+=this[Q+Ue]*$e;return $e*=128,Te>=$e&&(Te-=Math.pow(2,8*X)),Te},O.prototype.readIntBE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=X,$e=1,Ue=this[Q+--Te];for(;Te>0&&($e*=256);)Ue+=this[Q+--Te]*$e;return $e*=128,Ue>=$e&&(Ue-=Math.pow(2,8*X)),Ue},O.prototype.readInt8=function(Q,X){return Q=Q>>>0,X||_t(Q,1,this.length),this[Q]&128?(255-this[Q]+1)*-1:this[Q]},O.prototype.readInt16LE=function(Q,X){Q=Q>>>0,X||_t(Q,2,this.length);const he=this[Q]|this[Q+1]<<8;return he&32768?he|4294901760:he},O.prototype.readInt16BE=function(Q,X){Q=Q>>>0,X||_t(Q,2,this.length);const he=this[Q+1]|this[Q]<<8;return he&32768?he|4294901760:he},O.prototype.readInt32LE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),this[Q]|this[Q+1]<<8|this[Q+2]<<16|this[Q+3]<<24},O.prototype.readInt32BE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),this[Q]<<24|this[Q+1]<<16|this[Q+2]<<8|this[Q+3]},O.prototype.readBigInt64LE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=this[Q+4]+this[Q+5]*2**8+this[Q+6]*2**16+(he<<24);return(BigInt(Te)<<BigInt(32))+BigInt(X+this[++Q]*2**8+this[++Q]*2**16+this[++Q]*2**24)}),O.prototype.readBigInt64BE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=(X<<24)+this[++Q]*2**16+this[++Q]*2**8+this[++Q];return(BigInt(Te)<<BigInt(32))+BigInt(this[++Q]*2**24+this[++Q]*2**16+this[++Q]*2**8+he)}),O.prototype.readFloatLE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),q.read(this,Q,!0,23,4)},O.prototype.readFloatBE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),q.read(this,Q,!1,23,4)},O.prototype.readDoubleLE=function(Q,X){return Q=Q>>>0,X||_t(Q,8,this.length),q.read(this,Q,!0,52,8)},O.prototype.readDoubleBE=function(Q,X){return Q=Q>>>0,X||_t(Q,8,this.length),q.read(this,Q,!1,52,8)};function rt(ae,Q,X,he,Te,$e){if(!O.isBuffer(ae))throw new TypeError('"buffer" argument must be a Buffer instance');if(Q>Te||Q<$e)throw new RangeError('"value" argument is out of bounds');if(X+he>ae.length)throw new RangeError("Index out of range")}O.prototype.writeUintLE=O.prototype.writeUIntLE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,he=he>>>0,!Te){const ct=Math.pow(2,8*he)-1;rt(this,Q,X,he,ct,0)}let $e=1,Ue=0;for(this[X]=Q&255;++Ue<he&&($e*=256);)this[X+Ue]=Q/$e&255;return X+he},O.prototype.writeUintBE=O.prototype.writeUIntBE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,he=he>>>0,!Te){const ct=Math.pow(2,8*he)-1;rt(this,Q,X,he,ct,0)}let $e=he-1,Ue=1;for(this[X+$e]=Q&255;--$e>=0&&(Ue*=256);)this[X+$e]=Q/Ue&255;return X+he},O.prototype.writeUint8=O.prototype.writeUInt8=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,1,255,0),this[X]=Q&255,X+1},O.prototype.writeUint16LE=O.prototype.writeUInt16LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,65535,0),this[X]=Q&255,this[X+1]=Q>>>8,X+2},O.prototype.writeUint16BE=O.prototype.writeUInt16BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,65535,0),this[X]=Q>>>8,this[X+1]=Q&255,X+2},O.prototype.writeUint32LE=O.prototype.writeUInt32LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,4294967295,0),this[X+3]=Q>>>24,this[X+2]=Q>>>16,this[X+1]=Q>>>8,this[X]=Q&255,X+4},O.prototype.writeUint32BE=O.prototype.writeUInt32BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,4294967295,0),this[X]=Q>>>24,this[X+1]=Q>>>16,this[X+2]=Q>>>8,this[X+3]=Q&255,X+4};function Vt(ae,Q,X,he,Te){st(Q,he,Te,ae,X,7);let $e=Number(Q&BigInt(4294967295));ae[X++]=$e,$e=$e>>8,ae[X++]=$e,$e=$e>>8,ae[X++]=$e,$e=$e>>8,ae[X++]=$e;let Ue=Number(Q>>BigInt(32)&BigInt(4294967295));return ae[X++]=Ue,Ue=Ue>>8,ae[X++]=Ue,Ue=Ue>>8,ae[X++]=Ue,Ue=Ue>>8,ae[X++]=Ue,X}function Rt(ae,Q,X,he,Te){st(Q,he,Te,ae,X,7);let $e=Number(Q&BigInt(4294967295));ae[X+7]=$e,$e=$e>>8,ae[X+6]=$e,$e=$e>>8,ae[X+5]=$e,$e=$e>>8,ae[X+4]=$e;let Ue=Number(Q>>BigInt(32)&BigInt(4294967295));return ae[X+3]=Ue,Ue=Ue>>8,ae[X+2]=Ue,Ue=Ue>>8,ae[X+1]=Ue,Ue=Ue>>8,ae[X]=Ue,X+8}O.prototype.writeBigUInt64LE=rn(function(Q,X=0){return Vt(this,Q,X,BigInt(0),BigInt("0xffffffffffffffff"))}),O.prototype.writeBigUInt64BE=rn(function(Q,X=0){return Rt(this,Q,X,BigInt(0),BigInt("0xffffffffffffffff"))}),O.prototype.writeIntLE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,!Te){const kt=Math.pow(2,8*he-1);rt(this,Q,X,he,kt-1,-kt)}let $e=0,Ue=1,ct=0;for(this[X]=Q&255;++$e<he&&(Ue*=256);)Q<0&&ct===0&&this[X+$e-1]!==0&&(ct=1),this[X+$e]=(Q/Ue>>0)-ct&255;return X+he},O.prototype.writeIntBE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,!Te){const kt=Math.pow(2,8*he-1);rt(this,Q,X,he,kt-1,-kt)}let $e=he-1,Ue=1,ct=0;for(this[X+$e]=Q&255;--$e>=0&&(Ue*=256);)Q<0&&ct===0&&this[X+$e+1]!==0&&(ct=1),this[X+$e]=(Q/Ue>>0)-ct&255;return X+he},O.prototype.writeInt8=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,1,127,-128),Q<0&&(Q=255+Q+1),this[X]=Q&255,X+1},O.prototype.writeInt16LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,32767,-32768),this[X]=Q&255,this[X+1]=Q>>>8,X+2},O.prototype.writeInt16BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,32767,-32768),this[X]=Q>>>8,this[X+1]=Q&255,X+2},O.prototype.writeInt32LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,2147483647,-2147483648),this[X]=Q&255,this[X+1]=Q>>>8,this[X+2]=Q>>>16,this[X+3]=Q>>>24,X+4},O.prototype.writeInt32BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,2147483647,-2147483648),Q<0&&(Q=4294967295+Q+1),this[X]=Q>>>24,this[X+1]=Q>>>16,this[X+2]=Q>>>8,this[X+3]=Q&255,X+4},O.prototype.writeBigInt64LE=rn(function(Q,X=0){return Vt(this,Q,X,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),O.prototype.writeBigInt64BE=rn(function(Q,X=0){return Rt(this,Q,X,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Pe(ae,Q,X,he,Te,$e){if(X+he>ae.length)throw new RangeError("Index out of range");if(X<0)throw new RangeError("Index out of range")}function it(ae,Q,X,he,Te){return Q=+Q,X=X>>>0,Te||Pe(ae,Q,X,4),q.write(ae,Q,X,he,23,4),X+4}O.prototype.writeFloatLE=function(Q,X,he){return it(this,Q,X,!0,he)},O.prototype.writeFloatBE=function(Q,X,he){return it(this,Q,X,!1,he)};function zt(ae,Q,X,he,Te){return Q=+Q,X=X>>>0,Te||Pe(ae,Q,X,8),q.write(ae,Q,X,he,52,8),X+8}O.prototype.writeDoubleLE=function(Q,X,he){return zt(this,Q,X,!0,he)},O.prototype.writeDoubleBE=function(Q,X,he){return zt(this,Q,X,!1,he)},O.prototype.copy=function(Q,X,he,Te){if(!O.isBuffer(Q))throw new TypeError("argument should be a Buffer");if(he||(he=0),!Te&&Te!==0&&(Te=this.length),X>=Q.length&&(X=Q.length),X||(X=0),Te>0&&Te<he&&(Te=he),Te===he||Q.length===0||this.length===0)return 0;if(X<0)throw new RangeError("targetStart out of bounds");if(he<0||he>=this.length)throw new RangeError("Index out of range");if(Te<0)throw new RangeError("sourceEnd out of bounds");Te>this.length&&(Te=this.length),Q.length-X<Te-he&&(Te=Q.length-X+he);const $e=Te-he;return this===Q&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(X,he,Te):Uint8Array.prototype.set.call(Q,this.subarray(he,Te),X),$e},O.prototype.fill=function(Q,X,he,Te){if(typeof Q=="string"){if(typeof X=="string"?(Te=X,X=0,he=this.length):typeof he=="string"&&(Te=he,he=this.length),Te!==void 0&&typeof Te!="string")throw new TypeError("encoding must be a string");if(typeof Te=="string"&&!O.isEncoding(Te))throw new TypeError("Unknown encoding: "+Te);if(Q.length===1){const Ue=Q.charCodeAt(0);(Te==="utf8"&&Ue<128||Te==="latin1")&&(Q=Ue)}}else typeof Q=="number"?Q=Q&255:typeof Q=="boolean"&&(Q=Number(Q));if(X<0||this.length<X||this.length<he)throw new RangeError("Out of range index");if(he<=X)return this;X=X>>>0,he=he===void 0?this.length:he>>>0,Q||(Q=0);let $e;if(typeof Q=="number")for($e=X;$e<he;++$e)this[$e]=Q;else{const Ue=O.isBuffer(Q)?Q:O.from(Q,Te),ct=Ue.length;if(ct===0)throw new TypeError('The value "'+Q+'" is invalid for argument "value"');for($e=0;$e<he-X;++$e)this[$e+X]=Ue[$e%ct]}return this};const Bt={};function nt(ae,Q,X){Bt[ae]=class extends X{constructor(){super(),Object.defineProperty(this,"message",{value:Q.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${ae}]`,this.stack,delete this.name}get code(){return ae}set code(Te){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:Te,writable:!0})}toString(){return`${this.name} [${ae}]: ${this.message}`}}}nt("ERR_BUFFER_OUT_OF_BOUNDS",function(ae){return ae?`${ae} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),nt("ERR_INVALID_ARG_TYPE",function(ae,Q){return`The "${ae}" argument must be of type number. Received type ${typeof Q}`},TypeError),nt("ERR_OUT_OF_RANGE",function(ae,Q,X){let he=`The value of "${ae}" is out of range.`,Te=X;return Number.isInteger(X)&&Math.abs(X)>2**32?Te=et(String(X)):typeof X=="bigint"&&(Te=String(X),(X>BigInt(2)**BigInt(32)||X<-(BigInt(2)**BigInt(32)))&&(Te=et(Te)),Te+="n"),he+=` It must be ${Q}. Received ${Te}`,he},RangeError);function et(ae){let Q="",X=ae.length;const he=ae[0]==="-"?1:0;for(;X>=he+4;X-=3)Q=`_${ae.slice(X-3,X)}${Q}`;return`${ae.slice(0,X)}${Q}`}function ot(ae,Q,X){gt(Q,"offset"),(ae[Q]===void 0||ae[Q+X]===void 0)&&Dt(Q,ae.length-(X+1))}function st(ae,Q,X,he,Te,$e){if(ae>X||ae<Q){const Ue=typeof Q=="bigint"?"n":"";let ct;throw Q===0||Q===BigInt(0)?ct=`>= 0${Ue} and < 2${Ue} ** ${($e+1)*8}${Ue}`:ct=`>= -(2${Ue} ** ${($e+1)*8-1}${Ue}) and < 2 ** ${($e+1)*8-1}${Ue}`,new Bt.ERR_OUT_OF_RANGE("value",ct,ae)}ot(he,Te,$e)}function gt(ae,Q){if(typeof ae!="number")throw new Bt.ERR_INVALID_ARG_TYPE(Q,"number",ae)}function Dt(ae,Q,X){throw Math.floor(ae)!==ae?(gt(ae,X),new Bt.ERR_OUT_OF_RANGE("offset","an integer",ae)):Q<0?new Bt.ERR_BUFFER_OUT_OF_BOUNDS:new Bt.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${Q}`,ae)}const Ut=/[^+/0-9A-Za-z-_]/g;function Lt(ae){if(ae=ae.split("=")[0],ae=ae.trim().replace(Ut,""),ae.length<2)return"";for(;ae.length%4!==0;)ae=ae+"=";return ae}function Zt(ae,Q){Q=Q||1/0;let X;const he=ae.length;let Te=null;const $e=[];for(let Ue=0;Ue<he;++Ue){if(X=ae.charCodeAt(Ue),X>55295&&X<57344){if(!Te){if(X>56319){(Q-=3)>-1&&$e.push(239,191,189);continue}else if(Ue+1===he){(Q-=3)>-1&&$e.push(239,191,189);continue}Te=X;continue}if(X<56320){(Q-=3)>-1&&$e.push(239,191,189),Te=X;continue}X=(Te-55296<<10|X-56320)+65536}else Te&&(Q-=3)>-1&&$e.push(239,191,189);if(Te=null,X<128){if((Q-=1)<0)break;$e.push(X)}else if(X<2048){if((Q-=2)<0)break;$e.push(X>>6|192,X&63|128)}else if(X<65536){if((Q-=3)<0)break;$e.push(X>>12|224,X>>6&63|128,X&63|128)}else if(X<1114112){if((Q-=4)<0)break;$e.push(X>>18|240,X>>12&63|128,X>>6&63|128,X&63|128)}else throw new Error("Invalid code point")}return $e}function Kt(ae){const Q=[];for(let X=0;X<ae.length;++X)Q.push(ae.charCodeAt(X)&255);return Q}function fn(ae,Q){let X,he,Te;const $e=[];for(let Ue=0;Ue<ae.length&&!((Q-=2)<0);++Ue)X=ae.charCodeAt(Ue),he=X>>8,Te=X%256,$e.push(Te),$e.push(he);return $e}function tn(ae){return Z.toByteArray(Lt(ae))}function nn(ae,Q,X,he){let Te;for(Te=0;Te<he&&!(Te+X>=Q.length||Te>=ae.length);++Te)Q[Te+X]=ae[Te];return Te}function Wt(ae,Q){return ae instanceof Q||ae!=null&&ae.constructor!=null&&ae.constructor.name!=null&&ae.constructor.name===Q.name}function Gt(ae){return ae!==ae}const _n=function(){const ae="0123456789abcdef",Q=new Array(256);for(let X=0;X<16;++X){const he=X*16;for(let Te=0;Te<16;++Te)Q[he+Te]=ae[X]+ae[Te]}return Q}();function rn(ae){return typeof BigInt>"u"?Qt:ae}function Qt(){throw new Error("BigInt not supported")}}(buffer)),buffer}var toolsEbml={},hasRequiredToolsEbml;function requireToolsEbml(){if(hasRequiredToolsEbml)return toolsEbml;hasRequiredToolsEbml=1;var N=toolsEbml&&toolsEbml.__assign||function(){return N=Object.assign||function(I){for(var D,a=1,O=arguments.length;a<O;a++){D=arguments[a];for(var F in D)Object.prototype.hasOwnProperty.call(D,F)&&(I[F]=D[F])}return I},N.apply(this,arguments)},Z=toolsEbml&&toolsEbml.__spreadArray||function(I,D,a){if(a||arguments.length===2)for(var O=0,F=D.length,z;O<F;O++)(z||!(O in D))&&(z||(z=Array.prototype.slice.call(D,0,O)),z[O]=D[O]);return I.concat(z||Array.prototype.slice.call(D))};Object.defineProperty(toolsEbml,"__esModule",{value:!0});var q=requireTools(),J=function(){function I(){}return I.readVint=function(D,a){a===void 0&&(a=0);var O=8-Math.floor(Math.log2(D[a]));if(O>8){var F=I.readHexString(D,a,a+O);throw new Error("Unrepresentable length: ".concat(O," ").concat(F))}if(a+O>D.length)return null;for(var z=D[a]&(1<<8-O)-1,K=1;K<O;K+=1){if(K===7&&z>=Math.pow(2,8)&&D[a+7]>0)return{length:O,value:-1};z*=Math.pow(2,8),z+=D[a+K]}return{length:O,value:z}},I.writeVint=function(D){if(D<0||D>Math.pow(2,53))throw new Error("Unrepresentable value: ".concat(D));var a=1;for(a=1;a<=8&&!(D<Math.pow(2,7*a)-1);a+=1);for(var O=q.Buffer.alloc(a),F=D,z=1;z<=a;z+=1){var K=F&255;O[a-z]=K,F-=K,F/=Math.pow(2,8)}return O[0]|=1<<8-a,O},I.concatenate=function(D,a){return!D&&!a?q.Buffer.from([]):!D||D.byteLength===0?a:!a||a.byteLength===0?D:q.Buffer.from(Z(Z([],D,!0),a,!0))},I.readHexString=function(D,a,O){return a===void 0&&(a=0),O===void 0&&(O=D.byteLength),Array.from(D.slice(a,O)).map(function(F){return Number(F).toString(16)}).reduce(function(F,z){return"".concat(F).concat(z.padStart(2,"0"))},"")},I.readUtf8=function(D){try{return q.Buffer.from(D).toString("utf8")}catch{return null}},I.readUnsigned=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 1:return a.getUint8(0);case 2:return a.getUint16(0);case 4:return a.getUint32(0)}return D.byteLength<=6?D.reduce(function(O,F){return O*256+F},0):I.readHexString(D,0,D.byteLength)},I.readSigned=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 1:return a.getInt8(0);case 2:return a.getInt16(0);case 4:return a.getInt32(0);default:return NaN}},I.readFloat=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 4:return a.getFloat32(0);case 8:return a.getFloat64(0);default:return NaN}},I.readDate=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 1:return new Date(a.getUint8(0));case 2:return new Date(a.getUint16(0));case 4:return new Date(a.getUint32(0));case 8:return new Date(Number.parseInt(I.readHexString(D),16));default:return new Date(0)}},I.readDataFromTag=function(D,a){var O=D.type,F=D.name,z=D.track,K=D.discardable||!1,te=D.keyframe||!1,ne=null,ee;switch(O){case"u":ee=I.readUnsigned(a);break;case"f":ee=I.readFloat(a);break;case"i":ee=I.readSigned(a);break;case"s":ee=String.fromCharCode.apply(String,a);break;case"8":ee=I.readUtf8(a);break;case"d":ee=I.readDate(a);break}if(F==="SimpleBlock"||F==="Block"){var re=0,ce=I.readVint(a,re),oe=ce.length,se=ce.value;re+=oe,z=se,ee=I.readSigned(a.subarray(re,re+2)),re+=2,F==="SimpleBlock"&&(te=!!(a[oe+2]&128),K=!!(a[oe+2]&1)),re+=1,ne=a.subarray(re)}return N(N({},D),{data:a,discardable:K,keyframe:te,payload:ne,track:z,value:ee})},I}();return toolsEbml.default=J,toolsEbml}var vint,hasRequiredVint;function requireVint(){return hasRequiredVint||(hasRequiredVint=1,vint=function(N,Z,q){Z=Z||0;for(var J=1;J<=8&&!(N[Z]>=Math.pow(2,8-J));J++);if(J>8)throw new Error("Unrepresentable length: "+J+" "+N.toString("hex",Z,Z+J));if(Z+J>N.length)return null;var I,D=N[Z]&(1<<8-J)-1;for(I=1;I<J;I++){if(I===7&&D>=Math.pow(2,45)&&N[Z+7]>0)return{length:J,value:-1};D*=Math.pow(2,8),D+=N[Z+I]}return q&&(D-=Math.pow(2,J*7-1)-1),{length:J,value:D}}),vint}var bufferReader,hasRequiredBufferReader;function requireBufferReader(){if(hasRequiredBufferReader)return bufferReader;hasRequiredBufferReader=1;var N=requireVint();function Z(q){this.buffer=q,this.offset=0}return Z.prototype.nextInt16BE=function(){var q=this.buffer.readInt16BE(this.offset);return this.offset+=2,q},Z.prototype.nextUInt8=function(){var q=this.buffer.readUInt8(this.offset);return this.offset+=1,q},Z.prototype.nextUIntV=function(){var q=N(this.buffer,this.offset);return this.offset+=q.length,q.value},Z.prototype.nextIntV=function(){var q=N(this.buffer,this.offset,!0);return this.offset+=q.length,q.value},Z.prototype.nextBuffer=function(q){var J=q?this.buffer.slice(this.offset,this.offset+q):this.buffer.slice(this.offset);return this.offset+=q||this.length,J},Object.defineProperty(Z.prototype,"length",{get:function(){return this.buffer.length-this.offset}}),bufferReader=Z,bufferReader}var ebmlBlock,hasRequiredEbmlBlock;function requireEbmlBlock(){if(hasRequiredEbmlBlock)return ebmlBlock;hasRequiredEbmlBlock=1;var N=requireBufferReader(),Z=1,q=3,J=2;ebmlBlock=function(D){var a={},O=new N(D);a.trackNumber=O.nextUIntV(),a.timecode=O.nextInt16BE();var F=O.nextUInt8();a.invisible=!!(F&8),a.keyframe=!!(F&128),a.discardable=!!(F&1);var z=(F&6)>>1;return a.frames=I(O,z),a};function I(D,a){if(!a)return[D.nextBuffer()];var O,F,z=[],K=D.nextUInt8()+1;if(a===J){if(D.length%K!==0)throw new Error("Fixed-Size Lacing Error");for(F=D.length/K,O=0;O<K;O++)z.push(D.nextBuffer(F));return z}var te=[];if(a===Z)for(O=0;O<K-1;O++){var ne;F=0;do ne=D.nextUInt8(),F+=ne;while(ne===255);te.push(F)}else if(a===q)for(F=D.nextUIntV(),te.push(F),O=1;O<K-1;O++)F+=D.nextIntV(),te.push(F);for(O=0;O<K-1;O++)z.push(D.nextBuffer(te[O]));return z.push(D.nextBuffer()),z}return ebmlBlock}var hasRequiredTools;function requireTools(){return hasRequiredTools||(hasRequiredTools=1,function(N){Object.defineProperty(N,"__esModule",{value:!0}),N.convertEBMLDateToJSDate=N.createFloatBuffer=N.createIntBuffer=N.createUIntBuffer=N.encodeValueToBuffer=N.concat=N.putRefinedMetaData=N.extractElement=N.removeElement=N.makeMetadataSeekable=N.createRIFFChunk=N.VP8BitStreamToRiffWebPBuffer=N.WebPBlockFilter=N.encodeTag=N.readBlock=N.ebmlBlock=N.writeVint=N.readVint=N.Buffer=void 0;var Z=requireInt64Buffer(),q=requireEBMLEncoder(),J=requireBuffer(),I=requireToolsEbml(),D=requireEbmlBlock();N.Buffer=J.Buffer,N.readVint=I.default.readVint,N.writeVint=I.default.writeVint,N.ebmlBlock=D;function a(be){return(0,N.ebmlBlock)(new N.Buffer(be))}N.readBlock=a;function O(be,Se,Me){return Me===void 0&&(Me=!1),ue([be,Me?new N.Buffer("01ffffffffffffff","hex"):(0,N.writeVint)(Se.length),Se])}N.encodeTag=O;function F(be){return be.reduce(function(Se,Me){if(Me.type!=="b"||Me.name!=="SimpleBlock")return Se;var We=(0,N.ebmlBlock)(Me.data),Je=We.frames.some(function(Le){var Tt=Le.slice(3,6).toString("hex");return Tt==="9d012a"});return Je?Se.concat(Me):Se},[])}N.WebPBlockFilter=F;function z(be){var Se=K("VP8 ",be),Me=ue([new N.Buffer("WEBP","ascii"),Se]);return K("RIFF",Me)}N.VP8BitStreamToRiffWebPBuffer=z;function K(be,Se){var Me=new N.Buffer(4);return Me.writeUInt32LE(Se.byteLength,0),ue([new N.Buffer(be.substr(0,4),"ascii"),Me,Se,new N.Buffer(Se.byteLength%2===0?0:1)])}N.createRIFFChunk=K;function te(be,Se,Me){var We=ee("EBML",be),Je=ce(We),Le=Je+12,Tt=be[be.length-1].dataEnd-Le,Et=ee("Info",be);ne("Duration",Et),Et.splice(1,0,{name:"Duration",type:"f",data:we(Se,8)});for(var At=ce(Et),jt=ee("Tracks",be),Pt=ce(jt),_t=47,rt=[],Vt=5+Me.length*15,Rt=[],Pe=-1,it=10,zt=function(st){var gt=_t,Dt=gt+At,Ut=Dt+Pt,Lt=Ut+Vt,Zt=Lt-Tt;if(rt=[],rt.push({name:"SeekHead",type:"m",isEnd:!1}),rt.push({name:"Seek",type:"m",isEnd:!1}),rt.push({name:"SeekID",type:"b",data:new N.Buffer([21,73,169,102])}),rt.push({name:"SeekPosition",type:"u",data:pe(gt)}),rt.push({name:"Seek",type:"m",isEnd:!0}),rt.push({name:"Seek",type:"m",isEnd:!1}),rt.push({name:"SeekID",type:"b",data:new N.Buffer([22,84,174,107])}),rt.push({name:"SeekPosition",type:"u",data:pe(Dt)}),rt.push({name:"Seek",type:"m",isEnd:!0}),rt.push({name:"Seek",type:"m",isEnd:!1}),rt.push({name:"SeekID",type:"b",data:new N.Buffer([28,83,187,107])}),rt.push({name:"SeekPosition",type:"u",data:pe(Ut)}),rt.push({name:"Seek",type:"m",isEnd:!0}),rt.push({name:"SeekHead",type:"m",isEnd:!0}),_t=ce(rt),Rt=[],Rt.push({name:"Cues",type:"m",isEnd:!1}),Me.forEach(function(Kt){var fn=Kt.CueTrack,tn=Kt.CueClusterPosition,nn=Kt.CueTime;Rt.push({name:"CuePoint",type:"m",isEnd:!1}),Rt.push({name:"CueTime",type:"u",data:pe(nn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Rt.push({name:"CueTrack",type:"u",data:pe(fn)}),tn-=Le,tn+=Zt,Rt.push({name:"CueClusterPosition",type:"u",data:pe(tn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Rt.push({name:"CuePoint",type:"m",isEnd:!0})}),Rt.push({name:"Cues",type:"m",isEnd:!0}),Vt=ce(Rt),Pe!==Zt){if(Pe=Zt,st===it-1)throw new Error("Failed to converge to a stable metadata size")}else return"break"},Bt=0;Bt<it;Bt++){var nt=zt(Bt);if(nt==="break")break}var et=[].concat.apply([],[We,{name:"Segment",type:"m",isEnd:!1,unknownSize:!0},rt,Et,jt,Rt]),ot=new q.default().encode(et);return ot}N.makeMetadataSeekable=te;function ne(be,Se){for(var Me=-1,We=0;We<Se.length;We++){var Je=Se[We];if(Je.name===be)if(Je.type==="m")if(!Je.isEnd)Me=We;else{if(Me==-1)throw new Error("Detected ".concat(be," closing element before finding the start"));Se.splice(Me,We-Me+1);return}else{Se.splice(We,1);return}}}N.removeElement=ne;function ee(be,Se){for(var Me=[],We=-1,Je=0;Je<Se.length;Je++){var Le=Se[Je];if(Le.name===be)if(Le.type==="m")if(!Le.isEnd)We=Je;else{if(We==-1)throw new Error("Detected ".concat(be," closing element before finding the start"));Me=Se.slice(We,Je+1);break}else{Me.push(Se[Je]);break}}return Me}N.extractElement=ee;function re(be,Se){Array.isArray(Se.cueInfos)&&!Array.isArray(Se.cues)&&(console.warn("putRefinedMetaData: info.cueInfos property is deprecated. please use info.cues"),Se.cues=Se.cueInfos);for(var Me=[],We=[],Je=0;Je<be.length;Je++){var Le=be[Je];if(Le.type==="m"&&Le.name==="Segment"){if(Me=be.slice(0,Je),We=be.slice(Je),Le.unknownSize){We.shift();break}throw new Error("this metadata is not streaming webm file")}}if(!(We[We.length-1].dataEnd>0))throw new Error("metadata dataEnd has wrong number");var Tt=We[We.length-1].dataEnd,Et=Me[Me.length-1].dataEnd,At=new q.default().encode(Me).byteLength,jt=At-Et,Pt=Tt-We[0].tagStart;We[0].tagStart-Et,We[0].tagStart;var _t=new N.Buffer([24,83,128,103]),rt=new N.Buffer("01ffffffffffffff","hex"),Vt=_t.byteLength+rt.byteLength,Rt=Pt,Pe;for(Pe=1;Pe<20;Pe++){var it=Et+Vt+Rt,zt=it-Tt,Bt=jt+zt,nt=oe(We,Bt,Se),et=new q.default().encode(nt).byteLength;if(et===Rt)return new q.default().encode([].concat(Me,[{type:"m",name:"Segment",isEnd:!1,unknownSize:!0}],nt));Rt=et}throw new Error("unable to refine metadata, stable size could not be found in "+Pe+" iterations!")}N.putRefinedMetaData=re;function ce(be){var Se=new q.default;return be.reduce(function(Me,We){return Me.concat(Se.encode([We]))},[]).reduce(function(Me,We){return Me+We.byteLength},0)}function oe(be,Se,Me){var We=Me.duration,Je=Me.clusterPtrs,Le=Me.cues,Tt=be.slice(0);if(typeof We=="number"){var Et=!1;Tt.forEach(function(jt){jt.type==="f"&&jt.name==="Duration"&&(Et=!0,jt.data=we(We,8))}),Et||ge(Tt,"Info",[{name:"Duration",type:"f",data:we(We,8)}])}Array.isArray(Le)&&ge(Tt,"Cues",fe(Le,Se));var At=[];return Array.isArray(Je)&&(console.warn("append cluster pointers to seekhead is deprecated. please use cues"),At=se(Je,Se)),ge(Tt,"SeekHead",At,!0),Tt}function se(be,Se){var Me=[];return be.forEach(function(We){Me.push({name:"Seek",type:"m",isEnd:!1}),Me.push({name:"SeekID",type:"b",data:new N.Buffer([31,67,182,117])}),Me.push({name:"SeekPosition",type:"u",data:pe(We+Se)}),Me.push({name:"Seek",type:"m",isEnd:!0})}),Me}function fe(be,Se){var Me=[];return be.forEach(function(We){var Je=We.CueTrack,Le=We.CueClusterPosition,Tt=We.CueTime;Me.push({name:"CuePoint",type:"m",isEnd:!1}),Me.push({name:"CueTime",type:"u",data:pe(Tt)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Me.push({name:"CueTrack",type:"u",data:pe(Je)}),Me.push({name:"CueClusterPosition",type:"u",data:pe(Le+Se)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Me.push({name:"CuePoint",type:"m",isEnd:!0})}),Me}function ge(be,Se,Me,We){We===void 0&&(We=!1);for(var Je=-1,Le=0;Le<be.length;Le++){var Tt=be[Le];if(Tt.type==="m"&&Tt.name===Se&&Tt.isEnd===!1){Je=Le;break}}Je>=0?Array.prototype.splice.apply(be,[Je+1,0].concat(Me)):We?[].concat([{name:Se,type:"m",isEnd:!1}],Me,[{name:Se,type:"m",isEnd:!0}]).reverse().forEach(function(Et){be.unshift(Et)}):(be.push({name:Se,type:"m",isEnd:!1}),Me.forEach(function(Et){be.push(Et)}),be.push({name:Se,type:"m",isEnd:!0}))}function ue(be){return N.Buffer.concat(be)}N.concat=ue;function _e(be){var Se=new N.Buffer(0);if(be.type==="m")return be;switch(be.type){case"u":Se=pe(be.value);break;case"i":Se=ye(be.value);break;case"f":Se=we(be.value);break;case"s":Se=new N.Buffer(be.value,"ascii");break;case"8":Se=new N.Buffer(be.value,"utf8");break;case"b":Se=be.value;break;case"d":Se=new Z.Int64BE(be.value.getTime().toString()).toBuffer();break}return Object.assign({},be,{data:Se})}N.encodeValueToBuffer=_e;function pe(be){for(var Se=1;be>=Math.pow(2,8*Se);Se++);if(Se>=7)return console.warn("7bit or more bigger uint not supported."),new Z.Uint64BE(be).toBuffer();var Me=new N.Buffer(Se);return Me.writeUIntBE(be,0,Se),Me}N.createUIntBuffer=pe;function ye(be){for(var Se=1;be>=Math.pow(2,8*Se);Se++);if(Se>=7)return console.warn("7bit or more bigger uint not supported."),new Z.Int64BE(be).toBuffer();var Me=new N.Buffer(Se);return Me.writeIntBE(be,0,Se),Me}N.createIntBuffer=ye;function we(be,Se){if(Se===void 0&&(Se=8),Se===8){var Me=new N.Buffer(8);return Me.writeDoubleBE(be,0),Me}else if(Se===4){var Me=new N.Buffer(4);return Me.writeFloatBE(be,0),Me}else throw new Error("float type bits must 4bytes or 8bytes")}N.createFloatBuffer=we;function Ie(be){return be instanceof Date?be:new Date(new Date("2001-01-01T00:00:00.000Z").getTime()+Number(be)/1e3/1e3)}N.convertEBMLDateToJSDate=Ie}(tools)),tools}var hasRequiredEBMLDecoder;function requireEBMLDecoder(){if(hasRequiredEBMLDecoder)return EBMLDecoder;hasRequiredEBMLDecoder=1,Object.defineProperty(EBMLDecoder,"__esModule",{value:!0});var N=requireInt64Buffer(),Z=requireTools(),q=requireTools(),J=requireEbmlID(),I;(function(a){a[a.STATE_TAG=1]="STATE_TAG",a[a.STATE_SIZE=2]="STATE_SIZE",a[a.STATE_CONTENT=3]="STATE_CONTENT"})(I||(I={}));var D=function(){function a(){this._buffer=new Z.Buffer(0),this._tag_stack=[],this._state=I.STATE_TAG,this._cursor=0,this._total=0,this._schema=J.byEbmlID,this._result=[]}return a.prototype.decode=function(O){this.readChunk(O);var F=this._result;return this._result=[],F},a.prototype.readChunk=function(O){for(this._buffer=q.concat([this._buffer,new Z.Buffer(O)]);this._cursor<this._buffer.length&&!(this._state===I.STATE_TAG&&!this.readTag()||this._state===I.STATE_SIZE&&!this.readSize()||this._state===I.STATE_CONTENT&&!this.readContent()););},a.prototype.getSchemaInfo=function(O){return this._schema[O]||{name:"unknown",level:-1,type:"unknown",description:"unknown"}},a.prototype.readTag=function(){if(this._cursor>=this._buffer.length)return!1;var O=(0,Z.readVint)(this._buffer,this._cursor);if(O==null)return!1;var F=this._buffer.slice(this._cursor,this._cursor+O.length),z=F.reduce(function(ne,ee,re,ce){return ne+ee*Math.pow(16,2*(ce.length-1-re))},0),K=this.getSchemaInfo(z),te={EBML_ID:z.toString(16),schema:K,type:K.type,name:K.name,level:K.level,tagStart:this._total,tagEnd:this._total+O.length,sizeStart:this._total+O.length,sizeEnd:null,dataStart:null,dataEnd:null,dataSize:null,data:null};return this._tag_stack.push(te),this._cursor+=O.length,this._total+=O.length,this._state=I.STATE_SIZE,!0},a.prototype.readSize=function(){if(this._cursor>=this._buffer.length)return!1;var O=(0,Z.readVint)(this._buffer,this._cursor);if(O==null)return!1;var F=this._tag_stack[this._tag_stack.length-1];return F.sizeEnd=F.sizeStart+O.length,F.dataStart=F.sizeEnd,F.dataSize=O.value,O.value===-1?(F.dataEnd=-1,F.type==="m"&&(F.unknownSize=!0)):F.dataEnd=F.sizeEnd+O.value,this._cursor+=O.length,this._total+=O.length,this._state=I.STATE_CONTENT,!0},a.prototype.readContent=function(){var O=this._tag_stack[this._tag_stack.length-1];if(O.type==="m"){if(O.isEnd=!1,this._result.push(O),this._state=I.STATE_TAG,O.dataSize===0){var F=Object.assign({},O,{isEnd:!0});this._result.push(F),this._tag_stack.pop()}return!0}if(this._buffer.length<this._cursor+O.dataSize)return!1;var z=this._buffer.slice(this._cursor,this._cursor+O.dataSize);switch(this._buffer=this._buffer.slice(this._cursor+O.dataSize),O.data=z,O.type){case"u":O.value=z.readUIntBE(0,z.length);break;case"i":O.value=z.readIntBE(0,z.length);break;case"f":O.value=O.dataSize===4?z.readFloatBE(0):O.dataSize===8?z.readDoubleBE(0):(console.warn("cannot read ".concat(O.dataSize," octets float. failback to 0")),0);break;case"s":O.value=z.toString("ascii");break;case"8":O.value=z.toString("utf8");break;case"b":O.value=z;break;case"d":O.value=(0,Z.convertEBMLDateToJSDate)(new N.Int64BE(z).toNumber());break}if(O.value===null)throw new Error("unknown tag type:"+O.type);for(this._result.push(O),this._total+=O.dataSize,this._state=I.STATE_TAG,this._cursor=0,this._tag_stack.pop();this._tag_stack.length>0;){var K=this._tag_stack[this._tag_stack.length-1];if(K.dataEnd<0)return this._tag_stack.pop(),!0;if(this._total<K.dataEnd)break;if(K.type!=="m")throw new Error("parent element is not master element");var F=Object.assign({},K,{isEnd:!0});this._result.push(F),this._tag_stack.pop()}return!0},a}();return EBMLDecoder.default=D,EBMLDecoder}var EBMLReader={},events={exports:{}},hasRequiredEvents;function requireEvents(){if(hasRequiredEvents)return events.exports;hasRequiredEvents=1;var N=typeof Reflect=="object"?Reflect:null,Z=N&&typeof N.apply=="function"?N.apply:function(_e,pe,ye){return Function.prototype.apply.call(_e,pe,ye)},q;N&&typeof N.ownKeys=="function"?q=N.ownKeys:Object.getOwnPropertySymbols?q=function(_e){return Object.getOwnPropertyNames(_e).concat(Object.getOwnPropertySymbols(_e))}:q=function(_e){return Object.getOwnPropertyNames(_e)};function J(ue){console&&console.warn&&console.warn(ue)}var I=Number.isNaN||function(_e){return _e!==_e};function D(){D.init.call(this)}events.exports=D,events.exports.once=se,D.EventEmitter=D,D.prototype._events=void 0,D.prototype._eventsCount=0,D.prototype._maxListeners=void 0;var a=10;function O(ue){if(typeof ue!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof ue)}Object.defineProperty(D,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(ue){if(typeof ue!="number"||ue<0||I(ue))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+ue+".");a=ue}}),D.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(_e){if(typeof _e!="number"||_e<0||I(_e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+_e+".");return this._maxListeners=_e,this};function F(ue){return ue._maxListeners===void 0?D.defaultMaxListeners:ue._maxListeners}D.prototype.getMaxListeners=function(){return F(this)},D.prototype.emit=function(_e){for(var pe=[],ye=1;ye<arguments.length;ye++)pe.push(arguments[ye]);var we=_e==="error",Ie=this._events;if(Ie!==void 0)we=we&&Ie.error===void 0;else if(!we)return!1;if(we){var be;if(pe.length>0&&(be=pe[0]),be instanceof Error)throw be;var Se=new Error("Unhandled error."+(be?" ("+be.message+")":""));throw Se.context=be,Se}var Me=Ie[_e];if(Me===void 0)return!1;if(typeof Me=="function")Z(Me,this,pe);else for(var We=Me.length,Je=re(Me,We),ye=0;ye<We;++ye)Z(Je[ye],this,pe);return!0};function z(ue,_e,pe,ye){var we,Ie,be;if(O(pe),Ie=ue._events,Ie===void 0?(Ie=ue._events=Object.create(null),ue._eventsCount=0):(Ie.newListener!==void 0&&(ue.emit("newListener",_e,pe.listener?pe.listener:pe),Ie=ue._events),be=Ie[_e]),be===void 0)be=Ie[_e]=pe,++ue._eventsCount;else if(typeof be=="function"?be=Ie[_e]=ye?[pe,be]:[be,pe]:ye?be.unshift(pe):be.push(pe),we=F(ue),we>0&&be.length>we&&!be.warned){be.warned=!0;var Se=new Error("Possible EventEmitter memory leak detected. "+be.length+" "+String(_e)+" listeners added. Use emitter.setMaxListeners() to increase limit");Se.name="MaxListenersExceededWarning",Se.emitter=ue,Se.type=_e,Se.count=be.length,J(Se)}return ue}D.prototype.addListener=function(_e,pe){return z(this,_e,pe,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(_e,pe){return z(this,_e,pe,!0)};function K(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function te(ue,_e,pe){var ye={fired:!1,wrapFn:void 0,target:ue,type:_e,listener:pe},we=K.bind(ye);return we.listener=pe,ye.wrapFn=we,we}D.prototype.once=function(_e,pe){return O(pe),this.on(_e,te(this,_e,pe)),this},D.prototype.prependOnceListener=function(_e,pe){return O(pe),this.prependListener(_e,te(this,_e,pe)),this},D.prototype.removeListener=function(_e,pe){var ye,we,Ie,be,Se;if(O(pe),we=this._events,we===void 0)return this;if(ye=we[_e],ye===void 0)return this;if(ye===pe||ye.listener===pe)--this._eventsCount===0?this._events=Object.create(null):(delete we[_e],we.removeListener&&this.emit("removeListener",_e,ye.listener||pe));else if(typeof ye!="function"){for(Ie=-1,be=ye.length-1;be>=0;be--)if(ye[be]===pe||ye[be].listener===pe){Se=ye[be].listener,Ie=be;break}if(Ie<0)return this;Ie===0?ye.shift():ce(ye,Ie),ye.length===1&&(we[_e]=ye[0]),we.removeListener!==void 0&&this.emit("removeListener",_e,Se||pe)}return this},D.prototype.off=D.prototype.removeListener,D.prototype.removeAllListeners=function(_e){var pe,ye,we;if(ye=this._events,ye===void 0)return this;if(ye.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):ye[_e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete ye[_e]),this;if(arguments.length===0){var Ie=Object.keys(ye),be;for(we=0;we<Ie.length;++we)be=Ie[we],be!=="removeListener"&&this.removeAllListeners(be);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(pe=ye[_e],typeof pe=="function")this.removeListener(_e,pe);else if(pe!==void 0)for(we=pe.length-1;we>=0;we--)this.removeListener(_e,pe[we]);return this};function ne(ue,_e,pe){var ye=ue._events;if(ye===void 0)return[];var we=ye[_e];return we===void 0?[]:typeof we=="function"?pe?[we.listener||we]:[we]:pe?oe(we):re(we,we.length)}D.prototype.listeners=function(_e){return ne(this,_e,!0)},D.prototype.rawListeners=function(_e){return ne(this,_e,!1)},D.listenerCount=function(ue,_e){return typeof ue.listenerCount=="function"?ue.listenerCount(_e):ee.call(ue,_e)},D.prototype.listenerCount=ee;function ee(ue){var _e=this._events;if(_e!==void 0){var pe=_e[ue];if(typeof pe=="function")return 1;if(pe!==void 0)return pe.length}return 0}D.prototype.eventNames=function(){return this._eventsCount>0?q(this._events):[]};function re(ue,_e){for(var pe=new Array(_e),ye=0;ye<_e;++ye)pe[ye]=ue[ye];return pe}function ce(ue,_e){for(;_e+1<ue.length;_e++)ue[_e]=ue[_e+1];ue.pop()}function oe(ue){for(var _e=new Array(ue.length),pe=0;pe<_e.length;++pe)_e[pe]=ue[pe].listener||ue[pe];return _e}function se(ue,_e){return new Promise(function(pe,ye){function we(be){ue.removeListener(_e,Ie),ye(be)}function Ie(){typeof ue.removeListener=="function"&&ue.removeListener("error",we),pe([].slice.call(arguments))}ge(ue,_e,Ie,{once:!0}),_e!=="error"&&fe(ue,we,{once:!0})})}function fe(ue,_e,pe){typeof ue.on=="function"&&ge(ue,"error",_e,pe)}function ge(ue,_e,pe,ye){if(typeof ue.on=="function")ye.once?ue.once(_e,pe):ue.on(_e,pe);else if(typeof ue.addEventListener=="function")ue.addEventListener(_e,function we(Ie){ye.once&&ue.removeEventListener(_e,we),pe(Ie)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof ue)}return events.exports}var hasRequiredEBMLReader;function requireEBMLReader(){if(hasRequiredEBMLReader)return EBMLReader;hasRequiredEBMLReader=1;var N=EBMLReader&&EBMLReader.__extends||function(){var I=function(D,a){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(O,F){O.__proto__=F}||function(O,F){for(var z in F)Object.prototype.hasOwnProperty.call(F,z)&&(O[z]=F[z])},I(D,a)};return function(D,a){if(typeof a!="function"&&a!==null)throw new TypeError("Class extends value "+String(a)+" is not a constructor or null");I(D,a);function O(){this.constructor=D}D.prototype=a===null?Object.create(a):(O.prototype=a.prototype,new O)}}();Object.defineProperty(EBMLReader,"__esModule",{value:!0});var Z=requireEvents(),q=requireTools(),J=function(I){N(D,I);function D(){var a=I.call(this)||this;return a.logGroup="",a.hasLoggingStarted=!1,a.metadataloaded=!1,a.chunks=[],a.stack=[],a.segmentOffset=0,a.last2SimpleBlockVideoTrackTimecode=[0,0],a.last2SimpleBlockAudioTrackTimecode=[0,0],a.lastClusterTimecode=0,a.lastClusterPosition=0,a.timecodeScale=1e6,a.metadataSize=0,a.metadatas=[],a.cues=[],a.firstVideoBlockRead=!1,a.firstAudioBlockRead=!1,a.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null},a.trackTypes=[],a.trackDefaultDuration=[],a.trackCodecDelay=[],a.trackInfo={type:"nothing"},a.ended=!1,a.logging=!1,a.use_duration_every_simpleblock=!1,a.use_webp=!1,a.use_segment_info=!0,a.drop_default_duration=!0,a}return D.prototype.stop=function(){for(this.ended=!0,this.emit_segment_info();this.stack.length;)this.stack.pop(),this.logging&&console.groupEnd();this.logging&&this.hasLoggingStarted&&this.logGroup&&console.groupEnd()},D.prototype.emit_segment_info=function(){var a=this.chunks;if(this.chunks=[],this.metadataloaded){if(!this.use_segment_info)return;var z=this.lastClusterTimecode,K=this.duration,te=this.timecodeScale;this.emit("cluster",{timecode:z,data:a}),this.emit("duration",{timecodeScale:te,duration:K})}else{this.metadataloaded=!0,this.metadatas=a;var O=this.trackTypes.indexOf(1),F=this.trackTypes.indexOf(2);if(this.trackInfo=O>=0&&F>=0?{type:"both",trackNumber:O}:O>=0?{type:"video",trackNumber:O}:F>=0?{type:"audio",trackNumber:F}:{type:"nothing"},!this.use_segment_info)return;this.emit("metadata",{data:a,metadataSize:this.metadataSize})}},D.prototype.read=function(a){var O=this,F=!1;if(!this.ended){if(a.type==="m")if(a.isEnd)this.stack.pop();else{var z=this.stack[this.stack.length-1];if(z!=null&&z.level>=a.level){this.stack.pop(),this.logging&&console.groupEnd(),z.dataEnd=a.dataEnd,z.dataSize=a.dataEnd-z.dataStart,z.unknownSize=!1;var K=Object.assign({},z,{name:z.name,type:z.type,isEnd:!0});this.chunks.push(K)}this.stack.push(a)}if(a.type==="m"&&a.name=="Segment")this.segmentOffset!=0&&console.warn("Multiple segments detected!"),this.segmentOffset=a.dataStart,this.emit("segment_offset",this.segmentOffset);else if(a.type==="b"&&a.name==="SimpleBlock"){var te=q.ebmlBlock(a.data),ne=te.timecode,ee=te.trackNumber,re=te.frames;if(this.trackTypes[ee]===1){if(!this.firstVideoBlockRead&&(this.firstVideoBlockRead=!0,this.trackInfo.type==="both"||this.trackInfo.type==="video")){var ce=this.lastClusterTimecode+ne;this.cues.push({CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce}),this.emit("cue_info",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce})}this.last2SimpleBlockVideoTrackTimecode=[this.last2SimpleBlockVideoTrackTimecode[1],ne]}else if(this.trackTypes[ee]===2){if(!this.firstAudioBlockRead&&(this.firstAudioBlockRead=!0,this.trackInfo.type==="audio")){var ce=this.lastClusterTimecode+ne;this.cues.push({CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce}),this.emit("cue_info",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce})}this.last2SimpleBlockAudioTrackTimecode=[this.last2SimpleBlockAudioTrackTimecode[1],ne]}this.use_duration_every_simpleblock&&this.emit("duration",{timecodeScale:this.timecodeScale,duration:this.duration}),this.use_webp&&re.forEach(function(oe){var se=oe.slice(3,6).toString("hex");if(se==="9d012a"){var fe=q.VP8BitStreamToRiffWebPBuffer(oe),ge=new Blob([fe],{type:"image/webp"}),ue=O.duration;O.emit("webp",{currentTime:ue,webp:ge})}})}else a.type==="m"&&a.name==="Cluster"&&a.isEnd===!1?(this.firstVideoBlockRead=!1,this.firstAudioBlockRead=!1,this.emit_segment_info(),this.emit("cluster_ptr",a.tagStart),this.lastClusterPosition=a.tagStart):a.type==="u"&&a.name==="Timecode"?this.lastClusterTimecode=a.value:a.type==="u"&&a.name==="TimecodeScale"?this.timecodeScale=a.value:a.type==="m"&&a.name==="TrackEntry"?a.isEnd?(this.trackTypes[this.currentTrack.TrackNumber]=this.currentTrack.TrackType,this.trackDefaultDuration[this.currentTrack.TrackNumber]=this.currentTrack.DefaultDuration,this.trackCodecDelay[this.currentTrack.TrackNumber]=this.currentTrack.CodecDelay):this.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null}:a.type==="u"&&a.name==="TrackType"?this.currentTrack.TrackType=a.value:a.type==="u"&&a.name==="TrackNumber"?this.currentTrack.TrackNumber=a.value:a.type==="u"&&a.name==="CodecDelay"?this.currentTrack.CodecDelay=a.value:a.type==="u"&&a.name==="DefaultDuration"?this.drop_default_duration?(console.warn("DefaultDuration detected!, remove it"),F=!0):this.currentTrack.DefaultDuration=a.value:a.name==="unknown"&&console.warn(a);!this.metadataloaded&&a.dataEnd>0&&(this.metadataSize=a.dataEnd),F||this.chunks.push(a),this.logging&&this.put(a)}},Object.defineProperty(D.prototype,"duration",{get:function(){if(this.trackInfo.type==="nothing")return console.warn("no video, no audio track"),0;var a=0,O=0,F=0,z=this.trackDefaultDuration[this.trackInfo.trackNumber];if(typeof z=="number")a=z;else if(this.trackInfo.type==="both")if(this.last2SimpleBlockAudioTrackTimecode[1]>this.last2SimpleBlockVideoTrackTimecode[1]){a=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackTypes.indexOf(2)];typeof K=="number"&&(O=K),F=this.last2SimpleBlockAudioTrackTimecode[1]}else{a=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackTypes.indexOf(1)];typeof K=="number"&&(O=K),F=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="video"){a=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackInfo.trackNumber];typeof K=="number"&&(O=K),F=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="audio"){a=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackInfo.trackNumber];typeof K=="number"&&(O=K),F=this.last2SimpleBlockAudioTrackTimecode[1]}var te=(this.lastClusterTimecode+F)*this.timecodeScale+a-O,ne=te/this.timecodeScale;return Math.floor(ne)},enumerable:!1,configurable:!0}),D.prototype.addListener=function(a,O){return I.prototype.addListener.call(this,a,O)},D.prototype.put=function(a){this.hasLoggingStarted||(this.hasLoggingStarted=!0,this.logging&&this.logGroup&&console.groupCollapsed(this.logGroup)),a.type==="m"?a.isEnd?console.groupEnd():console.group(a.name+":"+a.tagStart):a.type==="b"?console.log(a.name,a.type):console.log(a.name,a.tagStart,a.type,a.value)},D}(Z.EventEmitter);return EBMLReader.default=J,EBMLReader}var hasRequiredEbml;function requireEbml(){return hasRequiredEbml||(hasRequiredEbml=1,function(N){var Z=ebml&&ebml.__createBinding||(Object.create?function(O,F,z,K){K===void 0&&(K=z),Object.defineProperty(O,K,{enumerable:!0,get:function(){return F[z]}})}:function(O,F,z,K){K===void 0&&(K=z),O[K]=F[z]}),q=ebml&&ebml.__exportStar||function(O,F){for(var z in O)z!=="default"&&!Object.prototype.hasOwnProperty.call(F,z)&&Z(F,O,z)};Object.defineProperty(N,"__esModule",{value:!0}),N.tools=N.Reader=N.Encoder=N.Decoder=void 0,q(requireEBML(),N);var J=requireEBMLDecoder();N.Decoder=J.default;var I=requireEBMLEncoder();N.Encoder=I.default;var D=requireEBMLReader();N.Reader=D.default;var a=requireTools();N.tools=a}(ebml)),ebml}var hasRequiredLib;function requireLib(){if(hasRequiredLib)return lib;hasRequiredLib=1;var N=lib&&lib.__awaiter||function(I,D,a,O){function F(z){return z instanceof a?z:new a(function(K){K(z)})}return new(a||(a=Promise))(function(z,K){function te(re){try{ee(O.next(re))}catch(ce){K(ce)}}function ne(re){try{ee(O.throw(re))}catch(ce){K(ce)}}function ee(re){re.done?z(re.value):F(re.value).then(te,ne)}ee((O=O.apply(I,D||[])).next())})},Z=lib&&lib.__generator||function(I,D){var a={label:0,sent:function(){if(z[0]&1)throw z[1];return z[1]},trys:[],ops:[]},O,F,z,K;return K={next:te(0),throw:te(1),return:te(2)},typeof Symbol=="function"&&(K[Symbol.iterator]=function(){return this}),K;function te(ee){return function(re){return ne([ee,re])}}function ne(ee){if(O)throw new TypeError("Generator is already executing.");for(;a;)try{if(O=1,F&&(z=ee[0]&2?F.return:ee[0]?F.throw||((z=F.return)&&z.call(F),0):F.next)&&!(z=z.call(F,ee[1])).done)return z;switch(F=0,z&&(ee=[ee[0]&2,z.value]),ee[0]){case 0:case 1:z=ee;break;case 4:return a.label++,{value:ee[1],done:!1};case 5:a.label++,F=ee[1],ee=[0];continue;case 7:ee=a.ops.pop(),a.trys.pop();continue;default:if(z=a.trys,!(z=z.length>0&&z[z.length-1])&&(ee[0]===6||ee[0]===2)){a=0;continue}if(ee[0]===3&&(!z||ee[1]>z[0]&&ee[1]<z[3])){a.label=ee[1];break}if(ee[0]===6&&a.label<z[1]){a.label=z[1],z=ee;break}if(z&&a.label<z[2]){a.label=z[2],a.ops.push(ee);break}z[2]&&a.ops.pop(),a.trys.pop();continue}ee=D.call(I,a)}catch(re){ee=[6,re],F=0}finally{O=z=0}if(ee[0]&5)throw ee[1];return{value:ee[0]?ee[1]:void 0,done:!0}}};Object.defineProperty(lib,"__esModule",{value:!0});var q=requireEbml();function J(I){return N(this,void 0,void 0,function(){var D,a,O,F,z,K,te,ne,ee,re,ce,oe;return Z(this,function(se){switch(se.label){case 0:if(!I)throw Error("call to fixWebmDuration requires a blob");D=new q.Decoder,a=new q.Reader,O=I.stream(),F=O.getReader(),se.label=1;case 1:return[4,F.read()];case 2:return z=se.sent(),K=z.done,te=z.value,K?(a.stop(),[3,3]):(ne=D.decode(te),ne=ne==null?void 0:ne.filter(function(fe){return fe.type!=="unknown"}),ne.forEach(function(fe){a.read(fe)}),te=null,[3,1]);case 3:return ee=q.tools.makeMetadataSeekable(a.metadatas,a.duration,a.cues),re=new Blob([ee],{type:I.type}),ce=I.slice(a.metadataSize),oe=new Blob([re,ce],{type:I.type}),[2,oe]}})})}return lib.default=J,lib}var libExports=requireLib();const fixWebmDuration=getDefaultExportFromCjs(libExports);class StreamRecorder{constructor(){at(this,Xt);at(this,mn,!1);at(this,hn,!1);at(this,In,0);at(this,xn,0);at(this,sn,0);at(this,ln,0);at(this,yn,0);Ee(this,"onchange",Z=>{});Ee(this,"onDurationChange",Z=>{});Ee(this,"start",async(Z="")=>{Z||(Z=`video_Record_${E$1(Date.now())}`);let q=[];return navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}).then(J=>{const I=J.getTracks();for(const a of I)a.onended=()=>this.stop();Ct(this,mn,!0),Ct(this,hn,!1),Ct(this,Xt,new MediaRecorder(J)),De(this,Xt).start();const D=new Date().getTime();Ct(this,In,D),Ct(this,sn,D),De(this,vn).call(this),De(this,Rn).call(this),De(this,Xt).addEventListener("dataavailable",a=>{q.push(a.data)}),De(this,Xt).addEventListener("stop",async()=>{Ct(this,mn,!1);const a=new Date().getTime();Ct(this,xn,a),Ct(this,ln,De(this,ln)+(a-De(this,sn))),De(this,vn).call(this),clearInterval(De(this,yn));const O=J.getTracks();for(const ne of O)ne.stop();if(De(this,Xt)===null)return;const F=new Blob(q,{type:De(this,Xt).mimeType}),z=await fixWebmDuration(F),K=URL.createObjectURL(z),te=document.createElement("a");te.href=K,te.download=`${Z}.mp4`,te.click(),URL.revokeObjectURL(K),q=[],Ct(this,Xt,null)})})});Ee(this,"pause",async()=>{var q;await new Promise(J=>setTimeout(()=>J(!0),300)),(q=De(this,Xt))==null||q.pause(),Ct(this,hn,!0);const Z=new Date().getTime();Ct(this,ln,De(this,ln)+(Z-De(this,sn))),De(this,vn).call(this),clearInterval(De(this,yn))});Ee(this,"resume",async()=>{var q;(q=De(this,Xt))==null||q.resume(),Ct(this,hn,!1);const Z=new Date().getTime();Ct(this,sn,Z),De(this,vn).call(this),De(this,Rn).call(this)});Ee(this,"stop",async()=>{var Z;(Z=De(this,Xt))==null||Z.stop()});Ee(this,"getDuration",()=>{if(De(this,sn)===0)return 0;let Z=De(this,ln);const q=new Date().getTime();if(De(this,mn)&&De(this,hn)===!1){const J=q-De(this,sn);Ct(this,sn,q),Z=Z+J}return Z});Ee(this,"getInfo",()=>({active:De(this,mn),pause:De(this,hn),startTime:De(this,In),endTime:De(this,xn),duration:De(this,ln)}));at(this,vn,()=>{const Z=this.getInfo();this.onchange(Z)});at(this,Rn,()=>{clearInterval(De(this,yn)),Ct(this,yn,window.setInterval(()=>{Ct(this,ln,this.getDuration()),this.onDurationChange(De(this,ln))},500))})}}Xt=new WeakMap,mn=new WeakMap,hn=new WeakMap,In=new WeakMap,xn=new WeakMap,sn=new WeakMap,ln=new WeakMap,yn=new WeakMap,vn=new WeakMap,Rn=new WeakMap;class RoomBase{constructor(Z){Ee(this,"options",{appid:"",sdkToken:"",roomId:"",userId:"",earlyId:"",callType:0,debug:!1,reportErr:!0,logUrl:"https://logs1.quickvo.org",newPublishAutoSubscribe:!0});Ee(this,"sdk_service_version","1.0.6");Ee(this,"prohibitNotify",!1);Ee(this,"isEarly",!1);Ee(this,"isInRoom",!1);Ee(this,"taskQueue");Ee(this,"roomState","ready");Ee(this,"createAt",Date.now());Ee(this,"cwsIns");Ee(this,"peerIns");Ee(this,"transceiverMap",new Map);Ee(this,"sendChannel");Ee(this,"receiveChannel");Ee(this,"userMap",new Map);Ee(this,"setLocalStreamActiveMap",new Map);Ee(this,"phoneyStreams",new Map);Ee(this,"recorder",new StreamRecorder);Ee(this,"networkQualityTester",new NetworkQualityTester);Ee(this,"mediaDevicesErrInfo",{microphoneCamera_audio:"",microphoneCamera_video:"",screenSharing_video:"",screenSharing_audio:""});Ee(this,"reportLogs",(Z,q="未知错误")=>{const{appid:J,userId:I,earlyId:D="",logUrl:a,reportErr:O}=this.options;if(!O)return;const F="web",z=K=>({ws_c_timeout:0,webrtc_c_timeout:1,join_room_error:2,publish_error:3,subscribe_error:4,close_track_error:5,heartbeat_e_timeout:6,heartbeat_i_timeout:7,quit_room_error:8})[K].toString();{const K=z(Z),te={origin:F,type:K,app_id:J,user_id:I,ins_id:D,desc:q},ne=btoa(encodeURI(JSON.stringify(te))),ee=`${a}/upload/log?log_key=${ne}`;{const re=localStorage.getItem("#quickvo.logs")||JSON.stringify([]),oe=new TextEncoder().encode(re),se=pako.deflate(oe,{gzip:!0});this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: reportLogs",{obj:te,url:ee,size:lt(se.byteLength)}),fetch(ee,{headers:{"Content-Type":"multipart/form-data"},method:"POST",body:se})}}});Ee(this,"initPhoneyStreams",(Z,q=[])=>{q.length===0&&(q=mediaType_keys);for(const J of q){const I=this.phoneyStreams.get(J);if(I){const D=I.getTracks();for(const a of D)a.stop()}switch(J){case"microphoneCamera_audio":this.phoneyStreams.set("microphoneCamera_audio",createMutedAudioStream(Z));break;case"microphoneCamera_video":this.phoneyStreams.set("microphoneCamera_video",createFakeVideoStream());break;case"screenSharing_audio":this.phoneyStreams.set("screenSharing_audio",createMutedAudioStream(Z));break;case"screenSharing_video":this.phoneyStreams.set("screenSharing_video",createFakeVideoStream());break}}});Ee(this,"getPhoneyStreams",Z=>this.phoneyStreams.get(Z));Ee(this,"getRoomInfo",()=>{const{options:Z,roomState:q,createAt:J}=this;return{...Z,roomState:q,createAt:J}});Ee(this,"setRoomState",Z=>{this.roomState=Z;const q=enum_roomState[Z],J={state:Z,stateStr:q};this.cwsIns.emitNotify("onRoomState",{code:200,data:J,desc:"room state is change."})});Ee(this,"setOptions",async Z=>{const q={...this.options,...Z};this.options=q});Ee(this,"stopStream",async Z=>{const q=Z.getTracks();for(const J of q)J.stop()});Ee(this,"getMediaDevicesErrInfo",async()=>{try{const Z=await navigator.mediaDevices.enumerateDevices();Z.find(J=>J.kind==="audioinput")||(this.mediaDevicesErrInfo.microphoneCamera_audio="audioinput is not available."),Z.find(J=>J.kind==="videoinput")||(this.mediaDevicesErrInfo.microphoneCamera_video="videoinput is not available.")}catch(Z){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getMediaDevicesErrInfo is error.",Z)}return this.mediaDevicesErrInfo});Ee(this,"getUserMediaKey",(Z,q)=>`${Z}-${q}`);Ee(this,"getCallAction",async Z=>{let q="";const J=D=>Z.findIndex(({type:O,enabled:F=!0})=>O===D&&F)===-1?"0":"1";return q=`${J(0)}${q}`,q=`${J(1)}${q}`,q=`${J(2)}${q}`,q=`${J(3)}${q}`,parseInt(q,2)});Ee(this,"getCallActionMap",(Z=0)=>{const J=Number(Z).toString(2).padStart(4,"0").split(""),[I,D,a,O]=J;return{microphoneCamera_audio:!!Number(O),microphoneCamera_video:!!Number(a),screenSharing_video:!!Number(D),screenSharing_audio:!!Number(I)}});Ee(this,"getBanBehaviorMap",(Z=0)=>{const J=Number(Z).toString(2).padStart(4,"0").split(""),[I,D,a,O]=J;return{microphoneCamera_audio:!!Number(O),microphoneCamera_video:!!Number(a),screenSharing_video:!!Number(D),screenSharing_audio:!!Number(I)}});Ee(this,"getAverageVolume",(Z,q)=>{Z.getByteFrequencyData(q);let J=0;for(let D=0;D<q.length;D++)J+=q[D];return Math.ceil(J/q.length)});Ee(this,"getTrackNamesFormTracks",(Z,q=[],J="trackName")=>{const I=[];for(const D of Z){const{type:a}=D;if(q.length===0||q.includes(a)){const O=D[J];O&&I.push(`${O}`)}}return I});Ee(this,"usersFilter",Z=>dt(Z,["id","isSelf","isOwner","joinTime","tracks","network","permissions","isPublished","updateStreams","callAction","callActionStr","callActionMap","banBehavior","banBehaviorStr","banBehaviorMap"]).sort((I,D)=>I.id.localeCompare(D.id,"en")));this.setOptions(Z),this.cwsIns=new CallsWebSocket({...Z}),this.taskQueue=new Y(["createWs","createSession","ice","joinRoom","createTrack","publish","subscribe","renegotiate","closeTrack"],{debug:Z.debug}),this.taskQueue.setCondition("createSession",!1),this.taskQueue.setCondition("ice",!1),this.options.debug&&this.networkQualityTester.testAll().then(q=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: networkQualityTester",q)})}}var m=Object.defineProperty,G=(N,Z,q)=>Z in N?m(N,Z,{enumerable:!0,configurable:!0,writable:!0,value:q}):N[Z]=q,e$1=(N,Z,q)=>G(N,typeof Z!="symbol"?Z+"":Z,q);class g{constructor(Z,q){e$1(this,"inputStream",new MediaStream),e$1(this,"outputStream",new MediaStream),e$1(this,"inputGain",1),e$1(this,"enhanceGain",1),e$1(this,"bgsGain",1),e$1(this,"bgmGain",1),e$1(this,"outputGain",1),e$1(this,"mixAudioMap",new Map),e$1(this,"audioContext",new AudioContext),e$1(this,"sourceNode"),e$1(this,"inputGainNode"),e$1(this,"enhanceGainNode"),e$1(this,"bgsGainNode"),e$1(this,"bgmGainNode"),e$1(this,"analyserNode"),e$1(this,"analyserArrayData"),e$1(this,"outputGainNode"),e$1(this,"destinationNode"),e$1(this,"filterStream",J=>J),e$1(this,"stop",()=>{{const J=this.inputStream.getTracks();for(const I of J)I.stop(),this.inputStream.removeTrack(I)}}),e$1(this,"getStream",()=>this.filterStream(this.outputStream)),e$1(this,"setMute",(J=!0)=>{J?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),e$1(this,"setInputGain",J=>{this.inputGain=J,this.inputGainNode.gain.setValueAtTime(J,this.audioContext.currentTime)}),e$1(this,"setEnhanceGain",async J=>{this.enhanceGain=J+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),e$1(this,"setBgsGain",J=>{this.bgsGain=J,this.bgsGainNode.gain.setValueAtTime(J,this.audioContext.currentTime)}),e$1(this,"setBgmGain",J=>{this.bgmGain=J,this.bgmGainNode.gain.setValueAtTime(J,this.audioContext.currentTime)}),e$1(this,"setOutputGain",J=>{this.outputGain=J,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),e$1(this,"getVolume",()=>{const{analyserNode:J,analyserArrayData:I}=this;J.getByteFrequencyData(I);let D=0;for(let a=0;a<I.length;a++)D+=I[a];return Math.ceil(D/I.length)}),e$1(this,"mixAudio",(J,I="bgm")=>new Promise(async(D,a)=>{try{{const z=this.mixAudioMap.get(I);z&&z.stop()}const O=I==="bgs"?this.bgsGainNode:this.bgmGainNode,F=this.audioContext.createBufferSource();this.mixAudioMap.set(I,F),F.buffer=J,F.connect(O),F.onended=()=>{F.disconnect(O),this.mixAudioMap.delete(I),D(!0)},F.start(0)}catch(O){a(O)}})),e$1(this,"mixAudioStop",J=>{const I=this.mixAudioMap.get(J);I==null||I.stop()}),e$1(this,"changeMix",(J,I)=>{const D=J==="bgs"?this.bgsGainNode:this.bgmGainNode;I?D.connect(this.destinationNode):D.disconnect(this.destinationNode)}),q&&(this.audioContext=q),this.inputStream=Z,this.sourceNode=this.audioContext.createMediaStreamSource(this.inputStream),this.inputGainNode=this.audioContext.createGain(),this.inputGainNode.gain.setValueAtTime(this.inputGain,this.audioContext.currentTime),this.enhanceGainNode=this.audioContext.createGain(),this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime),this.bgsGainNode=this.audioContext.createGain(),this.bgsGainNode.gain.setValueAtTime(this.bgsGain,this.audioContext.currentTime),this.bgmGainNode=this.audioContext.createGain(),this.bgmGainNode.gain.setValueAtTime(this.bgmGain,this.audioContext.currentTime),this.analyserNode=this.audioContext.createAnalyser(),this.analyserNode.fftSize=512,this.analyserArrayData=new Uint8Array(this.analyserNode.frequencyBinCount),this.outputGainNode=this.audioContext.createGain(),this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime),this.destinationNode=this.audioContext.createMediaStreamDestination(),this.outputStream=this.destinationNode.stream;{const{sourceNode:J,inputGainNode:I,enhanceGainNode:D,bgsGainNode:a,bgmGainNode:O,analyserNode:F,outputGainNode:z,destinationNode:K}=this;J.connect(I),I.connect(D),D.connect(F),a.connect(F),O.connect(F),D.connect(K),a.connect(K),O.connect(K),F.connect(z),z.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}class RoomMedias extends RoomBase{constructor(q){super(q);at(this,wn,[]);at(this,en,new Map);at(this,Ht,new Map);at(this,cn,new Map);at(this,un,new Map);at(this,pn,new Map);Ee(this,"localStreamsActionMap",new Map);at(this,kn,new Map);Ee(this,"audioContext",new(window.AudioContext||window.webkitAudioContext));Ee(this,"initMediaPhoneyStreams",(q=[])=>this.initPhoneyStreams(this.audioContext,q));Ee(this,"initLocalStreamsFilter",()=>{for(const q of mediaType_keys){const J=async I=>I;De(this,kn).set(q,J)}});Ee(this,"setLocalFilterStream",(q,J)=>{De(this,kn).set(q,J)});at(this,Un,()=>{De(this,Ht).set("microphoneCamera_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0}),De(this,Ht).set("microphoneCamera_video",{frameRate:{min:10,ideal:30}}),De(this,Ht).set("screenSharing_video",{frameRate:{min:10,ideal:30}}),De(this,Ht).set("screenSharing_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0})});at(this,Ln,()=>{De(this,en).set("audioinput","default"),De(this,en).set("videoinput","default"),De(this,en).set("audiooutput","default")});Ee(this,"emitNotifyUpdateUsersStreams",async q=>{this.cwsIns.emitNotify("onRoomUsersStreams",{code:200,data:q,desc:"users streams is change."})});Ee(this,"initUserMediaStreamContext",async(q,J,I)=>{const[D]=I.getTracks();if(!D){console.warn("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: tracks.length is 0.",{userId:q,mediaType:J,stream:I});return}this.removeUserMediaStreamContext(q,J);const a=this.getUserMediaKey(q,J),{kind:O}=D;switch(O){case"audio":{const F=new MediaStream;F.addTrack(D);const z=new g(F,this.audioContext);De(this,cn).set(a,z)}break;case"video":{const F=new VideoMediaContext(D);De(this,un).set(a,F)}break}});Ee(this,"getUserMediaStreamContext",(q,J)=>{const I=this.getUserMediaKey(q,J);if(["microphoneCamera_audio","screenSharing_audio"].includes(J))return De(this,cn).get(I);if(["microphoneCamera_video","screenSharing_video"].includes(J))return De(this,un).get(I)});Ee(this,"getUserAudioMediaStreamContext",(q,J)=>{const I=this.getUserMediaKey(q,J);return De(this,cn).get(I)});Ee(this,"removeUserMediaStreamContext",(q,J)=>{const I=this.getUserMediaKey(q,J);if(["microphoneCamera_audio","screenSharing_audio"].includes(J)){const D=De(this,cn).get(I);return D==null||D.stop(),De(this,cn).delete(I)}if(["microphoneCamera_video","screenSharing_video"].includes(J)){const D=De(this,un).get(I);return D==null||D.stop(),De(this,un).get(I)}});Ee(this,"getUserStream",(q,J)=>{const I=this.getUserMediaStreamContext(q,J);return(I==null?void 0:I.getStream())||new MediaStream});Ee(this,"getUserStreams",(q,J=[])=>{J.length===0&&(J=mediaType_keys);const I={};for(const D of J){const a=this.getUserStream(q,D);I[D]=a}return I});Ee(this,"removeUserStreams",async(q,J=[])=>{J.length===0&&(J=mediaType_keys);for(const I of J)this.removeUserMediaStreamContext(q,I)});Ee(this,"clearUserStreams",()=>{{const q=De(this,cn).values();for(const J of q)J.stop();Ct(this,cn,new Map)}{const q=De(this,un).values();for(const J of q)J.stop();Ct(this,un,new Map)}});Ee(this,"setMediaTrackConstraints",async(q,J)=>{De(this,Ht).set(q,J);const I=await this.getLocalStream(q);if(!I)return;const D=I.getTracks();if(D.length!==0)for(const a of D){const O=a.getConstraints(),z={...De(this,Ht).get(q),...O,...J};await a.applyConstraints(z)}});Ee(this,"stopLocalStreams",async(q=[])=>{q.length===0&&(q=mediaType_keys);for(const J of q){const I=De(this,pn).get(J);I&&await this.stopStream(I),De(this,pn).delete(J)}});Ee(this,"addLocalStream",(q,J)=>{const I=De(this,pn).get(q);I&&this.stopStream(I),De(this,pn).set(q,J)});Ee(this,"initLocalStream",async q=>{switch(q){case"microphoneCamera_audio":{const J=De(this,en).get("audioinput"),I=De(this,Ht).get("microphoneCamera_audio"),D=await navigator.mediaDevices.getUserMedia({audio:{deviceId:J,...I},video:!1});this.addLocalStream("microphoneCamera_audio",D)}break;case"microphoneCamera_video":{const J=De(this,en).get("videoinput"),I=De(this,Ht).get("microphoneCamera_video"),D=await navigator.mediaDevices.getUserMedia({audio:!1,video:{deviceId:J,...I}});this.addLocalStream("microphoneCamera_video",D)}break;case"microphoneCamera":{const J=De(this,en).get("audioinput"),I=De(this,en).get("videoinput"),D=De(this,Ht).get("microphoneCamera_audio"),a=De(this,Ht).get("microphoneCamera_video"),F=(await navigator.mediaDevices.getUserMedia({audio:{deviceId:J,...D},video:{deviceId:I,...a}})).getTracks();for(const z of F){const{kind:K}=z;if(K==="audio"){const te=new MediaStream;te.addTrack(z),this.addLocalStream("microphoneCamera_audio",te)}if(K==="video"){const te=new MediaStream;te.addTrack(z),this.addLocalStream("microphoneCamera_video",te)}}}break;case"screenSharing_audio":{const J=De(this,Ht).get("screenSharing_audio"),D=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...J})).getTracks();for(const a of D){const{kind:O}=a;if(O==="audio"){const F=new MediaStream;F.addTrack(a),this.addLocalStream("screenSharing_audio",F)}}}break;case"screenSharing_video":{const J=De(this,Ht).get(q),D=(await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0,...J})).getTracks();for(const a of D){const{kind:O}=a;if(O==="video"){const F=new MediaStream;F.addTrack(a),this.addLocalStream("screenSharing_video",F)}}}break;case"screenSharing":{const J=De(this,Ht).get("screenSharing_audio"),I=De(this,Ht).get("screenSharing_video"),a=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...J,...I})).getTracks();for(const O of a){const{kind:F}=O;if(F==="audio"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_audio",z)}if(F==="video"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_video",z)}}}break}});Ee(this,"getLocalStream",async q=>{const J=De(this,pn).get(q),I=De(this,kn).get(q);let D=J;return J&&I&&(D=await I(J)),D});Ee(this,"getLocalStreams",async(q=[])=>{q.length===0&&(q=mediaType_keys);const J={};for(const I of q)J[I]=await this.getLocalStream(I);return J});at(this,Sn,async()=>!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices?(console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 不支持 enumerateDevices"),[]):(await navigator.mediaDevices.enumerateDevices().then(q=>{const J=q.filter(I=>!["default","communications"].includes(I.deviceId));Ct(this,wn,J.sort((I,D)=>I.label.localeCompare(D.label,"zh-Hans-CN",{sensitivity:"accent"})))}).catch(function(q){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getEnumerateDevices is err",q)}),De(this,wn)));at(this,Fn,()=>{navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=async()=>{await De(this,Sn).call(this),this.cwsIns.emitNotify("onDevicechange",{code:200,data:{},desc:"device is change."})}),De(this,Sn).call(this)});Ee(this,"getMediaDeviceKind",q=>De(this,en).get(q));Ee(this,"changeAudiooutput",async()=>{try{const q=De(this,en).get("audiooutput");await this.audioContext.setSinkId(q)}catch(q){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSinkId is error.",q)}});Ee(this,"setDeviceKind",(q,J)=>{De(this,en).set(q,J)});Ee(this,"setAudioOutputDevice",q=>this.setDeviceKind("audiooutput",q));Ee(this,"getEnumerateDevices",async q=>(await De(this,Sn).call(this),De(this,wn).filter(I=>I.kind===q)));Ee(this,"getEnumerateAudioinputDevices",()=>this.getEnumerateDevices("audioinput"));Ee(this,"getEnumerateAudioOutputDevices",()=>this.getEnumerateDevices("audiooutput"));Ee(this,"getEnumerateVideoinputDevices",()=>this.getEnumerateDevices("videoinput"));De(this,Fn).call(this),De(this,Ln).call(this),De(this,Un).call(this),this.initPhoneyStreams(this.audioContext),document.addEventListener("click",()=>{var J;((J=this.audioContext)==null?void 0:J.state)==="suspended"&&this.audioContext.resume()})}}wn=new WeakMap,en=new WeakMap,Ht=new WeakMap,cn=new WeakMap,un=new WeakMap,pn=new WeakMap,kn=new WeakMap,Un=new WeakMap,Ln=new WeakMap,Sn=new WeakMap,Fn=new WeakMap;class RoomUsers extends RoomMedias{constructor(q){super(q);Ee(this,"getMaxVolumeUser",()=>{const q=Array.from(this.userMap.values(),({id:I})=>I);if(q.length===0)return;let J=[];for(const I of q){const D=this.getUserAudioMediaStreamContext(I,"microphoneCamera_audio");if(!D)continue;const a=D.getVolume();J.push({id:I,volume:a})}return J=J.sort((I,D)=>I.volume-D.volume>0?-1:1),J[0]});Ee(this,"setVolume",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setInputGain(I)});Ee(this,"setEnhanceGain",async(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setEnhanceGain(I)});Ee(this,"setSpeaker",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setOutputGain(I);const a=I===0;D==null||D.setMute(a)});Ee(this,"playBgs",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);return D==null?void 0:D.mixAudio(I,"bgs")});Ee(this,"setBgsGain",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setBgsGain(I)});Ee(this,"stopBgs",(q,J)=>{const I=this.getUserAudioMediaStreamContext(q,J);I==null||I.mixAudioStop("bgs")});Ee(this,"playBgm",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);return D==null?void 0:D.mixAudio(I,"bgm")});Ee(this,"setBgmGain",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setBgmGain(I)});Ee(this,"stopBgm",(q,J)=>{const I=this.getUserAudioMediaStreamContext(q,J);I==null||I.mixAudioStop("bgm")});Ee(this,"changBgsMix",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.changeMix("bgs",I)});Ee(this,"changBgmMix",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.changeMix("bgm",I)});Ee(this,"getVolume",(q,J)=>{const I=this.getUserAudioMediaStreamContext(q,J);return I==null?void 0:I.getVolume()});Ee(this,"clearUsers",()=>{this.userMap=new Map});Ee(this,"removeUsers",async q=>{for(const J of q)this.userMap.delete(J),await this.removeUserStreams(J)});Ee(this,"createUser",async q=>{const J=Date.now(),I={id:q,permissions:0,callAction:0,callActionStr:"",callActionMap:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1},banBehavior:0,banBehaviorStr:"",banBehaviorMap:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1},callState:0,isOwner:this.userMap.size===0,isSelf:q===this.options.userId,isPublished:!1,joinTime:J,updateAt:J,network:{egress:0,ingress:0},tracks:[],channels:[],updateStreams:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1}};this.userMap.set(q,I)});Ee(this,"getUser",async q=>(this.userMap.has(q)||await this.createUser(q),this.userMap.get(q)));Ee(this,"getUsers",async(q=[])=>{q.length===0&&(q=[...this.userMap.keys()]);const J=[];for(const I of q){const D=await this.getUser(I);J.push(D)}return J});Ee(this,"getAllUserTrackMids",async()=>{const q=await this.getUsers(),J=[];for(const I of q){const{tracks:D=[]}=I;for(const a of D)J.push(a.mid)}return J});Ee(this,"getUserTrackByTrackName",async q=>{const J=await this.getUsers(),I=[];for(const D of J){const{tracks:a=[]}=D;for(const O of a){const{trackName:F}=O;q.includes(F)&&I.push(O)}}return I});Ee(this,"getUserTrackFromMid",async q=>{const J=await this.getUsers();let I;for(const D of J){const{tracks:a=[]}=D;for(const O of a)if(O.mid===q){I=O;break}}return I});Ee(this,"checkUserInRoom",q=>this.userMap.has(q));Ee(this,"getUsersId",async()=>[...this.userMap.keys()]);Ee(this,"getSelfInfo",async()=>await this.getUser(this.options.userId));Ee(this,"updateIsPublished",async(q,J=!1)=>{const I=await this.getUser(q);I.isPublished=J});Ee(this,"setUserUpdateStreams",async(q,J,I=!0)=>{const D=await this.getUser(q),a={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};a[J]=I,D.updateStreams=a});Ee(this,"updateUserChannels",async(q,J=[],I)=>{const D=await this.getUser(q);I&&(J=[...D.channels,...J]),D.channels=J});Ee(this,"updateUsertracks",async(q,J=[],I)=>{const D=await this.getUser(q);I&&(J=[...D.tracks,...J]),J=J.filter(({mid:F=""})=>F!==""),J=pt(J,["type"]),J=J.sort((F,z)=>F.type-z.type<0?-1:1);for(const F of J)F.userId=q,F.mediaType=mediaType_keys[F.type],F.enabled===void 0&&(F.enabled=!0);D.updateStreams={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};const a=dt(D.tracks,["mediaType","enabled","mid","msid","trackName"]),O=dt(J,["mediaType","enabled","mid","msid","trackName"]);{const F="microphoneCamera_audio",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}{const F="microphoneCamera_video",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}{const F="screenSharing_audio",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}{const F="screenSharing_video",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}D.tracks=J});Ee(this,"updateUserCallAction",async(q,J=0)=>{const I=await this.getUser(q);I.callAction=J,I.callActionStr=J.toString(2).padStart(4,"0"),I.callActionMap=this.getCallActionMap(J)});Ee(this,"updateUserBehaviors",async(q,J=0)=>{const I=await this.getUser(q);I.banBehavior=J,I.banBehaviorStr=J.toString(2).padStart(4,"0"),I.banBehaviorMap=this.getBanBehaviorMap(J)});Ee(this,"updateUserNetwork",async(q,J={egress:5,ingress:5})=>{const I=await this.getUser(q);I.network=J});Ee(this,"updateUserPermissions",async(q,J)=>{if(J){const I=await this.getUser(q);I.permissions=J}});Ee(this,"updateUserBase",async q=>{const J=await this.getUser(q);J.isSelf=q===this.options.userId,J.updateAt=Date.now()});Ee(this,"updateUsers",async q=>{for(const J of q){const{id:I,tracks:D,callAction:a,permissions:O,isPublished:F}=J;await this.updateUserBase(I),await this.updateIsPublished(I,F),await this.updateUserPermissions(I,O),await this.updateUsertracks(I,D,!0),await this.updateUserCallAction(I,a),await this.updateUserNetwork(I)}});Ee(this,"emitNotifyUpdateUser",async q=>{const J=await this.getUsers([q]),[I]=this.usersFilter(J);this.cwsIns.emitNotify("onRoomUser",{code:200,data:I,desc:"user info is change."})});Ee(this,"emitNotifyUpdateUsers",async()=>{const q=await this.getUsers(),J=this.usersFilter(q);this.cwsIns.emitNotify("onRoomUsers",{code:200,data:J,desc:"all users info is change."})})}}const t=(N,Z=4294967295,q=79764919)=>{const J=new Int32Array(256);let I,D,a,O=Z;for(I=0;I<256;I++){for(a=I<<24,D=8;D>0;--D)a=2147483648&a?a<<1^q:a<<1;J[I]=a}for(I=0;I<N.length;I++)O=O<<8^J[255&(O>>24^N[I])];return O},e=(N,Z=t)=>{const q=oe=>new Uint8Array(oe.length/2).map((se,fe)=>parseInt(oe.substring(2*fe,2*(fe+1)),16)),J=oe=>q(oe)[0],I=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach((oe,se)=>I.set(oe,se));const D=new Uint8Array(N.length);let a,O,F,z=!1,K=0,te=42,ne=N.length>13&&N.substring(0,9)==="dynEncode",ee=0;ne&&(ee=11,O=J(N.substring(9,ee)),O<=1&&(ee+=2,te=J(N.substring(11,ee))),O===1&&(ee+=8,F=(oe=>new DataView(q(oe).buffer).getInt32(0,!0))(N.substring(13,ee))));const re=256-te;for(let oe=ee;oe<N.length;oe++)if(a=N.charCodeAt(oe),a!==61||z){if(a===92&&oe<N.length-5&&ne){const se=N.charCodeAt(oe+1);se!==117&&se!==85||(a=parseInt(N.substring(oe+2,oe+6),16),oe+=5)}if(a>255){const se=I.get(a);se&&(a=se+127)}z&&(z=!1,a-=64),D[K++]=a<te&&a>0?a+re:a-te}else z=!0;const ce=D.subarray(0,K);if(ne&&O===1){const oe=Z(ce);if(oe!==F){const se="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",se+`
13
+ */var hasRequiredBuffer;function requireBuffer(){return hasRequiredBuffer||(hasRequiredBuffer=1,function(N){const Z=requireBase64Js(),q=requireIeee754(),J=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;N.Buffer=O,N.SlowBuffer=fe,N.INSPECT_MAX_BYTES=50;const I=2147483647;N.kMaxLength=I,O.TYPED_ARRAY_SUPPORT=D(),!O.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function D(){try{const ae=new Uint8Array(1),Q={foo:function(){return 42}};return Object.setPrototypeOf(Q,Uint8Array.prototype),Object.setPrototypeOf(ae,Q),ae.foo()===42}catch{return!1}}Object.defineProperty(O.prototype,"parent",{enumerable:!0,get:function(){if(O.isBuffer(this))return this.buffer}}),Object.defineProperty(O.prototype,"offset",{enumerable:!0,get:function(){if(O.isBuffer(this))return this.byteOffset}});function a(ae){if(ae>I)throw new RangeError('The value "'+ae+'" is invalid for option "size"');const Q=new Uint8Array(ae);return Object.setPrototypeOf(Q,O.prototype),Q}function O(ae,Q,X){if(typeof ae=="number"){if(typeof Q=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return te(ae)}return F(ae,Q,X)}O.poolSize=8192;function F(ae,Q,X){if(typeof ae=="string")return ne(ae,Q);if(ArrayBuffer.isView(ae))return re(ae);if(ae==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ae);if(Wt(ae,ArrayBuffer)||ae&&Wt(ae.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Wt(ae,SharedArrayBuffer)||ae&&Wt(ae.buffer,SharedArrayBuffer)))return ce(ae,Q,X);if(typeof ae=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const he=ae.valueOf&&ae.valueOf();if(he!=null&&he!==ae)return O.from(he,Q,X);const Te=oe(ae);if(Te)return Te;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof ae[Symbol.toPrimitive]=="function")return O.from(ae[Symbol.toPrimitive]("string"),Q,X);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ae)}O.from=function(ae,Q,X){return F(ae,Q,X)},Object.setPrototypeOf(O.prototype,Uint8Array.prototype),Object.setPrototypeOf(O,Uint8Array);function z(ae){if(typeof ae!="number")throw new TypeError('"size" argument must be of type number');if(ae<0)throw new RangeError('The value "'+ae+'" is invalid for option "size"')}function K(ae,Q,X){return z(ae),ae<=0?a(ae):Q!==void 0?typeof X=="string"?a(ae).fill(Q,X):a(ae).fill(Q):a(ae)}O.alloc=function(ae,Q,X){return K(ae,Q,X)};function te(ae){return z(ae),a(ae<0?0:se(ae)|0)}O.allocUnsafe=function(ae){return te(ae)},O.allocUnsafeSlow=function(ae){return te(ae)};function ne(ae,Q){if((typeof Q!="string"||Q==="")&&(Q="utf8"),!O.isEncoding(Q))throw new TypeError("Unknown encoding: "+Q);const X=ge(ae,Q)|0;let he=a(X);const Te=he.write(ae,Q);return Te!==X&&(he=he.slice(0,Te)),he}function ee(ae){const Q=ae.length<0?0:se(ae.length)|0,X=a(Q);for(let he=0;he<Q;he+=1)X[he]=ae[he]&255;return X}function re(ae){if(Wt(ae,Uint8Array)){const Q=new Uint8Array(ae);return ce(Q.buffer,Q.byteOffset,Q.byteLength)}return ee(ae)}function ce(ae,Q,X){if(Q<0||ae.byteLength<Q)throw new RangeError('"offset" is outside of buffer bounds');if(ae.byteLength<Q+(X||0))throw new RangeError('"length" is outside of buffer bounds');let he;return Q===void 0&&X===void 0?he=new Uint8Array(ae):X===void 0?he=new Uint8Array(ae,Q):he=new Uint8Array(ae,Q,X),Object.setPrototypeOf(he,O.prototype),he}function oe(ae){if(O.isBuffer(ae)){const Q=se(ae.length)|0,X=a(Q);return X.length===0||ae.copy(X,0,0,Q),X}if(ae.length!==void 0)return typeof ae.length!="number"||Gt(ae.length)?a(0):ee(ae);if(ae.type==="Buffer"&&Array.isArray(ae.data))return ee(ae.data)}function se(ae){if(ae>=I)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+I.toString(16)+" bytes");return ae|0}function fe(ae){return+ae!=ae&&(ae=0),O.alloc(+ae)}O.isBuffer=function(Q){return Q!=null&&Q._isBuffer===!0&&Q!==O.prototype},O.compare=function(Q,X){if(Wt(Q,Uint8Array)&&(Q=O.from(Q,Q.offset,Q.byteLength)),Wt(X,Uint8Array)&&(X=O.from(X,X.offset,X.byteLength)),!O.isBuffer(Q)||!O.isBuffer(X))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(Q===X)return 0;let he=Q.length,Te=X.length;for(let $e=0,Ue=Math.min(he,Te);$e<Ue;++$e)if(Q[$e]!==X[$e]){he=Q[$e],Te=X[$e];break}return he<Te?-1:Te<he?1:0},O.isEncoding=function(Q){switch(String(Q).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},O.concat=function(Q,X){if(!Array.isArray(Q))throw new TypeError('"list" argument must be an Array of Buffers');if(Q.length===0)return O.alloc(0);let he;if(X===void 0)for(X=0,he=0;he<Q.length;++he)X+=Q[he].length;const Te=O.allocUnsafe(X);let $e=0;for(he=0;he<Q.length;++he){let Ue=Q[he];if(Wt(Ue,Uint8Array))$e+Ue.length>Te.length?(O.isBuffer(Ue)||(Ue=O.from(Ue)),Ue.copy(Te,$e)):Uint8Array.prototype.set.call(Te,Ue,$e);else if(O.isBuffer(Ue))Ue.copy(Te,$e);else throw new TypeError('"list" argument must be an Array of Buffers');$e+=Ue.length}return Te};function ge(ae,Q){if(O.isBuffer(ae))return ae.length;if(ArrayBuffer.isView(ae)||Wt(ae,ArrayBuffer))return ae.byteLength;if(typeof ae!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof ae);const X=ae.length,he=arguments.length>2&&arguments[2]===!0;if(!he&&X===0)return 0;let Te=!1;for(;;)switch(Q){case"ascii":case"latin1":case"binary":return X;case"utf8":case"utf-8":return Zt(ae).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X*2;case"hex":return X>>>1;case"base64":return tn(ae).length;default:if(Te)return he?-1:Zt(ae).length;Q=(""+Q).toLowerCase(),Te=!0}}O.byteLength=ge;function ue(ae,Q,X){let he=!1;if((Q===void 0||Q<0)&&(Q=0),Q>this.length||((X===void 0||X>this.length)&&(X=this.length),X<=0)||(X>>>=0,Q>>>=0,X<=Q))return"";for(ae||(ae="utf8");;)switch(ae){case"hex":return jt(this,Q,X);case"utf8":case"utf-8":return Je(this,Q,X);case"ascii":return Et(this,Q,X);case"latin1":case"binary":return At(this,Q,X);case"base64":return We(this,Q,X);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Pt(this,Q,X);default:if(he)throw new TypeError("Unknown encoding: "+ae);ae=(ae+"").toLowerCase(),he=!0}}O.prototype._isBuffer=!0;function _e(ae,Q,X){const he=ae[Q];ae[Q]=ae[X],ae[X]=he}O.prototype.swap16=function(){const Q=this.length;if(Q%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let X=0;X<Q;X+=2)_e(this,X,X+1);return this},O.prototype.swap32=function(){const Q=this.length;if(Q%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let X=0;X<Q;X+=4)_e(this,X,X+3),_e(this,X+1,X+2);return this},O.prototype.swap64=function(){const Q=this.length;if(Q%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let X=0;X<Q;X+=8)_e(this,X,X+7),_e(this,X+1,X+6),_e(this,X+2,X+5),_e(this,X+3,X+4);return this},O.prototype.toString=function(){const Q=this.length;return Q===0?"":arguments.length===0?Je(this,0,Q):ue.apply(this,arguments)},O.prototype.toLocaleString=O.prototype.toString,O.prototype.equals=function(Q){if(!O.isBuffer(Q))throw new TypeError("Argument must be a Buffer");return this===Q?!0:O.compare(this,Q)===0},O.prototype.inspect=function(){let Q="";const X=N.INSPECT_MAX_BYTES;return Q=this.toString("hex",0,X).replace(/(.{2})/g,"$1 ").trim(),this.length>X&&(Q+=" ... "),"<Buffer "+Q+">"},J&&(O.prototype[J]=O.prototype.inspect),O.prototype.compare=function(Q,X,he,Te,$e){if(Wt(Q,Uint8Array)&&(Q=O.from(Q,Q.offset,Q.byteLength)),!O.isBuffer(Q))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof Q);if(X===void 0&&(X=0),he===void 0&&(he=Q?Q.length:0),Te===void 0&&(Te=0),$e===void 0&&($e=this.length),X<0||he>Q.length||Te<0||$e>this.length)throw new RangeError("out of range index");if(Te>=$e&&X>=he)return 0;if(Te>=$e)return-1;if(X>=he)return 1;if(X>>>=0,he>>>=0,Te>>>=0,$e>>>=0,this===Q)return 0;let Ue=$e-Te,ct=he-X;const kt=Math.min(Ue,ct),yt=this.slice(Te,$e),It=Q.slice(X,he);for(let St=0;St<kt;++St)if(yt[St]!==It[St]){Ue=yt[St],ct=It[St];break}return Ue<ct?-1:ct<Ue?1:0};function pe(ae,Q,X,he,Te){if(ae.length===0)return-1;if(typeof X=="string"?(he=X,X=0):X>2147483647?X=2147483647:X<-2147483648&&(X=-2147483648),X=+X,Gt(X)&&(X=Te?0:ae.length-1),X<0&&(X=ae.length+X),X>=ae.length){if(Te)return-1;X=ae.length-1}else if(X<0)if(Te)X=0;else return-1;if(typeof Q=="string"&&(Q=O.from(Q,he)),O.isBuffer(Q))return Q.length===0?-1:ye(ae,Q,X,he,Te);if(typeof Q=="number")return Q=Q&255,typeof Uint8Array.prototype.indexOf=="function"?Te?Uint8Array.prototype.indexOf.call(ae,Q,X):Uint8Array.prototype.lastIndexOf.call(ae,Q,X):ye(ae,[Q],X,he,Te);throw new TypeError("val must be string, number or Buffer")}function ye(ae,Q,X,he,Te){let $e=1,Ue=ae.length,ct=Q.length;if(he!==void 0&&(he=String(he).toLowerCase(),he==="ucs2"||he==="ucs-2"||he==="utf16le"||he==="utf-16le")){if(ae.length<2||Q.length<2)return-1;$e=2,Ue/=2,ct/=2,X/=2}function kt(It,St){return $e===1?It[St]:It.readUInt16BE(St*$e)}let yt;if(Te){let It=-1;for(yt=X;yt<Ue;yt++)if(kt(ae,yt)===kt(Q,It===-1?0:yt-It)){if(It===-1&&(It=yt),yt-It+1===ct)return It*$e}else It!==-1&&(yt-=yt-It),It=-1}else for(X+ct>Ue&&(X=Ue-ct),yt=X;yt>=0;yt--){let It=!0;for(let St=0;St<ct;St++)if(kt(ae,yt+St)!==kt(Q,St)){It=!1;break}if(It)return yt}return-1}O.prototype.includes=function(Q,X,he){return this.indexOf(Q,X,he)!==-1},O.prototype.indexOf=function(Q,X,he){return pe(this,Q,X,he,!0)},O.prototype.lastIndexOf=function(Q,X,he){return pe(this,Q,X,he,!1)};function we(ae,Q,X,he){X=Number(X)||0;const Te=ae.length-X;he?(he=Number(he),he>Te&&(he=Te)):he=Te;const $e=Q.length;he>$e/2&&(he=$e/2);let Ue;for(Ue=0;Ue<he;++Ue){const ct=parseInt(Q.substr(Ue*2,2),16);if(Gt(ct))return Ue;ae[X+Ue]=ct}return Ue}function Ie(ae,Q,X,he){return nn(Zt(Q,ae.length-X),ae,X,he)}function be(ae,Q,X,he){return nn(Kt(Q),ae,X,he)}function Se(ae,Q,X,he){return nn(tn(Q),ae,X,he)}function Me(ae,Q,X,he){return nn(fn(Q,ae.length-X),ae,X,he)}O.prototype.write=function(Q,X,he,Te){if(X===void 0)Te="utf8",he=this.length,X=0;else if(he===void 0&&typeof X=="string")Te=X,he=this.length,X=0;else if(isFinite(X))X=X>>>0,isFinite(he)?(he=he>>>0,Te===void 0&&(Te="utf8")):(Te=he,he=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const $e=this.length-X;if((he===void 0||he>$e)&&(he=$e),Q.length>0&&(he<0||X<0)||X>this.length)throw new RangeError("Attempt to write outside buffer bounds");Te||(Te="utf8");let Ue=!1;for(;;)switch(Te){case"hex":return we(this,Q,X,he);case"utf8":case"utf-8":return Ie(this,Q,X,he);case"ascii":case"latin1":case"binary":return be(this,Q,X,he);case"base64":return Se(this,Q,X,he);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Me(this,Q,X,he);default:if(Ue)throw new TypeError("Unknown encoding: "+Te);Te=(""+Te).toLowerCase(),Ue=!0}},O.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function We(ae,Q,X){return Q===0&&X===ae.length?Z.fromByteArray(ae):Z.fromByteArray(ae.slice(Q,X))}function Je(ae,Q,X){X=Math.min(ae.length,X);const he=[];let Te=Q;for(;Te<X;){const $e=ae[Te];let Ue=null,ct=$e>239?4:$e>223?3:$e>191?2:1;if(Te+ct<=X){let kt,yt,It,St;switch(ct){case 1:$e<128&&(Ue=$e);break;case 2:kt=ae[Te+1],(kt&192)===128&&(St=($e&31)<<6|kt&63,St>127&&(Ue=St));break;case 3:kt=ae[Te+1],yt=ae[Te+2],(kt&192)===128&&(yt&192)===128&&(St=($e&15)<<12|(kt&63)<<6|yt&63,St>2047&&(St<55296||St>57343)&&(Ue=St));break;case 4:kt=ae[Te+1],yt=ae[Te+2],It=ae[Te+3],(kt&192)===128&&(yt&192)===128&&(It&192)===128&&(St=($e&15)<<18|(kt&63)<<12|(yt&63)<<6|It&63,St>65535&&St<1114112&&(Ue=St))}}Ue===null?(Ue=65533,ct=1):Ue>65535&&(Ue-=65536,he.push(Ue>>>10&1023|55296),Ue=56320|Ue&1023),he.push(Ue),Te+=ct}return Tt(he)}const Le=4096;function Tt(ae){const Q=ae.length;if(Q<=Le)return String.fromCharCode.apply(String,ae);let X="",he=0;for(;he<Q;)X+=String.fromCharCode.apply(String,ae.slice(he,he+=Le));return X}function Et(ae,Q,X){let he="";X=Math.min(ae.length,X);for(let Te=Q;Te<X;++Te)he+=String.fromCharCode(ae[Te]&127);return he}function At(ae,Q,X){let he="";X=Math.min(ae.length,X);for(let Te=Q;Te<X;++Te)he+=String.fromCharCode(ae[Te]);return he}function jt(ae,Q,X){const he=ae.length;(!Q||Q<0)&&(Q=0),(!X||X<0||X>he)&&(X=he);let Te="";for(let $e=Q;$e<X;++$e)Te+=_n[ae[$e]];return Te}function Pt(ae,Q,X){const he=ae.slice(Q,X);let Te="";for(let $e=0;$e<he.length-1;$e+=2)Te+=String.fromCharCode(he[$e]+he[$e+1]*256);return Te}O.prototype.slice=function(Q,X){const he=this.length;Q=~~Q,X=X===void 0?he:~~X,Q<0?(Q+=he,Q<0&&(Q=0)):Q>he&&(Q=he),X<0?(X+=he,X<0&&(X=0)):X>he&&(X=he),X<Q&&(X=Q);const Te=this.subarray(Q,X);return Object.setPrototypeOf(Te,O.prototype),Te};function _t(ae,Q,X){if(ae%1!==0||ae<0)throw new RangeError("offset is not uint");if(ae+Q>X)throw new RangeError("Trying to access beyond buffer length")}O.prototype.readUintLE=O.prototype.readUIntLE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=this[Q],$e=1,Ue=0;for(;++Ue<X&&($e*=256);)Te+=this[Q+Ue]*$e;return Te},O.prototype.readUintBE=O.prototype.readUIntBE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=this[Q+--X],$e=1;for(;X>0&&($e*=256);)Te+=this[Q+--X]*$e;return Te},O.prototype.readUint8=O.prototype.readUInt8=function(Q,X){return Q=Q>>>0,X||_t(Q,1,this.length),this[Q]},O.prototype.readUint16LE=O.prototype.readUInt16LE=function(Q,X){return Q=Q>>>0,X||_t(Q,2,this.length),this[Q]|this[Q+1]<<8},O.prototype.readUint16BE=O.prototype.readUInt16BE=function(Q,X){return Q=Q>>>0,X||_t(Q,2,this.length),this[Q]<<8|this[Q+1]},O.prototype.readUint32LE=O.prototype.readUInt32LE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),(this[Q]|this[Q+1]<<8|this[Q+2]<<16)+this[Q+3]*16777216},O.prototype.readUint32BE=O.prototype.readUInt32BE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),this[Q]*16777216+(this[Q+1]<<16|this[Q+2]<<8|this[Q+3])},O.prototype.readBigUInt64LE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=X+this[++Q]*2**8+this[++Q]*2**16+this[++Q]*2**24,$e=this[++Q]+this[++Q]*2**8+this[++Q]*2**16+he*2**24;return BigInt(Te)+(BigInt($e)<<BigInt(32))}),O.prototype.readBigUInt64BE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=X*2**24+this[++Q]*2**16+this[++Q]*2**8+this[++Q],$e=this[++Q]*2**24+this[++Q]*2**16+this[++Q]*2**8+he;return(BigInt(Te)<<BigInt(32))+BigInt($e)}),O.prototype.readIntLE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=this[Q],$e=1,Ue=0;for(;++Ue<X&&($e*=256);)Te+=this[Q+Ue]*$e;return $e*=128,Te>=$e&&(Te-=Math.pow(2,8*X)),Te},O.prototype.readIntBE=function(Q,X,he){Q=Q>>>0,X=X>>>0,he||_t(Q,X,this.length);let Te=X,$e=1,Ue=this[Q+--Te];for(;Te>0&&($e*=256);)Ue+=this[Q+--Te]*$e;return $e*=128,Ue>=$e&&(Ue-=Math.pow(2,8*X)),Ue},O.prototype.readInt8=function(Q,X){return Q=Q>>>0,X||_t(Q,1,this.length),this[Q]&128?(255-this[Q]+1)*-1:this[Q]},O.prototype.readInt16LE=function(Q,X){Q=Q>>>0,X||_t(Q,2,this.length);const he=this[Q]|this[Q+1]<<8;return he&32768?he|4294901760:he},O.prototype.readInt16BE=function(Q,X){Q=Q>>>0,X||_t(Q,2,this.length);const he=this[Q+1]|this[Q]<<8;return he&32768?he|4294901760:he},O.prototype.readInt32LE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),this[Q]|this[Q+1]<<8|this[Q+2]<<16|this[Q+3]<<24},O.prototype.readInt32BE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),this[Q]<<24|this[Q+1]<<16|this[Q+2]<<8|this[Q+3]},O.prototype.readBigInt64LE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=this[Q+4]+this[Q+5]*2**8+this[Q+6]*2**16+(he<<24);return(BigInt(Te)<<BigInt(32))+BigInt(X+this[++Q]*2**8+this[++Q]*2**16+this[++Q]*2**24)}),O.prototype.readBigInt64BE=rn(function(Q){Q=Q>>>0,gt(Q,"offset");const X=this[Q],he=this[Q+7];(X===void 0||he===void 0)&&Dt(Q,this.length-8);const Te=(X<<24)+this[++Q]*2**16+this[++Q]*2**8+this[++Q];return(BigInt(Te)<<BigInt(32))+BigInt(this[++Q]*2**24+this[++Q]*2**16+this[++Q]*2**8+he)}),O.prototype.readFloatLE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),q.read(this,Q,!0,23,4)},O.prototype.readFloatBE=function(Q,X){return Q=Q>>>0,X||_t(Q,4,this.length),q.read(this,Q,!1,23,4)},O.prototype.readDoubleLE=function(Q,X){return Q=Q>>>0,X||_t(Q,8,this.length),q.read(this,Q,!0,52,8)},O.prototype.readDoubleBE=function(Q,X){return Q=Q>>>0,X||_t(Q,8,this.length),q.read(this,Q,!1,52,8)};function rt(ae,Q,X,he,Te,$e){if(!O.isBuffer(ae))throw new TypeError('"buffer" argument must be a Buffer instance');if(Q>Te||Q<$e)throw new RangeError('"value" argument is out of bounds');if(X+he>ae.length)throw new RangeError("Index out of range")}O.prototype.writeUintLE=O.prototype.writeUIntLE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,he=he>>>0,!Te){const ct=Math.pow(2,8*he)-1;rt(this,Q,X,he,ct,0)}let $e=1,Ue=0;for(this[X]=Q&255;++Ue<he&&($e*=256);)this[X+Ue]=Q/$e&255;return X+he},O.prototype.writeUintBE=O.prototype.writeUIntBE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,he=he>>>0,!Te){const ct=Math.pow(2,8*he)-1;rt(this,Q,X,he,ct,0)}let $e=he-1,Ue=1;for(this[X+$e]=Q&255;--$e>=0&&(Ue*=256);)this[X+$e]=Q/Ue&255;return X+he},O.prototype.writeUint8=O.prototype.writeUInt8=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,1,255,0),this[X]=Q&255,X+1},O.prototype.writeUint16LE=O.prototype.writeUInt16LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,65535,0),this[X]=Q&255,this[X+1]=Q>>>8,X+2},O.prototype.writeUint16BE=O.prototype.writeUInt16BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,65535,0),this[X]=Q>>>8,this[X+1]=Q&255,X+2},O.prototype.writeUint32LE=O.prototype.writeUInt32LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,4294967295,0),this[X+3]=Q>>>24,this[X+2]=Q>>>16,this[X+1]=Q>>>8,this[X]=Q&255,X+4},O.prototype.writeUint32BE=O.prototype.writeUInt32BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,4294967295,0),this[X]=Q>>>24,this[X+1]=Q>>>16,this[X+2]=Q>>>8,this[X+3]=Q&255,X+4};function Vt(ae,Q,X,he,Te){st(Q,he,Te,ae,X,7);let $e=Number(Q&BigInt(4294967295));ae[X++]=$e,$e=$e>>8,ae[X++]=$e,$e=$e>>8,ae[X++]=$e,$e=$e>>8,ae[X++]=$e;let Ue=Number(Q>>BigInt(32)&BigInt(4294967295));return ae[X++]=Ue,Ue=Ue>>8,ae[X++]=Ue,Ue=Ue>>8,ae[X++]=Ue,Ue=Ue>>8,ae[X++]=Ue,X}function Rt(ae,Q,X,he,Te){st(Q,he,Te,ae,X,7);let $e=Number(Q&BigInt(4294967295));ae[X+7]=$e,$e=$e>>8,ae[X+6]=$e,$e=$e>>8,ae[X+5]=$e,$e=$e>>8,ae[X+4]=$e;let Ue=Number(Q>>BigInt(32)&BigInt(4294967295));return ae[X+3]=Ue,Ue=Ue>>8,ae[X+2]=Ue,Ue=Ue>>8,ae[X+1]=Ue,Ue=Ue>>8,ae[X]=Ue,X+8}O.prototype.writeBigUInt64LE=rn(function(Q,X=0){return Vt(this,Q,X,BigInt(0),BigInt("0xffffffffffffffff"))}),O.prototype.writeBigUInt64BE=rn(function(Q,X=0){return Rt(this,Q,X,BigInt(0),BigInt("0xffffffffffffffff"))}),O.prototype.writeIntLE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,!Te){const kt=Math.pow(2,8*he-1);rt(this,Q,X,he,kt-1,-kt)}let $e=0,Ue=1,ct=0;for(this[X]=Q&255;++$e<he&&(Ue*=256);)Q<0&&ct===0&&this[X+$e-1]!==0&&(ct=1),this[X+$e]=(Q/Ue>>0)-ct&255;return X+he},O.prototype.writeIntBE=function(Q,X,he,Te){if(Q=+Q,X=X>>>0,!Te){const kt=Math.pow(2,8*he-1);rt(this,Q,X,he,kt-1,-kt)}let $e=he-1,Ue=1,ct=0;for(this[X+$e]=Q&255;--$e>=0&&(Ue*=256);)Q<0&&ct===0&&this[X+$e+1]!==0&&(ct=1),this[X+$e]=(Q/Ue>>0)-ct&255;return X+he},O.prototype.writeInt8=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,1,127,-128),Q<0&&(Q=255+Q+1),this[X]=Q&255,X+1},O.prototype.writeInt16LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,32767,-32768),this[X]=Q&255,this[X+1]=Q>>>8,X+2},O.prototype.writeInt16BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,2,32767,-32768),this[X]=Q>>>8,this[X+1]=Q&255,X+2},O.prototype.writeInt32LE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,2147483647,-2147483648),this[X]=Q&255,this[X+1]=Q>>>8,this[X+2]=Q>>>16,this[X+3]=Q>>>24,X+4},O.prototype.writeInt32BE=function(Q,X,he){return Q=+Q,X=X>>>0,he||rt(this,Q,X,4,2147483647,-2147483648),Q<0&&(Q=4294967295+Q+1),this[X]=Q>>>24,this[X+1]=Q>>>16,this[X+2]=Q>>>8,this[X+3]=Q&255,X+4},O.prototype.writeBigInt64LE=rn(function(Q,X=0){return Vt(this,Q,X,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),O.prototype.writeBigInt64BE=rn(function(Q,X=0){return Rt(this,Q,X,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Pe(ae,Q,X,he,Te,$e){if(X+he>ae.length)throw new RangeError("Index out of range");if(X<0)throw new RangeError("Index out of range")}function it(ae,Q,X,he,Te){return Q=+Q,X=X>>>0,Te||Pe(ae,Q,X,4),q.write(ae,Q,X,he,23,4),X+4}O.prototype.writeFloatLE=function(Q,X,he){return it(this,Q,X,!0,he)},O.prototype.writeFloatBE=function(Q,X,he){return it(this,Q,X,!1,he)};function zt(ae,Q,X,he,Te){return Q=+Q,X=X>>>0,Te||Pe(ae,Q,X,8),q.write(ae,Q,X,he,52,8),X+8}O.prototype.writeDoubleLE=function(Q,X,he){return zt(this,Q,X,!0,he)},O.prototype.writeDoubleBE=function(Q,X,he){return zt(this,Q,X,!1,he)},O.prototype.copy=function(Q,X,he,Te){if(!O.isBuffer(Q))throw new TypeError("argument should be a Buffer");if(he||(he=0),!Te&&Te!==0&&(Te=this.length),X>=Q.length&&(X=Q.length),X||(X=0),Te>0&&Te<he&&(Te=he),Te===he||Q.length===0||this.length===0)return 0;if(X<0)throw new RangeError("targetStart out of bounds");if(he<0||he>=this.length)throw new RangeError("Index out of range");if(Te<0)throw new RangeError("sourceEnd out of bounds");Te>this.length&&(Te=this.length),Q.length-X<Te-he&&(Te=Q.length-X+he);const $e=Te-he;return this===Q&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(X,he,Te):Uint8Array.prototype.set.call(Q,this.subarray(he,Te),X),$e},O.prototype.fill=function(Q,X,he,Te){if(typeof Q=="string"){if(typeof X=="string"?(Te=X,X=0,he=this.length):typeof he=="string"&&(Te=he,he=this.length),Te!==void 0&&typeof Te!="string")throw new TypeError("encoding must be a string");if(typeof Te=="string"&&!O.isEncoding(Te))throw new TypeError("Unknown encoding: "+Te);if(Q.length===1){const Ue=Q.charCodeAt(0);(Te==="utf8"&&Ue<128||Te==="latin1")&&(Q=Ue)}}else typeof Q=="number"?Q=Q&255:typeof Q=="boolean"&&(Q=Number(Q));if(X<0||this.length<X||this.length<he)throw new RangeError("Out of range index");if(he<=X)return this;X=X>>>0,he=he===void 0?this.length:he>>>0,Q||(Q=0);let $e;if(typeof Q=="number")for($e=X;$e<he;++$e)this[$e]=Q;else{const Ue=O.isBuffer(Q)?Q:O.from(Q,Te),ct=Ue.length;if(ct===0)throw new TypeError('The value "'+Q+'" is invalid for argument "value"');for($e=0;$e<he-X;++$e)this[$e+X]=Ue[$e%ct]}return this};const Bt={};function nt(ae,Q,X){Bt[ae]=class extends X{constructor(){super(),Object.defineProperty(this,"message",{value:Q.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${ae}]`,this.stack,delete this.name}get code(){return ae}set code(Te){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:Te,writable:!0})}toString(){return`${this.name} [${ae}]: ${this.message}`}}}nt("ERR_BUFFER_OUT_OF_BOUNDS",function(ae){return ae?`${ae} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),nt("ERR_INVALID_ARG_TYPE",function(ae,Q){return`The "${ae}" argument must be of type number. Received type ${typeof Q}`},TypeError),nt("ERR_OUT_OF_RANGE",function(ae,Q,X){let he=`The value of "${ae}" is out of range.`,Te=X;return Number.isInteger(X)&&Math.abs(X)>2**32?Te=et(String(X)):typeof X=="bigint"&&(Te=String(X),(X>BigInt(2)**BigInt(32)||X<-(BigInt(2)**BigInt(32)))&&(Te=et(Te)),Te+="n"),he+=` It must be ${Q}. Received ${Te}`,he},RangeError);function et(ae){let Q="",X=ae.length;const he=ae[0]==="-"?1:0;for(;X>=he+4;X-=3)Q=`_${ae.slice(X-3,X)}${Q}`;return`${ae.slice(0,X)}${Q}`}function ot(ae,Q,X){gt(Q,"offset"),(ae[Q]===void 0||ae[Q+X]===void 0)&&Dt(Q,ae.length-(X+1))}function st(ae,Q,X,he,Te,$e){if(ae>X||ae<Q){const Ue=typeof Q=="bigint"?"n":"";let ct;throw Q===0||Q===BigInt(0)?ct=`>= 0${Ue} and < 2${Ue} ** ${($e+1)*8}${Ue}`:ct=`>= -(2${Ue} ** ${($e+1)*8-1}${Ue}) and < 2 ** ${($e+1)*8-1}${Ue}`,new Bt.ERR_OUT_OF_RANGE("value",ct,ae)}ot(he,Te,$e)}function gt(ae,Q){if(typeof ae!="number")throw new Bt.ERR_INVALID_ARG_TYPE(Q,"number",ae)}function Dt(ae,Q,X){throw Math.floor(ae)!==ae?(gt(ae,X),new Bt.ERR_OUT_OF_RANGE("offset","an integer",ae)):Q<0?new Bt.ERR_BUFFER_OUT_OF_BOUNDS:new Bt.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${Q}`,ae)}const Ut=/[^+/0-9A-Za-z-_]/g;function Lt(ae){if(ae=ae.split("=")[0],ae=ae.trim().replace(Ut,""),ae.length<2)return"";for(;ae.length%4!==0;)ae=ae+"=";return ae}function Zt(ae,Q){Q=Q||1/0;let X;const he=ae.length;let Te=null;const $e=[];for(let Ue=0;Ue<he;++Ue){if(X=ae.charCodeAt(Ue),X>55295&&X<57344){if(!Te){if(X>56319){(Q-=3)>-1&&$e.push(239,191,189);continue}else if(Ue+1===he){(Q-=3)>-1&&$e.push(239,191,189);continue}Te=X;continue}if(X<56320){(Q-=3)>-1&&$e.push(239,191,189),Te=X;continue}X=(Te-55296<<10|X-56320)+65536}else Te&&(Q-=3)>-1&&$e.push(239,191,189);if(Te=null,X<128){if((Q-=1)<0)break;$e.push(X)}else if(X<2048){if((Q-=2)<0)break;$e.push(X>>6|192,X&63|128)}else if(X<65536){if((Q-=3)<0)break;$e.push(X>>12|224,X>>6&63|128,X&63|128)}else if(X<1114112){if((Q-=4)<0)break;$e.push(X>>18|240,X>>12&63|128,X>>6&63|128,X&63|128)}else throw new Error("Invalid code point")}return $e}function Kt(ae){const Q=[];for(let X=0;X<ae.length;++X)Q.push(ae.charCodeAt(X)&255);return Q}function fn(ae,Q){let X,he,Te;const $e=[];for(let Ue=0;Ue<ae.length&&!((Q-=2)<0);++Ue)X=ae.charCodeAt(Ue),he=X>>8,Te=X%256,$e.push(Te),$e.push(he);return $e}function tn(ae){return Z.toByteArray(Lt(ae))}function nn(ae,Q,X,he){let Te;for(Te=0;Te<he&&!(Te+X>=Q.length||Te>=ae.length);++Te)Q[Te+X]=ae[Te];return Te}function Wt(ae,Q){return ae instanceof Q||ae!=null&&ae.constructor!=null&&ae.constructor.name!=null&&ae.constructor.name===Q.name}function Gt(ae){return ae!==ae}const _n=function(){const ae="0123456789abcdef",Q=new Array(256);for(let X=0;X<16;++X){const he=X*16;for(let Te=0;Te<16;++Te)Q[he+Te]=ae[X]+ae[Te]}return Q}();function rn(ae){return typeof BigInt>"u"?Qt:ae}function Qt(){throw new Error("BigInt not supported")}}(buffer)),buffer}var toolsEbml={},hasRequiredToolsEbml;function requireToolsEbml(){if(hasRequiredToolsEbml)return toolsEbml;hasRequiredToolsEbml=1;var N=toolsEbml&&toolsEbml.__assign||function(){return N=Object.assign||function(I){for(var D,a=1,O=arguments.length;a<O;a++){D=arguments[a];for(var F in D)Object.prototype.hasOwnProperty.call(D,F)&&(I[F]=D[F])}return I},N.apply(this,arguments)},Z=toolsEbml&&toolsEbml.__spreadArray||function(I,D,a){if(a||arguments.length===2)for(var O=0,F=D.length,z;O<F;O++)(z||!(O in D))&&(z||(z=Array.prototype.slice.call(D,0,O)),z[O]=D[O]);return I.concat(z||Array.prototype.slice.call(D))};Object.defineProperty(toolsEbml,"__esModule",{value:!0});var q=requireTools(),J=function(){function I(){}return I.readVint=function(D,a){a===void 0&&(a=0);var O=8-Math.floor(Math.log2(D[a]));if(O>8){var F=I.readHexString(D,a,a+O);throw new Error("Unrepresentable length: ".concat(O," ").concat(F))}if(a+O>D.length)return null;for(var z=D[a]&(1<<8-O)-1,K=1;K<O;K+=1){if(K===7&&z>=Math.pow(2,8)&&D[a+7]>0)return{length:O,value:-1};z*=Math.pow(2,8),z+=D[a+K]}return{length:O,value:z}},I.writeVint=function(D){if(D<0||D>Math.pow(2,53))throw new Error("Unrepresentable value: ".concat(D));var a=1;for(a=1;a<=8&&!(D<Math.pow(2,7*a)-1);a+=1);for(var O=q.Buffer.alloc(a),F=D,z=1;z<=a;z+=1){var K=F&255;O[a-z]=K,F-=K,F/=Math.pow(2,8)}return O[0]|=1<<8-a,O},I.concatenate=function(D,a){return!D&&!a?q.Buffer.from([]):!D||D.byteLength===0?a:!a||a.byteLength===0?D:q.Buffer.from(Z(Z([],D,!0),a,!0))},I.readHexString=function(D,a,O){return a===void 0&&(a=0),O===void 0&&(O=D.byteLength),Array.from(D.slice(a,O)).map(function(F){return Number(F).toString(16)}).reduce(function(F,z){return"".concat(F).concat(z.padStart(2,"0"))},"")},I.readUtf8=function(D){try{return q.Buffer.from(D).toString("utf8")}catch{return null}},I.readUnsigned=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 1:return a.getUint8(0);case 2:return a.getUint16(0);case 4:return a.getUint32(0)}return D.byteLength<=6?D.reduce(function(O,F){return O*256+F},0):I.readHexString(D,0,D.byteLength)},I.readSigned=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 1:return a.getInt8(0);case 2:return a.getInt16(0);case 4:return a.getInt32(0);default:return NaN}},I.readFloat=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 4:return a.getFloat32(0);case 8:return a.getFloat64(0);default:return NaN}},I.readDate=function(D){var a=new DataView(D.buffer,D.byteOffset,D.byteLength);switch(D.byteLength){case 1:return new Date(a.getUint8(0));case 2:return new Date(a.getUint16(0));case 4:return new Date(a.getUint32(0));case 8:return new Date(Number.parseInt(I.readHexString(D),16));default:return new Date(0)}},I.readDataFromTag=function(D,a){var O=D.type,F=D.name,z=D.track,K=D.discardable||!1,te=D.keyframe||!1,ne=null,ee;switch(O){case"u":ee=I.readUnsigned(a);break;case"f":ee=I.readFloat(a);break;case"i":ee=I.readSigned(a);break;case"s":ee=String.fromCharCode.apply(String,a);break;case"8":ee=I.readUtf8(a);break;case"d":ee=I.readDate(a);break}if(F==="SimpleBlock"||F==="Block"){var re=0,ce=I.readVint(a,re),oe=ce.length,se=ce.value;re+=oe,z=se,ee=I.readSigned(a.subarray(re,re+2)),re+=2,F==="SimpleBlock"&&(te=!!(a[oe+2]&128),K=!!(a[oe+2]&1)),re+=1,ne=a.subarray(re)}return N(N({},D),{data:a,discardable:K,keyframe:te,payload:ne,track:z,value:ee})},I}();return toolsEbml.default=J,toolsEbml}var vint,hasRequiredVint;function requireVint(){return hasRequiredVint||(hasRequiredVint=1,vint=function(N,Z,q){Z=Z||0;for(var J=1;J<=8&&!(N[Z]>=Math.pow(2,8-J));J++);if(J>8)throw new Error("Unrepresentable length: "+J+" "+N.toString("hex",Z,Z+J));if(Z+J>N.length)return null;var I,D=N[Z]&(1<<8-J)-1;for(I=1;I<J;I++){if(I===7&&D>=Math.pow(2,45)&&N[Z+7]>0)return{length:J,value:-1};D*=Math.pow(2,8),D+=N[Z+I]}return q&&(D-=Math.pow(2,J*7-1)-1),{length:J,value:D}}),vint}var bufferReader,hasRequiredBufferReader;function requireBufferReader(){if(hasRequiredBufferReader)return bufferReader;hasRequiredBufferReader=1;var N=requireVint();function Z(q){this.buffer=q,this.offset=0}return Z.prototype.nextInt16BE=function(){var q=this.buffer.readInt16BE(this.offset);return this.offset+=2,q},Z.prototype.nextUInt8=function(){var q=this.buffer.readUInt8(this.offset);return this.offset+=1,q},Z.prototype.nextUIntV=function(){var q=N(this.buffer,this.offset);return this.offset+=q.length,q.value},Z.prototype.nextIntV=function(){var q=N(this.buffer,this.offset,!0);return this.offset+=q.length,q.value},Z.prototype.nextBuffer=function(q){var J=q?this.buffer.slice(this.offset,this.offset+q):this.buffer.slice(this.offset);return this.offset+=q||this.length,J},Object.defineProperty(Z.prototype,"length",{get:function(){return this.buffer.length-this.offset}}),bufferReader=Z,bufferReader}var ebmlBlock,hasRequiredEbmlBlock;function requireEbmlBlock(){if(hasRequiredEbmlBlock)return ebmlBlock;hasRequiredEbmlBlock=1;var N=requireBufferReader(),Z=1,q=3,J=2;ebmlBlock=function(D){var a={},O=new N(D);a.trackNumber=O.nextUIntV(),a.timecode=O.nextInt16BE();var F=O.nextUInt8();a.invisible=!!(F&8),a.keyframe=!!(F&128),a.discardable=!!(F&1);var z=(F&6)>>1;return a.frames=I(O,z),a};function I(D,a){if(!a)return[D.nextBuffer()];var O,F,z=[],K=D.nextUInt8()+1;if(a===J){if(D.length%K!==0)throw new Error("Fixed-Size Lacing Error");for(F=D.length/K,O=0;O<K;O++)z.push(D.nextBuffer(F));return z}var te=[];if(a===Z)for(O=0;O<K-1;O++){var ne;F=0;do ne=D.nextUInt8(),F+=ne;while(ne===255);te.push(F)}else if(a===q)for(F=D.nextUIntV(),te.push(F),O=1;O<K-1;O++)F+=D.nextIntV(),te.push(F);for(O=0;O<K-1;O++)z.push(D.nextBuffer(te[O]));return z.push(D.nextBuffer()),z}return ebmlBlock}var hasRequiredTools;function requireTools(){return hasRequiredTools||(hasRequiredTools=1,function(N){Object.defineProperty(N,"__esModule",{value:!0}),N.convertEBMLDateToJSDate=N.createFloatBuffer=N.createIntBuffer=N.createUIntBuffer=N.encodeValueToBuffer=N.concat=N.putRefinedMetaData=N.extractElement=N.removeElement=N.makeMetadataSeekable=N.createRIFFChunk=N.VP8BitStreamToRiffWebPBuffer=N.WebPBlockFilter=N.encodeTag=N.readBlock=N.ebmlBlock=N.writeVint=N.readVint=N.Buffer=void 0;var Z=requireInt64Buffer(),q=requireEBMLEncoder(),J=requireBuffer(),I=requireToolsEbml(),D=requireEbmlBlock();N.Buffer=J.Buffer,N.readVint=I.default.readVint,N.writeVint=I.default.writeVint,N.ebmlBlock=D;function a(be){return(0,N.ebmlBlock)(new N.Buffer(be))}N.readBlock=a;function O(be,Se,Me){return Me===void 0&&(Me=!1),ue([be,Me?new N.Buffer("01ffffffffffffff","hex"):(0,N.writeVint)(Se.length),Se])}N.encodeTag=O;function F(be){return be.reduce(function(Se,Me){if(Me.type!=="b"||Me.name!=="SimpleBlock")return Se;var We=(0,N.ebmlBlock)(Me.data),Je=We.frames.some(function(Le){var Tt=Le.slice(3,6).toString("hex");return Tt==="9d012a"});return Je?Se.concat(Me):Se},[])}N.WebPBlockFilter=F;function z(be){var Se=K("VP8 ",be),Me=ue([new N.Buffer("WEBP","ascii"),Se]);return K("RIFF",Me)}N.VP8BitStreamToRiffWebPBuffer=z;function K(be,Se){var Me=new N.Buffer(4);return Me.writeUInt32LE(Se.byteLength,0),ue([new N.Buffer(be.substr(0,4),"ascii"),Me,Se,new N.Buffer(Se.byteLength%2===0?0:1)])}N.createRIFFChunk=K;function te(be,Se,Me){var We=ee("EBML",be),Je=ce(We),Le=Je+12,Tt=be[be.length-1].dataEnd-Le,Et=ee("Info",be);ne("Duration",Et),Et.splice(1,0,{name:"Duration",type:"f",data:we(Se,8)});for(var At=ce(Et),jt=ee("Tracks",be),Pt=ce(jt),_t=47,rt=[],Vt=5+Me.length*15,Rt=[],Pe=-1,it=10,zt=function(st){var gt=_t,Dt=gt+At,Ut=Dt+Pt,Lt=Ut+Vt,Zt=Lt-Tt;if(rt=[],rt.push({name:"SeekHead",type:"m",isEnd:!1}),rt.push({name:"Seek",type:"m",isEnd:!1}),rt.push({name:"SeekID",type:"b",data:new N.Buffer([21,73,169,102])}),rt.push({name:"SeekPosition",type:"u",data:pe(gt)}),rt.push({name:"Seek",type:"m",isEnd:!0}),rt.push({name:"Seek",type:"m",isEnd:!1}),rt.push({name:"SeekID",type:"b",data:new N.Buffer([22,84,174,107])}),rt.push({name:"SeekPosition",type:"u",data:pe(Dt)}),rt.push({name:"Seek",type:"m",isEnd:!0}),rt.push({name:"Seek",type:"m",isEnd:!1}),rt.push({name:"SeekID",type:"b",data:new N.Buffer([28,83,187,107])}),rt.push({name:"SeekPosition",type:"u",data:pe(Ut)}),rt.push({name:"Seek",type:"m",isEnd:!0}),rt.push({name:"SeekHead",type:"m",isEnd:!0}),_t=ce(rt),Rt=[],Rt.push({name:"Cues",type:"m",isEnd:!1}),Me.forEach(function(Kt){var fn=Kt.CueTrack,tn=Kt.CueClusterPosition,nn=Kt.CueTime;Rt.push({name:"CuePoint",type:"m",isEnd:!1}),Rt.push({name:"CueTime",type:"u",data:pe(nn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Rt.push({name:"CueTrack",type:"u",data:pe(fn)}),tn-=Le,tn+=Zt,Rt.push({name:"CueClusterPosition",type:"u",data:pe(tn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Rt.push({name:"CuePoint",type:"m",isEnd:!0})}),Rt.push({name:"Cues",type:"m",isEnd:!0}),Vt=ce(Rt),Pe!==Zt){if(Pe=Zt,st===it-1)throw new Error("Failed to converge to a stable metadata size")}else return"break"},Bt=0;Bt<it;Bt++){var nt=zt(Bt);if(nt==="break")break}var et=[].concat.apply([],[We,{name:"Segment",type:"m",isEnd:!1,unknownSize:!0},rt,Et,jt,Rt]),ot=new q.default().encode(et);return ot}N.makeMetadataSeekable=te;function ne(be,Se){for(var Me=-1,We=0;We<Se.length;We++){var Je=Se[We];if(Je.name===be)if(Je.type==="m")if(!Je.isEnd)Me=We;else{if(Me==-1)throw new Error("Detected ".concat(be," closing element before finding the start"));Se.splice(Me,We-Me+1);return}else{Se.splice(We,1);return}}}N.removeElement=ne;function ee(be,Se){for(var Me=[],We=-1,Je=0;Je<Se.length;Je++){var Le=Se[Je];if(Le.name===be)if(Le.type==="m")if(!Le.isEnd)We=Je;else{if(We==-1)throw new Error("Detected ".concat(be," closing element before finding the start"));Me=Se.slice(We,Je+1);break}else{Me.push(Se[Je]);break}}return Me}N.extractElement=ee;function re(be,Se){Array.isArray(Se.cueInfos)&&!Array.isArray(Se.cues)&&(console.warn("putRefinedMetaData: info.cueInfos property is deprecated. please use info.cues"),Se.cues=Se.cueInfos);for(var Me=[],We=[],Je=0;Je<be.length;Je++){var Le=be[Je];if(Le.type==="m"&&Le.name==="Segment"){if(Me=be.slice(0,Je),We=be.slice(Je),Le.unknownSize){We.shift();break}throw new Error("this metadata is not streaming webm file")}}if(!(We[We.length-1].dataEnd>0))throw new Error("metadata dataEnd has wrong number");var Tt=We[We.length-1].dataEnd,Et=Me[Me.length-1].dataEnd,At=new q.default().encode(Me).byteLength,jt=At-Et,Pt=Tt-We[0].tagStart;We[0].tagStart-Et,We[0].tagStart;var _t=new N.Buffer([24,83,128,103]),rt=new N.Buffer("01ffffffffffffff","hex"),Vt=_t.byteLength+rt.byteLength,Rt=Pt,Pe;for(Pe=1;Pe<20;Pe++){var it=Et+Vt+Rt,zt=it-Tt,Bt=jt+zt,nt=oe(We,Bt,Se),et=new q.default().encode(nt).byteLength;if(et===Rt)return new q.default().encode([].concat(Me,[{type:"m",name:"Segment",isEnd:!1,unknownSize:!0}],nt));Rt=et}throw new Error("unable to refine metadata, stable size could not be found in "+Pe+" iterations!")}N.putRefinedMetaData=re;function ce(be){var Se=new q.default;return be.reduce(function(Me,We){return Me.concat(Se.encode([We]))},[]).reduce(function(Me,We){return Me+We.byteLength},0)}function oe(be,Se,Me){var We=Me.duration,Je=Me.clusterPtrs,Le=Me.cues,Tt=be.slice(0);if(typeof We=="number"){var Et=!1;Tt.forEach(function(jt){jt.type==="f"&&jt.name==="Duration"&&(Et=!0,jt.data=we(We,8))}),Et||ge(Tt,"Info",[{name:"Duration",type:"f",data:we(We,8)}])}Array.isArray(Le)&&ge(Tt,"Cues",fe(Le,Se));var At=[];return Array.isArray(Je)&&(console.warn("append cluster pointers to seekhead is deprecated. please use cues"),At=se(Je,Se)),ge(Tt,"SeekHead",At,!0),Tt}function se(be,Se){var Me=[];return be.forEach(function(We){Me.push({name:"Seek",type:"m",isEnd:!1}),Me.push({name:"SeekID",type:"b",data:new N.Buffer([31,67,182,117])}),Me.push({name:"SeekPosition",type:"u",data:pe(We+Se)}),Me.push({name:"Seek",type:"m",isEnd:!0})}),Me}function fe(be,Se){var Me=[];return be.forEach(function(We){var Je=We.CueTrack,Le=We.CueClusterPosition,Tt=We.CueTime;Me.push({name:"CuePoint",type:"m",isEnd:!1}),Me.push({name:"CueTime",type:"u",data:pe(Tt)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Me.push({name:"CueTrack",type:"u",data:pe(Je)}),Me.push({name:"CueClusterPosition",type:"u",data:pe(Le+Se)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Me.push({name:"CuePoint",type:"m",isEnd:!0})}),Me}function ge(be,Se,Me,We){We===void 0&&(We=!1);for(var Je=-1,Le=0;Le<be.length;Le++){var Tt=be[Le];if(Tt.type==="m"&&Tt.name===Se&&Tt.isEnd===!1){Je=Le;break}}Je>=0?Array.prototype.splice.apply(be,[Je+1,0].concat(Me)):We?[].concat([{name:Se,type:"m",isEnd:!1}],Me,[{name:Se,type:"m",isEnd:!0}]).reverse().forEach(function(Et){be.unshift(Et)}):(be.push({name:Se,type:"m",isEnd:!1}),Me.forEach(function(Et){be.push(Et)}),be.push({name:Se,type:"m",isEnd:!0}))}function ue(be){return N.Buffer.concat(be)}N.concat=ue;function _e(be){var Se=new N.Buffer(0);if(be.type==="m")return be;switch(be.type){case"u":Se=pe(be.value);break;case"i":Se=ye(be.value);break;case"f":Se=we(be.value);break;case"s":Se=new N.Buffer(be.value,"ascii");break;case"8":Se=new N.Buffer(be.value,"utf8");break;case"b":Se=be.value;break;case"d":Se=new Z.Int64BE(be.value.getTime().toString()).toBuffer();break}return Object.assign({},be,{data:Se})}N.encodeValueToBuffer=_e;function pe(be){for(var Se=1;be>=Math.pow(2,8*Se);Se++);if(Se>=7)return console.warn("7bit or more bigger uint not supported."),new Z.Uint64BE(be).toBuffer();var Me=new N.Buffer(Se);return Me.writeUIntBE(be,0,Se),Me}N.createUIntBuffer=pe;function ye(be){for(var Se=1;be>=Math.pow(2,8*Se);Se++);if(Se>=7)return console.warn("7bit or more bigger uint not supported."),new Z.Int64BE(be).toBuffer();var Me=new N.Buffer(Se);return Me.writeIntBE(be,0,Se),Me}N.createIntBuffer=ye;function we(be,Se){if(Se===void 0&&(Se=8),Se===8){var Me=new N.Buffer(8);return Me.writeDoubleBE(be,0),Me}else if(Se===4){var Me=new N.Buffer(4);return Me.writeFloatBE(be,0),Me}else throw new Error("float type bits must 4bytes or 8bytes")}N.createFloatBuffer=we;function Ie(be){return be instanceof Date?be:new Date(new Date("2001-01-01T00:00:00.000Z").getTime()+Number(be)/1e3/1e3)}N.convertEBMLDateToJSDate=Ie}(tools)),tools}var hasRequiredEBMLDecoder;function requireEBMLDecoder(){if(hasRequiredEBMLDecoder)return EBMLDecoder;hasRequiredEBMLDecoder=1,Object.defineProperty(EBMLDecoder,"__esModule",{value:!0});var N=requireInt64Buffer(),Z=requireTools(),q=requireTools(),J=requireEbmlID(),I;(function(a){a[a.STATE_TAG=1]="STATE_TAG",a[a.STATE_SIZE=2]="STATE_SIZE",a[a.STATE_CONTENT=3]="STATE_CONTENT"})(I||(I={}));var D=function(){function a(){this._buffer=new Z.Buffer(0),this._tag_stack=[],this._state=I.STATE_TAG,this._cursor=0,this._total=0,this._schema=J.byEbmlID,this._result=[]}return a.prototype.decode=function(O){this.readChunk(O);var F=this._result;return this._result=[],F},a.prototype.readChunk=function(O){for(this._buffer=q.concat([this._buffer,new Z.Buffer(O)]);this._cursor<this._buffer.length&&!(this._state===I.STATE_TAG&&!this.readTag()||this._state===I.STATE_SIZE&&!this.readSize()||this._state===I.STATE_CONTENT&&!this.readContent()););},a.prototype.getSchemaInfo=function(O){return this._schema[O]||{name:"unknown",level:-1,type:"unknown",description:"unknown"}},a.prototype.readTag=function(){if(this._cursor>=this._buffer.length)return!1;var O=(0,Z.readVint)(this._buffer,this._cursor);if(O==null)return!1;var F=this._buffer.slice(this._cursor,this._cursor+O.length),z=F.reduce(function(ne,ee,re,ce){return ne+ee*Math.pow(16,2*(ce.length-1-re))},0),K=this.getSchemaInfo(z),te={EBML_ID:z.toString(16),schema:K,type:K.type,name:K.name,level:K.level,tagStart:this._total,tagEnd:this._total+O.length,sizeStart:this._total+O.length,sizeEnd:null,dataStart:null,dataEnd:null,dataSize:null,data:null};return this._tag_stack.push(te),this._cursor+=O.length,this._total+=O.length,this._state=I.STATE_SIZE,!0},a.prototype.readSize=function(){if(this._cursor>=this._buffer.length)return!1;var O=(0,Z.readVint)(this._buffer,this._cursor);if(O==null)return!1;var F=this._tag_stack[this._tag_stack.length-1];return F.sizeEnd=F.sizeStart+O.length,F.dataStart=F.sizeEnd,F.dataSize=O.value,O.value===-1?(F.dataEnd=-1,F.type==="m"&&(F.unknownSize=!0)):F.dataEnd=F.sizeEnd+O.value,this._cursor+=O.length,this._total+=O.length,this._state=I.STATE_CONTENT,!0},a.prototype.readContent=function(){var O=this._tag_stack[this._tag_stack.length-1];if(O.type==="m"){if(O.isEnd=!1,this._result.push(O),this._state=I.STATE_TAG,O.dataSize===0){var F=Object.assign({},O,{isEnd:!0});this._result.push(F),this._tag_stack.pop()}return!0}if(this._buffer.length<this._cursor+O.dataSize)return!1;var z=this._buffer.slice(this._cursor,this._cursor+O.dataSize);switch(this._buffer=this._buffer.slice(this._cursor+O.dataSize),O.data=z,O.type){case"u":O.value=z.readUIntBE(0,z.length);break;case"i":O.value=z.readIntBE(0,z.length);break;case"f":O.value=O.dataSize===4?z.readFloatBE(0):O.dataSize===8?z.readDoubleBE(0):(console.warn("cannot read ".concat(O.dataSize," octets float. failback to 0")),0);break;case"s":O.value=z.toString("ascii");break;case"8":O.value=z.toString("utf8");break;case"b":O.value=z;break;case"d":O.value=(0,Z.convertEBMLDateToJSDate)(new N.Int64BE(z).toNumber());break}if(O.value===null)throw new Error("unknown tag type:"+O.type);for(this._result.push(O),this._total+=O.dataSize,this._state=I.STATE_TAG,this._cursor=0,this._tag_stack.pop();this._tag_stack.length>0;){var K=this._tag_stack[this._tag_stack.length-1];if(K.dataEnd<0)return this._tag_stack.pop(),!0;if(this._total<K.dataEnd)break;if(K.type!=="m")throw new Error("parent element is not master element");var F=Object.assign({},K,{isEnd:!0});this._result.push(F),this._tag_stack.pop()}return!0},a}();return EBMLDecoder.default=D,EBMLDecoder}var EBMLReader={},events={exports:{}},hasRequiredEvents;function requireEvents(){if(hasRequiredEvents)return events.exports;hasRequiredEvents=1;var N=typeof Reflect=="object"?Reflect:null,Z=N&&typeof N.apply=="function"?N.apply:function(_e,pe,ye){return Function.prototype.apply.call(_e,pe,ye)},q;N&&typeof N.ownKeys=="function"?q=N.ownKeys:Object.getOwnPropertySymbols?q=function(_e){return Object.getOwnPropertyNames(_e).concat(Object.getOwnPropertySymbols(_e))}:q=function(_e){return Object.getOwnPropertyNames(_e)};function J(ue){console&&console.warn&&console.warn(ue)}var I=Number.isNaN||function(_e){return _e!==_e};function D(){D.init.call(this)}events.exports=D,events.exports.once=se,D.EventEmitter=D,D.prototype._events=void 0,D.prototype._eventsCount=0,D.prototype._maxListeners=void 0;var a=10;function O(ue){if(typeof ue!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof ue)}Object.defineProperty(D,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(ue){if(typeof ue!="number"||ue<0||I(ue))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+ue+".");a=ue}}),D.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(_e){if(typeof _e!="number"||_e<0||I(_e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+_e+".");return this._maxListeners=_e,this};function F(ue){return ue._maxListeners===void 0?D.defaultMaxListeners:ue._maxListeners}D.prototype.getMaxListeners=function(){return F(this)},D.prototype.emit=function(_e){for(var pe=[],ye=1;ye<arguments.length;ye++)pe.push(arguments[ye]);var we=_e==="error",Ie=this._events;if(Ie!==void 0)we=we&&Ie.error===void 0;else if(!we)return!1;if(we){var be;if(pe.length>0&&(be=pe[0]),be instanceof Error)throw be;var Se=new Error("Unhandled error."+(be?" ("+be.message+")":""));throw Se.context=be,Se}var Me=Ie[_e];if(Me===void 0)return!1;if(typeof Me=="function")Z(Me,this,pe);else for(var We=Me.length,Je=re(Me,We),ye=0;ye<We;++ye)Z(Je[ye],this,pe);return!0};function z(ue,_e,pe,ye){var we,Ie,be;if(O(pe),Ie=ue._events,Ie===void 0?(Ie=ue._events=Object.create(null),ue._eventsCount=0):(Ie.newListener!==void 0&&(ue.emit("newListener",_e,pe.listener?pe.listener:pe),Ie=ue._events),be=Ie[_e]),be===void 0)be=Ie[_e]=pe,++ue._eventsCount;else if(typeof be=="function"?be=Ie[_e]=ye?[pe,be]:[be,pe]:ye?be.unshift(pe):be.push(pe),we=F(ue),we>0&&be.length>we&&!be.warned){be.warned=!0;var Se=new Error("Possible EventEmitter memory leak detected. "+be.length+" "+String(_e)+" listeners added. Use emitter.setMaxListeners() to increase limit");Se.name="MaxListenersExceededWarning",Se.emitter=ue,Se.type=_e,Se.count=be.length,J(Se)}return ue}D.prototype.addListener=function(_e,pe){return z(this,_e,pe,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(_e,pe){return z(this,_e,pe,!0)};function K(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function te(ue,_e,pe){var ye={fired:!1,wrapFn:void 0,target:ue,type:_e,listener:pe},we=K.bind(ye);return we.listener=pe,ye.wrapFn=we,we}D.prototype.once=function(_e,pe){return O(pe),this.on(_e,te(this,_e,pe)),this},D.prototype.prependOnceListener=function(_e,pe){return O(pe),this.prependListener(_e,te(this,_e,pe)),this},D.prototype.removeListener=function(_e,pe){var ye,we,Ie,be,Se;if(O(pe),we=this._events,we===void 0)return this;if(ye=we[_e],ye===void 0)return this;if(ye===pe||ye.listener===pe)--this._eventsCount===0?this._events=Object.create(null):(delete we[_e],we.removeListener&&this.emit("removeListener",_e,ye.listener||pe));else if(typeof ye!="function"){for(Ie=-1,be=ye.length-1;be>=0;be--)if(ye[be]===pe||ye[be].listener===pe){Se=ye[be].listener,Ie=be;break}if(Ie<0)return this;Ie===0?ye.shift():ce(ye,Ie),ye.length===1&&(we[_e]=ye[0]),we.removeListener!==void 0&&this.emit("removeListener",_e,Se||pe)}return this},D.prototype.off=D.prototype.removeListener,D.prototype.removeAllListeners=function(_e){var pe,ye,we;if(ye=this._events,ye===void 0)return this;if(ye.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):ye[_e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete ye[_e]),this;if(arguments.length===0){var Ie=Object.keys(ye),be;for(we=0;we<Ie.length;++we)be=Ie[we],be!=="removeListener"&&this.removeAllListeners(be);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(pe=ye[_e],typeof pe=="function")this.removeListener(_e,pe);else if(pe!==void 0)for(we=pe.length-1;we>=0;we--)this.removeListener(_e,pe[we]);return this};function ne(ue,_e,pe){var ye=ue._events;if(ye===void 0)return[];var we=ye[_e];return we===void 0?[]:typeof we=="function"?pe?[we.listener||we]:[we]:pe?oe(we):re(we,we.length)}D.prototype.listeners=function(_e){return ne(this,_e,!0)},D.prototype.rawListeners=function(_e){return ne(this,_e,!1)},D.listenerCount=function(ue,_e){return typeof ue.listenerCount=="function"?ue.listenerCount(_e):ee.call(ue,_e)},D.prototype.listenerCount=ee;function ee(ue){var _e=this._events;if(_e!==void 0){var pe=_e[ue];if(typeof pe=="function")return 1;if(pe!==void 0)return pe.length}return 0}D.prototype.eventNames=function(){return this._eventsCount>0?q(this._events):[]};function re(ue,_e){for(var pe=new Array(_e),ye=0;ye<_e;++ye)pe[ye]=ue[ye];return pe}function ce(ue,_e){for(;_e+1<ue.length;_e++)ue[_e]=ue[_e+1];ue.pop()}function oe(ue){for(var _e=new Array(ue.length),pe=0;pe<_e.length;++pe)_e[pe]=ue[pe].listener||ue[pe];return _e}function se(ue,_e){return new Promise(function(pe,ye){function we(be){ue.removeListener(_e,Ie),ye(be)}function Ie(){typeof ue.removeListener=="function"&&ue.removeListener("error",we),pe([].slice.call(arguments))}ge(ue,_e,Ie,{once:!0}),_e!=="error"&&fe(ue,we,{once:!0})})}function fe(ue,_e,pe){typeof ue.on=="function"&&ge(ue,"error",_e,pe)}function ge(ue,_e,pe,ye){if(typeof ue.on=="function")ye.once?ue.once(_e,pe):ue.on(_e,pe);else if(typeof ue.addEventListener=="function")ue.addEventListener(_e,function we(Ie){ye.once&&ue.removeEventListener(_e,we),pe(Ie)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof ue)}return events.exports}var hasRequiredEBMLReader;function requireEBMLReader(){if(hasRequiredEBMLReader)return EBMLReader;hasRequiredEBMLReader=1;var N=EBMLReader&&EBMLReader.__extends||function(){var I=function(D,a){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(O,F){O.__proto__=F}||function(O,F){for(var z in F)Object.prototype.hasOwnProperty.call(F,z)&&(O[z]=F[z])},I(D,a)};return function(D,a){if(typeof a!="function"&&a!==null)throw new TypeError("Class extends value "+String(a)+" is not a constructor or null");I(D,a);function O(){this.constructor=D}D.prototype=a===null?Object.create(a):(O.prototype=a.prototype,new O)}}();Object.defineProperty(EBMLReader,"__esModule",{value:!0});var Z=requireEvents(),q=requireTools(),J=function(I){N(D,I);function D(){var a=I.call(this)||this;return a.logGroup="",a.hasLoggingStarted=!1,a.metadataloaded=!1,a.chunks=[],a.stack=[],a.segmentOffset=0,a.last2SimpleBlockVideoTrackTimecode=[0,0],a.last2SimpleBlockAudioTrackTimecode=[0,0],a.lastClusterTimecode=0,a.lastClusterPosition=0,a.timecodeScale=1e6,a.metadataSize=0,a.metadatas=[],a.cues=[],a.firstVideoBlockRead=!1,a.firstAudioBlockRead=!1,a.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null},a.trackTypes=[],a.trackDefaultDuration=[],a.trackCodecDelay=[],a.trackInfo={type:"nothing"},a.ended=!1,a.logging=!1,a.use_duration_every_simpleblock=!1,a.use_webp=!1,a.use_segment_info=!0,a.drop_default_duration=!0,a}return D.prototype.stop=function(){for(this.ended=!0,this.emit_segment_info();this.stack.length;)this.stack.pop(),this.logging&&console.groupEnd();this.logging&&this.hasLoggingStarted&&this.logGroup&&console.groupEnd()},D.prototype.emit_segment_info=function(){var a=this.chunks;if(this.chunks=[],this.metadataloaded){if(!this.use_segment_info)return;var z=this.lastClusterTimecode,K=this.duration,te=this.timecodeScale;this.emit("cluster",{timecode:z,data:a}),this.emit("duration",{timecodeScale:te,duration:K})}else{this.metadataloaded=!0,this.metadatas=a;var O=this.trackTypes.indexOf(1),F=this.trackTypes.indexOf(2);if(this.trackInfo=O>=0&&F>=0?{type:"both",trackNumber:O}:O>=0?{type:"video",trackNumber:O}:F>=0?{type:"audio",trackNumber:F}:{type:"nothing"},!this.use_segment_info)return;this.emit("metadata",{data:a,metadataSize:this.metadataSize})}},D.prototype.read=function(a){var O=this,F=!1;if(!this.ended){if(a.type==="m")if(a.isEnd)this.stack.pop();else{var z=this.stack[this.stack.length-1];if(z!=null&&z.level>=a.level){this.stack.pop(),this.logging&&console.groupEnd(),z.dataEnd=a.dataEnd,z.dataSize=a.dataEnd-z.dataStart,z.unknownSize=!1;var K=Object.assign({},z,{name:z.name,type:z.type,isEnd:!0});this.chunks.push(K)}this.stack.push(a)}if(a.type==="m"&&a.name=="Segment")this.segmentOffset!=0&&console.warn("Multiple segments detected!"),this.segmentOffset=a.dataStart,this.emit("segment_offset",this.segmentOffset);else if(a.type==="b"&&a.name==="SimpleBlock"){var te=q.ebmlBlock(a.data),ne=te.timecode,ee=te.trackNumber,re=te.frames;if(this.trackTypes[ee]===1){if(!this.firstVideoBlockRead&&(this.firstVideoBlockRead=!0,this.trackInfo.type==="both"||this.trackInfo.type==="video")){var ce=this.lastClusterTimecode+ne;this.cues.push({CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce}),this.emit("cue_info",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce})}this.last2SimpleBlockVideoTrackTimecode=[this.last2SimpleBlockVideoTrackTimecode[1],ne]}else if(this.trackTypes[ee]===2){if(!this.firstAudioBlockRead&&(this.firstAudioBlockRead=!0,this.trackInfo.type==="audio")){var ce=this.lastClusterTimecode+ne;this.cues.push({CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce}),this.emit("cue_info",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:ee,CueClusterPosition:this.lastClusterPosition,CueTime:ce})}this.last2SimpleBlockAudioTrackTimecode=[this.last2SimpleBlockAudioTrackTimecode[1],ne]}this.use_duration_every_simpleblock&&this.emit("duration",{timecodeScale:this.timecodeScale,duration:this.duration}),this.use_webp&&re.forEach(function(oe){var se=oe.slice(3,6).toString("hex");if(se==="9d012a"){var fe=q.VP8BitStreamToRiffWebPBuffer(oe),ge=new Blob([fe],{type:"image/webp"}),ue=O.duration;O.emit("webp",{currentTime:ue,webp:ge})}})}else a.type==="m"&&a.name==="Cluster"&&a.isEnd===!1?(this.firstVideoBlockRead=!1,this.firstAudioBlockRead=!1,this.emit_segment_info(),this.emit("cluster_ptr",a.tagStart),this.lastClusterPosition=a.tagStart):a.type==="u"&&a.name==="Timecode"?this.lastClusterTimecode=a.value:a.type==="u"&&a.name==="TimecodeScale"?this.timecodeScale=a.value:a.type==="m"&&a.name==="TrackEntry"?a.isEnd?(this.trackTypes[this.currentTrack.TrackNumber]=this.currentTrack.TrackType,this.trackDefaultDuration[this.currentTrack.TrackNumber]=this.currentTrack.DefaultDuration,this.trackCodecDelay[this.currentTrack.TrackNumber]=this.currentTrack.CodecDelay):this.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null}:a.type==="u"&&a.name==="TrackType"?this.currentTrack.TrackType=a.value:a.type==="u"&&a.name==="TrackNumber"?this.currentTrack.TrackNumber=a.value:a.type==="u"&&a.name==="CodecDelay"?this.currentTrack.CodecDelay=a.value:a.type==="u"&&a.name==="DefaultDuration"?this.drop_default_duration?(console.warn("DefaultDuration detected!, remove it"),F=!0):this.currentTrack.DefaultDuration=a.value:a.name==="unknown"&&console.warn(a);!this.metadataloaded&&a.dataEnd>0&&(this.metadataSize=a.dataEnd),F||this.chunks.push(a),this.logging&&this.put(a)}},Object.defineProperty(D.prototype,"duration",{get:function(){if(this.trackInfo.type==="nothing")return console.warn("no video, no audio track"),0;var a=0,O=0,F=0,z=this.trackDefaultDuration[this.trackInfo.trackNumber];if(typeof z=="number")a=z;else if(this.trackInfo.type==="both")if(this.last2SimpleBlockAudioTrackTimecode[1]>this.last2SimpleBlockVideoTrackTimecode[1]){a=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackTypes.indexOf(2)];typeof K=="number"&&(O=K),F=this.last2SimpleBlockAudioTrackTimecode[1]}else{a=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackTypes.indexOf(1)];typeof K=="number"&&(O=K),F=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="video"){a=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackInfo.trackNumber];typeof K=="number"&&(O=K),F=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="audio"){a=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var K=this.trackCodecDelay[this.trackInfo.trackNumber];typeof K=="number"&&(O=K),F=this.last2SimpleBlockAudioTrackTimecode[1]}var te=(this.lastClusterTimecode+F)*this.timecodeScale+a-O,ne=te/this.timecodeScale;return Math.floor(ne)},enumerable:!1,configurable:!0}),D.prototype.addListener=function(a,O){return I.prototype.addListener.call(this,a,O)},D.prototype.put=function(a){this.hasLoggingStarted||(this.hasLoggingStarted=!0,this.logging&&this.logGroup&&console.groupCollapsed(this.logGroup)),a.type==="m"?a.isEnd?console.groupEnd():console.group(a.name+":"+a.tagStart):a.type==="b"?console.log(a.name,a.type):console.log(a.name,a.tagStart,a.type,a.value)},D}(Z.EventEmitter);return EBMLReader.default=J,EBMLReader}var hasRequiredEbml;function requireEbml(){return hasRequiredEbml||(hasRequiredEbml=1,function(N){var Z=ebml&&ebml.__createBinding||(Object.create?function(O,F,z,K){K===void 0&&(K=z),Object.defineProperty(O,K,{enumerable:!0,get:function(){return F[z]}})}:function(O,F,z,K){K===void 0&&(K=z),O[K]=F[z]}),q=ebml&&ebml.__exportStar||function(O,F){for(var z in O)z!=="default"&&!Object.prototype.hasOwnProperty.call(F,z)&&Z(F,O,z)};Object.defineProperty(N,"__esModule",{value:!0}),N.tools=N.Reader=N.Encoder=N.Decoder=void 0,q(requireEBML(),N);var J=requireEBMLDecoder();N.Decoder=J.default;var I=requireEBMLEncoder();N.Encoder=I.default;var D=requireEBMLReader();N.Reader=D.default;var a=requireTools();N.tools=a}(ebml)),ebml}var hasRequiredLib;function requireLib(){if(hasRequiredLib)return lib;hasRequiredLib=1;var N=lib&&lib.__awaiter||function(I,D,a,O){function F(z){return z instanceof a?z:new a(function(K){K(z)})}return new(a||(a=Promise))(function(z,K){function te(re){try{ee(O.next(re))}catch(ce){K(ce)}}function ne(re){try{ee(O.throw(re))}catch(ce){K(ce)}}function ee(re){re.done?z(re.value):F(re.value).then(te,ne)}ee((O=O.apply(I,D||[])).next())})},Z=lib&&lib.__generator||function(I,D){var a={label:0,sent:function(){if(z[0]&1)throw z[1];return z[1]},trys:[],ops:[]},O,F,z,K;return K={next:te(0),throw:te(1),return:te(2)},typeof Symbol=="function"&&(K[Symbol.iterator]=function(){return this}),K;function te(ee){return function(re){return ne([ee,re])}}function ne(ee){if(O)throw new TypeError("Generator is already executing.");for(;a;)try{if(O=1,F&&(z=ee[0]&2?F.return:ee[0]?F.throw||((z=F.return)&&z.call(F),0):F.next)&&!(z=z.call(F,ee[1])).done)return z;switch(F=0,z&&(ee=[ee[0]&2,z.value]),ee[0]){case 0:case 1:z=ee;break;case 4:return a.label++,{value:ee[1],done:!1};case 5:a.label++,F=ee[1],ee=[0];continue;case 7:ee=a.ops.pop(),a.trys.pop();continue;default:if(z=a.trys,!(z=z.length>0&&z[z.length-1])&&(ee[0]===6||ee[0]===2)){a=0;continue}if(ee[0]===3&&(!z||ee[1]>z[0]&&ee[1]<z[3])){a.label=ee[1];break}if(ee[0]===6&&a.label<z[1]){a.label=z[1],z=ee;break}if(z&&a.label<z[2]){a.label=z[2],a.ops.push(ee);break}z[2]&&a.ops.pop(),a.trys.pop();continue}ee=D.call(I,a)}catch(re){ee=[6,re],F=0}finally{O=z=0}if(ee[0]&5)throw ee[1];return{value:ee[0]?ee[1]:void 0,done:!0}}};Object.defineProperty(lib,"__esModule",{value:!0});var q=requireEbml();function J(I){return N(this,void 0,void 0,function(){var D,a,O,F,z,K,te,ne,ee,re,ce,oe;return Z(this,function(se){switch(se.label){case 0:if(!I)throw Error("call to fixWebmDuration requires a blob");D=new q.Decoder,a=new q.Reader,O=I.stream(),F=O.getReader(),se.label=1;case 1:return[4,F.read()];case 2:return z=se.sent(),K=z.done,te=z.value,K?(a.stop(),[3,3]):(ne=D.decode(te),ne=ne==null?void 0:ne.filter(function(fe){return fe.type!=="unknown"}),ne.forEach(function(fe){a.read(fe)}),te=null,[3,1]);case 3:return ee=q.tools.makeMetadataSeekable(a.metadatas,a.duration,a.cues),re=new Blob([ee],{type:I.type}),ce=I.slice(a.metadataSize),oe=new Blob([re,ce],{type:I.type}),[2,oe]}})})}return lib.default=J,lib}var libExports=requireLib();const fixWebmDuration=getDefaultExportFromCjs(libExports);class StreamRecorder{constructor(){at(this,Xt);at(this,mn,!1);at(this,hn,!1);at(this,In,0);at(this,xn,0);at(this,sn,0);at(this,ln,0);at(this,yn,0);Ee(this,"onchange",Z=>{});Ee(this,"onDurationChange",Z=>{});Ee(this,"start",async(Z="")=>{Z||(Z=`video_Record_${E$1(Date.now())}`);let q=[];return navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}).then(J=>{const I=J.getTracks();for(const a of I)a.onended=()=>this.stop();Ct(this,mn,!0),Ct(this,hn,!1),Ct(this,Xt,new MediaRecorder(J)),De(this,Xt).start();const D=new Date().getTime();Ct(this,In,D),Ct(this,sn,D),De(this,vn).call(this),De(this,Rn).call(this),De(this,Xt).addEventListener("dataavailable",a=>{q.push(a.data)}),De(this,Xt).addEventListener("stop",async()=>{Ct(this,mn,!1);const a=new Date().getTime();Ct(this,xn,a),Ct(this,ln,De(this,ln)+(a-De(this,sn))),De(this,vn).call(this),clearInterval(De(this,yn));const O=J.getTracks();for(const ne of O)ne.stop();if(De(this,Xt)===null)return;const F=new Blob(q,{type:De(this,Xt).mimeType}),z=await fixWebmDuration(F),K=URL.createObjectURL(z),te=document.createElement("a");te.href=K,te.download=`${Z}.mp4`,te.click(),URL.revokeObjectURL(K),q=[],Ct(this,Xt,null)})})});Ee(this,"pause",async()=>{var q;await new Promise(J=>setTimeout(()=>J(!0),300)),(q=De(this,Xt))==null||q.pause(),Ct(this,hn,!0);const Z=new Date().getTime();Ct(this,ln,De(this,ln)+(Z-De(this,sn))),De(this,vn).call(this),clearInterval(De(this,yn))});Ee(this,"resume",async()=>{var q;(q=De(this,Xt))==null||q.resume(),Ct(this,hn,!1);const Z=new Date().getTime();Ct(this,sn,Z),De(this,vn).call(this),De(this,Rn).call(this)});Ee(this,"stop",async()=>{var Z;(Z=De(this,Xt))==null||Z.stop()});Ee(this,"getDuration",()=>{if(De(this,sn)===0)return 0;let Z=De(this,ln);const q=new Date().getTime();if(De(this,mn)&&De(this,hn)===!1){const J=q-De(this,sn);Ct(this,sn,q),Z=Z+J}return Z});Ee(this,"getInfo",()=>({active:De(this,mn),pause:De(this,hn),startTime:De(this,In),endTime:De(this,xn),duration:De(this,ln)}));at(this,vn,()=>{const Z=this.getInfo();this.onchange(Z)});at(this,Rn,()=>{clearInterval(De(this,yn)),Ct(this,yn,window.setInterval(()=>{Ct(this,ln,this.getDuration()),this.onDurationChange(De(this,ln))},500))})}}Xt=new WeakMap,mn=new WeakMap,hn=new WeakMap,In=new WeakMap,xn=new WeakMap,sn=new WeakMap,ln=new WeakMap,yn=new WeakMap,vn=new WeakMap,Rn=new WeakMap;class RoomBase{constructor(Z){Ee(this,"options",{appid:"",sdkToken:"",roomId:"",userId:"",earlyId:"",callType:0,debug:!1,reportErr:!0,logUrl:"https://logs1.quickvo.org",newPublishAutoSubscribe:!0});Ee(this,"sdk_service_version","1.0.6");Ee(this,"prohibitNotify",!1);Ee(this,"isEarly",!1);Ee(this,"isInRoom",!1);Ee(this,"taskQueue");Ee(this,"roomState","ready");Ee(this,"createAt",Date.now());Ee(this,"cwsIns");Ee(this,"peerIns");Ee(this,"transceiverMap",new Map);Ee(this,"sendChannel");Ee(this,"receiveChannel");Ee(this,"userMap",new Map);Ee(this,"setLocalStreamActiveMap",new Map);Ee(this,"phoneyStreams",new Map);Ee(this,"recorder",new StreamRecorder);Ee(this,"networkQualityTester",new NetworkQualityTester);Ee(this,"mediaDevicesErrInfo",{microphoneCamera_audio:"",microphoneCamera_video:"",screenSharing_video:"",screenSharing_audio:""});Ee(this,"reportLogs",(Z,q="未知错误")=>{const{appid:J,userId:I,earlyId:D="",logUrl:a,reportErr:O}=this.options;if(!O)return;const F="web",z=K=>({ws_c_timeout:0,webrtc_c_timeout:1,join_room_error:2,publish_error:3,subscribe_error:4,close_track_error:5,heartbeat_e_timeout:6,heartbeat_i_timeout:7,quit_room_error:8})[K].toString();{const K=z(Z),te={origin:F,type:K,app_id:J,user_id:I,ins_id:D,desc:q},ne=btoa(encodeURI(JSON.stringify(te))),ee=`${a}/upload/log?log_key=${ne}`;{const re=localStorage.getItem("#quickvo.logs")||JSON.stringify([]),oe=new TextEncoder().encode(re),se=pako.deflate(oe,{gzip:!0});this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: reportLogs",{obj:te,url:ee,size:lt(se.byteLength)}),fetch(ee,{headers:{"Content-Type":"multipart/form-data"},method:"POST",body:se})}}});Ee(this,"initPhoneyStreams",(Z,q=[])=>{q.length===0&&(q=mediaType_keys);for(const J of q){const I=this.phoneyStreams.get(J);if(I){const D=I.getTracks();for(const a of D)a.stop()}switch(J){case"microphoneCamera_audio":this.phoneyStreams.set("microphoneCamera_audio",createMutedAudioStream(Z));break;case"microphoneCamera_video":this.phoneyStreams.set("microphoneCamera_video",createFakeVideoStream());break;case"screenSharing_audio":this.phoneyStreams.set("screenSharing_audio",createMutedAudioStream(Z));break;case"screenSharing_video":this.phoneyStreams.set("screenSharing_video",createFakeVideoStream());break}}});Ee(this,"getPhoneyStreams",Z=>this.phoneyStreams.get(Z));Ee(this,"getRoomInfo",()=>{const{options:Z,roomState:q,createAt:J}=this;return{...Z,roomState:q,createAt:J}});Ee(this,"setRoomState",Z=>{this.roomState=Z;const q=enum_roomState[Z],J={state:Z,stateStr:q};this.cwsIns.emitNotify("onRoomState",{code:200,data:J,desc:"room state is change."})});Ee(this,"setOptions",async Z=>{const q={...this.options,...Z};this.options=q});Ee(this,"stopStream",async Z=>{const q=Z.getTracks();for(const J of q)J.stop()});Ee(this,"getMediaDevicesErrInfo",async()=>{try{const Z=await navigator.mediaDevices.enumerateDevices();Z.find(J=>J.kind==="audioinput")||(this.mediaDevicesErrInfo.microphoneCamera_audio="audioinput is not available."),Z.find(J=>J.kind==="videoinput")||(this.mediaDevicesErrInfo.microphoneCamera_video="videoinput is not available.")}catch(Z){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getMediaDevicesErrInfo is error.",Z)}return this.mediaDevicesErrInfo});Ee(this,"getUserMediaKey",(Z,q)=>`${Z}-${q}`);Ee(this,"getCallAction",async Z=>{let q="";const J=D=>Z.findIndex(({type:O,enabled:F=!0})=>O===D&&F)===-1?"0":"1";return q=`${J(0)}${q}`,q=`${J(1)}${q}`,q=`${J(2)}${q}`,q=`${J(3)}${q}`,parseInt(q,2)});Ee(this,"getCallActionMap",(Z=0)=>{const J=Number(Z).toString(2).padStart(4,"0").split(""),[I,D,a,O]=J;return{microphoneCamera_audio:!!Number(O),microphoneCamera_video:!!Number(a),screenSharing_video:!!Number(D),screenSharing_audio:!!Number(I)}});Ee(this,"getBanBehaviorMap",(Z=0)=>{const J=Number(Z).toString(2).padStart(4,"0").split(""),[I,D,a,O]=J;return{microphoneCamera_audio:!!Number(O),microphoneCamera_video:!!Number(a),screenSharing_video:!!Number(D),screenSharing_audio:!!Number(I)}});Ee(this,"getAverageVolume",(Z,q)=>{Z.getByteFrequencyData(q);let J=0;for(let D=0;D<q.length;D++)J+=q[D];return Math.ceil(J/q.length)});Ee(this,"getTrackNamesFormTracks",(Z,q=[],J="trackName")=>{const I=[];for(const D of Z){const{type:a}=D;if(q.length===0||q.includes(a)){const O=D[J];O&&I.push(`${O}`)}}return I});Ee(this,"usersFilter",Z=>dt(Z,["id","isSelf","isOwner","joinTime","tracks","network","permissions","isPublished","updateStreams","callAction","callActionStr","callActionMap","banBehavior","banBehaviorStr","banBehaviorMap"]).sort((I,D)=>I.id.localeCompare(D.id,"en")));this.setOptions(Z),this.cwsIns=new CallsWebSocket({...Z}),this.taskQueue=new Y(["createWs","createSession","ice","joinRoom","createTrack","publish","subscribe","renegotiate","closeTrack"],{debug:Z.debug}),this.taskQueue.setCondition("createSession",!1),this.taskQueue.setCondition("ice",!1),this.options.debug&&this.networkQualityTester.testAll().then(q=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: networkQualityTester",q)})}}var m=Object.defineProperty,G=(N,Z,q)=>Z in N?m(N,Z,{enumerable:!0,configurable:!0,writable:!0,value:q}):N[Z]=q,e$1=(N,Z,q)=>G(N,typeof Z!="symbol"?Z+"":Z,q);class g{constructor(Z,q){e$1(this,"inputStream",new MediaStream),e$1(this,"outputStream",new MediaStream),e$1(this,"inputGain",1),e$1(this,"enhanceGain",1),e$1(this,"bgsGain",1),e$1(this,"bgmGain",1),e$1(this,"outputGain",1),e$1(this,"mixAudioMap",new Map),e$1(this,"audioContext",new AudioContext),e$1(this,"sourceNode"),e$1(this,"inputGainNode"),e$1(this,"enhanceGainNode"),e$1(this,"bgsGainNode"),e$1(this,"bgmGainNode"),e$1(this,"analyserNode"),e$1(this,"analyserArrayData"),e$1(this,"outputGainNode"),e$1(this,"destinationNode"),e$1(this,"filterStream",J=>J),e$1(this,"stop",()=>{{const J=this.inputStream.getTracks();for(const I of J)I.stop(),this.inputStream.removeTrack(I)}}),e$1(this,"getStream",()=>this.filterStream(this.outputStream)),e$1(this,"setMute",(J=!0)=>{J?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),e$1(this,"setInputGain",J=>{this.inputGain=J,this.inputGainNode.gain.setValueAtTime(J,this.audioContext.currentTime)}),e$1(this,"setEnhanceGain",async J=>{this.enhanceGain=J+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),e$1(this,"setBgsGain",J=>{this.bgsGain=J,this.bgsGainNode.gain.setValueAtTime(J,this.audioContext.currentTime)}),e$1(this,"setBgmGain",J=>{this.bgmGain=J,this.bgmGainNode.gain.setValueAtTime(J,this.audioContext.currentTime)}),e$1(this,"setOutputGain",J=>{this.outputGain=J,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),e$1(this,"getVolume",()=>{const{analyserNode:J,analyserArrayData:I}=this;J.getByteFrequencyData(I);let D=0;for(let a=0;a<I.length;a++)D+=I[a];return Math.ceil(D/I.length)}),e$1(this,"mixAudio",(J,I="bgm")=>new Promise(async(D,a)=>{try{{const z=this.mixAudioMap.get(I);z&&z.stop()}const O=I==="bgs"?this.bgsGainNode:this.bgmGainNode,F=this.audioContext.createBufferSource();this.mixAudioMap.set(I,F),F.buffer=J,F.connect(O),F.onended=()=>{F.disconnect(O),this.mixAudioMap.delete(I),D(!0)},F.start(0)}catch(O){a(O)}})),e$1(this,"mixAudioStop",J=>{const I=this.mixAudioMap.get(J);I==null||I.stop()}),e$1(this,"changeMix",(J,I)=>{const D=J==="bgs"?this.bgsGainNode:this.bgmGainNode;I?D.connect(this.destinationNode):D.disconnect(this.destinationNode)}),q&&(this.audioContext=q),this.inputStream=Z,this.sourceNode=this.audioContext.createMediaStreamSource(this.inputStream),this.inputGainNode=this.audioContext.createGain(),this.inputGainNode.gain.setValueAtTime(this.inputGain,this.audioContext.currentTime),this.enhanceGainNode=this.audioContext.createGain(),this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime),this.bgsGainNode=this.audioContext.createGain(),this.bgsGainNode.gain.setValueAtTime(this.bgsGain,this.audioContext.currentTime),this.bgmGainNode=this.audioContext.createGain(),this.bgmGainNode.gain.setValueAtTime(this.bgmGain,this.audioContext.currentTime),this.analyserNode=this.audioContext.createAnalyser(),this.analyserNode.fftSize=512,this.analyserArrayData=new Uint8Array(this.analyserNode.frequencyBinCount),this.outputGainNode=this.audioContext.createGain(),this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime),this.destinationNode=this.audioContext.createMediaStreamDestination(),this.outputStream=this.destinationNode.stream;{const{sourceNode:J,inputGainNode:I,enhanceGainNode:D,bgsGainNode:a,bgmGainNode:O,analyserNode:F,outputGainNode:z,destinationNode:K}=this;J.connect(I),I.connect(D),D.connect(F),a.connect(F),O.connect(F),D.connect(K),a.connect(K),O.connect(K),F.connect(z),z.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}class RoomMedias extends RoomBase{constructor(q){super(q);at(this,wn,[]);at(this,en,new Map);at(this,Ht,new Map);at(this,cn,new Map);at(this,un,new Map);at(this,pn,new Map);Ee(this,"localStreamsActionMap",new Map);at(this,kn,new Map);Ee(this,"audioContext",new(window.AudioContext||window.webkitAudioContext));Ee(this,"initMediaPhoneyStreams",(q=[])=>this.initPhoneyStreams(this.audioContext,q));Ee(this,"initLocalStreamsFilter",()=>{for(const q of mediaType_keys){const J=async I=>I;De(this,kn).set(q,J)}});Ee(this,"setLocalFilterStream",(q,J)=>{De(this,kn).set(q,J)});at(this,Un,()=>{De(this,Ht).set("microphoneCamera_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0}),De(this,Ht).set("microphoneCamera_video",{frameRate:{min:10,ideal:30}}),De(this,Ht).set("screenSharing_video",{frameRate:{min:10,ideal:30}}),De(this,Ht).set("screenSharing_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0})});at(this,Ln,()=>{De(this,en).set("audioinput","default"),De(this,en).set("videoinput","default"),De(this,en).set("audiooutput","default")});Ee(this,"emitNotifyUpdateUsersStreams",async q=>{this.cwsIns.emitNotify("onRoomUsersStreams",{code:200,data:q,desc:"users streams is change."})});Ee(this,"initUserMediaStreamContext",async(q,J,I)=>{const[D]=I.getTracks();if(!D){console.warn("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: tracks.length is 0.",{userId:q,mediaType:J,stream:I});return}this.removeUserMediaStreamContext(q,J);const a=this.getUserMediaKey(q,J),{kind:O}=D;switch(O){case"audio":{const F=new MediaStream;F.addTrack(D);const z=new g(F,this.audioContext);De(this,cn).set(a,z)}break;case"video":{const F=new VideoMediaContext(D);De(this,un).set(a,F)}break}});Ee(this,"getUserMediaStreamContext",(q,J)=>{const I=this.getUserMediaKey(q,J);if(["microphoneCamera_audio","screenSharing_audio"].includes(J))return De(this,cn).get(I);if(["microphoneCamera_video","screenSharing_video"].includes(J))return De(this,un).get(I)});Ee(this,"getUserAudioMediaStreamContext",(q,J)=>{const I=this.getUserMediaKey(q,J);return De(this,cn).get(I)});Ee(this,"removeUserMediaStreamContext",(q,J)=>{const I=this.getUserMediaKey(q,J);if(["microphoneCamera_audio","screenSharing_audio"].includes(J)){const D=De(this,cn).get(I);return D==null||D.stop(),De(this,cn).delete(I)}if(["microphoneCamera_video","screenSharing_video"].includes(J)){const D=De(this,un).get(I);return D==null||D.stop(),De(this,un).get(I)}});Ee(this,"getUserStream",(q,J)=>{const I=this.getUserMediaStreamContext(q,J);return(I==null?void 0:I.getStream())||new MediaStream});Ee(this,"getUserStreams",(q,J=[])=>{J.length===0&&(J=mediaType_keys);const I={};for(const D of J){const a=this.getUserStream(q,D);I[D]=a}return I});Ee(this,"removeUserStreams",async(q,J=[])=>{J.length===0&&(J=mediaType_keys);for(const I of J)this.removeUserMediaStreamContext(q,I)});Ee(this,"clearUserStreams",()=>{{const q=De(this,cn).values();for(const J of q)J.stop();Ct(this,cn,new Map)}{const q=De(this,un).values();for(const J of q)J.stop();Ct(this,un,new Map)}});Ee(this,"setMediaTrackConstraints",async(q,J)=>{De(this,Ht).set(q,J);const I=await this.getLocalStream(q);if(!I)return;const D=I.getTracks();if(D.length!==0)for(const a of D){const O=a.getConstraints(),z={...De(this,Ht).get(q),...O,...J};await a.applyConstraints(z)}});Ee(this,"stopLocalStreams",async(q=[])=>{q.length===0&&(q=mediaType_keys);for(const J of q){const I=De(this,pn).get(J);I&&await this.stopStream(I),De(this,pn).delete(J)}});Ee(this,"addLocalStream",(q,J)=>{const I=De(this,pn).get(q);I&&this.stopStream(I),De(this,pn).set(q,J)});Ee(this,"initLocalStream",async q=>{switch(q){case"microphoneCamera_audio":{const J=De(this,en).get("audioinput"),I=De(this,Ht).get("microphoneCamera_audio"),D=await navigator.mediaDevices.getUserMedia({audio:{deviceId:J,...I},video:!1});this.addLocalStream("microphoneCamera_audio",D)}break;case"microphoneCamera_video":{const J=De(this,en).get("videoinput"),I=De(this,Ht).get("microphoneCamera_video"),D=await navigator.mediaDevices.getUserMedia({audio:!1,video:{deviceId:J,...I}});this.addLocalStream("microphoneCamera_video",D)}break;case"microphoneCamera":{const J=De(this,en).get("audioinput"),I=De(this,en).get("videoinput"),D=De(this,Ht).get("microphoneCamera_audio"),a=De(this,Ht).get("microphoneCamera_video"),F=(await navigator.mediaDevices.getUserMedia({audio:{deviceId:J,...D},video:{deviceId:I,...a}})).getTracks();for(const z of F){const{kind:K}=z;if(K==="audio"){const te=new MediaStream;te.addTrack(z),this.addLocalStream("microphoneCamera_audio",te)}if(K==="video"){const te=new MediaStream;te.addTrack(z),this.addLocalStream("microphoneCamera_video",te)}}}break;case"screenSharing_audio":{const J=De(this,Ht).get("screenSharing_audio"),D=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...J})).getTracks();for(const a of D){const{kind:O}=a;if(O==="audio"){const F=new MediaStream;F.addTrack(a),this.addLocalStream("screenSharing_audio",F)}}}break;case"screenSharing_video":{const J=De(this,Ht).get(q),D=(await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0,...J})).getTracks();for(const a of D){const{kind:O}=a;if(O==="video"){const F=new MediaStream;F.addTrack(a),this.addLocalStream("screenSharing_video",F)}}}break;case"screenSharing":{const J=De(this,Ht).get("screenSharing_audio"),I=De(this,Ht).get("screenSharing_video"),a=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...J,...I})).getTracks();for(const O of a){const{kind:F}=O;if(F==="audio"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_audio",z)}if(F==="video"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_video",z)}}}break}});Ee(this,"getLocalStream",async q=>{const J=De(this,pn).get(q),I=De(this,kn).get(q);let D=J;return J&&I&&(D=await I(J)),D});Ee(this,"getLocalStreams",async(q=[])=>{q.length===0&&(q=mediaType_keys);const J={};for(const I of q)J[I]=await this.getLocalStream(I);return J});at(this,Sn,async()=>!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices?(console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 不支持 enumerateDevices"),[]):(await navigator.mediaDevices.enumerateDevices().then(q=>{const J=q.filter(I=>!["communications"].includes(I.deviceId));Ct(this,wn,J.sort((I,D)=>I.label.localeCompare(D.label,"zh-Hans-CN",{sensitivity:"accent"})))}).catch(function(q){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getEnumerateDevices is err",q)}),De(this,wn)));at(this,Fn,()=>{navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=async()=>{await De(this,Sn).call(this),this.cwsIns.emitNotify("onDevicechange",{code:200,data:{},desc:"device is change."})}),De(this,Sn).call(this)});Ee(this,"getMediaDeviceKind",q=>De(this,en).get(q));Ee(this,"changeAudiooutput",async()=>{try{const q=De(this,en).get("audiooutput");await this.audioContext.setSinkId(q)}catch(q){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSinkId is error.",q)}});Ee(this,"setDeviceKind",(q,J)=>{De(this,en).set(q,J)});Ee(this,"setAudioOutputDevice",q=>this.setDeviceKind("audiooutput",q));Ee(this,"getEnumerateDevices",async q=>(await De(this,Sn).call(this),De(this,wn).filter(I=>I.kind===q)));Ee(this,"getEnumerateAudioinputDevices",()=>this.getEnumerateDevices("audioinput"));Ee(this,"getEnumerateAudioOutputDevices",()=>this.getEnumerateDevices("audiooutput"));Ee(this,"getEnumerateVideoinputDevices",()=>this.getEnumerateDevices("videoinput"));De(this,Fn).call(this),De(this,Ln).call(this),De(this,Un).call(this),this.initPhoneyStreams(this.audioContext),document.addEventListener("click",()=>{var J;((J=this.audioContext)==null?void 0:J.state)==="suspended"&&this.audioContext.resume()})}}wn=new WeakMap,en=new WeakMap,Ht=new WeakMap,cn=new WeakMap,un=new WeakMap,pn=new WeakMap,kn=new WeakMap,Un=new WeakMap,Ln=new WeakMap,Sn=new WeakMap,Fn=new WeakMap;class RoomUsers extends RoomMedias{constructor(q){super(q);Ee(this,"getMaxVolumeUser",()=>{const q=Array.from(this.userMap.values(),({id:I})=>I);if(q.length===0)return;let J=[];for(const I of q){const D=this.getUserAudioMediaStreamContext(I,"microphoneCamera_audio");if(!D)continue;const a=D.getVolume();J.push({id:I,volume:a})}return J=J.sort((I,D)=>I.volume-D.volume>0?-1:1),J[0]});Ee(this,"setVolume",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setInputGain(I)});Ee(this,"setEnhanceGain",async(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setEnhanceGain(I)});Ee(this,"setSpeaker",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setOutputGain(I);const a=I===0;D==null||D.setMute(a)});Ee(this,"playBgs",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);return D==null?void 0:D.mixAudio(I,"bgs")});Ee(this,"setBgsGain",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setBgsGain(I)});Ee(this,"stopBgs",(q,J)=>{const I=this.getUserAudioMediaStreamContext(q,J);I==null||I.mixAudioStop("bgs")});Ee(this,"playBgm",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);return D==null?void 0:D.mixAudio(I,"bgm")});Ee(this,"setBgmGain",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.setBgmGain(I)});Ee(this,"stopBgm",(q,J)=>{const I=this.getUserAudioMediaStreamContext(q,J);I==null||I.mixAudioStop("bgm")});Ee(this,"changBgsMix",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.changeMix("bgs",I)});Ee(this,"changBgmMix",(q,J,I)=>{const D=this.getUserAudioMediaStreamContext(q,J);D==null||D.changeMix("bgm",I)});Ee(this,"getVolume",(q,J)=>{const I=this.getUserAudioMediaStreamContext(q,J);return I==null?void 0:I.getVolume()});Ee(this,"clearUsers",()=>{this.userMap=new Map});Ee(this,"removeUsers",async q=>{for(const J of q)this.userMap.delete(J),await this.removeUserStreams(J)});Ee(this,"createUser",async q=>{const J=Date.now(),I={id:q,permissions:0,callAction:0,callActionStr:"",callActionMap:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1},banBehavior:0,banBehaviorStr:"",banBehaviorMap:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1},callState:0,isOwner:this.userMap.size===0,isSelf:q===this.options.userId,isPublished:!1,joinTime:J,updateAt:J,network:{egress:0,ingress:0},tracks:[],channels:[],updateStreams:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1}};this.userMap.set(q,I)});Ee(this,"getUser",async q=>(this.userMap.has(q)||await this.createUser(q),this.userMap.get(q)));Ee(this,"getUsers",async(q=[])=>{q.length===0&&(q=[...this.userMap.keys()]);const J=[];for(const I of q){const D=await this.getUser(I);J.push(D)}return J});Ee(this,"getAllUserTrackMids",async()=>{const q=await this.getUsers(),J=[];for(const I of q){const{tracks:D=[]}=I;for(const a of D)J.push(a.mid)}return J});Ee(this,"getUserTrackByTrackName",async q=>{const J=await this.getUsers(),I=[];for(const D of J){const{tracks:a=[]}=D;for(const O of a){const{trackName:F}=O;q.includes(F)&&I.push(O)}}return I});Ee(this,"getUserTrackFromMid",async q=>{const J=await this.getUsers();let I;for(const D of J){const{tracks:a=[]}=D;for(const O of a)if(O.mid===q){I=O;break}}return I});Ee(this,"checkUserInRoom",q=>this.userMap.has(q));Ee(this,"getUsersId",async()=>[...this.userMap.keys()]);Ee(this,"getSelfInfo",async()=>await this.getUser(this.options.userId));Ee(this,"updateIsPublished",async(q,J=!1)=>{const I=await this.getUser(q);I.isPublished=J});Ee(this,"setUserUpdateStreams",async(q,J,I=!0)=>{const D=await this.getUser(q),a={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};a[J]=I,D.updateStreams=a});Ee(this,"updateUserChannels",async(q,J=[],I)=>{const D=await this.getUser(q);I&&(J=[...D.channels,...J]),D.channels=J});Ee(this,"updateUsertracks",async(q,J=[],I)=>{const D=await this.getUser(q);I&&(J=[...D.tracks,...J]),J=J.filter(({mid:F=""})=>F!==""),J=pt(J,["type"]),J=J.sort((F,z)=>F.type-z.type<0?-1:1);for(const F of J)F.userId=q,F.mediaType=mediaType_keys[F.type],F.enabled===void 0&&(F.enabled=!0);D.updateStreams={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};const a=dt(D.tracks,["mediaType","enabled","mid","msid","trackName"]),O=dt(J,["mediaType","enabled","mid","msid","trackName"]);{const F="microphoneCamera_audio",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}{const F="microphoneCamera_video",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}{const F="screenSharing_audio",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}{const F="screenSharing_video",z=O.find(ne=>ne.mediaType===F),K=a.find(ne=>ne.mediaType===F),te=JSON.stringify(z)!==JSON.stringify(K);D.updateStreams[F]=te}D.tracks=J});Ee(this,"updateUserCallAction",async(q,J=0)=>{const I=await this.getUser(q);I.callAction=J,I.callActionStr=J.toString(2).padStart(4,"0"),I.callActionMap=this.getCallActionMap(J)});Ee(this,"updateUserBehaviors",async(q,J=0)=>{const I=await this.getUser(q);I.banBehavior=J,I.banBehaviorStr=J.toString(2).padStart(4,"0"),I.banBehaviorMap=this.getBanBehaviorMap(J)});Ee(this,"updateUserNetwork",async(q,J={egress:5,ingress:5})=>{const I=await this.getUser(q);I.network=J});Ee(this,"updateUserPermissions",async(q,J)=>{if(J){const I=await this.getUser(q);I.permissions=J}});Ee(this,"updateUserBase",async q=>{const J=await this.getUser(q);J.isSelf=q===this.options.userId,J.updateAt=Date.now()});Ee(this,"updateUsers",async q=>{for(const J of q){const{id:I,tracks:D,callAction:a,permissions:O,isPublished:F}=J;await this.updateUserBase(I),await this.updateIsPublished(I,F),await this.updateUserPermissions(I,O),await this.updateUsertracks(I,D,!0),await this.updateUserCallAction(I,a),await this.updateUserNetwork(I)}});Ee(this,"emitNotifyUpdateUser",async q=>{const J=await this.getUsers([q]),[I]=this.usersFilter(J);this.cwsIns.emitNotify("onRoomUser",{code:200,data:I,desc:"user info is change."})});Ee(this,"emitNotifyUpdateUsers",async()=>{const q=await this.getUsers(),J=this.usersFilter(q);this.cwsIns.emitNotify("onRoomUsers",{code:200,data:J,desc:"all users info is change."})})}}const t=(N,Z=4294967295,q=79764919)=>{const J=new Int32Array(256);let I,D,a,O=Z;for(I=0;I<256;I++){for(a=I<<24,D=8;D>0;--D)a=2147483648&a?a<<1^q:a<<1;J[I]=a}for(I=0;I<N.length;I++)O=O<<8^J[255&(O>>24^N[I])];return O},e=(N,Z=t)=>{const q=oe=>new Uint8Array(oe.length/2).map((se,fe)=>parseInt(oe.substring(2*fe,2*(fe+1)),16)),J=oe=>q(oe)[0],I=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach((oe,se)=>I.set(oe,se));const D=new Uint8Array(N.length);let a,O,F,z=!1,K=0,te=42,ne=N.length>13&&N.substring(0,9)==="dynEncode",ee=0;ne&&(ee=11,O=J(N.substring(9,ee)),O<=1&&(ee+=2,te=J(N.substring(11,ee))),O===1&&(ee+=8,F=(oe=>new DataView(q(oe).buffer).getInt32(0,!0))(N.substring(13,ee))));const re=256-te;for(let oe=ee;oe<N.length;oe++)if(a=N.charCodeAt(oe),a!==61||z){if(a===92&&oe<N.length-5&&ne){const se=N.charCodeAt(oe+1);se!==117&&se!==85||(a=parseInt(N.substring(oe+2,oe+6),16),oe+=5)}if(a>255){const se=I.get(a);se&&(a=se+127)}z&&(z=!1,a-=64),D[K++]=a<te&&a>0?a+re:a-te}else z=!0;const ce=D.subarray(0,K);if(ne&&O===1){const oe=Z(ce);if(oe!==F){const se="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",se+`
14
14
  `,"Expected: "+F+"; Got: "+oe+`
15
15
  `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(se)}}return ce};function WASMAudioDecoderCommon(){const N=Uint8Array,Z=Float32Array;WASMAudioDecoderCommon.modules||Object.defineProperties(WASMAudioDecoderCommon,{modules:{value:new WeakMap},setModule:{value(q,J){WASMAudioDecoderCommon.modules.set(q,Promise.resolve(J))}},getModule:{value(q,J){let I=WASMAudioDecoderCommon.modules.get(q);return I||(J?I=WebAssembly.compile(e(J)):(J=q.wasm,I=WASMAudioDecoderCommon.inflateDynEncodeString(J).then(D=>WebAssembly.compile(D))),WASMAudioDecoderCommon.modules.set(q,I)),I}},concatFloat32:{value(q,J){let I=new Z(J),D=0,a=0;for(;D<q.length;)I.set(q[D],a),a+=q[D++].length;return I}},getDecodedAudio:{value:(q,J,I,D,a)=>({errors:q,channelData:J,samplesDecoded:I,sampleRate:D,bitDepth:a})},getDecodedAudioMultiChannel:{value(q,J,I,D,a,O){let F=[],z,K;for(z=0;z<I;z++){const te=[];for(K=0;K<J.length;)te.push(J[K++][z]||[]);F.push(WASMAudioDecoderCommon.concatFloat32(te,D))}return WASMAudioDecoderCommon.getDecodedAudio(q,F,D,a,O)}},inflateDynEncodeString:{value(q){return q=e(q),new Promise(J=>{const I=String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;WASMAudioDecoderCommon.getModule(WASMAudioDecoderCommon,I).then(D=>WebAssembly.instantiate(D,{})).then(({exports:D})=>{const a=new Map(Object.entries(D)),O=a.get("puff"),F=a.get("memory").buffer,z=new N(F),K=new DataView(F);let te=a.get("__heap_base");const ne=q.length,ee=te;te+=4,K.setInt32(ee,ne,!0);const re=te;te+=ne,z.set(q,re);const ce=te;te+=4,K.setInt32(ce,z.byteLength-te,!0),O(te,ce,re,ee),J(z.slice(te,te+K.getInt32(ce,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(q,J,I)=>{let D=[],a=0;for(;a<J;)D.push(q.slice(a*I,a++*I+I));return D},this.allocateTypedArray=(q,J,I=!0)=>{const D=this._wasm.malloc(J.BYTES_PER_ELEMENT*q);return I&&this._pointers.add(D),{ptr:D,len:q,buf:new J(this._wasm.HEAP,D,q)}},this.free=()=>{this._pointers.forEach(q=>{this._wasm.free(q)}),this._pointers.clear()},this.codeToString=q=>{const J=[],I=new Uint8Array(this._wasm.HEAP);for(let D=I[q];D!==0;D=I[++q])J.push(D);return String.fromCharCode.apply(null,J)},this.addError=(q,J,I,D,a,O)=>{q.push({message:J,frameLength:I,frameNumber:D,inputBytes:a,outputSamples:O})},this.instantiate=(q,J)=>(J&&WASMAudioDecoderCommon.setModule(q,J),this._wasm=new q(WASMAudioDecoderCommon).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var browser,hasRequiredBrowser;function requireBrowser(){return hasRequiredBrowser||(hasRequiredBrowser=1,browser=Worker),browser}var browserExports=requireBrowser();const NodeWorker=getDefaultExportFromCjs(browserExports),getWorker=()=>globalThis.Worker||NodeWorker;class WASMAudioDecoderWorker extends getWorker(){constructor(Z,q,J,I){WASMAudioDecoderCommon.modules||new WASMAudioDecoderCommon;let D=WASMAudioDecoderCommon.modules.get(J);if(!D){let a="text/javascript",O,F=`'use strict';(${((z,K,te)=>{let ne,ee,re=new Promise(ce=>{ee=ce});self.onmessage=({data:{id:ce,command:oe,data:se}})=>{let fe=re,ge={id:ce},ue;oe==="init"?(Object.defineProperties(z,{WASMAudioDecoderCommon:{value:K},EmscriptenWASM:{value:te},module:{value:se.module},isWebWorker:{value:!0}}),ne=new z(se.options),ee()):oe==="free"?ne.free():oe==="ready"?fe=fe.then(()=>ne.ready):oe==="reset"?fe=fe.then(()=>ne.reset()):(Object.assign(ge,ne[oe](Array.isArray(se)?se.map(_e=>new Uint8Array(_e)):new Uint8Array(se))),ue=ge.channelData?ge.channelData.map(_e=>_e.buffer):[]),fe.then(()=>self.postMessage(ge,ue))}}).toString()})(${J}, ${WASMAudioDecoderCommon}, ${I})`;try{O=typeof process.versions.node<"u"}catch{}D=O?`data:${a};base64,${Buffer.from(F).toString("base64")}`:URL.createObjectURL(new Blob([F],{type:a})),WASMAudioDecoderCommon.modules.set(J,D)}super(D,{name:q}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:a})=>{const{id:O,...F}=a;this._enqueuedOperations.get(O)(F),this._enqueuedOperations.delete(O)},new I(WASMAudioDecoderCommon).getModule().then(a=>{this.postToDecoder("init",{module:a,options:Z})})}async postToDecoder(Z,q){return new Promise(J=>{this.postMessage({command:Z,id:this._id,data:q}),this._enqueuedOperations.set(this._id++,J)})}get ready(){return this.postToDecoder("ready")}async free(){await this.postToDecoder("free").finally(()=>{this.terminate()})}async reset(){await this.postToDecoder("reset")}}const assignNames=(N,Z)=>{Object.defineProperty(N,"name",{value:Z})};function EmscriptenWASM(N){function Z(){}function q(Se){throw Se}var J,I;function D(){var Se=I.buffer;J=new Uint8Array(Se),new BigInt64Array(Se),new BigUint64Array(Se)}for(var a=()=>q(""),O=()=>{},F={},z=Se=>Se(),K=()=>performance.now(),te=(Se,Me)=>{if(F[Se]&&(clearTimeout(F[Se].id),delete F[Se]),!Me)return 0;var We=setTimeout(()=>{delete F[Se],z(()=>we(Se,K()))},Me);return F[Se]={id:We,timeout_ms:Me},0},ne=Math.cos,ee=Se=>(J.length,!1),re=Se=>{throw`exit(${Se})`},ce=new Uint8Array(123),oe=25;oe>=0;--oe)ce[48+oe]=52+oe,ce[65+oe]=oe,ce[97+oe]=26+oe;ce[43]=62,ce[47]=63;var se={d:a,c:O,e:te,a:ne,f:ee,b:re};function fe(Se){ge=Se.i,ue=Se.j,_e=Se.k,pe=Se.l,ye=Se.m,we=Se.o}var ge,ue,_e,pe,ye,we;function Ie(Se){Se.h()}EmscriptenWASM.wasm||Object.defineProperty(EmscriptenWASM,"wasm",{get:()=>String.raw`dynEncode0158c8b8d85e¼æ=M™]™lGu³õPoš]ÐãÞ·£3² ÁÚ= ’Êöc/ÓZ8s³‹íÛ³u­Ð¥t"+¦›¦~dòR\(nº}÷£¢¢ë¢k}Ÿt¡) ,‚­äÕüP
16
16
  *øüäÖeù‡i“ ÝWŠÍ¦ÖPMŸ¨[æu>Ü(«l‹'Ë$c‡˜¿9ZEúº¼ù‹¼=}ŠŒäÍÂý²­‚\åô҅'.õt­ÅXî=}~õ"uÊr˜ÁýóòÝ ÔúéÊ
@@ -203,4 +203,4 @@ DÙ VààÍ³ÄvÒ2; 5c±-ìʞ‹öª§}Ou¡ƒ¡‡¦ƒîGÇ D
203
203
  Ùup3‹q@ݱu„Xt•X07=M˜‡p_¤I¬ø®®[¦ó[ÀRŠ˜VsX?F^":hˆa?ØÎeÄQc{Yíz’0j¹{b ×c˜4ö–= %¡›ì?XÜñÊ,ŒxþÀŠf©û‡y O}:Fà= NuÙO_hÌÍtÝg|ȳ]²(aŸ= žTÜøN»j/Ì|éŽÚœ{^ëÐÖ{¡•Çzñú_|Åûl*†Ztì{8ޝa@©¥Z”K؍¨c¿iš<±†üFÇkº-cy 5±4§o9ы,;KzÌ $à1I=MºôÉ©¤=MêÈ5
204
204
  }õíë(—ŒðìÍäWD„?£©ÿ㪔=M äҕ±ì6í)ˆ‘ÏÙtbFÐöÚFÈ´Ù§R‚1.]¢¦¨ùû­,9ï‚tö»LÂô⍦qªk{ä(9«ž4>°»ŽB‰¶ñ»šGÓ½vÃâ£d$°AŠ‹†0ô‰¼¦­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Îç˜õn„D1MøhO¥me Q†Ê¸[F< ^MBÜÛ
205
205
   Aãϧüï†4î%M°6M…ùtN)›FR˜[¾F™qV6¥óðlœò©Ë= c»R =}Ù8õ.­%BÂIµÃI&æ×U”1Q«Ïñ3&ÑóÓÝ»“ñ²eL°(ÑòOzBð·Q]üôföê+h.³´)ÅKé¥JR#/GóuÉɾ¯Áõ¿-½ñ'î<·Q ¼=MÛ²6+þ筓Ydb_öcHm™öôزj¾…nÚ7aÌvؓOå¹÷e0Ff˜ÊÈønØ#?ÁhÊÀcœ–Ýåõ(å û)ü)éðк¿ÓÜ¡]q†ákÈۚÝL·ºrCMmp_ÀÏ Óìcç6®þsosÒÝóô1¬Ã6<2#Ò±Cˆ“65Q"4ŠB&pç
206
- gUn…g= !þ+µèm M½Êê½½²¦é%0Yg~´p5.\Ø®z‚y9%Ôiܒ!Ùc‰ÝŦH>ÓX ÿZR’[¬&ønÇl’Ó_:ïi«ñ<ø"QÚ©yz …®ªOL¥ÎêŠÌÝi?Ê‚'/Ne»:2NÅÝ_òspüR Oø!!ù+##üÓkéªX-fpd“q[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ÎËýæ×%I­OIø¦Ä(HTJ†~),ÕDCWWÃö(›VwV=M§TsLP³ þV'tT#¡ZLŽêé;ßù[`});var be={a:se};this.setModule=Se=>{N.setModule(EmscriptenWASM,Se)},this.getModule=()=>N.getModule(EmscriptenWASM),this.instantiate=()=>(this.getModule().then(Se=>WebAssembly.instantiate(Se,be)).then(Se=>{const Me=Se.exports;fe(Me),I=Me.g,D(),Ie(Me),Z()}),this.ready=new Promise(Se=>{Z=Se}).then(()=>{this.HEAP=I.buffer,this.malloc=ue,this.free=ye,this.opus_frame_decoder_create=ge,this.opus_frame_decode_float_deinterleaved=_e,this.opus_frame_decoder_destroy=pe}),this)}function OpusDecoder(N={}){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(K=>{this._common=K,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 te=this._common.allocateTypedArray(this._channels,Uint8Array);te.buf.set(this._channelMappingTable),this._decoder=this._common.wasm.opus_frame_decoder_create(this._sampleRate,this._channels,this._streamCount,this._coupledStreamCount,te.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=K=>{if(!(K instanceof Uint8Array))throw Error("Data to decode must be Uint8Array. Instead got "+typeof K);this._input.buf.set(K);let te=this._common.wasm.opus_frame_decode_float_deinterleaved(this._decoder,this._input.ptr,K.length,this._output.ptr),ne;return te<0&&(ne="libopus "+te+" "+(OpusDecoder.errors.get(te)||"Unknown Error"),console.error(ne),te=0),{outputBuffer:this._common.getOutputChannels(this._output.buf,this._outputChannels,te),samplesDecoded:te,error:ne}},this.decodeFrame=K=>{let te=[];const ne=this._decode(K);return ne.error&&this._common.addError(te,ne.error,K.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=K.length,this._outputSamples+=ne.samplesDecoded,this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(te,[ne.outputBuffer],this._outputChannels,ne.samplesDecoded,this._sampleRate)},this.decodeFrames=K=>{let te=[],ne=[],ee=0,re=0;for(;re<K.length;){const ce=K[re++],oe=this._decode(ce);te.push(oe.outputBuffer),ee+=oe.samplesDecoded,oe.error&&this._common.addError(ne,oe.error,ce.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=ce.length,this._outputSamples+=oe.samplesDecoded}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(ne,te,this._outputChannels,ee,this._sampleRate)},this._isWebWorker=OpusDecoder.isWebWorker,this._WASMAudioDecoderCommon=OpusDecoder.WASMAudioDecoderCommon||WASMAudioDecoderCommon,this._EmscriptenWASM=OpusDecoder.EmscriptenWASM||EmscriptenWASM,this._module=OpusDecoder.module;const Z=8,q=K=>typeof K=="number",J=N.sampleRate,I=N.channels,D=N.streamCount,a=N.coupledStreamCount,O=N.channelMappingTable,F=N.preSkip,z=N.forceStereo?1:0;if(I>2&&(!q(D)||!q(a)||!Array.isArray(O)))throw new Error("Invalid Opus Decoder Options for multichannel decoding.");return this._sampleRate=[8e3,12e3,16e3,24e3,48e3].includes(J)?J:48e3,this._channels=q(I)?I:2,this._streamCount=q(D)?D:1,this._coupledStreamCount=q(a)?a:this._channels-1,this._channelMappingTable=O||(this._channels===2?[0,1]:[0]),this._preSkip=F||0,this._forceStereo=I<=Z&&I!=2?z: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(Z){super(Z,"opus-decoder",OpusDecoder,EmscriptenWASM)}async decodeFrame(Z){return this.postToDecoder("decodeFrame",Z)}async decodeFrames(Z){return this.postToDecoder("decodeFrames",Z)}}assignNames(OpusDecoder,"OpusDecoder"),assignNames(OpusDecoderWebWorker,"OpusDecoderWebWorker"),new OpusDecoder;class RoomPeer extends RoomUsers{constructor(q){super(q);Ee(this,"getPeerStatsTimer",0);Ee(this,"reports",[]);Ee(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});Ee(this,"initPeer",()=>{var q;(q=this.peerIns)==null||q.close(),this.transceiverMap=new Map,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),De(this,Hn).call(this),De(this,zn).call(this)});Ee(this,"getNatType",async()=>{});Ee(this,"initSendChannel",(q="",J)=>{});Ee(this,"initReceiveChannel",(q="",J)=>{});Ee(this,"replaceSenderStream",async(q=[],J)=>{const{userId:I}=this.options;q.length===0&&(q=mediaType_keys);for(const D of q){const a=this.transceiverMap.get(D);let O;if(a){const{sender:F}=a;J?O=this.getUserStream(I,D):O=this.getPhoneyStreams(D);const[z]=O.getTracks();z&&await F.replaceTrack(z)}}});Ee(this,"getSenderTracks",async(q=[])=>{const J=[];for(const I of q){const D=this.transceiverMap.get(I);if(!D)continue;const{mid:a,sender:O}=D,{track:F}=O;if(!F)continue;const{id:z,enabled:K}=F,te=mediaType_keys.findIndex(ee=>ee===I),ne={type:te,enabled:K,trackName:`web-${te}-${z}`,location:"local",mid:a};J.push(ne)}return J});Ee(this,"addSenders",async(q=[])=>{q.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const J=[];for(const I of q){if(this.transceiverMap.get(I))continue;const a=this.getPhoneyStreams(I),[O]=a.getTracks(),F=this.peerIns.addTransceiver(O,{direction:"sendonly"});this.transceiverMap.set(I,F),J.push(I)}if(q.length===0||J.length!==0){const I=await this.peerIns.createOffer();if(this.options.debug){const D=libExports$1.parse(I.sdp),a=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:a,sdpJson:D,description:I})}await this.peerIns.setLocalDescription(I)}return J});Ee(this,"removeSenders",async(q=[])=>{q.length===0&&(q=mediaType_keys);for(const J of q)this.transceiverMap.has(J)&&this.transceiverMap.delete(J)});Ee(this,"onSubscribeUserTracks",q=>{let J=0;return new Promise(async I=>{const D=[];for(const a of q){const{tracks:O=[]}=a;for(const F of O){const{trackName:z,mid:K}=F,[te]=await this.getUserTrackByTrackName([z]);D.push({...te,mid:K})}}{let a=[];const O=async()=>{clearTimeout(J);const z=new Map;for(const te of a){const{userId:ne,mediaType:ee}=te;if(!ne||!ee)continue;z.has(ne)||z.set(ne,{userId:ne,tracks:[],updateStreams:{}});const ce=z.get(ne);ce.tracks.push(te),ce.updateStreams[ee]=!0}const K=[...z.values()];for(const te of K){const{userId:ne,tracks:ee}=te;await this.updateUsertracks(ne,ee,!0)}await this.emitNotifyUpdateUsersStreams(K),this.peerIns.removeEventListener("track",F);{const te=Array.from(D,re=>re.trackName),ne=Array.from(a,re=>re.trackName),ee=te.filter(re=>!ne.includes(re));I({target:te,success:ne,fail:ee})}},F=async z=>{const{streams:K,transceiver:te}=z,[ne]=K,{mid:ee,receiver:re}=te,{track:ce}=re,{id:oe}=ce,se=D.find(ue=>ue.mid===`${ee}`);if(!se)return;const{userId:fe,mediaType:ge}=se;if(!(!fe||!ge)){{const ue={...se,mid:ee,msid:oe};a.push(ue)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${a.length}/${D.length}`,{mediaType:ge,mid:ee,userTrack:se,e:z});{const ue=new Audio;if(ue.srcObject=ne,await this.initUserMediaStreamContext(fe,ge,ne),ge==="microphoneCamera_audio"||ge==="screenSharing_audio"){const _e=this.getUserAudioMediaStreamContext(fe,ge);_e==null||_e.setMute(!1)}}D.length===a.length&&O()}};this.peerIns.addEventListener("track",F),J=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${a.length}/${D.length})`),O()},5*1e3)}})});at(this,Hn,()=>{let q=0;const J=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.oniceconnectionstatechange=async()=>{const I=this.peerIns.iceConnectionState;switch(await this.taskQueue.setCondition("ice",!1),clearTimeout(q),I){case"connected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${I}`),await this.taskQueue.setCondition("ice",!0),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:${I}`),q=window.setTimeout(J,30*1e3);break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${I}`),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:${I}`),J();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${I}`);break}}});Ee(this,"closeUserTracks",async(q,J=[],I=!1)=>{const D=[];for(const z of J){const{trackName:K,msid:te}=z;D.push(K),te&&D.push(te)}const a=z=>D.includes(z),O=this.peerIns.getTransceivers();for(const z of O){const{mid:K,sender:te,receiver:ne}=z;te.track&&a(te.track.id)&&(z.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${K} is stop.`,z)),ne.track&&a(ne.track.id)&&(z.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${K} is stop.`,z))}const F=await this.getUser(q);if(F){for(const z of F.tracks){const{trackName:K,msid:te,userId:ne,mediaType:ee}=z;!ne||!ee||!a(K)||(this.removeUserMediaStreamContext(ne,ee),te&&delete z.msid)}if(I){const z=F.tracks.filter(({trackName:K})=>!a(K));await this.updateUsertracks(q,z,!1)}}});Ee(this,"createOffer",async()=>{const q=await this.peerIns.createOffer();if(this.options.debug){const J=libExports$1.parse(q.sdp),I=dt(J.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:I,sdpJson:J,description:q})}await this.peerIns.setLocalDescription(q)});Ee(this,"createAnswer",async()=>{const q=await this.peerIns.createAnswer();if(this.options.debug){const J=libExports$1.parse(q.sdp),I=dt(J.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:I,sdpJson:J,description:q})}await this.peerIns.setLocalDescription(q)});Ee(this,"getSdp",()=>{var q;return(q=this.peerIns.localDescription)==null?void 0:q.sdp});Ee(this,"setRemoteDescription",async q=>{if(this.options.debug){const J=libExports$1.parse(q.sdp),I=dt(J.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:I,sdpJson:J,description:q})}return await this.peerIns.setRemoteDescription(q),q});Ee(this,"setCallStrategy",async(q,J=[])=>{J.length===0&&(J=mediaType_keys);let I="balanced";switch(q){case"qualityPriority":I="maintain-resolution";break;case"fluencyPriority":I="maintain-framerate";break;case"balancedDowngrade":I="balanced";break}const D=await this.getSelfInfo(),a=Array.from(D.tracks,({trackName:F})=>F),O=this.peerIns.getSenders();for(const F of O){const{track:z}=F;if(!z||!a.includes(z.id))continue;const K=F.getParameters();F.setParameters({...K,degradationPreference:I})}});Ee(this,"setRTCRtpSenderParameters",q=>{try{const J=this.peerIns.getSenders();for(const I of J){const D=I.getParameters();I.setParameters({...D,...q})}}catch(J){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",J)}});Ee(this,"getReportsByMid",async(q=[])=>q.length===0?this.reports:this.reports.filter(J=>q.includes(J.mid)));Ee(this,"getRoomNetwork",()=>this.peerNetwork);Ee(this,"getPeerNetwork",()=>this.peerNetwork);at(this,jn,async()=>{try{const q=await this.peerIns.getStats(),J=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],D=[...q.values()].filter(_e=>J.includes(_e.type));let a=0,O=0,F=0,z=0,K=0,te=0,ne=[],ee=[];for(const _e of this.reports){const{packetsSent:pe,packetsLost:ye}=_e;pe&&(F+=pe),ye&&(z+=ye)}this.reports=D;for(const _e of this.reports){const{bytesSent:pe,bytesReceived:ye,packetsSent:we,packetsLost:Ie,roundTripTime:be,jitter:Se}=_e;pe&&(O=pe),ye&&(a=ye),we&&(K+=we),Ie&&(te+=Ie),be&&ne.push((be*100).toFixed(2)),Se&&ee.push(Se.toFixed(2))}ee.sort().reverse(),ne.sort().reverse();const re=K-F,ce=te-z,oe=re===0?"0.00":(ce/re).toFixed(2),[se="0"]=ne,[fe="0"]=ee,ge={outboundBytes:O,inboundBytes:a,lostRate:oe,roundTripTime:se,jitter:fe};this.peerNetwork=ge;const ue=(_e,pe,ye)=>{const we=Number(_e),Ie=Number(pe),be=Number(ye);let Se="0";return we<.03&&Ie<100&&be<.05?Se="5":we<.06&&Ie<160&&be<.1?Se="4":we<.1&&Ie<250&&be<.15?Se="3":we<.15&&Ie<400&&be<.2?Se="2":Se="1",Number(Se)};{const _e=ue(oe,se,fe),pe=await this.getSelfInfo(),{network:ye}=pe,we={egress:_e,ingress:_e};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,we),JSON.stringify(ye)!==JSON.stringify(we)){this.emitNotifyUpdateUsers();const{userId:Se,roomId:Me}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...we,userId:Se,roomId:Me}},!1)}},3*1e3)}}catch(q){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",q)}});at(this,zn,()=>{const q=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||De(this,jn).call(this)};this.getPeerStatsTimer=window.setInterval(q,1*1e3)});Ee(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer))}}Hn=new WeakMap,jn=new WeakMap,zn=new WeakMap;class RoomCalls extends RoomPeer{constructor(q){super(q);at(this,Tn,0);Ee(this,"setLocalStream",(q,J)=>new Promise(async(I,D)=>{try{typeof q=="string"&&(q=[q]);for(const O of q)this.localStreamsActionMap.set(O,J);if(J){if(q.includes("microphoneCamera_audio")&&q.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):q.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):q.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):q.includes("screenSharing_audio")&&q.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):q.includes("screenSharing_audio")&&!q.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):q.includes("screenSharing_video")&&!q.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),q.includes("screenSharing_audio")){const O=await this.getLocalStream("screenSharing_audio");if(O){const F=O.getTracks();for(const z of F)z.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if(q.includes("screenSharing_video")){const O=await this.getLocalStream("screenSharing_video");if(O){const F=O.getTracks();for(const z of F)z.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams(q);const a=await this.getLocalStreams(q);this.cwsIns.emitNotify("onLocalStream",{code:200,data:a,desc:"local stream is change."}),I(a)}catch(a){D(a)}}));Ee(this,"setMediaDeviceKind",(q,J)=>new Promise(async(I,D)=>{this.setDeviceKind(q,J);const a=await this.getSelfInfo(),{id:O,tracks:F=[],callActionMap:z}=a,K=[],te=async ne=>{const ee=this.localStreamsActionMap.get(ne),re=F.find(oe=>oe.mediaType===ne),ce=z[ne];if(ee){K.push(ne),await this.stopLocalStreams([ne]);try{await this.initLocalStream(ne)}catch(oe){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initLocalStream is error.",oe),await this.inactiveTracks([ne],!1),D(oe)}}if(re){const oe=await this.getLocalStream(ne);oe&&(await this.initUserMediaStreamContext(O,ne,oe),ce&&await this.replaceSenderStream([ne],!0))}{const oe=await this.getLocalStreams(K);this.cwsIns.emitNotify("onLocalStream",{code:200,data:oe,desc:"local stream is change."}),await this.emitNotifyUpdateUsers(),I(!0)}};q==="audioinput"&&te("microphoneCamera_audio"),q==="videoinput"&&te("microphoneCamera_video"),q==="audiooutput"&&(await this.changeAudiooutput(),I(!0))}));Ee(this,"changeScreenSharing",async q=>{const J=await this.getSelfInfo(),{tracks:I=[],callActionMap:D}=J;try{await this.setLocalStream(q,!0);for(const a of q)I.find(F=>F.mediaType===a&&D[a])&&await this.replaceSenderStream([a],!0)}catch(a){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",a)}});Ee(this,"createSession",()=>new Promise(async(q,J)=>{if(["connecting","connected"].includes(this.roomState))return q(!0);this.setRoomState("connecting"),await this.taskQueue.createTask({describe:"createSession",conditionKeys:["createWs","createSession"],changeConditionKeys:["createSession"],func:()=>new Promise(async(I,D)=>{try{await this.addSenders(),this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async a=>{const{code:O=0,desc:F,data:z}=a;if(O!==200)return D(F);const{remoteSdp:K}=z;if(this.options.debug){const te=libExports$1.parse(K),ne=dt(te.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:ne,sdpJson:te})}await this.taskQueue.setCondition("ice",!1),await this.taskQueue.createTask({describe:"ice",timeout:30*1e3,conditionKeys:["ice"],func:()=>new Promise(te=>setTimeout(()=>te(!0),300)),success:async()=>{I(!0)},fail:async te=>{throw new Error(`ice connection failed: ${te}`)}}),await this.setRemoteDescription({type:"answer",sdp:K})})}catch(a){D(a)}}),success:async I=>{q(I)},fail:async I=>{this.reportLogs("ws_c_timeout",I.message||I),J(I)},complete:()=>{this.taskQueue.setCondition("createSession",!0)}})}));Ee(this,"earlyConnect",(q=[])=>{this.isEarly=!0,De(this,Cn).call(this),this.createSession(),q.length===0&&(q=["microphoneCamera_audio","microphoneCamera_video"]),De(this,An).call(this,q)});Ee(this,"joinRoom",async q=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"joinRoom",conditionKeys:["createWs"],changeConditionKeys:["joinRoom"],func:()=>new Promise(async(D,a)=>{try{this.setOptions(q),await De(this,Cn).call(this),this.clearUsers();const{roomId:O,userId:F,callType:z,sdkToken:K}=this.options;this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:z,roomId:O,user:{id:F,tracks:[],callAction:0},token:K},version:2}).then(async te=>{const{code:ne=0,desc:ee="服务器繁忙",data:re}=te;if(ne!==200)return a(ee);const{roomId:ce="",roomUsers:oe=[]}=re;if(ce!==O)return a("加入的房间不匹配");this.isInRoom=!0,this.taskQueue.setCondition("createTrack",!0),this.taskQueue.setCondition("publish",!0),this.taskQueue.setCondition("subscribe",!0),this.taskQueue.setCondition("renegotiate",!0),this.taskQueue.setCondition("closeTrack",!0),this.initHeartbeat(),this.createSession(),await this.updateUsers(oe);const se=[];for(const ge of oe){const{id:ue,channelCache:_e}=ge,{channels:pe=[]}=_e;await this.updateUserBehaviors(ue,ge.behavior),await this.updateUserChannels(ue,pe,!1),pe.length!==0&&se.push({userId:ue,channels:pe})}this.subChannel(se),await this.emitNotifyUpdateUsers();const fe=await this.getUsers();D(fe)})}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("join_room_error",D.message||D),I(D)},complete:()=>{this.taskQueue.setCondition("joinRoom",!0)}})}));Ee(this,"quitRoom",()=>new Promise(async q=>{const{roomId:J,userId:I}=this.options,D={roomId:J,user:{id:I}};try{this.isInRoom=!1,clearInterval(De(this,Tn)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(a){this.reportLogs("quit_room_error",a.message||a)}await new Promise(a=>setTimeout(()=>a(!0),300)),await this.taskQueue.setCondition("closeTrack",!0),this.cwsIns.sendMessage({event:"quitRoom",data:D}),q(!0)}));Ee(this,"quitRoomEx",()=>new Promise(async q=>{const{roomId:J,userId:I}=this.options,D={roomId:J,user:{id:I}};try{this.isInRoom=!1,this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(a){this.reportLogs("quit_room_error",a.message||a)}await new Promise(a=>setTimeout(()=>a(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:D}),q(!0)}));Ee(this,"syncRoomInfo",()=>new Promise(async(q,J)=>{const{userId:I}=this.options,D=await this.getUser(I),{id:a=I,callAction:O=0}=D;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:a,callAction:O}}}).then(async F=>{if(F.code!==200)return J(F.desc);const z=F.data.users;this.clearUsers(),await this.updateUsers(z),await this.updateUsertracks(D.id,D.tracks,!1);{const K=await this.getUsers();q(K)}}).catch(F=>J(F))}));Ee(this,"checkInRoom",()=>new Promise(async(q,J)=>{const{userId:I}=this.options,D=await this.getUser(I),{id:a=I,callAction:O=0}=D;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:a,callAction:O}}}).then(async F=>F.code!==200?J(F.desc):F.data.users.find(te=>te.id===this.options.userId)?q(!0):q(!1)).catch(()=>q(!1))}));Ee(this,"publish",q=>new Promise(async(J,I)=>{{const D=await this.getSelfInfo(),{banBehaviorMap:a}=D;let O=!0;for(const F of q)if(a[F]){O=!1;break}if(O===!1)return I("publish is error: prohibited by administrator.")}try{await this.setLocalStream(q,!0)}catch(D){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",D)}await this.taskQueue.createTask({describe:"publish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["publish"],func:()=>new Promise(async(D,a)=>{try{const O=await this.getSelfInfo(),F=[];for(const ee of q){{const re=this.getPhoneyStreams(ee);await this.initUserMediaStreamContext(O.id,ee,re)}{const re=await this.getLocalStream(ee);re?await this.initUserMediaStreamContext(O.id,ee,re):F.push(ee)}}const z=q.filter(ee=>!F.includes(ee)||["microphoneCamera_audio","microphoneCamera_video"].includes(ee));await this.replaceSenderStream(q,!1),await De(this,An).call(this,z);const K=await this.getSenderTracks(z),te=[...O.tracks,...K];await this.updateUsertracks(O.id,te,!0),F.length!==0&&await this.inactiveTracks(F,!1),z.length!==0&&await this.replaceSenderStream(z,!0);const ne=await this.getCallAction(te);await De(this,On).call(this,ne),await new Promise(ee=>setTimeout(()=>ee(!0),230)),De(this,Jn).call(this,q);{await this.emitNotifyUpdateUsers();const ee=await this.getSelfInfo();D(ee)}}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("publish_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("publish",!0)}})}));Ee(this,"stopPublish",(q=[])=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"stopPublish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(D,a)=>{try{const O=await this.getSelfInfo();q.length===0&&(q=mediaType_keys);const F=O.tracks.filter(({mediaType:K})=>K&&q.includes(K)),z=async()=>{this.initMediaPhoneyStreams(q);const K=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),D(K)};if(F.length===0)return z();await this.replaceSenderStream(q,!0),await this.closeUserTracks(O.id,F,!0),await this.removeSenders(q);{const K=await this.getCallAction(O.tracks);await De(this,On).call(this,K)}await this.createOffer(),this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:F}}).then(async K=>{const{code:te=0,data:ne,desc:ee}=K;if(te!==200)return a(ee);const{remoteSdp:re}=ne;await this.setRemoteDescription({type:"answer",sdp:re}),z()})}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("close_track_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ee(this,"subscribe",(q=[],J=3)=>new Promise(async(I,D)=>{const a=await this.taskQueue.createTask({describe:"subscribe",strict:!0,conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["subscribe"],func:()=>new Promise(async(O,F)=>{try{const z=await this.getUsers();let K=[];for(const ee of z){const{isSelf:re,tracks:ce=[]}=ee;if(!re){const oe=ce.filter(({trackName:se,mid:fe=""})=>fe!==""&&(q.includes(se)||q.length===0));oe.length!==0&&K.push({...ee,tracks:oe})}}const te=async(ee={})=>{const re=Array.from(K,({id:oe})=>oe),ce=await this.getUsers(re);await this.emitNotifyUpdateUsers(),O({users:ce,detail:ee})};if(K.length===0)return te();const ne=[];for(const ee of K){const{id:re,tracks:ce}=ee,oe=dt(ce,["type","trackName"]),se={id:re,tracks:oe};ne.push(se)}this.cwsIns.sendMessage({event:"subscribe",data:{users:ne}}).then(async ee=>{const{code:re=0,data:ce,desc:oe}=ee;if(re===2017&&oe.includes("renegotiation is expected before pulling or pushing tracks")&&await this.renegotiate(),re!==200)return F(oe);const{remoteSdp:se,users:fe=[]}=ce;this.onSubscribeUserTracks(fe).then(async ge=>{await this.renegotiate().then(()=>te(ge)).catch(ue=>F(ue))}).catch(ge=>{F(ge)}),await this.setRemoteDescription({type:"offer",sdp:se})})}catch(z){F(z)}}),success:async O=>{a.clear(),this.taskQueue.setCondition("subscribe",!0),I(O)},fail:async O=>{if(this.options.debug&&console.info("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: subscribe error. surplus count is ${J}`),J>0)return await new Promise(F=>setTimeout(()=>F(!0),(3-J)*1e3)),J=J-1,a.retry();a.clear(),this.reportLogs("subscribe_error",O.message||O),this.taskQueue.setCondition("subscribe",!0),D(O)},complete:async()=>{}})}));Ee(this,"renegotiate",()=>new Promise(async(q,J)=>{try{await this.taskQueue.setCondition("renegotiate",!1),await this.createAnswer(),this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(I=>{const{code:D=0,desc:a}=I;if(D!==200)return J(a);q(I)})}catch(I){J(I)}this.taskQueue.setCondition("renegotiate",!0)}));Ee(this,"stopSubscribe",(q=[])=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"closeTrack",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(D,a)=>{try{const O=await this.getUsers(),F=[];for(const K of O){const{tracks:te=[]}=K;for(const ne of te){const{type:ee,mid:re,trackName:ce,mediaType:oe,msid:se}=ne;if(!(!oe||!se)&&(q.length===0||q.includes(ce))){const fe={type:ee,mid:re,trackName:se};F.push(fe),await this.closeUserTracks(K.id,[ne])}}}const z=async()=>{await this.emitNotifyUpdateUsers(),D(!0)};if(F.length===0)return z();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:F}}).then(async K=>{const{remoteSdp:te}=K.data;await this.setRemoteDescription({type:"answer",sdp:te})}),z()}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: stopPublish is error.",D),this.reportLogs("close_track_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ee(this,"inactiveTracks",async(q,J)=>new Promise(async I=>{const D=await this.getSelfInfo();if(!D||!D.id)return I(!0);const{tracks:a=[]}=D,O=[...a];for(let z of O){const{mediaType:K}=z;if(K&&q.includes(K)){z.enabled=J;const te=await this.getLocalStream(K);if(!te)continue;const ne=te.getTracks();for(const ee of ne)ee.enabled=J}}await this.replaceSenderStream(q,J);const F=await this.getCallAction(O);await De(this,On).call(this,F),await this.emitNotifyUpdateUsers(),I(!0)}));Ee(this,"setBanBehaviors",q=>new Promise(async(J,I)=>{try{const{roomId:D}=this.options,a=[];for(const O of q){const{id:F,banBehaviors:z}=O,K=Object.keys(z);if(K.length===0)continue;const te=[];for(const ee of K){const re=mediaType_keys.findIndex(se=>se===ee),ce=z[ee],oe={type:re,behavior:ce};te.push(oe)}const ne={id:F,behaviors:te};a.push(ne)}this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:D,users:a}}).then(async O=>{const{code:F=0,desc:z}=O;if(F!==200)return I(z);J(O)}).finally(()=>{})}catch(D){I(D)}}));Ee(this,"pubChannel",()=>new Promise(async(q,J)=>{const D=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:D}}).then(async a=>{const{code:O=0,data:F,desc:z}=a;if(O!==200)return J(z);const{channels:K=[]}=F;for(const te of K){const{channels:ne=[]}=te;for(const ee of ne){const{dataChannelName:re,id:ce}=ee;this.initSendChannel(re,ce)}}q(!0)}).catch(a=>{J(a)})}));Ee(this,"subChannel",(q=[])=>new Promise(async(J,I)=>{if(q.length===0)return J(!0);await this.taskQueue.createTask({describe:"subChannel",strict:!0,conditionKeys:["createWs","createSession","ice"],changeConditionKeys:[],func:()=>this.cwsIns.sendMessage({event:"subChannel",data:{channels:q}}).then(async D=>{const{code:a=0,data:O,desc:F}=D;if(a!==200)return I(F);const{channels:z=[]}=O;for(const K of z){const{channels:te=[]}=K;for(const ne of te){const{dataChannelName:ee,id:re}=ne;this.initReceiveChannel(ee,re)}}}),success:async D=>{J(D)},fail:async D=>{I(D)}})}));Ee(this,"debugger",()=>new Promise(async(q,J)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async I=>{if(I.code!==200)return J(I.desc);q(!0)}).catch(I=>{J(I)})}));Ee(this,"shutdown",()=>new Promise(async(q,J)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async I=>{if(I.code!==200)return J(I.desc);q(!0)}).catch(I=>{J(I)})}));Ee(this,"initHeartbeat",()=>{this.stopHeartbeat();const q=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),J=this.isInRoom?5*1e3:30*1e3;Ct(this,Tn,window.setInterval(q,J)),q()});Ee(this,"stopHeartbeat",()=>{clearInterval(De(this,Tn))});at(this,Jn,async q=>{const{roomId:J}=this.options;if(!J)return;const{id:I,tracks:D=[]}=await this.getSelfInfo(),a=D.filter(O=>O.mediaType&&q.includes(O.mediaType));a.length!==0&&this.cwsIns.sendMessage({event:"pubNotify",data:{roomId:J,user:{id:I,tracks:a}}})});at(this,On,async q=>new Promise(async(J,I)=>{const{roomId:D,userId:a}=this.options,O={roomId:D,user:{id:a,callAction:q}};await this.cwsIns.sendMessage({event:"updateCall",data:O}).then(async F=>{const{code:z=0}=F;if(z!==200)return I(F);await this.updateUserCallAction(a,q),J(q)}).catch(F=>I(F))}));at(this,Cn,()=>new Promise(async(q,J)=>{try{if(["connecting","connected"].includes(this.cwsIns.state))return q(!0);await this.taskQueue.setCondition("createWs",!1),this.cwsIns.clearEvents(),this.initPeer();const{appid:I,roomId:D,userId:a}=this.options;if(!I)return J("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const O={c:I,r:D,v:this.sdk_service_version};if(this.isEarly){const z=xt();O.i=z,this.setOptions({earlyId:z})}else O.b=a;this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs",O);const F=btoa(encodeURI(JSON.stringify(O)));await this.cwsIns.connect(F),this.initHeartbeat(),await this.taskQueue.setCondition("createWs",!0),await this.taskQueue.setCondition("createSession",!0),q(!0)}catch(I){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",I),this.reportLogs("ws_c_timeout",I.message||I),J(I)}}));at(this,An,async q=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"createTrack",conditionKeys:["createWs","createSession","ice","createTrack","subscribe","renegotiate","closeTrack"],func:()=>new Promise(async(D,a)=>{try{await this.taskQueue.setCondition("createTrack",!1);const O=await this.addSenders(q),F=await this.getSenderTracks(O);if(F.length===0)return await this.taskQueue.setCondition("createTrack",!0),D(!0);this.cwsIns.sendMessage({event:"publish",data:{sdp:this.getSdp(),tracks:F,callAction:0}}).then(async z=>{const{code:K=0,desc:te,data:ne}=z;if(K!==200)return a(te);const{remoteSdp:ee}=ne;await this.setRemoteDescription({type:"answer",sdp:ee}),D(!0)})}catch(O){await this.removeSenders(q),a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("publish_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("createTrack",!0)}})}))}}Tn=new WeakMap,Jn=new WeakMap,On=new WeakMap,Cn=new WeakMap,An=new WeakMap;class Room extends RoomCalls{constructor(Z){super(Z)}}class QuickVO extends Room{constructor(q){super(q);at(this,bn,new Map);Ee(this,"reconstruct",async()=>{if(this.cwsIns.state!=="connected")return;this.setRoomState("ready"),this.initMediaPhoneyStreams(),this.taskQueue.clear(),this.initPeer(),this.taskQueue.setCondition("createSession",!0),this.taskQueue.setCondition("ice",!0),await this.createSession();const q=[],J=[],I=await this.getUsers();for(const D of I){const{isSelf:a,callActionMap:O,tracks:F=[]}=D;if(a)for(const z of mediaType_keys)O[z]&&q.push(z);for(const z of F)z.msid&&J.push(z.trackName)}await this.syncRoomInfo(),await this.subscribe(J),await this.publish(q)});at(this,Wn,()=>{{const q=async J=>{const{state:I}=J.data;if(I==="closed"){const{roomId:D,userId:a}=this.options,O={roomId:D,user:{id:a}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:O}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}this.roomState==="failed"&&this.reconstruct()};this.cwsIns.addNotify({event:"onRoomState",callback:q},!0)}{const q=async J=>{const{qualities:I=[]}=J.data,[D]=I;if(!(D&&D.userId===this.options.userId&&I.length===1)){for(const a of I){const{userId:O,egress:F,ingress:z}=a;this.checkUserInRoom(O)&&await this.updateUserNetwork(O,{egress:F,ingress:z})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:q},!0)}{const q=async J=>{const I=J.data.user;await this.updateUsers([I]),await this.updateUsertracks(I.id,I.track,!1),await this.updateUserBehaviors(I.id,I.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:q},!0)}{const q=async J=>{await this.removeUsers([J.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:q},!0)}{const q=async J=>{const{user:I}=J.data,{id:D,tracks:a=[],callAction:O=0}=I;if(await this.updateUserCallAction(D,O),await this.updateUserPermissions(D,3),await this.updateUsertracks(D,a,!0),this.options.newPublishAutoSubscribe){const F=this.getTrackNamesFormTracks(a);await this.subscribe(F)}else await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onPublish",callback:q},!0)}{const q=async J=>{const I=[J.data];this.subChannel(I)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:q},!0)}{const q=async J=>{const{id:I,tracks:D}=J.data.user;I!==this.options.userId&&(await this.closeUserTracks(I,D,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:q},!0)}{const q=async J=>{const{id:I,callAction:D}=J.data.user;this.checkUserInRoom(I)&&(await this.updateUserCallAction(I,D),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:q},!0)}{const q=async J=>{const{user:I}=J.data,{id:D,permissions:a=1}=I;a===1?await this.removeUsers([D]):a===3&&await this.updateUsers([I]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:q},!0)}{const q=async J=>{const{users:I}=J.data;for(const D of I){const{id:a,behavior:O}=D;await this.updateUserBehaviors(a,O)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:q},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async q=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});Ee(this,"addNotify",q=>this.cwsIns.addNotify(q));at(this,Vn,()=>{});at(this,Zn,()=>{this.cwsIns.onReconnectSuccess=async()=>{await this.checkInRoom()?await this.reconstruct():this.setRoomState("closed")}});at(this,Kn,async()=>{this.cwsIns.onReconnectStop=async()=>{this.setRoomState("closed")}});Ee(this,"addRequestAnimationFrame",async(q,J)=>{{const D=De(this,bn).get(q);D&&cancelAnimationFrame(D)}const I=(D=Date.now())=>{J(D);const a=requestAnimationFrame(I);De(this,bn).set(q,a)};I()});Ee(this,"clearRequestAnimationFrame",async(q=[])=>{q.length===0&&(q=[...De(this,bn).keys()]);const J=[];for(const I of q){const D=De(this,bn).get(I);D&&(cancelAnimationFrame(D),J.push(D))}return J});Ee(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(q=>setTimeout(()=>q(!0),300)),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.cwsIns.close()});De(this,Vn).call(this),De(this,Zn).call(this),De(this,Kn).call(this),De(this,Wn).call(this),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: quickvo",this)}}bn=new WeakMap,Wn=new WeakMap,Vn=new WeakMap,Zn=new WeakMap,Kn=new WeakMap,exports.QuickVO=QuickVO,exports.ignoreEvent=ignoreEvent,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
206
+ gUn…g= !þ+µèm M½Êê½½²¦é%0Yg~´p5.\Ø®z‚y9%Ôiܒ!Ùc‰ÝŦH>ÓX ÿZR’[¬&ønÇl’Ó_:ïi«ñ<ø"QÚ©yz …®ªOL¥ÎêŠÌÝi?Ê‚'/Ne»:2NÅÝ_òspüR Oø!!ù+##üÓkéªX-fpd“q[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ÎËýæ×%I­OIø¦Ä(HTJ†~),ÕDCWWÃö(›VwV=M§TsLP³ þV'tT#¡ZLŽêé;ßù[`});var be={a:se};this.setModule=Se=>{N.setModule(EmscriptenWASM,Se)},this.getModule=()=>N.getModule(EmscriptenWASM),this.instantiate=()=>(this.getModule().then(Se=>WebAssembly.instantiate(Se,be)).then(Se=>{const Me=Se.exports;fe(Me),I=Me.g,D(),Ie(Me),Z()}),this.ready=new Promise(Se=>{Z=Se}).then(()=>{this.HEAP=I.buffer,this.malloc=ue,this.free=ye,this.opus_frame_decoder_create=ge,this.opus_frame_decode_float_deinterleaved=_e,this.opus_frame_decoder_destroy=pe}),this)}function OpusDecoder(N={}){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(K=>{this._common=K,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 te=this._common.allocateTypedArray(this._channels,Uint8Array);te.buf.set(this._channelMappingTable),this._decoder=this._common.wasm.opus_frame_decoder_create(this._sampleRate,this._channels,this._streamCount,this._coupledStreamCount,te.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=K=>{if(!(K instanceof Uint8Array))throw Error("Data to decode must be Uint8Array. Instead got "+typeof K);this._input.buf.set(K);let te=this._common.wasm.opus_frame_decode_float_deinterleaved(this._decoder,this._input.ptr,K.length,this._output.ptr),ne;return te<0&&(ne="libopus "+te+" "+(OpusDecoder.errors.get(te)||"Unknown Error"),console.error(ne),te=0),{outputBuffer:this._common.getOutputChannels(this._output.buf,this._outputChannels,te),samplesDecoded:te,error:ne}},this.decodeFrame=K=>{let te=[];const ne=this._decode(K);return ne.error&&this._common.addError(te,ne.error,K.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=K.length,this._outputSamples+=ne.samplesDecoded,this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(te,[ne.outputBuffer],this._outputChannels,ne.samplesDecoded,this._sampleRate)},this.decodeFrames=K=>{let te=[],ne=[],ee=0,re=0;for(;re<K.length;){const ce=K[re++],oe=this._decode(ce);te.push(oe.outputBuffer),ee+=oe.samplesDecoded,oe.error&&this._common.addError(ne,oe.error,ce.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=ce.length,this._outputSamples+=oe.samplesDecoded}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(ne,te,this._outputChannels,ee,this._sampleRate)},this._isWebWorker=OpusDecoder.isWebWorker,this._WASMAudioDecoderCommon=OpusDecoder.WASMAudioDecoderCommon||WASMAudioDecoderCommon,this._EmscriptenWASM=OpusDecoder.EmscriptenWASM||EmscriptenWASM,this._module=OpusDecoder.module;const Z=8,q=K=>typeof K=="number",J=N.sampleRate,I=N.channels,D=N.streamCount,a=N.coupledStreamCount,O=N.channelMappingTable,F=N.preSkip,z=N.forceStereo?1:0;if(I>2&&(!q(D)||!q(a)||!Array.isArray(O)))throw new Error("Invalid Opus Decoder Options for multichannel decoding.");return this._sampleRate=[8e3,12e3,16e3,24e3,48e3].includes(J)?J:48e3,this._channels=q(I)?I:2,this._streamCount=q(D)?D:1,this._coupledStreamCount=q(a)?a:this._channels-1,this._channelMappingTable=O||(this._channels===2?[0,1]:[0]),this._preSkip=F||0,this._forceStereo=I<=Z&&I!=2?z: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(Z){super(Z,"opus-decoder",OpusDecoder,EmscriptenWASM)}async decodeFrame(Z){return this.postToDecoder("decodeFrame",Z)}async decodeFrames(Z){return this.postToDecoder("decodeFrames",Z)}}assignNames(OpusDecoder,"OpusDecoder"),assignNames(OpusDecoderWebWorker,"OpusDecoderWebWorker"),new OpusDecoder;class RoomPeer extends RoomUsers{constructor(q){super(q);Ee(this,"getPeerStatsTimer",0);Ee(this,"reports",[]);Ee(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});Ee(this,"initPeer",()=>{var q;(q=this.peerIns)==null||q.close(),this.transceiverMap=new Map,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),De(this,Hn).call(this),De(this,zn).call(this)});Ee(this,"getNatType",async()=>{});Ee(this,"initSendChannel",(q="",J)=>{});Ee(this,"initReceiveChannel",(q="",J)=>{});Ee(this,"replaceSenderStream",async(q=[],J)=>{const{userId:I}=this.options;q.length===0&&(q=mediaType_keys);for(const D of q){const a=this.transceiverMap.get(D);let O;if(a){const{sender:F}=a;J?O=this.getUserStream(I,D):O=this.getPhoneyStreams(D);const[z]=O.getTracks();z&&await F.replaceTrack(z)}}});Ee(this,"getSenderTracks",async(q=[])=>{const J=[];for(const I of q){const D=this.transceiverMap.get(I);if(!D)continue;const{mid:a,sender:O}=D,{track:F}=O;if(!F)continue;const{id:z,enabled:K}=F,te=mediaType_keys.findIndex(ee=>ee===I),ne={type:te,enabled:K,trackName:`web-${te}-${z}`,location:"local",mid:a};J.push(ne)}return J});Ee(this,"addSenders",async(q=[])=>{q.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const J=[];for(const I of q){if(this.transceiverMap.get(I))continue;const a=this.getPhoneyStreams(I),[O]=a.getTracks(),F=this.peerIns.addTransceiver(O,{direction:"sendonly"});this.transceiverMap.set(I,F),J.push(I)}if(q.length===0||J.length!==0){const I=await this.peerIns.createOffer();if(this.options.debug){const D=libExports$1.parse(I.sdp),a=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:a,sdpJson:D,description:I})}await this.peerIns.setLocalDescription(I)}return J});Ee(this,"removeSenders",async(q=[])=>{q.length===0&&(q=mediaType_keys);for(const J of q)this.transceiverMap.has(J)&&this.transceiverMap.delete(J)});Ee(this,"onSubscribeUserTracks",q=>{let J=0;return new Promise(async I=>{const D=[];for(const a of q){const{tracks:O=[]}=a;for(const F of O){const{trackName:z,mid:K}=F,[te]=await this.getUserTrackByTrackName([z]);D.push({...te,mid:K})}}{let a=[];const O=async()=>{clearTimeout(J);const z=new Map;for(const te of a){const{userId:ne,mediaType:ee}=te;if(!ne||!ee)continue;z.has(ne)||z.set(ne,{userId:ne,tracks:[],updateStreams:{}});const ce=z.get(ne);ce.tracks.push(te),ce.updateStreams[ee]=!0}const K=[...z.values()];for(const te of K){const{userId:ne,tracks:ee}=te;await this.updateUsertracks(ne,ee,!0)}await this.emitNotifyUpdateUsersStreams(K),this.peerIns.removeEventListener("track",F);{const te=Array.from(D,re=>re.trackName),ne=Array.from(a,re=>re.trackName),ee=te.filter(re=>!ne.includes(re));I({target:te,success:ne,fail:ee})}},F=async z=>{const{streams:K,transceiver:te}=z,[ne]=K,{mid:ee,receiver:re}=te,{track:ce}=re,{id:oe}=ce,se=D.find(ue=>ue.mid===`${ee}`);if(!se)return;const{userId:fe,mediaType:ge}=se;if(!(!fe||!ge)){{const ue={...se,mid:ee,msid:oe};a.push(ue)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${a.length}/${D.length}`,{mediaType:ge,mid:ee,userTrack:se,e:z});{const ue=new Audio;if(ue.srcObject=ne,await this.initUserMediaStreamContext(fe,ge,ne),ge==="microphoneCamera_audio"||ge==="screenSharing_audio"){const _e=this.getUserAudioMediaStreamContext(fe,ge);_e==null||_e.setMute(!1)}}D.length===a.length&&O()}};this.peerIns.addEventListener("track",F),J=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${a.length}/${D.length})`),O()},5*1e3)}})});at(this,Hn,()=>{let q=0;const J=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.oniceconnectionstatechange=async()=>{const I=this.peerIns.iceConnectionState;switch(await this.taskQueue.setCondition("ice",!1),clearTimeout(q),I){case"connected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${I}`),await this.taskQueue.setCondition("ice",!0),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:${I}`),q=window.setTimeout(J,30*1e3);break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${I}`),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:${I}`),J();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${I}`);break}}});Ee(this,"closeUserTracks",async(q,J=[],I=!1)=>{const D=[];for(const z of J){const{trackName:K,msid:te}=z;D.push(K),te&&D.push(te)}const a=z=>D.includes(z),O=this.peerIns.getTransceivers();for(const z of O){const{mid:K,sender:te,receiver:ne}=z;te.track&&a(te.track.id)&&(z.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${K} is stop.`,z)),ne.track&&a(ne.track.id)&&(z.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${K} is stop.`,z))}const F=await this.getUser(q);if(F){for(const z of F.tracks){const{trackName:K,msid:te,userId:ne,mediaType:ee}=z;!ne||!ee||!a(K)||(this.removeUserMediaStreamContext(ne,ee),te&&delete z.msid)}if(I){const z=F.tracks.filter(({trackName:K})=>!a(K));await this.updateUsertracks(q,z,!1)}}});Ee(this,"createOffer",async()=>{const q=await this.peerIns.createOffer();if(this.options.debug){const J=libExports$1.parse(q.sdp),I=dt(J.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:I,sdpJson:J,description:q})}await this.peerIns.setLocalDescription(q)});Ee(this,"createAnswer",async()=>{const q=await this.peerIns.createAnswer();if(this.options.debug){const J=libExports$1.parse(q.sdp),I=dt(J.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:I,sdpJson:J,description:q})}await this.peerIns.setLocalDescription(q)});Ee(this,"getSdp",()=>{var q;return(q=this.peerIns.localDescription)==null?void 0:q.sdp});Ee(this,"setRemoteDescription",async q=>{if(this.options.debug){const J=libExports$1.parse(q.sdp),I=dt(J.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:I,sdpJson:J,description:q})}return await this.peerIns.setRemoteDescription(q),q});Ee(this,"setCallStrategy",async(q,J=[])=>{J.length===0&&(J=mediaType_keys);let I="balanced";switch(q){case"qualityPriority":I="maintain-resolution";break;case"fluencyPriority":I="maintain-framerate";break;case"balancedDowngrade":I="balanced";break}const D=await this.getSelfInfo(),a=Array.from(D.tracks,({trackName:F})=>F),O=this.peerIns.getSenders();for(const F of O){const{track:z}=F;if(!z||!a.includes(z.id))continue;const K=F.getParameters();F.setParameters({...K,degradationPreference:I})}});Ee(this,"setRTCRtpSenderParameters",q=>{try{const J=this.peerIns.getSenders();for(const I of J){const D=I.getParameters();I.setParameters({...D,...q})}}catch(J){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",J)}});Ee(this,"getReportsByMid",async(q=[])=>q.length===0?this.reports:this.reports.filter(J=>q.includes(J.mid)));Ee(this,"getRoomNetwork",()=>this.peerNetwork);Ee(this,"getPeerNetwork",()=>this.peerNetwork);at(this,jn,async()=>{try{const q=await this.peerIns.getStats(),J=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],D=[...q.values()].filter(_e=>J.includes(_e.type));let a=0,O=0,F=0,z=0,K=0,te=0,ne=[],ee=[];for(const _e of this.reports){const{packetsSent:pe,packetsLost:ye}=_e;pe&&(F+=pe),ye&&(z+=ye)}this.reports=D;for(const _e of this.reports){const{bytesSent:pe,bytesReceived:ye,packetsSent:we,packetsLost:Ie,roundTripTime:be,jitter:Se}=_e;pe&&(O=pe),ye&&(a=ye),we&&(K+=we),Ie&&(te+=Ie),be&&ne.push((be*100).toFixed(2)),Se&&ee.push(Se.toFixed(2))}ee.sort().reverse(),ne.sort().reverse();const re=K-F,ce=te-z,oe=re===0?"0.00":(ce/re).toFixed(2),[se="0"]=ne,[fe="0"]=ee,ge={outboundBytes:O,inboundBytes:a,lostRate:oe,roundTripTime:se,jitter:fe};this.peerNetwork=ge;const ue=(_e,pe,ye)=>{const we=Number(_e),Ie=Number(pe),be=Number(ye);let Se="0";return we<.03&&Ie<100&&be<.05?Se="5":we<.06&&Ie<160&&be<.1?Se="4":we<.1&&Ie<250&&be<.15?Se="3":we<.15&&Ie<400&&be<.2?Se="2":Se="1",Number(Se)};{const _e=ue(oe,se,fe),pe=await this.getSelfInfo(),{network:ye}=pe,we={egress:_e,ingress:_e};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,we),JSON.stringify(ye)!==JSON.stringify(we)){this.emitNotifyUpdateUsers();const{userId:Se,roomId:Me}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...we,userId:Se,roomId:Me}},!1)}},3*1e3)}}catch(q){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",q)}});at(this,zn,()=>{const q=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||De(this,jn).call(this)};this.getPeerStatsTimer=window.setInterval(q,1*1e3)});Ee(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer))}}Hn=new WeakMap,jn=new WeakMap,zn=new WeakMap;class RoomCalls extends RoomPeer{constructor(q){super(q);at(this,Tn,0);Ee(this,"setLocalStream",(q,J)=>new Promise(async(I,D)=>{try{typeof q=="string"&&(q=[q]);for(const O of q)this.localStreamsActionMap.set(O,J);if(J){if(q.includes("microphoneCamera_audio")&&q.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):q.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):q.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):q.includes("screenSharing_audio")&&q.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):q.includes("screenSharing_audio")&&!q.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):q.includes("screenSharing_video")&&!q.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),q.includes("screenSharing_audio")){const O=await this.getLocalStream("screenSharing_audio");if(O){const F=O.getTracks();for(const z of F)z.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if(q.includes("screenSharing_video")){const O=await this.getLocalStream("screenSharing_video");if(O){const F=O.getTracks();for(const z of F)z.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams(q);const a=await this.getLocalStreams(q);this.cwsIns.emitNotify("onLocalStream",{code:200,data:a,desc:"local stream is change."}),I(a)}catch(a){D(a)}}));Ee(this,"setMediaDeviceKind",(q,J)=>new Promise(async(I,D)=>{this.setDeviceKind(q,J);const a=await this.getSelfInfo(),{id:O,tracks:F=[],callActionMap:z}=a,K=[],te=async ne=>{const ee=this.localStreamsActionMap.get(ne),re=F.find(oe=>oe.mediaType===ne),ce=z[ne];if(ee){K.push(ne),await this.stopLocalStreams([ne]);try{await this.initLocalStream(ne)}catch(oe){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initLocalStream is error.",oe),await this.inactiveTracks([ne],!1),D(oe)}}if(re){const oe=await this.getLocalStream(ne);oe&&(await this.initUserMediaStreamContext(O,ne,oe),ce&&await this.replaceSenderStream([ne],!0))}{const oe=await this.getLocalStreams(K);this.cwsIns.emitNotify("onLocalStream",{code:200,data:oe,desc:"local stream is change."}),await this.emitNotifyUpdateUsers(),I(!0)}};q==="audioinput"&&te("microphoneCamera_audio"),q==="videoinput"&&te("microphoneCamera_video"),q==="audiooutput"&&(await this.changeAudiooutput(),I(!0))}));Ee(this,"changeScreenSharing",async q=>{const J=await this.getSelfInfo(),{tracks:I=[],callActionMap:D}=J;try{await this.setLocalStream(q,!0);for(const a of q)I.find(F=>F.mediaType===a&&D[a])&&await this.replaceSenderStream([a],!0)}catch(a){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",a)}});Ee(this,"createSession",()=>new Promise(async(q,J)=>{if(["connecting","connected"].includes(this.roomState))return q(!0);this.setRoomState("connecting"),await this.taskQueue.createTask({describe:"createSession",conditionKeys:["createWs","createSession"],changeConditionKeys:["createSession"],func:()=>new Promise(async(I,D)=>{try{await this.addSenders(),this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async a=>{const{code:O=0,desc:F,data:z}=a;if(O!==200)return D(F);const{remoteSdp:K}=z;if(this.options.debug){const te=libExports$1.parse(K),ne=dt(te.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:ne,sdpJson:te})}await this.taskQueue.setCondition("ice",!1),await this.taskQueue.createTask({describe:"ice",timeout:30*1e3,conditionKeys:["ice"],func:()=>new Promise(te=>setTimeout(()=>te(!0),300)),success:async()=>{I(!0)},fail:async te=>{throw new Error(`ice connection failed: ${te}`)}}),await this.setRemoteDescription({type:"answer",sdp:K})})}catch(a){D(a)}}),success:async I=>{q(I)},fail:async I=>{this.reportLogs("ws_c_timeout",I.message||I),J(I)},complete:()=>{this.taskQueue.setCondition("createSession",!0)}})}));Ee(this,"earlyConnect",(q=[])=>{this.isEarly=!0,De(this,Cn).call(this),this.createSession(),q.length===0&&(q=["microphoneCamera_audio","microphoneCamera_video"]),De(this,An).call(this,q)});Ee(this,"joinRoom",async q=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"joinRoom",conditionKeys:["createWs"],changeConditionKeys:["joinRoom"],func:()=>new Promise(async(D,a)=>{try{this.setOptions(q),await De(this,Cn).call(this),this.clearUsers();const{roomId:O,userId:F,callType:z,sdkToken:K}=this.options;this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:z,roomId:O,user:{id:F,tracks:[],callAction:0},token:K},version:2}).then(async te=>{const{code:ne=0,desc:ee="服务器繁忙",data:re}=te;if(ne!==200)return a(ee);const{roomId:ce="",roomUsers:oe=[]}=re;if(ce!==O)return a("加入的房间不匹配");this.isInRoom=!0,this.taskQueue.setCondition("createTrack",!0),this.taskQueue.setCondition("publish",!0),this.taskQueue.setCondition("subscribe",!0),this.taskQueue.setCondition("renegotiate",!0),this.taskQueue.setCondition("closeTrack",!0),this.initHeartbeat(),this.createSession(),await this.updateUsers(oe);const se=[];for(const ge of oe){const{id:ue,channelCache:_e}=ge,{channels:pe=[]}=_e;await this.updateUserBehaviors(ue,ge.behavior),await this.updateUserChannels(ue,pe,!1),pe.length!==0&&se.push({userId:ue,channels:pe})}this.subChannel(se),await this.emitNotifyUpdateUsers();const fe=await this.getUsers();D(fe)})}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("join_room_error",D.message||D),I(D)},complete:()=>{this.taskQueue.setCondition("joinRoom",!0)}})}));Ee(this,"quitRoom",()=>new Promise(async q=>{const{roomId:J,userId:I}=this.options,D={roomId:J,user:{id:I}};try{this.isInRoom=!1,clearInterval(De(this,Tn)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(a){this.reportLogs("quit_room_error",a.message||a)}await new Promise(a=>setTimeout(()=>a(!0),300)),await this.taskQueue.setCondition("closeTrack",!0),this.cwsIns.sendMessage({event:"quitRoom",data:D}),q(!0)}));Ee(this,"quitRoomEx",()=>new Promise(async q=>{const{roomId:J,userId:I}=this.options,D={roomId:J,user:{id:I}};try{this.isInRoom=!1,this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(a){this.reportLogs("quit_room_error",a.message||a)}await new Promise(a=>setTimeout(()=>a(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:D}),q(!0)}));Ee(this,"syncRoomInfo",()=>new Promise(async(q,J)=>{const{userId:I}=this.options,D=await this.getUser(I),{id:a=I,callAction:O=0}=D;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:a,callAction:O}}}).then(async F=>{if(F.code!==200)return J(F.desc);const z=F.data.users;this.clearUsers(),await this.updateUsers(z),await this.updateUsertracks(D.id,D.tracks,!1);{const K=await this.getUsers();q(K)}}).catch(F=>J(F))}));Ee(this,"checkInRoom",()=>new Promise(async(q,J)=>{const{userId:I}=this.options,D=await this.getUser(I),{id:a=I,callAction:O=0}=D;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:a,callAction:O}}}).then(async F=>F.code!==200?J(F.desc):F.data.users.find(te=>te.id===this.options.userId)?q(!0):q(!1)).catch(()=>q(!1))}));Ee(this,"publish",q=>new Promise(async(J,I)=>{{const D=await this.getSelfInfo(),{banBehaviorMap:a}=D;let O=!0;for(const F of q)if(a[F]){O=!1;break}if(O===!1)return I("publish is error: prohibited by administrator.")}try{await this.setLocalStream(q,!0)}catch(D){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",D)}await this.taskQueue.createTask({describe:"publish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["publish"],func:()=>new Promise(async(D,a)=>{try{const O=await this.getSelfInfo(),F=[];for(const ee of q){{const re=this.getPhoneyStreams(ee);await this.initUserMediaStreamContext(O.id,ee,re)}{const re=await this.getLocalStream(ee);re?await this.initUserMediaStreamContext(O.id,ee,re):F.push(ee)}}const z=q.filter(ee=>!F.includes(ee)||["microphoneCamera_audio","microphoneCamera_video"].includes(ee));await this.replaceSenderStream(q,!1),await De(this,An).call(this,z);const K=await this.getSenderTracks(z),te=[...O.tracks,...K];await this.updateUsertracks(O.id,te,!0),F.length!==0&&await this.inactiveTracks(F,!1),z.length!==0&&await this.replaceSenderStream(z,!0);const ne=await this.getCallAction(te);await De(this,On).call(this,ne),await new Promise(ee=>setTimeout(()=>ee(!0),230)),De(this,Jn).call(this,q);{await this.emitNotifyUpdateUsers();const ee=await this.getSelfInfo();D(ee)}}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("publish_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("publish",!0)}})}));Ee(this,"stopPublish",(q=[])=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"stopPublish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(D,a)=>{try{const O=await this.getSelfInfo();q.length===0&&(q=mediaType_keys);const F=O.tracks.filter(({mediaType:K})=>K&&q.includes(K)),z=async()=>{this.initMediaPhoneyStreams(q);const K=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),D(K)};if(F.length===0)return z();await this.replaceSenderStream(q,!0),await this.closeUserTracks(O.id,F,!0),await this.removeSenders(q);{const K=await this.getCallAction(O.tracks);await De(this,On).call(this,K)}await this.createOffer(),this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:F}}).then(async K=>{const{code:te=0,data:ne,desc:ee}=K;if(te!==200)return a(ee);const{remoteSdp:re}=ne;await this.setRemoteDescription({type:"answer",sdp:re}),z()})}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("close_track_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ee(this,"subscribe",(q=[],J=3)=>new Promise(async(I,D)=>{const a=await this.taskQueue.createTask({describe:"subscribe",strict:!0,conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["subscribe"],func:()=>new Promise(async(O,F)=>{try{const z=await this.getUsers();let K=[];for(const ee of z){const{isSelf:re,tracks:ce=[]}=ee;if(!re){const oe=ce.filter(({trackName:se,mid:fe=""})=>fe!==""&&(q.includes(se)||q.length===0));oe.length!==0&&K.push({...ee,tracks:oe})}}const te=async(ee={})=>{const re=Array.from(K,({id:oe})=>oe),ce=await this.getUsers(re);await this.emitNotifyUpdateUsers(),O({users:ce,detail:ee})};if(K.length===0)return te();const ne=[];for(const ee of K){const{id:re,tracks:ce}=ee,oe=dt(ce,["type","trackName"]),se={id:re,tracks:oe};ne.push(se)}this.cwsIns.sendMessage({event:"subscribe",data:{users:ne}}).then(async ee=>{const{code:re=0,data:ce,desc:oe}=ee;if(re===2017&&oe.includes("renegotiation is expected before pulling or pushing tracks")&&await this.renegotiate(),re!==200)return F(oe);const{remoteSdp:se,users:fe=[]}=ce;this.onSubscribeUserTracks(fe).then(async ge=>{await this.renegotiate().then(()=>te(ge)).catch(ue=>F(ue))}).catch(ge=>{F(ge)}),await this.setRemoteDescription({type:"offer",sdp:se})})}catch(z){F(z)}}),success:async O=>{a.clear(),this.taskQueue.setCondition("subscribe",!0),I(O)},fail:async O=>{if(this.options.debug&&console.info("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: subscribe error. surplus count is ${J}`),J>0)return await new Promise(F=>setTimeout(()=>F(!0),(3-J)*1e3)),J=J-1,a.retry();a.clear(),this.reportLogs("subscribe_error",O.message||O),this.taskQueue.setCondition("subscribe",!0),D(O)},complete:async()=>{}})}));Ee(this,"renegotiate",()=>new Promise(async(q,J)=>{try{await this.taskQueue.setCondition("renegotiate",!1),await this.createAnswer(),this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(I=>{const{code:D=0,desc:a}=I;if(D!==200)return J(a);q(I)})}catch(I){J(I)}this.taskQueue.setCondition("renegotiate",!0)}));Ee(this,"stopSubscribe",(q=[])=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"closeTrack",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(D,a)=>{try{const O=await this.getUsers(),F=[];for(const K of O){const{tracks:te=[]}=K;for(const ne of te){const{type:ee,mid:re,trackName:ce,mediaType:oe,msid:se}=ne;if(!(!oe||!se)&&(q.length===0||q.includes(ce))){const fe={type:ee,mid:re,trackName:se};F.push(fe),await this.closeUserTracks(K.id,[ne])}}}const z=async()=>{await this.emitNotifyUpdateUsers(),D(!0)};if(F.length===0)return z();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:F}}).then(async K=>{const{remoteSdp:te}=K.data;await this.setRemoteDescription({type:"answer",sdp:te})}),z()}catch(O){a(O)}}),success:async D=>{J(D)},fail:async D=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: stopPublish is error.",D),this.reportLogs("close_track_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ee(this,"inactiveTracks",async(q,J)=>new Promise(async I=>{const D=await this.getSelfInfo();if(!D||!D.id)return I(!0);const{tracks:a=[]}=D,O=[...a];for(let z of O){const{mediaType:K}=z;if(K&&q.includes(K)){z.enabled=J;const te=await this.getLocalStream(K);if(!te)continue;const ne=te.getTracks();for(const ee of ne)ee.enabled=J}}await this.replaceSenderStream(q,J);const F=await this.getCallAction(O);await De(this,On).call(this,F),await this.emitNotifyUpdateUsers(),I(!0)}));Ee(this,"setBanBehaviors",q=>new Promise(async(J,I)=>{try{const{roomId:D}=this.options,a=[];for(const O of q){const{id:F,banBehaviors:z}=O,K=Object.keys(z);if(K.length===0)continue;const te=[];for(const ee of K){const re=mediaType_keys.findIndex(se=>se===ee),ce=z[ee],oe={type:re,behavior:ce};te.push(oe)}const ne={id:F,behaviors:te};a.push(ne)}this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:D,users:a}}).then(async O=>{const{code:F=0,desc:z}=O;if(F!==200)return I(z);J(O)}).finally(()=>{})}catch(D){I(D)}}));Ee(this,"pubChannel",()=>new Promise(async(q,J)=>{const D=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:D}}).then(async a=>{const{code:O=0,data:F,desc:z}=a;if(O!==200)return J(z);const{channels:K=[]}=F;for(const te of K){const{channels:ne=[]}=te;for(const ee of ne){const{dataChannelName:re,id:ce}=ee;this.initSendChannel(re,ce)}}q(!0)}).catch(a=>{J(a)})}));Ee(this,"subChannel",(q=[])=>new Promise(async(J,I)=>{if(q.length===0)return J(!0);await this.taskQueue.createTask({describe:"subChannel",strict:!0,conditionKeys:["createWs","createSession","ice"],changeConditionKeys:[],func:()=>this.cwsIns.sendMessage({event:"subChannel",data:{channels:q}}).then(async D=>{const{code:a=0,data:O,desc:F}=D;if(a!==200)return I(F);const{channels:z=[]}=O;for(const K of z){const{channels:te=[]}=K;for(const ne of te){const{dataChannelName:ee,id:re}=ne;this.initReceiveChannel(ee,re)}}}),success:async D=>{J(D)},fail:async D=>{I(D)}})}));Ee(this,"debugger",()=>new Promise(async(q,J)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async I=>{if(I.code!==200)return J(I.desc);q(!0)}).catch(I=>{J(I)})}));Ee(this,"shutdown",()=>new Promise(async(q,J)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async I=>{if(I.code!==200)return J(I.desc);q(!0)}).catch(I=>{J(I)})}));Ee(this,"initHeartbeat",()=>{this.stopHeartbeat();const q=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),J=this.isInRoom?5*1e3:30*1e3;Ct(this,Tn,window.setInterval(q,J)),q()});Ee(this,"stopHeartbeat",()=>{clearInterval(De(this,Tn))});at(this,Jn,async q=>{const{roomId:J}=this.options;if(!J)return;const{id:I,tracks:D=[]}=await this.getSelfInfo(),a=D.filter(O=>O.mediaType&&q.includes(O.mediaType));a.length!==0&&this.cwsIns.sendMessage({event:"pubNotify",data:{roomId:J,user:{id:I,tracks:a}}})});at(this,On,async q=>new Promise(async(J,I)=>{const{roomId:D,userId:a}=this.options,O={roomId:D,user:{id:a,callAction:q}};await this.cwsIns.sendMessage({event:"updateCall",data:O}).then(async F=>{const{code:z=0}=F;if(z!==200)return I(F);await this.updateUserCallAction(a,q),J(q)}).catch(F=>I(F))}));at(this,Cn,()=>new Promise(async(q,J)=>{try{if(["connecting","connected"].includes(this.cwsIns.state))return q(!0);await this.taskQueue.setCondition("createWs",!1),this.cwsIns.clearEvents(),this.initPeer();const{appid:I,roomId:D,userId:a}=this.options;if(!I)return J("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const O={c:I,r:D,v:this.sdk_service_version};if(this.isEarly){const z=xt();O.i=z,this.setOptions({earlyId:z})}else O.b=a;this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs",O);const F=btoa(encodeURI(JSON.stringify(O)));await this.cwsIns.connect(F),this.initHeartbeat(),await this.taskQueue.setCondition("createWs",!0),await this.taskQueue.setCondition("createSession",!0),q(!0)}catch(I){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",I),this.reportLogs("ws_c_timeout",I.message||I),J(I)}}));at(this,An,async q=>new Promise(async(J,I)=>{await this.taskQueue.createTask({describe:"createTrack",conditionKeys:["createWs","createSession","ice","createTrack","subscribe","renegotiate","closeTrack"],func:()=>new Promise(async(D,a)=>{try{await this.taskQueue.setCondition("createTrack",!1);const O=await this.addSenders(q),F=await this.getSenderTracks(O);if(F.length===0)return await this.taskQueue.setCondition("createTrack",!0),D(!0);this.cwsIns.sendMessage({event:"publish",data:{sdp:this.getSdp(),tracks:F,callAction:0}}).then(async z=>{const{code:K=0,desc:te,data:ne}=z;if(K!==200)return a(te);const{remoteSdp:ee}=ne;await this.setRemoteDescription({type:"answer",sdp:ee}),D(!0)})}catch(O){await this.removeSenders(q),a(O)}}),success:async D=>{J(D)},fail:async D=>{this.reportLogs("publish_error",D.message||D),I(D)},complete:async()=>{await this.taskQueue.setCondition("createTrack",!0)}})}))}}Tn=new WeakMap,Jn=new WeakMap,On=new WeakMap,Cn=new WeakMap,An=new WeakMap;class Room extends RoomCalls{constructor(Z){super(Z)}}class QuickVO extends Room{constructor(q){super(q);at(this,bn,new Map);Ee(this,"reconstruct",async()=>{if(this.cwsIns.state!=="connected")return;this.setRoomState("ready"),this.initMediaPhoneyStreams(),this.taskQueue.clear(),this.initPeer(),this.taskQueue.setCondition("createSession",!0),this.taskQueue.setCondition("ice",!0),await this.createSession();const q=[],J=[],I=await this.getUsers();for(const D of I){const{isSelf:a,callActionMap:O,tracks:F=[]}=D;if(a)for(const z of mediaType_keys)O[z]&&q.push(z);for(const z of F)z.msid&&J.push(z.trackName)}await this.syncRoomInfo(),await this.publish(q),await this.subscribe(J)});at(this,Wn,()=>{{const q=async J=>{const{state:I}=J.data;if(I==="closed"){const{roomId:D,userId:a}=this.options,O={roomId:D,user:{id:a}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:O}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}};this.cwsIns.addNotify({event:"onRoomState",callback:q},!0)}{const q=async J=>{const{qualities:I=[]}=J.data,[D]=I;if(!(D&&D.userId===this.options.userId&&I.length===1)){for(const a of I){const{userId:O,egress:F,ingress:z}=a;this.checkUserInRoom(O)&&await this.updateUserNetwork(O,{egress:F,ingress:z})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:q},!0)}{const q=async J=>{const I=J.data.user;await this.updateUsers([I]),await this.updateUsertracks(I.id,I.track,!1),await this.updateUserBehaviors(I.id,I.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:q},!0)}{const q=async J=>{await this.removeUsers([J.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:q},!0)}{const q=async J=>{const{user:I}=J.data,{id:D,tracks:a=[],callAction:O=0}=I;if(await this.updateUserCallAction(D,O),await this.updateUserPermissions(D,3),await this.updateUsertracks(D,a,!0),this.options.newPublishAutoSubscribe){const F=this.getTrackNamesFormTracks(a);await this.subscribe(F)}else await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onPublish",callback:q},!0)}{const q=async J=>{const I=[J.data];this.subChannel(I)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:q},!0)}{const q=async J=>{const{id:I,tracks:D}=J.data.user;I!==this.options.userId&&(await this.closeUserTracks(I,D,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:q},!0)}{const q=async J=>{const{id:I,callAction:D}=J.data.user;this.checkUserInRoom(I)&&(await this.updateUserCallAction(I,D),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:q},!0)}{const q=async J=>{const{user:I}=J.data,{id:D,permissions:a=1}=I;a===1?await this.removeUsers([D]):a===3&&await this.updateUsers([I]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:q},!0)}{const q=async J=>{const{users:I}=J.data;for(const D of I){const{id:a,behavior:O}=D;await this.updateUserBehaviors(a,O)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:q},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async q=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});Ee(this,"addNotify",q=>this.cwsIns.addNotify(q));at(this,Vn,()=>{});at(this,Zn,()=>{this.cwsIns.onReconnectSuccess=async()=>{await this.checkInRoom()?await this.reconstruct():this.setRoomState("closed")}});at(this,Kn,async()=>{this.cwsIns.onReconnectStop=async()=>{this.setRoomState("closed")}});Ee(this,"addRequestAnimationFrame",async(q,J)=>{{const D=De(this,bn).get(q);D&&cancelAnimationFrame(D)}const I=(D=Date.now())=>{J(D);const a=requestAnimationFrame(I);De(this,bn).set(q,a)};I()});Ee(this,"clearRequestAnimationFrame",async(q=[])=>{q.length===0&&(q=[...De(this,bn).keys()]);const J=[];for(const I of q){const D=De(this,bn).get(I);D&&(cancelAnimationFrame(D),J.push(D))}return J});Ee(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(q=>setTimeout(()=>q(!0),300)),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.cwsIns.close()});De(this,Vn).call(this),De(this,Zn).call(this),De(this,Kn).call(this),De(this,Wn).call(this),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: quickvo",this)}}bn=new WeakMap,Wn=new WeakMap,Vn=new WeakMap,Zn=new WeakMap,Kn=new WeakMap,exports.QuickVO=QuickVO,exports.ignoreEvent=ignoreEvent,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});