@tkey-mpc/core
Version:
TKey Core library
2 lines • 465 kB
JavaScript
/*! For license information please see core.umd.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Core=t():e.Core=t()}(self,(()=>(()=>{var e={7619:(e,t)=>{var r;function n(e,t){navigator.onLine||e("offline"),e("error",t)}function i(e,t,r){navigator.serviceWorker.register(e,r).then((function(e){t("registered",e),e.waiting?t("updated",e):e.onupdatefound=function(){t("updatefound",e);var r=e.installing;r.onstatechange=function(){"installed"===r.state&&(navigator.serviceWorker.controller?t("updated",e):t("cached",e))}}})).catch((function(e){return n(t,e)}))}"undefined"!=typeof window&&(r="undefined"==typeof document||"interactive"!==document.readyState&&"complete"!==document.readyState?"undefined"!=typeof Promise?new Promise((function(e){return window.addEventListener("load",e)})):{then:function(e){return window.addEventListener("load",e)}}:Promise.resolve()),t.k=function(e,t){void 0===t&&(t={});var s=t.registrationOptions;void 0===s&&(s={}),delete t.registrationOptions;var o=function(e){for(var r=[],n=arguments.length-1;n-- >0;)r[n]=arguments[n+1];t&&t[e]&&t[e].apply(t,r)};"serviceWorker"in navigator&&r.then((function(){Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/))?(function(e,t,r){fetch(e).then((function(n){404===n.status?(t("error",new Error("Service worker not found at "+e)),unregister()):-1===n.headers.get("content-type").indexOf("javascript")?(t("error",new Error("Expected "+e+" to have javascript content-type, but received "+n.headers.get("content-type"))),unregister()):i(e,t,r)})).catch((function(e){return n(t,e)}))}(e,o,s),navigator.serviceWorker.ready.then((function(e){o("ready",e)})).catch((function(e){return n(o,e)}))):(i(e,o,s),navigator.serviceWorker.ready.then((function(e){o("ready",e)})).catch((function(e){return n(o,e)})))}))}},3425:(e,t,r)=>{"use strict";r.d(t,{BroadcastChannel:()=>ar});var n={};r.r(n),r.d(n,{averageResponseTime:()=>x,canBeUsed:()=>A,close:()=>w,create:()=>v,microSeconds:()=>y,onMessage:()=>_,postMessage:()=>S,type:()=>g});var i={};r.r(i),r.d(i,{TRANSACTION_SETTINGS:()=>T,averageResponseTime:()=>W,canBeUsed:()=>Y,cleanOldMessages:()=>j,close:()=>H,commitIndexedDBTransaction:()=>L,create:()=>q,createDatabase:()=>C,getAllMessages:()=>F,getIdb:()=>N,getMessagesHigherThan:()=>K,getOldMessages:()=>U,microSeconds:()=>k,onMessage:()=>G,postMessage:()=>J,removeMessagesById:()=>D,type:()=>R,writeMessage:()=>B});var s={};r.r(s),r.d(s,{addStorageEventListener:()=>re,averageResponseTime:()=>ce,canBeUsed:()=>ae,close:()=>se,create:()=>ie,getLocalStorage:()=>Q,microSeconds:()=>V,onMessage:()=>oe,postMessage:()=>te,removeStorageEventListener:()=>ne,storageKey:()=>ee,type:()=>Z});var o={};r.r(o),r.d(o,{Decoder:()=>wt,Encoder:()=>gt,PacketType:()=>yt,protocol:()=>bt});var a={};r.r(a),r.d(a,{averageResponseTime:()=>Gt,canBeUsed:()=>Jt,close:()=>zt,create:()=>$t,getSocketInstance:()=>Ut,microSeconds:()=>Nt,onMessage:()=>Ht,postMessage:()=>Dt,removeStorageEventListener:()=>qt,setupSocketConnection:()=>jt,storageKey:()=>Kt,type:()=>Ct});var c={};r.r(c),r.d(c,{SIMULATE_DELAY_TIME:()=>Xt,averageResponseTime:()=>nr,canBeUsed:()=>rr,close:()=>Qt,create:()=>Zt,microSeconds:()=>Yt,onMessage:()=>tr,postMessage:()=>er,type:()=>Wt});var d=r(5880),h=r.n(d);Promise.resolve(!1),Promise.resolve(!0);const f=Promise.resolve();function u(e,t){return e||(e=0),new Promise((r=>setTimeout((()=>r(t)),e)))}function l(){return Math.random().toString(36).substring(2)}let p=0;function m(){let e=1e3*Date.now();return e<=p&&(e=p+1),p=e,e}const b=h().getLogger("broadcast-channel");b.setLevel("error");const y=m,g="native";function v(e){const t={time:m(),messagesCallback:null,bc:new BroadcastChannel(e),subFns:[]};return t.bc.onmessage=e=>{t.messagesCallback&&t.messagesCallback(e.data)},t}function w(e){e.bc.close(),e.subFns=[]}function S(e,t){try{return e.bc.postMessage(t,!1),f}catch(e){return Promise.reject(e)}}function _(e,t){e.messagesCallback=t}function A(){if("undefined"==typeof window)return!1;if("function"==typeof BroadcastChannel){if(BroadcastChannel._pubkey)throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");return!0}return!1}function x(){return 150}class P{ttl;map=new Map;_to=!1;constructor(e){this.ttl=e}has(e){return this.map.has(e)}add(e){this.map.set(e,E()),this._to||(this._to=!0,setTimeout((()=>{this._to=!1,function(e){const t=E()-e.ttl,r=e.map[Symbol.iterator]();for(;;){const n=r.next().value;if(!n)return;const i=n[0];if(!(n[1]<t))return;e.map.delete(i)}}(this)}),0))}clear(){this.map.clear()}}function E(){return Date.now()}function M(e={}){const t=JSON.parse(JSON.stringify(e));return void 0===t.webWorkerSupport&&(t.webWorkerSupport=!0),t.idb||(t.idb={}),t.idb.ttl||(t.idb.ttl=45e3),t.idb.fallbackInterval||(t.idb.fallbackInterval=150),e.idb&&"function"==typeof e.idb.onclose&&(t.idb.onclose=e.idb.onclose),t.localstorage||(t.localstorage={}),t.localstorage.removeTimeout||(t.localstorage.removeTimeout=6e4),t.server||(t.server={}),t.server.url||(t.server.url="https://session.web3auth.io"),t.server.removeTimeout||(t.server.removeTimeout=3e5),e.methods&&(t.methods=e.methods),t}const k=m,I="pubkey.broadcast-channel-0-",O="messages",T={durability:"relaxed"},R="idb";function N(){if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof window){if(void 0!==window.mozIndexedDB)return window.mozIndexedDB;if(void 0!==window.webkitIndexedDB)return window.webkitIndexedDB;if(void 0!==window.msIndexedDB)return window.msIndexedDB}return!1}function L(e){e.commit&&e.commit()}function C(e){const t=N(),r=I+e,n=t.open(r);return n.onupgradeneeded=e=>{e.target.result.createObjectStore(O,{keyPath:"id",autoIncrement:!0})},new Promise(((e,t)=>{n.onerror=e=>t(e),n.onsuccess=()=>{e(n.result)}}))}function B(e,t,r){const n={uuid:t,time:Date.now(),data:r},i=e.transaction([O],"readwrite",T);return new Promise(((e,t)=>{i.oncomplete=()=>e(),i.onerror=e=>t(e),i.objectStore(O).add(n),L(i)}))}function F(e){const t=e.transaction(O,"readonly",T),r=t.objectStore(O),n=[];return new Promise((e=>{r.openCursor().onsuccess=r=>{const i=r.target.result;i?(n.push(i.value),i.continue()):(L(t),e(n))}}))}function K(e,t){const r=e.transaction(O,"readonly",T),n=r.objectStore(O),i=[];let s=IDBKeyRange.bound(t+1,1/0);if(n.getAll){const e=n.getAll(s);return new Promise(((t,r)=>{e.onerror=e=>r(e),e.onsuccess=function(e){t(e.target.result)}}))}return new Promise(((e,o)=>{const a=function(){try{return s=IDBKeyRange.bound(t+1,1/0),n.openCursor(s)}catch(e){return n.openCursor()}}();a.onerror=e=>o(e),a.onsuccess=n=>{const s=n.target.result;s?s.value.id<t+1?s.continue(t+1):(i.push(s.value),s.continue()):(L(r),e(i))}}))}function D(e,t){const r=e.transaction([O],"readwrite",T).objectStore(O);return Promise.all(t.map((e=>{const t=r.delete(e);return new Promise((e=>{t.onsuccess=()=>e()}))})))}function U(e,t){const r=Date.now()-t,n=e.transaction(O,"readonly",T),i=n.objectStore(O),s=[];return new Promise((e=>{i.openCursor().onsuccess=t=>{const i=t.target.result;if(i){const t=i.value;if(!(t.time<r))return L(n),void e(s);s.push(t),i.continue()}else e(s)}}))}function j(e,t){return U(e,t).then((t=>D(e,t.map((e=>e.id)))))}function q(e,t){return t=M(t),C(e).then((r=>{const n={closed:!1,lastCursorId:0,channelName:e,options:t,uuid:l(),eMIs:new P(2*t.idb.ttl),writeBlockPromise:f,messagesCallback:null,readQueuePromises:[],db:r,time:m()};return r.onclose=function(){n.closed=!0,t.idb.onclose&&t.idb.onclose()},$(n),n}))}function $(e){e.closed||z(e).then((()=>u(e.options.idb.fallbackInterval))).then((()=>$(e)))}function z(e){return e.closed?f:e.messagesCallback?K(e.db,e.lastCursorId).then((t=>{const r=t.filter((e=>!!e)).map((t=>(t.id>e.lastCursorId&&(e.lastCursorId=t.id),t))).filter((t=>function(e,t){return!(e.uuid===t.uuid||t.eMIs.has(e.id)||e.data.time<t.messagesCallbackTime)}(t,e))).sort(((e,t)=>e.time-t.time));return r.forEach((t=>{e.messagesCallback&&(e.eMIs.add(t.id),e.messagesCallback(t.data))})),f})):f}function H(e){e.closed=!0,e.db.close()}function J(e,t){return e.writeBlockPromise=e.writeBlockPromise.then((()=>B(e.db,e.uuid,t))).then((()=>{0===Math.floor(11*Math.random()+0)&&j(e.db,e.options.idb.ttl)})),e.writeBlockPromise}function G(e,t,r){e.messagesCallbackTime=r,e.messagesCallback=t,z(e)}function Y(){return!!N()}function W(e){return 2*e.idb.fallbackInterval}const V=m,X="pubkey.broadcastChannel-",Z="localstorage";function Q(){let e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function ee(e){return X+e}function te(e,t){return new Promise((r=>{u().then((()=>{const n=ee(e.channelName),i={token:l(),time:Date.now(),data:t,uuid:e.uuid},s=JSON.stringify(i);Q().setItem(n,s);const o=document.createEvent("Event");o.initEvent("storage",!0,!0),o.key=n,o.newValue=s,window.dispatchEvent(o),r()}))}))}function re(e,t){const r=ee(e),n=e=>{e.key===r&&t(JSON.parse(e.newValue))};return window.addEventListener("storage",n),n}function ne(e){window.removeEventListener("storage",e)}function ie(e,t){if(t=M(t),!ae())throw new Error("BroadcastChannel: localstorage cannot be used");const r=l(),n=new P(t.localstorage.removeTimeout),i={channelName:e,uuid:r,time:m(),eMIs:n};return i.listener=re(e,(e=>{i.messagesCallback&&e.uuid!==r&&e.token&&!n.has(e.token)&&(e.data.time&&e.data.time<i.messagesCallbackTime||(n.add(e.token),i.messagesCallback(e.data)))})),i}function se(e){ne(e.listener)}function oe(e,t,r){e.messagesCallbackTime=r,e.messagesCallback=t}function ae(){const e=Q();if(!e)return!1;try{const t="__broadcastchannel_check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}function ce(){const e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120}const de=Object.create(null);de.open="0",de.close="1",de.ping="2",de.pong="3",de.message="4",de.upgrade="5",de.noop="6";const he=Object.create(null);Object.keys(de).forEach((e=>{he[de[e]]=e}));const fe={type:"error",data:"parser error"},ue="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),le="function"==typeof ArrayBuffer,pe=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,me=({type:e,data:t},r,n)=>ue&&t instanceof Blob?r?n(t):be(t,n):le&&(t instanceof ArrayBuffer||pe(t))?r?n(t):be(new Blob([t]),n):n(de[e]+(t||"")),be=(e,t)=>{const r=new FileReader;return r.onload=function(){const e=r.result.split(",")[1];t("b"+(e||""))},r.readAsDataURL(e)};function ye(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let ge;const ve="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let e=0;e<64;e++)ve["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(e)]=e;const we="function"==typeof ArrayBuffer,Se=(e,t)=>{if("string"!=typeof e)return{type:"message",data:Ae(e,t)};const r=e.charAt(0);return"b"===r?{type:"message",data:_e(e.substring(1),t)}:he[r]?e.length>1?{type:he[r],data:e.substring(1)}:{type:he[r]}:fe},_e=(e,t)=>{if(we){const r=(e=>{let t,r,n,i,s,o=.75*e.length,a=e.length,c=0;"="===e[e.length-1]&&(o--,"="===e[e.length-2]&&o--);const d=new ArrayBuffer(o),h=new Uint8Array(d);for(t=0;t<a;t+=4)r=ve[e.charCodeAt(t)],n=ve[e.charCodeAt(t+1)],i=ve[e.charCodeAt(t+2)],s=ve[e.charCodeAt(t+3)],h[c++]=r<<2|n>>4,h[c++]=(15&n)<<4|i>>2,h[c++]=(3&i)<<6|63&s;return d})(e);return Ae(r,t)}return{base64:!0,data:e}},Ae=(e,t)=>"blob"===t?e instanceof Blob?e:new Blob([e]):e instanceof ArrayBuffer?e:e.buffer,xe=String.fromCharCode(30);let Pe;function Ee(e){return e.reduce(((e,t)=>e+t.length),0)}function Me(e,t){if(e[0].length===t)return e.shift();const r=new Uint8Array(t);let n=0;for(let i=0;i<t;i++)r[i]=e[0][n++],n===e[0].length&&(e.shift(),n=0);return e.length&&n<e[0].length&&(e[0]=e[0].slice(n)),r}function ke(e){if(e)return function(e){for(var t in ke.prototype)e[t]=ke.prototype[t];return e}(e)}ke.prototype.on=ke.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},ke.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this},ke.prototype.off=ke.prototype.removeListener=ke.prototype.removeAllListeners=ke.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r,n=this._callbacks["$"+e];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<n.length;i++)if((r=n[i])===t||r.fn===t){n.splice(i,1);break}return 0===n.length&&delete this._callbacks["$"+e],this},ke.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),r=this._callbacks["$"+e],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(r){n=0;for(var i=(r=r.slice(0)).length;n<i;++n)r[n].apply(this,t)}return this},ke.prototype.emitReserved=ke.prototype.emit,ke.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},ke.prototype.hasListeners=function(e){return!!this.listeners(e).length};const Ie="function"==typeof Promise&&"function"==typeof Promise.resolve?e=>Promise.resolve().then(e):(e,t)=>t(e,0),Oe="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function Te(e,...t){return t.reduce(((t,r)=>(e.hasOwnProperty(r)&&(t[r]=e[r]),t)),{})}const Re=Oe.setTimeout,Ne=Oe.clearTimeout;function Le(e,t){t.useNativeTimers?(e.setTimeoutFn=Re.bind(Oe),e.clearTimeoutFn=Ne.bind(Oe)):(e.setTimeoutFn=Oe.setTimeout.bind(Oe),e.clearTimeoutFn=Oe.clearTimeout.bind(Oe))}function Ce(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class Be extends Error{constructor(e,t,r){super(e),this.description=t,this.context=r,this.type="TransportError"}}class Fe extends ke{constructor(e){super(),this.writable=!1,Le(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,r){return super.emitReserved("error",new Be(e,t,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(e){"open"===this.readyState&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=Se(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){const e=this.opts.hostname;return-1===e.indexOf(":")?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(e){const t=function(e){let t="";for(let r in e)e.hasOwnProperty(r)&&(t.length&&(t+="&"),t+=encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return t}(e);return t.length?"?"+t:""}}class Ke extends Fe{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(e){this.readyState="pausing";const t=()=>{this.readyState="paused",e()};if(this._polling||!this.writable){let e=0;this._polling&&(e++,this.once("pollComplete",(function(){--e||t()}))),this.writable||(e++,this.once("drain",(function(){--e||t()})))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){((e,t)=>{const r=e.split(xe),n=[];for(let e=0;e<r.length;e++){const i=Se(r[e],t);if(n.push(i),"error"===i.type)break}return n})(e,this.socket.binaryType).forEach((e=>{if("opening"===this.readyState&&"open"===e.type&&this.onOpen(),"close"===e.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(e)})),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const e=()=>{this.write([{type:"close"}])};"open"===this.readyState?e():this.once("open",e)}write(e){this.writable=!1,((e,t)=>{const r=e.length,n=new Array(r);let i=0;e.forEach(((e,s)=>{me(e,!1,(e=>{n[s]=e,++i===r&&t(n.join(xe))}))}))})(e,(e=>{this.doWrite(e,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=Ce()),this.supportsBinary||t.sid||(t.b64=1),this.createUri(e,t)}}let De=!1;try{De="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(e){}const Ue=De;function je(){}class qe extends Ke{constructor(e){if(super(e),"undefined"!=typeof location){const t="https:"===location.protocol;let r=location.port;r||(r=t?"443":"80"),this.xd="undefined"!=typeof location&&e.hostname!==location.hostname||r!==e.port}}doWrite(e,t){const r=this.request({method:"POST",data:e});r.on("success",t),r.on("error",((e,t)=>{this.onError("xhr post error",e,t)}))}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",((e,t)=>{this.onError("xhr poll error",e,t)})),this.pollXhr=e}}class $e extends ke{constructor(e,t,r){super(),this.createRequest=e,Le(this,r),this._opts=r,this._method=r.method||"GET",this._uri=t,this._data=void 0!==r.data?r.data:null,this._create()}_create(){var e;const t=Te(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;const r=this._xhr=this.createRequest(t);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let e in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(e)&&r.setRequestHeader(e,this._opts.extraHeaders[e])}}catch(e){}if("POST"===this._method)try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{r.setRequestHeader("Accept","*/*")}catch(e){}null===(e=this._opts.cookieJar)||void 0===e||e.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var e;3===r.readyState&&(null===(e=this._opts.cookieJar)||void 0===e||e.parseCookies(r.getResponseHeader("set-cookie"))),4===r.readyState&&(200===r.status||1223===r.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof r.status?r.status:0)}),0))},r.send(this._data)}catch(e){return void this.setTimeoutFn((()=>{this._onError(e)}),0)}"undefined"!=typeof document&&(this._index=$e.requestsCount++,$e.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(void 0!==this._xhr&&null!==this._xhr){if(this._xhr.onreadystatechange=je,e)try{this._xhr.abort()}catch(e){}"undefined"!=typeof document&&delete $e.requests[this._index],this._xhr=null}}_onLoad(){const e=this._xhr.responseText;null!==e&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}function ze(){for(let e in $e.requests)$e.requests.hasOwnProperty(e)&&$e.requests[e].abort()}$e.requestsCount=0,$e.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",ze):"function"==typeof addEventListener&&addEventListener("onpagehide"in Oe?"pagehide":"unload",ze,!1));const He=function(){const e=Je({xdomain:!1});return e&&null!==e.responseType}();function Je(e){const t=e.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!t||Ue))return new XMLHttpRequest}catch(e){}if(!t)try{return new(Oe[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}}const Ge="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class Ye extends Fe{get name(){return"websocket"}doOpen(){const e=this.uri(),t=this.opts.protocols,r=Ge?{}:Te(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,r)}catch(e){return this.emitReserved("error",e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const r=e[t],n=t===e.length-1;me(r,this.supportsBinary,(e=>{try{this.doWrite(r,e)}catch(e){}n&&Ie((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=Ce()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}}const We=Oe.WebSocket||Oe.MozWebSocket,Ve={websocket:class extends Ye{createSocket(e,t,r){return Ge?new We(e,t,r):t?new We(e,t):new We(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends Fe{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}this._transport.closed.then((()=>{this.onClose()})).catch((e=>{this.onError("webtransport error",e)})),this._transport.ready.then((()=>{this._transport.createBidirectionalStream().then((e=>{const t=function(e,t){Pe||(Pe=new TextDecoder);const r=[];let n=0,i=-1,s=!1;return new TransformStream({transform(o,a){for(r.push(o);;){if(0===n){if(Ee(r)<1)break;const e=Me(r,1);s=!(128&~e[0]),i=127&e[0],n=i<126?3:126===i?1:2}else if(1===n){if(Ee(r)<2)break;const e=Me(r,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),n=3}else if(2===n){if(Ee(r)<8)break;const e=Me(r,8),t=new DataView(e.buffer,e.byteOffset,e.length),s=t.getUint32(0);if(s>Math.pow(2,21)-1){a.enqueue(fe);break}i=s*Math.pow(2,32)+t.getUint32(4),n=3}else{if(Ee(r)<i)break;const e=Me(r,i);a.enqueue(Se(s?e:Pe.decode(e),t)),n=0}if(0===i||i>e){a.enqueue(fe);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=e.readable.pipeThrough(t).getReader(),n=new TransformStream({transform(e,t){!function(e,t){ue&&e.data instanceof Blob?e.data.arrayBuffer().then(ye).then(t):le&&(e.data instanceof ArrayBuffer||pe(e.data))?t(ye(e.data)):me(e,!1,(e=>{ge||(ge=new TextEncoder),t(ge.encode(e))}))}(e,(r=>{const n=r.length;let i;if(n<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,n);else if(n<65536){i=new Uint8Array(3);const e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,n)}else{i=new Uint8Array(9);const e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(n))}e.data&&"string"!=typeof e.data&&(i[0]|=128),t.enqueue(i),t.enqueue(r)}))}});n.readable.pipeTo(e.writable),this._writer=n.writable.getWriter();const i=()=>{r.read().then((({done:e,value:t})=>{e||(this.onPacket(t),i())})).catch((e=>{}))};i();const s={type:"open"};this.query.sid&&(s.data=`{"sid":"${this.query.sid}"}`),this._writer.write(s).then((()=>this.onOpen()))}))}))}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const r=e[t],n=t===e.length-1;this._writer.write(r).then((()=>{n&&Ie((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var e;null===(e=this._transport)||void 0===e||e.close()}},polling:class extends qe{constructor(e){super(e);const t=e&&e.forceBase64;this.supportsBinary=He&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new $e(Je,this.uri(),e)}}},Xe=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Ze=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Qe(e){if(e.length>8e3)throw"URI too long";const t=e,r=e.indexOf("["),n=e.indexOf("]");-1!=r&&-1!=n&&(e=e.substring(0,r)+e.substring(r,n).replace(/:/g,";")+e.substring(n,e.length));let i=Xe.exec(e||""),s={},o=14;for(;o--;)s[Ze[o]]=i[o]||"";return-1!=r&&-1!=n&&(s.source=t,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=function(e,t){const r=t.replace(/\/{2,9}/g,"/").split("/");return"/"!=t.slice(0,1)&&0!==t.length||r.splice(0,1),"/"==t.slice(-1)&&r.splice(r.length-1,1),r}(0,s.path),s.queryKey=function(e,t){const r={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(e,t,n){t&&(r[t]=n)})),r}(0,s.query),s}const et="function"==typeof addEventListener&&"function"==typeof removeEventListener,tt=[];et&&addEventListener("offline",(()=>{tt.forEach((e=>e()))}),!1);class rt extends ke{constructor(e,t){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&"object"==typeof e&&(t=e,e=null),e){const r=Qe(e);t.hostname=r.host,t.secure="https"===r.protocol||"wss"===r.protocol,t.port=r.port,r.query&&(t.query=r.query)}else t.host&&(t.hostname=Qe(t.host).host);Le(this,t),this.secure=null!=t.secure?t.secure:"undefined"!=typeof location&&"https:"===location.protocol,t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=t.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},t.transports.forEach((e=>{const t=e.prototype.name;this.transports.push(t),this._transportsByName[t]=e})),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(e){let t={},r=e.split("&");for(let e=0,n=r.length;e<n;e++){let n=r[e].split("=");t[decodeURIComponent(n[0])]=decodeURIComponent(n[1])}return t}(this.opts.query)),et&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},tt.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);const r=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](r)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const e=this.opts.rememberUpgrade&&rt.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const t=this.createTransport(e);t.open(),this.setTransport(t)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",(e=>this._onClose("transport close",e)))}onOpen(){this.readyState="open",rt.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const t=new Error("server error");t.code=e.data,this._onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data)}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),e),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this._getWritablePackets();this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let e=1;for(let r=0;r<this.writeBuffer.length;r++){const n=this.writeBuffer[r].data;if(n&&(e+="string"==typeof(t=n)?function(e){let t=0,r=0;for(let n=0,i=e.length;n<i;n++)t=e.charCodeAt(n),t<128?r+=1:t<2048?r+=2:t<55296||t>=57344?r+=3:(n++,r+=4);return r}(t):Math.ceil(1.33*(t.byteLength||t.size))),r>0&&e>this._maxPayload)return this.writeBuffer.slice(0,r);e+=2}var t;return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,Ie((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),e}write(e,t,r){return this._sendPacket("message",e,t,r),this}send(e,t,r){return this._sendPacket("message",e,t,r),this}_sendPacket(e,t,r,n){if("function"==typeof t&&(n=t,t=void 0),"function"==typeof r&&(n=r,r=null),"closing"===this.readyState||"closed"===this.readyState)return;(r=r||{}).compress=!1!==r.compress;const i={type:e,data:t,options:r};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),n&&this.once("flush",n),this.flush()}close(){const e=()=>{this._onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},r=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?r():e()})):this.upgrading?r():e()),this}_onError(e){if(rt.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),et&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const e=tt.indexOf(this._offlineEventListener);-1!==e&&tt.splice(e,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}}rt.protocol=4;class nt extends rt{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),r=!1;rt.priorWebsocketSuccess=!1;const n=()=>{r||(t.send([{type:"ping",data:"probe"}]),t.once("packet",(e=>{if(!r)if("pong"===e.type&&"probe"===e.data){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;rt.priorWebsocketSuccess="websocket"===t.name,this.transport.pause((()=>{r||"closed"!==this.readyState&&(d(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())}))}else{const e=new Error("probe error");e.transport=t.name,this.emitReserved("upgradeError",e)}})))};function i(){r||(r=!0,d(),t.close(),t=null)}const s=e=>{const r=new Error("probe error: "+e);r.transport=t.name,i(),this.emitReserved("upgradeError",r)};function o(){s("transport closed")}function a(){s("socket closed")}function c(e){t&&e.name!==t.name&&i()}const d=()=>{t.removeListener("open",n),t.removeListener("error",s),t.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};t.once("open",n),t.once("error",s),t.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==e?this.setTimeoutFn((()=>{r||t.open()}),200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){const t=[];for(let r=0;r<e.length;r++)~this.transports.indexOf(e[r])&&t.push(e[r]);return t}}class it extends nt{constructor(e,t={}){const r="object"==typeof e?e:t;(!r.transports||r.transports&&"string"==typeof r.transports[0])&&(r.transports=(r.transports||["polling","websocket","webtransport"]).map((e=>Ve[e])).filter((e=>!!e))),super(e,r)}}const st="function"==typeof ArrayBuffer,ot=Object.prototype.toString,at="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===ot.call(Blob),ct="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===ot.call(File);function dt(e){return st&&(e instanceof ArrayBuffer||(e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer)(e))||at&&e instanceof Blob||ct&&e instanceof File}function ht(e,t){if(!e||"object"!=typeof e)return!1;if(Array.isArray(e)){for(let t=0,r=e.length;t<r;t++)if(ht(e[t]))return!0;return!1}if(dt(e))return!0;if(e.toJSON&&"function"==typeof e.toJSON&&1===arguments.length)return ht(e.toJSON(),!0);for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&ht(e[t]))return!0;return!1}function ft(e){const t=[],r=e.data,n=e;return n.data=ut(r,t),n.attachments=t.length,{packet:n,buffers:t}}function ut(e,t){if(!e)return e;if(dt(e)){const r={_placeholder:!0,num:t.length};return t.push(e),r}if(Array.isArray(e)){const r=new Array(e.length);for(let n=0;n<e.length;n++)r[n]=ut(e[n],t);return r}if("object"==typeof e&&!(e instanceof Date)){const r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=ut(e[n],t));return r}return e}function lt(e,t){return e.data=pt(e.data,t),delete e.attachments,e}function pt(e,t){if(!e)return e;if(e&&!0===e._placeholder){if("number"==typeof e.num&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}if(Array.isArray(e))for(let r=0;r<e.length;r++)e[r]=pt(e[r],t);else if("object"==typeof e)for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(e[r]=pt(e[r],t));return e}const mt=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],bt=5;var yt;!function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"}(yt||(yt={}));class gt{constructor(e){this.replacer=e}encode(e){return e.type!==yt.EVENT&&e.type!==yt.ACK||!ht(e)?[this.encodeAsString(e)]:this.encodeAsBinary({type:e.type===yt.EVENT?yt.BINARY_EVENT:yt.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id})}encodeAsString(e){let t=""+e.type;return e.type!==yt.BINARY_EVENT&&e.type!==yt.BINARY_ACK||(t+=e.attachments+"-"),e.nsp&&"/"!==e.nsp&&(t+=e.nsp+","),null!=e.id&&(t+=e.id),null!=e.data&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){const t=ft(e),r=this.encodeAsString(t.packet),n=t.buffers;return n.unshift(r),n}}function vt(e){return"[object Object]"===Object.prototype.toString.call(e)}class wt extends ke{constructor(e){super(),this.reviver=e}add(e){let t;if("string"==typeof e){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);const r=t.type===yt.BINARY_EVENT;r||t.type===yt.BINARY_ACK?(t.type=r?yt.EVENT:yt.ACK,this.reconstructor=new St(t),0===t.attachments&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else{if(!dt(e)&&!e.base64)throw new Error("Unknown type: "+e);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t))}}decodeString(e){let t=0;const r={type:Number(e.charAt(0))};if(void 0===yt[r.type])throw new Error("unknown packet type "+r.type);if(r.type===yt.BINARY_EVENT||r.type===yt.BINARY_ACK){const n=t+1;for(;"-"!==e.charAt(++t)&&t!=e.length;);const i=e.substring(n,t);if(i!=Number(i)||"-"!==e.charAt(t))throw new Error("Illegal attachments");r.attachments=Number(i)}if("/"===e.charAt(t+1)){const n=t+1;for(;++t&&","!==e.charAt(t)&&t!==e.length;);r.nsp=e.substring(n,t)}else r.nsp="/";const n=e.charAt(t+1);if(""!==n&&Number(n)==n){const n=t+1;for(;++t;){const r=e.charAt(t);if(null==r||Number(r)!=r){--t;break}if(t===e.length)break}r.id=Number(e.substring(n,t+1))}if(e.charAt(++t)){const n=this.tryParse(e.substr(t));if(!wt.isPayloadValid(r.type,n))throw new Error("invalid payload");r.data=n}return r}tryParse(e){try{return JSON.parse(e,this.reviver)}catch(e){return!1}}static isPayloadValid(e,t){switch(e){case yt.CONNECT:return vt(t);case yt.DISCONNECT:return void 0===t;case yt.CONNECT_ERROR:return"string"==typeof t||vt(t);case yt.EVENT:case yt.BINARY_EVENT:return Array.isArray(t)&&("number"==typeof t[0]||"string"==typeof t[0]&&-1===mt.indexOf(t[0]));case yt.ACK:case yt.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class St{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const e=lt(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}function _t(e,t,r){return e.on(t,r),function(){e.off(t,r)}}const At=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class xt extends ke{constructor(e,t,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[_t(e,"open",this.onopen.bind(this)),_t(e,"packet",this.onpacket.bind(this)),_t(e,"error",this.onerror.bind(this)),_t(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){var r,n,i;if(At.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const s={type:yt.EVENT,data:t,options:{}};if(s.options.compress=!1!==this.flags.compress,"function"==typeof t[t.length-1]){const e=this.ids++,r=t.pop();this._registerAckCallback(e,r),s.id=e}const o=null===(n=null===(r=this.io.engine)||void 0===r?void 0:r.transport)||void 0===n?void 0:n.writable,a=this.connected&&!(null===(i=this.io.engine)||void 0===i?void 0:i._hasPingExpired());return this.flags.volatile&&!o||(a?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(e,t){var r;const n=null!==(r=this.flags.timeout)&&void 0!==r?r:this._opts.ackTimeout;if(void 0===n)return void(this.acks[e]=t);const i=this.io.setTimeoutFn((()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&this.sendBuffer.splice(t,1);t.call(this,new Error("operation has timed out"))}),n),s=(...e)=>{this.io.clearTimeoutFn(i),t.apply(this,e)};s.withError=!0,this.acks[e]=s}emitWithAck(e,...t){return new Promise(((r,n)=>{const i=(e,t)=>e?n(e):r(t);i.withError=!0,t.push(i),this.emit(e,...t)}))}_addToQueue(e){let t;"function"==typeof e[e.length-1]&&(t=e.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push(((e,...n)=>{if(r===this._queue[0])return null!==e?r.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(e)):(this._queue.shift(),t&&t(null,...n)),r.pending=!1,this._drainQueue()})),this._queue.push(r),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||0===this._queue.length)return;const t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){"function"==typeof this.auth?this.auth((e=>{this._sendConnectPacket(e)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:yt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach((e=>{if(!this.sendBuffer.some((t=>String(t.id)===e))){const t=this.acks[e];delete this.acks[e],t.withError&&t.call(this,new Error("socket has been disconnected"))}}))}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case yt.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case yt.EVENT:case yt.BINARY_EVENT:this.onevent(e);break;case yt.ACK:case yt.BINARY_ACK:this.onack(e);break;case yt.DISCONNECT:this.ondisconnect();break;case yt.CONNECT_ERROR:this.destroy();const t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t)}}onevent(e){const t=e.data||[];null!=e.id&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const r of t)r.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&"string"==typeof e[e.length-1]&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let r=!1;return function(...n){r||(r=!0,t.packet({type:yt.ACK,id:e,data:n}))}}onack(e){const t=this.acks[e.id];"function"==typeof t&&(delete this.acks[e.id],t.withError&&e.data.unshift(null),t.apply(this,e.data))}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((e=>this.emitEvent(e))),this.receiveBuffer=[],this.sendBuffer.forEach((e=>{this.notifyOutgoingListeners(e),this.packet(e)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((e=>e())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:yt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let r=0;r<t.length;r++)if(e===t[r])return t.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const t=this._anyOutgoingListeners;for(let r=0;r<t.length;r++)if(e===t[r])return t.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const t=this._anyOutgoingListeners.slice();for(const r of t)r.apply(this,e.data)}}}function Pt(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}Pt.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),r=Math.floor(t*this.jitter*e);e=1&Math.floor(10*t)?e+r:e-r}return 0|Math.min(e,this.max)},Pt.prototype.reset=function(){this.attempts=0},Pt.prototype.setMin=function(e){this.ms=e},Pt.prototype.setMax=function(e){this.max=e},Pt.prototype.setJitter=function(e){this.jitter=e};class Et extends ke{constructor(e,t){var r;super(),this.nsps={},this.subs=[],e&&"object"==typeof e&&(t=e,e=void 0),(t=t||{}).path=t.path||"/socket.io",this.opts=t,Le(this,t),this.reconnection(!1!==t.reconnection),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(r=t.randomizationFactor)&&void 0!==r?r:.5),this.backoff=new Pt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==t.timeout?2e4:t.timeout),this._readyState="closed",this.uri=e;const n=t.parser||o;this.encoder=new n.Encoder,this.decoder=new n.Decoder,this._autoConnect=!1!==t.autoConnect,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(e){return void 0===e?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return void 0===e?this._reconnectionDelay:(this._reconnectionDelay=e,null===(t=this.backoff)||void 0===t||t.setMin(e),this)}randomizationFactor(e){var t;return void 0===e?this._randomizationFactor:(this._randomizationFactor=e,null===(t=this.backoff)||void 0===t||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return void 0===e?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,null===(t=this.backoff)||void 0===t||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new it(this.uri,this.opts);const t=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const n=_t(t,"open",(function(){r.onopen(),e&&e()})),i=t=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",t),e?e(t):this.maybeReconnectOnOpen()},s=_t(t,"error",i);if(!1!==this._timeout){const e=this._timeout,r=this.setTimeoutFn((()=>{n(),i(new Error("timeout")),t.close()}),e);this.opts.autoUnref&&r.unref(),this.subs.push((()=>{this.clearTimeoutFn(r)}))}return this.subs.push(n),this.subs.push(s),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(_t(e,"ping",this.onping.bind(this)),_t(e,"data",this.ondata.bind(this)),_t(e,"error",this.onerror.bind(this)),_t(e,"close",this.onclose.bind(this)),_t(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose("parse error",e)}}ondecoded(e){Ie((()=>{this.emitReserved("packet",e)}),this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let r=this.nsps[e];return r?this._autoConnect&&!r.active&&r.connect():(r=new xt(this,e,t),this.nsps[e]=r),r}_destroy(e){const t=Object.keys(this.nsps);for(const e of t)if(this.nsps[e].active)return;this._close()}_packet(e){const t=this.encoder.encode(e);for(let r=0;r<t.length;r++)this.engine.write(t[r],e.options)}cleanup(){this.subs.forEach((e=>e())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(e,t){var r;this.cleanup(),null===(r=this.engine)||void 0===r||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn((()=>{e.skipReconnect||(this.emitReserved("