quickvo-sdk-js 1.0.1 → 1.0.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.
Files changed (3) hide show
  1. package/dist/index.js +22335 -22256
  2. package/dist/index.umd.cjs +2 -2
  3. package/package.json +1 -1
@@ -10,7 +10,7 @@ between two successive fields at the output of the decoding process (see the not
10
10
  *
11
11
  * @author Feross Aboukhadijeh <https://feross.org>
12
12
  * @license MIT
13
- */var hasRequiredBuffer;function requireBuffer(){return hasRequiredBuffer||(hasRequiredBuffer=1,function(q){const K=requireBase64Js(),F=requireIeee754(),Z=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;q.Buffer=I,q.SlowBuffer=de,q.INSPECT_MAX_BYTES=50;const D=2147483647;q.kMaxLength=D,I.TYPED_ARRAY_SUPPORT=N(),!I.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 N(){try{const se=new Uint8Array(1),X={foo:function(){return 42}};return Object.setPrototypeOf(X,Uint8Array.prototype),Object.setPrototypeOf(se,X),se.foo()===42}catch{return!1}}Object.defineProperty(I.prototype,"parent",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.buffer}}),Object.defineProperty(I.prototype,"offset",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.byteOffset}});function O(se){if(se>D)throw new RangeError('The value "'+se+'" is invalid for option "size"');const X=new Uint8Array(se);return Object.setPrototypeOf(X,I.prototype),X}function I(se,X,ee){if(typeof se=="number"){if(typeof X=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return ne(se)}return z(se,X,ee)}I.poolSize=8192;function z(se,X,ee){if(typeof se=="string")return re(se,X);if(ArrayBuffer.isView(se))return oe(se);if(se==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof se);if(Vt(se,ArrayBuffer)||se&&Vt(se.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Vt(se,SharedArrayBuffer)||se&&Vt(se.buffer,SharedArrayBuffer)))return le(se,X,ee);if(typeof se=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const pe=se.valueOf&&se.valueOf();if(pe!=null&&pe!==se)return I.from(pe,X,ee);const Oe=ae(se);if(Oe)return Oe;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof se[Symbol.toPrimitive]=="function")return I.from(se[Symbol.toPrimitive]("string"),X,ee);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof se)}I.from=function(se,X,ee){return z(se,X,ee)},Object.setPrototypeOf(I.prototype,Uint8Array.prototype),Object.setPrototypeOf(I,Uint8Array);function J(se){if(typeof se!="number")throw new TypeError('"size" argument must be of type number');if(se<0)throw new RangeError('The value "'+se+'" is invalid for option "size"')}function Q(se,X,ee){return J(se),se<=0?O(se):X!==void 0?typeof ee=="string"?O(se).fill(X,ee):O(se).fill(X):O(se)}I.alloc=function(se,X,ee){return Q(se,X,ee)};function ne(se){return J(se),O(se<0?0:ce(se)|0)}I.allocUnsafe=function(se){return ne(se)},I.allocUnsafeSlow=function(se){return ne(se)};function re(se,X){if((typeof X!="string"||X==="")&&(X="utf8"),!I.isEncoding(X))throw new TypeError("Unknown encoding: "+X);const ee=we(se,X)|0;let pe=O(ee);const Oe=pe.write(se,X);return Oe!==ee&&(pe=pe.slice(0,Oe)),pe}function te(se){const X=se.length<0?0:ce(se.length)|0,ee=O(X);for(let pe=0;pe<X;pe+=1)ee[pe]=se[pe]&255;return ee}function oe(se){if(Vt(se,Uint8Array)){const X=new Uint8Array(se);return le(X.buffer,X.byteOffset,X.byteLength)}return te(se)}function le(se,X,ee){if(X<0||se.byteLength<X)throw new RangeError('"offset" is outside of buffer bounds');if(se.byteLength<X+(ee||0))throw new RangeError('"length" is outside of buffer bounds');let pe;return X===void 0&&ee===void 0?pe=new Uint8Array(se):ee===void 0?pe=new Uint8Array(se,X):pe=new Uint8Array(se,X,ee),Object.setPrototypeOf(pe,I.prototype),pe}function ae(se){if(I.isBuffer(se)){const X=ce(se.length)|0,ee=O(X);return ee.length===0||se.copy(ee,0,0,X),ee}if(se.length!==void 0)return typeof se.length!="number"||Qt(se.length)?O(0):te(se);if(se.type==="Buffer"&&Array.isArray(se.data))return te(se.data)}function ce(se){if(se>=D)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+D.toString(16)+" bytes");return se|0}function de(se){return+se!=se&&(se=0),I.alloc(+se)}I.isBuffer=function(X){return X!=null&&X._isBuffer===!0&&X!==I.prototype},I.compare=function(X,ee){if(Vt(X,Uint8Array)&&(X=I.from(X,X.offset,X.byteLength)),Vt(ee,Uint8Array)&&(ee=I.from(ee,ee.offset,ee.byteLength)),!I.isBuffer(X)||!I.isBuffer(ee))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(X===ee)return 0;let pe=X.length,Oe=ee.length;for(let De=0,Le=Math.min(pe,Oe);De<Le;++De)if(X[De]!==ee[De]){pe=X[De],Oe=ee[De];break}return pe<Oe?-1:Oe<pe?1:0},I.isEncoding=function(X){switch(String(X).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}},I.concat=function(X,ee){if(!Array.isArray(X))throw new TypeError('"list" argument must be an Array of Buffers');if(X.length===0)return I.alloc(0);let pe;if(ee===void 0)for(ee=0,pe=0;pe<X.length;++pe)ee+=X[pe].length;const Oe=I.allocUnsafe(ee);let De=0;for(pe=0;pe<X.length;++pe){let Le=X[pe];if(Vt(Le,Uint8Array))De+Le.length>Oe.length?(I.isBuffer(Le)||(Le=I.from(Le)),Le.copy(Oe,De)):Uint8Array.prototype.set.call(Oe,Le,De);else if(I.isBuffer(Le))Le.copy(Oe,De);else throw new TypeError('"list" argument must be an Array of Buffers');De+=Le.length}return Oe};function we(se,X){if(I.isBuffer(se))return se.length;if(ArrayBuffer.isView(se)||Vt(se,ArrayBuffer))return se.byteLength;if(typeof se!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof se);const ee=se.length,pe=arguments.length>2&&arguments[2]===!0;if(!pe&&ee===0)return 0;let Oe=!1;for(;;)switch(X){case"ascii":case"latin1":case"binary":return ee;case"utf8":case"utf-8":return Kt(se).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ee*2;case"hex":return ee>>>1;case"base64":return nn(se).length;default:if(Oe)return pe?-1:Kt(se).length;X=(""+X).toLowerCase(),Oe=!0}}I.byteLength=we;function fe(se,X,ee){let pe=!1;if((X===void 0||X<0)&&(X=0),X>this.length||((ee===void 0||ee>this.length)&&(ee=this.length),ee<=0)||(ee>>>=0,X>>>=0,ee<=X))return"";for(se||(se="utf8");;)switch(se){case"hex":return zt(this,X,ee);case"utf8":case"utf-8":return We(this,X,ee);case"ascii":return It(this,X,ee);case"latin1":case"binary":return Dt(this,X,ee);case"base64":return Ve(this,X,ee);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ut(this,X,ee);default:if(pe)throw new TypeError("Unknown encoding: "+se);se=(se+"").toLowerCase(),pe=!0}}I.prototype._isBuffer=!0;function ge(se,X,ee){const pe=se[X];se[X]=se[ee],se[ee]=pe}I.prototype.swap16=function(){const X=this.length;if(X%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let ee=0;ee<X;ee+=2)ge(this,ee,ee+1);return this},I.prototype.swap32=function(){const X=this.length;if(X%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let ee=0;ee<X;ee+=4)ge(this,ee,ee+3),ge(this,ee+1,ee+2);return this},I.prototype.swap64=function(){const X=this.length;if(X%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let ee=0;ee<X;ee+=8)ge(this,ee,ee+7),ge(this,ee+1,ee+6),ge(this,ee+2,ee+5),ge(this,ee+3,ee+4);return this},I.prototype.toString=function(){const X=this.length;return X===0?"":arguments.length===0?We(this,0,X):fe.apply(this,arguments)},I.prototype.toLocaleString=I.prototype.toString,I.prototype.equals=function(X){if(!I.isBuffer(X))throw new TypeError("Argument must be a Buffer");return this===X?!0:I.compare(this,X)===0},I.prototype.inspect=function(){let X="";const ee=q.INSPECT_MAX_BYTES;return X=this.toString("hex",0,ee).replace(/(.{2})/g,"$1 ").trim(),this.length>ee&&(X+=" ... "),"<Buffer "+X+">"},Z&&(I.prototype[Z]=I.prototype.inspect),I.prototype.compare=function(X,ee,pe,Oe,De){if(Vt(X,Uint8Array)&&(X=I.from(X,X.offset,X.byteLength)),!I.isBuffer(X))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof X);if(ee===void 0&&(ee=0),pe===void 0&&(pe=X?X.length:0),Oe===void 0&&(Oe=0),De===void 0&&(De=this.length),ee<0||pe>X.length||Oe<0||De>this.length)throw new RangeError("out of range index");if(Oe>=De&&ee>=pe)return 0;if(Oe>=De)return-1;if(ee>=pe)return 1;if(ee>>>=0,pe>>>=0,Oe>>>=0,De>>>=0,this===X)return 0;let Le=De-Oe,ut=pe-ee;const St=Math.min(Le,ut),vt=this.slice(Oe,De),Ct=X.slice(ee,pe);for(let Tt=0;Tt<St;++Tt)if(vt[Tt]!==Ct[Tt]){Le=vt[Tt],ut=Ct[Tt];break}return Le<ut?-1:ut<Le?1:0};function me(se,X,ee,pe,Oe){if(se.length===0)return-1;if(typeof ee=="string"?(pe=ee,ee=0):ee>2147483647?ee=2147483647:ee<-2147483648&&(ee=-2147483648),ee=+ee,Qt(ee)&&(ee=Oe?0:se.length-1),ee<0&&(ee=se.length+ee),ee>=se.length){if(Oe)return-1;ee=se.length-1}else if(ee<0)if(Oe)ee=0;else return-1;if(typeof X=="string"&&(X=I.from(X,pe)),I.isBuffer(X))return X.length===0?-1:ve(se,X,ee,pe,Oe);if(typeof X=="number")return X=X&255,typeof Uint8Array.prototype.indexOf=="function"?Oe?Uint8Array.prototype.indexOf.call(se,X,ee):Uint8Array.prototype.lastIndexOf.call(se,X,ee):ve(se,[X],ee,pe,Oe);throw new TypeError("val must be string, number or Buffer")}function ve(se,X,ee,pe,Oe){let De=1,Le=se.length,ut=X.length;if(pe!==void 0&&(pe=String(pe).toLowerCase(),pe==="ucs2"||pe==="ucs-2"||pe==="utf16le"||pe==="utf-16le")){if(se.length<2||X.length<2)return-1;De=2,Le/=2,ut/=2,ee/=2}function St(Ct,Tt){return De===1?Ct[Tt]:Ct.readUInt16BE(Tt*De)}let vt;if(Oe){let Ct=-1;for(vt=ee;vt<Le;vt++)if(St(se,vt)===St(X,Ct===-1?0:vt-Ct)){if(Ct===-1&&(Ct=vt),vt-Ct+1===ut)return Ct*De}else Ct!==-1&&(vt-=vt-Ct),Ct=-1}else for(ee+ut>Le&&(ee=Le-ut),vt=ee;vt>=0;vt--){let Ct=!0;for(let Tt=0;Tt<ut;Tt++)if(St(se,vt+Tt)!==St(X,Tt)){Ct=!1;break}if(Ct)return vt}return-1}I.prototype.includes=function(X,ee,pe){return this.indexOf(X,ee,pe)!==-1},I.prototype.indexOf=function(X,ee,pe){return me(this,X,ee,pe,!0)},I.prototype.lastIndexOf=function(X,ee,pe){return me(this,X,ee,pe,!1)};function ke(se,X,ee,pe){ee=Number(ee)||0;const Oe=se.length-ee;pe?(pe=Number(pe),pe>Oe&&(pe=Oe)):pe=Oe;const De=X.length;pe>De/2&&(pe=De/2);let Le;for(Le=0;Le<pe;++Le){const ut=parseInt(X.substr(Le*2,2),16);if(Qt(ut))return Le;se[ee+Le]=ut}return Le}function xe(se,X,ee,pe){return rn(Kt(X,se.length-ee),se,ee,pe)}function _e(se,X,ee,pe){return rn(Gt(X),se,ee,pe)}function Te(se,X,ee,pe){return rn(nn(X),se,ee,pe)}function qe(se,X,ee,pe){return rn(dn(X,se.length-ee),se,ee,pe)}I.prototype.write=function(X,ee,pe,Oe){if(ee===void 0)Oe="utf8",pe=this.length,ee=0;else if(pe===void 0&&typeof ee=="string")Oe=ee,pe=this.length,ee=0;else if(isFinite(ee))ee=ee>>>0,isFinite(pe)?(pe=pe>>>0,Oe===void 0&&(Oe="utf8")):(Oe=pe,pe=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const De=this.length-ee;if((pe===void 0||pe>De)&&(pe=De),X.length>0&&(pe<0||ee<0)||ee>this.length)throw new RangeError("Attempt to write outside buffer bounds");Oe||(Oe="utf8");let Le=!1;for(;;)switch(Oe){case"hex":return ke(this,X,ee,pe);case"utf8":case"utf-8":return xe(this,X,ee,pe);case"ascii":case"latin1":case"binary":return _e(this,X,ee,pe);case"base64":return Te(this,X,ee,pe);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return qe(this,X,ee,pe);default:if(Le)throw new TypeError("Unknown encoding: "+Oe);Oe=(""+Oe).toLowerCase(),Le=!0}},I.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Ve(se,X,ee){return X===0&&ee===se.length?K.fromByteArray(se):K.fromByteArray(se.slice(X,ee))}function We(se,X,ee){ee=Math.min(se.length,ee);const pe=[];let Oe=X;for(;Oe<ee;){const De=se[Oe];let Le=null,ut=De>239?4:De>223?3:De>191?2:1;if(Oe+ut<=ee){let St,vt,Ct,Tt;switch(ut){case 1:De<128&&(Le=De);break;case 2:St=se[Oe+1],(St&192)===128&&(Tt=(De&31)<<6|St&63,Tt>127&&(Le=Tt));break;case 3:St=se[Oe+1],vt=se[Oe+2],(St&192)===128&&(vt&192)===128&&(Tt=(De&15)<<12|(St&63)<<6|vt&63,Tt>2047&&(Tt<55296||Tt>57343)&&(Le=Tt));break;case 4:St=se[Oe+1],vt=se[Oe+2],Ct=se[Oe+3],(St&192)===128&&(vt&192)===128&&(Ct&192)===128&&(Tt=(De&15)<<18|(St&63)<<12|(vt&63)<<6|Ct&63,Tt>65535&&Tt<1114112&&(Le=Tt))}}Le===null?(Le=65533,ut=1):Le>65535&&(Le-=65536,pe.push(Le>>>10&1023|55296),Le=56320|Le&1023),pe.push(Le),Oe+=ut}return Ot(pe)}const Fe=4096;function Ot(se){const X=se.length;if(X<=Fe)return String.fromCharCode.apply(String,se);let ee="",pe=0;for(;pe<X;)ee+=String.fromCharCode.apply(String,se.slice(pe,pe+=Fe));return ee}function It(se,X,ee){let pe="";ee=Math.min(se.length,ee);for(let Oe=X;Oe<ee;++Oe)pe+=String.fromCharCode(se[Oe]&127);return pe}function Dt(se,X,ee){let pe="";ee=Math.min(se.length,ee);for(let Oe=X;Oe<ee;++Oe)pe+=String.fromCharCode(se[Oe]);return pe}function zt(se,X,ee){const pe=se.length;(!X||X<0)&&(X=0),(!ee||ee<0||ee>pe)&&(ee=pe);let Oe="";for(let De=X;De<ee;++De)Oe+=gn[se[De]];return Oe}function Ut(se,X,ee){const pe=se.slice(X,ee);let Oe="";for(let De=0;De<pe.length-1;De+=2)Oe+=String.fromCharCode(pe[De]+pe[De+1]*256);return Oe}I.prototype.slice=function(X,ee){const pe=this.length;X=~~X,ee=ee===void 0?pe:~~ee,X<0?(X+=pe,X<0&&(X=0)):X>pe&&(X=pe),ee<0?(ee+=pe,ee<0&&(ee=0)):ee>pe&&(ee=pe),ee<X&&(ee=X);const Oe=this.subarray(X,ee);return Object.setPrototypeOf(Oe,I.prototype),Oe};function gt(se,X,ee){if(se%1!==0||se<0)throw new RangeError("offset is not uint");if(se+X>ee)throw new RangeError("Trying to access beyond buffer length")}I.prototype.readUintLE=I.prototype.readUIntLE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=this[X],De=1,Le=0;for(;++Le<ee&&(De*=256);)Oe+=this[X+Le]*De;return Oe},I.prototype.readUintBE=I.prototype.readUIntBE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=this[X+--ee],De=1;for(;ee>0&&(De*=256);)Oe+=this[X+--ee]*De;return Oe},I.prototype.readUint8=I.prototype.readUInt8=function(X,ee){return X=X>>>0,ee||gt(X,1,this.length),this[X]},I.prototype.readUint16LE=I.prototype.readUInt16LE=function(X,ee){return X=X>>>0,ee||gt(X,2,this.length),this[X]|this[X+1]<<8},I.prototype.readUint16BE=I.prototype.readUInt16BE=function(X,ee){return X=X>>>0,ee||gt(X,2,this.length),this[X]<<8|this[X+1]},I.prototype.readUint32LE=I.prototype.readUInt32LE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),(this[X]|this[X+1]<<8|this[X+2]<<16)+this[X+3]*16777216},I.prototype.readUint32BE=I.prototype.readUInt32BE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),this[X]*16777216+(this[X+1]<<16|this[X+2]<<8|this[X+3])},I.prototype.readBigUInt64LE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=ee+this[++X]*2**8+this[++X]*2**16+this[++X]*2**24,De=this[++X]+this[++X]*2**8+this[++X]*2**16+pe*2**24;return BigInt(Oe)+(BigInt(De)<<BigInt(32))}),I.prototype.readBigUInt64BE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=ee*2**24+this[++X]*2**16+this[++X]*2**8+this[++X],De=this[++X]*2**24+this[++X]*2**16+this[++X]*2**8+pe;return(BigInt(Oe)<<BigInt(32))+BigInt(De)}),I.prototype.readIntLE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=this[X],De=1,Le=0;for(;++Le<ee&&(De*=256);)Oe+=this[X+Le]*De;return De*=128,Oe>=De&&(Oe-=Math.pow(2,8*ee)),Oe},I.prototype.readIntBE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=ee,De=1,Le=this[X+--Oe];for(;Oe>0&&(De*=256);)Le+=this[X+--Oe]*De;return De*=128,Le>=De&&(Le-=Math.pow(2,8*ee)),Le},I.prototype.readInt8=function(X,ee){return X=X>>>0,ee||gt(X,1,this.length),this[X]&128?(255-this[X]+1)*-1:this[X]},I.prototype.readInt16LE=function(X,ee){X=X>>>0,ee||gt(X,2,this.length);const pe=this[X]|this[X+1]<<8;return pe&32768?pe|4294901760:pe},I.prototype.readInt16BE=function(X,ee){X=X>>>0,ee||gt(X,2,this.length);const pe=this[X+1]|this[X]<<8;return pe&32768?pe|4294901760:pe},I.prototype.readInt32LE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),this[X]|this[X+1]<<8|this[X+2]<<16|this[X+3]<<24},I.prototype.readInt32BE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),this[X]<<24|this[X+1]<<16|this[X+2]<<8|this[X+3]},I.prototype.readBigInt64LE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=this[X+4]+this[X+5]*2**8+this[X+6]*2**16+(pe<<24);return(BigInt(Oe)<<BigInt(32))+BigInt(ee+this[++X]*2**8+this[++X]*2**16+this[++X]*2**24)}),I.prototype.readBigInt64BE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=(ee<<24)+this[++X]*2**16+this[++X]*2**8+this[++X];return(BigInt(Oe)<<BigInt(32))+BigInt(this[++X]*2**24+this[++X]*2**16+this[++X]*2**8+pe)}),I.prototype.readFloatLE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),F.read(this,X,!0,23,4)},I.prototype.readFloatBE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),F.read(this,X,!1,23,4)},I.prototype.readDoubleLE=function(X,ee){return X=X>>>0,ee||gt(X,8,this.length),F.read(this,X,!0,52,8)},I.prototype.readDoubleBE=function(X,ee){return X=X>>>0,ee||gt(X,8,this.length),F.read(this,X,!1,52,8)};function it(se,X,ee,pe,Oe,De){if(!I.isBuffer(se))throw new TypeError('"buffer" argument must be a Buffer instance');if(X>Oe||X<De)throw new RangeError('"value" argument is out of bounds');if(ee+pe>se.length)throw new RangeError("Index out of range")}I.prototype.writeUintLE=I.prototype.writeUIntLE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,pe=pe>>>0,!Oe){const ut=Math.pow(2,8*pe)-1;it(this,X,ee,pe,ut,0)}let De=1,Le=0;for(this[ee]=X&255;++Le<pe&&(De*=256);)this[ee+Le]=X/De&255;return ee+pe},I.prototype.writeUintBE=I.prototype.writeUIntBE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,pe=pe>>>0,!Oe){const ut=Math.pow(2,8*pe)-1;it(this,X,ee,pe,ut,0)}let De=pe-1,Le=1;for(this[ee+De]=X&255;--De>=0&&(Le*=256);)this[ee+De]=X/Le&255;return ee+pe},I.prototype.writeUint8=I.prototype.writeUInt8=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,1,255,0),this[ee]=X&255,ee+1},I.prototype.writeUint16LE=I.prototype.writeUInt16LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,65535,0),this[ee]=X&255,this[ee+1]=X>>>8,ee+2},I.prototype.writeUint16BE=I.prototype.writeUInt16BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,65535,0),this[ee]=X>>>8,this[ee+1]=X&255,ee+2},I.prototype.writeUint32LE=I.prototype.writeUInt32LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,4294967295,0),this[ee+3]=X>>>24,this[ee+2]=X>>>16,this[ee+1]=X>>>8,this[ee]=X&255,ee+4},I.prototype.writeUint32BE=I.prototype.writeUInt32BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,4294967295,0),this[ee]=X>>>24,this[ee+1]=X>>>16,this[ee+2]=X>>>8,this[ee+3]=X&255,ee+4};function Zt(se,X,ee,pe,Oe){ct(X,pe,Oe,se,ee,7);let De=Number(X&BigInt(4294967295));se[ee++]=De,De=De>>8,se[ee++]=De,De=De>>8,se[ee++]=De,De=De>>8,se[ee++]=De;let Le=Number(X>>BigInt(32)&BigInt(4294967295));return se[ee++]=Le,Le=Le>>8,se[ee++]=Le,Le=Le>>8,se[ee++]=Le,Le=Le>>8,se[ee++]=Le,ee}function Rt(se,X,ee,pe,Oe){ct(X,pe,Oe,se,ee,7);let De=Number(X&BigInt(4294967295));se[ee+7]=De,De=De>>8,se[ee+6]=De,De=De>>8,se[ee+5]=De,De=De>>8,se[ee+4]=De;let Le=Number(X>>BigInt(32)&BigInt(4294967295));return se[ee+3]=Le,Le=Le>>8,se[ee+2]=Le,Le=Le>>8,se[ee+1]=Le,Le=Le>>8,se[ee]=Le,ee+8}I.prototype.writeBigUInt64LE=on(function(X,ee=0){return Zt(this,X,ee,BigInt(0),BigInt("0xffffffffffffffff"))}),I.prototype.writeBigUInt64BE=on(function(X,ee=0){return Rt(this,X,ee,BigInt(0),BigInt("0xffffffffffffffff"))}),I.prototype.writeIntLE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,!Oe){const St=Math.pow(2,8*pe-1);it(this,X,ee,pe,St-1,-St)}let De=0,Le=1,ut=0;for(this[ee]=X&255;++De<pe&&(Le*=256);)X<0&&ut===0&&this[ee+De-1]!==0&&(ut=1),this[ee+De]=(X/Le>>0)-ut&255;return ee+pe},I.prototype.writeIntBE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,!Oe){const St=Math.pow(2,8*pe-1);it(this,X,ee,pe,St-1,-St)}let De=pe-1,Le=1,ut=0;for(this[ee+De]=X&255;--De>=0&&(Le*=256);)X<0&&ut===0&&this[ee+De+1]!==0&&(ut=1),this[ee+De]=(X/Le>>0)-ut&255;return ee+pe},I.prototype.writeInt8=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,1,127,-128),X<0&&(X=255+X+1),this[ee]=X&255,ee+1},I.prototype.writeInt16LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,32767,-32768),this[ee]=X&255,this[ee+1]=X>>>8,ee+2},I.prototype.writeInt16BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,32767,-32768),this[ee]=X>>>8,this[ee+1]=X&255,ee+2},I.prototype.writeInt32LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,2147483647,-2147483648),this[ee]=X&255,this[ee+1]=X>>>8,this[ee+2]=X>>>16,this[ee+3]=X>>>24,ee+4},I.prototype.writeInt32BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,2147483647,-2147483648),X<0&&(X=4294967295+X+1),this[ee]=X>>>24,this[ee+1]=X>>>16,this[ee+2]=X>>>8,this[ee+3]=X&255,ee+4},I.prototype.writeBigInt64LE=on(function(X,ee=0){return Zt(this,X,ee,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),I.prototype.writeBigInt64BE=on(function(X,ee=0){return Rt(this,X,ee,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ue(se,X,ee,pe,Oe,De){if(ee+pe>se.length)throw new RangeError("Index out of range");if(ee<0)throw new RangeError("Index out of range")}function ot(se,X,ee,pe,Oe){return X=+X,ee=ee>>>0,Oe||Ue(se,X,ee,4),F.write(se,X,ee,pe,23,4),ee+4}I.prototype.writeFloatLE=function(X,ee,pe){return ot(this,X,ee,!0,pe)},I.prototype.writeFloatBE=function(X,ee,pe){return ot(this,X,ee,!1,pe)};function Jt(se,X,ee,pe,Oe){return X=+X,ee=ee>>>0,Oe||Ue(se,X,ee,8),F.write(se,X,ee,pe,52,8),ee+8}I.prototype.writeDoubleLE=function(X,ee,pe){return Jt(this,X,ee,!0,pe)},I.prototype.writeDoubleBE=function(X,ee,pe){return Jt(this,X,ee,!1,pe)},I.prototype.copy=function(X,ee,pe,Oe){if(!I.isBuffer(X))throw new TypeError("argument should be a Buffer");if(pe||(pe=0),!Oe&&Oe!==0&&(Oe=this.length),ee>=X.length&&(ee=X.length),ee||(ee=0),Oe>0&&Oe<pe&&(Oe=pe),Oe===pe||X.length===0||this.length===0)return 0;if(ee<0)throw new RangeError("targetStart out of bounds");if(pe<0||pe>=this.length)throw new RangeError("Index out of range");if(Oe<0)throw new RangeError("sourceEnd out of bounds");Oe>this.length&&(Oe=this.length),X.length-ee<Oe-pe&&(Oe=X.length-ee+pe);const De=Oe-pe;return this===X&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(ee,pe,Oe):Uint8Array.prototype.set.call(X,this.subarray(pe,Oe),ee),De},I.prototype.fill=function(X,ee,pe,Oe){if(typeof X=="string"){if(typeof ee=="string"?(Oe=ee,ee=0,pe=this.length):typeof pe=="string"&&(Oe=pe,pe=this.length),Oe!==void 0&&typeof Oe!="string")throw new TypeError("encoding must be a string");if(typeof Oe=="string"&&!I.isEncoding(Oe))throw new TypeError("Unknown encoding: "+Oe);if(X.length===1){const Le=X.charCodeAt(0);(Oe==="utf8"&&Le<128||Oe==="latin1")&&(X=Le)}}else typeof X=="number"?X=X&255:typeof X=="boolean"&&(X=Number(X));if(ee<0||this.length<ee||this.length<pe)throw new RangeError("Out of range index");if(pe<=ee)return this;ee=ee>>>0,pe=pe===void 0?this.length:pe>>>0,X||(X=0);let De;if(typeof X=="number")for(De=ee;De<pe;++De)this[De]=X;else{const Le=I.isBuffer(X)?X:I.from(X,Oe),ut=Le.length;if(ut===0)throw new TypeError('The value "'+X+'" is invalid for argument "value"');for(De=0;De<pe-ee;++De)this[De+ee]=Le[De%ut]}return this};const Nt={};function rt(se,X,ee){Nt[se]=class extends ee{constructor(){super(),Object.defineProperty(this,"message",{value:X.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${se}]`,this.stack,delete this.name}get code(){return se}set code(Oe){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:Oe,writable:!0})}toString(){return`${this.name} [${se}]: ${this.message}`}}}rt("ERR_BUFFER_OUT_OF_BOUNDS",function(se){return se?`${se} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),rt("ERR_INVALID_ARG_TYPE",function(se,X){return`The "${se}" argument must be of type number. Received type ${typeof X}`},TypeError),rt("ERR_OUT_OF_RANGE",function(se,X,ee){let pe=`The value of "${se}" is out of range.`,Oe=ee;return Number.isInteger(ee)&&Math.abs(ee)>2**32?Oe=tt(String(ee)):typeof ee=="bigint"&&(Oe=String(ee),(ee>BigInt(2)**BigInt(32)||ee<-(BigInt(2)**BigInt(32)))&&(Oe=tt(Oe)),Oe+="n"),pe+=` It must be ${X}. Received ${Oe}`,pe},RangeError);function tt(se){let X="",ee=se.length;const pe=se[0]==="-"?1:0;for(;ee>=pe+4;ee-=3)X=`_${se.slice(ee-3,ee)}${X}`;return`${se.slice(0,ee)}${X}`}function at(se,X,ee){wt(X,"offset"),(se[X]===void 0||se[X+ee]===void 0)&&Bt(X,se.length-(ee+1))}function ct(se,X,ee,pe,Oe,De){if(se>ee||se<X){const Le=typeof X=="bigint"?"n":"";let ut;throw X===0||X===BigInt(0)?ut=`>= 0${Le} and < 2${Le} ** ${(De+1)*8}${Le}`:ut=`>= -(2${Le} ** ${(De+1)*8-1}${Le}) and < 2 ** ${(De+1)*8-1}${Le}`,new Nt.ERR_OUT_OF_RANGE("value",ut,se)}at(pe,Oe,De)}function wt(se,X){if(typeof se!="number")throw new Nt.ERR_INVALID_ARG_TYPE(X,"number",se)}function Bt(se,X,ee){throw Math.floor(se)!==se?(wt(se,ee),new Nt.ERR_OUT_OF_RANGE("offset","an integer",se)):X<0?new Nt.ERR_BUFFER_OUT_OF_BOUNDS:new Nt.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${X}`,se)}const Lt=/[^+/0-9A-Za-z-_]/g;function Ft(se){if(se=se.split("=")[0],se=se.trim().replace(Lt,""),se.length<2)return"";for(;se.length%4!==0;)se=se+"=";return se}function Kt(se,X){X=X||1/0;let ee;const pe=se.length;let Oe=null;const De=[];for(let Le=0;Le<pe;++Le){if(ee=se.charCodeAt(Le),ee>55295&&ee<57344){if(!Oe){if(ee>56319){(X-=3)>-1&&De.push(239,191,189);continue}else if(Le+1===pe){(X-=3)>-1&&De.push(239,191,189);continue}Oe=ee;continue}if(ee<56320){(X-=3)>-1&&De.push(239,191,189),Oe=ee;continue}ee=(Oe-55296<<10|ee-56320)+65536}else Oe&&(X-=3)>-1&&De.push(239,191,189);if(Oe=null,ee<128){if((X-=1)<0)break;De.push(ee)}else if(ee<2048){if((X-=2)<0)break;De.push(ee>>6|192,ee&63|128)}else if(ee<65536){if((X-=3)<0)break;De.push(ee>>12|224,ee>>6&63|128,ee&63|128)}else if(ee<1114112){if((X-=4)<0)break;De.push(ee>>18|240,ee>>12&63|128,ee>>6&63|128,ee&63|128)}else throw new Error("Invalid code point")}return De}function Gt(se){const X=[];for(let ee=0;ee<se.length;++ee)X.push(se.charCodeAt(ee)&255);return X}function dn(se,X){let ee,pe,Oe;const De=[];for(let Le=0;Le<se.length&&!((X-=2)<0);++Le)ee=se.charCodeAt(Le),pe=ee>>8,Oe=ee%256,De.push(Oe),De.push(pe);return De}function nn(se){return K.toByteArray(Ft(se))}function rn(se,X,ee,pe){let Oe;for(Oe=0;Oe<pe&&!(Oe+ee>=X.length||Oe>=se.length);++Oe)X[Oe+ee]=se[Oe];return Oe}function Vt(se,X){return se instanceof X||se!=null&&se.constructor!=null&&se.constructor.name!=null&&se.constructor.name===X.name}function Qt(se){return se!==se}const gn=function(){const se="0123456789abcdef",X=new Array(256);for(let ee=0;ee<16;++ee){const pe=ee*16;for(let Oe=0;Oe<16;++Oe)X[pe+Oe]=se[ee]+se[Oe]}return X}();function on(se){return typeof BigInt>"u"?Yt:se}function Yt(){throw new Error("BigInt not supported")}}(buffer)),buffer}var toolsEbml={},hasRequiredToolsEbml;function requireToolsEbml(){if(hasRequiredToolsEbml)return toolsEbml;hasRequiredToolsEbml=1;var q=toolsEbml&&toolsEbml.__assign||function(){return q=Object.assign||function(D){for(var N,O=1,I=arguments.length;O<I;O++){N=arguments[O];for(var z in N)Object.prototype.hasOwnProperty.call(N,z)&&(D[z]=N[z])}return D},q.apply(this,arguments)},K=toolsEbml&&toolsEbml.__spreadArray||function(D,N,O){if(O||arguments.length===2)for(var I=0,z=N.length,J;I<z;I++)(J||!(I in N))&&(J||(J=Array.prototype.slice.call(N,0,I)),J[I]=N[I]);return D.concat(J||Array.prototype.slice.call(N))};Object.defineProperty(toolsEbml,"__esModule",{value:!0});var F=requireTools(),Z=function(){function D(){}return D.readVint=function(N,O){O===void 0&&(O=0);var I=8-Math.floor(Math.log2(N[O]));if(I>8){var z=D.readHexString(N,O,O+I);throw new Error("Unrepresentable length: ".concat(I," ").concat(z))}if(O+I>N.length)return null;for(var J=N[O]&(1<<8-I)-1,Q=1;Q<I;Q+=1){if(Q===7&&J>=Math.pow(2,8)&&N[O+7]>0)return{length:I,value:-1};J*=Math.pow(2,8),J+=N[O+Q]}return{length:I,value:J}},D.writeVint=function(N){if(N<0||N>Math.pow(2,53))throw new Error("Unrepresentable value: ".concat(N));var O=1;for(O=1;O<=8&&!(N<Math.pow(2,7*O)-1);O+=1);for(var I=F.Buffer.alloc(O),z=N,J=1;J<=O;J+=1){var Q=z&255;I[O-J]=Q,z-=Q,z/=Math.pow(2,8)}return I[0]|=1<<8-O,I},D.concatenate=function(N,O){return!N&&!O?F.Buffer.from([]):!N||N.byteLength===0?O:!O||O.byteLength===0?N:F.Buffer.from(K(K([],N,!0),O,!0))},D.readHexString=function(N,O,I){return O===void 0&&(O=0),I===void 0&&(I=N.byteLength),Array.from(N.slice(O,I)).map(function(z){return Number(z).toString(16)}).reduce(function(z,J){return"".concat(z).concat(J.padStart(2,"0"))},"")},D.readUtf8=function(N){try{return F.Buffer.from(N).toString("utf8")}catch{return null}},D.readUnsigned=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 1:return O.getUint8(0);case 2:return O.getUint16(0);case 4:return O.getUint32(0)}return N.byteLength<=6?N.reduce(function(I,z){return I*256+z},0):D.readHexString(N,0,N.byteLength)},D.readSigned=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 1:return O.getInt8(0);case 2:return O.getInt16(0);case 4:return O.getInt32(0);default:return NaN}},D.readFloat=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 4:return O.getFloat32(0);case 8:return O.getFloat64(0);default:return NaN}},D.readDate=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 1:return new Date(O.getUint8(0));case 2:return new Date(O.getUint16(0));case 4:return new Date(O.getUint32(0));case 8:return new Date(Number.parseInt(D.readHexString(N),16));default:return new Date(0)}},D.readDataFromTag=function(N,O){var I=N.type,z=N.name,J=N.track,Q=N.discardable||!1,ne=N.keyframe||!1,re=null,te;switch(I){case"u":te=D.readUnsigned(O);break;case"f":te=D.readFloat(O);break;case"i":te=D.readSigned(O);break;case"s":te=String.fromCharCode.apply(String,O);break;case"8":te=D.readUtf8(O);break;case"d":te=D.readDate(O);break}if(z==="SimpleBlock"||z==="Block"){var oe=0,le=D.readVint(O,oe),ae=le.length,ce=le.value;oe+=ae,J=ce,te=D.readSigned(O.subarray(oe,oe+2)),oe+=2,z==="SimpleBlock"&&(ne=!!(O[ae+2]&128),Q=!!(O[ae+2]&1)),oe+=1,re=O.subarray(oe)}return q(q({},N),{data:O,discardable:Q,keyframe:ne,payload:re,track:J,value:te})},D}();return toolsEbml.default=Z,toolsEbml}var vint,hasRequiredVint;function requireVint(){return hasRequiredVint||(hasRequiredVint=1,vint=function(q,K,F){K=K||0;for(var Z=1;Z<=8&&!(q[K]>=Math.pow(2,8-Z));Z++);if(Z>8)throw new Error("Unrepresentable length: "+Z+" "+q.toString("hex",K,K+Z));if(K+Z>q.length)return null;var D,N=q[K]&(1<<8-Z)-1;for(D=1;D<Z;D++){if(D===7&&N>=Math.pow(2,45)&&q[K+7]>0)return{length:Z,value:-1};N*=Math.pow(2,8),N+=q[K+D]}return F&&(N-=Math.pow(2,Z*7-1)-1),{length:Z,value:N}}),vint}var bufferReader,hasRequiredBufferReader;function requireBufferReader(){if(hasRequiredBufferReader)return bufferReader;hasRequiredBufferReader=1;var q=requireVint();function K(F){this.buffer=F,this.offset=0}return K.prototype.nextInt16BE=function(){var F=this.buffer.readInt16BE(this.offset);return this.offset+=2,F},K.prototype.nextUInt8=function(){var F=this.buffer.readUInt8(this.offset);return this.offset+=1,F},K.prototype.nextUIntV=function(){var F=q(this.buffer,this.offset);return this.offset+=F.length,F.value},K.prototype.nextIntV=function(){var F=q(this.buffer,this.offset,!0);return this.offset+=F.length,F.value},K.prototype.nextBuffer=function(F){var Z=F?this.buffer.slice(this.offset,this.offset+F):this.buffer.slice(this.offset);return this.offset+=F||this.length,Z},Object.defineProperty(K.prototype,"length",{get:function(){return this.buffer.length-this.offset}}),bufferReader=K,bufferReader}var ebmlBlock,hasRequiredEbmlBlock;function requireEbmlBlock(){if(hasRequiredEbmlBlock)return ebmlBlock;hasRequiredEbmlBlock=1;var q=requireBufferReader(),K=1,F=3,Z=2;ebmlBlock=function(N){var O={},I=new q(N);O.trackNumber=I.nextUIntV(),O.timecode=I.nextInt16BE();var z=I.nextUInt8();O.invisible=!!(z&8),O.keyframe=!!(z&128),O.discardable=!!(z&1);var J=(z&6)>>1;return O.frames=D(I,J),O};function D(N,O){if(!O)return[N.nextBuffer()];var I,z,J=[],Q=N.nextUInt8()+1;if(O===Z){if(N.length%Q!==0)throw new Error("Fixed-Size Lacing Error");for(z=N.length/Q,I=0;I<Q;I++)J.push(N.nextBuffer(z));return J}var ne=[];if(O===K)for(I=0;I<Q-1;I++){var re;z=0;do re=N.nextUInt8(),z+=re;while(re===255);ne.push(z)}else if(O===F)for(z=N.nextUIntV(),ne.push(z),I=1;I<Q-1;I++)z+=N.nextIntV(),ne.push(z);for(I=0;I<Q-1;I++)J.push(N.nextBuffer(ne[I]));return J.push(N.nextBuffer()),J}return ebmlBlock}var hasRequiredTools;function requireTools(){return hasRequiredTools||(hasRequiredTools=1,function(q){Object.defineProperty(q,"__esModule",{value:!0}),q.convertEBMLDateToJSDate=q.createFloatBuffer=q.createIntBuffer=q.createUIntBuffer=q.encodeValueToBuffer=q.concat=q.putRefinedMetaData=q.extractElement=q.removeElement=q.makeMetadataSeekable=q.createRIFFChunk=q.VP8BitStreamToRiffWebPBuffer=q.WebPBlockFilter=q.encodeTag=q.readBlock=q.ebmlBlock=q.writeVint=q.readVint=q.Buffer=void 0;var K=requireInt64Buffer(),F=requireEBMLEncoder(),Z=requireBuffer(),D=requireToolsEbml(),N=requireEbmlBlock();q.Buffer=Z.Buffer,q.readVint=D.default.readVint,q.writeVint=D.default.writeVint,q.ebmlBlock=N;function O(_e){return(0,q.ebmlBlock)(new q.Buffer(_e))}q.readBlock=O;function I(_e,Te,qe){return qe===void 0&&(qe=!1),fe([_e,qe?new q.Buffer("01ffffffffffffff","hex"):(0,q.writeVint)(Te.length),Te])}q.encodeTag=I;function z(_e){return _e.reduce(function(Te,qe){if(qe.type!=="b"||qe.name!=="SimpleBlock")return Te;var Ve=(0,q.ebmlBlock)(qe.data),We=Ve.frames.some(function(Fe){var Ot=Fe.slice(3,6).toString("hex");return Ot==="9d012a"});return We?Te.concat(qe):Te},[])}q.WebPBlockFilter=z;function J(_e){var Te=Q("VP8 ",_e),qe=fe([new q.Buffer("WEBP","ascii"),Te]);return Q("RIFF",qe)}q.VP8BitStreamToRiffWebPBuffer=J;function Q(_e,Te){var qe=new q.Buffer(4);return qe.writeUInt32LE(Te.byteLength,0),fe([new q.Buffer(_e.substr(0,4),"ascii"),qe,Te,new q.Buffer(Te.byteLength%2===0?0:1)])}q.createRIFFChunk=Q;function ne(_e,Te,qe){var Ve=te("EBML",_e),We=le(Ve),Fe=We+12,Ot=_e[_e.length-1].dataEnd-Fe,It=te("Info",_e);re("Duration",It),It.splice(1,0,{name:"Duration",type:"f",data:ke(Te,8)});for(var Dt=le(It),zt=te("Tracks",_e),Ut=le(zt),gt=47,it=[],Zt=5+qe.length*15,Rt=[],Ue=-1,ot=10,Jt=function(ct){var wt=gt,Bt=wt+Dt,Lt=Bt+Ut,Ft=Lt+Zt,Kt=Ft-Ot;if(it=[],it.push({name:"SeekHead",type:"m",isEnd:!1}),it.push({name:"Seek",type:"m",isEnd:!1}),it.push({name:"SeekID",type:"b",data:new q.Buffer([21,73,169,102])}),it.push({name:"SeekPosition",type:"u",data:me(wt)}),it.push({name:"Seek",type:"m",isEnd:!0}),it.push({name:"Seek",type:"m",isEnd:!1}),it.push({name:"SeekID",type:"b",data:new q.Buffer([22,84,174,107])}),it.push({name:"SeekPosition",type:"u",data:me(Bt)}),it.push({name:"Seek",type:"m",isEnd:!0}),it.push({name:"Seek",type:"m",isEnd:!1}),it.push({name:"SeekID",type:"b",data:new q.Buffer([28,83,187,107])}),it.push({name:"SeekPosition",type:"u",data:me(Lt)}),it.push({name:"Seek",type:"m",isEnd:!0}),it.push({name:"SeekHead",type:"m",isEnd:!0}),gt=le(it),Rt=[],Rt.push({name:"Cues",type:"m",isEnd:!1}),qe.forEach(function(Gt){var dn=Gt.CueTrack,nn=Gt.CueClusterPosition,rn=Gt.CueTime;Rt.push({name:"CuePoint",type:"m",isEnd:!1}),Rt.push({name:"CueTime",type:"u",data:me(rn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Rt.push({name:"CueTrack",type:"u",data:me(dn)}),nn-=Fe,nn+=Kt,Rt.push({name:"CueClusterPosition",type:"u",data:me(nn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Rt.push({name:"CuePoint",type:"m",isEnd:!0})}),Rt.push({name:"Cues",type:"m",isEnd:!0}),Zt=le(Rt),Ue!==Kt){if(Ue=Kt,ct===ot-1)throw new Error("Failed to converge to a stable metadata size")}else return"break"},Nt=0;Nt<ot;Nt++){var rt=Jt(Nt);if(rt==="break")break}var tt=[].concat.apply([],[Ve,{name:"Segment",type:"m",isEnd:!1,unknownSize:!0},it,It,zt,Rt]),at=new F.default().encode(tt);return at}q.makeMetadataSeekable=ne;function re(_e,Te){for(var qe=-1,Ve=0;Ve<Te.length;Ve++){var We=Te[Ve];if(We.name===_e)if(We.type==="m")if(!We.isEnd)qe=Ve;else{if(qe==-1)throw new Error("Detected ".concat(_e," closing element before finding the start"));Te.splice(qe,Ve-qe+1);return}else{Te.splice(Ve,1);return}}}q.removeElement=re;function te(_e,Te){for(var qe=[],Ve=-1,We=0;We<Te.length;We++){var Fe=Te[We];if(Fe.name===_e)if(Fe.type==="m")if(!Fe.isEnd)Ve=We;else{if(Ve==-1)throw new Error("Detected ".concat(_e," closing element before finding the start"));qe=Te.slice(Ve,We+1);break}else{qe.push(Te[We]);break}}return qe}q.extractElement=te;function oe(_e,Te){Array.isArray(Te.cueInfos)&&!Array.isArray(Te.cues)&&(console.warn("putRefinedMetaData: info.cueInfos property is deprecated. please use info.cues"),Te.cues=Te.cueInfos);for(var qe=[],Ve=[],We=0;We<_e.length;We++){var Fe=_e[We];if(Fe.type==="m"&&Fe.name==="Segment"){if(qe=_e.slice(0,We),Ve=_e.slice(We),Fe.unknownSize){Ve.shift();break}throw new Error("this metadata is not streaming webm file")}}if(!(Ve[Ve.length-1].dataEnd>0))throw new Error("metadata dataEnd has wrong number");var Ot=Ve[Ve.length-1].dataEnd,It=qe[qe.length-1].dataEnd,Dt=new F.default().encode(qe).byteLength,zt=Dt-It,Ut=Ot-Ve[0].tagStart;Ve[0].tagStart-It,Ve[0].tagStart;var gt=new q.Buffer([24,83,128,103]),it=new q.Buffer("01ffffffffffffff","hex"),Zt=gt.byteLength+it.byteLength,Rt=Ut,Ue;for(Ue=1;Ue<20;Ue++){var ot=It+Zt+Rt,Jt=ot-Ot,Nt=zt+Jt,rt=ae(Ve,Nt,Te),tt=new F.default().encode(rt).byteLength;if(tt===Rt)return new F.default().encode([].concat(qe,[{type:"m",name:"Segment",isEnd:!1,unknownSize:!0}],rt));Rt=tt}throw new Error("unable to refine metadata, stable size could not be found in "+Ue+" iterations!")}q.putRefinedMetaData=oe;function le(_e){var Te=new F.default;return _e.reduce(function(qe,Ve){return qe.concat(Te.encode([Ve]))},[]).reduce(function(qe,Ve){return qe+Ve.byteLength},0)}function ae(_e,Te,qe){var Ve=qe.duration,We=qe.clusterPtrs,Fe=qe.cues,Ot=_e.slice(0);if(typeof Ve=="number"){var It=!1;Ot.forEach(function(zt){zt.type==="f"&&zt.name==="Duration"&&(It=!0,zt.data=ke(Ve,8))}),It||we(Ot,"Info",[{name:"Duration",type:"f",data:ke(Ve,8)}])}Array.isArray(Fe)&&we(Ot,"Cues",de(Fe,Te));var Dt=[];return Array.isArray(We)&&(console.warn("append cluster pointers to seekhead is deprecated. please use cues"),Dt=ce(We,Te)),we(Ot,"SeekHead",Dt,!0),Ot}function ce(_e,Te){var qe=[];return _e.forEach(function(Ve){qe.push({name:"Seek",type:"m",isEnd:!1}),qe.push({name:"SeekID",type:"b",data:new q.Buffer([31,67,182,117])}),qe.push({name:"SeekPosition",type:"u",data:me(Ve+Te)}),qe.push({name:"Seek",type:"m",isEnd:!0})}),qe}function de(_e,Te){var qe=[];return _e.forEach(function(Ve){var We=Ve.CueTrack,Fe=Ve.CueClusterPosition,Ot=Ve.CueTime;qe.push({name:"CuePoint",type:"m",isEnd:!1}),qe.push({name:"CueTime",type:"u",data:me(Ot)}),qe.push({name:"CueTrackPositions",type:"m",isEnd:!1}),qe.push({name:"CueTrack",type:"u",data:me(We)}),qe.push({name:"CueClusterPosition",type:"u",data:me(Fe+Te)}),qe.push({name:"CueTrackPositions",type:"m",isEnd:!0}),qe.push({name:"CuePoint",type:"m",isEnd:!0})}),qe}function we(_e,Te,qe,Ve){Ve===void 0&&(Ve=!1);for(var We=-1,Fe=0;Fe<_e.length;Fe++){var Ot=_e[Fe];if(Ot.type==="m"&&Ot.name===Te&&Ot.isEnd===!1){We=Fe;break}}We>=0?Array.prototype.splice.apply(_e,[We+1,0].concat(qe)):Ve?[].concat([{name:Te,type:"m",isEnd:!1}],qe,[{name:Te,type:"m",isEnd:!0}]).reverse().forEach(function(It){_e.unshift(It)}):(_e.push({name:Te,type:"m",isEnd:!1}),qe.forEach(function(It){_e.push(It)}),_e.push({name:Te,type:"m",isEnd:!0}))}function fe(_e){return q.Buffer.concat(_e)}q.concat=fe;function ge(_e){var Te=new q.Buffer(0);if(_e.type==="m")return _e;switch(_e.type){case"u":Te=me(_e.value);break;case"i":Te=ve(_e.value);break;case"f":Te=ke(_e.value);break;case"s":Te=new q.Buffer(_e.value,"ascii");break;case"8":Te=new q.Buffer(_e.value,"utf8");break;case"b":Te=_e.value;break;case"d":Te=new K.Int64BE(_e.value.getTime().toString()).toBuffer();break}return Object.assign({},_e,{data:Te})}q.encodeValueToBuffer=ge;function me(_e){for(var Te=1;_e>=Math.pow(2,8*Te);Te++);if(Te>=7)return console.warn("7bit or more bigger uint not supported."),new K.Uint64BE(_e).toBuffer();var qe=new q.Buffer(Te);return qe.writeUIntBE(_e,0,Te),qe}q.createUIntBuffer=me;function ve(_e){for(var Te=1;_e>=Math.pow(2,8*Te);Te++);if(Te>=7)return console.warn("7bit or more bigger uint not supported."),new K.Int64BE(_e).toBuffer();var qe=new q.Buffer(Te);return qe.writeIntBE(_e,0,Te),qe}q.createIntBuffer=ve;function ke(_e,Te){if(Te===void 0&&(Te=8),Te===8){var qe=new q.Buffer(8);return qe.writeDoubleBE(_e,0),qe}else if(Te===4){var qe=new q.Buffer(4);return qe.writeFloatBE(_e,0),qe}else throw new Error("float type bits must 4bytes or 8bytes")}q.createFloatBuffer=ke;function xe(_e){return _e instanceof Date?_e:new Date(new Date("2001-01-01T00:00:00.000Z").getTime()+Number(_e)/1e3/1e3)}q.convertEBMLDateToJSDate=xe}(tools)),tools}var hasRequiredEBMLDecoder;function requireEBMLDecoder(){if(hasRequiredEBMLDecoder)return EBMLDecoder;hasRequiredEBMLDecoder=1,Object.defineProperty(EBMLDecoder,"__esModule",{value:!0});var q=requireInt64Buffer(),K=requireTools(),F=requireTools(),Z=requireEbmlID(),D;(function(O){O[O.STATE_TAG=1]="STATE_TAG",O[O.STATE_SIZE=2]="STATE_SIZE",O[O.STATE_CONTENT=3]="STATE_CONTENT"})(D||(D={}));var N=function(){function O(){this._buffer=new K.Buffer(0),this._tag_stack=[],this._state=D.STATE_TAG,this._cursor=0,this._total=0,this._schema=Z.byEbmlID,this._result=[]}return O.prototype.decode=function(I){this.readChunk(I);var z=this._result;return this._result=[],z},O.prototype.readChunk=function(I){for(this._buffer=F.concat([this._buffer,new K.Buffer(I)]);this._cursor<this._buffer.length&&!(this._state===D.STATE_TAG&&!this.readTag()||this._state===D.STATE_SIZE&&!this.readSize()||this._state===D.STATE_CONTENT&&!this.readContent()););},O.prototype.getSchemaInfo=function(I){return this._schema[I]||{name:"unknown",level:-1,type:"unknown",description:"unknown"}},O.prototype.readTag=function(){if(this._cursor>=this._buffer.length)return!1;var I=(0,K.readVint)(this._buffer,this._cursor);if(I==null)return!1;var z=this._buffer.slice(this._cursor,this._cursor+I.length),J=z.reduce(function(re,te,oe,le){return re+te*Math.pow(16,2*(le.length-1-oe))},0),Q=this.getSchemaInfo(J),ne={EBML_ID:J.toString(16),schema:Q,type:Q.type,name:Q.name,level:Q.level,tagStart:this._total,tagEnd:this._total+I.length,sizeStart:this._total+I.length,sizeEnd:null,dataStart:null,dataEnd:null,dataSize:null,data:null};return this._tag_stack.push(ne),this._cursor+=I.length,this._total+=I.length,this._state=D.STATE_SIZE,!0},O.prototype.readSize=function(){if(this._cursor>=this._buffer.length)return!1;var I=(0,K.readVint)(this._buffer,this._cursor);if(I==null)return!1;var z=this._tag_stack[this._tag_stack.length-1];return z.sizeEnd=z.sizeStart+I.length,z.dataStart=z.sizeEnd,z.dataSize=I.value,I.value===-1?(z.dataEnd=-1,z.type==="m"&&(z.unknownSize=!0)):z.dataEnd=z.sizeEnd+I.value,this._cursor+=I.length,this._total+=I.length,this._state=D.STATE_CONTENT,!0},O.prototype.readContent=function(){var I=this._tag_stack[this._tag_stack.length-1];if(I.type==="m"){if(I.isEnd=!1,this._result.push(I),this._state=D.STATE_TAG,I.dataSize===0){var z=Object.assign({},I,{isEnd:!0});this._result.push(z),this._tag_stack.pop()}return!0}if(this._buffer.length<this._cursor+I.dataSize)return!1;var J=this._buffer.slice(this._cursor,this._cursor+I.dataSize);switch(this._buffer=this._buffer.slice(this._cursor+I.dataSize),I.data=J,I.type){case"u":I.value=J.readUIntBE(0,J.length);break;case"i":I.value=J.readIntBE(0,J.length);break;case"f":I.value=I.dataSize===4?J.readFloatBE(0):I.dataSize===8?J.readDoubleBE(0):(console.warn("cannot read ".concat(I.dataSize," octets float. failback to 0")),0);break;case"s":I.value=J.toString("ascii");break;case"8":I.value=J.toString("utf8");break;case"b":I.value=J;break;case"d":I.value=(0,K.convertEBMLDateToJSDate)(new q.Int64BE(J).toNumber());break}if(I.value===null)throw new Error("unknown tag type:"+I.type);for(this._result.push(I),this._total+=I.dataSize,this._state=D.STATE_TAG,this._cursor=0,this._tag_stack.pop();this._tag_stack.length>0;){var Q=this._tag_stack[this._tag_stack.length-1];if(Q.dataEnd<0)return this._tag_stack.pop(),!0;if(this._total<Q.dataEnd)break;if(Q.type!=="m")throw new Error("parent element is not master element");var z=Object.assign({},Q,{isEnd:!0});this._result.push(z),this._tag_stack.pop()}return!0},O}();return EBMLDecoder.default=N,EBMLDecoder}var EBMLReader={},events={exports:{}},hasRequiredEvents;function requireEvents(){if(hasRequiredEvents)return events.exports;hasRequiredEvents=1;var q=typeof Reflect=="object"?Reflect:null,K=q&&typeof q.apply=="function"?q.apply:function(ge,me,ve){return Function.prototype.apply.call(ge,me,ve)},F;q&&typeof q.ownKeys=="function"?F=q.ownKeys:Object.getOwnPropertySymbols?F=function(ge){return Object.getOwnPropertyNames(ge).concat(Object.getOwnPropertySymbols(ge))}:F=function(ge){return Object.getOwnPropertyNames(ge)};function Z(fe){console&&console.warn&&console.warn(fe)}var D=Number.isNaN||function(ge){return ge!==ge};function N(){N.init.call(this)}events.exports=N,events.exports.once=ce,N.EventEmitter=N,N.prototype._events=void 0,N.prototype._eventsCount=0,N.prototype._maxListeners=void 0;var O=10;function I(fe){if(typeof fe!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof fe)}Object.defineProperty(N,"defaultMaxListeners",{enumerable:!0,get:function(){return O},set:function(fe){if(typeof fe!="number"||fe<0||D(fe))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+fe+".");O=fe}}),N.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},N.prototype.setMaxListeners=function(ge){if(typeof ge!="number"||ge<0||D(ge))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+ge+".");return this._maxListeners=ge,this};function z(fe){return fe._maxListeners===void 0?N.defaultMaxListeners:fe._maxListeners}N.prototype.getMaxListeners=function(){return z(this)},N.prototype.emit=function(ge){for(var me=[],ve=1;ve<arguments.length;ve++)me.push(arguments[ve]);var ke=ge==="error",xe=this._events;if(xe!==void 0)ke=ke&&xe.error===void 0;else if(!ke)return!1;if(ke){var _e;if(me.length>0&&(_e=me[0]),_e instanceof Error)throw _e;var Te=new Error("Unhandled error."+(_e?" ("+_e.message+")":""));throw Te.context=_e,Te}var qe=xe[ge];if(qe===void 0)return!1;if(typeof qe=="function")K(qe,this,me);else for(var Ve=qe.length,We=oe(qe,Ve),ve=0;ve<Ve;++ve)K(We[ve],this,me);return!0};function J(fe,ge,me,ve){var ke,xe,_e;if(I(me),xe=fe._events,xe===void 0?(xe=fe._events=Object.create(null),fe._eventsCount=0):(xe.newListener!==void 0&&(fe.emit("newListener",ge,me.listener?me.listener:me),xe=fe._events),_e=xe[ge]),_e===void 0)_e=xe[ge]=me,++fe._eventsCount;else if(typeof _e=="function"?_e=xe[ge]=ve?[me,_e]:[_e,me]:ve?_e.unshift(me):_e.push(me),ke=z(fe),ke>0&&_e.length>ke&&!_e.warned){_e.warned=!0;var Te=new Error("Possible EventEmitter memory leak detected. "+_e.length+" "+String(ge)+" listeners added. Use emitter.setMaxListeners() to increase limit");Te.name="MaxListenersExceededWarning",Te.emitter=fe,Te.type=ge,Te.count=_e.length,Z(Te)}return fe}N.prototype.addListener=function(ge,me){return J(this,ge,me,!1)},N.prototype.on=N.prototype.addListener,N.prototype.prependListener=function(ge,me){return J(this,ge,me,!0)};function Q(){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 ne(fe,ge,me){var ve={fired:!1,wrapFn:void 0,target:fe,type:ge,listener:me},ke=Q.bind(ve);return ke.listener=me,ve.wrapFn=ke,ke}N.prototype.once=function(ge,me){return I(me),this.on(ge,ne(this,ge,me)),this},N.prototype.prependOnceListener=function(ge,me){return I(me),this.prependListener(ge,ne(this,ge,me)),this},N.prototype.removeListener=function(ge,me){var ve,ke,xe,_e,Te;if(I(me),ke=this._events,ke===void 0)return this;if(ve=ke[ge],ve===void 0)return this;if(ve===me||ve.listener===me)--this._eventsCount===0?this._events=Object.create(null):(delete ke[ge],ke.removeListener&&this.emit("removeListener",ge,ve.listener||me));else if(typeof ve!="function"){for(xe=-1,_e=ve.length-1;_e>=0;_e--)if(ve[_e]===me||ve[_e].listener===me){Te=ve[_e].listener,xe=_e;break}if(xe<0)return this;xe===0?ve.shift():le(ve,xe),ve.length===1&&(ke[ge]=ve[0]),ke.removeListener!==void 0&&this.emit("removeListener",ge,Te||me)}return this},N.prototype.off=N.prototype.removeListener,N.prototype.removeAllListeners=function(ge){var me,ve,ke;if(ve=this._events,ve===void 0)return this;if(ve.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):ve[ge]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete ve[ge]),this;if(arguments.length===0){var xe=Object.keys(ve),_e;for(ke=0;ke<xe.length;++ke)_e=xe[ke],_e!=="removeListener"&&this.removeAllListeners(_e);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(me=ve[ge],typeof me=="function")this.removeListener(ge,me);else if(me!==void 0)for(ke=me.length-1;ke>=0;ke--)this.removeListener(ge,me[ke]);return this};function re(fe,ge,me){var ve=fe._events;if(ve===void 0)return[];var ke=ve[ge];return ke===void 0?[]:typeof ke=="function"?me?[ke.listener||ke]:[ke]:me?ae(ke):oe(ke,ke.length)}N.prototype.listeners=function(ge){return re(this,ge,!0)},N.prototype.rawListeners=function(ge){return re(this,ge,!1)},N.listenerCount=function(fe,ge){return typeof fe.listenerCount=="function"?fe.listenerCount(ge):te.call(fe,ge)},N.prototype.listenerCount=te;function te(fe){var ge=this._events;if(ge!==void 0){var me=ge[fe];if(typeof me=="function")return 1;if(me!==void 0)return me.length}return 0}N.prototype.eventNames=function(){return this._eventsCount>0?F(this._events):[]};function oe(fe,ge){for(var me=new Array(ge),ve=0;ve<ge;++ve)me[ve]=fe[ve];return me}function le(fe,ge){for(;ge+1<fe.length;ge++)fe[ge]=fe[ge+1];fe.pop()}function ae(fe){for(var ge=new Array(fe.length),me=0;me<ge.length;++me)ge[me]=fe[me].listener||fe[me];return ge}function ce(fe,ge){return new Promise(function(me,ve){function ke(_e){fe.removeListener(ge,xe),ve(_e)}function xe(){typeof fe.removeListener=="function"&&fe.removeListener("error",ke),me([].slice.call(arguments))}we(fe,ge,xe,{once:!0}),ge!=="error"&&de(fe,ke,{once:!0})})}function de(fe,ge,me){typeof fe.on=="function"&&we(fe,"error",ge,me)}function we(fe,ge,me,ve){if(typeof fe.on=="function")ve.once?fe.once(ge,me):fe.on(ge,me);else if(typeof fe.addEventListener=="function")fe.addEventListener(ge,function ke(xe){ve.once&&fe.removeEventListener(ge,ke),me(xe)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof fe)}return events.exports}var hasRequiredEBMLReader;function requireEBMLReader(){if(hasRequiredEBMLReader)return EBMLReader;hasRequiredEBMLReader=1;var q=EBMLReader&&EBMLReader.__extends||function(){var D=function(N,O){return D=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,z){I.__proto__=z}||function(I,z){for(var J in z)Object.prototype.hasOwnProperty.call(z,J)&&(I[J]=z[J])},D(N,O)};return function(N,O){if(typeof O!="function"&&O!==null)throw new TypeError("Class extends value "+String(O)+" is not a constructor or null");D(N,O);function I(){this.constructor=N}N.prototype=O===null?Object.create(O):(I.prototype=O.prototype,new I)}}();Object.defineProperty(EBMLReader,"__esModule",{value:!0});var K=requireEvents(),F=requireTools(),Z=function(D){q(N,D);function N(){var O=D.call(this)||this;return O.logGroup="",O.hasLoggingStarted=!1,O.metadataloaded=!1,O.chunks=[],O.stack=[],O.segmentOffset=0,O.last2SimpleBlockVideoTrackTimecode=[0,0],O.last2SimpleBlockAudioTrackTimecode=[0,0],O.lastClusterTimecode=0,O.lastClusterPosition=0,O.timecodeScale=1e6,O.metadataSize=0,O.metadatas=[],O.cues=[],O.firstVideoBlockRead=!1,O.firstAudioBlockRead=!1,O.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null},O.trackTypes=[],O.trackDefaultDuration=[],O.trackCodecDelay=[],O.trackInfo={type:"nothing"},O.ended=!1,O.logging=!1,O.use_duration_every_simpleblock=!1,O.use_webp=!1,O.use_segment_info=!0,O.drop_default_duration=!0,O}return N.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()},N.prototype.emit_segment_info=function(){var O=this.chunks;if(this.chunks=[],this.metadataloaded){if(!this.use_segment_info)return;var J=this.lastClusterTimecode,Q=this.duration,ne=this.timecodeScale;this.emit("cluster",{timecode:J,data:O}),this.emit("duration",{timecodeScale:ne,duration:Q})}else{this.metadataloaded=!0,this.metadatas=O;var I=this.trackTypes.indexOf(1),z=this.trackTypes.indexOf(2);if(this.trackInfo=I>=0&&z>=0?{type:"both",trackNumber:I}:I>=0?{type:"video",trackNumber:I}:z>=0?{type:"audio",trackNumber:z}:{type:"nothing"},!this.use_segment_info)return;this.emit("metadata",{data:O,metadataSize:this.metadataSize})}},N.prototype.read=function(O){var I=this,z=!1;if(!this.ended){if(O.type==="m")if(O.isEnd)this.stack.pop();else{var J=this.stack[this.stack.length-1];if(J!=null&&J.level>=O.level){this.stack.pop(),this.logging&&console.groupEnd(),J.dataEnd=O.dataEnd,J.dataSize=O.dataEnd-J.dataStart,J.unknownSize=!1;var Q=Object.assign({},J,{name:J.name,type:J.type,isEnd:!0});this.chunks.push(Q)}this.stack.push(O)}if(O.type==="m"&&O.name=="Segment")this.segmentOffset!=0&&console.warn("Multiple segments detected!"),this.segmentOffset=O.dataStart,this.emit("segment_offset",this.segmentOffset);else if(O.type==="b"&&O.name==="SimpleBlock"){var ne=F.ebmlBlock(O.data),re=ne.timecode,te=ne.trackNumber,oe=ne.frames;if(this.trackTypes[te]===1){if(!this.firstVideoBlockRead&&(this.firstVideoBlockRead=!0,this.trackInfo.type==="both"||this.trackInfo.type==="video")){var le=this.lastClusterTimecode+re;this.cues.push({CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le}),this.emit("cue_info",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le})}this.last2SimpleBlockVideoTrackTimecode=[this.last2SimpleBlockVideoTrackTimecode[1],re]}else if(this.trackTypes[te]===2){if(!this.firstAudioBlockRead&&(this.firstAudioBlockRead=!0,this.trackInfo.type==="audio")){var le=this.lastClusterTimecode+re;this.cues.push({CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le}),this.emit("cue_info",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le})}this.last2SimpleBlockAudioTrackTimecode=[this.last2SimpleBlockAudioTrackTimecode[1],re]}this.use_duration_every_simpleblock&&this.emit("duration",{timecodeScale:this.timecodeScale,duration:this.duration}),this.use_webp&&oe.forEach(function(ae){var ce=ae.slice(3,6).toString("hex");if(ce==="9d012a"){var de=F.VP8BitStreamToRiffWebPBuffer(ae),we=new Blob([de],{type:"image/webp"}),fe=I.duration;I.emit("webp",{currentTime:fe,webp:we})}})}else O.type==="m"&&O.name==="Cluster"&&O.isEnd===!1?(this.firstVideoBlockRead=!1,this.firstAudioBlockRead=!1,this.emit_segment_info(),this.emit("cluster_ptr",O.tagStart),this.lastClusterPosition=O.tagStart):O.type==="u"&&O.name==="Timecode"?this.lastClusterTimecode=O.value:O.type==="u"&&O.name==="TimecodeScale"?this.timecodeScale=O.value:O.type==="m"&&O.name==="TrackEntry"?O.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}:O.type==="u"&&O.name==="TrackType"?this.currentTrack.TrackType=O.value:O.type==="u"&&O.name==="TrackNumber"?this.currentTrack.TrackNumber=O.value:O.type==="u"&&O.name==="CodecDelay"?this.currentTrack.CodecDelay=O.value:O.type==="u"&&O.name==="DefaultDuration"?this.drop_default_duration?(console.warn("DefaultDuration detected!, remove it"),z=!0):this.currentTrack.DefaultDuration=O.value:O.name==="unknown"&&console.warn(O);!this.metadataloaded&&O.dataEnd>0&&(this.metadataSize=O.dataEnd),z||this.chunks.push(O),this.logging&&this.put(O)}},Object.defineProperty(N.prototype,"duration",{get:function(){if(this.trackInfo.type==="nothing")return console.warn("no video, no audio track"),0;var O=0,I=0,z=0,J=this.trackDefaultDuration[this.trackInfo.trackNumber];if(typeof J=="number")O=J;else if(this.trackInfo.type==="both")if(this.last2SimpleBlockAudioTrackTimecode[1]>this.last2SimpleBlockVideoTrackTimecode[1]){O=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackTypes.indexOf(2)];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockAudioTrackTimecode[1]}else{O=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackTypes.indexOf(1)];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="video"){O=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackInfo.trackNumber];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="audio"){O=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackInfo.trackNumber];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockAudioTrackTimecode[1]}var ne=(this.lastClusterTimecode+z)*this.timecodeScale+O-I,re=ne/this.timecodeScale;return Math.floor(re)},enumerable:!1,configurable:!0}),N.prototype.addListener=function(O,I){return D.prototype.addListener.call(this,O,I)},N.prototype.put=function(O){this.hasLoggingStarted||(this.hasLoggingStarted=!0,this.logging&&this.logGroup&&console.groupCollapsed(this.logGroup)),O.type==="m"?O.isEnd?console.groupEnd():console.group(O.name+":"+O.tagStart):O.type==="b"?console.log(O.name,O.type):console.log(O.name,O.tagStart,O.type,O.value)},N}(K.EventEmitter);return EBMLReader.default=Z,EBMLReader}var hasRequiredEbml;function requireEbml(){return hasRequiredEbml||(hasRequiredEbml=1,function(q){var K=ebml&&ebml.__createBinding||(Object.create?function(I,z,J,Q){Q===void 0&&(Q=J),Object.defineProperty(I,Q,{enumerable:!0,get:function(){return z[J]}})}:function(I,z,J,Q){Q===void 0&&(Q=J),I[Q]=z[J]}),F=ebml&&ebml.__exportStar||function(I,z){for(var J in I)J!=="default"&&!Object.prototype.hasOwnProperty.call(z,J)&&K(z,I,J)};Object.defineProperty(q,"__esModule",{value:!0}),q.tools=q.Reader=q.Encoder=q.Decoder=void 0,F(requireEBML(),q);var Z=requireEBMLDecoder();q.Decoder=Z.default;var D=requireEBMLEncoder();q.Encoder=D.default;var N=requireEBMLReader();q.Reader=N.default;var O=requireTools();q.tools=O}(ebml)),ebml}var hasRequiredLib;function requireLib(){if(hasRequiredLib)return lib;hasRequiredLib=1;var q=lib&&lib.__awaiter||function(D,N,O,I){function z(J){return J instanceof O?J:new O(function(Q){Q(J)})}return new(O||(O=Promise))(function(J,Q){function ne(oe){try{te(I.next(oe))}catch(le){Q(le)}}function re(oe){try{te(I.throw(oe))}catch(le){Q(le)}}function te(oe){oe.done?J(oe.value):z(oe.value).then(ne,re)}te((I=I.apply(D,N||[])).next())})},K=lib&&lib.__generator||function(D,N){var O={label:0,sent:function(){if(J[0]&1)throw J[1];return J[1]},trys:[],ops:[]},I,z,J,Q;return Q={next:ne(0),throw:ne(1),return:ne(2)},typeof Symbol=="function"&&(Q[Symbol.iterator]=function(){return this}),Q;function ne(te){return function(oe){return re([te,oe])}}function re(te){if(I)throw new TypeError("Generator is already executing.");for(;O;)try{if(I=1,z&&(J=te[0]&2?z.return:te[0]?z.throw||((J=z.return)&&J.call(z),0):z.next)&&!(J=J.call(z,te[1])).done)return J;switch(z=0,J&&(te=[te[0]&2,J.value]),te[0]){case 0:case 1:J=te;break;case 4:return O.label++,{value:te[1],done:!1};case 5:O.label++,z=te[1],te=[0];continue;case 7:te=O.ops.pop(),O.trys.pop();continue;default:if(J=O.trys,!(J=J.length>0&&J[J.length-1])&&(te[0]===6||te[0]===2)){O=0;continue}if(te[0]===3&&(!J||te[1]>J[0]&&te[1]<J[3])){O.label=te[1];break}if(te[0]===6&&O.label<J[1]){O.label=J[1],J=te;break}if(J&&O.label<J[2]){O.label=J[2],O.ops.push(te);break}J[2]&&O.ops.pop(),O.trys.pop();continue}te=N.call(D,O)}catch(oe){te=[6,oe],z=0}finally{I=J=0}if(te[0]&5)throw te[1];return{value:te[0]?te[1]:void 0,done:!0}}};Object.defineProperty(lib,"__esModule",{value:!0});var F=requireEbml();function Z(D){return q(this,void 0,void 0,function(){var N,O,I,z,J,Q,ne,re,te,oe,le,ae;return K(this,function(ce){switch(ce.label){case 0:if(!D)throw Error("call to fixWebmDuration requires a blob");N=new F.Decoder,O=new F.Reader,I=D.stream(),z=I.getReader(),ce.label=1;case 1:return[4,z.read()];case 2:return J=ce.sent(),Q=J.done,ne=J.value,Q?(O.stop(),[3,3]):(re=N.decode(ne),re=re==null?void 0:re.filter(function(de){return de.type!=="unknown"}),re.forEach(function(de){O.read(de)}),ne=null,[3,1]);case 3:return te=F.tools.makeMetadataSeekable(O.metadatas,O.duration,O.cues),oe=new Blob([te],{type:D.type}),le=D.slice(O.metadataSize),ae=new Blob([oe,le],{type:D.type}),[2,ae]}})})}return lib.default=Z,lib}var libExports=requireLib();const fixWebmDuration=getDefaultExportFromCjs(libExports);class StreamRecorder{constructor(){st(this,en);st(this,yn,!1);st(this,pn,!1);st(this,xn,0);st(this,Cn,0);st(this,cn,0);st(this,un,0);st(this,vn,0);Ie(this,"onchange",K=>{});Ie(this,"onDurationChange",K=>{});Ie(this,"start",async(K="")=>{K||(K=`video_Record_${E$1(Date.now())}`);let F=[];return navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}).then(Z=>{const D=Z.getTracks();for(const O of D)O.onended=()=>this.stop();At(this,yn,!0),At(this,pn,!1),At(this,en,new MediaRecorder(Z)),Be(this,en).start();const N=new Date().getTime();At(this,xn,N),At(this,cn,N),Be(this,bn).call(this),Be(this,Rn).call(this),Be(this,en).addEventListener("dataavailable",O=>{F.push(O.data)}),Be(this,en).addEventListener("stop",async()=>{At(this,yn,!1);const O=new Date().getTime();At(this,Cn,O),At(this,un,Be(this,un)+(O-Be(this,cn))),Be(this,bn).call(this),clearInterval(Be(this,vn));const I=Z.getTracks();for(const re of I)re.stop();if(Be(this,en)===null)return;const z=new Blob(F,{type:Be(this,en).mimeType}),J=await fixWebmDuration(z),Q=URL.createObjectURL(J),ne=document.createElement("a");ne.href=Q,ne.download=`${K}.mp4`,ne.click(),URL.revokeObjectURL(Q),F=[],At(this,en,null)})})});Ie(this,"pause",async()=>{var F;await new Promise(Z=>setTimeout(()=>Z(!0),300)),(F=Be(this,en))==null||F.pause(),At(this,pn,!0);const K=new Date().getTime();At(this,un,Be(this,un)+(K-Be(this,cn))),Be(this,bn).call(this),clearInterval(Be(this,vn))});Ie(this,"resume",async()=>{var F;(F=Be(this,en))==null||F.resume(),At(this,pn,!1);const K=new Date().getTime();At(this,cn,K),Be(this,bn).call(this),Be(this,Rn).call(this)});Ie(this,"stop",async()=>{var K;(K=Be(this,en))==null||K.stop()});Ie(this,"getDuration",()=>{if(Be(this,cn)===0)return 0;let K=Be(this,un);const F=new Date().getTime();if(Be(this,yn)&&Be(this,pn)===!1){const Z=F-Be(this,cn);At(this,cn,F),K=K+Z}return K});Ie(this,"getInfo",()=>({active:Be(this,yn),pause:Be(this,pn),startTime:Be(this,xn),endTime:Be(this,Cn),duration:Be(this,un)}));st(this,bn,()=>{const K=this.getInfo();this.onchange(K)});st(this,Rn,()=>{clearInterval(Be(this,vn)),At(this,vn,window.setInterval(()=>{At(this,un,this.getDuration()),this.onDurationChange(Be(this,un))},500))})}}en=new WeakMap,yn=new WeakMap,pn=new WeakMap,xn=new WeakMap,Cn=new WeakMap,cn=new WeakMap,un=new WeakMap,vn=new WeakMap,bn=new WeakMap,Rn=new WeakMap;class RoomBase{constructor(K){Ie(this,"options",{appid:"",sdkToken:"",roomId:"",userId:"",earlyId:"",callType:0,debug:!1,reportErr:!0,logUrl:"https://logs.putplay.cc",newPublishAutoSubscribe:!0});Ie(this,"sdk_service_version","1.0.6");Ie(this,"prohibitNotify",!1);Ie(this,"isEarly",!1);Ie(this,"isInRoom",!1);Ie(this,"taskQueue");Ie(this,"roomState","ready");Ie(this,"createAt",Date.now());Ie(this,"cwsIns");Ie(this,"peerIns");Ie(this,"transceiverMap",new Map);Ie(this,"sendChannel");Ie(this,"receiveChannel");Ie(this,"userMap",new Map);Ie(this,"setLocalStreamActiveMap",new Map);Ie(this,"phoneyStreams",new Map);Ie(this,"recorder",new StreamRecorder);Ie(this,"networkQualityTester",new NetworkQualityTester);Ie(this,"mediaDevicesErrInfo",{microphoneCamera_audio:"",microphoneCamera_video:"",screenSharing_video:"",screenSharing_audio:""});Ie(this,"reportLogs",(K,F="未知错误")=>{const{appid:Z,userId:D,earlyId:N="",logUrl:O,reportErr:I}=this.options;if(!I)return;const z="web",J=Q=>({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})[Q].toString();{const Q=J(K),ne={origin:z,type:Q,app_id:Z,user_id:D,ins_id:N,desc:F},re=btoa(encodeURI(JSON.stringify(ne))),te=`${O}/upload/log?log_key=${re}`;{const oe=localStorage.getItem("#quickvo.logs")||JSON.stringify([]),ae=new TextEncoder().encode(oe),ce=pako.deflate(ae,{gzip:!0});this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: reportLogs",{obj:ne,url:te,size:lt(ce.byteLength)}),fetch(te,{headers:{"Content-Type":"multipart/form-data"},method:"POST",body:ce})}}});Ie(this,"initPhoneyStreams",(K,F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F){const D=this.phoneyStreams.get(Z);if(D){const N=D.getTracks();for(const O of N)O.stop()}switch(Z){case"microphoneCamera_audio":this.phoneyStreams.set("microphoneCamera_audio",createMutedAudioStream(K));break;case"microphoneCamera_video":this.phoneyStreams.set("microphoneCamera_video",createFakeVideoStream());break;case"screenSharing_audio":this.phoneyStreams.set("screenSharing_audio",createMutedAudioStream(K));break;case"screenSharing_video":this.phoneyStreams.set("screenSharing_video",createFakeVideoStream());break}}});Ie(this,"getPhoneyStreams",K=>this.phoneyStreams.get(K));Ie(this,"getRoomInfo",()=>{const{options:K,roomState:F,createAt:Z}=this;return{...K,roomState:F,createAt:Z}});Ie(this,"setRoomState",K=>{this.roomState=K;const F=enum_roomState[K],Z={state:K,stateStr:F};this.cwsIns.emitNotify("onRoomState",{code:200,data:Z,desc:"room state is change."})});Ie(this,"setOptions",async K=>{const F={...this.options,...K};this.options=F});Ie(this,"stopStream",async K=>{const F=K.getTracks();for(const Z of F)Z.stop()});Ie(this,"getMediaDevicesErrInfo",async()=>{try{const K=await navigator.mediaDevices.enumerateDevices();K.find(Z=>Z.kind==="audioinput")||(this.mediaDevicesErrInfo.microphoneCamera_audio="audioinput is not available."),K.find(Z=>Z.kind==="videoinput")||(this.mediaDevicesErrInfo.microphoneCamera_video="videoinput is not available.")}catch(K){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getMediaDevicesErrInfo is error.",K)}return this.mediaDevicesErrInfo});Ie(this,"getUserMediaKey",(K,F)=>`${K}-${F}`);Ie(this,"getCallAction",async K=>{let F="";const Z=N=>K.findIndex(({type:I,enabled:z=!0})=>I===N&&z)===-1?"0":"1";return F=`${Z(0)}${F}`,F=`${Z(1)}${F}`,F=`${Z(2)}${F}`,F=`${Z(3)}${F}`,parseInt(F,2)});Ie(this,"getCallActionMap",(K=0)=>{const Z=Number(K).toString(2).padStart(4,"0").split(""),[D,N,O,I]=Z;return{microphoneCamera_audio:!!Number(I),microphoneCamera_video:!!Number(O),screenSharing_video:!!Number(N),screenSharing_audio:!!Number(D)}});Ie(this,"getBanBehaviorMap",(K=0)=>{const Z=Number(K).toString(2).padStart(4,"0").split(""),[D,N,O,I]=Z;return{microphoneCamera_audio:!!Number(I),microphoneCamera_video:!!Number(O),screenSharing_video:!!Number(N),screenSharing_audio:!!Number(D)}});Ie(this,"getAverageVolume",(K,F)=>{K.getByteFrequencyData(F);let Z=0;for(let N=0;N<F.length;N++)Z+=F[N];return Math.ceil(Z/F.length)});Ie(this,"getTrackNamesFormTracks",(K,F=[],Z="trackName")=>{const D=[];for(const N of K){const{type:O}=N;if(F.length===0||F.includes(O)){const I=N[Z];I&&D.push(`${I}`)}}return D});Ie(this,"usersFilter",K=>dt(K,["id","isSelf","isOwner","joinTime","tracks","network","permissions","isPublished","updateStreams","callAction","callActionStr","callActionMap","banBehavior","banBehaviorStr","banBehaviorMap"]).sort((D,N)=>D.id.localeCompare(N.id,"en")));this.setOptions(K),this.cwsIns=new CallsWebSocket({...K}),this.taskQueue=new Y(["createWs","createSession","ice","joinRoom","createTrack","publish","subscribe","renegotiate","closeTrack"],{debug:K.debug}),this.taskQueue.setCondition("createSession",!1),this.taskQueue.setCondition("ice",!1),this.options.debug&&this.networkQualityTester.testAll().then(F=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: networkQualityTester",F)})}}var m=Object.defineProperty,G=(q,K,F)=>K in q?m(q,K,{enumerable:!0,configurable:!0,writable:!0,value:F}):q[K]=F,e$1=(q,K,F)=>G(q,typeof K!="symbol"?K+"":K,F);class g{constructor(K,F){e$1(this,"inputStream",new MediaStream),e$1(this,"outputStream",new MediaStream),e$1(this,"inputGain",1),e$1(this,"enhanceGain",1),e$1(this,"bgsGain",1),e$1(this,"bgmGain",1),e$1(this,"outputGain",1),e$1(this,"mixAudioMap",new Map),e$1(this,"audioContext",new AudioContext),e$1(this,"sourceNode"),e$1(this,"inputGainNode"),e$1(this,"enhanceGainNode"),e$1(this,"bgsGainNode"),e$1(this,"bgmGainNode"),e$1(this,"analyserNode"),e$1(this,"analyserArrayData"),e$1(this,"outputGainNode"),e$1(this,"destinationNode"),e$1(this,"filterStream",Z=>Z),e$1(this,"stop",()=>{{const Z=this.inputStream.getTracks();for(const D of Z)D.stop(),this.inputStream.removeTrack(D)}}),e$1(this,"getStream",()=>this.filterStream(this.outputStream)),e$1(this,"setMute",(Z=!0)=>{Z?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),e$1(this,"setInputGain",Z=>{this.inputGain=Z,this.inputGainNode.gain.setValueAtTime(Z,this.audioContext.currentTime)}),e$1(this,"setEnhanceGain",async Z=>{this.enhanceGain=Z+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),e$1(this,"setBgsGain",Z=>{this.bgsGain=Z,this.bgsGainNode.gain.setValueAtTime(Z,this.audioContext.currentTime)}),e$1(this,"setBgmGain",Z=>{this.bgmGain=Z,this.bgmGainNode.gain.setValueAtTime(Z,this.audioContext.currentTime)}),e$1(this,"setOutputGain",Z=>{this.outputGain=Z,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),e$1(this,"getVolume",()=>{const{analyserNode:Z,analyserArrayData:D}=this;Z.getByteFrequencyData(D);let N=0;for(let O=0;O<D.length;O++)N+=D[O];return Math.ceil(N/D.length)}),e$1(this,"mixAudio",(Z,D="bgm")=>new Promise(async(N,O)=>{try{{const J=this.mixAudioMap.get(D);J&&J.stop()}const I=D==="bgs"?this.bgsGainNode:this.bgmGainNode,z=this.audioContext.createBufferSource();this.mixAudioMap.set(D,z),z.buffer=Z,z.connect(I),z.onended=()=>{z.disconnect(I),this.mixAudioMap.delete(D),N(!0)},z.start(0)}catch(I){O(I)}})),e$1(this,"mixAudioStop",Z=>{const D=this.mixAudioMap.get(Z);D==null||D.stop()}),e$1(this,"changeMix",(Z,D)=>{const N=Z==="bgs"?this.bgsGainNode:this.bgmGainNode;D?N.connect(this.destinationNode):N.disconnect(this.destinationNode)}),F&&(this.audioContext=F),this.inputStream=K,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:Z,inputGainNode:D,enhanceGainNode:N,bgsGainNode:O,bgmGainNode:I,analyserNode:z,outputGainNode:J,destinationNode:Q}=this;Z.connect(D),D.connect(N),N.connect(z),O.connect(z),I.connect(z),N.connect(Q),O.connect(Q),I.connect(Q),z.connect(J),J.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}class RoomMedias extends RoomBase{constructor(F){super(F);st(this,kn,[]);st(this,tn,new Map);st(this,jt,new Map);st(this,ln,new Map);st(this,fn,new Map);st(this,mn,new Map);Ie(this,"localStreamsActionMap",new Map);st(this,Sn,new Map);Ie(this,"audioContext",new(window.AudioContext||window.webkitAudioContext));Ie(this,"initMediaPhoneyStreams",(F=[])=>this.initPhoneyStreams(this.audioContext,F));Ie(this,"initLocalStreamsFilter",()=>{for(const F of mediaType_keys){const Z=async D=>D;Be(this,Sn).set(F,Z)}});Ie(this,"setLocalFilterStream",(F,Z)=>{Be(this,Sn).set(F,Z)});st(this,Ln,()=>{Be(this,jt).set("microphoneCamera_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0}),Be(this,jt).set("microphoneCamera_video",{frameRate:{min:10,ideal:30}}),Be(this,jt).set("screenSharing_video",{frameRate:{min:10,ideal:30}}),Be(this,jt).set("screenSharing_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0})});st(this,Fn,()=>{Be(this,tn).set("audioinput","default"),Be(this,tn).set("videoinput","default"),Be(this,tn).set("audiooutput","default")});Ie(this,"emitNotifyUpdateUsersStreams",async F=>{this.cwsIns.emitNotify("onRoomUsersStreams",{code:200,data:F,desc:"users streams is change."})});Ie(this,"initUserMediaStreamContext",async(F,Z,D)=>{const[N]=D.getTracks();if(!N){console.warn("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: tracks.length is 0.",{userId:F,mediaType:Z,stream:D});return}this.removeUserMediaStreamContext(F,Z);const O=this.getUserMediaKey(F,Z),{kind:I}=N;switch(I){case"audio":{const z=new MediaStream;z.addTrack(N);const J=new g(z,this.audioContext);Be(this,ln).set(O,J)}break;case"video":{const z=new VideoMediaContext(N);Be(this,fn).set(O,z)}break}});Ie(this,"getUserMediaStreamContext",(F,Z)=>{const D=this.getUserMediaKey(F,Z);if(["microphoneCamera_audio","screenSharing_audio"].includes(Z))return Be(this,ln).get(D);if(["microphoneCamera_video","screenSharing_video"].includes(Z))return Be(this,fn).get(D)});Ie(this,"getUserAudioMediaStreamContext",(F,Z)=>{const D=this.getUserMediaKey(F,Z);return Be(this,ln).get(D)});Ie(this,"removeUserMediaStreamContext",(F,Z)=>{const D=this.getUserMediaKey(F,Z);if(["microphoneCamera_audio","screenSharing_audio"].includes(Z)){const N=Be(this,ln).get(D);return N==null||N.stop(),Be(this,ln).delete(D)}if(["microphoneCamera_video","screenSharing_video"].includes(Z)){const N=Be(this,fn).get(D);return N==null||N.stop(),Be(this,fn).get(D)}});Ie(this,"getUserStream",(F,Z)=>{const D=this.getUserMediaStreamContext(F,Z);return(D==null?void 0:D.getStream())||new MediaStream});Ie(this,"getUserStreams",(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);const D={};for(const N of Z){const O=this.getUserStream(F,N);D[N]=O}return D});Ie(this,"removeUserStreams",async(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);for(const D of Z)this.removeUserMediaStreamContext(F,D)});Ie(this,"clearUserStreams",()=>{{const F=Be(this,ln).values();for(const Z of F)Z.stop();At(this,ln,new Map)}{const F=Be(this,fn).values();for(const Z of F)Z.stop();At(this,fn,new Map)}});Ie(this,"setMediaTrackConstraints",async(F,Z)=>{Be(this,jt).set(F,Z);const D=await this.getLocalStream(F);if(!D)return;const N=D.getTracks();if(N.length!==0)for(const O of N){const I=O.getConstraints(),J={...Be(this,jt).get(F),...I,...Z};await O.applyConstraints(J)}});Ie(this,"stopLocalStreams",async(F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F){const D=Be(this,mn).get(Z);D&&await this.stopStream(D),Be(this,mn).delete(Z)}});Ie(this,"addLocalStream",(F,Z)=>{const D=Be(this,mn).get(F);D&&this.stopStream(D),Be(this,mn).set(F,Z)});Ie(this,"initLocalStream",async F=>{switch(F){case"microphoneCamera_audio":{const Z=Be(this,tn).get("audioinput"),D=Be(this,jt).get("microphoneCamera_audio"),N=await navigator.mediaDevices.getUserMedia({audio:{deviceId:Z,...D},video:!1});this.addLocalStream("microphoneCamera_audio",N)}break;case"microphoneCamera_video":{const Z=Be(this,tn).get("videoinput"),D=Be(this,jt).get("microphoneCamera_video"),N=await navigator.mediaDevices.getUserMedia({audio:!1,video:{deviceId:Z,...D}});this.addLocalStream("microphoneCamera_video",N)}break;case"microphoneCamera":{const Z=Be(this,tn).get("audioinput"),D=Be(this,tn).get("videoinput"),N=Be(this,jt).get("microphoneCamera_audio"),O=Be(this,jt).get("microphoneCamera_video"),z=(await navigator.mediaDevices.getUserMedia({audio:{deviceId:Z,...N},video:{deviceId:D,...O}})).getTracks();for(const J of z){const{kind:Q}=J;if(Q==="audio"){const ne=new MediaStream;ne.addTrack(J),this.addLocalStream("microphoneCamera_audio",ne)}if(Q==="video"){const ne=new MediaStream;ne.addTrack(J),this.addLocalStream("microphoneCamera_video",ne)}}}break;case"screenSharing_audio":{const Z=Be(this,jt).get("screenSharing_audio"),N=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...Z})).getTracks();for(const O of N){const{kind:I}=O;if(I==="audio"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_audio",z)}}}break;case"screenSharing_video":{const Z=Be(this,jt).get(F),N=(await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0,...Z})).getTracks();for(const O of N){const{kind:I}=O;if(I==="video"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_video",z)}}}break;case"screenSharing":{const Z=Be(this,jt).get("screenSharing_audio"),D=Be(this,jt).get("screenSharing_video"),O=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...Z,...D})).getTracks();for(const I of O){const{kind:z}=I;if(z==="audio"){const J=new MediaStream;J.addTrack(I),this.addLocalStream("screenSharing_audio",J)}if(z==="video"){const J=new MediaStream;J.addTrack(I),this.addLocalStream("screenSharing_video",J)}}}break}});Ie(this,"getLocalStream",async F=>{const Z=Be(this,mn).get(F),D=Be(this,Sn).get(F);let N=Z;return Z&&D&&(N=await D(Z)),N});Ie(this,"getLocalStreams",async(F=[])=>{F.length===0&&(F=mediaType_keys);const Z={};for(const D of F)Z[D]=await this.getLocalStream(D);return Z});st(this,Tn,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(F=>{const Z=F.filter(D=>!["default","communications"].includes(D.deviceId));At(this,kn,Z.sort((D,N)=>D.label.localeCompare(N.label,"zh-Hans-CN",{sensitivity:"accent"})))}).catch(function(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getEnumerateDevices is err",F)}),Be(this,kn)));st(this,Hn,()=>{navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=async()=>{await Be(this,Tn).call(this),this.cwsIns.emitNotify("onDevicechange",{code:200,data:{},desc:"device is change."})}),Be(this,Tn).call(this)});Ie(this,"getMediaDeviceKind",F=>Be(this,tn).get(F));Ie(this,"changeAudiooutput",async()=>{try{const F=Be(this,tn).get("audiooutput");await this.audioContext.setSinkId(F)}catch(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSinkId is error.",F)}});Ie(this,"setDeviceKind",(F,Z)=>{Be(this,tn).set(F,Z)});Ie(this,"setAudioOutputDevice",F=>this.setDeviceKind("audiooutput",F));Ie(this,"getEnumerateDevices",async F=>(await Be(this,Tn).call(this),Be(this,kn).filter(D=>D.kind===F)));Ie(this,"getEnumerateAudioinputDevices",()=>this.getEnumerateDevices("audioinput"));Ie(this,"getEnumerateAudioOutputDevices",()=>this.getEnumerateDevices("audiooutput"));Ie(this,"getEnumerateVideoinputDevices",()=>this.getEnumerateDevices("videoinput"));Be(this,Hn).call(this),Be(this,Fn).call(this),Be(this,Ln).call(this),this.initPhoneyStreams(this.audioContext),document.addEventListener("click",()=>{var Z;((Z=this.audioContext)==null?void 0:Z.state)==="suspended"&&this.audioContext.resume()})}}kn=new WeakMap,tn=new WeakMap,jt=new WeakMap,ln=new WeakMap,fn=new WeakMap,mn=new WeakMap,Sn=new WeakMap,Ln=new WeakMap,Fn=new WeakMap,Tn=new WeakMap,Hn=new WeakMap;class RoomUsers extends RoomMedias{constructor(F){super(F);Ie(this,"getMaxVolumeUser",()=>{const F=Array.from(this.userMap.values(),({id:D})=>D);if(F.length===0)return;let Z=[];for(const D of F){const N=this.getUserAudioMediaStreamContext(D,"microphoneCamera_audio");if(!N)continue;const O=N.getVolume();Z.push({id:D,volume:O})}return Z=Z.sort((D,N)=>D.volume-N.volume>0?-1:1),Z[0]});Ie(this,"setVolume",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setInputGain(D)});Ie(this,"setEnhanceGain",async(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setEnhanceGain(D)});Ie(this,"setSpeaker",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setOutputGain(D);const O=D===0;N==null||N.setMute(O)});Ie(this,"playBgs",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);return N==null?void 0:N.mixAudio(D,"bgs")});Ie(this,"setBgsGain",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setBgsGain(D)});Ie(this,"stopBgs",(F,Z)=>{const D=this.getUserAudioMediaStreamContext(F,Z);D==null||D.mixAudioStop("bgs")});Ie(this,"playBgm",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);return N==null?void 0:N.mixAudio(D,"bgm")});Ie(this,"setBgmGain",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setBgmGain(D)});Ie(this,"stopBgm",(F,Z)=>{const D=this.getUserAudioMediaStreamContext(F,Z);D==null||D.mixAudioStop("bgm")});Ie(this,"changBgsMix",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.changeMix("bgs",D)});Ie(this,"changBgmMix",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.changeMix("bgm",D)});Ie(this,"getVolume",(F,Z)=>{const D=this.getUserAudioMediaStreamContext(F,Z);return D==null?void 0:D.getVolume()});Ie(this,"clearUsers",()=>{this.userMap=new Map});Ie(this,"removeUsers",async F=>{for(const Z of F)this.userMap.delete(Z),await this.removeUserStreams(Z)});Ie(this,"createUser",async F=>{const Z=Date.now(),D={id:F,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:F===this.options.userId,isPublished:!1,joinTime:Z,updateAt:Z,network:{egress:0,ingress:0},tracks:[],channels:[],updateStreams:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1}};this.userMap.set(F,D)});Ie(this,"getUser",async F=>(this.userMap.has(F)||await this.createUser(F),this.userMap.get(F)));Ie(this,"getUsers",async(F=[])=>{F.length===0&&(F=[...this.userMap.keys()]);const Z=[];for(const D of F){const N=await this.getUser(D);Z.push(N)}return Z});Ie(this,"getAllUserTrackMids",async()=>{const F=await this.getUsers(),Z=[];for(const D of F){const{tracks:N=[]}=D;for(const O of N)Z.push(O.mid)}return Z});Ie(this,"getUserTrackByTrackName",async F=>{const Z=await this.getUsers(),D=[];for(const N of Z){const{tracks:O=[]}=N;for(const I of O){const{trackName:z}=I;F.includes(z)&&D.push(I)}}return D});Ie(this,"getUserTrackFromMid",async F=>{const Z=await this.getUsers();let D;for(const N of Z){const{tracks:O=[]}=N;for(const I of O)if(I.mid===F){D=I;break}}return D});Ie(this,"checkUserInRoom",F=>this.userMap.has(F));Ie(this,"getUsersId",async()=>[...this.userMap.keys()]);Ie(this,"getSelfInfo",async()=>await this.getUser(this.options.userId));Ie(this,"updateIsPublished",async(F,Z=!1)=>{const D=await this.getUser(F);D.isPublished=Z});Ie(this,"setUserUpdateStreams",async(F,Z,D=!0)=>{const N=await this.getUser(F),O={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};O[Z]=D,N.updateStreams=O});Ie(this,"updateUserChannels",async(F,Z=[],D)=>{const N=await this.getUser(F);D&&(Z=[...N.channels,...Z]),N.channels=Z});Ie(this,"updateUsertracks",async(F,Z=[],D)=>{const N=await this.getUser(F);D&&(Z=[...N.tracks,...Z]),Z=Z.filter(({mid:z=""})=>z!==""),Z=pt(Z,["type"]),Z=Z.sort((z,J)=>z.type-J.type<0?-1:1);for(const z of Z)z.userId=F,z.mediaType=mediaType_keys[z.type],z.enabled===void 0&&(z.enabled=!0);N.updateStreams={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};const O=dt(N.tracks,["mediaType","enabled","mid","msid","trackName"]),I=dt(Z,["mediaType","enabled","mid","msid","trackName"]);{const z="microphoneCamera_audio",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}{const z="microphoneCamera_video",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}{const z="screenSharing_audio",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}{const z="screenSharing_video",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}N.tracks=Z});Ie(this,"updateUserCallAction",async(F,Z=0)=>{const D=await this.getUser(F);D.callAction=Z,D.callActionStr=Z.toString(2).padStart(4,"0"),D.callActionMap=this.getCallActionMap(Z)});Ie(this,"updateUserBehaviors",async(F,Z=0)=>{const D=await this.getUser(F);D.banBehavior=Z,D.banBehaviorStr=Z.toString(2).padStart(4,"0"),D.banBehaviorMap=this.getBanBehaviorMap(Z)});Ie(this,"updateUserNetwork",async(F,Z={egress:5,ingress:5})=>{const D=await this.getUser(F);D.network=Z});Ie(this,"updateUserPermissions",async(F,Z)=>{if(Z){const D=await this.getUser(F);D.permissions=Z}});Ie(this,"updateUserBase",async F=>{const Z=await this.getUser(F);Z.isSelf=F===this.options.userId,Z.updateAt=Date.now()});Ie(this,"updateUsers",async F=>{for(const Z of F){const{id:D,tracks:N,callAction:O,permissions:I,isPublished:z}=Z;await this.updateUserBase(D),await this.updateIsPublished(D,z),await this.updateUserPermissions(D,I),await this.updateUsertracks(D,N,!0),await this.updateUserCallAction(D,O),await this.updateUserNetwork(D)}});Ie(this,"emitNotifyUpdateUser",async F=>{const Z=await this.getUsers([F]),[D]=this.usersFilter(Z);this.cwsIns.emitNotify("onRoomUser",{code:200,data:D,desc:"user info is change."})});Ie(this,"emitNotifyUpdateUsers",async()=>{const F=await this.getUsers(),Z=this.usersFilter(F);this.cwsIns.emitNotify("onRoomUsers",{code:200,data:Z,desc:"all users info is change."})})}}const t=(q,K=4294967295,F=79764919)=>{const Z=new Int32Array(256);let D,N,O,I=K;for(D=0;D<256;D++){for(O=D<<24,N=8;N>0;--N)O=2147483648&O?O<<1^F:O<<1;Z[D]=O}for(D=0;D<q.length;D++)I=I<<8^Z[255&(I>>24^q[D])];return I},e=(q,K=t)=>{const F=ae=>new Uint8Array(ae.length/2).map((ce,de)=>parseInt(ae.substring(2*de,2*(de+1)),16)),Z=ae=>F(ae)[0],D=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach((ae,ce)=>D.set(ae,ce));const N=new Uint8Array(q.length);let O,I,z,J=!1,Q=0,ne=42,re=q.length>13&&q.substring(0,9)==="dynEncode",te=0;re&&(te=11,I=Z(q.substring(9,te)),I<=1&&(te+=2,ne=Z(q.substring(11,te))),I===1&&(te+=8,z=(ae=>new DataView(F(ae).buffer).getInt32(0,!0))(q.substring(13,te))));const oe=256-ne;for(let ae=te;ae<q.length;ae++)if(O=q.charCodeAt(ae),O!==61||J){if(O===92&&ae<q.length-5&&re){const ce=q.charCodeAt(ae+1);ce!==117&&ce!==85||(O=parseInt(q.substring(ae+2,ae+6),16),ae+=5)}if(O>255){const ce=D.get(O);ce&&(O=ce+127)}J&&(J=!1,O-=64),N[Q++]=O<ne&&O>0?O+oe:O-ne}else J=!0;const le=N.subarray(0,Q);if(re&&I===1){const ae=K(le);if(ae!==z){const ce="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",ce+`
13
+ */var hasRequiredBuffer;function requireBuffer(){return hasRequiredBuffer||(hasRequiredBuffer=1,function(q){const K=requireBase64Js(),F=requireIeee754(),Z=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;q.Buffer=I,q.SlowBuffer=de,q.INSPECT_MAX_BYTES=50;const D=2147483647;q.kMaxLength=D,I.TYPED_ARRAY_SUPPORT=N(),!I.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 N(){try{const se=new Uint8Array(1),X={foo:function(){return 42}};return Object.setPrototypeOf(X,Uint8Array.prototype),Object.setPrototypeOf(se,X),se.foo()===42}catch{return!1}}Object.defineProperty(I.prototype,"parent",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.buffer}}),Object.defineProperty(I.prototype,"offset",{enumerable:!0,get:function(){if(I.isBuffer(this))return this.byteOffset}});function O(se){if(se>D)throw new RangeError('The value "'+se+'" is invalid for option "size"');const X=new Uint8Array(se);return Object.setPrototypeOf(X,I.prototype),X}function I(se,X,ee){if(typeof se=="number"){if(typeof X=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return ne(se)}return z(se,X,ee)}I.poolSize=8192;function z(se,X,ee){if(typeof se=="string")return re(se,X);if(ArrayBuffer.isView(se))return oe(se);if(se==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof se);if(Vt(se,ArrayBuffer)||se&&Vt(se.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Vt(se,SharedArrayBuffer)||se&&Vt(se.buffer,SharedArrayBuffer)))return le(se,X,ee);if(typeof se=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const pe=se.valueOf&&se.valueOf();if(pe!=null&&pe!==se)return I.from(pe,X,ee);const Oe=ae(se);if(Oe)return Oe;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof se[Symbol.toPrimitive]=="function")return I.from(se[Symbol.toPrimitive]("string"),X,ee);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof se)}I.from=function(se,X,ee){return z(se,X,ee)},Object.setPrototypeOf(I.prototype,Uint8Array.prototype),Object.setPrototypeOf(I,Uint8Array);function J(se){if(typeof se!="number")throw new TypeError('"size" argument must be of type number');if(se<0)throw new RangeError('The value "'+se+'" is invalid for option "size"')}function Q(se,X,ee){return J(se),se<=0?O(se):X!==void 0?typeof ee=="string"?O(se).fill(X,ee):O(se).fill(X):O(se)}I.alloc=function(se,X,ee){return Q(se,X,ee)};function ne(se){return J(se),O(se<0?0:ce(se)|0)}I.allocUnsafe=function(se){return ne(se)},I.allocUnsafeSlow=function(se){return ne(se)};function re(se,X){if((typeof X!="string"||X==="")&&(X="utf8"),!I.isEncoding(X))throw new TypeError("Unknown encoding: "+X);const ee=we(se,X)|0;let pe=O(ee);const Oe=pe.write(se,X);return Oe!==ee&&(pe=pe.slice(0,Oe)),pe}function te(se){const X=se.length<0?0:ce(se.length)|0,ee=O(X);for(let pe=0;pe<X;pe+=1)ee[pe]=se[pe]&255;return ee}function oe(se){if(Vt(se,Uint8Array)){const X=new Uint8Array(se);return le(X.buffer,X.byteOffset,X.byteLength)}return te(se)}function le(se,X,ee){if(X<0||se.byteLength<X)throw new RangeError('"offset" is outside of buffer bounds');if(se.byteLength<X+(ee||0))throw new RangeError('"length" is outside of buffer bounds');let pe;return X===void 0&&ee===void 0?pe=new Uint8Array(se):ee===void 0?pe=new Uint8Array(se,X):pe=new Uint8Array(se,X,ee),Object.setPrototypeOf(pe,I.prototype),pe}function ae(se){if(I.isBuffer(se)){const X=ce(se.length)|0,ee=O(X);return ee.length===0||se.copy(ee,0,0,X),ee}if(se.length!==void 0)return typeof se.length!="number"||Qt(se.length)?O(0):te(se);if(se.type==="Buffer"&&Array.isArray(se.data))return te(se.data)}function ce(se){if(se>=D)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+D.toString(16)+" bytes");return se|0}function de(se){return+se!=se&&(se=0),I.alloc(+se)}I.isBuffer=function(X){return X!=null&&X._isBuffer===!0&&X!==I.prototype},I.compare=function(X,ee){if(Vt(X,Uint8Array)&&(X=I.from(X,X.offset,X.byteLength)),Vt(ee,Uint8Array)&&(ee=I.from(ee,ee.offset,ee.byteLength)),!I.isBuffer(X)||!I.isBuffer(ee))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(X===ee)return 0;let pe=X.length,Oe=ee.length;for(let De=0,Le=Math.min(pe,Oe);De<Le;++De)if(X[De]!==ee[De]){pe=X[De],Oe=ee[De];break}return pe<Oe?-1:Oe<pe?1:0},I.isEncoding=function(X){switch(String(X).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}},I.concat=function(X,ee){if(!Array.isArray(X))throw new TypeError('"list" argument must be an Array of Buffers');if(X.length===0)return I.alloc(0);let pe;if(ee===void 0)for(ee=0,pe=0;pe<X.length;++pe)ee+=X[pe].length;const Oe=I.allocUnsafe(ee);let De=0;for(pe=0;pe<X.length;++pe){let Le=X[pe];if(Vt(Le,Uint8Array))De+Le.length>Oe.length?(I.isBuffer(Le)||(Le=I.from(Le)),Le.copy(Oe,De)):Uint8Array.prototype.set.call(Oe,Le,De);else if(I.isBuffer(Le))Le.copy(Oe,De);else throw new TypeError('"list" argument must be an Array of Buffers');De+=Le.length}return Oe};function we(se,X){if(I.isBuffer(se))return se.length;if(ArrayBuffer.isView(se)||Vt(se,ArrayBuffer))return se.byteLength;if(typeof se!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof se);const ee=se.length,pe=arguments.length>2&&arguments[2]===!0;if(!pe&&ee===0)return 0;let Oe=!1;for(;;)switch(X){case"ascii":case"latin1":case"binary":return ee;case"utf8":case"utf-8":return Kt(se).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ee*2;case"hex":return ee>>>1;case"base64":return nn(se).length;default:if(Oe)return pe?-1:Kt(se).length;X=(""+X).toLowerCase(),Oe=!0}}I.byteLength=we;function fe(se,X,ee){let pe=!1;if((X===void 0||X<0)&&(X=0),X>this.length||((ee===void 0||ee>this.length)&&(ee=this.length),ee<=0)||(ee>>>=0,X>>>=0,ee<=X))return"";for(se||(se="utf8");;)switch(se){case"hex":return zt(this,X,ee);case"utf8":case"utf-8":return We(this,X,ee);case"ascii":return It(this,X,ee);case"latin1":case"binary":return Dt(this,X,ee);case"base64":return Ve(this,X,ee);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ut(this,X,ee);default:if(pe)throw new TypeError("Unknown encoding: "+se);se=(se+"").toLowerCase(),pe=!0}}I.prototype._isBuffer=!0;function ge(se,X,ee){const pe=se[X];se[X]=se[ee],se[ee]=pe}I.prototype.swap16=function(){const X=this.length;if(X%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let ee=0;ee<X;ee+=2)ge(this,ee,ee+1);return this},I.prototype.swap32=function(){const X=this.length;if(X%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let ee=0;ee<X;ee+=4)ge(this,ee,ee+3),ge(this,ee+1,ee+2);return this},I.prototype.swap64=function(){const X=this.length;if(X%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let ee=0;ee<X;ee+=8)ge(this,ee,ee+7),ge(this,ee+1,ee+6),ge(this,ee+2,ee+5),ge(this,ee+3,ee+4);return this},I.prototype.toString=function(){const X=this.length;return X===0?"":arguments.length===0?We(this,0,X):fe.apply(this,arguments)},I.prototype.toLocaleString=I.prototype.toString,I.prototype.equals=function(X){if(!I.isBuffer(X))throw new TypeError("Argument must be a Buffer");return this===X?!0:I.compare(this,X)===0},I.prototype.inspect=function(){let X="";const ee=q.INSPECT_MAX_BYTES;return X=this.toString("hex",0,ee).replace(/(.{2})/g,"$1 ").trim(),this.length>ee&&(X+=" ... "),"<Buffer "+X+">"},Z&&(I.prototype[Z]=I.prototype.inspect),I.prototype.compare=function(X,ee,pe,Oe,De){if(Vt(X,Uint8Array)&&(X=I.from(X,X.offset,X.byteLength)),!I.isBuffer(X))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof X);if(ee===void 0&&(ee=0),pe===void 0&&(pe=X?X.length:0),Oe===void 0&&(Oe=0),De===void 0&&(De=this.length),ee<0||pe>X.length||Oe<0||De>this.length)throw new RangeError("out of range index");if(Oe>=De&&ee>=pe)return 0;if(Oe>=De)return-1;if(ee>=pe)return 1;if(ee>>>=0,pe>>>=0,Oe>>>=0,De>>>=0,this===X)return 0;let Le=De-Oe,ut=pe-ee;const St=Math.min(Le,ut),vt=this.slice(Oe,De),Ct=X.slice(ee,pe);for(let Tt=0;Tt<St;++Tt)if(vt[Tt]!==Ct[Tt]){Le=vt[Tt],ut=Ct[Tt];break}return Le<ut?-1:ut<Le?1:0};function me(se,X,ee,pe,Oe){if(se.length===0)return-1;if(typeof ee=="string"?(pe=ee,ee=0):ee>2147483647?ee=2147483647:ee<-2147483648&&(ee=-2147483648),ee=+ee,Qt(ee)&&(ee=Oe?0:se.length-1),ee<0&&(ee=se.length+ee),ee>=se.length){if(Oe)return-1;ee=se.length-1}else if(ee<0)if(Oe)ee=0;else return-1;if(typeof X=="string"&&(X=I.from(X,pe)),I.isBuffer(X))return X.length===0?-1:ve(se,X,ee,pe,Oe);if(typeof X=="number")return X=X&255,typeof Uint8Array.prototype.indexOf=="function"?Oe?Uint8Array.prototype.indexOf.call(se,X,ee):Uint8Array.prototype.lastIndexOf.call(se,X,ee):ve(se,[X],ee,pe,Oe);throw new TypeError("val must be string, number or Buffer")}function ve(se,X,ee,pe,Oe){let De=1,Le=se.length,ut=X.length;if(pe!==void 0&&(pe=String(pe).toLowerCase(),pe==="ucs2"||pe==="ucs-2"||pe==="utf16le"||pe==="utf-16le")){if(se.length<2||X.length<2)return-1;De=2,Le/=2,ut/=2,ee/=2}function St(Ct,Tt){return De===1?Ct[Tt]:Ct.readUInt16BE(Tt*De)}let vt;if(Oe){let Ct=-1;for(vt=ee;vt<Le;vt++)if(St(se,vt)===St(X,Ct===-1?0:vt-Ct)){if(Ct===-1&&(Ct=vt),vt-Ct+1===ut)return Ct*De}else Ct!==-1&&(vt-=vt-Ct),Ct=-1}else for(ee+ut>Le&&(ee=Le-ut),vt=ee;vt>=0;vt--){let Ct=!0;for(let Tt=0;Tt<ut;Tt++)if(St(se,vt+Tt)!==St(X,Tt)){Ct=!1;break}if(Ct)return vt}return-1}I.prototype.includes=function(X,ee,pe){return this.indexOf(X,ee,pe)!==-1},I.prototype.indexOf=function(X,ee,pe){return me(this,X,ee,pe,!0)},I.prototype.lastIndexOf=function(X,ee,pe){return me(this,X,ee,pe,!1)};function ke(se,X,ee,pe){ee=Number(ee)||0;const Oe=se.length-ee;pe?(pe=Number(pe),pe>Oe&&(pe=Oe)):pe=Oe;const De=X.length;pe>De/2&&(pe=De/2);let Le;for(Le=0;Le<pe;++Le){const ut=parseInt(X.substr(Le*2,2),16);if(Qt(ut))return Le;se[ee+Le]=ut}return Le}function xe(se,X,ee,pe){return rn(Kt(X,se.length-ee),se,ee,pe)}function _e(se,X,ee,pe){return rn(Gt(X),se,ee,pe)}function Te(se,X,ee,pe){return rn(nn(X),se,ee,pe)}function qe(se,X,ee,pe){return rn(dn(X,se.length-ee),se,ee,pe)}I.prototype.write=function(X,ee,pe,Oe){if(ee===void 0)Oe="utf8",pe=this.length,ee=0;else if(pe===void 0&&typeof ee=="string")Oe=ee,pe=this.length,ee=0;else if(isFinite(ee))ee=ee>>>0,isFinite(pe)?(pe=pe>>>0,Oe===void 0&&(Oe="utf8")):(Oe=pe,pe=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const De=this.length-ee;if((pe===void 0||pe>De)&&(pe=De),X.length>0&&(pe<0||ee<0)||ee>this.length)throw new RangeError("Attempt to write outside buffer bounds");Oe||(Oe="utf8");let Le=!1;for(;;)switch(Oe){case"hex":return ke(this,X,ee,pe);case"utf8":case"utf-8":return xe(this,X,ee,pe);case"ascii":case"latin1":case"binary":return _e(this,X,ee,pe);case"base64":return Te(this,X,ee,pe);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return qe(this,X,ee,pe);default:if(Le)throw new TypeError("Unknown encoding: "+Oe);Oe=(""+Oe).toLowerCase(),Le=!0}},I.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Ve(se,X,ee){return X===0&&ee===se.length?K.fromByteArray(se):K.fromByteArray(se.slice(X,ee))}function We(se,X,ee){ee=Math.min(se.length,ee);const pe=[];let Oe=X;for(;Oe<ee;){const De=se[Oe];let Le=null,ut=De>239?4:De>223?3:De>191?2:1;if(Oe+ut<=ee){let St,vt,Ct,Tt;switch(ut){case 1:De<128&&(Le=De);break;case 2:St=se[Oe+1],(St&192)===128&&(Tt=(De&31)<<6|St&63,Tt>127&&(Le=Tt));break;case 3:St=se[Oe+1],vt=se[Oe+2],(St&192)===128&&(vt&192)===128&&(Tt=(De&15)<<12|(St&63)<<6|vt&63,Tt>2047&&(Tt<55296||Tt>57343)&&(Le=Tt));break;case 4:St=se[Oe+1],vt=se[Oe+2],Ct=se[Oe+3],(St&192)===128&&(vt&192)===128&&(Ct&192)===128&&(Tt=(De&15)<<18|(St&63)<<12|(vt&63)<<6|Ct&63,Tt>65535&&Tt<1114112&&(Le=Tt))}}Le===null?(Le=65533,ut=1):Le>65535&&(Le-=65536,pe.push(Le>>>10&1023|55296),Le=56320|Le&1023),pe.push(Le),Oe+=ut}return Ot(pe)}const Fe=4096;function Ot(se){const X=se.length;if(X<=Fe)return String.fromCharCode.apply(String,se);let ee="",pe=0;for(;pe<X;)ee+=String.fromCharCode.apply(String,se.slice(pe,pe+=Fe));return ee}function It(se,X,ee){let pe="";ee=Math.min(se.length,ee);for(let Oe=X;Oe<ee;++Oe)pe+=String.fromCharCode(se[Oe]&127);return pe}function Dt(se,X,ee){let pe="";ee=Math.min(se.length,ee);for(let Oe=X;Oe<ee;++Oe)pe+=String.fromCharCode(se[Oe]);return pe}function zt(se,X,ee){const pe=se.length;(!X||X<0)&&(X=0),(!ee||ee<0||ee>pe)&&(ee=pe);let Oe="";for(let De=X;De<ee;++De)Oe+=gn[se[De]];return Oe}function Ut(se,X,ee){const pe=se.slice(X,ee);let Oe="";for(let De=0;De<pe.length-1;De+=2)Oe+=String.fromCharCode(pe[De]+pe[De+1]*256);return Oe}I.prototype.slice=function(X,ee){const pe=this.length;X=~~X,ee=ee===void 0?pe:~~ee,X<0?(X+=pe,X<0&&(X=0)):X>pe&&(X=pe),ee<0?(ee+=pe,ee<0&&(ee=0)):ee>pe&&(ee=pe),ee<X&&(ee=X);const Oe=this.subarray(X,ee);return Object.setPrototypeOf(Oe,I.prototype),Oe};function gt(se,X,ee){if(se%1!==0||se<0)throw new RangeError("offset is not uint");if(se+X>ee)throw new RangeError("Trying to access beyond buffer length")}I.prototype.readUintLE=I.prototype.readUIntLE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=this[X],De=1,Le=0;for(;++Le<ee&&(De*=256);)Oe+=this[X+Le]*De;return Oe},I.prototype.readUintBE=I.prototype.readUIntBE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=this[X+--ee],De=1;for(;ee>0&&(De*=256);)Oe+=this[X+--ee]*De;return Oe},I.prototype.readUint8=I.prototype.readUInt8=function(X,ee){return X=X>>>0,ee||gt(X,1,this.length),this[X]},I.prototype.readUint16LE=I.prototype.readUInt16LE=function(X,ee){return X=X>>>0,ee||gt(X,2,this.length),this[X]|this[X+1]<<8},I.prototype.readUint16BE=I.prototype.readUInt16BE=function(X,ee){return X=X>>>0,ee||gt(X,2,this.length),this[X]<<8|this[X+1]},I.prototype.readUint32LE=I.prototype.readUInt32LE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),(this[X]|this[X+1]<<8|this[X+2]<<16)+this[X+3]*16777216},I.prototype.readUint32BE=I.prototype.readUInt32BE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),this[X]*16777216+(this[X+1]<<16|this[X+2]<<8|this[X+3])},I.prototype.readBigUInt64LE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=ee+this[++X]*2**8+this[++X]*2**16+this[++X]*2**24,De=this[++X]+this[++X]*2**8+this[++X]*2**16+pe*2**24;return BigInt(Oe)+(BigInt(De)<<BigInt(32))}),I.prototype.readBigUInt64BE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=ee*2**24+this[++X]*2**16+this[++X]*2**8+this[++X],De=this[++X]*2**24+this[++X]*2**16+this[++X]*2**8+pe;return(BigInt(Oe)<<BigInt(32))+BigInt(De)}),I.prototype.readIntLE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=this[X],De=1,Le=0;for(;++Le<ee&&(De*=256);)Oe+=this[X+Le]*De;return De*=128,Oe>=De&&(Oe-=Math.pow(2,8*ee)),Oe},I.prototype.readIntBE=function(X,ee,pe){X=X>>>0,ee=ee>>>0,pe||gt(X,ee,this.length);let Oe=ee,De=1,Le=this[X+--Oe];for(;Oe>0&&(De*=256);)Le+=this[X+--Oe]*De;return De*=128,Le>=De&&(Le-=Math.pow(2,8*ee)),Le},I.prototype.readInt8=function(X,ee){return X=X>>>0,ee||gt(X,1,this.length),this[X]&128?(255-this[X]+1)*-1:this[X]},I.prototype.readInt16LE=function(X,ee){X=X>>>0,ee||gt(X,2,this.length);const pe=this[X]|this[X+1]<<8;return pe&32768?pe|4294901760:pe},I.prototype.readInt16BE=function(X,ee){X=X>>>0,ee||gt(X,2,this.length);const pe=this[X+1]|this[X]<<8;return pe&32768?pe|4294901760:pe},I.prototype.readInt32LE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),this[X]|this[X+1]<<8|this[X+2]<<16|this[X+3]<<24},I.prototype.readInt32BE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),this[X]<<24|this[X+1]<<16|this[X+2]<<8|this[X+3]},I.prototype.readBigInt64LE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=this[X+4]+this[X+5]*2**8+this[X+6]*2**16+(pe<<24);return(BigInt(Oe)<<BigInt(32))+BigInt(ee+this[++X]*2**8+this[++X]*2**16+this[++X]*2**24)}),I.prototype.readBigInt64BE=on(function(X){X=X>>>0,wt(X,"offset");const ee=this[X],pe=this[X+7];(ee===void 0||pe===void 0)&&Bt(X,this.length-8);const Oe=(ee<<24)+this[++X]*2**16+this[++X]*2**8+this[++X];return(BigInt(Oe)<<BigInt(32))+BigInt(this[++X]*2**24+this[++X]*2**16+this[++X]*2**8+pe)}),I.prototype.readFloatLE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),F.read(this,X,!0,23,4)},I.prototype.readFloatBE=function(X,ee){return X=X>>>0,ee||gt(X,4,this.length),F.read(this,X,!1,23,4)},I.prototype.readDoubleLE=function(X,ee){return X=X>>>0,ee||gt(X,8,this.length),F.read(this,X,!0,52,8)},I.prototype.readDoubleBE=function(X,ee){return X=X>>>0,ee||gt(X,8,this.length),F.read(this,X,!1,52,8)};function it(se,X,ee,pe,Oe,De){if(!I.isBuffer(se))throw new TypeError('"buffer" argument must be a Buffer instance');if(X>Oe||X<De)throw new RangeError('"value" argument is out of bounds');if(ee+pe>se.length)throw new RangeError("Index out of range")}I.prototype.writeUintLE=I.prototype.writeUIntLE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,pe=pe>>>0,!Oe){const ut=Math.pow(2,8*pe)-1;it(this,X,ee,pe,ut,0)}let De=1,Le=0;for(this[ee]=X&255;++Le<pe&&(De*=256);)this[ee+Le]=X/De&255;return ee+pe},I.prototype.writeUintBE=I.prototype.writeUIntBE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,pe=pe>>>0,!Oe){const ut=Math.pow(2,8*pe)-1;it(this,X,ee,pe,ut,0)}let De=pe-1,Le=1;for(this[ee+De]=X&255;--De>=0&&(Le*=256);)this[ee+De]=X/Le&255;return ee+pe},I.prototype.writeUint8=I.prototype.writeUInt8=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,1,255,0),this[ee]=X&255,ee+1},I.prototype.writeUint16LE=I.prototype.writeUInt16LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,65535,0),this[ee]=X&255,this[ee+1]=X>>>8,ee+2},I.prototype.writeUint16BE=I.prototype.writeUInt16BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,65535,0),this[ee]=X>>>8,this[ee+1]=X&255,ee+2},I.prototype.writeUint32LE=I.prototype.writeUInt32LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,4294967295,0),this[ee+3]=X>>>24,this[ee+2]=X>>>16,this[ee+1]=X>>>8,this[ee]=X&255,ee+4},I.prototype.writeUint32BE=I.prototype.writeUInt32BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,4294967295,0),this[ee]=X>>>24,this[ee+1]=X>>>16,this[ee+2]=X>>>8,this[ee+3]=X&255,ee+4};function Zt(se,X,ee,pe,Oe){ct(X,pe,Oe,se,ee,7);let De=Number(X&BigInt(4294967295));se[ee++]=De,De=De>>8,se[ee++]=De,De=De>>8,se[ee++]=De,De=De>>8,se[ee++]=De;let Le=Number(X>>BigInt(32)&BigInt(4294967295));return se[ee++]=Le,Le=Le>>8,se[ee++]=Le,Le=Le>>8,se[ee++]=Le,Le=Le>>8,se[ee++]=Le,ee}function Rt(se,X,ee,pe,Oe){ct(X,pe,Oe,se,ee,7);let De=Number(X&BigInt(4294967295));se[ee+7]=De,De=De>>8,se[ee+6]=De,De=De>>8,se[ee+5]=De,De=De>>8,se[ee+4]=De;let Le=Number(X>>BigInt(32)&BigInt(4294967295));return se[ee+3]=Le,Le=Le>>8,se[ee+2]=Le,Le=Le>>8,se[ee+1]=Le,Le=Le>>8,se[ee]=Le,ee+8}I.prototype.writeBigUInt64LE=on(function(X,ee=0){return Zt(this,X,ee,BigInt(0),BigInt("0xffffffffffffffff"))}),I.prototype.writeBigUInt64BE=on(function(X,ee=0){return Rt(this,X,ee,BigInt(0),BigInt("0xffffffffffffffff"))}),I.prototype.writeIntLE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,!Oe){const St=Math.pow(2,8*pe-1);it(this,X,ee,pe,St-1,-St)}let De=0,Le=1,ut=0;for(this[ee]=X&255;++De<pe&&(Le*=256);)X<0&&ut===0&&this[ee+De-1]!==0&&(ut=1),this[ee+De]=(X/Le>>0)-ut&255;return ee+pe},I.prototype.writeIntBE=function(X,ee,pe,Oe){if(X=+X,ee=ee>>>0,!Oe){const St=Math.pow(2,8*pe-1);it(this,X,ee,pe,St-1,-St)}let De=pe-1,Le=1,ut=0;for(this[ee+De]=X&255;--De>=0&&(Le*=256);)X<0&&ut===0&&this[ee+De+1]!==0&&(ut=1),this[ee+De]=(X/Le>>0)-ut&255;return ee+pe},I.prototype.writeInt8=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,1,127,-128),X<0&&(X=255+X+1),this[ee]=X&255,ee+1},I.prototype.writeInt16LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,32767,-32768),this[ee]=X&255,this[ee+1]=X>>>8,ee+2},I.prototype.writeInt16BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,2,32767,-32768),this[ee]=X>>>8,this[ee+1]=X&255,ee+2},I.prototype.writeInt32LE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,2147483647,-2147483648),this[ee]=X&255,this[ee+1]=X>>>8,this[ee+2]=X>>>16,this[ee+3]=X>>>24,ee+4},I.prototype.writeInt32BE=function(X,ee,pe){return X=+X,ee=ee>>>0,pe||it(this,X,ee,4,2147483647,-2147483648),X<0&&(X=4294967295+X+1),this[ee]=X>>>24,this[ee+1]=X>>>16,this[ee+2]=X>>>8,this[ee+3]=X&255,ee+4},I.prototype.writeBigInt64LE=on(function(X,ee=0){return Zt(this,X,ee,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),I.prototype.writeBigInt64BE=on(function(X,ee=0){return Rt(this,X,ee,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ue(se,X,ee,pe,Oe,De){if(ee+pe>se.length)throw new RangeError("Index out of range");if(ee<0)throw new RangeError("Index out of range")}function ot(se,X,ee,pe,Oe){return X=+X,ee=ee>>>0,Oe||Ue(se,X,ee,4),F.write(se,X,ee,pe,23,4),ee+4}I.prototype.writeFloatLE=function(X,ee,pe){return ot(this,X,ee,!0,pe)},I.prototype.writeFloatBE=function(X,ee,pe){return ot(this,X,ee,!1,pe)};function Jt(se,X,ee,pe,Oe){return X=+X,ee=ee>>>0,Oe||Ue(se,X,ee,8),F.write(se,X,ee,pe,52,8),ee+8}I.prototype.writeDoubleLE=function(X,ee,pe){return Jt(this,X,ee,!0,pe)},I.prototype.writeDoubleBE=function(X,ee,pe){return Jt(this,X,ee,!1,pe)},I.prototype.copy=function(X,ee,pe,Oe){if(!I.isBuffer(X))throw new TypeError("argument should be a Buffer");if(pe||(pe=0),!Oe&&Oe!==0&&(Oe=this.length),ee>=X.length&&(ee=X.length),ee||(ee=0),Oe>0&&Oe<pe&&(Oe=pe),Oe===pe||X.length===0||this.length===0)return 0;if(ee<0)throw new RangeError("targetStart out of bounds");if(pe<0||pe>=this.length)throw new RangeError("Index out of range");if(Oe<0)throw new RangeError("sourceEnd out of bounds");Oe>this.length&&(Oe=this.length),X.length-ee<Oe-pe&&(Oe=X.length-ee+pe);const De=Oe-pe;return this===X&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(ee,pe,Oe):Uint8Array.prototype.set.call(X,this.subarray(pe,Oe),ee),De},I.prototype.fill=function(X,ee,pe,Oe){if(typeof X=="string"){if(typeof ee=="string"?(Oe=ee,ee=0,pe=this.length):typeof pe=="string"&&(Oe=pe,pe=this.length),Oe!==void 0&&typeof Oe!="string")throw new TypeError("encoding must be a string");if(typeof Oe=="string"&&!I.isEncoding(Oe))throw new TypeError("Unknown encoding: "+Oe);if(X.length===1){const Le=X.charCodeAt(0);(Oe==="utf8"&&Le<128||Oe==="latin1")&&(X=Le)}}else typeof X=="number"?X=X&255:typeof X=="boolean"&&(X=Number(X));if(ee<0||this.length<ee||this.length<pe)throw new RangeError("Out of range index");if(pe<=ee)return this;ee=ee>>>0,pe=pe===void 0?this.length:pe>>>0,X||(X=0);let De;if(typeof X=="number")for(De=ee;De<pe;++De)this[De]=X;else{const Le=I.isBuffer(X)?X:I.from(X,Oe),ut=Le.length;if(ut===0)throw new TypeError('The value "'+X+'" is invalid for argument "value"');for(De=0;De<pe-ee;++De)this[De+ee]=Le[De%ut]}return this};const Nt={};function rt(se,X,ee){Nt[se]=class extends ee{constructor(){super(),Object.defineProperty(this,"message",{value:X.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${se}]`,this.stack,delete this.name}get code(){return se}set code(Oe){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:Oe,writable:!0})}toString(){return`${this.name} [${se}]: ${this.message}`}}}rt("ERR_BUFFER_OUT_OF_BOUNDS",function(se){return se?`${se} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),rt("ERR_INVALID_ARG_TYPE",function(se,X){return`The "${se}" argument must be of type number. Received type ${typeof X}`},TypeError),rt("ERR_OUT_OF_RANGE",function(se,X,ee){let pe=`The value of "${se}" is out of range.`,Oe=ee;return Number.isInteger(ee)&&Math.abs(ee)>2**32?Oe=tt(String(ee)):typeof ee=="bigint"&&(Oe=String(ee),(ee>BigInt(2)**BigInt(32)||ee<-(BigInt(2)**BigInt(32)))&&(Oe=tt(Oe)),Oe+="n"),pe+=` It must be ${X}. Received ${Oe}`,pe},RangeError);function tt(se){let X="",ee=se.length;const pe=se[0]==="-"?1:0;for(;ee>=pe+4;ee-=3)X=`_${se.slice(ee-3,ee)}${X}`;return`${se.slice(0,ee)}${X}`}function at(se,X,ee){wt(X,"offset"),(se[X]===void 0||se[X+ee]===void 0)&&Bt(X,se.length-(ee+1))}function ct(se,X,ee,pe,Oe,De){if(se>ee||se<X){const Le=typeof X=="bigint"?"n":"";let ut;throw X===0||X===BigInt(0)?ut=`>= 0${Le} and < 2${Le} ** ${(De+1)*8}${Le}`:ut=`>= -(2${Le} ** ${(De+1)*8-1}${Le}) and < 2 ** ${(De+1)*8-1}${Le}`,new Nt.ERR_OUT_OF_RANGE("value",ut,se)}at(pe,Oe,De)}function wt(se,X){if(typeof se!="number")throw new Nt.ERR_INVALID_ARG_TYPE(X,"number",se)}function Bt(se,X,ee){throw Math.floor(se)!==se?(wt(se,ee),new Nt.ERR_OUT_OF_RANGE("offset","an integer",se)):X<0?new Nt.ERR_BUFFER_OUT_OF_BOUNDS:new Nt.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${X}`,se)}const Lt=/[^+/0-9A-Za-z-_]/g;function Ft(se){if(se=se.split("=")[0],se=se.trim().replace(Lt,""),se.length<2)return"";for(;se.length%4!==0;)se=se+"=";return se}function Kt(se,X){X=X||1/0;let ee;const pe=se.length;let Oe=null;const De=[];for(let Le=0;Le<pe;++Le){if(ee=se.charCodeAt(Le),ee>55295&&ee<57344){if(!Oe){if(ee>56319){(X-=3)>-1&&De.push(239,191,189);continue}else if(Le+1===pe){(X-=3)>-1&&De.push(239,191,189);continue}Oe=ee;continue}if(ee<56320){(X-=3)>-1&&De.push(239,191,189),Oe=ee;continue}ee=(Oe-55296<<10|ee-56320)+65536}else Oe&&(X-=3)>-1&&De.push(239,191,189);if(Oe=null,ee<128){if((X-=1)<0)break;De.push(ee)}else if(ee<2048){if((X-=2)<0)break;De.push(ee>>6|192,ee&63|128)}else if(ee<65536){if((X-=3)<0)break;De.push(ee>>12|224,ee>>6&63|128,ee&63|128)}else if(ee<1114112){if((X-=4)<0)break;De.push(ee>>18|240,ee>>12&63|128,ee>>6&63|128,ee&63|128)}else throw new Error("Invalid code point")}return De}function Gt(se){const X=[];for(let ee=0;ee<se.length;++ee)X.push(se.charCodeAt(ee)&255);return X}function dn(se,X){let ee,pe,Oe;const De=[];for(let Le=0;Le<se.length&&!((X-=2)<0);++Le)ee=se.charCodeAt(Le),pe=ee>>8,Oe=ee%256,De.push(Oe),De.push(pe);return De}function nn(se){return K.toByteArray(Ft(se))}function rn(se,X,ee,pe){let Oe;for(Oe=0;Oe<pe&&!(Oe+ee>=X.length||Oe>=se.length);++Oe)X[Oe+ee]=se[Oe];return Oe}function Vt(se,X){return se instanceof X||se!=null&&se.constructor!=null&&se.constructor.name!=null&&se.constructor.name===X.name}function Qt(se){return se!==se}const gn=function(){const se="0123456789abcdef",X=new Array(256);for(let ee=0;ee<16;++ee){const pe=ee*16;for(let Oe=0;Oe<16;++Oe)X[pe+Oe]=se[ee]+se[Oe]}return X}();function on(se){return typeof BigInt>"u"?Yt:se}function Yt(){throw new Error("BigInt not supported")}}(buffer)),buffer}var toolsEbml={},hasRequiredToolsEbml;function requireToolsEbml(){if(hasRequiredToolsEbml)return toolsEbml;hasRequiredToolsEbml=1;var q=toolsEbml&&toolsEbml.__assign||function(){return q=Object.assign||function(D){for(var N,O=1,I=arguments.length;O<I;O++){N=arguments[O];for(var z in N)Object.prototype.hasOwnProperty.call(N,z)&&(D[z]=N[z])}return D},q.apply(this,arguments)},K=toolsEbml&&toolsEbml.__spreadArray||function(D,N,O){if(O||arguments.length===2)for(var I=0,z=N.length,J;I<z;I++)(J||!(I in N))&&(J||(J=Array.prototype.slice.call(N,0,I)),J[I]=N[I]);return D.concat(J||Array.prototype.slice.call(N))};Object.defineProperty(toolsEbml,"__esModule",{value:!0});var F=requireTools(),Z=function(){function D(){}return D.readVint=function(N,O){O===void 0&&(O=0);var I=8-Math.floor(Math.log2(N[O]));if(I>8){var z=D.readHexString(N,O,O+I);throw new Error("Unrepresentable length: ".concat(I," ").concat(z))}if(O+I>N.length)return null;for(var J=N[O]&(1<<8-I)-1,Q=1;Q<I;Q+=1){if(Q===7&&J>=Math.pow(2,8)&&N[O+7]>0)return{length:I,value:-1};J*=Math.pow(2,8),J+=N[O+Q]}return{length:I,value:J}},D.writeVint=function(N){if(N<0||N>Math.pow(2,53))throw new Error("Unrepresentable value: ".concat(N));var O=1;for(O=1;O<=8&&!(N<Math.pow(2,7*O)-1);O+=1);for(var I=F.Buffer.alloc(O),z=N,J=1;J<=O;J+=1){var Q=z&255;I[O-J]=Q,z-=Q,z/=Math.pow(2,8)}return I[0]|=1<<8-O,I},D.concatenate=function(N,O){return!N&&!O?F.Buffer.from([]):!N||N.byteLength===0?O:!O||O.byteLength===0?N:F.Buffer.from(K(K([],N,!0),O,!0))},D.readHexString=function(N,O,I){return O===void 0&&(O=0),I===void 0&&(I=N.byteLength),Array.from(N.slice(O,I)).map(function(z){return Number(z).toString(16)}).reduce(function(z,J){return"".concat(z).concat(J.padStart(2,"0"))},"")},D.readUtf8=function(N){try{return F.Buffer.from(N).toString("utf8")}catch{return null}},D.readUnsigned=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 1:return O.getUint8(0);case 2:return O.getUint16(0);case 4:return O.getUint32(0)}return N.byteLength<=6?N.reduce(function(I,z){return I*256+z},0):D.readHexString(N,0,N.byteLength)},D.readSigned=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 1:return O.getInt8(0);case 2:return O.getInt16(0);case 4:return O.getInt32(0);default:return NaN}},D.readFloat=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 4:return O.getFloat32(0);case 8:return O.getFloat64(0);default:return NaN}},D.readDate=function(N){var O=new DataView(N.buffer,N.byteOffset,N.byteLength);switch(N.byteLength){case 1:return new Date(O.getUint8(0));case 2:return new Date(O.getUint16(0));case 4:return new Date(O.getUint32(0));case 8:return new Date(Number.parseInt(D.readHexString(N),16));default:return new Date(0)}},D.readDataFromTag=function(N,O){var I=N.type,z=N.name,J=N.track,Q=N.discardable||!1,ne=N.keyframe||!1,re=null,te;switch(I){case"u":te=D.readUnsigned(O);break;case"f":te=D.readFloat(O);break;case"i":te=D.readSigned(O);break;case"s":te=String.fromCharCode.apply(String,O);break;case"8":te=D.readUtf8(O);break;case"d":te=D.readDate(O);break}if(z==="SimpleBlock"||z==="Block"){var oe=0,le=D.readVint(O,oe),ae=le.length,ce=le.value;oe+=ae,J=ce,te=D.readSigned(O.subarray(oe,oe+2)),oe+=2,z==="SimpleBlock"&&(ne=!!(O[ae+2]&128),Q=!!(O[ae+2]&1)),oe+=1,re=O.subarray(oe)}return q(q({},N),{data:O,discardable:Q,keyframe:ne,payload:re,track:J,value:te})},D}();return toolsEbml.default=Z,toolsEbml}var vint,hasRequiredVint;function requireVint(){return hasRequiredVint||(hasRequiredVint=1,vint=function(q,K,F){K=K||0;for(var Z=1;Z<=8&&!(q[K]>=Math.pow(2,8-Z));Z++);if(Z>8)throw new Error("Unrepresentable length: "+Z+" "+q.toString("hex",K,K+Z));if(K+Z>q.length)return null;var D,N=q[K]&(1<<8-Z)-1;for(D=1;D<Z;D++){if(D===7&&N>=Math.pow(2,45)&&q[K+7]>0)return{length:Z,value:-1};N*=Math.pow(2,8),N+=q[K+D]}return F&&(N-=Math.pow(2,Z*7-1)-1),{length:Z,value:N}}),vint}var bufferReader,hasRequiredBufferReader;function requireBufferReader(){if(hasRequiredBufferReader)return bufferReader;hasRequiredBufferReader=1;var q=requireVint();function K(F){this.buffer=F,this.offset=0}return K.prototype.nextInt16BE=function(){var F=this.buffer.readInt16BE(this.offset);return this.offset+=2,F},K.prototype.nextUInt8=function(){var F=this.buffer.readUInt8(this.offset);return this.offset+=1,F},K.prototype.nextUIntV=function(){var F=q(this.buffer,this.offset);return this.offset+=F.length,F.value},K.prototype.nextIntV=function(){var F=q(this.buffer,this.offset,!0);return this.offset+=F.length,F.value},K.prototype.nextBuffer=function(F){var Z=F?this.buffer.slice(this.offset,this.offset+F):this.buffer.slice(this.offset);return this.offset+=F||this.length,Z},Object.defineProperty(K.prototype,"length",{get:function(){return this.buffer.length-this.offset}}),bufferReader=K,bufferReader}var ebmlBlock,hasRequiredEbmlBlock;function requireEbmlBlock(){if(hasRequiredEbmlBlock)return ebmlBlock;hasRequiredEbmlBlock=1;var q=requireBufferReader(),K=1,F=3,Z=2;ebmlBlock=function(N){var O={},I=new q(N);O.trackNumber=I.nextUIntV(),O.timecode=I.nextInt16BE();var z=I.nextUInt8();O.invisible=!!(z&8),O.keyframe=!!(z&128),O.discardable=!!(z&1);var J=(z&6)>>1;return O.frames=D(I,J),O};function D(N,O){if(!O)return[N.nextBuffer()];var I,z,J=[],Q=N.nextUInt8()+1;if(O===Z){if(N.length%Q!==0)throw new Error("Fixed-Size Lacing Error");for(z=N.length/Q,I=0;I<Q;I++)J.push(N.nextBuffer(z));return J}var ne=[];if(O===K)for(I=0;I<Q-1;I++){var re;z=0;do re=N.nextUInt8(),z+=re;while(re===255);ne.push(z)}else if(O===F)for(z=N.nextUIntV(),ne.push(z),I=1;I<Q-1;I++)z+=N.nextIntV(),ne.push(z);for(I=0;I<Q-1;I++)J.push(N.nextBuffer(ne[I]));return J.push(N.nextBuffer()),J}return ebmlBlock}var hasRequiredTools;function requireTools(){return hasRequiredTools||(hasRequiredTools=1,function(q){Object.defineProperty(q,"__esModule",{value:!0}),q.convertEBMLDateToJSDate=q.createFloatBuffer=q.createIntBuffer=q.createUIntBuffer=q.encodeValueToBuffer=q.concat=q.putRefinedMetaData=q.extractElement=q.removeElement=q.makeMetadataSeekable=q.createRIFFChunk=q.VP8BitStreamToRiffWebPBuffer=q.WebPBlockFilter=q.encodeTag=q.readBlock=q.ebmlBlock=q.writeVint=q.readVint=q.Buffer=void 0;var K=requireInt64Buffer(),F=requireEBMLEncoder(),Z=requireBuffer(),D=requireToolsEbml(),N=requireEbmlBlock();q.Buffer=Z.Buffer,q.readVint=D.default.readVint,q.writeVint=D.default.writeVint,q.ebmlBlock=N;function O(_e){return(0,q.ebmlBlock)(new q.Buffer(_e))}q.readBlock=O;function I(_e,Te,qe){return qe===void 0&&(qe=!1),fe([_e,qe?new q.Buffer("01ffffffffffffff","hex"):(0,q.writeVint)(Te.length),Te])}q.encodeTag=I;function z(_e){return _e.reduce(function(Te,qe){if(qe.type!=="b"||qe.name!=="SimpleBlock")return Te;var Ve=(0,q.ebmlBlock)(qe.data),We=Ve.frames.some(function(Fe){var Ot=Fe.slice(3,6).toString("hex");return Ot==="9d012a"});return We?Te.concat(qe):Te},[])}q.WebPBlockFilter=z;function J(_e){var Te=Q("VP8 ",_e),qe=fe([new q.Buffer("WEBP","ascii"),Te]);return Q("RIFF",qe)}q.VP8BitStreamToRiffWebPBuffer=J;function Q(_e,Te){var qe=new q.Buffer(4);return qe.writeUInt32LE(Te.byteLength,0),fe([new q.Buffer(_e.substr(0,4),"ascii"),qe,Te,new q.Buffer(Te.byteLength%2===0?0:1)])}q.createRIFFChunk=Q;function ne(_e,Te,qe){var Ve=te("EBML",_e),We=le(Ve),Fe=We+12,Ot=_e[_e.length-1].dataEnd-Fe,It=te("Info",_e);re("Duration",It),It.splice(1,0,{name:"Duration",type:"f",data:ke(Te,8)});for(var Dt=le(It),zt=te("Tracks",_e),Ut=le(zt),gt=47,it=[],Zt=5+qe.length*15,Rt=[],Ue=-1,ot=10,Jt=function(ct){var wt=gt,Bt=wt+Dt,Lt=Bt+Ut,Ft=Lt+Zt,Kt=Ft-Ot;if(it=[],it.push({name:"SeekHead",type:"m",isEnd:!1}),it.push({name:"Seek",type:"m",isEnd:!1}),it.push({name:"SeekID",type:"b",data:new q.Buffer([21,73,169,102])}),it.push({name:"SeekPosition",type:"u",data:me(wt)}),it.push({name:"Seek",type:"m",isEnd:!0}),it.push({name:"Seek",type:"m",isEnd:!1}),it.push({name:"SeekID",type:"b",data:new q.Buffer([22,84,174,107])}),it.push({name:"SeekPosition",type:"u",data:me(Bt)}),it.push({name:"Seek",type:"m",isEnd:!0}),it.push({name:"Seek",type:"m",isEnd:!1}),it.push({name:"SeekID",type:"b",data:new q.Buffer([28,83,187,107])}),it.push({name:"SeekPosition",type:"u",data:me(Lt)}),it.push({name:"Seek",type:"m",isEnd:!0}),it.push({name:"SeekHead",type:"m",isEnd:!0}),gt=le(it),Rt=[],Rt.push({name:"Cues",type:"m",isEnd:!1}),qe.forEach(function(Gt){var dn=Gt.CueTrack,nn=Gt.CueClusterPosition,rn=Gt.CueTime;Rt.push({name:"CuePoint",type:"m",isEnd:!1}),Rt.push({name:"CueTime",type:"u",data:me(rn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!1}),Rt.push({name:"CueTrack",type:"u",data:me(dn)}),nn-=Fe,nn+=Kt,Rt.push({name:"CueClusterPosition",type:"u",data:me(nn)}),Rt.push({name:"CueTrackPositions",type:"m",isEnd:!0}),Rt.push({name:"CuePoint",type:"m",isEnd:!0})}),Rt.push({name:"Cues",type:"m",isEnd:!0}),Zt=le(Rt),Ue!==Kt){if(Ue=Kt,ct===ot-1)throw new Error("Failed to converge to a stable metadata size")}else return"break"},Nt=0;Nt<ot;Nt++){var rt=Jt(Nt);if(rt==="break")break}var tt=[].concat.apply([],[Ve,{name:"Segment",type:"m",isEnd:!1,unknownSize:!0},it,It,zt,Rt]),at=new F.default().encode(tt);return at}q.makeMetadataSeekable=ne;function re(_e,Te){for(var qe=-1,Ve=0;Ve<Te.length;Ve++){var We=Te[Ve];if(We.name===_e)if(We.type==="m")if(!We.isEnd)qe=Ve;else{if(qe==-1)throw new Error("Detected ".concat(_e," closing element before finding the start"));Te.splice(qe,Ve-qe+1);return}else{Te.splice(Ve,1);return}}}q.removeElement=re;function te(_e,Te){for(var qe=[],Ve=-1,We=0;We<Te.length;We++){var Fe=Te[We];if(Fe.name===_e)if(Fe.type==="m")if(!Fe.isEnd)Ve=We;else{if(Ve==-1)throw new Error("Detected ".concat(_e," closing element before finding the start"));qe=Te.slice(Ve,We+1);break}else{qe.push(Te[We]);break}}return qe}q.extractElement=te;function oe(_e,Te){Array.isArray(Te.cueInfos)&&!Array.isArray(Te.cues)&&(console.warn("putRefinedMetaData: info.cueInfos property is deprecated. please use info.cues"),Te.cues=Te.cueInfos);for(var qe=[],Ve=[],We=0;We<_e.length;We++){var Fe=_e[We];if(Fe.type==="m"&&Fe.name==="Segment"){if(qe=_e.slice(0,We),Ve=_e.slice(We),Fe.unknownSize){Ve.shift();break}throw new Error("this metadata is not streaming webm file")}}if(!(Ve[Ve.length-1].dataEnd>0))throw new Error("metadata dataEnd has wrong number");var Ot=Ve[Ve.length-1].dataEnd,It=qe[qe.length-1].dataEnd,Dt=new F.default().encode(qe).byteLength,zt=Dt-It,Ut=Ot-Ve[0].tagStart;Ve[0].tagStart-It,Ve[0].tagStart;var gt=new q.Buffer([24,83,128,103]),it=new q.Buffer("01ffffffffffffff","hex"),Zt=gt.byteLength+it.byteLength,Rt=Ut,Ue;for(Ue=1;Ue<20;Ue++){var ot=It+Zt+Rt,Jt=ot-Ot,Nt=zt+Jt,rt=ae(Ve,Nt,Te),tt=new F.default().encode(rt).byteLength;if(tt===Rt)return new F.default().encode([].concat(qe,[{type:"m",name:"Segment",isEnd:!1,unknownSize:!0}],rt));Rt=tt}throw new Error("unable to refine metadata, stable size could not be found in "+Ue+" iterations!")}q.putRefinedMetaData=oe;function le(_e){var Te=new F.default;return _e.reduce(function(qe,Ve){return qe.concat(Te.encode([Ve]))},[]).reduce(function(qe,Ve){return qe+Ve.byteLength},0)}function ae(_e,Te,qe){var Ve=qe.duration,We=qe.clusterPtrs,Fe=qe.cues,Ot=_e.slice(0);if(typeof Ve=="number"){var It=!1;Ot.forEach(function(zt){zt.type==="f"&&zt.name==="Duration"&&(It=!0,zt.data=ke(Ve,8))}),It||we(Ot,"Info",[{name:"Duration",type:"f",data:ke(Ve,8)}])}Array.isArray(Fe)&&we(Ot,"Cues",de(Fe,Te));var Dt=[];return Array.isArray(We)&&(console.warn("append cluster pointers to seekhead is deprecated. please use cues"),Dt=ce(We,Te)),we(Ot,"SeekHead",Dt,!0),Ot}function ce(_e,Te){var qe=[];return _e.forEach(function(Ve){qe.push({name:"Seek",type:"m",isEnd:!1}),qe.push({name:"SeekID",type:"b",data:new q.Buffer([31,67,182,117])}),qe.push({name:"SeekPosition",type:"u",data:me(Ve+Te)}),qe.push({name:"Seek",type:"m",isEnd:!0})}),qe}function de(_e,Te){var qe=[];return _e.forEach(function(Ve){var We=Ve.CueTrack,Fe=Ve.CueClusterPosition,Ot=Ve.CueTime;qe.push({name:"CuePoint",type:"m",isEnd:!1}),qe.push({name:"CueTime",type:"u",data:me(Ot)}),qe.push({name:"CueTrackPositions",type:"m",isEnd:!1}),qe.push({name:"CueTrack",type:"u",data:me(We)}),qe.push({name:"CueClusterPosition",type:"u",data:me(Fe+Te)}),qe.push({name:"CueTrackPositions",type:"m",isEnd:!0}),qe.push({name:"CuePoint",type:"m",isEnd:!0})}),qe}function we(_e,Te,qe,Ve){Ve===void 0&&(Ve=!1);for(var We=-1,Fe=0;Fe<_e.length;Fe++){var Ot=_e[Fe];if(Ot.type==="m"&&Ot.name===Te&&Ot.isEnd===!1){We=Fe;break}}We>=0?Array.prototype.splice.apply(_e,[We+1,0].concat(qe)):Ve?[].concat([{name:Te,type:"m",isEnd:!1}],qe,[{name:Te,type:"m",isEnd:!0}]).reverse().forEach(function(It){_e.unshift(It)}):(_e.push({name:Te,type:"m",isEnd:!1}),qe.forEach(function(It){_e.push(It)}),_e.push({name:Te,type:"m",isEnd:!0}))}function fe(_e){return q.Buffer.concat(_e)}q.concat=fe;function ge(_e){var Te=new q.Buffer(0);if(_e.type==="m")return _e;switch(_e.type){case"u":Te=me(_e.value);break;case"i":Te=ve(_e.value);break;case"f":Te=ke(_e.value);break;case"s":Te=new q.Buffer(_e.value,"ascii");break;case"8":Te=new q.Buffer(_e.value,"utf8");break;case"b":Te=_e.value;break;case"d":Te=new K.Int64BE(_e.value.getTime().toString()).toBuffer();break}return Object.assign({},_e,{data:Te})}q.encodeValueToBuffer=ge;function me(_e){for(var Te=1;_e>=Math.pow(2,8*Te);Te++);if(Te>=7)return console.warn("7bit or more bigger uint not supported."),new K.Uint64BE(_e).toBuffer();var qe=new q.Buffer(Te);return qe.writeUIntBE(_e,0,Te),qe}q.createUIntBuffer=me;function ve(_e){for(var Te=1;_e>=Math.pow(2,8*Te);Te++);if(Te>=7)return console.warn("7bit or more bigger uint not supported."),new K.Int64BE(_e).toBuffer();var qe=new q.Buffer(Te);return qe.writeIntBE(_e,0,Te),qe}q.createIntBuffer=ve;function ke(_e,Te){if(Te===void 0&&(Te=8),Te===8){var qe=new q.Buffer(8);return qe.writeDoubleBE(_e,0),qe}else if(Te===4){var qe=new q.Buffer(4);return qe.writeFloatBE(_e,0),qe}else throw new Error("float type bits must 4bytes or 8bytes")}q.createFloatBuffer=ke;function xe(_e){return _e instanceof Date?_e:new Date(new Date("2001-01-01T00:00:00.000Z").getTime()+Number(_e)/1e3/1e3)}q.convertEBMLDateToJSDate=xe}(tools)),tools}var hasRequiredEBMLDecoder;function requireEBMLDecoder(){if(hasRequiredEBMLDecoder)return EBMLDecoder;hasRequiredEBMLDecoder=1,Object.defineProperty(EBMLDecoder,"__esModule",{value:!0});var q=requireInt64Buffer(),K=requireTools(),F=requireTools(),Z=requireEbmlID(),D;(function(O){O[O.STATE_TAG=1]="STATE_TAG",O[O.STATE_SIZE=2]="STATE_SIZE",O[O.STATE_CONTENT=3]="STATE_CONTENT"})(D||(D={}));var N=function(){function O(){this._buffer=new K.Buffer(0),this._tag_stack=[],this._state=D.STATE_TAG,this._cursor=0,this._total=0,this._schema=Z.byEbmlID,this._result=[]}return O.prototype.decode=function(I){this.readChunk(I);var z=this._result;return this._result=[],z},O.prototype.readChunk=function(I){for(this._buffer=F.concat([this._buffer,new K.Buffer(I)]);this._cursor<this._buffer.length&&!(this._state===D.STATE_TAG&&!this.readTag()||this._state===D.STATE_SIZE&&!this.readSize()||this._state===D.STATE_CONTENT&&!this.readContent()););},O.prototype.getSchemaInfo=function(I){return this._schema[I]||{name:"unknown",level:-1,type:"unknown",description:"unknown"}},O.prototype.readTag=function(){if(this._cursor>=this._buffer.length)return!1;var I=(0,K.readVint)(this._buffer,this._cursor);if(I==null)return!1;var z=this._buffer.slice(this._cursor,this._cursor+I.length),J=z.reduce(function(re,te,oe,le){return re+te*Math.pow(16,2*(le.length-1-oe))},0),Q=this.getSchemaInfo(J),ne={EBML_ID:J.toString(16),schema:Q,type:Q.type,name:Q.name,level:Q.level,tagStart:this._total,tagEnd:this._total+I.length,sizeStart:this._total+I.length,sizeEnd:null,dataStart:null,dataEnd:null,dataSize:null,data:null};return this._tag_stack.push(ne),this._cursor+=I.length,this._total+=I.length,this._state=D.STATE_SIZE,!0},O.prototype.readSize=function(){if(this._cursor>=this._buffer.length)return!1;var I=(0,K.readVint)(this._buffer,this._cursor);if(I==null)return!1;var z=this._tag_stack[this._tag_stack.length-1];return z.sizeEnd=z.sizeStart+I.length,z.dataStart=z.sizeEnd,z.dataSize=I.value,I.value===-1?(z.dataEnd=-1,z.type==="m"&&(z.unknownSize=!0)):z.dataEnd=z.sizeEnd+I.value,this._cursor+=I.length,this._total+=I.length,this._state=D.STATE_CONTENT,!0},O.prototype.readContent=function(){var I=this._tag_stack[this._tag_stack.length-1];if(I.type==="m"){if(I.isEnd=!1,this._result.push(I),this._state=D.STATE_TAG,I.dataSize===0){var z=Object.assign({},I,{isEnd:!0});this._result.push(z),this._tag_stack.pop()}return!0}if(this._buffer.length<this._cursor+I.dataSize)return!1;var J=this._buffer.slice(this._cursor,this._cursor+I.dataSize);switch(this._buffer=this._buffer.slice(this._cursor+I.dataSize),I.data=J,I.type){case"u":I.value=J.readUIntBE(0,J.length);break;case"i":I.value=J.readIntBE(0,J.length);break;case"f":I.value=I.dataSize===4?J.readFloatBE(0):I.dataSize===8?J.readDoubleBE(0):(console.warn("cannot read ".concat(I.dataSize," octets float. failback to 0")),0);break;case"s":I.value=J.toString("ascii");break;case"8":I.value=J.toString("utf8");break;case"b":I.value=J;break;case"d":I.value=(0,K.convertEBMLDateToJSDate)(new q.Int64BE(J).toNumber());break}if(I.value===null)throw new Error("unknown tag type:"+I.type);for(this._result.push(I),this._total+=I.dataSize,this._state=D.STATE_TAG,this._cursor=0,this._tag_stack.pop();this._tag_stack.length>0;){var Q=this._tag_stack[this._tag_stack.length-1];if(Q.dataEnd<0)return this._tag_stack.pop(),!0;if(this._total<Q.dataEnd)break;if(Q.type!=="m")throw new Error("parent element is not master element");var z=Object.assign({},Q,{isEnd:!0});this._result.push(z),this._tag_stack.pop()}return!0},O}();return EBMLDecoder.default=N,EBMLDecoder}var EBMLReader={},events={exports:{}},hasRequiredEvents;function requireEvents(){if(hasRequiredEvents)return events.exports;hasRequiredEvents=1;var q=typeof Reflect=="object"?Reflect:null,K=q&&typeof q.apply=="function"?q.apply:function(ge,me,ve){return Function.prototype.apply.call(ge,me,ve)},F;q&&typeof q.ownKeys=="function"?F=q.ownKeys:Object.getOwnPropertySymbols?F=function(ge){return Object.getOwnPropertyNames(ge).concat(Object.getOwnPropertySymbols(ge))}:F=function(ge){return Object.getOwnPropertyNames(ge)};function Z(fe){console&&console.warn&&console.warn(fe)}var D=Number.isNaN||function(ge){return ge!==ge};function N(){N.init.call(this)}events.exports=N,events.exports.once=ce,N.EventEmitter=N,N.prototype._events=void 0,N.prototype._eventsCount=0,N.prototype._maxListeners=void 0;var O=10;function I(fe){if(typeof fe!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof fe)}Object.defineProperty(N,"defaultMaxListeners",{enumerable:!0,get:function(){return O},set:function(fe){if(typeof fe!="number"||fe<0||D(fe))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+fe+".");O=fe}}),N.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},N.prototype.setMaxListeners=function(ge){if(typeof ge!="number"||ge<0||D(ge))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+ge+".");return this._maxListeners=ge,this};function z(fe){return fe._maxListeners===void 0?N.defaultMaxListeners:fe._maxListeners}N.prototype.getMaxListeners=function(){return z(this)},N.prototype.emit=function(ge){for(var me=[],ve=1;ve<arguments.length;ve++)me.push(arguments[ve]);var ke=ge==="error",xe=this._events;if(xe!==void 0)ke=ke&&xe.error===void 0;else if(!ke)return!1;if(ke){var _e;if(me.length>0&&(_e=me[0]),_e instanceof Error)throw _e;var Te=new Error("Unhandled error."+(_e?" ("+_e.message+")":""));throw Te.context=_e,Te}var qe=xe[ge];if(qe===void 0)return!1;if(typeof qe=="function")K(qe,this,me);else for(var Ve=qe.length,We=oe(qe,Ve),ve=0;ve<Ve;++ve)K(We[ve],this,me);return!0};function J(fe,ge,me,ve){var ke,xe,_e;if(I(me),xe=fe._events,xe===void 0?(xe=fe._events=Object.create(null),fe._eventsCount=0):(xe.newListener!==void 0&&(fe.emit("newListener",ge,me.listener?me.listener:me),xe=fe._events),_e=xe[ge]),_e===void 0)_e=xe[ge]=me,++fe._eventsCount;else if(typeof _e=="function"?_e=xe[ge]=ve?[me,_e]:[_e,me]:ve?_e.unshift(me):_e.push(me),ke=z(fe),ke>0&&_e.length>ke&&!_e.warned){_e.warned=!0;var Te=new Error("Possible EventEmitter memory leak detected. "+_e.length+" "+String(ge)+" listeners added. Use emitter.setMaxListeners() to increase limit");Te.name="MaxListenersExceededWarning",Te.emitter=fe,Te.type=ge,Te.count=_e.length,Z(Te)}return fe}N.prototype.addListener=function(ge,me){return J(this,ge,me,!1)},N.prototype.on=N.prototype.addListener,N.prototype.prependListener=function(ge,me){return J(this,ge,me,!0)};function Q(){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 ne(fe,ge,me){var ve={fired:!1,wrapFn:void 0,target:fe,type:ge,listener:me},ke=Q.bind(ve);return ke.listener=me,ve.wrapFn=ke,ke}N.prototype.once=function(ge,me){return I(me),this.on(ge,ne(this,ge,me)),this},N.prototype.prependOnceListener=function(ge,me){return I(me),this.prependListener(ge,ne(this,ge,me)),this},N.prototype.removeListener=function(ge,me){var ve,ke,xe,_e,Te;if(I(me),ke=this._events,ke===void 0)return this;if(ve=ke[ge],ve===void 0)return this;if(ve===me||ve.listener===me)--this._eventsCount===0?this._events=Object.create(null):(delete ke[ge],ke.removeListener&&this.emit("removeListener",ge,ve.listener||me));else if(typeof ve!="function"){for(xe=-1,_e=ve.length-1;_e>=0;_e--)if(ve[_e]===me||ve[_e].listener===me){Te=ve[_e].listener,xe=_e;break}if(xe<0)return this;xe===0?ve.shift():le(ve,xe),ve.length===1&&(ke[ge]=ve[0]),ke.removeListener!==void 0&&this.emit("removeListener",ge,Te||me)}return this},N.prototype.off=N.prototype.removeListener,N.prototype.removeAllListeners=function(ge){var me,ve,ke;if(ve=this._events,ve===void 0)return this;if(ve.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):ve[ge]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete ve[ge]),this;if(arguments.length===0){var xe=Object.keys(ve),_e;for(ke=0;ke<xe.length;++ke)_e=xe[ke],_e!=="removeListener"&&this.removeAllListeners(_e);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(me=ve[ge],typeof me=="function")this.removeListener(ge,me);else if(me!==void 0)for(ke=me.length-1;ke>=0;ke--)this.removeListener(ge,me[ke]);return this};function re(fe,ge,me){var ve=fe._events;if(ve===void 0)return[];var ke=ve[ge];return ke===void 0?[]:typeof ke=="function"?me?[ke.listener||ke]:[ke]:me?ae(ke):oe(ke,ke.length)}N.prototype.listeners=function(ge){return re(this,ge,!0)},N.prototype.rawListeners=function(ge){return re(this,ge,!1)},N.listenerCount=function(fe,ge){return typeof fe.listenerCount=="function"?fe.listenerCount(ge):te.call(fe,ge)},N.prototype.listenerCount=te;function te(fe){var ge=this._events;if(ge!==void 0){var me=ge[fe];if(typeof me=="function")return 1;if(me!==void 0)return me.length}return 0}N.prototype.eventNames=function(){return this._eventsCount>0?F(this._events):[]};function oe(fe,ge){for(var me=new Array(ge),ve=0;ve<ge;++ve)me[ve]=fe[ve];return me}function le(fe,ge){for(;ge+1<fe.length;ge++)fe[ge]=fe[ge+1];fe.pop()}function ae(fe){for(var ge=new Array(fe.length),me=0;me<ge.length;++me)ge[me]=fe[me].listener||fe[me];return ge}function ce(fe,ge){return new Promise(function(me,ve){function ke(_e){fe.removeListener(ge,xe),ve(_e)}function xe(){typeof fe.removeListener=="function"&&fe.removeListener("error",ke),me([].slice.call(arguments))}we(fe,ge,xe,{once:!0}),ge!=="error"&&de(fe,ke,{once:!0})})}function de(fe,ge,me){typeof fe.on=="function"&&we(fe,"error",ge,me)}function we(fe,ge,me,ve){if(typeof fe.on=="function")ve.once?fe.once(ge,me):fe.on(ge,me);else if(typeof fe.addEventListener=="function")fe.addEventListener(ge,function ke(xe){ve.once&&fe.removeEventListener(ge,ke),me(xe)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof fe)}return events.exports}var hasRequiredEBMLReader;function requireEBMLReader(){if(hasRequiredEBMLReader)return EBMLReader;hasRequiredEBMLReader=1;var q=EBMLReader&&EBMLReader.__extends||function(){var D=function(N,O){return D=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,z){I.__proto__=z}||function(I,z){for(var J in z)Object.prototype.hasOwnProperty.call(z,J)&&(I[J]=z[J])},D(N,O)};return function(N,O){if(typeof O!="function"&&O!==null)throw new TypeError("Class extends value "+String(O)+" is not a constructor or null");D(N,O);function I(){this.constructor=N}N.prototype=O===null?Object.create(O):(I.prototype=O.prototype,new I)}}();Object.defineProperty(EBMLReader,"__esModule",{value:!0});var K=requireEvents(),F=requireTools(),Z=function(D){q(N,D);function N(){var O=D.call(this)||this;return O.logGroup="",O.hasLoggingStarted=!1,O.metadataloaded=!1,O.chunks=[],O.stack=[],O.segmentOffset=0,O.last2SimpleBlockVideoTrackTimecode=[0,0],O.last2SimpleBlockAudioTrackTimecode=[0,0],O.lastClusterTimecode=0,O.lastClusterPosition=0,O.timecodeScale=1e6,O.metadataSize=0,O.metadatas=[],O.cues=[],O.firstVideoBlockRead=!1,O.firstAudioBlockRead=!1,O.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null},O.trackTypes=[],O.trackDefaultDuration=[],O.trackCodecDelay=[],O.trackInfo={type:"nothing"},O.ended=!1,O.logging=!1,O.use_duration_every_simpleblock=!1,O.use_webp=!1,O.use_segment_info=!0,O.drop_default_duration=!0,O}return N.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()},N.prototype.emit_segment_info=function(){var O=this.chunks;if(this.chunks=[],this.metadataloaded){if(!this.use_segment_info)return;var J=this.lastClusterTimecode,Q=this.duration,ne=this.timecodeScale;this.emit("cluster",{timecode:J,data:O}),this.emit("duration",{timecodeScale:ne,duration:Q})}else{this.metadataloaded=!0,this.metadatas=O;var I=this.trackTypes.indexOf(1),z=this.trackTypes.indexOf(2);if(this.trackInfo=I>=0&&z>=0?{type:"both",trackNumber:I}:I>=0?{type:"video",trackNumber:I}:z>=0?{type:"audio",trackNumber:z}:{type:"nothing"},!this.use_segment_info)return;this.emit("metadata",{data:O,metadataSize:this.metadataSize})}},N.prototype.read=function(O){var I=this,z=!1;if(!this.ended){if(O.type==="m")if(O.isEnd)this.stack.pop();else{var J=this.stack[this.stack.length-1];if(J!=null&&J.level>=O.level){this.stack.pop(),this.logging&&console.groupEnd(),J.dataEnd=O.dataEnd,J.dataSize=O.dataEnd-J.dataStart,J.unknownSize=!1;var Q=Object.assign({},J,{name:J.name,type:J.type,isEnd:!0});this.chunks.push(Q)}this.stack.push(O)}if(O.type==="m"&&O.name=="Segment")this.segmentOffset!=0&&console.warn("Multiple segments detected!"),this.segmentOffset=O.dataStart,this.emit("segment_offset",this.segmentOffset);else if(O.type==="b"&&O.name==="SimpleBlock"){var ne=F.ebmlBlock(O.data),re=ne.timecode,te=ne.trackNumber,oe=ne.frames;if(this.trackTypes[te]===1){if(!this.firstVideoBlockRead&&(this.firstVideoBlockRead=!0,this.trackInfo.type==="both"||this.trackInfo.type==="video")){var le=this.lastClusterTimecode+re;this.cues.push({CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le}),this.emit("cue_info",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le})}this.last2SimpleBlockVideoTrackTimecode=[this.last2SimpleBlockVideoTrackTimecode[1],re]}else if(this.trackTypes[te]===2){if(!this.firstAudioBlockRead&&(this.firstAudioBlockRead=!0,this.trackInfo.type==="audio")){var le=this.lastClusterTimecode+re;this.cues.push({CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le}),this.emit("cue_info",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:te,CueClusterPosition:this.lastClusterPosition,CueTime:le})}this.last2SimpleBlockAudioTrackTimecode=[this.last2SimpleBlockAudioTrackTimecode[1],re]}this.use_duration_every_simpleblock&&this.emit("duration",{timecodeScale:this.timecodeScale,duration:this.duration}),this.use_webp&&oe.forEach(function(ae){var ce=ae.slice(3,6).toString("hex");if(ce==="9d012a"){var de=F.VP8BitStreamToRiffWebPBuffer(ae),we=new Blob([de],{type:"image/webp"}),fe=I.duration;I.emit("webp",{currentTime:fe,webp:we})}})}else O.type==="m"&&O.name==="Cluster"&&O.isEnd===!1?(this.firstVideoBlockRead=!1,this.firstAudioBlockRead=!1,this.emit_segment_info(),this.emit("cluster_ptr",O.tagStart),this.lastClusterPosition=O.tagStart):O.type==="u"&&O.name==="Timecode"?this.lastClusterTimecode=O.value:O.type==="u"&&O.name==="TimecodeScale"?this.timecodeScale=O.value:O.type==="m"&&O.name==="TrackEntry"?O.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}:O.type==="u"&&O.name==="TrackType"?this.currentTrack.TrackType=O.value:O.type==="u"&&O.name==="TrackNumber"?this.currentTrack.TrackNumber=O.value:O.type==="u"&&O.name==="CodecDelay"?this.currentTrack.CodecDelay=O.value:O.type==="u"&&O.name==="DefaultDuration"?this.drop_default_duration?(console.warn("DefaultDuration detected!, remove it"),z=!0):this.currentTrack.DefaultDuration=O.value:O.name==="unknown"&&console.warn(O);!this.metadataloaded&&O.dataEnd>0&&(this.metadataSize=O.dataEnd),z||this.chunks.push(O),this.logging&&this.put(O)}},Object.defineProperty(N.prototype,"duration",{get:function(){if(this.trackInfo.type==="nothing")return console.warn("no video, no audio track"),0;var O=0,I=0,z=0,J=this.trackDefaultDuration[this.trackInfo.trackNumber];if(typeof J=="number")O=J;else if(this.trackInfo.type==="both")if(this.last2SimpleBlockAudioTrackTimecode[1]>this.last2SimpleBlockVideoTrackTimecode[1]){O=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackTypes.indexOf(2)];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockAudioTrackTimecode[1]}else{O=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackTypes.indexOf(1)];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="video"){O=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackInfo.trackNumber];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockVideoTrackTimecode[1]}else if(this.trackInfo.type==="audio"){O=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale;var Q=this.trackCodecDelay[this.trackInfo.trackNumber];typeof Q=="number"&&(I=Q),z=this.last2SimpleBlockAudioTrackTimecode[1]}var ne=(this.lastClusterTimecode+z)*this.timecodeScale+O-I,re=ne/this.timecodeScale;return Math.floor(re)},enumerable:!1,configurable:!0}),N.prototype.addListener=function(O,I){return D.prototype.addListener.call(this,O,I)},N.prototype.put=function(O){this.hasLoggingStarted||(this.hasLoggingStarted=!0,this.logging&&this.logGroup&&console.groupCollapsed(this.logGroup)),O.type==="m"?O.isEnd?console.groupEnd():console.group(O.name+":"+O.tagStart):O.type==="b"?console.log(O.name,O.type):console.log(O.name,O.tagStart,O.type,O.value)},N}(K.EventEmitter);return EBMLReader.default=Z,EBMLReader}var hasRequiredEbml;function requireEbml(){return hasRequiredEbml||(hasRequiredEbml=1,function(q){var K=ebml&&ebml.__createBinding||(Object.create?function(I,z,J,Q){Q===void 0&&(Q=J),Object.defineProperty(I,Q,{enumerable:!0,get:function(){return z[J]}})}:function(I,z,J,Q){Q===void 0&&(Q=J),I[Q]=z[J]}),F=ebml&&ebml.__exportStar||function(I,z){for(var J in I)J!=="default"&&!Object.prototype.hasOwnProperty.call(z,J)&&K(z,I,J)};Object.defineProperty(q,"__esModule",{value:!0}),q.tools=q.Reader=q.Encoder=q.Decoder=void 0,F(requireEBML(),q);var Z=requireEBMLDecoder();q.Decoder=Z.default;var D=requireEBMLEncoder();q.Encoder=D.default;var N=requireEBMLReader();q.Reader=N.default;var O=requireTools();q.tools=O}(ebml)),ebml}var hasRequiredLib;function requireLib(){if(hasRequiredLib)return lib;hasRequiredLib=1;var q=lib&&lib.__awaiter||function(D,N,O,I){function z(J){return J instanceof O?J:new O(function(Q){Q(J)})}return new(O||(O=Promise))(function(J,Q){function ne(oe){try{te(I.next(oe))}catch(le){Q(le)}}function re(oe){try{te(I.throw(oe))}catch(le){Q(le)}}function te(oe){oe.done?J(oe.value):z(oe.value).then(ne,re)}te((I=I.apply(D,N||[])).next())})},K=lib&&lib.__generator||function(D,N){var O={label:0,sent:function(){if(J[0]&1)throw J[1];return J[1]},trys:[],ops:[]},I,z,J,Q;return Q={next:ne(0),throw:ne(1),return:ne(2)},typeof Symbol=="function"&&(Q[Symbol.iterator]=function(){return this}),Q;function ne(te){return function(oe){return re([te,oe])}}function re(te){if(I)throw new TypeError("Generator is already executing.");for(;O;)try{if(I=1,z&&(J=te[0]&2?z.return:te[0]?z.throw||((J=z.return)&&J.call(z),0):z.next)&&!(J=J.call(z,te[1])).done)return J;switch(z=0,J&&(te=[te[0]&2,J.value]),te[0]){case 0:case 1:J=te;break;case 4:return O.label++,{value:te[1],done:!1};case 5:O.label++,z=te[1],te=[0];continue;case 7:te=O.ops.pop(),O.trys.pop();continue;default:if(J=O.trys,!(J=J.length>0&&J[J.length-1])&&(te[0]===6||te[0]===2)){O=0;continue}if(te[0]===3&&(!J||te[1]>J[0]&&te[1]<J[3])){O.label=te[1];break}if(te[0]===6&&O.label<J[1]){O.label=J[1],J=te;break}if(J&&O.label<J[2]){O.label=J[2],O.ops.push(te);break}J[2]&&O.ops.pop(),O.trys.pop();continue}te=N.call(D,O)}catch(oe){te=[6,oe],z=0}finally{I=J=0}if(te[0]&5)throw te[1];return{value:te[0]?te[1]:void 0,done:!0}}};Object.defineProperty(lib,"__esModule",{value:!0});var F=requireEbml();function Z(D){return q(this,void 0,void 0,function(){var N,O,I,z,J,Q,ne,re,te,oe,le,ae;return K(this,function(ce){switch(ce.label){case 0:if(!D)throw Error("call to fixWebmDuration requires a blob");N=new F.Decoder,O=new F.Reader,I=D.stream(),z=I.getReader(),ce.label=1;case 1:return[4,z.read()];case 2:return J=ce.sent(),Q=J.done,ne=J.value,Q?(O.stop(),[3,3]):(re=N.decode(ne),re=re==null?void 0:re.filter(function(de){return de.type!=="unknown"}),re.forEach(function(de){O.read(de)}),ne=null,[3,1]);case 3:return te=F.tools.makeMetadataSeekable(O.metadatas,O.duration,O.cues),oe=new Blob([te],{type:D.type}),le=D.slice(O.metadataSize),ae=new Blob([oe,le],{type:D.type}),[2,ae]}})})}return lib.default=Z,lib}var libExports=requireLib();const fixWebmDuration=getDefaultExportFromCjs(libExports);class StreamRecorder{constructor(){st(this,en);st(this,yn,!1);st(this,pn,!1);st(this,xn,0);st(this,Cn,0);st(this,cn,0);st(this,un,0);st(this,vn,0);Ie(this,"onchange",K=>{});Ie(this,"onDurationChange",K=>{});Ie(this,"start",async(K="")=>{K||(K=`video_Record_${E$1(Date.now())}`);let F=[];return navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}).then(Z=>{const D=Z.getTracks();for(const O of D)O.onended=()=>this.stop();At(this,yn,!0),At(this,pn,!1),At(this,en,new MediaRecorder(Z)),Be(this,en).start();const N=new Date().getTime();At(this,xn,N),At(this,cn,N),Be(this,bn).call(this),Be(this,Rn).call(this),Be(this,en).addEventListener("dataavailable",O=>{F.push(O.data)}),Be(this,en).addEventListener("stop",async()=>{At(this,yn,!1);const O=new Date().getTime();At(this,Cn,O),At(this,un,Be(this,un)+(O-Be(this,cn))),Be(this,bn).call(this),clearInterval(Be(this,vn));const I=Z.getTracks();for(const re of I)re.stop();if(Be(this,en)===null)return;const z=new Blob(F,{type:Be(this,en).mimeType}),J=await fixWebmDuration(z),Q=URL.createObjectURL(J),ne=document.createElement("a");ne.href=Q,ne.download=`${K}.mp4`,ne.click(),URL.revokeObjectURL(Q),F=[],At(this,en,null)})})});Ie(this,"pause",async()=>{var F;await new Promise(Z=>setTimeout(()=>Z(!0),300)),(F=Be(this,en))==null||F.pause(),At(this,pn,!0);const K=new Date().getTime();At(this,un,Be(this,un)+(K-Be(this,cn))),Be(this,bn).call(this),clearInterval(Be(this,vn))});Ie(this,"resume",async()=>{var F;(F=Be(this,en))==null||F.resume(),At(this,pn,!1);const K=new Date().getTime();At(this,cn,K),Be(this,bn).call(this),Be(this,Rn).call(this)});Ie(this,"stop",async()=>{var K;(K=Be(this,en))==null||K.stop()});Ie(this,"getDuration",()=>{if(Be(this,cn)===0)return 0;let K=Be(this,un);const F=new Date().getTime();if(Be(this,yn)&&Be(this,pn)===!1){const Z=F-Be(this,cn);At(this,cn,F),K=K+Z}return K});Ie(this,"getInfo",()=>({active:Be(this,yn),pause:Be(this,pn),startTime:Be(this,xn),endTime:Be(this,Cn),duration:Be(this,un)}));st(this,bn,()=>{const K=this.getInfo();this.onchange(K)});st(this,Rn,()=>{clearInterval(Be(this,vn)),At(this,vn,window.setInterval(()=>{At(this,un,this.getDuration()),this.onDurationChange(Be(this,un))},500))})}}en=new WeakMap,yn=new WeakMap,pn=new WeakMap,xn=new WeakMap,Cn=new WeakMap,cn=new WeakMap,un=new WeakMap,vn=new WeakMap,bn=new WeakMap,Rn=new WeakMap;class RoomBase{constructor(K){Ie(this,"options",{appid:"",sdkToken:"",roomId:"",userId:"",earlyId:"",callType:0,debug:!1,reportErr:!0,logUrl:"https://logs1.quickvo.org",newPublishAutoSubscribe:!0});Ie(this,"sdk_service_version","1.0.6");Ie(this,"prohibitNotify",!1);Ie(this,"isEarly",!1);Ie(this,"isInRoom",!1);Ie(this,"taskQueue");Ie(this,"roomState","ready");Ie(this,"createAt",Date.now());Ie(this,"cwsIns");Ie(this,"peerIns");Ie(this,"transceiverMap",new Map);Ie(this,"sendChannel");Ie(this,"receiveChannel");Ie(this,"userMap",new Map);Ie(this,"setLocalStreamActiveMap",new Map);Ie(this,"phoneyStreams",new Map);Ie(this,"recorder",new StreamRecorder);Ie(this,"networkQualityTester",new NetworkQualityTester);Ie(this,"mediaDevicesErrInfo",{microphoneCamera_audio:"",microphoneCamera_video:"",screenSharing_video:"",screenSharing_audio:""});Ie(this,"reportLogs",(K,F="未知错误")=>{const{appid:Z,userId:D,earlyId:N="",logUrl:O,reportErr:I}=this.options;if(!I)return;const z="web",J=Q=>({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})[Q].toString();{const Q=J(K),ne={origin:z,type:Q,app_id:Z,user_id:D,ins_id:N,desc:F},re=btoa(encodeURI(JSON.stringify(ne))),te=`${O}/upload/log?log_key=${re}`;{const oe=localStorage.getItem("#quickvo.logs")||JSON.stringify([]),ae=new TextEncoder().encode(oe),ce=pako.deflate(ae,{gzip:!0});this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: reportLogs",{obj:ne,url:te,size:lt(ce.byteLength)}),fetch(te,{headers:{"Content-Type":"multipart/form-data"},method:"POST",body:ce})}}});Ie(this,"initPhoneyStreams",(K,F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F){const D=this.phoneyStreams.get(Z);if(D){const N=D.getTracks();for(const O of N)O.stop()}switch(Z){case"microphoneCamera_audio":this.phoneyStreams.set("microphoneCamera_audio",createMutedAudioStream(K));break;case"microphoneCamera_video":this.phoneyStreams.set("microphoneCamera_video",createFakeVideoStream());break;case"screenSharing_audio":this.phoneyStreams.set("screenSharing_audio",createMutedAudioStream(K));break;case"screenSharing_video":this.phoneyStreams.set("screenSharing_video",createFakeVideoStream());break}}});Ie(this,"getPhoneyStreams",K=>this.phoneyStreams.get(K));Ie(this,"getRoomInfo",()=>{const{options:K,roomState:F,createAt:Z}=this;return{...K,roomState:F,createAt:Z}});Ie(this,"setRoomState",K=>{this.roomState=K;const F=enum_roomState[K],Z={state:K,stateStr:F};this.cwsIns.emitNotify("onRoomState",{code:200,data:Z,desc:"room state is change."})});Ie(this,"setOptions",async K=>{const F={...this.options,...K};this.options=F});Ie(this,"stopStream",async K=>{const F=K.getTracks();for(const Z of F)Z.stop()});Ie(this,"getMediaDevicesErrInfo",async()=>{try{const K=await navigator.mediaDevices.enumerateDevices();K.find(Z=>Z.kind==="audioinput")||(this.mediaDevicesErrInfo.microphoneCamera_audio="audioinput is not available."),K.find(Z=>Z.kind==="videoinput")||(this.mediaDevicesErrInfo.microphoneCamera_video="videoinput is not available.")}catch(K){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getMediaDevicesErrInfo is error.",K)}return this.mediaDevicesErrInfo});Ie(this,"getUserMediaKey",(K,F)=>`${K}-${F}`);Ie(this,"getCallAction",async K=>{let F="";const Z=N=>K.findIndex(({type:I,enabled:z=!0})=>I===N&&z)===-1?"0":"1";return F=`${Z(0)}${F}`,F=`${Z(1)}${F}`,F=`${Z(2)}${F}`,F=`${Z(3)}${F}`,parseInt(F,2)});Ie(this,"getCallActionMap",(K=0)=>{const Z=Number(K).toString(2).padStart(4,"0").split(""),[D,N,O,I]=Z;return{microphoneCamera_audio:!!Number(I),microphoneCamera_video:!!Number(O),screenSharing_video:!!Number(N),screenSharing_audio:!!Number(D)}});Ie(this,"getBanBehaviorMap",(K=0)=>{const Z=Number(K).toString(2).padStart(4,"0").split(""),[D,N,O,I]=Z;return{microphoneCamera_audio:!!Number(I),microphoneCamera_video:!!Number(O),screenSharing_video:!!Number(N),screenSharing_audio:!!Number(D)}});Ie(this,"getAverageVolume",(K,F)=>{K.getByteFrequencyData(F);let Z=0;for(let N=0;N<F.length;N++)Z+=F[N];return Math.ceil(Z/F.length)});Ie(this,"getTrackNamesFormTracks",(K,F=[],Z="trackName")=>{const D=[];for(const N of K){const{type:O}=N;if(F.length===0||F.includes(O)){const I=N[Z];I&&D.push(`${I}`)}}return D});Ie(this,"usersFilter",K=>dt(K,["id","isSelf","isOwner","joinTime","tracks","network","permissions","isPublished","updateStreams","callAction","callActionStr","callActionMap","banBehavior","banBehaviorStr","banBehaviorMap"]).sort((D,N)=>D.id.localeCompare(N.id,"en")));this.setOptions(K),this.cwsIns=new CallsWebSocket({...K}),this.taskQueue=new Y(["createWs","createSession","ice","joinRoom","createTrack","publish","subscribe","renegotiate","closeTrack"],{debug:K.debug}),this.taskQueue.setCondition("createSession",!1),this.taskQueue.setCondition("ice",!1),this.options.debug&&this.networkQualityTester.testAll().then(F=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: networkQualityTester",F)})}}var m=Object.defineProperty,G=(q,K,F)=>K in q?m(q,K,{enumerable:!0,configurable:!0,writable:!0,value:F}):q[K]=F,e$1=(q,K,F)=>G(q,typeof K!="symbol"?K+"":K,F);class g{constructor(K,F){e$1(this,"inputStream",new MediaStream),e$1(this,"outputStream",new MediaStream),e$1(this,"inputGain",1),e$1(this,"enhanceGain",1),e$1(this,"bgsGain",1),e$1(this,"bgmGain",1),e$1(this,"outputGain",1),e$1(this,"mixAudioMap",new Map),e$1(this,"audioContext",new AudioContext),e$1(this,"sourceNode"),e$1(this,"inputGainNode"),e$1(this,"enhanceGainNode"),e$1(this,"bgsGainNode"),e$1(this,"bgmGainNode"),e$1(this,"analyserNode"),e$1(this,"analyserArrayData"),e$1(this,"outputGainNode"),e$1(this,"destinationNode"),e$1(this,"filterStream",Z=>Z),e$1(this,"stop",()=>{{const Z=this.inputStream.getTracks();for(const D of Z)D.stop(),this.inputStream.removeTrack(D)}}),e$1(this,"getStream",()=>this.filterStream(this.outputStream)),e$1(this,"setMute",(Z=!0)=>{Z?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),e$1(this,"setInputGain",Z=>{this.inputGain=Z,this.inputGainNode.gain.setValueAtTime(Z,this.audioContext.currentTime)}),e$1(this,"setEnhanceGain",async Z=>{this.enhanceGain=Z+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),e$1(this,"setBgsGain",Z=>{this.bgsGain=Z,this.bgsGainNode.gain.setValueAtTime(Z,this.audioContext.currentTime)}),e$1(this,"setBgmGain",Z=>{this.bgmGain=Z,this.bgmGainNode.gain.setValueAtTime(Z,this.audioContext.currentTime)}),e$1(this,"setOutputGain",Z=>{this.outputGain=Z,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),e$1(this,"getVolume",()=>{const{analyserNode:Z,analyserArrayData:D}=this;Z.getByteFrequencyData(D);let N=0;for(let O=0;O<D.length;O++)N+=D[O];return Math.ceil(N/D.length)}),e$1(this,"mixAudio",(Z,D="bgm")=>new Promise(async(N,O)=>{try{{const J=this.mixAudioMap.get(D);J&&J.stop()}const I=D==="bgs"?this.bgsGainNode:this.bgmGainNode,z=this.audioContext.createBufferSource();this.mixAudioMap.set(D,z),z.buffer=Z,z.connect(I),z.onended=()=>{z.disconnect(I),this.mixAudioMap.delete(D),N(!0)},z.start(0)}catch(I){O(I)}})),e$1(this,"mixAudioStop",Z=>{const D=this.mixAudioMap.get(Z);D==null||D.stop()}),e$1(this,"changeMix",(Z,D)=>{const N=Z==="bgs"?this.bgsGainNode:this.bgmGainNode;D?N.connect(this.destinationNode):N.disconnect(this.destinationNode)}),F&&(this.audioContext=F),this.inputStream=K,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:Z,inputGainNode:D,enhanceGainNode:N,bgsGainNode:O,bgmGainNode:I,analyserNode:z,outputGainNode:J,destinationNode:Q}=this;Z.connect(D),D.connect(N),N.connect(z),O.connect(z),I.connect(z),N.connect(Q),O.connect(Q),I.connect(Q),z.connect(J),J.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}class RoomMedias extends RoomBase{constructor(F){super(F);st(this,kn,[]);st(this,tn,new Map);st(this,jt,new Map);st(this,ln,new Map);st(this,fn,new Map);st(this,mn,new Map);Ie(this,"localStreamsActionMap",new Map);st(this,Sn,new Map);Ie(this,"audioContext",new(window.AudioContext||window.webkitAudioContext));Ie(this,"initMediaPhoneyStreams",(F=[])=>this.initPhoneyStreams(this.audioContext,F));Ie(this,"initLocalStreamsFilter",()=>{for(const F of mediaType_keys){const Z=async D=>D;Be(this,Sn).set(F,Z)}});Ie(this,"setLocalFilterStream",(F,Z)=>{Be(this,Sn).set(F,Z)});st(this,Ln,()=>{Be(this,jt).set("microphoneCamera_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0}),Be(this,jt).set("microphoneCamera_video",{frameRate:{min:10,ideal:30}}),Be(this,jt).set("screenSharing_video",{frameRate:{min:10,ideal:30}}),Be(this,jt).set("screenSharing_audio",{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0})});st(this,Fn,()=>{Be(this,tn).set("audioinput","default"),Be(this,tn).set("videoinput","default"),Be(this,tn).set("audiooutput","default")});Ie(this,"emitNotifyUpdateUsersStreams",async F=>{this.cwsIns.emitNotify("onRoomUsersStreams",{code:200,data:F,desc:"users streams is change."})});Ie(this,"initUserMediaStreamContext",async(F,Z,D)=>{const[N]=D.getTracks();if(!N){console.warn("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: tracks.length is 0.",{userId:F,mediaType:Z,stream:D});return}this.removeUserMediaStreamContext(F,Z);const O=this.getUserMediaKey(F,Z),{kind:I}=N;switch(I){case"audio":{const z=new MediaStream;z.addTrack(N);const J=new g(z,this.audioContext);Be(this,ln).set(O,J)}break;case"video":{const z=new VideoMediaContext(N);Be(this,fn).set(O,z)}break}});Ie(this,"getUserMediaStreamContext",(F,Z)=>{const D=this.getUserMediaKey(F,Z);if(["microphoneCamera_audio","screenSharing_audio"].includes(Z))return Be(this,ln).get(D);if(["microphoneCamera_video","screenSharing_video"].includes(Z))return Be(this,fn).get(D)});Ie(this,"getUserAudioMediaStreamContext",(F,Z)=>{const D=this.getUserMediaKey(F,Z);return Be(this,ln).get(D)});Ie(this,"removeUserMediaStreamContext",(F,Z)=>{const D=this.getUserMediaKey(F,Z);if(["microphoneCamera_audio","screenSharing_audio"].includes(Z)){const N=Be(this,ln).get(D);return N==null||N.stop(),Be(this,ln).delete(D)}if(["microphoneCamera_video","screenSharing_video"].includes(Z)){const N=Be(this,fn).get(D);return N==null||N.stop(),Be(this,fn).get(D)}});Ie(this,"getUserStream",(F,Z)=>{const D=this.getUserMediaStreamContext(F,Z);return(D==null?void 0:D.getStream())||new MediaStream});Ie(this,"getUserStreams",(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);const D={};for(const N of Z){const O=this.getUserStream(F,N);D[N]=O}return D});Ie(this,"removeUserStreams",async(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);for(const D of Z)this.removeUserMediaStreamContext(F,D)});Ie(this,"clearUserStreams",()=>{{const F=Be(this,ln).values();for(const Z of F)Z.stop();At(this,ln,new Map)}{const F=Be(this,fn).values();for(const Z of F)Z.stop();At(this,fn,new Map)}});Ie(this,"setMediaTrackConstraints",async(F,Z)=>{Be(this,jt).set(F,Z);const D=await this.getLocalStream(F);if(!D)return;const N=D.getTracks();if(N.length!==0)for(const O of N){const I=O.getConstraints(),J={...Be(this,jt).get(F),...I,...Z};await O.applyConstraints(J)}});Ie(this,"stopLocalStreams",async(F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F){const D=Be(this,mn).get(Z);D&&await this.stopStream(D),Be(this,mn).delete(Z)}});Ie(this,"addLocalStream",(F,Z)=>{const D=Be(this,mn).get(F);D&&this.stopStream(D),Be(this,mn).set(F,Z)});Ie(this,"initLocalStream",async F=>{switch(F){case"microphoneCamera_audio":{const Z=Be(this,tn).get("audioinput"),D=Be(this,jt).get("microphoneCamera_audio"),N=await navigator.mediaDevices.getUserMedia({audio:{deviceId:Z,...D},video:!1});this.addLocalStream("microphoneCamera_audio",N)}break;case"microphoneCamera_video":{const Z=Be(this,tn).get("videoinput"),D=Be(this,jt).get("microphoneCamera_video"),N=await navigator.mediaDevices.getUserMedia({audio:!1,video:{deviceId:Z,...D}});this.addLocalStream("microphoneCamera_video",N)}break;case"microphoneCamera":{const Z=Be(this,tn).get("audioinput"),D=Be(this,tn).get("videoinput"),N=Be(this,jt).get("microphoneCamera_audio"),O=Be(this,jt).get("microphoneCamera_video"),z=(await navigator.mediaDevices.getUserMedia({audio:{deviceId:Z,...N},video:{deviceId:D,...O}})).getTracks();for(const J of z){const{kind:Q}=J;if(Q==="audio"){const ne=new MediaStream;ne.addTrack(J),this.addLocalStream("microphoneCamera_audio",ne)}if(Q==="video"){const ne=new MediaStream;ne.addTrack(J),this.addLocalStream("microphoneCamera_video",ne)}}}break;case"screenSharing_audio":{const Z=Be(this,jt).get("screenSharing_audio"),N=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...Z})).getTracks();for(const O of N){const{kind:I}=O;if(I==="audio"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_audio",z)}}}break;case"screenSharing_video":{const Z=Be(this,jt).get(F),N=(await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0,...Z})).getTracks();for(const O of N){const{kind:I}=O;if(I==="video"){const z=new MediaStream;z.addTrack(O),this.addLocalStream("screenSharing_video",z)}}}break;case"screenSharing":{const Z=Be(this,jt).get("screenSharing_audio"),D=Be(this,jt).get("screenSharing_video"),O=(await navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0,...Z,...D})).getTracks();for(const I of O){const{kind:z}=I;if(z==="audio"){const J=new MediaStream;J.addTrack(I),this.addLocalStream("screenSharing_audio",J)}if(z==="video"){const J=new MediaStream;J.addTrack(I),this.addLocalStream("screenSharing_video",J)}}}break}});Ie(this,"getLocalStream",async F=>{const Z=Be(this,mn).get(F),D=Be(this,Sn).get(F);let N=Z;return Z&&D&&(N=await D(Z)),N});Ie(this,"getLocalStreams",async(F=[])=>{F.length===0&&(F=mediaType_keys);const Z={};for(const D of F)Z[D]=await this.getLocalStream(D);return Z});st(this,Tn,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(F=>{const Z=F.filter(D=>!["default","communications"].includes(D.deviceId));At(this,kn,Z.sort((D,N)=>D.label.localeCompare(N.label,"zh-Hans-CN",{sensitivity:"accent"})))}).catch(function(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: getEnumerateDevices is err",F)}),Be(this,kn)));st(this,Hn,()=>{navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=async()=>{await Be(this,Tn).call(this),this.cwsIns.emitNotify("onDevicechange",{code:200,data:{},desc:"device is change."})}),Be(this,Tn).call(this)});Ie(this,"getMediaDeviceKind",F=>Be(this,tn).get(F));Ie(this,"changeAudiooutput",async()=>{try{const F=Be(this,tn).get("audiooutput");await this.audioContext.setSinkId(F)}catch(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setSinkId is error.",F)}});Ie(this,"setDeviceKind",(F,Z)=>{Be(this,tn).set(F,Z)});Ie(this,"setAudioOutputDevice",F=>this.setDeviceKind("audiooutput",F));Ie(this,"getEnumerateDevices",async F=>(await Be(this,Tn).call(this),Be(this,kn).filter(D=>D.kind===F)));Ie(this,"getEnumerateAudioinputDevices",()=>this.getEnumerateDevices("audioinput"));Ie(this,"getEnumerateAudioOutputDevices",()=>this.getEnumerateDevices("audiooutput"));Ie(this,"getEnumerateVideoinputDevices",()=>this.getEnumerateDevices("videoinput"));Be(this,Hn).call(this),Be(this,Fn).call(this),Be(this,Ln).call(this),this.initPhoneyStreams(this.audioContext),document.addEventListener("click",()=>{var Z;((Z=this.audioContext)==null?void 0:Z.state)==="suspended"&&this.audioContext.resume()})}}kn=new WeakMap,tn=new WeakMap,jt=new WeakMap,ln=new WeakMap,fn=new WeakMap,mn=new WeakMap,Sn=new WeakMap,Ln=new WeakMap,Fn=new WeakMap,Tn=new WeakMap,Hn=new WeakMap;class RoomUsers extends RoomMedias{constructor(F){super(F);Ie(this,"getMaxVolumeUser",()=>{const F=Array.from(this.userMap.values(),({id:D})=>D);if(F.length===0)return;let Z=[];for(const D of F){const N=this.getUserAudioMediaStreamContext(D,"microphoneCamera_audio");if(!N)continue;const O=N.getVolume();Z.push({id:D,volume:O})}return Z=Z.sort((D,N)=>D.volume-N.volume>0?-1:1),Z[0]});Ie(this,"setVolume",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setInputGain(D)});Ie(this,"setEnhanceGain",async(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setEnhanceGain(D)});Ie(this,"setSpeaker",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setOutputGain(D);const O=D===0;N==null||N.setMute(O)});Ie(this,"playBgs",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);return N==null?void 0:N.mixAudio(D,"bgs")});Ie(this,"setBgsGain",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setBgsGain(D)});Ie(this,"stopBgs",(F,Z)=>{const D=this.getUserAudioMediaStreamContext(F,Z);D==null||D.mixAudioStop("bgs")});Ie(this,"playBgm",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);return N==null?void 0:N.mixAudio(D,"bgm")});Ie(this,"setBgmGain",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.setBgmGain(D)});Ie(this,"stopBgm",(F,Z)=>{const D=this.getUserAudioMediaStreamContext(F,Z);D==null||D.mixAudioStop("bgm")});Ie(this,"changBgsMix",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.changeMix("bgs",D)});Ie(this,"changBgmMix",(F,Z,D)=>{const N=this.getUserAudioMediaStreamContext(F,Z);N==null||N.changeMix("bgm",D)});Ie(this,"getVolume",(F,Z)=>{const D=this.getUserAudioMediaStreamContext(F,Z);return D==null?void 0:D.getVolume()});Ie(this,"clearUsers",()=>{this.userMap=new Map});Ie(this,"removeUsers",async F=>{for(const Z of F)this.userMap.delete(Z),await this.removeUserStreams(Z)});Ie(this,"createUser",async F=>{const Z=Date.now(),D={id:F,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:F===this.options.userId,isPublished:!1,joinTime:Z,updateAt:Z,network:{egress:0,ingress:0},tracks:[],channels:[],updateStreams:{microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1}};this.userMap.set(F,D)});Ie(this,"getUser",async F=>(this.userMap.has(F)||await this.createUser(F),this.userMap.get(F)));Ie(this,"getUsers",async(F=[])=>{F.length===0&&(F=[...this.userMap.keys()]);const Z=[];for(const D of F){const N=await this.getUser(D);Z.push(N)}return Z});Ie(this,"getAllUserTrackMids",async()=>{const F=await this.getUsers(),Z=[];for(const D of F){const{tracks:N=[]}=D;for(const O of N)Z.push(O.mid)}return Z});Ie(this,"getUserTrackByTrackName",async F=>{const Z=await this.getUsers(),D=[];for(const N of Z){const{tracks:O=[]}=N;for(const I of O){const{trackName:z}=I;F.includes(z)&&D.push(I)}}return D});Ie(this,"getUserTrackFromMid",async F=>{const Z=await this.getUsers();let D;for(const N of Z){const{tracks:O=[]}=N;for(const I of O)if(I.mid===F){D=I;break}}return D});Ie(this,"checkUserInRoom",F=>this.userMap.has(F));Ie(this,"getUsersId",async()=>[...this.userMap.keys()]);Ie(this,"getSelfInfo",async()=>await this.getUser(this.options.userId));Ie(this,"updateIsPublished",async(F,Z=!1)=>{const D=await this.getUser(F);D.isPublished=Z});Ie(this,"setUserUpdateStreams",async(F,Z,D=!0)=>{const N=await this.getUser(F),O={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};O[Z]=D,N.updateStreams=O});Ie(this,"updateUserChannels",async(F,Z=[],D)=>{const N=await this.getUser(F);D&&(Z=[...N.channels,...Z]),N.channels=Z});Ie(this,"updateUsertracks",async(F,Z=[],D)=>{const N=await this.getUser(F);D&&(Z=[...N.tracks,...Z]),Z=Z.filter(({mid:z=""})=>z!==""),Z=pt(Z,["type"]),Z=Z.sort((z,J)=>z.type-J.type<0?-1:1);for(const z of Z)z.userId=F,z.mediaType=mediaType_keys[z.type],z.enabled===void 0&&(z.enabled=!0);N.updateStreams={microphoneCamera_audio:!1,microphoneCamera_video:!1,screenSharing_video:!1,screenSharing_audio:!1};const O=dt(N.tracks,["mediaType","enabled","mid","msid","trackName"]),I=dt(Z,["mediaType","enabled","mid","msid","trackName"]);{const z="microphoneCamera_audio",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}{const z="microphoneCamera_video",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}{const z="screenSharing_audio",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}{const z="screenSharing_video",J=I.find(re=>re.mediaType===z),Q=O.find(re=>re.mediaType===z),ne=JSON.stringify(J)!==JSON.stringify(Q);N.updateStreams[z]=ne}N.tracks=Z});Ie(this,"updateUserCallAction",async(F,Z=0)=>{const D=await this.getUser(F);D.callAction=Z,D.callActionStr=Z.toString(2).padStart(4,"0"),D.callActionMap=this.getCallActionMap(Z)});Ie(this,"updateUserBehaviors",async(F,Z=0)=>{const D=await this.getUser(F);D.banBehavior=Z,D.banBehaviorStr=Z.toString(2).padStart(4,"0"),D.banBehaviorMap=this.getBanBehaviorMap(Z)});Ie(this,"updateUserNetwork",async(F,Z={egress:5,ingress:5})=>{const D=await this.getUser(F);D.network=Z});Ie(this,"updateUserPermissions",async(F,Z)=>{if(Z){const D=await this.getUser(F);D.permissions=Z}});Ie(this,"updateUserBase",async F=>{const Z=await this.getUser(F);Z.isSelf=F===this.options.userId,Z.updateAt=Date.now()});Ie(this,"updateUsers",async F=>{for(const Z of F){const{id:D,tracks:N,callAction:O,permissions:I,isPublished:z}=Z;await this.updateUserBase(D),await this.updateIsPublished(D,z),await this.updateUserPermissions(D,I),await this.updateUsertracks(D,N,!0),await this.updateUserCallAction(D,O),await this.updateUserNetwork(D)}});Ie(this,"emitNotifyUpdateUser",async F=>{const Z=await this.getUsers([F]),[D]=this.usersFilter(Z);this.cwsIns.emitNotify("onRoomUser",{code:200,data:D,desc:"user info is change."})});Ie(this,"emitNotifyUpdateUsers",async()=>{const F=await this.getUsers(),Z=this.usersFilter(F);this.cwsIns.emitNotify("onRoomUsers",{code:200,data:Z,desc:"all users info is change."})})}}const t=(q,K=4294967295,F=79764919)=>{const Z=new Int32Array(256);let D,N,O,I=K;for(D=0;D<256;D++){for(O=D<<24,N=8;N>0;--N)O=2147483648&O?O<<1^F:O<<1;Z[D]=O}for(D=0;D<q.length;D++)I=I<<8^Z[255&(I>>24^q[D])];return I},e=(q,K=t)=>{const F=ae=>new Uint8Array(ae.length/2).map((ce,de)=>parseInt(ae.substring(2*de,2*(de+1)),16)),Z=ae=>F(ae)[0],D=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach((ae,ce)=>D.set(ae,ce));const N=new Uint8Array(q.length);let O,I,z,J=!1,Q=0,ne=42,re=q.length>13&&q.substring(0,9)==="dynEncode",te=0;re&&(te=11,I=Z(q.substring(9,te)),I<=1&&(te+=2,ne=Z(q.substring(11,te))),I===1&&(te+=8,z=(ae=>new DataView(F(ae).buffer).getInt32(0,!0))(q.substring(13,te))));const oe=256-ne;for(let ae=te;ae<q.length;ae++)if(O=q.charCodeAt(ae),O!==61||J){if(O===92&&ae<q.length-5&&re){const ce=q.charCodeAt(ae+1);ce!==117&&ce!==85||(O=parseInt(q.substring(ae+2,ae+6),16),ae+=5)}if(O>255){const ce=D.get(O);ce&&(O=ce+127)}J&&(J=!1,O-=64),N[Q++]=O<ne&&O>0?O+oe:O-ne}else J=!0;const le=N.subarray(0,Q);if(re&&I===1){const ae=K(le);if(ae!==z){const ce="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",ce+`
14
14
  `,"Expected: "+z+"; Got: "+ae+`
15
15
  `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(ce)}}return le};function WASMAudioDecoderCommon(){const q=Uint8Array,K=Float32Array;WASMAudioDecoderCommon.modules||Object.defineProperties(WASMAudioDecoderCommon,{modules:{value:new WeakMap},setModule:{value(F,Z){WASMAudioDecoderCommon.modules.set(F,Promise.resolve(Z))}},getModule:{value(F,Z){let D=WASMAudioDecoderCommon.modules.get(F);return D||(Z?D=WebAssembly.compile(e(Z)):(Z=F.wasm,D=WASMAudioDecoderCommon.inflateDynEncodeString(Z).then(N=>WebAssembly.compile(N))),WASMAudioDecoderCommon.modules.set(F,D)),D}},concatFloat32:{value(F,Z){let D=new K(Z),N=0,O=0;for(;N<F.length;)D.set(F[N],O),O+=F[N++].length;return D}},getDecodedAudio:{value:(F,Z,D,N,O)=>({errors:F,channelData:Z,samplesDecoded:D,sampleRate:N,bitDepth:O})},getDecodedAudioMultiChannel:{value(F,Z,D,N,O,I){let z=[],J,Q;for(J=0;J<D;J++){const ne=[];for(Q=0;Q<Z.length;)ne.push(Z[Q++][J]||[]);z.push(WASMAudioDecoderCommon.concatFloat32(ne,N))}return WASMAudioDecoderCommon.getDecodedAudio(F,z,N,O,I)}},inflateDynEncodeString:{value(F){return F=e(F),new Promise(Z=>{const D=String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;WASMAudioDecoderCommon.getModule(WASMAudioDecoderCommon,D).then(N=>WebAssembly.instantiate(N,{})).then(({exports:N})=>{const O=new Map(Object.entries(N)),I=O.get("puff"),z=O.get("memory").buffer,J=new q(z),Q=new DataView(z);let ne=O.get("__heap_base");const re=F.length,te=ne;ne+=4,Q.setInt32(te,re,!0);const oe=ne;ne+=re,J.set(F,oe);const le=ne;ne+=4,Q.setInt32(le,J.byteLength-ne,!0),I(ne,le,oe,te),Z(J.slice(ne,ne+Q.getInt32(le,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(F,Z,D)=>{let N=[],O=0;for(;O<Z;)N.push(F.slice(O*D,O++*D+D));return N},this.allocateTypedArray=(F,Z,D=!0)=>{const N=this._wasm.malloc(Z.BYTES_PER_ELEMENT*F);return D&&this._pointers.add(N),{ptr:N,len:F,buf:new Z(this._wasm.HEAP,N,F)}},this.free=()=>{this._pointers.forEach(F=>{this._wasm.free(F)}),this._pointers.clear()},this.codeToString=F=>{const Z=[],D=new Uint8Array(this._wasm.HEAP);for(let N=D[F];N!==0;N=D[++F])Z.push(N);return String.fromCharCode.apply(null,Z)},this.addError=(F,Z,D,N,O,I)=>{F.push({message:Z,frameLength:D,frameNumber:N,inputBytes:O,outputSamples:I})},this.instantiate=(F,Z)=>(Z&&WASMAudioDecoderCommon.setModule(F,Z),this._wasm=new F(WASMAudioDecoderCommon).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var browser,hasRequiredBrowser;function requireBrowser(){return hasRequiredBrowser||(hasRequiredBrowser=1,browser=Worker),browser}var browserExports=requireBrowser();const NodeWorker=getDefaultExportFromCjs(browserExports),getWorker=()=>globalThis.Worker||NodeWorker;class WASMAudioDecoderWorker extends getWorker(){constructor(K,F,Z,D){WASMAudioDecoderCommon.modules||new WASMAudioDecoderCommon;let N=WASMAudioDecoderCommon.modules.get(Z);if(!N){let O="text/javascript",I,z=`'use strict';(${((J,Q,ne)=>{let re,te,oe=new Promise(le=>{te=le});self.onmessage=({data:{id:le,command:ae,data:ce}})=>{let de=oe,we={id:le},fe;ae==="init"?(Object.defineProperties(J,{WASMAudioDecoderCommon:{value:Q},EmscriptenWASM:{value:ne},module:{value:ce.module},isWebWorker:{value:!0}}),re=new J(ce.options),te()):ae==="free"?re.free():ae==="ready"?de=de.then(()=>re.ready):ae==="reset"?de=de.then(()=>re.reset()):(Object.assign(we,re[ae](Array.isArray(ce)?ce.map(ge=>new Uint8Array(ge)):new Uint8Array(ce))),fe=we.channelData?we.channelData.map(ge=>ge.buffer):[]),de.then(()=>self.postMessage(we,fe))}}).toString()})(${Z}, ${WASMAudioDecoderCommon}, ${D})`;try{I=typeof process.versions.node<"u"}catch{}N=I?`data:${O};base64,${Buffer.from(z).toString("base64")}`:URL.createObjectURL(new Blob([z],{type:O})),WASMAudioDecoderCommon.modules.set(Z,N)}super(N,{name:F}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:O})=>{const{id:I,...z}=O;this._enqueuedOperations.get(I)(z),this._enqueuedOperations.delete(I)},new D(WASMAudioDecoderCommon).getModule().then(O=>{this.postToDecoder("init",{module:O,options:K})})}async postToDecoder(K,F){return new Promise(Z=>{this.postMessage({command:K,id:this._id,data:F}),this._enqueuedOperations.set(this._id++,Z)})}get ready(){return this.postToDecoder("ready")}async free(){await this.postToDecoder("free").finally(()=>{this.terminate()})}async reset(){await this.postToDecoder("reset")}}const assignNames=(q,K)=>{Object.defineProperty(q,"name",{value:K})};function EmscriptenWASM(q){function K(){}function F(Te){throw Te}var Z,D;function N(){var Te=D.buffer;Z=new Uint8Array(Te),new BigInt64Array(Te),new BigUint64Array(Te)}for(var O=()=>F(""),I=()=>{},z={},J=Te=>Te(),Q=()=>performance.now(),ne=(Te,qe)=>{if(z[Te]&&(clearTimeout(z[Te].id),delete z[Te]),!qe)return 0;var Ve=setTimeout(()=>{delete z[Te],J(()=>ke(Te,Q()))},qe);return z[Te]={id:Ve,timeout_ms:qe},0},re=Math.cos,te=Te=>(Z.length,!1),oe=Te=>{throw`exit(${Te})`},le=new Uint8Array(123),ae=25;ae>=0;--ae)le[48+ae]=52+ae,le[65+ae]=ae,le[97+ae]=26+ae;le[43]=62,le[47]=63;var ce={d:O,c:I,e:ne,a:re,f:te,b:oe};function de(Te){we=Te.i,fe=Te.j,ge=Te.k,me=Te.l,ve=Te.m,ke=Te.o}var we,fe,ge,me,ve,ke;function xe(Te){Te.h()}EmscriptenWASM.wasm||Object.defineProperty(EmscriptenWASM,"wasm",{get:()=>String.raw`dynEncode0158c8b8d85e¼æ=M™]™lGu³õPoš]ÐãÞ·£3² ÁÚ= ’Êöc/ÓZ8s³‹íÛ³u­Ð¥t"+¦›¦~dòR\(nº}÷£¢¢ë¢k}Ÿt¡) ,‚­äÕüP
16
16
  *øüäÖeù‡i“ ÝWŠÍ¦ÖPMŸ¨[æu>Ü(«l‹'Ë$c‡˜¿9ZEúº¼ù‹¼=}ŠŒäÍÂý²­‚\åô҅'.õt­ÅXî=}~õ"uÊr˜ÁýóòÝ ÔúéÊ
@@ -203,4 +203,4 @@ DÙ VààÍ³ÄvÒ2; 5c±-ìʞ‹öª§}Ou¡ƒ¡‡¦ƒîGÇ D
203
203
  Ùup3‹q@ݱu„Xt•X07=M˜‡p_¤I¬ø®®[¦ó[ÀRŠ˜VsX?F^":hˆa?ØÎeÄQc{Yíz’0j¹{b ×c˜4ö–= %¡›ì?XÜñÊ,ŒxþÀŠf©û‡y O}:Fà= NuÙO_hÌÍtÝg|ȳ]²(aŸ= žTÜøN»j/Ì|éŽÚœ{^ëÐÖ{¡•Çzñú_|Åûl*†Ztì{8ޝa@©¥Z”K؍¨c¿iš<±†üFÇkº-cy 5±4§o9ы,;KzÌ $à1I=MºôÉ©¤=MêÈ5
204
204
  }õíë(—ŒðìÍäWD„?£©ÿ㪔=M äҕ±ì6í)ˆ‘ÏÙtbFÐöÚFÈ´Ù§R‚1.]¢¦¨ùû­,9ï‚tö»LÂô⍦qªk{ä(9«ž4>°»ŽB‰¶ñ»šGÓ½vÃâ£d$°AŠ‹†0ô‰¼¦­d=M¢«£ Àß}â$ æ0òÊ6¾%¼>3(…-D+ÂÔÂ…o7#æFåEIîkNDÒ_&Š3iÍHÌúk&@â‹k1ýîW¶ƒY¬ŽXޖXáXâ¢XEeØØÈ\‘gi,Ç~æ{™…Ü-ïœÈÛx6„Û{—í8+¾\g¦ñ۟írŠô9³®°3D_åãxQÈxþÚ·/ª= Íu_̛uL•^t^{g9áqž?ª•(üo!€*Írâ&ÚËì÷¨Pd׺ÓG)àþê¤sJ’…ñAÉå$†AÐNÎç˜õn„D1MøhO¥me Q†Ê¸[F< ^MBÜÛ
205
205
   Aãϧüï†4î%M°6M…ùtN)›FR˜[¾F™qV6¥óðlœò©Ë= c»R =}Ù8õ.­%BÂIµÃI&æ×U”1Q«Ïñ3&ÑóÓÝ»“ñ²eL°(ÑòOzBð·Q]üôföê+h.³´)ÅKé¥JR#/GóuÉɾ¯Áõ¿-½ñ'î<·Q ¼=MÛ²6+þ筓Ydb_öcHm™öôزj¾…nÚ7aÌvؓOå¹÷e0Ff˜ÊÈønØ#?ÁhÊÀcœ–Ýåõ(å û)ü)éðк¿ÓÜ¡]q†ákÈۚÝL·ºrCMmp_ÀÏ Óìcç6®þsosÒÝóô1¬Ã6<2#Ò±Cˆ“65Q"4ŠB&pç
206
- gUn…g= !þ+µèm M½Êê½½²¦é%0Yg~´p5.\Ø®z‚y9%Ôiܒ!Ùc‰ÝŦH>ÓX ÿZR’[¬&ønÇl’Ó_:ïi«ñ<ø"QÚ©yz …®ªOL¥ÎêŠÌÝi?Ê‚'/Ne»:2NÅÝ_òspüR Oø!!ù+##üÓkéªX-fpd“q[U*]@ ö¨5͔pÖYhܪ= › ÛN3{ü® À)¡9þ‘ž-1® ÂcBNö÷0+È6ò„Òэ;lÅ^_>ÓÛQ&jðMIŠì¤³àlS×j΀¢@ȝåÕ¢•­on‡=M°©xÉûÖäav=MM©²öÖ¹?{ß ßî€øyÛ= ‰„0òûÏ4gr’èNÒíÏqëðð-êö¸†ᖥ$¨”Q.Ò4ä¿V$N_Ý><´æë[⑲F#T1É'utÿZXÁ“š(ošàx¡Jo˜"­ö–ùSæ÷ÒUFÓs* U¡ ÓºUµøGáL¨÷©ASjÕ®'!L‹¢ÕvC¿m·Gžâ¼N¹Ÿ³OÃで1T:ê¹\Z£ËZæ.î}ª°O'ãà¾I;ûÁ€HÃä&ÃÐÐK@3EÅÓÉ>½e@ã/òi¡’|ÌE³{ñSCm…ÎëöÁÐÐ%Ó>dš''¶9Á/T.N?äª †æÿÀÐÐ%Ó¶ ö¾ì¦)ÃÕ÷×"e|ÚþBåýrv¶K6“ŸŒöuâÐÌRÎËýæ×%I­OIø¦Ä(HTJ†~),ÕDCWWÃö(›VwV=M§TsLP³ þV'tT#¡ZLŽêé;ßù[`});var _e={a:ce};this.setModule=Te=>{q.setModule(EmscriptenWASM,Te)},this.getModule=()=>q.getModule(EmscriptenWASM),this.instantiate=()=>(this.getModule().then(Te=>WebAssembly.instantiate(Te,_e)).then(Te=>{const qe=Te.exports;de(qe),D=qe.g,N(),xe(qe),K()}),this.ready=new Promise(Te=>{K=Te}).then(()=>{this.HEAP=D.buffer,this.malloc=fe,this.free=ve,this.opus_frame_decoder_create=we,this.opus_frame_decode_float_deinterleaved=ge,this.opus_frame_decoder_destroy=me}),this)}function OpusDecoder(q={}){OpusDecoder.errors||Object.defineProperties(OpusDecoder,{errors:{value:new Map([[-1,"OPUS_BAD_ARG: One or more invalid/out of range arguments"],[-2,"OPUS_BUFFER_TOO_SMALL: Not enough bytes allocated in the buffer"],[-3,"OPUS_INTERNAL_ERROR: An internal error was detected"],[-4,"OPUS_INVALID_PACKET: The compressed data passed is corrupted"],[-5,"OPUS_UNIMPLEMENTED: Invalid/unsupported request number"],[-6,"OPUS_INVALID_STATE: An encoder or decoder structure is invalid or already freed"],[-7,"OPUS_ALLOC_FAIL: Memory allocation has failed"]])}}),this._init=()=>new this._WASMAudioDecoderCommon(this).instantiate(this._EmscriptenWASM,this._module).then(Q=>{this._common=Q,this._inputBytes=0,this._outputSamples=0,this._frameNumber=0,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._output=this._common.allocateTypedArray(this._outputChannels*this._outputChannelSize,Float32Array);const ne=this._common.allocateTypedArray(this._channels,Uint8Array);ne.buf.set(this._channelMappingTable),this._decoder=this._common.wasm.opus_frame_decoder_create(this._sampleRate,this._channels,this._streamCount,this._coupledStreamCount,ne.ptr,this._preSkip,this._forceStereo)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.free(),this._common.wasm.opus_frame_decoder_destroy(this._decoder),this._common.wasm.free(this._decoder)},this._decode=Q=>{if(!(Q instanceof Uint8Array))throw Error("Data to decode must be Uint8Array. Instead got "+typeof Q);this._input.buf.set(Q);let ne=this._common.wasm.opus_frame_decode_float_deinterleaved(this._decoder,this._input.ptr,Q.length,this._output.ptr),re;return ne<0&&(re="libopus "+ne+" "+(OpusDecoder.errors.get(ne)||"Unknown Error"),console.error(re),ne=0),{outputBuffer:this._common.getOutputChannels(this._output.buf,this._outputChannels,ne),samplesDecoded:ne,error:re}},this.decodeFrame=Q=>{let ne=[];const re=this._decode(Q);return re.error&&this._common.addError(ne,re.error,Q.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=Q.length,this._outputSamples+=re.samplesDecoded,this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(ne,[re.outputBuffer],this._outputChannels,re.samplesDecoded,this._sampleRate)},this.decodeFrames=Q=>{let ne=[],re=[],te=0,oe=0;for(;oe<Q.length;){const le=Q[oe++],ae=this._decode(le);ne.push(ae.outputBuffer),te+=ae.samplesDecoded,ae.error&&this._common.addError(re,ae.error,le.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=le.length,this._outputSamples+=ae.samplesDecoded}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(re,ne,this._outputChannels,te,this._sampleRate)},this._isWebWorker=OpusDecoder.isWebWorker,this._WASMAudioDecoderCommon=OpusDecoder.WASMAudioDecoderCommon||WASMAudioDecoderCommon,this._EmscriptenWASM=OpusDecoder.EmscriptenWASM||EmscriptenWASM,this._module=OpusDecoder.module;const K=8,F=Q=>typeof Q=="number",Z=q.sampleRate,D=q.channels,N=q.streamCount,O=q.coupledStreamCount,I=q.channelMappingTable,z=q.preSkip,J=q.forceStereo?1:0;if(D>2&&(!F(N)||!F(O)||!Array.isArray(I)))throw new Error("Invalid Opus Decoder Options for multichannel decoding.");return this._sampleRate=[8e3,12e3,16e3,24e3,48e3].includes(Z)?Z:48e3,this._channels=F(D)?D:2,this._streamCount=F(N)?N:1,this._coupledStreamCount=F(O)?O:this._channels-1,this._channelMappingTable=I||(this._channels===2?[0,1]:[0]),this._preSkip=z||0,this._forceStereo=D<=K&&D!=2?J:0,this._inputSize=32e3*.12*this._channels,this._outputChannelSize=120*48,this._outputChannels=this._forceStereo?2:this._channels,this._ready=this._init(),this}class OpusDecoderWebWorker extends WASMAudioDecoderWorker{constructor(K){super(K,"opus-decoder",OpusDecoder,EmscriptenWASM)}async decodeFrame(K){return this.postToDecoder("decodeFrame",K)}async decodeFrames(K){return this.postToDecoder("decodeFrames",K)}}assignNames(OpusDecoder,"OpusDecoder"),assignNames(OpusDecoderWebWorker,"OpusDecoderWebWorker"),new OpusDecoder;class RoomPeer extends RoomUsers{constructor(F){super(F);Ie(this,"getPeerStatsTimer",0);Ie(this,"reports",[]);Ie(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});Ie(this,"initPeer",()=>{var Z;(Z=this.peerIns)==null||Z.close(),this.transceiverMap=new Map,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),Be(this,jn).call(this),Be(this,Jn).call(this);const F=[];this.peerIns.onicecandidate=async D=>{if(D.candidate){const N=await parseCandidate(D.candidate.candidate);F.push(N)}console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: parseCandidate",F)}});Ie(this,"getNatType",async()=>{});Ie(this,"initSendChannel",(F="",Z)=>{});Ie(this,"initReceiveChannel",(F="",Z)=>{});Ie(this,"replaceSenderStream",async(F=[],Z)=>{const{userId:D}=this.options;F.length===0&&(F=mediaType_keys);for(const N of F){const O=this.transceiverMap.get(N);let I;if(O){const{sender:z}=O;Z?I=this.getUserStream(D,N):I=this.getPhoneyStreams(N);const[J]=I.getTracks();J&&await z.replaceTrack(J)}}});Ie(this,"getSenderTracks",async(F=[])=>{const Z=[];for(const D of F){const N=this.transceiverMap.get(D);if(!N)continue;const{mid:O,sender:I}=N,{track:z}=I;if(!z)continue;const{id:J,enabled:Q}=z,ne=mediaType_keys.findIndex(te=>te===D),re={type:ne,enabled:Q,trackName:`web-${ne}-${J}`,location:"local",mid:O};Z.push(re)}return Z});Ie(this,"addSenders",async(F=[])=>{F.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const Z=[];for(const D of F){if(this.transceiverMap.get(D))continue;const O=this.getPhoneyStreams(D),[I]=O.getTracks(),z=this.peerIns.addTransceiver(I,{direction:"sendonly"});this.transceiverMap.set(D,z),Z.push(D)}if(F.length===0||Z.length!==0){const D=await this.peerIns.createOffer();if(this.options.debug){const N=libExports$1.parse(D.sdp),O=dt(N.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:O,sdpJson:N,description:D})}await this.peerIns.setLocalDescription(D)}return Z});Ie(this,"removeSenders",async(F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F)this.transceiverMap.has(Z)&&this.transceiverMap.delete(Z)});Ie(this,"onSubscribeUserTracks",F=>{let Z=0;return new Promise(async D=>{const N=[];for(const O of F){const{tracks:I=[]}=O;for(const z of I){const{trackName:J,mid:Q}=z,[ne]=await this.getUserTrackByTrackName([J]);N.push({...ne,mid:Q})}}{let O=[];const I=async()=>{clearTimeout(Z);const J=new Map;for(const ne of O){const{userId:re,mediaType:te}=ne;if(!re||!te)continue;J.has(re)||J.set(re,{userId:re,tracks:[],updateStreams:{}});const le=J.get(re);le.tracks.push(ne),le.updateStreams[te]=!0}const Q=[...J.values()];for(const ne of Q){const{userId:re,tracks:te}=ne;await this.updateUsertracks(re,te,!0)}await this.emitNotifyUpdateUsersStreams(Q),this.peerIns.removeEventListener("track",z);{const ne=Array.from(N,oe=>oe.trackName),re=Array.from(O,oe=>oe.trackName),te=ne.filter(oe=>!re.includes(oe));D({target:ne,success:re,fail:te})}},z=async J=>{const{streams:Q,transceiver:ne}=J,[re]=Q,{mid:te,receiver:oe}=ne,{track:le}=oe,{id:ae}=le,ce=N.find(fe=>fe.mid===`${te}`);if(!ce)return;const{userId:de,mediaType:we}=ce;if(!(!de||!we)){{const fe={...ce,mid:te,msid:ae};O.push(fe)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${O.length}/${N.length}`,{mediaType:we,mid:te,userTrack:ce,e:J});{const fe=new Audio;if(fe.srcObject=re,await this.initUserMediaStreamContext(de,we,re),we==="microphoneCamera_audio"||we==="screenSharing_audio"){const ge=this.getUserAudioMediaStreamContext(de,we);ge==null||ge.setMute(!1)}}N.length===O.length&&I()}};this.peerIns.addEventListener("track",z),Z=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${O.length}/${N.length})`),I()},5*1e3)}})});st(this,jn,()=>{let F=0;const Z=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.onconnectionstatechange=async D=>{const N=D.target.connectionState;switch(await this.taskQueue.setCondition("ice",!1),clearTimeout(F),N){case"connected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${N}`),await this.taskQueue.setCondition("ice",!0),await this.getNatType(),this.setRoomState("connected");break;case"disconnected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${N}`),F=window.setTimeout(Z,30*1e3);break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${N}`),this.setRoomState("failed");break;case"closed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${N}`),Z();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${N}`);break}}});Ie(this,"closeUserTracks",async(F,Z=[],D=!1)=>{const N=[];for(const J of Z){const{trackName:Q,msid:ne}=J;N.push(Q),ne&&N.push(ne)}const O=J=>N.includes(J),I=this.peerIns.getTransceivers();for(const J of I){const{mid:Q,sender:ne,receiver:re}=J;ne.track&&O(ne.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${Q} is stop.`,J)),re.track&&O(re.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${Q} is stop.`,J))}const z=await this.getUser(F);if(z){for(const J of z.tracks){const{trackName:Q,msid:ne,userId:re,mediaType:te}=J;!re||!te||!O(Q)||(this.removeUserMediaStreamContext(re,te),ne&&delete J.msid)}if(D){const J=z.tracks.filter(({trackName:Q})=>!O(Q));await this.updateUsertracks(F,J,!1)}}});Ie(this,"createOffer",async()=>{const F=await this.peerIns.createOffer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"createAnswer",async()=>{const F=await this.peerIns.createAnswer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"getSdp",()=>{var F;return(F=this.peerIns.localDescription)==null?void 0:F.sdp});Ie(this,"setRemoteDescription",async F=>{if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:D,sdpJson:Z,description:F})}return await this.peerIns.setRemoteDescription(F),F});Ie(this,"setCallStrategy",async(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);let D="balanced";switch(F){case"qualityPriority":D="maintain-resolution";break;case"fluencyPriority":D="maintain-framerate";break;case"balancedDowngrade":D="balanced";break}const N=await this.getSelfInfo(),O=Array.from(N.tracks,({trackName:z})=>z),I=this.peerIns.getSenders();for(const z of I){const{track:J}=z;if(!J||!O.includes(J.id))continue;const Q=z.getParameters();z.setParameters({...Q,degradationPreference:D})}});Ie(this,"setRTCRtpSenderParameters",F=>{try{const Z=this.peerIns.getSenders();for(const D of Z){const N=D.getParameters();D.setParameters({...N,...F})}}catch(Z){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",Z)}});Ie(this,"getReportsByMid",async(F=[])=>F.length===0?this.reports:this.reports.filter(Z=>F.includes(Z.mid)));Ie(this,"getRoomNetwork",()=>this.peerNetwork);Ie(this,"getPeerNetwork",()=>this.peerNetwork);st(this,zn,async()=>{try{const F=await this.peerIns.getStats(),Z=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],N=[...F.values()].filter(ge=>Z.includes(ge.type));let O=0,I=0,z=0,J=0,Q=0,ne=0,re=[],te=[];for(const ge of this.reports){const{packetsSent:me,packetsLost:ve}=ge;me&&(z+=me),ve&&(J+=ve)}this.reports=N;for(const ge of this.reports){const{bytesSent:me,bytesReceived:ve,packetsSent:ke,packetsLost:xe,roundTripTime:_e,jitter:Te}=ge;me&&(I=me),ve&&(O=ve),ke&&(Q+=ke),xe&&(ne+=xe),_e&&re.push((_e*100).toFixed(2)),Te&&te.push(Te.toFixed(2))}te.sort().reverse(),re.sort().reverse();const oe=Q-z,le=ne-J,ae=oe===0?"0.00":(le/oe).toFixed(2),[ce="0"]=re,[de="0"]=te,we={outboundBytes:I,inboundBytes:O,lostRate:ae,roundTripTime:ce,jitter:de};this.peerNetwork=we;const fe=(ge,me,ve)=>{const ke=Number(ge),xe=Number(me),_e=Number(ve);let Te="0";return ke<.03&&xe<100&&_e<.05?Te="5":ke<.06&&xe<160&&_e<.1?Te="4":ke<.1&&xe<250&&_e<.15?Te="3":ke<.15&&xe<400&&_e<.2?Te="2":Te="1",Number(Te)};{const ge=fe(ae,ce,de),me=await this.getSelfInfo(),{network:ve}=me,ke={egress:ge,ingress:ge};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,ke),JSON.stringify(ve)!==JSON.stringify(ke)){this.emitNotifyUpdateUsers();const{userId:Te,roomId:qe}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...ke,userId:Te,roomId:qe}},!1)}},3*1e3)}}catch(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",F)}});st(this,Jn,()=>{const F=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||Be(this,zn).call(this)};this.getPeerStatsTimer=window.setInterval(F,1*1e3)});Ie(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer))}}jn=new WeakMap,zn=new WeakMap,Jn=new WeakMap;class RoomCalls extends RoomPeer{constructor(F){super(F);st(this,On,0);Ie(this,"setLocalStream",(F,Z)=>new Promise(async(D,N)=>{try{typeof F=="string"&&(F=[F]);for(const I of F)this.localStreamsActionMap.set(I,Z);if(Z){if(F.includes("microphoneCamera_audio")&&F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):F.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):F.includes("screenSharing_audio")&&F.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):F.includes("screenSharing_audio")&&!F.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):F.includes("screenSharing_video")&&!F.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),F.includes("screenSharing_audio")){const I=await this.getLocalStream("screenSharing_audio");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if(F.includes("screenSharing_video")){const I=await this.getLocalStream("screenSharing_video");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams(F);const O=await this.getLocalStreams(F);this.cwsIns.emitNotify("onLocalStream",{code:200,data:O,desc:"local stream is change."}),D(O)}catch(O){N(O)}}));Ie(this,"setMediaDeviceKind",(F,Z)=>new Promise(async(D,N)=>{this.setDeviceKind(F,Z);const O=await this.getSelfInfo(),{id:I,tracks:z=[],callActionMap:J}=O,Q=[],ne=async re=>{const te=this.localStreamsActionMap.get(re),oe=z.find(ae=>ae.mediaType===re),le=J[re];if(te){Q.push(re),await this.stopLocalStreams([re]);try{await this.initLocalStream(re)}catch(ae){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initLocalStream is error.",ae),await this.inactiveTracks([re],!1),N(ae)}}if(oe){const ae=await this.getLocalStream(re);ae&&(await this.initUserMediaStreamContext(I,re,ae),le&&await this.replaceSenderStream([re],!0))}{const ae=await this.getLocalStreams(Q);this.cwsIns.emitNotify("onLocalStream",{code:200,data:ae,desc:"local stream is change."}),await this.emitNotifyUpdateUsers(),D(!0)}};F==="audioinput"&&ne("microphoneCamera_audio"),F==="videoinput"&&ne("microphoneCamera_video"),F==="audiooutput"&&(await this.changeAudiooutput(),D(!0))}));Ie(this,"changeScreenSharing",async F=>{const Z=await this.getSelfInfo(),{tracks:D=[],callActionMap:N}=Z;try{await this.setLocalStream(F,!0);for(const O of F)D.find(z=>z.mediaType===O&&N[O])&&await this.replaceSenderStream([O],!0)}catch(O){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",O)}});Ie(this,"createSession",()=>new Promise(async(F,Z)=>{if(["connecting","connected"].includes(this.roomState))return F(!0);this.setRoomState("connecting"),await this.taskQueue.createTask({describe:"createSession",conditionKeys:["createWs","createSession"],changeConditionKeys:["createSession"],func:()=>new Promise(async(D,N)=>{try{await this.addSenders(),this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async O=>{const{code:I=0,desc:z,data:J}=O;if(I!==200)return N(z);const{remoteSdp:Q}=J;await this.taskQueue.setCondition("ice",!1),await this.taskQueue.createTask({describe:"ice",timeout:30*1e3,conditionKeys:["ice"],func:()=>new Promise(ne=>setTimeout(()=>ne(!0),300)),success:async()=>{D(!0)},fail:async ne=>{throw new Error(`ice connection failed: ${ne}`)}}),await this.setRemoteDescription({type:"answer",sdp:Q})})}catch(O){N(O)}}),success:async D=>{F(D)},fail:async D=>{this.reportLogs("ws_c_timeout",D.message||D),Z(D)},complete:()=>{this.taskQueue.setCondition("createSession",!0)}})}));Ie(this,"earlyConnect",(F=[])=>{this.isEarly=!0,Be(this,An).call(this),this.createSession(),F.length===0&&(F=["microphoneCamera_audio","microphoneCamera_video"]),Be(this,$n).call(this,F)});Ie(this,"joinRoom",async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"joinRoom",conditionKeys:["createWs"],changeConditionKeys:["joinRoom"],func:()=>new Promise(async(N,O)=>{try{this.setOptions(F),await Be(this,An).call(this),this.clearUsers();const{roomId:I,userId:z,callType:J,sdkToken:Q}=this.options;this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:J,roomId:I,user:{id:z,tracks:[],callAction:0},token:Q},version:2}).then(async ne=>{const{code:re=0,desc:te="服务器繁忙",data:oe}=ne;if(re!==200)return O(te);const{roomId:le="",roomUsers:ae=[]}=oe;if(le!==I)return O("加入的房间不匹配");this.isInRoom=!0,this.taskQueue.setCondition("createTrack",!0),this.taskQueue.setCondition("publish",!0),this.taskQueue.setCondition("subscribe",!0),this.taskQueue.setCondition("renegotiate",!0),this.taskQueue.setCondition("closeTrack",!0),this.initHeartbeat(),this.createSession(),await this.updateUsers(ae);const ce=[];for(const we of ae){const{id:fe,channelCache:ge}=we,{channels:me=[]}=ge;await this.updateUserBehaviors(fe,we.behavior),await this.updateUserChannels(fe,me,!1),me.length!==0&&ce.push({userId:fe,channels:me})}this.subChannel(ce),await this.emitNotifyUpdateUsers();const de=await this.getUsers();N(de)})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("join_room_error",N.message||N),D(N)},complete:()=>{this.taskQueue.setCondition("joinRoom",!0)}})}));Ie(this,"quitRoom",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,clearInterval(Be(this,On)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),await this.taskQueue.setCondition("closeTrack",!0),this.cwsIns.sendMessage({event:"quitRoom",data:N}),F(!0)}));Ie(this,"quitRoomEx",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:N}),F(!0)}));Ie(this,"syncRoomInfo",()=>new Promise(async(F,Z)=>{const{userId:D}=this.options,N=await this.getUser(D),{id:O=D,callAction:I=0}=N;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:O,callAction:I}}}).then(async z=>{if(z.code!==200)return Z(z.desc);const J=z.data.users;this.clearUsers(),await this.updateUsers(J),await this.updateUsertracks(N.id,N.tracks,!1);{const Q=await this.getUsers();F(Q)}}).catch(z=>Z(z))}));Ie(this,"publish",F=>new Promise(async(Z,D)=>{{const N=await this.getSelfInfo(),{banBehaviorMap:O}=N;let I=!0;for(const z of F)if(O[z]){I=!1;break}if(I===!1)return D("publish is error: prohibited by administrator.")}try{await this.setLocalStream(F,!0)}catch(N){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",N)}await this.taskQueue.createTask({describe:"publish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["publish"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo(),z=[];for(const te of F){{const oe=this.getPhoneyStreams(te);await this.initUserMediaStreamContext(I.id,te,oe)}{const oe=await this.getLocalStream(te);oe?await this.initUserMediaStreamContext(I.id,te,oe):z.push(te)}}const J=F.filter(te=>!z.includes(te)||["microphoneCamera_audio","microphoneCamera_video"].includes(te));await this.replaceSenderStream(F,!1),await Be(this,$n).call(this,J);const Q=await this.getSenderTracks(J),ne=[...I.tracks,...Q];await this.updateUsertracks(I.id,ne,!0),z.length!==0&&await this.inactiveTracks(z,!1),J.length!==0&&await this.replaceSenderStream(J,!0);const re=await this.getCallAction(ne);await Be(this,En).call(this,re),await new Promise(te=>setTimeout(()=>te(!0),230)),Be(this,Wn).call(this,F);{await this.emitNotifyUpdateUsers();const te=await this.getSelfInfo();N(te)}}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("publish",!0)}})}));Ie(this,"stopPublish",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"stopPublish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo();F.length===0&&(F=mediaType_keys);const z=I.tracks.filter(({mediaType:Q})=>Q&&F.includes(Q)),J=async()=>{this.initMediaPhoneyStreams(F);const Q=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),N(Q)};if(z.length===0)return J();await this.replaceSenderStream(F,!0),await this.closeUserTracks(I.id,z,!0),await this.removeSenders(F);{const Q=await this.getCallAction(I.tracks);await Be(this,En).call(this,Q)}await this.createOffer(),this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{code:ne=0,data:re,desc:te}=Q;if(ne!==200)return O(te);const{remoteSdp:oe}=re;await this.setRemoteDescription({type:"answer",sdp:oe}),J()})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"subscribe",(F=[],Z=3)=>new Promise(async(D,N)=>{const O=await this.taskQueue.createTask({describe:"subscribe",strict:!0,conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["subscribe"],func:()=>new Promise(async(I,z)=>{try{const J=await this.getUsers();let Q=[];for(const te of J){const{isSelf:oe,tracks:le=[]}=te;if(!oe){const ae=le.filter(({trackName:ce,mid:de=""})=>de!==""&&(F.includes(ce)||F.length===0));ae.length!==0&&Q.push({...te,tracks:ae})}}const ne=async(te={})=>{const oe=Array.from(Q,({id:ae})=>ae),le=await this.getUsers(oe);await this.emitNotifyUpdateUsers(),I({users:le,detail:te})};if(Q.length===0)return ne();const re=[];for(const te of Q){const{id:oe,tracks:le}=te,ae=dt(le,["type","trackName"]),ce={id:oe,tracks:ae};re.push(ce)}this.cwsIns.sendMessage({event:"subscribe",data:{users:re}}).then(async te=>{const{code:oe=0,data:le,desc:ae}=te;if(oe!==200)return z(ae);const{remoteSdp:ce,users:de=[]}=le;this.onSubscribeUserTracks(de).then(async we=>{await this.renegotiate().then(()=>ne(we)).catch(fe=>z(fe))}).catch(we=>{z(we)}),await this.setRemoteDescription({type:"offer",sdp:ce})})}catch(J){z(J)}}),success:async I=>{O.clear(),this.taskQueue.setCondition("subscribe",!0),D(I)},fail:async I=>{if(this.options.debug&&console.info("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: subscribe error. surplus count is ${Z}`),Z>0)return await new Promise(z=>setTimeout(()=>z(!0),(3-Z)*1e3)),Z=Z-1,O.retry();O.clear(),this.reportLogs("subscribe_error",I.message||I),this.taskQueue.setCondition("subscribe",!0),N(I)},complete:async()=>{}})}));Ie(this,"renegotiate",()=>new Promise(async(F,Z)=>{try{await this.taskQueue.setCondition("renegotiate",!1),await this.createAnswer(),this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(D=>{const{code:N=0,desc:O}=D;if(N!==200)return Z(O);F(D)}).finally(()=>{this.taskQueue.setCondition("renegotiate",!0)})}catch(D){Z(D)}}));Ie(this,"stopSubscribe",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"closeTrack",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getUsers(),z=[];for(const Q of I){const{tracks:ne=[]}=Q;for(const re of ne){const{type:te,mid:oe,trackName:le,mediaType:ae,msid:ce}=re;if(!(!ae||!ce)&&(F.length===0||F.includes(le))){const de={type:te,mid:oe,trackName:ce};z.push(de),await this.closeUserTracks(Q.id,[re])}}}const J=async()=>{await this.emitNotifyUpdateUsers(),N(!0)};if(z.length===0)return J();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{remoteSdp:ne}=Q.data;await this.setRemoteDescription({type:"answer",sdp:ne})}),J()}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: stopPublish is error.",N),this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"inactiveTracks",async(F,Z)=>new Promise(async D=>{const N=await this.getSelfInfo();if(!N||!N.id)return D(!0);const{tracks:O=[]}=N,I=[...O];for(let J of I){const{mediaType:Q}=J;if(Q&&F.includes(Q)){J.enabled=Z;const ne=await this.getLocalStream(Q);if(!ne)continue;const re=ne.getTracks();for(const te of re)te.enabled=Z}}await this.replaceSenderStream(F,Z);const z=await this.getCallAction(I);await Be(this,En).call(this,z),await this.emitNotifyUpdateUsers(),D(!0)}));Ie(this,"setBanBehaviors",F=>new Promise(async(Z,D)=>{try{const{roomId:N}=this.options,O=[];for(const I of F){const{id:z,banBehaviors:J}=I,Q=Object.keys(J);if(Q.length===0)continue;const ne=[];for(const te of Q){const oe=mediaType_keys.findIndex(ce=>ce===te),le=J[te],ae={type:oe,behavior:le};ne.push(ae)}const re={id:z,behaviors:ne};O.push(re)}this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:N,users:O}}).then(async I=>{const{code:z=0,desc:J}=I;if(z!==200)return D(J);Z(I)}).finally(()=>{})}catch(N){D(N)}}));Ie(this,"pubChannel",()=>new Promise(async(F,Z)=>{const N=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:N}}).then(async O=>{const{code:I=0,data:z,desc:J}=O;if(I!==200)return Z(J);const{channels:Q=[]}=z;for(const ne of Q){const{channels:re=[]}=ne;for(const te of re){const{dataChannelName:oe,id:le}=te;this.initSendChannel(oe,le)}}F(!0)}).catch(O=>{Z(O)})}));Ie(this,"subChannel",(F=[])=>new Promise(async(Z,D)=>{if(F.length===0)return Z(!0);await this.taskQueue.createTask({describe:"subChannel",strict:!0,conditionKeys:["createWs","createSession","ice"],changeConditionKeys:[],func:()=>this.cwsIns.sendMessage({event:"subChannel",data:{channels:F}}).then(async N=>{const{code:O=0,data:I,desc:z}=N;if(O!==200)return D(z);const{channels:J=[]}=I;for(const Q of J){const{channels:ne=[]}=Q;for(const re of ne){const{dataChannelName:te,id:oe}=re;this.initReceiveChannel(te,oe)}}}),success:async N=>{Z(N)},fail:async N=>{D(N)}})}));Ie(this,"debugger",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"shutdown",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"initHeartbeat",()=>{this.stopHeartbeat();const F=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),Z=this.isInRoom?5*1e3:30*1e3;At(this,On,window.setInterval(F,Z)),F()});Ie(this,"stopHeartbeat",()=>{clearInterval(Be(this,On))});st(this,Wn,async F=>{const{roomId:Z}=this.options;if(!Z)return;const{id:D,tracks:N=[]}=await this.getSelfInfo(),O=N.filter(I=>I.mediaType&&F.includes(I.mediaType));O.length!==0&&this.cwsIns.sendMessage({event:"pubNotify",data:{roomId:Z,user:{id:D,tracks:O}}})});st(this,En,async F=>new Promise(async(Z,D)=>{const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O,callAction:F}};await this.cwsIns.sendMessage({event:"updateCall",data:I}).then(async z=>{const{code:J=0}=z;if(J!==200)return D(z);await this.updateUserCallAction(O,F),Z(F)}).catch(z=>D(z))}));st(this,An,()=>new Promise(async(F,Z)=>{try{if(["connecting","connected"].includes(this.cwsIns.state))return F(!0);await this.taskQueue.setCondition("createWs",!1),this.cwsIns.clearEvents(),this.initPeer();const{appid:D,roomId:N,userId:O}=this.options;if(!D)return Z("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const I={c:D,r:N,v:this.sdk_service_version};if(this.isEarly){const J=xt();I.i=J,this.setOptions({earlyId:J})}else I.b=O;this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs",I);const z=btoa(encodeURI(JSON.stringify(I)));await this.cwsIns.connect(z),this.initHeartbeat(),await this.taskQueue.setCondition("createWs",!0),await this.taskQueue.setCondition("createSession",!0),F(!0)}catch(D){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",D),this.reportLogs("ws_c_timeout",D.message||D),Z(D)}}));st(this,$n,async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"createTrack",conditionKeys:["createWs","createSession","ice","createTrack","subscribe","renegotiate","closeTrack"],func:()=>new Promise(async(N,O)=>{try{await this.taskQueue.setCondition("createTrack",!1);const I=await this.addSenders(F),z=await this.getSenderTracks(I);if(z.length===0)return await this.taskQueue.setCondition("createTrack",!0),N(!0);this.cwsIns.sendMessage({event:"publish",data:{sdp:this.getSdp(),tracks:z,callAction:0}}).then(async J=>{const{code:Q=0,desc:ne,data:re}=J;if(Q!==200)return O(ne);const{remoteSdp:te}=re;await this.setRemoteDescription({type:"answer",sdp:te}),N(!0)})}catch(I){await this.removeSenders(F),O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("createTrack",!0)}})}))}}On=new WeakMap,Wn=new WeakMap,En=new WeakMap,An=new WeakMap,$n=new WeakMap;class Room extends RoomCalls{constructor(K){super(K)}}class QuickVO extends Room{constructor(F){super(F);st(this,_n,new Map);Ie(this,"reconstruct",async()=>{if(this.cwsIns.state!=="connected"||this.roomState!=="failed")return;this.setRoomState("ready"),this.initMediaPhoneyStreams(),this.taskQueue.clear(),this.peerIns.close(),await this.syncRoomInfo(),this.initPeer(),this.taskQueue.setCondition("createSession",!0),this.taskQueue.setCondition("ice",!0),await this.createSession();const F=[],Z=[],D=await this.getUsers();for(const N of D){const{isSelf:O,callActionMap:I,tracks:z=[]}=N;if(O)for(const J of mediaType_keys)I[J]&&F.push(J);for(const J of z)J.msid&&Z.push(J.trackName)}await this.subscribe(Z),await this.publish(F)});st(this,Vn,()=>{{const F=async Z=>{const{state:D}=Z.data;if(D==="closed"){const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:I}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}this.reconstruct()};this.cwsIns.addNotify({event:"onRoomState",callback:F},!0)}{const F=async Z=>{const{qualities:D=[]}=Z.data,[N]=D;if(!(N&&N.userId===this.options.userId&&D.length===1)){for(const O of D){const{userId:I,egress:z,ingress:J}=O;this.checkUserInRoom(I)&&await this.updateUserNetwork(I,{egress:z,ingress:J})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:F},!0)}{const F=async Z=>{const D=Z.data.user;await this.updateUsers([D]),await this.updateUsertracks(D.id,D.track,!1),await this.updateUserBehaviors(D.id,D.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:F},!0)}{const F=async Z=>{await this.removeUsers([Z.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,tracks:O=[],callAction:I=0}=D;if(await this.updateUserCallAction(N,I),await this.updateUserPermissions(N,3),await this.updateUsertracks(N,O,!0),this.options.newPublishAutoSubscribe){const z=this.getTrackNamesFormTracks(O);await this.subscribe(z)}else await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onPublish",callback:F},!0)}{const F=async Z=>{const D=[Z.data];this.subChannel(D)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:F},!0)}{const F=async Z=>{const{id:D,tracks:N}=Z.data.user;D!==this.options.userId&&(await this.closeUserTracks(D,N,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:F},!0)}{const F=async Z=>{const{id:D,callAction:N}=Z.data.user;this.checkUserInRoom(D)&&(await this.updateUserCallAction(D,N),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,permissions:O=1}=D;O===1?await this.removeUsers([N]):O===3&&await this.updateUsers([D]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:F},!0)}{const F=async Z=>{const{users:D}=Z.data;for(const N of D){const{id:O,behavior:I}=N;await this.updateUserBehaviors(O,I)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:F},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async F=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});Ie(this,"addNotify",F=>this.cwsIns.addNotify(F));st(this,Zn,()=>{});st(this,Kn,()=>{this.cwsIns.onReconnectSuccess=async()=>{this.reconstruct()}});st(this,Gn,async()=>{this.setRoomState("closed")});Ie(this,"addRequestAnimationFrame",async(F,Z)=>{{const N=Be(this,_n).get(F);N&&cancelAnimationFrame(N)}const D=(N=Date.now())=>{Z(N);const O=requestAnimationFrame(D);Be(this,_n).set(F,O)};D()});Ie(this,"clearRequestAnimationFrame",async(F=[])=>{F.length===0&&(F=[...Be(this,_n).keys()]);const Z=[];for(const D of F){const N=Be(this,_n).get(D);N&&(cancelAnimationFrame(N),Z.push(N))}return Z});Ie(this,"destroy",async()=>{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 销毁SDK"),this.cwsIns.emitNotify("onDestroy",{code:200,data:{},desc:"sdk is destroy."}),this.stopLocalStreams(),await new Promise(F=>setTimeout(()=>F(!0),300)),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.cwsIns.close()});Be(this,Zn).call(this),Be(this,Kn).call(this),Be(this,Gn).call(this),Be(this,Vn).call(this)}}_n=new WeakMap,Vn=new WeakMap,Zn=new WeakMap,Kn=new WeakMap,Gn=new WeakMap,exports.QuickVO=QuickVO,exports.ignoreEvent=ignoreEvent,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
206
+ gUn…g= !þ+µèm M½Êê½½²¦é%0Yg~´p5.\Ø®z‚y9%Ôiܒ!Ùc‰ÝŦH>ÓX ÿZR’[¬&ønÇl’Ó_:ïi«ñ<ø"QÚ©yz …®ªOL¥ÎêŠÌÝi?Ê‚'/Ne»:2NÅÝ_òspüR Oø!!ù+##üÓkéªX-fpd“q[U*]@ ö¨5͔pÖYhܪ= › ÛN3{ü® À)¡9þ‘ž-1® ÂcBNö÷0+È6ò„Òэ;lÅ^_>ÓÛQ&jðMIŠì¤³àlS×j΀¢@ȝåÕ¢•­on‡=M°©xÉûÖäav=MM©²öÖ¹?{ß ßî€øyÛ= ‰„0òûÏ4gr’èNÒíÏqëðð-êö¸†ᖥ$¨”Q.Ò4ä¿V$N_Ý><´æë[⑲F#T1É'utÿZXÁ“š(ošàx¡Jo˜"­ö–ùSæ÷ÒUFÓs* U¡ ÓºUµøGáL¨÷©ASjÕ®'!L‹¢ÕvC¿m·Gžâ¼N¹Ÿ³OÃで1T:ê¹\Z£ËZæ.î}ª°O'ãà¾I;ûÁ€HÃä&ÃÐÐK@3EÅÓÉ>½e@ã/òi¡’|ÌE³{ñSCm…ÎëöÁÐÐ%Ó>dš''¶9Á/T.N?äª †æÿÀÐÐ%Ó¶ ö¾ì¦)ÃÕ÷×"e|ÚþBåýrv¶K6“ŸŒöuâÐÌRÎËýæ×%I­OIø¦Ä(HTJ†~),ÕDCWWÃö(›VwV=M§TsLP³ þV'tT#¡ZLŽêé;ßù[`});var _e={a:ce};this.setModule=Te=>{q.setModule(EmscriptenWASM,Te)},this.getModule=()=>q.getModule(EmscriptenWASM),this.instantiate=()=>(this.getModule().then(Te=>WebAssembly.instantiate(Te,_e)).then(Te=>{const qe=Te.exports;de(qe),D=qe.g,N(),xe(qe),K()}),this.ready=new Promise(Te=>{K=Te}).then(()=>{this.HEAP=D.buffer,this.malloc=fe,this.free=ve,this.opus_frame_decoder_create=we,this.opus_frame_decode_float_deinterleaved=ge,this.opus_frame_decoder_destroy=me}),this)}function OpusDecoder(q={}){OpusDecoder.errors||Object.defineProperties(OpusDecoder,{errors:{value:new Map([[-1,"OPUS_BAD_ARG: One or more invalid/out of range arguments"],[-2,"OPUS_BUFFER_TOO_SMALL: Not enough bytes allocated in the buffer"],[-3,"OPUS_INTERNAL_ERROR: An internal error was detected"],[-4,"OPUS_INVALID_PACKET: The compressed data passed is corrupted"],[-5,"OPUS_UNIMPLEMENTED: Invalid/unsupported request number"],[-6,"OPUS_INVALID_STATE: An encoder or decoder structure is invalid or already freed"],[-7,"OPUS_ALLOC_FAIL: Memory allocation has failed"]])}}),this._init=()=>new this._WASMAudioDecoderCommon(this).instantiate(this._EmscriptenWASM,this._module).then(Q=>{this._common=Q,this._inputBytes=0,this._outputSamples=0,this._frameNumber=0,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._output=this._common.allocateTypedArray(this._outputChannels*this._outputChannelSize,Float32Array);const ne=this._common.allocateTypedArray(this._channels,Uint8Array);ne.buf.set(this._channelMappingTable),this._decoder=this._common.wasm.opus_frame_decoder_create(this._sampleRate,this._channels,this._streamCount,this._coupledStreamCount,ne.ptr,this._preSkip,this._forceStereo)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.free(),this._common.wasm.opus_frame_decoder_destroy(this._decoder),this._common.wasm.free(this._decoder)},this._decode=Q=>{if(!(Q instanceof Uint8Array))throw Error("Data to decode must be Uint8Array. Instead got "+typeof Q);this._input.buf.set(Q);let ne=this._common.wasm.opus_frame_decode_float_deinterleaved(this._decoder,this._input.ptr,Q.length,this._output.ptr),re;return ne<0&&(re="libopus "+ne+" "+(OpusDecoder.errors.get(ne)||"Unknown Error"),console.error(re),ne=0),{outputBuffer:this._common.getOutputChannels(this._output.buf,this._outputChannels,ne),samplesDecoded:ne,error:re}},this.decodeFrame=Q=>{let ne=[];const re=this._decode(Q);return re.error&&this._common.addError(ne,re.error,Q.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=Q.length,this._outputSamples+=re.samplesDecoded,this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(ne,[re.outputBuffer],this._outputChannels,re.samplesDecoded,this._sampleRate)},this.decodeFrames=Q=>{let ne=[],re=[],te=0,oe=0;for(;oe<Q.length;){const le=Q[oe++],ae=this._decode(le);ne.push(ae.outputBuffer),te+=ae.samplesDecoded,ae.error&&this._common.addError(re,ae.error,le.length,this._frameNumber,this._inputBytes,this._outputSamples),this._frameNumber++,this._inputBytes+=le.length,this._outputSamples+=ae.samplesDecoded}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(re,ne,this._outputChannels,te,this._sampleRate)},this._isWebWorker=OpusDecoder.isWebWorker,this._WASMAudioDecoderCommon=OpusDecoder.WASMAudioDecoderCommon||WASMAudioDecoderCommon,this._EmscriptenWASM=OpusDecoder.EmscriptenWASM||EmscriptenWASM,this._module=OpusDecoder.module;const K=8,F=Q=>typeof Q=="number",Z=q.sampleRate,D=q.channels,N=q.streamCount,O=q.coupledStreamCount,I=q.channelMappingTable,z=q.preSkip,J=q.forceStereo?1:0;if(D>2&&(!F(N)||!F(O)||!Array.isArray(I)))throw new Error("Invalid Opus Decoder Options for multichannel decoding.");return this._sampleRate=[8e3,12e3,16e3,24e3,48e3].includes(Z)?Z:48e3,this._channels=F(D)?D:2,this._streamCount=F(N)?N:1,this._coupledStreamCount=F(O)?O:this._channels-1,this._channelMappingTable=I||(this._channels===2?[0,1]:[0]),this._preSkip=z||0,this._forceStereo=D<=K&&D!=2?J:0,this._inputSize=32e3*.12*this._channels,this._outputChannelSize=120*48,this._outputChannels=this._forceStereo?2:this._channels,this._ready=this._init(),this}class OpusDecoderWebWorker extends WASMAudioDecoderWorker{constructor(K){super(K,"opus-decoder",OpusDecoder,EmscriptenWASM)}async decodeFrame(K){return this.postToDecoder("decodeFrame",K)}async decodeFrames(K){return this.postToDecoder("decodeFrames",K)}}assignNames(OpusDecoder,"OpusDecoder"),assignNames(OpusDecoderWebWorker,"OpusDecoderWebWorker"),new OpusDecoder;class RoomPeer extends RoomUsers{constructor(F){super(F);Ie(this,"getPeerStatsTimer",0);Ie(this,"reports",[]);Ie(this,"peerNetwork",{inboundBytes:0,outboundBytes:0,lostRate:"0.00",roundTripTime:"0",jitter:"0"});Ie(this,"initPeer",()=>{var F;(F=this.peerIns)==null||F.close(),this.transceiverMap=new Map,this.peerIns=new RTCPeerConnection({iceServers:[{urls:"stun:stun.cloudflare.com:3478"}],bundlePolicy:"max-bundle"}),this.peerIns.createDataChannel("scapegoat-channel"),Be(this,jn).call(this),Be(this,Jn).call(this),this.peerIns.onicecandidate=async Z=>{Z.candidate&&await parseCandidate(Z.candidate.candidate)}});Ie(this,"getNatType",async()=>{});Ie(this,"initSendChannel",(F="",Z)=>{});Ie(this,"initReceiveChannel",(F="",Z)=>{});Ie(this,"replaceSenderStream",async(F=[],Z)=>{const{userId:D}=this.options;F.length===0&&(F=mediaType_keys);for(const N of F){const O=this.transceiverMap.get(N);let I;if(O){const{sender:z}=O;Z?I=this.getUserStream(D,N):I=this.getPhoneyStreams(N);const[J]=I.getTracks();J&&await z.replaceTrack(J)}}});Ie(this,"getSenderTracks",async(F=[])=>{const Z=[];for(const D of F){const N=this.transceiverMap.get(D);if(!N)continue;const{mid:O,sender:I}=N,{track:z}=I;if(!z)continue;const{id:J,enabled:Q}=z,ne=mediaType_keys.findIndex(te=>te===D),re={type:ne,enabled:Q,trackName:`web-${ne}-${J}`,location:"local",mid:O};Z.push(re)}return Z});Ie(this,"addSenders",async(F=[])=>{F.length===0&&(this.peerIns.addTransceiver("audio",{direction:"sendonly"}),this.peerIns.addTransceiver("video",{direction:"sendonly"}));const Z=[];for(const D of F){if(this.transceiverMap.get(D))continue;const O=this.getPhoneyStreams(D),[I]=O.getTracks(),z=this.peerIns.addTransceiver(I,{direction:"sendonly"});this.transceiverMap.set(D,z),Z.push(D)}if(F.length===0||Z.length!==0){const D=await this.peerIns.createOffer();if(this.options.debug){const N=libExports$1.parse(D.sdp),O=dt(N.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setLocalDescription",{msidArr:O,sdpJson:N,description:D})}await this.peerIns.setLocalDescription(D)}return Z});Ie(this,"removeSenders",async(F=[])=>{F.length===0&&(F=mediaType_keys);for(const Z of F)this.transceiverMap.has(Z)&&this.transceiverMap.delete(Z)});Ie(this,"onSubscribeUserTracks",F=>{let Z=0;return new Promise(async D=>{const N=[];for(const O of F){const{tracks:I=[]}=O;for(const z of I){const{trackName:J,mid:Q}=z,[ne]=await this.getUserTrackByTrackName([J]);N.push({...ne,mid:Q})}}{let O=[];const I=async()=>{clearTimeout(Z);const J=new Map;for(const ne of O){const{userId:re,mediaType:te}=ne;if(!re||!te)continue;J.has(re)||J.set(re,{userId:re,tracks:[],updateStreams:{}});const le=J.get(re);le.tracks.push(ne),le.updateStreams[te]=!0}const Q=[...J.values()];for(const ne of Q){const{userId:re,tracks:te}=ne;await this.updateUsertracks(re,te,!0)}await this.emitNotifyUpdateUsersStreams(Q),this.peerIns.removeEventListener("track",z);{const ne=Array.from(N,oe=>oe.trackName),re=Array.from(O,oe=>oe.trackName),te=ne.filter(oe=>!re.includes(oe));D({target:ne,success:re,fail:te})}},z=async J=>{const{streams:Q,transceiver:ne}=J,[re]=Q,{mid:te,receiver:oe}=ne,{track:le}=oe,{id:ae}=le,ce=N.find(fe=>fe.mid===`${te}`);if(!ce)return;const{userId:de,mediaType:we}=ce;if(!(!de||!we)){{const fe={...ce,mid:te,msid:ae};O.push(fe)}this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: await subscribe ${O.length}/${N.length}`,{mediaType:we,mid:te,userTrack:ce,e:J});{const fe=new Audio;if(fe.srcObject=re,await this.initUserMediaStreamContext(de,we,re),we==="microphoneCamera_audio"||we==="screenSharing_audio"){const ge=this.getUserAudioMediaStreamContext(de,we);ge==null||ge.setMute(!1)}}N.length===O.length&&I()}};this.peerIns.addEventListener("track",z),Z=window.setTimeout(()=>{this.reportLogs("subscribe_error",`incomplete subscription. (${O.length}/${N.length})`),I()},5*1e3)}})});st(this,jn,()=>{let F=0;const Z=()=>{this.peerIns.close(),this.setRoomState("closed")};this.peerIns.oniceconnectionstatechange=async()=>{const D=this.peerIns.iceConnectionState;switch(await this.taskQueue.setCondition("ice",!1),clearTimeout(F),D){case"connected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#00b60f;",`------->quickvo: connectionState:${D}`),await this.taskQueue.setCondition("ice",!0),await this.getNatType(),this.setRoomState("connected");break;case"disconnected":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${D}`),F=window.setTimeout(Z,30*1e3);break;case"failed":this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b60000;",`------->quickvo: connectionState:${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}`),Z();break;default:this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#b64900;",`------->quickvo: connectionState:${D}`);break}}});Ie(this,"closeUserTracks",async(F,Z=[],D=!1)=>{const N=[];for(const J of Z){const{trackName:Q,msid:ne}=J;N.push(Q),ne&&N.push(ne)}const O=J=>N.includes(J),I=this.peerIns.getTransceivers();for(const J of I){const{mid:Q,sender:ne,receiver:re}=J;ne.track&&O(ne.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.sender: ${Q} is stop.`,J)),re.track&&O(re.track.id)&&(J.stop(),this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: transceiver.receiver: ${Q} is stop.`,J))}const z=await this.getUser(F);if(z){for(const J of z.tracks){const{trackName:Q,msid:ne,userId:re,mediaType:te}=J;!re||!te||!O(Q)||(this.removeUserMediaStreamContext(re,te),ne&&delete J.msid)}if(D){const J=z.tracks.filter(({trackName:Q})=>!O(Q));await this.updateUsertracks(F,J,!1)}}});Ie(this,"createOffer",async()=>{const F=await this.peerIns.createOffer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createOffer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"createAnswer",async()=>{const F=await this.peerIns.createAnswer();if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: createAnswer",{msidArr:D,sdpJson:Z,description:F})}await this.peerIns.setLocalDescription(F)});Ie(this,"getSdp",()=>{var F;return(F=this.peerIns.localDescription)==null?void 0:F.sdp});Ie(this,"setRemoteDescription",async F=>{if(this.options.debug){const Z=libExports$1.parse(F.sdp),D=dt(Z.media,["mid","msid","type"]);console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#ffffff;","------->quickvo: setRemoteDescription",{msidArr:D,sdpJson:Z,description:F})}return await this.peerIns.setRemoteDescription(F),F});Ie(this,"setCallStrategy",async(F,Z=[])=>{Z.length===0&&(Z=mediaType_keys);let D="balanced";switch(F){case"qualityPriority":D="maintain-resolution";break;case"fluencyPriority":D="maintain-framerate";break;case"balancedDowngrade":D="balanced";break}const N=await this.getSelfInfo(),O=Array.from(N.tracks,({trackName:z})=>z),I=this.peerIns.getSenders();for(const z of I){const{track:J}=z;if(!J||!O.includes(J.id))continue;const Q=z.getParameters();z.setParameters({...Q,degradationPreference:D})}});Ie(this,"setRTCRtpSenderParameters",F=>{try{const Z=this.peerIns.getSenders();for(const D of Z){const N=D.getParameters();D.setParameters({...N,...F})}}catch(Z){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setRTCRtpSenderParameters is error.",Z)}});Ie(this,"getReportsByMid",async(F=[])=>F.length===0?this.reports:this.reports.filter(Z=>F.includes(Z.mid)));Ie(this,"getRoomNetwork",()=>this.peerNetwork);Ie(this,"getPeerNetwork",()=>this.peerNetwork);st(this,zn,async()=>{try{const F=await this.peerIns.getStats(),Z=["inbound-rtp","remote-inbound-rtp","outbound-rtp","transport"],N=[...F.values()].filter(ge=>Z.includes(ge.type));let O=0,I=0,z=0,J=0,Q=0,ne=0,re=[],te=[];for(const ge of this.reports){const{packetsSent:me,packetsLost:ve}=ge;me&&(z+=me),ve&&(J+=ve)}this.reports=N;for(const ge of this.reports){const{bytesSent:me,bytesReceived:ve,packetsSent:ke,packetsLost:xe,roundTripTime:_e,jitter:Te}=ge;me&&(I=me),ve&&(O=ve),ke&&(Q+=ke),xe&&(ne+=xe),_e&&re.push((_e*100).toFixed(2)),Te&&te.push(Te.toFixed(2))}te.sort().reverse(),re.sort().reverse();const oe=Q-z,le=ne-J,ae=oe===0?"0.00":(le/oe).toFixed(2),[ce="0"]=re,[de="0"]=te,we={outboundBytes:I,inboundBytes:O,lostRate:ae,roundTripTime:ce,jitter:de};this.peerNetwork=we;const fe=(ge,me,ve)=>{const ke=Number(ge),xe=Number(me),_e=Number(ve);let Te="0";return ke<.03&&xe<100&&_e<.05?Te="5":ke<.06&&xe<160&&_e<.1?Te="4":ke<.1&&xe<250&&_e<.15?Te="3":ke<.15&&xe<400&&_e<.2?Te="2":Te="1",Number(Te)};{const ge=fe(ae,ce,de),me=await this.getSelfInfo(),{network:ve}=me,ke={egress:ge,ingress:ge};$t("updateUserNetwork",async()=>{if(await this.updateUserNetwork(this.options.userId,ke),JSON.stringify(ve)!==JSON.stringify(ke)){this.emitNotifyUpdateUsers();const{userId:Te,roomId:qe}=this.options;this.cwsIns.sendMessage({event:"networkQualityChange",data:{...ke,userId:Te,roomId:qe}},!1)}},3*1e3)}}catch(F){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setNetQuality is err.",F)}});st(this,Jn,()=>{const F=async()=>{this.peerIns.connectionState!=="connected"||!this.options.roomId||Be(this,zn).call(this)};this.getPeerStatsTimer=window.setInterval(F,1*1e3)});Ie(this,"stopGetPeerStats",()=>clearInterval(this.getPeerStatsTimer))}}jn=new WeakMap,zn=new WeakMap,Jn=new WeakMap;class RoomCalls extends RoomPeer{constructor(F){super(F);st(this,On,0);Ie(this,"setLocalStream",(F,Z)=>new Promise(async(D,N)=>{try{typeof F=="string"&&(F=[F]);for(const I of F)this.localStreamsActionMap.set(I,Z);if(Z){if(F.includes("microphoneCamera_audio")&&F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera"):F.includes("microphoneCamera_audio")?await this.initLocalStream("microphoneCamera_audio"):F.includes("microphoneCamera_video")?await this.initLocalStream("microphoneCamera_video"):F.includes("screenSharing_audio")&&F.includes("screenSharing_video")?await this.initLocalStream("screenSharing"):F.includes("screenSharing_audio")&&!F.includes("screenSharing_video")?await this.initLocalStream("screenSharing_audio"):F.includes("screenSharing_video")&&!F.includes("screenSharing_audio")&&await this.initLocalStream("screenSharing_video"),F.includes("screenSharing_audio")){const I=await this.getLocalStream("screenSharing_audio");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}if(F.includes("screenSharing_video")){const I=await this.getLocalStream("screenSharing_video");if(I){const z=I.getTracks();for(const J of z)J.onended=()=>this.stopPublish(["screenSharing_audio","screenSharing_video"])}}}else await this.stopLocalStreams(F);const O=await this.getLocalStreams(F);this.cwsIns.emitNotify("onLocalStream",{code:200,data:O,desc:"local stream is change."}),D(O)}catch(O){N(O)}}));Ie(this,"setMediaDeviceKind",(F,Z)=>new Promise(async(D,N)=>{this.setDeviceKind(F,Z);const O=await this.getSelfInfo(),{id:I,tracks:z=[],callActionMap:J}=O,Q=[],ne=async re=>{const te=this.localStreamsActionMap.get(re),oe=z.find(ae=>ae.mediaType===re),le=J[re];if(te){Q.push(re),await this.stopLocalStreams([re]);try{await this.initLocalStream(re)}catch(ae){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: initLocalStream is error.",ae),await this.inactiveTracks([re],!1),N(ae)}}if(oe){const ae=await this.getLocalStream(re);ae&&(await this.initUserMediaStreamContext(I,re,ae),le&&await this.replaceSenderStream([re],!0))}{const ae=await this.getLocalStreams(Q);this.cwsIns.emitNotify("onLocalStream",{code:200,data:ae,desc:"local stream is change."}),await this.emitNotifyUpdateUsers(),D(!0)}};F==="audioinput"&&ne("microphoneCamera_audio"),F==="videoinput"&&ne("microphoneCamera_video"),F==="audiooutput"&&(await this.changeAudiooutput(),D(!0))}));Ie(this,"changeScreenSharing",async F=>{const Z=await this.getSelfInfo(),{tracks:D=[],callActionMap:N}=Z;try{await this.setLocalStream(F,!0);for(const O of F)D.find(z=>z.mediaType===O&&N[O])&&await this.replaceSenderStream([O],!0)}catch(O){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: changeScreenSharing is error.",O)}});Ie(this,"createSession",()=>new Promise(async(F,Z)=>{if(["connecting","connected"].includes(this.roomState))return F(!0);this.setRoomState("connecting"),await this.taskQueue.createTask({describe:"createSession",conditionKeys:["createWs","createSession"],changeConditionKeys:["createSession"],func:()=>new Promise(async(D,N)=>{try{await this.addSenders(),this.cwsIns.sendMessage({event:"connectCF",data:{sdp:this.getSdp()}}).then(async O=>{const{code:I=0,desc:z,data:J}=O;if(I!==200)return N(z);const{remoteSdp:Q}=J;await this.taskQueue.setCondition("ice",!1),await this.taskQueue.createTask({describe:"ice",timeout:30*1e3,conditionKeys:["ice"],func:()=>new Promise(ne=>setTimeout(()=>ne(!0),300)),success:async()=>{D(!0)},fail:async ne=>{throw new Error(`ice connection failed: ${ne}`)}}),await this.setRemoteDescription({type:"answer",sdp:Q})})}catch(O){N(O)}}),success:async D=>{F(D)},fail:async D=>{this.reportLogs("ws_c_timeout",D.message||D),Z(D)},complete:()=>{this.taskQueue.setCondition("createSession",!0)}})}));Ie(this,"earlyConnect",(F=[])=>{this.isEarly=!0,Be(this,An).call(this),this.createSession(),F.length===0&&(F=["microphoneCamera_audio","microphoneCamera_video"]),Be(this,$n).call(this,F)});Ie(this,"joinRoom",async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"joinRoom",conditionKeys:["createWs"],changeConditionKeys:["joinRoom"],func:()=>new Promise(async(N,O)=>{try{this.setOptions(F),await Be(this,An).call(this),this.clearUsers();const{roomId:I,userId:z,callType:J,sdkToken:Q}=this.options;this.cwsIns.sendMessage({event:this.isEarly?"joinRoomEx":"joinRoom",data:{callType:J,roomId:I,user:{id:z,tracks:[],callAction:0},token:Q},version:2}).then(async ne=>{const{code:re=0,desc:te="服务器繁忙",data:oe}=ne;if(re!==200)return O(te);const{roomId:le="",roomUsers:ae=[]}=oe;if(le!==I)return O("加入的房间不匹配");this.isInRoom=!0,this.taskQueue.setCondition("createTrack",!0),this.taskQueue.setCondition("publish",!0),this.taskQueue.setCondition("subscribe",!0),this.taskQueue.setCondition("renegotiate",!0),this.taskQueue.setCondition("closeTrack",!0),this.initHeartbeat(),this.createSession(),await this.updateUsers(ae);const ce=[];for(const we of ae){const{id:fe,channelCache:ge}=we,{channels:me=[]}=ge;await this.updateUserBehaviors(fe,we.behavior),await this.updateUserChannels(fe,me,!1),me.length!==0&&ce.push({userId:fe,channels:me})}this.subChannel(ce),await this.emitNotifyUpdateUsers();const de=await this.getUsers();N(de)})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("join_room_error",N.message||N),D(N)},complete:()=>{this.taskQueue.setCondition("joinRoom",!0)}})}));Ie(this,"quitRoom",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,clearInterval(Be(this,On)),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.setRoomState("ready")}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),await this.taskQueue.setCondition("closeTrack",!0),this.cwsIns.sendMessage({event:"quitRoom",data:N}),F(!0)}));Ie(this,"quitRoomEx",()=>new Promise(async F=>{const{roomId:Z,userId:D}=this.options,N={roomId:Z,user:{id:D}};try{this.isInRoom=!1,this.initHeartbeat(),await this.stopLocalStreams(),this.stopSubscribe(),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams()}catch(O){this.reportLogs("quit_room_error",O.message||O)}await new Promise(O=>setTimeout(()=>O(!0),300)),this.cwsIns.sendMessage({event:"quitRoomEx",data:N}),F(!0)}));Ie(this,"syncRoomInfo",()=>new Promise(async(F,Z)=>{const{userId:D}=this.options,N=await this.getUser(D),{id:O=D,callAction:I=0}=N;this.cwsIns.sendMessage({event:"syncRoomInfo",data:{user:{id:O,callAction:I}}}).then(async z=>{if(z.code!==200)return Z(z.desc);const J=z.data.users;this.clearUsers(),await this.updateUsers(J),await this.updateUsertracks(N.id,N.tracks,!1);{const Q=await this.getUsers();F(Q)}}).catch(z=>Z(z))}));Ie(this,"publish",F=>new Promise(async(Z,D)=>{{const N=await this.getSelfInfo(),{banBehaviorMap:O}=N;let I=!0;for(const z of F)if(O[z]){I=!1;break}if(I===!1)return D("publish is error: prohibited by administrator.")}try{await this.setLocalStream(F,!0)}catch(N){this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: setLocalStream is error.",N)}await this.taskQueue.createTask({describe:"publish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["publish"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo(),z=[];for(const te of F){{const oe=this.getPhoneyStreams(te);await this.initUserMediaStreamContext(I.id,te,oe)}{const oe=await this.getLocalStream(te);oe?await this.initUserMediaStreamContext(I.id,te,oe):z.push(te)}}const J=F.filter(te=>!z.includes(te)||["microphoneCamera_audio","microphoneCamera_video"].includes(te));await this.replaceSenderStream(F,!1),await Be(this,$n).call(this,J);const Q=await this.getSenderTracks(J),ne=[...I.tracks,...Q];await this.updateUsertracks(I.id,ne,!0),z.length!==0&&await this.inactiveTracks(z,!1),J.length!==0&&await this.replaceSenderStream(J,!0);const re=await this.getCallAction(ne);await Be(this,En).call(this,re),await new Promise(te=>setTimeout(()=>te(!0),230)),Be(this,Wn).call(this,F);{await this.emitNotifyUpdateUsers();const te=await this.getSelfInfo();N(te)}}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("publish",!0)}})}));Ie(this,"stopPublish",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"stopPublish",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getSelfInfo();F.length===0&&(F=mediaType_keys);const z=I.tracks.filter(({mediaType:Q})=>Q&&F.includes(Q)),J=async()=>{this.initMediaPhoneyStreams(F);const Q=await this.getSelfInfo();await this.emitNotifyUpdateUsers(),N(Q)};if(z.length===0)return J();await this.replaceSenderStream(F,!0),await this.closeUserTracks(I.id,z,!0),await this.removeSenders(F);{const Q=await this.getCallAction(I.tracks);await Be(this,En).call(this,Q)}await this.createOffer(),this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{code:ne=0,data:re,desc:te}=Q;if(ne!==200)return O(te);const{remoteSdp:oe}=re;await this.setRemoteDescription({type:"answer",sdp:oe}),J()})}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"subscribe",(F=[],Z=3)=>new Promise(async(D,N)=>{const O=await this.taskQueue.createTask({describe:"subscribe",strict:!0,conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe","renegotiate","closeTrack"],changeConditionKeys:["subscribe"],func:()=>new Promise(async(I,z)=>{try{const J=await this.getUsers();let Q=[];for(const te of J){const{isSelf:oe,tracks:le=[]}=te;if(!oe){const ae=le.filter(({trackName:ce,mid:de=""})=>de!==""&&(F.includes(ce)||F.length===0));ae.length!==0&&Q.push({...te,tracks:ae})}}const ne=async(te={})=>{const oe=Array.from(Q,({id:ae})=>ae),le=await this.getUsers(oe);await this.emitNotifyUpdateUsers(),I({users:le,detail:te})};if(Q.length===0)return ne();const re=[];for(const te of Q){const{id:oe,tracks:le}=te,ae=dt(le,["type","trackName"]),ce={id:oe,tracks:ae};re.push(ce)}this.cwsIns.sendMessage({event:"subscribe",data:{users:re}}).then(async te=>{const{code:oe=0,data:le,desc:ae}=te;if(oe!==200)return z(ae);const{remoteSdp:ce,users:de=[]}=le;this.onSubscribeUserTracks(de).then(async we=>{await this.renegotiate().then(()=>ne(we)).catch(fe=>z(fe))}).catch(we=>{z(we)}),await this.setRemoteDescription({type:"offer",sdp:ce})})}catch(J){z(J)}}),success:async I=>{O.clear(),this.taskQueue.setCondition("subscribe",!0),D(I)},fail:async I=>{if(this.options.debug&&console.info("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;",`------->quickvo: subscribe error. surplus count is ${Z}`),Z>0)return await new Promise(z=>setTimeout(()=>z(!0),(3-Z)*1e3)),Z=Z-1,O.retry();O.clear(),this.reportLogs("subscribe_error",I.message||I),this.taskQueue.setCondition("subscribe",!0),N(I)},complete:async()=>{}})}));Ie(this,"renegotiate",()=>new Promise(async(F,Z)=>{try{await this.taskQueue.setCondition("renegotiate",!1),await this.createAnswer(),this.cwsIns.sendMessage({event:"renegotiate",data:{sdp:this.getSdp()}}).then(D=>{const{code:N=0,desc:O}=D;if(N!==200)return Z(O);F(D)}).finally(()=>{this.taskQueue.setCondition("renegotiate",!0)})}catch(D){Z(D)}}));Ie(this,"stopSubscribe",(F=[])=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"closeTrack",conditionKeys:["createWs","createSession","ice","createTrack","publish","subscribe"],changeConditionKeys:["closeTrack"],func:()=>new Promise(async(N,O)=>{try{const I=await this.getUsers(),z=[];for(const Q of I){const{tracks:ne=[]}=Q;for(const re of ne){const{type:te,mid:oe,trackName:le,mediaType:ae,msid:ce}=re;if(!(!ae||!ce)&&(F.length===0||F.includes(le))){const de={type:te,mid:oe,trackName:ce};z.push(de),await this.closeUserTracks(Q.id,[re])}}}const J=async()=>{await this.emitNotifyUpdateUsers(),N(!0)};if(z.length===0)return J();await this.createOffer(),await this.cwsIns.sendMessage({event:"closeTrack",data:{roomId:this.options.roomId,sdp:this.getSdp(),tracks:z}}).then(async Q=>{const{remoteSdp:ne}=Q.data;await this.setRemoteDescription({type:"answer",sdp:ne})}),J()}catch(I){O(I)}}),success:async N=>{Z(N)},fail:async N=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: stopPublish is error.",N),this.reportLogs("close_track_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("closeTrack",!0)}})}));Ie(this,"inactiveTracks",async(F,Z)=>new Promise(async D=>{const N=await this.getSelfInfo();if(!N||!N.id)return D(!0);const{tracks:O=[]}=N,I=[...O];for(let J of I){const{mediaType:Q}=J;if(Q&&F.includes(Q)){J.enabled=Z;const ne=await this.getLocalStream(Q);if(!ne)continue;const re=ne.getTracks();for(const te of re)te.enabled=Z}}await this.replaceSenderStream(F,Z);const z=await this.getCallAction(I);await Be(this,En).call(this,z),await this.emitNotifyUpdateUsers(),D(!0)}));Ie(this,"setBanBehaviors",F=>new Promise(async(Z,D)=>{try{const{roomId:N}=this.options,O=[];for(const I of F){const{id:z,banBehaviors:J}=I,Q=Object.keys(J);if(Q.length===0)continue;const ne=[];for(const te of Q){const oe=mediaType_keys.findIndex(ce=>ce===te),le=J[te],ae={type:oe,behavior:le};ne.push(ae)}const re={id:z,behaviors:ne};O.push(re)}this.cwsIns.sendMessage({event:"preventUsersBehavior",data:{roomId:N,users:O}}).then(async I=>{const{code:z=0,desc:J}=I;if(z!==200)return D(J);Z(I)}).finally(()=>{})}catch(N){D(N)}}));Ie(this,"pubChannel",()=>new Promise(async(F,Z)=>{const N=[{dataChannelName:"web-channe"}];await this.cwsIns.sendMessage({event:"pubChannel",data:{channels:N}}).then(async O=>{const{code:I=0,data:z,desc:J}=O;if(I!==200)return Z(J);const{channels:Q=[]}=z;for(const ne of Q){const{channels:re=[]}=ne;for(const te of re){const{dataChannelName:oe,id:le}=te;this.initSendChannel(oe,le)}}F(!0)}).catch(O=>{Z(O)})}));Ie(this,"subChannel",(F=[])=>new Promise(async(Z,D)=>{if(F.length===0)return Z(!0);await this.taskQueue.createTask({describe:"subChannel",strict:!0,conditionKeys:["createWs","createSession","ice"],changeConditionKeys:[],func:()=>this.cwsIns.sendMessage({event:"subChannel",data:{channels:F}}).then(async N=>{const{code:O=0,data:I,desc:z}=N;if(O!==200)return D(z);const{channels:J=[]}=I;for(const Q of J){const{channels:ne=[]}=Q;for(const re of ne){const{dataChannelName:te,id:oe}=re;this.initReceiveChannel(te,oe)}}}),success:async N=>{Z(N)},fail:async N=>{D(N)}})}));Ie(this,"debugger",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"debugger"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"shutdown",()=>new Promise(async(F,Z)=>{await this.cwsIns.sendMessage({event:"shutdown"},!1).then(async D=>{if(D.code!==200)return Z(D.desc);F(!0)}).catch(D=>{Z(D)})}));Ie(this,"initHeartbeat",()=>{this.stopHeartbeat();const F=()=>this.cwsIns.sendMessage({event:this.isInRoom?"heartbeat":"heartbeatEx"},!1),Z=this.isInRoom?5*1e3:30*1e3;At(this,On,window.setInterval(F,Z)),F()});Ie(this,"stopHeartbeat",()=>{clearInterval(Be(this,On))});st(this,Wn,async F=>{const{roomId:Z}=this.options;if(!Z)return;const{id:D,tracks:N=[]}=await this.getSelfInfo(),O=N.filter(I=>I.mediaType&&F.includes(I.mediaType));O.length!==0&&this.cwsIns.sendMessage({event:"pubNotify",data:{roomId:Z,user:{id:D,tracks:O}}})});st(this,En,async F=>new Promise(async(Z,D)=>{const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O,callAction:F}};await this.cwsIns.sendMessage({event:"updateCall",data:I}).then(async z=>{const{code:J=0}=z;if(J!==200)return D(z);await this.updateUserCallAction(O,F),Z(F)}).catch(z=>D(z))}));st(this,An,()=>new Promise(async(F,Z)=>{try{if(["connecting","connected"].includes(this.cwsIns.state))return F(!0);await this.taskQueue.setCondition("createWs",!1),this.cwsIns.clearEvents(),this.initPeer();const{appid:D,roomId:N,userId:O}=this.options;if(!D)return Z("quickvo: createWs is error. You must first use QuickVO.setOptions to set the appid.");const I={c:D,r:N,v:this.sdk_service_version};if(this.isEarly){const J=xt();I.i=J,this.setOptions({earlyId:J})}else I.b=O;this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs",I);const z=btoa(encodeURI(JSON.stringify(I)));await this.cwsIns.connect(z),this.initHeartbeat(),await this.taskQueue.setCondition("createWs",!0),await this.taskQueue.setCondition("createSession",!0),F(!0)}catch(D){console.error("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: createWs is error.",D),this.reportLogs("ws_c_timeout",D.message||D),Z(D)}}));st(this,$n,async F=>new Promise(async(Z,D)=>{await this.taskQueue.createTask({describe:"createTrack",conditionKeys:["createWs","createSession","ice","createTrack","subscribe","renegotiate","closeTrack"],func:()=>new Promise(async(N,O)=>{try{await this.taskQueue.setCondition("createTrack",!1);const I=await this.addSenders(F),z=await this.getSenderTracks(I);if(z.length===0)return await this.taskQueue.setCondition("createTrack",!0),N(!0);this.cwsIns.sendMessage({event:"publish",data:{sdp:this.getSdp(),tracks:z,callAction:0}}).then(async J=>{const{code:Q=0,desc:ne,data:re}=J;if(Q!==200)return O(ne);const{remoteSdp:te}=re;await this.setRemoteDescription({type:"answer",sdp:te}),N(!0)})}catch(I){await this.removeSenders(F),O(I)}}),success:async N=>{Z(N)},fail:async N=>{this.reportLogs("publish_error",N.message||N),D(N)},complete:async()=>{await this.taskQueue.setCondition("createTrack",!0)}})}))}}On=new WeakMap,Wn=new WeakMap,En=new WeakMap,An=new WeakMap,$n=new WeakMap;class Room extends RoomCalls{constructor(K){super(K)}}class QuickVO extends Room{constructor(F){super(F);st(this,_n,new Map);Ie(this,"reconstruct",async()=>{if(this.cwsIns.state!=="connected"||this.roomState!=="failed")return;this.setRoomState("ready"),this.initMediaPhoneyStreams(),this.taskQueue.clear(),await this.syncRoomInfo(),this.initPeer(),this.taskQueue.setCondition("createSession",!0),this.taskQueue.setCondition("ice",!0),await this.createSession();const F=[],Z=[],D=await this.getUsers();for(const N of D){const{isSelf:O,callActionMap:I,tracks:z=[]}=N;if(O)for(const J of mediaType_keys)I[J]&&F.push(J);for(const J of z)J.msid&&Z.push(J.trackName)}await this.subscribe(Z),await this.publish(F)});st(this,Vn,()=>{{const F=async Z=>{const{state:D}=Z.data;if(D==="closed"){const{roomId:N,userId:O}=this.options,I={roomId:N,user:{id:O}};this.stopHeartbeat(),this.cwsIns.sendMessage({event:"quitRoom",data:I}),this.cwsIns.close(),this.reportLogs("webrtc_c_timeout","webrtc state is closed.")}this.roomState==="failed"&&this.reconstruct()};this.cwsIns.addNotify({event:"onRoomState",callback:F},!0)}{const F=async Z=>{const{qualities:D=[]}=Z.data,[N]=D;if(!(N&&N.userId===this.options.userId&&D.length===1)){for(const O of D){const{userId:I,egress:z,ingress:J}=O;this.checkUserInRoom(I)&&await this.updateUserNetwork(I,{egress:z,ingress:J})}await this.emitNotifyUpdateUsers()}};this.cwsIns.addNotify({event:"onNetQuality",callback:F},!0)}{const F=async Z=>{const D=Z.data.user;await this.updateUsers([D]),await this.updateUsertracks(D.id,D.track,!1),await this.updateUserBehaviors(D.id,D.behavior),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onJoinRoom",callback:F},!0)}{const F=async Z=>{await this.removeUsers([Z.data.user.id]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onQuitRoom",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,tracks:O=[],callAction:I=0}=D;if(await this.updateUserCallAction(N,I),await this.updateUserPermissions(N,3),await this.updateUsertracks(N,O,!0),this.options.newPublishAutoSubscribe){const z=this.getTrackNamesFormTracks(O);await this.subscribe(z)}else await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onPublish",callback:F},!0)}{const F=async Z=>{const D=[Z.data];this.subChannel(D)};this.cwsIns.addNotify({event:"onDataChannelPublish",callback:F},!0)}{const F=async Z=>{const{id:D,tracks:N}=Z.data.user;D!==this.options.userId&&(await this.closeUserTracks(D,N,!0),await this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onCloseTrack",callback:F},!0)}{const F=async Z=>{const{id:D,callAction:N}=Z.data.user;this.checkUserInRoom(D)&&(await this.updateUserCallAction(D,N),this.emitNotifyUpdateUsers())};this.cwsIns.addNotify({event:"onUpdateCall",callback:F},!0)}{const F=async Z=>{const{user:D}=Z.data,{id:N,permissions:O=1}=D;O===1?await this.removeUsers([N]):O===3&&await this.updateUsers([D]),await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdatePermissions",callback:F},!0)}{const F=async Z=>{const{users:D}=Z.data;for(const N of D){const{id:O,behavior:I}=N;await this.updateUserBehaviors(O,I)}await this.emitNotifyUpdateUsers()};this.cwsIns.addNotify({event:"onUpdateBehavior",callback:F},!0)}this.cwsIns.addNotify({event:"onTokenExpired",callback:async F=>this.destroy()},!0),this.cwsIns.addNotify({event:"destroyRoom",callback:this.destroy},!0)});Ie(this,"addNotify",F=>this.cwsIns.addNotify(F));st(this,Zn,()=>{});st(this,Kn,()=>{this.cwsIns.onReconnectSuccess=async()=>{this.reconstruct()}});st(this,Gn,async()=>{this.setRoomState("closed")});Ie(this,"addRequestAnimationFrame",async(F,Z)=>{{const N=Be(this,_n).get(F);N&&cancelAnimationFrame(N)}const D=(N=Date.now())=>{Z(N);const O=requestAnimationFrame(D);Be(this,_n).set(F,O)};D()});Ie(this,"clearRequestAnimationFrame",async(F=[])=>{F.length===0&&(F=[...Be(this,_n).keys()]);const Z=[];for(const D of F){const N=Be(this,_n).get(D);N&&(cancelAnimationFrame(N),Z.push(N))}return Z});Ie(this,"destroy",async()=>{this.options.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->quickvo: 销毁SDK"),this.cwsIns.emitNotify("onDestroy",{code:200,data:{},desc:"sdk is destroy."}),this.stopLocalStreams(),await new Promise(F=>setTimeout(()=>F(!0),300)),this.stopGetPeerStats(),this.clearUsers(),this.clearUserStreams(),this.cwsIns.clearEvents(),this.cwsIns.close()});Be(this,Zn).call(this),Be(this,Kn).call(this),Be(this,Gn).call(this),Be(this,Vn).call(this)}}_n=new WeakMap,Vn=new WeakMap,Zn=new WeakMap,Kn=new WeakMap,Gn=new WeakMap,exports.QuickVO=QuickVO,exports.ignoreEvent=ignoreEvent,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});