quickvo-sdk-js 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +18033 -18107
- package/dist/index.umd.cjs +1 -1
- package/dist/protos/compiled.d.ts +5468 -5468
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -6,4 +6,4 @@ between two successive fields at the output of the decoding process (see the not
|
|
|
6
6
|
*
|
|
7
7
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
8
8
|
* @license MIT
|
|
9
|
-
*/var hasRequiredBuffer;function requireBuffer(){return hasRequiredBuffer||(hasRequiredBuffer=1,function(O){const N=requireBase64Js(),$=requireIeee754(),D=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;O.Buffer=c,O.SlowBuffer=de,O.INSPECT_MAX_BYTES=50;const b=2147483647;O.kMaxLength=b,c.TYPED_ARRAY_SUPPORT=k(),!c.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 k(){try{const K=new Uint8Array(1),F={foo:function(){return 42}};return Object.setPrototypeOf(F,Uint8Array.prototype),Object.setPrototypeOf(K,F),K.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function i(K){if(K>b)throw new RangeError('The value "'+K+'" is invalid for option "size"');const F=new Uint8Array(K);return Object.setPrototypeOf(F,c.prototype),F}function c(K,F,j){if(typeof K=="number"){if(typeof F=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Z(K)}return S(K,F,j)}c.poolSize=8192;function S(K,F,j){if(typeof K=="string")return J(K,F);if(ArrayBuffer.isView(K))return Y(K);if(K==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K);if(et(K,ArrayBuffer)||K&&et(K.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(et(K,SharedArrayBuffer)||K&&et(K.buffer,SharedArrayBuffer)))return re(K,F,j);if(typeof K=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const X=K.valueOf&&K.valueOf();if(X!=null&&X!==K)return c.from(X,F,j);const te=oe(K);if(te)return te;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof K[Symbol.toPrimitive]=="function")return c.from(K[Symbol.toPrimitive]("string"),F,j);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K)}c.from=function(K,F,j){return S(K,F,j)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array);function C(K){if(typeof K!="number")throw new TypeError('"size" argument must be of type number');if(K<0)throw new RangeError('The value "'+K+'" is invalid for option "size"')}function M(K,F,j){return C(K),K<=0?i(K):F!==void 0?typeof j=="string"?i(K).fill(F,j):i(K).fill(F):i(K)}c.alloc=function(K,F,j){return M(K,F,j)};function Z(K){return C(K),i(K<0?0:ie(K)|0)}c.allocUnsafe=function(K){return Z(K)},c.allocUnsafeSlow=function(K){return Z(K)};function J(K,F){if((typeof F!="string"||F==="")&&(F="utf8"),!c.isEncoding(F))throw new TypeError("Unknown encoding: "+F);const j=ye(K,F)|0;let X=i(j);const te=X.write(K,F);return te!==j&&(X=X.slice(0,te)),X}function z(K){const F=K.length<0?0:ie(K.length)|0,j=i(F);for(let X=0;X<F;X+=1)j[X]=K[X]&255;return j}function Y(K){if(et(K,Uint8Array)){const F=new Uint8Array(K);return re(F.buffer,F.byteOffset,F.byteLength)}return z(K)}function re(K,F,j){if(F<0||K.byteLength<F)throw new RangeError('"offset" is outside of buffer bounds');if(K.byteLength<F+(j||0))throw new RangeError('"length" is outside of buffer bounds');let X;return F===void 0&&j===void 0?X=new Uint8Array(K):j===void 0?X=new Uint8Array(K,F):X=new Uint8Array(K,F,j),Object.setPrototypeOf(X,c.prototype),X}function oe(K){if(c.isBuffer(K)){const F=ie(K.length)|0,j=i(F);return j.length===0||K.copy(j,0,0,F),j}if(K.length!==void 0)return typeof K.length!="number"||Qt(K.length)?i(0):z(K);if(K.type==="Buffer"&&Array.isArray(K.data))return z(K.data)}function ie(K){if(K>=b)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+b.toString(16)+" bytes");return K|0}function de(K){return+K!=K&&(K=0),c.alloc(+K)}c.isBuffer=function(F){return F!=null&&F._isBuffer===!0&&F!==c.prototype},c.compare=function(F,j){if(et(F,Uint8Array)&&(F=c.from(F,F.offset,F.byteLength)),et(j,Uint8Array)&&(j=c.from(j,j.offset,j.byteLength)),!c.isBuffer(F)||!c.isBuffer(j))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(F===j)return 0;let X=F.length,te=j.length;for(let ue=0,pe=Math.min(X,te);ue<pe;++ue)if(F[ue]!==j[ue]){X=F[ue],te=j[ue];break}return X<te?-1:te<X?1:0},c.isEncoding=function(F){switch(String(F).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}},c.concat=function(F,j){if(!Array.isArray(F))throw new TypeError('"list" argument must be an Array of Buffers');if(F.length===0)return c.alloc(0);let X;if(j===void 0)for(j=0,X=0;X<F.length;++X)j+=F[X].length;const te=c.allocUnsafe(j);let ue=0;for(X=0;X<F.length;++X){let pe=F[X];if(et(pe,Uint8Array))ue+pe.length>te.length?(c.isBuffer(pe)||(pe=c.from(pe)),pe.copy(te,ue)):Uint8Array.prototype.set.call(te,pe,ue);else if(c.isBuffer(pe))pe.copy(te,ue);else throw new TypeError('"list" argument must be an Array of Buffers');ue+=pe.length}return te};function ye(K,F){if(c.isBuffer(K))return K.length;if(ArrayBuffer.isView(K)||et(K,ArrayBuffer))return K.byteLength;if(typeof K!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof K);const j=K.length,X=arguments.length>2&&arguments[2]===!0;if(!X&&j===0)return 0;let te=!1;for(;;)switch(F){case"ascii":case"latin1":case"binary":return j;case"utf8":case"utf-8":return ot(K).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j*2;case"hex":return j>>>1;case"base64":return At(K).length;default:if(te)return X?-1:ot(K).length;F=(""+F).toLowerCase(),te=!0}}c.byteLength=ye;function Q(K,F,j){let X=!1;if((F===void 0||F<0)&&(F=0),F>this.length||((j===void 0||j>this.length)&&(j=this.length),j<=0)||(j>>>=0,F>>>=0,j<=F))return"";for(K||(K="utf8");;)switch(K){case"hex":return We(this,F,j);case"utf8":case"utf-8":return we(this,F,j);case"ascii":return Le(this,F,j);case"latin1":case"binary":return Fe(this,F,j);case"base64":return be(this,F,j);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ft(this,F,j);default:if(X)throw new TypeError("Unknown encoding: "+K);K=(K+"").toLowerCase(),X=!0}}c.prototype._isBuffer=!0;function ae(K,F,j){const X=K[F];K[F]=K[j],K[j]=X}c.prototype.swap16=function(){const F=this.length;if(F%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let j=0;j<F;j+=2)ae(this,j,j+1);return this},c.prototype.swap32=function(){const F=this.length;if(F%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let j=0;j<F;j+=4)ae(this,j,j+3),ae(this,j+1,j+2);return this},c.prototype.swap64=function(){const F=this.length;if(F%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let j=0;j<F;j+=8)ae(this,j,j+7),ae(this,j+1,j+6),ae(this,j+2,j+5),ae(this,j+3,j+4);return this},c.prototype.toString=function(){const F=this.length;return F===0?"":arguments.length===0?we(this,0,F):Q.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(F){if(!c.isBuffer(F))throw new TypeError("Argument must be a Buffer");return this===F?!0:c.compare(this,F)===0},c.prototype.inspect=function(){let F="";const j=O.INSPECT_MAX_BYTES;return F=this.toString("hex",0,j).replace(/(.{2})/g,"$1 ").trim(),this.length>j&&(F+=" ... "),"<Buffer "+F+">"},D&&(c.prototype[D]=c.prototype.inspect),c.prototype.compare=function(F,j,X,te,ue){if(et(F,Uint8Array)&&(F=c.from(F,F.offset,F.byteLength)),!c.isBuffer(F))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof F);if(j===void 0&&(j=0),X===void 0&&(X=F?F.length:0),te===void 0&&(te=0),ue===void 0&&(ue=this.length),j<0||X>F.length||te<0||ue>this.length)throw new RangeError("out of range index");if(te>=ue&&j>=X)return 0;if(te>=ue)return-1;if(j>=X)return 1;if(j>>>=0,X>>>=0,te>>>=0,ue>>>=0,this===F)return 0;let pe=ue-te,Ee=X-j;const Pe=Math.min(pe,Ee),qe=this.slice(te,ue),Ue=F.slice(j,X);for(let Ae=0;Ae<Pe;++Ae)if(qe[Ae]!==Ue[Ae]){pe=qe[Ae],Ee=Ue[Ae];break}return pe<Ee?-1:Ee<pe?1:0};function he(K,F,j,X,te){if(K.length===0)return-1;if(typeof j=="string"?(X=j,j=0):j>2147483647?j=2147483647:j<-2147483648&&(j=-2147483648),j=+j,Qt(j)&&(j=te?0:K.length-1),j<0&&(j=K.length+j),j>=K.length){if(te)return-1;j=K.length-1}else if(j<0)if(te)j=0;else return-1;if(typeof F=="string"&&(F=c.from(F,X)),c.isBuffer(F))return F.length===0?-1:ce(K,F,j,X,te);if(typeof F=="number")return F=F&255,typeof Uint8Array.prototype.indexOf=="function"?te?Uint8Array.prototype.indexOf.call(K,F,j):Uint8Array.prototype.lastIndexOf.call(K,F,j):ce(K,[F],j,X,te);throw new TypeError("val must be string, number or Buffer")}function ce(K,F,j,X,te){let ue=1,pe=K.length,Ee=F.length;if(X!==void 0&&(X=String(X).toLowerCase(),X==="ucs2"||X==="ucs-2"||X==="utf16le"||X==="utf-16le")){if(K.length<2||F.length<2)return-1;ue=2,pe/=2,Ee/=2,j/=2}function Pe(Ue,Ae){return ue===1?Ue[Ae]:Ue.readUInt16BE(Ae*ue)}let qe;if(te){let Ue=-1;for(qe=j;qe<pe;qe++)if(Pe(K,qe)===Pe(F,Ue===-1?0:qe-Ue)){if(Ue===-1&&(Ue=qe),qe-Ue+1===Ee)return Ue*ue}else Ue!==-1&&(qe-=qe-Ue),Ue=-1}else for(j+Ee>pe&&(j=pe-Ee),qe=j;qe>=0;qe--){let Ue=!0;for(let Ae=0;Ae<Ee;Ae++)if(Pe(K,qe+Ae)!==Pe(F,Ae)){Ue=!1;break}if(Ue)return qe}return-1}c.prototype.includes=function(F,j,X){return this.indexOf(F,j,X)!==-1},c.prototype.indexOf=function(F,j,X){return he(this,F,j,X,!0)},c.prototype.lastIndexOf=function(F,j,X){return he(this,F,j,X,!1)};function fe(K,F,j,X){j=Number(j)||0;const te=K.length-j;X?(X=Number(X),X>te&&(X=te)):X=te;const ue=F.length;X>ue/2&&(X=ue/2);let pe;for(pe=0;pe<X;++pe){const Ee=parseInt(F.substr(pe*2,2),16);if(Qt(Ee))return pe;K[j+pe]=Ee}return pe}function me(K,F,j,X){return Bt(ot(F,K.length-j),K,j,X)}function ee(K,F,j,X){return Bt(mt(F),K,j,X)}function le(K,F,j,X){return Bt(At(F),K,j,X)}function ve(K,F,j,X){return Bt(Xt(F,K.length-j),K,j,X)}c.prototype.write=function(F,j,X,te){if(j===void 0)te="utf8",X=this.length,j=0;else if(X===void 0&&typeof j=="string")te=j,X=this.length,j=0;else if(isFinite(j))j=j>>>0,isFinite(X)?(X=X>>>0,te===void 0&&(te="utf8")):(te=X,X=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ue=this.length-j;if((X===void 0||X>ue)&&(X=ue),F.length>0&&(X<0||j<0)||j>this.length)throw new RangeError("Attempt to write outside buffer bounds");te||(te="utf8");let pe=!1;for(;;)switch(te){case"hex":return fe(this,F,j,X);case"utf8":case"utf-8":return me(this,F,j,X);case"ascii":case"latin1":case"binary":return ee(this,F,j,X);case"base64":return le(this,F,j,X);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ve(this,F,j,X);default:if(pe)throw new TypeError("Unknown encoding: "+te);te=(""+te).toLowerCase(),pe=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function be(K,F,j){return F===0&&j===K.length?N.fromByteArray(K):N.fromByteArray(K.slice(F,j))}function we(K,F,j){j=Math.min(K.length,j);const X=[];let te=F;for(;te<j;){const ue=K[te];let pe=null,Ee=ue>239?4:ue>223?3:ue>191?2:1;if(te+Ee<=j){let Pe,qe,Ue,Ae;switch(Ee){case 1:ue<128&&(pe=ue);break;case 2:Pe=K[te+1],(Pe&192)===128&&(Ae=(ue&31)<<6|Pe&63,Ae>127&&(pe=Ae));break;case 3:Pe=K[te+1],qe=K[te+2],(Pe&192)===128&&(qe&192)===128&&(Ae=(ue&15)<<12|(Pe&63)<<6|qe&63,Ae>2047&&(Ae<55296||Ae>57343)&&(pe=Ae));break;case 4:Pe=K[te+1],qe=K[te+2],Ue=K[te+3],(Pe&192)===128&&(qe&192)===128&&(Ue&192)===128&&(Ae=(ue&15)<<18|(Pe&63)<<12|(qe&63)<<6|Ue&63,Ae>65535&&Ae<1114112&&(pe=Ae))}}pe===null?(pe=65533,Ee=1):pe>65535&&(pe-=65536,X.push(pe>>>10&1023|55296),pe=56320|pe&1023),X.push(pe),te+=Ee}return Ne(X)}const $e=4096;function Ne(K){const F=K.length;if(F<=$e)return String.fromCharCode.apply(String,K);let j="",X=0;for(;X<F;)j+=String.fromCharCode.apply(String,K.slice(X,X+=$e));return j}function Le(K,F,j){let X="";j=Math.min(K.length,j);for(let te=F;te<j;++te)X+=String.fromCharCode(K[te]&127);return X}function Fe(K,F,j){let X="";j=Math.min(K.length,j);for(let te=F;te<j;++te)X+=String.fromCharCode(K[te]);return X}function We(K,F,j){const X=K.length;(!F||F<0)&&(F=0),(!j||j<0||j>X)&&(j=X);let te="";for(let ue=F;ue<j;++ue)te+=nn[K[ue]];return te}function ft(K,F,j){const X=K.slice(F,j);let te="";for(let ue=0;ue<X.length-1;ue+=2)te+=String.fromCharCode(X[ue]+X[ue+1]*256);return te}c.prototype.slice=function(F,j){const X=this.length;F=~~F,j=j===void 0?X:~~j,F<0?(F+=X,F<0&&(F=0)):F>X&&(F=X),j<0?(j+=X,j<0&&(j=0)):j>X&&(j=X),j<F&&(j=F);const te=this.subarray(F,j);return Object.setPrototypeOf(te,c.prototype),te};function Re(K,F,j){if(K%1!==0||K<0)throw new RangeError("offset is not uint");if(K+F>j)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=this[F],ue=1,pe=0;for(;++pe<j&&(ue*=256);)te+=this[F+pe]*ue;return te},c.prototype.readUintBE=c.prototype.readUIntBE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=this[F+--j],ue=1;for(;j>0&&(ue*=256);)te+=this[F+--j]*ue;return te},c.prototype.readUint8=c.prototype.readUInt8=function(F,j){return F=F>>>0,j||Re(F,1,this.length),this[F]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(F,j){return F=F>>>0,j||Re(F,2,this.length),this[F]|this[F+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(F,j){return F=F>>>0,j||Re(F,2,this.length),this[F]<<8|this[F+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),(this[F]|this[F+1]<<8|this[F+2]<<16)+this[F+3]*16777216},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),this[F]*16777216+(this[F+1]<<16|this[F+2]<<8|this[F+3])},c.prototype.readBigUInt64LE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=j+this[++F]*2**8+this[++F]*2**16+this[++F]*2**24,ue=this[++F]+this[++F]*2**8+this[++F]*2**16+X*2**24;return BigInt(te)+(BigInt(ue)<<BigInt(32))}),c.prototype.readBigUInt64BE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=j*2**24+this[++F]*2**16+this[++F]*2**8+this[++F],ue=this[++F]*2**24+this[++F]*2**16+this[++F]*2**8+X;return(BigInt(te)<<BigInt(32))+BigInt(ue)}),c.prototype.readIntLE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=this[F],ue=1,pe=0;for(;++pe<j&&(ue*=256);)te+=this[F+pe]*ue;return ue*=128,te>=ue&&(te-=Math.pow(2,8*j)),te},c.prototype.readIntBE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=j,ue=1,pe=this[F+--te];for(;te>0&&(ue*=256);)pe+=this[F+--te]*ue;return ue*=128,pe>=ue&&(pe-=Math.pow(2,8*j)),pe},c.prototype.readInt8=function(F,j){return F=F>>>0,j||Re(F,1,this.length),this[F]&128?(255-this[F]+1)*-1:this[F]},c.prototype.readInt16LE=function(F,j){F=F>>>0,j||Re(F,2,this.length);const X=this[F]|this[F+1]<<8;return X&32768?X|4294901760:X},c.prototype.readInt16BE=function(F,j){F=F>>>0,j||Re(F,2,this.length);const X=this[F+1]|this[F]<<8;return X&32768?X|4294901760:X},c.prototype.readInt32LE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),this[F]|this[F+1]<<8|this[F+2]<<16|this[F+3]<<24},c.prototype.readInt32BE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),this[F]<<24|this[F+1]<<16|this[F+2]<<8|this[F+3]},c.prototype.readBigInt64LE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=this[F+4]+this[F+5]*2**8+this[F+6]*2**16+(X<<24);return(BigInt(te)<<BigInt(32))+BigInt(j+this[++F]*2**8+this[++F]*2**16+this[++F]*2**24)}),c.prototype.readBigInt64BE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=(j<<24)+this[++F]*2**16+this[++F]*2**8+this[++F];return(BigInt(te)<<BigInt(32))+BigInt(this[++F]*2**24+this[++F]*2**16+this[++F]*2**8+X)}),c.prototype.readFloatLE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),$.read(this,F,!0,23,4)},c.prototype.readFloatBE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),$.read(this,F,!1,23,4)},c.prototype.readDoubleLE=function(F,j){return F=F>>>0,j||Re(F,8,this.length),$.read(this,F,!0,52,8)},c.prototype.readDoubleBE=function(F,j){return F=F>>>0,j||Re(F,8,this.length),$.read(this,F,!1,52,8)};function xe(K,F,j,X,te,ue){if(!c.isBuffer(K))throw new TypeError('"buffer" argument must be a Buffer instance');if(F>te||F<ue)throw new RangeError('"value" argument is out of bounds');if(j+X>K.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(F,j,X,te){if(F=+F,j=j>>>0,X=X>>>0,!te){const Ee=Math.pow(2,8*X)-1;xe(this,F,j,X,Ee,0)}let ue=1,pe=0;for(this[j]=F&255;++pe<X&&(ue*=256);)this[j+pe]=F/ue&255;return j+X},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(F,j,X,te){if(F=+F,j=j>>>0,X=X>>>0,!te){const Ee=Math.pow(2,8*X)-1;xe(this,F,j,X,Ee,0)}let ue=X-1,pe=1;for(this[j+ue]=F&255;--ue>=0&&(pe*=256);)this[j+ue]=F/pe&255;return j+X},c.prototype.writeUint8=c.prototype.writeUInt8=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,1,255,0),this[j]=F&255,j+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,65535,0),this[j]=F&255,this[j+1]=F>>>8,j+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,65535,0),this[j]=F>>>8,this[j+1]=F&255,j+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,4294967295,0),this[j+3]=F>>>24,this[j+2]=F>>>16,this[j+1]=F>>>8,this[j]=F&255,j+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,4294967295,0),this[j]=F>>>24,this[j+1]=F>>>16,this[j+2]=F>>>8,this[j+3]=F&255,j+4};function it(K,F,j,X,te){Ie(F,X,te,K,j,7);let ue=Number(F&BigInt(4294967295));K[j++]=ue,ue=ue>>8,K[j++]=ue,ue=ue>>8,K[j++]=ue,ue=ue>>8,K[j++]=ue;let pe=Number(F>>BigInt(32)&BigInt(4294967295));return K[j++]=pe,pe=pe>>8,K[j++]=pe,pe=pe>>8,K[j++]=pe,pe=pe>>8,K[j++]=pe,j}function Me(K,F,j,X,te){Ie(F,X,te,K,j,7);let ue=Number(F&BigInt(4294967295));K[j+7]=ue,ue=ue>>8,K[j+6]=ue,ue=ue>>8,K[j+5]=ue,ue=ue>>8,K[j+4]=ue;let pe=Number(F>>BigInt(32)&BigInt(4294967295));return K[j+3]=pe,pe=pe>>8,K[j+2]=pe,pe=pe>>8,K[j+1]=pe,pe=pe>>8,K[j]=pe,j+8}c.prototype.writeBigUInt64LE=yt(function(F,j=0){return it(this,F,j,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=yt(function(F,j=0){return Me(this,F,j,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(F,j,X,te){if(F=+F,j=j>>>0,!te){const Pe=Math.pow(2,8*X-1);xe(this,F,j,X,Pe-1,-Pe)}let ue=0,pe=1,Ee=0;for(this[j]=F&255;++ue<X&&(pe*=256);)F<0&&Ee===0&&this[j+ue-1]!==0&&(Ee=1),this[j+ue]=(F/pe>>0)-Ee&255;return j+X},c.prototype.writeIntBE=function(F,j,X,te){if(F=+F,j=j>>>0,!te){const Pe=Math.pow(2,8*X-1);xe(this,F,j,X,Pe-1,-Pe)}let ue=X-1,pe=1,Ee=0;for(this[j+ue]=F&255;--ue>=0&&(pe*=256);)F<0&&Ee===0&&this[j+ue+1]!==0&&(Ee=1),this[j+ue]=(F/pe>>0)-Ee&255;return j+X},c.prototype.writeInt8=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,1,127,-128),F<0&&(F=255+F+1),this[j]=F&255,j+1},c.prototype.writeInt16LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,32767,-32768),this[j]=F&255,this[j+1]=F>>>8,j+2},c.prototype.writeInt16BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,32767,-32768),this[j]=F>>>8,this[j+1]=F&255,j+2},c.prototype.writeInt32LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,2147483647,-2147483648),this[j]=F&255,this[j+1]=F>>>8,this[j+2]=F>>>16,this[j+3]=F>>>24,j+4},c.prototype.writeInt32BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,2147483647,-2147483648),F<0&&(F=4294967295+F+1),this[j]=F>>>24,this[j+1]=F>>>16,this[j+2]=F>>>8,this[j+3]=F&255,j+4},c.prototype.writeBigInt64LE=yt(function(F,j=0){return it(this,F,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=yt(function(F,j=0){return Me(this,F,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ke(K,F,j,X,te,ue){if(j+X>K.length)throw new RangeError("Index out of range");if(j<0)throw new RangeError("Index out of range")}function rt(K,F,j,X,te){return F=+F,j=j>>>0,te||Ke(K,F,j,4),$.write(K,F,j,X,23,4),j+4}c.prototype.writeFloatLE=function(F,j,X){return rt(this,F,j,!0,X)},c.prototype.writeFloatBE=function(F,j,X){return rt(this,F,j,!1,X)};function Ye(K,F,j,X,te){return F=+F,j=j>>>0,te||Ke(K,F,j,8),$.write(K,F,j,X,52,8),j+8}c.prototype.writeDoubleLE=function(F,j,X){return Ye(this,F,j,!0,X)},c.prototype.writeDoubleBE=function(F,j,X){return Ye(this,F,j,!1,X)},c.prototype.copy=function(F,j,X,te){if(!c.isBuffer(F))throw new TypeError("argument should be a Buffer");if(X||(X=0),!te&&te!==0&&(te=this.length),j>=F.length&&(j=F.length),j||(j=0),te>0&&te<X&&(te=X),te===X||F.length===0||this.length===0)return 0;if(j<0)throw new RangeError("targetStart out of bounds");if(X<0||X>=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),F.length-j<te-X&&(te=F.length-j+X);const ue=te-X;return this===F&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(j,X,te):Uint8Array.prototype.set.call(F,this.subarray(X,te),j),ue},c.prototype.fill=function(F,j,X,te){if(typeof F=="string"){if(typeof j=="string"?(te=j,j=0,X=this.length):typeof X=="string"&&(te=X,X=this.length),te!==void 0&&typeof te!="string")throw new TypeError("encoding must be a string");if(typeof te=="string"&&!c.isEncoding(te))throw new TypeError("Unknown encoding: "+te);if(F.length===1){const pe=F.charCodeAt(0);(te==="utf8"&&pe<128||te==="latin1")&&(F=pe)}}else typeof F=="number"?F=F&255:typeof F=="boolean"&&(F=Number(F));if(j<0||this.length<j||this.length<X)throw new RangeError("Out of range index");if(X<=j)return this;j=j>>>0,X=X===void 0?this.length:X>>>0,F||(F=0);let ue;if(typeof F=="number")for(ue=j;ue<X;++ue)this[ue]=F;else{const pe=c.isBuffer(F)?F:c.from(F,te),Ee=pe.length;if(Ee===0)throw new TypeError('The value "'+F+'" is invalid for argument "value"');for(ue=0;ue<X-j;++ue)this[ue+j]=pe[ue%Ee]}return this};const He={};function ge(K,F,j){He[K]=class extends j{constructor(){super(),Object.defineProperty(this,"message",{value:F.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${K}]`,this.stack,delete this.name}get code(){return K}set code(te){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:te,writable:!0})}toString(){return`${this.name} [${K}]: ${this.message}`}}}ge("ERR_BUFFER_OUT_OF_BOUNDS",function(K){return K?`${K} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ge("ERR_INVALID_ARG_TYPE",function(K,F){return`The "${K}" argument must be of type number. Received type ${typeof F}`},TypeError),ge("ERR_OUT_OF_RANGE",function(K,F,j){let X=`The value of "${K}" is out of range.`,te=j;return Number.isInteger(j)&&Math.abs(j)>2**32?te=_e(String(j)):typeof j=="bigint"&&(te=String(j),(j>BigInt(2)**BigInt(32)||j<-(BigInt(2)**BigInt(32)))&&(te=_e(te)),te+="n"),X+=` It must be ${F}. Received ${te}`,X},RangeError);function _e(K){let F="",j=K.length;const X=K[0]==="-"?1:0;for(;j>=X+4;j-=3)F=`_${K.slice(j-3,j)}${F}`;return`${K.slice(0,j)}${F}`}function Se(K,F,j){De(F,"offset"),(K[F]===void 0||K[F+j]===void 0)&&je(F,K.length-(j+1))}function Ie(K,F,j,X,te,ue){if(K>j||K<F){const pe=typeof F=="bigint"?"n":"";let Ee;throw F===0||F===BigInt(0)?Ee=`>= 0${pe} and < 2${pe} ** ${(ue+1)*8}${pe}`:Ee=`>= -(2${pe} ** ${(ue+1)*8-1}${pe}) and < 2 ** ${(ue+1)*8-1}${pe}`,new He.ERR_OUT_OF_RANGE("value",Ee,K)}Se(X,te,ue)}function De(K,F){if(typeof K!="number")throw new He.ERR_INVALID_ARG_TYPE(F,"number",K)}function je(K,F,j){throw Math.floor(K)!==K?(De(K,j),new He.ERR_OUT_OF_RANGE("offset","an integer",K)):F<0?new He.ERR_BUFFER_OUT_OF_BOUNDS:new He.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${F}`,K)}const Je=/[^+/0-9A-Za-z-_]/g;function Ze(K){if(K=K.split("=")[0],K=K.trim().replace(Je,""),K.length<2)return"";for(;K.length%4!==0;)K=K+"=";return K}function ot(K,F){F=F||1/0;let j;const X=K.length;let te=null;const ue=[];for(let pe=0;pe<X;++pe){if(j=K.charCodeAt(pe),j>55295&&j<57344){if(!te){if(j>56319){(F-=3)>-1&&ue.push(239,191,189);continue}else if(pe+1===X){(F-=3)>-1&&ue.push(239,191,189);continue}te=j;continue}if(j<56320){(F-=3)>-1&&ue.push(239,191,189),te=j;continue}j=(te-55296<<10|j-56320)+65536}else te&&(F-=3)>-1&&ue.push(239,191,189);if(te=null,j<128){if((F-=1)<0)break;ue.push(j)}else if(j<2048){if((F-=2)<0)break;ue.push(j>>6|192,j&63|128)}else if(j<65536){if((F-=3)<0)break;ue.push(j>>12|224,j>>6&63|128,j&63|128)}else if(j<1114112){if((F-=4)<0)break;ue.push(j>>18|240,j>>12&63|128,j>>6&63|128,j&63|128)}else throw new Error("Invalid code point")}return ue}function mt(K){const F=[];for(let j=0;j<K.length;++j)F.push(K.charCodeAt(j)&255);return F}function Xt(K,F){let j,X,te;const ue=[];for(let pe=0;pe<K.length&&!((F-=2)<0);++pe)j=K.charCodeAt(pe),X=j>>8,te=j%256,ue.push(te),ue.push(X);return ue}function At(K){return N.toByteArray(Ze(K))}function Bt(K,F,j,X){let te;for(te=0;te<X&&!(te+j>=F.length||te>=K.length);++te)F[te+j]=K[te];return te}function et(K,F){return K instanceof F||K!=null&&K.constructor!=null&&K.constructor.name!=null&&K.constructor.name===F.name}function Qt(K){return K!==K}const nn=function(){const K="0123456789abcdef",F=new Array(256);for(let j=0;j<16;++j){const X=j*16;for(let te=0;te<16;++te)F[X+te]=K[j]+K[te]}return F}();function yt(K){return typeof BigInt>"u"?rn:K}function rn(){throw new Error("BigInt not supported")}}(buffer)),buffer}var toolsEbml={},hasRequiredToolsEbml;function requireToolsEbml(){if(hasRequiredToolsEbml)return toolsEbml;hasRequiredToolsEbml=1;var O=toolsEbml&&toolsEbml.__assign||function(){return O=Object.assign||function(b){for(var k,i=1,c=arguments.length;i<c;i++){k=arguments[i];for(var S in k)Object.prototype.hasOwnProperty.call(k,S)&&(b[S]=k[S])}return b},O.apply(this,arguments)},N=toolsEbml&&toolsEbml.__spreadArray||function(b,k,i){if(i||arguments.length===2)for(var c=0,S=k.length,C;c<S;c++)(C||!(c in k))&&(C||(C=Array.prototype.slice.call(k,0,c)),C[c]=k[c]);return b.concat(C||Array.prototype.slice.call(k))};Object.defineProperty(toolsEbml,"__esModule",{value:!0});var $=requireTools(),D=function(){function b(){}return b.readVint=function(k,i){i===void 0&&(i=0);var c=8-Math.floor(Math.log2(k[i]));if(c>8){var S=b.readHexString(k,i,i+c);throw new Error("Unrepresentable length: ".concat(c," ").concat(S))}if(i+c>k.length)return null;for(var C=k[i]&(1<<8-c)-1,M=1;M<c;M+=1){if(M===7&&C>=Math.pow(2,8)&&k[i+7]>0)return{length:c,value:-1};C*=Math.pow(2,8),C+=k[i+M]}return{length:c,value:C}},b.writeVint=function(k){if(k<0||k>Math.pow(2,53))throw new Error("Unrepresentable value: ".concat(k));var i=1;for(i=1;i<=8&&!(k<Math.pow(2,7*i)-1);i+=1);for(var c=$.Buffer.alloc(i),S=k,C=1;C<=i;C+=1){var M=S&255;c[i-C]=M,S-=M,S/=Math.pow(2,8)}return c[0]|=1<<8-i,c},b.concatenate=function(k,i){return!k&&!i?$.Buffer.from([]):!k||k.byteLength===0?i:!i||i.byteLength===0?k:$.Buffer.from(N(N([],k,!0),i,!0))},b.readHexString=function(k,i,c){return i===void 0&&(i=0),c===void 0&&(c=k.byteLength),Array.from(k.slice(i,c)).map(function(S){return Number(S).toString(16)}).reduce(function(S,C){return"".concat(S).concat(C.padStart(2,"0"))},"")},b.readUtf8=function(k){try{return $.Buffer.from(k).toString("utf8")}catch{return null}},b.readUnsigned=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 1:return i.getUint8(0);case 2:return i.getUint16(0);case 4:return i.getUint32(0)}return k.byteLength<=6?k.reduce(function(c,S){return c*256+S},0):b.readHexString(k,0,k.byteLength)},b.readSigned=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 1:return i.getInt8(0);case 2:return i.getInt16(0);case 4:return i.getInt32(0);default:return NaN}},b.readFloat=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 4:return i.getFloat32(0);case 8:return i.getFloat64(0);default:return NaN}},b.readDate=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 1:return new Date(i.getUint8(0));case 2:return new Date(i.getUint16(0));case 4:return new Date(i.getUint32(0));case 8:return new Date(Number.parseInt(b.readHexString(k),16));default:return new Date(0)}},b.readDataFromTag=function(k,i){var c=k.type,S=k.name,C=k.track,M=k.discardable||!1,Z=k.keyframe||!1,J=null,z;switch(c){case"u":z=b.readUnsigned(i);break;case"f":z=b.readFloat(i);break;case"i":z=b.readSigned(i);break;case"s":z=String.fromCharCode.apply(String,i);break;case"8":z=b.readUtf8(i);break;case"d":z=b.readDate(i);break}if(S==="SimpleBlock"||S==="Block"){var Y=0,re=b.readVint(i,Y),oe=re.length,ie=re.value;Y+=oe,C=ie,z=b.readSigned(i.subarray(Y,Y+2)),Y+=2,S==="SimpleBlock"&&(Z=!!(i[oe+2]&128),M=!!(i[oe+2]&1)),Y+=1,J=i.subarray(Y)}return O(O({},k),{data:i,discardable:M,keyframe:Z,payload:J,track:C,value:z})},b}();return toolsEbml.default=D,toolsEbml}var vint,hasRequiredVint;function requireVint(){return hasRequiredVint||(hasRequiredVint=1,vint=function(O,N,$){N=N||0;for(var D=1;D<=8&&!(O[N]>=Math.pow(2,8-D));D++);if(D>8)throw new Error("Unrepresentable length: "+D+" "+O.toString("hex",N,N+D));if(N+D>O.length)return null;var b,k=O[N]&(1<<8-D)-1;for(b=1;b<D;b++){if(b===7&&k>=Math.pow(2,45)&&O[N+7]>0)return{length:D,value:-1};k*=Math.pow(2,8),k+=O[N+b]}return $&&(k-=Math.pow(2,D*7-1)-1),{length:D,value:k}}),vint}var bufferReader,hasRequiredBufferReader;function requireBufferReader(){if(hasRequiredBufferReader)return bufferReader;hasRequiredBufferReader=1;var O=requireVint();function N($){this.buffer=$,this.offset=0}return N.prototype.nextInt16BE=function(){var $=this.buffer.readInt16BE(this.offset);return this.offset+=2,$},N.prototype.nextUInt8=function(){var $=this.buffer.readUInt8(this.offset);return this.offset+=1,$},N.prototype.nextUIntV=function(){var $=O(this.buffer,this.offset);return this.offset+=$.length,$.value},N.prototype.nextIntV=function(){var $=O(this.buffer,this.offset,!0);return this.offset+=$.length,$.value},N.prototype.nextBuffer=function($){var D=$?this.buffer.slice(this.offset,this.offset+$):this.buffer.slice(this.offset);return this.offset+=$||this.length,D},Object.defineProperty(N.prototype,"length",{get:function(){return this.buffer.length-this.offset}}),bufferReader=N,bufferReader}var ebmlBlock,hasRequiredEbmlBlock;function requireEbmlBlock(){if(hasRequiredEbmlBlock)return ebmlBlock;hasRequiredEbmlBlock=1;var O=requireBufferReader(),N=1,$=3,D=2;ebmlBlock=function(k){var i={},c=new O(k);i.trackNumber=c.nextUIntV(),i.timecode=c.nextInt16BE();var S=c.nextUInt8();i.invisible=!!(S&8),i.keyframe=!!(S&128),i.discardable=!!(S&1);var C=(S&6)>>1;return i.frames=b(c,C),i};function b(k,i){if(!i)return[k.nextBuffer()];var c,S,C=[],M=k.nextUInt8()+1;if(i===D){if(k.length%M!==0)throw new Error("Fixed-Size Lacing Error");for(S=k.length/M,c=0;c<M;c++)C.push(k.nextBuffer(S));return C}var Z=[];if(i===N)for(c=0;c<M-1;c++){var J;S=0;do J=k.nextUInt8(),S+=J;while(J===255);Z.push(S)}else if(i===$)for(S=k.nextUIntV(),Z.push(S),c=1;c<M-1;c++)S+=k.nextIntV(),Z.push(S);for(c=0;c<M-1;c++)C.push(k.nextBuffer(Z[c]));return C.push(k.nextBuffer()),C}return ebmlBlock}var hasRequiredTools;function requireTools(){return hasRequiredTools||(hasRequiredTools=1,function(O){Object.defineProperty(O,"__esModule",{value:!0}),O.convertEBMLDateToJSDate=O.createFloatBuffer=O.createIntBuffer=O.createUIntBuffer=O.encodeValueToBuffer=O.concat=O.putRefinedMetaData=O.extractElement=O.removeElement=O.makeMetadataSeekable=O.createRIFFChunk=O.VP8BitStreamToRiffWebPBuffer=O.WebPBlockFilter=O.encodeTag=O.readBlock=O.ebmlBlock=O.writeVint=O.readVint=O.Buffer=void 0;var N=requireInt64Buffer(),$=requireEBMLEncoder(),D=requireBuffer(),b=requireToolsEbml(),k=requireEbmlBlock();O.Buffer=D.Buffer,O.readVint=b.default.readVint,O.writeVint=b.default.writeVint,O.ebmlBlock=k;function i(ee){return(0,O.ebmlBlock)(new O.Buffer(ee))}O.readBlock=i;function c(ee,le,ve){return ve===void 0&&(ve=!1),Q([ee,ve?new O.Buffer("01ffffffffffffff","hex"):(0,O.writeVint)(le.length),le])}O.encodeTag=c;function S(ee){return ee.reduce(function(le,ve){if(ve.type!=="b"||ve.name!=="SimpleBlock")return le;var be=(0,O.ebmlBlock)(ve.data),we=be.frames.some(function($e){var Ne=$e.slice(3,6).toString("hex");return Ne==="9d012a"});return we?le.concat(ve):le},[])}O.WebPBlockFilter=S;function C(ee){var le=M("VP8 ",ee),ve=Q([new O.Buffer("WEBP","ascii"),le]);return M("RIFF",ve)}O.VP8BitStreamToRiffWebPBuffer=C;function M(ee,le){var ve=new O.Buffer(4);return ve.writeUInt32LE(le.byteLength,0),Q([new O.Buffer(ee.substr(0,4),"ascii"),ve,le,new O.Buffer(le.byteLength%2===0?0:1)])}O.createRIFFChunk=M;function Z(ee,le,ve){var be=z("EBML",ee),we=re(be),$e=we+12,Ne=ee[ee.length-1].dataEnd-$e,Le=z("Info",ee);J("Duration",Le),Le.splice(1,0,{name:"Duration",type:"f",data:fe(le,8)});for(var Fe=re(Le),We=z("Tracks",ee),ft=re(We),Re=47,xe=[],it=5+ve.length*15,Me=[],Ke=-1,rt=10,Ye=function(Ie){var De=Re,je=De+Fe,Je=je+ft,Ze=Je+it,ot=Ze-Ne;if(xe=[],xe.push({name:"SeekHead",type:"m",isEnd:!1}),xe.push({name:"Seek",type:"m",isEnd:!1}),xe.push({name:"SeekID",type:"b",data:new O.Buffer([21,73,169,102])}),xe.push({name:"SeekPosition",type:"u",data:he(De)}),xe.push({name:"Seek",type:"m",isEnd:!0}),xe.push({name:"Seek",type:"m",isEnd:!1}),xe.push({name:"SeekID",type:"b",data:new O.Buffer([22,84,174,107])}),xe.push({name:"SeekPosition",type:"u",data:he(je)}),xe.push({name:"Seek",type:"m",isEnd:!0}),xe.push({name:"Seek",type:"m",isEnd:!1}),xe.push({name:"SeekID",type:"b",data:new O.Buffer([28,83,187,107])}),xe.push({name:"SeekPosition",type:"u",data:he(Je)}),xe.push({name:"Seek",type:"m",isEnd:!0}),xe.push({name:"SeekHead",type:"m",isEnd:!0}),Re=re(xe),Me=[],Me.push({name:"Cues",type:"m",isEnd:!1}),ve.forEach(function(mt){var Xt=mt.CueTrack,At=mt.CueClusterPosition,Bt=mt.CueTime;Me.push({name:"CuePoint",type:"m",isEnd:!1}),Me.push({name:"CueTime",type:"u",data:he(Bt)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Me.push({name:"CueTrack",type:"u",data:he(Xt)}),At-=$e,At+=ot,Me.push({name:"CueClusterPosition",type:"u",data:he(At)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Me.push({name:"CuePoint",type:"m",isEnd:!0})}),Me.push({name:"Cues",type:"m",isEnd:!0}),it=re(Me),Ke!==ot){if(Ke=ot,Ie===rt-1)throw new Error("Failed to converge to a stable metadata size")}else return"break"},He=0;He<rt;He++){var ge=Ye(He);if(ge==="break")break}var _e=[].concat.apply([],[be,{name:"Segment",type:"m",isEnd:!1,unknownSize:!0},xe,Le,We,Me]),Se=new $.default().encode(_e);return Se}O.makeMetadataSeekable=Z;function J(ee,le){for(var ve=-1,be=0;be<le.length;be++){var we=le[be];if(we.name===ee)if(we.type==="m")if(!we.isEnd)ve=be;else{if(ve==-1)throw new Error("Detected ".concat(ee," closing element before finding the start"));le.splice(ve,be-ve+1);return}else{le.splice(be,1);return}}}O.removeElement=J;function z(ee,le){for(var ve=[],be=-1,we=0;we<le.length;we++){var $e=le[we];if($e.name===ee)if($e.type==="m")if(!$e.isEnd)be=we;else{if(be==-1)throw new Error("Detected ".concat(ee," closing element before finding the start"));ve=le.slice(be,we+1);break}else{ve.push(le[we]);break}}return ve}O.extractElement=z;function Y(ee,le){Array.isArray(le.cueInfos)&&!Array.isArray(le.cues)&&(console.warn("putRefinedMetaData: info.cueInfos property is deprecated. please use info.cues"),le.cues=le.cueInfos);for(var ve=[],be=[],we=0;we<ee.length;we++){var $e=ee[we];if($e.type==="m"&&$e.name==="Segment"){if(ve=ee.slice(0,we),be=ee.slice(we),$e.unknownSize){be.shift();break}throw new Error("this metadata is not streaming webm file")}}if(!(be[be.length-1].dataEnd>0))throw new Error("metadata dataEnd has wrong number");var Ne=be[be.length-1].dataEnd,Le=ve[ve.length-1].dataEnd,Fe=new $.default().encode(ve).byteLength,We=Fe-Le,ft=Ne-be[0].tagStart;be[0].tagStart-Le,be[0].tagStart;var Re=new O.Buffer([24,83,128,103]),xe=new O.Buffer("01ffffffffffffff","hex"),it=Re.byteLength+xe.byteLength,Me=ft,Ke;for(Ke=1;Ke<20;Ke++){var rt=Le+it+Me,Ye=rt-Ne,He=We+Ye,ge=oe(be,He,le),_e=new $.default().encode(ge).byteLength;if(_e===Me)return new $.default().encode([].concat(ve,[{type:"m",name:"Segment",isEnd:!1,unknownSize:!0}],ge));Me=_e}throw new Error("unable to refine metadata, stable size could not be found in "+Ke+" iterations!")}O.putRefinedMetaData=Y;function re(ee){var le=new $.default;return ee.reduce(function(ve,be){return ve.concat(le.encode([be]))},[]).reduce(function(ve,be){return ve+be.byteLength},0)}function oe(ee,le,ve){var be=ve.duration,we=ve.clusterPtrs,$e=ve.cues,Ne=ee.slice(0);if(typeof be=="number"){var Le=!1;Ne.forEach(function(We){We.type==="f"&&We.name==="Duration"&&(Le=!0,We.data=fe(be,8))}),Le||ye(Ne,"Info",[{name:"Duration",type:"f",data:fe(be,8)}])}Array.isArray($e)&&ye(Ne,"Cues",de($e,le));var Fe=[];return Array.isArray(we)&&(console.warn("append cluster pointers to seekhead is deprecated. please use cues"),Fe=ie(we,le)),ye(Ne,"SeekHead",Fe,!0),Ne}function ie(ee,le){var ve=[];return ee.forEach(function(be){ve.push({name:"Seek",type:"m",isEnd:!1}),ve.push({name:"SeekID",type:"b",data:new O.Buffer([31,67,182,117])}),ve.push({name:"SeekPosition",type:"u",data:he(be+le)}),ve.push({name:"Seek",type:"m",isEnd:!0})}),ve}function de(ee,le){var ve=[];return ee.forEach(function(be){var we=be.CueTrack,$e=be.CueClusterPosition,Ne=be.CueTime;ve.push({name:"CuePoint",type:"m",isEnd:!1}),ve.push({name:"CueTime",type:"u",data:he(Ne)}),ve.push({name:"CueTrackPositions",type:"m",isEnd:!1}),ve.push({name:"CueTrack",type:"u",data:he(we)}),ve.push({name:"CueClusterPosition",type:"u",data:he($e+le)}),ve.push({name:"CueTrackPositions",type:"m",isEnd:!0}),ve.push({name:"CuePoint",type:"m",isEnd:!0})}),ve}function ye(ee,le,ve,be){be===void 0&&(be=!1);for(var we=-1,$e=0;$e<ee.length;$e++){var Ne=ee[$e];if(Ne.type==="m"&&Ne.name===le&&Ne.isEnd===!1){we=$e;break}}we>=0?Array.prototype.splice.apply(ee,[we+1,0].concat(ve)):be?[].concat([{name:le,type:"m",isEnd:!1}],ve,[{name:le,type:"m",isEnd:!0}]).reverse().forEach(function(Le){ee.unshift(Le)}):(ee.push({name:le,type:"m",isEnd:!1}),ve.forEach(function(Le){ee.push(Le)}),ee.push({name:le,type:"m",isEnd:!0}))}function Q(ee){return O.Buffer.concat(ee)}O.concat=Q;function ae(ee){var le=new O.Buffer(0);if(ee.type==="m")return ee;switch(ee.type){case"u":le=he(ee.value);break;case"i":le=ce(ee.value);break;case"f":le=fe(ee.value);break;case"s":le=new O.Buffer(ee.value,"ascii");break;case"8":le=new O.Buffer(ee.value,"utf8");break;case"b":le=ee.value;break;case"d":le=new N.Int64BE(ee.value.getTime().toString()).toBuffer();break}return Object.assign({},ee,{data:le})}O.encodeValueToBuffer=ae;function he(ee){for(var le=1;ee>=Math.pow(2,8*le);le++);if(le>=7)return console.warn("7bit or more bigger uint not supported."),new N.Uint64BE(ee).toBuffer();var ve=new O.Buffer(le);return ve.writeUIntBE(ee,0,le),ve}O.createUIntBuffer=he;function ce(ee){for(var le=1;ee>=Math.pow(2,8*le);le++);if(le>=7)return console.warn("7bit or more bigger uint not supported."),new N.Int64BE(ee).toBuffer();var ve=new O.Buffer(le);return ve.writeIntBE(ee,0,le),ve}O.createIntBuffer=ce;function fe(ee,le){if(le===void 0&&(le=8),le===8){var ve=new O.Buffer(8);return ve.writeDoubleBE(ee,0),ve}else if(le===4){var ve=new O.Buffer(4);return ve.writeFloatBE(ee,0),ve}else throw new Error("float type bits must 4bytes or 8bytes")}O.createFloatBuffer=fe;function me(ee){return ee instanceof Date?ee:new Date(new Date("2001-01-01T00:00:00.000Z").getTime()+Number(ee)/1e3/1e3)}O.convertEBMLDateToJSDate=me}(tools)),tools}var hasRequiredEBMLDecoder;function requireEBMLDecoder(){if(hasRequiredEBMLDecoder)return EBMLDecoder;hasRequiredEBMLDecoder=1,Object.defineProperty(EBMLDecoder,"__esModule",{value:!0});var O=requireInt64Buffer(),N=requireTools(),$=requireTools(),D=requireEbmlID(),b;(function(i){i[i.STATE_TAG=1]="STATE_TAG",i[i.STATE_SIZE=2]="STATE_SIZE",i[i.STATE_CONTENT=3]="STATE_CONTENT"})(b||(b={}));var k=function(){function i(){this._buffer=new N.Buffer(0),this._tag_stack=[],this._state=b.STATE_TAG,this._cursor=0,this._total=0,this._schema=D.byEbmlID,this._result=[]}return i.prototype.decode=function(c){this.readChunk(c);var S=this._result;return this._result=[],S},i.prototype.readChunk=function(c){for(this._buffer=$.concat([this._buffer,new N.Buffer(c)]);this._cursor<this._buffer.length&&!(this._state===b.STATE_TAG&&!this.readTag()||this._state===b.STATE_SIZE&&!this.readSize()||this._state===b.STATE_CONTENT&&!this.readContent()););},i.prototype.getSchemaInfo=function(c){return this._schema[c]||{name:"unknown",level:-1,type:"unknown",description:"unknown"}},i.prototype.readTag=function(){if(this._cursor>=this._buffer.length)return!1;var c=(0,N.readVint)(this._buffer,this._cursor);if(c==null)return!1;var S=this._buffer.slice(this._cursor,this._cursor+c.length),C=S.reduce(function(J,z,Y,re){return J+z*Math.pow(16,2*(re.length-1-Y))},0),M=this.getSchemaInfo(C),Z={EBML_ID:C.toString(16),schema:M,type:M.type,name:M.name,level:M.level,tagStart:this._total,tagEnd:this._total+c.length,sizeStart:this._total+c.length,sizeEnd:null,dataStart:null,dataEnd:null,dataSize:null,data:null};return this._tag_stack.push(Z),this._cursor+=c.length,this._total+=c.length,this._state=b.STATE_SIZE,!0},i.prototype.readSize=function(){if(this._cursor>=this._buffer.length)return!1;var c=(0,N.readVint)(this._buffer,this._cursor);if(c==null)return!1;var S=this._tag_stack[this._tag_stack.length-1];return S.sizeEnd=S.sizeStart+c.length,S.dataStart=S.sizeEnd,S.dataSize=c.value,c.value===-1?(S.dataEnd=-1,S.type==="m"&&(S.unknownSize=!0)):S.dataEnd=S.sizeEnd+c.value,this._cursor+=c.length,this._total+=c.length,this._state=b.STATE_CONTENT,!0},i.prototype.readContent=function(){var c=this._tag_stack[this._tag_stack.length-1];if(c.type==="m"){if(c.isEnd=!1,this._result.push(c),this._state=b.STATE_TAG,c.dataSize===0){var S=Object.assign({},c,{isEnd:!0});this._result.push(S),this._tag_stack.pop()}return!0}if(this._buffer.length<this._cursor+c.dataSize)return!1;var C=this._buffer.slice(this._cursor,this._cursor+c.dataSize);switch(this._buffer=this._buffer.slice(this._cursor+c.dataSize),c.data=C,c.type){case"u":c.value=C.readUIntBE(0,C.length);break;case"i":c.value=C.readIntBE(0,C.length);break;case"f":c.value=c.dataSize===4?C.readFloatBE(0):c.dataSize===8?C.readDoubleBE(0):(console.warn("cannot read ".concat(c.dataSize," octets float. failback to 0")),0);break;case"s":c.value=C.toString("ascii");break;case"8":c.value=C.toString("utf8");break;case"b":c.value=C;break;case"d":c.value=(0,N.convertEBMLDateToJSDate)(new O.Int64BE(C).toNumber());break}if(c.value===null)throw new Error("unknown tag type:"+c.type);for(this._result.push(c),this._total+=c.dataSize,this._state=b.STATE_TAG,this._cursor=0,this._tag_stack.pop();this._tag_stack.length>0;){var M=this._tag_stack[this._tag_stack.length-1];if(M.dataEnd<0)return this._tag_stack.pop(),!0;if(this._total<M.dataEnd)break;if(M.type!=="m")throw new Error("parent element is not master element");var S=Object.assign({},M,{isEnd:!0});this._result.push(S),this._tag_stack.pop()}return!0},i}();return EBMLDecoder.default=k,EBMLDecoder}var EBMLReader={},events={exports:{}},hasRequiredEvents;function requireEvents(){if(hasRequiredEvents)return events.exports;hasRequiredEvents=1;var O=typeof Reflect=="object"?Reflect:null,N=O&&typeof O.apply=="function"?O.apply:function(ae,he,ce){return Function.prototype.apply.call(ae,he,ce)},$;O&&typeof O.ownKeys=="function"?$=O.ownKeys:Object.getOwnPropertySymbols?$=function(ae){return Object.getOwnPropertyNames(ae).concat(Object.getOwnPropertySymbols(ae))}:$=function(ae){return Object.getOwnPropertyNames(ae)};function D(Q){console&&console.warn&&console.warn(Q)}var b=Number.isNaN||function(ae){return ae!==ae};function k(){k.init.call(this)}events.exports=k,events.exports.once=ie,k.EventEmitter=k,k.prototype._events=void 0,k.prototype._eventsCount=0,k.prototype._maxListeners=void 0;var i=10;function c(Q){if(typeof Q!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof Q)}Object.defineProperty(k,"defaultMaxListeners",{enumerable:!0,get:function(){return i},set:function(Q){if(typeof Q!="number"||Q<0||b(Q))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+Q+".");i=Q}}),k.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},k.prototype.setMaxListeners=function(ae){if(typeof ae!="number"||ae<0||b(ae))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+ae+".");return this._maxListeners=ae,this};function S(Q){return Q._maxListeners===void 0?k.defaultMaxListeners:Q._maxListeners}k.prototype.getMaxListeners=function(){return S(this)},k.prototype.emit=function(ae){for(var he=[],ce=1;ce<arguments.length;ce++)he.push(arguments[ce]);var fe=ae==="error",me=this._events;if(me!==void 0)fe=fe&&me.error===void 0;else if(!fe)return!1;if(fe){var ee;if(he.length>0&&(ee=he[0]),ee instanceof Error)throw ee;var le=new Error("Unhandled error."+(ee?" ("+ee.message+")":""));throw le.context=ee,le}var ve=me[ae];if(ve===void 0)return!1;if(typeof ve=="function")N(ve,this,he);else for(var be=ve.length,we=Y(ve,be),ce=0;ce<be;++ce)N(we[ce],this,he);return!0};function C(Q,ae,he,ce){var fe,me,ee;if(c(he),me=Q._events,me===void 0?(me=Q._events=Object.create(null),Q._eventsCount=0):(me.newListener!==void 0&&(Q.emit("newListener",ae,he.listener?he.listener:he),me=Q._events),ee=me[ae]),ee===void 0)ee=me[ae]=he,++Q._eventsCount;else if(typeof ee=="function"?ee=me[ae]=ce?[he,ee]:[ee,he]:ce?ee.unshift(he):ee.push(he),fe=S(Q),fe>0&&ee.length>fe&&!ee.warned){ee.warned=!0;var le=new Error("Possible EventEmitter memory leak detected. "+ee.length+" "+String(ae)+" listeners added. Use emitter.setMaxListeners() to increase limit");le.name="MaxListenersExceededWarning",le.emitter=Q,le.type=ae,le.count=ee.length,D(le)}return Q}k.prototype.addListener=function(ae,he){return C(this,ae,he,!1)},k.prototype.on=k.prototype.addListener,k.prototype.prependListener=function(ae,he){return C(this,ae,he,!0)};function M(){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 Z(Q,ae,he){var ce={fired:!1,wrapFn:void 0,target:Q,type:ae,listener:he},fe=M.bind(ce);return fe.listener=he,ce.wrapFn=fe,fe}k.prototype.once=function(ae,he){return c(he),this.on(ae,Z(this,ae,he)),this},k.prototype.prependOnceListener=function(ae,he){return c(he),this.prependListener(ae,Z(this,ae,he)),this},k.prototype.removeListener=function(ae,he){var ce,fe,me,ee,le;if(c(he),fe=this._events,fe===void 0)return this;if(ce=fe[ae],ce===void 0)return this;if(ce===he||ce.listener===he)--this._eventsCount===0?this._events=Object.create(null):(delete fe[ae],fe.removeListener&&this.emit("removeListener",ae,ce.listener||he));else if(typeof ce!="function"){for(me=-1,ee=ce.length-1;ee>=0;ee--)if(ce[ee]===he||ce[ee].listener===he){le=ce[ee].listener,me=ee;break}if(me<0)return this;me===0?ce.shift():re(ce,me),ce.length===1&&(fe[ae]=ce[0]),fe.removeListener!==void 0&&this.emit("removeListener",ae,le||he)}return this},k.prototype.off=k.prototype.removeListener,k.prototype.removeAllListeners=function(ae){var he,ce,fe;if(ce=this._events,ce===void 0)return this;if(ce.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):ce[ae]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete ce[ae]),this;if(arguments.length===0){var me=Object.keys(ce),ee;for(fe=0;fe<me.length;++fe)ee=me[fe],ee!=="removeListener"&&this.removeAllListeners(ee);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(he=ce[ae],typeof he=="function")this.removeListener(ae,he);else if(he!==void 0)for(fe=he.length-1;fe>=0;fe--)this.removeListener(ae,he[fe]);return this};function J(Q,ae,he){var ce=Q._events;if(ce===void 0)return[];var fe=ce[ae];return fe===void 0?[]:typeof fe=="function"?he?[fe.listener||fe]:[fe]:he?oe(fe):Y(fe,fe.length)}k.prototype.listeners=function(ae){return J(this,ae,!0)},k.prototype.rawListeners=function(ae){return J(this,ae,!1)},k.listenerCount=function(Q,ae){return typeof Q.listenerCount=="function"?Q.listenerCount(ae):z.call(Q,ae)},k.prototype.listenerCount=z;function z(Q){var ae=this._events;if(ae!==void 0){var he=ae[Q];if(typeof he=="function")return 1;if(he!==void 0)return he.length}return 0}k.prototype.eventNames=function(){return this._eventsCount>0?$(this._events):[]};function Y(Q,ae){for(var he=new Array(ae),ce=0;ce<ae;++ce)he[ce]=Q[ce];return he}function re(Q,ae){for(;ae+1<Q.length;ae++)Q[ae]=Q[ae+1];Q.pop()}function oe(Q){for(var ae=new Array(Q.length),he=0;he<ae.length;++he)ae[he]=Q[he].listener||Q[he];return ae}function ie(Q,ae){return new Promise(function(he,ce){function fe(ee){Q.removeListener(ae,me),ce(ee)}function me(){typeof Q.removeListener=="function"&&Q.removeListener("error",fe),he([].slice.call(arguments))}ye(Q,ae,me,{once:!0}),ae!=="error"&&de(Q,fe,{once:!0})})}function de(Q,ae,he){typeof Q.on=="function"&&ye(Q,"error",ae,he)}function ye(Q,ae,he,ce){if(typeof Q.on=="function")ce.once?Q.once(ae,he):Q.on(ae,he);else if(typeof Q.addEventListener=="function")Q.addEventListener(ae,function fe(me){ce.once&&Q.removeEventListener(ae,fe),he(me)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof Q)}return events.exports}var hasRequiredEBMLReader;function requireEBMLReader(){if(hasRequiredEBMLReader)return EBMLReader;hasRequiredEBMLReader=1;var O=EBMLReader&&EBMLReader.__extends||function(){var b=function(k,i){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,S){c.__proto__=S}||function(c,S){for(var C in S)Object.prototype.hasOwnProperty.call(S,C)&&(c[C]=S[C])},b(k,i)};return function(k,i){if(typeof i!="function"&&i!==null)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");b(k,i);function c(){this.constructor=k}k.prototype=i===null?Object.create(i):(c.prototype=i.prototype,new c)}}();Object.defineProperty(EBMLReader,"__esModule",{value:!0});var N=requireEvents(),$=requireTools(),D=function(b){O(k,b);function k(){var i=b.call(this)||this;return i.logGroup="",i.hasLoggingStarted=!1,i.metadataloaded=!1,i.chunks=[],i.stack=[],i.segmentOffset=0,i.last2SimpleBlockVideoTrackTimecode=[0,0],i.last2SimpleBlockAudioTrackTimecode=[0,0],i.lastClusterTimecode=0,i.lastClusterPosition=0,i.timecodeScale=1e6,i.metadataSize=0,i.metadatas=[],i.cues=[],i.firstVideoBlockRead=!1,i.firstAudioBlockRead=!1,i.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null},i.trackTypes=[],i.trackDefaultDuration=[],i.trackCodecDelay=[],i.trackInfo={type:"nothing"},i.ended=!1,i.logging=!1,i.use_duration_every_simpleblock=!1,i.use_webp=!1,i.use_segment_info=!0,i.drop_default_duration=!0,i}return k.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()},k.prototype.emit_segment_info=function(){var i=this.chunks;if(this.chunks=[],this.metadataloaded){if(!this.use_segment_info)return;var C=this.lastClusterTimecode,M=this.duration,Z=this.timecodeScale;this.emit("cluster",{timecode:C,data:i}),this.emit("duration",{timecodeScale:Z,duration:M})}else{this.metadataloaded=!0,this.metadatas=i;var c=this.trackTypes.indexOf(1),S=this.trackTypes.indexOf(2);if(this.trackInfo=c>=0&&S>=0?{type:"both",trackNumber:c}:c>=0?{type:"video",trackNumber:c}:S>=0?{type:"audio",trackNumber:S}:{type:"nothing"},!this.use_segment_info)return;this.emit("metadata",{data:i,metadataSize:this.metadataSize})}},k.prototype.read=function(i){var c=this,S=!1;if(!this.ended){if(i.type==="m")if(i.isEnd)this.stack.pop();else{var C=this.stack[this.stack.length-1];if(C!=null&&C.level>=i.level){this.stack.pop(),this.logging&&console.groupEnd(),C.dataEnd=i.dataEnd,C.dataSize=i.dataEnd-C.dataStart,C.unknownSize=!1;var M=Object.assign({},C,{name:C.name,type:C.type,isEnd:!0});this.chunks.push(M)}this.stack.push(i)}if(i.type==="m"&&i.name=="Segment")this.segmentOffset!=0&&console.warn("Multiple segments detected!"),this.segmentOffset=i.dataStart,this.emit("segment_offset",this.segmentOffset);else if(i.type==="b"&&i.name==="SimpleBlock"){var Z=$.ebmlBlock(i.data),J=Z.timecode,z=Z.trackNumber,Y=Z.frames;if(this.trackTypes[z]===1){if(!this.firstVideoBlockRead&&(this.firstVideoBlockRead=!0,this.trackInfo.type==="both"||this.trackInfo.type==="video")){var re=this.lastClusterTimecode+J;this.cues.push({CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re}),this.emit("cue_info",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re})}this.last2SimpleBlockVideoTrackTimecode=[this.last2SimpleBlockVideoTrackTimecode[1],J]}else if(this.trackTypes[z]===2){if(!this.firstAudioBlockRead&&(this.firstAudioBlockRead=!0,this.trackInfo.type==="audio")){var re=this.lastClusterTimecode+J;this.cues.push({CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re}),this.emit("cue_info",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re})}this.last2SimpleBlockAudioTrackTimecode=[this.last2SimpleBlockAudioTrackTimecode[1],J]}this.use_duration_every_simpleblock&&this.emit("duration",{timecodeScale:this.timecodeScale,duration:this.duration}),this.use_webp&&Y.forEach(function(oe){var ie=oe.slice(3,6).toString("hex");if(ie==="9d012a"){var de=$.VP8BitStreamToRiffWebPBuffer(oe),ye=new Blob([de],{type:"image/webp"}),Q=c.duration;c.emit("webp",{currentTime:Q,webp:ye})}})}else i.type==="m"&&i.name==="Cluster"&&i.isEnd===!1?(this.firstVideoBlockRead=!1,this.firstAudioBlockRead=!1,this.emit_segment_info(),this.emit("cluster_ptr",i.tagStart),this.lastClusterPosition=i.tagStart):i.type==="u"&&i.name==="Timecode"?this.lastClusterTimecode=i.value:i.type==="u"&&i.name==="TimecodeScale"?this.timecodeScale=i.value:i.type==="m"&&i.name==="TrackEntry"?i.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}:i.type==="u"&&i.name==="TrackType"?this.currentTrack.TrackType=i.value:i.type==="u"&&i.name==="TrackNumber"?this.currentTrack.TrackNumber=i.value:i.type==="u"&&i.name==="CodecDelay"?this.currentTrack.CodecDelay=i.value:i.type==="u"&&i.name==="DefaultDuration"?this.drop_default_duration?(console.warn("DefaultDuration detected!, remove it"),S=!0):this.currentTrack.DefaultDuration=i.value:i.name==="unknown"&&console.warn(i);!this.metadataloaded&&i.dataEnd>0&&(this.metadataSize=i.dataEnd),S||this.chunks.push(i),this.logging&&this.put(i)}},Object.defineProperty(k.prototype,"duration",{get:function(){if(this.trackInfo.type==="nothing")return console.warn("no video, no audio track"),0;var i=0,c=0,S=0,C=this.trackDefaultDuration[this.trackInfo.trackNumber];if(typeof C=="number")i=C;else if(this.trackInfo.type==="both")if(this.last2SimpleBlockAudioTrackTimecode[1]>this.last2SimpleBlockVideoTrackTimecode[1]){i=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackTypes.indexOf(2)];typeof M=="number"&&(c=M),S=this.last2SimpleBlockAudioTrackTimecode[1]}else{i=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackTypes.indexOf(1)];typeof M=="number"&&(c=M),S=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="video"){i=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackInfo.trackNumber];typeof M=="number"&&(c=M),S=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="audio"){i=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackInfo.trackNumber];typeof M=="number"&&(c=M),S=this.last2SimpleBlockAudioTrackTimecode[1]}var Z=(this.lastClusterTimecode+S)*this.timecodeScale+i-c,J=Z/this.timecodeScale;return Math.floor(J)},enumerable:!1,configurable:!0}),k.prototype.addListener=function(i,c){return b.prototype.addListener.call(this,i,c)},k.prototype.put=function(i){this.hasLoggingStarted||(this.hasLoggingStarted=!0,this.logging&&this.logGroup&&console.groupCollapsed(this.logGroup)),i.type==="m"?i.isEnd?console.groupEnd():console.group(i.name+":"+i.tagStart):i.type==="b"?console.log(i.name,i.type):console.log(i.name,i.tagStart,i.type,i.value)},k}(N.EventEmitter);return EBMLReader.default=D,EBMLReader}var hasRequiredEbml;function requireEbml(){return hasRequiredEbml||(hasRequiredEbml=1,function(O){var N=ebml&&ebml.__createBinding||(Object.create?function(c,S,C,M){M===void 0&&(M=C),Object.defineProperty(c,M,{enumerable:!0,get:function(){return S[C]}})}:function(c,S,C,M){M===void 0&&(M=C),c[M]=S[C]}),$=ebml&&ebml.__exportStar||function(c,S){for(var C in c)C!=="default"&&!Object.prototype.hasOwnProperty.call(S,C)&&N(S,c,C)};Object.defineProperty(O,"__esModule",{value:!0}),O.tools=O.Reader=O.Encoder=O.Decoder=void 0,$(requireEBML(),O);var D=requireEBMLDecoder();O.Decoder=D.default;var b=requireEBMLEncoder();O.Encoder=b.default;var k=requireEBMLReader();O.Reader=k.default;var i=requireTools();O.tools=i}(ebml)),ebml}var hasRequiredLib;function requireLib(){if(hasRequiredLib)return lib;hasRequiredLib=1;var O=lib&&lib.__awaiter||function(b,k,i,c){function S(C){return C instanceof i?C:new i(function(M){M(C)})}return new(i||(i=Promise))(function(C,M){function Z(Y){try{z(c.next(Y))}catch(re){M(re)}}function J(Y){try{z(c.throw(Y))}catch(re){M(re)}}function z(Y){Y.done?C(Y.value):S(Y.value).then(Z,J)}z((c=c.apply(b,k||[])).next())})},N=lib&&lib.__generator||function(b,k){var i={label:0,sent:function(){if(C[0]&1)throw C[1];return C[1]},trys:[],ops:[]},c,S,C,M;return M={next:Z(0),throw:Z(1),return:Z(2)},typeof Symbol=="function"&&(M[Symbol.iterator]=function(){return this}),M;function Z(z){return function(Y){return J([z,Y])}}function J(z){if(c)throw new TypeError("Generator is already executing.");for(;i;)try{if(c=1,S&&(C=z[0]&2?S.return:z[0]?S.throw||((C=S.return)&&C.call(S),0):S.next)&&!(C=C.call(S,z[1])).done)return C;switch(S=0,C&&(z=[z[0]&2,C.value]),z[0]){case 0:case 1:C=z;break;case 4:return i.label++,{value:z[1],done:!1};case 5:i.label++,S=z[1],z=[0];continue;case 7:z=i.ops.pop(),i.trys.pop();continue;default:if(C=i.trys,!(C=C.length>0&&C[C.length-1])&&(z[0]===6||z[0]===2)){i=0;continue}if(z[0]===3&&(!C||z[1]>C[0]&&z[1]<C[3])){i.label=z[1];break}if(z[0]===6&&i.label<C[1]){i.label=C[1],C=z;break}if(C&&i.label<C[2]){i.label=C[2],i.ops.push(z);break}C[2]&&i.ops.pop(),i.trys.pop();continue}z=k.call(b,i)}catch(Y){z=[6,Y],S=0}finally{c=C=0}if(z[0]&5)throw z[1];return{value:z[0]?z[1]:void 0,done:!0}}};Object.defineProperty(lib,"__esModule",{value:!0});var $=requireEbml();function D(b){return O(this,void 0,void 0,function(){var k,i,c,S,C,M,Z,J,z,Y,re,oe;return N(this,function(ie){switch(ie.label){case 0:if(!b)throw Error("call to fixWebmDuration requires a blob");k=new $.Decoder,i=new $.Reader,c=b.stream(),S=c.getReader(),ie.label=1;case 1:return[4,S.read()];case 2:return C=ie.sent(),M=C.done,Z=C.value,M?(i.stop(),[3,3]):(J=k.decode(Z),J=J==null?void 0:J.filter(function(de){return de.type!=="unknown"}),J.forEach(function(de){i.read(de)}),Z=null,[3,1]);case 3:return z=$.tools.makeMetadataSeekable(i.metadatas,i.duration,i.cues),Y=new Blob([z],{type:b.type}),re=b.slice(i.metadataSize),oe=new Blob([Y,re],{type:b.type}),[2,oe]}})})}return lib.default=D,lib}var libExports=requireLib();const fixWebmDuration=getDefaultExportFromCjs(libExports);class StreamRecorder{constructor(){ke(this,Ve);ke(this,vt,!1);ke(this,st,!1);ke(this,qt,0);ke(this,Nt,0);ke(this,Xe,0);ke(this,tt,0);ke(this,bt,0);ne(this,"onchange",N=>{});ne(this,"onDurationChange",N=>{});ne(this,"start",async(N="")=>{N||(N=`video_Record_${E(Date.now())}`);let $=[];return navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}).then(D=>{const b=D.getTracks();for(const i of b)i.onended=()=>this.stop();Be(this,vt,!0),Be(this,st,!1),Be(this,Ve,new MediaRecorder(D)),se(this,Ve).start();const k=new Date().getTime();Be(this,qt,k),Be(this,Xe,k),se(this,kt).call(this),se(this,Pt).call(this),se(this,Ve).addEventListener("dataavailable",i=>{$.push(i.data)}),se(this,Ve).addEventListener("stop",async()=>{Be(this,vt,!1);const i=new Date().getTime();Be(this,Nt,i),Be(this,tt,se(this,tt)+(i-se(this,Xe))),se(this,kt).call(this),clearInterval(se(this,bt));const c=D.getTracks();for(const J of c)J.stop();if(se(this,Ve)===null)return;const S=new Blob($,{type:se(this,Ve).mimeType}),C=await fixWebmDuration(S),M=URL.createObjectURL(C),Z=document.createElement("a");Z.href=M,Z.download=`${N}.mp4`,Z.click(),URL.revokeObjectURL(M),$=[],Be(this,Ve,null)})})});ne(this,"pause",async()=>{var $;await new Promise(D=>setTimeout(()=>D(!0),300)),($=se(this,Ve))==null||$.pause(),Be(this,st,!0);const N=new Date().getTime();Be(this,tt,se(this,tt)+(N-se(this,Xe))),se(this,kt).call(this),clearInterval(se(this,bt))});ne(this,"resume",async()=>{var $;($=se(this,Ve))==null||$.resume(),Be(this,st,!1);const N=new Date().getTime();Be(this,Xe,N),se(this,kt).call(this),se(this,Pt).call(this)});ne(this,"stop",async()=>{var N;(N=se(this,Ve))==null||N.stop()});ne(this,"getDuration",()=>{if(se(this,Xe)===0)return 0;let N=se(this,tt);const $=new Date().getTime();if(se(this,vt)&&se(this,st)===!1){const D=$-se(this,Xe);Be(this,Xe,$),N=N+D}return N});ne(this,"getInfo",()=>({active:se(this,vt),pause:se(this,st),startTime:se(this,qt),endTime:se(this,Nt),duration:se(this,tt)}));ke(this,kt,()=>{const N=this.getInfo();this.onchange(N)});ke(this,Pt,()=>{clearInterval(se(this,bt)),Be(this,bt,window.setInterval(()=>{Be(this,tt,this.getDuration()),this.onDurationChange(se(this,tt))},500))})}}Ve=new WeakMap,vt=new WeakMap,st=new WeakMap,qt=new WeakMap,Nt=new WeakMap,Xe=new WeakMap,tt=new WeakMap,bt=new WeakMap,kt=new WeakMap,Pt=new WeakMap;var l=Object.defineProperty,y=O=>{throw TypeError(O)},q=(O,N,$)=>N in O?l(O,N,{enumerable:!0,configurable:!0,writable:!0,value:$}):O[N]=$,s=(O,N,$)=>q(O,typeof N!="symbol"?N+"":N,$),P=(O,N,$)=>N.has(O)||y("Cannot "+$),n=(O,N,$)=>(P(O,N,"read from private field"),$?$.call(O):N.get(O)),a=(O,N,$)=>N.has(O)?y("Cannot add the same private member more than once"):N instanceof WeakSet?N.add(O):N.set(O,$),d,v,o;class p{constructor(N={}){s(this,"queue",[]),s(this,"timer",0),s(this,"activeIndex",0),s(this,"activePromise"),s(this,"options",{timeout:0}),s(this,"add",($,D={})=>new Promise(async(b,k)=>{const i=D.timeout||this.options.timeout,c=D.key||n(this,d).call(this),S=D.describe||"";if(this.queue.findIndex(M=>M.key===c)!==-1)return k(`${c} is exist.`);const C={key:c,func:$,describe:S,timeout:i,resolve:b,reject:k};this.queue.unshift(C),this.activePromise||n(this,o).call(this)})),s(this,"clear",()=>{this.queue=[],this.activePromise=void 0,clearTimeout(this.timer)}),s(this,"retry",()=>{n(this,o).call(this)}),a(this,d,()=>(this.activeIndex=this.activeIndex+1,`${this.activeIndex}`)),a(this,v,$=>{const D=this.queue.findIndex(b=>b.key===$);this.queue.splice(D,1)}),a(this,o,async()=>{const $=this.queue.length;if($===0)return;const D=$-1,b=this.queue[D];this.activePromise=b;const{key:k,func:i,resolve:c,reject:S,timeout:C}=this.activePromise;C&&(this.timer=window.setTimeout(()=>{S(`pr-async-queue: ${k} is timeout.`),n(this,o).call(this)},C)),await i().then(c).catch(S).finally(()=>{clearTimeout(this.timer),this.activePromise=void 0,n(this,v).call(this,k),n(this,o).call(this)})}),this.options={timeout:0,...N}}}d=new WeakMap,v=new WeakMap,o=new WeakMap;class RoomBase{constructor(N){ne(this,"options",{appid:"",sdkToken:"",roomId:"",userId:"",earlyId:xt(),callType:0,debug:!1,reportErr:!0,logUrl:"https://logs1.quickvo.org",newPublishAutoSubscribe:!0});ne(this,"sdk_service_version","1.0.8");ne(this,"sdk_session","");ne(this,"prohibitNotify",!1);ne(this,"isEarly",!1);ne(this,"isInRoom",!1);ne(this,"asyncQueue");ne(this,"roomState","ready");ne(this,"createAt",Date.now());ne(this,"cwsIns");ne(this,"peerIns");ne(this,"transceiverMap",new Map);ne(this,"sendChannel");ne(this,"receiveChannel");ne(this,"userMap",new Map);ne(this,"p2pMap",new Map);ne(this,"setLocalStreamActiveMap",new Map);ne(this,"phoneyStreams",new Map);ne(this,"recorder",new StreamRecorder);ne(this,"networkQualityTester",new NetworkQualityTester);ne(this,"mediaDevicesErrInfo",{microphoneCamera_audio:"",microphoneCamera_video:"",screenSharing_video:"",screenSharing_audio:""});ne(this,"reportLogs",(N,$="未知错误")=>{const{appid:D,userId:b,earlyId:k="",logUrl:i,reportErr:c}=this.options;if(!c)return;const S="web",C=M=>({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})[M].toString();{const M=C(N),Z={origin:S,type:M,app_id:D,user_id:b,ins_id:k,desc:$},J=btoa(encodeURI(JSON.stringify(Z))),z=`${i}/upload/log?log_key=${J}`;{const Y=localStorage.getItem("#quickvo.logs")||JSON.stringify([]),oe=new TextEncoder().encode(Y),ie=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:Z,url:z,size:lt(ie.byteLength)}),fetch(z,{headers:{"Content-Type":"multipart/form-data"},method:"POST",body:ie})}}});ne(this,"initPhoneyStreams",(N,$=[])=>{$.length===0&&($=mediaType_keys);for(const D of $){const b=this.phoneyStreams.get(D);if(b){const k=b.getTracks();for(const i of k)i.stop()}switch(D){case"microphoneCamera_audio":this.phoneyStreams.set("microphoneCamera_audio",createMutedAudioStream(N));break;case"microphoneCamera_video":this.phoneyStreams.set("microphoneCamera_video",createFakeVideoStream());break;case"screenSharing_audio":this.phoneyStreams.set("screenSharing_audio",createMutedAudioStream(N));break;case"screenSharing_video":this.phoneyStreams.set("screenSharing_video",createFakeVideoStream());break}}});ne(this,"getPhoneyStreams",N=>this.phoneyStreams.get(N));ne(this,"getRoomInfo",()=>{const{options:N,roomState:$,createAt:D}=this;return{...N,roomState:$,createAt:D}});ne(this,"setRoomState",N=>{this.roomState=N,N==="closed"&&(this.cwsIns.state=N);const $=enum_roomState[N],D={state:N,stateStr:$};this.cwsIns.emitNotify("onRoomState",{code:200,data:D,desc:"room state is change."})});ne(this,"setOptions",async N=>{const $={...this.options,...N};this.options=$});ne(this,"stopStream",async N=>{const $=N.getTracks();for(const D of $)D.stop()});ne(this,"getMediaDevicesErrInfo",async()=>{try{const N=await navigator.mediaDevices.enumerateDevices();N.find(D=>D.kind==="audioinput")||(this.mediaDevicesErrInfo.microphoneCamera_audio="audioinput is not available."),N.find(D=>D.kind==="videoinput")||(this.mediaDevicesErrInfo.microphoneCamera_video="videoinput is not available.")}catch(N){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getMediaDevicesErrInfo is error.",N)}return this.mediaDevicesErrInfo});ne(this,"getUserMediaKey",(N,$)=>`${N}-${$}`);ne(this,"getCallAction",async N=>{let $="";const D=k=>N.findIndex(({type:c,enabled:S=!0})=>c===k&&S)===-1?"0":"1";return $=`${D(0)}${$}`,$=`${D(1)}${$}`,$=`${D(2)}${$}`,$=`${D(3)}${$}`,parseInt($,2)});ne(this,"getCallActionMap",(N=0)=>{const D=Number(N).toString(2).padStart(4,"0").split(""),[b,k,i,c]=D;return{microphoneCamera_audio:!!Number(c),microphoneCamera_video:!!Number(i),screenSharing_video:!!Number(k),screenSharing_audio:!!Number(b)}});ne(this,"getBanBehaviorMap",(N=0)=>{const D=Number(N).toString(2).padStart(4,"0").split(""),[b,k,i,c]=D;return{microphoneCamera_audio:!!Number(c),microphoneCamera_video:!!Number(i),screenSharing_video:!!Number(k),screenSharing_audio:!!Number(b)}});ne(this,"getAverageVolume",(N,$)=>{N.getByteFrequencyData($);let D=0;for(let k=0;k<$.length;k++)D+=$[k];return Math.ceil(D/$.length)});ne(this,"getTrackNamesFormTracks",(N,$=[],D="trackName")=>{const b=[];for(const k of N){const{type:i}=k;if($.length===0||$.includes(i)){const c=k[D];c&&b.push(`${c}`)}}return b});ne(this,"usersFilter",N=>dt(N,["id","isSelf","isOwner","joinTime","tracks","network","permissions","isPublished","updateStreams","callAction","callActionStr","callActionMap","banBehavior","banBehaviorStr","banBehaviorMap"]).sort((b,k)=>b.id.localeCompare(k.id,"en")));this.setOptions(N),this.cwsIns=new CallsWebSocket({...N}),this.asyncQueue=new p}}var m=Object.defineProperty,G=(O,N,$)=>N in O?m(O,N,{enumerable:!0,configurable:!0,writable:!0,value:$}):O[N]=$,e=(O,N,$)=>G(O,typeof N!="symbol"?N+"":N,$);class g{constructor(N,$){e(this,"inputStream",new MediaStream),e(this,"outputStream",new MediaStream),e(this,"inputGain",1),e(this,"enhanceGain",1),e(this,"bgsGain",1),e(this,"bgmGain",1),e(this,"outputGain",1),e(this,"mixAudioMap",new Map),e(this,"audioContext",new AudioContext),e(this,"sourceNode"),e(this,"inputGainNode"),e(this,"enhanceGainNode"),e(this,"bgsGainNode"),e(this,"bgmGainNode"),e(this,"analyserNode"),e(this,"analyserArrayData"),e(this,"outputGainNode"),e(this,"destinationNode"),e(this,"filterStream",D=>D),e(this,"stop",()=>{{const D=this.inputStream.getTracks();for(const b of D)b.stop(),this.inputStream.removeTrack(b)}}),e(this,"getStream",()=>this.filterStream(this.outputStream)),e(this,"setMute",(D=!0)=>{D?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),e(this,"setInputGain",D=>{this.inputGain=D,this.inputGainNode.gain.setValueAtTime(D,this.audioContext.currentTime)}),e(this,"setEnhanceGain",async D=>{this.enhanceGain=D+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),e(this,"setBgsGain",D=>{this.bgsGain=D,this.bgsGainNode.gain.setValueAtTime(D,this.audioContext.currentTime)}),e(this,"setBgmGain",D=>{this.bgmGain=D,this.bgmGainNode.gain.setValueAtTime(D,this.audioContext.currentTime)}),e(this,"setOutputGain",D=>{this.outputGain=D,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),e(this,"getVolume",()=>{const{analyserNode:D,analyserArrayData:b}=this;D.getByteFrequencyData(b);let k=0;for(let i=0;i<b.length;i++)k+=b[i];return Math.ceil(k/b.length)}),e(this,"mixAudio",(D,b="bgm")=>new Promise(async(k,i)=>{try{{const C=this.mixAudioMap.get(b);C&&C.stop()}const c=b==="bgs"?this.bgsGainNode:this.bgmGainNode,S=this.audioContext.createBufferSource();this.mixAudioMap.set(b,S),S.buffer=D,S.connect(c),S.onended=()=>{S.disconnect(c),this.mixAudioMap.delete(b),k(!0)},S.start(0)}catch(c){i(c)}})),e(this,"mixAudioStop",D=>{const b=this.mixAudioMap.get(D);b==null||b.stop()}),e(this,"changeMix",(D,b)=>{const k=D==="bgs"?this.bgsGainNode:this.bgmGainNode;b?k.connect(this.destinationNode):k.disconnect(this.destinationNode)}),$&&(this.audioContext=$),this.inputStream=N,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:D,inputGainNode:b,enhanceGainNode:k,bgsGainNode:i,bgmGainNode:c,analyserNode:S,outputGainNode:C,destinationNode:M}=this;D.connect(b),b.connect(k),k.connect(S),i.connect(S),c.connect(S),k.connect(M),i.connect(M),c.connect(M),S.connect(C),C.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}class RoomMedias extends RoomBase{constructor($){super($);ke(this,St,[]);ke(this,Ge,new Map);ke(this,ze,new Map);ke(this,Qe,new Map);ke(this,nt,new Map);ke(this,ct,new Map);ne(this,"localStreamsActionMap",new Map);ke(this,Ot,new Map);ne(this,"audioContext",new(window.AudioContext||window.webkitAudioContext));ne(this,"initMediaPhoneyStreams",($=[])=>this.initPhoneyStreams(this.audioContext,$));ne(this,"initLocalStreamsFilter",()=>{for(const $ of mediaType_keys){const D=async b=>b;se(this,Ot).set($,D)}});ne(this,"setLocalFilterStream",($,D)=>{se(this,Ot).set($,D)});ke(this,zt,()=>{se(this,ze).set("microphoneCamera_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0}),se(this,ze).set("microphoneCamera_video",{frameRate:{min:10,ideal:30}}),se(this,ze).set("screenSharing_video",{frameRate:{min:10,ideal:30}}),se(this,ze).set("screenSharing_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0})});ke(this,Ht,()=>{se(this,Ge).set("audioinput","default"),se(this,Ge).set("videoinput","default"),se(this,Ge).set("audiooutput","default")});ne(this,"emitNotifyUpdateUsersStreams",async $=>{this.cwsIns.emitNotify("onRoomUsersStreams",{code:200,data:$,desc:"users streams is change."})});ne(this,"initUserMediaStreamContext",async($,D,b)=>{const[k]=b.getTracks();if(!k){console.warn("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: tracks.length is 0.",{userId:$,mediaType:D,stream:b});return}this.removeUserMediaStreamContext($,D);const i=this.getUserMediaKey($,D),{kind:c}=k;switch(c){case"audio":{const S=new MediaStream;S.addTrack(k);const C=new g(S,this.audioContext);se(this,Qe).set(i,C)}break;case"video":{const S=new VideoMediaContext(k);se(this,nt).set(i,S)}break}});ne(this,"getUserMediaStreamContext",($,D)=>{const b=this.getUserMediaKey($,D);if(["microphoneCamera_audio","screenSharing_audio"].includes(D))return se(this,Qe).get(b);if(["microphoneCamera_video","screenSharing_video"].includes(D))return se(this,nt).get(b)});ne(this,"getUserAudioMediaStreamContext",($,D)=>{const b=this.getUserMediaKey($,D);return se(this,Qe).get(b)});ne(this,"removeUserMediaStreamContext",($,D)=>{const b=this.getUserMediaKey($,D);if(["microphoneCamera_audio","screenSharing_audio"].includes(D)){const k=se(this,Qe).get(b);return k==null||k.stop(),se(this,Qe).delete(b)}if(["microphoneCamera_video","screenSharing_video"].includes(D)){const k=se(this,nt).get(b);return k==null||k.stop(),se(this,nt).get(b)}});ne(this,"getUserStream",($,D)=>{const b=this.getUserMediaStreamContext($,D);return(b==null?void 0:b.getStream())||new MediaStream});ne(this,"getUserStreams",($,D=[])=>{D.length===0&&(D=mediaType_keys);const b={};for(const k of D){const i=this.getUserStream($,k);b[k]=i}return b});ne(this,"removeUserStreams",async($,D=[])=>{D.length===0&&(D=mediaType_keys);for(const b of D)this.removeUserMediaStreamContext($,b)});ne(this,"clearUserStreams",()=>{{const $=se(this,Qe).values();for(const D of $)D.stop();Be(this,Qe,new Map)}{const $=se(this,nt).values();for(const D of $)D.stop();Be(this,nt,new Map)}});ne(this,"setMediaTrackConstraints",async($,D)=>{se(this,ze).set($,D);const b=await this.getLocalStream($);if(!b)return;const k=b.getTracks();if(k.length!==0)for(const i of k){const c=i.getConstraints(),C={...se(this,ze).get($),...c,...D};await i.applyConstraints(C)}});ne(this,"stopLocalStreams",async($=[])=>{$.length===0&&($=mediaType_keys);for(const D of $){const b=se(this,ct).get(D);b&&await this.stopStream(b),se(this,ct).delete(D)}});ne(this,"addLocalStream",($,D)=>{const b=se(this,ct).get($);b&&this.stopStream(b),se(this,ct).set($,D)});ne(this,"initLocalStream",async $=>{switch($){case"microphoneCamera_audio":{const D=se(this,Ge).get("audioinput"),b=se(this,ze).get("microphoneCamera_audio"),k=await navigator.mediaDevices.getUserMedia({audio:{deviceId:D,...b},video:!1});this.addLocalStream("microphoneCamera_audio",k)}break;case"microphoneCamera_video":{const D=se(this,Ge).get("videoinput"),b=se(this,ze).get("microphoneCamera_video"),k=await navigator.mediaDevices.getUserMedia({audio:!1,video:{deviceId:D,...b}});this.addLocalStream("microphoneCamera_video",k)}break;case"microphoneCamera":{const D=se(this,Ge).get("audioinput"),b=se(this,Ge).get("videoinput"),k=se(this,ze).get("microphoneCamera_audio"),i=se(this,ze).get("microphoneCamera_video"),S=(await navigator.mediaDevices.getUserMedia({audio:{deviceId:D,...k},video:{deviceId:b,...i}})).getTracks();for(const C of S){const{kind:M}=C;if(M==="audio"){const Z=new MediaStream;Z.addTrack(C),this.addLocalStream("microphoneCamera_audio",Z)}if(M==="video"){const Z=new MediaStream;Z.addTrack(C),this.addLocalStream("microphoneCamera_video",Z)}}}break;case"screenSharing_audio":{const D=se(this,ze).get("screenSharing_audio"),k=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...D})).getTracks();for(const i of k){const{kind:c}=i;if(c==="audio"){const S=new MediaStream;S.addTrack(i),this.addLocalStream("screenSharing_audio",S)}}}break;case"screenSharing_video":{const D=se(this,ze).get($),k=(await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0,...D})).getTracks();for(const i of k){const{kind:c}=i;if(c==="video"){const S=new MediaStream;S.addTrack(i),this.addLocalStream("screenSharing_video",S)}}}break;case"screenSharing":{const D=se(this,ze).get("screenSharing_audio"),b=se(this,ze).get("screenSharing_video"),i=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...D,...b})).getTracks();for(const c of i){const{kind:S}=c;if(S==="audio"){const C=new MediaStream;C.addTrack(c),this.addLocalStream("screenSharing_audio",C)}if(S==="video"){const C=new MediaStream;C.addTrack(c),this.addLocalStream("screenSharing_video",C)}}}break}});ne(this,"getLocalStream",async $=>{const D=se(this,ct).get($),b=se(this,Ot).get($);let k=D;return D&&b&&(k=await b(D)),k});ne(this,"getLocalStreams",async($=[])=>{$.length===0&&($=mediaType_keys);const D={};for(const b of $)D[b]=await this.getLocalStream(b);return D});ke(this,Tt,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($=>{const D=$.filter(b=>!["communications"].includes(b.deviceId));Be(this,St,D.sort((b,k)=>b.label.localeCompare(k.label,"zh-Hans-CN",{sensitivity:"accent"})))}).catch(function($){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getEnumerateDevices is err",$)}),se(this,St)));ke(this,Zt,()=>{navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=async()=>{await se(this,Tt).call(this),this.cwsIns.emitNotify("onDevicechange",{code:200,data:{},desc:"device is change."})}),se(this,Tt).call(this)});ne(this,"getMediaDeviceKind",$=>se(this,Ge).get($));ne(this,"changeAudiooutput",async()=>{try{const $=se(this,Ge).get("audiooutput");await this.audioContext.setSinkId($)}catch($){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSinkId is error.",$)}});ne(this,"setDeviceKind",($,D)=>{se(this,Ge).set($,D)});ne(this,"setAudioOutputDevice",$=>this.setDeviceKind("audiooutput",$));ne(this,"getEnumerateDevices",async $=>(await se(this,Tt).call(this),se(this,St).filter(b=>b.kind===$)));ne(this,"getEnumerateAudioinputDevices",()=>this.getEnumerateDevices("audioinput"));ne(this,"getEnumerateAudioOutputDevices",()=>this.getEnumerateDevices("audiooutput"));ne(this,"getEnumerateVideoinputDevices",()=>this.getEnumerateDevices("videoinput"));se(this,Zt).call(this),se(this,Ht).call(this),se(this,zt).call(this),this.initPhoneyStreams(this.audioContext),document.addEventListener("click",()=>{var D;((D=this.audioContext)==null?void 0:D.state)==="suspended"&&this.audioContext.resume()})}}St=new WeakMap,Ge=new WeakMap,ze=new WeakMap,Qe=new WeakMap,nt=new WeakMap,ct=new WeakMap,Ot=new WeakMap,zt=new WeakMap,Ht=new WeakMap,Tt=new WeakMap,Zt=new WeakMap;const getIcecandidate=O=>new Promise((N,$)=>{const D=[],b=async i=>{i.candidate?D.push(i.candidate):(clearTimeout(k),O.removeEventListener("icecandidate",b),N(D))},k=window.setTimeout(()=>{O.removeEventListener("icecandidate",b),$(new Error("timeout"))},1e3);O.addEventListener("icecandidate",b)});class P2P{constructor(){ne(this,"peerIns",new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}));ne(this,"initOffer",()=>new Promise(async N=>{const $=async()=>{const c=await this.peerIns.createOffer();return await this.peerIns.setLocalDescription(c),c},D=getIcecandidate(this.peerIns),b=$(),[k,i]=await Promise.all([D,b]);N({offer:i,icecandidates:k})}));ne(this,"initAnswer",async(N,$)=>new Promise(async D=>{const b=async()=>{await this.peerIns.setRemoteDescription(N);for(const M of $)await this.peerIns.addIceCandidate(M);const C=await this.peerIns.createAnswer();return await this.peerIns.setLocalDescription(C),C},k=getIcecandidate(this.peerIns),i=b(),[c,S]=await Promise.all([k,i]);D({answer:S,icecandidates:c})}));ne(this,"setAnswer",async(N,$)=>new Promise(async D=>{await this.peerIns.setRemoteDescription(N);for(const b of $)await this.peerIns.addIceCandidate(b);D(!0)}));ne(this,"close",()=>{this.peerIns.close()});this.peerIns.addTransceiver("video",{direction:"sendrecv"})}}class RoomUsers extends RoomMedias{constructor($){super($);ne(this,"createP2P",async()=>{const $=new P2P,D=await $.initOffer();console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: res",D),this.p2pMap.set("aaa",$)});ne(this,"getMaxVolumeUser",()=>{const $=Array.from(this.userMap.values(),({id:b})=>b);if($.length===0)return;let D=[];for(const b of $){const k=this.getUserAudioMediaStreamContext(b,"microphoneCamera_audio");if(!k)continue;const i=k.getVolume();D.push({id:b,volume:i})}return D=D.sort((b,k)=>b.volume-k.volume>0?-1:1),D[0]});ne(this,"setVolume",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setInputGain(b)});ne(this,"setEnhanceGain",async($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setEnhanceGain(b)});ne(this,"setSpeaker",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setOutputGain(b);const i=b===0;k==null||k.setMute(i)});ne(this,"playBgs",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);return k==null?void 0:k.mixAudio(b,"bgs")});ne(this,"setBgsGain",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setBgsGain(b)});ne(this,"stopBgs",($,D)=>{const b=this.getUserAudioMediaStreamContext($,D);b==null||b.mixAudioStop("bgs")});ne(this,"playBgm",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);return k==null?void 0:k.mixAudio(b,"bgm")});ne(this,"setBgmGain",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setBgmGain(b)});ne(this,"stopBgm",($,D)=>{const b=this.getUserAudioMediaStreamContext($,D);b==null||b.mixAudioStop("bgm")});ne(this,"changBgsMix",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.changeMix("bgs",b)});ne(this,"changBgmMix",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.changeMix("bgm",b)});ne(this,"getVolume",($,D)=>{const b=this.getUserAudioMediaStreamContext($,D);return b==null?void 0:b.getVolume()});ne(this,"clearUsers",()=>{this.userMap=new Map});ne(this,"removeUsers",async $=>{for(const D of $)this.userMap.delete(D),await this.removeUserStreams(D)});ne(this,"createUser",async $=>{const D=Date.now(),b={id:$,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:$===this.options.userId,isPublished:!1,joinTime:D,updateAt:D,network:{egress:0,ingress:0},tracks:[],channels:[],updateStreams:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1}};this.userMap.set($,b)});ne(this,"getUser",async $=>(this.userMap.has($)||await this.createUser($),this.userMap.get($)));ne(this,"getUsers",async($=[])=>{$.length===0&&($=[...this.userMap.keys()]);const D=[];for(const b of $){const k=await this.getUser(b);D.push(k)}return D});ne(this,"getAllUserTrackMids",async()=>{const $=await this.getUsers(),D=[];for(const b of $){const{tracks:k=[]}=b;for(const i of k)D.push(i.mid)}return D});ne(this,"getUserTrackByTrackName",async $=>{const D=await this.getUsers(),b=[];for(const k of D){const{tracks:i=[]}=k;for(const c of i){const{trackName:S}=c;$.includes(S)&&b.push(c)}}return b});ne(this,"getUserTrackFromMid",async $=>{const D=await this.getUsers();let b;for(const k of D){const{tracks:i=[]}=k;for(const c of i)if(c.mid===$){b=c;break}}return b});ne(this,"checkUserInRoom",$=>this.userMap.has($));ne(this,"getUsersId",async()=>[...this.userMap.keys()]);ne(this,"getSelfInfo",async()=>await this.getUser(this.options.userId));ne(this,"updateIsPublished",async($,D=!1)=>{const b=await this.getUser($);b.isPublished=D});ne(this,"setUserUpdateStreams",async($,D,b=!0)=>{const k=await this.getUser($),i={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};i[D]=b,k.updateStreams=i});ne(this,"updateUserChannels",async($,D=[],b)=>{const k=await this.getUser($);b&&(D=[...k.channels,...D]),k.channels=D});ne(this,"updateUsertracks",async($,D=[],b)=>{const k=await this.getUser($);b&&(D=[...k.tracks,...D]),D=D.filter(({mid:S=""})=>S!==""),D=pt(D,["type"]),D=D.sort((S,C)=>S.type-C.type<0?-1:1);for(const S of D)S.userId=$,S.mediaType=mediaType_keys[S.type],S.enabled===void 0&&(S.enabled=!0);k.updateStreams={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};const i=dt(k.tracks,["mediaType","enabled","mid","msid","trackName","key"]),c=dt(D,["mediaType","enabled","mid","msid","trackName","key"]);for(const S of mediaType_keys){const C=c.find(J=>J.mediaType===S),M=i.find(J=>J.mediaType===S),Z=JSON.stringify(C)!==JSON.stringify(M);k.updateStreams[S]=Z}k.tracks=D});ne(this,"updateUserCallAction",async($,D=0)=>{const b=await this.getUser($);b.callAction=D,b.callActionStr=D.toString(2).padStart(4,"0"),b.callActionMap=this.getCallActionMap(D)});ne(this,"updateUserBehaviors",async($,D=0)=>{const b=await this.getUser($);b.banBehavior=D,b.banBehaviorStr=D.toString(2).padStart(4,"0"),b.banBehaviorMap=this.getBanBehaviorMap(D)});ne(this,"updateUserNetwork",async($,D={egress:5,ingress:5})=>{const b=await this.getUser($);b.network=D});ne(this,"updateUserPermissions",async($,D)=>{if(D){const b=await this.getUser($);b.permissions=D}});ne(this,"updateUserBase",async $=>{const D=await this.getUser($);D.isSelf=$===this.options.userId,D.updateAt=Date.now()});ne(this,"updateUsers",async $=>{for(const D of $){const{id:b,tracks:k,callAction:i,permissions:c,isPublished:S}=D;await this.updateUserBase(b),await this.updateIsPublished(b,S),await this.updateUserPermissions(b,c),await this.updateUsertracks(b,k,!0),await this.updateUserCallAction(b,i),await this.updateUserNetwork(b)}});ne(this,"emitNotifyUpdateUser",async $=>{const D=await this.getUsers([$]),[b]=this.usersFilter(D);this.cwsIns.emitNotify("onRoomUser",{code:200,data:b,desc:"user info is change."})});ne(this,"emitNotifyUpdateUsers",async()=>{const $=await this.getUsers(),D=this.usersFilter($);this.cwsIns.emitNotify("onRoomUsers",{code:200,data:D,desc:"all users info is change."})})}}class RoomPeer extends RoomUsers{constructor($){super($);ne(this,"getPeerStatsTimer",0);ne(this,"reports",[]);ne(this,"candidates",[]);ke(this,Ut,[]);ke(this,It,0);ne(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});ne(this,"initPeer",()=>{var $;clearTimeout(se(this,It)),this.transceiverMap=new Map,($=this.peerIns)==null||$.close(),this.peerIns=void 0,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),se(this,Jt).call(this),se(this,Gt).call(this),this.initMediaPhoneyStreams()});ne(this,"initSendChannel",($="",D)=>{const b=this.peerIns.createDataChannel($,{negotiated:!0,id:D});b.addEventListener("open",async k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->sendChannel: onopen",k),setInterval(()=>{const i=new Date().getTime();b.send(`Hi you! on: ${E(i)}`)},1e3)}),b.addEventListener("close",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->sendChannel: close",k)}),b.addEventListener("message",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->sendChannel: onmessage",k)}),this.sendChannel=b,this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initSendChannel",{label:$,id:D,channel:b})});ne(this,"initReceiveChannel",($="",D)=>{const b=this.peerIns.createDataChannel($,{negotiated:!0,id:D});b.addEventListener("open",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->receiveChannel: onopen",k)}),b.addEventListener("close",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->receiveChannel: close",k)}),b.addEventListener("message",async k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->receiveChannel: onmessage",k)}),this.receiveChannel=b,this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initReceiveChannel",{label:$,id:D,channel:b}),this.receiveChannel.send("hello")});ne(this,"replaceSenderStream",async($=[],D)=>{const{userId:b}=this.options;$.length===0&&($=mediaType_keys);for(const k of $){const i=this.transceiverMap.get(k);let c;if(i){const{sender:S}=i;D?c=this.getUserStream(b,k):c=this.getPhoneyStreams(k);const[C]=c.getTracks();C&&await S.replaceTrack(C)}}});ne(this,"getSenderTracks",async($=[])=>{const D=[];for(const b of $){const k=this.transceiverMap.get(b);if(!k)continue;const{mid:i,sender:c}=k,{track:S}=c;if(!S)continue;const{id:C,enabled:M}=S,Z=mediaType_keys.findIndex(Y=>Y===b),J=xt(),z={type:Z,enabled:M,trackName:`web-${Z}-${C}`,location:"local",mid:i,key:J};D.push(z)}return D});ne(this,"addSenders",async($=[])=>{$.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const D=[];for(const b of $){if(this.transceiverMap.get(b))continue;const i=this.getPhoneyStreams(b),[c]=i.getTracks(),S=this.peerIns.addTransceiver(c,{direction:"sendonly"});this.transceiverMap.set(b,S),D.push(b)}if($.length===0||D.length!==0){const b=await this.peerIns.createOffer();if(this.options.debug){const k=libExports$1.parse(b.sdp),i=dt(k.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:i,sdpJson:k,description:b})}await this.peerIns.setLocalDescription(b)}return D});ne(this,"removeSenders",async($=[])=>{$.length===0&&($=mediaType_keys);for(const D of $)this.transceiverMap.has(D)&&this.transceiverMap.delete(D)});ne(this,"onSubscribeUserTracks",$=>{let D=0;return new Promise(async b=>{const k=[];for(const i of $){const{tracks:c=[]}=i;for(const S of c){const{trackName:C,mid:M}=S,[Z]=await this.getUserTrackByTrackName([C]);k.push({...Z,mid:M})}}{let i=[];const c=async()=>{clearTimeout(D);const C=new Map;for(const Z of i){const{userId:J,mediaType:z}=Z;if(!J||!z)continue;C.has(J)||C.set(J,{userId:J,tracks:[],updateStreams:{}});const re=C.get(J);re.tracks.push(Z),re.updateStreams[z]=!0}const M=[...C.values()];for(const Z of M){const{userId:J,tracks:z}=Z;await this.updateUsertracks(J,z,!0)}await this.emitNotifyUpdateUsersStreams(M),this.peerIns.removeEventListener("track",S);{const Z=Array.from(k,Y=>Y.trackName),J=Array.from(i,Y=>Y.trackName),z=Z.filter(Y=>!J.includes(Y));b({target:Z,success:J,fail:z})}},S=async C=>{const{streams:M,transceiver:Z}=C,[J]=M,{mid:z,receiver:Y}=Z,{track:re}=Y,{id:oe}=re,ie=k.find(Q=>Q.mid===`${z}`);if(!ie)return;const{userId:de,mediaType:ye}=ie;if(!(!de||!ye)){{const Q={...ie,mid:z,msid:oe,key:xt()};i.push(Q)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${i.length}/${k.length}`,{mediaType:ye,mid:z,userTrack:ie,e:C});{const Q=new Audio;if(Q.srcObject=J,await this.initUserMediaStreamContext(de,ye,J),ye==="microphoneCamera_audio"||ye==="screenSharing_audio"){const ae=this.getUserAudioMediaStreamContext(de,ye);ae==null||ae.setMute(!1)}}k.length===i.length&&c()}};this.peerIns.addEventListener("track",S),D=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${i.length}/${k.length})`),c()},5*1e3)}})});ke(this,Jt,()=>{const $=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.oniceconnectionstatechange=async()=>{const D=this.peerIns.iceConnectionState;switch(clearTimeout(se(this,It)),D){case"connected":{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${D}`),this.setRoomState("connected");for(const b of se(this,Ut))await b()}break;case"disconnected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${D}`),Be(this,It,window.setTimeout($,30*1e3));break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${D}`),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:${D}`),$();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${D}`);break}}});ne(this,"iceConnected",()=>new Promise($=>{if(this.peerIns.iceConnectionState==="connected")return $(!0);se(this,Ut).push($)}));ne(this,"closeUserTracks",async($,D=[],b=!1)=>{const k=[];for(const C of D){const{trackName:M,msid:Z}=C;k.push(M),Z&&k.push(Z)}const i=C=>k.includes(C),c=this.peerIns.getTransceivers();for(const C of c){const{mid:M,sender:Z,receiver:J}=C;Z.track&&i(Z.track.id)&&(C.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${M} is stop.`,C)),J.track&&i(J.track.id)&&(C.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${M} is stop.`,C))}const S=await this.getUser($);if(S){for(const C of S.tracks){const{trackName:M,msid:Z,userId:J,mediaType:z}=C;!J||!z||!i(M)||(this.removeUserMediaStreamContext(J,z),Z&&delete C.msid)}if(b){const C=S.tracks.filter(({trackName:M})=>!i(M));await this.updateUsertracks($,C,!1)}}});ne(this,"createOffer",async()=>{const $=await this.peerIns.createOffer();if(this.options.debug){const D=libExports$1.parse($.sdp),b=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:b,sdpJson:D,description:$})}await this.peerIns.setLocalDescription($)});ne(this,"createAnswer",async()=>{const $=await this.peerIns.createAnswer();if(this.options.debug){const D=libExports$1.parse($.sdp),b=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:b,sdpJson:D,description:$})}await this.peerIns.setLocalDescription($)});ne(this,"getSdp",()=>{var $;return($=this.peerIns.localDescription)==null?void 0:$.sdp});ne(this,"setRemoteDescription",async $=>{if(this.options.debug){const D=libExports$1.parse($.sdp),b=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:b,sdpJson:D,description:$})}return await this.peerIns.setRemoteDescription($),$});ne(this,"setCallStrategy",async($,D=[])=>{D.length===0&&(D=mediaType_keys);let b="balanced";switch($){case"qualityPriority":b="maintain-resolution";break;case"fluencyPriority":b="maintain-framerate";break;case"balancedDowngrade":b="balanced";break}const k=await this.getSelfInfo(),i=Array.from(k.tracks,({trackName:S})=>S),c=this.peerIns.getSenders();for(const S of c){const{track:C}=S;if(!C||!i.includes(C.id))continue;const M=S.getParameters();S.setParameters({...M,degradationPreference:b})}});ne(this,"setRTCRtpSenderParameters",$=>{try{const D=this.peerIns.getSenders();for(const b of D){const k=b.getParameters();b.setParameters({...k,...$})}}catch(D){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",D)}});ne(this,"getReportsByMid",async($=[])=>$.length===0?this.reports:this.reports.filter(D=>$.includes(D.mid)));ne(this,"getRoomNetwork",()=>this.peerNetwork);ne(this,"getPeerNetwork",()=>this.peerNetwork);ke(this,Vt,async()=>{try{const $=await this.peerIns.getStats(),D=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],k=[...$.values()].filter(ae=>D.includes(ae.type));let i=0,c=0,S=0,C=0,M=0,Z=0,J=[],z=[];for(const ae of this.reports){const{packetsSent:he,packetsLost:ce}=ae;he&&(S+=he),ce&&(C+=ce)}this.reports=k;for(const ae of this.reports){const{bytesSent:he,bytesReceived:ce,packetsSent:fe,packetsLost:me,roundTripTime:ee,jitter:le}=ae;he&&(c=he),ce&&(i=ce),fe&&(M+=fe),me&&(Z+=me),ee&&J.push((ee*100).toFixed(2)),le&&z.push(le.toFixed(2))}z.sort().reverse(),J.sort().reverse();const Y=M-S,re=Z-C,oe=Y===0?"0.00":(re/Y).toFixed(2),[ie="0"]=J,[de="0"]=z,ye={outboundBytes:c,inboundBytes:i,lostRate:oe,roundTripTime:ie,jitter:de};this.peerNetwork=ye;const Q=(ae,he,ce)=>{const fe=Number(ae),me=Number(he),ee=Number(ce);let le="0";return fe<.03&&me<100&&ee<.05?le="5":fe<.06&&me<160&&ee<.1?le="4":fe<.1&&me<250&&ee<.15?le="3":fe<.15&&me<400&&ee<.2?le="2":le="1",Number(le)};{const ae=Q(oe,ie,de),he=await this.getSelfInfo(),{network:ce}=he,fe={egress:ae,ingress:ae};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,fe),JSON.stringify(ce)!==JSON.stringify(fe)){this.emitNotifyUpdateUsers();const{userId:le,roomId:ve}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...fe,userId:le,roomId:ve}},!1)}},3*1e3)}}catch($){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",$)}});ke(this,Gt,()=>{const $=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||se(this,Vt).call(this)};this.getPeerStatsTimer=window.setInterval($,1*1e3)});ne(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer));this.initPeer()}}Ut=new WeakMap,It=new WeakMap,Jt=new WeakMap,Vt=new WeakMap,Gt=new WeakMap;class RoomCalls extends RoomPeer{constructor($){super($);ke(this,Et,0);ke(this,Rt,[]);ke(this,_t,()=>{});ne(this,"setLocalStream",($,D)=>new Promise(async(b,k)=>{try{typeof $=="string"&&($=[$]);for(const c of $)this.localStreamsActionMap.set(c,D);if(D){if($.includes("microphoneCamera_audio")&&$.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):$.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):$.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):$.includes("screenSharing_audio")&&$.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):$.includes("screenSharing_audio")&&!$.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):$.includes("screenSharing_video")&&!$.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),$.includes("screenSharing_audio")){const c=await this.getLocalStream("screenSharing_audio");if(c){const S=c.getTracks();for(const C of S)C.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if($.includes("screenSharing_video")){const c=await this.getLocalStream("screenSharing_video");if(c){const S=c.getTracks();for(const C of S)C.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams($);const i=await this.getLocalStreams($);await this.cwsIns.emitNotify("onLocalStream",{code:200,data:i,desc:"local stream is change."}),b(i)}catch(i){k(i)}}));ne(this,"setMediaDeviceKind",($,D)=>new Promise(async(b,k)=>{this.setDeviceKind($,D);const i=await this.getSelfInfo(),{id:c,tracks:S=[],callActionMap:C}=i,M=[],Z=async J=>{const z=this.localStreamsActionMap.get(J),Y=S.find(oe=>oe.mediaType===J),re=C[J];if(z){M.push(J),await this.stopLocalStreams([J]);try{await this.initLocalStream(J)}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([J],!1),k(oe)}}if(Y){const oe=await this.getLocalStream(J);oe&&(await this.initUserMediaStreamContext(c,J,oe),re&&await this.replaceSenderStream([J],!0))}{const oe=await this.getLocalStreams(M);await this.cwsIns.emitNotify("onLocalStream",{code:200,data:oe,desc:"local stream is change."}),await this.emitNotifyUpdateUsers(),b(!0)}};$==="audioinput"&&await Z("microphoneCamera_audio"),$==="videoinput"&&await Z("microphoneCamera_video"),$==="audiooutput"&&(await this.changeAudiooutput(),b(!0))}));ne(this,"changeScreenSharing",async $=>{const D=await this.getSelfInfo(),{tracks:b=[],callActionMap:k}=D;try{await this.setLocalStream($,!0);for(const i of $)b.find(S=>S.mediaType===i&&k[i])&&await this.replaceSenderStream([i],!0)}catch(i){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",i)}});ne(this,"earlyConnect",($=[])=>{this.isEarly=!0;const D=async()=>new Promise(async(b,k)=>{try{await se(this,wt).call(this).then(async()=>{await se(this,Dt).call(this),$.length===0&&($=["microphoneCamera_audio","microphoneCamera_video"]),await se(this,Mt).call(this,$),b(!0)})}catch(i){k(i)}});return this.asyncQueue.add(D,{describe:"earlyConnect"})});ne(this,"joinRoom",async $=>(this.isInRoom=!0,this.setOptions($),await se(this,wt).call(this),new Promise(async(D,b)=>{Be(this,_t,async()=>{try{this.clearUsers();const{roomId:k,userId:i,callType:c,sdkToken:S}=this.options;await this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:c,roomId:k,user:{id:i,tracks:[],callAction:0},token:S},version:2}).then(async C=>{const{code:M=0,desc:Z="服务器繁忙",data:J}=C;if(M!==200)throw new Error(Z);const{roomId:z="",roomUsers:Y=[]}=J;if(z!==k)return b("加入的房间不匹配");this.initHeartbeat(),this.isEarly===!1&&await se(this,Dt).call(this),await this.updateUsers(Y);const re=[];for(const ie of Y){const{id:de,channelCache:ye}=ie,{channels:Q=[]}=ye;await this.updateUserBehaviors(de,ie.behavior),await this.updateUserChannels(de,Q,!1),Q.length!==0&&re.push({userId:de,channels:Q})}await this.subChannel(re),await this.emitNotifyUpdateUsers();const oe=await this.getUsers();D(oe)})}catch(k){b(k)}}),se(this,_t).call(this)})));ne(this,"quitRoom",()=>new Promise(async $=>{const{roomId:D,userId:b}=this.options,k={roomId:D,user:{id:b}};try{this.isInRoom=!1,this.options.roomId="",this.asyncQueue.clear(),clearInterval(se(this,Et)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(i){this.reportLogs("quit_room_error",i.message||i)}await new Promise(i=>setTimeout(()=>i(!0),300)),await this.cwsIns.sendMessage({event:"quitRoom",data:k}),$(!0)}));ne(this,"quitRoomEx",()=>new Promise(async $=>{const{roomId:D,userId:b}=this.options,k={roomId:D,user:{id:b}};try{this.isInRoom=!1,this.options.roomId="",this.asyncQueue.clear(),this.stopHeartbeat(),this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe().catch(()=>{this.reconstruct()}),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(i){this.reportLogs("quit_room_error",i.message||i)}await new Promise(i=>setTimeout(()=>i(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:k}),$(!0)}));ne(this,"syncRoomInfo",()=>new Promise(async($,D)=>{try{const{userId:b}=this.options,k=await this.getUser(b),{id:i=b,callAction:c=0}=k;await this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:i,callAction:c}}}).then(async S=>{const{code:C=0,desc:M,data:Z={}}=S;if(C!==200)throw new Error(M);const{isActive:J=!1,users:z=[]}=Z;if(J===!1)throw new Error("Do not stay in this room.");if(z.find(re=>re.id===this.options.userId)===!1)throw new Error("Need to rejoin the room.");this.clearUsers(),await this.updateUsers(z),await this.updateUsertracks(k.id,k.tracks,!1);{const re=await this.getUsers();$(re)}})}catch(b){D(b)}}));ne(this,"checkInRoom",()=>new Promise(async $=>{const{userId:D}=this.options,b=await this.getUser(D),{id:k=D,callAction:i=0}=b;await this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:k,callAction:i}}}).then(async c=>{var J;const{code:S=0,desc:C}=c;if(S!==200)throw new Error(C);const M=c.data.users;return(J=c.data)!=null&&J.isActive||M.find(z=>z.id===this.options.userId)?$(!0):$(!1)}).catch(()=>$(!1))}));ne(this,"publish",$=>{const D=()=>new Promise(async(b,k)=>{try{{const J=await this.getSelfInfo(),{banBehaviorMap:z}=J;let Y=!0;for(const re of $)if(z[re]){Y=!1;break}if(Y===!1)return k("publish is error: prohibited by administrator.")}try{await this.setLocalStream($,!0)}catch(J){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",J)}const i=await this.getSelfInfo(),c=[];for(const J of $){{const z=this.getPhoneyStreams(J);await this.initUserMediaStreamContext(i.id,J,z)}{const z=await this.getLocalStream(J);z?await this.initUserMediaStreamContext(i.id,J,z):c.push(J)}}const S=$.filter(J=>!c.includes(J)||["microphoneCamera_audio","microphoneCamera_video"].includes(J));await this.replaceSenderStream($,!1),await se(this,Mt).call(this,S);const C=await this.getSenderTracks(S),M=[...i.tracks,...C];await this.updateUsertracks(i.id,M,!0),c.length!==0&&await this.inactiveTracks(c,!1),S.length!==0&&await this.replaceSenderStream(S,!0);const Z=await this.getCallAction(M);await se(this,Ct).call(this,Z),await new Promise(J=>setTimeout(()=>J(!0),230)),se(this,Wt).call(this,$);{await this.emitNotifyUpdateUsers();const J=await this.getSelfInfo();b(J)}}catch(i){this.reportLogs("publish_error",i.message||i),k(i)}});return this.asyncQueue.add(D,{describe:"publish"})});ne(this,"stopPublish",($=[])=>{const D=()=>new Promise(async(b,k)=>{try{const i=await this.getSelfInfo();$.length===0&&($=mediaType_keys);const c=i.tracks.filter(({mediaType:C})=>C&&$.includes(C)),S=async()=>{const C=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),b(C)};if(c.length===0)return S();await this.replaceSenderStream($,!0),await this.closeUserTracks(i.id,c,!0),await this.removeSenders($);{const C=await this.getCallAction(i.tracks);await se(this,Ct).call(this,C)}await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{session:this.sdk_session,roomId:this.options.roomId,sdp:this.getSdp(),tracks:c}}).then(async C=>{const{code:M=0,desc:Z,sn:J="",data:z={}}=C;if(await se(this,ut).call(this,J),M!==200)throw new Error(Z);const{remoteSdp:Y}=z;await this.setRemoteDescription({type:"answer",sdp:Y}),S()})}catch(i){this.reportLogs("close_track_error",i.message||i),k(i)}});return this.asyncQueue.add(D,{describe:"stopPublish"})});ne(this,"subscribe",($=[],D=3)=>{const b=()=>new Promise(async(k,i)=>{try{await this.iceConnected();const c=await this.getUsers();let S=[];for(const J of c){const{isSelf:z,tracks:Y=[]}=J;if(!z){const re=Y.filter(({trackName:oe,mid:ie=""})=>ie!==""&&($.includes(oe)||$.length===0));re.length!==0&&S.push({...J,tracks:re})}}const C=async(J={})=>{const z=Array.from(S,({id:re})=>re),Y=await this.getUsers(z);await this.emitNotifyUpdateUsers(),k({users:Y,detail:J})};if(S.length===0)return C();const M=[];for(const J of S){const{id:z,tracks:Y}=J,re=dt(Y,["type","trackName"]),oe={id:z,tracks:re};M.push(oe)}const Z=async()=>{D--,await this.cwsIns.sendMessage({event:"subscribe",data:{session:this.sdk_session,users:M}}).then(async J=>{const{code:z=0,desc:Y,sn:re="",data:oe={}}=J;if(await se(this,ut).call(this,re),z===2017&&Y.includes("renegotiation is expected before pulling or pushing tracks")&&await this.renegotiate(),z!==200){if(D>=0)return await new Promise(ye=>setTimeout(()=>ye(!0),500)),await Z();throw new Error(Y)}const{remoteSdp:ie,users:de=[]}=oe;this.onSubscribeUserTracks(de).then(async ye=>{await this.renegotiate().then(()=>C(ye))}).catch(ye=>{throw new Error(ye)}),await this.setRemoteDescription({type:"offer",sdp:ie})})};await Z()}catch(c){this.reportLogs("subscribe_error",c.message||c),i(c)}});return this.asyncQueue.add(b,{describe:"subscribe"})});ne(this,"renegotiate",()=>new Promise(async($,D)=>{try{await this.createAnswer(),await this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(async b=>{const{code:k=0,desc:i,sn:c=""}=b;if(await se(this,ut).call(this,c),k!==200)throw new Error(i);$(b)})}catch(b){D(b)}}));ne(this,"stopSubscribe",($=[])=>{const D=()=>new Promise(async(b,k)=>{try{const i=await this.getUsers(),c=[];for(const C of i){const{tracks:M=[]}=C;for(const Z of M){const{type:J,mid:z,trackName:Y,mediaType:re,msid:oe}=Z;if(!(!re||!oe)&&($.length===0||$.includes(Y))){const ie={type:J,mid:z,trackName:oe};c.push(ie),await this.closeUserTracks(C.id,[Z])}}}const S=async()=>{await this.emitNotifyUpdateUsers(),b(!0)};if(c.length===0)return S();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:c}}).then(async C=>{const{code:M=0,desc:Z,sn:J="",data:z={}}=C;if(M!==200)throw new Error(Z);await se(this,ut).call(this,J);const{remoteSdp:Y}=z;await this.setRemoteDescription({type:"answer",sdp:Y})}),S()}catch(i){this.reportLogs("close_track_error",i.message||i),k(i)}});return this.asyncQueue.add(D,{describe:"stopSubscribe"})});ne(this,"inactiveTracks",async($,D)=>new Promise(async b=>{const k=await this.getSelfInfo();if(!k||!k.id)return b(!0);const{tracks:i=[]}=k,c=[...i];for(let C of c){const{mediaType:M}=C;if(M&&$.includes(M)){C.enabled=D;const Z=await this.getLocalStream(M);if(!Z)continue;const J=Z.getTracks();for(const z of J)z.enabled=D}}await this.replaceSenderStream($,D);const S=await this.getCallAction(c);await se(this,Ct).call(this,S),await this.emitNotifyUpdateUsers(),b(!0)}));ne(this,"setBanBehaviors",$=>new Promise(async(D,b)=>{try{const{roomId:k}=this.options,i=[];for(const c of $){const{id:S,banBehaviors:C}=c,M=Object.keys(C);if(M.length===0)continue;const Z=[];for(const z of M){const Y=mediaType_keys.findIndex(ie=>ie===z),re=C[z],oe={type:Y,behavior:re};Z.push(oe)}const J={id:S,behaviors:Z};i.push(J)}await this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:k,users:i}}).then(async c=>{const{code:S=0,desc:C}=c;if(S!==200)return b(C);D(c)})}catch(k){b(k)}}));ne(this,"pubChannel",()=>new Promise(async($,D)=>{const k=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:k}}).then(async i=>{const{code:c=0,data:S,desc:C}=i;if(c!==200)throw new Error(C);const{channels:M=[]}=S;for(const Z of M){const{channels:J=[]}=Z;for(const z of J){const{dataChannelName:Y,id:re}=z;this.initSendChannel(Y,re)}}$(!0)}).catch(i=>{D(i)})}));ne(this,"subChannel",($=[])=>new Promise(async D=>{if($.length===0)return D(!0);await this.cwsIns.sendMessage({event:"subChannel",data:{channels:$}}).then(async b=>{const{code:k=0,data:i,desc:c}=b;if(k!==200)throw new Error(c);const{channels:S=[]}=i;for(const C of S){const{channels:M=[]}=C;for(const Z of M){const{dataChannelName:J,id:z}=Z;this.initReceiveChannel(J,z)}}})}));ne(this,"debugger",()=>new Promise(async($,D)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async b=>{if(b.code!==200)return D(b.desc);$(!0)}).catch(b=>{D(b)})}));ne(this,"shutdown",()=>new Promise(async($,D)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async b=>{if(b.code!==200)return D(b.desc);$(!0)}).catch(b=>{D(b)})}));ne(this,"reconstruct",async()=>{if(this.asyncQueue.clear(),this.setRoomState("ready"),this.asyncQueue.clear(),this.initPeer(),this.isEarly&&this.earlyConnect(),this.isInRoom===!1)return;this.isInRoom&&(this.isEarly===!1&&await se(this,wt).call(this).then(async()=>{await se(this,Dt).call(this)}),se(this,_t)&&await se(this,_t).call(this));const $=[],D=[],b=await this.getUsers();for(const k of b){const{isSelf:i,callActionMap:c,tracks:S=[]}=k;if(i)for(const C of mediaType_keys)c[C]&&$.push(C);for(const C of S)C.msid&&D.push(C.trackName)}await this.syncRoomInfo().then(async()=>{await this.publish($),await this.subscribe(D)}).catch(()=>{this.setRoomState("closed")})});ne(this,"initHeartbeat",()=>{this.stopHeartbeat();const $=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),D=this.isInRoom?10*1e3:30*1e3;Be(this,Et,window.setInterval($,D)),$()});ne(this,"stopHeartbeat",()=>{clearInterval(se(this,Et))});ke(this,Wt,async $=>new Promise(async(D,b)=>{try{const{roomId:k}=this.options;if(!k)return;const{id:i,tracks:c=[]}=await this.getSelfInfo(),S=c.filter(C=>C.mediaType&&$.includes(C.mediaType));if(S.length===0)return;await this.cwsIns.sendMessage({event:"pubNotify",data:{session:this.sdk_session,roomId:k,user:{id:i,tracks:S}}}),D(!0)}catch(k){b(k)}}));ke(this,ut,$=>new Promise(D=>{this.cwsIns.sendMessage({event:"ackMsg",data:{msgId:$}},!1),D(!0)}));ke(this,Ct,async $=>new Promise(async(D,b)=>{const{roomId:k,userId:i}=this.options,c={roomId:k,user:{id:i,callAction:$}};await this.cwsIns.sendMessage({event:"updateCall",data:c}).then(async S=>{const{code:C=0}=S;if(C!==200)return b(S);await this.updateUserCallAction(i,$),D($)}).catch(S=>b(S))}));ne(this,"setSession",()=>{const{appid:$,roomId:D,userId:b}=this.options;if(!$)throw new Error("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const k={c:$,r:D,p:"web",h:location.hostname,v:this.sdk_service_version};this.isEarly?k.i=this.options.earlyId:k.b=b;const i=btoa(encodeURI(JSON.stringify(k)));this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSession",k);const c=`${this.options.url}?s=${i}&t=${Date.now()}`;this.cwsIns.prws.setOptions({url:c})});ke(this,wt,()=>new Promise(async($,D)=>{try{switch(this.cwsIns.state){case"connected":this.cwsIns.state==="connected"&&$(!0);break;case"connecting":se(this,Rt).push($);break;case"closed":{se(this,Rt).push($),this.cwsIns.clearEvents(),this.setSession(),await this.cwsIns.connect(),this.initHeartbeat();for(const b of se(this,Rt))await b()}break}}catch(b){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",b),this.reportLogs("ws_c_timeout",b.message||b),D(b)}}));ke(this,Dt,async()=>new Promise(async($,D)=>{try{await se(this,wt).call(this),await this.addSenders(),await this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async b=>{const{code:k=0,desc:i,data:c}=b;if(k!==200)throw new Error(i);const{remoteSdp:S,session:C=""}=c;if(this.sdk_session=C,this.options.debug){const M=libExports$1.parse(S),Z=dt(M.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:Z,sdpJson:M})}await this.setRemoteDescription({type:"answer",sdp:S}),await this.iceConnected().then(()=>{$(!0)})})}catch(b){D(b)}}));ke(this,Mt,async $=>new Promise(async(D,b)=>{try{await this.iceConnected();const k=await this.addSenders($),i=await this.getSenderTracks(k);if(i.length===0)return D(!0);await this.cwsIns.sendMessage({event:"publish",data:{session:this.sdk_session,sdp:this.getSdp(),tracks:i,callAction:0}}).then(async c=>{const{code:S=0,desc:C,sn:M="",data:Z={}}=c;if(await se(this,ut).call(this,M),S!==200)throw new Error(C);const{remoteSdp:J}=Z;await this.setRemoteDescription({type:"answer",sdp:J}),D(!0)})}catch(k){this.reportLogs("publish_error",k.message||k),await this.removeSenders($),b(k)}}))}}Et=new WeakMap,Rt=new WeakMap,_t=new WeakMap,Wt=new WeakMap,ut=new WeakMap,Ct=new WeakMap,wt=new WeakMap,Dt=new WeakMap,Mt=new WeakMap;class Room extends RoomCalls{constructor(N){super(N)}}class QuickVO extends Room{constructor($){super($);ke(this,gt,new Map);ke(this,Kt,()=>{{const $=async D=>{const{state:b}=D.data;if(b==="closed"){const{roomId:k,userId:i}=this.options,c={roomId:k,user:{id:i}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:c}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}};this.cwsIns.addNotify({event:"onRoomState",callback:$},!0)}{const $=async D=>{const{qualities:b=[]}=D.data,[k]=b;if(!(k&&k.userId===this.options.userId&&b.length===1)){for(const i of b){const{userId:c,egress:S,ingress:C}=i;this.checkUserInRoom(c)&&await this.updateUserNetwork(c,{egress:S,ingress:C})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:$},!0)}{const $=async D=>{const b=D.data.user;await this.removeUsers([b.id]),await this.updateUsers([b]),await this.updateUsertracks(b.id,b.track,!1),await this.updateUserBehaviors(b.id,b.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:$},!0)}{const $=async D=>{await this.removeUsers([D.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:$},!0)}{const $=async D=>{const{user:b}=D.data,{id:k,tracks:i=[],callAction:c=0}=b,S=()=>new Promise(async C=>{await this.updateUserCallAction(k,c),await this.updateUserPermissions(k,3),await this.updateUsertracks(k,i,!0),C(!0)});this.asyncQueue.add(S,{describe:"onPublish"}).then(async()=>{if(this.options.newPublishAutoSubscribe){const C=this.getTrackNamesFormTracks(i);await this.subscribe(C)}else await this.emitNotifyUpdateUsers()})};this.cwsIns.addNotify({event:"onPublish",callback:$},!0)}{const $=async D=>{const b=[D.data];this.subChannel(b)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:$},!0)}{const $=async D=>{const{id:b,tracks:k}=D.data.user;b!==this.options.userId&&(await this.closeUserTracks(b,k,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:$},!0)}{const $=async D=>{const{id:b,callAction:k}=D.data.user;this.checkUserInRoom(b)&&(await this.updateUserCallAction(b,k),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:$},!0)}{const $=async D=>{const{user:b}=D.data,{id:k,permissions:i=1}=b;i===1?await this.removeUsers([k]):i===3&&await this.updateUsers([b]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:$},!0)}{const $=async D=>{const{users:b}=D.data;for(const k of b){const{id:i,behavior:c}=k;await this.updateUserBehaviors(i,c)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:$},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async $=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});ne(this,"addNotify",$=>this.cwsIns.addNotify($));ke(this,Yt,()=>{this.cwsIns.prws.checkReconnect=async $=>$.code===1e3?(this.setRoomState("closed"),!1):$.code===4001?(this.setRoomState("closed"),!1):$.code===4002?(this.setRoomState("closed"),!1):$.code===4003?(this.setRoomState("closed"),!1):(this.setSession(),$.code===4010||await new Promise(D=>setTimeout(()=>D(!0),5*1e3)),!0),this.cwsIns.prws.onReconnectSuccess=async $=>{this.reconstruct()},this.cwsIns.prws.onReconnectStop=async $=>{this.setRoomState("closed")}});ne(this,"addRequestAnimationFrame",async($,D)=>{{const k=se(this,gt).get($);k&&cancelAnimationFrame(k)}const b=(k=Date.now())=>{D(k);const i=requestAnimationFrame(b);se(this,gt).set($,i)};b()});ne(this,"clearRequestAnimationFrame",async($=[])=>{$.length===0&&($=[...se(this,gt).keys()]);const D=[];for(const b of $){const k=se(this,gt).get(b);k&&(cancelAnimationFrame(k),D.push(k))}return D});ne(this,"destroy",async()=>{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 销毁SDK"),this.stopLocalStreams(),this.stopGetPeerStats(),this.quitRoom(),this.clearUsers(),this.clearUserStreams(),this.stopHeartbeat(),await new Promise($=>setTimeout(()=>$(!0),300)),this.cwsIns.emitNotify("onDestroy",{code:200,data:{},desc:"sdk is destroy."}),this.cwsIns.clearEvents()});se(this,Yt).call(this),se(this,Kt).call(this)}}gt=new WeakMap,Kt=new WeakMap,Yt=new WeakMap,exports.QuickVO=QuickVO,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var hasRequiredBuffer;function requireBuffer(){return hasRequiredBuffer||(hasRequiredBuffer=1,function(O){const N=requireBase64Js(),$=requireIeee754(),D=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;O.Buffer=c,O.SlowBuffer=de,O.INSPECT_MAX_BYTES=50;const b=2147483647;O.kMaxLength=b,c.TYPED_ARRAY_SUPPORT=k(),!c.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 k(){try{const K=new Uint8Array(1),F={foo:function(){return 42}};return Object.setPrototypeOf(F,Uint8Array.prototype),Object.setPrototypeOf(K,F),K.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function i(K){if(K>b)throw new RangeError('The value "'+K+'" is invalid for option "size"');const F=new Uint8Array(K);return Object.setPrototypeOf(F,c.prototype),F}function c(K,F,j){if(typeof K=="number"){if(typeof F=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Z(K)}return S(K,F,j)}c.poolSize=8192;function S(K,F,j){if(typeof K=="string")return J(K,F);if(ArrayBuffer.isView(K))return Y(K);if(K==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K);if(et(K,ArrayBuffer)||K&&et(K.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(et(K,SharedArrayBuffer)||K&&et(K.buffer,SharedArrayBuffer)))return re(K,F,j);if(typeof K=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const X=K.valueOf&&K.valueOf();if(X!=null&&X!==K)return c.from(X,F,j);const te=oe(K);if(te)return te;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof K[Symbol.toPrimitive]=="function")return c.from(K[Symbol.toPrimitive]("string"),F,j);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K)}c.from=function(K,F,j){return S(K,F,j)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array);function C(K){if(typeof K!="number")throw new TypeError('"size" argument must be of type number');if(K<0)throw new RangeError('The value "'+K+'" is invalid for option "size"')}function M(K,F,j){return C(K),K<=0?i(K):F!==void 0?typeof j=="string"?i(K).fill(F,j):i(K).fill(F):i(K)}c.alloc=function(K,F,j){return M(K,F,j)};function Z(K){return C(K),i(K<0?0:ie(K)|0)}c.allocUnsafe=function(K){return Z(K)},c.allocUnsafeSlow=function(K){return Z(K)};function J(K,F){if((typeof F!="string"||F==="")&&(F="utf8"),!c.isEncoding(F))throw new TypeError("Unknown encoding: "+F);const j=ye(K,F)|0;let X=i(j);const te=X.write(K,F);return te!==j&&(X=X.slice(0,te)),X}function z(K){const F=K.length<0?0:ie(K.length)|0,j=i(F);for(let X=0;X<F;X+=1)j[X]=K[X]&255;return j}function Y(K){if(et(K,Uint8Array)){const F=new Uint8Array(K);return re(F.buffer,F.byteOffset,F.byteLength)}return z(K)}function re(K,F,j){if(F<0||K.byteLength<F)throw new RangeError('"offset" is outside of buffer bounds');if(K.byteLength<F+(j||0))throw new RangeError('"length" is outside of buffer bounds');let X;return F===void 0&&j===void 0?X=new Uint8Array(K):j===void 0?X=new Uint8Array(K,F):X=new Uint8Array(K,F,j),Object.setPrototypeOf(X,c.prototype),X}function oe(K){if(c.isBuffer(K)){const F=ie(K.length)|0,j=i(F);return j.length===0||K.copy(j,0,0,F),j}if(K.length!==void 0)return typeof K.length!="number"||Qt(K.length)?i(0):z(K);if(K.type==="Buffer"&&Array.isArray(K.data))return z(K.data)}function ie(K){if(K>=b)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+b.toString(16)+" bytes");return K|0}function de(K){return+K!=K&&(K=0),c.alloc(+K)}c.isBuffer=function(F){return F!=null&&F._isBuffer===!0&&F!==c.prototype},c.compare=function(F,j){if(et(F,Uint8Array)&&(F=c.from(F,F.offset,F.byteLength)),et(j,Uint8Array)&&(j=c.from(j,j.offset,j.byteLength)),!c.isBuffer(F)||!c.isBuffer(j))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(F===j)return 0;let X=F.length,te=j.length;for(let ue=0,pe=Math.min(X,te);ue<pe;++ue)if(F[ue]!==j[ue]){X=F[ue],te=j[ue];break}return X<te?-1:te<X?1:0},c.isEncoding=function(F){switch(String(F).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}},c.concat=function(F,j){if(!Array.isArray(F))throw new TypeError('"list" argument must be an Array of Buffers');if(F.length===0)return c.alloc(0);let X;if(j===void 0)for(j=0,X=0;X<F.length;++X)j+=F[X].length;const te=c.allocUnsafe(j);let ue=0;for(X=0;X<F.length;++X){let pe=F[X];if(et(pe,Uint8Array))ue+pe.length>te.length?(c.isBuffer(pe)||(pe=c.from(pe)),pe.copy(te,ue)):Uint8Array.prototype.set.call(te,pe,ue);else if(c.isBuffer(pe))pe.copy(te,ue);else throw new TypeError('"list" argument must be an Array of Buffers');ue+=pe.length}return te};function ye(K,F){if(c.isBuffer(K))return K.length;if(ArrayBuffer.isView(K)||et(K,ArrayBuffer))return K.byteLength;if(typeof K!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof K);const j=K.length,X=arguments.length>2&&arguments[2]===!0;if(!X&&j===0)return 0;let te=!1;for(;;)switch(F){case"ascii":case"latin1":case"binary":return j;case"utf8":case"utf-8":return ot(K).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j*2;case"hex":return j>>>1;case"base64":return At(K).length;default:if(te)return X?-1:ot(K).length;F=(""+F).toLowerCase(),te=!0}}c.byteLength=ye;function Q(K,F,j){let X=!1;if((F===void 0||F<0)&&(F=0),F>this.length||((j===void 0||j>this.length)&&(j=this.length),j<=0)||(j>>>=0,F>>>=0,j<=F))return"";for(K||(K="utf8");;)switch(K){case"hex":return We(this,F,j);case"utf8":case"utf-8":return we(this,F,j);case"ascii":return Le(this,F,j);case"latin1":case"binary":return Fe(this,F,j);case"base64":return be(this,F,j);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ft(this,F,j);default:if(X)throw new TypeError("Unknown encoding: "+K);K=(K+"").toLowerCase(),X=!0}}c.prototype._isBuffer=!0;function ae(K,F,j){const X=K[F];K[F]=K[j],K[j]=X}c.prototype.swap16=function(){const F=this.length;if(F%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let j=0;j<F;j+=2)ae(this,j,j+1);return this},c.prototype.swap32=function(){const F=this.length;if(F%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let j=0;j<F;j+=4)ae(this,j,j+3),ae(this,j+1,j+2);return this},c.prototype.swap64=function(){const F=this.length;if(F%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let j=0;j<F;j+=8)ae(this,j,j+7),ae(this,j+1,j+6),ae(this,j+2,j+5),ae(this,j+3,j+4);return this},c.prototype.toString=function(){const F=this.length;return F===0?"":arguments.length===0?we(this,0,F):Q.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(F){if(!c.isBuffer(F))throw new TypeError("Argument must be a Buffer");return this===F?!0:c.compare(this,F)===0},c.prototype.inspect=function(){let F="";const j=O.INSPECT_MAX_BYTES;return F=this.toString("hex",0,j).replace(/(.{2})/g,"$1 ").trim(),this.length>j&&(F+=" ... "),"<Buffer "+F+">"},D&&(c.prototype[D]=c.prototype.inspect),c.prototype.compare=function(F,j,X,te,ue){if(et(F,Uint8Array)&&(F=c.from(F,F.offset,F.byteLength)),!c.isBuffer(F))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof F);if(j===void 0&&(j=0),X===void 0&&(X=F?F.length:0),te===void 0&&(te=0),ue===void 0&&(ue=this.length),j<0||X>F.length||te<0||ue>this.length)throw new RangeError("out of range index");if(te>=ue&&j>=X)return 0;if(te>=ue)return-1;if(j>=X)return 1;if(j>>>=0,X>>>=0,te>>>=0,ue>>>=0,this===F)return 0;let pe=ue-te,Ee=X-j;const Pe=Math.min(pe,Ee),qe=this.slice(te,ue),Ue=F.slice(j,X);for(let Ae=0;Ae<Pe;++Ae)if(qe[Ae]!==Ue[Ae]){pe=qe[Ae],Ee=Ue[Ae];break}return pe<Ee?-1:Ee<pe?1:0};function he(K,F,j,X,te){if(K.length===0)return-1;if(typeof j=="string"?(X=j,j=0):j>2147483647?j=2147483647:j<-2147483648&&(j=-2147483648),j=+j,Qt(j)&&(j=te?0:K.length-1),j<0&&(j=K.length+j),j>=K.length){if(te)return-1;j=K.length-1}else if(j<0)if(te)j=0;else return-1;if(typeof F=="string"&&(F=c.from(F,X)),c.isBuffer(F))return F.length===0?-1:ce(K,F,j,X,te);if(typeof F=="number")return F=F&255,typeof Uint8Array.prototype.indexOf=="function"?te?Uint8Array.prototype.indexOf.call(K,F,j):Uint8Array.prototype.lastIndexOf.call(K,F,j):ce(K,[F],j,X,te);throw new TypeError("val must be string, number or Buffer")}function ce(K,F,j,X,te){let ue=1,pe=K.length,Ee=F.length;if(X!==void 0&&(X=String(X).toLowerCase(),X==="ucs2"||X==="ucs-2"||X==="utf16le"||X==="utf-16le")){if(K.length<2||F.length<2)return-1;ue=2,pe/=2,Ee/=2,j/=2}function Pe(Ue,Ae){return ue===1?Ue[Ae]:Ue.readUInt16BE(Ae*ue)}let qe;if(te){let Ue=-1;for(qe=j;qe<pe;qe++)if(Pe(K,qe)===Pe(F,Ue===-1?0:qe-Ue)){if(Ue===-1&&(Ue=qe),qe-Ue+1===Ee)return Ue*ue}else Ue!==-1&&(qe-=qe-Ue),Ue=-1}else for(j+Ee>pe&&(j=pe-Ee),qe=j;qe>=0;qe--){let Ue=!0;for(let Ae=0;Ae<Ee;Ae++)if(Pe(K,qe+Ae)!==Pe(F,Ae)){Ue=!1;break}if(Ue)return qe}return-1}c.prototype.includes=function(F,j,X){return this.indexOf(F,j,X)!==-1},c.prototype.indexOf=function(F,j,X){return he(this,F,j,X,!0)},c.prototype.lastIndexOf=function(F,j,X){return he(this,F,j,X,!1)};function fe(K,F,j,X){j=Number(j)||0;const te=K.length-j;X?(X=Number(X),X>te&&(X=te)):X=te;const ue=F.length;X>ue/2&&(X=ue/2);let pe;for(pe=0;pe<X;++pe){const Ee=parseInt(F.substr(pe*2,2),16);if(Qt(Ee))return pe;K[j+pe]=Ee}return pe}function me(K,F,j,X){return Bt(ot(F,K.length-j),K,j,X)}function ee(K,F,j,X){return Bt(mt(F),K,j,X)}function le(K,F,j,X){return Bt(At(F),K,j,X)}function ve(K,F,j,X){return Bt(Xt(F,K.length-j),K,j,X)}c.prototype.write=function(F,j,X,te){if(j===void 0)te="utf8",X=this.length,j=0;else if(X===void 0&&typeof j=="string")te=j,X=this.length,j=0;else if(isFinite(j))j=j>>>0,isFinite(X)?(X=X>>>0,te===void 0&&(te="utf8")):(te=X,X=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ue=this.length-j;if((X===void 0||X>ue)&&(X=ue),F.length>0&&(X<0||j<0)||j>this.length)throw new RangeError("Attempt to write outside buffer bounds");te||(te="utf8");let pe=!1;for(;;)switch(te){case"hex":return fe(this,F,j,X);case"utf8":case"utf-8":return me(this,F,j,X);case"ascii":case"latin1":case"binary":return ee(this,F,j,X);case"base64":return le(this,F,j,X);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ve(this,F,j,X);default:if(pe)throw new TypeError("Unknown encoding: "+te);te=(""+te).toLowerCase(),pe=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function be(K,F,j){return F===0&&j===K.length?N.fromByteArray(K):N.fromByteArray(K.slice(F,j))}function we(K,F,j){j=Math.min(K.length,j);const X=[];let te=F;for(;te<j;){const ue=K[te];let pe=null,Ee=ue>239?4:ue>223?3:ue>191?2:1;if(te+Ee<=j){let Pe,qe,Ue,Ae;switch(Ee){case 1:ue<128&&(pe=ue);break;case 2:Pe=K[te+1],(Pe&192)===128&&(Ae=(ue&31)<<6|Pe&63,Ae>127&&(pe=Ae));break;case 3:Pe=K[te+1],qe=K[te+2],(Pe&192)===128&&(qe&192)===128&&(Ae=(ue&15)<<12|(Pe&63)<<6|qe&63,Ae>2047&&(Ae<55296||Ae>57343)&&(pe=Ae));break;case 4:Pe=K[te+1],qe=K[te+2],Ue=K[te+3],(Pe&192)===128&&(qe&192)===128&&(Ue&192)===128&&(Ae=(ue&15)<<18|(Pe&63)<<12|(qe&63)<<6|Ue&63,Ae>65535&&Ae<1114112&&(pe=Ae))}}pe===null?(pe=65533,Ee=1):pe>65535&&(pe-=65536,X.push(pe>>>10&1023|55296),pe=56320|pe&1023),X.push(pe),te+=Ee}return Ne(X)}const $e=4096;function Ne(K){const F=K.length;if(F<=$e)return String.fromCharCode.apply(String,K);let j="",X=0;for(;X<F;)j+=String.fromCharCode.apply(String,K.slice(X,X+=$e));return j}function Le(K,F,j){let X="";j=Math.min(K.length,j);for(let te=F;te<j;++te)X+=String.fromCharCode(K[te]&127);return X}function Fe(K,F,j){let X="";j=Math.min(K.length,j);for(let te=F;te<j;++te)X+=String.fromCharCode(K[te]);return X}function We(K,F,j){const X=K.length;(!F||F<0)&&(F=0),(!j||j<0||j>X)&&(j=X);let te="";for(let ue=F;ue<j;++ue)te+=nn[K[ue]];return te}function ft(K,F,j){const X=K.slice(F,j);let te="";for(let ue=0;ue<X.length-1;ue+=2)te+=String.fromCharCode(X[ue]+X[ue+1]*256);return te}c.prototype.slice=function(F,j){const X=this.length;F=~~F,j=j===void 0?X:~~j,F<0?(F+=X,F<0&&(F=0)):F>X&&(F=X),j<0?(j+=X,j<0&&(j=0)):j>X&&(j=X),j<F&&(j=F);const te=this.subarray(F,j);return Object.setPrototypeOf(te,c.prototype),te};function Re(K,F,j){if(K%1!==0||K<0)throw new RangeError("offset is not uint");if(K+F>j)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=this[F],ue=1,pe=0;for(;++pe<j&&(ue*=256);)te+=this[F+pe]*ue;return te},c.prototype.readUintBE=c.prototype.readUIntBE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=this[F+--j],ue=1;for(;j>0&&(ue*=256);)te+=this[F+--j]*ue;return te},c.prototype.readUint8=c.prototype.readUInt8=function(F,j){return F=F>>>0,j||Re(F,1,this.length),this[F]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(F,j){return F=F>>>0,j||Re(F,2,this.length),this[F]|this[F+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(F,j){return F=F>>>0,j||Re(F,2,this.length),this[F]<<8|this[F+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),(this[F]|this[F+1]<<8|this[F+2]<<16)+this[F+3]*16777216},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),this[F]*16777216+(this[F+1]<<16|this[F+2]<<8|this[F+3])},c.prototype.readBigUInt64LE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=j+this[++F]*2**8+this[++F]*2**16+this[++F]*2**24,ue=this[++F]+this[++F]*2**8+this[++F]*2**16+X*2**24;return BigInt(te)+(BigInt(ue)<<BigInt(32))}),c.prototype.readBigUInt64BE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=j*2**24+this[++F]*2**16+this[++F]*2**8+this[++F],ue=this[++F]*2**24+this[++F]*2**16+this[++F]*2**8+X;return(BigInt(te)<<BigInt(32))+BigInt(ue)}),c.prototype.readIntLE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=this[F],ue=1,pe=0;for(;++pe<j&&(ue*=256);)te+=this[F+pe]*ue;return ue*=128,te>=ue&&(te-=Math.pow(2,8*j)),te},c.prototype.readIntBE=function(F,j,X){F=F>>>0,j=j>>>0,X||Re(F,j,this.length);let te=j,ue=1,pe=this[F+--te];for(;te>0&&(ue*=256);)pe+=this[F+--te]*ue;return ue*=128,pe>=ue&&(pe-=Math.pow(2,8*j)),pe},c.prototype.readInt8=function(F,j){return F=F>>>0,j||Re(F,1,this.length),this[F]&128?(255-this[F]+1)*-1:this[F]},c.prototype.readInt16LE=function(F,j){F=F>>>0,j||Re(F,2,this.length);const X=this[F]|this[F+1]<<8;return X&32768?X|4294901760:X},c.prototype.readInt16BE=function(F,j){F=F>>>0,j||Re(F,2,this.length);const X=this[F+1]|this[F]<<8;return X&32768?X|4294901760:X},c.prototype.readInt32LE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),this[F]|this[F+1]<<8|this[F+2]<<16|this[F+3]<<24},c.prototype.readInt32BE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),this[F]<<24|this[F+1]<<16|this[F+2]<<8|this[F+3]},c.prototype.readBigInt64LE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=this[F+4]+this[F+5]*2**8+this[F+6]*2**16+(X<<24);return(BigInt(te)<<BigInt(32))+BigInt(j+this[++F]*2**8+this[++F]*2**16+this[++F]*2**24)}),c.prototype.readBigInt64BE=yt(function(F){F=F>>>0,De(F,"offset");const j=this[F],X=this[F+7];(j===void 0||X===void 0)&&je(F,this.length-8);const te=(j<<24)+this[++F]*2**16+this[++F]*2**8+this[++F];return(BigInt(te)<<BigInt(32))+BigInt(this[++F]*2**24+this[++F]*2**16+this[++F]*2**8+X)}),c.prototype.readFloatLE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),$.read(this,F,!0,23,4)},c.prototype.readFloatBE=function(F,j){return F=F>>>0,j||Re(F,4,this.length),$.read(this,F,!1,23,4)},c.prototype.readDoubleLE=function(F,j){return F=F>>>0,j||Re(F,8,this.length),$.read(this,F,!0,52,8)},c.prototype.readDoubleBE=function(F,j){return F=F>>>0,j||Re(F,8,this.length),$.read(this,F,!1,52,8)};function xe(K,F,j,X,te,ue){if(!c.isBuffer(K))throw new TypeError('"buffer" argument must be a Buffer instance');if(F>te||F<ue)throw new RangeError('"value" argument is out of bounds');if(j+X>K.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(F,j,X,te){if(F=+F,j=j>>>0,X=X>>>0,!te){const Ee=Math.pow(2,8*X)-1;xe(this,F,j,X,Ee,0)}let ue=1,pe=0;for(this[j]=F&255;++pe<X&&(ue*=256);)this[j+pe]=F/ue&255;return j+X},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(F,j,X,te){if(F=+F,j=j>>>0,X=X>>>0,!te){const Ee=Math.pow(2,8*X)-1;xe(this,F,j,X,Ee,0)}let ue=X-1,pe=1;for(this[j+ue]=F&255;--ue>=0&&(pe*=256);)this[j+ue]=F/pe&255;return j+X},c.prototype.writeUint8=c.prototype.writeUInt8=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,1,255,0),this[j]=F&255,j+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,65535,0),this[j]=F&255,this[j+1]=F>>>8,j+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,65535,0),this[j]=F>>>8,this[j+1]=F&255,j+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,4294967295,0),this[j+3]=F>>>24,this[j+2]=F>>>16,this[j+1]=F>>>8,this[j]=F&255,j+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,4294967295,0),this[j]=F>>>24,this[j+1]=F>>>16,this[j+2]=F>>>8,this[j+3]=F&255,j+4};function it(K,F,j,X,te){Ie(F,X,te,K,j,7);let ue=Number(F&BigInt(4294967295));K[j++]=ue,ue=ue>>8,K[j++]=ue,ue=ue>>8,K[j++]=ue,ue=ue>>8,K[j++]=ue;let pe=Number(F>>BigInt(32)&BigInt(4294967295));return K[j++]=pe,pe=pe>>8,K[j++]=pe,pe=pe>>8,K[j++]=pe,pe=pe>>8,K[j++]=pe,j}function Me(K,F,j,X,te){Ie(F,X,te,K,j,7);let ue=Number(F&BigInt(4294967295));K[j+7]=ue,ue=ue>>8,K[j+6]=ue,ue=ue>>8,K[j+5]=ue,ue=ue>>8,K[j+4]=ue;let pe=Number(F>>BigInt(32)&BigInt(4294967295));return K[j+3]=pe,pe=pe>>8,K[j+2]=pe,pe=pe>>8,K[j+1]=pe,pe=pe>>8,K[j]=pe,j+8}c.prototype.writeBigUInt64LE=yt(function(F,j=0){return it(this,F,j,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=yt(function(F,j=0){return Me(this,F,j,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(F,j,X,te){if(F=+F,j=j>>>0,!te){const Pe=Math.pow(2,8*X-1);xe(this,F,j,X,Pe-1,-Pe)}let ue=0,pe=1,Ee=0;for(this[j]=F&255;++ue<X&&(pe*=256);)F<0&&Ee===0&&this[j+ue-1]!==0&&(Ee=1),this[j+ue]=(F/pe>>0)-Ee&255;return j+X},c.prototype.writeIntBE=function(F,j,X,te){if(F=+F,j=j>>>0,!te){const Pe=Math.pow(2,8*X-1);xe(this,F,j,X,Pe-1,-Pe)}let ue=X-1,pe=1,Ee=0;for(this[j+ue]=F&255;--ue>=0&&(pe*=256);)F<0&&Ee===0&&this[j+ue+1]!==0&&(Ee=1),this[j+ue]=(F/pe>>0)-Ee&255;return j+X},c.prototype.writeInt8=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,1,127,-128),F<0&&(F=255+F+1),this[j]=F&255,j+1},c.prototype.writeInt16LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,32767,-32768),this[j]=F&255,this[j+1]=F>>>8,j+2},c.prototype.writeInt16BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,2,32767,-32768),this[j]=F>>>8,this[j+1]=F&255,j+2},c.prototype.writeInt32LE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,2147483647,-2147483648),this[j]=F&255,this[j+1]=F>>>8,this[j+2]=F>>>16,this[j+3]=F>>>24,j+4},c.prototype.writeInt32BE=function(F,j,X){return F=+F,j=j>>>0,X||xe(this,F,j,4,2147483647,-2147483648),F<0&&(F=4294967295+F+1),this[j]=F>>>24,this[j+1]=F>>>16,this[j+2]=F>>>8,this[j+3]=F&255,j+4},c.prototype.writeBigInt64LE=yt(function(F,j=0){return it(this,F,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=yt(function(F,j=0){return Me(this,F,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ke(K,F,j,X,te,ue){if(j+X>K.length)throw new RangeError("Index out of range");if(j<0)throw new RangeError("Index out of range")}function rt(K,F,j,X,te){return F=+F,j=j>>>0,te||Ke(K,F,j,4),$.write(K,F,j,X,23,4),j+4}c.prototype.writeFloatLE=function(F,j,X){return rt(this,F,j,!0,X)},c.prototype.writeFloatBE=function(F,j,X){return rt(this,F,j,!1,X)};function Ye(K,F,j,X,te){return F=+F,j=j>>>0,te||Ke(K,F,j,8),$.write(K,F,j,X,52,8),j+8}c.prototype.writeDoubleLE=function(F,j,X){return Ye(this,F,j,!0,X)},c.prototype.writeDoubleBE=function(F,j,X){return Ye(this,F,j,!1,X)},c.prototype.copy=function(F,j,X,te){if(!c.isBuffer(F))throw new TypeError("argument should be a Buffer");if(X||(X=0),!te&&te!==0&&(te=this.length),j>=F.length&&(j=F.length),j||(j=0),te>0&&te<X&&(te=X),te===X||F.length===0||this.length===0)return 0;if(j<0)throw new RangeError("targetStart out of bounds");if(X<0||X>=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),F.length-j<te-X&&(te=F.length-j+X);const ue=te-X;return this===F&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(j,X,te):Uint8Array.prototype.set.call(F,this.subarray(X,te),j),ue},c.prototype.fill=function(F,j,X,te){if(typeof F=="string"){if(typeof j=="string"?(te=j,j=0,X=this.length):typeof X=="string"&&(te=X,X=this.length),te!==void 0&&typeof te!="string")throw new TypeError("encoding must be a string");if(typeof te=="string"&&!c.isEncoding(te))throw new TypeError("Unknown encoding: "+te);if(F.length===1){const pe=F.charCodeAt(0);(te==="utf8"&&pe<128||te==="latin1")&&(F=pe)}}else typeof F=="number"?F=F&255:typeof F=="boolean"&&(F=Number(F));if(j<0||this.length<j||this.length<X)throw new RangeError("Out of range index");if(X<=j)return this;j=j>>>0,X=X===void 0?this.length:X>>>0,F||(F=0);let ue;if(typeof F=="number")for(ue=j;ue<X;++ue)this[ue]=F;else{const pe=c.isBuffer(F)?F:c.from(F,te),Ee=pe.length;if(Ee===0)throw new TypeError('The value "'+F+'" is invalid for argument "value"');for(ue=0;ue<X-j;++ue)this[ue+j]=pe[ue%Ee]}return this};const He={};function ge(K,F,j){He[K]=class extends j{constructor(){super(),Object.defineProperty(this,"message",{value:F.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${K}]`,this.stack,delete this.name}get code(){return K}set code(te){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:te,writable:!0})}toString(){return`${this.name} [${K}]: ${this.message}`}}}ge("ERR_BUFFER_OUT_OF_BOUNDS",function(K){return K?`${K} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ge("ERR_INVALID_ARG_TYPE",function(K,F){return`The "${K}" argument must be of type number. Received type ${typeof F}`},TypeError),ge("ERR_OUT_OF_RANGE",function(K,F,j){let X=`The value of "${K}" is out of range.`,te=j;return Number.isInteger(j)&&Math.abs(j)>2**32?te=_e(String(j)):typeof j=="bigint"&&(te=String(j),(j>BigInt(2)**BigInt(32)||j<-(BigInt(2)**BigInt(32)))&&(te=_e(te)),te+="n"),X+=` It must be ${F}. Received ${te}`,X},RangeError);function _e(K){let F="",j=K.length;const X=K[0]==="-"?1:0;for(;j>=X+4;j-=3)F=`_${K.slice(j-3,j)}${F}`;return`${K.slice(0,j)}${F}`}function Se(K,F,j){De(F,"offset"),(K[F]===void 0||K[F+j]===void 0)&&je(F,K.length-(j+1))}function Ie(K,F,j,X,te,ue){if(K>j||K<F){const pe=typeof F=="bigint"?"n":"";let Ee;throw F===0||F===BigInt(0)?Ee=`>= 0${pe} and < 2${pe} ** ${(ue+1)*8}${pe}`:Ee=`>= -(2${pe} ** ${(ue+1)*8-1}${pe}) and < 2 ** ${(ue+1)*8-1}${pe}`,new He.ERR_OUT_OF_RANGE("value",Ee,K)}Se(X,te,ue)}function De(K,F){if(typeof K!="number")throw new He.ERR_INVALID_ARG_TYPE(F,"number",K)}function je(K,F,j){throw Math.floor(K)!==K?(De(K,j),new He.ERR_OUT_OF_RANGE("offset","an integer",K)):F<0?new He.ERR_BUFFER_OUT_OF_BOUNDS:new He.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${F}`,K)}const Je=/[^+/0-9A-Za-z-_]/g;function Ze(K){if(K=K.split("=")[0],K=K.trim().replace(Je,""),K.length<2)return"";for(;K.length%4!==0;)K=K+"=";return K}function ot(K,F){F=F||1/0;let j;const X=K.length;let te=null;const ue=[];for(let pe=0;pe<X;++pe){if(j=K.charCodeAt(pe),j>55295&&j<57344){if(!te){if(j>56319){(F-=3)>-1&&ue.push(239,191,189);continue}else if(pe+1===X){(F-=3)>-1&&ue.push(239,191,189);continue}te=j;continue}if(j<56320){(F-=3)>-1&&ue.push(239,191,189),te=j;continue}j=(te-55296<<10|j-56320)+65536}else te&&(F-=3)>-1&&ue.push(239,191,189);if(te=null,j<128){if((F-=1)<0)break;ue.push(j)}else if(j<2048){if((F-=2)<0)break;ue.push(j>>6|192,j&63|128)}else if(j<65536){if((F-=3)<0)break;ue.push(j>>12|224,j>>6&63|128,j&63|128)}else if(j<1114112){if((F-=4)<0)break;ue.push(j>>18|240,j>>12&63|128,j>>6&63|128,j&63|128)}else throw new Error("Invalid code point")}return ue}function mt(K){const F=[];for(let j=0;j<K.length;++j)F.push(K.charCodeAt(j)&255);return F}function Xt(K,F){let j,X,te;const ue=[];for(let pe=0;pe<K.length&&!((F-=2)<0);++pe)j=K.charCodeAt(pe),X=j>>8,te=j%256,ue.push(te),ue.push(X);return ue}function At(K){return N.toByteArray(Ze(K))}function Bt(K,F,j,X){let te;for(te=0;te<X&&!(te+j>=F.length||te>=K.length);++te)F[te+j]=K[te];return te}function et(K,F){return K instanceof F||K!=null&&K.constructor!=null&&K.constructor.name!=null&&K.constructor.name===F.name}function Qt(K){return K!==K}const nn=function(){const K="0123456789abcdef",F=new Array(256);for(let j=0;j<16;++j){const X=j*16;for(let te=0;te<16;++te)F[X+te]=K[j]+K[te]}return F}();function yt(K){return typeof BigInt>"u"?rn:K}function rn(){throw new Error("BigInt not supported")}}(buffer)),buffer}var toolsEbml={},hasRequiredToolsEbml;function requireToolsEbml(){if(hasRequiredToolsEbml)return toolsEbml;hasRequiredToolsEbml=1;var O=toolsEbml&&toolsEbml.__assign||function(){return O=Object.assign||function(b){for(var k,i=1,c=arguments.length;i<c;i++){k=arguments[i];for(var S in k)Object.prototype.hasOwnProperty.call(k,S)&&(b[S]=k[S])}return b},O.apply(this,arguments)},N=toolsEbml&&toolsEbml.__spreadArray||function(b,k,i){if(i||arguments.length===2)for(var c=0,S=k.length,C;c<S;c++)(C||!(c in k))&&(C||(C=Array.prototype.slice.call(k,0,c)),C[c]=k[c]);return b.concat(C||Array.prototype.slice.call(k))};Object.defineProperty(toolsEbml,"__esModule",{value:!0});var $=requireTools(),D=function(){function b(){}return b.readVint=function(k,i){i===void 0&&(i=0);var c=8-Math.floor(Math.log2(k[i]));if(c>8){var S=b.readHexString(k,i,i+c);throw new Error("Unrepresentable length: ".concat(c," ").concat(S))}if(i+c>k.length)return null;for(var C=k[i]&(1<<8-c)-1,M=1;M<c;M+=1){if(M===7&&C>=Math.pow(2,8)&&k[i+7]>0)return{length:c,value:-1};C*=Math.pow(2,8),C+=k[i+M]}return{length:c,value:C}},b.writeVint=function(k){if(k<0||k>Math.pow(2,53))throw new Error("Unrepresentable value: ".concat(k));var i=1;for(i=1;i<=8&&!(k<Math.pow(2,7*i)-1);i+=1);for(var c=$.Buffer.alloc(i),S=k,C=1;C<=i;C+=1){var M=S&255;c[i-C]=M,S-=M,S/=Math.pow(2,8)}return c[0]|=1<<8-i,c},b.concatenate=function(k,i){return!k&&!i?$.Buffer.from([]):!k||k.byteLength===0?i:!i||i.byteLength===0?k:$.Buffer.from(N(N([],k,!0),i,!0))},b.readHexString=function(k,i,c){return i===void 0&&(i=0),c===void 0&&(c=k.byteLength),Array.from(k.slice(i,c)).map(function(S){return Number(S).toString(16)}).reduce(function(S,C){return"".concat(S).concat(C.padStart(2,"0"))},"")},b.readUtf8=function(k){try{return $.Buffer.from(k).toString("utf8")}catch{return null}},b.readUnsigned=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 1:return i.getUint8(0);case 2:return i.getUint16(0);case 4:return i.getUint32(0)}return k.byteLength<=6?k.reduce(function(c,S){return c*256+S},0):b.readHexString(k,0,k.byteLength)},b.readSigned=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 1:return i.getInt8(0);case 2:return i.getInt16(0);case 4:return i.getInt32(0);default:return NaN}},b.readFloat=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 4:return i.getFloat32(0);case 8:return i.getFloat64(0);default:return NaN}},b.readDate=function(k){var i=new DataView(k.buffer,k.byteOffset,k.byteLength);switch(k.byteLength){case 1:return new Date(i.getUint8(0));case 2:return new Date(i.getUint16(0));case 4:return new Date(i.getUint32(0));case 8:return new Date(Number.parseInt(b.readHexString(k),16));default:return new Date(0)}},b.readDataFromTag=function(k,i){var c=k.type,S=k.name,C=k.track,M=k.discardable||!1,Z=k.keyframe||!1,J=null,z;switch(c){case"u":z=b.readUnsigned(i);break;case"f":z=b.readFloat(i);break;case"i":z=b.readSigned(i);break;case"s":z=String.fromCharCode.apply(String,i);break;case"8":z=b.readUtf8(i);break;case"d":z=b.readDate(i);break}if(S==="SimpleBlock"||S==="Block"){var Y=0,re=b.readVint(i,Y),oe=re.length,ie=re.value;Y+=oe,C=ie,z=b.readSigned(i.subarray(Y,Y+2)),Y+=2,S==="SimpleBlock"&&(Z=!!(i[oe+2]&128),M=!!(i[oe+2]&1)),Y+=1,J=i.subarray(Y)}return O(O({},k),{data:i,discardable:M,keyframe:Z,payload:J,track:C,value:z})},b}();return toolsEbml.default=D,toolsEbml}var vint,hasRequiredVint;function requireVint(){return hasRequiredVint||(hasRequiredVint=1,vint=function(O,N,$){N=N||0;for(var D=1;D<=8&&!(O[N]>=Math.pow(2,8-D));D++);if(D>8)throw new Error("Unrepresentable length: "+D+" "+O.toString("hex",N,N+D));if(N+D>O.length)return null;var b,k=O[N]&(1<<8-D)-1;for(b=1;b<D;b++){if(b===7&&k>=Math.pow(2,45)&&O[N+7]>0)return{length:D,value:-1};k*=Math.pow(2,8),k+=O[N+b]}return $&&(k-=Math.pow(2,D*7-1)-1),{length:D,value:k}}),vint}var bufferReader,hasRequiredBufferReader;function requireBufferReader(){if(hasRequiredBufferReader)return bufferReader;hasRequiredBufferReader=1;var O=requireVint();function N($){this.buffer=$,this.offset=0}return N.prototype.nextInt16BE=function(){var $=this.buffer.readInt16BE(this.offset);return this.offset+=2,$},N.prototype.nextUInt8=function(){var $=this.buffer.readUInt8(this.offset);return this.offset+=1,$},N.prototype.nextUIntV=function(){var $=O(this.buffer,this.offset);return this.offset+=$.length,$.value},N.prototype.nextIntV=function(){var $=O(this.buffer,this.offset,!0);return this.offset+=$.length,$.value},N.prototype.nextBuffer=function($){var D=$?this.buffer.slice(this.offset,this.offset+$):this.buffer.slice(this.offset);return this.offset+=$||this.length,D},Object.defineProperty(N.prototype,"length",{get:function(){return this.buffer.length-this.offset}}),bufferReader=N,bufferReader}var ebmlBlock,hasRequiredEbmlBlock;function requireEbmlBlock(){if(hasRequiredEbmlBlock)return ebmlBlock;hasRequiredEbmlBlock=1;var O=requireBufferReader(),N=1,$=3,D=2;ebmlBlock=function(k){var i={},c=new O(k);i.trackNumber=c.nextUIntV(),i.timecode=c.nextInt16BE();var S=c.nextUInt8();i.invisible=!!(S&8),i.keyframe=!!(S&128),i.discardable=!!(S&1);var C=(S&6)>>1;return i.frames=b(c,C),i};function b(k,i){if(!i)return[k.nextBuffer()];var c,S,C=[],M=k.nextUInt8()+1;if(i===D){if(k.length%M!==0)throw new Error("Fixed-Size Lacing Error");for(S=k.length/M,c=0;c<M;c++)C.push(k.nextBuffer(S));return C}var Z=[];if(i===N)for(c=0;c<M-1;c++){var J;S=0;do J=k.nextUInt8(),S+=J;while(J===255);Z.push(S)}else if(i===$)for(S=k.nextUIntV(),Z.push(S),c=1;c<M-1;c++)S+=k.nextIntV(),Z.push(S);for(c=0;c<M-1;c++)C.push(k.nextBuffer(Z[c]));return C.push(k.nextBuffer()),C}return ebmlBlock}var hasRequiredTools;function requireTools(){return hasRequiredTools||(hasRequiredTools=1,function(O){Object.defineProperty(O,"__esModule",{value:!0}),O.convertEBMLDateToJSDate=O.createFloatBuffer=O.createIntBuffer=O.createUIntBuffer=O.encodeValueToBuffer=O.concat=O.putRefinedMetaData=O.extractElement=O.removeElement=O.makeMetadataSeekable=O.createRIFFChunk=O.VP8BitStreamToRiffWebPBuffer=O.WebPBlockFilter=O.encodeTag=O.readBlock=O.ebmlBlock=O.writeVint=O.readVint=O.Buffer=void 0;var N=requireInt64Buffer(),$=requireEBMLEncoder(),D=requireBuffer(),b=requireToolsEbml(),k=requireEbmlBlock();O.Buffer=D.Buffer,O.readVint=b.default.readVint,O.writeVint=b.default.writeVint,O.ebmlBlock=k;function i(ee){return(0,O.ebmlBlock)(new O.Buffer(ee))}O.readBlock=i;function c(ee,le,ve){return ve===void 0&&(ve=!1),Q([ee,ve?new O.Buffer("01ffffffffffffff","hex"):(0,O.writeVint)(le.length),le])}O.encodeTag=c;function S(ee){return ee.reduce(function(le,ve){if(ve.type!=="b"||ve.name!=="SimpleBlock")return le;var be=(0,O.ebmlBlock)(ve.data),we=be.frames.some(function($e){var Ne=$e.slice(3,6).toString("hex");return Ne==="9d012a"});return we?le.concat(ve):le},[])}O.WebPBlockFilter=S;function C(ee){var le=M("VP8 ",ee),ve=Q([new O.Buffer("WEBP","ascii"),le]);return M("RIFF",ve)}O.VP8BitStreamToRiffWebPBuffer=C;function M(ee,le){var ve=new O.Buffer(4);return ve.writeUInt32LE(le.byteLength,0),Q([new O.Buffer(ee.substr(0,4),"ascii"),ve,le,new O.Buffer(le.byteLength%2===0?0:1)])}O.createRIFFChunk=M;function Z(ee,le,ve){var be=z("EBML",ee),we=re(be),$e=we+12,Ne=ee[ee.length-1].dataEnd-$e,Le=z("Info",ee);J("Duration",Le),Le.splice(1,0,{name:"Duration",type:"f",data:fe(le,8)});for(var Fe=re(Le),We=z("Tracks",ee),ft=re(We),Re=47,xe=[],it=5+ve.length*15,Me=[],Ke=-1,rt=10,Ye=function(Ie){var De=Re,je=De+Fe,Je=je+ft,Ze=Je+it,ot=Ze-Ne;if(xe=[],xe.push({name:"SeekHead",type:"m",isEnd:!1}),xe.push({name:"Seek",type:"m",isEnd:!1}),xe.push({name:"SeekID",type:"b",data:new O.Buffer([21,73,169,102])}),xe.push({name:"SeekPosition",type:"u",data:he(De)}),xe.push({name:"Seek",type:"m",isEnd:!0}),xe.push({name:"Seek",type:"m",isEnd:!1}),xe.push({name:"SeekID",type:"b",data:new O.Buffer([22,84,174,107])}),xe.push({name:"SeekPosition",type:"u",data:he(je)}),xe.push({name:"Seek",type:"m",isEnd:!0}),xe.push({name:"Seek",type:"m",isEnd:!1}),xe.push({name:"SeekID",type:"b",data:new O.Buffer([28,83,187,107])}),xe.push({name:"SeekPosition",type:"u",data:he(Je)}),xe.push({name:"Seek",type:"m",isEnd:!0}),xe.push({name:"SeekHead",type:"m",isEnd:!0}),Re=re(xe),Me=[],Me.push({name:"Cues",type:"m",isEnd:!1}),ve.forEach(function(mt){var Xt=mt.CueTrack,At=mt.CueClusterPosition,Bt=mt.CueTime;Me.push({name:"CuePoint",type:"m",isEnd:!1}),Me.push({name:"CueTime",type:"u",data:he(Bt)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Me.push({name:"CueTrack",type:"u",data:he(Xt)}),At-=$e,At+=ot,Me.push({name:"CueClusterPosition",type:"u",data:he(At)}),Me.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Me.push({name:"CuePoint",type:"m",isEnd:!0})}),Me.push({name:"Cues",type:"m",isEnd:!0}),it=re(Me),Ke!==ot){if(Ke=ot,Ie===rt-1)throw new Error("Failed to converge to a stable metadata size")}else return"break"},He=0;He<rt;He++){var ge=Ye(He);if(ge==="break")break}var _e=[].concat.apply([],[be,{name:"Segment",type:"m",isEnd:!1,unknownSize:!0},xe,Le,We,Me]),Se=new $.default().encode(_e);return Se}O.makeMetadataSeekable=Z;function J(ee,le){for(var ve=-1,be=0;be<le.length;be++){var we=le[be];if(we.name===ee)if(we.type==="m")if(!we.isEnd)ve=be;else{if(ve==-1)throw new Error("Detected ".concat(ee," closing element before finding the start"));le.splice(ve,be-ve+1);return}else{le.splice(be,1);return}}}O.removeElement=J;function z(ee,le){for(var ve=[],be=-1,we=0;we<le.length;we++){var $e=le[we];if($e.name===ee)if($e.type==="m")if(!$e.isEnd)be=we;else{if(be==-1)throw new Error("Detected ".concat(ee," closing element before finding the start"));ve=le.slice(be,we+1);break}else{ve.push(le[we]);break}}return ve}O.extractElement=z;function Y(ee,le){Array.isArray(le.cueInfos)&&!Array.isArray(le.cues)&&(console.warn("putRefinedMetaData: info.cueInfos property is deprecated. please use info.cues"),le.cues=le.cueInfos);for(var ve=[],be=[],we=0;we<ee.length;we++){var $e=ee[we];if($e.type==="m"&&$e.name==="Segment"){if(ve=ee.slice(0,we),be=ee.slice(we),$e.unknownSize){be.shift();break}throw new Error("this metadata is not streaming webm file")}}if(!(be[be.length-1].dataEnd>0))throw new Error("metadata dataEnd has wrong number");var Ne=be[be.length-1].dataEnd,Le=ve[ve.length-1].dataEnd,Fe=new $.default().encode(ve).byteLength,We=Fe-Le,ft=Ne-be[0].tagStart;be[0].tagStart-Le,be[0].tagStart;var Re=new O.Buffer([24,83,128,103]),xe=new O.Buffer("01ffffffffffffff","hex"),it=Re.byteLength+xe.byteLength,Me=ft,Ke;for(Ke=1;Ke<20;Ke++){var rt=Le+it+Me,Ye=rt-Ne,He=We+Ye,ge=oe(be,He,le),_e=new $.default().encode(ge).byteLength;if(_e===Me)return new $.default().encode([].concat(ve,[{type:"m",name:"Segment",isEnd:!1,unknownSize:!0}],ge));Me=_e}throw new Error("unable to refine metadata, stable size could not be found in "+Ke+" iterations!")}O.putRefinedMetaData=Y;function re(ee){var le=new $.default;return ee.reduce(function(ve,be){return ve.concat(le.encode([be]))},[]).reduce(function(ve,be){return ve+be.byteLength},0)}function oe(ee,le,ve){var be=ve.duration,we=ve.clusterPtrs,$e=ve.cues,Ne=ee.slice(0);if(typeof be=="number"){var Le=!1;Ne.forEach(function(We){We.type==="f"&&We.name==="Duration"&&(Le=!0,We.data=fe(be,8))}),Le||ye(Ne,"Info",[{name:"Duration",type:"f",data:fe(be,8)}])}Array.isArray($e)&&ye(Ne,"Cues",de($e,le));var Fe=[];return Array.isArray(we)&&(console.warn("append cluster pointers to seekhead is deprecated. please use cues"),Fe=ie(we,le)),ye(Ne,"SeekHead",Fe,!0),Ne}function ie(ee,le){var ve=[];return ee.forEach(function(be){ve.push({name:"Seek",type:"m",isEnd:!1}),ve.push({name:"SeekID",type:"b",data:new O.Buffer([31,67,182,117])}),ve.push({name:"SeekPosition",type:"u",data:he(be+le)}),ve.push({name:"Seek",type:"m",isEnd:!0})}),ve}function de(ee,le){var ve=[];return ee.forEach(function(be){var we=be.CueTrack,$e=be.CueClusterPosition,Ne=be.CueTime;ve.push({name:"CuePoint",type:"m",isEnd:!1}),ve.push({name:"CueTime",type:"u",data:he(Ne)}),ve.push({name:"CueTrackPositions",type:"m",isEnd:!1}),ve.push({name:"CueTrack",type:"u",data:he(we)}),ve.push({name:"CueClusterPosition",type:"u",data:he($e+le)}),ve.push({name:"CueTrackPositions",type:"m",isEnd:!0}),ve.push({name:"CuePoint",type:"m",isEnd:!0})}),ve}function ye(ee,le,ve,be){be===void 0&&(be=!1);for(var we=-1,$e=0;$e<ee.length;$e++){var Ne=ee[$e];if(Ne.type==="m"&&Ne.name===le&&Ne.isEnd===!1){we=$e;break}}we>=0?Array.prototype.splice.apply(ee,[we+1,0].concat(ve)):be?[].concat([{name:le,type:"m",isEnd:!1}],ve,[{name:le,type:"m",isEnd:!0}]).reverse().forEach(function(Le){ee.unshift(Le)}):(ee.push({name:le,type:"m",isEnd:!1}),ve.forEach(function(Le){ee.push(Le)}),ee.push({name:le,type:"m",isEnd:!0}))}function Q(ee){return O.Buffer.concat(ee)}O.concat=Q;function ae(ee){var le=new O.Buffer(0);if(ee.type==="m")return ee;switch(ee.type){case"u":le=he(ee.value);break;case"i":le=ce(ee.value);break;case"f":le=fe(ee.value);break;case"s":le=new O.Buffer(ee.value,"ascii");break;case"8":le=new O.Buffer(ee.value,"utf8");break;case"b":le=ee.value;break;case"d":le=new N.Int64BE(ee.value.getTime().toString()).toBuffer();break}return Object.assign({},ee,{data:le})}O.encodeValueToBuffer=ae;function he(ee){for(var le=1;ee>=Math.pow(2,8*le);le++);if(le>=7)return console.warn("7bit or more bigger uint not supported."),new N.Uint64BE(ee).toBuffer();var ve=new O.Buffer(le);return ve.writeUIntBE(ee,0,le),ve}O.createUIntBuffer=he;function ce(ee){for(var le=1;ee>=Math.pow(2,8*le);le++);if(le>=7)return console.warn("7bit or more bigger uint not supported."),new N.Int64BE(ee).toBuffer();var ve=new O.Buffer(le);return ve.writeIntBE(ee,0,le),ve}O.createIntBuffer=ce;function fe(ee,le){if(le===void 0&&(le=8),le===8){var ve=new O.Buffer(8);return ve.writeDoubleBE(ee,0),ve}else if(le===4){var ve=new O.Buffer(4);return ve.writeFloatBE(ee,0),ve}else throw new Error("float type bits must 4bytes or 8bytes")}O.createFloatBuffer=fe;function me(ee){return ee instanceof Date?ee:new Date(new Date("2001-01-01T00:00:00.000Z").getTime()+Number(ee)/1e3/1e3)}O.convertEBMLDateToJSDate=me}(tools)),tools}var hasRequiredEBMLDecoder;function requireEBMLDecoder(){if(hasRequiredEBMLDecoder)return EBMLDecoder;hasRequiredEBMLDecoder=1,Object.defineProperty(EBMLDecoder,"__esModule",{value:!0});var O=requireInt64Buffer(),N=requireTools(),$=requireTools(),D=requireEbmlID(),b;(function(i){i[i.STATE_TAG=1]="STATE_TAG",i[i.STATE_SIZE=2]="STATE_SIZE",i[i.STATE_CONTENT=3]="STATE_CONTENT"})(b||(b={}));var k=function(){function i(){this._buffer=new N.Buffer(0),this._tag_stack=[],this._state=b.STATE_TAG,this._cursor=0,this._total=0,this._schema=D.byEbmlID,this._result=[]}return i.prototype.decode=function(c){this.readChunk(c);var S=this._result;return this._result=[],S},i.prototype.readChunk=function(c){for(this._buffer=$.concat([this._buffer,new N.Buffer(c)]);this._cursor<this._buffer.length&&!(this._state===b.STATE_TAG&&!this.readTag()||this._state===b.STATE_SIZE&&!this.readSize()||this._state===b.STATE_CONTENT&&!this.readContent()););},i.prototype.getSchemaInfo=function(c){return this._schema[c]||{name:"unknown",level:-1,type:"unknown",description:"unknown"}},i.prototype.readTag=function(){if(this._cursor>=this._buffer.length)return!1;var c=(0,N.readVint)(this._buffer,this._cursor);if(c==null)return!1;var S=this._buffer.slice(this._cursor,this._cursor+c.length),C=S.reduce(function(J,z,Y,re){return J+z*Math.pow(16,2*(re.length-1-Y))},0),M=this.getSchemaInfo(C),Z={EBML_ID:C.toString(16),schema:M,type:M.type,name:M.name,level:M.level,tagStart:this._total,tagEnd:this._total+c.length,sizeStart:this._total+c.length,sizeEnd:null,dataStart:null,dataEnd:null,dataSize:null,data:null};return this._tag_stack.push(Z),this._cursor+=c.length,this._total+=c.length,this._state=b.STATE_SIZE,!0},i.prototype.readSize=function(){if(this._cursor>=this._buffer.length)return!1;var c=(0,N.readVint)(this._buffer,this._cursor);if(c==null)return!1;var S=this._tag_stack[this._tag_stack.length-1];return S.sizeEnd=S.sizeStart+c.length,S.dataStart=S.sizeEnd,S.dataSize=c.value,c.value===-1?(S.dataEnd=-1,S.type==="m"&&(S.unknownSize=!0)):S.dataEnd=S.sizeEnd+c.value,this._cursor+=c.length,this._total+=c.length,this._state=b.STATE_CONTENT,!0},i.prototype.readContent=function(){var c=this._tag_stack[this._tag_stack.length-1];if(c.type==="m"){if(c.isEnd=!1,this._result.push(c),this._state=b.STATE_TAG,c.dataSize===0){var S=Object.assign({},c,{isEnd:!0});this._result.push(S),this._tag_stack.pop()}return!0}if(this._buffer.length<this._cursor+c.dataSize)return!1;var C=this._buffer.slice(this._cursor,this._cursor+c.dataSize);switch(this._buffer=this._buffer.slice(this._cursor+c.dataSize),c.data=C,c.type){case"u":c.value=C.readUIntBE(0,C.length);break;case"i":c.value=C.readIntBE(0,C.length);break;case"f":c.value=c.dataSize===4?C.readFloatBE(0):c.dataSize===8?C.readDoubleBE(0):(console.warn("cannot read ".concat(c.dataSize," octets float. failback to 0")),0);break;case"s":c.value=C.toString("ascii");break;case"8":c.value=C.toString("utf8");break;case"b":c.value=C;break;case"d":c.value=(0,N.convertEBMLDateToJSDate)(new O.Int64BE(C).toNumber());break}if(c.value===null)throw new Error("unknown tag type:"+c.type);for(this._result.push(c),this._total+=c.dataSize,this._state=b.STATE_TAG,this._cursor=0,this._tag_stack.pop();this._tag_stack.length>0;){var M=this._tag_stack[this._tag_stack.length-1];if(M.dataEnd<0)return this._tag_stack.pop(),!0;if(this._total<M.dataEnd)break;if(M.type!=="m")throw new Error("parent element is not master element");var S=Object.assign({},M,{isEnd:!0});this._result.push(S),this._tag_stack.pop()}return!0},i}();return EBMLDecoder.default=k,EBMLDecoder}var EBMLReader={},events={exports:{}},hasRequiredEvents;function requireEvents(){if(hasRequiredEvents)return events.exports;hasRequiredEvents=1;var O=typeof Reflect=="object"?Reflect:null,N=O&&typeof O.apply=="function"?O.apply:function(ae,he,ce){return Function.prototype.apply.call(ae,he,ce)},$;O&&typeof O.ownKeys=="function"?$=O.ownKeys:Object.getOwnPropertySymbols?$=function(ae){return Object.getOwnPropertyNames(ae).concat(Object.getOwnPropertySymbols(ae))}:$=function(ae){return Object.getOwnPropertyNames(ae)};function D(Q){console&&console.warn&&console.warn(Q)}var b=Number.isNaN||function(ae){return ae!==ae};function k(){k.init.call(this)}events.exports=k,events.exports.once=ie,k.EventEmitter=k,k.prototype._events=void 0,k.prototype._eventsCount=0,k.prototype._maxListeners=void 0;var i=10;function c(Q){if(typeof Q!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof Q)}Object.defineProperty(k,"defaultMaxListeners",{enumerable:!0,get:function(){return i},set:function(Q){if(typeof Q!="number"||Q<0||b(Q))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+Q+".");i=Q}}),k.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},k.prototype.setMaxListeners=function(ae){if(typeof ae!="number"||ae<0||b(ae))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+ae+".");return this._maxListeners=ae,this};function S(Q){return Q._maxListeners===void 0?k.defaultMaxListeners:Q._maxListeners}k.prototype.getMaxListeners=function(){return S(this)},k.prototype.emit=function(ae){for(var he=[],ce=1;ce<arguments.length;ce++)he.push(arguments[ce]);var fe=ae==="error",me=this._events;if(me!==void 0)fe=fe&&me.error===void 0;else if(!fe)return!1;if(fe){var ee;if(he.length>0&&(ee=he[0]),ee instanceof Error)throw ee;var le=new Error("Unhandled error."+(ee?" ("+ee.message+")":""));throw le.context=ee,le}var ve=me[ae];if(ve===void 0)return!1;if(typeof ve=="function")N(ve,this,he);else for(var be=ve.length,we=Y(ve,be),ce=0;ce<be;++ce)N(we[ce],this,he);return!0};function C(Q,ae,he,ce){var fe,me,ee;if(c(he),me=Q._events,me===void 0?(me=Q._events=Object.create(null),Q._eventsCount=0):(me.newListener!==void 0&&(Q.emit("newListener",ae,he.listener?he.listener:he),me=Q._events),ee=me[ae]),ee===void 0)ee=me[ae]=he,++Q._eventsCount;else if(typeof ee=="function"?ee=me[ae]=ce?[he,ee]:[ee,he]:ce?ee.unshift(he):ee.push(he),fe=S(Q),fe>0&&ee.length>fe&&!ee.warned){ee.warned=!0;var le=new Error("Possible EventEmitter memory leak detected. "+ee.length+" "+String(ae)+" listeners added. Use emitter.setMaxListeners() to increase limit");le.name="MaxListenersExceededWarning",le.emitter=Q,le.type=ae,le.count=ee.length,D(le)}return Q}k.prototype.addListener=function(ae,he){return C(this,ae,he,!1)},k.prototype.on=k.prototype.addListener,k.prototype.prependListener=function(ae,he){return C(this,ae,he,!0)};function M(){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 Z(Q,ae,he){var ce={fired:!1,wrapFn:void 0,target:Q,type:ae,listener:he},fe=M.bind(ce);return fe.listener=he,ce.wrapFn=fe,fe}k.prototype.once=function(ae,he){return c(he),this.on(ae,Z(this,ae,he)),this},k.prototype.prependOnceListener=function(ae,he){return c(he),this.prependListener(ae,Z(this,ae,he)),this},k.prototype.removeListener=function(ae,he){var ce,fe,me,ee,le;if(c(he),fe=this._events,fe===void 0)return this;if(ce=fe[ae],ce===void 0)return this;if(ce===he||ce.listener===he)--this._eventsCount===0?this._events=Object.create(null):(delete fe[ae],fe.removeListener&&this.emit("removeListener",ae,ce.listener||he));else if(typeof ce!="function"){for(me=-1,ee=ce.length-1;ee>=0;ee--)if(ce[ee]===he||ce[ee].listener===he){le=ce[ee].listener,me=ee;break}if(me<0)return this;me===0?ce.shift():re(ce,me),ce.length===1&&(fe[ae]=ce[0]),fe.removeListener!==void 0&&this.emit("removeListener",ae,le||he)}return this},k.prototype.off=k.prototype.removeListener,k.prototype.removeAllListeners=function(ae){var he,ce,fe;if(ce=this._events,ce===void 0)return this;if(ce.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):ce[ae]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete ce[ae]),this;if(arguments.length===0){var me=Object.keys(ce),ee;for(fe=0;fe<me.length;++fe)ee=me[fe],ee!=="removeListener"&&this.removeAllListeners(ee);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(he=ce[ae],typeof he=="function")this.removeListener(ae,he);else if(he!==void 0)for(fe=he.length-1;fe>=0;fe--)this.removeListener(ae,he[fe]);return this};function J(Q,ae,he){var ce=Q._events;if(ce===void 0)return[];var fe=ce[ae];return fe===void 0?[]:typeof fe=="function"?he?[fe.listener||fe]:[fe]:he?oe(fe):Y(fe,fe.length)}k.prototype.listeners=function(ae){return J(this,ae,!0)},k.prototype.rawListeners=function(ae){return J(this,ae,!1)},k.listenerCount=function(Q,ae){return typeof Q.listenerCount=="function"?Q.listenerCount(ae):z.call(Q,ae)},k.prototype.listenerCount=z;function z(Q){var ae=this._events;if(ae!==void 0){var he=ae[Q];if(typeof he=="function")return 1;if(he!==void 0)return he.length}return 0}k.prototype.eventNames=function(){return this._eventsCount>0?$(this._events):[]};function Y(Q,ae){for(var he=new Array(ae),ce=0;ce<ae;++ce)he[ce]=Q[ce];return he}function re(Q,ae){for(;ae+1<Q.length;ae++)Q[ae]=Q[ae+1];Q.pop()}function oe(Q){for(var ae=new Array(Q.length),he=0;he<ae.length;++he)ae[he]=Q[he].listener||Q[he];return ae}function ie(Q,ae){return new Promise(function(he,ce){function fe(ee){Q.removeListener(ae,me),ce(ee)}function me(){typeof Q.removeListener=="function"&&Q.removeListener("error",fe),he([].slice.call(arguments))}ye(Q,ae,me,{once:!0}),ae!=="error"&&de(Q,fe,{once:!0})})}function de(Q,ae,he){typeof Q.on=="function"&&ye(Q,"error",ae,he)}function ye(Q,ae,he,ce){if(typeof Q.on=="function")ce.once?Q.once(ae,he):Q.on(ae,he);else if(typeof Q.addEventListener=="function")Q.addEventListener(ae,function fe(me){ce.once&&Q.removeEventListener(ae,fe),he(me)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof Q)}return events.exports}var hasRequiredEBMLReader;function requireEBMLReader(){if(hasRequiredEBMLReader)return EBMLReader;hasRequiredEBMLReader=1;var O=EBMLReader&&EBMLReader.__extends||function(){var b=function(k,i){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,S){c.__proto__=S}||function(c,S){for(var C in S)Object.prototype.hasOwnProperty.call(S,C)&&(c[C]=S[C])},b(k,i)};return function(k,i){if(typeof i!="function"&&i!==null)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");b(k,i);function c(){this.constructor=k}k.prototype=i===null?Object.create(i):(c.prototype=i.prototype,new c)}}();Object.defineProperty(EBMLReader,"__esModule",{value:!0});var N=requireEvents(),$=requireTools(),D=function(b){O(k,b);function k(){var i=b.call(this)||this;return i.logGroup="",i.hasLoggingStarted=!1,i.metadataloaded=!1,i.chunks=[],i.stack=[],i.segmentOffset=0,i.last2SimpleBlockVideoTrackTimecode=[0,0],i.last2SimpleBlockAudioTrackTimecode=[0,0],i.lastClusterTimecode=0,i.lastClusterPosition=0,i.timecodeScale=1e6,i.metadataSize=0,i.metadatas=[],i.cues=[],i.firstVideoBlockRead=!1,i.firstAudioBlockRead=!1,i.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null},i.trackTypes=[],i.trackDefaultDuration=[],i.trackCodecDelay=[],i.trackInfo={type:"nothing"},i.ended=!1,i.logging=!1,i.use_duration_every_simpleblock=!1,i.use_webp=!1,i.use_segment_info=!0,i.drop_default_duration=!0,i}return k.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()},k.prototype.emit_segment_info=function(){var i=this.chunks;if(this.chunks=[],this.metadataloaded){if(!this.use_segment_info)return;var C=this.lastClusterTimecode,M=this.duration,Z=this.timecodeScale;this.emit("cluster",{timecode:C,data:i}),this.emit("duration",{timecodeScale:Z,duration:M})}else{this.metadataloaded=!0,this.metadatas=i;var c=this.trackTypes.indexOf(1),S=this.trackTypes.indexOf(2);if(this.trackInfo=c>=0&&S>=0?{type:"both",trackNumber:c}:c>=0?{type:"video",trackNumber:c}:S>=0?{type:"audio",trackNumber:S}:{type:"nothing"},!this.use_segment_info)return;this.emit("metadata",{data:i,metadataSize:this.metadataSize})}},k.prototype.read=function(i){var c=this,S=!1;if(!this.ended){if(i.type==="m")if(i.isEnd)this.stack.pop();else{var C=this.stack[this.stack.length-1];if(C!=null&&C.level>=i.level){this.stack.pop(),this.logging&&console.groupEnd(),C.dataEnd=i.dataEnd,C.dataSize=i.dataEnd-C.dataStart,C.unknownSize=!1;var M=Object.assign({},C,{name:C.name,type:C.type,isEnd:!0});this.chunks.push(M)}this.stack.push(i)}if(i.type==="m"&&i.name=="Segment")this.segmentOffset!=0&&console.warn("Multiple segments detected!"),this.segmentOffset=i.dataStart,this.emit("segment_offset",this.segmentOffset);else if(i.type==="b"&&i.name==="SimpleBlock"){var Z=$.ebmlBlock(i.data),J=Z.timecode,z=Z.trackNumber,Y=Z.frames;if(this.trackTypes[z]===1){if(!this.firstVideoBlockRead&&(this.firstVideoBlockRead=!0,this.trackInfo.type==="both"||this.trackInfo.type==="video")){var re=this.lastClusterTimecode+J;this.cues.push({CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re}),this.emit("cue_info",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re})}this.last2SimpleBlockVideoTrackTimecode=[this.last2SimpleBlockVideoTrackTimecode[1],J]}else if(this.trackTypes[z]===2){if(!this.firstAudioBlockRead&&(this.firstAudioBlockRead=!0,this.trackInfo.type==="audio")){var re=this.lastClusterTimecode+J;this.cues.push({CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re}),this.emit("cue_info",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:z,CueClusterPosition:this.lastClusterPosition,CueTime:re})}this.last2SimpleBlockAudioTrackTimecode=[this.last2SimpleBlockAudioTrackTimecode[1],J]}this.use_duration_every_simpleblock&&this.emit("duration",{timecodeScale:this.timecodeScale,duration:this.duration}),this.use_webp&&Y.forEach(function(oe){var ie=oe.slice(3,6).toString("hex");if(ie==="9d012a"){var de=$.VP8BitStreamToRiffWebPBuffer(oe),ye=new Blob([de],{type:"image/webp"}),Q=c.duration;c.emit("webp",{currentTime:Q,webp:ye})}})}else i.type==="m"&&i.name==="Cluster"&&i.isEnd===!1?(this.firstVideoBlockRead=!1,this.firstAudioBlockRead=!1,this.emit_segment_info(),this.emit("cluster_ptr",i.tagStart),this.lastClusterPosition=i.tagStart):i.type==="u"&&i.name==="Timecode"?this.lastClusterTimecode=i.value:i.type==="u"&&i.name==="TimecodeScale"?this.timecodeScale=i.value:i.type==="m"&&i.name==="TrackEntry"?i.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}:i.type==="u"&&i.name==="TrackType"?this.currentTrack.TrackType=i.value:i.type==="u"&&i.name==="TrackNumber"?this.currentTrack.TrackNumber=i.value:i.type==="u"&&i.name==="CodecDelay"?this.currentTrack.CodecDelay=i.value:i.type==="u"&&i.name==="DefaultDuration"?this.drop_default_duration?(console.warn("DefaultDuration detected!, remove it"),S=!0):this.currentTrack.DefaultDuration=i.value:i.name==="unknown"&&console.warn(i);!this.metadataloaded&&i.dataEnd>0&&(this.metadataSize=i.dataEnd),S||this.chunks.push(i),this.logging&&this.put(i)}},Object.defineProperty(k.prototype,"duration",{get:function(){if(this.trackInfo.type==="nothing")return console.warn("no video, no audio track"),0;var i=0,c=0,S=0,C=this.trackDefaultDuration[this.trackInfo.trackNumber];if(typeof C=="number")i=C;else if(this.trackInfo.type==="both")if(this.last2SimpleBlockAudioTrackTimecode[1]>this.last2SimpleBlockVideoTrackTimecode[1]){i=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackTypes.indexOf(2)];typeof M=="number"&&(c=M),S=this.last2SimpleBlockAudioTrackTimecode[1]}else{i=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackTypes.indexOf(1)];typeof M=="number"&&(c=M),S=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="video"){i=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackInfo.trackNumber];typeof M=="number"&&(c=M),S=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="audio"){i=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var M=this.trackCodecDelay[this.trackInfo.trackNumber];typeof M=="number"&&(c=M),S=this.last2SimpleBlockAudioTrackTimecode[1]}var Z=(this.lastClusterTimecode+S)*this.timecodeScale+i-c,J=Z/this.timecodeScale;return Math.floor(J)},enumerable:!1,configurable:!0}),k.prototype.addListener=function(i,c){return b.prototype.addListener.call(this,i,c)},k.prototype.put=function(i){this.hasLoggingStarted||(this.hasLoggingStarted=!0,this.logging&&this.logGroup&&console.groupCollapsed(this.logGroup)),i.type==="m"?i.isEnd?console.groupEnd():console.group(i.name+":"+i.tagStart):i.type==="b"?console.log(i.name,i.type):console.log(i.name,i.tagStart,i.type,i.value)},k}(N.EventEmitter);return EBMLReader.default=D,EBMLReader}var hasRequiredEbml;function requireEbml(){return hasRequiredEbml||(hasRequiredEbml=1,function(O){var N=ebml&&ebml.__createBinding||(Object.create?function(c,S,C,M){M===void 0&&(M=C),Object.defineProperty(c,M,{enumerable:!0,get:function(){return S[C]}})}:function(c,S,C,M){M===void 0&&(M=C),c[M]=S[C]}),$=ebml&&ebml.__exportStar||function(c,S){for(var C in c)C!=="default"&&!Object.prototype.hasOwnProperty.call(S,C)&&N(S,c,C)};Object.defineProperty(O,"__esModule",{value:!0}),O.tools=O.Reader=O.Encoder=O.Decoder=void 0,$(requireEBML(),O);var D=requireEBMLDecoder();O.Decoder=D.default;var b=requireEBMLEncoder();O.Encoder=b.default;var k=requireEBMLReader();O.Reader=k.default;var i=requireTools();O.tools=i}(ebml)),ebml}var hasRequiredLib;function requireLib(){if(hasRequiredLib)return lib;hasRequiredLib=1;var O=lib&&lib.__awaiter||function(b,k,i,c){function S(C){return C instanceof i?C:new i(function(M){M(C)})}return new(i||(i=Promise))(function(C,M){function Z(Y){try{z(c.next(Y))}catch(re){M(re)}}function J(Y){try{z(c.throw(Y))}catch(re){M(re)}}function z(Y){Y.done?C(Y.value):S(Y.value).then(Z,J)}z((c=c.apply(b,k||[])).next())})},N=lib&&lib.__generator||function(b,k){var i={label:0,sent:function(){if(C[0]&1)throw C[1];return C[1]},trys:[],ops:[]},c,S,C,M;return M={next:Z(0),throw:Z(1),return:Z(2)},typeof Symbol=="function"&&(M[Symbol.iterator]=function(){return this}),M;function Z(z){return function(Y){return J([z,Y])}}function J(z){if(c)throw new TypeError("Generator is already executing.");for(;i;)try{if(c=1,S&&(C=z[0]&2?S.return:z[0]?S.throw||((C=S.return)&&C.call(S),0):S.next)&&!(C=C.call(S,z[1])).done)return C;switch(S=0,C&&(z=[z[0]&2,C.value]),z[0]){case 0:case 1:C=z;break;case 4:return i.label++,{value:z[1],done:!1};case 5:i.label++,S=z[1],z=[0];continue;case 7:z=i.ops.pop(),i.trys.pop();continue;default:if(C=i.trys,!(C=C.length>0&&C[C.length-1])&&(z[0]===6||z[0]===2)){i=0;continue}if(z[0]===3&&(!C||z[1]>C[0]&&z[1]<C[3])){i.label=z[1];break}if(z[0]===6&&i.label<C[1]){i.label=C[1],C=z;break}if(C&&i.label<C[2]){i.label=C[2],i.ops.push(z);break}C[2]&&i.ops.pop(),i.trys.pop();continue}z=k.call(b,i)}catch(Y){z=[6,Y],S=0}finally{c=C=0}if(z[0]&5)throw z[1];return{value:z[0]?z[1]:void 0,done:!0}}};Object.defineProperty(lib,"__esModule",{value:!0});var $=requireEbml();function D(b){return O(this,void 0,void 0,function(){var k,i,c,S,C,M,Z,J,z,Y,re,oe;return N(this,function(ie){switch(ie.label){case 0:if(!b)throw Error("call to fixWebmDuration requires a blob");k=new $.Decoder,i=new $.Reader,c=b.stream(),S=c.getReader(),ie.label=1;case 1:return[4,S.read()];case 2:return C=ie.sent(),M=C.done,Z=C.value,M?(i.stop(),[3,3]):(J=k.decode(Z),J=J==null?void 0:J.filter(function(de){return de.type!=="unknown"}),J.forEach(function(de){i.read(de)}),Z=null,[3,1]);case 3:return z=$.tools.makeMetadataSeekable(i.metadatas,i.duration,i.cues),Y=new Blob([z],{type:b.type}),re=b.slice(i.metadataSize),oe=new Blob([Y,re],{type:b.type}),[2,oe]}})})}return lib.default=D,lib}var libExports=requireLib();const fixWebmDuration=getDefaultExportFromCjs(libExports);class StreamRecorder{constructor(){ke(this,Ve);ke(this,vt,!1);ke(this,st,!1);ke(this,qt,0);ke(this,Nt,0);ke(this,Xe,0);ke(this,tt,0);ke(this,bt,0);ne(this,"onchange",N=>{});ne(this,"onDurationChange",N=>{});ne(this,"start",async(N="")=>{N||(N=`video_Record_${E(Date.now())}`);let $=[];return navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}).then(D=>{const b=D.getTracks();for(const i of b)i.onended=()=>this.stop();Be(this,vt,!0),Be(this,st,!1),Be(this,Ve,new MediaRecorder(D)),se(this,Ve).start();const k=new Date().getTime();Be(this,qt,k),Be(this,Xe,k),se(this,kt).call(this),se(this,Pt).call(this),se(this,Ve).addEventListener("dataavailable",i=>{$.push(i.data)}),se(this,Ve).addEventListener("stop",async()=>{Be(this,vt,!1);const i=new Date().getTime();Be(this,Nt,i),Be(this,tt,se(this,tt)+(i-se(this,Xe))),se(this,kt).call(this),clearInterval(se(this,bt));const c=D.getTracks();for(const J of c)J.stop();if(se(this,Ve)===null)return;const S=new Blob($,{type:se(this,Ve).mimeType}),C=await fixWebmDuration(S),M=URL.createObjectURL(C),Z=document.createElement("a");Z.href=M,Z.download=`${N}.mp4`,Z.click(),URL.revokeObjectURL(M),$=[],Be(this,Ve,null)})})});ne(this,"pause",async()=>{var $;await new Promise(D=>setTimeout(()=>D(!0),300)),($=se(this,Ve))==null||$.pause(),Be(this,st,!0);const N=new Date().getTime();Be(this,tt,se(this,tt)+(N-se(this,Xe))),se(this,kt).call(this),clearInterval(se(this,bt))});ne(this,"resume",async()=>{var $;($=se(this,Ve))==null||$.resume(),Be(this,st,!1);const N=new Date().getTime();Be(this,Xe,N),se(this,kt).call(this),se(this,Pt).call(this)});ne(this,"stop",async()=>{var N;(N=se(this,Ve))==null||N.stop()});ne(this,"getDuration",()=>{if(se(this,Xe)===0)return 0;let N=se(this,tt);const $=new Date().getTime();if(se(this,vt)&&se(this,st)===!1){const D=$-se(this,Xe);Be(this,Xe,$),N=N+D}return N});ne(this,"getInfo",()=>({active:se(this,vt),pause:se(this,st),startTime:se(this,qt),endTime:se(this,Nt),duration:se(this,tt)}));ke(this,kt,()=>{const N=this.getInfo();this.onchange(N)});ke(this,Pt,()=>{clearInterval(se(this,bt)),Be(this,bt,window.setInterval(()=>{Be(this,tt,this.getDuration()),this.onDurationChange(se(this,tt))},500))})}}Ve=new WeakMap,vt=new WeakMap,st=new WeakMap,qt=new WeakMap,Nt=new WeakMap,Xe=new WeakMap,tt=new WeakMap,bt=new WeakMap,kt=new WeakMap,Pt=new WeakMap;var l=Object.defineProperty,y=O=>{throw TypeError(O)},q=(O,N,$)=>N in O?l(O,N,{enumerable:!0,configurable:!0,writable:!0,value:$}):O[N]=$,s=(O,N,$)=>q(O,typeof N!="symbol"?N+"":N,$),P=(O,N,$)=>N.has(O)||y("Cannot "+$),n=(O,N,$)=>(P(O,N,"read from private field"),$?$.call(O):N.get(O)),a=(O,N,$)=>N.has(O)?y("Cannot add the same private member more than once"):N instanceof WeakSet?N.add(O):N.set(O,$),d,v,o;class p{constructor(N={}){s(this,"queue",[]),s(this,"timer",0),s(this,"activeIndex",0),s(this,"activePromise"),s(this,"options",{timeout:0}),s(this,"add",($,D={})=>new Promise(async(b,k)=>{const i=D.timeout||this.options.timeout,c=D.key||n(this,d).call(this),S=D.describe||"";if(this.queue.findIndex(M=>M.key===c)!==-1)return k(`${c} is exist.`);const C={key:c,func:$,describe:S,timeout:i,resolve:b,reject:k};this.queue.unshift(C),this.activePromise||n(this,o).call(this)})),s(this,"clear",()=>{this.queue=[],this.activePromise=void 0,clearTimeout(this.timer)}),s(this,"retry",()=>{n(this,o).call(this)}),a(this,d,()=>(this.activeIndex=this.activeIndex+1,`${this.activeIndex}`)),a(this,v,$=>{const D=this.queue.findIndex(b=>b.key===$);this.queue.splice(D,1)}),a(this,o,async()=>{const $=this.queue.length;if($===0)return;const D=$-1,b=this.queue[D];this.activePromise=b;const{key:k,func:i,resolve:c,reject:S,timeout:C}=this.activePromise;C&&(this.timer=window.setTimeout(()=>{S(`pr-async-queue: ${k} is timeout.`),n(this,o).call(this)},C)),await i().then(c).catch(S).finally(()=>{clearTimeout(this.timer),this.activePromise=void 0,n(this,v).call(this,k),n(this,o).call(this)})}),this.options={timeout:0,...N}}}d=new WeakMap,v=new WeakMap,o=new WeakMap;class RoomBase{constructor(N){ne(this,"options",{appid:"",sdkToken:"",roomId:"",userId:"",earlyId:xt(),callType:0,debug:!1,reportErr:!0,logUrl:"https://logs1.quickvo.org",newPublishAutoSubscribe:!0});ne(this,"sdk_service_version","1.0.8");ne(this,"sdk_session","");ne(this,"prohibitNotify",!1);ne(this,"isEarly",!1);ne(this,"isInRoom",!1);ne(this,"asyncQueue");ne(this,"roomState","ready");ne(this,"createAt",Date.now());ne(this,"cwsIns");ne(this,"peerIns");ne(this,"transceiverMap",new Map);ne(this,"sendChannel");ne(this,"receiveChannel");ne(this,"userMap",new Map);ne(this,"p2pMap",new Map);ne(this,"setLocalStreamActiveMap",new Map);ne(this,"phoneyStreams",new Map);ne(this,"recorder",new StreamRecorder);ne(this,"networkQualityTester",new NetworkQualityTester);ne(this,"mediaDevicesErrInfo",{microphoneCamera_audio:"",microphoneCamera_video:"",screenSharing_video:"",screenSharing_audio:""});ne(this,"reportLogs",(N,$="未知错误")=>{const{appid:D,userId:b,earlyId:k="",logUrl:i,reportErr:c}=this.options;if(!c)return;const S="web",C=M=>({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})[M].toString();{const M=C(N),Z={origin:S,type:M,app_id:D,user_id:b,ins_id:k,desc:$},J=btoa(encodeURI(JSON.stringify(Z))),z=`${i}/upload/log?log_key=${J}`;{const Y=localStorage.getItem("#quickvo.logs")||JSON.stringify([]),oe=new TextEncoder().encode(Y),ie=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:Z,url:z,size:lt(ie.byteLength)}),fetch(z,{headers:{"Content-Type":"multipart/form-data"},method:"POST",body:ie})}}});ne(this,"initPhoneyStreams",(N,$=[])=>{$.length===0&&($=mediaType_keys);for(const D of $){const b=this.phoneyStreams.get(D);if(b){const k=b.getTracks();for(const i of k)i.stop()}switch(D){case"microphoneCamera_audio":this.phoneyStreams.set("microphoneCamera_audio",createMutedAudioStream(N));break;case"microphoneCamera_video":this.phoneyStreams.set("microphoneCamera_video",createFakeVideoStream());break;case"screenSharing_audio":this.phoneyStreams.set("screenSharing_audio",createMutedAudioStream(N));break;case"screenSharing_video":this.phoneyStreams.set("screenSharing_video",createFakeVideoStream());break}}});ne(this,"getPhoneyStreams",N=>this.phoneyStreams.get(N));ne(this,"getRoomInfo",()=>{const{options:N,roomState:$,createAt:D}=this;return{...N,roomState:$,createAt:D}});ne(this,"setRoomState",N=>{this.roomState=N,N==="closed"&&(this.cwsIns.state=N);const $=enum_roomState[N],D={state:N,stateStr:$};this.cwsIns.emitNotify("onRoomState",{code:200,data:D,desc:"room state is change."})});ne(this,"setOptions",async N=>{const $={...this.options,...N};this.options=$});ne(this,"stopStream",async N=>{const $=N.getTracks();for(const D of $)D.stop()});ne(this,"getMediaDevicesErrInfo",async()=>{try{const N=await navigator.mediaDevices.enumerateDevices();N.find(D=>D.kind==="audioinput")||(this.mediaDevicesErrInfo.microphoneCamera_audio="audioinput is not available."),N.find(D=>D.kind==="videoinput")||(this.mediaDevicesErrInfo.microphoneCamera_video="videoinput is not available.")}catch(N){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getMediaDevicesErrInfo is error.",N)}return this.mediaDevicesErrInfo});ne(this,"getUserMediaKey",(N,$)=>`${N}-${$}`);ne(this,"getCallAction",async N=>{let $="";const D=k=>N.findIndex(({type:c,enabled:S=!0})=>c===k&&S)===-1?"0":"1";return $=`${D(0)}${$}`,$=`${D(1)}${$}`,$=`${D(2)}${$}`,$=`${D(3)}${$}`,parseInt($,2)});ne(this,"getCallActionMap",(N=0)=>{const D=Number(N).toString(2).padStart(4,"0").split(""),[b,k,i,c]=D;return{microphoneCamera_audio:!!Number(c),microphoneCamera_video:!!Number(i),screenSharing_video:!!Number(k),screenSharing_audio:!!Number(b)}});ne(this,"getBanBehaviorMap",(N=0)=>{const D=Number(N).toString(2).padStart(4,"0").split(""),[b,k,i,c]=D;return{microphoneCamera_audio:!!Number(c),microphoneCamera_video:!!Number(i),screenSharing_video:!!Number(k),screenSharing_audio:!!Number(b)}});ne(this,"getAverageVolume",(N,$)=>{N.getByteFrequencyData($);let D=0;for(let k=0;k<$.length;k++)D+=$[k];return Math.ceil(D/$.length)});ne(this,"getTrackNamesFormTracks",(N,$=[],D="trackName")=>{const b=[];for(const k of N){const{type:i}=k;if($.length===0||$.includes(i)){const c=k[D];c&&b.push(`${c}`)}}return b});ne(this,"usersFilter",N=>dt(N,["id","isSelf","isOwner","joinTime","tracks","network","permissions","isPublished","updateStreams","callAction","callActionStr","callActionMap","banBehavior","banBehaviorStr","banBehaviorMap"]).sort((b,k)=>b.id.localeCompare(k.id,"en")));this.setOptions(N),this.cwsIns=new CallsWebSocket({...N}),this.asyncQueue=new p}}var m=Object.defineProperty,G=(O,N,$)=>N in O?m(O,N,{enumerable:!0,configurable:!0,writable:!0,value:$}):O[N]=$,e=(O,N,$)=>G(O,typeof N!="symbol"?N+"":N,$);class g{constructor(N,$){e(this,"inputStream",new MediaStream),e(this,"outputStream",new MediaStream),e(this,"inputGain",1),e(this,"enhanceGain",1),e(this,"bgsGain",1),e(this,"bgmGain",1),e(this,"outputGain",1),e(this,"mixAudioMap",new Map),e(this,"audioContext",new AudioContext),e(this,"sourceNode"),e(this,"inputGainNode"),e(this,"enhanceGainNode"),e(this,"bgsGainNode"),e(this,"bgmGainNode"),e(this,"analyserNode"),e(this,"analyserArrayData"),e(this,"outputGainNode"),e(this,"destinationNode"),e(this,"filterStream",D=>D),e(this,"stop",()=>{{const D=this.inputStream.getTracks();for(const b of D)b.stop(),this.inputStream.removeTrack(b)}}),e(this,"getStream",()=>this.filterStream(this.outputStream)),e(this,"setMute",(D=!0)=>{D?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),e(this,"setInputGain",D=>{this.inputGain=D,this.inputGainNode.gain.setValueAtTime(D,this.audioContext.currentTime)}),e(this,"setEnhanceGain",async D=>{this.enhanceGain=D+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),e(this,"setBgsGain",D=>{this.bgsGain=D,this.bgsGainNode.gain.setValueAtTime(D,this.audioContext.currentTime)}),e(this,"setBgmGain",D=>{this.bgmGain=D,this.bgmGainNode.gain.setValueAtTime(D,this.audioContext.currentTime)}),e(this,"setOutputGain",D=>{this.outputGain=D,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),e(this,"getVolume",()=>{const{analyserNode:D,analyserArrayData:b}=this;D.getByteFrequencyData(b);let k=0;for(let i=0;i<b.length;i++)k+=b[i];return Math.ceil(k/b.length)}),e(this,"mixAudio",(D,b="bgm")=>new Promise(async(k,i)=>{try{{const C=this.mixAudioMap.get(b);C&&C.stop()}const c=b==="bgs"?this.bgsGainNode:this.bgmGainNode,S=this.audioContext.createBufferSource();this.mixAudioMap.set(b,S),S.buffer=D,S.connect(c),S.onended=()=>{S.disconnect(c),this.mixAudioMap.delete(b),k(!0)},S.start(0)}catch(c){i(c)}})),e(this,"mixAudioStop",D=>{const b=this.mixAudioMap.get(D);b==null||b.stop()}),e(this,"changeMix",(D,b)=>{const k=D==="bgs"?this.bgsGainNode:this.bgmGainNode;b?k.connect(this.destinationNode):k.disconnect(this.destinationNode)}),$&&(this.audioContext=$),this.inputStream=N,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:D,inputGainNode:b,enhanceGainNode:k,bgsGainNode:i,bgmGainNode:c,analyserNode:S,outputGainNode:C,destinationNode:M}=this;D.connect(b),b.connect(k),k.connect(S),i.connect(S),c.connect(S),k.connect(M),i.connect(M),c.connect(M),S.connect(C),C.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}class RoomMedias extends RoomBase{constructor($){super($);ke(this,St,[]);ke(this,Ge,new Map);ke(this,ze,new Map);ke(this,Qe,new Map);ke(this,nt,new Map);ke(this,ct,new Map);ne(this,"localStreamsActionMap",new Map);ke(this,Ot,new Map);ne(this,"audioContext",new(window.AudioContext||window.webkitAudioContext));ne(this,"initMediaPhoneyStreams",($=[])=>this.initPhoneyStreams(this.audioContext,$));ne(this,"initLocalStreamsFilter",()=>{for(const $ of mediaType_keys){const D=async b=>b;se(this,Ot).set($,D)}});ne(this,"setLocalFilterStream",($,D)=>{se(this,Ot).set($,D)});ke(this,zt,()=>{se(this,ze).set("microphoneCamera_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0}),se(this,ze).set("microphoneCamera_video",{frameRate:{min:10,ideal:30}}),se(this,ze).set("screenSharing_video",{frameRate:{min:10,ideal:30}}),se(this,ze).set("screenSharing_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0})});ke(this,Ht,()=>{se(this,Ge).set("audioinput","default"),se(this,Ge).set("videoinput","default"),se(this,Ge).set("audiooutput","default")});ne(this,"emitNotifyUpdateUsersStreams",async $=>{this.cwsIns.emitNotify("onRoomUsersStreams",{code:200,data:$,desc:"users streams is change."})});ne(this,"initUserMediaStreamContext",async($,D,b)=>{const[k]=b.getTracks();if(!k){console.warn("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: tracks.length is 0.",{userId:$,mediaType:D,stream:b});return}this.removeUserMediaStreamContext($,D);const i=this.getUserMediaKey($,D),{kind:c}=k;switch(c){case"audio":{const S=new MediaStream;S.addTrack(k);const C=new g(S,this.audioContext);se(this,Qe).set(i,C)}break;case"video":{const S=new VideoMediaContext(k);se(this,nt).set(i,S)}break}});ne(this,"getUserMediaStreamContext",($,D)=>{const b=this.getUserMediaKey($,D);if(["microphoneCamera_audio","screenSharing_audio"].includes(D))return se(this,Qe).get(b);if(["microphoneCamera_video","screenSharing_video"].includes(D))return se(this,nt).get(b)});ne(this,"getUserAudioMediaStreamContext",($,D)=>{const b=this.getUserMediaKey($,D);return se(this,Qe).get(b)});ne(this,"removeUserMediaStreamContext",($,D)=>{const b=this.getUserMediaKey($,D);if(["microphoneCamera_audio","screenSharing_audio"].includes(D)){const k=se(this,Qe).get(b);return k==null||k.stop(),se(this,Qe).delete(b)}if(["microphoneCamera_video","screenSharing_video"].includes(D)){const k=se(this,nt).get(b);return k==null||k.stop(),se(this,nt).get(b)}});ne(this,"getUserStream",($,D)=>{const b=this.getUserMediaStreamContext($,D);return(b==null?void 0:b.getStream())||new MediaStream});ne(this,"getUserStreams",($,D=[])=>{D.length===0&&(D=mediaType_keys);const b={};for(const k of D){const i=this.getUserStream($,k);b[k]=i}return b});ne(this,"removeUserStreams",async($,D=[])=>{D.length===0&&(D=mediaType_keys);for(const b of D)this.removeUserMediaStreamContext($,b)});ne(this,"clearUserStreams",()=>{{const $=se(this,Qe).values();for(const D of $)D.stop();Be(this,Qe,new Map)}{const $=se(this,nt).values();for(const D of $)D.stop();Be(this,nt,new Map)}});ne(this,"setMediaTrackConstraints",async($,D)=>{se(this,ze).set($,D);const b=await this.getLocalStream($);if(!b)return;const k=b.getTracks();if(k.length!==0)for(const i of k){const c=i.getConstraints(),C={...se(this,ze).get($),...c,...D};await i.applyConstraints(C)}});ne(this,"stopLocalStreams",async($=[])=>{$.length===0&&($=mediaType_keys);for(const D of $){const b=se(this,ct).get(D);b&&await this.stopStream(b),se(this,ct).delete(D)}});ne(this,"addLocalStream",($,D)=>{const b=se(this,ct).get($);b&&this.stopStream(b),se(this,ct).set($,D)});ne(this,"initLocalStream",async $=>{switch($){case"microphoneCamera_audio":{const D=se(this,Ge).get("audioinput"),b=se(this,ze).get("microphoneCamera_audio"),k=await navigator.mediaDevices.getUserMedia({audio:{deviceId:D,...b},video:!1});this.addLocalStream("microphoneCamera_audio",k)}break;case"microphoneCamera_video":{const D=se(this,Ge).get("videoinput"),b=se(this,ze).get("microphoneCamera_video"),k=await navigator.mediaDevices.getUserMedia({audio:!1,video:{deviceId:D,...b}});this.addLocalStream("microphoneCamera_video",k)}break;case"microphoneCamera":{const D=se(this,Ge).get("audioinput"),b=se(this,Ge).get("videoinput"),k=se(this,ze).get("microphoneCamera_audio"),i=se(this,ze).get("microphoneCamera_video"),S=(await navigator.mediaDevices.getUserMedia({audio:{deviceId:D,...k},video:{deviceId:b,...i}})).getTracks();for(const C of S){const{kind:M}=C;if(M==="audio"){const Z=new MediaStream;Z.addTrack(C),this.addLocalStream("microphoneCamera_audio",Z)}if(M==="video"){const Z=new MediaStream;Z.addTrack(C),this.addLocalStream("microphoneCamera_video",Z)}}}break;case"screenSharing_audio":{const D=se(this,ze).get("screenSharing_audio"),k=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...D})).getTracks();for(const i of k){const{kind:c}=i;if(c==="audio"){const S=new MediaStream;S.addTrack(i),this.addLocalStream("screenSharing_audio",S)}}}break;case"screenSharing_video":{const D=se(this,ze).get($),k=(await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0,...D})).getTracks();for(const i of k){const{kind:c}=i;if(c==="video"){const S=new MediaStream;S.addTrack(i),this.addLocalStream("screenSharing_video",S)}}}break;case"screenSharing":{const D=se(this,ze).get("screenSharing_audio"),b=se(this,ze).get("screenSharing_video"),i=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...D,...b})).getTracks();for(const c of i){const{kind:S}=c;if(S==="audio"){const C=new MediaStream;C.addTrack(c),this.addLocalStream("screenSharing_audio",C)}if(S==="video"){const C=new MediaStream;C.addTrack(c),this.addLocalStream("screenSharing_video",C)}}}break}});ne(this,"getLocalStream",async $=>{const D=se(this,ct).get($),b=se(this,Ot).get($);let k=D;return D&&b&&(k=await b(D)),k});ne(this,"getLocalStreams",async($=[])=>{$.length===0&&($=mediaType_keys);const D={};for(const b of $)D[b]=await this.getLocalStream(b);return D});ke(this,Tt,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($=>{const D=$.filter(b=>!["communications"].includes(b.deviceId));Be(this,St,D.sort((b,k)=>b.label.localeCompare(k.label,"zh-Hans-CN",{sensitivity:"accent"})))}).catch(function($){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getEnumerateDevices is err",$)}),se(this,St)));ke(this,Zt,()=>{navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=async()=>{await se(this,Tt).call(this),this.cwsIns.emitNotify("onDevicechange",{code:200,data:{},desc:"device is change."})}),se(this,Tt).call(this)});ne(this,"getMediaDeviceKind",$=>se(this,Ge).get($));ne(this,"changeAudiooutput",async()=>{try{const $=se(this,Ge).get("audiooutput");await this.audioContext.setSinkId($)}catch($){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSinkId is error.",$)}});ne(this,"setDeviceKind",($,D)=>{se(this,Ge).set($,D)});ne(this,"setAudioOutputDevice",$=>this.setDeviceKind("audiooutput",$));ne(this,"getEnumerateDevices",async $=>(await se(this,Tt).call(this),se(this,St).filter(b=>b.kind===$)));ne(this,"getEnumerateAudioinputDevices",()=>this.getEnumerateDevices("audioinput"));ne(this,"getEnumerateAudioOutputDevices",()=>this.getEnumerateDevices("audiooutput"));ne(this,"getEnumerateVideoinputDevices",()=>this.getEnumerateDevices("videoinput"));se(this,Zt).call(this),se(this,Ht).call(this),se(this,zt).call(this),this.initPhoneyStreams(this.audioContext),document.addEventListener("click",()=>{var D;((D=this.audioContext)==null?void 0:D.state)==="suspended"&&this.audioContext.resume()})}}St=new WeakMap,Ge=new WeakMap,ze=new WeakMap,Qe=new WeakMap,nt=new WeakMap,ct=new WeakMap,Ot=new WeakMap,zt=new WeakMap,Ht=new WeakMap,Tt=new WeakMap,Zt=new WeakMap;const getIcecandidate=O=>new Promise((N,$)=>{const D=[],b=async i=>{i.candidate?D.push(i.candidate):(clearTimeout(k),O.removeEventListener("icecandidate",b),N(D))},k=window.setTimeout(()=>{O.removeEventListener("icecandidate",b),$(new Error("timeout"))},1e3);O.addEventListener("icecandidate",b)});class P2P{constructor(){ne(this,"peerIns",new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}));ne(this,"initOffer",()=>new Promise(async N=>{const $=async()=>{const c=await this.peerIns.createOffer();return await this.peerIns.setLocalDescription(c),c},D=getIcecandidate(this.peerIns),b=$(),[k,i]=await Promise.all([D,b]);N({offer:i,icecandidates:k})}));ne(this,"initAnswer",async(N,$)=>new Promise(async D=>{const b=async()=>{await this.peerIns.setRemoteDescription(N);for(const M of $)await this.peerIns.addIceCandidate(M);const C=await this.peerIns.createAnswer();return await this.peerIns.setLocalDescription(C),C},k=getIcecandidate(this.peerIns),i=b(),[c,S]=await Promise.all([k,i]);D({answer:S,icecandidates:c})}));ne(this,"setAnswer",async(N,$)=>new Promise(async D=>{await this.peerIns.setRemoteDescription(N);for(const b of $)await this.peerIns.addIceCandidate(b);D(!0)}));ne(this,"close",()=>{this.peerIns.close()});this.peerIns.addTransceiver("video",{direction:"sendrecv"})}}class RoomUsers extends RoomMedias{constructor($){super($);ne(this,"createP2P",async()=>{const $=new P2P,D=await $.initOffer();console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: res",D),this.p2pMap.set("aaa",$)});ne(this,"getMaxVolumeUser",()=>{const $=Array.from(this.userMap.values(),({id:b})=>b);if($.length===0)return;let D=[];for(const b of $){const k=this.getUserAudioMediaStreamContext(b,"microphoneCamera_audio");if(!k)continue;const i=k.getVolume();D.push({id:b,volume:i})}return D=D.sort((b,k)=>b.volume-k.volume>0?-1:1),D[0]});ne(this,"setVolume",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setInputGain(b)});ne(this,"setEnhanceGain",async($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setEnhanceGain(b)});ne(this,"setSpeaker",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setOutputGain(b);const i=b===0;k==null||k.setMute(i)});ne(this,"playBgs",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);return k==null?void 0:k.mixAudio(b,"bgs")});ne(this,"setBgsGain",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setBgsGain(b)});ne(this,"stopBgs",($,D)=>{const b=this.getUserAudioMediaStreamContext($,D);b==null||b.mixAudioStop("bgs")});ne(this,"playBgm",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);return k==null?void 0:k.mixAudio(b,"bgm")});ne(this,"setBgmGain",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.setBgmGain(b)});ne(this,"stopBgm",($,D)=>{const b=this.getUserAudioMediaStreamContext($,D);b==null||b.mixAudioStop("bgm")});ne(this,"changBgsMix",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.changeMix("bgs",b)});ne(this,"changBgmMix",($,D,b)=>{const k=this.getUserAudioMediaStreamContext($,D);k==null||k.changeMix("bgm",b)});ne(this,"getVolume",($,D)=>{const b=this.getUserAudioMediaStreamContext($,D);return b==null?void 0:b.getVolume()});ne(this,"clearUsers",()=>{this.userMap=new Map});ne(this,"removeUsers",async $=>{for(const D of $)this.userMap.delete(D),await this.removeUserStreams(D)});ne(this,"createUser",async $=>{const D=Date.now(),b={id:$,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:$===this.options.userId,isPublished:!1,joinTime:D,updateAt:D,network:{egress:0,ingress:0},tracks:[],channels:[],updateStreams:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1}};this.userMap.set($,b)});ne(this,"getUser",async $=>(this.userMap.has($)||await this.createUser($),this.userMap.get($)));ne(this,"getUsers",async($=[])=>{$.length===0&&($=[...this.userMap.keys()]);const D=[];for(const b of $){const k=await this.getUser(b);D.push(k)}return D});ne(this,"getAllUserTrackMids",async()=>{const $=await this.getUsers(),D=[];for(const b of $){const{tracks:k=[]}=b;for(const i of k)D.push(i.mid)}return D});ne(this,"getUserTrackByTrackName",async $=>{const D=await this.getUsers(),b=[];for(const k of D){const{tracks:i=[]}=k;for(const c of i){const{trackName:S}=c;$.includes(S)&&b.push(c)}}return b});ne(this,"getUserTrackFromMid",async $=>{const D=await this.getUsers();let b;for(const k of D){const{tracks:i=[]}=k;for(const c of i)if(c.mid===$){b=c;break}}return b});ne(this,"checkUserInRoom",$=>this.userMap.has($));ne(this,"getUsersId",async()=>[...this.userMap.keys()]);ne(this,"getSelfInfo",async()=>await this.getUser(this.options.userId));ne(this,"updateIsPublished",async($,D=!1)=>{const b=await this.getUser($);b.isPublished=D});ne(this,"setUserUpdateStreams",async($,D,b=!0)=>{const k=await this.getUser($),i={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};i[D]=b,k.updateStreams=i});ne(this,"updateUserChannels",async($,D=[],b)=>{const k=await this.getUser($);b&&(D=[...k.channels,...D]),k.channels=D});ne(this,"updateUsertracks",async($,D=[],b)=>{const k=await this.getUser($);b&&(D=[...k.tracks,...D]),D=D.filter(({mid:S=""})=>S!==""),D=pt(D,["type"]),D=D.sort((S,C)=>S.type-C.type<0?-1:1);for(const S of D)S.userId=$,S.mediaType=mediaType_keys[S.type],S.enabled===void 0&&(S.enabled=!0);k.updateStreams={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};const i=dt(k.tracks,["mediaType","enabled","mid","msid","trackName","key"]),c=dt(D,["mediaType","enabled","mid","msid","trackName","key"]);for(const S of mediaType_keys){const C=c.find(J=>J.mediaType===S),M=i.find(J=>J.mediaType===S),Z=JSON.stringify(C)!==JSON.stringify(M);k.updateStreams[S]=Z}k.tracks=D});ne(this,"updateUserCallAction",async($,D=0)=>{const b=await this.getUser($);b.callAction=D,b.callActionStr=D.toString(2).padStart(4,"0"),b.callActionMap=this.getCallActionMap(D)});ne(this,"updateUserBehaviors",async($,D=0)=>{const b=await this.getUser($);b.banBehavior=D,b.banBehaviorStr=D.toString(2).padStart(4,"0"),b.banBehaviorMap=this.getBanBehaviorMap(D)});ne(this,"updateUserNetwork",async($,D={egress:5,ingress:5})=>{const b=await this.getUser($);b.network=D});ne(this,"updateUserPermissions",async($,D)=>{if(D){const b=await this.getUser($);b.permissions=D}});ne(this,"updateUserBase",async $=>{const D=await this.getUser($);D.isSelf=$===this.options.userId,D.updateAt=Date.now()});ne(this,"updateUsers",async $=>{for(const D of $){const{id:b,tracks:k,callAction:i,permissions:c,isPublished:S}=D;await this.updateUserBase(b),await this.updateIsPublished(b,S),await this.updateUserPermissions(b,c),await this.updateUsertracks(b,k,!0),await this.updateUserCallAction(b,i),await this.updateUserNetwork(b)}});ne(this,"emitNotifyUpdateUser",async $=>{const D=await this.getUsers([$]),[b]=this.usersFilter(D);this.cwsIns.emitNotify("onRoomUser",{code:200,data:b,desc:"user info is change."})});ne(this,"emitNotifyUpdateUsers",async()=>{const $=await this.getUsers(),D=this.usersFilter($);this.cwsIns.emitNotify("onRoomUsers",{code:200,data:D,desc:"all users info is change."})})}}class RoomPeer extends RoomUsers{constructor($){super($);ne(this,"getPeerStatsTimer",0);ne(this,"reports",[]);ne(this,"candidates",[]);ke(this,Ut,[]);ke(this,It,0);ne(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});ne(this,"initPeer",()=>{var $;clearTimeout(se(this,It)),this.transceiverMap=new Map,($=this.peerIns)==null||$.close(),this.peerIns=void 0,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),se(this,Jt).call(this),se(this,Gt).call(this),this.initMediaPhoneyStreams()});ne(this,"initSendChannel",($="",D)=>{const b=this.peerIns.createDataChannel($,{negotiated:!0,id:D});b.addEventListener("open",async k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->sendChannel: onopen",k),setInterval(()=>{const i=new Date().getTime();b.send(`Hi you! on: ${E(i)}`)},1e3)}),b.addEventListener("close",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->sendChannel: close",k)}),b.addEventListener("message",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->sendChannel: onmessage",k)}),this.sendChannel=b,this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initSendChannel",{label:$,id:D,channel:b})});ne(this,"initReceiveChannel",($="",D)=>{const b=this.peerIns.createDataChannel($,{negotiated:!0,id:D});b.addEventListener("open",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->receiveChannel: onopen",k)}),b.addEventListener("close",k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->receiveChannel: close",k)}),b.addEventListener("message",async k=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->receiveChannel: onmessage",k)}),this.receiveChannel=b,this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initReceiveChannel",{label:$,id:D,channel:b}),this.receiveChannel.send("hello")});ne(this,"replaceSenderStream",async($=[],D)=>{const{userId:b}=this.options;$.length===0&&($=mediaType_keys);for(const k of $){const i=this.transceiverMap.get(k);let c;if(i){const{sender:S}=i;D?c=this.getUserStream(b,k):c=this.getPhoneyStreams(k);const[C]=c.getTracks();C&&await S.replaceTrack(C)}}});ne(this,"getSenderTracks",async($=[])=>{const D=[];for(const b of $){const k=this.transceiverMap.get(b);if(!k)continue;const{mid:i,sender:c}=k,{track:S}=c;if(!S)continue;const{id:C,enabled:M}=S,Z=mediaType_keys.findIndex(Y=>Y===b),J=xt(),z={type:Z,enabled:M,trackName:`web-${Z}-${C}`,location:"local",mid:i,key:J};D.push(z)}return D});ne(this,"addSenders",async($=[])=>{$.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const D=[];for(const b of $){if(this.transceiverMap.get(b))continue;const i=this.getPhoneyStreams(b),[c]=i.getTracks(),S=this.peerIns.addTransceiver(c,{direction:"sendonly"});this.transceiverMap.set(b,S),D.push(b)}if($.length===0||D.length!==0){const b=await this.peerIns.createOffer();if(this.options.debug){const k=libExports$1.parse(b.sdp),i=dt(k.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:i,sdpJson:k,description:b})}await this.peerIns.setLocalDescription(b)}return D});ne(this,"removeSenders",async($=[])=>{$.length===0&&($=mediaType_keys);for(const D of $)this.transceiverMap.has(D)&&this.transceiverMap.delete(D)});ne(this,"onSubscribeUserTracks",$=>{let D=0;return new Promise(async b=>{const k=[];for(const i of $){const{tracks:c=[]}=i;for(const S of c){const{trackName:C,mid:M}=S,[Z]=await this.getUserTrackByTrackName([C]);k.push({...Z,mid:M})}}{let i=[];const c=async()=>{clearTimeout(D);const C=new Map;for(const Z of i){const{userId:J,mediaType:z}=Z;if(!J||!z)continue;C.has(J)||C.set(J,{userId:J,tracks:[],updateStreams:{}});const re=C.get(J);re.tracks.push(Z),re.updateStreams[z]=!0}const M=[...C.values()];for(const Z of M){const{userId:J,tracks:z}=Z;await this.updateUsertracks(J,z,!0)}await this.emitNotifyUpdateUsersStreams(M),this.peerIns.removeEventListener("track",S);{const Z=Array.from(k,Y=>Y.trackName),J=Array.from(i,Y=>Y.trackName),z=Z.filter(Y=>!J.includes(Y));b({target:Z,success:J,fail:z})}},S=async C=>{const{streams:M,transceiver:Z}=C,[J]=M,{mid:z,receiver:Y}=Z,{track:re}=Y,{id:oe}=re,ie=k.find(Q=>Q.mid===`${z}`);if(!ie)return;const{userId:de,mediaType:ye}=ie;if(!(!de||!ye)){{const Q={...ie,mid:z,msid:oe,key:xt()};i.push(Q)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${i.length}/${k.length}`,{mediaType:ye,mid:z,userTrack:ie,e:C});{const Q=new Audio;if(Q.srcObject=J,await this.initUserMediaStreamContext(de,ye,J),ye==="microphoneCamera_audio"||ye==="screenSharing_audio"){const ae=this.getUserAudioMediaStreamContext(de,ye);ae==null||ae.setMute(!1)}}k.length===i.length&&c()}};this.peerIns.addEventListener("track",S),D=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${i.length}/${k.length})`),c()},5*1e3)}})});ke(this,Jt,()=>{const $=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.oniceconnectionstatechange=async()=>{const D=this.peerIns.iceConnectionState;switch(clearTimeout(se(this,It)),D){case"connected":{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${D}`),this.setRoomState("connected");for(const b of se(this,Ut))await b()}break;case"disconnected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${D}`),Be(this,It,window.setTimeout($,30*1e3));break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${D}`),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:${D}`),$();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${D}`);break}}});ne(this,"iceConnected",()=>new Promise($=>{if(this.peerIns.iceConnectionState==="connected")return $(!0);se(this,Ut).push($)}));ne(this,"closeUserTracks",async($,D=[],b=!1)=>{const k=[];for(const C of D){const{trackName:M,msid:Z}=C;k.push(M),Z&&k.push(Z)}const i=C=>k.includes(C),c=this.peerIns.getTransceivers();for(const C of c){const{mid:M,sender:Z,receiver:J}=C;Z.track&&i(Z.track.id)&&(C.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${M} is stop.`,C)),J.track&&i(J.track.id)&&(C.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${M} is stop.`,C))}const S=await this.getUser($);if(S){for(const C of S.tracks){const{trackName:M,msid:Z,userId:J,mediaType:z}=C;!J||!z||!i(M)||(this.removeUserMediaStreamContext(J,z),Z&&delete C.msid)}if(b){const C=S.tracks.filter(({trackName:M})=>!i(M));await this.updateUsertracks($,C,!1)}}});ne(this,"createOffer",async()=>{const $=await this.peerIns.createOffer();if(this.options.debug){const D=libExports$1.parse($.sdp),b=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:b,sdpJson:D,description:$})}await this.peerIns.setLocalDescription($)});ne(this,"createAnswer",async()=>{const $=await this.peerIns.createAnswer();if(this.options.debug){const D=libExports$1.parse($.sdp),b=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:b,sdpJson:D,description:$})}await this.peerIns.setLocalDescription($)});ne(this,"getSdp",()=>{var $;return($=this.peerIns.localDescription)==null?void 0:$.sdp});ne(this,"setRemoteDescription",async $=>{if(this.options.debug){const D=libExports$1.parse($.sdp),b=dt(D.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:b,sdpJson:D,description:$})}return await this.peerIns.setRemoteDescription($),$});ne(this,"setCallStrategy",async($,D=[])=>{D.length===0&&(D=mediaType_keys);let b="balanced";switch($){case"qualityPriority":b="maintain-resolution";break;case"fluencyPriority":b="maintain-framerate";break;case"balancedDowngrade":b="balanced";break}const k=await this.getSelfInfo(),i=Array.from(k.tracks,({trackName:S})=>S),c=this.peerIns.getSenders();for(const S of c){const{track:C}=S;if(!C||!i.includes(C.id))continue;const M=S.getParameters();S.setParameters({...M,degradationPreference:b})}});ne(this,"setRTCRtpSenderParameters",$=>{try{const D=this.peerIns.getSenders();for(const b of D){const k=b.getParameters();b.setParameters({...k,...$})}}catch(D){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",D)}});ne(this,"getReportsByMid",async($=[])=>$.length===0?this.reports:this.reports.filter(D=>$.includes(D.mid)));ne(this,"getRoomNetwork",()=>this.peerNetwork);ne(this,"getPeerNetwork",()=>this.peerNetwork);ke(this,Vt,async()=>{try{const $=await this.peerIns.getStats(),D=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],k=[...$.values()].filter(ae=>D.includes(ae.type));let i=0,c=0,S=0,C=0,M=0,Z=0,J=[],z=[];for(const ae of this.reports){const{packetsSent:he,packetsLost:ce}=ae;he&&(S+=he),ce&&(C+=ce)}this.reports=k;for(const ae of this.reports){const{bytesSent:he,bytesReceived:ce,packetsSent:fe,packetsLost:me,roundTripTime:ee,jitter:le}=ae;he&&(c=he),ce&&(i=ce),fe&&(M+=fe),me&&(Z+=me),ee&&J.push((ee*100).toFixed(2)),le&&z.push(le.toFixed(2))}z.sort().reverse(),J.sort().reverse();const Y=M-S,re=Z-C,oe=Y===0?"0.00":(re/Y).toFixed(2),[ie="0"]=J,[de="0"]=z,ye={outboundBytes:c,inboundBytes:i,lostRate:oe,roundTripTime:ie,jitter:de};this.peerNetwork=ye;const Q=(ae,he,ce)=>{const fe=Number(ae),me=Number(he),ee=Number(ce);let le="0";return fe<.03&&me<100&&ee<.05?le="5":fe<.06&&me<160&&ee<.1?le="4":fe<.1&&me<250&&ee<.15?le="3":fe<.15&&me<400&&ee<.2?le="2":le="1",Number(le)};{const ae=Q(oe,ie,de),he=await this.getSelfInfo(),{network:ce}=he,fe={egress:ae,ingress:ae};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,fe),JSON.stringify(ce)!==JSON.stringify(fe)){this.emitNotifyUpdateUsers();const{userId:le,roomId:ve}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...fe,userId:le,roomId:ve}},!1)}},3*1e3)}}catch($){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",$)}});ke(this,Gt,()=>{const $=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||se(this,Vt).call(this)};this.getPeerStatsTimer=window.setInterval($,1*1e3)});ne(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer));this.initPeer()}}Ut=new WeakMap,It=new WeakMap,Jt=new WeakMap,Vt=new WeakMap,Gt=new WeakMap;class RoomCalls extends RoomPeer{constructor($){super($);ke(this,Et,0);ke(this,Rt,[]);ke(this,_t,()=>{});ne(this,"setLocalStream",($,D)=>new Promise(async(b,k)=>{try{typeof $=="string"&&($=[$]);for(const c of $)this.localStreamsActionMap.set(c,D);if(D){if($.includes("microphoneCamera_audio")&&$.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):$.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):$.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):$.includes("screenSharing_audio")&&$.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):$.includes("screenSharing_audio")&&!$.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):$.includes("screenSharing_video")&&!$.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),$.includes("screenSharing_audio")){const c=await this.getLocalStream("screenSharing_audio");if(c){const S=c.getTracks();for(const C of S)C.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if($.includes("screenSharing_video")){const c=await this.getLocalStream("screenSharing_video");if(c){const S=c.getTracks();for(const C of S)C.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams($);const i=await this.getLocalStreams($);await this.cwsIns.emitNotify("onLocalStream",{code:200,data:i,desc:"local stream is change."}),b(i)}catch(i){k(i)}}));ne(this,"setMediaDeviceKind",($,D)=>new Promise(async(b,k)=>{this.setDeviceKind($,D);const i=await this.getSelfInfo(),{id:c,tracks:S=[],callActionMap:C}=i,M=[],Z=async J=>{const z=this.localStreamsActionMap.get(J),Y=S.find(oe=>oe.mediaType===J),re=C[J];if(z){M.push(J),await this.stopLocalStreams([J]);try{await this.initLocalStream(J)}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([J],!1),k(oe)}}if(Y){const oe=await this.getLocalStream(J);oe&&(await this.initUserMediaStreamContext(c,J,oe),re&&await this.replaceSenderStream([J],!0))}{if(M.length!==0){const oe=await this.getLocalStreams(M);await this.cwsIns.emitNotify("onLocalStream",{code:200,data:oe,desc:"local stream is change."});const ie={};for(const de of M)ie[de]=!0;await this.emitNotifyUpdateUsersStreams([{userId:this.options.userId,updateStreams:ie}]),await this.emitNotifyUpdateUsers()}b(!0)}};$==="audioinput"&&await Z("microphoneCamera_audio"),$==="videoinput"&&await Z("microphoneCamera_video"),$==="audiooutput"&&(await this.changeAudiooutput(),b(!0))}));ne(this,"changeScreenSharing",async $=>{const D=await this.getSelfInfo(),{tracks:b=[],callActionMap:k}=D;try{await this.setLocalStream($,!0);for(const i of $)b.find(S=>S.mediaType===i&&k[i])&&await this.replaceSenderStream([i],!0)}catch(i){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",i)}});ne(this,"earlyConnect",($=[])=>{this.isEarly=!0;const D=async()=>new Promise(async(b,k)=>{try{await se(this,wt).call(this).then(async()=>{await se(this,Dt).call(this),$.length===0&&($=["microphoneCamera_audio","microphoneCamera_video"]),await se(this,Mt).call(this,$),b(!0)})}catch(i){k(i)}});return this.asyncQueue.add(D,{describe:"earlyConnect"})});ne(this,"joinRoom",async $=>(this.isInRoom=!0,this.setOptions($),await se(this,wt).call(this),new Promise(async(D,b)=>{Be(this,_t,async()=>{try{this.clearUsers();const{roomId:k,userId:i,callType:c,sdkToken:S}=this.options;await this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:c,roomId:k,user:{id:i,tracks:[],callAction:0},token:S},version:2}).then(async C=>{const{code:M=0,desc:Z="服务器繁忙",data:J}=C;if(M!==200)throw new Error(Z);const{roomId:z="",roomUsers:Y=[]}=J;if(z!==k)return b("加入的房间不匹配");this.initHeartbeat(),this.isEarly===!1&&await se(this,Dt).call(this),await this.updateUsers(Y);const re=[];for(const ie of Y){const{id:de,channelCache:ye}=ie,{channels:Q=[]}=ye;await this.updateUserBehaviors(de,ie.behavior),await this.updateUserChannels(de,Q,!1),Q.length!==0&&re.push({userId:de,channels:Q})}await this.subChannel(re),await this.emitNotifyUpdateUsers();const oe=await this.getUsers();D(oe)})}catch(k){b(k)}}),se(this,_t).call(this)})));ne(this,"quitRoom",()=>new Promise(async $=>{const{roomId:D,userId:b}=this.options,k={roomId:D,user:{id:b}};try{this.isInRoom=!1,this.options.roomId="",this.asyncQueue.clear(),clearInterval(se(this,Et)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(i){this.reportLogs("quit_room_error",i.message||i)}await new Promise(i=>setTimeout(()=>i(!0),300)),await this.cwsIns.sendMessage({event:"quitRoom",data:k}),$(!0)}));ne(this,"quitRoomEx",()=>new Promise(async $=>{const{roomId:D,userId:b}=this.options,k={roomId:D,user:{id:b}};try{this.isInRoom=!1,this.options.roomId="",this.asyncQueue.clear(),this.stopHeartbeat(),this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe().catch(()=>{this.reconstruct()}),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(i){this.reportLogs("quit_room_error",i.message||i)}await new Promise(i=>setTimeout(()=>i(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:k}),$(!0)}));ne(this,"syncRoomInfo",()=>new Promise(async($,D)=>{try{const{userId:b}=this.options,k=await this.getUser(b),{id:i=b,callAction:c=0}=k;await this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:i,callAction:c}}}).then(async S=>{const{code:C=0,desc:M,data:Z={}}=S;if(C!==200)throw new Error(M);const{isActive:J=!1,users:z=[]}=Z;if(J===!1)throw new Error("Do not stay in this room.");if(z.find(re=>re.id===this.options.userId)===!1)throw new Error("Need to rejoin the room.");this.clearUsers(),await this.updateUsers(z),await this.updateUsertracks(k.id,k.tracks,!1);{const re=await this.getUsers();$(re)}})}catch(b){D(b)}}));ne(this,"checkInRoom",()=>new Promise(async $=>{const{userId:D}=this.options,b=await this.getUser(D),{id:k=D,callAction:i=0}=b;await this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:k,callAction:i}}}).then(async c=>{var J;const{code:S=0,desc:C}=c;if(S!==200)throw new Error(C);const M=c.data.users;return(J=c.data)!=null&&J.isActive||M.find(z=>z.id===this.options.userId)?$(!0):$(!1)}).catch(()=>$(!1))}));ne(this,"publish",$=>{const D=()=>new Promise(async(b,k)=>{try{{const J=await this.getSelfInfo(),{banBehaviorMap:z}=J;let Y=!0;for(const re of $)if(z[re]){Y=!1;break}if(Y===!1)return k("publish is error: prohibited by administrator.")}try{await this.setLocalStream($,!0)}catch(J){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",J)}const i=await this.getSelfInfo(),c=[];for(const J of $){{const z=this.getPhoneyStreams(J);await this.initUserMediaStreamContext(i.id,J,z)}{const z=await this.getLocalStream(J);z?await this.initUserMediaStreamContext(i.id,J,z):c.push(J)}}const S=$.filter(J=>!c.includes(J)||["microphoneCamera_audio","microphoneCamera_video"].includes(J));await this.replaceSenderStream($,!1),await se(this,Mt).call(this,S);const C=await this.getSenderTracks(S),M=[...i.tracks,...C];await this.updateUsertracks(i.id,M,!0),c.length!==0&&await this.inactiveTracks(c,!1),S.length!==0&&await this.replaceSenderStream(S,!0);const Z=await this.getCallAction(M);await se(this,Ct).call(this,Z),await new Promise(J=>setTimeout(()=>J(!0),230)),se(this,Wt).call(this,$);{await this.emitNotifyUpdateUsers();const J=await this.getSelfInfo(),z={};for(const Y of $)z[Y]=!0;await this.emitNotifyUpdateUsersStreams([{userId:J.id,updateStreams:z}]),b(J)}}catch(i){this.reportLogs("publish_error",i.message||i),k(i)}});return this.asyncQueue.add(D,{describe:"publish"})});ne(this,"stopPublish",($=[])=>{const D=()=>new Promise(async(b,k)=>{try{const i=await this.getSelfInfo();$.length===0&&($=mediaType_keys);const c=i.tracks.filter(({mediaType:C})=>C&&$.includes(C)),S=async()=>{const C=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),b(C)};if(c.length===0)return S();await this.replaceSenderStream($,!0),await this.closeUserTracks(i.id,c,!0),await this.removeSenders($);{const C=await this.getCallAction(i.tracks);await se(this,Ct).call(this,C)}await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{session:this.sdk_session,roomId:this.options.roomId,sdp:this.getSdp(),tracks:c}}).then(async C=>{const{code:M=0,desc:Z,sn:J="",data:z={}}=C;if(await se(this,ut).call(this,J),M!==200)throw new Error(Z);const{remoteSdp:Y}=z;await this.setRemoteDescription({type:"answer",sdp:Y}),S()})}catch(i){this.reportLogs("close_track_error",i.message||i),k(i)}});return this.asyncQueue.add(D,{describe:"stopPublish"})});ne(this,"subscribe",($=[],D=3)=>{const b=()=>new Promise(async(k,i)=>{try{await this.iceConnected();const c=await this.getUsers();let S=[];for(const J of c){const{isSelf:z,tracks:Y=[]}=J;if(!z){const re=Y.filter(({trackName:oe,mid:ie=""})=>ie!==""&&($.includes(oe)||$.length===0));re.length!==0&&S.push({...J,tracks:re})}}const C=async(J={})=>{const z=Array.from(S,({id:re})=>re),Y=await this.getUsers(z);await this.emitNotifyUpdateUsers(),k({users:Y,detail:J})};if(S.length===0)return C();const M=[];for(const J of S){const{id:z,tracks:Y}=J,re=dt(Y,["type","trackName"]),oe={id:z,tracks:re};M.push(oe)}const Z=async()=>{D--,await this.cwsIns.sendMessage({event:"subscribe",data:{session:this.sdk_session,users:M}}).then(async J=>{const{code:z=0,desc:Y,sn:re="",data:oe={}}=J;if(await se(this,ut).call(this,re),z===2017&&Y.includes("renegotiation is expected before pulling or pushing tracks")&&await this.renegotiate(),z!==200){if(D>=0)return await new Promise(ye=>setTimeout(()=>ye(!0),500)),await Z();throw new Error(Y)}const{remoteSdp:ie,users:de=[]}=oe;this.onSubscribeUserTracks(de).then(async ye=>{await this.renegotiate().then(()=>C(ye))}).catch(ye=>{throw new Error(ye)}),await this.setRemoteDescription({type:"offer",sdp:ie})})};await Z()}catch(c){this.reportLogs("subscribe_error",c.message||c),i(c)}});return this.asyncQueue.add(b,{describe:"subscribe"})});ne(this,"renegotiate",()=>new Promise(async($,D)=>{try{await this.createAnswer(),await this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(async b=>{const{code:k=0,desc:i,sn:c=""}=b;if(await se(this,ut).call(this,c),k!==200)throw new Error(i);$(b)})}catch(b){D(b)}}));ne(this,"stopSubscribe",($=[])=>{const D=()=>new Promise(async(b,k)=>{try{const i=await this.getUsers(),c=[];for(const C of i){const{tracks:M=[]}=C;for(const Z of M){const{type:J,mid:z,trackName:Y,mediaType:re,msid:oe}=Z;if(!(!re||!oe)&&($.length===0||$.includes(Y))){const ie={type:J,mid:z,trackName:oe};c.push(ie),await this.closeUserTracks(C.id,[Z])}}}const S=async()=>{await this.emitNotifyUpdateUsers(),b(!0)};if(c.length===0)return S();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:c}}).then(async C=>{const{code:M=0,desc:Z,sn:J="",data:z={}}=C;if(M!==200)throw new Error(Z);await se(this,ut).call(this,J);const{remoteSdp:Y}=z;await this.setRemoteDescription({type:"answer",sdp:Y})}),S()}catch(i){this.reportLogs("close_track_error",i.message||i),k(i)}});return this.asyncQueue.add(D,{describe:"stopSubscribe"})});ne(this,"inactiveTracks",async($,D)=>new Promise(async b=>{const k=await this.getSelfInfo();if(!k||!k.id)return b(!0);const{tracks:i=[]}=k,c=[...i];for(let C of c){const{mediaType:M}=C;if(M&&$.includes(M)){C.enabled=D;const Z=await this.getLocalStream(M);if(!Z)continue;const J=Z.getTracks();for(const z of J)z.enabled=D}}await this.replaceSenderStream($,D);const S=await this.getCallAction(c);await se(this,Ct).call(this,S),await this.emitNotifyUpdateUsers(),b(!0)}));ne(this,"setBanBehaviors",$=>new Promise(async(D,b)=>{try{const{roomId:k}=this.options,i=[];for(const c of $){const{id:S,banBehaviors:C}=c,M=Object.keys(C);if(M.length===0)continue;const Z=[];for(const z of M){const Y=mediaType_keys.findIndex(ie=>ie===z),re=C[z],oe={type:Y,behavior:re};Z.push(oe)}const J={id:S,behaviors:Z};i.push(J)}await this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:k,users:i}}).then(async c=>{const{code:S=0,desc:C}=c;if(S!==200)return b(C);D(c)})}catch(k){b(k)}}));ne(this,"pubChannel",()=>new Promise(async($,D)=>{const k=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:k}}).then(async i=>{const{code:c=0,data:S,desc:C}=i;if(c!==200)throw new Error(C);const{channels:M=[]}=S;for(const Z of M){const{channels:J=[]}=Z;for(const z of J){const{dataChannelName:Y,id:re}=z;this.initSendChannel(Y,re)}}$(!0)}).catch(i=>{D(i)})}));ne(this,"subChannel",($=[])=>new Promise(async D=>{if($.length===0)return D(!0);await this.cwsIns.sendMessage({event:"subChannel",data:{channels:$}}).then(async b=>{const{code:k=0,data:i,desc:c}=b;if(k!==200)throw new Error(c);const{channels:S=[]}=i;for(const C of S){const{channels:M=[]}=C;for(const Z of M){const{dataChannelName:J,id:z}=Z;this.initReceiveChannel(J,z)}}})}));ne(this,"debugger",()=>new Promise(async($,D)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async b=>{if(b.code!==200)return D(b.desc);$(!0)}).catch(b=>{D(b)})}));ne(this,"shutdown",()=>new Promise(async($,D)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async b=>{if(b.code!==200)return D(b.desc);$(!0)}).catch(b=>{D(b)})}));ne(this,"reconstruct",async()=>{if(this.asyncQueue.clear(),this.setRoomState("ready"),this.asyncQueue.clear(),this.initPeer(),this.isEarly&&this.earlyConnect(),this.isInRoom===!1)return;this.isInRoom&&(this.isEarly===!1&&await se(this,wt).call(this).then(async()=>{await se(this,Dt).call(this)}),se(this,_t)&&await se(this,_t).call(this));const $=[],D=[],b=await this.getUsers();for(const k of b){const{isSelf:i,callActionMap:c,tracks:S=[]}=k;if(i)for(const C of mediaType_keys)c[C]&&$.push(C);for(const C of S)C.msid&&D.push(C.trackName)}await this.syncRoomInfo().then(async()=>{await this.publish($),await this.subscribe(D)}).catch(()=>{this.setRoomState("closed")})});ne(this,"initHeartbeat",()=>{this.stopHeartbeat();const $=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),D=this.isInRoom?10*1e3:30*1e3;Be(this,Et,window.setInterval($,D)),$()});ne(this,"stopHeartbeat",()=>{clearInterval(se(this,Et))});ke(this,Wt,async $=>new Promise(async(D,b)=>{try{const{roomId:k}=this.options;if(!k)return;const{id:i,tracks:c=[]}=await this.getSelfInfo(),S=c.filter(C=>C.mediaType&&$.includes(C.mediaType));if(S.length===0)return;await this.cwsIns.sendMessage({event:"pubNotify",data:{session:this.sdk_session,roomId:k,user:{id:i,tracks:S}}}),D(!0)}catch(k){b(k)}}));ke(this,ut,$=>new Promise(D=>{this.cwsIns.sendMessage({event:"ackMsg",data:{msgId:$}},!1),D(!0)}));ke(this,Ct,async $=>new Promise(async(D,b)=>{const{roomId:k,userId:i}=this.options,c={roomId:k,user:{id:i,callAction:$}};await this.cwsIns.sendMessage({event:"updateCall",data:c}).then(async S=>{const{code:C=0}=S;if(C!==200)return b(S);await this.updateUserCallAction(i,$),D($)}).catch(S=>b(S))}));ne(this,"setSession",()=>{const{appid:$,roomId:D,userId:b}=this.options;if(!$)throw new Error("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const k={c:$,r:D,p:"web",h:location.hostname,v:this.sdk_service_version};this.isEarly?k.i=this.options.earlyId:k.b=b;const i=btoa(encodeURI(JSON.stringify(k)));this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSession",k);const c=`${this.options.url}?s=${i}&t=${Date.now()}`;this.cwsIns.prws.setOptions({url:c})});ke(this,wt,()=>new Promise(async($,D)=>{try{switch(this.cwsIns.state){case"connected":this.cwsIns.state==="connected"&&$(!0);break;case"connecting":se(this,Rt).push($);break;case"closed":{se(this,Rt).push($),this.cwsIns.clearEvents(),this.setSession(),await this.cwsIns.connect(),this.initHeartbeat();for(const b of se(this,Rt))await b()}break}}catch(b){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",b),this.reportLogs("ws_c_timeout",b.message||b),D(b)}}));ke(this,Dt,async()=>new Promise(async($,D)=>{try{await se(this,wt).call(this),await this.addSenders(),await this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async b=>{const{code:k=0,desc:i,data:c}=b;if(k!==200)throw new Error(i);const{remoteSdp:S,session:C=""}=c;if(this.sdk_session=C,this.options.debug){const M=libExports$1.parse(S),Z=dt(M.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:Z,sdpJson:M})}await this.setRemoteDescription({type:"answer",sdp:S}),await this.iceConnected().then(()=>{$(!0)})})}catch(b){D(b)}}));ke(this,Mt,async $=>new Promise(async(D,b)=>{try{await this.iceConnected();const k=await this.addSenders($),i=await this.getSenderTracks(k);if(i.length===0)return D(!0);await this.cwsIns.sendMessage({event:"publish",data:{session:this.sdk_session,sdp:this.getSdp(),tracks:i,callAction:0}}).then(async c=>{const{code:S=0,desc:C,sn:M="",data:Z={}}=c;if(await se(this,ut).call(this,M),S!==200)throw new Error(C);const{remoteSdp:J}=Z;await this.setRemoteDescription({type:"answer",sdp:J}),D(!0)})}catch(k){this.reportLogs("publish_error",k.message||k),await this.removeSenders($),b(k)}}))}}Et=new WeakMap,Rt=new WeakMap,_t=new WeakMap,Wt=new WeakMap,ut=new WeakMap,Ct=new WeakMap,wt=new WeakMap,Dt=new WeakMap,Mt=new WeakMap;class Room extends RoomCalls{constructor(N){super(N)}}class QuickVO extends Room{constructor($){super($);ke(this,gt,new Map);ke(this,Kt,()=>{{const $=async D=>{const{state:b}=D.data;if(b==="closed"){const{roomId:k,userId:i}=this.options,c={roomId:k,user:{id:i}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:c}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}};this.cwsIns.addNotify({event:"onRoomState",callback:$},!0)}{const $=async D=>{const{qualities:b=[]}=D.data,[k]=b;if(!(k&&k.userId===this.options.userId&&b.length===1)){for(const i of b){const{userId:c,egress:S,ingress:C}=i;this.checkUserInRoom(c)&&await this.updateUserNetwork(c,{egress:S,ingress:C})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:$},!0)}{const $=async D=>{const b=D.data.user;await this.removeUsers([b.id]),await this.updateUsers([b]),await this.updateUsertracks(b.id,b.track,!1),await this.updateUserBehaviors(b.id,b.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:$},!0)}{const $=async D=>{await this.removeUsers([D.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:$},!0)}{const $=async D=>{const{user:b}=D.data,{id:k,tracks:i=[],callAction:c=0}=b;if(await this.updateUserCallAction(k,c),await this.updateUserPermissions(k,3),await this.updateUsertracks(k,i,!0),this.options.newPublishAutoSubscribe){const S=this.getTrackNamesFormTracks(i);await this.subscribe(S)}else await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onPublish",callback:$},!0)}{const $=async D=>{const b=[D.data];this.subChannel(b)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:$},!0)}{const $=async D=>{const{id:b,tracks:k}=D.data.user;b!==this.options.userId&&(await this.closeUserTracks(b,k,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:$},!0)}{const $=async D=>{const{id:b,callAction:k}=D.data.user;this.checkUserInRoom(b)&&(await this.updateUserCallAction(b,k),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:$},!0)}{const $=async D=>{const{user:b}=D.data,{id:k,permissions:i=1}=b;i===1?await this.removeUsers([k]):i===3&&await this.updateUsers([b]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:$},!0)}{const $=async D=>{const{users:b}=D.data;for(const k of b){const{id:i,behavior:c}=k;await this.updateUserBehaviors(i,c)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:$},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async $=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});ne(this,"addNotify",$=>this.cwsIns.addNotify($));ke(this,Yt,()=>{this.cwsIns.prws.checkReconnect=async $=>$.code===1e3?(this.setRoomState("closed"),!1):$.code===4001?(this.setRoomState("closed"),!1):$.code===4002?(this.setRoomState("closed"),!1):$.code===4003?(this.setRoomState("closed"),!1):(this.setSession(),$.code===4010||await new Promise(D=>setTimeout(()=>D(!0),5*1e3)),!0),this.cwsIns.prws.onReconnectSuccess=async $=>{this.reconstruct()},this.cwsIns.prws.onReconnectStop=async $=>{this.setRoomState("closed")}});ne(this,"addRequestAnimationFrame",async($,D)=>{{const k=se(this,gt).get($);k&&cancelAnimationFrame(k)}const b=(k=Date.now())=>{D(k);const i=requestAnimationFrame(b);se(this,gt).set($,i)};b()});ne(this,"clearRequestAnimationFrame",async($=[])=>{$.length===0&&($=[...se(this,gt).keys()]);const D=[];for(const b of $){const k=se(this,gt).get(b);k&&(cancelAnimationFrame(k),D.push(k))}return D});ne(this,"destroy",async()=>{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 销毁SDK"),this.stopLocalStreams(),this.stopGetPeerStats(),this.quitRoom(),this.clearUsers(),this.clearUserStreams(),this.stopHeartbeat(),await new Promise($=>setTimeout(()=>$(!0),300)),this.cwsIns.emitNotify("onDestroy",{code:200,data:{},desc:"sdk is destroy."}),this.cwsIns.clearEvents()});se(this,Yt).call(this),se(this,Kt).call(this)}}gt=new WeakMap,Kt=new WeakMap,Yt=new WeakMap,exports.QuickVO=QuickVO,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|