iosignal 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/io.js CHANGED
@@ -19,5 +19,5 @@ var s=(r||(r=1,function(r){const n=function(){if(t)return i;t=1,i.byteLength=fun
19
19
  *
20
20
  * @author Feross Aboukhadijeh <https://feross.org>
21
21
  * @license MIT
22
- */var Ht=(Dt||(Dt=1,function(t){const e=function(){if(xt)return jt;xt=1,jt.byteLength=function(t){var e=o(t),r=e[0],n=e[1];return 3*(r+n)/4-n},jt.toByteArray=function(t){var n,i,s=o(t),f=s[0],u=s[1],h=new r(function(t,e,r){return 3*(e+r)/4-r}(0,f,u)),a=0,c=u>0?f-4:f;for(i=0;i<c;i+=4)n=e[t.charCodeAt(i)]<<18|e[t.charCodeAt(i+1)]<<12|e[t.charCodeAt(i+2)]<<6|e[t.charCodeAt(i+3)],h[a++]=n>>16&255,h[a++]=n>>8&255,h[a++]=255&n;return 2===u&&(n=e[t.charCodeAt(i)]<<2|e[t.charCodeAt(i+1)]>>4,h[a++]=255&n),1===u&&(n=e[t.charCodeAt(i)]<<10|e[t.charCodeAt(i+1)]<<4|e[t.charCodeAt(i+2)]>>2,h[a++]=n>>8&255,h[a++]=255&n),h},jt.fromByteArray=function(e){for(var r,n=e.length,i=n%3,o=[],f=16383,u=0,h=n-i;u<h;u+=f)o.push(s(e,u,u+f>h?h:u+f));return 1===i?(r=e[n-1],o.push(t[r>>2]+t[r<<4&63]+"==")):2===i&&(r=(e[n-2]<<8)+e[n-1],o.push(t[r>>10]+t[r>>4&63]+t[r<<2&63]+"=")),o.join("")};for(var t=[],e=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)t[i]=n[i],e[n.charCodeAt(i)]=i;function o(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function s(e,r,n){for(var i,o,s=[],f=r;f<n;f+=3)i=(e[f]<<16&16711680)+(e[f+1]<<8&65280)+(255&e[f+2]),s.push(t[(o=i)>>18&63]+t[o>>12&63]+t[o>>6&63]+t[63&o]);return s.join("")}return e["-".charCodeAt(0)]=62,e["_".charCodeAt(0)]=63,jt}(),r=Ft(),n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=s,t.SlowBuffer=function(t){return+t!=t&&(t=0),s.alloc(+t)},t.INSPECT_MAX_BYTES=50;const i=2147483647;function o(t){if(t>i)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return h(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|p(t,e);let n=o(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(q(t,Uint8Array)){const e=new Uint8Array(t);return c(e.buffer,e.byteOffset,e.byteLength)}return a(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer))return c(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return c(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);const i=function(t){if(s.isBuffer(t)){const e=0|l(t.length),r=o(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||J(t.length)?o(0):a(t):"Buffer"===t.type&&Array.isArray(t.data)?a(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t){return u(t),o(t<0?0:0|l(t))}function a(t){const e=t.length<0?0:0|l(t.length),r=o(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function c(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function l(t){if(t>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|t}function p(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(t).length;default:if(i)return n?-1:G(t).length;e=(""+e).toLowerCase(),i=!0}}function y(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return T(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return L(this,e,r);case"latin1":case"binary":return v(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),J(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,i){let o,s=1,f=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,f/=2,u/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){let n=-1;for(o=r;o<f;o++)if(h(t,o)===h(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>f&&(r=f-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(h(t,o+n)!==h(e,n)){r=!1;break}if(r)return o}return-1}function w(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(e.substr(2*s,2),16);if(J(n))return s;t[r+s]=n}return s}function E(t,e,r,n){return V(G(e,t.length-r),t,r,n)}function B(t,e,r,n){return V(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function m(t,e,r,n){return V(Y(e),t,r,n)}function A(t,e,r,n){return V(function(t,e){let r,n,i;const o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function _(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function I(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,s=e>239?4:e>223?3:e>191?2:1;if(i+s<=r){let r,n,f,u;switch(s){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(o=u));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=t[i+1],n=t[i+2],f=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&f)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&f,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(t){const e=t.length;if(e<=U)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=U));return r}(n)}t.kMaxLength=i,s.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return u(t),t<=0?o(t):void 0!==e?"string"==typeof r?o(t).fill(e,r):o(t).fill(e):o(t)}(t,e,r)},s.allocUnsafe=function(t){return h(t)},s.allocUnsafeSlow=function(t){return h(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),q(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=s.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(q(e,Uint8Array))i+e.length>n.length?(s.isBuffer(e)||(e=s.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!s.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},s.byteLength=p,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},s.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},s.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},s.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?I(this,0,t):y.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(s.prototype[n]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,i){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),f=(r>>>=0)-(e>>>=0);const u=Math.min(o,f),h=this.slice(n,i),a=t.slice(e,r);for(let t=0;t<u;++t)if(h[t]!==a[t]){o=h[t],f=a[t];break}return o<f?-1:f<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return d(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return d(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return w(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return B(this,t,e,r);case"base64":return m(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const U=4096;function L(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function v(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function T(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=Q[t[n]];return i}function S(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function R(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function O(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function M(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function C(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function N(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function k(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,4),r.write(t,e,n,i,23,4),n+4}function x(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,8),r.write(t,e,n,i,52,8),n+8}s.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,s.prototype),n},s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),s.prototype.readBigUInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),s.prototype.readBigInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),s.prototype.readFloatLE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigUInt64LE=K((function(t,e=0){return M(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=K((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=0,o=1,s=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigInt64LE=K((function(t,e=0){return M(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=K((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return k(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return k(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=s.isBuffer(t)?t:s.from(t,n),f=o.length;if(0===f)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%f]}return this};const P={};function D(t,e,r){P[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function $(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,i,o){if(t>r||t<e){const r="bigint"==typeof e?"n":"";let n;throw n=0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new P.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||F(e,t.length-(r+1))}(n,i,o)}function z(t,e){if("number"!=typeof t)throw new P.ERR_INVALID_ARG_TYPE(e,"number",t)}function F(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new P.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=$(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=$(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const H=/[^+/0-9A-Za-z-_]/g;function G(t,e){let r;e=e||1/0;const n=t.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(H,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function K(t){return"undefined"==typeof BigInt?W:t}function W(){throw new Error("BigInt not supported")}}($t)),$t);let Gt={AUTH_REQ:176,AUTH_NONCE:177,AUTH_HMAC:178,AUTH_ACK:179,AUTH_FAIL:180,AUTH_EXT:181,ENC_PACK:182,ENC_E2E:183,ENC_488:184};for(let t in Gt)Gt[Gt[t]]=t;const Yt={AUTH_REQ:Nt.meta(Nt.MB("header","8",0),Nt.MB("reserved","8",0)),AUTH_NONCE:Nt.meta(Nt.MB("header","8",0),Nt.MB("unixTime","32L",0),Nt.MB("milTime","32L",0),Nt.MB("nonce",Ht.Buffer.alloc(4))),AUTH_HMAC:Nt.meta(Nt.MB("header","8",0),Nt.MB("id8",Ht.Buffer.alloc(8)),Nt.MB("nonce",Ht.Buffer.alloc(4)),Nt.MB("hmac32",Ht.Buffer.alloc(32))),AUTH_ACK:Nt.meta(Nt.MB("header","8",0),Nt.MB("hmac32",Ht.Buffer.alloc(32))),ENC_PACK:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("salt12",Ht.Buffer.alloc(12)),Nt.MB("hmac",8,0)),ENC_488:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("otpSrc8",Ht.Buffer.alloc(8)),Nt.MB("hmac8",Ht.Buffer.alloc(8)))};function Vt(t){let e=t[t.length-1];return e[2]+e[3]}const qt={AUTH_REQ:Vt(Yt.AUTH_REQ),AUTH_NONCE:Vt(Yt.AUTH_NONCE),AUTH_HMAC:Vt(Yt.AUTH_HMAC),AUTH_ACK:Vt(Yt.AUTH_ACK),ENC_PACK:Vt(Yt.ENC_PACK),ENC_488:Vt(Yt.ENC_488)};function Jt(t){return globalThis.crypto.getRandomValues(Ht.Buffer.alloc(t))}class Qt{constructor(){this._id8=Ht.Buffer.alloc(8),this._otpSrc44=Ht.Buffer.alloc(44),this._otp36=Ht.Buffer.alloc(36),this._hmac=Ht.Buffer.alloc(32),this.auth_salt12=Ht.Buffer.alloc(12),this.localNonce=Ht.Buffer.alloc(4),this.remoteNonce=Ht.Buffer.alloc(4),this.isAuthorized=!1}clearAuth(){this._id8.fill(0),this._otpSrc44.fill(0),this._otp36.fill(0),this._hmac.fill(0),this.auth_salt12.fill(0),this.localNonce.fill(0),this.remoteNonce.fill(0),this.isAuthorized=!1}set_hash_id8(t){Nt.B8(kt.hash(t)).copy(this._id8,0,0,8)}set_id8(t){let e=Nt.B8(t);this._id8.fill(0),e.copy(this._id8,0,0,8)}set_key(t){Nt.B8(kt.hash(t)).copy(this._otpSrc44,0,0,32)}set_id_key(t){let e=t.indexOf(".");if(-1==e)return;let r=t.substring(0,e),n=t.substring(e+1);this.set_id8(r),this.set_key(n)}copy_id8(t){t.copy(this._id8,0,0,8)}copy_key(t){t.copy(this._otpSrc44,0,0,32)}sha256_n(t,e){let r=kt.hash(t);for(let t=0;t<e;t++)r=kt.hash(r);return r}set_clock_rand(){let t=Date.now(),e=parseInt(t/1e3);t%=4294967295,Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",t),Jt(4)]).copy(this._otpSrc44,32)}set_clock_nonce(t){let e=Date.now(),r=parseInt(e/1e3);e%=4294967295,Ht.Buffer.concat([Nt.NB("32L",r),Nt.NB("32L",e),t]).copy(this._otpSrc44,32)}set_salt12(t){t.copy(this._otpSrc44,32)}resetOTP(){Nt.B8(kt.hash(this._otpSrc44)).copy(this._otp36,0,0,32)}getIndexOTP(t){return this._otp36.writeUInt32LE(t,32),kt.hash(this._otp36)}generateHMAC(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);this._hmac=Nt.B8(kt.hash(e))}getHMAC8(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);return this._hmac=Nt.B8(kt.hash(e)),this._hmac.subarray(0,8)}xotp(t,e=0,r=!1){let n=(t=Nt.B8(t,r)).byteLength,i=e,o=0,s=0;for(;n>0;){s=n<32?n:32;let e=this.getIndexOTP(++i);for(let r=0;r<s;r++)t[o++]^=e[r];n-=32}return t}auth_req(){return Nt.pack(Nt.MB("#type","8",Gt.AUTH_REQ),Nt.MB("#reserved","8",0))}auth_nonce(){let t=Date.now(),e=Math.floor(t/1e3),r=t%1e3;return this.localNonce=Jt(4),this.auth_salt12=Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",r),this.localNonce]),Ht.Buffer.concat([Nt.NB("8",Gt.AUTH_NONCE),this.auth_salt12])}auth_hmac(t){let e=Nt.unpack(t,Yt.AUTH_NONCE);if(e){let t=Ht.Buffer.concat([Nt.NB("32L",e.unixTime),Nt.NB("32L",e.milTime),e.nonce]);return this.set_salt12(t),this.localNonce=Jt(4),this.generateHMAC(this.localNonce),this.remoteNonce=e.nonce,Nt.pack(Nt.MB("#header","8",Gt.AUTH_HMAC),Nt.MB("#id8",this._id8),Nt.MB("#nonce",this.localNonce),Nt.MB("#hmac32",this._hmac))}return!1}check_auth_hmac(t){let e;if(t instanceof Uint8Array){if(e=Nt.unpack(t,Yt.AUTH_HMAC),!e)return}else e=t;this.set_salt12(this.auth_salt12),this.generateHMAC(e.nonce);let r=this._hmac;if(Nt.equal(e.hmac32,r)){this.remoteNonce=e.nonce;let t=Ht.Buffer.concat([this.localNonce,this.remoteNonce,this.localNonce]);this.set_salt12(t),this.generateHMAC(e.nonce);let r=this._hmac,n=Nt.rawPack(Nt.MB("header","8",Gt.AUTH_ACK),Nt.MB("hmac32",r));return this.isAuthorized=!0,n}return!1}check_auth_ack_hmac(t){let e=Nt.unpack(t,Yt.AUTH_ACK);if(e){let t=Ht.Buffer.concat([this.remoteNonce,this.localNonce,this.remoteNonce]);this.set_salt12(t),this.generateHMAC(this.localNonce);let r=this._hmac;if(Nt.equal(r,e.hmac32))return this.isAuthorized=!0,!0}}encrypt_488(t){if(!this.isAuthorized)return;t=Nt.B8(t),this.set_clock_nonce(this.remoteNonce),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_488),Nt.MB("#len","32L",t.byteLength),Nt.MB("#otpSrc8",this._otpSrc44.subarray(32,40)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decrypt_488(t){t=Nt.B8(t);let e=Nt.unpack(t,Yt.ENC_488);if(e){let t=Ht.Buffer.concat([e.otpSrc8,this.localNonce]);this.set_salt12(t),this.resetOTP();let r=e.$OTHERS.subarray(0,e.len),n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(i,e.hmac8))return n}}encryptPack(t){t=Nt.B8(t),this.set_clock_rand(),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_PACK),Nt.MB("#len","32L",t.byteLength),Nt.MB("#salt12",this._otpSrc44.subarray(32)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decryptPack(t){if(t[0]===Gt.ENC_PACK&&t.readUint32LE(1)==t.byteLength-qt.ENC_PACK)try{let e=Nt.unpack(t,Yt.ENC_PACK);if(!e)return;this.set_salt12(e.salt12),this.resetOTP();let r=e.$OTHERS,n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(e.hmac,i))return e.data=n,e}catch(t){}}encrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.encryptPack(t);return this._otpSrc44.set(r),n}decrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.decryptPack(t);return this._otpSrc44.set(r),n}}Qt.RAND=Jt,Qt.BohoMsg=Gt,Qt.Meta=Yt,Qt.MetaSize=qt,Qt.sha256=kt,Qt.MBP=Nt,Qt.Buffer=Ht.Buffer;const Kt=C.Buffer,Wt=new TextEncoder,Xt=new TextDecoder;class Zt extends D{constructor(t){super(),this.cid="",this.ip="",this.socket=null,this.url=t,this.state=$.CLOSED,this.stateName=this.getStateName(),this.txCounter=0,this.rxCounter=0,this.txBytes=0,this.rxBytes=0,this.lastTxRxTime=Date.now(),this.connectionCheckerPeriod=F.CONNECTION_CHECKER_PERIOD,this.connectionCheckerIntervalID=null,this.boho=new Qt,this.TLS=!1,this.encMode=z.AUTO,this.useAuth=!1,this.nick="",this.channels=new Set,this.promiseMap=new Map,this.promiseTimeOut=F.PROMISE_TIMEOUT,this.mid=0,this.level=3,this.quota=V[this.level],this.serverSet={},this.linkMap=new Map,this.autoReconnect=!0,this._closed=!1,this.on("open",this.onOpen.bind(this)),this.on("close",this.onClose.bind(this)),this.on("socket_data",this.onData.bind(this))}close(){if(!this._closed){if(this._closed=!0,!1===this.autoReconnect&&(clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null),this.socket){if(0===this.socket.readyState){const t=this.socket;t.onopen=()=>{t&&t.close()},t.onmessage=null,t.onerror=null,t.onclose=null}else try{this.socket.close?.()}catch{}this.socket=null}this.promiseMap.clear(),this.emit("closed"),this.stateChange("closed")}}stop(){this.autoReconnect=!1,this.close()}destroy(){this.stop(),this.removeAllListeners(),this.channels.clear(),this.linkMap.clear(),this.boho=null}keepAlive(){this.autoReconnect}redirect(t){this.close(),this.stateChange("redirecting"),this.createConnection(t)}open(t){this.socket&&this.close(),t&&(this.url=t),this.url?(this.createConnection(this.url),this.connectionCheckerIntervalID||(this.connectionCheckerIntervalID=setInterval(this.keepAlive.bind(this),this.connectionCheckerPeriod))):this.emit("error",new Error("URL is not set."))}onOpen(){this._closed=!1,this.url.includes("wss://")?this.TLS=!0:this.TLS=!1,this.stateChange("open")}onClose(){this.boho.isAuthorized=!1,this.cid="",this.stateChange("closed")}login(t,e){if(!this.auth(t,e))return!1;this.useAuth=!0;let r=this.boho.auth_req();return this.send(r),!0}auth(t,e){if(!t&&!e)return this.emit("error",new Error("auth failed. no id and key.")),!1;if(!e&&t.includes("."))this.boho.set_id_key(t);else{if(!t||!e)return this.emit("error",new Error("auth failed. no id or key.")),!1;this.boho.set_id8(t),this.boho.set_key(e)}return this.useAuth=!0,!0}onData(t){let e,r=t[0];if(r===Qt.BohoMsg.ENC_488)e=this.boho.decrypt_488(t),e&&(r=e[0],t=e);else if(r===Qt.BohoMsg.ENC_E2E)try{if(e=this.boho.decrypt_488(t),!e)return;r=e[0],t.set(e,Qt.MetaSize.ENC_488),t=t.subarray(Qt.MetaSize.ENC_488)}catch(t){return}let n=G[r];switch(n||(n=Qt.BohoMsg[r]),r){case G.OVER_SIZE:console.log("## server sent: over_size event."),this.emit("over_size","over_size");break;case G.PING:this.pong();break;case G.PONG:break;case G.IAM_RES:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.ip&&(this.ip=r.ip)}catch(t){this.emit("error",new Error("IAM_RES data error"))}break;case G.CID_RES:let r=Xt.decode(t.subarray(1));this.cid=r,this.stateChange("ready","cid_ready"),this.subscribe_memory_channels();break;case G.QUOTA_LEVEL:let n=t[1];this.level=n,this.quota=V[n],console.log("## QUOTA:",n,JSON.stringify(this.quota));break;case G.SERVER_CLEAR_AUTH:this.useAuth=!1,this.boho.clearAuth(),this.stop();break;case G.SERVER_REDIRECT:let i,o,s;7==t.byteLength?(i=function(t){if(6!=t.byteLength)return;return t[0].toString()+"."+t[1].toString()+"."+t[2].toString()+"."+t[3].toString()+":"+((t[4]<<8)+t[5]).toString()}(t.subarray(1)),s="cong://"):(i=Xt.decode(t.subarray(1)),s=""),o=s+i,this.redirect(o);break;case G.SERVER_READY:this.stateChange("server_ready","server_ready"),this.useAuth?this.send(this.boho.auth_req()):this.send(Kt.from([G.CID_REQ]));break;case G.SERVER_SIGNAL:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.event&&r.data&&(this.serverSet=r.data,this.emit(r.event,r.data))}catch(t){this.emit("error",new Error("SERVER_SIGNAL parsing error"))}break;case G.SET:try{let e=C.unpack(t);e&&this.emit(e.topic,...e.args)}catch(t){this.emit("error",new Error("SET parsing error"))}break;case G.SIGNAL_E2E:case G.SIGNAL:try{let e=t.readUint8(1),r=t.subarray(2,2+e),n=Xt.decode(r),i=t.readUint8(2+e),o=t.subarray(3+e);switch(i){case H.EMPTY:0===n.indexOf("@")?this.emit("@",null,n):this.emit(n,null,n);break;case H.TEXT:let t=o;0===o[o.byteLength-1]&&(t=o.subarray(0,o.byteLength-1));let e=Xt.decode(t);0===n.indexOf("@")&&this.emit("@",e,n),"@"!==n&&this.emit(n,e,n);break;case H.BINARY:0===n.indexOf("@")&&this.emit("@",o,n),"@"!==n&&this.emit(n,o,n);break;case H.OBJECT:let r=Xt.decode(o),i=JSON.parse(r);0===n.indexOf("@")&&this.emit("@",i,n),"@"!==n&&this.emit(n,i,n);break;case H.MJSON:let s=Xt.decode(o),f=JSON.parse(s);0===n.indexOf("@")&&this.emit("@",...f,n),"@"!==n&&this.emit(n,...f,n);break;case H.MBA:let u=C.unpack(o);0===n.indexOf("@")&&this.emit("@",...u.args,n),"@"!==n&&this.emit(n,...u.args,n)}}catch(t){this.emit("error",new Error("signal parse err"))}break;case G.RESPONSE_MBP:this.testPromise(t);break;case Qt.BohoMsg.AUTH_NONCE:let f=this.boho.auth_hmac(t);f?this.send(f):this.stateChange("auth_fail","Invalid local auth_hmac.");break;case Qt.BohoMsg.AUTH_FAIL:this.stateChange("auth_fail","server reject auth.");break;case Qt.BohoMsg.AUTH_ACK:this.boho.check_auth_ack_hmac(t)?(this.stateChange("auth_ready","server sent auth_ack"),this.send(Kt.from([G.CID_REQ]))):this.stateChange("auth_fail","invalid server_hmac");break;default:try{e=Xt.decode(t),this.emit("text_message",e)}catch(t){}}}iam(t){t?this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM),C.MB("#",t))):this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM)))}ping(){this.send(Kt.from([G.PING]))}pong(){this.send(Kt.from([G.PONG]))}echo(t){t?(console.log("echo args:",t),this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.ECHO),C.MB("#msg",t)))):this.send(Kt.from([G.ECHO]))}bin(...t){this.send(C.U8pack(...t))}send(t){if(t.byteLength>this.quota.signalSize)return this.emit("over_size"),console.log("## QUOTA LIMIT OVER!! \nsignal message.byteLength: ",t.byteLength),void console.log("## your maximum signalSize(bytes) is:",this.quota.signalSize);this.socket_send(t)}getEncryptionMode(){return!(this.encMode!==z.YES&&(this.encMode!==z.AUTO||this.TLS||!this.boho.isAuthorized))}send_enc_mode(t,e){if(void 0===e&&(e=this.getEncryptionMode()),t[0]==G.SIGNAL_E2E&&e){let e=t[1],r=this.boho.encrypt_488(t.subarray(0,3+e));r[0]=Qt.BohoMsg.ENC_E2E,this.send(Kt.concat([r,t.subarray(3+e)]))}else if(e){let e=this.boho.encrypt_488(t);this.send(e)}else this.send(t)}setMsgPromise(t){return new Promise(((e,r)=>{this.promiseMap.set(t,[e,r]),setTimeout((e=>{this.promiseMap.has(t)&&(r("timeout"),this.promiseMap.delete(t))}),this.promiseTimeOut)}))}testPromise(t){let e=C.unpack(t);if(e)if(this.promiseMap.has(e.mid)){let[t,r]=this.promiseMap.get(e.mid);this.promiseMap.delete(e.mid),e.status<128?(e.ok=!0,t(e)):(e.ok=!1,r(e))}else console.log("no promise id")}publish(...t){this.signal(...t)}signal(t,...e){if("string"!=typeof t)throw TypeError("tag should be string.");let r=J(t,...e);this.send_enc_mode(r)}decrypt_e2e(t,e){return this.boho.decrypt_e2e(t,e)}signal_e2e(t,e,r){if("string"!=typeof t)throw TypeError("tag should be string.");let n=Wt.encode(t),i=C.B8(e),o=this.boho.encrypt_e2e(i,r),s=C.pack(C.MB("#MsgType","8",G.SIGNAL_E2E),C.MB("#tagLen","8",n.byteLength),C.MB("#tag",n),C.MB("#payloadType","8",H.BINARY),C.MB("#payload",o));this.send_enc_mode(s)}set(t,...e){return t&&0!=e.length?this.req("store","set",t,...e):Promise.reject(new Error("set need storeName and value)"))}async get(t){if(!t)return Promise.reject(new Error("store get need storeName)"));let e=await this.req("store","get",t),{$:r}=C.unpack(e.body);return r}req(t,e,...r){if(!t||!e)return Promise.reject(new Error("request need target and topic)"));let n;return n=r.length>0?C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e),C.MBA(...r)):C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e)),this.send_enc_mode(n),this.setMsgPromise(this.mid)}subscribe(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return;t.split(",").forEach((t=>{this.channels.add(t)}));let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE),C.NB("8",e.byteLength),e]))}subscribe_promise(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return Promise.reject("subscribe_promise:: connection is not ready");let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN2)throw TypeError("please use tag string bytelength: "+F.TAG_LEN2);return this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE_REQ),C.NB("16",++this.mid),C.NB("16",e.byteLength),e])),this.setMsgPromise(this.mid)}subscribe_memory_channels(){if(0==this.channels.size)return;let t=Array.from(this.channels).join(",");this.subscribe_promise(t).then((t=>{})).catch((t=>{console.log(">> SUBSCRIBE FAIL:",t)}))}unsubscribe(t=""){if("string"!=typeof t)throw TypeError("tag should be string.");if(""==t)this.channels.clear();else{t.split(",").forEach((t=>{this.channels.delete(t)}))}let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.UNSUBSCRIBE),C.NB("8",e.byteLength),e]))}listen(t,e){if("string"!=typeof t)throw TypeError("tag should be string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof e)throw TypeError("handler is not a function.");0!==t.indexOf("@")&&this.channels.add(t),this.on(t,e)}link(t,e,r){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof r)throw TypeError("handler is not a function.");let n;0!==e.indexOf("@")&&this.channels.add(e),n=this.linkMap.has(t)?this.linkMap.get(t):new Set,n.add(e),this.linkMap.set(t,n),this.on(e,r),this.subscribe(e)}unlink(t,e){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");const r=this.linkMap.get(t);r&&r.has(e)&&(this.unsubscribe(e),this.removeAllListeners(e),r.delete(e),0===r.size&&this.linkMap.delete(t))}unlinkAll(t){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");const e=this.linkMap.get(t);if(e){for(const t of e)this.unsubscribe(t),this.removeAllListeners(t);this.linkMap.delete(t)}}getMetric(){return{tx:this.txCounter,rx:this.rxCounter,txb:this.txBytes,rxb:this.rxBytes,last:(Date.now()-this.lastTxRxTime)/1e3}}getState(){return this.state}getStateName(){return $[this.state].toLowerCase()}getSecurity(){return{useAuth:this.useAuth,isTLS:this.TLS,isAuthorized:this.boho.isAuthorized,encMode:this.encMode,usingEncryption:this.getEncryptionMode()}}stateChange(t,e){let r=t.toLowerCase();this.state=$[t.toUpperCase()],e&&this.emit(r,e),this.stateName!==r&&(this.stateName=r,this.emit("change",r))}}const te=Qt.Buffer;class ee extends Zt{static version="3.1.0";static binaryType="arraybuffer";static Boho=Qt;static MBP=Qt.MBP;static Buffer=Qt.Buffer;static constants=Y;static instanceCount=0;static webSocketCount=0;constructor(t){super(t),ee.instanceCount++,this.boundBrowserVisiblePing=this.browserVisiblePing.bind(this),document.addEventListener("visibilitychange",this.boundBrowserVisiblePing),t&&this.open()}browserVisiblePing(){"visible"===document.visibilityState&&this.ping()}stop(){super.stop()}destroy(){document.removeEventListener("visibilitychange",this.boundBrowserVisiblePing),super.destroy()}keepAlive(){this.autoReconnect&&(this.socket&&this.socket.readyState!==WebSocket.CLOSED||this.state!==ee.constants.STATES.CLOSED||this.open())}createConnection(t){ee.webSocketCount++,this.socket=new WebSocket(t),this.socket.binaryType=ee.binaryType,this.stateChange("opening"),this.socket.onopen=()=>{this.socket&&("arraybuffer"==this.socket.binaryType?this.socket.onmessage=this.onWebSocketMessage.bind(this):this.socket.onmessage=this.onWebSocketMessageBlob.bind(this),this.emit("open"))},this.socket.onerror=t=>{this.emit("error",t)},this.socket.onclose=()=>{this.emit("close")}}onWebSocketMessage(t){this.rxCounter++,this.lastTxRxTime=Date.now();let e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}async onWebSocketMessageBlob(t){let e;if(this.rxCounter++,this.lastTxRxTime=Date.now(),t.data instanceof Blob){let r=await t.data.arrayBuffer();e=te.from(r)}else e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}socket_send(t){1===this.socket?.readyState?(this.socket.send(t),this.txCounter++,this.txBytes+=t.byteLength,this.lastTxRxTime=Date.now()):console.log(".")}}export{ee as default};
22
+ */var Ht=(Dt||(Dt=1,function(t){const e=function(){if(xt)return jt;xt=1,jt.byteLength=function(t){var e=o(t),r=e[0],n=e[1];return 3*(r+n)/4-n},jt.toByteArray=function(t){var n,i,s=o(t),f=s[0],u=s[1],h=new r(function(t,e,r){return 3*(e+r)/4-r}(0,f,u)),a=0,c=u>0?f-4:f;for(i=0;i<c;i+=4)n=e[t.charCodeAt(i)]<<18|e[t.charCodeAt(i+1)]<<12|e[t.charCodeAt(i+2)]<<6|e[t.charCodeAt(i+3)],h[a++]=n>>16&255,h[a++]=n>>8&255,h[a++]=255&n;return 2===u&&(n=e[t.charCodeAt(i)]<<2|e[t.charCodeAt(i+1)]>>4,h[a++]=255&n),1===u&&(n=e[t.charCodeAt(i)]<<10|e[t.charCodeAt(i+1)]<<4|e[t.charCodeAt(i+2)]>>2,h[a++]=n>>8&255,h[a++]=255&n),h},jt.fromByteArray=function(e){for(var r,n=e.length,i=n%3,o=[],f=16383,u=0,h=n-i;u<h;u+=f)o.push(s(e,u,u+f>h?h:u+f));return 1===i?(r=e[n-1],o.push(t[r>>2]+t[r<<4&63]+"==")):2===i&&(r=(e[n-2]<<8)+e[n-1],o.push(t[r>>10]+t[r>>4&63]+t[r<<2&63]+"=")),o.join("")};for(var t=[],e=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)t[i]=n[i],e[n.charCodeAt(i)]=i;function o(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function s(e,r,n){for(var i,o,s=[],f=r;f<n;f+=3)i=(e[f]<<16&16711680)+(e[f+1]<<8&65280)+(255&e[f+2]),s.push(t[(o=i)>>18&63]+t[o>>12&63]+t[o>>6&63]+t[63&o]);return s.join("")}return e["-".charCodeAt(0)]=62,e["_".charCodeAt(0)]=63,jt}(),r=Ft(),n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=s,t.SlowBuffer=function(t){return+t!=t&&(t=0),s.alloc(+t)},t.INSPECT_MAX_BYTES=50;const i=2147483647;function o(t){if(t>i)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return h(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|p(t,e);let n=o(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(q(t,Uint8Array)){const e=new Uint8Array(t);return c(e.buffer,e.byteOffset,e.byteLength)}return a(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer))return c(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return c(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);const i=function(t){if(s.isBuffer(t)){const e=0|l(t.length),r=o(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||J(t.length)?o(0):a(t):"Buffer"===t.type&&Array.isArray(t.data)?a(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t){return u(t),o(t<0?0:0|l(t))}function a(t){const e=t.length<0?0:0|l(t.length),r=o(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function c(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function l(t){if(t>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|t}function p(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(t).length;default:if(i)return n?-1:G(t).length;e=(""+e).toLowerCase(),i=!0}}function y(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return T(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return L(this,e,r);case"latin1":case"binary":return v(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),J(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,i){let o,s=1,f=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,f/=2,u/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){let n=-1;for(o=r;o<f;o++)if(h(t,o)===h(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>f&&(r=f-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(h(t,o+n)!==h(e,n)){r=!1;break}if(r)return o}return-1}function w(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(e.substr(2*s,2),16);if(J(n))return s;t[r+s]=n}return s}function E(t,e,r,n){return V(G(e,t.length-r),t,r,n)}function B(t,e,r,n){return V(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function m(t,e,r,n){return V(Y(e),t,r,n)}function A(t,e,r,n){return V(function(t,e){let r,n,i;const o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function _(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function I(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,s=e>239?4:e>223?3:e>191?2:1;if(i+s<=r){let r,n,f,u;switch(s){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(o=u));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=t[i+1],n=t[i+2],f=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&f)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&f,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(t){const e=t.length;if(e<=U)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=U));return r}(n)}t.kMaxLength=i,s.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return u(t),t<=0?o(t):void 0!==e?"string"==typeof r?o(t).fill(e,r):o(t).fill(e):o(t)}(t,e,r)},s.allocUnsafe=function(t){return h(t)},s.allocUnsafeSlow=function(t){return h(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),q(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=s.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(q(e,Uint8Array))i+e.length>n.length?(s.isBuffer(e)||(e=s.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!s.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},s.byteLength=p,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},s.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},s.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},s.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?I(this,0,t):y.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(s.prototype[n]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,i){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),f=(r>>>=0)-(e>>>=0);const u=Math.min(o,f),h=this.slice(n,i),a=t.slice(e,r);for(let t=0;t<u;++t)if(h[t]!==a[t]){o=h[t],f=a[t];break}return o<f?-1:f<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return d(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return d(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return w(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return B(this,t,e,r);case"base64":return m(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const U=4096;function L(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function v(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function T(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=Q[t[n]];return i}function S(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function R(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function O(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function M(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function C(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function N(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function k(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,4),r.write(t,e,n,i,23,4),n+4}function x(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,8),r.write(t,e,n,i,52,8),n+8}s.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,s.prototype),n},s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),s.prototype.readBigUInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),s.prototype.readBigInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),s.prototype.readFloatLE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigUInt64LE=K((function(t,e=0){return M(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=K((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=0,o=1,s=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigInt64LE=K((function(t,e=0){return M(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=K((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return k(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return k(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=s.isBuffer(t)?t:s.from(t,n),f=o.length;if(0===f)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%f]}return this};const P={};function D(t,e,r){P[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function $(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,i,o){if(t>r||t<e){const r="bigint"==typeof e?"n":"";let n;throw n=0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new P.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||F(e,t.length-(r+1))}(n,i,o)}function z(t,e){if("number"!=typeof t)throw new P.ERR_INVALID_ARG_TYPE(e,"number",t)}function F(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new P.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=$(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=$(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const H=/[^+/0-9A-Za-z-_]/g;function G(t,e){let r;e=e||1/0;const n=t.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(H,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function K(t){return"undefined"==typeof BigInt?W:t}function W(){throw new Error("BigInt not supported")}}($t)),$t);let Gt={AUTH_REQ:176,AUTH_NONCE:177,AUTH_HMAC:178,AUTH_ACK:179,AUTH_FAIL:180,AUTH_EXT:181,ENC_PACK:182,ENC_E2E:183,ENC_488:184};for(let t in Gt)Gt[Gt[t]]=t;const Yt={AUTH_REQ:Nt.meta(Nt.MB("header","8",0),Nt.MB("reserved","8",0)),AUTH_NONCE:Nt.meta(Nt.MB("header","8",0),Nt.MB("unixTime","32L",0),Nt.MB("milTime","32L",0),Nt.MB("nonce",Ht.Buffer.alloc(4))),AUTH_HMAC:Nt.meta(Nt.MB("header","8",0),Nt.MB("id8",Ht.Buffer.alloc(8)),Nt.MB("nonce",Ht.Buffer.alloc(4)),Nt.MB("hmac32",Ht.Buffer.alloc(32))),AUTH_ACK:Nt.meta(Nt.MB("header","8",0),Nt.MB("hmac32",Ht.Buffer.alloc(32))),ENC_PACK:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("salt12",Ht.Buffer.alloc(12)),Nt.MB("hmac",8,0)),ENC_488:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("otpSrc8",Ht.Buffer.alloc(8)),Nt.MB("hmac8",Ht.Buffer.alloc(8)))};function Vt(t){let e=t[t.length-1];return e[2]+e[3]}const qt={AUTH_REQ:Vt(Yt.AUTH_REQ),AUTH_NONCE:Vt(Yt.AUTH_NONCE),AUTH_HMAC:Vt(Yt.AUTH_HMAC),AUTH_ACK:Vt(Yt.AUTH_ACK),ENC_PACK:Vt(Yt.ENC_PACK),ENC_488:Vt(Yt.ENC_488)};function Jt(t){return globalThis.crypto.getRandomValues(Ht.Buffer.alloc(t))}class Qt{constructor(){this._id8=Ht.Buffer.alloc(8),this._otpSrc44=Ht.Buffer.alloc(44),this._otp36=Ht.Buffer.alloc(36),this._hmac=Ht.Buffer.alloc(32),this.auth_salt12=Ht.Buffer.alloc(12),this.localNonce=Ht.Buffer.alloc(4),this.remoteNonce=Ht.Buffer.alloc(4),this.isAuthorized=!1}clearAuth(){this._id8.fill(0),this._otpSrc44.fill(0),this._otp36.fill(0),this._hmac.fill(0),this.auth_salt12.fill(0),this.localNonce.fill(0),this.remoteNonce.fill(0),this.isAuthorized=!1}set_hash_id8(t){Nt.B8(kt.hash(t)).copy(this._id8,0,0,8)}set_id8(t){let e=Nt.B8(t);this._id8.fill(0),e.copy(this._id8,0,0,8)}set_key(t){Nt.B8(kt.hash(t)).copy(this._otpSrc44,0,0,32)}set_id_key(t){let e=t.indexOf(".");if(-1==e)return;let r=t.substring(0,e),n=t.substring(e+1);this.set_id8(r),this.set_key(n)}copy_id8(t){t.copy(this._id8,0,0,8)}copy_key(t){t.copy(this._otpSrc44,0,0,32)}sha256_n(t,e){let r=kt.hash(t);for(let t=0;t<e;t++)r=kt.hash(r);return r}set_clock_rand(){let t=Date.now(),e=parseInt(t/1e3);t%=4294967295,Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",t),Jt(4)]).copy(this._otpSrc44,32)}set_clock_nonce(t){let e=Date.now(),r=parseInt(e/1e3);e%=4294967295,Ht.Buffer.concat([Nt.NB("32L",r),Nt.NB("32L",e),t]).copy(this._otpSrc44,32)}set_salt12(t){t.copy(this._otpSrc44,32)}resetOTP(){Nt.B8(kt.hash(this._otpSrc44)).copy(this._otp36,0,0,32)}getIndexOTP(t){return this._otp36.writeUInt32LE(t,32),kt.hash(this._otp36)}generateHMAC(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);this._hmac=Nt.B8(kt.hash(e))}getHMAC8(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);return this._hmac=Nt.B8(kt.hash(e)),this._hmac.subarray(0,8)}xotp(t,e=0,r=!1){let n=(t=Nt.B8(t,r)).byteLength,i=e,o=0,s=0;for(;n>0;){s=n<32?n:32;let e=this.getIndexOTP(++i);for(let r=0;r<s;r++)t[o++]^=e[r];n-=32}return t}auth_req(){return Nt.pack(Nt.MB("#type","8",Gt.AUTH_REQ),Nt.MB("#reserved","8",0))}auth_nonce(){let t=Date.now(),e=Math.floor(t/1e3),r=t%1e3;return this.localNonce=Jt(4),this.auth_salt12=Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",r),this.localNonce]),Ht.Buffer.concat([Nt.NB("8",Gt.AUTH_NONCE),this.auth_salt12])}auth_hmac(t){let e=Nt.unpack(t,Yt.AUTH_NONCE);if(e){let t=Ht.Buffer.concat([Nt.NB("32L",e.unixTime),Nt.NB("32L",e.milTime),e.nonce]);return this.set_salt12(t),this.localNonce=Jt(4),this.generateHMAC(this.localNonce),this.remoteNonce=e.nonce,Nt.pack(Nt.MB("#header","8",Gt.AUTH_HMAC),Nt.MB("#id8",this._id8),Nt.MB("#nonce",this.localNonce),Nt.MB("#hmac32",this._hmac))}return!1}check_auth_hmac(t){let e;if(t instanceof Uint8Array){if(e=Nt.unpack(t,Yt.AUTH_HMAC),!e)return}else e=t;this.set_salt12(this.auth_salt12),this.generateHMAC(e.nonce);let r=this._hmac;if(Nt.equal(e.hmac32,r)){this.remoteNonce=e.nonce;let t=Ht.Buffer.concat([this.localNonce,this.remoteNonce,this.localNonce]);this.set_salt12(t),this.generateHMAC(e.nonce);let r=this._hmac,n=Nt.rawPack(Nt.MB("header","8",Gt.AUTH_ACK),Nt.MB("hmac32",r));return this.isAuthorized=!0,n}return!1}check_auth_ack_hmac(t){let e=Nt.unpack(t,Yt.AUTH_ACK);if(e){let t=Ht.Buffer.concat([this.remoteNonce,this.localNonce,this.remoteNonce]);this.set_salt12(t),this.generateHMAC(this.localNonce);let r=this._hmac;if(Nt.equal(r,e.hmac32))return this.isAuthorized=!0,!0}}encrypt_488(t){if(!this.isAuthorized)return;t=Nt.B8(t),this.set_clock_nonce(this.remoteNonce),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_488),Nt.MB("#len","32L",t.byteLength),Nt.MB("#otpSrc8",this._otpSrc44.subarray(32,40)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decrypt_488(t){t=Nt.B8(t);let e=Nt.unpack(t,Yt.ENC_488);if(e){let t=Ht.Buffer.concat([e.otpSrc8,this.localNonce]);this.set_salt12(t),this.resetOTP();let r=e.$OTHERS.subarray(0,e.len),n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(i,e.hmac8))return n}}encryptPack(t){t=Nt.B8(t),this.set_clock_rand(),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_PACK),Nt.MB("#len","32L",t.byteLength),Nt.MB("#salt12",this._otpSrc44.subarray(32)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decryptPack(t){if(t[0]===Gt.ENC_PACK&&t.readUint32LE(1)==t.byteLength-qt.ENC_PACK)try{let e=Nt.unpack(t,Yt.ENC_PACK);if(!e)return;this.set_salt12(e.salt12),this.resetOTP();let r=e.$OTHERS,n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(e.hmac,i))return e.data=n,e}catch(t){}}encrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.encryptPack(t);return this._otpSrc44.set(r),n}decrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.decryptPack(t);return this._otpSrc44.set(r),n}}Qt.RAND=Jt,Qt.BohoMsg=Gt,Qt.Meta=Yt,Qt.MetaSize=qt,Qt.sha256=kt,Qt.MBP=Nt,Qt.Buffer=Ht.Buffer;const Kt=C.Buffer,Wt=new TextEncoder,Xt=new TextDecoder;class Zt extends D{constructor(t){super(),this.cid="",this.ip="",this.socket=null,this.url=t,this.state=$.CLOSED,this.stateName=this.getStateName(),this.txCounter=0,this.rxCounter=0,this.txBytes=0,this.rxBytes=0,this.lastTxRxTime=Date.now(),this.connectionCheckerPeriod=F.CONNECTION_CHECKER_PERIOD,this.connectionCheckerIntervalID=null,this.boho=new Qt,this.TLS=!1,this.encMode=z.AUTO,this.useAuth=!1,this.nick="",this.channels=new Set,this.promiseMap=new Map,this.promiseTimeOut=F.PROMISE_TIMEOUT,this.mid=0,this.level=3,this.quota=V[this.level],this.serverSet={},this.linkMap=new Map,this.autoReconnect=!0,this._closed=!1,this.on("open",this.onOpen.bind(this)),this.on("close",this.onClose.bind(this)),this.on("socket_data",this.onData.bind(this))}close(){if(!this._closed){if(this._closed=!0,!1===this.autoReconnect&&(clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null),this.socket){if(0===this.socket.readyState){const t=this.socket;t.onopen=()=>{t&&t.close()},t.onmessage=null,t.onerror=null,t.onclose=null}else try{this.socket.close?.()}catch{}this.socket=null}this.promiseMap.clear(),this.emit("closed"),this.stateChange("closed")}}stop(){this.autoReconnect=!1,this.close()}destroy(){this.stop(),this.removeAllListeners(),this.channels.clear(),this.linkMap.clear(),this.boho=null}keepAlive(){this.autoReconnect}redirect(t){this.close(),this.stateChange("redirecting"),this.createConnection(t)}open(t){this.socket&&this.close(),t&&(this.url=t),this.url?(this.createConnection(this.url),this.connectionCheckerIntervalID||(this.connectionCheckerIntervalID=setInterval(this.keepAlive.bind(this),this.connectionCheckerPeriod))):this.emit("error",new Error("URL is not set."))}onOpen(){this._closed=!1,this.url.includes("wss://")?this.TLS=!0:this.TLS=!1,this.stateChange("open")}onClose(){this.boho.isAuthorized=!1,this.cid="",this.stateChange("closed")}login(t,e){if(!this.auth(t,e))return!1;this.useAuth=!0;let r=this.boho.auth_req();return this.send(r),!0}auth(t,e){if(!t&&!e)return this.emit("error",new Error("auth failed. no id and key.")),!1;if(!e&&t.includes("."))this.boho.set_id_key(t);else{if(!t||!e)return this.emit("error",new Error("auth failed. no id or key.")),!1;this.boho.set_id8(t),this.boho.set_key(e)}return this.useAuth=!0,!0}onData(t){let e,r=t[0];if(r===Qt.BohoMsg.ENC_488)e=this.boho.decrypt_488(t),e&&(r=e[0],t=e);else if(r===Qt.BohoMsg.ENC_E2E)try{if(e=this.boho.decrypt_488(t),!e)return;r=e[0],t.set(e,Qt.MetaSize.ENC_488),t=t.subarray(Qt.MetaSize.ENC_488)}catch(t){return}let n=G[r];switch(n||(n=Qt.BohoMsg[r]),r){case G.OVER_SIZE:console.log("## server sent: over_size event."),this.emit("over_size","over_size");break;case G.PING:this.pong();break;case G.PONG:break;case G.IAM_RES:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.ip&&(this.ip=r.ip)}catch(t){this.emit("error",new Error("IAM_RES data error"))}break;case G.CID_RES:let r=Xt.decode(t.subarray(1));this.cid=r,this.stateChange("ready","cid_ready"),this.subscribe_memory_channels();break;case G.QUOTA_LEVEL:let n=t[1];this.level=n,this.quota=V[n],console.log("## QUOTA:",n,JSON.stringify(this.quota));break;case G.SERVER_CLEAR_AUTH:this.useAuth=!1,this.boho.clearAuth(),this.stop();break;case G.SERVER_REDIRECT:let i,o,s;7==t.byteLength?(i=function(t){if(6!=t.byteLength)return;return t[0].toString()+"."+t[1].toString()+"."+t[2].toString()+"."+t[3].toString()+":"+((t[4]<<8)+t[5]).toString()}(t.subarray(1)),s="cong://"):(i=Xt.decode(t.subarray(1)),s=""),o=s+i,this.redirect(o);break;case G.SERVER_READY:this.stateChange("server_ready","server_ready"),this.useAuth?this.send(this.boho.auth_req()):this.send(Kt.from([G.CID_REQ]));break;case G.SERVER_SIGNAL:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.event&&r.data&&(this.serverSet=r.data,this.emit(r.event,r.data))}catch(t){this.emit("error",new Error("SERVER_SIGNAL parsing error"))}break;case G.SET:try{let e=C.unpack(t);e&&this.emit(e.topic,...e.args)}catch(t){this.emit("error",new Error("SET parsing error"))}break;case G.SIGNAL_E2E:case G.SIGNAL:try{let e=t.readUint8(1),r=t.subarray(2,2+e),n=Xt.decode(r),i=t.readUint8(2+e),o=t.subarray(3+e);switch(i){case H.EMPTY:0===n.indexOf("@")?this.emit("@",null,n):this.emit(n,null,n);break;case H.TEXT:let t=o;0===o[o.byteLength-1]&&(t=o.subarray(0,o.byteLength-1));let e=Xt.decode(t);0===n.indexOf("@")&&this.emit("@",e,n),"@"!==n&&this.emit(n,e,n);break;case H.BINARY:0===n.indexOf("@")&&this.emit("@",o,n),"@"!==n&&this.emit(n,o,n);break;case H.OBJECT:let r=Xt.decode(o),i=JSON.parse(r);0===n.indexOf("@")&&this.emit("@",i,n),"@"!==n&&this.emit(n,i,n);break;case H.MJSON:let s=Xt.decode(o),f=JSON.parse(s);0===n.indexOf("@")&&this.emit("@",...f,n),"@"!==n&&this.emit(n,...f,n);break;case H.MBA:let u=C.unpack(o);0===n.indexOf("@")&&this.emit("@",...u.args,n),"@"!==n&&this.emit(n,...u.args,n)}}catch(t){this.emit("error",new Error("signal parse err"))}break;case G.RESPONSE_MBP:this.testPromise(t);break;case Qt.BohoMsg.AUTH_NONCE:let f=this.boho.auth_hmac(t);f?this.send(f):this.stateChange("auth_fail","Invalid local auth_hmac.");break;case Qt.BohoMsg.AUTH_FAIL:this.stateChange("auth_fail","server reject auth.");break;case Qt.BohoMsg.AUTH_ACK:this.boho.check_auth_ack_hmac(t)?(this.stateChange("auth_ready","server sent auth_ack"),this.send(Kt.from([G.CID_REQ]))):this.stateChange("auth_fail","invalid server_hmac");break;default:try{e=Xt.decode(t),this.emit("text_message",e)}catch(t){}}}iam(t){t?this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM),C.MB("#",t))):this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM)))}ping(){this.send(Kt.from([G.PING]))}pong(){this.send(Kt.from([G.PONG]))}echo(t){t?(console.log("echo args:",t),this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.ECHO),C.MB("#msg",t)))):this.send(Kt.from([G.ECHO]))}bin(...t){this.send(C.U8pack(...t))}send(t){if(t.byteLength>this.quota.signalSize)return this.emit("over_size"),console.log("## QUOTA LIMIT OVER!! \nsignal message.byteLength: ",t.byteLength),void console.log("## your maximum signalSize(bytes) is:",this.quota.signalSize);this.socket_send(t)}getEncryptionMode(){return!(this.encMode!==z.YES&&(this.encMode!==z.AUTO||this.TLS||!this.boho.isAuthorized))}send_enc_mode(t,e){if(void 0===e&&(e=this.getEncryptionMode()),t[0]==G.SIGNAL_E2E&&e){let e=t[1],r=this.boho.encrypt_488(t.subarray(0,3+e));r[0]=Qt.BohoMsg.ENC_E2E,this.send(Kt.concat([r,t.subarray(3+e)]))}else if(e){let e=this.boho.encrypt_488(t);this.send(e)}else this.send(t)}setMsgPromise(t){return new Promise(((e,r)=>{this.promiseMap.set(t,[e,r]),setTimeout((e=>{this.promiseMap.has(t)&&(r("timeout"),this.promiseMap.delete(t))}),this.promiseTimeOut)}))}testPromise(t){let e=C.unpack(t);if(e)if(this.promiseMap.has(e.mid)){let[t,r]=this.promiseMap.get(e.mid);this.promiseMap.delete(e.mid),e.status<128?(e.ok=!0,t(e)):(e.ok=!1,r(e))}else console.log("no promise id")}publish(...t){this.signal(...t)}signal(t,...e){if("string"!=typeof t)throw TypeError("tag should be string.");let r=J(t,...e);this.send_enc_mode(r)}decrypt_e2e(t,e){return this.boho.decrypt_e2e(t,e)}signal_e2e(t,e,r){if("string"!=typeof t)throw TypeError("tag should be string.");let n=Wt.encode(t),i=C.B8(e),o=this.boho.encrypt_e2e(i,r),s=C.pack(C.MB("#MsgType","8",G.SIGNAL_E2E),C.MB("#tagLen","8",n.byteLength),C.MB("#tag",n),C.MB("#payloadType","8",H.BINARY),C.MB("#payload",o));this.send_enc_mode(s)}set(t,...e){return t&&0!=e.length?this.req("store","set",t,...e):Promise.reject(new Error("set need storeName and value)"))}async get(t){if(!t)return Promise.reject(new Error("store get need storeName)"));let e=await this.req("store","get",t),{$:r}=C.unpack(e.body);return r}req(t,e,...r){if(!t||!e)return Promise.reject(new Error("request need target and topic)"));let n;return n=r.length>0?C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e),C.MBA(...r)):C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e)),this.send_enc_mode(n),this.setMsgPromise(this.mid)}subscribe(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return;t.split(",").forEach((t=>{this.channels.add(t)}));let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE),C.NB("8",e.byteLength),e]))}subscribe_promise(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return Promise.reject("subscribe_promise:: connection is not ready");let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN2)throw TypeError("please use tag string bytelength: "+F.TAG_LEN2);return this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE_REQ),C.NB("16",++this.mid),C.NB("16",e.byteLength),e])),this.setMsgPromise(this.mid)}subscribe_memory_channels(){if(0==this.channels.size)return;let t=Array.from(this.channels).join(",");this.subscribe_promise(t).then((t=>{})).catch((t=>{console.log(">> SUBSCRIBE FAIL:",t)}))}unsubscribe(t=""){if("string"!=typeof t)throw TypeError("tag should be string.");if(""==t)this.channels.clear();else{t.split(",").forEach((t=>{this.channels.delete(t)}))}let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.UNSUBSCRIBE),C.NB("8",e.byteLength),e]))}listen(t,e){if("string"!=typeof t)throw TypeError("tag should be string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof e)throw TypeError("handler is not a function.");0!==t.indexOf("@")&&this.channels.add(t),this.on(t,e)}link(t,e,r){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof r)throw TypeError("handler is not a function.");let n;0!==e.indexOf("@")&&this.channels.add(e),n=this.linkMap.has(t)?this.linkMap.get(t):new Set,n.add(e),this.linkMap.set(t,n),this.on(e,r),this.subscribe(e)}unlink(t,e){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");const r=this.linkMap.get(t);r&&r.has(e)&&(this.unsubscribe(e),this.removeAllListeners(e),r.delete(e),0===r.size&&this.linkMap.delete(t))}unlinkAll(t){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");const e=this.linkMap.get(t);if(e){for(const t of e)this.unsubscribe(t),this.removeAllListeners(t);this.linkMap.delete(t)}}getMetric(){return{tx:this.txCounter,rx:this.rxCounter,txb:this.txBytes,rxb:this.rxBytes,last:(Date.now()-this.lastTxRxTime)/1e3}}getState(){return this.state}getStateName(){return $[this.state].toLowerCase()}getSecurity(){return{useAuth:this.useAuth,isTLS:this.TLS,isAuthorized:this.boho.isAuthorized,encMode:this.encMode,usingEncryption:this.getEncryptionMode()}}stateChange(t,e){let r=t.toLowerCase();this.state=$[t.toUpperCase()],e&&this.emit(r,e),this.stateName!==r&&(this.stateName=r,this.emit("change",r))}}const te=Qt.Buffer;class ee extends Zt{static version="3.2.0";static binaryType="arraybuffer";static Boho=Qt;static MBP=Qt.MBP;static Buffer=Qt.Buffer;static constants=Y;static instanceCount=0;static webSocketCount=0;constructor(t){super(t),ee.instanceCount++,this.boundBrowserVisiblePing=this.browserVisiblePing.bind(this),document.addEventListener("visibilitychange",this.boundBrowserVisiblePing),t&&this.open()}browserVisiblePing(){"visible"===document.visibilityState&&this.ping()}stop(){super.stop()}destroy(){document.removeEventListener("visibilitychange",this.boundBrowserVisiblePing),super.destroy()}keepAlive(){this.autoReconnect&&(this.socket&&this.socket.readyState!==WebSocket.CLOSED||this.state!==ee.constants.STATES.CLOSED||this.open())}createConnection(t){ee.webSocketCount++,this.socket=new WebSocket(t),this.socket.binaryType=ee.binaryType,this.stateChange("opening"),this.socket.onopen=()=>{this.socket&&("arraybuffer"==this.socket.binaryType?this.socket.onmessage=this.onWebSocketMessage.bind(this):this.socket.onmessage=this.onWebSocketMessageBlob.bind(this),this.emit("open"))},this.socket.onerror=t=>{this.emit("error",t)},this.socket.onclose=()=>{this.emit("close")}}onWebSocketMessage(t){this.rxCounter++,this.lastTxRxTime=Date.now();let e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}async onWebSocketMessageBlob(t){let e;if(this.rxCounter++,this.lastTxRxTime=Date.now(),t.data instanceof Blob){let r=await t.data.arrayBuffer();e=te.from(r)}else e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}socket_send(t){1===this.socket?.readyState?(this.socket.send(t),this.txCounter++,this.txBytes+=t.byteLength,this.lastTxRxTime=Date.now()):console.log(".")}}export{ee as default};
23
23
  //# sourceMappingURL=io.js.map
package/dist/io.min.js CHANGED
@@ -19,5 +19,5 @@ var s=(r||(r=1,function(r){const n=function(){if(t)return i;t=1,i.byteLength=fun
19
19
  *
20
20
  * @author Feross Aboukhadijeh <https://feross.org>
21
21
  * @license MIT
22
- */var Ht=(Dt||(Dt=1,function(t){const e=function(){if(xt)return jt;xt=1,jt.byteLength=function(t){var e=o(t),r=e[0],n=e[1];return 3*(r+n)/4-n},jt.toByteArray=function(t){var n,i,s=o(t),f=s[0],u=s[1],h=new r(function(t,e,r){return 3*(e+r)/4-r}(0,f,u)),a=0,c=u>0?f-4:f;for(i=0;i<c;i+=4)n=e[t.charCodeAt(i)]<<18|e[t.charCodeAt(i+1)]<<12|e[t.charCodeAt(i+2)]<<6|e[t.charCodeAt(i+3)],h[a++]=n>>16&255,h[a++]=n>>8&255,h[a++]=255&n;return 2===u&&(n=e[t.charCodeAt(i)]<<2|e[t.charCodeAt(i+1)]>>4,h[a++]=255&n),1===u&&(n=e[t.charCodeAt(i)]<<10|e[t.charCodeAt(i+1)]<<4|e[t.charCodeAt(i+2)]>>2,h[a++]=n>>8&255,h[a++]=255&n),h},jt.fromByteArray=function(e){for(var r,n=e.length,i=n%3,o=[],f=16383,u=0,h=n-i;u<h;u+=f)o.push(s(e,u,u+f>h?h:u+f));return 1===i?(r=e[n-1],o.push(t[r>>2]+t[r<<4&63]+"==")):2===i&&(r=(e[n-2]<<8)+e[n-1],o.push(t[r>>10]+t[r>>4&63]+t[r<<2&63]+"=")),o.join("")};for(var t=[],e=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)t[i]=n[i],e[n.charCodeAt(i)]=i;function o(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function s(e,r,n){for(var i,o,s=[],f=r;f<n;f+=3)i=(e[f]<<16&16711680)+(e[f+1]<<8&65280)+(255&e[f+2]),s.push(t[(o=i)>>18&63]+t[o>>12&63]+t[o>>6&63]+t[63&o]);return s.join("")}return e["-".charCodeAt(0)]=62,e["_".charCodeAt(0)]=63,jt}(),r=Ft(),n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=s,t.SlowBuffer=function(t){return+t!=t&&(t=0),s.alloc(+t)},t.INSPECT_MAX_BYTES=50;const i=2147483647;function o(t){if(t>i)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return h(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|p(t,e);let n=o(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(q(t,Uint8Array)){const e=new Uint8Array(t);return c(e.buffer,e.byteOffset,e.byteLength)}return a(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer))return c(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return c(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);const i=function(t){if(s.isBuffer(t)){const e=0|l(t.length),r=o(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||J(t.length)?o(0):a(t):"Buffer"===t.type&&Array.isArray(t.data)?a(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t){return u(t),o(t<0?0:0|l(t))}function a(t){const e=t.length<0?0:0|l(t.length),r=o(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function c(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function l(t){if(t>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|t}function p(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(t).length;default:if(i)return n?-1:G(t).length;e=(""+e).toLowerCase(),i=!0}}function y(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return T(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return L(this,e,r);case"latin1":case"binary":return v(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),J(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,i){let o,s=1,f=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,f/=2,u/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){let n=-1;for(o=r;o<f;o++)if(h(t,o)===h(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>f&&(r=f-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(h(t,o+n)!==h(e,n)){r=!1;break}if(r)return o}return-1}function w(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(e.substr(2*s,2),16);if(J(n))return s;t[r+s]=n}return s}function E(t,e,r,n){return V(G(e,t.length-r),t,r,n)}function B(t,e,r,n){return V(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function m(t,e,r,n){return V(Y(e),t,r,n)}function A(t,e,r,n){return V(function(t,e){let r,n,i;const o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function _(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function I(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,s=e>239?4:e>223?3:e>191?2:1;if(i+s<=r){let r,n,f,u;switch(s){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(o=u));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=t[i+1],n=t[i+2],f=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&f)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&f,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(t){const e=t.length;if(e<=U)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=U));return r}(n)}t.kMaxLength=i,s.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return u(t),t<=0?o(t):void 0!==e?"string"==typeof r?o(t).fill(e,r):o(t).fill(e):o(t)}(t,e,r)},s.allocUnsafe=function(t){return h(t)},s.allocUnsafeSlow=function(t){return h(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),q(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=s.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(q(e,Uint8Array))i+e.length>n.length?(s.isBuffer(e)||(e=s.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!s.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},s.byteLength=p,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},s.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},s.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},s.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?I(this,0,t):y.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(s.prototype[n]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,i){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),f=(r>>>=0)-(e>>>=0);const u=Math.min(o,f),h=this.slice(n,i),a=t.slice(e,r);for(let t=0;t<u;++t)if(h[t]!==a[t]){o=h[t],f=a[t];break}return o<f?-1:f<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return d(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return d(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return w(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return B(this,t,e,r);case"base64":return m(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const U=4096;function L(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function v(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function T(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=Q[t[n]];return i}function S(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function R(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function O(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function M(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function C(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function N(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function k(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,4),r.write(t,e,n,i,23,4),n+4}function x(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,8),r.write(t,e,n,i,52,8),n+8}s.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,s.prototype),n},s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),s.prototype.readBigUInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),s.prototype.readBigInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),s.prototype.readFloatLE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigUInt64LE=K((function(t,e=0){return M(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=K((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=0,o=1,s=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigInt64LE=K((function(t,e=0){return M(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=K((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return k(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return k(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=s.isBuffer(t)?t:s.from(t,n),f=o.length;if(0===f)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%f]}return this};const P={};function D(t,e,r){P[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function $(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,i,o){if(t>r||t<e){const r="bigint"==typeof e?"n":"";let n;throw n=0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new P.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||F(e,t.length-(r+1))}(n,i,o)}function z(t,e){if("number"!=typeof t)throw new P.ERR_INVALID_ARG_TYPE(e,"number",t)}function F(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new P.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=$(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=$(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const H=/[^+/0-9A-Za-z-_]/g;function G(t,e){let r;e=e||1/0;const n=t.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(H,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function K(t){return"undefined"==typeof BigInt?W:t}function W(){throw new Error("BigInt not supported")}}($t)),$t);let Gt={AUTH_REQ:176,AUTH_NONCE:177,AUTH_HMAC:178,AUTH_ACK:179,AUTH_FAIL:180,AUTH_EXT:181,ENC_PACK:182,ENC_E2E:183,ENC_488:184};for(let t in Gt)Gt[Gt[t]]=t;const Yt={AUTH_REQ:Nt.meta(Nt.MB("header","8",0),Nt.MB("reserved","8",0)),AUTH_NONCE:Nt.meta(Nt.MB("header","8",0),Nt.MB("unixTime","32L",0),Nt.MB("milTime","32L",0),Nt.MB("nonce",Ht.Buffer.alloc(4))),AUTH_HMAC:Nt.meta(Nt.MB("header","8",0),Nt.MB("id8",Ht.Buffer.alloc(8)),Nt.MB("nonce",Ht.Buffer.alloc(4)),Nt.MB("hmac32",Ht.Buffer.alloc(32))),AUTH_ACK:Nt.meta(Nt.MB("header","8",0),Nt.MB("hmac32",Ht.Buffer.alloc(32))),ENC_PACK:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("salt12",Ht.Buffer.alloc(12)),Nt.MB("hmac",8,0)),ENC_488:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("otpSrc8",Ht.Buffer.alloc(8)),Nt.MB("hmac8",Ht.Buffer.alloc(8)))};function Vt(t){let e=t[t.length-1];return e[2]+e[3]}const qt={AUTH_REQ:Vt(Yt.AUTH_REQ),AUTH_NONCE:Vt(Yt.AUTH_NONCE),AUTH_HMAC:Vt(Yt.AUTH_HMAC),AUTH_ACK:Vt(Yt.AUTH_ACK),ENC_PACK:Vt(Yt.ENC_PACK),ENC_488:Vt(Yt.ENC_488)};function Jt(t){return globalThis.crypto.getRandomValues(Ht.Buffer.alloc(t))}class Qt{constructor(){this._id8=Ht.Buffer.alloc(8),this._otpSrc44=Ht.Buffer.alloc(44),this._otp36=Ht.Buffer.alloc(36),this._hmac=Ht.Buffer.alloc(32),this.auth_salt12=Ht.Buffer.alloc(12),this.localNonce=Ht.Buffer.alloc(4),this.remoteNonce=Ht.Buffer.alloc(4),this.isAuthorized=!1}clearAuth(){this._id8.fill(0),this._otpSrc44.fill(0),this._otp36.fill(0),this._hmac.fill(0),this.auth_salt12.fill(0),this.localNonce.fill(0),this.remoteNonce.fill(0),this.isAuthorized=!1}set_hash_id8(t){Nt.B8(kt.hash(t)).copy(this._id8,0,0,8)}set_id8(t){let e=Nt.B8(t);this._id8.fill(0),e.copy(this._id8,0,0,8)}set_key(t){Nt.B8(kt.hash(t)).copy(this._otpSrc44,0,0,32)}set_id_key(t){let e=t.indexOf(".");if(-1==e)return;let r=t.substring(0,e),n=t.substring(e+1);this.set_id8(r),this.set_key(n)}copy_id8(t){t.copy(this._id8,0,0,8)}copy_key(t){t.copy(this._otpSrc44,0,0,32)}sha256_n(t,e){let r=kt.hash(t);for(let t=0;t<e;t++)r=kt.hash(r);return r}set_clock_rand(){let t=Date.now(),e=parseInt(t/1e3);t%=4294967295,Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",t),Jt(4)]).copy(this._otpSrc44,32)}set_clock_nonce(t){let e=Date.now(),r=parseInt(e/1e3);e%=4294967295,Ht.Buffer.concat([Nt.NB("32L",r),Nt.NB("32L",e),t]).copy(this._otpSrc44,32)}set_salt12(t){t.copy(this._otpSrc44,32)}resetOTP(){Nt.B8(kt.hash(this._otpSrc44)).copy(this._otp36,0,0,32)}getIndexOTP(t){return this._otp36.writeUInt32LE(t,32),kt.hash(this._otp36)}generateHMAC(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);this._hmac=Nt.B8(kt.hash(e))}getHMAC8(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);return this._hmac=Nt.B8(kt.hash(e)),this._hmac.subarray(0,8)}xotp(t,e=0,r=!1){let n=(t=Nt.B8(t,r)).byteLength,i=e,o=0,s=0;for(;n>0;){s=n<32?n:32;let e=this.getIndexOTP(++i);for(let r=0;r<s;r++)t[o++]^=e[r];n-=32}return t}auth_req(){return Nt.pack(Nt.MB("#type","8",Gt.AUTH_REQ),Nt.MB("#reserved","8",0))}auth_nonce(){let t=Date.now(),e=Math.floor(t/1e3),r=t%1e3;return this.localNonce=Jt(4),this.auth_salt12=Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",r),this.localNonce]),Ht.Buffer.concat([Nt.NB("8",Gt.AUTH_NONCE),this.auth_salt12])}auth_hmac(t){let e=Nt.unpack(t,Yt.AUTH_NONCE);if(e){let t=Ht.Buffer.concat([Nt.NB("32L",e.unixTime),Nt.NB("32L",e.milTime),e.nonce]);return this.set_salt12(t),this.localNonce=Jt(4),this.generateHMAC(this.localNonce),this.remoteNonce=e.nonce,Nt.pack(Nt.MB("#header","8",Gt.AUTH_HMAC),Nt.MB("#id8",this._id8),Nt.MB("#nonce",this.localNonce),Nt.MB("#hmac32",this._hmac))}return!1}check_auth_hmac(t){let e;if(t instanceof Uint8Array){if(e=Nt.unpack(t,Yt.AUTH_HMAC),!e)return}else e=t;this.set_salt12(this.auth_salt12),this.generateHMAC(e.nonce);let r=this._hmac;if(Nt.equal(e.hmac32,r)){this.remoteNonce=e.nonce;let t=Ht.Buffer.concat([this.localNonce,this.remoteNonce,this.localNonce]);this.set_salt12(t),this.generateHMAC(e.nonce);let r=this._hmac,n=Nt.rawPack(Nt.MB("header","8",Gt.AUTH_ACK),Nt.MB("hmac32",r));return this.isAuthorized=!0,n}return!1}check_auth_ack_hmac(t){let e=Nt.unpack(t,Yt.AUTH_ACK);if(e){let t=Ht.Buffer.concat([this.remoteNonce,this.localNonce,this.remoteNonce]);this.set_salt12(t),this.generateHMAC(this.localNonce);let r=this._hmac;if(Nt.equal(r,e.hmac32))return this.isAuthorized=!0,!0}}encrypt_488(t){if(!this.isAuthorized)return;t=Nt.B8(t),this.set_clock_nonce(this.remoteNonce),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_488),Nt.MB("#len","32L",t.byteLength),Nt.MB("#otpSrc8",this._otpSrc44.subarray(32,40)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decrypt_488(t){t=Nt.B8(t);let e=Nt.unpack(t,Yt.ENC_488);if(e){let t=Ht.Buffer.concat([e.otpSrc8,this.localNonce]);this.set_salt12(t),this.resetOTP();let r=e.$OTHERS.subarray(0,e.len),n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(i,e.hmac8))return n}}encryptPack(t){t=Nt.B8(t),this.set_clock_rand(),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_PACK),Nt.MB("#len","32L",t.byteLength),Nt.MB("#salt12",this._otpSrc44.subarray(32)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decryptPack(t){if(t[0]===Gt.ENC_PACK&&t.readUint32LE(1)==t.byteLength-qt.ENC_PACK)try{let e=Nt.unpack(t,Yt.ENC_PACK);if(!e)return;this.set_salt12(e.salt12),this.resetOTP();let r=e.$OTHERS,n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(e.hmac,i))return e.data=n,e}catch(t){}}encrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.encryptPack(t);return this._otpSrc44.set(r),n}decrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.decryptPack(t);return this._otpSrc44.set(r),n}}Qt.RAND=Jt,Qt.BohoMsg=Gt,Qt.Meta=Yt,Qt.MetaSize=qt,Qt.sha256=kt,Qt.MBP=Nt,Qt.Buffer=Ht.Buffer;const Kt=C.Buffer,Wt=new TextEncoder,Xt=new TextDecoder;class Zt extends D{constructor(t){super(),this.cid="",this.ip="",this.socket=null,this.url=t,this.state=$.CLOSED,this.stateName=this.getStateName(),this.txCounter=0,this.rxCounter=0,this.txBytes=0,this.rxBytes=0,this.lastTxRxTime=Date.now(),this.connectionCheckerPeriod=F.CONNECTION_CHECKER_PERIOD,this.connectionCheckerIntervalID=null,this.boho=new Qt,this.TLS=!1,this.encMode=z.AUTO,this.useAuth=!1,this.nick="",this.channels=new Set,this.promiseMap=new Map,this.promiseTimeOut=F.PROMISE_TIMEOUT,this.mid=0,this.level=3,this.quota=V[this.level],this.serverSet={},this.linkMap=new Map,this.autoReconnect=!0,this._closed=!1,this.on("open",this.onOpen.bind(this)),this.on("close",this.onClose.bind(this)),this.on("socket_data",this.onData.bind(this))}close(){if(!this._closed){if(this._closed=!0,!1===this.autoReconnect&&(clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null),this.socket){if(0===this.socket.readyState){const t=this.socket;t.onopen=()=>{t&&t.close()},t.onmessage=null,t.onerror=null,t.onclose=null}else try{this.socket.close?.()}catch{}this.socket=null}this.promiseMap.clear(),this.emit("closed"),this.stateChange("closed")}}stop(){this.autoReconnect=!1,this.close()}destroy(){this.stop(),this.removeAllListeners(),this.channels.clear(),this.linkMap.clear(),this.boho=null}keepAlive(){this.autoReconnect}redirect(t){this.close(),this.stateChange("redirecting"),this.createConnection(t)}open(t){this.socket&&this.close(),t&&(this.url=t),this.url?(this.createConnection(this.url),this.connectionCheckerIntervalID||(this.connectionCheckerIntervalID=setInterval(this.keepAlive.bind(this),this.connectionCheckerPeriod))):this.emit("error",new Error("URL is not set."))}onOpen(){this._closed=!1,this.url.includes("wss://")?this.TLS=!0:this.TLS=!1,this.stateChange("open")}onClose(){this.boho.isAuthorized=!1,this.cid="",this.stateChange("closed")}login(t,e){if(!this.auth(t,e))return!1;this.useAuth=!0;let r=this.boho.auth_req();return this.send(r),!0}auth(t,e){if(!t&&!e)return this.emit("error",new Error("auth failed. no id and key.")),!1;if(!e&&t.includes("."))this.boho.set_id_key(t);else{if(!t||!e)return this.emit("error",new Error("auth failed. no id or key.")),!1;this.boho.set_id8(t),this.boho.set_key(e)}return this.useAuth=!0,!0}onData(t){let e,r=t[0];if(r===Qt.BohoMsg.ENC_488)e=this.boho.decrypt_488(t),e&&(r=e[0],t=e);else if(r===Qt.BohoMsg.ENC_E2E)try{if(e=this.boho.decrypt_488(t),!e)return;r=e[0],t.set(e,Qt.MetaSize.ENC_488),t=t.subarray(Qt.MetaSize.ENC_488)}catch(t){return}let n=G[r];switch(n||(n=Qt.BohoMsg[r]),r){case G.OVER_SIZE:console.log("## server sent: over_size event."),this.emit("over_size","over_size");break;case G.PING:this.pong();break;case G.PONG:break;case G.IAM_RES:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.ip&&(this.ip=r.ip)}catch(t){this.emit("error",new Error("IAM_RES data error"))}break;case G.CID_RES:let r=Xt.decode(t.subarray(1));this.cid=r,this.stateChange("ready","cid_ready"),this.subscribe_memory_channels();break;case G.QUOTA_LEVEL:let n=t[1];this.level=n,this.quota=V[n],console.log("## QUOTA:",n,JSON.stringify(this.quota));break;case G.SERVER_CLEAR_AUTH:this.useAuth=!1,this.boho.clearAuth(),this.stop();break;case G.SERVER_REDIRECT:let i,o,s;7==t.byteLength?(i=function(t){if(6!=t.byteLength)return;return t[0].toString()+"."+t[1].toString()+"."+t[2].toString()+"."+t[3].toString()+":"+((t[4]<<8)+t[5]).toString()}(t.subarray(1)),s="cong://"):(i=Xt.decode(t.subarray(1)),s=""),o=s+i,this.redirect(o);break;case G.SERVER_READY:this.stateChange("server_ready","server_ready"),this.useAuth?this.send(this.boho.auth_req()):this.send(Kt.from([G.CID_REQ]));break;case G.SERVER_SIGNAL:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.event&&r.data&&(this.serverSet=r.data,this.emit(r.event,r.data))}catch(t){this.emit("error",new Error("SERVER_SIGNAL parsing error"))}break;case G.SET:try{let e=C.unpack(t);e&&this.emit(e.topic,...e.args)}catch(t){this.emit("error",new Error("SET parsing error"))}break;case G.SIGNAL_E2E:case G.SIGNAL:try{let e=t.readUint8(1),r=t.subarray(2,2+e),n=Xt.decode(r),i=t.readUint8(2+e),o=t.subarray(3+e);switch(i){case H.EMPTY:0===n.indexOf("@")?this.emit("@",null,n):this.emit(n,null,n);break;case H.TEXT:let t=o;0===o[o.byteLength-1]&&(t=o.subarray(0,o.byteLength-1));let e=Xt.decode(t);0===n.indexOf("@")&&this.emit("@",e,n),"@"!==n&&this.emit(n,e,n);break;case H.BINARY:0===n.indexOf("@")&&this.emit("@",o,n),"@"!==n&&this.emit(n,o,n);break;case H.OBJECT:let r=Xt.decode(o),i=JSON.parse(r);0===n.indexOf("@")&&this.emit("@",i,n),"@"!==n&&this.emit(n,i,n);break;case H.MJSON:let s=Xt.decode(o),f=JSON.parse(s);0===n.indexOf("@")&&this.emit("@",...f,n),"@"!==n&&this.emit(n,...f,n);break;case H.MBA:let u=C.unpack(o);0===n.indexOf("@")&&this.emit("@",...u.args,n),"@"!==n&&this.emit(n,...u.args,n)}}catch(t){this.emit("error",new Error("signal parse err"))}break;case G.RESPONSE_MBP:this.testPromise(t);break;case Qt.BohoMsg.AUTH_NONCE:let f=this.boho.auth_hmac(t);f?this.send(f):this.stateChange("auth_fail","Invalid local auth_hmac.");break;case Qt.BohoMsg.AUTH_FAIL:this.stateChange("auth_fail","server reject auth.");break;case Qt.BohoMsg.AUTH_ACK:this.boho.check_auth_ack_hmac(t)?(this.stateChange("auth_ready","server sent auth_ack"),this.send(Kt.from([G.CID_REQ]))):this.stateChange("auth_fail","invalid server_hmac");break;default:try{e=Xt.decode(t),this.emit("text_message",e)}catch(t){}}}iam(t){t?this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM),C.MB("#",t))):this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM)))}ping(){this.send(Kt.from([G.PING]))}pong(){this.send(Kt.from([G.PONG]))}echo(t){t?(console.log("echo args:",t),this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.ECHO),C.MB("#msg",t)))):this.send(Kt.from([G.ECHO]))}bin(...t){this.send(C.U8pack(...t))}send(t){if(t.byteLength>this.quota.signalSize)return this.emit("over_size"),console.log("## QUOTA LIMIT OVER!! \nsignal message.byteLength: ",t.byteLength),void console.log("## your maximum signalSize(bytes) is:",this.quota.signalSize);this.socket_send(t)}getEncryptionMode(){return!(this.encMode!==z.YES&&(this.encMode!==z.AUTO||this.TLS||!this.boho.isAuthorized))}send_enc_mode(t,e){if(void 0===e&&(e=this.getEncryptionMode()),t[0]==G.SIGNAL_E2E&&e){let e=t[1],r=this.boho.encrypt_488(t.subarray(0,3+e));r[0]=Qt.BohoMsg.ENC_E2E,this.send(Kt.concat([r,t.subarray(3+e)]))}else if(e){let e=this.boho.encrypt_488(t);this.send(e)}else this.send(t)}setMsgPromise(t){return new Promise(((e,r)=>{this.promiseMap.set(t,[e,r]),setTimeout((e=>{this.promiseMap.has(t)&&(r("timeout"),this.promiseMap.delete(t))}),this.promiseTimeOut)}))}testPromise(t){let e=C.unpack(t);if(e)if(this.promiseMap.has(e.mid)){let[t,r]=this.promiseMap.get(e.mid);this.promiseMap.delete(e.mid),e.status<128?(e.ok=!0,t(e)):(e.ok=!1,r(e))}else console.log("no promise id")}publish(...t){this.signal(...t)}signal(t,...e){if("string"!=typeof t)throw TypeError("tag should be string.");let r=J(t,...e);this.send_enc_mode(r)}decrypt_e2e(t,e){return this.boho.decrypt_e2e(t,e)}signal_e2e(t,e,r){if("string"!=typeof t)throw TypeError("tag should be string.");let n=Wt.encode(t),i=C.B8(e),o=this.boho.encrypt_e2e(i,r),s=C.pack(C.MB("#MsgType","8",G.SIGNAL_E2E),C.MB("#tagLen","8",n.byteLength),C.MB("#tag",n),C.MB("#payloadType","8",H.BINARY),C.MB("#payload",o));this.send_enc_mode(s)}set(t,...e){return t&&0!=e.length?this.req("store","set",t,...e):Promise.reject(new Error("set need storeName and value)"))}async get(t){if(!t)return Promise.reject(new Error("store get need storeName)"));let e=await this.req("store","get",t),{$:r}=C.unpack(e.body);return r}req(t,e,...r){if(!t||!e)return Promise.reject(new Error("request need target and topic)"));let n;return n=r.length>0?C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e),C.MBA(...r)):C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e)),this.send_enc_mode(n),this.setMsgPromise(this.mid)}subscribe(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return;t.split(",").forEach((t=>{this.channels.add(t)}));let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE),C.NB("8",e.byteLength),e]))}subscribe_promise(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return Promise.reject("subscribe_promise:: connection is not ready");let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN2)throw TypeError("please use tag string bytelength: "+F.TAG_LEN2);return this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE_REQ),C.NB("16",++this.mid),C.NB("16",e.byteLength),e])),this.setMsgPromise(this.mid)}subscribe_memory_channels(){if(0==this.channels.size)return;let t=Array.from(this.channels).join(",");this.subscribe_promise(t).then((t=>{})).catch((t=>{console.log(">> SUBSCRIBE FAIL:",t)}))}unsubscribe(t=""){if("string"!=typeof t)throw TypeError("tag should be string.");if(""==t)this.channels.clear();else{t.split(",").forEach((t=>{this.channels.delete(t)}))}let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.UNSUBSCRIBE),C.NB("8",e.byteLength),e]))}listen(t,e){if("string"!=typeof t)throw TypeError("tag should be string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof e)throw TypeError("handler is not a function.");0!==t.indexOf("@")&&this.channels.add(t),this.on(t,e)}link(t,e,r){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof r)throw TypeError("handler is not a function.");let n;0!==e.indexOf("@")&&this.channels.add(e),n=this.linkMap.has(t)?this.linkMap.get(t):new Set,n.add(e),this.linkMap.set(t,n),this.on(e,r),this.subscribe(e)}unlink(t,e){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");const r=this.linkMap.get(t);r&&r.has(e)&&(this.unsubscribe(e),this.removeAllListeners(e),r.delete(e),0===r.size&&this.linkMap.delete(t))}unlinkAll(t){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");const e=this.linkMap.get(t);if(e){for(const t of e)this.unsubscribe(t),this.removeAllListeners(t);this.linkMap.delete(t)}}getMetric(){return{tx:this.txCounter,rx:this.rxCounter,txb:this.txBytes,rxb:this.rxBytes,last:(Date.now()-this.lastTxRxTime)/1e3}}getState(){return this.state}getStateName(){return $[this.state].toLowerCase()}getSecurity(){return{useAuth:this.useAuth,isTLS:this.TLS,isAuthorized:this.boho.isAuthorized,encMode:this.encMode,usingEncryption:this.getEncryptionMode()}}stateChange(t,e){let r=t.toLowerCase();this.state=$[t.toUpperCase()],e&&this.emit(r,e),this.stateName!==r&&(this.stateName=r,this.emit("change",r))}}const te=Qt.Buffer;class ee extends Zt{static version="3.1.0";static binaryType="arraybuffer";static Boho=Qt;static MBP=Qt.MBP;static Buffer=Qt.Buffer;static constants=Y;static instanceCount=0;static webSocketCount=0;constructor(t){super(t),ee.instanceCount++,this.boundBrowserVisiblePing=this.browserVisiblePing.bind(this),document.addEventListener("visibilitychange",this.boundBrowserVisiblePing),t&&this.open()}browserVisiblePing(){"visible"===document.visibilityState&&this.ping()}stop(){super.stop()}destroy(){document.removeEventListener("visibilitychange",this.boundBrowserVisiblePing),super.destroy()}keepAlive(){this.autoReconnect&&(this.socket&&this.socket.readyState!==WebSocket.CLOSED||this.state!==ee.constants.STATES.CLOSED||this.open())}createConnection(t){ee.webSocketCount++,this.socket=new WebSocket(t),this.socket.binaryType=ee.binaryType,this.stateChange("opening"),this.socket.onopen=()=>{this.socket&&("arraybuffer"==this.socket.binaryType?this.socket.onmessage=this.onWebSocketMessage.bind(this):this.socket.onmessage=this.onWebSocketMessageBlob.bind(this),this.emit("open"))},this.socket.onerror=t=>{this.emit("error",t)},this.socket.onclose=()=>{this.emit("close")}}onWebSocketMessage(t){this.rxCounter++,this.lastTxRxTime=Date.now();let e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}async onWebSocketMessageBlob(t){let e;if(this.rxCounter++,this.lastTxRxTime=Date.now(),t.data instanceof Blob){let r=await t.data.arrayBuffer();e=te.from(r)}else e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}socket_send(t){1===this.socket?.readyState?(this.socket.send(t),this.txCounter++,this.txBytes+=t.byteLength,this.lastTxRxTime=Date.now()):console.log(".")}}return ee}));
22
+ */var Ht=(Dt||(Dt=1,function(t){const e=function(){if(xt)return jt;xt=1,jt.byteLength=function(t){var e=o(t),r=e[0],n=e[1];return 3*(r+n)/4-n},jt.toByteArray=function(t){var n,i,s=o(t),f=s[0],u=s[1],h=new r(function(t,e,r){return 3*(e+r)/4-r}(0,f,u)),a=0,c=u>0?f-4:f;for(i=0;i<c;i+=4)n=e[t.charCodeAt(i)]<<18|e[t.charCodeAt(i+1)]<<12|e[t.charCodeAt(i+2)]<<6|e[t.charCodeAt(i+3)],h[a++]=n>>16&255,h[a++]=n>>8&255,h[a++]=255&n;return 2===u&&(n=e[t.charCodeAt(i)]<<2|e[t.charCodeAt(i+1)]>>4,h[a++]=255&n),1===u&&(n=e[t.charCodeAt(i)]<<10|e[t.charCodeAt(i+1)]<<4|e[t.charCodeAt(i+2)]>>2,h[a++]=n>>8&255,h[a++]=255&n),h},jt.fromByteArray=function(e){for(var r,n=e.length,i=n%3,o=[],f=16383,u=0,h=n-i;u<h;u+=f)o.push(s(e,u,u+f>h?h:u+f));return 1===i?(r=e[n-1],o.push(t[r>>2]+t[r<<4&63]+"==")):2===i&&(r=(e[n-2]<<8)+e[n-1],o.push(t[r>>10]+t[r>>4&63]+t[r<<2&63]+"=")),o.join("")};for(var t=[],e=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)t[i]=n[i],e[n.charCodeAt(i)]=i;function o(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function s(e,r,n){for(var i,o,s=[],f=r;f<n;f+=3)i=(e[f]<<16&16711680)+(e[f+1]<<8&65280)+(255&e[f+2]),s.push(t[(o=i)>>18&63]+t[o>>12&63]+t[o>>6&63]+t[63&o]);return s.join("")}return e["-".charCodeAt(0)]=62,e["_".charCodeAt(0)]=63,jt}(),r=Ft(),n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=s,t.SlowBuffer=function(t){return+t!=t&&(t=0),s.alloc(+t)},t.INSPECT_MAX_BYTES=50;const i=2147483647;function o(t){if(t>i)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return h(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|p(t,e);let n=o(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(q(t,Uint8Array)){const e=new Uint8Array(t);return c(e.buffer,e.byteOffset,e.byteLength)}return a(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer))return c(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return c(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);const i=function(t){if(s.isBuffer(t)){const e=0|l(t.length),r=o(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||J(t.length)?o(0):a(t):"Buffer"===t.type&&Array.isArray(t.data)?a(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t){return u(t),o(t<0?0:0|l(t))}function a(t){const e=t.length<0?0:0|l(t.length),r=o(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function c(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function l(t){if(t>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|t}function p(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(t).length;default:if(i)return n?-1:G(t).length;e=(""+e).toLowerCase(),i=!0}}function y(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return T(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return L(this,e,r);case"latin1":case"binary":return v(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),J(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,i){let o,s=1,f=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,f/=2,u/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){let n=-1;for(o=r;o<f;o++)if(h(t,o)===h(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+u>f&&(r=f-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(h(t,o+n)!==h(e,n)){r=!1;break}if(r)return o}return-1}function w(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(e.substr(2*s,2),16);if(J(n))return s;t[r+s]=n}return s}function E(t,e,r,n){return V(G(e,t.length-r),t,r,n)}function B(t,e,r,n){return V(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function m(t,e,r,n){return V(Y(e),t,r,n)}function A(t,e,r,n){return V(function(t,e){let r,n,i;const o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function _(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function I(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,s=e>239?4:e>223?3:e>191?2:1;if(i+s<=r){let r,n,f,u;switch(s){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(o=u));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=t[i+1],n=t[i+2],f=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&f)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&f,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(t){const e=t.length;if(e<=U)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=U));return r}(n)}t.kMaxLength=i,s.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return u(t),t<=0?o(t):void 0!==e?"string"==typeof r?o(t).fill(e,r):o(t).fill(e):o(t)}(t,e,r)},s.allocUnsafe=function(t){return h(t)},s.allocUnsafeSlow=function(t){return h(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),q(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=s.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(q(e,Uint8Array))i+e.length>n.length?(s.isBuffer(e)||(e=s.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!s.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},s.byteLength=p,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},s.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},s.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},s.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?I(this,0,t):y.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(s.prototype[n]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,i){if(q(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),f=(r>>>=0)-(e>>>=0);const u=Math.min(o,f),h=this.slice(n,i),a=t.slice(e,r);for(let t=0;t<u;++t)if(h[t]!==a[t]){o=h[t],f=a[t];break}return o<f?-1:f<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return d(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return d(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return w(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return B(this,t,e,r);case"base64":return m(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const U=4096;function L(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function v(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function T(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=Q[t[n]];return i}function S(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function R(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function O(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function M(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function C(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function N(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function k(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,4),r.write(t,e,n,i,23,4),n+4}function x(t,e,n,i,o){return e=+e,n>>>=0,o||N(t,0,n,8),r.write(t,e,n,i,52,8),n+8}s.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,s.prototype),n},s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||R(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),s.prototype.readBigUInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||R(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||R(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),s.prototype.readBigInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||F(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),s.prototype.readFloatLE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||R(t,4,this.length),r.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||R(t,8,this.length),r.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||O(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigUInt64LE=K((function(t,e=0){return M(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=K((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=0,o=1,s=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);O(this,t,e,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||O(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigInt64LE=K((function(t,e=0){return M(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=K((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return k(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return k(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=s.isBuffer(t)?t:s.from(t,n),f=o.length;if(0===f)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%f]}return this};const P={};function D(t,e,r){P[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function $(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,i,o){if(t>r||t<e){const r="bigint"==typeof e?"n":"";let n;throw n=0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new P.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||F(e,t.length-(r+1))}(n,i,o)}function z(t,e){if("number"!=typeof t)throw new P.ERR_INVALID_ARG_TYPE(e,"number",t)}function F(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new P.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=$(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=$(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const H=/[^+/0-9A-Za-z-_]/g;function G(t,e){let r;e=e||1/0;const n=t.length;let i=null;const o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(H,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function K(t){return"undefined"==typeof BigInt?W:t}function W(){throw new Error("BigInt not supported")}}($t)),$t);let Gt={AUTH_REQ:176,AUTH_NONCE:177,AUTH_HMAC:178,AUTH_ACK:179,AUTH_FAIL:180,AUTH_EXT:181,ENC_PACK:182,ENC_E2E:183,ENC_488:184};for(let t in Gt)Gt[Gt[t]]=t;const Yt={AUTH_REQ:Nt.meta(Nt.MB("header","8",0),Nt.MB("reserved","8",0)),AUTH_NONCE:Nt.meta(Nt.MB("header","8",0),Nt.MB("unixTime","32L",0),Nt.MB("milTime","32L",0),Nt.MB("nonce",Ht.Buffer.alloc(4))),AUTH_HMAC:Nt.meta(Nt.MB("header","8",0),Nt.MB("id8",Ht.Buffer.alloc(8)),Nt.MB("nonce",Ht.Buffer.alloc(4)),Nt.MB("hmac32",Ht.Buffer.alloc(32))),AUTH_ACK:Nt.meta(Nt.MB("header","8",0),Nt.MB("hmac32",Ht.Buffer.alloc(32))),ENC_PACK:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("salt12",Ht.Buffer.alloc(12)),Nt.MB("hmac",8,0)),ENC_488:Nt.meta(Nt.MB("type","8",0),Nt.MB("len","32L",0),Nt.MB("otpSrc8",Ht.Buffer.alloc(8)),Nt.MB("hmac8",Ht.Buffer.alloc(8)))};function Vt(t){let e=t[t.length-1];return e[2]+e[3]}const qt={AUTH_REQ:Vt(Yt.AUTH_REQ),AUTH_NONCE:Vt(Yt.AUTH_NONCE),AUTH_HMAC:Vt(Yt.AUTH_HMAC),AUTH_ACK:Vt(Yt.AUTH_ACK),ENC_PACK:Vt(Yt.ENC_PACK),ENC_488:Vt(Yt.ENC_488)};function Jt(t){return globalThis.crypto.getRandomValues(Ht.Buffer.alloc(t))}class Qt{constructor(){this._id8=Ht.Buffer.alloc(8),this._otpSrc44=Ht.Buffer.alloc(44),this._otp36=Ht.Buffer.alloc(36),this._hmac=Ht.Buffer.alloc(32),this.auth_salt12=Ht.Buffer.alloc(12),this.localNonce=Ht.Buffer.alloc(4),this.remoteNonce=Ht.Buffer.alloc(4),this.isAuthorized=!1}clearAuth(){this._id8.fill(0),this._otpSrc44.fill(0),this._otp36.fill(0),this._hmac.fill(0),this.auth_salt12.fill(0),this.localNonce.fill(0),this.remoteNonce.fill(0),this.isAuthorized=!1}set_hash_id8(t){Nt.B8(kt.hash(t)).copy(this._id8,0,0,8)}set_id8(t){let e=Nt.B8(t);this._id8.fill(0),e.copy(this._id8,0,0,8)}set_key(t){Nt.B8(kt.hash(t)).copy(this._otpSrc44,0,0,32)}set_id_key(t){let e=t.indexOf(".");if(-1==e)return;let r=t.substring(0,e),n=t.substring(e+1);this.set_id8(r),this.set_key(n)}copy_id8(t){t.copy(this._id8,0,0,8)}copy_key(t){t.copy(this._otpSrc44,0,0,32)}sha256_n(t,e){let r=kt.hash(t);for(let t=0;t<e;t++)r=kt.hash(r);return r}set_clock_rand(){let t=Date.now(),e=parseInt(t/1e3);t%=4294967295,Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",t),Jt(4)]).copy(this._otpSrc44,32)}set_clock_nonce(t){let e=Date.now(),r=parseInt(e/1e3);e%=4294967295,Ht.Buffer.concat([Nt.NB("32L",r),Nt.NB("32L",e),t]).copy(this._otpSrc44,32)}set_salt12(t){t.copy(this._otpSrc44,32)}resetOTP(){Nt.B8(kt.hash(this._otpSrc44)).copy(this._otp36,0,0,32)}getIndexOTP(t){return this._otp36.writeUInt32LE(t,32),kt.hash(this._otp36)}generateHMAC(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);this._hmac=Nt.B8(kt.hash(e))}getHMAC8(t){let e=Ht.Buffer.concat([this._otpSrc44,t]);return this._hmac=Nt.B8(kt.hash(e)),this._hmac.subarray(0,8)}xotp(t,e=0,r=!1){let n=(t=Nt.B8(t,r)).byteLength,i=e,o=0,s=0;for(;n>0;){s=n<32?n:32;let e=this.getIndexOTP(++i);for(let r=0;r<s;r++)t[o++]^=e[r];n-=32}return t}auth_req(){return Nt.pack(Nt.MB("#type","8",Gt.AUTH_REQ),Nt.MB("#reserved","8",0))}auth_nonce(){let t=Date.now(),e=Math.floor(t/1e3),r=t%1e3;return this.localNonce=Jt(4),this.auth_salt12=Ht.Buffer.concat([Nt.NB("32L",e),Nt.NB("32L",r),this.localNonce]),Ht.Buffer.concat([Nt.NB("8",Gt.AUTH_NONCE),this.auth_salt12])}auth_hmac(t){let e=Nt.unpack(t,Yt.AUTH_NONCE);if(e){let t=Ht.Buffer.concat([Nt.NB("32L",e.unixTime),Nt.NB("32L",e.milTime),e.nonce]);return this.set_salt12(t),this.localNonce=Jt(4),this.generateHMAC(this.localNonce),this.remoteNonce=e.nonce,Nt.pack(Nt.MB("#header","8",Gt.AUTH_HMAC),Nt.MB("#id8",this._id8),Nt.MB("#nonce",this.localNonce),Nt.MB("#hmac32",this._hmac))}return!1}check_auth_hmac(t){let e;if(t instanceof Uint8Array){if(e=Nt.unpack(t,Yt.AUTH_HMAC),!e)return}else e=t;this.set_salt12(this.auth_salt12),this.generateHMAC(e.nonce);let r=this._hmac;if(Nt.equal(e.hmac32,r)){this.remoteNonce=e.nonce;let t=Ht.Buffer.concat([this.localNonce,this.remoteNonce,this.localNonce]);this.set_salt12(t),this.generateHMAC(e.nonce);let r=this._hmac,n=Nt.rawPack(Nt.MB("header","8",Gt.AUTH_ACK),Nt.MB("hmac32",r));return this.isAuthorized=!0,n}return!1}check_auth_ack_hmac(t){let e=Nt.unpack(t,Yt.AUTH_ACK);if(e){let t=Ht.Buffer.concat([this.remoteNonce,this.localNonce,this.remoteNonce]);this.set_salt12(t),this.generateHMAC(this.localNonce);let r=this._hmac;if(Nt.equal(r,e.hmac32))return this.isAuthorized=!0,!0}}encrypt_488(t){if(!this.isAuthorized)return;t=Nt.B8(t),this.set_clock_nonce(this.remoteNonce),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_488),Nt.MB("#len","32L",t.byteLength),Nt.MB("#otpSrc8",this._otpSrc44.subarray(32,40)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decrypt_488(t){t=Nt.B8(t);let e=Nt.unpack(t,Yt.ENC_488);if(e){let t=Ht.Buffer.concat([e.otpSrc8,this.localNonce]);this.set_salt12(t),this.resetOTP();let r=e.$OTHERS.subarray(0,e.len),n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(i,e.hmac8))return n}}encryptPack(t){t=Nt.B8(t),this.set_clock_rand(),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return Nt.pack(Nt.MB("#type","8",Gt.ENC_PACK),Nt.MB("#len","32L",t.byteLength),Nt.MB("#salt12",this._otpSrc44.subarray(32)),Nt.MB("#hmac8",e),Nt.MB("#xdata",r))}decryptPack(t){if(t[0]===Gt.ENC_PACK&&t.readUint32LE(1)==t.byteLength-qt.ENC_PACK)try{let e=Nt.unpack(t,Yt.ENC_PACK);if(!e)return;this.set_salt12(e.salt12),this.resetOTP();let r=e.$OTHERS,n=this.xotp(r),i=this.getHMAC8(n);if(Nt.equal(e.hmac,i))return e.data=n,e}catch(t){}}encrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.encryptPack(t);return this._otpSrc44.set(r),n}decrypt_e2e(t,e){let r=Ht.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.decryptPack(t);return this._otpSrc44.set(r),n}}Qt.RAND=Jt,Qt.BohoMsg=Gt,Qt.Meta=Yt,Qt.MetaSize=qt,Qt.sha256=kt,Qt.MBP=Nt,Qt.Buffer=Ht.Buffer;const Kt=C.Buffer,Wt=new TextEncoder,Xt=new TextDecoder;class Zt extends D{constructor(t){super(),this.cid="",this.ip="",this.socket=null,this.url=t,this.state=$.CLOSED,this.stateName=this.getStateName(),this.txCounter=0,this.rxCounter=0,this.txBytes=0,this.rxBytes=0,this.lastTxRxTime=Date.now(),this.connectionCheckerPeriod=F.CONNECTION_CHECKER_PERIOD,this.connectionCheckerIntervalID=null,this.boho=new Qt,this.TLS=!1,this.encMode=z.AUTO,this.useAuth=!1,this.nick="",this.channels=new Set,this.promiseMap=new Map,this.promiseTimeOut=F.PROMISE_TIMEOUT,this.mid=0,this.level=3,this.quota=V[this.level],this.serverSet={},this.linkMap=new Map,this.autoReconnect=!0,this._closed=!1,this.on("open",this.onOpen.bind(this)),this.on("close",this.onClose.bind(this)),this.on("socket_data",this.onData.bind(this))}close(){if(!this._closed){if(this._closed=!0,!1===this.autoReconnect&&(clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null),this.socket){if(0===this.socket.readyState){const t=this.socket;t.onopen=()=>{t&&t.close()},t.onmessage=null,t.onerror=null,t.onclose=null}else try{this.socket.close?.()}catch{}this.socket=null}this.promiseMap.clear(),this.emit("closed"),this.stateChange("closed")}}stop(){this.autoReconnect=!1,this.close()}destroy(){this.stop(),this.removeAllListeners(),this.channels.clear(),this.linkMap.clear(),this.boho=null}keepAlive(){this.autoReconnect}redirect(t){this.close(),this.stateChange("redirecting"),this.createConnection(t)}open(t){this.socket&&this.close(),t&&(this.url=t),this.url?(this.createConnection(this.url),this.connectionCheckerIntervalID||(this.connectionCheckerIntervalID=setInterval(this.keepAlive.bind(this),this.connectionCheckerPeriod))):this.emit("error",new Error("URL is not set."))}onOpen(){this._closed=!1,this.url.includes("wss://")?this.TLS=!0:this.TLS=!1,this.stateChange("open")}onClose(){this.boho.isAuthorized=!1,this.cid="",this.stateChange("closed")}login(t,e){if(!this.auth(t,e))return!1;this.useAuth=!0;let r=this.boho.auth_req();return this.send(r),!0}auth(t,e){if(!t&&!e)return this.emit("error",new Error("auth failed. no id and key.")),!1;if(!e&&t.includes("."))this.boho.set_id_key(t);else{if(!t||!e)return this.emit("error",new Error("auth failed. no id or key.")),!1;this.boho.set_id8(t),this.boho.set_key(e)}return this.useAuth=!0,!0}onData(t){let e,r=t[0];if(r===Qt.BohoMsg.ENC_488)e=this.boho.decrypt_488(t),e&&(r=e[0],t=e);else if(r===Qt.BohoMsg.ENC_E2E)try{if(e=this.boho.decrypt_488(t),!e)return;r=e[0],t.set(e,Qt.MetaSize.ENC_488),t=t.subarray(Qt.MetaSize.ENC_488)}catch(t){return}let n=G[r];switch(n||(n=Qt.BohoMsg[r]),r){case G.OVER_SIZE:console.log("## server sent: over_size event."),this.emit("over_size","over_size");break;case G.PING:this.pong();break;case G.PONG:break;case G.IAM_RES:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.ip&&(this.ip=r.ip)}catch(t){this.emit("error",new Error("IAM_RES data error"))}break;case G.CID_RES:let r=Xt.decode(t.subarray(1));this.cid=r,this.stateChange("ready","cid_ready"),this.subscribe_memory_channels();break;case G.QUOTA_LEVEL:let n=t[1];this.level=n,this.quota=V[n],console.log("## QUOTA:",n,JSON.stringify(this.quota));break;case G.SERVER_CLEAR_AUTH:this.useAuth=!1,this.boho.clearAuth(),this.stop();break;case G.SERVER_REDIRECT:let i,o,s;7==t.byteLength?(i=function(t){if(6!=t.byteLength)return;return t[0].toString()+"."+t[1].toString()+"."+t[2].toString()+"."+t[3].toString()+":"+((t[4]<<8)+t[5]).toString()}(t.subarray(1)),s="cong://"):(i=Xt.decode(t.subarray(1)),s=""),o=s+i,this.redirect(o);break;case G.SERVER_READY:this.stateChange("server_ready","server_ready"),this.useAuth?this.send(this.boho.auth_req()):this.send(Kt.from([G.CID_REQ]));break;case G.SERVER_SIGNAL:try{let e=Xt.decode(t.subarray(1)),r=JSON.parse(e);r.event&&r.data&&(this.serverSet=r.data,this.emit(r.event,r.data))}catch(t){this.emit("error",new Error("SERVER_SIGNAL parsing error"))}break;case G.SET:try{let e=C.unpack(t);e&&this.emit(e.topic,...e.args)}catch(t){this.emit("error",new Error("SET parsing error"))}break;case G.SIGNAL_E2E:case G.SIGNAL:try{let e=t.readUint8(1),r=t.subarray(2,2+e),n=Xt.decode(r),i=t.readUint8(2+e),o=t.subarray(3+e);switch(i){case H.EMPTY:0===n.indexOf("@")?this.emit("@",null,n):this.emit(n,null,n);break;case H.TEXT:let t=o;0===o[o.byteLength-1]&&(t=o.subarray(0,o.byteLength-1));let e=Xt.decode(t);0===n.indexOf("@")&&this.emit("@",e,n),"@"!==n&&this.emit(n,e,n);break;case H.BINARY:0===n.indexOf("@")&&this.emit("@",o,n),"@"!==n&&this.emit(n,o,n);break;case H.OBJECT:let r=Xt.decode(o),i=JSON.parse(r);0===n.indexOf("@")&&this.emit("@",i,n),"@"!==n&&this.emit(n,i,n);break;case H.MJSON:let s=Xt.decode(o),f=JSON.parse(s);0===n.indexOf("@")&&this.emit("@",...f,n),"@"!==n&&this.emit(n,...f,n);break;case H.MBA:let u=C.unpack(o);0===n.indexOf("@")&&this.emit("@",...u.args,n),"@"!==n&&this.emit(n,...u.args,n)}}catch(t){this.emit("error",new Error("signal parse err"))}break;case G.RESPONSE_MBP:this.testPromise(t);break;case Qt.BohoMsg.AUTH_NONCE:let f=this.boho.auth_hmac(t);f?this.send(f):this.stateChange("auth_fail","Invalid local auth_hmac.");break;case Qt.BohoMsg.AUTH_FAIL:this.stateChange("auth_fail","server reject auth.");break;case Qt.BohoMsg.AUTH_ACK:this.boho.check_auth_ack_hmac(t)?(this.stateChange("auth_ready","server sent auth_ack"),this.send(Kt.from([G.CID_REQ]))):this.stateChange("auth_fail","invalid server_hmac");break;default:try{e=Xt.decode(t),this.emit("text_message",e)}catch(t){}}}iam(t){t?this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM),C.MB("#",t))):this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.IAM)))}ping(){this.send(Kt.from([G.PING]))}pong(){this.send(Kt.from([G.PONG]))}echo(t){t?(console.log("echo args:",t),this.send_enc_mode(C.pack(C.MB("#MsgType","8",G.ECHO),C.MB("#msg",t)))):this.send(Kt.from([G.ECHO]))}bin(...t){this.send(C.U8pack(...t))}send(t){if(t.byteLength>this.quota.signalSize)return this.emit("over_size"),console.log("## QUOTA LIMIT OVER!! \nsignal message.byteLength: ",t.byteLength),void console.log("## your maximum signalSize(bytes) is:",this.quota.signalSize);this.socket_send(t)}getEncryptionMode(){return!(this.encMode!==z.YES&&(this.encMode!==z.AUTO||this.TLS||!this.boho.isAuthorized))}send_enc_mode(t,e){if(void 0===e&&(e=this.getEncryptionMode()),t[0]==G.SIGNAL_E2E&&e){let e=t[1],r=this.boho.encrypt_488(t.subarray(0,3+e));r[0]=Qt.BohoMsg.ENC_E2E,this.send(Kt.concat([r,t.subarray(3+e)]))}else if(e){let e=this.boho.encrypt_488(t);this.send(e)}else this.send(t)}setMsgPromise(t){return new Promise(((e,r)=>{this.promiseMap.set(t,[e,r]),setTimeout((e=>{this.promiseMap.has(t)&&(r("timeout"),this.promiseMap.delete(t))}),this.promiseTimeOut)}))}testPromise(t){let e=C.unpack(t);if(e)if(this.promiseMap.has(e.mid)){let[t,r]=this.promiseMap.get(e.mid);this.promiseMap.delete(e.mid),e.status<128?(e.ok=!0,t(e)):(e.ok=!1,r(e))}else console.log("no promise id")}publish(...t){this.signal(...t)}signal(t,...e){if("string"!=typeof t)throw TypeError("tag should be string.");let r=J(t,...e);this.send_enc_mode(r)}decrypt_e2e(t,e){return this.boho.decrypt_e2e(t,e)}signal_e2e(t,e,r){if("string"!=typeof t)throw TypeError("tag should be string.");let n=Wt.encode(t),i=C.B8(e),o=this.boho.encrypt_e2e(i,r),s=C.pack(C.MB("#MsgType","8",G.SIGNAL_E2E),C.MB("#tagLen","8",n.byteLength),C.MB("#tag",n),C.MB("#payloadType","8",H.BINARY),C.MB("#payload",o));this.send_enc_mode(s)}set(t,...e){return t&&0!=e.length?this.req("store","set",t,...e):Promise.reject(new Error("set need storeName and value)"))}async get(t){if(!t)return Promise.reject(new Error("store get need storeName)"));let e=await this.req("store","get",t),{$:r}=C.unpack(e.body);return r}req(t,e,...r){if(!t||!e)return Promise.reject(new Error("request need target and topic)"));let n;return n=r.length>0?C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e),C.MBA(...r)):C.pack(C.MB("#MsgType","8",G.REQUEST),C.MB("mid","16",++this.mid),C.MB("target",t),C.MB("topic",e)),this.send_enc_mode(n),this.setMsgPromise(this.mid)}subscribe(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return;t.split(",").forEach((t=>{this.channels.add(t)}));let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE),C.NB("8",e.byteLength),e]))}subscribe_promise(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==$.READY)return Promise.reject("subscribe_promise:: connection is not ready");let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN2)throw TypeError("please use tag string bytelength: "+F.TAG_LEN2);return this.send_enc_mode(Kt.concat([C.NB("8",G.SUBSCRIBE_REQ),C.NB("16",++this.mid),C.NB("16",e.byteLength),e])),this.setMsgPromise(this.mid)}subscribe_memory_channels(){if(0==this.channels.size)return;let t=Array.from(this.channels).join(",");this.subscribe_promise(t).then((t=>{})).catch((t=>{console.log(">> SUBSCRIBE FAIL:",t)}))}unsubscribe(t=""){if("string"!=typeof t)throw TypeError("tag should be string.");if(""==t)this.channels.clear();else{t.split(",").forEach((t=>{this.channels.delete(t)}))}let e=Wt.encode(t);if(e.byteLength>F.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+F.TAG_LEN1);this.send_enc_mode(Kt.concat([C.NB("8",G.UNSUBSCRIBE),C.NB("8",e.byteLength),e]))}listen(t,e){if("string"!=typeof t)throw TypeError("tag should be string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof e)throw TypeError("handler is not a function.");0!==t.indexOf("@")&&this.channels.add(t),this.on(t,e)}link(t,e,r){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof r)throw TypeError("handler is not a function.");let n;0!==e.indexOf("@")&&this.channels.add(e),n=this.linkMap.has(t)?this.linkMap.get(t):new Set,n.add(e),this.linkMap.set(t,n),this.on(e,r),this.subscribe(e)}unlink(t,e){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");const r=this.linkMap.get(t);r&&r.has(e)&&(this.unsubscribe(e),this.removeAllListeners(e),r.delete(e),0===r.size&&this.linkMap.delete(t))}unlinkAll(t){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");const e=this.linkMap.get(t);if(e){for(const t of e)this.unsubscribe(t),this.removeAllListeners(t);this.linkMap.delete(t)}}getMetric(){return{tx:this.txCounter,rx:this.rxCounter,txb:this.txBytes,rxb:this.rxBytes,last:(Date.now()-this.lastTxRxTime)/1e3}}getState(){return this.state}getStateName(){return $[this.state].toLowerCase()}getSecurity(){return{useAuth:this.useAuth,isTLS:this.TLS,isAuthorized:this.boho.isAuthorized,encMode:this.encMode,usingEncryption:this.getEncryptionMode()}}stateChange(t,e){let r=t.toLowerCase();this.state=$[t.toUpperCase()],e&&this.emit(r,e),this.stateName!==r&&(this.stateName=r,this.emit("change",r))}}const te=Qt.Buffer;class ee extends Zt{static version="3.2.0";static binaryType="arraybuffer";static Boho=Qt;static MBP=Qt.MBP;static Buffer=Qt.Buffer;static constants=Y;static instanceCount=0;static webSocketCount=0;constructor(t){super(t),ee.instanceCount++,this.boundBrowserVisiblePing=this.browserVisiblePing.bind(this),document.addEventListener("visibilitychange",this.boundBrowserVisiblePing),t&&this.open()}browserVisiblePing(){"visible"===document.visibilityState&&this.ping()}stop(){super.stop()}destroy(){document.removeEventListener("visibilitychange",this.boundBrowserVisiblePing),super.destroy()}keepAlive(){this.autoReconnect&&(this.socket&&this.socket.readyState!==WebSocket.CLOSED||this.state!==ee.constants.STATES.CLOSED||this.open())}createConnection(t){ee.webSocketCount++,this.socket=new WebSocket(t),this.socket.binaryType=ee.binaryType,this.stateChange("opening"),this.socket.onopen=()=>{this.socket&&("arraybuffer"==this.socket.binaryType?this.socket.onmessage=this.onWebSocketMessage.bind(this):this.socket.onmessage=this.onWebSocketMessageBlob.bind(this),this.emit("open"))},this.socket.onerror=t=>{this.emit("error",t)},this.socket.onclose=()=>{this.emit("close")}}onWebSocketMessage(t){this.rxCounter++,this.lastTxRxTime=Date.now();let e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}async onWebSocketMessageBlob(t){let e;if(this.rxCounter++,this.lastTxRxTime=Date.now(),t.data instanceof Blob){let r=await t.data.arrayBuffer();e=te.from(r)}else e=te.from(t.data);this.rxBytes+=e.byteLength,this.emit("socket_data",e)}socket_send(t){1===this.socket?.readyState?(this.socket.send(t),this.txCounter++,this.txBytes+=t.byteLength,this.lastTxRxTime=Date.now()):console.log(".")}}return ee}));
23
23
  //# sourceMappingURL=io.min.js.map
package/dist/iosignal.js CHANGED
@@ -13,7 +13,9 @@ import require$$2 from 'os';
13
13
  import require$$0$1 from 'buffer';
14
14
  import { memoryUsage } from 'process';
15
15
 
16
- var version = "3.1.0";
16
+ var version$1 = "3.2.0";
17
+ var pkg = {
18
+ version: version$1};
17
19
 
18
20
  var t$1,e$1={},r$1={};var n$1,i$1,o$1={};
19
21
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */function f$1(){return n$1||(n$1=1,o$1.read=function(t,e,r,n,i){var o,f,u=8*i-n-1,s=(1<<u)-1,h=s>>1,a=-7,c=r?i-1:0,l=r?-1:1,p=t[e+c];for(c+=l,o=p&(1<<-a)-1,p>>=-a,a+=u;a>0;o=256*o+t[e+c],c+=l,a-=8);for(f=o&(1<<-a)-1,o>>=-a,a+=n;a>0;f=256*f+t[e+c],c+=l,a-=8);if(0===o)o=1-h;else {if(o===s)return f?NaN:1/0*(p?-1:1);f+=Math.pow(2,n),o-=h;}return (p?-1:1)*f*Math.pow(2,o-n)},o$1.write=function(t,e,r,n,i,o){var f,u,s,h=8*o-i-1,a=(1<<h)-1,c=a>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,y=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(u=isNaN(e)?1:0,f=a):(f=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-f))<1&&(f--,s*=2),(e+=f+c>=1?l/s:l*Math.pow(2,1-c))*s>=2&&(f++,s/=2),f+c>=a?(u=0,f=a):f+c>=1?(u=(e*s-1)*Math.pow(2,i),f+=c):(u=e*Math.pow(2,c-1)*Math.pow(2,i),f=0));i>=8;t[r+p]=255&u,p+=y,u/=256,i-=8);for(f=f<<i|u,h+=i;h>0;t[r+p]=255&f,p+=y,f/=256,h-=8);t[r+p-y]|=128*g;}),o$1}
@@ -7586,9 +7588,9 @@ class IOWS extends IOCore {
7586
7588
 
7587
7589
  let serverOption = {
7588
7590
  clientTracking: false,
7589
- port: 0, //wsPort
7591
+ port: null, // WebSocket
7592
+ congPort: null, // CongSocket
7590
7593
  httpServer: null,
7591
- congPort: 0,
7592
7594
  timeout: 50000,
7593
7595
  showMessage: 'none',
7594
7596
  showMetric: 0,
@@ -8131,6 +8133,8 @@ class Remote extends RemoteCore {
8131
8133
  socket.on("ping", this.receiveMonitor.bind(this));
8132
8134
  socket.on("error", (e) => { console.log('Websocket error', e, e.code); });
8133
8135
  socket.onclose = (e) => {
8136
+ // Clean up all listeners on the socket to prevent leaks
8137
+ socket.removeAllListeners();
8134
8138
  this.manager.removeRemote(this);
8135
8139
  };
8136
8140
  } else { // TCP else
@@ -8150,6 +8154,9 @@ class Remote extends RemoteCore {
8150
8154
 
8151
8155
  socket.on('error', e => { console.log('TCP Socket error', e); });
8152
8156
  socket.on('close', e => {
8157
+ // Clean up listeners on both the socket and the parser
8158
+ socket.removeAllListeners();
8159
+ this.congRx.removeAllListeners();
8153
8160
  this.manager.removeRemote(this);
8154
8161
  });
8155
8162
 
@@ -8873,7 +8880,23 @@ class Manager {
8873
8880
  }
8874
8881
  }
8875
8882
 
8883
+ close() {
8884
+ clearInterval(this.pingIntervalID);
8885
+ if (this.monitIntervalID) {
8886
+ clearInterval(this.monitIntervalID);
8887
+ }
8876
8888
 
8889
+ this.remotes.forEach(remote => {
8890
+ remote.close();
8891
+ });
8892
+
8893
+ this.remotes.clear();
8894
+ this.cid2remote.clear();
8895
+ this.retain_messages.clear();
8896
+ this.channel_map.clear();
8897
+
8898
+ console.log('Manager closed');
8899
+ }
8877
8900
  }
8878
8901
 
8879
8902
  const STATUS = {
@@ -8889,6 +8912,8 @@ class Server extends require$$0$3 {
8889
8912
  super();
8890
8913
  this.apiNames = new Set();
8891
8914
  this.wss = {};
8915
+ this.port = null;
8916
+ this.congPort = null;
8892
8917
 
8893
8918
  if (options.timeout) {
8894
8919
  let pingT = parseInt(options.timeout);
@@ -8909,38 +8934,44 @@ class Server extends require$$0$3 {
8909
8934
  serverOption.showMetric = options.showMetric;
8910
8935
  }
8911
8936
 
8912
- if (options.timeout) {
8913
- serverOption.timeout = options.timeout;
8914
- }
8915
-
8916
- if (options.port) {
8917
- serverOption.port = parseInt(options.port);
8937
+ if (options.port || options.port == 0) {
8938
+ this.port = parseInt(options.port);
8918
8939
  }
8919
8940
 
8920
8941
  if (options.httpServer) {
8921
- serverOption.httpServer = options.httpServer;
8942
+ this.httpServer = options.httpServer;
8922
8943
  }
8923
8944
 
8924
- if (options.congPort) {
8925
- serverOption.congPort = parseInt(options.congPort);
8945
+ if (options.congPort || options.congPort == 0) {
8946
+ this.congPort = parseInt(options.congPort);
8926
8947
  }
8927
8948
 
8928
8949
  this.manager = new Manager(this, authManager);
8929
8950
 
8930
- if (serverOption.port || serverOption.httpServer) this.startWSServer(serverOption);
8931
- if (serverOption.congPort) this.startCongServer(serverOption.congPort);
8951
+ this.serverCountToListen = 0;
8952
+ this.listeningServerCount = 0;
8953
+ if (this.port || this.port == 0 || this.httpServer) this.serverCountToListen++;
8954
+ if (this.congPort || this.congPort == 0) this.serverCountToListen++;
8955
+
8956
+ if (this.serverCountToListen === 0) {
8957
+ process.nextTick(() => this.emit('ready'));
8958
+ } else {
8959
+ if (this.port || this.port == 0 || this.httpServer) this.startWSServer();
8960
+ if (this.congPort || this.congPort == 0) this.startCongServer();
8961
+ }
8932
8962
 
8933
8963
  }
8934
8964
 
8935
8965
 
8936
- startWSServer(serverOption) {
8966
+ startWSServer() {
8937
8967
 
8938
- if (serverOption.port) {
8939
- console.log('opening WebSocket Server port:', serverOption.port);
8940
- this.wss = new WebSocketServer({ port: serverOption.port });
8941
- } else if (serverOption.httpServer) {
8968
+ // console.log('optoins', options )
8969
+ if (this.port || this.port == 0) {
8970
+ console.log('opening WebSocket Server port:', this.port);
8971
+ this.wss = new WebSocketServer({ port: this.port });
8972
+ } else if (this.httpServer) {
8942
8973
  console.log('opening WebSocket Server external httpServer:');
8943
- this.wss = new WebSocketServer({ server: serverOption.httpServer });
8974
+ this.wss = new WebSocketServer({ server: this.httpServer });
8944
8975
  } else {
8945
8976
  throw new TypeError(
8946
8977
  'One and only one of the "port", "httpServer"' +
@@ -8949,6 +8980,15 @@ class Server extends require$$0$3 {
8949
8980
  }
8950
8981
 
8951
8982
 
8983
+ this.wss.once('listening', () => {
8984
+ this.port = this.wss.address().port;
8985
+ console.log('wss server bound port:', this.port );
8986
+ this.listeningServerCount++;
8987
+ if (this.listeningServerCount === this.serverCountToListen) {
8988
+ this.emit('ready');
8989
+ }
8990
+ });
8991
+
8952
8992
  // this.wss.setMaxListeners(0)
8953
8993
 
8954
8994
  this.wss.on('error', (err) => {
@@ -8970,8 +9010,8 @@ class Server extends require$$0$3 {
8970
9010
 
8971
9011
  }
8972
9012
 
8973
- startCongServer(congPort) {
8974
- console.log('opening CongSocket Server:', congPort);
9013
+ startCongServer() {
9014
+ console.log('opening CongSocket Server port:', this.congPort);
8975
9015
 
8976
9016
  this.congServer = net.createServer((socket) => {
8977
9017
  this.manager.addRemote(socket);
@@ -8981,8 +9021,15 @@ class Server extends require$$0$3 {
8981
9021
  if (err.code == 'EADDRINUSE') {
8982
9022
  process.exit();
8983
9023
  }
8984
- }).listen(congPort, () => {
8985
- // console.log('congsocket server bound' );
9024
+ }).on('close', () => {
9025
+ console.log('### cong server closed.');
9026
+ }).listen(this.congPort, () => {
9027
+ this.congPort = this.congServer.address().port;
9028
+ console.log('congsocket server bound port:', this.congPort );
9029
+ this.listeningServerCount++;
9030
+ if (this.listeningServerCount === this.serverCountToListen) {
9031
+ this.emit('ready');
9032
+ }
8986
9033
  });
8987
9034
  }
8988
9035
 
@@ -9038,6 +9085,46 @@ class Server extends require$$0$3 {
9038
9085
  return this
9039
9086
  }
9040
9087
 
9088
+ close(callback) {
9089
+ console.log('closing io-signal server...');
9090
+ if (this.manager) {
9091
+ this.manager.close();
9092
+ }
9093
+
9094
+ let serverCount = 0;
9095
+ if (this.wss) serverCount++;
9096
+ if (this.congServer) serverCount++;
9097
+
9098
+ if (serverCount === 0) {
9099
+ if (callback) process.nextTick(callback);
9100
+ return;
9101
+ }
9102
+
9103
+ let closedCount = 0;
9104
+ const onClosed = () => {
9105
+ closedCount++;
9106
+ if (closedCount === serverCount) {
9107
+ console.log('io-signal server closed.');
9108
+ if (callback) callback();
9109
+ }
9110
+ };
9111
+
9112
+ if (this.wss) {
9113
+ this.wss.close(() => {
9114
+ console.log('wss server closed.');
9115
+ onClosed();
9116
+ });
9117
+ }
9118
+
9119
+ if (this.congServer) {
9120
+ this.congServer.close((err) => {
9121
+ if (err) console.error('congServer close error', err);
9122
+ console.log('cong server closed.');
9123
+ onClosed();
9124
+ });
9125
+ }
9126
+ }
9127
+
9041
9128
  }
9042
9129
 
9043
9130
  const decoder = new TextDecoder();
@@ -9569,4 +9656,6 @@ class RedisAPI {
9569
9656
 
9570
9657
  }
9571
9658
 
9659
+ const version = pkg.version;
9660
+
9572
9661
  export { API_TYPE, Auth_Env, Auth_File, Auth_Redis, tt as Boho, BohoAuth, CLIENT_STATE, CongRx, ENC_MODE, FileLogger, IOWS as IO, IOCongSocket, IOMsg, M$1 as MBP, PAYLOAD_TYPE, RedisAPI, SIZE_LIMIT, STATES, STATUS$1 as STATUS, Server, api_reply, api_sudo, getPayloadFromSignalPack, getSignalPack, pack, parsePayload, serverOption, version };
@@ -18,7 +18,7 @@
18
18
  }
19
19
  },
20
20
  "../..": {
21
- "version": "3.1.0",
21
+ "version": "3.2.0",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
24
  "boho": "^1.1.1",
@@ -12,7 +12,7 @@
12
12
  }
13
13
  },
14
14
  "../..": {
15
- "version": "3.1.0",
15
+ "version": "3.2.0",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "boho": "^1.1.1",
@@ -19,7 +19,7 @@
19
19
  }
20
20
  },
21
21
  "../..": {
22
- "version": "3.1.0",
22
+ "version": "3.2.0",
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
25
  "boho": "^1.1.1",
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export {version} from "./package.json";
1
+ import pkg from './package.json' with { type: 'json' };
2
+ export const version = pkg.version;
2
3
  export { IOCongSocket } from './src/client/IOCongSocket.js'
3
4
  export { IOWS as IO } from './src/client/IOWS.js'
4
5
  export { pack, CongRx } from './src/client/CongPacket.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iosignal",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "iosignal",
5
5
  "type": "module",
6
6
  "exports": {
@@ -429,5 +429,21 @@ export class Manager {
429
429
  }
430
430
  }
431
431
 
432
+ close() {
433
+ clearInterval(this.pingIntervalID);
434
+ if (this.monitIntervalID) {
435
+ clearInterval(this.monitIntervalID);
436
+ }
437
+
438
+ this.remotes.forEach(remote => {
439
+ remote.close();
440
+ });
432
441
 
442
+ this.remotes.clear();
443
+ this.cid2remote.clear();
444
+ this.retain_messages.clear();
445
+ this.channel_map.clear();
446
+
447
+ console.log('Manager closed');
448
+ }
433
449
  }
@@ -40,6 +40,8 @@ export class Remote extends RemoteCore {
40
40
  socket.on("ping", this.receiveMonitor.bind(this));
41
41
  socket.on("error", (e) => { console.log('Websocket error', e, e.code) });
42
42
  socket.onclose = (e) => {
43
+ // Clean up all listeners on the socket to prevent leaks
44
+ socket.removeAllListeners();
43
45
  this.manager.removeRemote(this);
44
46
  };
45
47
  } else { // TCP else
@@ -59,6 +61,9 @@ export class Remote extends RemoteCore {
59
61
 
60
62
  socket.on('error', e => { console.log('TCP Socket error', e) })
61
63
  socket.on('close', e => {
64
+ // Clean up listeners on both the socket and the parser
65
+ socket.removeAllListeners();
66
+ this.congRx.removeAllListeners();
62
67
  this.manager.removeRemote(this);
63
68
  })
64
69
 
@@ -11,6 +11,8 @@ export class Server extends EventEmitter {
11
11
  super();
12
12
  this.apiNames = new Set()
13
13
  this.wss = {};
14
+ this.port = null;
15
+ this.congPort = null;
14
16
 
15
17
  if (options.timeout) {
16
18
  let pingT = parseInt(options.timeout)
@@ -31,38 +33,44 @@ export class Server extends EventEmitter {
31
33
  serverOption.showMetric = options.showMetric
32
34
  }
33
35
 
34
- if (options.timeout) {
35
- serverOption.timeout = options.timeout
36
- }
37
-
38
- if (options.port) {
39
- serverOption.port = parseInt(options.port)
36
+ if (options.port || options.port == 0) {
37
+ this.port = parseInt(options.port)
40
38
  }
41
39
 
42
40
  if (options.httpServer) {
43
- serverOption.httpServer = options.httpServer
41
+ this.httpServer = options.httpServer
44
42
  }
45
43
 
46
- if (options.congPort) {
47
- serverOption.congPort = parseInt(options.congPort)
44
+ if (options.congPort || options.congPort == 0) {
45
+ this.congPort = parseInt(options.congPort)
48
46
  }
49
47
 
50
48
  this.manager = new Manager(this, authManager)
51
49
 
52
- if (serverOption.port || serverOption.httpServer) this.startWSServer(serverOption)
53
- if (serverOption.congPort) this.startCongServer(serverOption.congPort)
50
+ this.serverCountToListen = 0;
51
+ this.listeningServerCount = 0;
52
+ if (this.port || this.port == 0 || this.httpServer) this.serverCountToListen++;
53
+ if (this.congPort || this.congPort == 0) this.serverCountToListen++;
54
+
55
+ if (this.serverCountToListen === 0) {
56
+ process.nextTick(() => this.emit('ready'));
57
+ } else {
58
+ if (this.port || this.port == 0 || this.httpServer) this.startWSServer();
59
+ if (this.congPort || this.congPort == 0) this.startCongServer();
60
+ }
54
61
 
55
62
  }
56
63
 
57
64
 
58
- startWSServer(serverOption) {
65
+ startWSServer() {
59
66
 
60
- if (serverOption.port) {
61
- console.log('opening WebSocket Server port:', serverOption.port)
62
- this.wss = new WebSocketServer({ port: serverOption.port })
63
- } else if (serverOption.httpServer) {
67
+ // console.log('optoins', options )
68
+ if (this.port || this.port == 0) {
69
+ console.log('opening WebSocket Server port:', this.port)
70
+ this.wss = new WebSocketServer({ port: this.port })
71
+ } else if (this.httpServer) {
64
72
  console.log('opening WebSocket Server external httpServer:')
65
- this.wss = new WebSocketServer({ server: serverOption.httpServer })
73
+ this.wss = new WebSocketServer({ server: this.httpServer })
66
74
  } else {
67
75
  throw new TypeError(
68
76
  'One and only one of the "port", "httpServer"' +
@@ -71,6 +79,15 @@ export class Server extends EventEmitter {
71
79
  }
72
80
 
73
81
 
82
+ this.wss.once('listening', () => {
83
+ this.port = this.wss.address().port;
84
+ console.log('wss server bound port:', this.port );
85
+ this.listeningServerCount++;
86
+ if (this.listeningServerCount === this.serverCountToListen) {
87
+ this.emit('ready');
88
+ }
89
+ });
90
+
74
91
  // this.wss.setMaxListeners(0)
75
92
 
76
93
  this.wss.on('error', (err) => {
@@ -92,8 +109,8 @@ export class Server extends EventEmitter {
92
109
 
93
110
  }
94
111
 
95
- startCongServer(congPort) {
96
- console.log('opening CongSocket Server:', congPort)
112
+ startCongServer() {
113
+ console.log('opening CongSocket Server port:', this.congPort)
97
114
 
98
115
  this.congServer = net.createServer((socket) => {
99
116
  this.manager.addRemote(socket)
@@ -103,8 +120,15 @@ export class Server extends EventEmitter {
103
120
  if (err.code == 'EADDRINUSE') {
104
121
  process.exit()
105
122
  }
106
- }).listen(congPort, () => {
107
- // console.log('congsocket server bound' );
123
+ }).on('close', () => {
124
+ console.log('### cong server closed.')
125
+ }).listen(this.congPort, () => {
126
+ this.congPort = this.congServer.address().port;
127
+ console.log('congsocket server bound port:', this.congPort );
128
+ this.listeningServerCount++;
129
+ if (this.listeningServerCount === this.serverCountToListen) {
130
+ this.emit('ready');
131
+ }
108
132
  });
109
133
  }
110
134
 
@@ -160,4 +184,44 @@ export class Server extends EventEmitter {
160
184
  return this
161
185
  }
162
186
 
187
+ close(callback) {
188
+ console.log('closing io-signal server...')
189
+ if (this.manager) {
190
+ this.manager.close()
191
+ }
192
+
193
+ let serverCount = 0;
194
+ if (this.wss) serverCount++;
195
+ if (this.congServer) serverCount++;
196
+
197
+ if (serverCount === 0) {
198
+ if (callback) process.nextTick(callback);
199
+ return;
200
+ }
201
+
202
+ let closedCount = 0;
203
+ const onClosed = () => {
204
+ closedCount++;
205
+ if (closedCount === serverCount) {
206
+ console.log('io-signal server closed.')
207
+ if (callback) callback();
208
+ }
209
+ }
210
+
211
+ if (this.wss) {
212
+ this.wss.close(() => {
213
+ console.log('wss server closed.')
214
+ onClosed()
215
+ })
216
+ }
217
+
218
+ if (this.congServer) {
219
+ this.congServer.close((err) => {
220
+ if (err) console.error('congServer close error', err)
221
+ console.log('cong server closed.')
222
+ onClosed()
223
+ })
224
+ }
225
+ }
226
+
163
227
  }
@@ -2,9 +2,9 @@
2
2
 
3
3
  export let serverOption = {
4
4
  clientTracking: false,
5
- port: 0, //wsPort
5
+ port: null, // WebSocket
6
+ congPort: null, // CongSocket
6
7
  httpServer: null,
7
- congPort: 0,
8
8
  timeout: 50000,
9
9
  showMessage: 'none',
10
10
  showMetric: 0,
@@ -0,0 +1,19 @@
1
+
2
+ import { IO } from "iosignal"
3
+
4
+ const io = new IO('wss://io.iosignal.net/ws')
5
+
6
+ // io.auth('id','key')
7
+
8
+ io.on('ready', () => {
9
+ console.log('ready cid:', io.cid)
10
+ io.signal('#screen', 'playToggle')
11
+ });
12
+
13
+ io.listen('#notify', (...args) => {
14
+ console.log(args)
15
+ })
16
+
17
+ io.on('error', err => {
18
+ console.log('err', err)
19
+ })