1024&&(c.push(u.apply(String,a)),a.length=0),void Array.prototype.push.apply(a,arguments))}}function r(a,c,p,f,m){var _,v,R=8*m-f-1,y=(1<>1,L=-7,N=p?m-1:0,E=p?-1:1,A=a[c+N];for(N+=E,_=A&(1<<-L)-1,A>>=-L,L+=R;L>0;_=256*_+a[c+N],N+=E,L-=8);for(v=_&(1<<-L)-1,_>>=-L,L+=f;L>0;v=256*v+a[c+N],N+=E,L-=8);if(_===0)_=1-P;else{if(_===y)return v?NaN:1/0*(A?-1:1);v+=Math.pow(2,f),_-=P}return(A?-1:1)*v*Math.pow(2,_-f)}function i(a,c,p,f,m,_){var v,R,y,P=8*_-m-1,L=(1<>1,E=m===23?Math.pow(2,-24)-Math.pow(2,-77):0,A=f?0:_-1,F=f?1:-1,q=c<0||c===0&&1/c<0?1:0;for(c=Math.abs(c),isNaN(c)||1/0===c?(R=isNaN(c)?1:0,v=L):(v=Math.floor(Math.log(c)/Math.LN2),c*(y=Math.pow(2,-v))<1&&(v--,y*=2),(c+=v+N>=1?E/y:E*Math.pow(2,1-N))*y>=2&&(v++,y/=2),v+N>=L?(R=0,v=L):v+N>=1?(R=(c*y-1)*Math.pow(2,m),v+=N):(R=c*Math.pow(2,N-1)*Math.pow(2,m),v=0));m>=8;a[p+A]=255&R,A+=F,R/=256,m-=8);for(v=v<0;a[p+A]=255&v,A+=F,v/=256,P-=8);a[p+A-F]|=128*q}var o,s,u,d,l,h=function(a,c,p){if(a===void 0&&(a=h.DEFAULT_CAPACITY),c===void 0&&(c=h.DEFAULT_ENDIAN),p===void 0&&(p=h.DEFAULT_NOASSERT),!p){if((a|=0)<0)throw RangeError("Illegal capacity");c=!!c,p=!!p}this.buffer=a===0?s:new ArrayBuffer(a),this.view=a===0?null:new Uint8Array(this.buffer),this.offset=0,this.markedOffset=-1,this.limit=a,this.littleEndian=c,this.noAssert=p};return h.VERSION="5.0.1",h.LITTLE_ENDIAN=!0,h.BIG_ENDIAN=!1,h.DEFAULT_CAPACITY=16,h.DEFAULT_ENDIAN=h.BIG_ENDIAN,h.DEFAULT_NOASSERT=!1,h.Long=n||null,(o=h.prototype).__isByteBuffer__,Object.defineProperty(o,"__isByteBuffer__",{value:!0,enumerable:!1,configurable:!1}),s=new ArrayBuffer(0),u=String.fromCharCode,h.accessor=function(){return Uint8Array},h.allocate=function(a,c,p){return new h(a,c,p)},h.concat=function(a,c,p,f){var m,_,v,R,y,P;for((typeof c=="boolean"||typeof c!="string")&&(f=p,p=c,c=void 0),m=0,v=0,R=a.length;R>v;++v)h.isByteBuffer(a[v])||(a[v]=h.wrap(a[v],c)),(_=a[v].limit-a[v].offset)>0&&(m+=_);if(m===0)return new h(0,p,f);for(P=new h(m,p,f),v=0;R>v;)(_=(y=a[v++]).limit-y.offset)<=0||(P.view.set(y.view.subarray(y.offset,y.limit),P.offset),P.offset+=_);return P.limit=P.offset,P.offset=0,P},h.isByteBuffer=function(a){return(a&&a.__isByteBuffer__)===!0},h.type=function(){return ArrayBuffer},h.wrap=function(a,c,p,f){var m,_;if(typeof c!="string"&&(f=p,p=c,c=void 0),typeof a=="string")switch(c===void 0&&(c="utf8"),c){case"base64":return h.fromBase64(a,p);case"hex":return h.fromHex(a,p);case"binary":return h.fromBinary(a,p);case"utf8":return h.fromUTF8(a,p);case"debug":return h.fromDebug(a,p);default:throw Error("Unsupported encoding: "+c)}if(a===null||typeof a!="object")throw TypeError("Illegal buffer");if(h.isByteBuffer(a))return(m=o.clone.call(a)).markedOffset=-1,m;if(a instanceof Uint8Array)m=new h(0,p,f),a.length>0&&(m.buffer=a.buffer,m.offset=a.byteOffset,m.limit=a.byteOffset+a.byteLength,m.view=new Uint8Array(a.buffer));else if(a instanceof ArrayBuffer)m=new h(0,p,f),a.byteLength>0&&(m.buffer=a,m.offset=0,m.limit=a.byteLength,m.view=a.byteLength>0?new Uint8Array(a):null);else{if(Object.prototype.toString.call(a)!=="[object Array]")throw TypeError("Illegal buffer");for((m=new h(a.length,p,f)).limit=a.length,_=0;_>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}for(f=c,_=(m=a.length)>>3,v=0,c+=this.writeVarint32(m,c);_--;)p=1&!!a[v++]|(1&!!a[v++])<<1|(1&!!a[v++])<<2|(1&!!a[v++])<<3|(1&!!a[v++])<<4|(1&!!a[v++])<<5|(1&!!a[v++])<<6|(1&!!a[v++])<<7,this.writeByte(p,c++);if(m>v){for(R=0,p=0;m>v;)p|=(1&!!a[v++])<>3,_=0,v=[],a+=p.length;m--;)c=this.readByte(a++),v[_++]=!!(1&c),v[_++]=!!(2&c),v[_++]=!!(4&c),v[_++]=!!(8&c),v[_++]=!!(16&c),v[_++]=!!(32&c),v[_++]=!!(64&c),v[_++]=!!(128&c);if(f>_)for(R=0,c=this.readByte(a++);f>_;)v[_++]=!!(1&c>>R++);return y&&(this.offset=a),v},o.readBytes=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+a>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+"+a+") <= "+this.buffer.byteLength)}return p=this.slice(c,c+a),f&&(this.offset+=a),p},o.writeBytes=o.append,o.writeInt8=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a|=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=1)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=1,this.view[c]=a,f&&(this.offset+=1),this},o.writeByte=o.writeInt8,o.readInt8=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength)}return(128&(c=this.view[a]))==128&&(c=-(255-c+1)),p&&(this.offset+=1),c},o.readByte=o.readInt8,o.writeUint8=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a>>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=1)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=1,this.view[c]=a,f&&(this.offset+=1),this},o.writeUInt8=o.writeUint8,o.readUint8=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength)}return c=this.view[a],p&&(this.offset+=1),c},o.readUInt8=o.readUint8,o.writeInt16=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a|=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=2)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=2,this.littleEndian?(this.view[c+1]=(65280&a)>>>8,this.view[c]=255&a):(this.view[c]=(65280&a)>>>8,this.view[c+1]=255&a),f&&(this.offset+=2),this},o.writeShort=o.writeInt16,o.readInt16=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+2) <= "+this.buffer.byteLength)}return c=0,this.littleEndian?(c=this.view[a],c|=this.view[a+1]<<8):(c=this.view[a]<<8,c|=this.view[a+1]),(32768&c)==32768&&(c=-(65535-c+1)),p&&(this.offset+=2),c},o.readShort=o.readInt16,o.writeUint16=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a>>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=2)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=2,this.littleEndian?(this.view[c+1]=(65280&a)>>>8,this.view[c]=255&a):(this.view[c]=(65280&a)>>>8,this.view[c+1]=255&a),f&&(this.offset+=2),this},o.writeUInt16=o.writeUint16,o.readUint16=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+2) <= "+this.buffer.byteLength)}return c=0,this.littleEndian?(c=this.view[a],c|=this.view[a+1]<<8):(c=this.view[a]<<8,c|=this.view[a+1]),p&&(this.offset+=2),c},o.readUInt16=o.readUint16,o.writeInt32=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a|=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=4)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=4,this.littleEndian?(this.view[c+3]=255&a>>>24,this.view[c+2]=255&a>>>16,this.view[c+1]=255&a>>>8,this.view[c]=255&a):(this.view[c]=255&a>>>24,this.view[c+1]=255&a>>>16,this.view[c+2]=255&a>>>8,this.view[c+3]=255&a),f&&(this.offset+=4),this},o.writeInt=o.writeInt32,o.readInt32=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength)}return c=0,this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0):(c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+=this.view[a]<<24>>>0),c|=0,p&&(this.offset+=4),c},o.readInt=o.readInt32,o.writeUint32=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a>>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=4)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=4,this.littleEndian?(this.view[c+3]=255&a>>>24,this.view[c+2]=255&a>>>16,this.view[c+1]=255&a>>>8,this.view[c]=255&a):(this.view[c]=255&a>>>24,this.view[c+1]=255&a>>>16,this.view[c+2]=255&a>>>8,this.view[c+3]=255&a),f&&(this.offset+=4),this},o.writeUInt32=o.writeUint32,o.readUint32=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength)}return c=0,this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0):(c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+=this.view[a]<<24>>>0),p&&(this.offset+=4),c},o.readUInt32=o.readUint32,n&&(o.writeInt64=function(a,c){var p,f,m,_=c===void 0;if(_&&(c=this.offset),!this.noAssert){if(typeof a=="number")a=n.fromNumber(a);else if(typeof a=="string")a=n.fromString(a);else if(!(a&&a instanceof n))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return typeof a=="number"?a=n.fromNumber(a):typeof a=="string"&&(a=n.fromString(a)),(c+=8)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=8,f=a.low,m=a.high,this.littleEndian?(this.view[c+3]=255&f>>>24,this.view[c+2]=255&f>>>16,this.view[c+1]=255&f>>>8,this.view[c]=255&f,c+=4,this.view[c+3]=255&m>>>24,this.view[c+2]=255&m>>>16,this.view[c+1]=255&m>>>8,this.view[c]=255&m):(this.view[c]=255&m>>>24,this.view[c+1]=255&m>>>16,this.view[c+2]=255&m>>>8,this.view[c+3]=255&m,c+=4,this.view[c]=255&f>>>24,this.view[c+1]=255&f>>>16,this.view[c+2]=255&f>>>8,this.view[c+3]=255&f),_&&(this.offset+=8),this},o.writeLong=o.writeInt64,o.readInt64=function(a){var c,p,f,m=a===void 0;if(m&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength)}return c=0,p=0,this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0,a+=4,p=this.view[a+2]<<16,p|=this.view[a+1]<<8,p|=this.view[a],p+=this.view[a+3]<<24>>>0):(p=this.view[a+1]<<16,p|=this.view[a+2]<<8,p|=this.view[a+3],p+=this.view[a]<<24>>>0,a+=4,c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+=this.view[a]<<24>>>0),f=new n(c,p,!1),m&&(this.offset+=8),f},o.readLong=o.readInt64,o.writeUint64=function(a,c){var p,f,m,_=c===void 0;if(_&&(c=this.offset),!this.noAssert){if(typeof a=="number")a=n.fromNumber(a);else if(typeof a=="string")a=n.fromString(a);else if(!(a&&a instanceof n))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return typeof a=="number"?a=n.fromNumber(a):typeof a=="string"&&(a=n.fromString(a)),(c+=8)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=8,f=a.low,m=a.high,this.littleEndian?(this.view[c+3]=255&f>>>24,this.view[c+2]=255&f>>>16,this.view[c+1]=255&f>>>8,this.view[c]=255&f,c+=4,this.view[c+3]=255&m>>>24,this.view[c+2]=255&m>>>16,this.view[c+1]=255&m>>>8,this.view[c]=255&m):(this.view[c]=255&m>>>24,this.view[c+1]=255&m>>>16,this.view[c+2]=255&m>>>8,this.view[c+3]=255&m,c+=4,this.view[c]=255&f>>>24,this.view[c+1]=255&f>>>16,this.view[c+2]=255&f>>>8,this.view[c+3]=255&f),_&&(this.offset+=8),this},o.writeUInt64=o.writeUint64,o.readUint64=function(a){var c,p,f,m=a===void 0;if(m&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength)}return c=0,p=0,this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0,a+=4,p=this.view[a+2]<<16,p|=this.view[a+1]<<8,p|=this.view[a],p+=this.view[a+3]<<24>>>0):(p=this.view[a+1]<<16,p|=this.view[a+2]<<8,p|=this.view[a+3],p+=this.view[a]<<24>>>0,a+=4,c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+=this.view[a]<<24>>>0),f=new n(c,p,!0),m&&(this.offset+=8),f},o.readUInt64=o.readUint64),o.writeFloat32=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number")throw TypeError("Illegal value: "+a+" (not a number)");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=4)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=4,i(this.view,a,c,this.littleEndian,23,4),f&&(this.offset+=4),this},o.writeFloat=o.writeFloat32,o.readFloat32=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength)}return c=r(this.view,a,this.littleEndian,23,4),p&&(this.offset+=4),c},o.readFloat=o.readFloat32,o.writeFloat64=function(a,c){var p,f=c===void 0;if(f&&(c=this.offset),!this.noAssert){if(typeof a!="number")throw TypeError("Illegal value: "+a+" (not a number)");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return(c+=8)>(p=this.buffer.byteLength)&&this.resize((p*=2)>c?p:c),c-=8,i(this.view,a,c,this.littleEndian,52,8),f&&(this.offset+=8),this},o.writeDouble=o.writeFloat64,o.readFloat64=function(a){var c,p=a===void 0;if(p&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength)}return c=r(this.view,a,this.littleEndian,52,8),p&&(this.offset+=8),c},o.readDouble=o.readFloat64,h.MAX_VARINT32_BYTES=5,h.calculateVarint32=function(a){return(a>>>=0)<128?1:a<16384?2:1<<21>a?3:1<<28>a?4:5},h.zigZagEncode32=function(a){return((a|=0)<<1^a>>31)>>>0},h.zigZagDecode32=function(a){return 0|a>>>1^-(1&a)},o.writeVarint32=function(a,c){var p,f,m,_=c===void 0;if(_&&(c=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a|=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}for((c+=f=h.calculateVarint32(a))>(m=this.buffer.byteLength)&&this.resize((m*=2)>c?m:c),c-=f,a>>>=0;a>=128;)p=128|127&a,this.view[c++]=p,a>>>=7;return this.view[c++]=a,_?(this.offset=c,this):f},o.writeVarint32ZigZag=function(a,c){return this.writeVarint32(h.zigZagEncode32(a),c)},o.readVarint32=function(a){var c,p,f,m,_=a===void 0;if(_&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength)}p=0,f=0;do{if(!this.noAssert&&a>this.limit)throw(m=Error("Truncated")).truncated=!0,m;c=this.view[a++],p<5&&(f|=(127&c)<<7*p),++p}while((128&c)!=0);return f|=0,_?(this.offset=a,f):{value:f,length:p}},o.readVarint32ZigZag=function(a){var c=this.readVarint32(a);return typeof c=="object"?c.value=h.zigZagDecode32(c.value):c=h.zigZagDecode32(c),c},n&&(h.MAX_VARINT64_BYTES=10,h.calculateVarint64=function(a){typeof a=="number"?a=n.fromNumber(a):typeof a=="string"&&(a=n.fromString(a));var c=a.toInt()>>>0,p=a.shiftRightUnsigned(28).toInt()>>>0,f=a.shiftRightUnsigned(56).toInt()>>>0;return f==0?p==0?c<16384?c<128?1:2:1<<21>c?3:4:p<16384?p<128?5:6:1<<21>p?7:8:f<128?9:10},h.zigZagEncode64=function(a){return typeof a=="number"?a=n.fromNumber(a,!1):typeof a=="string"?a=n.fromString(a,!1):a.unsigned!==!1&&(a=a.toSigned()),a.shiftLeft(1).xor(a.shiftRight(63)).toUnsigned()},h.zigZagDecode64=function(a){return typeof a=="number"?a=n.fromNumber(a,!1):typeof a=="string"?a=n.fromString(a,!1):a.unsigned!==!1&&(a=a.toSigned()),a.shiftRightUnsigned(1).xor(a.and(n.ONE).toSigned().negate()).toSigned()},o.writeVarint64=function(a,c){var p,f,m,_,v,R=c===void 0;if(R&&(c=this.offset),!this.noAssert){if(typeof a=="number")a=n.fromNumber(a);else if(typeof a=="string")a=n.fromString(a);else if(!(a&&a instanceof n))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}switch(typeof a=="number"?a=n.fromNumber(a,!1):typeof a=="string"?a=n.fromString(a,!1):a.unsigned!==!1&&(a=a.toSigned()),p=h.calculateVarint64(a),f=a.toInt()>>>0,m=a.shiftRightUnsigned(28).toInt()>>>0,_=a.shiftRightUnsigned(56).toInt()>>>0,(c+=p)>(v=this.buffer.byteLength)&&this.resize((v*=2)>c?v:c),c-=p,p){case 10:this.view[c+9]=1&_>>>7;case 9:this.view[c+8]=p!==9?128|_:127&_;case 8:this.view[c+7]=p!==8?128|m>>>21:127&m>>>21;case 7:this.view[c+6]=p!==7?128|m>>>14:127&m>>>14;case 6:this.view[c+5]=p!==6?128|m>>>7:127&m>>>7;case 5:this.view[c+4]=p!==5?128|m:127&m;case 4:this.view[c+3]=p!==4?128|f>>>21:127&f>>>21;case 3:this.view[c+2]=p!==3?128|f>>>14:127&f>>>14;case 2:this.view[c+1]=p!==2?128|f>>>7:127&f>>>7;case 1:this.view[c]=p!==1?128|f:127&f}return R?(this.offset+=p,this):p},o.writeVarint64ZigZag=function(a,c){return this.writeVarint64(h.zigZagEncode64(a),c)},o.readVarint64=function(a){var c,p,f,m,_,v,R=a===void 0;if(R&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength)}if(c=a,p=0,f=0,m=0,_=0,p=127&(_=this.view[a++]),128&_&&(p|=(127&(_=this.view[a++]))<<7,(128&_||this.noAssert&&_===void 0)&&(p|=(127&(_=this.view[a++]))<<14,(128&_||this.noAssert&&_===void 0)&&(p|=(127&(_=this.view[a++]))<<21,(128&_||this.noAssert&&_===void 0)&&(f=127&(_=this.view[a++]),(128&_||this.noAssert&&_===void 0)&&(f|=(127&(_=this.view[a++]))<<7,(128&_||this.noAssert&&_===void 0)&&(f|=(127&(_=this.view[a++]))<<14,(128&_||this.noAssert&&_===void 0)&&(f|=(127&(_=this.view[a++]))<<21,(128&_||this.noAssert&&_===void 0)&&(m=127&(_=this.view[a++]),(128&_||this.noAssert&&_===void 0)&&(m|=(127&(_=this.view[a++]))<<7,128&_||this.noAssert&&_===void 0))))))))))throw Error("Buffer overrun");return v=n.fromBits(p|f<<28,f>>>4|m<<24,!1),R?(this.offset=a,v):{value:v,length:a-c}},o.readVarint64ZigZag=function(a){var c=this.readVarint64(a);return c&&c.value instanceof n?c.value=h.zigZagDecode64(c.value):c=h.zigZagDecode64(c),c}),o.writeCString=function(a,c){var p,f,m,_=c===void 0;if(_&&(c=this.offset),f=a.length,!this.noAssert){if(typeof a!="string")throw TypeError("Illegal str: Not a string");for(p=0;f>p;++p)if(a.charCodeAt(p)===0)throw RangeError("Illegal str: Contains NULL-characters");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return f=l.calculateUTF16asUTF8(e(a))[1],c+=f+1,m=this.buffer.byteLength,c>m&&this.resize((m*=2)>c?m:c),c-=f+1,l.encodeUTF16toUTF8(e(a),function(v){this.view[c++]=v}.bind(this)),this.view[c++]=0,_?(this.offset=c,this):f},o.readCString=function(a){var c,p,f,m=a===void 0;if(m&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength)}return c=a,f=-1,l.decodeUTF8toUTF16(function(){if(f===0)return null;if(a>=this.limit)throw RangeError("Illegal range: Truncated data, "+a+" < "+this.limit);return(f=this.view[a++])===0?null:f}.bind(this),p=t(),!0),m?(this.offset=a,p()):{string:p(),length:a-c}},o.writeIString=function(a,c){var p,f,m,_=c===void 0;if(_&&(c=this.offset),!this.noAssert){if(typeof a!="string")throw TypeError("Illegal str: Not a string");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}if(f=c,p=l.calculateUTF16asUTF8(e(a),this.noAssert)[1],c+=4+p,m=this.buffer.byteLength,c>m&&this.resize((m*=2)>c?m:c),c-=4+p,this.littleEndian?(this.view[c+3]=255&p>>>24,this.view[c+2]=255&p>>>16,this.view[c+1]=255&p>>>8,this.view[c]=255&p):(this.view[c]=255&p>>>24,this.view[c+1]=255&p>>>16,this.view[c+2]=255&p>>>8,this.view[c+3]=255&p),c+=4,l.encodeUTF16toUTF8(e(a),function(v){this.view[c++]=v}.bind(this)),c!==f+4+p)throw RangeError("Illegal range: Truncated data, "+c+" == "+(c+4+p));return _?(this.offset=c,this):c-f},o.readIString=function(a){var c,p,f,m=a===void 0;if(m&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength)}return c=a,p=this.readUint32(a),f=this.readUTF8String(p,h.METRICS_BYTES,a+=4),a+=f.length,m?(this.offset=a,f.string):{string:f.string,length:a-c}},h.METRICS_CHARS="c",h.METRICS_BYTES="b",o.writeUTF8String=function(a,c){var p,f,m,_=c===void 0;if(_&&(c=this.offset),!this.noAssert){if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}return f=c,p=l.calculateUTF16asUTF8(e(a))[1],c+=p,m=this.buffer.byteLength,c>m&&this.resize((m*=2)>c?m:c),c-=p,l.encodeUTF16toUTF8(e(a),function(v){this.view[c++]=v}.bind(this)),_?(this.offset=c,this):c-f},o.writeString=o.writeUTF8String,h.calculateUTF8Chars=function(a){return l.calculateUTF16asUTF8(e(a))[0]},h.calculateUTF8Bytes=function(a){return l.calculateUTF16asUTF8(e(a))[1]},h.calculateString=h.calculateUTF8Bytes,o.readUTF8String=function(a,c,p){var f,m,_,v,R;if(typeof c=="number"&&(p=c,c=void 0),(f=p===void 0)&&(p=this.offset),c===void 0&&(c=h.METRICS_CHARS),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal length: "+a+" (not an integer)");if(a|=0,typeof p!="number"||p%1!=0)throw TypeError("Illegal offset: "+p+" (not an integer)");if((p>>>=0)<0||p+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+p+" (+0) <= "+this.buffer.byteLength)}if(_=0,v=p,c===h.METRICS_CHARS){if(m=t(),l.decodeUTF8(function(){return a>_&&p>>=0)<0||p+a>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+p+" (+"+a+") <= "+this.buffer.byteLength)}if(R=p+a,l.decodeUTF8toUTF16(function(){return R>p?this.view[p++]:null}.bind(this),m=t(),this.noAssert),p!==R)throw RangeError("Illegal range: Truncated data, "+p+" == "+R);return f?(this.offset=p,m()):{string:m(),length:p-v}}throw TypeError("Unsupported metrics: "+c)},o.readString=o.readUTF8String,o.writeVString=function(a,c){var p,f,m,_,v=c===void 0;if(v&&(c=this.offset),!this.noAssert){if(typeof a!="string")throw TypeError("Illegal str: Not a string");if(typeof c!="number"||c%1!=0)throw TypeError("Illegal offset: "+c+" (not an integer)");if((c>>>=0)<0||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength)}if(m=c,p=l.calculateUTF16asUTF8(e(a),this.noAssert)[1],f=h.calculateVarint32(p),c+=f+p,_=this.buffer.byteLength,c>_&&this.resize((_*=2)>c?_:c),c-=f+p,c+=this.writeVarint32(p,c),l.encodeUTF16toUTF8(e(a),function(R){this.view[c++]=R}.bind(this)),c!==m+p+f)throw RangeError("Illegal range: Truncated data, "+c+" == "+(c+p+f));return v?(this.offset=c,this):c-m},o.readVString=function(a){var c,p,f,m=a===void 0;if(m&&(a=this.offset),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength)}return c=a,p=this.readVarint32(a),f=this.readUTF8String(p.value,h.METRICS_BYTES,a+=p.length),a+=f.length,m?(this.offset=a,f.string):{string:f.string,length:a-c}},o.append=function(a,c,p){var f,m,_;if((typeof c=="number"||typeof c!="string")&&(p=c,c=void 0),(f=p===void 0)&&(p=this.offset),!this.noAssert){if(typeof p!="number"||p%1!=0)throw TypeError("Illegal offset: "+p+" (not an integer)");if((p>>>=0)<0||p+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+p+" (+0) <= "+this.buffer.byteLength)}return a instanceof h||(a=h.wrap(a,c)),(m=a.limit-a.offset)<=0||((p+=m)>(_=this.buffer.byteLength)&&this.resize((_*=2)>p?_:p),p-=m,this.view.set(a.view.subarray(a.offset,a.limit),p),a.offset+=m,f&&(this.offset+=m)),this},o.appendTo=function(a,c){return a.append(this,c),this},o.assert=function(a){return this.noAssert=!a,this},o.capacity=function(){return this.buffer.byteLength},o.clear=function(){return this.offset=0,this.limit=this.buffer.byteLength,this.markedOffset=-1,this},o.clone=function(a){var c=new h(0,this.littleEndian,this.noAssert);return a?(c.buffer=new ArrayBuffer(this.buffer.byteLength),c.view=new Uint8Array(c.buffer)):(c.buffer=this.buffer,c.view=this.view),c.offset=this.offset,c.markedOffset=this.markedOffset,c.limit=this.limit,c},o.compact=function(a,c){var p,f,m;if(a===void 0&&(a=this.offset),c===void 0&&(c=this.limit),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal begin: Not an integer");if(a>>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal end: Not an integer");if(c>>>=0,a<0||a>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+c+" <= "+this.buffer.byteLength)}return a===0&&c===this.buffer.byteLength?this:(p=c-a)==0?(this.buffer=s,this.view=null,this.markedOffset>=0&&(this.markedOffset-=a),this.offset=0,this.limit=0,this):(f=new ArrayBuffer(p),(m=new Uint8Array(f)).set(this.view.subarray(a,c)),this.buffer=f,this.view=m,this.markedOffset>=0&&(this.markedOffset-=a),this.offset=0,this.limit=p,this)},o.copy=function(a,c){if(a===void 0&&(a=this.offset),c===void 0&&(c=this.limit),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal begin: Not an integer");if(a>>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal end: Not an integer");if(c>>>=0,a<0||a>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+c+" <= "+this.buffer.byteLength)}if(a===c)return new h(0,this.littleEndian,this.noAssert);var p=c-a,f=new h(p,this.littleEndian,this.noAssert);return f.offset=0,f.limit=p,f.markedOffset>=0&&(f.markedOffset-=a),this.copyTo(f,0,a,c),f},o.copyTo=function(a,c,p,f){var m,_,v;if(!this.noAssert&&!h.isByteBuffer(a))throw TypeError("Illegal target: Not a ByteBuffer");if(c=(_=c===void 0)?a.offset:0|c,p=(m=p===void 0)?this.offset:0|p,f=f===void 0?this.limit:0|f,c<0||c>a.buffer.byteLength)throw RangeError("Illegal target range: 0 <= "+c+" <= "+a.buffer.byteLength);if(p<0||f>this.buffer.byteLength)throw RangeError("Illegal source range: 0 <= "+p+" <= "+this.buffer.byteLength);return(v=f-p)==0?a:(a.ensureCapacity(c+v),a.view.set(this.view.subarray(p,f),c),m&&(this.offset+=v),_&&(a.offset+=v),this)},o.ensureCapacity=function(a){var c=this.buffer.byteLength;return a>c?this.resize((c*=2)>a?c:a):this},o.fill=function(a,c,p){var f=c===void 0;if(f&&(c=this.offset),typeof a=="string"&&a.length>0&&(a=a.charCodeAt(0)),c===void 0&&(c=this.offset),p===void 0&&(p=this.limit),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal value: "+a+" (not an integer)");if(a|=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal begin: Not an integer");if(c>>>=0,typeof p!="number"||p%1!=0)throw TypeError("Illegal end: Not an integer");if(p>>>=0,c<0||c>p||p>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+c+" <= "+p+" <= "+this.buffer.byteLength)}if(c>=p)return this;for(;p>c;)this.view[c++]=a;return f&&(this.offset=c),this},o.flip=function(){return this.limit=this.offset,this.offset=0,this},o.mark=function(a){if(a=a===void 0?this.offset:a,!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal offset: "+a+" (not an integer)");if((a>>>=0)<0||a+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+0) <= "+this.buffer.byteLength)}return this.markedOffset=a,this},o.order=function(a){if(!this.noAssert&&typeof a!="boolean")throw TypeError("Illegal littleEndian: Not a boolean");return this.littleEndian=!!a,this},o.LE=function(a){return this.littleEndian=a===void 0||!!a,this},o.BE=function(a){return this.littleEndian=a!==void 0&&!a,this},o.prepend=function(a,c,p){var f,m,_,v,R;if((typeof c=="number"||typeof c!="string")&&(p=c,c=void 0),(f=p===void 0)&&(p=this.offset),!this.noAssert){if(typeof p!="number"||p%1!=0)throw TypeError("Illegal offset: "+p+" (not an integer)");if((p>>>=0)<0||p+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+p+" (+0) <= "+this.buffer.byteLength)}return a instanceof h||(a=h.wrap(a,c)),(m=a.limit-a.offset)<=0||((_=m-p)>0?(v=new ArrayBuffer(this.buffer.byteLength+_),(R=new Uint8Array(v)).set(this.view.subarray(p,this.buffer.byteLength),m),this.buffer=v,this.view=R,this.offset+=_,this.markedOffset>=0&&(this.markedOffset+=_),this.limit+=_,p+=_):new Uint8Array(this.buffer),this.view.set(a.view.subarray(a.offset,a.limit),p-m),a.offset=a.limit,f&&(this.offset-=m)),this},o.prependTo=function(a,c){return a.prepend(this,c),this},o.printDebug=function(a){typeof a!="function"&&(a=console.log.bind(console)),a(this.toString()+`
-------------------------------------------------------------------
`+this.toDebug(!0))},o.remaining=function(){return this.limit-this.offset},o.reset=function(){return this.markedOffset>=0?(this.offset=this.markedOffset,this.markedOffset=-1):this.offset=0,this},o.resize=function(a){var c,p;if(!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal capacity: "+a+" (not an integer)");if((a|=0)<0)throw RangeError("Illegal capacity: 0 <= "+a)}return this.buffer.byteLength>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal end: Not an integer");if(c>>>=0,a<0||a>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+c+" <= "+this.buffer.byteLength)}return a===c||Array.prototype.reverse.call(this.view.subarray(a,c)),this},o.skip=function(a){if(!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal length: "+a+" (not an integer)");a|=0}var c=this.offset+a;if(!this.noAssert&&(c<0||c>this.buffer.byteLength))throw RangeError("Illegal length: 0 <= "+this.offset+" + "+a+" <= "+this.buffer.byteLength);return this.offset=c,this},o.slice=function(a,c){if(a===void 0&&(a=this.offset),c===void 0&&(c=this.limit),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal begin: Not an integer");if(a>>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal end: Not an integer");if(c>>>=0,a<0||a>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+c+" <= "+this.buffer.byteLength)}var p=this.clone();return p.offset=a,p.limit=c,p},o.toBuffer=function(a){var c,p=this.offset,f=this.limit;if(!this.noAssert){if(typeof p!="number"||p%1!=0)throw TypeError("Illegal offset: Not an integer");if(p>>>=0,typeof f!="number"||f%1!=0)throw TypeError("Illegal limit: Not an integer");if(f>>>=0,p<0||p>f||f>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+p+" <= "+f+" <= "+this.buffer.byteLength)}return a||p!==0||f!==this.buffer.byteLength?p===f?s:(c=new ArrayBuffer(f-p),new Uint8Array(c).set(new Uint8Array(this.buffer).subarray(p,f),0),c):this.buffer},o.toArrayBuffer=o.toBuffer,o.toString=function(a,c,p){if(a===void 0)return"ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";switch(typeof a=="number"&&(p=c=a="utf8"),a){case"utf8":return this.toUTF8(c,p);case"base64":return this.toBase64(c,p);case"hex":return this.toHex(c,p);case"binary":return this.toBinary(c,p);case"debug":return this.toDebug();case"columns":return this.toColumns();default:throw Error("Unsupported encoding: "+a)}},d=function(){var a,c,p={},f=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47],m=[];for(a=0,c=f.length;c>a;++a)m[f[a]]=a;return p.encode=function(_,v){for(var R,y;(R=_())!==null;)v(f[63&R>>2]),y=(3&R)<<4,(R=_())!==null?(v(f[63&((y|=15&R>>4)|15&R>>4)]),y=(15&R)<<2,(R=_())!==null?(v(f[63&(y|3&R>>6)]),v(f[63&R])):(v(f[63&y]),v(61))):(v(f[63&y]),v(61),v(61))},p.decode=function(_,v){function R(N){throw Error("Illegal character code: "+N)}for(var y,P,L;(y=_())!==null;)if((P=m[y])===void 0&&R(y),(y=_())!==null&&((L=m[y])===void 0&&R(y),v(P<<2>>>0|(48&L)>>4),(y=_())!==null)){if((P=m[y])===void 0){if(y===61)break;R(y)}if(v((15&L)<<4>>>0|(60&P)>>2),(y=_())!==null){if((L=m[y])===void 0){if(y===61)break;R(y)}v((3&P)<<6>>>0|L)}}},p.test=function(_){return/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(_)},p}(),o.toBase64=function(a,c){if(a===void 0&&(a=this.offset),c===void 0&&(c=this.limit),c|=0,(a|=0)<0||c>this.capacity||a>c)throw RangeError("begin, end");var p;return d.encode(function(){return c>a?this.view[a++]:null}.bind(this),p=t()),p()},h.fromBase64=function(a,c){if(typeof a!="string")throw TypeError("str");var p=new h(a.length/4*3,c),f=0;return d.decode(e(a),function(m){p.view[f++]=m}),p.limit=f,p},h.btoa=function(a){return h.fromBinary(a).toBase64()},h.atob=function(a){return h.fromBase64(a).toBinary()},o.toBinary=function(a,c){if(a===void 0&&(a=this.offset),c===void 0&&(c=this.limit),c|=0,(a|=0)<0||c>this.capacity()||a>c)throw RangeError("begin, end");if(a===c)return"";for(var p=[],f=[];c>a;)p.push(this.view[a++]),p.length>=1024&&(f.push(String.fromCharCode.apply(String,p)),p=[]);return f.join("")+String.fromCharCode.apply(String,p)},h.fromBinary=function(a,c){if(typeof a!="string")throw TypeError("str");for(var p,f=0,m=a.length,_=new h(m,c);m>f;){if((p=a.charCodeAt(f))>255)throw RangeError("illegal char code: "+p);_.view[f++]=p}return _.limit=m,_},o.toDebug=function(a){for(var c,p=-1,f=this.buffer.byteLength,m="",_="",v="";f>p;){if(p!==-1&&(m+=(c=this.view[p])<16?"0"+c.toString(16).toUpperCase():c.toString(16).toUpperCase(),a&&(_+=c>32&&c<127?String.fromCharCode(c):".")),++p,a&&p>0&&p%16==0&&p!==f){for(;m.length<51;)m+=" ";v+=m+_+`
`,m=_=""}m+=p===this.offset&&p===this.limit?p===this.markedOffset?"!":"|":p===this.offset?p===this.markedOffset?"[":"<":p===this.limit?p===this.markedOffset?"]":">":p===this.markedOffset?"'":a||p!==0&&p!==f?" ":""}if(a&&m!==" "){for(;m.length<51;)m+=" ";v+=m+_+`
`}return a?v:m},h.fromDebug=function(a,c,p){for(var f,m,_=a.length,v=new h(0|(_+1)/3,c,p),R=0,y=0,P=!1,L=!1,N=!1,E=!1,A=!1;_>R;){switch(f=a.charAt(R++)){case"!":if(!p){if(L||N||E){A=!0;break}L=N=E=!0}v.offset=v.markedOffset=v.limit=y,P=!1;break;case"|":if(!p){if(L||E){A=!0;break}L=E=!0}v.offset=v.limit=y,P=!1;break;case"[":if(!p){if(L||N){A=!0;break}L=N=!0}v.offset=v.markedOffset=y,P=!1;break;case"<":if(!p){if(L){A=!0;break}L=!0}v.offset=y,P=!1;break;case"]":if(!p){if(E||N){A=!0;break}E=N=!0}v.limit=v.markedOffset=y,P=!1;break;case">":if(!p){if(E){A=!0;break}E=!0}v.limit=y,P=!1;break;case"'":if(!p){if(N){A=!0;break}N=!0}v.markedOffset=y,P=!1;break;case" ":P=!1;break;default:if(!p&&P){A=!0;break}if(m=parseInt(f+a.charAt(R++),16),!p&&(isNaN(m)||m<0||m>255))throw TypeError("Illegal str: Not a debug encoded string");v.view[y++]=m,P=!0}if(A)throw TypeError("Illegal str: Invalid symbol at "+R)}if(!p){if(!L||!E)throw TypeError("Illegal str: Missing offset or limit");if(y>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal end: Not an integer");if(c>>>=0,a<0||a>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+c+" <= "+this.buffer.byteLength)}for(var p,f=new Array(c-a);c>a;)(p=this.view[a++])<16?f.push("0",p.toString(16)):f.push(p.toString(16));return f.join("")},h.fromHex=function(a,c,p){var f,m,_,v,R;if(!p){if(typeof a!="string")throw TypeError("Illegal str: Not a string");if(a.length%2!=0)throw TypeError("Illegal str: Length not a multiple of 2")}for(m=a.length,_=new h(0|m/2,c),v=0,R=0;m>v;v+=2){if(f=parseInt(a.substring(v,v+2),16),!p&&(!isFinite(f)||f<0||f>255))throw TypeError("Illegal str: Contains non-hex characters");_.view[R++]=f}return _.limit=R,_},l=function(){var a={MAX_CODEPOINT:1114111,encodeUTF8:function(c,p){var f=null;for(typeof c=="number"&&(f=c,c=function(){return null});f!==null||(f=c())!==null;)f<128?p(127&f):f<2048?(p(192|31&f>>6),p(128|63&f)):f<65536?(p(224|15&f>>12),p(128|63&f>>6),p(128|63&f)):(p(240|7&f>>18),p(128|63&f>>12),p(128|63&f>>6),p(128|63&f)),f=null},decodeUTF8:function(c,p){for(var f,m,_,v,R=function(y){y=y.slice(0,y.indexOf(null));var P=Error(y.toString());throw P.name="TruncatedError",P.bytes=y,P};(f=c())!==null;)if((128&f)==0)p(f);else if((224&f)==192)(m=c())===null&&R([f,m]),p((31&f)<<6|63&m);else if((240&f)==224)((m=c())===null||(_=c())===null)&&R([f,m,_]),p((15&f)<<12|(63&m)<<6|63&_);else{if((248&f)!=240)throw RangeError("Illegal starting byte: "+f);((m=c())===null||(_=c())===null||(v=c())===null)&&R([f,m,_,v]),p((7&f)<<18|(63&m)<<12|(63&_)<<6|63&v)}},UTF16toUTF8:function(c,p){for(var f,m=null;(f=m!==null?m:c())!==null;)f>=55296&&f<=57343&&(m=c())!==null&&m>=56320&&m<=57343?(p(1024*(f-55296)+m-56320+65536),m=null):p(f);m!==null&&p(m)},UTF8toUTF16:function(c,p){var f=null;for(typeof c=="number"&&(f=c,c=function(){return null});f!==null||(f=c())!==null;)f<=65535?p(f):(p(55296+((f-=65536)>>10)),p(f%1024+56320)),f=null},encodeUTF16toUTF8:function(c,p){a.UTF16toUTF8(c,function(f){a.encodeUTF8(f,p)})},decodeUTF8toUTF16:function(c,p){a.decodeUTF8(c,function(f){a.UTF8toUTF16(f,p)})},calculateCodePoint:function(c){return c<128?1:c<2048?2:c<65536?3:4},calculateUTF8:function(c){for(var p,f=0;(p=c())!==null;)f+=p<128?1:p<2048?2:p<65536?3:4;return f},calculateUTF16asUTF8:function(c){var p=0,f=0;return a.UTF16toUTF8(c,function(m){++p,f+=m<128?1:m<2048?2:m<65536?3:4}),[p,f]}};return a}(),o.toUTF8=function(a,c){if(a===void 0&&(a=this.offset),c===void 0&&(c=this.limit),!this.noAssert){if(typeof a!="number"||a%1!=0)throw TypeError("Illegal begin: Not an integer");if(a>>>=0,typeof c!="number"||c%1!=0)throw TypeError("Illegal end: Not an integer");if(c>>>=0,a<0||a>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+c+" <= "+this.buffer.byteLength)}var p;try{l.decodeUTF8toUTF16(function(){return c>a?this.view[a++]:null}.bind(this),p=t())}catch{if(a!==c)throw RangeError("Illegal range: Truncated data, "+a+" != "+c)}return p()},h.fromUTF8=function(a,c,p){if(!p&&typeof a!="string")throw TypeError("Illegal str: Not a string");var f=new h(l.calculateUTF16asUTF8(e(a),!0)[1],c,p),m=0;return l.encodeUTF16toUTF8(e(a),function(_){f.view[m++]=_}),f.limit=m,f},h}(Cs=function(){function n(E,A,F){this.low=0|E,this.high=0|A,this.unsigned=!!F}function e(E){return(E&&E.__isLong__)===!0}function t(E,A){var F,q,C;return A?(C=(E>>>=0)>=0&&E<256)&&(q=d[E])?q:(F=i(E,(0|E)<0?-1:0,!0),C&&(d[E]=F),F):(C=(E|=0)>=-128&&E<128)&&(q=u[E])?q:(F=i(E,E<0?-1:0,!1),C&&(u[E]=F),F)}function r(E,A){if(isNaN(E)||!isFinite(E))return A?m:f;if(A){if(E<0)return m;if(E>=a)return P}else{if(-c>=E)return L;if(E+1>=c)return y}return E<0?r(-E,A).neg():i(0|E%h,0|E/h,A)}function i(E,A,F){return new n(E,A,F)}function o(E,A,F){var q,C,T,S,O,I,U;if(E.length===0)throw Error("empty string");if(E==="NaN"||E==="Infinity"||E==="+Infinity"||E==="-Infinity")return f;if(typeof A=="number"?(F=A,A=!1):A=!!A,(F=F||10)<2||F>36)throw RangeError("radix");if((q=E.indexOf("-"))>0)throw Error("interior hyphen");if(q===0)return o(E.substring(1),A,F).neg();for(C=r(l(F,8)),T=f,S=0;S>>0:this.low},N.toNumber=function(){return this.unsigned?(this.high>>>0)*h+(this.low>>>0):this.high*h+(this.low>>>0)},N.toString=function(E){var A,F,q,C,T,S,O,I;if((E=E||10)<2||E>36)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())return this.eq(L)?(A=r(E),q=(F=this.div(A)).mul(A).sub(this),F.toString(E)+q.toInt().toString(E)):"-"+this.neg().toString(E);for(C=r(l(E,6),this.unsigned),T=this,S="";;){if(O=T.div(C),I=(T.sub(O.mul(C)).toInt()>>>0).toString(E),(T=O).isZero())return I+S;for(;I.length<6;)I="0"+I;S=""+I+S}},N.getHighBits=function(){return this.high},N.getHighBitsUnsigned=function(){return this.high>>>0},N.getLowBits=function(){return this.low},N.getLowBitsUnsigned=function(){return this.low>>>0},N.getNumBitsAbs=function(){var E,A;if(this.isNegative())return this.eq(L)?64:this.neg().getNumBitsAbs();for(E=this.high!=0?this.high:this.low,A=31;A>0&&(E&1<=0},N.isOdd=function(){return(1&this.low)==1},N.isEven=function(){return(1&this.low)==0},N.equals=function(E){return e(E)||(E=s(E)),(this.unsigned===E.unsigned||this.high>>>31!=1||E.high>>>31!=1)&&this.high===E.high&&this.low===E.low},N.eq=N.equals,N.notEquals=function(E){return!this.eq(E)},N.neq=N.notEquals,N.lessThan=function(E){return this.comp(E)<0},N.lt=N.lessThan,N.lessThanOrEqual=function(E){return this.comp(E)<=0},N.lte=N.lessThanOrEqual,N.greaterThan=function(E){return this.comp(E)>0},N.gt=N.greaterThan,N.greaterThanOrEqual=function(E){return this.comp(E)>=0},N.gte=N.greaterThanOrEqual,N.compare=function(E){if(e(E)||(E=s(E)),this.eq(E))return 0;var A=this.isNegative(),F=E.isNegative();return A&&!F?-1:!A&&F?1:this.unsigned?E.high>>>0>this.high>>>0||E.high===this.high&&E.low>>>0>this.low>>>0?-1:1:this.sub(E).isNegative()?-1:1},N.comp=N.compare,N.negate=function(){return!this.unsigned&&this.eq(L)?L:this.not().add(_)},N.neg=N.negate,N.add=function(E){var A,F,q,C,T,S,O,I,U,D,$;return e(E)||(E=s(E)),A=this.high>>>16,F=65535&this.high,q=this.low>>>16,C=65535&this.low,T=E.high>>>16,S=65535&E.high,O=E.low>>>16,I=0,U=0,D=0,$=0,D+=($+=C+(65535&E.low))>>>16,U+=(D+=q+O)>>>16,I+=(U+=F+S)>>>16,I+=A+T,i((D&=65535)<<16|($&=65535),(I&=65535)<<16|(U&=65535),this.unsigned)},N.subtract=function(E){return e(E)||(E=s(E)),this.add(E.neg())},N.sub=N.subtract,N.multiply=function(E){var A,F,q,C,T,S,O,I,U,D,$,j;return this.isZero()?f:(e(E)||(E=s(E)),E.isZero()?f:this.eq(L)?E.isOdd()?L:f:E.eq(L)?this.isOdd()?L:f:this.isNegative()?E.isNegative()?this.neg().mul(E.neg()):this.neg().mul(E).neg():E.isNegative()?this.mul(E.neg()).neg():this.lt(p)&&E.lt(p)?r(this.toNumber()*E.toNumber(),this.unsigned):(A=this.high>>>16,F=65535&this.high,q=this.low>>>16,C=65535&this.low,T=E.high>>>16,S=65535&E.high,O=E.low>>>16,U=0,D=0,$=0,j=0,$+=(j+=C*(I=65535&E.low))>>>16,D+=($+=q*I)>>>16,$&=65535,D+=($+=C*O)>>>16,U+=(D+=F*I)>>>16,D&=65535,U+=(D+=q*O)>>>16,D&=65535,U+=(D+=C*S)>>>16,U+=A*I+F*O+q*S+C*T,i(($&=65535)<<16|(j&=65535),(U&=65535)<<16|(D&=65535),this.unsigned)))},N.mul=N.multiply,N.divide=function(E){var A,F,q,C,T,S,O;if(e(E)||(E=s(E)),E.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?m:f;if(this.unsigned){if(E.unsigned||(E=E.toUnsigned()),E.gt(this))return m;if(E.gt(this.shru(1)))return v;q=m}else{if(this.eq(L))return E.eq(_)||E.eq(R)?L:E.eq(L)?_:(A=this.shr(1).div(E).shl(1)).eq(f)?E.isNegative()?_:R:(F=this.sub(E.mul(A)),q=A.add(F.div(E)));if(E.eq(L))return this.unsigned?m:f;if(this.isNegative())return E.isNegative()?this.neg().div(E.neg()):this.neg().div(E).neg();if(E.isNegative())return this.div(E.neg()).neg();q=f}for(F=this;F.gte(E);){for(A=Math.max(1,Math.floor(F.toNumber()/E.toNumber())),T=(C=Math.ceil(Math.log(A)/Math.LN2))<=48?1:l(2,C-48),O=(S=r(A)).mul(E);O.isNegative()||O.gt(F);)O=(S=r(A-=T,this.unsigned)).mul(E);S.isZero()&&(S=_),q=q.add(S),F=F.sub(O)}return q},N.div=N.divide,N.modulo=function(E){return e(E)||(E=s(E)),this.sub(this.div(E).mul(E))},N.mod=N.modulo,N.not=function(){return i(~this.low,~this.high,this.unsigned)},N.and=function(E){return e(E)||(E=s(E)),i(this.low&E.low,this.high&E.high,this.unsigned)},N.or=function(E){return e(E)||(E=s(E)),i(this.low|E.low,this.high|E.high,this.unsigned)},N.xor=function(E){return e(E)||(E=s(E)),i(this.low^E.low,this.high^E.high,this.unsigned)},N.shiftLeft=function(E){return e(E)&&(E=E.toInt()),(E&=63)==0?this:E<32?i(this.low<>>32-E,this.unsigned):i(0,this.low<>>E|this.high<<32-E,this.high>>E,this.unsigned):i(this.high>>E-32,this.high>=0?0:-1,this.unsigned)},N.shr=N.shiftRight,N.shiftRightUnsigned=function(E){var A;return e(E)&&(E=E.toInt()),(E&=63)==0?this:(A=this.high,E<32?i(this.low>>>E|A<<32-E,A>>>E,this.unsigned):i(E===32?A:A>>>E-32,0,this.unsigned))},N.shru=N.shiftRightUnsigned,N.toSigned=function(){return this.unsigned?i(this.low,this.high,!1):this},N.toUnsigned=function(){return this.unsigned?this:i(this.low,this.high,!0)},N.toBytes=function(E){return E?this.toBytesLE():this.toBytesBE()},N.toBytesLE=function(){var E=this.high,A=this.low;return[255&A,255&A>>>8,255&A>>>16,255&A>>>24,255&E,255&E>>>8,255&E>>>16,255&E>>>24]},N.toBytesBE=function(){var E=this.high,A=this.low;return[255&E>>>24,255&E>>>16,255&E>>>8,255&E,255&A>>>24,255&A>>>16,255&A>>>8,255&A]},n}()),Cs));Ti.getModule=function(n){var e=new Ti[n];return e.getArrayData=function(){var t=e.toArrayBuffer();return t=ba(t)?[].slice.call(new Int8Array(t)):t},e};var Si,Zu="pgMsgP",Qu="chatMsg",Xu="pcMsgP",ed={PRIVATE:"ppMsgS",GROUP:"pgMsgS",CHATROOM:"chatMsgS"},td="delMsg",nd="joinChrm",rd="joinChrmR",id="exitChrm",od="setKV",sd="delKV",ad="setKVS",cd="delKVS",ys="qryRelationR",ud="delRelation",dd="setSeAtt",xn={PRIVATE:"cleanPMsg",GROUP:"cleanGMsg",CUSTOMER_SERVICE:"cleanCMsg",SYSTEM:"cleanSMsg"},Fa="qryPMsg",ld="qryGMsg",$a="qryCHMsg",hd="qryCMsg",pd="qrySMsg",fd=((Qt={}).ppMsgP=ee.PRIVATE,Qt[Zu]=ee.GROUP,Qt[Qu]=ee.CHATROOM,Qt[Xu]=ee.CUSTOMER_SERVICE,Qt),gd=((kt={})[ee.PRIVATE]=Fa,kt[ee.GROUP]=ld,kt[ee.CHATROOM]=$a,kt[ee.CUSTOMER_SERVICE]=hd,kt[ee.SYSTEM]=pd,kt),md=((Xt={})[ee.PRIVATE]=xn.PRIVATE,Xt[ee.GROUP]=xn.GROUP,Xt[ee.CUSTOMER_SERVICE]=xn.CUSTOMER_SERVICE,Xt[ee.SYSTEM]=xn.SYSTEM,Xt),Jr="1",_d="0",Es=1,Ts=2,Ss=3,vd=function(){function n(e){this._codec=e==="websocket"?Ti:Tn,this._connectType=e}return n.prototype.decodeByPBName=function(e,t,r){var i,o=this,s=e,u=((i={})[Cn]=o._formatSyncMessages,i[wr]=o._formatReceivedMessage,i[Rn]=o._formatSentMessage,i[yn]=o._formatHistoryMessages,i[En]=o._formatConversationList,i[Mr]=o._formatChatRoomInfos,i[It]=o._formatRTCUserList,i[Pr]=o._formatRTCData,i[Ft]=o._formatChatRoomKVList,i[Lr]=o._formatUserSetting,i[Dr]=o._formatConversationStatus,i[Ur]=o._formatGrpReadReceiptQryResp,i[$t]=o._formatSetUserSettingOutput,i[kr]=o._formatUserSettingNotification,i[xr]=o._formatRTCRoomKVList,i[Ar]=o._formatRTCAuidenceJoinRoomData,i[Vr]=o._formatRTCJoinedUserInfo,i)[t];try{s=e.length>0&&o._codec[t].decode(e),Ne(s)&&(s=function(d){for(var l in d)Ne(d[l])&&(d[l]=$e(d[l]));return d}(s)),sr(u)&&(s=u.call(this,s,r))}catch(d){G.error(`PB parse error
`,d,e,t)}return s},n.prototype._readBytes=function(e){var t=e.offset,r=e.buffer,i=e.limit;if(t)try{var o=ba(r)?new Uint8Array(r):r;return Nn.readUTF(o.subarray(t,i))}catch(s){G.info(`readBytes error
`,s)}return e},n.prototype._formatBytes=function(e){var t=this._readBytes(e);try{t=JSON.parse(t)}catch(r){G.info(`formatBytes error
`,r)}return t||e},n.prototype._formatSyncMessages=function(e,t){t=t||{};var r=this,i=e.list,o=e.syncTime,s=e.finished;return(le(s)||s===null)&&(e.finished=!0),e.syncTime=$e(o),e.list=Un(i,function(u){return r._formatReceivedMessage(u,t)}),e},n.prototype._formatReceivedMessage=function(e,t){var r=(t=t||{}).currentUserId,i=t.connectedTime,o=e.content,s=e.fromUserId,u=e.type,d=e.groupId,l=e.status,h=e.dataTime,a=e.classname,c=e.msgId,p=e.extraContent,f=e.pushContent,m=e.pushExt,_=e.configFlag,v=(e.direction||je.RECEIVE)===je.SEND,R=function(W){var Z=_n.READ;return{isPersited:!!(16&W),isCounted:!!(32&W),isMentioned:!!(64&W),disableNotification:!!(512&W),receivedStatus:Z=2&W?_n.RETRIEVED:Z,canIncludeExpansion:!!(1024&W)}}(l),y=R.isPersited,P=R.isCounted,L=R.isMentioned,N=R.disableNotification,E=R.receivedStatus,A=R.canIncludeExpansion,F=[ee.GROUP,ee.CHATROOM,ee.RTC_ROOM].indexOf(u)>-1?d:s,q=v?r:s,C=$e(h),T=C "+s),this.timestamp=t.readLong()}return{stream:t,length:r}},e.MESSAGE_LENGTH=2,e}(wn),$o=function(n){function e(){var t=n!==null&&n.apply(this,arguments)||this;return t._name=Fe.DISCONNECT,t.status=0,t}return Re(e,n),e.prototype.readMessage=function(t,r){return t.readByte(),this.status=+t.readByte(),{stream:t,length:r}},e.MESSAGE_LENGTH=2,e}(wn),Rd=function(n){function e(){var t=n.call(this,Me.PING_REQ)||this;return t._name=Fe.PING_REQ,t}return Re(e,n),e.prototype.writeMessage=function(t){},e}(Ka),Ga=function(n){function e(t){var r=n.call(this,t)||this;return r._name=Fe.PING_RESP,r}return Re(e,n),e}(wn),Ho=function(n){function e(){var t=n!==null&&n.apply(this,arguments)||this;return t.messageId=0,t}return Re(e,n),e.prototype.readMessage=function(t,r){var i=256*t.readByte()+t.readByte();return this.messageId=parseInt(i.toString(),10),{stream:t,length:r}},e}(wn),Br=function(n){function e(){var t=n!==null&&n.apply(this,arguments)||this;return t.messageId=0,t}return Re(e,n),e.prototype.writeMessage=function(t){var r=this.messageId,i=255&r,o=(65280&r)>>8;t.write(o),t.write(i)},e}(Ka),Sn=function(n){function e(){var t=n!==null&&n.apply(this,arguments)||this;return t._name=Fe.PUBLISH,t.topic="",t.targetId="",t.syncMsg=!1,t.identifier=Nt.PUB,t}return Re(e,n),e.prototype.readMessage=function(t,r){return this.date=t.readInt(),this.topic=t.readUTF(),this.targetId=t.readUTF(),n.prototype.readMessage.call(this,t,r),this.data=t.readAll(),{stream:t,length:r}},e}(Ho),en=function(n){function e(t,r,i){var o=n.call(this,Me.PUBLISH)||this;return o._name=Fe.PUBLISH,o.syncMsg=!1,o.identifier=Nt.PUB,o.topic=t,o.data=Be(r)?Nn.writeUTF(r):r,o.targetId=i,o}return Re(e,n),e.prototype.writeMessage=function(t){t.writeUTF(this.topic),t.writeUTF(this.targetId),n.prototype.writeMessage.call(this,t),t.write(this.data)},e}(Br),Ii=function(n){function e(){var t=n!==null&&n.apply(this,arguments)||this;return t._name=Fe.PUB_ACK,t.status=0,t.date=0,t.millisecond=0,t.messageUId="",t.timestamp=0,t.identifier=Nt.PUB,t.topic="",t.targetId="",t}return Re(e,n),e.prototype.readMessage=function(t,r){return n.prototype.readMessage.call(this,t,r),this.date=t.readInt(),this.status=256*t.readByte()+t.readByte(),this.millisecond=256*t.readByte()+t.readByte(),this.timestamp=1e3*this.date+this.millisecond,this.messageUId=t.readUTF(),{stream:t,length:r}},e}(Ho),Ya=function(n){function e(t){var r=n.call(this,Me.PUB_ACK)||this;return r._name=Fe.PUB_ACK,r.status=0,r.date=0,r.millisecond=0,r.messageUId="",r.timestamp=0,r.messageId=t,r}return Re(e,n),e.prototype.writeMessage=function(t){n.prototype.writeMessage.call(this,t)},e}(Br),te=function(n){function e(t,r,i){var o=n.call(this,Me.QUERY)||this;return o.name=Fe.QUERY,o.identifier=Nt.QUERY,o.topic=t,o.data=Be(r)?Nn.writeUTF(r):r,o.targetId=i,o}return Re(e,n),e.prototype.writeMessage=function(t){t.writeUTF(this.topic),t.writeUTF(this.targetId),n.prototype.writeMessage.call(this,t),t.write(this.data)},e}(Br),za=function(n){function e(t){var r=n.call(this,Me.QUERY_CONFIRM)||this;return r._name=Fe.QUERY_CON,r.messageId=t,r}return Re(e,n),e}(Br),fn=function(n){function e(){var t=n!==null&&n.apply(this,arguments)||this;return t._name=Fe.QUERY_ACK,t.status=0,t.identifier=Nt.QUERY,t.topic="",t.targetId="",t}return Re(e,n),e.prototype.readMessage=function(t,r){return n.prototype.readMessage.call(this,t,r),this.date=t.readInt(),this.status=256*t.readByte()+t.readByte(),this.data=t.readAll(),{stream:t,length:r}},e}(Ho),Ja=function(n){var e,t=n.type;switch(t){case Me.CONN_ACK:e=new qa(n);break;case Me.PUBLISH:(e=new Sn(n)).syncMsg=n.syncMsg;break;case Me.PUB_ACK:e=new Ii(n);break;case Me.QUERY_ACK:e=new fn(n);break;case Me.SUB_ACK:case Me.UNSUB_ACK:case Me.PING_RESP:e=new Ga(n);break;case Me.DISCONNECT:e=new $o(n);break;default:e=new wn(n),G.error("No support for deserializing "+t+" messages")}return e};(function(n){n[n.ppMsgP=1]="ppMsgP",n[n.ppMsgN=2]="ppMsgN",n[n.ppMsgS=3]="ppMsgS",n[n.pgMsgP=4]="pgMsgP",n[n.chatMsg=5]="chatMsg",n[n.pcMsgP=6]="pcMsgP",n[n.qryPMsg=7]="qryPMsg",n[n.qryGMsg=8]="qryGMsg",n[n.qryCHMsg=9]="qryCHMsg",n[n.qryCMsg=10]="qryCMsg",n[n.qrySMsg=11]="qrySMsg",n[n.recallMsg=12]="recallMsg",n[n.prMsgS=13]="prMsgS",n[n.rrMsg=14]="rrMsg",n[n.rrList=15]="rrList",n[n.s_ntf=16]="s_ntf",n[n.s_msg=17]="s_msg",n[n.s_stat=18]="s_stat",n[n.s_cmd=19]="s_cmd",n[n.s_us=20]="s_us",n[n.pullUS=21]="pullUS",n[n.pgMsgS=22]="pgMsgS",n[n.chatMsgS=23]="chatMsgS",n[n.qrySessionsAtt=24]="qrySessionsAtt",n[n.pullMsg=25]="pullMsg",n[n.qrySessions=26]="qrySessions",n[n.delSessions=27]="delSessions",n[n.delMsg=28]="delMsg",n[n.updRRTime=29]="updRRTime",n[n.chrmPull=30]="chrmPull",n[n.joinChrm=31]="joinChrm",n[n.joinChrmR=32]="joinChrmR",n[n.exitChrm=33]="exitChrm",n[n.queryChrmI=34]="queryChrmI",n[n.setKV=35]="setKV",n[n.delKV=36]="delKV",n[n.pullKV=37]="pullKV",n[n.qryRelation=38]="qryRelation",n[n.delRelation=39]="delRelation",n[n.pullSeAtts=40]="pullSeAtts",n[n.setSeAtt=41]="setSeAtt",n[n.qnTkn=42]="qnTkn",n[n.qnUrl=43]="qnUrl",n[n.aliUrl=44]="aliUrl",n[n.s3Url=45]="s3Url",n[n.stcUrl=46]="stcUrl",n[n.cleanPMsg=47]="cleanPMsg",n[n.cleanGMsg=48]="cleanGMsg",n[n.cleanCMsg=49]="cleanCMsg",n[n.cleanSMsg=50]="cleanSMsg",n[n.rtcRJoin_data=51]="rtcRJoin_data",n[n.rtcRExit=52]="rtcRExit",n[n.rtcPing=53]="rtcPing",n[n.rtcSetData=54]="rtcSetData",n[n.rtc_ntf=55]="rtc_ntf",n[n.viewerJoinR=56]="viewerJoinR",n[n.viewerExitR=57]="viewerExitR",n[n.rtcPullKv=58]="rtcPullKv",n[n.rtcIdentityChange=59]="rtcIdentityChange",n[n.userSetData=60]="userSetData",n[n.rtcQryData=61]="rtcQryData",n[n.rtcDelData=62]="rtcDelData",n[n.rtcSetOutData=63]="rtcSetOutData",n[n.rtcQryUserOutData=64]="rtcQryUserOutData",n[n.rtcToken=65]="rtcToken",n[n.rtcUserState=66]="rtcUserState",n[n.rtcRInfo=67]="rtcRInfo",n[n.rtcUData=68]="rtcUData",n[n.rtcUPut=69]="rtcUPut",n[n.rtcUDel=70]="rtcUDel",n[n.rtcUList=71]="rtcUList",n[n.rtcQueryJoined=72]="rtcQueryJoined",n[n.addSeTag=73]="addSeTag",n[n.delSeTag=74]="delSeTag",n[n.addTag=75]="addTag",n[n.delTag=76]="delTag",n[n.disTag=77]="disTag",n[n.reportsdk=78]="reportsdk",n[n.rtcInvite=79]="rtcInvite",n[n.rtcCancelInvite=80]="rtcCancelInvite",n[n.rtcInviteAnswer=81]="rtcInviteAnswer",n[n.rtcEndInvite=82]="rtcEndInvite"})(Si||(Si={}));var We,x=Si,Wa=function(n,e,t,r){return V(void 0,void 0,void 0,function(){var i;return B(this,function(o){return i=0,n.forEach(function(s){return V(void 0,void 0,void 0,function(){var u,d;return B(this,function(l){switch(l.label){case 0:return u=e+"://"+s+"/ping?r="+(a=9999,(h=1e3)+Math.floor(Math.random()*(a-h))),G.debug("start ping",u),[4,t.httpReq({url:u,timeout:5e3})];case 1:return d=l.sent(),G.debug("end ping",i,u,d.status),i++,r({finished:i===n.length,code:d.status,host:s}),[2]}var h,a})})}),[2]})})},Za=function(n,e,t,r,i,o,s,u){return n+"://"+e+"/websocket?appId="+t+"&token="+encodeURIComponent(r)+"&sdkVer="+o+"&pid="+s+"&apiVer="+(i.isFromUniapp?"uniapp":"normal")+(i.connectPlatform?"&platform="+i.connectPlatform:"")+(u?"&protocolVer="+u:"")},Qa=function(n){return[x.ppMsgS,x.pgMsgS,x.chatMsgS].map(function(e){return x[e]}).indexOf(n)>=0};(function(n){n[n.REDIRECT=0]="REDIRECT",n[n.OTHER_DEVICE_LOGIN=1]="OTHER_DEVICE_LOGIN",n[n.BLOCK=2]="BLOCK",n[n.REMOTE_CLOSE=3]="REMOTE_CLOSE",n[n.LOGOUT=4]="LOGOUT",n[n.BLOCK_NEW=5]="BLOCK_NEW",n[n.REDIRECT_NEW=6]="REDIRECT_NEW"})(We||(We={}));var Ze,Is=function(n,e){G.info("websocket send -> messageId: "+n.messageId);var t=n.getBufferData();e.send(t.buffer)},Yt=function(n){function e(t,r){var i=n.call(this,"websocket",r)||this;return i._runtime=t,i._socket=null,i._messageIds={},i._syncMessageIds={},i._failedCount=0,i.ALLOW_FAILED_TIMES=2,i._timer=null,i._idCount=0,i._generateMessageId=function(){return i._idCount>=65535&&(i._idCount=0),++i._idCount},i}return Re(e,n),e.prototype.connect=function(t,r,i,o,s,u){return V(this,void 0,void 0,function(){var d=this;return B(this,function(l){return[2,new Promise(function(h){var a=[],c=0,p=!1,f=!1,m=function(){return V(d,void 0,void 0,function(){var _;return B(this,function(v){switch(v.label){case 0:return a.length===0||p?[2]:(p=!0,[4,this._connect(t,r,a.shift(),o,s,u)]);case 1:if((_=v.sent())===b.SUCCESS)this._checkAlive(),h(_);else if(_===we.REDIRECT)h(_);else{if(f&&a.length===0)return h(Oa(_)),[2];p=!1,m()}return[2]}})})};s=qi(s),d._watcher.status(se.CONNECTING),Wa(i,o,d._runtime,function(_){var v=_.code,R=_.finished,y=_.host;f=R,v===200&&(a.push(y),c++,m()),R&&c===0&&(G.error("No valid websocket server hosts!"),h(b.RC_SOCKET_NOT_CREATED))})})]})})},e.prototype._connect=function(t,r,i,o,s,u){return V(this,void 0,void 0,function(){var d,l,h,a,c,p=this;return B(this,function(f){switch(f.label){case 0:return d=o.replace("http","ws"),l=Za(d,i,t,r,this._runtime,s,"",u),G.debug("conenct start -> "+l),this.sendConnectTime=Date.now(),h=this._runtime.createWebSocket(l),a=function(m){p._timer&&(clearTimeout(p._timer),p._timer=null),p._socket===h&&(p._socket=null,p._watcher.status(m))},[4,new Promise(function(m){h.onMessage(function(_){if(Object.prototype.toString.call(_)==="[object ArrayBuffer]"){var v=function(y,P){var L=new Uint8Array(y),N=new Gu(L),E=N.readByte(),A=new zi(E),F=Ja(A);return F.read(N,L.length-1,P),F}(_,u);if(v instanceof Ga&&p._pingResolve)return p._pingResolve(b.SUCCESS),void(p._pingResolve=void 0);if(v instanceof qa)return G.debug("recv connect ack -> "+v.status),v.status!==we.ACCEPTED?(G.warn("connect failed: "+v.status),void m(v.status)):(G.info("connect success -> "+l),p.connectedTime=v.timestamp,p.userId=v.userId||"",p._idCount=v.messageId,void m(b.SUCCESS));if(v instanceof $o){var R=v.status;switch(G.warn("recv disconnect signal -> status: "+R),R){case We.BLOCK:p._watcher.status(se.BLOCKED);break;case We.OTHER_DEVICE_LOGIN:p._watcher.status(se.KICKED_OFFLINE_BY_OTHER_CLIENT);break;case We.REDIRECT_NEW:case We.REDIRECT:p._watcher.status(se.REDIRECT);break;default:p._watcher.status(se.DISCONNECT_BY_SERVER)}}else p._onReceiveSignal(v)}else G.error("Socket received invalid data:",_)}),h.onClose(function(_,v){for(var R in G.warn("websocket closed! code:",_,"reason:",v),a(se.CONNECTION_CLOSED),p._messageIds){var y=p._messageIds[R];delete p._messageIds[R],y(b.RC_NET_CHANNEL_INVALID)}m(_)}),h.onError(function(_){var v;for(var R in G.error("websocket error!",(v=_)===null||v===void 0?void 0:v.stack),a(se.WEBSOCKET_ERROR),p._messageIds){var y=p._messageIds[R];delete p._messageIds[R],y(b.RC_NET_CHANNEL_INVALID)}m(b.NETWORK_ERROR)}),h.onOpen(function(){return G.debug("websocket open =>",l)}),setTimeout(function(){m(b.TIMEOUT)},5e3)})];case 1:return(c=f.sent())===b.SUCCESS?this._socket=h:(G.warn("connect result -> code: "+c+", url: "+l),h.close()),[2,c]}})})},e.prototype._checkAlive=function(){var t;return V(this,void 0,void 0,function(){var r,i=this;return B(this,function(o){switch(o.label){case 0:return this._socket?(G.debug("send ping ->"),this.sendOnly(new Rd),[4,new Promise(function(s){i._pingResolve=s,i._timer&&clearTimeout(i._timer),i._timer=setTimeout(function(){i._pingResolve=void 0,s(b.TIMEOUT)},15e3)})]):[2];case 1:return(r=o.sent())!==b.SUCCESS?(this._failedCount+=1,G.warn("ping failed count: "+this._failedCount+", code: "+r),this._failedCount>=this.ALLOW_FAILED_TIMES?(this._failedCount=0,G.warn("ping timeout, close current websocket to reconnect!"),(t=this._socket)===null||t===void 0||t.close(),this._watcher.status(se.NETWORK_UNAVAILABLE)):this._checkAlive(),[2]):(G.debug("recv pong <-"),this._failedCount=0,setTimeout(function(){return i._checkAlive()},15e3),[2])}})})},e.prototype._onReceiveSignal=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l=this;return B(this,function(h){switch(h.label){case 0:return r=t.messageId,t.header&&t.header.qos!==st.AT_MOST_ONCE&&(t instanceof Sn&&!t.syncMsg&&(G.debug("send pubAck -> "+r),this.sendOnly(new Ya(r))),t instanceof fn&&(G.debug("send queryCon -> "+r),this.sendOnly(new za(r)))),r>0&&(t instanceof Ii||t instanceof fn)&&(G.debug("recv ack -> messageId: "+r),(i=this._messageIds[r])&&(i(t),delete this._messageIds[r]),(o=this._syncMessageIds[r])&&(delete this._syncMessageIds[r],o(t))),t instanceof Sn?(s=t.syncMsg,(u=t.topic)===x[x.userSetData]?[2]:!s||Qa(u)?(this._watcher.signal(t),[2]):[4,new Promise(function(a){l._syncMessageIds[r]=a})]):[3,2];case 1:d=h.sent(),delete this._syncMessageIds[r],this._watcher.signal(t,d),h.label=2;case 2:return[2]}})})},e.prototype.sendOnly=function(t){this._socket&&Is(t,this._socket)},e.prototype.send=function(t,r,i,o){return o===void 0&&(o=3e4),V(this,void 0,void 0,function(){var s,u,d,l=this;return B(this,function(h){switch(h.label){case 0:return this._socket?(s=this._generateMessageId(),t.messageId=s,Is(t,this._socket),[4,new Promise(function(a){l._messageIds[s]=a,setTimeout(function(){l._messageIds[s]&&delete l._messageIds[s],a()},o)})]):[3,2];case 1:return(u=h.sent())?u instanceof fn||u instanceof Ii?(d=r&&u.data?this.codec.decodeByPBName(u.data,r,i):u,u.status!==0?(G.warn("send failed -> message: "+s+", respPBName: "+r+", status: "+u.status),[2,{code:u.status,data:r&&u.data?d:null}]):[2,{code:b.SUCCESS,data:d}]):[2,{code:u}]:(G.warn("send timeout -> message: "+s+", respPBName: "+r+", timeout: "+o),[2,{code:b.TIMEOUT}]);case 2:return[2,{code:b.RC_NET_CHANNEL_INVALID}]}})})},e.prototype.close=function(){this._socket&&(this._socket.close(),this._socket=null,this._watcher.status(se.DISCONNECTED))},e}(Ha);(function(n){n.GET="GET",n.POST="POST"})(Ze||(Ze={}));var zt=function(n){function e(t,r){var i=n.call(this,"comet",r)||this;return i._runtime=t,i._messageIds={},i._syncMessageIds={},i._idCount=0,i._generateMessageId=function(){return++i._idCount},i._pid=encodeURIComponent(new Date().getTime()+Math.random()+""),i}return Re(e,n),e.prototype.handleCometRes=function(t){var r=this;if(t.status!==200&&t.status!==202)return!1;var i=Be(t.data)?JSON.parse(t.data):t.data;return i?!Ue(i)||(ye(i,function(o){return V(r,void 0,void 0,function(){var s,u,d,l,h,a,c,p,f,m,_,v=this;return B(this,function(R){switch(R.label){case 0:if((s=o.sessionid)&&(this._sessionid=s),u=function(y){var P=y.headerCode,L=new zi(P),N=Ja(L);for(var E in y)N[E]=y[E];return N}(o),d=u.messageId,l=u._header,h=u.status,u.identifier,a=l&&l.qos!==st.AT_MOST_ONCE,d&&u.getIdentifier&&((c=this._messageIds[d])&&c(u),this._syncMessageIds[d]&&this._syncMessageIds[d](u)),a&&(u instanceof Sn&&!u.syncMsg&&(p=new Ya(d),this.sendOnly(p)),u instanceof fn&&(p=new za(d),this.sendOnly(p))),u instanceof $o){switch(h){case We.OTHER_DEVICE_LOGIN:this._watcher.status(se.KICKED_OFFLINE_BY_OTHER_CLIENT);break;case We.BLOCK:this._watcher.status(se.BLOCKED);break;case We.REDIRECT_NEW:case We.REDIRECT:this._watcher.status(se.REDIRECT);break;default:this._watcher.status(se.DISCONNECT_BY_SERVER)}return[2]}return u instanceof Sn?(f=u.syncMsg,m=u.topic,!f||Qa(m)?(this._watcher.signal(u),[2,!1]):[4,new Promise(function(y){v._syncMessageIds[d]=y})]):[3,2];case 1:_=R.sent(),delete this._syncMessageIds[d],this._watcher.signal(u,_),R.label=2;case 2:return[2]}})})}),!0):(G.error("received data is not a validJson",i),!1)},e.prototype._startPullSignal=function(t){return V(this,void 0,void 0,function(){var r,i,o,s;return B(this,function(u){switch(u.label){case 0:return r=new Date().getTime(),i=t+"://"+this._domain+"/pullmsg.js?sessionid="+this._sessionid+"×trap="+r+"&pid="+this._pid,[4,this._runtime.httpReq({url:i,body:{pid:this._pid},timeout:45e3})];case 1:return o=u.sent(),s=this.handleCometRes(o),this._isDisconnected||(s?this._startPullSignal(t):(this._isDisconnected=!0,this._watcher.status(se.NETWORK_UNAVAILABLE))),[2]}})})},e.prototype.connect=function(t,r,i,o,s,u){return V(this,void 0,void 0,function(){var d,l,h,a,c=this;return B(this,function(p){return s=qi(s),this._protocol=o,this._isDisconnected=!1,this._watcher.status(se.CONNECTING),d=[],l=0,h=!1,a=!1,[2,new Promise(function(f){var m=function(){return V(c,void 0,void 0,function(){var _;return B(this,function(v){switch(v.label){case 0:return d.length===0||h?[2]:(h=!0,[4,this._connect(t,r,d.shift(),o,s)]);case 1:if((_=v.sent())===b.SUCCESS)this._startPullSignal(o),f(_);else if(_===we.REDIRECT)f(_);else{if(a&&d.length===0)return f(Oa(_)),[2];h=!1,m()}return[2]}})})};c._watcher.status(se.CONNECTING),Wa(i,o,c._runtime,function(_){var v=_.code,R=_.finished,y=_.host;a=R,v===200&&(d.push(y),l++,m()),R&&l===0&&(G.error("No valid websocket server hosts!"),f(b.RC_SOCKET_NOT_CREATED))})})]})})},e.prototype._connect=function(t,r,i,o,s){return V(this,void 0,void 0,function(){var u,d,l,h;return B(this,function(a){switch(a.label){case 0:return u=function(c){return c.status!==200&&c.status!==202?(G.error("handle comet res -> res: "+JSON.stringify(c||{})),!1):!!c.data&&(function(p){if(Ne(p))return!0;var f=!1;try{var m=JSON.parse(p);f=JSON.stringify(m)===p}catch{f=!1}return f}(c.data)?Ne(c.data)?c.data:JSON.parse(c.data):(G.error("received data is not a validJson",c.data),!1))},d=Za(o,i,t,r,this._runtime,s,this._pid),this.sendConnectTime=Date.now(),G.debug("conenct start -> "+d),[4,this._runtime.httpReq({url:d,body:{pid:this._pid},timeout:5e3})];case 1:return l=a.sent(),h=u(l),this._domain=i,h&&h.status===0?(this._sessionid=h.sessionid,this.userId=h.userId,this.connectedTime=h.timestamp):G.warn("connect result -> code: "+(h==null?void 0:h.status)+", url: "+d),[2,h==null?void 0:h.status]}})})},e.prototype.sendCometData=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d,l,h,a,c,p;return B(this,function(f){switch(f.label){case 0:return o=(i=this)._domain,s=i._sessionid,u=i._pid,d=t.messageId,l=t.topic,h=t.targetId,t.identifier,a=t.getHeaderFlag(),c=l?this._protocol+"://"+o+"/websocket?messageid="+d+"&header="+a+"&sessionid="+s+"&topic="+l+"&targetid="+h+"&pid="+u:this._protocol+"://"+o+"/websocket?messageid="+d+"&header="+a+"&sessionid="+s+"&pid="+u,[4,this._runtime.httpReq({url:c,method:Ze.POST,body:t.getCometData()})];case 1:return p=f.sent(),this.handleCometRes(p),[2]}})})},e.prototype.sendOnly=function(t){this.sendCometData(t)},e.prototype.send=function(t,r,i,o){return o===void 0&&(o=3e4),V(this,void 0,void 0,function(){var s,u,d,l=this;return B(this,function(h){switch(h.label){case 0:return s=this._generateMessageId(),t.messageId=s,this.sendCometData(t),[4,new Promise(function(a){l._messageIds[s]=a,setTimeout(function(){delete l._messageIds[s],a()},o)})];case 1:return(u=h.sent())?(d=r&&u.data?this.codec.decodeByPBName(u.data,r,i):u,u.status!==0?[2,{code:u.status,data:r&&u.data?d:null}]:[2,{code:b.SUCCESS,data:d}]):[2,{code:b.TIMEOUT}]}})})},e.prototype.close=function(){this._isDisconnected=!0,this._watcher.status(se.DISCONNECTED)},e}(Ha),Cd=function(n,e,t){this.runtime=n,this._watcher=e,this._options=t,this.currentUserId="",this._appkey=this._options.appkey,this._apiVer=this._options.apiVersion,this.navi=this._createNavi()},Wr=function(n){return["navi",n].join("_")},yd=function(){function n(e,t){this._runtime=e,this._options=t,this._naviInfo=null,this._appkey=this._options.appkey,this._apiVersion=qi(this._options.apiVersion)}return n.prototype.getInfo=function(e,t,r,i){return V(this,void 0,void 0,function(){var o,s;return B(this,function(u){switch(u.label){case 0:return r&&this._clear(e),(o=function(d,l,h){var a,c,p=Wr(d);try{var f=h.getItem(p);c=f?JSON.parse(f):[]}catch{c=[]}var m=Date.now();return c.length>0&&(c=c.filter(function(_){return m-_.timestamp<72e5})),c.length===0?h.removeItem(p):h.setItem(p,JSON.stringify(c)),((a=c.find(function(_){return _.token===l}))===null||a===void 0?void 0:a.naviInfo)||null}(this._appkey,e,this._runtime.localStorage))?(this._naviInfo=o,[2,o]):(s=this._options.navigators.slice(),t.length&&t.forEach(function(d){s.indexOf(d)<0&&s.unshift(d)}),[4,this._reqNavi(s,this._appkey,e,i)]);case 1:return(o=u.sent())?(this._naviInfo=o,this.setNaviInfo2Cache(e,o),[2,o]):[2,o]}})})},n.prototype.setNaviInfo2Cache=function(e,t){this._naviInfo=t,function(r,i,o,s){var u,d=Wr(r);try{var l=s.getItem(d);u=l?JSON.parse(l):[]}catch{u=[]}var h=Date.now();u.length>0&&(u=u.filter(function(a){return h-a.timestamp<72e5&&i!==a.token})),u.push({timestamp:h,naviInfo:o,token:i}),s.setItem(d,JSON.stringify(u))}(this._appkey,e,t,this._runtime.localStorage)},n.prototype.getInfoFromCache=function(e){return this._naviInfo},n.prototype._clear=function(e){(function(t,r,i){var o,s=Wr(t);try{var u=i.getItem(s);o=u?JSON.parse(u):[]}catch{o=[]}var d=Date.now();o.length>0&&(o=o.filter(function(l){return d-l.timestamp<72e5&&r!==l.token})),o.length===0?i.removeItem(s):i.setItem(s,JSON.stringify(o))})(this._appkey,e,this._runtime.localStorage)},n}(),Vn=function(n,e,t){return[n,e,t].join("_")},Ed=function(){function n(e,t){this._runtime=e,this._appkey=t,this._users={}}return n.prototype._getMemData=function(e){return this._users[e]||(this._users[e]={inboxTime:0,outboxTime:0})},n.prototype.setInboxTime=function(e,t){var r=this._getMemData(t);if(!(r.inboxTime>e)){r.inboxTime=e;var i=Vn("inbox",this._appkey,t);this._runtime.localStorage.setItem(i,e.toString())}},n.prototype.getInboxTime=function(e){var t=this._getMemData(e);if(t.inboxTime===0){var r=Vn("inbox",this._appkey,e);t.inboxTime=parseInt(this._runtime.localStorage.getItem(r))||0}return t.inboxTime},n.prototype.setOutboxTime=function(e,t){var r=this._getMemData(t);if(!(r.outboxTime>=e)){r.outboxTime=e;var i=Vn("outbox",this._appkey,t);this._runtime.localStorage.setItem(i,e.toString())}},n.prototype.getOutboxTime=function(e){var t=this._getMemData(e);if(t.outboxTime===0){var r=Vn("outbox",this._appkey,e);t.outboxTime=parseInt(this._runtime.localStorage.getItem(r))||0}return t.outboxTime},n}(),Zr={_caches:{},set:function(n,e){this._caches[n]=e},get:function(n){return this._caches[n]||0},clear:function(n){this._caches[n]=0}},Td=function(){function n(e,t){this._kvCaches={},this._chatroomId=e,this._currentUserId=t}return n.prototype._add=function(e){var t=e.key;e.isDeleted=!1,this._kvCaches[t]=e},n.prototype._remove=function(e){var t=e.key,r=this._kvCaches[t];r&&(r.isDeleted=!0,this._kvCaches[t]=r)},n.prototype._setEntry=function(e,t){var r=e.key,i=e.type,o=e.isOverwrite,s=e.userId,u=this._getSetUserId(r),d=i===xe.DELETE,l=u===s,h=!this._isExisted(r),a=d?this._remove:this._add;(t||o||l||h)&&a.call(this,e)},n.prototype.getValue=function(e){var t=this._kvCaches[e]||{};return t.isDeleted?null:t.value},n.prototype.getAllValue=function(){var e={};for(var t in this._kvCaches)this._kvCaches[t].isDeleted||(e[t]=this._kvCaches[t].value);return e},n.prototype._getSetUserId=function(e){return(this._kvCaches[e]||{}).userId},n.prototype._isExisted=function(e){var t=this._kvCaches[e]||{},r=t.value,i=t.isDeleted;return r&&!i},n.prototype.setEntries=function(e){var t=this,r=e.kvEntries,i=e.isFullUpdate;r=r||[],(i=i||!1)&&this.clear(),r.forEach(function(o){t._setEntry(o,i)}),G.debug("end setEntries")},n.prototype.clear=function(){this._kvCaches={}},n}(),Sd=function(){function n(e){this._pullQueue=[],this._isPulling=!1,this._storeCaches={},this._engine=e}return n.prototype._startPull=function(){return V(this,void 0,void 0,function(){var e,t,r,i,o,s,u;return B(this,function(d){switch(d.label){case 0:return this._isPulling||this._pullQueue.length===0?[2]:(this._isPulling=!0,e=this._pullQueue.splice(0,1)[0],t=e.chrmId,r=e.timestamp,(i=Zr.get(t))>r?(this._isPulling=!1,this._startPull(),[2]):[4,this._engine.pullChatroomEntry(t,i)]);case 1:return o=d.sent(),s=o.code,u=o.data,this._isPulling=!1,s===b.SUCCESS?(Zr.set(t,u.syncTime||0),this._startPull()):this._startPull(),[2]}})})},n.prototype.reset=function(e){Zr.clear(e);var t=this._storeCaches[e];t&&t.clear()},n.prototype.pullEntry=function(e,t){this._pullQueue.push({chrmId:e,timestamp:t}),this._startPull()},n.prototype.setLocal=function(e,t,r){var i=this._storeCaches[e];hn(i)||(i=new Td(e,r)),i.setEntries(t),this._storeCaches[e]=i},n.prototype.getValue=function(e,t){var r=this._storeCaches[e];return r?r.getValue(t):null},n.prototype.getAll=function(e){var t=this._storeCaches[e],r={};return t&&(r=t.getAllValue()),r},n}(),Id=function(){function n(e,t,r,i){this._runtime=e,this._appkey=t,this._userId=r,this._canJoinMulipleChrm=i,this._sessionKey="",this._joinedChrmsInfo={},this._sessionKey="sync-chrm-"+this._appkey+"-"+this._userId}return n.prototype.set=function(e,t){t===void 0&&(t=10),!this._canJoinMulipleChrm&&(this._joinedChrmsInfo={}),this._joinedChrmsInfo[e]=t,this._runtime.sessionStorage.setItem(this._sessionKey,JSON.stringify(this._joinedChrmsInfo))},n.prototype.get=function(){var e,t;try{t=this._runtime.sessionStorage.getItem(this._sessionKey),e=JSON.parse(t||"{}")}catch{G.error("parse rejoined chrm infos error -> "+t),e={}}return e},n.prototype.remove=function(e){delete this._joinedChrmsInfo[e],hn(this._joinedChrmsInfo)?this._runtime.sessionStorage.setItem(this._sessionKey,JSON.stringify(this._joinedChrmsInfo)):this.clear()},n.prototype.clear=function(){this._joinedChrmsInfo={},this._runtime.sessionStorage.removeItem(this._sessionKey)},n}(),Qr="converStatusChanged",bd=function(){function n(e,t,r){this._eventEmitter=new On,this._pullQueue=[],this._isPulling=!1,this._storage=Or(e.runtime),this._appkey=t,this._currentUserId=r,this._engine=e,this._storagePullTimeKey="con-s-"+t+"-"+r}return n.prototype._set=function(e){var t=this;if(!le(e)&&Array.isArray(e)){var r=this._storage.get(this._storagePullTimeKey)||0,i=e.length;e.forEach(function(o,s){var u=o.updatedTime||0;r=u>r?u:r,o.conversationType=o.type,t._eventEmitter.emit(Qr,{statusItem:o,isLastPull:s===i-1})}),this._storage.set(this._storagePullTimeKey,r)}},n.prototype._startPull=function(){return V(this,void 0,void 0,function(){var e,t,r,i;return B(this,function(o){switch(o.label){case 0:return this._isPulling||this._pullQueue.length===0?[2]:(this._isPulling=!0,e=this._pullQueue.splice(0,1)[0],[4,this._engine.pullConversationStatus(e)]);case 1:return t=o.sent(),r=t.code,i=t.data,r===b.SUCCESS?(this._isPulling=!1,this._set(i),this._startPull()):this._startPull(),[2]}})})},n.prototype.pull=function(e){var t=this._storage.get(this._storagePullTimeKey)||0;(e>t||e===0)&&(this._pullQueue.push(t),this._startPull())},n.prototype.watch=function(e){this._eventEmitter.on(Qr,function(t){e(t)})},n.prototype.unwatch=function(){this._eventEmitter.off(Qr,function(e){})},n}(),Tt={c:{keyName:"unreadMessageCount",defaultVal:0},hm:{keyName:"hasMentioned",defaultVal:!1},m:{keyName:"mentionedInfo",defaultVal:null},t:{keyName:"lastUnreadTime",defaultVal:0},nc:{keyName:"notificationStatus",defaultVal:2},to:{keyName:"isTop",defaultVal:!1},tg:{keyName:"tags",defaultVal:{}},mc:{keyName:"unreadMentionedCount",defaultVal:0}},Xn={};for(var bs in Tt){var Od=Tt[bs].keyName;Xn[Od]=bs}var tn,Nd=function(){function n(e,t,r){this._appkey=t,this._currentUserId=r;var i="con-"+t+"-"+r;this.storage=new ss(e,i),this._localStore=new ss(e,"CONVER-"+t+"-"+r)}return n.prototype._getStoreKey=function(e,t,r){return r+"_"+e+"_"+t},n.prototype._getConOptionByKey=function(e){var t=(e=e||"").split("_");if(t.length>=2){var r=t.shift(),i=t.shift(),o=t.join("_");return{conversationType:Number(i),targetId:o,channelId:r}}return{conversationType:ee.PRIVATE,targetId:"",channelId:""}},n.prototype.updateMentionedData=function(e){var t=this,r=e.conversationType,i=e.targetId,o=e.messageType,s=e.isMentioned,u=e.content,d=e.senderUserId,l=e.channelId,h=this._getStoreKey(r,i,l),a=this._localStore.get(h)||{},c=Xn.mentionedInfo,p=Xn.hasMentioned,f=a[c]||{},m=f.userIdList||[],_=u.mentionedInfo;if(_){if(s&&r===ee.GROUP&&((_.userIdList||[]).forEach(function(R){R===t._currentUserId&&m.indexOf(d)<0&&m.push(d)}),_.type===Yi.ALL&&m.indexOf(d)<0&&m.push(d)),o===Ae.RECALL&&r===ee.GROUP){var v=m.indexOf(d);v>=0&&m.splice(v,1)}_={userIdList:m,type:(_==null?void 0:_.type)||f.type},m.length!==0?(a[c]=_,a[p]=!0):(delete a[c],delete a[p]),hn(a)?this._localStore.set(h,a):this._localStore.remove(h)}},n.prototype.set=function(e,t,r,i){var o=this._getStoreKey(e,t,i),s=this._localStore.get(o)||{};for(var u in r){var d=Xn[u],l=r[u];if(!le(d)&&!le(l)&&u!=="hasMentioned"&&u!=="MentionedInfo"){if(l===Tt[d].defaultVal||u==="tags"&&!hn(l))delete s[d];else if(u==="tags"){var h=l;for(var a in h)h[a].isTop||delete h[a].isTop;s[d]=l}else s[d]=l;s.c||(delete s.t,delete s.hm,delete s.m,delete s.mc)}}hn(s)?this._localStore.set(o,s):this._localStore.remove(o)},n.prototype.get=function(e,t,r){r===void 0&&(r="");var i=this._getStoreKey(e,t,r),o=this._localStore.get(i)||{},s={};for(var u in Tt){var d=Tt[u],l=d.keyName,h=d.defaultVal;s[l]=o[u]||Qn(h)}return s},n.prototype.getValue=function(e){var t=this._localStore.getValues()||{},r=[];for(var i in t){var o=this._getConOptionByKey(i),s={conversationType:o.conversationType,targetId:o.targetId,channelId:o.channelId},u=t[i];for(var d in u){var l=Tt[d],h=l.keyName,a=l.defaultVal;s[h]=u[d]||Qn(a)}s=e?e(s):s,r.push(s)}return r},n.prototype.getValueForTag=function(){var e=this._localStore.getValues()||{},t={};for(var r in e){var i=this._getConOptionByKey(r),o=i.conversationType,s=i.targetId,u={},d=e[r];for(var l in d){var h=Tt[l],a=h.keyName,c=h.defaultVal;u[a]=d[l]||Qn(c)}for(var p in u.tags){le(t[p])&&(t[p]=[]);var f=Object.assign({},u,{conversationType:o,targetId:s});delete f.tags,t[p].push(f)}}return t},n.prototype.adaptOldStore=function(){try{var e=this.storage.getValues();if(Object.keys(e).length===0)return;for(var t in e){var r="_"+t;this._localStore.set(r,e[t])}}catch(i){G.error("adaptOldStore error: "+i.message)}},n}(),wd=[ee.PRIVATE,ee.GROUP,ee.SYSTEM,ee.PUBLIC_SERVICE,ee.APP_PUBLIC_SERVICE],Os="conversationChanged",Ns="conTagStatusChanged",Md=function(){function n(e,t,r,i,o){var s=this;this._updatedConversations={},this._conTagStatusChanged=!1,this._eventEmitter=new On,this._draftMap={},this._appkey=t,this._loginUserId=r,this._store=new Nd(e.runtime,t,r),this._statusManager=new bd(e,t,r),this._statusManager.watch(function(u){var d=u.statusItem,l=u.isLastPull;s.addStatus(d,l)}),this._eventEmitter.on(Os,function(u){i(u)}),this._eventEmitter.on(Ns,function(){o()})}return n.prototype._calcUnreadCount=function(e,t){var r=e.content,i=e.messageType,o=e.sentTime,s=e.isCounted,u=e.messageDirection,d=e.senderUserId,l=u===je.SEND&&d===this._loginUserId,h=i===Ae.RECALL,a=Ne(r),c=!1,p={},f=t.lastUnreadTime||0,m=t.unreadMessageCount||0;return f>o||l?{hasChanged:c,localConversation:t,updateItems:p}:(s&&(t.unreadMessageCount=m+1,t.lastUnreadTime=o,c=!0),h&&a&&f>=r.sentTime&&m&&(t.unreadMessageCount=m-1,c=!0),c&&(p.unreadMessageCount={val:t.unreadMessageCount,time:o}),{hasChanged:c,localConversation:t,updateItems:p})},n.prototype._calcMentionedInfo=function(e,t){var r=e.content,i=(e.messageDirection,e.isMentioned),o=e.sentTime;je.SEND;var s=Ne(r),u=!1,d={};return i&&s&&r.mentionedInfo&&(t.hasMentioned=!0,u=!0,d.hasMentioned={val:!0,time:o},d.mentionedInfo={val:r.mentionedInfo,time:o}),{hasChanged:u,localConversation:t,updateItems:d}},n.prototype._calcMentionedCount=function(e,t){var r=e.content,i=e.messageDirection,o=!1;if(e.isMentioned&&i===je.RECEIVE&&(r==null?void 0:r.mentionedInfo)){var s=r.mentionedInfo,u=s.type,d=s.userIdList;if(u===Yi.ALL||(d||[]).includes(this._loginUserId)){o=!0;var l=t.unreadMentionedCount||0;t.unreadMentionedCount=l+1}}return{hasChanged:o,localConversation:t}},n.prototype._setUpdatedConversation=function(e){if(Ne(e)){var t=e.conversationType,r=e.targetId,i=e.channelId,o=t+"_"+r,s=this._store.get(t,r,i)||{};this._updatedConversations[o]=Object.assign(s,e)}},n.prototype._setConTagStatusChanged=function(e,t,r,i){var o=(this._store.get(e,t,i)||{}).tags||{};if(Object.keys(o).length===Object.keys(r).length){for(var s in o)if(!r[s]||o[s].isTop!==r[s].isTop)return void(this._conTagStatusChanged=!0)}else this._conTagStatusChanged=!0},n.prototype.addStatus=function(e,t){var r=e.conversationType,i=e.targetId,o=e.updatedTime,s=e.notificationStatus,u=e.isTop,d=e.tags,l=e.channelId,h={},a={};le(s)||(a.notificationStatus={time:o,val:s}),le(u)||(a.isTop={time:o,val:u}),le(d)||(a.tags={time:o,val:d},d==null||d.forEach(function(c){h[c.tagId]={isTop:c.isTop}})),this._setConTagStatusChanged(r,i,h,l),this._store.set(r,i,{notificationStatus:s,isTop:u,tags:h},l),this._setUpdatedConversation({conversationType:r,targetId:i,updatedItems:a,channelId:l}),t&&this._notifyConversationChanged()},n.prototype._notifyConversationChanged=function(){var e=[];for(var t in this._updatedConversations)e.push(this._updatedConversations[t]);e.length!==0&&(this._eventEmitter.emit(Os,e),this._updatedConversations={},this._conTagStatusChanged&&(this._eventEmitter.emit(Ns),this._conTagStatusChanged=!1))},n.prototype.setConversationCacheByMessage=function(e,t){var r=this,i=e.conversationType,o=e.isPersited,s=e.targetId,u=e.channelId;if(wd.indexOf(i)>=0){var d=!1,l=this._store.get(i,s,u),h={};if([this._calcUnreadCount,this._calcMentionedInfo,this._calcMentionedCount].forEach(function(p){var f=p.call(r,e,l),m=f.hasChanged,_=f.localConversation,v=f.updateItems;d=d||m,h=fe(fe({},h),v),l=Qn(_)}),d&&this._store.set(i,s,l,u),this._store.updateMentionedData(e),o){var a=this._store.get(i,s,u);a.updatedItems=fe({latestMessage:{time:e.sentTime,val:e}},h),a.latestMessage=e;var c=Object.assign(a,{conversationType:i,targetId:s,channelId:u});this._setUpdatedConversation(c)}(d||o)&&this._notifyConversationChanged()}},n.prototype.get=function(e,t,r){return r===void 0&&(r=""),this._store.get(e,t,r)},n.prototype.getAllUnreadCount=function(e,t,r){var i=this._store.getValue(),o=0;return i.forEach(function(s){var u=s.unreadMessageCount,d=s.notificationStatus,l=s.conversationType;u=u||0,(r||d!==1)&&(t.length>0?t.includes(Number(l))&&(o+=Number(u)):o+=Number(u))}),o},n.prototype.getUnreadCountByTag=function(e,t){var r=this._store.getValueForTag()[e]||[],i=0;return r.forEach(function(o){var s=o.unreadMessageCount,u=o.notificationStatus;(t||u!==1)&&(s=s||0,i+=Number(s))}),i},n.prototype.getUnreadCount=function(e,t,r){return this._store.get(e,t,r).unreadMessageCount||0},n.prototype.clearUnreadCount=function(e,t,r,i){i===void 0&&(i=!0);var o=this._store.get(e,t,r),s=o.unreadMessageCount,u=o.hasMentioned,d={};if(s&&(o.unreadMessageCount=0,d.unreadMessageCount={val:0,time:Date.now()}),u&&(o.hasMentioned=!1,o.unreadMentionedCount=0,o.mentionedInfo=void 0,d.hasMentioned={val:!1,time:Date.now()},d.mentionedInfo={val:void 0,time:Date.now()}),this._store.set(e,t,o,r),i&&Object.keys(d).length!==0){var l=Object.assign(o,{conversationType:e,targetId:t,channelId:r,updatedItems:d});this._setUpdatedConversation(l),this._notifyConversationChanged()}},n.prototype.clearAllUnreadCount=function(){var e=this;this._store.getValue().forEach(function(t){t.unreadMessageCount&&(t.unreadMessageCount=0,e._store.set(t.conversationType,t.targetId,t,t.channelId))})},n.prototype.startPullConversationStatus=function(e){this._statusManager.pull(e)},n.prototype.setDraft=function(e,t,r,i){var o=e+"_"+t+"_"+i;this._draftMap[o]=r},n.prototype.getDraft=function(e,t,r){var i=e+"_"+t+"_"+r;return this._draftMap[i]},n.prototype.clearDraft=function(e,t,r){var i=e+"_"+t+"_"+r;delete this._draftMap[i]},n.prototype.addTagStatus=function(e,t,r,i){i===void 0&&(i="");var o=this._store.get(e,t,i).tags;o=Object.assign(o,r),this._store.set(e,t,{tags:o},i)},n.prototype.deleteTagStatus=function(e,t,r,i){i===void 0&&(i="");var o=this._store.get(e,t,i).tags;r.forEach(function(s){delete o[s]}),this._store.set(e,t,{tags:o},i)},n.prototype.getConversationListForTag=function(){return this._store.getValueForTag()},n.prototype.getBlockConversationList=function(){return this._store.getValue().filter(function(e){return e.notificationStatus===Ut.OPEN}).map(function(e){return{conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId}})},n.prototype.getTopConversationList=function(){return(this._store.getValue()||{}).filter(function(e){return e.isTop}).map(function(e){return{conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId}})},n.prototype.adaptOldStore=function(){this._store.adaptOldStore()},n.prototype.getUnreadMentionedCount=function(e,t,r){return e===void 0&&(e=""),this.get(t,r,e).unreadMentionedCount||0},n.prototype.getAllUnreadMentionedCount=function(){var e=this._store.getValue(),t=0;return e.forEach(function(r){var i=r.unreadMentionedCount;i=i||0,t+=Number(i)}),t},n}(),Ad=function(){function n(e,t,r,i){this._pullQueue=[],this._isPulling=!1,this._storageTagKey="tag-"+t+"-"+r,this._storagePullTimeKey="us-s-"+t+"-"+r,this._storage=Or(e.runtime),this._engine=e,this._tagWatcherFunc=i}return n.prototype._updateTag=function(e){var t=e.tags,r={};t.forEach(function(i){r[i.tagId]={tagName:i.tagName,createdTime:i.createdTime}}),this._storage.set(this._storageTagKey,r),this._tagWatcherFunc()},n.prototype.addTag=function(e,t){var r=this._storage.get(this._storageTagKey)||{};e.forEach(function(i){var o,s=((o=r[i.tagId])===null||o===void 0?void 0:o.createdTime)||i.createdTime||0;r[i.tagId]={tagName:i.tagName,createdTime:s}}),this._storage.set(this._storageTagKey,r),this._storage.set(this._storagePullTimeKey,t)},n.prototype.deleteTag=function(e,t){var r=this._storage.get(this._storageTagKey)||{};e.forEach(function(i){delete r[i]}),this._storage.set(this._storageTagKey,r),this._storage.set(this._storagePullTimeKey,t)},n.prototype.getTagsInfo=function(){return this._storage.get(this._storageTagKey)||{}},n.prototype.getTags=function(){var e=this._storage.get(this._storageTagKey)||{},t=[];for(var r in e)t.push({tagId:r,tagName:e[r].tagName,createdTime:e[r].createdTime,conversationCount:0});return t.sort(function(i,o){return(i.createdTime||0)-(o.createdTime||0)})},n.prototype.getTagById=function(e){var t=this._storage.get(this._storageTagKey)||{};return t[e]?{tagId:e,tagName:t[e].tagName,createdTime:t[e].createdTime,conversationCount:0}:null},n.prototype._startPull=function(){return V(this,void 0,void 0,function(){var e,t,r,i,o,s,u,d;return B(this,function(l){switch(l.label){case 0:return this._isPulling||this._pullQueue.length===0?[2]:(this._isPulling=!0,e=this._pullQueue.splice(0,1)[0],[4,this._engine.pullUserSettings(e)]);case 1:return t=l.sent(),r=t.code,i=t.data,r!==b.SUCCESS||le(i)?(this._isPulling=!1,this._startPull()):(s=(o=i).settings,u=o.version,d=s.Tag,le(d)||this._updateTag(d),this._storage.set(this._storagePullTimeKey,u),this._isPulling=!1,this._startPull()),[2]}})})},n.prototype.pullUserSettings=function(e){var t=this._storage.get(this._storagePullTimeKey)||0;(e>t||e===0)&&(this._pullQueue.push(t),this._startPull())},n.prototype.getVersion=function(){return this._storage.get(this._storagePullTimeKey)||0},n}(),Pd=function(n){function e(t,r){var i=n.call(this,t,r)||this;return i._miniConnectUrl="",i._connectType=r.connectionType,i}return Re(e,n),e.prototype._formatJSONPUrl=function(t,r,i,o){return t+"/"+(this._runtime.isSupportSocket()&&this._connectType==="websocket"?"navi":"cometnavi")+".js?appId="+i+"&token="+encodeURIComponent(r)+"&callBack="+o+"&v="+this._apiVersion+"&r="+Date.now()},e.prototype.getInfo=function(t,r,i){var o;return V(this,void 0,void 0,function(){var s;return B(this,function(u){return this._runtime.useNavi||(s=void 0,s=this._runtime.isSupportSocket()&&this._connectType==="websocket"?Pu.join(","):Lu.join(","),this._miniConnectUrl=((o=this._options.miniCMPProxy)===null||o===void 0?void 0:o.length)?this._options.miniCMPProxy.join(","):s||"",r=[]),[2,n.prototype.getInfo.call(this,t,r,i)]})})},e.prototype._reqNavi=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l,h,a,c,p;return B(this,function(f){switch(f.label){case 0:o="getServerEndpoint",s=0,u=t.length,f.label=1;case 1:return s "+d),[4,this._runtime.httpReq({url:d,timeout:1e4,dataType:"text"})]):[3,4];case 2:if((l=f.sent()).status!==200)return l.status===403?G.error("request navi error: "+b.RC_CONN_USER_OR_PASSWD_ERROR):l.status===401&&G.error("request navi error: "+b.RC_CONN_APP_BLOCKED_OR_DELETED),[3,3];try{return h=l.data.match(/{[\d\D]+}/),(a=h&&h[0]?h[0]:"").indexOf('{\\"code\\":')===0&&(a=JSON.parse('"'+a+'"')),p=JSON.parse(a),c=/^https/.test(d)?"https":"http",p.protocol=c,this._runtime.useNavi||(p.server="",p.backupServer=this._miniConnectUrl,p.logSwitch=0),[2,p]}catch(m){G.error("parse navi err =>",m)}f.label=3;case 3:return s+=1,[3,1];case 4:return this._runtime.useNavi?[2,null]:[2,p={code:200,protocol:"https",server:"",voipCallInfo:"",kvStorage:0,openHttpDNS:!1,historyMsg:!1,chatroomMsg:!1,uploadServer:"https://upload.qiniup.com",bosAddr:"https://gz.bcebos.com",location:"",monitor:0,joinMChrm:!1,openMp:0,openUS:0,grpMsgLimit:0,isFormatted:0,gifSize:2048,logSwitch:0,logPolicy:"",compDays:0,msgAck:"",activeServer:"",qnAddr:"",extkitSwitch:0,alone:!1,voipServer:"",offlinelogserver:"",backupServer:this._miniConnectUrl}]}})})},e}(yd),Ld=function(){function n(e){this._pullQueue=[],this._isPulling=!1,this._pullTime=0,this._engine=e}return n.prototype._startPull=function(){return V(this,void 0,void 0,function(){var e,t,r,i,o,s,u;return B(this,function(d){switch(d.label){case 0:return this._isPulling||this._pullQueue.length===0?[2]:(this._isPulling=!0,e=this._pullQueue.splice(0,1)[0],t=e.roomId,r=e.timestamp,(i=this._pullTime)>r?(this._isPulling=!1,this._startPull(),[2]):[4,this._engine.pullRTCRoomEntry(t,i)]);case 1:return o=d.sent(),s=o.code,u=o.data,s===b.SUCCESS?(this._isPulling=!1,this._pullTime=u.syncTime||0,this._startPull()):this._startPull(),[2]}})})},n.prototype.pullEntry=function(e,t){this._pullQueue.push({roomId:e,timestamp:t}),this._startPull()},n.prototype.reset=function(){this._pullTime=0,this._isPulling=!1},n}(),Xr=function(n,e){return["send_msg",n,e].join("_")},kd=function(){function n(e,t){this._runtime=e,this._appkey=t,this._sendMessageMap={},this._userId=""}return n.prototype.init=function(e){this._userId=e;var t=Xr(this._appkey,e);this._sendMessageMap=this._getLocalInfo(t)},n.prototype._getLocalInfo=function(e){var t=this._runtime.localStorage.getItem(e);try{return t?JSON.parse(t):{}}catch{return{}}},n.prototype.setMessage=function(e,t){this._sendMessageMap[e]=t;var r=Xr(this._appkey,this._userId),i=this._getLocalInfo(r);i[e]=t,this._runtime.localStorage.setItem(r,JSON.stringify(i))},n.prototype.getSendMessageMap=function(){return this._sendMessageMap},n.prototype.removeByUID=function(e){delete this._sendMessageMap[e]},n.prototype.removeByTimestamp=function(e){var t=Xr(this._appkey,this._userId),r=this._getLocalInfo(t);Object.keys(r).forEach(function(i){r[i] signal.messageId: "+t.messageId),this._pullMsg(t);break;case x.s_msg:this._receiveMsg(t);break;case x.s_cmd:this._receiveStateNotify(t);break;case x.s_us:this._receiveSettingNotify(t);break;case x.rtc_ntf:this._receiveRtcKv(t)}else G.error("unknown topic:",o)}},e.prototype._receiveStateNotify=function(t){var r,i=(r=this._channel)===null||r===void 0?void 0:r.codec.decodeByPBName(t.data,cr),o=i.time,s=i.type,u=i.chrmId;switch(s){case 2:this._chrmEntryHandler.pullEntry(u,o);break;case 3:this._conversationManager.startPullConversationStatus(o);break;case 4:this._chrmEntryHandler.reset(u),this._watcher.chatroom({chatroomDestroyed:t.targetId})}},e.prototype._receiveSettingNotify=function(t){var r,i=((r=this._channel)===null||r===void 0?void 0:r.codec.decodeByPBName(t.data,kr)).version;this._userSettingManager.pullUserSettings(i)},e.prototype._receiveRtcKv=function(t){var r,i=(r=this._channel)===null||r===void 0?void 0:r.codec.decodeByPBName(t.data,ko),o=i.time,s=i.type,u=i.roomId;switch(s){case 1:this._rtcKVManager.pullEntry(u,o)}},e.prototype._receiveMessageExpansion=function(t){var r=t.content,i=r.put,o=r.del,s=r.mid;i&&this._watcher.expansion({updatedExpansion:{messageUId:s,expansion:i}}),o&&this._watcher.expansion({deletedExpansion:{messageUId:s,deletedKeys:o}})},e.prototype._receiveSyncMsg=function(t,r){var i;if(Dd.includes(t.topic)){var o=(i=this._channel)===null||i===void 0?void 0:i.codec.decodeByPBName(t.data,Rn,{currentUserId:this.currentUserId,signal:t});o=this._handleMsgProperties(o),r&&(o.sentTime=r.timestamp,o.messageUId=r.messageUId),this._pullingMsg?this._pullQueue.push((r==null?void 0:r.timestamp)||o.sentTime):(r&&this._sendMessageStore.setMessage(r.messageUId,r.timestamp),o.messageType!==Ae.EXPANSION_NOTIFY?(o.messageType===Ae.SYNC_READ_STATUS&&this._conversationManager.clearUnreadCount(o.conversationType,o.targetId,o.channelId),this._conversationManager.setConversationCacheByMessage(o,!0),this._watcher.batchMessage([o])):this._receiveMessageExpansion(o))}},e.prototype._pullMsg=function(t){if(this._channel){var r=this._channel.codec.decodeByPBName(t.data,cr),i=r.type,o=r.chrmId,s=r.time;if(G.info("s_ntf -> type: "+i+", chrmId: "+o+", time: "+s),i===2){var u=this._chrmsQueue[o];if(!u)return;u.queue.push(s),this._pullChrmMsg(o)}else this._pullQueue.push(s),this._syncMsg()}},e.prototype._startSyncInterval=function(){var t=this;this._stopSyncInterval(),this._intervalTimer=setInterval(function(){Date.now()-t._latestSyncTimestamp>=18e4&&t._syncMsg()},3e4),this._latestSyncTimestamp=Date.now(),this._syncMsg()},e.prototype._stopSyncInterval=function(){this._intervalTimer!==-1&&(clearInterval(this._intervalTimer),this._intervalTimer=-1)},e.prototype._syncMsg=function(){return V(this,void 0,void 0,function(){var t,r,i,o,s,u,d,l,h,a,c,p,f,m,_=this;return B(this,function(v){switch(v.label){case 0:return this._pullingMsg?[2]:this._channel?(this._pullingMsg=!0,t=this._letterbox.getOutboxTime(this.currentUserId),r=this._letterbox.getInboxTime(this.currentUserId),G.info("pullMsg -> sendboxTime: "+t+", inboxTime: "+r),i=this._channel.codec.encodeSyncMsg({sendboxTime:t,inboxTime:r}),o=new te(x[x.pullMsg],i,this.currentUserId),[4,this._channel.send(o,Cn,{connectedTime:this._channel.connectedTime,currentUserId:this.currentUserId})]):(this._pullingMsg=!1,[2]);case 1:return s=v.sent(),u=s.code,d=s.data,this._latestSyncTimestamp=Date.now(),u===b.SUCCESS&&d?(l=d.list,h=d.finished,a=d.syncTime,G.info("pullMsg success -> syncTime: "+a+", finished: "+h),c=0,p=[],l.forEach(function(R){if(R.messageDirection===je.SEND&&(c=Math.max(R.sentTime,c),_._sendMessageStore.getSendMessageMap()[R.messageUId]))return void _._sendMessageStore.removeByUID(R.messageUId);if(R.messageType!==Ae.EXPANSION_NOTIFY){if(R.messageType===Ae.SYNC_READ_STATUS){if(R.senderUserId!==_.currentUserId)return;_._conversationManager.clearUnreadCount(R.conversationType,R.targetId,R.channelId)}var y=_._handleMsgProperties(R);_._conversationManager.setConversationCacheByMessage(y,!0),p.push(y)}else _._receiveMessageExpansion(R)}),this._watcher.batchMessage(p),this._letterbox.setInboxTime(a,this.currentUserId),this._letterbox.setOutboxTime(c,this.currentUserId),this._sendMessageStore.removeByTimestamp(c),this._pullingMsg=!1,f=this._pullQueue.filter(function(R){return R>a}),this._pullQueue.length=0,(m=this._pullQueue).push.apply(m,f),h&&!this._pullOfflineFinished&&(this._pullOfflineFinished=!0,this._watcher.pullFinished()),(!h||f.length>0)&&this._syncMsg(),[2]):(G.warn("pullMsg failed -> code:",u,", data: ",d),this._pullingMsg=!1,[2])}})})},e.prototype._receiveMsg=function(t){if(this._channel&&!this._pullingMsg)if(this._pullQueue.length>0)this._syncMsg();else{var r=this._channel.codec.decodeByPBName(t.data,wr,{currentUserId:this.currentUserId,connectedTime:this._channel.connectedTime});(r=this._handleMsgProperties(r)).senderUserId===this.currentUserId&&this._sendMessageStore.setMessage(r.messageUId,r.sentTime),r.isStatusMessage||r.senderUserId===this.currentUserId||this._letterbox.setInboxTime(r.sentTime,this.currentUserId),r.messageType!==Ae.EXPANSION_NOTIFY?r.messageType===Ae.SYNC_READ_STATUS&&r.senderUserId!==this.currentUserId||(this._conversationManager.setConversationCacheByMessage(r,!0),this._watcher.batchMessage([r])):this._receiveMessageExpansion(r)}},e.prototype._handleMsgProperties=function(t,r){r===void 0&&(r=!1);var i,o=t.messageType,s=t.isCounted,u=t.isPersited,d=t.isStatusMessage,l=o in os,h=o in this._customMessageType;if(i=l?os[o]:h?this._customMessageType[o]:{isCounted:!cs(s)&&s,isPersited:!cs(u)&&u},Object.assign(t,{isCounted:i.isCounted,isPersited:i.isPersited,isStatusMessage:ku.includes(o)}),r&&(t.isStatusMessage=d),!r){var a=t.content.user;if(a){var c=a.portrait,p=a.portraitUri,f=c||p;f&&(a.portrait=a.portraitUri=f)}}return t},e.prototype.getHistoryMessage=function(t,r,i,o,s,u){return u===void 0&&(u=""),V(this,void 0,void 0,function(){var d,l,h,a,c,p,f,m,_;return B(this,function(v){switch(v.label){case 0:return l=(d=this).currentUserId,h=d._channel,a=gd[t]||Fa,c=o===1&&i===0,h?(p=h.codec.encodeGetHistoryMsg(r,{timestamp:i,count:c?2:o,order:s,channelId:u}),[4,h.send(new te(a,p,l),yn,{currentUserId:l,connectedTime:h.connectedTime,conversation:{targetId:r}})]):[3,2];case 1:return f=v.sent(),(m=f.code)!==b.SUCCESS?[2,{code:m}]:(_=f.data,c&&_.list.length===2&&(_.hasMore=!0,s===0?_.list.shift():_.list.pop()),[2,{code:m,data:{list:_.list,hasMore:_.hasMore}}]);case 2:return[2,{code:b.RC_NET_CHANNEL_INVALID}]}})})},e.prototype.reportSDKInfo=function(t){var r=this.currentUserId,i=this._channel;if(i){G.debug("reportSDKInfo ->",t);var o=i.codec.encodeReportSDKInfo(JSON.stringify(t)),s=new te(x[x.reportsdk],o,r);i.send(s).then(function(u){var d=u.code;d!==b.SUCCESS&&G.warn("reportSDKInfo failed -> code: "+d)})}},e.prototype.deleteRemoteMessage=function(t,r,i,o){return V(this,void 0,void 0,function(){var s,u,d,l,h,a,c;return B(this,function(p){switch(p.label){case 0:return u=(s=this).currentUserId,(d=s._channel)?(l=d.codec.encodeDeleteMessages(t,r,i,o),h=new te(td,l,u),[4,d.send(h)]):[3,2];case 1:return a=p.sent(),c=a.code,b.SUCCESS,[2,c];case 2:return[2,b.RC_NET_CHANNEL_INVALID]}})})},e.prototype.deleteRemoteMessageByTimestamp=function(t,r,i,o){return V(this,void 0,void 0,function(){var s,u,d,l,h,a,c,p;return B(this,function(f){switch(f.label){case 0:return u=(s=this).currentUserId,(d=s._channel)?(l=d.codec.encodeClearMessages(r,i,o),h=md[t],a=new te(h,l,u),[4,d.send(a)]):[3,2];case 1:return c=f.sent(),p=c.code,b.SUCCESS,[2,p];case 2:return[2,b.RC_NET_CHANNEL_INVALID]}})})},e.prototype.getConversationList=function(t,r,i,o,s){return t===void 0&&(t=300),V(this,void 0,void 0,function(){var u,d,l,h,a,c,p,f,m=this;return B(this,function(_){switch(_.label){case 0:return d=(u=this).currentUserId,l=u._channel,r=r||ee.PRIVATE,l?(h=l.codec.encodeOldConversationList({count:t,type:r,startTime:i,order:o}),a=new te(ys,h,d),[4,l.send(a,En,{currentUserId:d,connectedTime:l.connectedTime,afterDecode:function(v){var R=v.conversationType,y=v.targetId,P=v.channelId,L=m._conversationManager.get(R,y,P);return Object.assign(v,L),v}})]):[3,2];case 1:return c=_.sent(),p=c.code,f=c.data,p!==b.SUCCESS?[2,{code:p}]:[2,{code:p,data:f}];case 2:return[2,{code:b.RC_NET_CHANNEL_INVALID}]}})})},e.prototype.removeConversation=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l;return B(this,function(h){switch(h.label){case 0:return(o=this._channel)?(s=o.codec.encodeRemoveOldConversationList({conversationType:t,channelId:i,targetId:r}),u=new te(ud,s,r),[4,o.send(u)]):[3,2];case 1:return d=h.sent(),G.info("RemoveConversation =>",d),l=d.code,b.SUCCESS,[2,l];case 2:return[2,b.RC_NET_CHANNEL_INVALID]}})})},e.prototype.getConversation=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l,h;return B(this,function(a){switch(a.label){case 0:return(o=this._conversationManager.get(t,r,i))?[4,this.getHistoryMessage(t,r,0,1,0)]:[2,{code:b.CONVER_GET_ERROR}];case 1:return s=a.sent(),u=s.code,d=s.data,u!==b.SUCCESS?[2,{code:b.CONVER_GET_ERROR}]:(l=(d==null?void 0:d.list[0])||null,h={conversationType:t,targetId:r,channelId:i,unreadMessageCount:o.unreadMessageCount||0,latestMessage:l,notificationStatus:o.notificationStatus||Ut.CLOSE,isTop:o.isTop||!1,lastUnreadTime:o.lastUnreadTime||0,unreadMentionedCount:o.unreadMentionedCount||0},[2,{code:b.SUCCESS,data:h}])}})})},e.prototype.getAllConversationUnreadCount=function(t,r,i){var o=this._conversationManager.getAllUnreadCount(t,r,i);return Promise.resolve({code:b.SUCCESS,data:o})},e.prototype.getConversationUnreadCount=function(t,r,i){var o=this._conversationManager.getUnreadCount(t,r,i);return Promise.resolve({code:b.SUCCESS,data:o})},e.prototype.clearConversationUnreadCount=function(t,r,i){return this._conversationManager.clearUnreadCount(t,r,i,!1),Promise.resolve(b.SUCCESS)},e.prototype.clearAllUnreadCount=function(){return this._conversationManager.clearAllUnreadCount(),Promise.resolve(b.SUCCESS)},e.prototype.getFirstUnreadMessage=function(t,r){throw new Error("Method not implemented.")},e.prototype.saveConversationMessageDraft=function(t,r,i,o){return this._conversationManager.setDraft(t,r,i,o),Promise.resolve(b.SUCCESS)},e.prototype.getConversationMessageDraft=function(t,r,i){var o=this._conversationManager.getDraft(t,r,i);return Promise.resolve({code:b.SUCCESS,data:o})},e.prototype.clearConversationMessageDraft=function(t,r,i){return this._conversationManager.clearDraft(t,r,i),Promise.resolve(b.SUCCESS)},e.prototype.pullConversationStatus=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l,h;return B(this,function(a){switch(a.label){case 0:return i=(r=this)._channel,o=r.currentUserId,i?(s=i.codec.encodeGetConversationStatus(t),u=new te(x[x.pullSeAtts],s,o),[4,i.send(u,Dr)]):[3,2];case 1:return d=a.sent(),l=d.code,h=d.data,l!==b.SUCCESS?[2,{code:l}]:[2,{code:l,data:h}];case 2:return[2,{code:b.RC_NET_CHANNEL_INVALID}]}})})},e.prototype.batchSetConversationStatus=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l,h,a,c=this;return B(this,function(p){switch(p.label){case 0:return i=(r=this).currentUserId,(o=r._channel)?(s=o.codec.encodeSetConversationStatus(t),u=new te(dd,s,i),[4,o.send(u,wo)]):[3,2];case 1:return d=p.sent(),l=d.code,h=d.data,l===b.SUCCESS?(a=h,t.forEach(function(f){c._conversationManager.addStatus(fe(fe({},f),{updatedTime:a.version}),!0)}),[2,l]):[2,l];case 2:return[2,b.RC_NET_CHANNEL_INVALID]}})})},e.prototype._joinChrm=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l,h,a;return B(this,function(c){switch(c.label){case 0:return(o=this._channel)?(s=o.codec.encodeJoinOrQuitChatRoom(),u=new te(i?rd:nd,s,t),[4,o.send(u,ao)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return d=c.sent(),l=d.code,h=d.data,l===b.SUCCESS&&(a=h.joinTime,this._chrmsQueue[t]||(this._chrmsQueue[t]={pulling:!1,queue:[],timestamp:0}),this._pullChrmMsg(t,r,a),this._naviInfo.kvStorage&&this._chrmEntryHandler.pullEntry(t,0),this._joinedChrmManager.set(t,r)),[2,l]}})})},e.prototype._rejoinChrm=function(){return V(this,void 0,void 0,function(){var t,r,i,o,s,u;return B(this,function(d){switch(d.label){case 0:for(i in t=this._joinedChrmManager.get(),r=[],t)r.push(i);o=0,d.label=1;case 1:return of}),_=[],p.forEach(function(R){R.sentTime0)&&this._pullChrmMsg(t),[2]):(G.warn("pull chatroom msg failed, code:",a,", data:",c),[2])}})})},e.prototype.joinChatroom=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return[2,this._joinChrm(t,r,!1)]})})},e.prototype.joinExistChatroom=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return[2,this._joinChrm(t,r,!0)]})})},e.prototype.quitChatroom=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u;return B(this,function(d){switch(d.label){case 0:return(r=this._channel)?(i=r.codec.encodeJoinOrQuitChatRoom(),o=new te(id,i,t),[4,r.send(o)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return s=d.sent(),(u=s.code)===b.SUCCESS&&(delete this._chrmsQueue[t],this._chrmEntryHandler.reset(t),this._joinedChrmManager.remove(t)),[2,u]}})})},e.prototype.getChatroomInfo=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l,h;return B(this,function(a){switch(a.label){case 0:return(o=this._channel)?(s=o.codec.encodeGetChatRoomInfo(r,i),u=new te(x[x.queryChrmI],s,t),[4,o.send(u,Mr)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return d=a.sent(),l=d.code,h=d.data,l!==b.SUCCESS?[2,{code:l}]:[2,{code:l,data:h}]}})})},e.prototype.getChatroomHistoryMessages=function(t,r,i,o){return V(this,void 0,void 0,function(){var s,u,d,l,h,a;return B(this,function(c){switch(c.label){case 0:return(s=this._channel)?(u=s.codec.encodeGetHistoryMsg(t,{timestamp:r,count:i,order:o}),d=new te($a,u,t),[4,s.send(d,yn,{conversation:{targetId:t}})]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return l=c.sent(),h=l.code,a=l.data,h!==b.SUCCESS?[2,{code:h}]:[2,{code:h,data:{list:a.list,hasMore:a.hasMore}}]}})})},e.prototype._modifyChatroomKV=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d,l,h,a;return B(this,function(c){switch(c.label){case 0:return o=(i=this)._channel,s=i.currentUserId,o?(u=o.codec.encodeModifyChatRoomKV(t,r,s),d=r.type===xe.UPDATE?od:sd,l=new te(d,u,t),[4,o.send(l)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return h=c.sent(),(a=h.code)===b.SUCCESS?(this._chrmEntryHandler.setLocal(t,{kvEntries:[r],syncTime:new Date().getTime()},s),[2,a]):[2,a]}})})},e.prototype._modifyChatroomKVS=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d,l,h,a,c,p,f,m;return B(this,function(_){switch(_.label){case 0:return o=(i=this)._channel,s=i.currentUserId,o?(u=o.codec.encodeModifyChatRoomKVS(t,r,s),d=r.type===xe.UPDATE?ad:cd,l=new te(d,u,t),[4,o.send(l,Io)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return h=_.sent(),a=h.code,[b.SUCCESS,b.CHATROOM_KV_STORE_NOT_ALL_SUCCESS].indexOf(a)!==-1&&(p=[],delete(f=Object.assign({},r)).entries,r.entries.forEach(function(v){p.push(Object.assign({},v,f))}),a===b.CHATROOM_KV_STORE_NOT_ALL_SUCCESS&&(m=h.data,G.warn("\u8BBE\u7F6E\u5931\u8D25\u7684\u5C5E\u6027\uFF1A",m.errorKeys),c=m.errorKeys,m&&Array.isArray(m.errorKeys)&&m.errorKeys.forEach(function(v){var R=p.findIndex(function(y){return v.key===y.key});R!==-1&&p.splice(R,1)})),G.warn("\u8BBE\u7F6E\u6210\u529F\u7684\u5C5E\u6027\uFF1A",p),this._chrmEntryHandler.setLocal(t,{kvEntries:p,syncTime:new Date().getTime()},s)),[2,{code:a,data:c}]}})})},e.prototype.setChatroomEntry=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return r.type=xe.UPDATE,r.userId=r.userId||this.currentUserId,[2,this._modifyChatroomKV(t,r)]})})},e.prototype.setChatroomEntries=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return r.type=xe.UPDATE,r.userId=r.userId||this.currentUserId,[2,this._modifyChatroomKVS(t,r)]})})},e.prototype.forceSetChatroomEntry=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return r.type=xe.UPDATE,r.isOverwrite=!0,r.userId=r.userId||this.currentUserId,[2,this._modifyChatroomKV(t,r)]})})},e.prototype.removeChatroomEntry=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return r.type=xe.DELETE,r.userId=r.userId||this.currentUserId,[2,this._modifyChatroomKV(t,r)]})})},e.prototype.removeChatroomEntries=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return r.type=xe.DELETE,r.userId=r.userId||this.currentUserId,[2,this._modifyChatroomKVS(t,r)]})})},e.prototype.forceRemoveChatroomEntry=function(t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return r.type=xe.DELETE,r.isOverwrite=!0,r.userId=r.userId||this.currentUserId,[2,this._modifyChatroomKV(t,r)]})})},e.prototype.getChatroomEntry=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d,l,h;return B(this,function(a){switch(a.label){case 0:return(i=this._chrmEntryHandler.getValue(t,r))?[2,Promise.resolve({code:b.SUCCESS,data:i})]:[3,1];case 1:return(o=this._channel)?(s=o.codec.encodePullChatRoomKV(0),u=new te(x[x.pullKV],s,t),[4,o.send(u,Ft)]):[2,Promise.reject({code:b.RC_NET_CHANNEL_INVALID})];case 2:return d=a.sent(),(l=d.data||{})&&l.kvEntries&&l.kvEntries.length&&(h=l.kvEntries.find(function(c){return c.key===r}))!==void 0?[2,Promise.resolve({code:b.SUCCESS,data:h==null?void 0:h.value})]:[2,Promise.resolve({code:b.CHATROOM_KEY_NOT_EXIST})]}})})},e.prototype.getAllChatroomEntry=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l;return B(this,function(h){switch(h.label){case 0:return(r=this._chrmEntryHandler.getAll(t))&&Object.keys(r).length?[2,Promise.resolve({code:b.SUCCESS,data:r})]:[3,1];case 1:return(i=this._channel)?(o={},s=i.codec.encodePullChatRoomKV(0),u=new te(x[x.pullKV],s,t),[4,i.send(u,Ft)]):[2,Promise.reject({code:b.RC_NET_CHANNEL_INVALID})];case 2:return d=h.sent(),(l=d.data||{})&&l.kvEntries&&l.kvEntries.length&&l.kvEntries.forEach(function(a){a.key&&(o[a.key]=a.value||"")}),[2,Promise.resolve({code:b.SUCCESS,data:o})]}})})},e.prototype.pullChatroomEntry=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d,l,h,a,c,p;return B(this,function(f){switch(f.label){case 0:return o=(i=this)._channel,s=i.currentUserId,o?(u=o.codec.encodePullChatRoomKV(r),d=new te(x[x.pullKV],u,t),[4,o.send(d,Ft)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return l=f.sent(),h=l.code,a=l.data,h===b.SUCCESS?(G.info("Pull success ChrmKV, "+JSON.stringify(l)),this._chrmEntryHandler.setLocal(t,a,s),G.info("Save into cache success!"),c=a.kvEntries,p=[],c.length>0&&(c.forEach(function(m){var _=m.key,v=m.value,R=m.type,y=m.timestamp;p.push({key:_,value:v,type:R,timestamp:y,chatroomId:t})}),this._watcher.chatroom({updatedEntries:p})),[2,{code:h,data:a}]):[2,{code:h}]}})})},e.prototype.sendMessage=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l,h,a,c,p,f;return B(this,function(m){switch(m.label){case 0:return this._channel?(i=function(_,v){return _.messageType==="RC:SRSMsg"&&Object.assign(_,{directionalUserIdList:[v]}),_}(i,this.currentUserId),i=this._handleMsgProperties(i,!0),o=!![ee.PRIVATE,ee.GROUP].includes(t)&&i.isStatusMessage,s=o?function(_){var v;return(v={},v[ee.PRIVATE]=x.ppMsgS,v[ee.GROUP]=x.pgMsgS,v)[_]}(t):function(_){var v;return(v={},v[ee.PRIVATE]=x.ppMsgP,v[ee.GROUP]=x.pgMsgP,v[ee.CHATROOM]=x.chatMsg,v[ee.CUSTOMER_SERVICE]=x.pcMsgP,v[ee.RTC_ROOM]=x.prMsgS,v)[_]}(t)||x.ppMsgP,o&&(i.isPersited=!1,i.isCounted=!1),u=this._channel.codec.encodeUpMsg({conversationType:t,targetId:r},i),(d=new en(x[s],u,r)).setHeaderQos(st.AT_LEAST_ONCE),o?(this._channel.sendOnly(d),[2,{code:b.SUCCESS,data:ei(t,r,fe({},i),"",0,this.currentUserId)}]):(l=Date.now()-this._localConnectedTime+this._connectedTime,h=ei(t,r,fe({},i),"",l,this.currentUserId),[4,this._channel.send(d)])):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return a=m.sent(),c=a.code,p=a.data,c!==b.SUCCESS?[2,{code:c,data:h}]:(f=p,this._sendMessageStore.setMessage(f.messageUId,f.timestamp),h.sentTime=f.timestamp,h.messageUId=f.messageUId,this._conversationManager.setConversationCacheByMessage(h,!0),[2,{code:b.SUCCESS,data:h}])}})})},e.prototype.recallMsg=function(t,r,i,o,s){var u;return V(this,void 0,void 0,function(){var d,l,h,a,c,p,f,m,_,v;return B(this,function(R){switch(R.label){case 0:return this._channel?(d=s.user,l={content:{conversationType:t,targetId:r,messageUId:i,sentTime:o,user:d},messageType:"RC:RcCmd",disableNotification:s==null?void 0:s.disableNotification,pushConfig:s==null?void 0:s.pushConfig,pushContent:((u=s.pushConfig)===null||u===void 0?void 0:u.pushContent)||s.pushContent||"",channelId:s.channelId},h=x[x.recallMsg],a=this._channel.codec.encodeUpMsg({conversationType:t,targetId:r},l),(c=new en(h,a,this.currentUserId)).setHeaderQos(st.AT_LEAST_ONCE),[4,this._channel.send(c)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return p=R.sent(),f=p.code,m=p.data,f!==b.SUCCESS?[2,{code:f}]:(_=m,this._sendMessageStore.setMessage(_.messageUId,_.timestamp),v=ei(t,r,fe(fe({},l),{isPersited:!0}),_.messageUId,_.timestamp,this.currentUserId),this._conversationManager.setConversationCacheByMessage(v,!0),[2,{code:b.SUCCESS,data:v}])}})})},e.prototype.sendReadReceiptMessage=function(t,r,i){return V(this,void 0,void 0,function(){var o,s;return B(this,function(u){switch(u.label){case 0:return this._channel?(o=this._channel.codec.encodeReadReceipt(r,i),s=new te(x[x.rrMsg],o,t),[4,this._channel.send(s)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return[2,u.sent()]}})})},e.prototype.getMessageReader=function(t,r,i){return V(this,void 0,void 0,function(){var o,s;return B(this,function(u){switch(u.label){case 0:return this._channel?(o=this._channel.codec.encodeMessageReader(r,i),s=new te(x[x.rrList],o,t),[4,this._channel.send(s,Ur)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return[2,u.sent()]}})})},e.prototype.pullUserSettings=function(t){return V(this,void 0,void 0,function(){var r,i;return B(this,function(o){return this._channel?(r=this._channel.codec.encodePullUserSetting(t),i=new te(x[x.pullUS],r,this.currentUserId),[2,this._channel.send(i,Lr)]):[2,{code:b.RC_NET_CHANNEL_INVALID}]})})},e.prototype.getFileToken=function(t,r,i,o){return V(this,void 0,void 0,function(){var s,u,d,l,h,a;return B(this,function(c){switch(c.label){case 0:return this._channel?(s=o&&o!=="uploads"?r||"":$u(t,r),u=this._channel.codec.encodeGetFileToken(t,s,i||"",o||""),d=new te(x[x.qnTkn],u,this.currentUserId),[4,this._channel.send(d,vo)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return l=c.sent(),h=l.code,a=l.data,a=Object.assign(a,{fileName:s}),h===b.SUCCESS?[2,{code:h,data:a}]:[2,{code:h}]}})})},e.prototype.getFileUrl=function(t,r,i,o){return V(this,void 0,void 0,function(){var s,u,d,l,h,a,c,p,f;return B(this,function(m){switch(m.label){case 0:return this._channel?(s="",u="",d="",r===De.QINIU?(u=Ro,d=yo):(u=Co,d=Eo),s=r===De.QINIU?x[x.qnUrl]:r===De.AWS?x[x.s3Url]:r===De.STC?x[x.stcUrl]:x[x.aliUrl],l=this._channel.codec.encodeGetFileUrl(u,t,i,o),h=new te(s,l,this.currentUserId),[4,this._channel.send(h,d)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return a=m.sent(),c=a.code,p=a.data,f=p,c===b.SUCCESS?[2,{code:c,data:f}]:[2,{code:c}]}})})},e.prototype.disconnect=function(){this._reconnectTimer!==-1&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=-1),this._channel&&(this._channel.close(),this._channel=void 0),this._pullQueue.length=0,this._stopSyncInterval()},e.prototype.destroy=function(){throw new Error("JSEngine's method not implemented.")},e.prototype.registerMessageType=function(t,r,i,o){this._customMessageType[t]={isPersited:r,isCounted:i}},e.prototype.getServerTime=function(){return Date.now()-this._localConnectedTime+this._connectedTime},e.prototype.getCurrentUserId=function(){return this.currentUserId},e.prototype.createTag=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l;return B(this,function(h){switch(h.label){case 0:return this._channel?(r=this._userSettingManager.getVersion(),i=this._channel.codec.encodeCreateTag([t],r),o=new te(x[x.addSeTag],i,this.currentUserId),[4,this._channel.send(o,$t)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return s=h.sent(),u=s.code,d=s.data,u!==b.SUCCESS?[2,{code:u}]:(l=d.version,this._userSettingManager.addTag([fe(fe({},t),{createdTime:l})],l),[2,{code:b.SUCCESS,data:d}])}})})},e.prototype.removeTag=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l;return B(this,function(h){switch(h.label){case 0:return this._channel?(r=this._userSettingManager.getVersion(),i=this._channel.codec.encodeRemoveTag([t],r),o=new te(x[x.delSeTag],i,this.currentUserId),[4,this._channel.send(o,$t)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return s=h.sent(),u=s.code,d=s.data,u!==b.SUCCESS?[2,{code:u}]:(l=d.version,this._userSettingManager.deleteTag([t],l),[2,{code:b.SUCCESS}])}})})},e.prototype.updateTag=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l;return B(this,function(h){switch(h.label){case 0:return this._channel?(r=this._userSettingManager.getVersion(),i=this._channel.codec.encodeCreateTag([t],r),o=new te(x[x.addSeTag],i,this.currentUserId),[4,this._channel.send(o,$t)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return s=h.sent(),u=s.code,d=s.data,u!==b.SUCCESS?[2,{code:u}]:(l=d.version,this._userSettingManager.addTag([t],l),[2,{code:b.SUCCESS,data:d}])}})})},e.prototype.getTagList=function(){return V(this,void 0,void 0,function(){var t,r;return B(this,function(i){return t=this._userSettingManager.getTags(),r=this._conversationManager.getConversationListForTag(),t.forEach(function(o){o.conversationCount=r[o.tagId]?r[o.tagId].length:0}),[2,{code:b.SUCCESS,data:t}]})})},e.prototype.addTagForConversations=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d=this;return B(this,function(l){switch(l.label){case 0:return this._channel?this._userSettingManager.getTagById(t)?(i=this._channel.codec.encodeUpdateConversationTag([{tagId:t}],r),o=new te(x[x.addTag],i,this.currentUserId),[4,this._channel.send(o)]):[2,{code:b.TAG_NOT_EXIST}]:[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return(s=l.sent().code)!==b.SUCCESS?[2,{code:s}]:((u={})[t]={},r.forEach(function(h){d._conversationManager.addTagStatus(h.conversationType,h.targetId,u,h.channelId)}),[2,{code:b.SUCCESS}])}})})},e.prototype.removeTagForConversations=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u=this;return B(this,function(d){switch(d.label){case 0:return this._channel?(i=this._channel.codec.encodeUpdateConversationTag([{tagId:t}],r),o=new te(x[x.delTag],i,this.currentUserId),[4,this._channel.send(o)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return(s=d.sent().code)!==b.SUCCESS?[2,{code:s}]:(r.forEach(function(l){u._conversationManager.deleteTagStatus(l.conversationType,l.targetId,[t],l.channelId)}),[2,{code:b.SUCCESS}])}})})},e.prototype.removeTagsForConversation=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d,l,h;return B(this,function(a){switch(a.label){case 0:return this._channel?(i=t.conversationType,o=t.targetId,s=t.channelId,u=r.map(function(c){return{tagId:c}}),d=this._channel.codec.encodeUpdateConversationTag(u,[t]),l=new te(x[x.delTag],d,this.currentUserId),[4,this._channel.send(l)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return(h=a.sent().code)!==b.SUCCESS?[2,{code:h}]:(this._conversationManager.deleteTagStatus(i,o,r,s),[2,{code:b.SUCCESS}])}})})},e.prototype.getConversationListByTag=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l,h,a,c,p;return B(this,function(f){switch(f.label){case 0:return s=(o=this).currentUserId,(u=o._channel)?(d=u.codec.encodeOldConversationList({count:i,type:ee.PRIVATE,startTime:r}),l=new te(ys,d,s),[4,u.send(l,En,{currentUserId:s,connectedTime:u.connectedTime})]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return h=f.sent(),a=h.code,c=h.data,p=this._conversationHasTagFilter(t,c),G.info("GetConversationListByTag",p),a!==b.SUCCESS?[2,{code:a}]:[2,{code:a,data:p}]}})})},e.prototype._conversationHasTagFilter=function(t,r){var i=this,o=[],s=[];function u(d,l){return d.latestMessage&&l.latestMessage?d.latestMessage.sentTime-l.latestMessage.sentTime:0}return r.forEach(function(d){var l=d.conversationType,h=d.targetId,a=d.channelId,c=i._conversationManager.get(l,h,a),p=c.hasMentioned,f=c.mentionedInfo,m=c.lastUnreadTime,_=c.notificationStatus,v=c.isTop,R=c.tags,y=c.unreadMessageCount,P=R&&R[t];if(P){var L=fe(fe({},d),{hasMentioned:p,mentionedInfo:f,lastUnreadTime:m,notificationStatus:_,isTop:v,unreadMessageCount:y});P.isTop?o.push(fe(fe({},L),{isTopInTag:!0})):s.push(fe(fe({},L),{isTopInTag:!1}))}}),bt(bt([],o.sort(u)),s.sort(u))},e.prototype.getUnreadCountByTag=function(t,r){return V(this,void 0,void 0,function(){var i;return B(this,function(o){return this._channel?(i=this._conversationManager.getUnreadCountByTag(t,r),[2,{code:b.SUCCESS,data:i}]):[2,{code:b.RC_NET_CHANNEL_INVALID}]})})},e.prototype.setConversationStatusInTag=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l,h,a,c,p,f;return B(this,function(m){switch(m.label){case 0:return this._channel?(o=r.targetId,s=r.conversationType,u=r.channelId,d=i.isTop,l=[{tagId:t,isTop:d}],(h=this._conversationManager.get(s,o,u)).tags&&Object.hasOwnProperty.call(h.tags,t)?(a=this._channel.codec.encodeUpdateConversationTag(l,[r]),c=new te(x[x.addTag],a,this.currentUserId),[4,this._channel.send(c)]):[2,{code:b.NO_TAG_IN_CONVER}]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return(p=m.sent().code)!==b.SUCCESS?[2,{code:p}]:((f={})[t]={},d&&(f[t].isTop=!0),this._conversationManager.addTagStatus(s,o,f,u),[2,{code:b.SUCCESS}])}})})},e.prototype.getTagsForConversation=function(t){var r;return V(this,void 0,void 0,function(){var i,o,s,u;return B(this,function(d){if(!this._channel)return[2,{code:b.RC_NET_CHANNEL_INVALID}];if(i=this._conversationManager.get(t.conversationType,t.targetId,t.channelId),o=this._userSettingManager.getTagsInfo(),s=[],i.tags)for(u in i.tags)s.push({tagId:u,tagName:(r=o[u])===null||r===void 0?void 0:r.tagName});return[2,{code:b.SUCCESS,data:s}]})})},e.prototype.getBlockConversationList=function(){var t=this._conversationManager.getBlockConversationList();return Promise.resolve({code:b.SUCCESS,data:t})},e.prototype.getTopConversationList=function(){var t=this._conversationManager.getTopConversationList();return Promise.resolve({code:b.SUCCESS,data:t})},e.prototype.getUnreadMentionedCount=function(t){var r=this._conversationManager.getUnreadMentionedCount(t.channelId,t.conversationType,t.targetId);return Promise.resolve({code:b.SUCCESS,data:r})},e.prototype.getAllUnreadMentionedCount=function(){var t=this._conversationManager.getAllUnreadMentionedCount();return Promise.resolve({code:b.SUCCESS,data:t})},e.prototype.joinRTCRoom=function(t,r,i,o){return V(this,void 0,void 0,function(){var s,u;return B(this,function(d){return this._channel?(s=this._channel.codec.encodeJoinRTCRoom(r,i,o),u=new te(x[x.rtcRJoin_data],s,t),[2,this._channel.send(u,It)]):[2,{code:b.RC_NET_CHANNEL_INVALID}]})})},e.prototype.quitRTCRoom=function(t){return V(this,void 0,void 0,function(){var r,i;return B(this,function(o){switch(o.label){case 0:return this._channel?(r=this._channel.codec.encodeQuitRTCRoom(),i=new te(x[x.rtcRExit],r,t),[4,this._channel.send(i)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,o.sent().code]}})})},e.prototype.rtcPing=function(t,r,i){return V(this,void 0,void 0,function(){var o,s;return B(this,function(u){switch(u.label){case 0:return this._channel?(o=this._channel.codec.encodeJoinRTCRoom(r,i),s=new te(x[x.rtcPing],o,t),[4,this._channel.send(s)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,u.sent().code]}})})},e.prototype.getRTCRoomInfo=function(t){return V(this,void 0,void 0,function(){var r,i;return B(this,function(o){return this._channel?(r=this._channel.codec.encodeGetRTCRoomInfo(),i=new te(x[x.rtcRInfo],r,t),[2,this._channel.send(i,Aa)]):[2,{code:b.RC_NET_CHANNEL_INVALID}]})})},e.prototype.getRTCUserInfoList=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u;return B(this,function(d){switch(d.label){case 0:return this._channel?(r=this._channel.codec.encodeGetRTCRoomInfo(),i=new te(x[x.rtcUData],r,t),[4,this._channel.send(i,It)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return o=d.sent(),s=o.code,u=o.data,[2,{code:s,data:u&&{users:u.users}}]}})})},e.prototype.setRTCUserInfo=function(t,r,i){return V(this,void 0,void 0,function(){var o,s;return B(this,function(u){switch(u.label){case 0:return this._channel?(o=this._channel.codec.encodeSetRTCUserInfo(r,i),s=new te(x[x.rtcUPut],o,t),[4,this._channel.send(s)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,u.sent().code]}})})},e.prototype.removeRTCUserInfo=function(t,r){return V(this,void 0,void 0,function(){var i,o;return B(this,function(s){switch(s.label){case 0:return this._channel?(i=this._channel.codec.encodeRemoveRTCUserInfo(r),o=new en(x[x.rtcUDel],i,t),[4,this._channel.send(o)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,s.sent().code]}})})},e.prototype.setRTCData=function(t,r,i,o,s,u){return V(this,void 0,void 0,function(){var d,l;return B(this,function(h){switch(h.label){case 0:return this._channel?(d=this._channel.codec.encodeSetRTCData(r,i,o,s,u),l=new en(x[x.rtcSetData],d,t),[4,this._channel.send(l)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,h.sent().code]}})})},e.prototype.setRTCTotalRes=function(t,r,i,o,s){return V(this,void 0,void 0,function(){var u,d;return B(this,function(l){switch(l.label){case 0:return this._channel?(u=this._channel.codec.encodeUserSetRTCData(r,i,o,s),d=new te(x[x.userSetData],u,t),[4,this._channel.send(d)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,l.sent().code]}})})},e.prototype.setRTCCDNUris=function(t,r,i){return V(this,void 0,void 0,function(){var o,s;return B(this,function(u){switch(u.label){case 0:return this._channel?(o=this._channel.codec.encodeUserSetRTCCDNUris(r,i),s=new te(x[x.userSetData],o,t),[4,this._channel.send(s)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,u.sent().code]}})})},e.prototype.getRTCData=function(t,r,i,o){if(!this._channel)return Promise.resolve({code:b.RC_NET_CHANNEL_INVALID});var s=this._channel.codec.encodeGetRTCData(r,i,o),u=new te(x[x.rtcQryData],s,t);return this._channel.send(u,Pr)},e.prototype.removeRTCData=function(t,r,i,o,s){return V(this,void 0,void 0,function(){var u,d;return B(this,function(l){switch(l.label){case 0:return this._channel?(u=this._channel.codec.encodeRemoveRTCData(r,i,o,s),d=new en(x[x.rtcDelData],u,t),[4,this._channel.send(d)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,l.sent().code]}})})},e.prototype.setRTCOutData=function(t,r,i,o){throw new Error("JSEngine's method not implemented.")},e.prototype.getRTCOutData=function(t,r){throw new Error("JSEngine's method not implemented.")},e.prototype.getRTCToken=function(t,r,i){return V(this,void 0,void 0,function(){var o,s;return B(this,function(u){return this._channel?(o=this._channel.codec.encodeJoinRTCRoom(r,i),s=new te(x[x.rtcToken],o,t),[2,this._channel.send(s,Ar)]):[2,{code:b.RC_NET_CHANNEL_INVALID}]})})},e.prototype.setRTCState=function(t,r){return V(this,void 0,void 0,function(){var i,o;return B(this,function(s){switch(s.label){case 0:return this._channel?(i=this._channel.codec.encodeSetRTCState(r),o=new te(x[x.rtcUserState],i,t),[4,this._channel.send(o)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return[2,s.sent().code]}})})},e.prototype.getRTCUserInfo=function(t){return V(this,void 0,void 0,function(){return B(this,function(r){throw new Error("Method not implemented.")})})},e.prototype.getRTCUserList=function(t){if(!this._channel)return Promise.resolve({code:b.RC_NET_CHANNEL_INVALID});var r=this._channel.codec.encodeGetRTCRoomInfo(),i=new te(x[x.rtcUList],r,t);return this._channel.send(i,It)},e.prototype.joinLivingRoomAsAudience=function(t,r,i){return r===void 0&&(r=Le.LIVE),V(this,void 0,void 0,function(){var o,s,u,d,l,h,a,c;return B(this,function(p){switch(p.label){case 0:return this._channel?(o=this._channel.codec.encodeJoinRTCRoom(r,i),s=new te(x[x.viewerJoinR],o,t),[4,this._channel.send(s,Va)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return u=p.sent(),d=u.code,l=u.data,d!==b.SUCCESS?[2,{code:d}]:(a=(h=l).rtcToken,c=h.entries,[2,{code:d,data:{token:a,kvEntries:c}}])}})})},e.prototype.quitLivingRoomAsAudience=function(t){return V(this,void 0,void 0,function(){var r,i,o;return B(this,function(s){switch(s.label){case 0:return this._channel?(r=this._channel.codec.encodeQuitRTCRoom(),i=new te(x[x.viewerExitR],r,t),[4,this._channel.send(i)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return o=s.sent().code,this._rtcKVManager.reset(),[2,o]}})})},e.prototype.rtcIdentityChange=function(t,r,i){return V(this,void 0,void 0,function(){var o,s,u,d,l;return B(this,function(h){switch(h.label){case 0:return this._channel?(o=this._channel.codec.encodeIdentityChangeInfo(r,i),s=new te(x[x.rtcIdentityChange],o,t),[4,this._channel.send(s,It)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return u=h.sent(),d=u.code,l=u.data,d!==b.SUCCESS?[2,{code:d}]:[2,{code:d,data:l}]}})})},e.prototype.pullRTCRoomEntry=function(t,r){return V(this,void 0,void 0,function(){var i,o,s,u,d,l,h,a,c;return B(this,function(p){switch(p.label){case 0:return o=(i=this)._channel,s=i.currentUserId,o?(G.info("audience in room start pull KV"),u=o.codec.encodePullRTCRoomKV(t,0),d=new te(x[x.rtcPullKv],u,s),[4,o.send(d,xr)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return l=p.sent(),h=l.code,a=l.data,G.info("audience in room end pull KV, code: "+h+", data: "+JSON.stringify(a||{})),h===b.SUCCESS?(c=a.kvEntries,this._watcher.onRTCDataChange(c,t),[2,{code:h,data:a}]):[2,{code:h}]}})})},e.prototype.getRTCJoinedUserInfo=function(t){return V(this,void 0,void 0,function(){var r,i,o,s,u,d,l,h;return B(this,function(a){switch(a.label){case 0:return i=(r=this)._channel,o=r.currentUserId,i?(s=i.codec.encodeQueryUserJoinedInfo(t),u=new te(x[x.rtcQueryJoined],s,o),[4,i.send(u,Vr)]):[2,{code:b.RC_NET_CHANNEL_INVALID}];case 1:return d=a.sent(),l=d.code,h=d.data,l===b.SUCCESS?[2,{code:l,data:h}]:[2,{code:l}]}})})},e.prototype.getDeviceId=function(){return Xa(this.runtime)},e.prototype.requestRoomPK=function(t){return V(this,void 0,void 0,function(){var r,i,o;return B(this,function(s){switch(s.label){case 0:return this._channel?(r=this._channel.codec.encodeRequestRoomPK(t),i=new te(x[x.rtcInvite],r,t.roomId),[4,this._channel.send(i)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return o=s.sent().code,this._rtcKVManager.reset(),[2,o]}})})},e.prototype.cancelRoomPK=function(t){return V(this,void 0,void 0,function(){var r,i,o;return B(this,function(s){switch(s.label){case 0:return this._channel?(r=this._channel.codec.encodeCancelRoomPK(t),i=new te(x[x.rtcCancelInvite],r,t.roomId),[4,this._channel.send(i)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return o=s.sent().code,this._rtcKVManager.reset(),[2,o]}})})},e.prototype.responseRoomPK=function(t){return V(this,void 0,void 0,function(){var r,i,o;return B(this,function(s){switch(s.label){case 0:return this._channel?(r=this._channel.codec.encodeResponseRoomPK(t),i=new te(x[x.rtcInviteAnswer],r,t.roomId),[4,this._channel.send(i)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return o=s.sent().code,this._rtcKVManager.reset(),[2,o]}})})},e.prototype.endRoomPK=function(t){return V(this,void 0,void 0,function(){var r,i,o;return B(this,function(s){switch(s.label){case 0:return this._channel?(r=this._channel.codec.encodeEndRoomPK(t),i=new te(x[x.rtcEndInvite],r,t.roomId),[4,this._channel.send(i)]):[2,b.RC_NET_CHANNEL_INVALID];case 1:return o=s.sent().code,this._rtcKVManager.reset(),[2,o]}})})},e.prototype.callExtra=function(t){for(var r=[],i=1;i0){var _=u.join("");if(u=[],_.length>26){var v=t.numberEncode(_.length),R=String.fromCharCode(t.dataType.NormalExt|v.length);s.push(R+v)}else{var y=String.fromCharCode(t.dataType.Normal|_.length);s.push(y)}s.push(_)}},l=0;l=h.length)u.push(e.substr(l,h.length)),l+=h.length;else{d();var p=String.fromCharCode(t.dataType.Compressed|a.length<<2|c.length);s.push(p+a+c),l+=h.length}}}d();var f=t.numberEncode(e.length),m=String.fromCharCode(t.dataType.Tail|f.length);return s.push(m+f),s.join("")},n.uncompress=function(e){var t=this,r=0,i="";e:do{var o=e.charCodeAt(r++),s=o&t.dataType.Mark,u=15&o,d=void 0;switch(s){case t.dataType.Compressed:var l=u>>2,h=3&u;if(l===0||h===0)throw new Error("Data parsing error,at "+r);var a=t.numberDecode(e.substr(r,l)),c=t.numberDecode(e.substr(r+=l,h));if((a=i.length-a)+c>i.length)throw new Error("Data parsing error,at "+r);r+=h,i+=i.substr(a,c);break;case t.dataType.Tail:if((d=t.numberDecode(e.substr(r,u)))!==i.length)throw console.log(i.length),console.log(d),new Error("Data parsing error,at "+r);r+=u;break e;case t.dataType.NormalExt:d=t.numberDecode(e.substr(r,u)),i+=e.substr(r+=u,d),r+=d;break;case t.dataType.Normal:i+=e.substr(r,u),r+=u;break;case t.dataType.Mark:if(u>10)throw new Error("Data parsing error,at "+r);i+=e.substr(r,16+u),r+=16+u;break;default:throw new Error("Data parsing error,at "+r+" header:"+s)}}while(r=t.length-1)return i;var o=e[t.charAt(r)+t.charAt(r+1)];if(o[0]===r)return i;for(var s=t.length-r,u=0,d=o.length;uthis.max)){var a=Math.min(s,h);if(a<=i.length)break;if(!(i.length>2&&t.charAt(l+i.length-1)!==t.charAt(r+i.length-1))){for(var c=2,p=c;p=i.length&&(i.length=c,i.offset=l)}}}return i},n.numberEncode=function(e){var t=this,r=[],i=0;do i=e%t.scale,r.push(t.chars.charAt(i)),e=(e-i)/t.scale;while(e>0);return r.join("")},n.numberDecode=function(e){for(var t=0,r=0,i=e.length-1;i>=0;i--){if((r=this.chars.indexOf(e.charAt(i)))===-1)throw new Error('decode number error, data is "'+e+'"');t=t*this.scale+r}return t},n.dataType={Tail:48,Compressed:64,NormalExt:80,Normal:96,Mark:112},n.chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",n.scale=n.chars.length,n.max=238327,n}(),nn=1,rn=!1,Ms=typeof location!="undefined"&&location.protocol==="https://"?"https://":"http://",Bn=function(){function n(e){this.info=e,this.logUrl="logcollection.ronghub.com",this.level=1,this.itv=30,this.times=5,this.deviceId="",this.deviceInfo="",this.logSwitch=0,this.logUrl=e.logPolicy.url||this.logUrl,this.level=e.logPolicy.level||this.level,this.itv=e.logPolicy.itv||this.itv,this.times=e.logPolicy.times||this.times,this.deviceId=Xa(e.runtime),this.logSwitch=e.logSwitch;var t=qu(e.runtime);this.deviceInfo=t.type+"|"+t.version+"|"+Rt.sessionId,this.startReport()}return n.init=function(e){return rn=!0,n._instance||(n._instance=new n(e)),n._instance},n.getInstance=function(){return n._instance},n.prototype.startReport=function(){var e=this;if(this.logSwitch&&rn){var t=this.itv*Math.pow(2,nn-1);nn "+o),e.startReport()})}else this.startReport()},n.prototype.reportFullLog=function(e){return V(this,void 0,void 0,function(){var t,r,i,o,s,u,d,l,h,a,c=this;return B(this,function(p){switch(p.label){case 0:return t=e.startTime,r=e.endTime,i=e.platform,o=e.logId,s=e.uri,u=Gi.getInstance(),G.debug("received report log msg, "+i.toLowerCase(),u),i.toLowerCase()==="web"&&u?t>r?(G.warn("report error: The start time("+t+") cannot be greater than the end time("+t+")"),[2]):[4,G.__insertLogIntoDatabase()]:[2];case 1:return p.sent(),[4,u.getRangeData(Bt,"time",t,r)];case 2:return d=(d=p.sent()).filter(function(f){return!f.userId||f.userId===c.info.userId}),l=ws.compress(d.map(function(f){return f.content}).join("")||"no data"),h=1,(a=function(){if(!(h>3)&&rn){var f=s||c.logUrl,m=""+Ms+f+"?version="+c.info.version+"&appkey="+c.info.appkey+"&userId="+c.info.userId+"&logId="+o+"&deviceId="+c.deviceId+"&deviceInfo="+c.deviceInfo+"&platform=Web",_=5e3*(h-1);h++,setTimeout(function(){rn&&c.info.runtime.httpReq({url:m,method:"POST",body:l}).then(function(){G.debug("report full log success!")}).catch(function(v){a(),G.warn("report full log error -> "+v)})},_)}})(),[2]}})})},n.prototype.distroy=function(){nn=1,rn=!1},n}();function Fn(n){return Object.assign({},n)}var As,Vd=function(){function n(e,t){var r;this._runtime=e,this._token="",this._pluginContextQueue=[],this._pluginInstanseMap={},this.coreVersion="5.1.1",this._versionInfo={},this._typingInfo={},this._isInternalConnected=!1,this._connectionStatus=se.DISCONNECTED,this._canRedirectConnect=!1,this._watcher={message:void 0,batchMessage:void 0,conversationState:void 0,chatroomState:void 0,connectionState:void 0,rtcInnerWatcher:void 0,expansion:void 0,tag:void 0,conversationTagChanged:void 0,pullFinished:void 0,onConnecting:void 0,onConnected:void 0,onDisconnect:void 0,onSuspend:void 0,readReceiptReceived:void 0,messageReceiptRequest:void 0,messageReceiptResponse:void 0,typingState:void 0,messageBlocked:void 0},this._typingInternalTimer=-1,this._typingExpireTime=2e3,this._typingChangedList=[],this.getChatRoomHistoryMessages=this.getChatroomHistoryMessages,this._options=Object.assign({},t),this.appkey=this._options.appkey,this.apiVersion=this._options.apiVersion,this._options.typingExpireTime&&(this._options.typingExpireTime<2e3?this._typingExpireTime=2e3:this._options.typingExpireTime>6e3?this._typingExpireTime=6e3:this._typingExpireTime=this._options.typingExpireTime),this._options.navigators=this._options.navigators.filter(function(o){return/^https?:\/\//.test(o)}),this._options.navigators=this._options.navigators.map(function(o){return o.replace(/\/$/g,"")}),this._options.navigators.length===0&&(r=this._options.navigators).push.apply(r,Au);var i={status:this._connectionStatusListener.bind(this),batchMessage:this._batchMessageReceiver.bind(this),chatroom:this._chatroomInfoListener.bind(this),conversation:this._conversationInfoListener.bind(this),expansion:this._expansionInfoListener.bind(this),tag:this._tagListener.bind(this),conversationTag:this._conversationTagListener.bind(this),onRTCDataChange:this._rtcDataChange.bind(this),pullFinished:this._pullFinishedListener.bind(this)};this._engine=ms()?new RCCppEngine(e,i,this._options):new Ud(e,i,this._options)}return n.init=function(e,t){return G.setLogLevel(t.logLevel),G.setLogStdout(t.logStdout),(t.indexDBSwitch||le(t.indexDBSwitch))&&Gi.init(),G.debug("APIContext.init =>",t.appkey,t.navigators),this._context?(G.error("Repeat initialize!"),this._context):(G.warn("RCEngine Commit:","41dbe38d1b376ca0a791b23ed94be291e3f92e81"),this._context=new n(e,t),G.__insertLogIntoDatabase(),this._context)},n.destroy=function(){this._context&&(this._context._destroy(),this._context=void 0)},n.prototype.install=function(e,t){if(this._pluginInstanseMap[e.tag])return G.warn("Repeat install plugin: "+e.tag),this._pluginInstanseMap[e.tag];var r=e.tag==="RCRTC"?new xd(this):new ec(this),i=null;try{if(!e.verify(this._runtime))return null;i=e.setup(r,this._runtime,t)}catch(o){G.error(`install plugin error!
`,o)}return["RCRTC","RCCall"].includes(e.tag)&&e.version&&e.name&&(this._versionInfo[e.name]=e.version),i&&this._pluginContextQueue.push(r),i&&(this._pluginInstanseMap[e.tag]=i),i},n.prototype._handleRedirect=function(){return V(this,void 0,void 0,function(){var e=this;return B(this,function(t){switch(t.label){case 0:return G.debug("_handleRedirct",this._token),[4,this.connect(this._token,!0)];case 1:return t.sent().code!==b.SUCCESS&&this._canRedirectConnect&&(this._handleSuspend(),setTimeout(function(){e._handleRedirect()},5e3)),[2]}})})},n.prototype._connectionStatusListener=function(e){var t;return V(this,void 0,void 0,function(){return B(this,function(r){return e===se.REDIRECT?(this._canRedirectConnect=!0,this._handleSuspend(),this._handleRedirect()):e===se.BLOCKED||e===se.KICKED_OFFLINE_BY_OTHER_CLIENT||e===se.DISCONNECT_BY_SERVER?(this._canRedirectConnect=!1,this._handleDisconnect()):e===se.CONNECTING?this._handleConnecting():e===se.CONNECTED?this._handleConnected():e===se.DISCONNECTED?this._handleDisconnect():e===se.NETWORK_UNAVAILABLE&&this._handleSuspend(),this._connectionStatus=e,((t=this._watcher.rtcInnerWatcher)===null||t===void 0?void 0:t.status)&&this._watcher.rtcInnerWatcher.status(e),this._pluginContextQueue.forEach(function(i){i.onconnectionstatechange&&i.onconnectionstatechange(e)}),this._watcher.connectionState&&this._watcher.connectionState(e),[2]})})},n.prototype._handleConnecting=function(){this._watcher.onConnecting&&this._watcher.onConnecting()},n.prototype._handleConnected=function(){this._watcher.onConnected&&this._watcher.onConnected()},n.prototype._handleDisconnect=function(){this._watcher.onDisconnect&&this._watcher.onDisconnect()},n.prototype._handleSuspend=function(){this._watcher.onSuspend&&this._watcher.onSuspend()},n.prototype._messageReceiver=function(e,t,r){var i,o,s;if((e.conversationType===ee.RTC_ROOM||Object.prototype.hasOwnProperty.call(Vu,e.messageType))&&this._watcher.rtcInnerWatcher&&this._watcher.rtcInnerWatcher.message)this._watcher.rtcInnerWatcher.message(Fn(e));else if(["RC:ChrmJoinNtf","RC:ChrmQuitNtf"].indexOf(e.messageType)===-1||typeof this._watcher.chatroomState!="function"){if(e.messageType!=="RC:ChrmMemChange"){if(e.messageType!==Ae.TYPING_STATUS||(this._addTypingInfo(Fn(e)),!this._watcher.typingState))if(e.messageType!==Ae.LOG_COMMAND||e.senderUserId!=="rongcloudsystem")if(e.messageType!==Ae.INTERCEPT){if(!this._pluginContextQueue.some(function(v){if(!v.onmessage)return!1;try{return v.onmessage(Fn(e))}catch(R){return G.error("plugin error =>",R),!1}}))if(e.messageType!=="RC:ReadNtf")if(e.messageType!=="RC:RRReqMsg"){if(e.messageType!=="RC:RRRspMsg")return this._watcher.message&&this._watcher.message(Fn(e),t,r),e;var u=(s=e.content)===null||s===void 0?void 0:s.receiptMessageDic;u&&Array.isArray(u[this._engine.currentUserId])&&typeof this._watcher.messageReceiptResponse=="function"&&this._watcher.messageReceiptResponse({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId},e.senderUserId,u[this._engine.currentUserId])}else typeof this._watcher.messageReceiptRequest=="function"&&this._watcher.messageReceiptRequest({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId},e.content.messageUId,e.senderUserId);else typeof this._watcher.readReceiptReceived=="function"&&this._watcher.readReceiptReceived({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId},e.content.messageUId,e.content.lastMessageSendTime)}else this._MessageBlockedListener({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId||"",blockType:e.content.interceptType,blockedMessageUId:e.content.msgUId});else{var d=e.content,l=d.startTime,h=d.endTime,a=d.platform,c=d.logId,p=d.uri,f=d.packageName,m={startTime:parseInt(l),endTime:parseInt(h),platform:a,logId:c,uri:p,packageName:f};(o=Bn.getInstance())===null||o===void 0||o.reportFullLog(m)}}else if(typeof this._watcher.chatroomState=="function"){var _={};Array.isArray(e.content.userList)&&e.content.userList.forEach(function(v){_[v.userId]=v.status}),this._watcher.chatroomState({userChange:{users:_,chatroomId:e.targetId}})}}else this._watcher.chatroomState({userChange:{users:(i={},i[e.senderUserId]=e.messageType==="RC:ChrmQuitNtf"?hs.QUIT:hs.JOIN,i),chatroomId:e.targetId}})},n.prototype._batchMessageReceiver=function(e,t,r){var i=this,o=[];e.forEach(function(s){var u=i._messageReceiver(s,t,r);u&&o.push(u)}),o.length&&this._watcher.batchMessage&&this._watcher.batchMessage(o)},n.prototype._chatroomInfoListener=function(e){this._watcher.chatroomState&&this._watcher.chatroomState(e)},n.prototype._conversationInfoListener=function(e){this._watcher.conversationState&&this._watcher.conversationState(e)},n.prototype._expansionInfoListener=function(e){this._watcher.expansion&&this._watcher.expansion(e)},n.prototype._tagListener=function(){this._watcher.tag&&this._watcher.tag()},n.prototype._conversationTagListener=function(){this._watcher.conversationTagChanged&&this._watcher.conversationTagChanged()},n.prototype._typingStatusListener=function(e){this._watcher.typingState&&this._watcher.typingState(e)},n.prototype._pullFinishedListener=function(){this._watcher.pullFinished&&this._watcher.pullFinished()},n.prototype._MessageBlockedListener=function(e){this._watcher.messageBlocked&&this._watcher.messageBlocked(e)},n.prototype._rtcDataChange=function(e,t){this._pluginContextQueue.forEach(function(r){r.onrtcdatachange&&r.onrtcdatachange(e,t)})},n.prototype.assignWatcher=function(e){var t=this;Object.keys(this._watcher).forEach(function(r){if(Object.prototype.hasOwnProperty.call(e,r)){var i=e[r];t._watcher[r]=sr(i)||Ne(i)?i:void 0}})},n.prototype.resetWatcher=function(){var e=this;Object.keys(this._watcher).forEach(function(t){e._watcher[t]=void 0})},n.prototype._addTypingInfo=function(e){var t=e.senderUserId,r=e.conversationType,i=e.targetId,o=e.content,s=e.channelId,u=o.typingContentType,d=r+"#"+i+"#"+(s||"");this._typingInfo[d]||(this._typingInfo[d]=[]);var l=this._typingInfo[d].findIndex(function(h){return h.userId===t});l>=0&&this._typingInfo[d][l].messageType===u?this._typingInfo[d][l].timestamp=Date.now():(l>=0&&this._typingInfo[d].splice(l,1),this._typingInfo[d].push({userId:t,messageType:u,timestamp:Date.now()}),this._typingChangedList.includes(d)||this._typingChangedList.push(d),this._startCheckTypingInfo())},n.prototype._startCheckTypingInfo=function(){var e=this;this._typingInternalTimer===-1&&Object.keys(this._typingInfo).length!==0&&(this._typingInternalTimer=setInterval(function(){for(var t in e._typingInfo){var r=e._typingInfo[t].length;e._typingInfo[t]=e._typingInfo[t].filter(function(o){return Date.now()-o.timestamp0){var i=e._typingChangedList.map(function(o){return{conversationType:Number(o.split("#")[0]),targetId:o.split("#")[1],channelId:o.split("#")[2],list:e._typingInfo[o]||[]}});e._typingStatusListener(i),e._typingChangedList=[]}Object.keys(e._typingInfo).length===0&&(clearInterval(e._typingInternalTimer),e._typingInternalTimer=-1)},500))},n.prototype.getConnectedTime=function(){return this._engine.getConnectedTime()},n.prototype.getServerTime=function(){return this._engine.getServerTime()},n.prototype.getDeviceId=function(){return this._engine.getDeviceId()},n.prototype.getCurrentUserId=function(){return this._engine.currentUserId},n.prototype.getConnectionStatus=function(){return this._connectionStatus},Object.defineProperty(n.prototype,"token",{get:function(){return this._token},enumerable:!1,configurable:!0}),n.prototype.connect=function(e,t){return t===void 0&&(t=!1),V(this,void 0,void 0,function(){var r,i,o,s,u,d;return B(this,function(l){switch(l.label){case 0:return this._connectionStatus===se.CONNECTED?[2,{code:b.SUCCESS,userId:this._engine.currentUserId}]:this._connectionStatus===se.CONNECTING?[2,{code:b.BIZ_ERROR_CONNECTING}]:typeof e!="string"||e.length===0?[2,{code:b.RC_CONN_USER_OR_PASSWD_ERROR}]:(this._token=e,r=e.split("@"),i=r[1],o=i?i.split(";").map(function(h){return/^https?:/.test(h)?h:"https://"+h}):[],[4,this._engine.navi.getInfo(this._getTokenWithoutNavi(),o,t,this._options.checkCA)]);case 1:return(s=l.sent())?(s==null?void 0:s.type)===1?[2,{code:b.PACKAGE_ENVIRONMENT_ERROR}]:(u=Ot.getInfo(),[4,this._engine.connect(this._getTokenWithoutNavi(),s)]):[2,{code:b.RC_NAVI_RESOURCE_ERROR}];case 2:return d=l.sent(),G.__insertLogIntoDatabase(),d!==we.REDIRECT?[3,4]:(this._connectionStatus=se.REDIRECT,[4,this.connect(e,!0)]);case 3:return[2,l.sent()];case 4:return d===b.SUCCESS&&(G.info("connect success, userId: "+this._engine.currentUserId),(s==null?void 0:s.type)!==1&&this._engine.reportSDKInfo&&this._engine.reportSDKInfo(u),Bn.init({runtime:this._runtime,logSwitch:(s==null?void 0:s.logSwitch)||0,logPolicy:JSON.parse((s==null?void 0:s.logPolicy)||"{}"),appkey:this.appkey,version:this.apiVersion,userId:this._engine.currentUserId}),Rt.init(this._engine.currentUserId),this._isInternalConnected=!0),d!==b.SUCCESS||ms()||s.openUS===1&&this._pullUserSettings(),d!==b.SUCCESS&&(this._connectionStatus=se.CONNECTION_CLOSED),[2,{code:d,userId:this._engine.currentUserId}]}})})},n.prototype._pullUserSettings=function(){return V(this,void 0,void 0,function(){return B(this,function(e){return[2]})})},n.prototype.disconnect=function(){var e;return this._isInternalConnected=!1,clearInterval(this._typingInternalTimer),this._typingInternalTimer=-1,(e=Bn.getInstance())===null||e===void 0||e.distroy(),G.__insertLogIntoDatabase(),Rt.reset(),this._engine.disconnect(),this._pluginContextQueue.forEach(function(t){if(t.ondisconnect)try{t.ondisconnect()}catch(r){G.error("plugin error =>",r)}}),Promise.resolve()},n.prototype.reconnect=function(){return this._isInternalConnected?Promise.resolve({code:b.CAN_NOT_RECONNECT}):this.connect(this._getTokenWithoutNavi())},n.prototype._getTokenWithoutNavi=function(){return this._token.replace(/@.+$/,"@")},n.prototype.getInfoFromCache=function(){return this._engine.navi.getInfoFromCache(this._getTokenWithoutNavi())},n.prototype.registerMessageType=function(e,t,r,i){i===void 0&&(i=[]),this._engine.registerMessageType(e,t,r,i)},n.prototype.sendMessage=function(e,t,r,i){var o=this.getInfoFromCache();if(((o==null?void 0:o.grpRRVer)||0)===1&&r.messageType===Ae.READ_RECEIPT_RESPONSE)return Promise.resolve({code:b.READ_RECEIPT_ERROR});var s=JSON.stringify(r.content);return Ta(s)>131072?Promise.resolve({code:b.RC_MSG_CONTENT_EXCEED_LIMIT}):this._engine.sendMessage(e,t,r,i)},n.prototype.sendExpansionMessage=function(e){return V(this,void 0,void 0,function(){var t,r,i,o,s,u,d,l,h,a,c,p,f,m;return B(this,function(_){switch(_.label){case 0:if(t=e.channelId,r=e.conversationType,i=e.targetId,o=e.messageUId,s=e.keys,u=e.expansion,d=e.removeAll,!e.canIncludeExpansion)return[2,{code:b.MESSAGE_KV_NOT_SUPPORT}];if(l=!1,h=!1,a=!1,Ne(u)){for(p in c=Object.keys(u).length,l=c>20,u)if(f=u[p],h=Be(p)&&!/^[A-Za-z0-9_=+-]+$/.test(p),(a=p.length>32||f.length>64)||h)break}return l||a?[2,{code:b.EXPANSION_LIMIT_EXCEET}]:h?[2,{code:b.BIZ_ERROR_INVALID_PARAMETER}]:(m={mid:o},u&&(m.put=u),s&&(m.del=s),d&&(m.removeAll=1),[4,this._engine.sendMessage(r,i,{content:m,messageType:Ae.EXPANSION_NOTIFY,channelId:t})]);case 1:return[2,{code:_.sent().code}]}})})},n.prototype.sendReadReceiptMessage=function(e,t,r){return V(this,void 0,void 0,function(){var i;return B(this,function(o){return i=this.getInfoFromCache(),((i==null?void 0:i.grpRRVer)||0)===0?[2,{code:b.READ_RECEIPT_ERROR,data:"The read receipt switch is not on, please call the sendMessage method!"}]:[2,this._engine.sendReadReceiptMessage(e,t,r)]})})},n.prototype.getMessageReader=function(e,t,r){return V(this,void 0,void 0,function(){var i;return B(this,function(o){return i=this.getInfoFromCache(),((i==null?void 0:i.grpRRVer)||0)===0?[2,{code:b.READ_RECEIPT_ERROR}]:[2,this._engine.getMessageReader(e,t,r)]})})},n.prototype._destroy=function(){var e;this._isInternalConnected=!1,this._watcher={batchMessage:void 0,message:void 0,conversationState:void 0,chatroomState:void 0,connectionState:void 0,rtcInnerWatcher:void 0,expansion:void 0,tag:void 0,conversationTagChanged:void 0,typingState:void 0,pullFinished:void 0,onConnecting:void 0,onConnected:void 0,onDisconnect:void 0,onSuspend:void 0},this._engine.disconnect(),this._pluginContextQueue.forEach(function(t){if(t.ondestroy)try{t.ondestroy()}catch(r){G.error("plugin error =>",r)}}),this._pluginContextQueue.length=0,this._pluginInstanseMap={},(e=Bn.getInstance())===null||e===void 0||e.distroy(),Rt.reset()},n.prototype.getHistoryMessage=function(e,t,r,i,o,s,u){return r===void 0&&(r=0),i===void 0&&(i=20),o===void 0&&(o=0),s===void 0&&(s=""),u===void 0&&(u=""),this._engine.getHistoryMessage(e,t,r,i,o,s,u||"")},n.prototype.getConversationList=function(e,t,r,i,o){return e===void 0&&(e=300),o===void 0&&(o=""),this._engine.getConversationList(e,t,r,i,o)},n.prototype.getConversation=function(e,t,r){return this._engine.getConversation(e,t,r)},n.prototype.removeConversation=function(e,t,r){return r===void 0&&(r=""),this._engine.removeConversation(e,t,r)},n.prototype.clearUnreadCount=function(e,t,r){return r===void 0&&(r=""),this._engine.clearConversationUnreadCount(e,t,r)},n.prototype.clearAllUnreadCount=function(){return this._engine.clearAllUnreadCount()},n.prototype.getUnreadCount=function(e,t,r){return r===void 0&&(r=""),this._engine.getConversationUnreadCount(e,t,r)},n.prototype.getTotalUnreadCount=function(e,t,r){return this._engine.getAllConversationUnreadCount(e,t&&t.length>0?t:[ee.PRIVATE,ee.GROUP,ee.SYSTEM,ee.PUBLIC_SERVICE],!!r)},n.prototype.getFirstUnreadMessage=function(e,t,r){return r===void 0&&(r=""),this._engine.getFirstUnreadMessage(e,t,r)},n.prototype.setConversationStatus=function(e,t,r,i,o){o===void 0&&(o="");var s=[{conversationType:e,targetId:t,isTop:r,notificationStatus:i,channelId:o}];return this._engine.batchSetConversationStatus(s)},n.prototype.saveConversationMessageDraft=function(e,t,r,i){return i===void 0&&(i=""),this._engine.saveConversationMessageDraft(e,t,r,i)},n.prototype.getConversationMessageDraft=function(e,t,r){return r===void 0&&(r=""),this._engine.getConversationMessageDraft(e,t,r)},n.prototype.clearConversationMessageDraft=function(e,t,r){return r===void 0&&(r=""),this._engine.clearConversationMessageDraft(e,t,r)},n.prototype.recallMessage=function(e,t,r,i,o){return this._engine.recallMsg(e,t,r,i,o)},n.prototype.deleteRemoteMessage=function(e,t,r,i){return i===void 0&&(i=""),this._engine.deleteRemoteMessage(e,t,r,i)},n.prototype.deleteRemoteMessageByTimestamp=function(e,t,r,i){return i===void 0&&(i=""),this._engine.deleteRemoteMessageByTimestamp(e,t,r,i)},n.prototype.joinChatroom=function(e,t){return t===void 0&&(t=10),this._engine.joinChatroom(e,t)},n.prototype.joinExistChatroom=function(e,t){return t===void 0&&(t=10),this._engine.joinExistChatroom(e,t)},n.prototype.quitChatroom=function(e){return this._engine.quitChatroom(e)},n.prototype.getChatroomInfo=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=0),this._engine.getChatroomInfo(e,t,r)},n.prototype.setChatroomEntry=function(e,t){var r=t.key,i=t.value;return Lt(r)&&zr(i)?this._engine.setChatroomEntry(e,t):Promise.resolve(b.BIZ_ERROR_INVALID_PARAMETER)},n.prototype.setChatroomEntries=function(e,t){for(var r=0;r1e3?[2,Promise.reject(b.CONVER_OUT_LIMIT_ERROR)]:[2,this._engine.addTagForConversations(e,t)]})})},n.prototype.removeTagForConversations=function(e,t){return V(this,void 0,void 0,function(){return B(this,function(r){return[2,this._engine.removeTagForConversations(e,t)]})})},n.prototype.removeTagsForConversation=function(e,t){return V(this,void 0,void 0,function(){return B(this,function(r){return[2,this._engine.removeTagsForConversation(e,t)]})})},n.prototype.getConversationListByTag=function(e,t,r,i){return V(this,void 0,void 0,function(){return B(this,function(o){return[2,this._engine.getConversationListByTag(e,t,r,i)]})})},n.prototype.getUnreadCountByTag=function(e,t){return V(this,void 0,void 0,function(){return B(this,function(r){return[2,this._engine.getUnreadCountByTag(e,t)]})})},n.prototype.setConversationStatusInTag=function(e,t,r){return V(this,void 0,void 0,function(){return B(this,function(i){return[2,this._engine.setConversationStatusInTag(e,t,r)]})})},n.prototype.getTagsForConversation=function(e){return V(this,void 0,void 0,function(){return B(this,function(t){return[2,this._engine.getTagsForConversation(e)]})})},n.prototype.getBlockConversationList=function(){return this._engine.getBlockConversationList()},n.prototype.getTopConversationList=function(){return this._engine.getTopConversationList()},n.prototype.getUnreadMentionedCount=function(e){return this._engine.getUnreadMentionedCount(e)},n.prototype.getAllUnreadMentionedCount=function(){return this._engine.getAllUnreadMentionedCount()},n.prototype.callExtra=function(e){for(var t,r=[],i=1;i0&&i[i.length-1])||h[0]!==6&&h[0]!==2)){s=0;continue}if(h[0]===3&&(!i||h[1]>i[0]&&h[1]"+t),[4,ze.imClient.context.joinChatroom(n,e.count)];case 1:return(r=i.sent())!==b.SUCCESS?(ke.warn("join chatroom fail ->code+:"+Kt[r]+","+t),[2,{code:r,msg:Kt[r]}]):[2,{code:r}]}})})}var tc=function(n,e,t,r){t===void 0&&(t=!0),r===void 0&&(r=!0),this.messageType=n,this.content=e,this.isPersited=t,this.isCounted=r};function qe(n,e,t){return e===void 0&&(e=!0),t===void 0&&(t=!0),function(r){return new tc(n,r,e,t)}}var nc,Ni,Qd=qe("RC:ImgMsg"),Xd=qe("RC:HQVCMsg"),el=qe("RC:SightMsg"),tl=qe("RC:TxtMsg"),nl=qe("RC:CombineMsg"),rl=qe("RC:FileMsg");qe("RC:GIFMsg");qe("RC:VcMsg");qe("RC:LBSMsg");qe("RC:ReferenceMsg");qe("RC:ImgTextMsg");var Dt={qiniu:function(n,e,t,r){var i,o="https://"+e.uploadHost.qiniu;i=sn()+pe[0][1]||o,pe.shift();var s=new XMLHttpRequest;s.upload&&e.support_options&&(s.upload.onprogress=function(u){t.onProgress(u.loaded,u.total)}),s.onreadystatechange=function(){if(s.readyState===4){var u=s.responseText||"{}";(u=JSON.parse(u)).filename=e.uniqueValue,u.uploadMethod=De?De.QINIU:"",s.status===200?t.onCompleted(u):pe.length?Dt[pe[0][0]](n,e,t,r):t.onError("upload fail")}},e.isChunk&&(i=function(u,d){var l="";return Gs(d,function(h,a){h!=="token"&&(l+=(l?"&":"")+encodeURIComponent(h)+"="+encodeURIComponent(a))}),l&&(u+=(u.indexOf("?")>0?"&":"?")+l),u}(i+="/mkblk/"+n.size,e.multi_parmas)),s.open(e.method,i,!0),t.onOpen(s),e.stream&&s.setRequestHeader("authorization","UpToken "+e.multi_parmas.token),Gs(e.headers,function(u,d){s.setRequestHeader(u,d)}),s.send(n)},baidu:function(n,e,t,r){if(console.log(r,e),r.size>qs)throw new Error("the file size is over 5GB!");var i=e||{};e=e||Ni;var o=new XMLHttpRequest,s=sn();if(!(!i.uploadHost.bos&&!i.bosUploadPath)){var u=s+pe[0][1]+i.bosUploadPath;pe.shift();var d=i.bosHeader||{},l={filename:e.uniqueValue||r.uniqueName,name:r.name,downloadUrl:u,isBosRes:!0};o.upload&&e.support_options&&(o.upload.onprogress=function(h){t.onProgress(h.loaded,h.total,!0)}),o.onreadystatechange=function(){if(o.readyState===4){var h=o.responseText||"{}";(h=JSON.parse(h)).filename=e.uniqueValue,o.status===200?t.onCompleted(l,!0):pe.length?Dt[pe[0][0]](n,e,t,r):t.onError("upload fail")}},o.open(e.method,u,!0),o.setRequestHeader("authorization",d.bosToken),o.setRequestHeader("x-bce-date",d.bosDate),o.send(r)}},aliyun:function(n,e,t,r){if(r.size>qs)throw new Error("the file size is over 5GB!");const i=new FormData;i.set("file",n.get("file")),i.set("key",n.get("key")),i.set("token",n.get("token"));const o=pe[0][1];pe.shift(),n=n||nc,e=(e=e||{})||Ni;var s=new XMLHttpRequest,u=sn()+e.ossBucketName+"."+o;s.upload&&e.support_options&&(s.upload.onprogress=function(l){t.onProgress(l.loaded,l.total)}),s.onreadystatechange=function(){if(s.readyState===4){var l=s.responseText||"{}";(l=JSON.parse(l)).name=e.uniqueValue,l.filename=e.uploadFileName,l.uploadMethod=De?De.ALI:"",s.status===200?t.onCompleted(l):pe.length?Dt[pe[0][0]](i,e,t,r):t.onError("upload fail")}},s.open(e.method,u,!0),console.log("ali:url",u);var d=e.aliHeader||{};n.set("OSSAccessKeyId",d.osskeyId),n.set("policy",d.ossPolicy),n.set("Signature",d.ossSign),n.set("success_action_status",200),n.delete("key"),n.append("key",e.uploadFileName),n.delete("file"),n.append("file",r),s.send(n)},s3:function(n,e,t,r){var i=new FormData,o=new XMLHttpRequest,s=sn();const u=pe[0][1];var d=s+e.s3BucketName+"."+u;console.log("uploadS3:url",d),pe.shift(),o.upload&&e.support_options&&(o.upload.onprogress=function(a){t.onProgress(a.loaded,a.total)}),o.onreadystatechange=function(){if(o.readyState===4){var a=o.responseText||"{}";if((a=JSON.parse(a)).name=e.uniqueValue,a.filename=e.uploadFileName,a.uploadMethod=De.AWS,console.log("UploadMethod:",De),o.status===200||o.status===204)t.onCompleted(a);else if(pe.length){const c=new FormData;c.set("file",n.get("file")),c.set("key",n.get("key")),c.set("token",n.get("token")),Dt[pe[0][0]](c,e,t,r)}else t.onError("upload fail")}},o.open(e.method,d,!0);var l=e?e.s3Header:{},h=r&&r.type;h==="text/html"?i.set("Content-Disposition","inline;"):i.set("Content-Disposition","attachment;"),i.set("Content-Type",h),i.set("x-amz-credential",l.s3Credential),i.set("x-amz-algorithm",l.s3Algorithm),i.set("x-amz-date",l.s3Date),i.set("policy",l.s3Policy),i.set("x-amz-signature",l.s3Signature),i.set("key",e.uploadFileName),i.set("file",r),o.send(i)},stc:function(n,e,t,r){new FormData;var i=new XMLHttpRequest;sn();var o="https://"+pe[0][1]+"/"+e.stcBucketName+"/"+e.uploadFileName;pe.shift(),i.upload&&e.support_options&&(i.upload.onprogress=function(u){t.onProgress(u.loaded,u.total)}),i.onreadystatechange=function(){if(i.readyState===4){var u=i.responseText||"{}";if((u=JSON.parse(u)).name=e.uniqueValue,u.filename=e.uploadFileName,u.uploadMethod=De?De.STC:"",i.status===200||i.status===204)t.onCompleted(u);else if(pe.length){const d=new FormData;d.set("file",n.get("file")),d.set("key",n.get("key")),d.set("token",n.get("token")),Dt[pe[0][0]](d,e,t,r)}else t.onError("upload fail")}},i.open("PUT",o,!0);var s=e?e.stcHeader:{};i.setRequestHeader("Content-Type",r.type),r.type==="text/html"?i.setRequestHeader("Content-Disposition","inline;"):i.setRequestHeader("Content-Disposition","attachment;"),i.setRequestHeader("Authorization",s.stcAuthorization),i.setRequestHeader("x-amz-content-sha256",s.stcContentSha256),i.setRequestHeader("x-amz-date",s.stcDate),i.send(r)}},pe=[],qs=5368709120;function Gs(n,e){for(var t in n)e(t,n[t])}function sn(){var n="https://";return location.protocol!=="http:"&&location.protocol!=="file:"||(n="http://"),n}function il(n,e,t){var r,i,o=n&&n.type||"text/plain",s=o.indexOf("image")>-1?1:4,u=Math.ceil(n.size/e.stc_chunk_size),d=e&&JSON.parse(e.ossConfig?e.ossConfig:"");Array.isArray(d)||(d=[]);var l=d.find(m=>Object.keys(m).includes("stc")),h="uploads";ze.imClient.getFileToken(s,r,"POST",h).then(function(m){r=m.fileName,i="https://"+l.stc+"/"+e.stcBucketName+"/"+r,console.log("uploadStcMultipart:url",i);var _=new XMLHttpRequest;_.open("POST",i+"?"+h,!0),o==="text/html"?_.setRequestHeader("Content-Disposition","inline;"):_.setRequestHeader("Content-Disposition","attacshment;"),_.setRequestHeader("Authorization",m&&m.stcAuthorization),_.setRequestHeader("x-amz-content-sha256",m&&m.stcContentSha256),_.setRequestHeader("x-amz-date",m&&m.stcDate),_.setRequestHeader("Content-Type",o),_.send(),_.onreadystatechange=function(v){if(_.readyState===4){var R=_.response.match(/(?:)(\S*?)(?:<\/UploadId>)/);console.log("uploadId",R),_.status===200||_.status===204?function(y){for(var P=[],L=1;L<=u;L++)P.push(f(y,L));p(y,P)}(Array.isArray(R)&&R[1]):t.onError("uploadStcMultipart:did not get uploadId")}}},function(m){t.onError("uploadStcMultipart:"+m)});var a=[],c=new Map;function p(m,_){_&&Array.isArray(_)&&_.length!==0&&Promise.all(_).then(()=>{var v="uploadId="+m;if(c.size===u)ze.imClient.context.getFileToken(s,r,"POST",v).then(function(P){console.log("onSuccess",P),console.log("onSuccess:uploadId",m);var L=new XMLHttpRequest;L.open("POST",i+"?"+v,!0),L.setRequestHeader("Authorization",P&&P.stcAuthorization),L.setRequestHeader("x-amz-content-sha256",P&&P.stcContentSha256),L.setRequestHeader("x-amz-date",P&&P.stcDate),L.setRequestHeader("Content-Type",o);var N="",E=Array.from(c.keys()||[]).sort((A,F)=>A-F);console.log("keys",E),E.map(A=>{N+=`${c.get(A)}${A}`}),N+="",L.send(N),console.log("xml",N),L.onreadystatechange=function(){if(L.readyState===4)if(L.status===200||L.status===204){var A={};A.name=n.name,A.filename=e.uploadFileName,A.uploadMethod=De.STC,t.onCompleted(A)}else t.onError("uploadStcMultipart:upload does not end")}},function(P){t.onError("uploadStcMultipart:"+P)});else{var R=[];for(var y of a)R.push(f(m,y));p(m,R)}},v=>{console.error(v),t.onError("uploadStcMultipart: chunkFiles upload failed and those will reupload");var R=[];for(var y of a)R.push(f(m,y));p(m,R)})}function f(m,_){return new Promise((v,R)=>{var y="partNumber="+_+"&uploadId="+m;ze.imClient.context.getFileToken(s,r,"PUT",y).then(function(P){console.log("signature "+_+" onSuccess",P);var L=n&&n.slice((_-1)*e.stc_chunk_size,_*e.stc_chunk_size);console.log("fileChunk:size",L.size);var N=new XMLHttpRequest;N.open("PUT",i+"?"+y,!0),N.setRequestHeader("Authorization",P&&P.stcAuthorization),N.setRequestHeader("x-amz-content-sha256",P&&P.stcContentSha256),N.setRequestHeader("x-amz-date",P&&P.stcDate),N.setRequestHeader("Content-Type",o),N.send(L),N.onreadystatechange=function(){if(N.readyState===4)if(N.status===200||N.status===204){var E=N.getResponseHeader("etag");console.log("etag:"+_,E),c.set(_,E),v(E)}else a.includes(_)||a.push(_),R(_)}},function(P){console.log("getETags:\u7B7E\u540D\u9A8C\u8BC1\u5931\u8D25"),a.includes(_)||a.push(_),R(_)})})}}var rc={form:function(n,e){var t=new FormData;if(e.unique_key){var r=n.name.substr(n.name.lastIndexOf(".")),i=wi()+r;t.append(e.unique_key,i),e.uniqueValue=i}return t.append(e.file_data_name,n),Mi(e.multi_parmas,function(o,s){t.append(o,s)}),t},json:function(n,e){var t={};if(e.unique_key){var r=n.name.substr(n.name.lastIndexOf(".")),i=wi()+r;t[e.unique_key]=i,e.uniqueValue=i}return t[e.file_data_name]=n,Mi(e.multi_parmas,function(o,s){t[o]=s}),JSON.stringify(t)},data:function(n,e){return n}};function wi(){var n=new Date().getTime();return"xxxxxx4xxxyxxxxxxx".replace(/[xy]/g,function(e){var t=(n+16*Math.random())%16|0;return n=Math.floor(n/16),(e==="x"?t:3&t|8).toString(16)})}function Mi(n,e){for(var t in n)e(t,n[t])}var Gn,ti=0;function ol(n){this.options=function(e){var t={domain:"",method:"POST",file_data_name:"file",unique_key:"key",base64_size:4194304,chunk_size:4194304,bos_chunk_size:4294967296,stc_chunk_size:10485760,headers:{},multi_parmas:{},query:{},support_options:!0,data:rc.form,genUId:wi};if(!e||!e.domain)throw new Error("domain is null");for(var r in e)t[r]=e[r];return t}(n),this.setOptions=function(e){var t=this;Mi(e,function(r,i){t.options[r]=i})},console.log("options",n),this.upload=function(e,t){if(e){var r=this;(function(i,o,s){if(nc=i,Ni=o,pe=[],o.ossConfig){const h=JSON.parse(o.ossConfig);let a,c,p="";const f=[];h.forEach(m=>{const _=Number(m.p)-1;for(const v in m)v==="aliyun"&&(p=m[v]),v==="s3"&&(a=m[v]),v==="stc"&&(c=m[v]),v!=="p"&&(f[_]=[v,m[v]])}),f.forEach(function(m){m&&pe.push(m)}),h.length!==pe.length&&(pe=[["qiniu",o.domain],["baidu",o.uploadHost.bos],["aliyun",p],["s3",a],["stc",c]])}else pe=[["qiniu",o.domain],["baidu",o.uploadHost.bos]];var u;if(o.ossConfig){var d=o&&JSON.parse(o.ossConfig);Array.isArray(d)||(d=[]),u=d.find(h=>Object.keys(h).includes("stc"))}if(u&&parseInt(u.p)===1&&i.size>=4194304)il(i,o,s);else{var l=o.data(i,o);Dt[pe[0][0]](l,o,s,i)}})(e,this.options,{onProgress:function(i,o,s){Gn=i,s?Gn=ti+i/o*(o-ti):ti=Gn,t.onProgress(Gn,o)},onCompleted:function(i){t.onCompleted(i)},onError:function(i){t.onError(i)},onOpen:function(i){r.xhr=i}})}else t.onError("upload file is null.")},this.cancel=function(){this.xhr&&this.xhr.abort()}}var Ys={init:function(n){return new ol(n)},dataType:rc,resize:function(n,e,t){n.type;var r=document.createElement("canvas"),i=new FileReader;i.readAsDataURL(n),i.onload=function(o){var s=o.target.result,u=new Image;u.src=s;var d=u.width,l=u.height,h=function(c,p){var f=1,m=c.width,_=p.maxWidth||0;_>0&&m>_&&(f=_/m);var v=c.height,R=p.maxHeight||0;if(R>0&&v>R){var y=R/v;f=Math.min(f,y)}var P=p.maxSize||0,L=Math.ceil(c.size/1e3);if(L>P){var N=P/L;f=Math.min(f,N)}return f}({width:d,height:l,size:o.total},e),a=s;h<1&&(a=function(c,p,f){r.width=p,r.height=f,r.getContext("2d").drawImage(c,0,0,p,f);var m="image/jpg";return r.toDataURL(m)}(u,d*h,l*h)),t(a)}}};const sl=function(n,e,t){var r=document.createElement("canvas"),i=r.getContext("2d"),o=new Image;o.onload=function(){var s=function(l,h,a){var c,p,f,m=la.scale?(m?(p=100,v=((f=h/(c=l/100))-a.maxHeight)/2):(f=100,_=((p=l/(c=h/100))-a.maxWidth)/2),{w:p,h:f,x:-_,y:-v}):(m?(c=h/a.maxHeight,f=a.maxHeight,p=l/c):(c=l/a.maxWidth,p=a.maxWidth,f=h/c),{w:p,h:f,x:-_,y:-v})}(o.width,o.height,e);r.width=s.w>e.maxWidth?e.maxWidth:s.w,r.height=s.h>e.maxHeight?e.maxHeight:s.h,i.drawImage(o,s.x,s.y,s.w,s.h);try{var u=r.toDataURL(n.type,e.quality),d=new RegExp("^data:image/[^;]+;base64,");u=u.replace(d,""),t(u)}catch(l){throw new Error(l)}},o.src=typeof n=="string"?"data:image/jpg;base64,"+n:function(s){var u=window.URL||window.webkitURL;return u?u.createObjectURL(s):""}(n)},al=function(n,e){var t=n.file,r=n.compress;sl(t,r,e)},ic=function(n,e){if(n.getToken)n.getToken(function(r,i){i=i||{},n.multi_parmas||(n.multi_parmas={}),n.multi_parmas.token=r,n.uploadHost||(n.uploadHost={}),n.uploadHost.bos=i.bos,n.ossConfig=i.ossConfig,n.bosHeader||(n.bosHeader={}),n.bosHeader.bosDate=i.bosDate,n.bosHeader.bosToken=i.bosToken,n.bosUploadPath=i.path,n.aliHeader={},n.aliHeader.osskeyId=i.osskeyId,n.aliHeader.ossPolicy=i.ossPolicy,n.aliHeader.ossSign=i.ossSign,n.ossBucketName=i.ossBucketName,n.uploadFileName=i.fileName,n.s3Header={},n.s3Header.s3Credential=i.s3Credential,n.s3Header.s3Algorithm=i.s3Algorithm,n.s3Header.s3Date=i.s3Date,n.s3Header.s3Policy=i.s3Policy,n.s3Header.s3Signature=i.s3Signature,n.s3BucketName=i.s3BucketName,n.stcHeader={},n.stcHeader.stcAuthorization=i.stcAuthorization,n.stcHeader.stcContentSha256=i.stcContentSha256,n.stcHeader.stcDate=i.stcDate,n.stcBucketName=i.stcBucketName,n.headers||(n.headers={}),n.base64&&(n.headers["Content-type"]="application/octet-stream",n.headers.Authorization="UpToken "+r),console.log("data",i);var o=Ys.init(n);e(o)});else{n.headers||(n.headers={}),n.base64&&(n.headers["Content-type"]="application/octet-stream");var t=Ys.init(n);e(t)}};var ni,Yn,oc=function(n,e,t){e.upload(n.file,{onError:function(r){t.onError(r)},onProgress:function(r,i){t.onProgress(r,i)},onCompleted:function(r){r.filename||(r.filename=r.hash);var i=n.compressThumbnail||al;n.compress?i(n,function(o){r.thumbnail=o,t.onCompleted(r)}):t.onCompleted(r)}})},cl=function(n){var e=this;this.instance=n,this.upload=function(t,r){oc({file:t},e.instance,r)},this.cancel=function(){e.instance.cancel()}},ul=function(n,e){var t=this;this.cfg=e,this.instance=n,this.upload=function(r,i){var o={file:r,compress:t.cfg};oc(o,t.instance,i)},this.cancel=function(){t.instance.cancel()}},dl=function(n,e){ic(n,function(t){var r={maxHeight:n.maxHeight||160,maxWidth:n.maxWidth||160,quality:n.quality||.5,scale:n.scale||2.4},i=new ul(t,r);e(i)})},ll=function(n,e){ic(n,function(t){var r=new cl(t);e(r)})},hl=dl;function zs(n){return ni=ni||new AudioContext,new Promise(function(e,t){ni.decodeAudioData(n,function(r){e({duration:r.duration,length:r.length})},t)})}function pl(n,e,t,r,i){return Ie("fileType",n,xu,!0),Ie("filename",e,Ee.STRING),Ie("saveName",t,Ee.STRING),Ie("serverType",i,Ee.NUMBER),new Promise(function(o){ze.imClient.context.getFileUrl(n,e,t,r,i).then(function(s){o({code:b.SUCCESS,data:s})}).catch(function(s){o({code:s})})})}function sc(n,e,t){return In(this,void 0,void 0,function(){var r,i,o,s,u,d,l,h,a;return bn(this,function(c){switch(c.label){case 0:return t=t||{},e instanceof tc?(Ie("conversation.channelId",n==null?void 0:n.channelId,Ee.CHANNEL_ID),r=n.conversationType,i=n.targetId,o=n.channelId,s="conversationType:"+r+",targetId:"+i,ke.debug("send message ->"+s),(u=Object.assign(t,e)).channelId=o||"",[4,ze.imClient.context.sendMessage(r,i,u)]):(ke.warn("send message fail -> message parameter is not an instance of BaseMessage"),[2,vr.ILLGAL_PARAMS]);case 1:return d=c.sent(),l=d.code,h=d.data,l===b.SUCCESS?(a=_r(h),[2,{code:l,data:a}]):(ke.warn("send message fail ->"+l+":"+Kt[l]+","+s),[2,{code:l,msg:Kt[l],data:_r({isMentioned:!!t.isMentioned,content:e.content,messageType:e.messageType,isPersited:e.isPersited||!1,isCounted:e.isCounted||!1,disableNotification:!!(t==null?void 0:t.disableNotification),canIncludeExpansion:!!(t==null?void 0:t.canIncludeExpansion),expansion:(t==null?void 0:t.expansion)||null,conversationType:r,targetId:i,channelId:o||"",senderUserId:ze.imClient.context.getCurrentUserId(),messageUId:"",messageDirection:je.SEND,isOffLineMessage:!1,sentTime:(h==null?void 0:h.sentTime)||0,receivedTime:0,isStatusMessage:t.isStatusMessage||!1,receivedStatus:_n.UNREAD})}])}})})}function Pn(n,e){return function(t,r,i,o){return new Promise(function(s){var u;(function(d,l,h,a){var c,p=this;if(l===void 0&&(l=Se.FILE),c=l===Se.IMAGE?Se.IMAGE:Se.FILE,!Yn){Yn="upload.qiniup.com";var f=ze.imClient.context.getInfoFromCache();if(f&&f.ossConfig)try{var m=JSON.parse(f.ossConfig).find(function(v){return v.qiniu!==void 0});m&&(Yn=m.qiniu)}catch{}}var _=Oi({domain:Yn,getToken:function(v){ze.imClient.context.getFileToken(c).then(function(R){v(R.token,R)}).catch(function(R){h.onFail(R)})}},a);(c===Se.IMAGE?hl:ll)(_,function(v){v.upload(d,{onProgress:function(R,y){var P,L=Math.floor(R/y*100);(P=h.onProgress)===null||P===void 0||P.call(h,L)},onCompleted:function(R){return In(p,void 0,void 0,function(){var y=this;return bn(this,function(P){return pl(c,R.filename,R.name,R,R.uploadMethod).then(function(L){return In(y,void 0,void 0,function(){var N,E;return bn(this,function(A){return L.code!==0?(h.onFail(L),[2]):((N=L.data).type=d.type,N.name=R.name||R.filename,l===Se.AUDIO?(typeof d.arrayBuffer=="function"?d.arrayBuffer().then(zs).then(function(F){Object.assign(N,F),h.onSuccess(N)},function(){h.onSuccess(N)}):((E=new FileReader).onload=function(){E.result?zs(E.result).then(function(F){Object.assign(N,F),h.onSuccess(N)},function(){h.onSuccess(N)}):h.onSuccess(N)},E.onerror=function(){N.duration=0,h.onSuccess(N)},E.readAsArrayBuffer(d)),[2]):(c===Se.IMAGE&&(N.thumbnail=R.thumbnail),h.onSuccess(N),[2]))})})}).catch(function(L){h.onFail(L)}),[2]})})},onError:function(R){h.onFail(R)}})})})(r.file,n,{onProgress:i==null?void 0:i.onProgress,onSuccess:function(d){var l,h=((l=i==null?void 0:i.onComplete)===null||l===void 0?void 0:l.call(i,{url:d.downloadUrl}))||e(d,r);sc(t,h,o).then(s)},onFail:function(d){s({code:b.UPLOAD_FILE_FAILED,msg:d||b[b.UPLOAD_FILE_FAILED]})}},((u=o)===null||u===void 0?void 0:u.thumbnailConfig)||{})})}}Pn(Se.FILE,function(n,e){return new rl({name:n.name,size:e.file.size,type:e.file.type,fileUrl:n.downloadUrl,user:e.user,extra:e.extra})});Pn(Se.IMAGE,function(n,e){return new Qd({content:n.thumbnail,imageUri:n.downloadUrl,user:e.user,extra:e.extra})});Pn(Se.AUDIO,function(n,e){return new Xd({remoteUrl:n.downloadUrl,duration:n.duration,type:n.type,user:e.user,extra:e.extra})});Pn(Se.SIGHT,function(n,e){return new el({sightUrl:n.downloadUrl,content:e.thumbnail,duration:e.duration,size:e.file.size||n.size,name:e.name||n.name,user:e.user,extra:e.extra})});function ct(n,e,t,r){return Ie("messageType",n,Ee.STRING,!0),Ie("isPersited",e,Ee.BOOLEAN,!0),Ie("isCounted",t,Ee.BOOLEAN,!0),ze.imClient.context.registerMessageType(n,e,t,r),qe(n,e,t)}Pn(Se.COMBINE_HTML,function(n,e){return new nl({remoteUrl:n.downloadUrl,nameList:e.nameList,summaryList:e.summaryList,conversationType:e.conversationType,user:e.user,extra:e.extra})});Ot.add("imlib","5.1.1"),Ot.validEngine("~5.1.1")||ke.error("The current engine version '"+Ot.getInfo().engine+"' error\uFF0Cimlib required engine version at least '~5.1.1'.");/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function H(n,e,t,r){return new(t||(t=Promise))(function(i,o){function s(l){try{d(r.next(l))}catch(h){o(h)}}function u(l){try{d(r.throw(l))}catch(h){o(h)}}function d(l){var h;l.done?i(l.value):(h=l.value,h instanceof t?h:new t(function(a){a(h)})).then(s,u)}d((r=r.apply(n,e||[])).next())})}const M=new Rt("RCRTC");var w,Ai;(function(n){n[n.SUCCESS=1e4]="SUCCESS",n[n.SIGNAL_DISCONNECTED=5e4]="SIGNAL_DISCONNECTED",n[n.PARAMS_ERROR=50001]="PARAMS_ERROR",n[n.REPERT_JOIN_ROOM=50002]="REPERT_JOIN_ROOM",n[n.NOT_IN_ROOM=50003]="NOT_IN_ROOM",n[n.SERVICE_INVALID=50004]="SERVICE_INVALID",n[n.RTC_TOKEN_INVALID=50006]="RTC_TOKEN_INVALID",n[n.SIGNAL_ERROR=53001]="SIGNAL_ERROR",n[n.CREATE_OFFER_FAILED=53003]="CREATE_OFFER_FAILED",n[n.REQUEST_FAILED=53004]="REQUEST_FAILED",n[n.MCU_SERVER_NOT_FOUND=53005]="MCU_SERVER_NOT_FOUND",n[n.BROADCAST_SUB_LIST_NOT_EMPTY=53007]="BROADCAST_SUB_LIST_NOT_EMPTY",n[n.ROOM_HAS_BEEN_DESTROYED=53008]="ROOM_HAS_BEEN_DESTROYED",n[n.NOT_OPEN_VIDEO_AUDIO_SERVER=53009]="NOT_OPEN_VIDEO_AUDIO_SERVER",n[n.GET_USER_MEDIA_FAILED=53010]="GET_USER_MEDIA_FAILED",n[n.GET_DISPLAY_MEDIA_FAILED=53011]="GET_DISPLAY_MEDIA_FAILED",n[n.PERMISSION_DENIED=53012]="PERMISSION_DENIED",n[n.CREATE_CUSTOM_TRACK_FAILED=53013]="CREATE_CUSTOM_TRACK_FAILED",n[n.INVALID_TAGS=53014]="INVALID_TAGS",n[n.INVALID_USER_ID=53015]="INVALID_USER_ID",n[n.CREATE_FILE_TRACK_FAILED=53016]="CREATE_FILE_TRACK_FAILED",n[n.INVALID_FILE_INSTANCE=53017]="INVALID_FILE_INSTANCE",n[n.SET_REMOTE_DESCRIPTION_FAILED=53018]="SET_REMOTE_DESCRIPTION_FAILED",n[n.BROWSER_NOT_SUPPORT=53019]="BROWSER_NOT_SUPPORT",n[n.TRACK_NOT_READY=53020]="TRACK_NOT_READY",n[n.VIDEO_TRACK_MISS_MEDIA_ELEMENT=53021]="VIDEO_TRACK_MISS_MEDIA_ELEMENT",n[n.TRACK_PLAY_ERROR=53022]="TRACK_PLAY_ERROR",n[n.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED=53023]="SIGNAL_AUDIENCE_JOIN_ROOM_FAILED",n[n.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED=53024]="SIGNAL_ROOM_CHANGE_IDENTITY_FAILED",n[n.PACKAGE_ENVIRONMENT_ERROR=53025]="PACKAGE_ENVIRONMENT_ERROR",n[n.PUBLISH_TRACK_LIMIT_EXCEEDED=53026]="PUBLISH_TRACK_LIMIT_EXCEEDED",n[n.CDN_RESOURCE_IS_EMPTY=53027]="CDN_RESOURCE_IS_EMPTY",n[n.SIGNAL_JOIN_RTC_ROOM_REFUSED=53028]="SIGNAL_JOIN_RTC_ROOM_REFUSED",n[n.NO_PERMISSION_TO_USE_REQUESTED_DEVICE=53029]="NO_PERMISSION_TO_USE_REQUESTED_DEVICE",n[n.THE_FUNCTION_IS_DISABLED_IN_PKROOM=53030]="THE_FUNCTION_IS_DISABLED_IN_PKROOM"})(w||(w={})),function(n){n[n.JOIN_REFUSED=40032]="JOIN_REFUSED"}(Ai||(Ai={}));class ac{constructor(){this.queue=[],this.locked=!1}checkToStart(){return H(this,void 0,void 0,function*(){if(this.queue.length===0||this.locked)return;this.locked=!0;const{resolve:e,task:t,reject:r}=this.queue.shift();let i;try{i=yield t(),e(i)}catch(o){r(o)}this.locked=!1,this.checkToStart()})}push(e){const t=new Promise((r,i)=>{this.queue.push({resolve:r,task:e,reject:i})});return this.checkToStart(),t}}const fl=new ac,ve=n=>fl.push(n);let cc=!0,uc=!0;function an(n,e,t){const r=n.match(e);return r&&r.length>=t&&parseInt(r[t],10)}function Jt(n,e,t){if(!n.RTCPeerConnection)return;const r=n.RTCPeerConnection.prototype,i=r.addEventListener;r.addEventListener=function(s,u){if(s!==e)return i.apply(this,arguments);const d=l=>{const h=t(l);h&&(u.handleEvent?u.handleEvent(h):u(h))};return this._eventMap=this._eventMap||{},this._eventMap[e]||(this._eventMap[e]=new Map),this._eventMap[e].set(u,d),i.apply(this,[s,d])};const o=r.removeEventListener;r.removeEventListener=function(s,u){if(s!==e||!this._eventMap||!this._eventMap[e])return o.apply(this,arguments);if(!this._eventMap[e].has(u))return o.apply(this,arguments);const d=this._eventMap[e].get(u);return this._eventMap[e].delete(u),this._eventMap[e].size===0&&delete this._eventMap[e],Object.keys(this._eventMap).length===0&&delete this._eventMap,o.apply(this,[s,d])},Object.defineProperty(r,"on"+e,{get(){return this["_on"+e]},set(s){this["_on"+e]&&(this.removeEventListener(e,this["_on"+e]),delete this["_on"+e]),s&&this.addEventListener(e,this["_on"+e]=s)},enumerable:!0,configurable:!0})}function gl(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(cc=n,n?"adapter.js logging disabled":"adapter.js logging enabled")}function ml(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(uc=!n,"adapter.js deprecation warnings "+(n?"disabled":"enabled"))}function jo(){if(typeof window=="object"){if(cc)return;typeof console!="undefined"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function Fr(n,e){uc&&console.warn(n+" is deprecated, please use "+e+" instead.")}function Js(n){return Object.prototype.toString.call(n)==="[object Object]"}function dc(n){return Js(n)?Object.keys(n).reduce(function(e,t){const r=Js(n[t]),i=r?dc(n[t]):n[t],o=r&&!Object.keys(i).length;return i===void 0||o?e:Object.assign(e,{[t]:i})},{}):n}function Pi(n,e,t){e&&!t.has(e.id)&&(t.set(e.id,e),Object.keys(e).forEach(r=>{r.endsWith("Id")?Pi(n,n.get(e[r]),t):r.endsWith("Ids")&&e[r].forEach(i=>{Pi(n,n.get(i),t)})}))}function Ws(n,e,t){const r=t?"outbound-rtp":"inbound-rtp",i=new Map;if(e===null)return i;const o=[];return n.forEach(s=>{s.type==="track"&&s.trackIdentifier===e.id&&o.push(s)}),o.forEach(s=>{n.forEach(u=>{u.type===r&&u.trackId===s.id&&Pi(n,u,i)})}),i}const Zs=jo;function lc(n,e){const t=n&&n.navigator;if(!t.mediaDevices)return;const r=function(s){if(typeof s!="object"||s.mandatory||s.optional)return s;const u={};return Object.keys(s).forEach(d=>{if(d==="require"||d==="advanced"||d==="mediaSource")return;const l=typeof s[d]=="object"?s[d]:{ideal:s[d]};l.exact!==void 0&&typeof l.exact=="number"&&(l.min=l.max=l.exact);const h=function(a,c){return a?a+c.charAt(0).toUpperCase()+c.slice(1):c==="deviceId"?"sourceId":c};if(l.ideal!==void 0){u.optional=u.optional||[];let a={};typeof l.ideal=="number"?(a[h("min",d)]=l.ideal,u.optional.push(a),a={},a[h("max",d)]=l.ideal,u.optional.push(a)):(a[h("",d)]=l.ideal,u.optional.push(a))}l.exact!==void 0&&typeof l.exact!="number"?(u.mandatory=u.mandatory||{},u.mandatory[h("",d)]=l.exact):["min","max"].forEach(a=>{l[a]!==void 0&&(u.mandatory=u.mandatory||{},u.mandatory[h(a,d)]=l[a])})}),s.advanced&&(u.optional=(u.optional||[]).concat(s.advanced)),u},i=function(s,u){if(e.version>=61)return u(s);if((s=JSON.parse(JSON.stringify(s)))&&typeof s.audio=="object"){const d=function(l,h,a){h in l&&!(a in l)&&(l[a]=l[h],delete l[h])};d((s=JSON.parse(JSON.stringify(s))).audio,"autoGainControl","googAutoGainControl"),d(s.audio,"noiseSuppression","googNoiseSuppression"),s.audio=r(s.audio)}if(s&&typeof s.video=="object"){let d=s.video.facingMode;d=d&&(typeof d=="object"?d:{ideal:d});const l=e.version<66;if(d&&(d.exact==="user"||d.exact==="environment"||d.ideal==="user"||d.ideal==="environment")&&(!t.mediaDevices.getSupportedConstraints||!t.mediaDevices.getSupportedConstraints().facingMode||l)){let h;if(delete s.video.facingMode,d.exact==="environment"||d.ideal==="environment"?h=["back","rear"]:d.exact!=="user"&&d.ideal!=="user"||(h=["front"]),h)return t.mediaDevices.enumerateDevices().then(a=>{let c=(a=a.filter(p=>p.kind==="videoinput")).find(p=>h.some(f=>p.label.toLowerCase().includes(f)));return!c&&a.length&&h.includes("back")&&(c=a[a.length-1]),c&&(s.video.deviceId=d.exact?{exact:c.deviceId}:{ideal:c.deviceId}),s.video=r(s.video),Zs("chrome: "+JSON.stringify(s)),u(s)})}s.video=r(s.video)}return Zs("chrome: "+JSON.stringify(s)),u(s)},o=function(s){return e.version>=64?s:{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[s.name]||s.name,message:s.message,constraint:s.constraint||s.constraintName,toString(){return this.name+(this.message&&": ")+this.message}}};if(t.getUserMedia=function(s,u,d){i(s,l=>{t.webkitGetUserMedia(l,u,h=>{d&&d(o(h))})})}.bind(t),t.mediaDevices.getUserMedia){const s=t.mediaDevices.getUserMedia.bind(t.mediaDevices);t.mediaDevices.getUserMedia=function(u){return i(u,d=>s(d).then(l=>{if(d.audio&&!l.getAudioTracks().length||d.video&&!l.getVideoTracks().length)throw l.getTracks().forEach(h=>{h.stop()}),new DOMException("","NotFoundError");return l},l=>Promise.reject(o(l))))}}}function hc(n){n.MediaStream=n.MediaStream||n.webkitMediaStream}function pc(n){if(typeof n=="object"&&n.RTCPeerConnection&&!("ontrack"in n.RTCPeerConnection.prototype)){Object.defineProperty(n.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(t){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=t)},enumerable:!0,configurable:!0});const e=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",r=>{let i;i=n.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find(s=>s.track&&s.track.id===r.track.id):{track:r.track};const o=new Event("track");o.track=r.track,o.receiver=i,o.transceiver={receiver:i},o.streams=[t.stream],this.dispatchEvent(o)}),t.stream.getTracks().forEach(r=>{let i;i=n.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find(s=>s.track&&s.track.id===r.id):{track:r};const o=new Event("track");o.track=r,o.receiver=i,o.transceiver={receiver:i},o.streams=[t.stream],this.dispatchEvent(o)})},this.addEventListener("addstream",this._ontrackpoly)),e.apply(this,arguments)}}else Jt(n,"track",e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}function fc(n){if(typeof n=="object"&&n.RTCPeerConnection&&!("getSenders"in n.RTCPeerConnection.prototype)&&"createDTMFSender"in n.RTCPeerConnection.prototype){const e=function(i,o){return{track:o,get dtmf(){return this._dtmf===void 0&&(o.kind==="audio"?this._dtmf=i.createDTMFSender(o):this._dtmf=null),this._dtmf},_pc:i}};if(!n.RTCPeerConnection.prototype.getSenders){n.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=n.RTCPeerConnection.prototype.addTrack;n.RTCPeerConnection.prototype.addTrack=function(s,u){let d=i.apply(this,arguments);return d||(d=e(this,s),this._senders.push(d)),d};const o=n.RTCPeerConnection.prototype.removeTrack;n.RTCPeerConnection.prototype.removeTrack=function(s){o.apply(this,arguments);const u=this._senders.indexOf(s);u!==-1&&this._senders.splice(u,1)}}const t=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(i){this._senders=this._senders||[],t.apply(this,[i]),i.getTracks().forEach(o=>{this._senders.push(e(this,o))})};const r=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(i){this._senders=this._senders||[],r.apply(this,[i]),i.getTracks().forEach(o=>{const s=this._senders.find(u=>u.track===o);s&&this._senders.splice(this._senders.indexOf(s),1)})}}else if(typeof n=="object"&&n.RTCPeerConnection&&"getSenders"in n.RTCPeerConnection.prototype&&"createDTMFSender"in n.RTCPeerConnection.prototype&&n.RTCRtpSender&&!("dtmf"in n.RTCRtpSender.prototype)){const e=n.RTCPeerConnection.prototype.getSenders;n.RTCPeerConnection.prototype.getSenders=function(){const t=e.apply(this,[]);return t.forEach(r=>r._pc=this),t},Object.defineProperty(n.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function gc(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[t,r,i]=arguments;if(arguments.length>0&&typeof t=="function")return e.apply(this,arguments);if(e.length===0&&(arguments.length===0||typeof t!="function"))return e.apply(this,[]);const o=function(u){const d={};return u.result().forEach(l=>{const h={id:l.id,timestamp:l.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[l.type]||l.type};l.names().forEach(a=>{h[a]=l.stat(a)}),d[h.id]=h}),d},s=function(u){return new Map(Object.keys(u).map(d=>[d,u[d]]))};if(arguments.length>=2){const u=function(d){r(s(o(d)))};return e.apply(this,[u,t])}return new Promise((u,d)=>{e.apply(this,[function(l){u(s(o(l)))},d])}).then(r,i)}}function mc(n){if(!(typeof n=="object"&&n.RTCPeerConnection&&n.RTCRtpSender&&n.RTCRtpReceiver))return;if(!("getStats"in n.RTCRtpSender.prototype)){const t=n.RTCPeerConnection.prototype.getSenders;t&&(n.RTCPeerConnection.prototype.getSenders=function(){const i=t.apply(this,[]);return i.forEach(o=>o._pc=this),i});const r=n.RTCPeerConnection.prototype.addTrack;r&&(n.RTCPeerConnection.prototype.addTrack=function(){const i=r.apply(this,arguments);return i._pc=this,i}),n.RTCRtpSender.prototype.getStats=function(){const i=this;return this._pc.getStats().then(o=>Ws(o,i.track,!0))}}if(!("getStats"in n.RTCRtpReceiver.prototype)){const t=n.RTCPeerConnection.prototype.getReceivers;t&&(n.RTCPeerConnection.prototype.getReceivers=function(){const r=t.apply(this,[]);return r.forEach(i=>i._pc=this),r}),Jt(n,"track",r=>(r.receiver._pc=r.srcElement,r)),n.RTCRtpReceiver.prototype.getStats=function(){const r=this;return this._pc.getStats().then(i=>Ws(i,r.track,!1))}}if(!("getStats"in n.RTCRtpSender.prototype)||!("getStats"in n.RTCRtpReceiver.prototype))return;const e=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof n.MediaStreamTrack){const t=arguments[0];let r,i,o;return this.getSenders().forEach(s=>{s.track===t&&(r?o=!0:r=s)}),this.getReceivers().forEach(s=>(s.track===t&&(i?o=!0:i=s),s.track===t)),o||r&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):r?r.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return e.apply(this,arguments)}}function _c(n){n.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(o=>this._shimmedLocalStreams[o][0])};const e=n.RTCPeerConnection.prototype.addTrack;n.RTCPeerConnection.prototype.addTrack=function(o,s){if(!s)return e.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const u=e.apply(this,arguments);return this._shimmedLocalStreams[s.id]?this._shimmedLocalStreams[s.id].indexOf(u)===-1&&this._shimmedLocalStreams[s.id].push(u):this._shimmedLocalStreams[s.id]=[s,u],u};const t=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(o){this._shimmedLocalStreams=this._shimmedLocalStreams||{},o.getTracks().forEach(d=>{if(this.getSenders().find(l=>l.track===d))throw new DOMException("Track already exists.","InvalidAccessError")});const s=this.getSenders();t.apply(this,arguments);const u=this.getSenders().filter(d=>s.indexOf(d)===-1);this._shimmedLocalStreams[o.id]=[o].concat(u)};const r=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(o){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[o.id],r.apply(this,arguments)};const i=n.RTCPeerConnection.prototype.removeTrack;n.RTCPeerConnection.prototype.removeTrack=function(o){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},o&&Object.keys(this._shimmedLocalStreams).forEach(s=>{const u=this._shimmedLocalStreams[s].indexOf(o);u!==-1&&this._shimmedLocalStreams[s].splice(u,1),this._shimmedLocalStreams[s].length===1&&delete this._shimmedLocalStreams[s]}),i.apply(this,arguments)}}function vc(n,e){if(!n.RTCPeerConnection)return;if(n.RTCPeerConnection.prototype.addTrack&&e.version>=65)return _c(n);const t=n.RTCPeerConnection.prototype.getLocalStreams;n.RTCPeerConnection.prototype.getLocalStreams=function(){const l=t.apply(this);return this._reverseStreams=this._reverseStreams||{},l.map(h=>this._reverseStreams[h.id])};const r=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(l){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},l.getTracks().forEach(h=>{if(this.getSenders().find(a=>a.track===h))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[l.id]){const h=new n.MediaStream(l.getTracks());this._streams[l.id]=h,this._reverseStreams[h.id]=l,l=h}r.apply(this,[l])};const i=n.RTCPeerConnection.prototype.removeStream;function o(l,h){let a=h.sdp;return Object.keys(l._reverseStreams||[]).forEach(c=>{const p=l._reverseStreams[c],f=l._streams[p.id];a=a.replace(new RegExp(f.id,"g"),p.id)}),new RTCSessionDescription({type:h.type,sdp:a})}function s(l,h){let a=h.sdp;return Object.keys(l._reverseStreams||[]).forEach(c=>{const p=l._reverseStreams[c],f=l._streams[p.id];a=a.replace(new RegExp(p.id,"g"),f.id)}),new RTCSessionDescription({type:h.type,sdp:a})}n.RTCPeerConnection.prototype.removeStream=function(l){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},i.apply(this,[this._streams[l.id]||l]),delete this._reverseStreams[this._streams[l.id]?this._streams[l.id].id:l.id],delete this._streams[l.id]},n.RTCPeerConnection.prototype.addTrack=function(l,h){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const a=[].slice.call(arguments,1);if(a.length!==1||!a[0].getTracks().find(f=>f===l))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");if(this.getSenders().find(f=>f.track===l))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const p=this._streams[h.id];if(p)p.addTrack(l),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{const f=new n.MediaStream([l]);this._streams[h.id]=f,this._reverseStreams[f.id]=h,this.addStream(f)}return this.getSenders().find(f=>f.track===l)},["createOffer","createAnswer"].forEach(function(l){const h=n.RTCPeerConnection.prototype[l],a={[l](){const c=arguments;return arguments.length&&typeof arguments[0]=="function"?h.apply(this,[p=>{const f=o(this,p);c[0].apply(null,[f])},p=>{c[1]&&c[1].apply(null,p)},arguments[2]]):h.apply(this,arguments).then(p=>o(this,p))}};n.RTCPeerConnection.prototype[l]=a[l]});const u=n.RTCPeerConnection.prototype.setLocalDescription;n.RTCPeerConnection.prototype.setLocalDescription=function(){return arguments.length&&arguments[0].type?(arguments[0]=s(this,arguments[0]),u.apply(this,arguments)):u.apply(this,arguments)};const d=Object.getOwnPropertyDescriptor(n.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(n.RTCPeerConnection.prototype,"localDescription",{get(){const l=d.get.apply(this);return l.type===""?l:o(this,l)}}),n.RTCPeerConnection.prototype.removeTrack=function(l){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!l._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(l._pc!==this)throw new DOMException("Sender was not created by this connection.","InvalidAccessError");let h;this._streams=this._streams||{},Object.keys(this._streams).forEach(a=>{this._streams[a].getTracks().find(c=>l.track===c)&&(h=this._streams[a])}),h&&(h.getTracks().length===1?this.removeStream(this._reverseStreams[h.id]):h.removeTrack(l.track),this.dispatchEvent(new Event("negotiationneeded")))}}function Li(n,e){!n.RTCPeerConnection&&n.webkitRTCPeerConnection&&(n.RTCPeerConnection=n.webkitRTCPeerConnection),n.RTCPeerConnection&&e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){const r=n.RTCPeerConnection.prototype[t],i={[t](){return arguments[0]=new(t==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),r.apply(this,arguments)}};n.RTCPeerConnection.prototype[t]=i[t]})}function Rc(n,e){Jt(n,"negotiationneeded",t=>{const r=t.target;if(!(e.version<72||r.getConfiguration&&r.getConfiguration().sdpSemantics==="plan-b")||r.signalingState==="stable")return t})}var Qs=Object.freeze({__proto__:null,shimMediaStream:hc,shimOnTrack:pc,shimGetSendersWithDtmf:fc,shimGetStats:gc,shimSenderReceiverGetStats:mc,shimAddTrackRemoveTrackWithNative:_c,shimAddTrackRemoveTrack:vc,shimPeerConnection:Li,fixNegotiationNeeded:Rc,shimGetUserMedia:lc,shimGetDisplayMedia:function(n,e){n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||n.navigator.mediaDevices&&(typeof e=="function"?n.navigator.mediaDevices.getDisplayMedia=function(t){return e(t).then(r=>{const i=t.video&&t.video.width,o=t.video&&t.video.height,s=t.video&&t.video.frameRate;return t.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:r,maxFrameRate:s||3}},i&&(t.video.mandatory.maxWidth=i),o&&(t.video.mandatory.maxHeight=o),n.navigator.mediaDevices.getUserMedia(t)})}:console.error("shimGetDisplayMedia: getSourceId argument is not a function"))}}),Xs,ri,ne=(Xs=function(n){var e={generateIdentifier:function(){return Math.random().toString(36).substr(2,10)}};e.localCName=e.generateIdentifier(),e.splitLines=function(t){return t.trim().split(`
`).map(function(r){return r.trim()})},e.splitSections=function(t){return t.split(`
m=`).map(function(r,i){return(i>0?"m="+r:r).trim()+`\r
`})},e.getDescription=function(t){var r=e.splitSections(t);return r&&r[0]},e.getMediaSections=function(t){var r=e.splitSections(t);return r.shift(),r},e.matchPrefix=function(t,r){return e.splitLines(t).filter(function(i){return i.indexOf(r)===0})},e.parseCandidate=function(t){for(var r,i={foundation:(r=t.indexOf("a=candidate:")===0?t.substring(12).split(" "):t.substring(10).split(" "))[0],component:parseInt(r[1],10),protocol:r[2].toLowerCase(),priority:parseInt(r[3],10),ip:r[4],address:r[4],port:parseInt(r[5],10),type:r[7]},o=8;o0?r[0].split("/")[1]:"sendrecv",uri:r[1]}},e.writeExtmap=function(t){return"a=extmap:"+(t.id||t.preferredId)+(t.direction&&t.direction!=="sendrecv"?"/"+t.direction:"")+" "+t.uri+`\r
`},e.parseFmtp=function(t){for(var r,i={},o=t.substr(t.indexOf(" ")+1).split(";"),s=0;s-1?(i.attribute=t.substr(r+1,o-r-1),i.value=t.substr(o+1)):i.attribute=t.substr(r+1),i},e.parseSsrcGroup=function(t){var r=t.substr(13).split(" ");return{semantics:r.shift(),ssrcs:r.map(function(i){return parseInt(i,10)})}},e.getMid=function(t){var r=e.matchPrefix(t,"a=mid:")[0];if(r)return r.substr(6)},e.parseFingerprint=function(t){var r=t.substr(14).split(" ");return{algorithm:r[0].toLowerCase(),value:r[1]}},e.getDtlsParameters=function(t,r){return{role:"auto",fingerprints:e.matchPrefix(t+r,"a=fingerprint:").map(e.parseFingerprint)}},e.writeDtlsParameters=function(t,r){var i="a=setup:"+r+`\r
`;return t.fingerprints.forEach(function(o){i+="a=fingerprint:"+o.algorithm+" "+o.value+`\r
`}),i},e.parseCryptoLine=function(t){var r=t.substr(9).split(" ");return{tag:parseInt(r[0],10),cryptoSuite:r[1],keyParams:r[2],sessionParams:r.slice(3)}},e.writeCryptoLine=function(t){return"a=crypto:"+t.tag+" "+t.cryptoSuite+" "+(typeof t.keyParams=="object"?e.writeCryptoKeyParams(t.keyParams):t.keyParams)+(t.sessionParams?" "+t.sessionParams.join(" "):"")+`\r
`},e.parseCryptoKeyParams=function(t){if(t.indexOf("inline:")!==0)return null;var r=t.substr(7).split("|");return{keyMethod:"inline",keySalt:r[0],lifeTime:r[1],mkiValue:r[2]?r[2].split(":")[0]:void 0,mkiLength:r[2]?r[2].split(":")[1]:void 0}},e.writeCryptoKeyParams=function(t){return t.keyMethod+":"+t.keySalt+(t.lifeTime?"|"+t.lifeTime:"")+(t.mkiValue&&t.mkiLength?"|"+t.mkiValue+":"+t.mkiLength:"")},e.getCryptoParameters=function(t,r){return e.matchPrefix(t+r,"a=crypto:").map(e.parseCryptoLine)},e.getIceParameters=function(t,r){var i=e.matchPrefix(t+r,"a=ice-ufrag:")[0],o=e.matchPrefix(t+r,"a=ice-pwd:")[0];return i&&o?{usernameFragment:i.substr(12),password:o.substr(10)}:null},e.writeIceParameters=function(t){return"a=ice-ufrag:"+t.usernameFragment+`\r
a=ice-pwd:`+t.password+`\r
`},e.parseRtpParameters=function(t){for(var r={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},i=e.splitLines(t)[0].split(" "),o=3;o0?"9":"0",i+=" UDP/TLS/RTP/SAVPF ",i+=r.codecs.map(function(s){return s.preferredPayloadType!==void 0?s.preferredPayloadType:s.payloadType}).join(" ")+`\r
`,i+=`c=IN IP4 0.0.0.0\r
`,i+=`a=rtcp:9 IN IP4 0.0.0.0\r
`,r.codecs.forEach(function(s){i+=e.writeRtpMap(s),i+=e.writeFmtp(s),i+=e.writeRtcpFb(s)});var o=0;return r.codecs.forEach(function(s){s.maxptime>o&&(o=s.maxptime)}),o>0&&(i+="a=maxptime:"+o+`\r
`),i+=`a=rtcp-mux\r
`,r.headerExtensions&&r.headerExtensions.forEach(function(s){i+=e.writeExtmap(s)}),i},e.parseRtpEncodingParameters=function(t){var r,i=[],o=e.parseRtpParameters(t),s=o.fecMechanisms.indexOf("RED")!==-1,u=o.fecMechanisms.indexOf("ULPFEC")!==-1,d=e.matchPrefix(t,"a=ssrc:").map(function(c){return e.parseSsrcMedia(c)}).filter(function(c){return c.attribute==="cname"}),l=d.length>0&&d[0].ssrc,h=e.matchPrefix(t,"a=ssrc-group:FID").map(function(c){return c.substr(17).split(" ").map(function(p){return parseInt(p,10)})});h.length>0&&h[0].length>1&&h[0][0]===l&&(r=h[0][1]),o.codecs.forEach(function(c){if(c.name.toUpperCase()==="RTX"&&c.parameters.apt){var p={ssrc:l,codecPayloadType:parseInt(c.parameters.apt,10)};l&&r&&(p.rtx={ssrc:r}),i.push(p),s&&((p=JSON.parse(JSON.stringify(p))).fec={ssrc:l,mechanism:u?"red+ulpfec":"red"},i.push(p))}}),i.length===0&&l&&i.push({ssrc:l});var a=e.matchPrefix(t,"b=");return a.length&&(a=a[0].indexOf("b=TIAS:")===0?parseInt(a[0].substr(7),10):a[0].indexOf("b=AS:")===0?1e3*parseInt(a[0].substr(5),10)*.95-16e3:void 0,i.forEach(function(c){c.maxBitrate=a})),i},e.parseRtcpParameters=function(t){var r={},i=e.matchPrefix(t,"a=ssrc:").map(function(u){return e.parseSsrcMedia(u)}).filter(function(u){return u.attribute==="cname"})[0];i&&(r.cname=i.value,r.ssrc=i.ssrc);var o=e.matchPrefix(t,"a=rtcp-rsize");r.reducedSize=o.length>0,r.compound=o.length===0;var s=e.matchPrefix(t,"a=rtcp-mux");return r.mux=s.length>0,r},e.parseMsid=function(t){var r,i=e.matchPrefix(t,"a=msid:");if(i.length===1)return{stream:(r=i[0].substr(7).split(" "))[0],track:r[1]};var o=e.matchPrefix(t,"a=ssrc:").map(function(s){return e.parseSsrcMedia(s)}).filter(function(s){return s.attribute==="msid"});return o.length>0?{stream:(r=o[0].value.split(" "))[0],track:r[1]}:void 0},e.parseSctpDescription=function(t){var r,i=e.parseMLine(t),o=e.matchPrefix(t,"a=max-message-size:");o.length>0&&(r=parseInt(o[0].substr(19),10)),isNaN(r)&&(r=65536);var s=e.matchPrefix(t,"a=sctp-port:");if(s.length>0)return{port:parseInt(s[0].substr(12),10),protocol:i.fmt,maxMessageSize:r};if(e.matchPrefix(t,"a=sctpmap:").length>0){var u=e.matchPrefix(t,"a=sctpmap:")[0].substr(10).split(" ");return{port:parseInt(u[0],10),protocol:u[1],maxMessageSize:r}}},e.writeSctpDescription=function(t,r){var i=[];return i=t.protocol!=="DTLS/SCTP"?["m="+t.kind+" 9 "+t.protocol+" "+r.protocol+`\r
`,`c=IN IP4 0.0.0.0\r
`,"a=sctp-port:"+r.port+`\r
`]:["m="+t.kind+" 9 "+t.protocol+" "+r.port+`\r
`,`c=IN IP4 0.0.0.0\r
`,"a=sctpmap:"+r.port+" "+r.protocol+` 65535\r
`],r.maxMessageSize!==void 0&&i.push("a=max-message-size:"+r.maxMessageSize+`\r
`),i.join("")},e.generateSessionId=function(){return Math.random().toString().substr(2,21)},e.writeSessionBoilerplate=function(t,r,i){var o=r!==void 0?r:2;return`v=0\r
o=`+(i||"thisisadapterortc")+" "+(t||e.generateSessionId())+" "+o+` IN IP4 127.0.0.1\r
s=-\r
t=0 0\r
`},e.writeMediaSection=function(t,r,i,o){var s=e.writeRtpDescription(t.kind,r);if(s+=e.writeIceParameters(t.iceGatherer.getLocalParameters()),s+=e.writeDtlsParameters(t.dtlsTransport.getLocalParameters(),i==="offer"?"actpass":"active"),s+="a=mid:"+t.mid+`\r
`,t.direction?s+="a="+t.direction+`\r
`:t.rtpSender&&t.rtpReceiver?s+=`a=sendrecv\r
`:t.rtpSender?s+=`a=sendonly\r
`:t.rtpReceiver?s+=`a=recvonly\r
`:s+=`a=inactive\r
`,t.rtpSender){var u="msid:"+o.id+" "+t.rtpSender.track.id+`\r
`;s+="a="+u,s+="a=ssrc:"+t.sendEncodingParameters[0].ssrc+" "+u,t.sendEncodingParameters[0].rtx&&(s+="a=ssrc:"+t.sendEncodingParameters[0].rtx.ssrc+" "+u,s+="a=ssrc-group:FID "+t.sendEncodingParameters[0].ssrc+" "+t.sendEncodingParameters[0].rtx.ssrc+`\r
`)}return s+="a=ssrc:"+t.sendEncodingParameters[0].ssrc+" cname:"+e.localCName+`\r
`,t.rtpSender&&t.sendEncodingParameters[0].rtx&&(s+="a=ssrc:"+t.sendEncodingParameters[0].rtx.ssrc+" cname:"+e.localCName+`\r
`),s},e.getDirection=function(t,r){for(var i=e.splitLines(t),o=0;o=14393&&_.indexOf("?transport=udp")===-1:(c=!0,!0)}),delete p.url,p.urls=m?f[0]:f,!!f.length}})}(s.iceServers||[],e),this._iceGatherers=[],s.iceCandidatePoolSize)for(var l=s.iceCandidatePoolSize;l>0;l--)this._iceGatherers.push(new n.RTCIceGatherer({iceServers:s.iceServers,gatherPolicy:s.iceTransportPolicy}));else s.iceCandidatePoolSize=0;this._config=s,this.transceivers=[],this._sdpSessionId=ne.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(i.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(i.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),i.prototype.onicecandidate=null,i.prototype.onaddstream=null,i.prototype.ontrack=null,i.prototype.onremovestream=null,i.prototype.onsignalingstatechange=null,i.prototype.oniceconnectionstatechange=null,i.prototype.onconnectionstatechange=null,i.prototype.onicegatheringstatechange=null,i.prototype.onnegotiationneeded=null,i.prototype.ondatachannel=null,i.prototype._dispatchEvent=function(s,u){this._isClosed||(this.dispatchEvent(u),typeof this["on"+s]=="function"&&this["on"+s](u))},i.prototype._emitGatheringStateChange=function(){var s=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",s)},i.prototype.getConfiguration=function(){return this._config},i.prototype.getLocalStreams=function(){return this.localStreams},i.prototype.getRemoteStreams=function(){return this.remoteStreams},i.prototype._createTransceiver=function(s,u){var d=this.transceivers.length>0,l={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:s,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&d)l.iceTransport=this.transceivers[0].iceTransport,l.dtlsTransport=this.transceivers[0].dtlsTransport;else{var h=this._createIceAndDtlsTransports();l.iceTransport=h.iceTransport,l.dtlsTransport=h.dtlsTransport}return u||this.transceivers.push(l),l},i.prototype.addTrack=function(s,u){if(this._isClosed)throw be("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var d;if(this.transceivers.find(function(h){return h.track===s}))throw be("InvalidAccessError","Track already exists.");for(var l=0;l=15025)s.getTracks().forEach(function(l){u.addTrack(l,s)});else{var d=s.clone();s.getTracks().forEach(function(l,h){var a=d.getTracks()[h];l.addEventListener("enabled",function(c){a.enabled=c.enabled})}),d.getTracks().forEach(function(l){u.addTrack(l,d)})}},i.prototype.removeTrack=function(s){if(this._isClosed)throw be("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(s instanceof n.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var u=this.transceivers.find(function(l){return l.rtpSender===s});if(!u)throw be("InvalidAccessError","Sender was not created by this connection.");var d=u.stream;u.rtpSender.stop(),u.rtpSender=null,u.track=null,u.stream=null,this.transceivers.map(function(l){return l.stream}).indexOf(d)===-1&&this.localStreams.indexOf(d)>-1&&this.localStreams.splice(this.localStreams.indexOf(d),1),this._maybeFireNegotiationNeeded()},i.prototype.removeStream=function(s){var u=this;s.getTracks().forEach(function(d){var l=u.getSenders().find(function(h){return h.track===d});l&&u.removeTrack(l)})},i.prototype.getSenders=function(){return this.transceivers.filter(function(s){return!!s.rtpSender}).map(function(s){return s.rtpSender})},i.prototype.getReceivers=function(){return this.transceivers.filter(function(s){return!!s.rtpReceiver}).map(function(s){return s.rtpReceiver})},i.prototype._createIceGatherer=function(s,u){var d=this;if(u&&s>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var l=new n.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(l,"state",{value:"new",writable:!0}),this.transceivers[s].bufferedCandidateEvents=[],this.transceivers[s].bufferCandidates=function(h){var a=!h.candidate||Object.keys(h.candidate).length===0;l.state=a?"completed":"gathering",d.transceivers[s].bufferedCandidateEvents!==null&&d.transceivers[s].bufferedCandidateEvents.push(h)},l.addEventListener("localcandidate",this.transceivers[s].bufferCandidates),l},i.prototype._gather=function(s,u){var d=this,l=this.transceivers[u].iceGatherer;if(!l.onlocalcandidate){var h=this.transceivers[u].bufferedCandidateEvents;this.transceivers[u].bufferedCandidateEvents=null,l.removeEventListener("localcandidate",this.transceivers[u].bufferCandidates),l.onlocalcandidate=function(a){if(!(d.usingBundle&&u>0)){var c=new Event("icecandidate");c.candidate={sdpMid:s,sdpMLineIndex:u};var p=a.candidate,f=!p||Object.keys(p).length===0;if(f)l.state!=="new"&&l.state!=="gathering"||(l.state="completed");else{l.state==="new"&&(l.state="gathering"),p.component=1,p.ufrag=l.getLocalParameters().usernameFragment;var m=ne.writeCandidate(p);c.candidate=Object.assign(c.candidate,ne.parseCandidate(m)),c.candidate.candidate=m,c.candidate.toJSON=function(){return{candidate:c.candidate.candidate,sdpMid:c.candidate.sdpMid,sdpMLineIndex:c.candidate.sdpMLineIndex,usernameFragment:c.candidate.usernameFragment}}}var _=ne.getMediaSections(d._localDescription.sdp);_[c.candidate.sdpMLineIndex]+=f?`a=end-of-candidates\r
`:"a="+c.candidate.candidate+`\r
`,d._localDescription.sdp=ne.getDescription(d._localDescription.sdp)+_.join("");var v=d.transceivers.every(function(R){return R.iceGatherer&&R.iceGatherer.state==="completed"});d.iceGatheringState!=="gathering"&&(d.iceGatheringState="gathering",d._emitGatheringStateChange()),f||d._dispatchEvent("icecandidate",c),v&&(d._dispatchEvent("icecandidate",new Event("icecandidate")),d.iceGatheringState="complete",d._emitGatheringStateChange())}},n.setTimeout(function(){h.forEach(function(a){l.onlocalcandidate(a)})},0)}},i.prototype._createIceAndDtlsTransports=function(){var s=this,u=new n.RTCIceTransport(null);u.onicestatechange=function(){s._updateIceConnectionState(),s._updateConnectionState()};var d=new n.RTCDtlsTransport(u);return d.ondtlsstatechange=function(){s._updateConnectionState()},d.onerror=function(){Object.defineProperty(d,"state",{value:"failed",writable:!0}),s._updateConnectionState()},{iceTransport:u,dtlsTransport:d}},i.prototype._disposeIceAndDtlsTransports=function(s){var u=this.transceivers[s].iceGatherer;u&&(delete u.onlocalcandidate,delete this.transceivers[s].iceGatherer);var d=this.transceivers[s].iceTransport;d&&(delete d.onicestatechange,delete this.transceivers[s].iceTransport);var l=this.transceivers[s].dtlsTransport;l&&(delete l.ondtlsstatechange,delete l.onerror,delete this.transceivers[s].dtlsTransport)},i.prototype._transceive=function(s,u,d){var l=zn(s.localCapabilities,s.remoteCapabilities);u&&s.rtpSender&&(l.encodings=s.sendEncodingParameters,l.rtcp={cname:ne.localCName,compound:s.rtcpParameters.compound},s.recvEncodingParameters.length&&(l.rtcp.ssrc=s.recvEncodingParameters[0].ssrc),s.rtpSender.send(l)),d&&s.rtpReceiver&&l.codecs.length>0&&(s.kind==="video"&&s.recvEncodingParameters&&e<15019&&s.recvEncodingParameters.forEach(function(h){delete h.rtx}),s.recvEncodingParameters.length?l.encodings=s.recvEncodingParameters:l.encodings=[{}],l.rtcp={compound:s.rtcpParameters.compound},s.rtcpParameters.cname&&(l.rtcp.cname=s.rtcpParameters.cname),s.sendEncodingParameters.length&&(l.rtcp.ssrc=s.sendEncodingParameters[0].ssrc),s.rtpReceiver.receive(l))},i.prototype.setLocalDescription=function(s){var u,d,l=this;if(["offer","answer"].indexOf(s.type)===-1)return Promise.reject(be("TypeError",'Unsupported type "'+s.type+'"'));if(!ta("setLocalDescription",s.type,l.signalingState)||l._isClosed)return Promise.reject(be("InvalidStateError","Can not set local "+s.type+" in state "+l.signalingState));if(s.type==="offer")u=ne.splitSections(s.sdp),d=u.shift(),u.forEach(function(a,c){var p=ne.parseRtpParameters(a);l.transceivers[c].localCapabilities=p}),l.transceivers.forEach(function(a,c){l._gather(a.mid,c)});else if(s.type==="answer"){u=ne.splitSections(l._remoteDescription.sdp),d=u.shift();var h=ne.matchPrefix(d,"a=ice-lite").length>0;u.forEach(function(a,c){var p=l.transceivers[c],f=p.iceGatherer,m=p.iceTransport,_=p.dtlsTransport,v=p.localCapabilities,R=p.remoteCapabilities;if(!(ne.isRejected(a)&&ne.matchPrefix(a,"a=bundle-only").length===0)&&!p.rejected){var y=ne.getIceParameters(a,d),P=ne.getDtlsParameters(a,d);h&&(P.role="server"),l.usingBundle&&c!==0||(l._gather(p.mid,c),m.state==="new"&&m.start(f,y,h?"controlling":"controlled"),_.state==="new"&&_.start(P));var L=zn(v,R);l._transceive(p,L.codecs.length>0,!1)}})}return l._localDescription={type:s.type,sdp:s.sdp},s.type==="offer"?l._updateSignalingState("have-local-offer"):l._updateSignalingState("stable"),Promise.resolve()},i.prototype.setRemoteDescription=function(s){var u=this;if(["offer","answer"].indexOf(s.type)===-1)return Promise.reject(be("TypeError",'Unsupported type "'+s.type+'"'));if(!ta("setRemoteDescription",s.type,u.signalingState)||u._isClosed)return Promise.reject(be("InvalidStateError","Can not set remote "+s.type+" in state "+u.signalingState));var d={};u.remoteStreams.forEach(function(m){d[m.id]=m});var l=[],h=ne.splitSections(s.sdp),a=h.shift(),c=ne.matchPrefix(a,"a=ice-lite").length>0,p=ne.matchPrefix(a,"a=group:BUNDLE ").length>0;u.usingBundle=p;var f=ne.matchPrefix(a,"a=ice-options:")[0];return u.canTrickleIceCandidates=!!f&&f.substr(14).split(" ").indexOf("trickle")>=0,h.forEach(function(m,_){var v=ne.splitLines(m),R=ne.getKind(m),y=ne.isRejected(m)&&ne.matchPrefix(m,"a=bundle-only").length===0,P=v[0].substr(2).split(" ")[2],L=ne.getDirection(m,a),N=ne.parseMsid(m),E=ne.getMid(m)||ne.generateIdentifier();if(y||R==="application"&&(P==="DTLS/SCTP"||P==="UDP/DTLS/SCTP"))u.transceivers[_]={mid:E,kind:R,protocol:P,rejected:!0};else{var A,F,q,C,T,S,O,I,U;!y&&u.transceivers[_]&&u.transceivers[_].rejected&&(u.transceivers[_]=u._createTransceiver(R,!0));var D,$,j=ne.parseRtpParameters(m);y||(D=ne.getIceParameters(m,a),($=ne.getDtlsParameters(m,a)).role="client"),O=ne.parseRtpEncodingParameters(m);var J=ne.parseRtcpParameters(m),re=ne.matchPrefix(m,"a=end-of-candidates",a).length>0,X=ne.matchPrefix(m,"a=candidate:").map(function(k){return ne.parseCandidate(k)}).filter(function(k){return k.component===1});if((s.type==="offer"||s.type==="answer")&&!y&&p&&_>0&&u.transceivers[_]&&(u._disposeIceAndDtlsTransports(_),u.transceivers[_].iceGatherer=u.transceivers[0].iceGatherer,u.transceivers[_].iceTransport=u.transceivers[0].iceTransport,u.transceivers[_].dtlsTransport=u.transceivers[0].dtlsTransport,u.transceivers[_].rtpSender&&u.transceivers[_].rtpSender.setTransport(u.transceivers[0].dtlsTransport),u.transceivers[_].rtpReceiver&&u.transceivers[_].rtpReceiver.setTransport(u.transceivers[0].dtlsTransport)),s.type!=="offer"||y)s.type==="answer"&&!y&&(F=(A=u.transceivers[_]).iceGatherer,q=A.iceTransport,C=A.dtlsTransport,T=A.rtpReceiver,S=A.sendEncodingParameters,I=A.localCapabilities,u.transceivers[_].recvEncodingParameters=O,u.transceivers[_].remoteCapabilities=j,u.transceivers[_].rtcpParameters=J,X.length&&q.state==="new"&&(!c&&!re||p&&_!==0?X.forEach(function(k){ii(A.iceTransport,k)}):q.setRemoteCandidates(X)),p&&_!==0||(q.state==="new"&&q.start(F,D,"controlling"),C.state==="new"&&C.start($)),!zn(A.localCapabilities,A.remoteCapabilities).codecs.filter(function(k){return k.name.toLowerCase()==="rtx"}).length&&A.sendEncodingParameters[0].rtx&&delete A.sendEncodingParameters[0].rtx,u._transceive(A,L==="sendrecv"||L==="recvonly",L==="sendrecv"||L==="sendonly"),!T||L!=="sendrecv"&&L!=="sendonly"?delete A.rtpReceiver:(U=T.track,N?(d[N.stream]||(d[N.stream]=new n.MediaStream),t(U,d[N.stream]),l.push([U,T,d[N.stream]])):(d.default||(d.default=new n.MediaStream),t(U,d.default),l.push([U,T,d.default]))));else{(A=u.transceivers[_]||u._createTransceiver(R)).mid=E,A.iceGatherer||(A.iceGatherer=u._createIceGatherer(_,p)),X.length&&A.iceTransport.state==="new"&&(!re||p&&_!==0?X.forEach(function(k){ii(A.iceTransport,k)}):A.iceTransport.setRemoteCandidates(X)),I=n.RTCRtpReceiver.getCapabilities(R),e<15019&&(I.codecs=I.codecs.filter(function(k){return k.name!=="rtx"})),S=A.sendEncodingParameters||[{ssrc:1001*(2*_+2)}];var W,Z=!1;L==="sendrecv"||L==="sendonly"?(Z=!A.rtpReceiver,T=A.rtpReceiver||new n.RTCRtpReceiver(A.dtlsTransport,R),Z&&(U=T.track,N&&N.stream==="-"||(N?(d[N.stream]||(d[N.stream]=new n.MediaStream,Object.defineProperty(d[N.stream],"id",{get:function(){return N.stream}})),Object.defineProperty(U,"id",{get:function(){return N.track}}),W=d[N.stream]):(d.default||(d.default=new n.MediaStream),W=d.default)),W&&(t(U,W),A.associatedRemoteMediaStreams.push(W)),l.push([U,T,W]))):A.rtpReceiver&&A.rtpReceiver.track&&(A.associatedRemoteMediaStreams.forEach(function(k){var z=k.getTracks().find(function(Q){return Q.id===A.rtpReceiver.track.id});z&&function(Q,ie){ie.removeTrack(Q),ie.dispatchEvent(new n.MediaStreamTrackEvent("removetrack",{track:Q}))}(z,k)}),A.associatedRemoteMediaStreams=[]),A.localCapabilities=I,A.remoteCapabilities=j,A.rtpReceiver=T,A.rtcpParameters=J,A.sendEncodingParameters=S,A.recvEncodingParameters=O,u._transceive(u.transceivers[_],!1,Z)}}}),u._dtlsRole===void 0&&(u._dtlsRole=s.type==="offer"?"active":"passive"),u._remoteDescription={type:s.type,sdp:s.sdp},s.type==="offer"?u._updateSignalingState("have-remote-offer"):u._updateSignalingState("stable"),Object.keys(d).forEach(function(m){var _=d[m];if(_.getTracks().length){if(u.remoteStreams.indexOf(_)===-1){u.remoteStreams.push(_);var v=new Event("addstream");v.stream=_,n.setTimeout(function(){u._dispatchEvent("addstream",v)})}l.forEach(function(R){var y=R[0],P=R[1];_.id===R[2].id&&r(u,y,P,[_])})}}),l.forEach(function(m){m[2]||r(u,m[0],m[1],[])}),n.setTimeout(function(){u&&u.transceivers&&u.transceivers.forEach(function(m){m.iceTransport&&m.iceTransport.state==="new"&&m.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),m.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},i.prototype.close=function(){this.transceivers.forEach(function(s){s.iceTransport&&s.iceTransport.stop(),s.dtlsTransport&&s.dtlsTransport.stop(),s.rtpSender&&s.rtpSender.stop(),s.rtpReceiver&&s.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},i.prototype._updateSignalingState=function(s){this.signalingState=s;var u=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",u)},i.prototype._maybeFireNegotiationNeeded=function(){var s=this;this.signalingState==="stable"&&this.needNegotiation!==!0&&(this.needNegotiation=!0,n.setTimeout(function(){if(s.needNegotiation){s.needNegotiation=!1;var u=new Event("negotiationneeded");s._dispatchEvent("negotiationneeded",u)}},0))},i.prototype._updateIceConnectionState=function(){var s,u={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(l){l.iceTransport&&!l.rejected&&u[l.iceTransport.state]++}),s="new",u.failed>0?s="failed":u.checking>0?s="checking":u.disconnected>0?s="disconnected":u.new>0?s="new":u.connected>0?s="connected":u.completed>0&&(s="completed"),s!==this.iceConnectionState){this.iceConnectionState=s;var d=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",d)}},i.prototype._updateConnectionState=function(){var s,u={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(l){l.iceTransport&&l.dtlsTransport&&!l.rejected&&(u[l.iceTransport.state]++,u[l.dtlsTransport.state]++)}),u.connected+=u.completed,s="new",u.failed>0?s="failed":u.connecting>0?s="connecting":u.disconnected>0?s="disconnected":u.new>0?s="new":u.connected>0&&(s="connected"),s!==this.connectionState){this.connectionState=s;var d=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",d)}},i.prototype.createOffer=function(){var s=this;if(s._isClosed)return Promise.reject(be("InvalidStateError","Can not call createOffer after close"));var u=s.transceivers.filter(function(c){return c.kind==="audio"}).length,d=s.transceivers.filter(function(c){return c.kind==="video"}).length,l=arguments[0];if(l){if(l.mandatory||l.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");l.offerToReceiveAudio!==void 0&&(u=l.offerToReceiveAudio===!0?1:l.offerToReceiveAudio===!1?0:l.offerToReceiveAudio),l.offerToReceiveVideo!==void 0&&(d=l.offerToReceiveVideo===!0?1:l.offerToReceiveVideo===!1?0:l.offerToReceiveVideo)}for(s.transceivers.forEach(function(c){c.kind==="audio"?--u<0&&(c.wantReceive=!1):c.kind==="video"&&--d<0&&(c.wantReceive=!1)});u>0||d>0;)u>0&&(s._createTransceiver("audio"),u--),d>0&&(s._createTransceiver("video"),d--);var h=ne.writeSessionBoilerplate(s._sdpSessionId,s._sdpSessionVersion++);s.transceivers.forEach(function(c,p){var f=c.track,m=c.kind,_=c.mid||ne.generateIdentifier();c.mid=_,c.iceGatherer||(c.iceGatherer=s._createIceGatherer(p,s.usingBundle));var v=n.RTCRtpSender.getCapabilities(m);e<15019&&(v.codecs=v.codecs.filter(function(y){return y.name!=="rtx"})),v.codecs.forEach(function(y){y.name==="H264"&&y.parameters["level-asymmetry-allowed"]===void 0&&(y.parameters["level-asymmetry-allowed"]="1"),c.remoteCapabilities&&c.remoteCapabilities.codecs&&c.remoteCapabilities.codecs.forEach(function(P){y.name.toLowerCase()===P.name.toLowerCase()&&y.clockRate===P.clockRate&&(y.preferredPayloadType=P.payloadType)})}),v.headerExtensions.forEach(function(y){(c.remoteCapabilities&&c.remoteCapabilities.headerExtensions||[]).forEach(function(P){y.uri===P.uri&&(y.id=P.id)})});var R=c.sendEncodingParameters||[{ssrc:1001*(2*p+1)}];f&&e>=15019&&m==="video"&&!R[0].rtx&&(R[0].rtx={ssrc:R[0].ssrc+1}),c.wantReceive&&(c.rtpReceiver=new n.RTCRtpReceiver(c.dtlsTransport,m)),c.localCapabilities=v,c.sendEncodingParameters=R}),s._config.bundlePolicy!=="max-compat"&&(h+="a=group:BUNDLE "+s.transceivers.map(function(c){return c.mid}).join(" ")+`\r
`),h+=`a=ice-options:trickle\r
`,s.transceivers.forEach(function(c,p){h+=ea(c,c.localCapabilities,"offer",c.stream,s._dtlsRole),h+=`a=rtcp-rsize\r
`,!c.iceGatherer||s.iceGatheringState==="new"||p!==0&&s.usingBundle||(c.iceGatherer.getLocalCandidates().forEach(function(f){f.component=1,h+="a="+ne.writeCandidate(f)+`\r
`}),c.iceGatherer.state==="completed"&&(h+=`a=end-of-candidates\r
`))});var a=new n.RTCSessionDescription({type:"offer",sdp:h});return Promise.resolve(a)},i.prototype.createAnswer=function(){var s=this;if(s._isClosed)return Promise.reject(be("InvalidStateError","Can not call createAnswer after close"));if(s.signalingState!=="have-remote-offer"&&s.signalingState!=="have-local-pranswer")return Promise.reject(be("InvalidStateError","Can not call createAnswer in signalingState "+s.signalingState));var u=ne.writeSessionBoilerplate(s._sdpSessionId,s._sdpSessionVersion++);s.usingBundle&&(u+="a=group:BUNDLE "+s.transceivers.map(function(h){return h.mid}).join(" ")+`\r
`),u+=`a=ice-options:trickle\r
`;var d=ne.getMediaSections(s._remoteDescription.sdp).length;s.transceivers.forEach(function(h,a){if(!(a+1>d)){if(h.rejected)return h.kind==="application"?h.protocol==="DTLS/SCTP"?u+=`m=application 0 DTLS/SCTP 5000\r
`:u+="m=application 0 "+h.protocol+` webrtc-datachannel\r
`:h.kind==="audio"?u+=`m=audio 0 UDP/TLS/RTP/SAVPF 0\r
a=rtpmap:0 PCMU/8000\r
`:h.kind==="video"&&(u+=`m=video 0 UDP/TLS/RTP/SAVPF 120\r
a=rtpmap:120 VP8/90000\r
`),void(u+=`c=IN IP4 0.0.0.0\r
a=inactive\r
a=mid:`+h.mid+`\r
`);var c;h.stream&&(h.kind==="audio"?c=h.stream.getAudioTracks()[0]:h.kind==="video"&&(c=h.stream.getVideoTracks()[0]),c&&e>=15019&&h.kind==="video"&&!h.sendEncodingParameters[0].rtx&&(h.sendEncodingParameters[0].rtx={ssrc:h.sendEncodingParameters[0].ssrc+1}));var p=zn(h.localCapabilities,h.remoteCapabilities);!p.codecs.filter(function(f){return f.name.toLowerCase()==="rtx"}).length&&h.sendEncodingParameters[0].rtx&&delete h.sendEncodingParameters[0].rtx,u+=ea(h,p,"answer",h.stream,s._dtlsRole),h.rtcpParameters&&h.rtcpParameters.reducedSize&&(u+=`a=rtcp-rsize\r
`)}});var l=new n.RTCSessionDescription({type:"answer",sdp:u});return Promise.resolve(l)},i.prototype.addIceCandidate=function(s){var u,d=this;return s&&s.sdpMLineIndex===void 0&&!s.sdpMid?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(l,h){if(!d._remoteDescription)return h(be("InvalidStateError","Can not add ICE candidate without a remote description"));if(s&&s.candidate!==""){var a=s.sdpMLineIndex;if(s.sdpMid){for(var c=0;c0?ne.parseCandidate(s.candidate):{};if(f.protocol==="tcp"&&(f.port===0||f.port===9)||f.component&&f.component!==1)return l();if((a===0||a>0&&p.iceTransport!==d.transceivers[0].iceTransport)&&!ii(p.iceTransport,f))return h(be("OperationError","Can not add ICE candidate"));var m=s.candidate.trim();m.indexOf("a=")===0&&(m=m.substr(2)),(u=ne.getMediaSections(d._remoteDescription.sdp))[a]+="a="+(f.type?m:"end-of-candidates")+`\r
`,d._remoteDescription.sdp=ne.getDescription(d._remoteDescription.sdp)+u.join("")}else for(var _=0;_Promise.reject(function(o){return{name:{PermissionDeniedError:"NotAllowedError"}[o.name]||o.name,message:o.message,constraint:o.constraint,toString(){return this.name}}}(i)))}}function yc(n){"getDisplayMedia"in n.navigator&&n.navigator.mediaDevices&&(n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||(n.navigator.mediaDevices.getDisplayMedia=n.navigator.getDisplayMedia.bind(n.navigator)))}function ki(n,e){if(n.RTCIceGatherer&&(n.RTCIceCandidate||(n.RTCIceCandidate=function(r){return r}),n.RTCSessionDescription||(n.RTCSessionDescription=function(r){return r}),e.version<15025)){const r=Object.getOwnPropertyDescriptor(n.MediaStreamTrack.prototype,"enabled");Object.defineProperty(n.MediaStreamTrack.prototype,"enabled",{set(i){r.set.call(this,i);const o=new Event("enabled");o.enabled=i,this.dispatchEvent(o)}})}n.RTCRtpSender&&!("dtmf"in n.RTCRtpSender.prototype)&&Object.defineProperty(n.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=new n.RTCDtmfSender(this):this.track.kind==="video"&&(this._dtmf=null)),this._dtmf}}),n.RTCDtmfSender&&!n.RTCDTMFSender&&(n.RTCDTMFSender=n.RTCDtmfSender);const t=_l(n,e.version);n.RTCPeerConnection=function(r){return r&&r.iceServers&&(r.iceServers=function(i,o){let s=!1;return(i=JSON.parse(JSON.stringify(i))).filter(u=>{if(u&&(u.urls||u.url)){let d=u.urls||u.url;u.url&&!u.urls&&Fr("RTCIceServer.url","RTCIceServer.urls");const l=typeof d=="string";return l&&(d=[d]),d=d.filter(h=>{if(h.indexOf("stun:")===0)return!1;const a=h.startsWith("turn")&&!h.startsWith("turn:[")&&h.includes("transport=udp");return a&&!s?(s=!0,!0):a&&!s}),delete u.url,u.urls=l?d[0]:d,!!d.length}})}(r.iceServers,e.version),jo("ICE servers after filtering:",r.iceServers)),new t(r)},n.RTCPeerConnection.prototype=t.prototype}function Ec(n){n.RTCRtpSender&&!("replaceTrack"in n.RTCRtpSender.prototype)&&(n.RTCRtpSender.prototype.replaceTrack=n.RTCRtpSender.prototype.setTrack)}var na=Object.freeze({__proto__:null,shimPeerConnection:ki,shimReplaceTrack:Ec,shimGetUserMedia:Cc,shimGetDisplayMedia:yc});function Tc(n,e){const t=n&&n.navigator,r=n&&n.MediaStreamTrack;if(t.getUserMedia=function(i,o,s){Fr("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),t.mediaDevices.getUserMedia(i).then(o,s)},!(e.version>55&&"autoGainControl"in t.mediaDevices.getSupportedConstraints())){const i=function(s,u,d){u in s&&!(d in s)&&(s[d]=s[u],delete s[u])},o=t.mediaDevices.getUserMedia.bind(t.mediaDevices);if(t.mediaDevices.getUserMedia=function(s){return typeof s=="object"&&typeof s.audio=="object"&&(s=JSON.parse(JSON.stringify(s)),i(s.audio,"autoGainControl","mozAutoGainControl"),i(s.audio,"noiseSuppression","mozNoiseSuppression")),o(s)},r&&r.prototype.getSettings){const s=r.prototype.getSettings;r.prototype.getSettings=function(){const u=s.apply(this,arguments);return i(u,"mozAutoGainControl","autoGainControl"),i(u,"mozNoiseSuppression","noiseSuppression"),u}}if(r&&r.prototype.applyConstraints){const s=r.prototype.applyConstraints;r.prototype.applyConstraints=function(u){return this.kind==="audio"&&typeof u=="object"&&(u=JSON.parse(JSON.stringify(u)),i(u,"autoGainControl","mozAutoGainControl"),i(u,"noiseSuppression","mozNoiseSuppression")),s.apply(this,[u])}}}}function Sc(n){typeof n=="object"&&n.RTCTrackEvent&&"receiver"in n.RTCTrackEvent.prototype&&!("transceiver"in n.RTCTrackEvent.prototype)&&Object.defineProperty(n.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Di(n,e){if(typeof n!="object"||!n.RTCPeerConnection&&!n.mozRTCPeerConnection)return;!n.RTCPeerConnection&&n.mozRTCPeerConnection&&(n.RTCPeerConnection=n.mozRTCPeerConnection),e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(i){const o=n.RTCPeerConnection.prototype[i],s={[i](){return arguments[0]=new(i==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),o.apply(this,arguments)}};n.RTCPeerConnection.prototype[i]=s[i]});const t={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},r=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[i,o,s]=arguments;return r.apply(this,[i||null]).then(u=>{if(e.version<53&&!o)try{u.forEach(d=>{d.type=t[d.type]||d.type})}catch(d){if(d.name!=="TypeError")throw d;u.forEach((l,h)=>{u.set(h,Object.assign({},l,{type:t[l.type]||l.type}))})}return u}).then(o,s)}}function Ic(n){if(typeof n!="object"||!n.RTCPeerConnection||!n.RTCRtpSender||n.RTCRtpSender&&"getStats"in n.RTCRtpSender.prototype)return;const e=n.RTCPeerConnection.prototype.getSenders;e&&(n.RTCPeerConnection.prototype.getSenders=function(){const r=e.apply(this,[]);return r.forEach(i=>i._pc=this),r});const t=n.RTCPeerConnection.prototype.addTrack;t&&(n.RTCPeerConnection.prototype.addTrack=function(){const r=t.apply(this,arguments);return r._pc=this,r}),n.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function bc(n){if(typeof n!="object"||!n.RTCPeerConnection||!n.RTCRtpSender||n.RTCRtpSender&&"getStats"in n.RTCRtpReceiver.prototype)return;const e=n.RTCPeerConnection.prototype.getReceivers;e&&(n.RTCPeerConnection.prototype.getReceivers=function(){const t=e.apply(this,[]);return t.forEach(r=>r._pc=this),t}),Jt(n,"track",t=>(t.receiver._pc=t.srcElement,t)),n.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function Oc(n){n.RTCPeerConnection&&!("removeStream"in n.RTCPeerConnection.prototype)&&(n.RTCPeerConnection.prototype.removeStream=function(e){Fr("removeStream","removeTrack"),this.getSenders().forEach(t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)})})}function Nc(n){n.DataChannel&&!n.RTCDataChannel&&(n.RTCDataChannel=n.DataChannel)}function wc(n){if(typeof n!="object"||!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype.addTransceiver;e&&(n.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const t=arguments[1],r=t&&"sendEncodings"in t;r&&t.sendEncodings.forEach(o=>{if("rid"in o&&!/^[a-z0-9]{0,16}$/i.test(o.rid))throw new TypeError("Invalid RID value provided.");if("scaleResolutionDownBy"in o&&!(parseFloat(o.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in o&&!(parseFloat(o.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")});const i=e.apply(this,arguments);if(r){const{sender:o}=i,s=o.getParameters();(!("encodings"in s)||s.encodings.length===1&&Object.keys(s.encodings[0]).length===0)&&(s.encodings=t.sendEncodings,o.sendEncodings=t.sendEncodings,this.setParametersPromises.push(o.setParameters(s).then(()=>{delete o.sendEncodings}).catch(()=>{delete o.sendEncodings})))}return i})}function Mc(n){if(typeof n!="object"||!n.RTCRtpSender)return;const e=n.RTCRtpSender.prototype.getParameters;e&&(n.RTCRtpSender.prototype.getParameters=function(){const t=e.apply(this,arguments);return"encodings"in t||(t.encodings=[].concat(this.sendEncodings||[{}])),t})}function Ac(n){if(typeof n!="object"||!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype.createOffer;n.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}function Pc(n){if(typeof n!="object"||!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype.createAnswer;n.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}var ra=Object.freeze({__proto__:null,shimOnTrack:Sc,shimPeerConnection:Di,shimSenderGetStats:Ic,shimReceiverGetStats:bc,shimRemoveStream:Oc,shimRTCDataChannel:Nc,shimAddTransceiver:wc,shimGetParameters:Mc,shimCreateOffer:Ac,shimCreateAnswer:Pc,shimGetUserMedia:Tc,shimGetDisplayMedia:function(n,e){n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||n.navigator.mediaDevices&&(n.navigator.mediaDevices.getDisplayMedia=function(t){if(!t||!t.video){const r=new DOMException("getDisplayMedia without video constraints is undefined");return r.name="NotFoundError",r.code=8,Promise.reject(r)}return t.video===!0?t.video={mediaSource:e}:t.video.mediaSource=e,n.navigator.mediaDevices.getUserMedia(t)})}});function Lc(n){if(typeof n=="object"&&n.RTCPeerConnection){if("getLocalStreams"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in n.RTCPeerConnection.prototype)){const e=n.RTCPeerConnection.prototype.addTrack;n.RTCPeerConnection.prototype.addStream=function(t){this._localStreams||(this._localStreams=[]),this._localStreams.includes(t)||this._localStreams.push(t),t.getAudioTracks().forEach(r=>e.call(this,r,t)),t.getVideoTracks().forEach(r=>e.call(this,r,t))},n.RTCPeerConnection.prototype.addTrack=function(t,...r){return r&&r.forEach(i=>{this._localStreams?this._localStreams.includes(i)||this._localStreams.push(i):this._localStreams=[i]}),e.apply(this,arguments)}}"removeStream"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||(this._localStreams=[]);const t=this._localStreams.indexOf(e);if(t===-1)return;this._localStreams.splice(t,1);const r=e.getTracks();this.getSenders().forEach(i=>{r.includes(i.track)&&this.removeTrack(i)})})}}function kc(n){if(typeof n=="object"&&n.RTCPeerConnection&&("getRemoteStreams"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in n.RTCPeerConnection.prototype))){Object.defineProperty(n.RTCPeerConnection.prototype,"onaddstream",{get(){return this._onaddstream},set(t){this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=t),this.addEventListener("track",this._onaddstreampoly=r=>{r.streams.forEach(i=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(i))return;this._remoteStreams.push(i);const o=new Event("addstream");o.stream=i,this.dispatchEvent(o)})})}});const e=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){const t=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(r){r.streams.forEach(i=>{if(t._remoteStreams||(t._remoteStreams=[]),t._remoteStreams.indexOf(i)>=0)return;t._remoteStreams.push(i);const o=new Event("addstream");o.stream=i,t.dispatchEvent(o)})}),e.apply(t,arguments)}}}function Dc(n){if(typeof n!="object"||!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype,t=e.createOffer,r=e.createAnswer,i=e.setLocalDescription,o=e.setRemoteDescription,s=e.addIceCandidate;e.createOffer=function(d,l){const h=arguments.length>=2?arguments[2]:arguments[0],a=t.apply(this,[h]);return l?(a.then(d,l),Promise.resolve()):a},e.createAnswer=function(d,l){const h=arguments.length>=2?arguments[2]:arguments[0],a=r.apply(this,[h]);return l?(a.then(d,l),Promise.resolve()):a};let u=function(d,l,h){const a=i.apply(this,[d]);return h?(a.then(l,h),Promise.resolve()):a};e.setLocalDescription=u,u=function(d,l,h){const a=o.apply(this,[d]);return h?(a.then(l,h),Promise.resolve()):a},e.setRemoteDescription=u,u=function(d,l,h){const a=s.apply(this,[d]);return h?(a.then(l,h),Promise.resolve()):a},e.addIceCandidate=u}function Uc(n){const e=n&&n.navigator;if(e.mediaDevices&&e.mediaDevices.getUserMedia){const t=e.mediaDevices,r=t.getUserMedia.bind(t);e.mediaDevices.getUserMedia=i=>r(xc(i))}!e.getUserMedia&&e.mediaDevices&&e.mediaDevices.getUserMedia&&(e.getUserMedia=function(t,r,i){e.mediaDevices.getUserMedia(t).then(r,i)}.bind(e))}function xc(n){return n&&n.video!==void 0?Object.assign({},n,{video:dc(n.video)}):n}function Vc(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection;n.RTCPeerConnection=function(t,r){if(t&&t.iceServers){const i=[];for(let o=0;oe.generateCertificate})}function Bc(n){typeof n=="object"&&n.RTCTrackEvent&&"receiver"in n.RTCTrackEvent.prototype&&!("transceiver"in n.RTCTrackEvent.prototype)&&Object.defineProperty(n.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Fc(n){const e=n.RTCPeerConnection.prototype.createOffer;n.RTCPeerConnection.prototype.createOffer=function(t){if(t){t.offerToReceiveAudio!==void 0&&(t.offerToReceiveAudio=!!t.offerToReceiveAudio);const r=this.getTransceivers().find(o=>o.receiver.track.kind==="audio");t.offerToReceiveAudio===!1&&r?r.direction==="sendrecv"?r.setDirection?r.setDirection("sendonly"):r.direction="sendonly":r.direction==="recvonly"&&(r.setDirection?r.setDirection("inactive"):r.direction="inactive"):t.offerToReceiveAudio!==!0||r||this.addTransceiver("audio"),t.offerToReceiveVideo!==void 0&&(t.offerToReceiveVideo=!!t.offerToReceiveVideo);const i=this.getTransceivers().find(o=>o.receiver.track.kind==="video");t.offerToReceiveVideo===!1&&i?i.direction==="sendrecv"?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":i.direction==="recvonly"&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):t.offerToReceiveVideo!==!0||i||this.addTransceiver("video")}return e.apply(this,arguments)}}function $c(n){typeof n!="object"||n.AudioContext||(n.AudioContext=n.webkitAudioContext)}var ia=Object.freeze({__proto__:null,shimLocalStreamsAPI:Lc,shimRemoteStreamsAPI:kc,shimCallbacksAPI:Dc,shimGetUserMedia:Uc,shimConstraints:xc,shimRTCIceServerUrls:Vc,shimTrackEventTransceiver:Bc,shimCreateOfferLegacy:Fc,shimAudioContext:$c});function er(n){if(!n.RTCIceCandidate||n.RTCIceCandidate&&"foundation"in n.RTCIceCandidate.prototype)return;const e=n.RTCIceCandidate;n.RTCIceCandidate=function(t){if(typeof t=="object"&&t.candidate&&t.candidate.indexOf("a=")===0&&((t=JSON.parse(JSON.stringify(t))).candidate=t.candidate.substr(2)),t.candidate&&t.candidate.length){const r=new e(t),i=ne.parseCandidate(t.candidate),o=Object.assign(r,i);return o.toJSON=function(){return{candidate:o.candidate,sdpMid:o.sdpMid,sdpMLineIndex:o.sdpMLineIndex,usernameFragment:o.usernameFragment}},o}return new e(t)},n.RTCIceCandidate.prototype=e.prototype,Jt(n,"icecandidate",t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new n.RTCIceCandidate(t.candidate),writable:"false"}),t))}function un(n,e){if(!n.RTCPeerConnection)return;"sctp"in n.RTCPeerConnection.prototype||Object.defineProperty(n.RTCPeerConnection.prototype,"sctp",{get(){return this._sctp===void 0?null:this._sctp}});const t=function(u){if(!u||!u.sdp)return!1;const d=ne.splitSections(u.sdp);return d.shift(),d.some(l=>{const h=ne.parseMLine(l);return h&&h.kind==="application"&&h.protocol.indexOf("SCTP")!==-1})},r=function(u){const d=u.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(d===null||d.length<2)return-1;const l=parseInt(d[1],10);return l!=l?-1:l},i=function(u){let d=65536;return e.browser==="firefox"&&(d=e.version<57?u===-1?16384:2147483637:e.version<60?e.version===57?65535:65536:2147483637),d},o=function(u,d){let l=65536;e.browser==="firefox"&&e.version===57&&(l=65535);const h=ne.matchPrefix(u.sdp,"a=max-message-size:");return h.length>0?l=parseInt(h[0].substr(19),10):e.browser==="firefox"&&d!==-1&&(l=2147483637),l},s=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,e.browser==="chrome"&&e.version>=76){const{sdpSemantics:u}=this.getConfiguration();u==="plan-b"&&Object.defineProperty(this,"sctp",{get(){return this._sctp===void 0?null:this._sctp},enumerable:!0,configurable:!0})}if(t(arguments[0])){const u=r(arguments[0]),d=i(u),l=o(arguments[0],u);let h;h=d===0&&l===0?Number.POSITIVE_INFINITY:d===0||l===0?Math.max(d,l):Math.min(d,l);const a={};Object.defineProperty(a,"maxMessageSize",{get:()=>h}),this._sctp=a}return s.apply(this,arguments)}}function dn(n){if(!n.RTCPeerConnection||!("createDataChannel"in n.RTCPeerConnection.prototype))return;function e(r,i){const o=r.send;r.send=function(){const s=arguments[0],u=s.length||s.size||s.byteLength;if(r.readyState==="open"&&i.sctp&&u>i.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+i.sctp.maxMessageSize+" bytes)");return o.apply(r,arguments)}}const t=n.RTCPeerConnection.prototype.createDataChannel;n.RTCPeerConnection.prototype.createDataChannel=function(){const r=t.apply(this,arguments);return e(r,this),r},Jt(n,"datachannel",r=>(e(r.channel,r.target),r))}function Ui(n){if(!n.RTCPeerConnection||"connectionState"in n.RTCPeerConnection.prototype)return;const e=n.RTCPeerConnection.prototype;Object.defineProperty(e,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(e,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(t){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),t&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=t)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach(t=>{const r=e[t];e[t]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=i=>{const o=i.target;if(o._lastConnectionState!==o.connectionState){o._lastConnectionState=o.connectionState;const s=new Event("connectionstatechange",i);o.dispatchEvent(s)}return i},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),r.apply(this,arguments)}})}function xi(n,e){if(!n.RTCPeerConnection||e.browser==="chrome"&&e.version>=71||e.browser==="safari"&&e.version>=605)return;const t=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(r){if(r&&r.sdp&&r.sdp.indexOf(`
a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
`).filter(o=>o.trim()!=="a=extmap-allow-mixed").join(`
`);n.RTCSessionDescription&&r instanceof n.RTCSessionDescription?arguments[0]=new n.RTCSessionDescription({type:r.type,sdp:i}):r.sdp=i}return t.apply(this,arguments)}}function tr(n,e){if(!n.RTCPeerConnection||!n.RTCPeerConnection.prototype)return;const t=n.RTCPeerConnection.prototype.addIceCandidate;t&&t.length!==0&&(n.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(e.browser==="chrome"&&e.version<78||e.browser==="firefox"&&e.version<68||e.browser==="safari")&&arguments[0]&&arguments[0].candidate===""?Promise.resolve():t.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}var vl=Object.freeze({__proto__:null,shimRTCIceCandidate:er,shimMaxMessageSize:un,shimSendThrowTypeError:dn,shimConnectionState:Ui,removeExtmapAllowMixed:xi,shimAddIceCandidateNullOrEmpty:tr});const Rl=function({window:n}={},e={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const t=jo,r=function(o){const s={browser:null,version:null};if(o===void 0||!o.navigator)return s.browser="Not a browser.",s;const{navigator:u}=o;if(u.mozGetUserMedia)s.browser="firefox",s.version=an(u.userAgent,/Firefox\/(\d+)\./,1);else if(u.webkitGetUserMedia||o.isSecureContext===!1&&o.webkitRTCPeerConnection&&!o.RTCIceGatherer)s.browser="chrome",s.version=an(u.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(u.mediaDevices&&u.userAgent.match(/Edge\/(\d+).(\d+)$/))s.browser="edge",s.version=an(u.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!o.RTCPeerConnection||!u.userAgent.match(/AppleWebKit\/(\d+)\./))return s.browser="Not a supported browser.",s;s.browser="safari",s.version=an(u.userAgent,/AppleWebKit\/(\d+)\./,1),s.supportsUnifiedPlan=o.RTCRtpTransceiver&&"currentDirection"in o.RTCRtpTransceiver.prototype}return s}(n),i={browserDetails:r,commonShim:vl,extractVersion:an,disableLog:gl,disableWarnings:ml};switch(r.browser){case"chrome":if(!Qs||!Li||!e.shimChrome)return t("Chrome shim is not included in this adapter release."),i;if(r.version===null)return t("Chrome shim can not determine version, not shimming."),i;t("adapter.js shimming chrome."),i.browserShim=Qs,tr(n,r),lc(n,r),hc(n),Li(n,r),pc(n),vc(n,r),fc(n),gc(n),mc(n),Rc(n,r),er(n),Ui(n),un(n,r),dn(n),xi(n,r);break;case"firefox":if(!ra||!Di||!e.shimFirefox)return t("Firefox shim is not included in this adapter release."),i;t("adapter.js shimming firefox."),i.browserShim=ra,tr(n,r),Tc(n,r),Di(n,r),Sc(n),Oc(n),Ic(n),bc(n),Nc(n),wc(n),Mc(n),Ac(n),Pc(n),er(n),Ui(n),un(n,r),dn(n);break;case"edge":if(!na||!ki||!e.shimEdge)return t("MS edge shim is not included in this adapter release."),i;t("adapter.js shimming edge."),i.browserShim=na,Cc(n),yc(n),ki(n,r),Ec(n),un(n,r),dn(n);break;case"safari":if(!ia||!e.shimSafari)return t("Safari shim is not included in this adapter release."),i;t("adapter.js shimming safari."),i.browserShim=ia,tr(n,r),Vc(n),Fc(n),Dc(n),Lc(n),kc(n),Bc(n),Uc(n),$c(n),er(n),un(n,r),dn(n),xi(n,r);break;default:t("Unsupported browser!")}return i}({window:typeof window=="undefined"?void 0:window});var Qe,ge,he;(function(n){n.FPS_10="FPS_10",n.FPS_15="FPS_15",n.FPS_24="FPS_24",n.FPS_30="FPS_30"})(Qe||(Qe={})),function(n){n.W176_H132="W176_H132",n.W176_H144="W176_H144",n.W256_H144="W256_H144",n.W320_H180="W320_H180",n.W240_H240="W240_H240",n.W320_H240="W320_H240",n.W480_H360="W480_H360",n.W640_H360="W640_H360",n.W480_H480="W480_H480",n.W640_H480="W640_H480",n.W720_H480="W720_H480",n.W1280_H720="W1280_H720",n.W1920_H1080="W1920_H1080"}(ge||(ge={})),function(n){n[n.AUDIO_ONLY=0]="AUDIO_ONLY",n[n.VIDEO_ONLY=1]="VIDEO_ONLY",n[n.AUDIO_VIDEO=2]="AUDIO_VIDEO"}(he||(he={}));const oa={[ge.W176_H132]:{width:176,height:132,maxBitrate:150,minBitrate:80},[ge.W176_H144]:{width:176,height:144,maxBitrate:160,minBitrate:80},[ge.W256_H144]:{width:256,height:144,maxBitrate:240,minBitrate:120},[ge.W320_H180]:{width:320,height:180,maxBitrate:280,minBitrate:120},[ge.W240_H240]:{width:240,height:240,maxBitrate:280,minBitrate:120},[ge.W320_H240]:{width:320,height:240,maxBitrate:400,minBitrate:120},[ge.W480_H360]:{width:480,height:360,maxBitrate:650,minBitrate:150},[ge.W640_H360]:{width:640,height:360,maxBitrate:800,minBitrate:180},[ge.W480_H480]:{width:480,height:480,maxBitrate:800,minBitrate:180},[ge.W640_H480]:{width:640,height:480,maxBitrate:900,minBitrate:200},[ge.W720_H480]:{width:720,height:480,maxBitrate:1e3,minBitrate:200},[ge.W1280_H720]:{width:1280,height:720,maxBitrate:2200,minBitrate:250},[ge.W1920_H1080]:{width:1920,height:1080,maxBitrate:4e3,minBitrate:400}},Hc=(n,e)=>{const t=n*e;let r=Number.MAX_VALUE,i=null;for(const o in oa){const s=oa[o],u=Math.abs(s.width*s.height-t);u{let e=Number.MAX_VALUE,t=1;for(const r in sa){const i=Math.abs(n-parseInt(r));iH(void 0,void 0,void 0,function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind==="videoinput")}),getMicrophones:()=>H(void 0,void 0,void 0,function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind==="audioinput")}),getSpeakers:()=>H(void 0,void 0,void 0,function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind==="audiooutput")})};class qo extends On{constructor(e,t,r,i,o){super(),this._tag=e,this._userId=t,this._kind=r,this._isLocalTrack=i,this._roomId=o,this._localMuted=!1,this._remoteMuted=!1,this._streamId=[this._userId||this._roomId,this._tag].join("_"),this._id=[this._streamId,this.isAudioTrack()?0:1].join("_")}getStreamId(){return this._streamId}getTrackId(){return this._id}getUserId(){return this._userId}__innerGetMediaStreamTrack(){return this._msTrack}getTag(){return this._tag}isLocalTrack(){return this._isLocalTrack}isVideoTrack(){return this._kind==="video"}isAudioTrack(){return this._kind==="audio"}isReady(){var e;return((e=this._msTrack)===null||e===void 0?void 0:e.readyState)==="live"}__innerSetMediaStreamTrack(e){this._msTrack=e,this._setLocalMuted(this._localMuted);const t=this._msStream=this._msStream||new MediaStream,r=t.getTracks()[0];r&&t.removeTrack(r),e?t.addTrack(e):this._element&&(this._element.pause(),this._element.srcObject=null)}_setLocalMuted(e){this._msTrack&&(this._msTrack.enabled=!e),this._localMuted=e}mute(){M.info(`set ${this._id} enabled: false`),this._setLocalMuted(!0)}unmute(){M.info(`set ${this._id} enabled: true`),this._setLocalMuted(!1)}isLocalMuted(){return this._localMuted}isMCUTrack(){return Boolean(this._roomId)}isOwnerMuted(){return this._remoteMuted}play(e,t){return H(this,void 0,void 0,function*(){if(!this._msTrack)return M.warn(`the track is not ready to play -> id: ${this._id}`),{code:w.TRACK_NOT_READY};if(this._msTrack.readyState==="ended"&&M.warn(`the track's readyState is 'ended' -> id: ${this._id}`),t==null?void 0:t.volume){if(!_e(t==null?void 0:t.volume))return M.error(`${t==null?void 0:t.volume} is not a number, the valid range of options.volume is 0-100`),{code:w.PARAMS_ERROR};(t==null?void 0:t.volume)<0&&(t.volume=0,M.warn("the valid range of options.volume is 0-100, the value of volume has been set 0")),(t==null?void 0:t.volume)>100&&(t.volume=100,M.warn("the valid range of options.volume is 0-100, the value of volume has been set 100"))}if((t==null?void 0:t.audioDeviceId)&&!(yield Ko.getSpeakers()).map(i=>i.deviceId).includes(t.audioDeviceId))return M.error(`the options.audioDeviceId is invalid --> ${t.audioDeviceId}`),{code:w.PARAMS_ERROR};const r=this.isVideoTrack();if(r&&(!e||!(e instanceof HTMLVideoElement)))return M.error(`the video track need an