qumra-cli 1.1.23 → 1.1.24
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/build/cli.cjs +1 -1
- package/build/cli.cjs.map +1 -1
- package/package.json +1 -1
package/build/cli.cjs
CHANGED
|
@@ -380,7 +380,7 @@ const f$=y,m$=n$,g$=e=>null!==e&&"object"==typeof e&&!Array.isArray(e),y$=e=>"nu
|
|
|
380
380
|
* base64id v0.1.0
|
|
381
381
|
*/
|
|
382
382
|
!function(e){var t=x,n=function(){};n.prototype.getRandomBytes=function(e){var n=4096,r=this;if((e=e||12)>n)return t.randomBytes(e);var i=parseInt(n/e),s=parseInt(.85*i);if(!s)return t.randomBytes(e);if(null==this.bytesBufferIndex&&(this.bytesBufferIndex=-1),this.bytesBufferIndex==i&&(this.bytesBuffer=null,this.bytesBufferIndex=-1),(-1==this.bytesBufferIndex||this.bytesBufferIndex>s)&&(this.isGeneratingBytes||(this.isGeneratingBytes=!0,t.randomBytes(n,(function(e,t){r.bytesBuffer=t,r.bytesBufferIndex=0,r.isGeneratingBytes=!1}))),-1==this.bytesBufferIndex))return t.randomBytes(e);var o=this.bytesBuffer.slice(e*this.bytesBufferIndex,e*(this.bytesBufferIndex+1));return this.bytesBufferIndex++,o},n.prototype.generateId=function(){var e=Buffer.alloc(15);return e.writeInt32BE?(this.sequenceNumber=this.sequenceNumber+1|0,e.writeInt32BE(this.sequenceNumber,11),t.randomBytes?this.getRandomBytes(12).copy(e):[0,4,8].forEach((function(t){e.writeInt32BE(Math.random()*Math.pow(2,32)|0,t)})),e.toString("base64").replace(/\//g,"_").replace(/\+/g,"-")):Math.abs(Math.random()*Math.random()*Date.now()|0).toString()+Math.abs(Math.random()*Math.random()*Date.now()|0).toString()},e.exports=new n}(IG);var PG=IG.exports,NG={},jG={},FG={},BG={},MG={},UG={};Object.defineProperty(UG,"__esModule",{value:!0}),UG.ERROR_PACKET=UG.PACKET_TYPES_REVERSE=UG.PACKET_TYPES=void 0;const qG=Object.create(null);UG.PACKET_TYPES=qG,qG.open="0",qG.close="1",qG.ping="2",qG.pong="3",qG.message="4",qG.upgrade="5",qG.noop="6";const HG=Object.create(null);UG.PACKET_TYPES_REVERSE=HG,Object.keys(qG).forEach((e=>{HG[qG[e]]=e}));UG.ERROR_PACKET={type:"error",data:"parser error"},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.encodePacket=void 0,e.encodePacketToBinary=function(t,i){if(t.data instanceof ArrayBuffer||ArrayBuffer.isView(t.data))return i(n(t.data,!1));(0,e.encodePacket)(t,!0,(e=>{r||(r=new TextEncoder),i(r.encode(e))}))};const t=UG;e.encodePacket=({type:e,data:r},i,s)=>r instanceof ArrayBuffer||ArrayBuffer.isView(r)?s(i?r:"b"+n(r,!0).toString("base64")):s(t.PACKET_TYPES[e]+(r||""));const n=(e,t)=>Buffer.isBuffer(e)||e instanceof Uint8Array&&!t?e:e instanceof ArrayBuffer?Buffer.from(e):Buffer.from(e.buffer,e.byteOffset,e.byteLength);let r}(MG);var $G={};Object.defineProperty($G,"__esModule",{value:!0}),$G.decodePacket=void 0;const zG=UG;$G.decodePacket=(e,t)=>{if("string"!=typeof e)return{type:"message",data:WG(e,t)};const n=e.charAt(0);if("b"===n){const n=Buffer.from(e.substring(1),"base64");return{type:"message",data:WG(n,t)}}return zG.PACKET_TYPES_REVERSE[n]?e.length>1?{type:zG.PACKET_TYPES_REVERSE[n],data:e.substring(1)}:{type:zG.PACKET_TYPES_REVERSE[n]}:zG.ERROR_PACKET};const WG=(e,t)=>"arraybuffer"===t?e instanceof ArrayBuffer?e:Buffer.isBuffer(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e.buffer:Buffer.isBuffer(e)?e:Buffer.from(e);!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.decodePayload=e.decodePacket=e.encodePayload=e.encodePacket=e.protocol=void 0,e.createPacketEncoderStream=function(){return new TransformStream({transform(e,n){(0,t.encodePacketToBinary)(e,(t=>{const r=t.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);const e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&"string"!=typeof e.data&&(i[0]|=128),n.enqueue(i),n.enqueue(t)}))}})},e.createPacketDecoderStream=function(e,t){s||(s=new TextDecoder);const i=[];let c=0,l=-1,u=!1;return new TransformStream({transform(p,h){for(i.push(p);;){if(0===c){if(o(i)<1)break;const e=a(i,1);u=!(128&~e[0]),l=127&e[0],c=l<126?3:126===l?1:2}else if(1===c){if(o(i)<2)break;const e=a(i,2);l=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),c=3}else if(2===c){if(o(i)<8)break;const e=a(i,8),t=new DataView(e.buffer,e.byteOffset,e.length),n=t.getUint32(0);if(n>Math.pow(2,21)-1){h.enqueue(r.ERROR_PACKET);break}l=n*Math.pow(2,32)+t.getUint32(4),c=3}else{if(o(i)<l)break;const e=a(i,l);h.enqueue((0,n.decodePacket)(u?e:s.decode(e),t)),c=0}if(0===l||l>e){h.enqueue(r.ERROR_PACKET);break}}}})};const t=MG;Object.defineProperty(e,"encodePacket",{enumerable:!0,get:function(){return t.encodePacket}});const n=$G;Object.defineProperty(e,"decodePacket",{enumerable:!0,get:function(){return n.decodePacket}});const r=UG,i=String.fromCharCode(30);e.encodePayload=(e,n)=>{const r=e.length,s=new Array(r);let o=0;e.forEach(((e,a)=>{(0,t.encodePacket)(e,!1,(e=>{s[a]=e,++o===r&&n(s.join(i))}))}))};let s;function o(e){return e.reduce(((e,t)=>e+t.length),0)}function a(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}e.decodePayload=(e,t)=>{const r=e.split(i),s=[];for(let e=0;e<r.length;e++){const i=(0,n.decodePacket)(r[e],t);if(s.push(i),"error"===i.type)break}return s},e.protocol=4}(BG);var GG,VG,KG,YG={},ZG=String.fromCharCode;
|
|
383
|
-
/*! https://mths.be/utf8js v2.1.2 by @mathias */function QG(e){for(var t,n,r=[],i=0,s=e.length;i<s;)(t=e.charCodeAt(i++))>=55296&&t<=56319&&i<s?56320==(64512&(n=e.charCodeAt(i++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),i--):r.push(t);return r}function JG(e,t){if(e>=55296&&e<=57343){if(t)throw Error("Lone surrogate U+"+e.toString(16).toUpperCase()+" is not a scalar value");return!1}return!0}function XG(e,t){return ZG(e>>t&63|128)}function eV(e,t){if(!(4294967168&e))return ZG(e);var n="";return 4294965248&e?4294901760&e?4292870144&e||(n=ZG(e>>18&7|240),n+=XG(e,12),n+=XG(e,6)):(JG(e,t)||(e=65533),n=ZG(e>>12&15|224),n+=XG(e,6)):n=ZG(e>>6&31|192),n+=ZG(63&e|128)}function tV(){if(KG>=VG)throw Error("Invalid byte index");var e=255&GG[KG];if(KG++,128==(192&e))return 63&e;throw Error("Invalid continuation byte")}function nV(e){var t,n;if(KG>VG)throw Error("Invalid byte index");if(KG==VG)return!1;if(t=255&GG[KG],KG++,!(128&t))return t;if(192==(224&t)){if((n=(31&t)<<6|tV())>=128)return n;throw Error("Invalid continuation byte")}if(224==(240&t)){if((n=(15&t)<<12|tV()<<6|tV())>=2048)return JG(n,e)?n:65533;throw Error("Invalid continuation byte")}if(240==(248&t)&&(n=(7&t)<<18|tV()<<12|tV()<<6|tV())>=65536&&n<=1114111)return n;throw Error("Invalid UTF-8 detected")}var rV={version:"2.1.2",encode:function(e,t){for(var n=!1!==(t=t||{}).strict,r=QG(e),i=r.length,s=-1,o="";++s<i;)o+=eV(r[s],n);return o},decode:function(e,t){var n=!1!==(t=t||{}).strict;GG=QG(e),VG=GG.length,KG=0;for(var r,i=[];!1!==(r=nV(n));)i.push(r);return function(e){for(var t,n=e.length,r=-1,i="";++r<n;)(t=e[r])>65535&&(i+=ZG((t-=65536)>>>10&1023|55296),t=56320|1023&t),i+=ZG(t);return i}(i)}};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.decodePayloadAsBinary=e.encodePayloadAsBinary=e.decodePayload=e.encodePayload=e.decodeBase64Packet=e.decodePacket=e.encodeBase64Packet=e.encodePacket=e.packets=e.protocol=void 0;var t=rV;e.protocol=3;e.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6};var n=Object.keys(e.packets),r={type:"error",data:"parser error"};const i=Buffer.concat([]);function s(n,r,i,s){if("function"==typeof r&&(s=r,r=null),"function"==typeof i&&(s=i,i=null),Buffer.isBuffer(n.data))return o(n,r,s);if(n.data&&(n.data.buffer||n.data)instanceof ArrayBuffer)return o({type:n.type,data:d(n.data)},r,s);var a=e.packets[n.type];return void 0!==n.data&&(a+=i?t.encode(String(n.data),{strict:!1}):String(n.data)),s(""+a)}function o(t,n,r){if(!n)return a(t,r);var i=t.data,s=Buffer.allocUnsafe(1);return s[0]=e.packets[t.type],r(Buffer.concat([s,i]))}function a(t,n){var r=Buffer.isBuffer(t.data)?t.data:d(t.data),i="b"+e.packets[t.type];return n(i+=r.toString("base64"))}function c(e,i,s){if(void 0===e)return r;var o;if("string"==typeof e)return"b"===(o=e.charAt(0))?l(e.slice(1),i):s&&!1===(e=function(e){try{e=t.decode(e,{strict:!1})}catch(e){return!1}return e}(e))?r:Number(o)==o&&n[o]?e.length>1?{type:n[o],data:e.slice(1)}:{type:n[o]}:r;if("arraybuffer"===i){var a=new Uint8Array(e);return o=a[0],{type:n[o],data:a.buffer.slice(1)}}return e instanceof ArrayBuffer&&(e=d(e)),o=e[0],{type:n[o],data:e.slice(1)}}function l(e,t){var r=n[e.charAt(0)],i=Buffer.from(e.slice(1),"base64");if("arraybuffer"===t){for(var s=new Uint8Array(i.length),o=0;o<s.length;o++)s[o]=i[o];i=s.buffer}return{type:r,data:i}}function u(e,t,n){const r=new Array(e.length);let i=0;for(let s=0;s<e.length;s++)t(e[s],((t,o)=>{r[s]=o,++i===e.length&&n(null,r)}))}function p(e){for(var t="",n=0,r=e.length;n<r;n++)t+=String.fromCharCode(e[n]);return t}function h(e){for(var t=Buffer.allocUnsafe(e.length),n=0,r=e.length;n<r;n++)t.writeUInt8(e.charCodeAt(n),n);return t}function d(e){var t=e.byteLength||e.length,n=e.byteOffset||0;return Buffer.from(e.buffer||e,n,t)}function f(e,t){if(!e.length)return t(i);u(e,m,(function(e,n){return t(Buffer.concat(n))}))}function m(e,t){s(e,!0,!0,(function(e){var n,r=""+e.length;if("string"==typeof e){(n=Buffer.allocUnsafe(r.length+2))[0]=0;for(var i=0;i<r.length;i++)n[i+1]=parseInt(r[i],10);return n[n.length-1]=255,t(null,Buffer.concat([n,h(e)]))}for((n=Buffer.allocUnsafe(r.length+2))[0]=1,i=0;i<r.length;i++)n[i+1]=parseInt(r[i],10);n[n.length-1]=255,t(null,Buffer.concat([n,e]))}))}function g(e,t,n){"function"==typeof t&&(n=t,t=null);for(var i,s=e,o=[];s.length>0;){var a="",l=0===s[0];for(i=1;255!==s[i];i++){if(a.length>310)return n(r,0,1);a+=""+s[i]}s=s.slice(a.length+1);var u=parseInt(a,10),h=s.slice(1,u+1);l&&(h=p(h)),o.push(h),s=s.slice(u+1)}var d=o.length;for(i=0;i<d;i++){n(c(o[i],t,!0),i,d)}}e.encodePacket=s,e.encodeBase64Packet=a,e.decodePacket=c,e.decodeBase64Packet=l,e.encodePayload=function(e,t,n){if("function"==typeof t&&(n=t,t=null),t&&(e=>{for(const t of e)if(t.data instanceof ArrayBuffer||ArrayBuffer.isView(t.data))return!0;return!1})(e))return f(e,n);if(!e.length)return n("0:");u(e,(function(e,n){s(e,t,!1,(function(e){n(null,function(e){return e.length+":"+e}(e))}))}),(function(e,t){return n(t.join(""))}))},e.decodePayload=function(e,t,n){if("string"!=typeof e)return g(e,t,n);if("function"==typeof t&&(n=t,t=null),""===e)return n(r,0,1);for(var i,s,o,a="",l=0,u=e.length;l<u;l++){var p=e.charAt(l);if(":"===p){if(""===a||a!=(i=Number(a)))return n(r,0,1);if(a!=(s=e.slice(l+1,l+1+i)).length)return n(r,0,1);if(s.length){if(o=c(s,t,!1),r.type===o.type&&r.data===o.data)return n(r,0,1);if(!1===n(o,l+i,u))return}l+=i,a=""}else a+=p}return""!==a?n(r,0,1):void 0},e.encodePayloadAsBinary=f,e.decodePayloadAsBinary=g}(YG),Object.defineProperty(FG,"__esModule",{value:!0}),FG.Transport=void 0;const iV=p,sV=BG,oV=YG,aV=(0,ah.default)("engine:transport");function cV(){}let lV=class extends iV.EventEmitter{constructor(e){super(),this.writable=!1,this._readyState="open",this.discarded=!1,this.protocol="4"===e._query.EIO?4:3,this.parser=4===this.protocol?sV:oV,this.supportsBinary=!(e._query&&e._query.b64)}get readyState(){return this._readyState}set readyState(e){aV("readyState updated from %s to %s (%s)",this._readyState,e,this.name),this._readyState=e}discard(){this.discarded=!0}onRequest(e){aV("setting request"),this.req=e}close(e){"closed"!==this.readyState&&"closing"!==this.readyState&&(this.readyState="closing",this.doClose(e||cV))}onError(e,t){if(this.listeners("error").length){const n=new Error(e);n.type="TransportError",n.description=t,this.emit("error",n)}else aV("ignored transport error %s (%s)",e,t)}onPacket(e){this.emit("packet",e)}onData(e){this.onPacket(this.parser.decodePacket(e))}onClose(){this.readyState="closed",this.emit("close")}};FG.Transport=lV,Object.defineProperty(jG,"__esModule",{value:!0}),jG.Polling=void 0;const uV=FG,pV=T,hV=KM,dV=(0,ah.default)("engine:polling"),fV={gzip:pV.createGzip,deflate:pV.createDeflate};let mV=class extends uV.Transport{constructor(e){super(e),this.closeTimeout=3e4}get name(){return"polling"}get supportsFraming(){return!1}onRequest(e){const t=e.res;e.res=null,"GET"===e.method?this.onPollRequest(e,t):"POST"===e.method?this.onDataRequest(e,t):(t.writeHead(500),t.end())}onPollRequest(e,t){if(this.req)return dV("request overlap"),this.onError("overlap from client"),t.writeHead(400),void t.end();dV("setting request"),this.req=e,this.res=t;const n=()=>{this.onError("poll connection closed prematurely")};e.cleanup=()=>{e.removeListener("close",n),this.req=this.res=null},e.on("close",n),this.writable=!0,this.emit("drain"),this.writable&&this.shouldClose&&(dV("triggering empty send to append close packet"),this.send([{type:"noop"}]))}onDataRequest(e,t){if(this.dataReq)return this.onError("data request overlap from client"),t.writeHead(400),void t.end();const n="application/octet-stream"===e.headers["content-type"];if(n&&4===this.protocol)return this.onError("invalid content");this.dataReq=e,this.dataRes=t;let r=n?Buffer.concat([]):"";const i=()=>{e.removeListener("data",o),e.removeListener("end",a),e.removeListener("close",s),this.dataReq=this.dataRes=r=null},s=()=>{i(),this.onError("data request connection closed prematurely")},o=e=>{let s;n?(r=Buffer.concat([r,e]),s=r.length):(r+=e,s=Buffer.byteLength(r)),s>this.maxHttpBufferSize&&(t.writeHead(413).end(),i())},a=()=>{this.onData(r);t.writeHead(200,this.headers(e,{"Content-Type":"text/html","Content-Length":2})),t.end("ok"),i()};e.on("close",s),n||e.setEncoding("utf8"),e.on("data",o),e.on("end",a)}onData(e){dV('received "%s"',e);const t=e=>{if("close"===e.type)return dV("got xhr close packet"),this.onClose(),!1;this.onPacket(e)};3===this.protocol?this.parser.decodePayload(e,t):this.parser.decodePayload(e).forEach(t)}onClose(){this.writable&&this.send([{type:"noop"}]),super.onClose()}send(e){this.writable=!1,this.shouldClose&&(dV("appending close packet to payload"),e.push({type:"close"}),this.shouldClose(),this.shouldClose=null);const t=t=>{const n=e.some((e=>e.options&&e.options.compress));this.write(t,{compress:n})};3===this.protocol?this.parser.encodePayload(e,this.supportsBinary,t):this.parser.encodePayload(e,t)}write(e,t){dV('writing "%s"',e),this.doWrite(e,t,(()=>{this.req.cleanup()}))}doWrite(e,t,n){const r="string"==typeof e,i={"Content-Type":r?"text/plain; charset=UTF-8":"application/octet-stream"},s=e=>{i["Content-Length"]="string"==typeof e?Buffer.byteLength(e):e.length,this.res.writeHead(200,this.headers(this.req,i)),this.res.end(e),n()};if(!this.httpCompression||!t.compress)return void s(e);if((r?Buffer.byteLength(e):e.length)<this.httpCompression.threshold)return void s(e);const o=hV(this.req).encodings(["gzip","deflate"]);o?this.compress(e,o,((e,t)=>{if(e)return this.res.writeHead(500),this.res.end(),void n(e);i["Content-Encoding"]=o,s(t)})):s(e)}compress(e,t,n){dV("compressing");const r=[];let i=0;fV[t](this.httpCompression).on("error",n).on("data",(function(e){r.push(e),i+=e.length})).on("end",(function(){n(null,Buffer.concat(r,i))})).end(e)}doClose(e){let t;dV("closing"),this.dataReq&&(dV("aborting ongoing data request"),this.dataReq.destroy());const n=()=>{clearTimeout(t),e(),this.onClose()};this.writable?(dV("transport writable - closing right away"),this.send([{type:"close"}]),n()):this.discarded?(dV("transport discarded - closing right away"),n()):(dV("transport not writable - buffering orderly close"),this.shouldClose=n,t=setTimeout(n,this.closeTimeout))}headers(e,t){t=t||{};const n=e.headers["user-agent"];return n&&(~n.indexOf(";MSIE")||~n.indexOf("Trident/"))&&(t["X-XSS-Protection"]="0"),t["cache-control"]="no-store",this.emit("headers",t,e),t}};jG.Polling=mV;var gV={};Object.defineProperty(gV,"__esModule",{value:!0}),gV.JSONP=void 0;const yV=jG,vV=L,bV=/\\\\n/g,_V=/(\\)?\\n/g;class xV extends yV.Polling{constructor(e){super(e),this.head="___eio["+(e._query.j||"").replace(/[^0-9]/g,"")+"](",this.foot=");"}onData(e){"string"==typeof(e=vV.parse(e).d)&&(e=e.replace(_V,(function(e,t){return t?e:"\n"})),super.onData(e.replace(bV,"\\n")))}doWrite(e,t,n){const r=JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029");e=this.head+r+this.foot,super.doWrite(e,t,n)}}gV.JSONP=xV;var wV={};Object.defineProperty(wV,"__esModule",{value:!0}),wV.WebSocket=void 0;const EV=FG,SV=(0,ah.default)("engine:ws");let TV=class extends EV.Transport{constructor(e){super(e),this.socket=e.websocket,this.socket.on("message",((e,t)=>{const n=t?e:e.toString();SV('received "%s"',n),super.onData(n)})),this.socket.once("close",this.onClose.bind(this)),this.socket.on("error",this.onError.bind(this)),this.writable=!0,this.perMessageDeflate=null}get name(){return"websocket"}get handlesUpgrades(){return!0}get supportsFraming(){return!0}send(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t+1===e.length,i={};n.options&&(i.compress=n.options.compress);const s=e=>{if(e)return this.onError("write error",e.stack);r&&(this.writable=!0,this.emit("drain"))},o=e=>{if(this.perMessageDeflate){("string"==typeof e?Buffer.byteLength(e):e.length)<this.perMessageDeflate.threshold&&(i.compress=!1)}SV('writing "%s"',e),this.socket.send(e,i,s)};n.options&&"string"==typeof n.options.wsPreEncoded?o(n.options.wsPreEncoded):this._canSendPreEncodedFrame(n)?this.socket._sender.sendFrame(n.options.wsPreEncodedFrame,s):this.parser.encodePacket(n,this.supportsBinary,o)}}_canSendPreEncodedFrame(e){var t,n,r;return!this.perMessageDeflate&&"function"==typeof(null===(n=null===(t=this.socket)||void 0===t?void 0:t._sender)||void 0===n?void 0:n.sendFrame)&&void 0!==(null===(r=e.options)||void 0===r?void 0:r.wsPreEncodedFrame)}doClose(e){SV("closing"),this.socket.close(),e&&e()}};wV.WebSocket=TV;var DV={};Object.defineProperty(DV,"__esModule",{value:!0}),DV.WebTransport=void 0;const kV=FG,AV=BG,CV=(0,ah.default)("engine:webtransport");let RV=class extends kV.Transport{constructor(e,t,n){super({_query:{EIO:"4"}}),this.session=e;const r=(0,AV.createPacketEncoderStream)();r.readable.pipeTo(t.writable).catch((()=>{CV("the stream was closed")})),this.writer=r.writable.getWriter(),(async()=>{try{for(;;){const{value:e,done:t}=await n.read();if(t){CV("session is closed");break}CV("received chunk: %o",e),this.onPacket(e)}}catch(e){CV("error while reading: %s",e.message)}})(),e.closed.then((()=>this.onClose())),this.writable=!0}get name(){return"webtransport"}get supportsFraming(){return!0}async send(e){this.writable=!1;try{for(let t=0;t<e.length;t++){const n=e[t];await this.writer.write(n)}}catch(e){CV("error while writing: %s",e.message)}this.writable=!0,this.emit("drain")}doClose(e){CV("closing WebTransport session"),this.session.close(),e&&e()}};DV.WebTransport=RV,Object.defineProperty(NG,"__esModule",{value:!0});const OV=jG,LV=gV,IV=wV,PV=DV;function NV(e){return"string"==typeof e._query.j?new LV.JSONP(e):new OV.Polling(e)}NG.default={polling:NV,websocket:IV.WebSocket,webtransport:PV.WebTransport},NV.upgradesTo=["websocket","webtransport"];var jV={};Object.defineProperty(jV,"__esModule",{value:!0}),jV.Socket=void 0;const FV=p,BV=P,MV=(0,ah.default)("engine:socket");let UV=class extends FV.EventEmitter{constructor(e,t,n,r,i){super(),this._readyState="opening",this.upgrading=!1,this.upgraded=!1,this.writeBuffer=[],this.packetsFn=[],this.sentCallbackFn=[],this.cleanupFn=[],this.id=e,this.server=t,this.request=r,this.protocol=i,r&&(r.websocket&&r.websocket._socket?this.remoteAddress=r.websocket._socket.remoteAddress:this.remoteAddress=r.connection.remoteAddress),this.pingTimeoutTimer=null,this.pingIntervalTimer=null,this.setTransport(n),this.onOpen()}get readyState(){return this._readyState}set readyState(e){MV("readyState updated from %s to %s",this._readyState,e),this._readyState=e}onOpen(){this.readyState="open",this.transport.sid=this.id,this.sendPacket("open",JSON.stringify({sid:this.id,upgrades:this.getAvailableUpgrades(),pingInterval:this.server.opts.pingInterval,pingTimeout:this.server.opts.pingTimeout,maxPayload:this.server.opts.maxHttpBufferSize})),this.server.opts.initialPacket&&this.sendPacket("message",this.server.opts.initialPacket),this.emit("open"),3===this.protocol?this.resetPingTimeout(this.server.opts.pingInterval+this.server.opts.pingTimeout):this.schedulePing()}onPacket(e){if("open"!==this.readyState)return MV("packet received with closed socket");switch(MV(`received packet ${e.type}`),this.emit("packet",e),this.resetPingTimeout(this.server.opts.pingInterval+this.server.opts.pingTimeout),e.type){case"ping":if(3!==this.transport.protocol)return void this.onError("invalid heartbeat direction");MV("got ping"),this.sendPacket("pong"),this.emit("heartbeat");break;case"pong":if(3===this.transport.protocol)return void this.onError("invalid heartbeat direction");MV("got pong"),this.pingIntervalTimer.refresh(),this.emit("heartbeat");break;case"error":this.onClose("parse error");break;case"message":this.emit("data",e.data),this.emit("message",e.data)}}onError(e){MV("transport error"),this.onClose("transport error",e)}schedulePing(){this.pingIntervalTimer=(0,BV.setTimeout)((()=>{MV("writing ping packet - expecting pong within %sms",this.server.opts.pingTimeout),this.sendPacket("ping"),this.resetPingTimeout(this.server.opts.pingTimeout)}),this.server.opts.pingInterval)}resetPingTimeout(e){(0,BV.clearTimeout)(this.pingTimeoutTimer),this.pingTimeoutTimer=(0,BV.setTimeout)((()=>{"closed"!==this.readyState&&this.onClose("ping timeout")}),e)}setTransport(e){const t=this.onError.bind(this),n=this.onPacket.bind(this),r=this.flush.bind(this),i=this.onClose.bind(this,"transport close");this.transport=e,this.transport.once("error",t),this.transport.on("packet",n),this.transport.on("drain",r),this.transport.once("close",i),this.setupSendCallback(),this.cleanupFn.push((function(){e.removeListener("error",t),e.removeListener("packet",n),e.removeListener("drain",r),e.removeListener("close",i)}))}maybeUpgrade(e){MV('might upgrade socket transport from "%s" to "%s"',this.transport.name,e.name),this.upgrading=!0;const t=(0,BV.setTimeout)((()=>{MV("client did not complete upgrade - closing transport"),s(),"open"===e.readyState&&e.close()}),this.server.opts.upgradeTimeout);let n;const r=t=>{"ping"===t.type&&"probe"===t.data?(MV("got probe ping packet, sending pong"),e.send([{type:"pong",data:"probe"}]),this.emit("upgrading",e),clearInterval(n),n=setInterval(i,100)):"upgrade"===t.type&&"closed"!==this.readyState?(MV("got upgrade packet - upgrading"),s(),this.transport.discard(),this.upgraded=!0,this.clearTransport(),this.setTransport(e),this.emit("upgrade",e),this.flush(),"closing"===this.readyState&&e.close((()=>{this.onClose("forced close")}))):(s(),e.close())},i=()=>{"polling"===this.transport.name&&this.transport.writable&&(MV("writing a noop packet to polling for fast upgrade"),this.transport.send([{type:"noop"}]))},s=()=>{this.upgrading=!1,clearInterval(n),(0,BV.clearTimeout)(t),e.removeListener("packet",r),e.removeListener("close",a),e.removeListener("error",o),this.removeListener("close",c)},o=t=>{MV("client did not complete upgrade - %s",t),s(),e.close(),e=null},a=()=>{o("transport closed")},c=()=>{o("socket closed")};e.on("packet",r),e.once("close",a),e.once("error",o),this.once("close",c)}clearTransport(){let e;const t=this.cleanupFn.length;for(let n=0;n<t;n++)e=this.cleanupFn.shift(),e();this.transport.on("error",(function(){MV("error triggered by discarded transport")})),this.transport.close(),(0,BV.clearTimeout)(this.pingTimeoutTimer)}onClose(e,t){"closed"!==this.readyState&&(this.readyState="closed",(0,BV.clearTimeout)(this.pingIntervalTimer),(0,BV.clearTimeout)(this.pingTimeoutTimer),process.nextTick((()=>{this.writeBuffer=[]})),this.packetsFn=[],this.sentCallbackFn=[],this.clearTransport(),this.emit("close",e,t))}setupSendCallback(){const e=()=>{if(this.sentCallbackFn.length>0){const e=this.sentCallbackFn.splice(0,1)[0];if("function"==typeof e)MV("executing send callback"),e(this.transport);else if(Array.isArray(e)){MV("executing batch send callback");const t=e.length;let n=0;for(;n<t;n++)"function"==typeof e[n]&&e[n](this.transport)}}};this.transport.on("drain",e),this.cleanupFn.push((()=>{this.transport.removeListener("drain",e)}))}send(e,t,n){return this.sendPacket("message",e,t,n),this}write(e,t,n){return this.sendPacket("message",e,t,n),this}sendPacket(e,t,n={},r){if("function"==typeof n&&(r=n,n={}),"closing"!==this.readyState&&"closed"!==this.readyState){MV('sending packet "%s" (%s)',e,t),n.compress=!1!==n.compress;const i={type:e,options:n};t&&(i.data=t),this.emit("packetCreate",i),this.writeBuffer.push(i),r&&this.packetsFn.push(r),this.flush()}}flush(){if("closed"!==this.readyState&&this.transport.writable&&this.writeBuffer.length){MV("flushing buffer to transport"),this.emit("flush",this.writeBuffer),this.server.emit("flush",this,this.writeBuffer);const e=this.writeBuffer;this.writeBuffer=[],this.transport.supportsFraming?this.sentCallbackFn.push.apply(this.sentCallbackFn,this.packetsFn):this.sentCallbackFn.push(this.packetsFn),this.packetsFn=[],this.transport.send(e),this.emit("drain"),this.server.emit("drain",this)}}getAvailableUpgrades(){const e=[],t=this.server.upgrades(this.transport.name);let n=0;const r=t.length;for(;n<r;++n){const r=t[n];-1!==this.server.opts.transports.indexOf(r)&&e.push(r)}return e}close(e){if("open"===this.readyState){if(this.readyState="closing",this.writeBuffer.length)return MV("there are %d remaining packets in the buffer, waiting for the 'drain' event",this.writeBuffer.length),void this.once("drain",(()=>{MV("all packets have been sent, closing the transport"),this.closeTransport(e)}));MV("the buffer is empty, closing the transport right away",e),this.closeTransport(e)}}closeTransport(e){MV("closing the transport (discard? %s)",e),e&&this.transport.discard(),this.transport.close(this.onClose.bind(this,"forced close"))}};jV.Socket=UV;var qV,HV,$V,zV,WV,GV,VV={exports:{}},KV={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}},YV={exports:{}},ZV={exports:{}};function QV(){if($V)return ZV.exports;$V=1;const e="function"==typeof __webpack_require__?__non_webpack_require__:rF;return"function"==typeof e.addon?ZV.exports=e.addon.bind(e):ZV.exports=function(){if(HV)return qV;HV=1;var e=s,t=o,n=a,r="function"==typeof __webpack_require__?__non_webpack_require__:rF,i=process.config&&process.config.variables||{},c=!!process.env.PREBUILDS_ONLY,l=process.versions.modules,u=process.versions&&process.versions.electron||process.env.ELECTRON_RUN_AS_NODE||"undefined"!=typeof window&&window.process&&"renderer"===window.process.type?"electron":process.versions&&process.versions.nw?"node-webkit":"node",p=process.env.npm_config_arch||n.arch(),h=process.env.npm_config_platform||n.platform(),d=process.env.LIBC||(function(t){return"linux"===t&&e.existsSync("/etc/alpine-release")}(h)?"musl":"glibc"),f=process.env.ARM_VERSION||("arm64"===p?"8":i.arm_version)||"",m=(process.versions.uv||"").split(".")[0];function g(e){return r(g.resolve(e))}function y(t){try{return e.readdirSync(t)}catch(e){return[]}}function v(e,n){var r=y(e).filter(n);return r[0]&&t.join(e,r[0])}function b(e){return/\.node$/.test(e)}function _(e){var t=e.split("-");if(2===t.length){var n=t[0],r=t[1].split("+");if(n&&r.length&&r.every(Boolean))return{name:e,platform:n,architectures:r}}}function x(e,t){return function(n){return null!=n&&n.platform===e&&n.architectures.includes(t)}}function w(e,t){return e.architectures.length-t.architectures.length}function E(e){var t=e.split("."),n={file:e,specificity:0};if("node"===t.pop()){for(var r=0;r<t.length;r++){var i=t[r];if("node"===i||"electron"===i||"node-webkit"===i)n.runtime=i;else if("napi"===i)n.napi=!0;else if("abi"===i.slice(0,3))n.abi=i.slice(3);else if("uv"===i.slice(0,2))n.uv=i.slice(2);else if("armv"===i.slice(0,4))n.armv=i.slice(4);else{if("glibc"!==i&&"musl"!==i)continue;n.libc=i}n.specificity++}return n}}function S(e,t){return function(n){return!(null==n||n.runtime&&n.runtime!==e&&!function(e){return"node"===e.runtime&&e.napi}(n)||n.abi&&n.abi!==t&&!n.napi||n.uv&&n.uv!==m||n.armv&&n.armv!==f||n.libc&&n.libc!==d)}}function T(e){return function(t,n){return t.runtime!==n.runtime?t.runtime===e?-1:1:t.abi!==n.abi?t.abi?-1:1:t.specificity!==n.specificity?t.specificity>n.specificity?-1:1:0}}return qV=g,g.resolve=g.path=function(e){e=t.resolve(e||".");try{var n=r(t.join(e,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[n+"_PREBUILD"]&&(e=process.env[n+"_PREBUILD"])}catch(e){}if(!c){var i=v(t.join(e,"build/Release"),b);if(i)return i;var s=v(t.join(e,"build/Debug"),b);if(s)return s}var o=D(e);if(o)return o;var a=D(t.dirname(process.execPath));if(a)return a;var g=["platform="+h,"arch="+p,"runtime="+u,"abi="+l,"uv="+m,f?"armv="+f:"","libc="+d,"node="+process.versions.node,process.versions.electron?"electron="+process.versions.electron:"","function"==typeof __webpack_require__?"webpack=true":""].filter(Boolean).join(" ");throw new Error("No native build was found for "+g+"\n loaded from: "+e+"\n");function D(e){var n=y(t.join(e,"prebuilds")).map(_).filter(x(h,p)).sort(w)[0];if(n){var r=t.join(e,"prebuilds",n.name),i=y(r).map(E).filter(S(u,l)).sort(T(u))[0];return i?t.join(r,i.file):void 0}}},g.parseTags=E,g.matchTags=S,g.compareTags=T,g.parseTuple=_,g.matchTuple=x,g.compareTuples=w,qV}(),ZV.exports}const{EMPTY_BUFFER:JV}=KV,XV=Buffer[Symbol.species];function eK(e,t,n,r,i){for(let s=0;s<i;s++)n[r+s]=e[s]^t[3&s]}function tK(e,t){for(let n=0;n<e.length;n++)e[n]^=t[3&n]}if(VV.exports={concat:function(e,t){if(0===e.length)return JV;if(1===e.length)return e[0];const n=Buffer.allocUnsafe(t);let r=0;for(let t=0;t<e.length;t++){const i=e[t];n.set(i,r),r+=i.length}return r<t?new XV(n.buffer,n.byteOffset,r):n},mask:eK,toArrayBuffer:function(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)},toBuffer:function e(t){if(e.readOnly=!0,Buffer.isBuffer(t))return t;let n;return t instanceof ArrayBuffer?n=new XV(t):ArrayBuffer.isView(t)?n=new XV(t.buffer,t.byteOffset,t.byteLength):(n=Buffer.from(t),e.readOnly=!1),n},unmask:tK},!process.env.WS_NO_BUFFER_UTIL)try{const e=function(){if(GV)return YV.exports;GV=1;try{YV.exports=QV()(__dirname)}catch(e){YV.exports=(WV||(WV=1,zV={mask:(e,t,n,r,i)=>{for(var s=0;s<i;s++)n[r+s]=e[s]^t[3&s]},unmask:(e,t)=>{const n=e.length;for(var r=0;r<n;r++)e[r]^=t[3&r]}}),zV)}return YV.exports}();VV.exports.mask=function(t,n,r,i,s){s<48?eK(t,n,r,i,s):e.mask(t,n,r,i,s)},VV.exports.unmask=function(t,n){t.length<32?tK(t,n):e.unmask(t,n)}}catch(e){}var nK=VV.exports;const rK=Symbol("kDone"),iK=Symbol("kRun");const sK=T,oK=nK,aK=class{constructor(e){this[rK]=()=>{this.pending--,this[iK]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[iK]()}[iK](){if(this.pending!==this.concurrency&&this.jobs.length){const e=this.jobs.shift();this.pending++,e(this[rK])}}},{kStatusCode:cK}=KV,lK=Buffer[Symbol.species],uK=Buffer.from([0,0,255,255]),pK=Symbol("permessage-deflate"),hK=Symbol("total-length"),dK=Symbol("callback"),fK=Symbol("buffers"),mK=Symbol("error");let gK;var yK=class{constructor(e,t,n){if(this._maxPayload=0|n,this._options=e||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._isServer=!!t,this._deflate=null,this._inflate=null,this.params=null,!gK){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;gK=new aK(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:null==this._options.clientMaxWindowBits&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){const e=this._deflate[dK];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){const t=this._options,n=e.find((e=>!(!1===t.serverNoContextTakeover&&e.server_no_context_takeover||e.server_max_window_bits&&(!1===t.serverMaxWindowBits||"number"==typeof t.serverMaxWindowBits&&t.serverMaxWindowBits>e.server_max_window_bits)||"number"==typeof t.clientMaxWindowBits&&!e.client_max_window_bits)));if(!n)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(n.server_no_context_takeover=!0),t.clientNoContextTakeover&&(n.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(n.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?n.client_max_window_bits=t.clientMaxWindowBits:!0!==n.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete n.client_max_window_bits,n}acceptAsClient(e){const t=e[0];if(!1===this._options.clientNoContextTakeover&&t.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(t.client_max_window_bits){if(!1===this._options.clientMaxWindowBits||"number"==typeof this._options.clientMaxWindowBits&&t.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}else"number"==typeof this._options.clientMaxWindowBits&&(t.client_max_window_bits=this._options.clientMaxWindowBits);return t}normalizeParams(e){return e.forEach((e=>{Object.keys(e).forEach((t=>{let n=e[t];if(n.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(n=n[0],"client_max_window_bits"===t){if(!0!==n){const e=+n;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${n}`);n=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${n}`)}else if("server_max_window_bits"===t){const e=+n;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${n}`);n=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==n)throw new TypeError(`Invalid value for parameter "${t}": ${n}`)}e[t]=n}))})),e}decompress(e,t,n){gK.add((r=>{this._decompress(e,t,((e,t)=>{r(),n(e,t)}))}))}compress(e,t,n){gK.add((r=>{this._compress(e,t,((e,t)=>{r(),n(e,t)}))}))}_decompress(e,t,n){const r=this._isServer?"client":"server";if(!this._inflate){const e=`${r}_max_window_bits`,t="number"!=typeof this.params[e]?sK.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=sK.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t}),this._inflate[pK]=this,this._inflate[hK]=0,this._inflate[fK]=[],this._inflate.on("error",_K),this._inflate.on("data",bK)}this._inflate[dK]=n,this._inflate.write(e),t&&this._inflate.write(uK),this._inflate.flush((()=>{const e=this._inflate[mK];if(e)return this._inflate.close(),this._inflate=null,void n(e);const i=oK.concat(this._inflate[fK],this._inflate[hK]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[hK]=0,this._inflate[fK]=[],t&&this.params[`${r}_no_context_takeover`]&&this._inflate.reset()),n(null,i)}))}_compress(e,t,n){const r=this._isServer?"server":"client";if(!this._deflate){const e=`${r}_max_window_bits`,t="number"!=typeof this.params[e]?sK.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=sK.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t}),this._deflate[hK]=0,this._deflate[fK]=[],this._deflate.on("data",vK)}this._deflate[dK]=n,this._deflate.write(e),this._deflate.flush(sK.Z_SYNC_FLUSH,(()=>{if(!this._deflate)return;let e=oK.concat(this._deflate[fK],this._deflate[hK]);t&&(e=new lK(e.buffer,e.byteOffset,e.length-4)),this._deflate[dK]=null,this._deflate[hK]=0,this._deflate[fK]=[],t&&this.params[`${r}_no_context_takeover`]&&this._deflate.reset(),n(null,e)}))}};function vK(e){this[fK].push(e),this[hK]+=e.length}function bK(e){this[hK]+=e.length,this[pK]._maxPayload<1||this[hK]<=this[pK]._maxPayload?this[fK].push(e):(this[mK]=new RangeError("Max payload size exceeded"),this[mK].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[mK][cK]=1009,this.removeListener("data",bK),this.reset())}function _K(e){this[pK]._inflate=null,e[cK]=1007,this[dK](e)}var xK,wK,EK,SK={exports:{}},TK={exports:{}};const{isUtf8:DK}=v;function kK(e){const t=e.length;let n=0;for(;n<t;)if(128&e[n])if(192==(224&e[n])){if(n+1===t||128!=(192&e[n+1])||192==(254&e[n]))return!1;n+=2}else if(224==(240&e[n])){if(n+2>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||224===e[n]&&128==(224&e[n+1])||237===e[n]&&160==(224&e[n+1]))return!1;n+=3}else{if(240!=(248&e[n]))return!1;if(n+3>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||128!=(192&e[n+3])||240===e[n]&&128==(240&e[n+1])||244===e[n]&&e[n+1]>143||e[n]>244)return!1;n+=4}else n++;return!0}if(SK.exports={isValidStatusCode:function(e){return e>=1e3&&e<=1014&&1004!==e&&1005!==e&&1006!==e||e>=3e3&&e<=4999},isValidUTF8:kK,tokenChars:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0]},DK)SK.exports.isValidUTF8=function(e){return e.length<24?kK(e):DK(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const e=function(){if(EK)return TK.exports;EK=1;try{TK.exports=QV()(__dirname)}catch(e){TK.exports=(wK||(wK=1,xK=function(e){const t=e.length;let n=0;for(;n<t;)if(128&e[n])if(192==(224&e[n])){if(n+1===t||128!=(192&e[n+1])||192==(254&e[n]))return!1;n+=2}else if(224==(240&e[n])){if(n+2>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||224===e[n]&&128==(224&e[n+1])||237===e[n]&&160==(224&e[n+1]))return!1;n+=3}else{if(240!=(248&e[n]))return!1;if(n+3>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||128!=(192&e[n+3])||240===e[n]&&128==(240&e[n+1])||244===e[n]&&e[n+1]>143||e[n]>244)return!1;n+=4}else n++;return!0}),xK)}return TK.exports}();SK.exports.isValidUTF8=function(t){return t.length<32?kK(t):e(t)}}catch(e){}var AK=SK.exports;const{Writable:CK}=h,RK=yK,{BINARY_TYPES:OK,EMPTY_BUFFER:LK,kStatusCode:IK,kWebSocket:PK}=KV,{concat:NK,toArrayBuffer:jK,unmask:FK}=nK,{isValidStatusCode:BK,isValidUTF8:MK}=AK,UK=Buffer[Symbol.species];var qK=class extends CK{constructor(e={}){super(),this._allowSynchronousEvents=void 0===e.allowSynchronousEvents||e.allowSynchronousEvents,this._binaryType=e.binaryType||OK[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=0|e.maxPayload,this._skipUTF8Validation=!!e.skipUTF8Validation,this[PK]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=0}_write(e,t,n){if(8===this._opcode&&0==this._state)return n();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(n)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];return this._buffers[0]=new UK(t.buffer,t.byteOffset+e,t.length-e),new UK(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const n=this._buffers[0],r=t.length-e;e>=n.length?t.set(this._buffers.shift(),r):(t.set(new Uint8Array(n.buffer,n.byteOffset,e),r),this._buffers[0]=new UK(n.buffer,n.byteOffset+e,n.length-e)),e-=n.length}while(e>0);return t}startLoop(e){this._loop=!0;do{switch(this._state){case 0:this.getInfo(e);break;case 1:this.getPayloadLength16(e);break;case 2:this.getPayloadLength64(e);break;case 3:this.getMask();break;case 4:this.getData(e);break;case 5:case 6:return void(this._loop=!1)}}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2)return void(this._loop=!1);const t=this.consume(2);if(48&t[0]){return void e(this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3"))}const n=!(64&~t[0]);if(!n||this._extensions[RK.extensionName]){if(this._fin=!(128&~t[0]),this._opcode=15&t[0],this._payloadLength=127&t[1],0===this._opcode){if(n){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(!this._fragmented){return void e(this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE"))}this._opcode=this._fragmented}else if(1===this._opcode||2===this._opcode){if(this._fragmented){return void e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}this._compressed=n}else{if(!(this._opcode>7&&this._opcode<11)){return void e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}if(!this._fin){return void e(this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN"))}if(n){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(this._payloadLength>125||8===this._opcode&&1===this._payloadLength){return void e(this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"))}}if(this._fin||this._fragmented||(this._fragmented=this._opcode),this._masked=!(128&~t[1]),this._isServer){if(!this._masked){return void e(this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK"))}}else if(this._masked){return void e(this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK"))}126===this._payloadLength?this._state=1:127===this._payloadLength?this._state=2:this.haveLength(e)}else{e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}}getPayloadLength16(e){this._bufferedBytes<2?this._loop=!1:(this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e))}getPayloadLength64(e){if(this._bufferedBytes<8)return void(this._loop=!1);const t=this.consume(8),n=t.readUInt32BE(0);if(n>Math.pow(2,21)-1){e(this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"))}else this._payloadLength=n*Math.pow(2,32)+t.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){e(this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"))}else this._masked?this._state=3:this._state=4}getMask(){this._bufferedBytes<4?this._loop=!1:(this._mask=this.consume(4),this._state=4)}getData(e){let t=LK;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength)return void(this._loop=!1);t=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&FK(t,this._mask)}if(this._opcode>7)this.controlMessage(t,e);else{if(this._compressed)return this._state=5,void this.decompress(t,e);t.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(t)),this.dataMessage(e)}}decompress(e,t){this._extensions[RK.extensionName].decompress(e,this._fin,((e,n)=>{if(e)return t(e);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){const e=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");return void t(e)}this._fragments.push(n)}this.dataMessage(t),0===this._state&&this.startLoop(t)}))}dataMessage(e){if(!this._fin)return void(this._state=0);const t=this._messageLength,n=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],2===this._opcode){let r;r="nodebuffer"===this._binaryType?NK(n,t):"arraybuffer"===this._binaryType?jK(NK(n,t)):n,this._allowSynchronousEvents?(this.emit("message",r,!0),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",r,!0),this._state=0,this.startLoop(e)})))}else{const r=NK(n,t);if(!this._skipUTF8Validation&&!MK(r)){const t=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void e(t)}5===this._state||this._allowSynchronousEvents?(this.emit("message",r,!1),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",r,!1),this._state=0,this.startLoop(e)})))}}controlMessage(e,t){if(8!==this._opcode)this._allowSynchronousEvents?(this.emit(9===this._opcode?"ping":"pong",e),this._state=0):(this._state=6,setImmediate((()=>{this.emit(9===this._opcode?"ping":"pong",e),this._state=0,this.startLoop(t)})));else{if(0===e.length)this._loop=!1,this.emit("conclude",1005,LK),this.end();else{const n=e.readUInt16BE(0);if(!BK(n)){const e=this.createError(RangeError,`invalid status code ${n}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void t(e)}const r=new UK(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!MK(r)){const e=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void t(e)}this._loop=!1,this.emit("conclude",n,r),this.end()}this._state=0}}createError(e,t,n,r,i){this._loop=!1,this._errored=!0;const s=new e(n?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(s,this.createError),s.code=i,s[IK]=r,s}};const{randomFillSync:HK}=x,$K=yK,{EMPTY_BUFFER:zK}=KV,{isValidStatusCode:WK}=AK,{mask:GK,toBuffer:VK}=nK,KK=Symbol("kByteLength"),YK=Buffer.alloc(4),ZK=8192;let QK,JK=ZK;var XK=class e{constructor(e,t,n){this._extensions=t||{},n&&(this._generateMask=n,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(e,t){let n,r,i=!1,s=2,o=!1;t.mask&&(n=t.maskBuffer||YK,t.generateMask?t.generateMask(n):(JK===ZK&&(void 0===QK&&(QK=Buffer.alloc(ZK)),HK(QK,0,ZK),JK=0),n[0]=QK[JK++],n[1]=QK[JK++],n[2]=QK[JK++],n[3]=QK[JK++]),o=!(n[0]|n[1]|n[2]|n[3]),s=6),"string"==typeof e?r=t.mask&&!o||void 0===t[KK]?(e=Buffer.from(e)).length:t[KK]:(r=e.length,i=t.mask&&t.readOnly&&!o);let a=r;r>=65536?(s+=8,a=127):r>125&&(s+=2,a=126);const c=Buffer.allocUnsafe(i?r+s:s);return c[0]=t.fin?128|t.opcode:t.opcode,t.rsv1&&(c[0]|=64),c[1]=a,126===a?c.writeUInt16BE(r,2):127===a&&(c[2]=c[3]=0,c.writeUIntBE(r,4,6)),t.mask?(c[1]|=128,c[s-4]=n[0],c[s-3]=n[1],c[s-2]=n[2],c[s-1]=n[3],o?[c,e]:i?(GK(e,n,c,s,r),[c]):(GK(e,n,e,0,r),[c,e])):[c,e]}close(t,n,r,i){let s;if(void 0===t)s=zK;else{if("number"!=typeof t||!WK(t))throw new TypeError("First argument must be a valid error code number");if(void 0!==n&&n.length){const e=Buffer.byteLength(n);if(e>123)throw new RangeError("The message must not be greater than 123 bytes");s=Buffer.allocUnsafe(2+e),s.writeUInt16BE(t,0),"string"==typeof n?s.write(n,2):s.set(n,2)}else s=Buffer.allocUnsafe(2),s.writeUInt16BE(t,0)}const o={[KK]:s.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._deflating?this.enqueue([this.dispatch,s,!1,o,i]):this.sendFrame(e.frame(s,o),i)}ping(t,n,r){let i,s;if("string"==typeof t?(i=Buffer.byteLength(t),s=!1):(i=(t=VK(t)).length,s=VK.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[KK]:i,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:9,readOnly:s,rsv1:!1};this._deflating?this.enqueue([this.dispatch,t,!1,o,r]):this.sendFrame(e.frame(t,o),r)}pong(t,n,r){let i,s;if("string"==typeof t?(i=Buffer.byteLength(t),s=!1):(i=(t=VK(t)).length,s=VK.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[KK]:i,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:10,readOnly:s,rsv1:!1};this._deflating?this.enqueue([this.dispatch,t,!1,o,r]):this.sendFrame(e.frame(t,o),r)}send(t,n,r){const i=this._extensions[$K.extensionName];let s,o,a=n.binary?2:1,c=n.compress;if("string"==typeof t?(s=Buffer.byteLength(t),o=!1):(s=(t=VK(t)).length,o=VK.readOnly),this._firstFragment?(this._firstFragment=!1,c&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(c=s>=i._threshold),this._compress=c):(c=!1,a=0),n.fin&&(this._firstFragment=!0),i){const e={[KK]:s,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:a,readOnly:o,rsv1:c};this._deflating?this.enqueue([this.dispatch,t,this._compress,e,r]):this.dispatch(t,this._compress,e,r)}else this.sendFrame(e.frame(t,{[KK]:s,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:a,readOnly:o,rsv1:!1}),r)}dispatch(t,n,r,i){if(!n)return void this.sendFrame(e.frame(t,r),i);const s=this._extensions[$K.extensionName];this._bufferedBytes+=r[KK],this._deflating=!0,s.compress(t,r.fin,((t,n)=>{if(this._socket.destroyed){const e=new Error("The socket was closed while data was being compressed");"function"==typeof i&&i(e);for(let t=0;t<this._queue.length;t++){const n=this._queue[t],r=n[n.length-1];"function"==typeof r&&r(e)}}else this._bufferedBytes-=r[KK],this._deflating=!1,r.readOnly=!1,this.sendFrame(e.frame(n,r),i),this.dequeue()}))}dequeue(){for(;!this._deflating&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[3][KK],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][KK],this._queue.push(e)}sendFrame(e,t){2===e.length?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],t),this._socket.uncork()):this._socket.write(e[0],t)}};const{kForOnEventAttribute:eY,kListener:tY}=KV,nY=Symbol("kCode"),rY=Symbol("kData"),iY=Symbol("kError"),sY=Symbol("kMessage"),oY=Symbol("kReason"),aY=Symbol("kTarget"),cY=Symbol("kType"),lY=Symbol("kWasClean");class uY{constructor(e){this[aY]=null,this[cY]=e}get target(){return this[aY]}get type(){return this[cY]}}Object.defineProperty(uY.prototype,"target",{enumerable:!0}),Object.defineProperty(uY.prototype,"type",{enumerable:!0});class pY extends uY{constructor(e,t={}){super(e),this[nY]=void 0===t.code?0:t.code,this[oY]=void 0===t.reason?"":t.reason,this[lY]=void 0!==t.wasClean&&t.wasClean}get code(){return this[nY]}get reason(){return this[oY]}get wasClean(){return this[lY]}}Object.defineProperty(pY.prototype,"code",{enumerable:!0}),Object.defineProperty(pY.prototype,"reason",{enumerable:!0}),Object.defineProperty(pY.prototype,"wasClean",{enumerable:!0});class hY extends uY{constructor(e,t={}){super(e),this[iY]=void 0===t.error?null:t.error,this[sY]=void 0===t.message?"":t.message}get error(){return this[iY]}get message(){return this[sY]}}Object.defineProperty(hY.prototype,"error",{enumerable:!0}),Object.defineProperty(hY.prototype,"message",{enumerable:!0});class dY extends uY{constructor(e,t={}){super(e),this[rY]=void 0===t.data?null:t.data}get data(){return this[rY]}}Object.defineProperty(dY.prototype,"data",{enumerable:!0});const fY={addEventListener(e,t,n={}){for(const r of this.listeners(e))if(!n[eY]&&r[tY]===t&&!r[eY])return;let r;if("message"===e)r=function(e,n){const r=new dY("message",{data:n?e:e.toString()});r[aY]=this,gY(t,this,r)};else if("close"===e)r=function(e,n){const r=new pY("close",{code:e,reason:n.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});r[aY]=this,gY(t,this,r)};else if("error"===e)r=function(e){const n=new hY("error",{error:e,message:e.message});n[aY]=this,gY(t,this,n)};else{if("open"!==e)return;r=function(){const e=new uY("open");e[aY]=this,gY(t,this,e)}}r[eY]=!!n[eY],r[tY]=t,n.once?this.once(e,r):this.on(e,r)},removeEventListener(e,t){for(const n of this.listeners(e))if(n[tY]===t&&!n[eY]){this.removeListener(e,n);break}}};var mY={CloseEvent:pY,ErrorEvent:hY,Event:uY,EventTarget:fY,MessageEvent:dY};function gY(e,t,n){"object"==typeof e&&e.handleEvent?e.handleEvent.call(e,n):e.call(t,n)}const{tokenChars:yY}=AK;function vY(e,t,n){void 0===e[t]?e[t]=[n]:e[t].push(n)}var bY={format:function(e){return Object.keys(e).map((t=>{let n=e[t];return Array.isArray(n)||(n=[n]),n.map((e=>[t].concat(Object.keys(e).map((t=>{let n=e[t];return Array.isArray(n)||(n=[n]),n.map((e=>!0===e?t:`${t}=${e}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")},parse:function(e){const t=Object.create(null);let n,r,i=Object.create(null),s=!1,o=!1,a=!1,c=-1,l=-1,u=-1,p=0;for(;p<e.length;p++)if(l=e.charCodeAt(p),void 0===n)if(-1===u&&1===yY[l])-1===c&&(c=p);else if(0===p||32!==l&&9!==l){if(59!==l&&44!==l)throw new SyntaxError(`Unexpected character at index ${p}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===u&&(u=p);const r=e.slice(c,u);44===l?(vY(t,r,i),i=Object.create(null)):n=r,c=u=-1}}else-1===u&&-1!==c&&(u=p);else if(void 0===r)if(-1===u&&1===yY[l])-1===c&&(c=p);else if(32===l||9===l)-1===u&&-1!==c&&(u=p);else if(59===l||44===l){if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===u&&(u=p),vY(i,e.slice(c,u),!0),44===l&&(vY(t,n,i),i=Object.create(null),n=void 0),c=u=-1}else{if(61!==l||-1===c||-1!==u)throw new SyntaxError(`Unexpected character at index ${p}`);r=e.slice(c,p),c=u=-1}else if(o){if(1!==yY[l])throw new SyntaxError(`Unexpected character at index ${p}`);-1===c?c=p:s||(s=!0),o=!1}else if(a)if(1===yY[l])-1===c&&(c=p);else if(34===l&&-1!==c)a=!1,u=p;else{if(92!==l)throw new SyntaxError(`Unexpected character at index ${p}`);o=!0}else if(34===l&&61===e.charCodeAt(p-1))a=!0;else if(-1===u&&1===yY[l])-1===c&&(c=p);else if(-1===c||32!==l&&9!==l){if(59!==l&&44!==l)throw new SyntaxError(`Unexpected character at index ${p}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===u&&(u=p);let o=e.slice(c,u);s&&(o=o.replace(/\\/g,""),s=!1),vY(i,r,o),44===l&&(vY(t,n,i),i=Object.create(null),n=void 0),r=void 0,c=u=-1}}else-1===u&&(u=p);if(-1===c||a||32===l||9===l)throw new SyntaxError("Unexpected end of input");-1===u&&(u=p);const h=e.slice(c,u);return void 0===n?vY(t,h,i):(void 0===r?vY(i,h,!0):vY(i,r,s?h.replace(/\\/g,""):h),vY(t,n,i)),t}};const _Y=p,xY=E,wY=w,EY=O,SY=N,{randomBytes:TY,createHash:DY}=x,{URL:kY}=S,AY=yK,CY=qK,RY=XK,{BINARY_TYPES:OY,EMPTY_BUFFER:LY,GUID:IY,kForOnEventAttribute:PY,kListener:NY,kStatusCode:jY,kWebSocket:FY,NOOP:BY}=KV,{EventTarget:{addEventListener:MY,removeEventListener:UY}}=mY,{format:qY,parse:HY}=bY,{toBuffer:$Y}=nK,zY=Symbol("kAborted"),WY=[8,13],GY=["CONNECTING","OPEN","CLOSING","CLOSED"],VY=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;let KY=class e extends _Y{constructor(t,n,r){super(),this._binaryType=OY[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=LY,this._closeTimer=null,this._extensions={},this._paused=!1,this._protocol="",this._readyState=e.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,null!==t?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,void 0===n?n=[]:Array.isArray(n)||("object"==typeof n&&null!==n?(r=n,n=[]):n=[n]),ZY(this,t,n,r)):(this._autoPong=r.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){OY.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(t,n,r){const i=new CY({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation});this._sender=new RY(t,this._extensions,r.generateMask),this._receiver=i,this._socket=t,i[FY]=this,t[FY]=this,i.on("conclude",nZ),i.on("drain",rZ),i.on("error",iZ),i.on("message",oZ),i.on("ping",aZ),i.on("pong",cZ),t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),n.length>0&&t.unshift(n),t.on("close",uZ),t.on("data",pZ),t.on("end",hZ),t.on("error",dZ),this._readyState=e.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=e.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[AY.extensionName]&&this._extensions[AY.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(t,n){if(this.readyState!==e.CLOSED)if(this.readyState!==e.CONNECTING)this.readyState!==e.CLOSING?(this._readyState=e.CLOSING,this._sender.close(t,n,!this._isServer,(e=>{e||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())})),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),3e4)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();else{const e="WebSocket was closed before the connection was established";eZ(this,this._req,e)}}pause(){this.readyState!==e.CONNECTING&&this.readyState!==e.CLOSED&&(this._paused=!0,this._socket.pause())}ping(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(r=t,t=n=void 0):"function"==typeof n&&(r=n,n=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===e.OPEN?(void 0===n&&(n=!this._isServer),this._sender.ping(t||LY,n,r)):tZ(this,t,r)}pong(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(r=t,t=n=void 0):"function"==typeof n&&(r=n,n=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===e.OPEN?(void 0===n&&(n=!this._isServer),this._sender.pong(t||LY,n,r)):tZ(this,t,r)}resume(){this.readyState!==e.CONNECTING&&this.readyState!==e.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof n&&(r=n,n={}),"number"==typeof t&&(t=t.toString()),this.readyState!==e.OPEN)return void tZ(this,t,r);const i={binary:"string"!=typeof t,mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[AY.extensionName]||(i.compress=!1),this._sender.send(t||LY,i,r)}terminate(){if(this.readyState!==e.CLOSED)if(this.readyState!==e.CONNECTING)this._socket&&(this._readyState=e.CLOSING,this._socket.destroy());else{const e="WebSocket was closed before the connection was established";eZ(this,this._req,e)}}};Object.defineProperty(KY,"CONNECTING",{enumerable:!0,value:GY.indexOf("CONNECTING")}),Object.defineProperty(KY.prototype,"CONNECTING",{enumerable:!0,value:GY.indexOf("CONNECTING")}),Object.defineProperty(KY,"OPEN",{enumerable:!0,value:GY.indexOf("OPEN")}),Object.defineProperty(KY.prototype,"OPEN",{enumerable:!0,value:GY.indexOf("OPEN")}),Object.defineProperty(KY,"CLOSING",{enumerable:!0,value:GY.indexOf("CLOSING")}),Object.defineProperty(KY.prototype,"CLOSING",{enumerable:!0,value:GY.indexOf("CLOSING")}),Object.defineProperty(KY,"CLOSED",{enumerable:!0,value:GY.indexOf("CLOSED")}),Object.defineProperty(KY.prototype,"CLOSED",{enumerable:!0,value:GY.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(KY.prototype,e,{enumerable:!0})})),["open","error","close","message"].forEach((e=>{Object.defineProperty(KY.prototype,`on${e}`,{enumerable:!0,get(){for(const t of this.listeners(e))if(t[PY])return t[NY];return null},set(t){for(const t of this.listeners(e))if(t[PY]){this.removeListener(e,t);break}"function"==typeof t&&this.addEventListener(e,t,{[PY]:!0})}})})),KY.prototype.addEventListener=MY,KY.prototype.removeEventListener=UY;var YY=KY;function ZY(e,t,n,r){const i={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:WY[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(e._autoPong=i.autoPong,!WY.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${WY.join(", ")})`);let s;if(t instanceof kY)s=t;else try{s=new kY(t)}catch(e){throw new SyntaxError(`Invalid URL: ${t}`)}"http:"===s.protocol?s.protocol="ws:":"https:"===s.protocol&&(s.protocol="wss:"),e._url=s.href;const o="wss:"===s.protocol,a="ws+unix:"===s.protocol;let c;if("ws:"===s.protocol||o||a?a&&!s.pathname?c="The URL's pathname is empty":s.hash&&(c="The URL contains a fragment identifier"):c='The URL\'s protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"',c){const t=new SyntaxError(c);if(0===e._redirects)throw t;return void QY(e,t)}const l=o?443:80,u=TY(16).toString("base64"),p=o?xY.request:wY.request,h=new Set;let d,f;if(i.createConnection=i.createConnection||(o?XY:JY),i.defaultPort=i.defaultPort||l,i.port=s.port||l,i.host=s.hostname.startsWith("[")?s.hostname.slice(1,-1):s.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":u,Connection:"Upgrade",Upgrade:"websocket"},i.path=s.pathname+s.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(d=new AY(!0!==i.perMessageDeflate?i.perMessageDeflate:{},!1,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=qY({[AY.extensionName]:d.offer()})),n.length){for(const e of n){if("string"!=typeof e||!VY.test(e)||h.has(e))throw new SyntaxError("An invalid or duplicated subprotocol was specified");h.add(e)}i.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(s.username||s.password)&&(i.auth=`${s.username}:${s.password}`),a){const e=i.path.split(":");i.socketPath=e[0],i.path=e[1]}if(i.followRedirects){if(0===e._redirects){e._originalIpc=a,e._originalSecure=o,e._originalHostOrSocketPath=a?i.socketPath:s.host;const t=r&&r.headers;if(r={...r,headers:{}},t)for(const[e,n]of Object.entries(t))r.headers[e.toLowerCase()]=n}else if(0===e.listenerCount("redirect")){const t=a?!!e._originalIpc&&i.socketPath===e._originalHostOrSocketPath:!e._originalIpc&&s.host===e._originalHostOrSocketPath;(!t||e._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,t||delete i.headers.host,i.auth=void 0)}i.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),f=e._req=p(i),e._redirects&&e.emit("redirect",e.url,f)}else f=e._req=p(i);i.timeout&&f.on("timeout",(()=>{eZ(e,f,"Opening handshake has timed out")})),f.on("error",(t=>{null===f||f[zY]||(f=e._req=null,QY(e,t))})),f.on("response",(s=>{const o=s.headers.location,a=s.statusCode;if(o&&i.followRedirects&&a>=300&&a<400){if(++e._redirects>i.maxRedirects)return void eZ(e,f,"Maximum redirects exceeded");let s;f.abort();try{s=new kY(o,t)}catch(t){const n=new SyntaxError(`Invalid URL: ${o}`);return void QY(e,n)}ZY(e,s,n,r)}else e.emit("unexpected-response",f,s)||eZ(e,f,`Unexpected server response: ${s.statusCode}`)})),f.on("upgrade",((t,n,r)=>{if(e.emit("upgrade",t),e.readyState!==KY.CONNECTING)return;f=e._req=null;const s=t.headers.upgrade;if(void 0===s||"websocket"!==s.toLowerCase())return void eZ(e,n,"Invalid Upgrade header");const o=DY("sha1").update(u+IY).digest("base64");if(t.headers["sec-websocket-accept"]!==o)return void eZ(e,n,"Invalid Sec-WebSocket-Accept header");const a=t.headers["sec-websocket-protocol"];let c;if(void 0!==a?h.size?h.has(a)||(c="Server sent an invalid subprotocol"):c="Server sent a subprotocol but none was requested":h.size&&(c="Server sent no subprotocol"),c)return void eZ(e,n,c);a&&(e._protocol=a);const l=t.headers["sec-websocket-extensions"];if(void 0!==l){if(!d){return void eZ(e,n,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let t;try{t=HY(l)}catch(t){return void eZ(e,n,"Invalid Sec-WebSocket-Extensions header")}const r=Object.keys(t);if(1!==r.length||r[0]!==AY.extensionName){return void eZ(e,n,"Server indicated an extension that was not requested")}try{d.accept(t[AY.extensionName])}catch(t){return void eZ(e,n,"Invalid Sec-WebSocket-Extensions header")}e._extensions[AY.extensionName]=d}e.setSocket(n,r,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})})),i.finishRequest?i.finishRequest(f,e):f.end()}function QY(e,t){e._readyState=KY.CLOSING,e.emit("error",t),e.emitClose()}function JY(e){return e.path=e.socketPath,EY.connect(e)}function XY(e){return e.path=void 0,e.servername||""===e.servername||(e.servername=EY.isIP(e.host)?"":e.host),SY.connect(e)}function eZ(e,t,n){e._readyState=KY.CLOSING;const r=new Error(n);Error.captureStackTrace(r,eZ),t.setHeader?(t[zY]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(QY,e,r)):(t.destroy(r),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function tZ(e,t,n){if(t){const n=$Y(t).length;e._socket?e._sender._bufferedBytes+=n:e._bufferedAmount+=n}if(n){const t=new Error(`WebSocket is not open: readyState ${e.readyState} (${GY[e.readyState]})`);process.nextTick(n,t)}}function nZ(e,t){const n=this[FY];n._closeFrameReceived=!0,n._closeMessage=t,n._closeCode=e,void 0!==n._socket[FY]&&(n._socket.removeListener("data",pZ),process.nextTick(lZ,n._socket),1005===e?n.close():n.close(e,t))}function rZ(){const e=this[FY];e.isPaused||e._socket.resume()}function iZ(e){const t=this[FY];void 0!==t._socket[FY]&&(t._socket.removeListener("data",pZ),process.nextTick(lZ,t._socket),t.close(e[jY])),t.emit("error",e)}function sZ(){this[FY].emitClose()}function oZ(e,t){this[FY].emit("message",e,t)}function aZ(e){const t=this[FY];t._autoPong&&t.pong(e,!this._isServer,BY),t.emit("ping",e)}function cZ(e){this[FY].emit("pong",e)}function lZ(e){e.resume()}function uZ(){const e=this[FY];let t;this.removeListener("close",uZ),this.removeListener("data",pZ),this.removeListener("end",hZ),e._readyState=KY.CLOSING,this._readableState.endEmitted||e._closeFrameReceived||e._receiver._writableState.errorEmitted||null===(t=e._socket.read())||e._receiver.write(t),e._receiver.end(),this[FY]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",sZ),e._receiver.on("finish",sZ))}function pZ(e){this[FY]._receiver.write(e)||this.pause()}function hZ(){const e=this[FY];e._readyState=KY.CLOSING,e._receiver.end(),this.end()}function dZ(){const e=this[FY];this.removeListener("error",dZ),this.on("error",BY),e&&(e._readyState=KY.CLOSING,this.destroy())}var fZ=q(YY);const{Duplex:mZ}=h;function gZ(e){e.emit("close")}function yZ(){!this.destroyed&&this._writableState.finished&&this.destroy()}function vZ(e){this.removeListener("error",vZ),this.destroy(),0===this.listenerCount("error")&&this.emit("error",e)}var bZ=function(e,t){let n=!0;const r=new mZ({...t,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return e.on("message",(function(t,n){const i=!n&&r._readableState.objectMode?t.toString():t;r.push(i)||e.pause()})),e.once("error",(function(e){r.destroyed||(n=!1,r.destroy(e))})),e.once("close",(function(){r.destroyed||r.push(null)})),r._destroy=function(t,i){if(e.readyState===e.CLOSED)return i(t),void process.nextTick(gZ,r);let s=!1;e.once("error",(function(e){s=!0,i(e)})),e.once("close",(function(){s||i(t),process.nextTick(gZ,r)})),n&&e.terminate()},r._final=function(t){e.readyState!==e.CONNECTING?null!==e._socket&&(e._socket._writableState.finished?(t(),r._readableState.endEmitted&&r.destroy()):(e._socket.once("finish",(function(){t()})),e.close())):e.once("open",(function(){r._final(t)}))},r._read=function(){e.isPaused&&e.resume()},r._write=function(t,n,i){e.readyState!==e.CONNECTING?e.send(t,i):e.once("open",(function(){r._write(t,n,i)}))},r.on("end",yZ),r.on("error",vZ),r};const{tokenChars:_Z}=AK;var xZ={parse:function(e){const t=new Set;let n=-1,r=-1,i=0;for(;i<e.length;i++){const s=e.charCodeAt(i);if(-1===r&&1===_Z[s])-1===n&&(n=i);else if(0===i||32!==s&&9!==s){if(44!==s)throw new SyntaxError(`Unexpected character at index ${i}`);{if(-1===n)throw new SyntaxError(`Unexpected character at index ${i}`);-1===r&&(r=i);const s=e.slice(n,r);if(t.has(s))throw new SyntaxError(`The "${s}" subprotocol is duplicated`);t.add(s),n=r=-1}}else-1===r&&-1!==n&&(r=i)}if(-1===n||-1!==r)throw new SyntaxError("Unexpected end of input");const s=e.slice(n,i);if(t.has(s))throw new SyntaxError(`The "${s}" subprotocol is duplicated`);return t.add(s),t}};const wZ=p,EZ=w,{createHash:SZ}=x,TZ=bY,DZ=yK,kZ=xZ,AZ=YY,{GUID:CZ,kWebSocket:RZ}=KV,OZ=/^[+/0-9A-Za-z]{22}==$/;var LZ=class extends wZ{constructor(e,t){if(super(),null==(e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:AZ,...e}).port&&!e.server&&!e.noServer||null!=e.port&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(null!=e.port?(this._server=EZ.createServer(((e,t)=>{const n=EZ.STATUS_CODES[426];t.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),t.end(n)})),this._server.listen(e.port,e.host,e.backlog,t)):e.server&&(this._server=e.server),this._server){const e=this.emit.bind(this,"connection");this._removeListeners=function(e,t){for(const n of Object.keys(t))e.on(n,t[n]);return function(){for(const n of Object.keys(t))e.removeListener(n,t[n])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,n,r)=>{this.handleUpgrade(t,n,r,e)}})}!0===e.perMessageDeflate&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=0}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(2===this._state)return e&&this.once("close",(()=>{e(new Error("The server is not running"))})),void process.nextTick(IZ,this);if(e&&this.once("close",e),1!==this._state)if(this._state=1,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients&&this.clients.size?this._shouldEmitClose=!0:process.nextTick(IZ,this);else{const e=this._server;this._removeListeners(),this._removeListeners=this._server=null,e.close((()=>{IZ(this)}))}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");if((-1!==t?e.url.slice(0,t):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,t,n,r){t.on("error",PZ);const i=e.headers["sec-websocket-key"],s=e.headers.upgrade,o=+e.headers["sec-websocket-version"];if("GET"!==e.method){return void jZ(this,e,t,405,"Invalid HTTP method")}if(void 0===s||"websocket"!==s.toLowerCase()){return void jZ(this,e,t,400,"Invalid Upgrade header")}if(void 0===i||!OZ.test(i)){return void jZ(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header")}if(8!==o&&13!==o){return void jZ(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header")}if(!this.shouldHandle(e))return void NZ(t,400);const a=e.headers["sec-websocket-protocol"];let c=new Set;if(void 0!==a)try{c=kZ.parse(a)}catch(n){return void jZ(this,e,t,400,"Invalid Sec-WebSocket-Protocol header")}const l=e.headers["sec-websocket-extensions"],u={};if(this.options.perMessageDeflate&&void 0!==l){const n=new DZ(this.options.perMessageDeflate,!0,this.options.maxPayload);try{const e=TZ.parse(l);e[DZ.extensionName]&&(n.accept(e[DZ.extensionName]),u[DZ.extensionName]=n)}catch(n){return void jZ(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const s={origin:e.headers[""+(8===o?"sec-websocket-origin":"origin")],secure:!(!e.socket.authorized&&!e.socket.encrypted),req:e};if(2===this.options.verifyClient.length)return void this.options.verifyClient(s,((s,o,a,l)=>{if(!s)return NZ(t,o||401,a,l);this.completeUpgrade(u,i,c,e,t,n,r)}));if(!this.options.verifyClient(s))return NZ(t,401)}this.completeUpgrade(u,i,c,e,t,n,r)}completeUpgrade(e,t,n,r,i,s,o){if(!i.readable||!i.writable)return i.destroy();if(i[RZ])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return NZ(i,503);const a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${SZ("sha1").update(t+CZ).digest("base64")}`],c=new this.options.WebSocket(null,void 0,this.options);if(n.size){const e=this.options.handleProtocols?this.options.handleProtocols(n,r):n.values().next().value;e&&(a.push(`Sec-WebSocket-Protocol: ${e}`),c._protocol=e)}if(e[DZ.extensionName]){const t=e[DZ.extensionName].params,n=TZ.format({[DZ.extensionName]:[t]});a.push(`Sec-WebSocket-Extensions: ${n}`),c._extensions=e}this.emit("headers",a,r),i.write(a.concat("\r\n").join("\r\n")),i.removeListener("error",PZ),c.setSocket(i,s,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(c),c.on("close",(()=>{this.clients.delete(c),this._shouldEmitClose&&!this.clients.size&&process.nextTick(IZ,this)}))),o(c,r)}};function IZ(e){e._state=2,e.emit("close")}function PZ(){this.destroy()}function NZ(e,t,n,r){n=n||EZ.STATUS_CODES[t],r={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(n),...r},e.once("finish",e.destroy),e.end(`HTTP/1.1 ${t} ${EZ.STATUS_CODES[t]}\r\n`+Object.keys(r).map((e=>`${e}: ${r[e]}`)).join("\r\n")+"\r\n\r\n"+n)}function jZ(e,t,n,r,i){if(e.listenerCount("wsClientError")){const r=new Error(i);Error.captureStackTrace(r,jZ),e.emit("wsClientError",r,n,t)}else NZ(n,r,i)}const FZ=YY;FZ.createWebSocketStream=bZ,FZ.Server=LZ,FZ.Receiver=qK,FZ.Sender=XK,FZ.WebSocket=FZ,FZ.WebSocketServer=FZ.Server;var BZ=FZ,MZ={exports:{}},UZ=Object.getOwnPropertySymbols,qZ=Object.prototype.hasOwnProperty,HZ=Object.prototype.propertyIsEnumerable;var $Z=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,r,i=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),s=1;s<arguments.length;s++){for(var o in n=Object(arguments[s]))qZ.call(n,o)&&(i[o]=n[o]);if(UZ){r=UZ(n);for(var a=0;a<r.length;a++)HZ.call(n,r[a])&&(i[r[a]]=n[r[a]])}}return i};!function(){var e=$Z,t=xU,n={origin:"*",methods:"GET,HEAD,PUT,PATCH,POST,DELETE",preflightContinue:!1,optionsSuccessStatus:204};function r(e){return"string"==typeof e||e instanceof String}function i(e,t){if(Array.isArray(t)){for(var n=0;n<t.length;++n)if(i(e,t[n]))return!0;return!1}return r(t)?e===t:t instanceof RegExp?t.test(e):!!t}function s(e,t){var n,s=t.headers.origin,o=[];return e.origin&&"*"!==e.origin?r(e.origin)?(o.push([{key:"Access-Control-Allow-Origin",value:e.origin}]),o.push([{key:"Vary",value:"Origin"}])):(n=i(s,e.origin),o.push([{key:"Access-Control-Allow-Origin",value:!!n&&s}]),o.push([{key:"Vary",value:"Origin"}])):o.push([{key:"Access-Control-Allow-Origin",value:"*"}]),o}function o(e){return!0===e.credentials?{key:"Access-Control-Allow-Credentials",value:"true"}:null}function a(e){var t=e.exposedHeaders;return t?(t.join&&(t=t.join(",")),t&&t.length?{key:"Access-Control-Expose-Headers",value:t}:null):null}function c(e,n){for(var r=0,i=e.length;r<i;r++){var s=e[r];s&&(Array.isArray(s)?c(s,n):"Vary"===s.key&&s.value?t(n,s.value):s.value&&n.setHeader(s.key,s.value))}}MZ.exports=function(t){var r=null;return r="function"==typeof t?t:function(e,n){n(null,t)},function(t,i,l){r(t,(function(r,u){if(r)l(r);else{var p=e({},n,u),h=null;p.origin&&"function"==typeof p.origin?h=p.origin:p.origin&&(h=function(e,t){t(null,p.origin)}),h?h(t.headers.origin,(function(e,n){e||!n?l(e):(p.origin=n,function(e,t,n,r){var i=[];"OPTIONS"===(t.method&&t.method.toUpperCase&&t.method.toUpperCase())?(i.push(s(e,t)),i.push(o(e)),i.push(function(e){var t=e.methods;return t.join&&(t=e.methods.join(",")),{key:"Access-Control-Allow-Methods",value:t}}(e)),i.push(function(e,t){var n=e.allowedHeaders||e.headers,r=[];return n?n.join&&(n=n.join(",")):(n=t.headers["access-control-request-headers"],r.push([{key:"Vary",value:"Access-Control-Request-Headers"}])),n&&n.length&&r.push([{key:"Access-Control-Allow-Headers",value:n}]),r}(e,t)),i.push(function(e){var t=("number"==typeof e.maxAge||e.maxAge)&&e.maxAge.toString();return t&&t.length?{key:"Access-Control-Max-Age",value:t}:null}(e)),i.push(a(e)),c(i,n),e.preflightContinue?r():(n.statusCode=e.optionsSuccessStatus,n.setHeader("Content-Length","0"),n.end())):(i.push(s(e,t)),i.push(o(e)),i.push(a(e)),c(i,n),r())}(p,t,i,l))})):l()}}))}}}();var zZ=MZ.exports;Object.defineProperty(LG,"__esModule",{value:!0}),LG.Server=LG.BaseServer=void 0;const WZ=L,GZ=S,VZ=PG,KZ=NG,YZ=p,ZZ=jV,QZ=eq,JZ=BZ,XZ=DV,eQ=BG,tQ=(0,ah.default)("engine"),nQ=Symbol("responseHeaders");class rQ extends YZ.EventEmitter{constructor(e={}){super(),this.middlewares=[],this.clients={},this.clientsCount=0,this.opts=Object.assign({wsEngine:JZ.Server,pingTimeout:2e4,pingInterval:25e3,upgradeTimeout:1e4,maxHttpBufferSize:1e6,transports:["polling","websocket"],allowUpgrades:!0,httpCompression:{threshold:1024},cors:!1,allowEIO3:!1},e),e.cookie&&(this.opts.cookie=Object.assign({name:"io",path:"/",httpOnly:!1!==e.cookie.path,sameSite:"lax"},e.cookie)),this.opts.cors&&this.use(zZ(this.opts.cors)),e.perMessageDeflate&&(this.opts.perMessageDeflate=Object.assign({threshold:1024},e.perMessageDeflate)),this.init()}_computePath(e){let t=(e.path||"/engine.io").replace(/\/$/,"");return!1!==e.addTrailingSlash&&(t+="/"),t}upgrades(e){return this.opts.allowUpgrades&&KZ.default[e].upgradesTo||[]}verify(e,t,n){const r=e._query.transport;if(!~this.opts.transports.indexOf(r)||"webtransport"===r)return tQ('unknown transport "%s"',r),n(sQ.errors.UNKNOWN_TRANSPORT,{transport:r});const i=function(e){if((e+="").length<1)return!1;if(!cQ[e.charCodeAt(0)])return tQ('invalid header, index 0, char "%s"',e.charCodeAt(0)),!0;if(e.length<2)return!1;if(!cQ[e.charCodeAt(1)])return tQ('invalid header, index 1, char "%s"',e.charCodeAt(1)),!0;if(e.length<3)return!1;if(!cQ[e.charCodeAt(2)])return tQ('invalid header, index 2, char "%s"',e.charCodeAt(2)),!0;if(e.length<4)return!1;if(!cQ[e.charCodeAt(3)])return tQ('invalid header, index 3, char "%s"',e.charCodeAt(3)),!0;for(let t=4;t<e.length;++t)if(!cQ[e.charCodeAt(t)])return tQ('invalid header, index "%i", char "%s"',t,e.charCodeAt(t)),!0;return!1}(e.headers.origin);if(i){const t=e.headers.origin;return e.headers.origin=null,tQ("origin header invalid"),n(sQ.errors.BAD_REQUEST,{name:"INVALID_ORIGIN",origin:t})}const s=e._query.sid;if(!s)return"GET"!==e.method?n(sQ.errors.BAD_HANDSHAKE_METHOD,{method:e.method}):"websocket"!==r||t?this.opts.allowRequest?this.opts.allowRequest(e,((e,t)=>{if(!t)return n(sQ.errors.FORBIDDEN,{message:e});n()})):n():(tQ("invalid transport upgrade"),n(sQ.errors.BAD_REQUEST,{name:"TRANSPORT_HANDSHAKE_ERROR"}));{if(!this.clients.hasOwnProperty(s))return tQ('unknown sid "%s"',s),n(sQ.errors.UNKNOWN_SID,{sid:s});const e=this.clients[s].transport.name;if(!t&&e!==r)return tQ("bad request: unexpected transport without upgrade"),n(sQ.errors.BAD_REQUEST,{name:"TRANSPORT_MISMATCH",transport:r,previousTransport:e})}n()}use(e){this.middlewares.push(e)}_applyMiddlewares(e,t,n){if(0===this.middlewares.length)return tQ("no middleware to apply, skipping"),n();const r=i=>{tQ("applying middleware n°%d",i+1),this.middlewares[i](e,t,(e=>{if(e)return n(e);i+1<this.middlewares.length?r(i+1):n()}))};r(0)}close(){tQ("closing all open clients");for(let e in this.clients)this.clients.hasOwnProperty(e)&&this.clients[e].close(!0);return this.cleanup(),this}generateId(e){return VZ.generateId()}async handshake(e,t,n){const r="4"===t._query.EIO?4:3;if(3===r&&!this.opts.allowEIO3)return tQ("unsupported protocol version"),this.emit("connection_error",{req:t,code:sQ.errors.UNSUPPORTED_PROTOCOL_VERSION,message:sQ.errorMessages[sQ.errors.UNSUPPORTED_PROTOCOL_VERSION],context:{protocol:r}}),void n(sQ.errors.UNSUPPORTED_PROTOCOL_VERSION);let i;try{i=await this.generateId(t)}catch(e){return tQ("error while generating an id"),this.emit("connection_error",{req:t,code:sQ.errors.BAD_REQUEST,message:sQ.errorMessages[sQ.errors.BAD_REQUEST],context:{name:"ID_GENERATION_ERROR",error:e}}),void n(sQ.errors.BAD_REQUEST)}tQ('handshaking client "%s"',i);try{var s=this.createTransport(e,t);"polling"===e?(s.maxHttpBufferSize=this.opts.maxHttpBufferSize,s.httpCompression=this.opts.httpCompression):"websocket"===e&&(s.perMessageDeflate=this.opts.perMessageDeflate)}catch(r){return tQ('error handshaking to transport "%s"',e),this.emit("connection_error",{req:t,code:sQ.errors.BAD_REQUEST,message:sQ.errorMessages[sQ.errors.BAD_REQUEST],context:{name:"TRANSPORT_HANDSHAKE_ERROR",error:r}}),void n(sQ.errors.BAD_REQUEST)}const o=new ZZ.Socket(i,this,s,t,r);return s.on("headers",((e,t)=>{!t._query.sid&&(this.opts.cookie&&(e["Set-Cookie"]=[(0,QZ.serialize)(this.opts.cookie.name,i,this.opts.cookie)]),this.emit("initial_headers",e,t)),this.emit("headers",e,t)})),s.onRequest(t),this.clients[i]=o,this.clientsCount++,o.once("close",(()=>{delete this.clients[i],this.clientsCount--})),this.emit("connection",o),s}async onWebTransportSession(e){const t=setTimeout((()=>{tQ("the client failed to establish a bidirectional stream in the given period"),e.close()}),this.opts.upgradeTimeout),n=e.incomingBidirectionalStreams.getReader(),r=await n.read();if(r.done)return void tQ("session is closed");const i=r.value,s=(0,eQ.createPacketDecoderStream)(this.opts.maxHttpBufferSize,"nodebuffer"),o=i.readable.pipeThrough(s).getReader(),{value:a,done:c}=await o.read();if(c)return void tQ("stream is closed");if(clearTimeout(t),"open"!==a.type)return tQ("invalid WebTransport handshake"),e.close();if(void 0===a.data){const t=new XZ.WebTransport(e,i,o),n=VZ.generateId();tQ('handshaking client "%s" (WebTransport)',n);const r=new ZZ.Socket(n,this,t,null,4);return this.clients[n]=r,this.clientsCount++,r.once("close",(()=>{delete this.clients[n],this.clientsCount--})),void this.emit("connection",r)}const l=function(e){try{const t=JSON.parse(e);if("string"==typeof t.sid)return t.sid}catch(e){}}(a.data);if(!l)return tQ("invalid WebTransport handshake"),e.close();const u=this.clients[l];if(u)if(u.upgrading)tQ("transport has already been trying to upgrade"),e.close();else if(u.upgraded)tQ("transport had already been upgraded"),e.close();else{tQ("upgrading existing transport");const t=new XZ.WebTransport(e,i,o);u.maybeUpgrade(t)}else tQ("upgrade attempt for closed client"),e.close()}}LG.BaseServer=rQ,rQ.errors={UNKNOWN_TRANSPORT:0,UNKNOWN_SID:1,BAD_HANDSHAKE_METHOD:2,BAD_REQUEST:3,FORBIDDEN:4,UNSUPPORTED_PROTOCOL_VERSION:5},rQ.errorMessages={0:"Transport unknown",1:"Session ID unknown",2:"Bad handshake method",3:"Bad request",4:"Forbidden",5:"Unsupported protocol version"};class iQ{constructor(e,t){this.req=e,this.socket=t,e[nQ]={}}setHeader(e,t){this.req[nQ][e]=t}getHeader(e){return this.req[nQ][e]}removeHeader(e){delete this.req[nQ][e]}write(){}writeHead(){}end(){this.socket.destroy()}}let sQ=class e extends rQ{init(){~this.opts.transports.indexOf("websocket")&&(this.ws&&this.ws.close(),this.ws=new this.opts.wsEngine({noServer:!0,clientTracking:!1,perMessageDeflate:this.opts.perMessageDeflate,maxPayload:this.opts.maxHttpBufferSize}),"function"==typeof this.ws.on&&this.ws.on("headers",((e,t)=>{const n=t[nQ]||{};delete t[nQ];!t._query.sid&&this.emit("initial_headers",n,t),this.emit("headers",n,t),tQ("writing headers: %j",n),Object.keys(n).forEach((t=>{e.push(`${t}: ${n[t]}`)}))})))}cleanup(){this.ws&&(tQ("closing webSocketServer"),this.ws.close())}prepare(e){e._query||(e._query=~e.url.indexOf("?")?WZ.parse((0,GZ.parse)(e.url).query):{})}createTransport(e,t){return new KZ.default[e](t)}handleRequest(t,n){tQ('handling "%s" http request "%s"',t.method,t.url),this.prepare(t),t.res=n;const r=(r,i)=>{if(void 0!==r)return this.emit("connection_error",{req:t,code:r,message:e.errorMessages[r],context:i}),void oQ(n,r,i);if(t._query.sid)tQ("setting new request for existing client"),this.clients[t._query.sid].transport.onRequest(t);else{const e=(e,t)=>oQ(n,e,t);this.handshake(t._query.transport,t,e)}};this._applyMiddlewares(t,n,(n=>{n?r(e.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!1,r)}))}handleUpgrade(t,n,r){this.prepare(t);const i=new iQ(t,n),s=(s,o)=>{if(void 0!==s)return this.emit("connection_error",{req:t,code:s,message:e.errorMessages[s],context:o}),void aQ(n,s,o);const a=Buffer.from(r);r=null,i.writeHead(),this.ws.handleUpgrade(t,n,a,(e=>{this.onWebSocket(t,n,e)}))};this._applyMiddlewares(t,i,(n=>{n?s(e.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!0,s)}))}onWebSocket(e,t,n){if(n.on("error",i),void 0!==KZ.default[e._query.transport]&&!KZ.default[e._query.transport].prototype.handlesUpgrades)return tQ("transport doesnt handle upgraded requests"),void n.close();const r=e._query.sid;if(e.websocket=n,r){const t=this.clients[r];if(t)if(t.upgrading)tQ("transport has already been trying to upgrade"),n.close();else if(t.upgraded)tQ("transport had already been upgraded"),n.close();else{tQ("upgrading existing transport"),n.removeListener("error",i);const r=this.createTransport(e._query.transport,e);r.perMessageDeflate=this.opts.perMessageDeflate,t.maybeUpgrade(r)}else tQ("upgrade attempt for closed client"),n.close()}else{const n=(e,n)=>aQ(t,e,n);this.handshake(e._query.transport,e,n)}function i(){tQ("websocket error before upgrade")}}attach(e,t={}){const n=this._computePath(t),r=t.destroyUpgradeTimeout||1e3;function i(e){return n===e.url.slice(0,n.length)}const s=e.listeners("request").slice(0);e.removeAllListeners("request"),e.on("close",this.close.bind(this)),e.on("listening",this.init.bind(this)),e.on("request",((t,r)=>{if(i(t))tQ('intercepting request for path "%s"',n),this.handleRequest(t,r);else{let n=0;const i=s.length;for(;n<i;n++)s[n].call(e,t,r)}})),~this.opts.transports.indexOf("websocket")&&e.on("upgrade",((e,n,s)=>{i(e)?this.handleUpgrade(e,n,s):!1!==t.destroyUpgrade&&setTimeout((function(){if(n.writable&&n.bytesWritten<=0)return n.on("error",(e=>{tQ("error while destroying upgrade: %s",e.message)})),n.end()}),r)}))}};function oQ(e,t,n){const r=t===sQ.errors.FORBIDDEN?403:400,i=n&&n.message?n.message:sQ.errorMessages[t];e.writeHead(r,{"Content-Type":"application/json"}),e.end(JSON.stringify({code:t,message:i}))}function aQ(e,t,n={}){if(e.on("error",(()=>{tQ("ignoring error from closed connection")})),e.writable){const r=n.message||sQ.errorMessages[t],i=Buffer.byteLength(r);e.write("HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-type: text/html\r\nContent-Length: "+i+"\r\n\r\n"+r)}e.destroy()}LG.Server=sQ;const cQ=[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];var lQ={},uQ={},pQ={};Object.defineProperty(pQ,"__esModule",{value:!0}),pQ.Polling=void 0;const hQ=FG,dQ=T,fQ=KM,mQ=(0,ah.default)("engine:polling"),gQ={gzip:dQ.createGzip,deflate:dQ.createDeflate};let yQ=class extends hQ.Transport{constructor(e){super(e),this.closeTimeout=3e4}get name(){return"polling"}get supportsFraming(){return!1}onRequest(e){const t=e.res;e.res=null,"get"===e.getMethod()?this.onPollRequest(e,t):"post"===e.getMethod()?this.onDataRequest(e,t):(t.writeStatus("500 Internal Server Error"),t.end())}onPollRequest(e,t){if(this.req)return mQ("request overlap"),this.onError("overlap from client"),t.writeStatus("500 Internal Server Error"),void t.end();mQ("setting request"),this.req=e,this.res=t;e.cleanup=()=>{this.req=this.res=null},t.onAborted((()=>{this.writable=!1,this.onError("poll connection closed prematurely")})),this.writable=!0,this.emit("drain"),this.writable&&this.shouldClose&&(mQ("triggering empty send to append close packet"),this.send([{type:"noop"}]))}onDataRequest(e,t){if(this.dataReq)return this.onError("data request overlap from client"),t.writeStatus("500 Internal Server Error"),void t.end();const n=Number(e.headers["content-length"]);if(!n)return this.onError("content-length header required"),void t.writeStatus("411 Length Required").end();if(n>this.maxHttpBufferSize)return this.onError("payload too large"),void t.writeStatus("413 Payload Too Large").end();if("application/octet-stream"===e.headers["content-type"]&&4===this.protocol)return this.onError("invalid content");let r;this.dataReq=e,this.dataRes=t;let i=0;const s={"Content-Type":"text/html"};this.headers(e,s);for(let e in s)t.writeHeader(e,String(s[e]));const o=e=>{this.onData(e.toString()),this.onDataRequestCleanup(),t.cork((()=>{t.end("ok")}))};t.onAborted((()=>{this.onDataRequestCleanup(),this.onError("data request connection closed prematurely")})),t.onData(((e,s)=>{const a=i+e.byteLength;if(a>n)return this.onError("content-length mismatch"),void t.close();if(!r){if(s)return void o(Buffer.from(e));r=Buffer.allocUnsafe(n)}if(Buffer.from(e).copy(r,i),s)return a!=n?(this.onError("content-length mismatch"),t.writeStatus("400 Content-Length Mismatch").end(),void this.onDataRequestCleanup()):void o(r);i=a}))}onDataRequestCleanup(){this.dataReq=this.dataRes=null}onData(e){mQ('received "%s"',e);const t=e=>{if("close"===e.type)return mQ("got xhr close packet"),this.onClose(),!1;this.onPacket(e)};3===this.protocol?this.parser.decodePayload(e,t):this.parser.decodePayload(e).forEach(t)}onClose(){this.writable&&this.send([{type:"noop"}]),super.onClose()}send(e){this.writable=!1,this.shouldClose&&(mQ("appending close packet to payload"),e.push({type:"close"}),this.shouldClose(),this.shouldClose=null);const t=t=>{const n=e.some((e=>e.options&&e.options.compress));this.write(t,{compress:n})};3===this.protocol?this.parser.encodePayload(e,this.supportsBinary,t):this.parser.encodePayload(e,t)}write(e,t){mQ('writing "%s"',e),this.doWrite(e,t,(()=>{this.req.cleanup()}))}doWrite(e,t,n){const r="string"==typeof e,i={"Content-Type":r?"text/plain; charset=UTF-8":"application/octet-stream"},s=e=>{this.headers(this.req,i),this.res.cork((()=>{Object.keys(i).forEach((e=>{this.res.writeHeader(e,String(i[e]))})),this.res.end(e)})),n()};if(!this.httpCompression||!t.compress)return void s(e);if((r?Buffer.byteLength(e):e.length)<this.httpCompression.threshold)return void s(e);const o=fQ(this.req).encodings(["gzip","deflate"]);o?this.compress(e,o,((e,t)=>{if(e)return this.res.writeStatus("500 Internal Server Error"),this.res.end(),void n(e);i["Content-Encoding"]=o,s(t)})):s(e)}compress(e,t,n){mQ("compressing");const r=[];let i=0;gQ[t](this.httpCompression).on("error",n).on("data",(function(e){r.push(e),i+=e.length})).on("end",(function(){n(null,Buffer.concat(r,i))})).end(e)}doClose(e){let t;mQ("closing");const n=()=>{clearTimeout(t),e(),this.onClose()};this.writable?(mQ("transport writable - closing right away"),this.send([{type:"close"}]),n()):this.discarded?(mQ("transport discarded - closing right away"),n()):(mQ("transport not writable - buffering orderly close"),this.shouldClose=n,t=setTimeout(n,this.closeTimeout))}headers(e,t){t=t||{};const n=e.headers["user-agent"];return n&&(~n.indexOf(";MSIE")||~n.indexOf("Trident/"))&&(t["X-XSS-Protection"]="0"),t["cache-control"]="no-store",this.emit("headers",t,e),t}};pQ.Polling=yQ;var vQ={};Object.defineProperty(vQ,"__esModule",{value:!0}),vQ.WebSocket=void 0;const bQ=FG,_Q=(0,ah.default)("engine:ws");let xQ=class extends bQ.Transport{constructor(e){super(e),this.writable=!1,this.perMessageDeflate=null}get name(){return"websocket"}get handlesUpgrades(){return!0}get supportsFraming(){return!0}send(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t+1===e.length,i=e=>{const t="string"!=typeof e,n=this.perMessageDeflate&&Buffer.byteLength(e)>this.perMessageDeflate.threshold;_Q('writing "%s"',e),this.socket.send(e,t,n),r&&(this.writable=!0,this.emit("drain"))};n.options&&"string"==typeof n.options.wsPreEncoded?i(n.options.wsPreEncoded):this.parser.encodePacket(n,this.supportsBinary,i)}}doClose(e){_Q("closing"),e&&e(),this.socket.end()}};vQ.WebSocket=xQ,Object.defineProperty(uQ,"__esModule",{value:!0});const wQ=pQ,EQ=vQ;uQ.default={polling:wQ.Polling,websocket:EQ.WebSocket},Object.defineProperty(lQ,"__esModule",{value:!0}),lQ.uServer=void 0;const SQ=LG,TQ=uQ,DQ=(0,ah.default)("engine:uws");class kQ extends SQ.BaseServer{init(){}cleanup(){}prepare(e,t){e.method=e.getMethod().toUpperCase(),e.url=e.getUrl();const n=new URLSearchParams(e.getQuery());e._query=Object.fromEntries(n.entries()),e.headers={},e.forEach(((t,n)=>{e.headers[t]=n})),e.connection={remoteAddress:Buffer.from(t.getRemoteAddressAsText()).toString()},t.onAborted((()=>{DQ("response has been aborted")}))}createTransport(e,t){return new TQ.default[e](t)}attach(e,t={}){const n=this._computePath(t);e.any(n,this.handleRequest.bind(this)).ws(n,{compression:t.compression,idleTimeout:t.idleTimeout,maxBackpressure:t.maxBackpressure,maxPayloadLength:this.opts.maxHttpBufferSize,upgrade:this.handleUpgrade.bind(this),open:e=>{const t=e.getUserData().transport;t.socket=e,t.writable=!0,t.emit("drain")},message:(e,t,n)=>{e.getUserData().transport.onData(n?t:Buffer.from(t).toString())},close:(e,t,n)=>{e.getUserData().transport.onClose(t,n)}})}_applyMiddlewares(e,t,n){if(0===this.middlewares.length)return n();e.res=new AQ(t),super._applyMiddlewares(e,e.res,(t=>{e.res.writeHead(),n(t)}))}handleRequest(e,t){DQ('handling "%s" http request "%s"',t.getMethod(),t.getUrl()),this.prepare(t,e),t.res=e;const n=(n,r)=>{if(void 0!==n)return this.emit("connection_error",{req:t,code:n,message:SQ.Server.errorMessages[n],context:r}),void this.abortRequest(t.res,n,r);if(t._query.sid)DQ("setting new request for existing client"),this.clients[t._query.sid].transport.onRequest(t);else{const n=(t,n)=>this.abortRequest(e,t,n);this.handshake(t._query.transport,t,n)}};this._applyMiddlewares(t,e,(e=>{e?n(SQ.Server.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!1,n)}))}handleUpgrade(e,t,n){DQ("on upgrade"),this.prepare(t,e),t.res=e;const r=async(r,i)=>{if(void 0!==r)return this.emit("connection_error",{req:t,code:r,message:SQ.Server.errorMessages[r],context:i}),void this.abortRequest(e,r,i);const s=t._query.sid;let o;if(s){const n=this.clients[s];n?n.upgrading?(DQ("transport has already been trying to upgrade"),e.close()):n.upgraded?(DQ("transport had already been upgraded"),e.close()):(DQ("upgrading existing transport"),o=this.createTransport(t._query.transport,t),n.maybeUpgrade(o)):(DQ("upgrade attempt for closed client"),e.close())}else if(o=await this.handshake(t._query.transport,t,((t,n)=>this.abortRequest(e,t,n))),!o)return;t.res.writeStatus("101 Switching Protocols"),e.upgrade({transport:o},t.getHeader("sec-websocket-key"),t.getHeader("sec-websocket-protocol"),t.getHeader("sec-websocket-extensions"),n)};this._applyMiddlewares(t,e,(e=>{e?r(SQ.Server.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!0,r)}))}abortRequest(e,t,n){const r=t===SQ.Server.errors.FORBIDDEN?"403 Forbidden":"400 Bad Request",i=n&&n.message?n.message:SQ.Server.errorMessages[t];e.writeStatus(r),e.writeHeader("Content-Type","application/json"),e.end(JSON.stringify({code:t,message:i}))}}lQ.uServer=kQ;class AQ{constructor(e){this.res=e,this.statusWritten=!1,this.headers=[],this.isAborted=!1}set statusCode(e){e&&this.writeStatus(200===e?"200 OK":"204 No Content")}writeHead(e){this.statusCode=e}setHeader(e,t){Array.isArray(t)?t.forEach((t=>{this.writeHeader(e,t)})):this.writeHeader(e,t)}removeHeader(){}getHeader(){}writeStatus(e){if(!this.isAborted)return this.res.writeStatus(e),this.statusWritten=!0,this.writeBufferedHeaders(),this}writeHeader(e,t){this.isAborted||"Content-Length"!==e&&(this.statusWritten?this.res.writeHeader(e,t):this.headers.push([e,t]))}writeBufferedHeaders(){this.headers.forEach((([e,t])=>{this.res.writeHeader(e,t)}))}end(e){this.isAborted||this.res.cork((()=>{this.statusWritten||this.writeBufferedHeaders(),this.res.end(e)}))}onData(e){this.isAborted||this.res.onData(e)}onAborted(e){this.isAborted||this.res.onAborted((()=>{this.isAborted=!0,e()}))}cork(e){this.isAborted||this.res.cork(e)}}!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.protocol=e.Transport=e.Socket=e.uServer=e.parser=e.attach=e.listen=e.transports=e.Server=void 0;const t=w,n=LG;Object.defineProperty(e,"Server",{enumerable:!0,get:function(){return n.Server}});const r=NG;e.transports=r.default;const i=BG;e.parser=i;var s=lQ;Object.defineProperty(e,"uServer",{enumerable:!0,get:function(){return s.uServer}});var o=jV;Object.defineProperty(e,"Socket",{enumerable:!0,get:function(){return o.Socket}});var a=FG;function c(e,t){const r=new n.Server(t);return r.attach(e,t),r}Object.defineProperty(e,"Transport",{enumerable:!0,get:function(){return a.Transport}}),e.protocol=i.protocol,e.listen=function(e,n,r){"function"==typeof n&&(r=n,n={});const i=(0,t.createServer)((function(e,t){t.writeHead(501),t.end("Not Implemented")})),s=c(i,n);return s.httpServer=i,i.listen(e,r),s},e.attach=c}(OG);var CQ={},RQ={};function OQ(e){if(e)return function(e){for(var t in OQ.prototype)e[t]=OQ.prototype[t];return e}(e)}OQ.prototype.on=OQ.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},OQ.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},OQ.prototype.off=OQ.prototype.removeListener=OQ.prototype.removeAllListeners=OQ.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<r.length;i++)if((n=r[i])===t||n.fn===t){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},OQ.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var i=(n=n.slice(0)).length;r<i;++r)n[r].apply(this,t)}return this},OQ.prototype.emitReserved=OQ.prototype.emit,OQ.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},OQ.prototype.hasListeners=function(e){return!!this.listeners(e).length};var LQ=H(Object.freeze({__proto__:null,Emitter:OQ})),IQ={},PQ={};Object.defineProperty(PQ,"__esModule",{value:!0}),PQ.hasBinary=PQ.isBinary=void 0;const NQ="function"==typeof ArrayBuffer,jQ=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,FQ=Object.prototype.toString,BQ="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===FQ.call(Blob),MQ="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===FQ.call(File);function UQ(e){return NQ&&(e instanceof ArrayBuffer||jQ(e))||BQ&&e instanceof Blob||MQ&&e instanceof File}PQ.isBinary=UQ,PQ.hasBinary=function e(t,n){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let n=0,r=t.length;n<r;n++)if(e(t[n]))return!0;return!1}if(UQ(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return e(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e(t[n]))return!0;return!1},Object.defineProperty(IQ,"__esModule",{value:!0}),IQ.reconstructPacket=IQ.deconstructPacket=void 0;const qQ=PQ;function HQ(e,t){if(!e)return e;if((0,qQ.isBinary)(e)){const n={_placeholder:!0,num:t.length};return t.push(e),n}if(Array.isArray(e)){const n=new Array(e.length);for(let r=0;r<e.length;r++)n[r]=HQ(e[r],t);return n}if("object"==typeof e&&!(e instanceof Date)){const n={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=HQ(e[r],t));return n}return e}function $Q(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 n=0;n<e.length;n++)e[n]=$Q(e[n],t);else if("object"==typeof e)for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=$Q(e[n],t));return e}IQ.deconstructPacket=function(e){const t=[],n=e.data,r=e;return r.data=HQ(n,t),r.attachments=t.length,{packet:r,buffers:t}},IQ.reconstructPacket=function(e,t){return e.data=$Q(e.data,t),delete e.attachments,e},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Decoder=e.Encoder=e.PacketType=e.protocol=void 0;const t=LQ,n=IQ,r=PQ,i=(0,ah.default)("socket.io-parser"),s=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var o;e.protocol=5,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"}(o=e.PacketType||(e.PacketType={}));function a(e){return"[object Object]"===Object.prototype.toString.call(e)}e.Encoder=class{constructor(e){this.replacer=e}encode(e){return i("encoding packet %j",e),e.type!==o.EVENT&&e.type!==o.ACK||!(0,r.hasBinary)(e)?[this.encodeAsString(e)]:this.encodeAsBinary({type:e.type===o.EVENT?o.BINARY_EVENT:o.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id})}encodeAsString(e){let t=""+e.type;return e.type!==o.BINARY_EVENT&&e.type!==o.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)),i("encoded %j as %s",e,t),t}encodeAsBinary(e){const t=(0,n.deconstructPacket)(e),r=this.encodeAsString(t.packet),i=t.buffers;return i.unshift(r),i}};class c extends t.Emitter{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 n=t.type===o.BINARY_EVENT;n||t.type===o.BINARY_ACK?(t.type=n?o.EVENT:o.ACK,this.reconstructor=new l(t),0===t.attachments&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else{if(!(0,r.isBinary)(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 n={type:Number(e.charAt(0))};if(void 0===o[n.type])throw new Error("unknown packet type "+n.type);if(n.type===o.BINARY_EVENT||n.type===o.BINARY_ACK){const r=t+1;for(;"-"!==e.charAt(++t)&&t!=e.length;);const i=e.substring(r,t);if(i!=Number(i)||"-"!==e.charAt(t))throw new Error("Illegal attachments");n.attachments=Number(i)}if("/"===e.charAt(t+1)){const r=t+1;for(;++t;){if(","===e.charAt(t))break;if(t===e.length)break}n.nsp=e.substring(r,t)}else n.nsp="/";const r=e.charAt(t+1);if(""!==r&&Number(r)==r){const r=t+1;for(;++t;){const n=e.charAt(t);if(null==n||Number(n)!=n){--t;break}if(t===e.length)break}n.id=Number(e.substring(r,t+1))}if(e.charAt(++t)){const r=this.tryParse(e.substr(t));if(!c.isPayloadValid(n.type,r))throw new Error("invalid payload");n.data=r}return i("decoded %s as %j",e,n),n}tryParse(e){try{return JSON.parse(e,this.reviver)}catch(e){return!1}}static isPayloadValid(e,t){switch(e){case o.CONNECT:return a(t);case o.DISCONNECT:return void 0===t;case o.CONNECT_ERROR:return"string"==typeof t||a(t);case o.EVENT:case o.BINARY_EVENT:return Array.isArray(t)&&("number"==typeof t[0]||"string"==typeof t[0]&&-1===s.indexOf(t[0]));case o.ACK:case o.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}e.Decoder=c;class l{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=(0,n.reconstructPacket)(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}}(RQ),Object.defineProperty(CQ,"__esModule",{value:!0}),CQ.Client=void 0;const zQ=RQ,WQ=S,GQ=ah("socket.io:client");CQ.Client=class{constructor(e,t){this.sockets=new Map,this.nsps=new Map,this.server=e,this.conn=t,this.encoder=e.encoder,this.decoder=new e._parser.Decoder,this.id=t.id,this.setup()}get request(){return this.conn.request}setup(){this.onclose=this.onclose.bind(this),this.ondata=this.ondata.bind(this),this.onerror=this.onerror.bind(this),this.ondecoded=this.ondecoded.bind(this),this.decoder.on("decoded",this.ondecoded),this.conn.on("data",this.ondata),this.conn.on("error",this.onerror),this.conn.on("close",this.onclose),this.connectTimeout=setTimeout((()=>{0===this.nsps.size?(GQ("no namespace joined yet, close the client"),this.close()):GQ("the client has already joined a namespace, nothing to do")}),this.server._connectTimeout)}connect(e,t={}){if(this.server._nsps.has(e))return GQ("connecting to namespace %s",e),this.doConnect(e,t);this.server._checkNamespace(e,t,(n=>{n?this.doConnect(e,t):(GQ("creation of namespace %s was denied",e),this._packet({type:zQ.PacketType.CONNECT_ERROR,nsp:e,data:{message:"Invalid namespace"}}))}))}doConnect(e,t){const n=this.server.of(e);n._add(this,t,(e=>{this.sockets.set(e.id,e),this.nsps.set(n.name,e),this.connectTimeout&&(clearTimeout(this.connectTimeout),this.connectTimeout=void 0)}))}_disconnect(){for(const e of this.sockets.values())e.disconnect();this.sockets.clear(),this.close()}_remove(e){if(this.sockets.has(e.id)){const t=this.sockets.get(e.id).nsp.name;this.sockets.delete(e.id),this.nsps.delete(t)}else GQ("ignoring remove for %s",e.id)}close(){"open"===this.conn.readyState&&(GQ("forcing transport close"),this.conn.close(),this.onclose("forced server close"))}_packet(e,t={}){if("open"!==this.conn.readyState)return void GQ("ignoring packet write %j",e);const n=t.preEncoded?e:this.encoder.encode(e);this.writeToEngine(n,t)}writeToEngine(e,t){if(t.volatile&&!this.conn.transport.writable)return void GQ("volatile packet is discarded since the transport is not currently writable");const n=Array.isArray(e)?e:[e];for(const e of n)this.conn.write(e,t)}ondata(e){try{this.decoder.add(e)}catch(e){GQ("invalid packet format"),this.onerror(e)}}ondecoded(e){let t,n;if(3===this.conn.protocol){const r=WQ.parse(e.nsp,!0);t=r.pathname,n=r.query}else t=e.nsp,n=e.data;const r=this.nsps.get(t);r||e.type!==zQ.PacketType.CONNECT?r&&e.type!==zQ.PacketType.CONNECT&&e.type!==zQ.PacketType.CONNECT_ERROR?process.nextTick((function(){r._onpacket(e)})):(GQ("invalid state (packet type: %s)",e.type),this.close()):this.connect(t,n)}onerror(e){for(const t of this.sockets.values())t._onerror(e);this.conn.close()}onclose(e,t){GQ("client close with reason %s",e),this.destroy();for(const n of this.sockets.values())n._onclose(e,t);this.sockets.clear(),this.decoder.destroy()}destroy(){this.conn.removeListener("data",this.ondata),this.conn.removeListener("error",this.onerror),this.conn.removeListener("close",this.onclose),this.decoder.removeListener("decoded",this.ondecoded),this.connectTimeout&&(clearTimeout(this.connectTimeout),this.connectTimeout=void 0)}};var VQ={},KQ={},YQ={};Object.defineProperty(YQ,"__esModule",{value:!0}),YQ.StrictEventEmitter=void 0;const ZQ=p;class QQ extends ZQ.EventEmitter{on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}emit(e,...t){return super.emit(e,...t)}emitReserved(e,...t){return super.emit(e,...t)}emitUntyped(e,...t){return super.emit(e,...t)}listeners(e){return super.listeners(e)}}YQ.StrictEventEmitter=QQ;var JQ,XQ,eJ={};function tJ(){if(JQ)return eJ;JQ=1,Object.defineProperty(eJ,"__esModule",{value:!0}),eJ.RemoteSocket=eJ.BroadcastOperator=void 0;const e=nJ(),t=RQ;class n{constructor(e,t=new Set,n=new Set,r={}){this.adapter=e,this.rooms=t,this.exceptRooms=n,this.flags=r}to(e){const t=new Set(this.rooms);return Array.isArray(e)?e.forEach((e=>t.add(e))):t.add(e),new n(this.adapter,t,this.exceptRooms,this.flags)}in(e){return this.to(e)}except(e){const t=new Set(this.exceptRooms);return Array.isArray(e)?e.forEach((e=>t.add(e))):t.add(e),new n(this.adapter,this.rooms,t,this.flags)}compress(e){const t=Object.assign({},this.flags,{compress:e});return new n(this.adapter,this.rooms,this.exceptRooms,t)}get volatile(){const e=Object.assign({},this.flags,{volatile:!0});return new n(this.adapter,this.rooms,this.exceptRooms,e)}get local(){const e=Object.assign({},this.flags,{local:!0});return new n(this.adapter,this.rooms,this.exceptRooms,e)}timeout(e){const t=Object.assign({},this.flags,{timeout:e});return new n(this.adapter,this.rooms,this.exceptRooms,t)}emit(n,...r){if(e.RESERVED_EVENTS.has(n))throw new Error(`"${String(n)}" is a reserved event name`);const i=[n,...r],s={type:t.PacketType.EVENT,data:i};if(!("function"==typeof i[i.length-1]))return this.adapter.broadcast(s,{rooms:this.rooms,except:this.exceptRooms,flags:this.flags}),!0;const o=i.pop();let a=!1,c=[];const l=setTimeout((()=>{a=!0,o.apply(this,[new Error("operation has timed out"),this.flags.expectSingleResponse?null:c])}),this.flags.timeout);let u=-1,p=0,h=0;const d=()=>{a||u!==p||c.length!==h||(clearTimeout(l),o.apply(this,[null,this.flags.expectSingleResponse?c[0]:c]))};return this.adapter.broadcastWithAck(s,{rooms:this.rooms,except:this.exceptRooms,flags:this.flags},(e=>{h+=e,p++,d()}),(e=>{c.push(e),d()})),this.adapter.serverCount().then((e=>{u=e,d()})),!0}emitWithAck(e,...t){return new Promise(((n,r)=>{t.push(((e,t)=>e?(e.responses=t,r(e)):n(t))),this.emit(e,...t)}))}allSockets(){if(!this.adapter)throw new Error("No adapter for this namespace, are you trying to get the list of clients of a dynamic namespace?");return this.adapter.sockets(this.rooms)}fetchSockets(){return this.adapter.fetchSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags}).then((t=>t.map((t=>t instanceof e.Socket?t:new r(this.adapter,t)))))}socketsJoin(e){this.adapter.addSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags},Array.isArray(e)?e:[e])}socketsLeave(e){this.adapter.delSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags},Array.isArray(e)?e:[e])}disconnectSockets(e=!1){this.adapter.disconnectSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags},e)}}eJ.BroadcastOperator=n;class r{constructor(e,t){this.id=t.id,this.handshake=t.handshake,this.rooms=new Set(t.rooms),this.data=t.data,this.operator=new n(e,new Set([this.id]),new Set,{expectSingleResponse:!0})}timeout(e){return this.operator.timeout(e)}emit(e,...t){return this.operator.emit(e,...t)}join(e){return this.operator.socketsJoin(e)}leave(e){return this.operator.socketsLeave(e)}disconnect(e=!1){return this.operator.disconnectSockets(e),this}}return eJ.RemoteSocket=r,eJ}function nJ(){return XQ||(XQ=1,function(e){var t=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.Socket=e.RESERVED_EVENTS=void 0;const n=RQ,r=t(ah),i=YQ,s=t(PG),o=tJ(),a=(0,r.default)("socket.io:socket"),c=new Set(["transport error","transport close","forced close","ping timeout","server shutting down","forced server close"]);function l(){}e.RESERVED_EVENTS=new Set(["connect","connect_error","disconnect","disconnecting","newListener","removeListener"]);class u extends i.StrictEventEmitter{constructor(e,t,r,i){super(),this.nsp=e,this.client=t,this.recovered=!1,this.data={},this.connected=!1,this.acks=new Map,this.fns=[],this.flags={},this.server=e.server,this.adapter=this.nsp.adapter,i?(this.id=i.sid,this.pid=i.pid,i.rooms.forEach((e=>this.join(e))),this.data=i.data,i.missedPackets.forEach((e=>{this.packet({type:n.PacketType.EVENT,data:e})})),this.recovered=!0):(3===t.conn.protocol?this.id="/"!==e.name?e.name+"#"+t.id:t.id:this.id=s.default.generateId(),this.server._opts.connectionStateRecovery&&(this.pid=s.default.generateId())),this.handshake=this.buildHandshake(r),this.on("error",l)}buildHandshake(e){var t,n,r,i;return{headers:(null===(t=this.request)||void 0===t?void 0:t.headers)||{},time:new Date+"",address:this.conn.remoteAddress,xdomain:!!(null===(n=this.request)||void 0===n?void 0:n.headers.origin),secure:!this.request||!!this.request.connection.encrypted,issued:+new Date,url:null===(r=this.request)||void 0===r?void 0:r.url,query:(null===(i=this.request)||void 0===i?void 0:i._query)||{},auth:e}}emit(t,...r){if(e.RESERVED_EVENTS.has(t))throw new Error(`"${String(t)}" is a reserved event name`);const i=[t,...r],s={type:n.PacketType.EVENT,data:i};if("function"==typeof i[i.length-1]){const e=this.nsp._ids++;a("emitting packet with ack id %d",e),this.registerAckCallback(e,i.pop()),s.id=e}const o=Object.assign({},this.flags);return this.flags={},this.nsp.server.opts.connectionStateRecovery?this.adapter.broadcast(s,{rooms:new Set([this.id]),except:new Set,flags:o}):(this.notifyOutgoingListeners(s),this.packet(s,o)),!0}emitWithAck(e,...t){const n=void 0!==this.flags.timeout;return new Promise(((r,i)=>{t.push(((e,t)=>n?e?i(e):r(t):r(e))),this.emit(e,...t)}))}registerAckCallback(e,t){const n=this.flags.timeout;if(void 0===n)return void this.acks.set(e,t);const r=setTimeout((()=>{a("event with ack id %d has timed out after %d ms",e,n),this.acks.delete(e),t.call(this,new Error("operation has timed out"))}),n);this.acks.set(e,((...e)=>{clearTimeout(r),t.apply(this,[null,...e])}))}to(e){return this.newBroadcastOperator().to(e)}in(e){return this.newBroadcastOperator().in(e)}except(e){return this.newBroadcastOperator().except(e)}send(...e){return this.emit("message",...e),this}write(...e){return this.emit("message",...e),this}packet(e,t={}){e.nsp=this.nsp.name,t.compress=!1!==t.compress,this.client._packet(e,t)}join(e){return a("join room %s",e),this.adapter.addAll(this.id,new Set(Array.isArray(e)?e:[e]))}leave(e){return a("leave room %s",e),this.adapter.del(this.id,e)}leaveAll(){this.adapter.delAll(this.id)}_onconnect(){a("socket connected - writing packet"),this.connected=!0,this.join(this.id),3===this.conn.protocol?this.packet({type:n.PacketType.CONNECT}):this.packet({type:n.PacketType.CONNECT,data:{sid:this.id,pid:this.pid}})}_onpacket(e){switch(a("got packet %j",e),e.type){case n.PacketType.EVENT:case n.PacketType.BINARY_EVENT:this.onevent(e);break;case n.PacketType.ACK:case n.PacketType.BINARY_ACK:this.onack(e);break;case n.PacketType.DISCONNECT:this.ondisconnect()}}onevent(e){const t=e.data||[];if(a("emitting event %j",t),null!=e.id&&(a("attaching ack callback to event"),t.push(this.ack(e.id))),this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}this.dispatch(t)}ack(e){const t=this;let r=!1;return function(){if(r)return;const i=Array.prototype.slice.call(arguments);a("sending ack %j",i),t.packet({id:e,type:n.PacketType.ACK,data:i}),r=!0}}onack(e){const t=this.acks.get(e.id);"function"==typeof t?(a("calling ack %s with %j",e.id,e.data),t.apply(this,e.data),this.acks.delete(e.id)):a("bad ack %s",e.id)}ondisconnect(){a("got disconnect packet"),this._onclose("client namespace disconnect")}_onerror(e){this.emitReserved("error",e)}_onclose(e,t){if(!this.connected)return this;a("closing socket - reason %s",e),this.emitReserved("disconnecting",e,t),this.server._opts.connectionStateRecovery&&c.has(e)&&(a("connection state recovery is enabled for sid %s",this.id),this.adapter.persistSession({sid:this.id,pid:this.pid,rooms:[...this.rooms],data:this.data})),this._cleanup(),this.client._remove(this),this.connected=!1,this.emitReserved("disconnect",e,t)}_cleanup(){this.leaveAll(),this.nsp._remove(this),this.join=l}_error(e){this.packet({type:n.PacketType.CONNECT_ERROR,data:e})}disconnect(e=!1){return this.connected?(e?this.client._disconnect():(this.packet({type:n.PacketType.DISCONNECT}),this._onclose("server namespace disconnect")),this):this}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}get broadcast(){return this.newBroadcastOperator()}get local(){return this.newBroadcastOperator().local}timeout(e){return this.flags.timeout=e,this}dispatch(e){a("dispatching an event %j",e),this.run(e,(t=>{process.nextTick((()=>{if(t)return this._onerror(t);this.connected?super.emitUntyped.apply(this,e):a("ignore packet received after disconnection")}))}))}use(e){return this.fns.push(e),this}run(e,t){const n=this.fns.slice(0);if(!n.length)return t(null);!function r(i){n[i](e,(function(e){return e?t(e):n[i+1]?void r(i+1):t(null)}))}(0)}get disconnected(){return!this.connected}get request(){return this.client.request}get conn(){return this.client.conn}get rooms(){return this.adapter.socketRooms(this.id)||new Set}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 n=0;n<t.length;n++)if(e===t[n])return t.splice(n,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 n=0;n<t.length;n++)if(e===t[n])return t.splice(n,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 n of t)n.apply(this,e.data)}}newBroadcastOperator(){const e=Object.assign({},this.flags);return this.flags={},new o.BroadcastOperator(this.adapter,new Set,new Set([this.id]),e)}}e.Socket=u}(KQ)),KQ}!function(e){var t=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.Namespace=e.RESERVED_EVENTS=void 0;const n=nJ(),r=YQ,i=t(ah),s=tJ(),o=(0,i.default)("socket.io:namespace");e.RESERVED_EVENTS=new Set(["connect","connection","new_namespace"]);class a extends r.StrictEventEmitter{constructor(e,t){super(),this.sockets=new Map,this._fns=[],this._ids=0,this.server=e,this.name=t,this._initAdapter()}_initAdapter(){this.adapter=new(this.server.adapter())(this)}use(e){return this._fns.push(e),this}run(e,t){const n=this._fns.slice(0);if(!n.length)return t(null);!function r(i){n[i](e,(function(e){return e?t(e):n[i+1]?void r(i+1):t(null)}))}(0)}to(e){return new s.BroadcastOperator(this.adapter).to(e)}in(e){return new s.BroadcastOperator(this.adapter).in(e)}except(e){return new s.BroadcastOperator(this.adapter).except(e)}async _add(e,t,n){var r;o("adding socket to nsp %s",this.name);const i=await this._createSocket(e,t);if((null===(r=this.server.opts.connectionStateRecovery)||void 0===r?void 0:r.skipMiddlewares)&&i.recovered&&"open"===e.conn.readyState)return this._doConnect(i,n);this.run(i,(t=>{process.nextTick((()=>"open"!==e.conn.readyState?(o("next called after client was closed - ignoring socket"),void i._cleanup()):t?(o("middleware error, sending CONNECT_ERROR packet to the client"),i._cleanup(),3===e.conn.protocol?i._error(t.data||t.message):i._error({message:t.message,data:t.data})):void this._doConnect(i,n)))}))}async _createSocket(e,t){const r=t.pid,i=t.offset;if(this.server.opts.connectionStateRecovery&&"string"==typeof r&&"string"==typeof i){let s;try{s=await this.adapter.restoreSession(r,i)}catch(e){o("error while restoring session: %s",e)}if(s)return o("connection state recovered for sid %s",s.sid),new n.Socket(this,e,t,s)}return new n.Socket(this,e,t)}_doConnect(e,t){this.sockets.set(e.id,e),e._onconnect(),t&&t(e),this.emitReserved("connect",e),this.emitReserved("connection",e)}_remove(e){this.sockets.has(e.id)?this.sockets.delete(e.id):o("ignoring remove for %s",e.id)}emit(e,...t){return new s.BroadcastOperator(this.adapter).emit(e,...t)}send(...e){return this.emit("message",...e),this}write(...e){return this.emit("message",...e),this}serverSideEmit(t,...n){if(e.RESERVED_EVENTS.has(t))throw new Error(`"${String(t)}" is a reserved event name`);return n.unshift(t),this.adapter.serverSideEmit(n),!0}serverSideEmitWithAck(e,...t){return new Promise(((n,r)=>{t.push(((e,t)=>e?(e.responses=t,r(e)):n(t))),this.serverSideEmit(e,...t)}))}_onServerSideEmit(e){super.emitUntyped.apply(this,e)}allSockets(){return new s.BroadcastOperator(this.adapter).allSockets()}compress(e){return new s.BroadcastOperator(this.adapter).compress(e)}get volatile(){return new s.BroadcastOperator(this.adapter).volatile}get local(){return new s.BroadcastOperator(this.adapter).local}timeout(e){return new s.BroadcastOperator(this.adapter).timeout(e)}fetchSockets(){return new s.BroadcastOperator(this.adapter).fetchSockets()}socketsJoin(e){return new s.BroadcastOperator(this.adapter).socketsJoin(e)}socketsLeave(e){return new s.BroadcastOperator(this.adapter).socketsLeave(e)}disconnectSockets(e=!1){return new s.BroadcastOperator(this.adapter).disconnectSockets(e)}}e.Namespace=a}(VQ);var rJ={},iJ={},sJ={},oJ={};Object.defineProperty(oJ,"__esModule",{value:!0}),oJ.yeast=oJ.decode=oJ.encode=void 0;const aJ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),cJ=64,lJ={};let uJ,pJ=0,hJ=0;function dJ(e){let t="";do{t=aJ[e%cJ]+t,e=Math.floor(e/cJ)}while(e>0);return t}for(oJ.encode=dJ,oJ.decode=function(e){let t=0;for(hJ=0;hJ<e.length;hJ++)t=t*cJ+lJ[e.charAt(hJ)];return t},oJ.yeast=function(){const e=dJ(+new Date);return e!==uJ?(pJ=0,uJ=e):e+"."+dJ(pJ++)};hJ<cJ;hJ++)lJ[aJ[hJ]]=hJ;var fJ;Object.defineProperty(sJ,"__esModule",{value:!0}),sJ.SessionAwareAdapter=sJ.Adapter=void 0;const mJ=p,gJ=oJ,yJ=BZ,vJ="function"==typeof(null===(fJ=null==yJ?void 0:yJ.Sender)||void 0===fJ?void 0:fJ.frame);class bJ extends mJ.EventEmitter{constructor(e){super(),this.nsp=e,this.rooms=new Map,this.sids=new Map,this.encoder=e.server.encoder}init(){}close(){}serverCount(){return Promise.resolve(1)}addAll(e,t){this.sids.has(e)||this.sids.set(e,new Set);for(const n of t)this.sids.get(e).add(n),this.rooms.has(n)||(this.rooms.set(n,new Set),this.emit("create-room",n)),this.rooms.get(n).has(e)||(this.rooms.get(n).add(e),this.emit("join-room",n,e))}del(e,t){this.sids.has(e)&&this.sids.get(e).delete(t),this._del(t,e)}_del(e,t){const n=this.rooms.get(e);if(null!=n){n.delete(t)&&this.emit("leave-room",e,t),0===n.size&&this.rooms.delete(e)&&this.emit("delete-room",e)}}delAll(e){if(this.sids.has(e)){for(const t of this.sids.get(e))this._del(t,e);this.sids.delete(e)}}broadcast(e,t){const n=t.flags||{},r={preEncoded:!0,volatile:n.volatile,compress:n.compress};e.nsp=this.nsp.name;const i=this._encode(e,r);this.apply(t,(t=>{"function"==typeof t.notifyOutgoingListeners&&t.notifyOutgoingListeners(e),t.client.writeToEngine(i,r)}))}broadcastWithAck(e,t,n,r){const i=t.flags||{},s={preEncoded:!0,volatile:i.volatile,compress:i.compress};e.nsp=this.nsp.name,e.id=this.nsp._ids++;const o=this._encode(e,s);let a=0;this.apply(t,(t=>{a++,t.acks.set(e.id,r),"function"==typeof t.notifyOutgoingListeners&&t.notifyOutgoingListeners(e),t.client.writeToEngine(o,s)})),n(a)}_encode(e,t){const n=this.encoder.encode(e);if(vJ&&1===n.length&&"string"==typeof n[0]){const e=Buffer.from("4"+n[0]);t.wsPreEncodedFrame=yJ.Sender.frame(e,{readOnly:!1,mask:!1,rsv1:!1,opcode:1,fin:!0})}return n}sockets(e){const t=new Set;return this.apply({rooms:e},(e=>{t.add(e.id)})),Promise.resolve(t)}socketRooms(e){return this.sids.get(e)}fetchSockets(e){const t=[];return this.apply(e,(e=>{t.push(e)})),Promise.resolve(t)}addSockets(e,t){this.apply(e,(e=>{e.join(t)}))}delSockets(e,t){this.apply(e,(e=>{t.forEach((t=>e.leave(t)))}))}disconnectSockets(e,t){this.apply(e,(e=>{e.disconnect(t)}))}apply(e,t){const n=e.rooms,r=this.computeExceptSids(e.except);if(n.size){const e=new Set;for(const i of n)if(this.rooms.has(i))for(const n of this.rooms.get(i)){if(e.has(n)||r.has(n))continue;const i=this.nsp.sockets.get(n);i&&(t(i),e.add(n))}}else for(const[e]of this.sids){if(r.has(e))continue;const n=this.nsp.sockets.get(e);n&&t(n)}}computeExceptSids(e){const t=new Set;if(e&&e.size>0)for(const n of e)this.rooms.has(n)&&this.rooms.get(n).forEach((e=>t.add(e)));return t}serverSideEmit(e){console.warn("this adapter does not support the serverSideEmit() functionality")}persistSession(e){}restoreSession(e,t){return null}}sJ.Adapter=bJ;function _J(e,t){const n=0===t.rooms.size||e.some((e=>t.rooms.has(e))),r=e.every((e=>!t.except.has(e)));return n&&r}sJ.SessionAwareAdapter=class extends bJ{constructor(e){super(e),this.nsp=e,this.sessions=new Map,this.packets=[],this.maxDisconnectionDuration=e.server.opts.connectionStateRecovery.maxDisconnectionDuration;const t=setInterval((()=>{const e=Date.now()-this.maxDisconnectionDuration;this.sessions.forEach(((t,n)=>{t.disconnectedAt<e&&this.sessions.delete(n)}));for(let t=this.packets.length-1;t>=0;t--){if(this.packets[t].emittedAt<e){this.packets.splice(0,t+1);break}}}),6e4);t.unref()}persistSession(e){e.disconnectedAt=Date.now(),this.sessions.set(e.pid,e)}restoreSession(e,t){const n=this.sessions.get(e);if(!n)return null;if(n.disconnectedAt+this.maxDisconnectionDuration<Date.now())return this.sessions.delete(e),null;const r=this.packets.findIndex((e=>e.id===t));if(-1===r)return null;const i=[];for(let e=r+1;e<this.packets.length;e++){const t=this.packets[e];_J(n.rooms,t.opts)&&i.push(t.data)}return Promise.resolve(Object.assign(Object.assign({},n),{missedPackets:i}))}broadcast(e,t){var n;const r=2===e.type,i=void 0===e.id,s=void 0===(null===(n=t.flags)||void 0===n?void 0:n.volatile);if(r&&i&&s){const n=(0,gJ.yeast)();e.data.push(n),this.packets.push({id:n,opts:t,data:e.data,emittedAt:Date.now()})}super.broadcast(e,t)}};var xJ={};!function(e){var t=U&&U.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n};Object.defineProperty(e,"__esModule",{value:!0}),e.ClusterAdapterWithHeartbeat=e.ClusterAdapter=e.MessageType=void 0;const n=sJ,r=x,i=(0,ah.debug)("socket.io-adapter"),s=5e3;function o(){return(0,r.randomBytes)(8).toString("hex")}var a;function c(e){return{rooms:[...e.rooms],except:[...e.except],flags:e.flags}}function l(e){return{rooms:new Set(e.rooms),except:new Set(e.except),flags:e.flags}}!function(e){e[e.INITIAL_HEARTBEAT=1]="INITIAL_HEARTBEAT",e[e.HEARTBEAT=2]="HEARTBEAT",e[e.BROADCAST=3]="BROADCAST",e[e.SOCKETS_JOIN=4]="SOCKETS_JOIN",e[e.SOCKETS_LEAVE=5]="SOCKETS_LEAVE",e[e.DISCONNECT_SOCKETS=6]="DISCONNECT_SOCKETS",e[e.FETCH_SOCKETS=7]="FETCH_SOCKETS",e[e.FETCH_SOCKETS_RESPONSE=8]="FETCH_SOCKETS_RESPONSE",e[e.SERVER_SIDE_EMIT=9]="SERVER_SIDE_EMIT",e[e.SERVER_SIDE_EMIT_RESPONSE=10]="SERVER_SIDE_EMIT_RESPONSE",e[e.BROADCAST_CLIENT_COUNT=11]="BROADCAST_CLIENT_COUNT",e[e.BROADCAST_ACK=12]="BROADCAST_ACK",e[e.ADAPTER_CLOSE=13]="ADAPTER_CLOSE"}(a=e.MessageType||(e.MessageType={}));class u extends n.Adapter{constructor(e){super(e),this.requests=new Map,this.ackRequests=new Map,this.uid=o()}onMessage(e,n){if(e.uid===this.uid)return i("[%s] ignore message from self",this.uid);switch(i("[%s] new event of type %d from %s",this.uid,e.type,e.uid),e.type){case a.BROADCAST:if(void 0!==e.data.requestId)super.broadcastWithAck(e.data.packet,l(e.data.opts),(t=>{i("[%s] waiting for %d client acknowledgements",this.uid,t),this.publishResponse(e.uid,{type:a.BROADCAST_CLIENT_COUNT,data:{requestId:e.data.requestId,clientCount:t}})}),(t=>{i("[%s] received acknowledgement with value %j",this.uid,t),this.publishResponse(e.uid,{type:a.BROADCAST_ACK,data:{requestId:e.data.requestId,packet:t}})}));else{const t=e.data.packet,r=l(e.data.opts);this.addOffsetIfNecessary(t,r,n),super.broadcast(t,r)}break;case a.SOCKETS_JOIN:super.addSockets(l(e.data.opts),e.data.rooms);break;case a.SOCKETS_LEAVE:super.delSockets(l(e.data.opts),e.data.rooms);break;case a.DISCONNECT_SOCKETS:super.disconnectSockets(l(e.data.opts),e.data.close);break;case a.FETCH_SOCKETS:i("[%s] calling fetchSockets with opts %j",this.uid,e.data.opts),super.fetchSockets(l(e.data.opts)).then((n=>{this.publishResponse(e.uid,{type:a.FETCH_SOCKETS_RESPONSE,data:{requestId:e.data.requestId,sockets:n.map((e=>{const n=e.handshake,r=t(n,["sessionStore"]);return{id:e.id,handshake:r,rooms:[...e.rooms],data:e.data}}))}})}));break;case a.SERVER_SIDE_EMIT:{const t=e.data.packet;if(!(void 0!==e.data.requestId))return void this.nsp._onServerSideEmit(t);let n=!1;const r=t=>{n||(n=!0,i("[%s] calling acknowledgement with %j",this.uid,t),this.publishResponse(e.uid,{type:a.SERVER_SIDE_EMIT_RESPONSE,data:{requestId:e.data.requestId,packet:t}}))};this.nsp._onServerSideEmit([...t,r]);break}case a.BROADCAST_CLIENT_COUNT:case a.BROADCAST_ACK:case a.FETCH_SOCKETS_RESPONSE:case a.SERVER_SIDE_EMIT_RESPONSE:this.onResponse(e);break;default:i("[%s] unknown message type: %s",this.uid,e.type)}}onResponse(e){var t,n;const r=e.data.requestId;switch(i("[%s] received response %s to request %s",this.uid,e.type,r),e.type){case a.BROADCAST_CLIENT_COUNT:null===(t=this.ackRequests.get(r))||void 0===t||t.clientCountCallback(e.data.clientCount);break;case a.BROADCAST_ACK:null===(n=this.ackRequests.get(r))||void 0===n||n.ack(e.data.packet);break;case a.FETCH_SOCKETS_RESPONSE:{const t=this.requests.get(r);if(!t)return;t.current++,e.data.sockets.forEach((e=>t.responses.push(e))),t.current===t.expected&&(clearTimeout(t.timeout),t.resolve(t.responses),this.requests.delete(r));break}case a.SERVER_SIDE_EMIT_RESPONSE:{const t=this.requests.get(r);if(!t)return;t.current++,t.responses.push(e.data.packet),t.current===t.expected&&(clearTimeout(t.timeout),t.resolve(null,t.responses),this.requests.delete(r));break}default:i("[%s] unknown response type: %s",this.uid,e.type)}}async broadcast(e,t){var n;if(!(null===(n=t.flags)||void 0===n?void 0:n.local))try{const n=await this.publishAndReturnOffset({type:a.BROADCAST,data:{packet:e,opts:c(t)}});this.addOffsetIfNecessary(e,t,n)}catch(e){return i("[%s] error while broadcasting message: %s",this.uid,e.message)}super.broadcast(e,t)}addOffsetIfNecessary(e,t,n){var r;if(!this.nsp.server.opts.connectionStateRecovery)return;const i=2===e.type,s=void 0===e.id,o=void 0===(null===(r=t.flags)||void 0===r?void 0:r.volatile);i&&s&&o&&e.data.push(n)}broadcastWithAck(e,t,n,r){var i;if(!(null===(i=null==t?void 0:t.flags)||void 0===i?void 0:i.local)){const i=o();this.ackRequests.set(i,{clientCountCallback:n,ack:r}),this.publish({type:a.BROADCAST,data:{packet:e,requestId:i,opts:c(t)}}),setTimeout((()=>{this.ackRequests.delete(i)}),t.flags.timeout)}super.broadcastWithAck(e,t,n,r)}async addSockets(e,t){var n;if(!(null===(n=e.flags)||void 0===n?void 0:n.local))try{await this.publishAndReturnOffset({type:a.SOCKETS_JOIN,data:{opts:c(e),rooms:t}})}catch(e){i("[%s] error while publishing message: %s",this.uid,e.message)}super.addSockets(e,t)}async delSockets(e,t){var n;if(!(null===(n=e.flags)||void 0===n?void 0:n.local))try{await this.publishAndReturnOffset({type:a.SOCKETS_LEAVE,data:{opts:c(e),rooms:t}})}catch(e){i("[%s] error while publishing message: %s",this.uid,e.message)}super.delSockets(e,t)}async disconnectSockets(e,t){var n;if(!(null===(n=e.flags)||void 0===n?void 0:n.local))try{await this.publishAndReturnOffset({type:a.DISCONNECT_SOCKETS,data:{opts:c(e),close:t}})}catch(e){i("[%s] error while publishing message: %s",this.uid,e.message)}super.disconnectSockets(e,t)}async fetchSockets(e){var t;const[n,r]=await Promise.all([super.fetchSockets(e),this.serverCount()]),i=r-1;if((null===(t=e.flags)||void 0===t?void 0:t.local)||i<=0)return n;const l=o();return new Promise(((t,r)=>{const o=setTimeout((()=>{const e=this.requests.get(l);e&&(r(new Error(`timeout reached: only ${e.current} responses received out of ${e.expected}`)),this.requests.delete(l))}),e.flags.timeout||s),u={type:a.FETCH_SOCKETS,resolve:t,timeout:o,current:0,expected:i,responses:n};this.requests.set(l,u),this.publish({type:a.FETCH_SOCKETS,data:{opts:c(e),requestId:l}})}))}async serverSideEmit(e){if(!("function"==typeof e[e.length-1]))return this.publish({type:a.SERVER_SIDE_EMIT,data:{packet:e}});const t=e.pop(),n=await this.serverCount()-1;if(i('[%s] waiting for %d responses to "serverSideEmit" request',this.uid,n),n<=0)return t(null,[]);const r=o(),c=setTimeout((()=>{const e=this.requests.get(r);e&&(t(new Error(`timeout reached: only ${e.current} responses received out of ${e.expected}`),e.responses),this.requests.delete(r))}),s),l={type:a.SERVER_SIDE_EMIT,resolve:t,timeout:c,current:0,expected:n,responses:[]};this.requests.set(r,l),this.publish({type:a.SERVER_SIDE_EMIT,data:{requestId:r,packet:e}})}publish(e){this.publishAndReturnOffset(e).catch((e=>{i("[%s] error while publishing message: %s",this.uid,e)}))}publishAndReturnOffset(e){return e.uid=this.uid,e.nsp=this.nsp.name,this.doPublish(e)}publishResponse(e,t){t.uid=this.uid,t.nsp=this.nsp.name,this.doPublishResponse(e,t).catch((e=>{i("[%s] error while publishing response: %s",this.uid,e)}))}}e.ClusterAdapter=u;e.ClusterAdapterWithHeartbeat=class extends u{constructor(e,t){super(e),this.nodesMap=new Map,this.customRequests=new Map,this._opts=Object.assign({heartbeatInterval:5e3,heartbeatTimeout:1e4},t),this.cleanupTimer=setInterval((()=>{const e=Date.now();this.nodesMap.forEach(((t,n)=>{e-t>this._opts.heartbeatTimeout&&(i("[%s] node %s seems down",this.uid,n),this.removeNode(n))}))}),1e3)}init(){this.publish({type:a.INITIAL_HEARTBEAT})}scheduleHeartbeat(){this.heartbeatTimer?this.heartbeatTimer.refresh():this.heartbeatTimer=setTimeout((()=>{this.publish({type:a.HEARTBEAT})}),this._opts.heartbeatInterval)}close(){this.publish({type:a.ADAPTER_CLOSE}),clearTimeout(this.heartbeatTimer),this.cleanupTimer&&clearInterval(this.cleanupTimer)}onMessage(e,t){if(e.uid===this.uid)return i("[%s] ignore message from self",this.uid);switch(e.uid&&"emitter"!==e.uid&&this.nodesMap.set(e.uid,Date.now()),i("[%s] new event of type %d from %s",this.uid,e.type,e.uid),e.type){case a.INITIAL_HEARTBEAT:this.publish({type:a.HEARTBEAT});break;case a.HEARTBEAT:break;case a.ADAPTER_CLOSE:this.removeNode(e.uid);break;default:super.onMessage(e,t)}}serverCount(){return Promise.resolve(1+this.nodesMap.size)}publish(e){return this.scheduleHeartbeat(),super.publish(e)}async serverSideEmit(e){if(!("function"==typeof e[e.length-1]))return this.publish({type:a.SERVER_SIDE_EMIT,data:{packet:e}});const t=e.pop(),n=this.nodesMap.size;if(i('[%s] waiting for %d responses to "serverSideEmit" request',this.uid,n),n<=0)return t(null,[]);const r=o(),c=setTimeout((()=>{const e=this.customRequests.get(r);e&&(t(new Error(`timeout reached: missing ${e.missingUids.size} responses`),e.responses),this.customRequests.delete(r))}),s),l={type:a.SERVER_SIDE_EMIT,resolve:t,timeout:c,missingUids:new Set([...this.nodesMap.keys()]),responses:[]};this.customRequests.set(r,l),this.publish({type:a.SERVER_SIDE_EMIT,data:{requestId:r,packet:e}})}async fetchSockets(e){var t;const[n,r]=await Promise.all([super.fetchSockets({rooms:e.rooms,except:e.except,flags:{local:!0}}),this.serverCount()]),i=r-1;if((null===(t=e.flags)||void 0===t?void 0:t.local)||i<=0)return n;const l=o();return new Promise(((t,r)=>{const i=setTimeout((()=>{const e=this.customRequests.get(l);e&&(r(new Error(`timeout reached: missing ${e.missingUids.size} responses`)),this.customRequests.delete(l))}),e.flags.timeout||s),o={type:a.FETCH_SOCKETS,resolve:t,timeout:i,missingUids:new Set([...this.nodesMap.keys()]),responses:n};this.customRequests.set(l,o),this.publish({type:a.FETCH_SOCKETS,data:{opts:c(e),requestId:l}})}))}onResponse(e){const t=e.data.requestId;switch(i("[%s] received response %s to request %s",this.uid,e.type,t),e.type){case a.FETCH_SOCKETS_RESPONSE:{const n=this.customRequests.get(t);if(!n)return;e.data.sockets.forEach((e=>n.responses.push(e))),n.missingUids.delete(e.uid),0===n.missingUids.size&&(clearTimeout(n.timeout),n.resolve(n.responses),this.customRequests.delete(t));break}case a.SERVER_SIDE_EMIT_RESPONSE:{const n=this.customRequests.get(t);if(!n)return;n.responses.push(e.data.packet),n.missingUids.delete(e.uid),0===n.missingUids.size&&(clearTimeout(n.timeout),n.resolve(null,n.responses),this.customRequests.delete(t));break}default:super.onResponse(e)}}removeNode(e){this.customRequests.forEach(((t,n)=>{t.missingUids.delete(e),0===t.missingUids.size&&(clearTimeout(t.timeout),t.type===a.FETCH_SOCKETS?t.resolve(t.responses):t.type===a.SERVER_SIDE_EMIT&&t.resolve(null,t.responses),this.customRequests.delete(n))})),this.nodesMap.delete(e)}}}(xJ),function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.MessageType=e.ClusterAdapterWithHeartbeat=e.ClusterAdapter=e.SessionAwareAdapter=e.Adapter=void 0;var t=sJ;Object.defineProperty(e,"Adapter",{enumerable:!0,get:function(){return t.Adapter}}),Object.defineProperty(e,"SessionAwareAdapter",{enumerable:!0,get:function(){return t.SessionAwareAdapter}});var n=xJ;Object.defineProperty(e,"ClusterAdapter",{enumerable:!0,get:function(){return n.ClusterAdapter}}),Object.defineProperty(e,"ClusterAdapterWithHeartbeat",{enumerable:!0,get:function(){return n.ClusterAdapterWithHeartbeat}}),Object.defineProperty(e,"MessageType",{enumerable:!0,get:function(){return n.MessageType}})}(iJ);var wJ=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(rJ,"__esModule",{value:!0}),rJ.ParentNamespace=void 0;const EJ=VQ,SJ=iJ,TJ=(0,wJ(ah).default)("socket.io:parent-namespace");class DJ extends EJ.Namespace{constructor(e){super(e,"/_"+DJ.count++),this.children=new Set}_initAdapter(){this.adapter=new kJ(this,this.children)}emit(e,...t){return this.children.forEach((n=>{n.emit(e,...t)})),!0}createChild(e){TJ("creating child namespace %s",e);const t=new EJ.Namespace(this.server,e);if(t._fns=this._fns.slice(0),this.listeners("connect").forEach((e=>t.on("connect",e))),this.listeners("connection").forEach((e=>t.on("connection",e))),this.children.add(t),this.server._opts.cleanupEmptyChildNamespaces){const n=t._remove;t._remove=r=>{n.call(t,r),0===t.sockets.size&&(TJ("closing child namespace %s",e),t.adapter.close(),this.server._nsps.delete(t.name),this.children.delete(t))}}return this.server._nsps.set(e,t),this.server.sockets.emitReserved("new_namespace",t),t}fetchSockets(){throw new Error("fetchSockets() is not supported on parent namespaces")}}rJ.ParentNamespace=DJ,DJ.count=0;class kJ extends SJ.Adapter{constructor(e,t){super(e),this.children=t}broadcast(e,t){this.children.forEach((n=>{n.adapter.broadcast(e,t)}))}}var AJ={},CJ=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(AJ,"__esModule",{value:!0}),AJ.serveFile=AJ.restoreAdapter=AJ.patchAdapter=void 0;const RJ=iJ,OJ=s,LJ=(0,CJ(ah).default)("socket.io:adapter-uws"),IJ="",{addAll:PJ,del:NJ,broadcast:jJ}=RJ.Adapter.prototype;function FJ(e,t,n,r){const i=t.conn.id,s=t.conn.transport.socket;n&&(LJ("subscribe connection %s to topic %s",i,e),s.subscribe(e)),r.forEach((t=>{const n=`${e}${IJ}${t}`;LJ("subscribe connection %s to topic %s",i,n),s.subscribe(n)}))}AJ.patchAdapter=function(e){RJ.Adapter.prototype.addAll=function(e,t){const n=!this.sids.has(e);PJ.call(this,e,t);const r=this.nsp.sockets.get(e);r&&("websocket"!==r.conn.transport.name?n&&r.conn.on("upgrade",(()=>{const t=this.sids.get(e);t&&FJ(this.nsp.name,r,n,t)})):FJ(this.nsp.name,r,n,t))},RJ.Adapter.prototype.del=function(e,t){NJ.call(this,e,t);const n=this.nsp.sockets.get(e);if(n&&"websocket"===n.conn.transport.name){const e=n.conn.id,r=n.conn.transport.socket,i=`${this.nsp.name}${IJ}${t}`;LJ("unsubscribe connection %s from topic %s",e,i),r.unsubscribe(i)}},RJ.Adapter.prototype.broadcast=function(t,n){if(!(n.rooms.size<=1&&0===n.except.size))return void jJ.call(this,t,n);const r=n.flags||{},i={preEncoded:!0,volatile:r.volatile,compress:r.compress};t.nsp=this.nsp.name;const s=this.encoder.encode(t),o=0===n.rooms.size?this.nsp.name:`${this.nsp.name}${IJ}${n.rooms.keys().next().value}`;LJ("fast publish to %s",o),s.forEach((t=>{const n="string"!=typeof t;e.publish(o,n?t:"4"+t,n)})),this.apply(n,(e=>{"websocket"!==e.conn.transport.name&&e.client.writeToEngine(s,i)}))}},AJ.restoreAdapter=function(){RJ.Adapter.prototype.addAll=PJ,RJ.Adapter.prototype.del=NJ,RJ.Adapter.prototype.broadcast=jJ};AJ.serveFile=function(e,t){const{size:n}=(0,OJ.statSync)(t),r=(0,OJ.createReadStream)(t),i=()=>!r.destroyed&&r.destroy();e.onAborted(i),r.on("data",(t=>{const i=(e=>{const{buffer:t,byteOffset:n,byteLength:r}=e;return t.slice(n,n+r)})(t),s=e.getWriteOffset(),[o,a]=e.tryEnd(i,n);a||o||(r.pause(),e.onWritable((t=>{const[o,a]=e.tryEnd(i.slice(t-s),n);return!a&&o&&r.resume(),o})))})).on("error",(e=>{throw i(),e})).on("end",i)};var BJ="4.7.5";!function(e,t){var n=U&&U.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=U&&U.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=U&&U.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&n(t,e,i);return r(t,e),t},a=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Namespace=t.Socket=t.Server=void 0;const c=w,l=s,u=T,d=KM,f=h,m=o,g=OG,y=CQ,v=p,b=VQ;Object.defineProperty(t,"Namespace",{enumerable:!0,get:function(){return b.Namespace}});const _=rJ,x=iJ,E=i(RQ),S=a(ah),D=nJ();Object.defineProperty(t,"Socket",{enumerable:!0,get:function(){return D.Socket}});const k=YQ,A=AJ,C=a(zZ),R=(0,S.default)("socket.io:server"),O=BJ,L=/\.map/;class I extends k.StrictEventEmitter{constructor(e,t={}){super(),this._nsps=new Map,this.parentNsps=new Map,this.parentNamespacesFromRegExp=new Map,"object"==typeof e&&e instanceof Object&&!e.listen&&(t=e,e=void 0),this.path(t.path||"/socket.io"),this.connectTimeout(t.connectTimeout||45e3),this.serveClient(!1!==t.serveClient),this._parser=t.parser||E,this.encoder=new this._parser.Encoder,this.opts=t,t.connectionStateRecovery?(t.connectionStateRecovery=Object.assign({maxDisconnectionDuration:12e4,skipMiddlewares:!0},t.connectionStateRecovery),this.adapter(t.adapter||x.SessionAwareAdapter)):this.adapter(t.adapter||x.Adapter),t.cleanupEmptyChildNamespaces=!!t.cleanupEmptyChildNamespaces,this.sockets=this.of("/"),(e||"number"==typeof e)&&this.attach(e),this.opts.cors&&(this._corsMiddleware=(0,C.default)(this.opts.cors))}get _opts(){return this.opts}serveClient(e){return arguments.length?(this._serveClient=e,this):this._serveClient}_checkNamespace(e,t,n){if(0===this.parentNsps.size)return n(!1);const r=this.parentNsps.keys(),i=()=>{const s=r.next();if(s.done)return n(!1);s.value(e,t,((t,r)=>{if(t||!r)return i();if(this._nsps.has(e))return R("dynamic namespace %s already exists",e),n(this._nsps.get(e));const o=this.parentNsps.get(s.value).createChild(e);R("dynamic namespace %s was created",e),n(o)}))};i()}path(e){if(!arguments.length)return this._path;this._path=e.replace(/\/$/,"");const t=this._path.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");return this.clientPathRegex=new RegExp("^"+t+"/socket\\.io(\\.msgpack|\\.esm)?(\\.min)?\\.js(\\.map)?(?:\\?|$)"),this}connectTimeout(e){return void 0===e?this._connectTimeout:(this._connectTimeout=e,this)}adapter(e){if(!arguments.length)return this._adapter;this._adapter=e;for(const e of this._nsps.values())e._initAdapter();return this}listen(e,t={}){return this.attach(e,t)}attach(e,t={}){if("function"==typeof e){throw new Error("You are trying to attach socket.io to an express request handler function. Please pass a http.Server instance.")}if(Number(e)==e&&(e=Number(e)),"number"==typeof e){R("creating http server and binding to %d",e);const t=e;e=c.createServer(((e,t)=>{t.writeHead(404),t.end()})),e.listen(t)}return Object.assign(t,this.opts),t.path=t.path||this._path,this.initEngine(e,t),this}attachApp(e,t={}){Object.assign(t,this.opts),t.path=t.path||this._path,R("creating uWebSockets.js-based engine with opts %j",t);const n=new g.uServer(t);n.attach(e,t),this.bind(n),this._serveClient&&e.get(`${this._path}/*`,((e,t)=>{if(!this.clientPathRegex.test(t.getUrl()))return void t.setYield(!0);const n=t.getUrl().replace(this._path,"").replace(/\?.*$/,"").replace(/^\//,""),r=L.test(n),i=r?"map":"source",s='"'+O+'"',o="W/"+s,a=t.getHeader("if-none-match");if(a&&(s===a||o===a))return R("serve client %s 304",i),e.writeStatus("304 Not Modified"),void e.end();R("serve client %s",i),e.writeHeader("cache-control","public, max-age=0"),e.writeHeader("content-type","application/"+(r?"json":"javascript")+"; charset=utf-8"),e.writeHeader("etag",s);const c=m.join(__dirname,"../client-dist/",n);(0,A.serveFile)(e,c)})),(0,A.patchAdapter)(e)}initEngine(e,t){R("creating engine.io instance with opts %j",t),this.eio=(0,g.attach)(e,t),this._serveClient&&this.attachServe(e),this.httpServer=e,this.bind(this.eio)}attachServe(e){R("attaching client serving req handler");const t=e.listeners("request").slice(0);e.removeAllListeners("request"),e.on("request",((n,r)=>{if(this.clientPathRegex.test(n.url))this._corsMiddleware?this._corsMiddleware(n,r,(()=>{this.serve(n,r)})):this.serve(n,r);else for(let i=0;i<t.length;i++)t[i].call(e,n,r)}))}serve(e,t){const n=e.url.replace(this._path,"").replace(/\?.*$/,""),r=L.test(n),i=r?"map":"source",s='"'+O+'"',o="W/"+s,a=e.headers["if-none-match"];if(a&&(s===a||o===a))return R("serve client %s 304",i),t.writeHead(304),void t.end();R("serve client %s",i),t.setHeader("Cache-Control","public, max-age=0"),t.setHeader("Content-Type","application/"+(r?"json":"javascript")+"; charset=utf-8"),t.setHeader("ETag",s),I.sendFile(n,e,t)}static sendFile(e,t,n){const r=(0,l.createReadStream)(m.join(__dirname,"../client-dist/",e)),i=e=>{e&&n.end()};switch(d(t).encodings(["br","gzip","deflate"])){case"br":n.writeHead(200,{"content-encoding":"br"}),(0,f.pipeline)(r,(0,u.createBrotliCompress)(),n,i);break;case"gzip":n.writeHead(200,{"content-encoding":"gzip"}),(0,f.pipeline)(r,(0,u.createGzip)(),n,i);break;case"deflate":n.writeHead(200,{"content-encoding":"deflate"}),(0,f.pipeline)(r,(0,u.createDeflate)(),n,i);break;default:n.writeHead(200),(0,f.pipeline)(r,n,i)}}bind(e){return this.engine=e,this.engine.on("connection",this.onconnection.bind(this)),this}onconnection(e){R("incoming connection with id %s",e.id);const t=new y.Client(this,e);return 3===e.protocol&&t.connect("/"),this}of(e,t){if("function"==typeof e||e instanceof RegExp){const n=new _.ParentNamespace(this);return R("initializing parent namespace %s",n.name),"function"==typeof e?this.parentNsps.set(e,n):(this.parentNsps.set(((t,n,r)=>r(null,e.test(t))),n),this.parentNamespacesFromRegExp.set(e,n)),t&&n.on("connect",t),n}"/"!==String(e)[0]&&(e="/"+e);let n=this._nsps.get(e);if(!n){for(const[t,n]of this.parentNamespacesFromRegExp)if(t.test(e))return R("attaching namespace %s to parent namespace %s",e,t),n.createChild(e);R("initializing namespace %s",e),n=new b.Namespace(this,e),this._nsps.set(e,n),"/"!==e&&this.sockets.emitReserved("new_namespace",n)}return t&&n.on("connect",t),n}close(e){this._nsps.forEach((e=>{e.sockets.forEach((e=>{e._onclose("server shutting down")})),e.adapter.close()})),this.engine.close(),(0,A.restoreAdapter)(),this.httpServer?this.httpServer.close(e):e&&e()}use(e){return this.sockets.use(e),this}to(e){return this.sockets.to(e)}in(e){return this.sockets.in(e)}except(e){return this.sockets.except(e)}send(...e){return this.sockets.emit("message",...e),this}write(...e){return this.sockets.emit("message",...e),this}serverSideEmit(e,...t){return this.sockets.serverSideEmit(e,...t)}serverSideEmitWithAck(e,...t){return this.sockets.serverSideEmitWithAck(e,...t)}allSockets(){return this.sockets.allSockets()}compress(e){return this.sockets.compress(e)}get volatile(){return this.sockets.volatile}get local(){return this.sockets.local}timeout(e){return this.sockets.timeout(e)}fetchSockets(){return this.sockets.fetchSockets()}socketsJoin(e){return this.sockets.socketsJoin(e)}socketsLeave(e){return this.sockets.socketsLeave(e)}disconnectSockets(e=!1){return this.sockets.disconnectSockets(e)}}t.Server=I;const P=Object.keys(v.EventEmitter.prototype).filter((function(e){return"function"==typeof v.EventEmitter.prototype[e]}));P.forEach((function(e){I.prototype[e]=function(){return this.sockets[e].apply(this.sockets,arguments)}})),e.exports=(e,t)=>new I(e,t),e.exports.Server=I,e.exports.Namespace=b.Namespace,e.exports.Socket=D.Socket,nJ()}(RG,RG.exports);var MJ=q(RG.exports);const{Server:UJ,Namespace:qJ,Socket:HJ}=MJ,$J=e=>new Promise(((t,n)=>{const r=a.platform();let i;if("win32"===r)i=`start ${e}`;else if("darwin"===r)i=`open ${e}`;else{if("linux"!==r)return n(new Error(`Unsupported platform: ${r}`));i=`xdg-open ${e}`}d.exec(i,(e=>{if(e)return n(new Error(`Failed to open URL on ${r}: ${e.message}`));t()}))})),zJ=process.cwd(),WJ=o.join(zJ,"src","views");const GJ=new ke;GJ.name("theme").description("dev, list"),GJ.command("create").description("Run development server with Webpack and BrowserSync").action(gf),GJ.command("check").description("Run development server with Webpack and BrowserSync").action((async function(){const e=zr("Checking files...").start();try{const t=await qO(WJ),n=Object.keys(t);await HO(n,e)}catch(t){e.fail("Failed to retrieve files"),console.error(_t.red(`Failed to retrieve files - Error: ${t.message}`))}})),GJ.command("dev").description("Run development server with Webpack and BrowserSync").action((async()=>{await mf();const{data:e}=await of.get("/apps"),t=e?.apps?.map((e=>({name:e.subdomain,value:e._id}))),n=await yl.prompt({type:"list",name:"app",message:"Choose the theme you want to use",choices:t});var r=e?.apps?.find((e=>e._id===n.app));const i=JU(),s=3e3,a=new w.Server(i),c=new UJ(a),l=zr("Start Server").start(),u=process.cwd(),p=o.join(u,"src"),h=o.join(u,"src","assets"),f=o.join(u,"dist");d.exec("npm run build",(async e=>{e&&console.log(e,"errrrrr");try{await I.access(p),await I.access(f)}catch{console.error("Error: Required directories do not exist."),process.exit(1)}i.use(JU.static(f)),i.get("*",j(i,{viewsDirectory:p,secretKey:r.secretKey,watch:!0})),hq.watch(h).on("change",(()=>{const e=zr("Building").start();d.exec(`cd ${u} && npm run build`,(t=>{if(t)return console.log(t),void e.fail(_t.red("Build failed"));e.succeed(_t.blue("Rebuilt successfully"))}))}));const t=zr("Connected");c.on("connection",(e=>{t.stop(),t.start();const n=hq.watch([p,o.join(u,"tailwind.config.js")]);n.on("change",(()=>{t.stop();const r=zr(_t.blue("Reloading")).start();e.emit("reload"),r.succeed(_t.blue("Reloaded successfully")),n.close()}))})),c.on("disconnect",(()=>{console.log(_t.blue("Disconnected")),t.stop(),reloadSpinner.stop()})),a.listen(s,(()=>{l.succeed("Server Started"),console.log("Server running at http://localhost:3000"),$J("http://localhost:3000")}))}))})),GJ.command("list").description("List available themes").action((async()=>{const e=zr("Fetching Data...").start();try{const{data:t}=await of.get("/themes");e.stop();const n=t?.themes?.map((e=>({name:e.title,value:e._id}))),r=await yl.prompt({type:"list",name:"selectedThemeId",message:"Choose the theme you want to use:",choices:n}),i=t?.themes.find((e=>e._id===r.selectedThemeId));console.log("🚀 ~ getThemes ~ selectedTheme:",i)}catch(t){e.stop(),console.error("Failed to fetch data:",t)}}));const VJ=Object.create(null);VJ.open="0",VJ.close="1",VJ.ping="2",VJ.pong="3",VJ.message="4",VJ.upgrade="5",VJ.noop="6";const KJ=Object.create(null);Object.keys(VJ).forEach((e=>{KJ[VJ[e]]=e}));const YJ={type:"error",data:"parser error"},ZJ=({type:e,data:t},n,r)=>t instanceof ArrayBuffer||ArrayBuffer.isView(t)?r(n?t:"b"+QJ(t,!0).toString("base64")):r(VJ[e]+(t||"")),QJ=(e,t)=>Buffer.isBuffer(e)||e instanceof Uint8Array&&!t?e:e instanceof ArrayBuffer?Buffer.from(e):Buffer.from(e.buffer,e.byteOffset,e.byteLength);let JJ;const XJ=(e,t)=>{if("string"!=typeof e)return{type:"message",data:eX(e,t)};const n=e.charAt(0);if("b"===n){const n=Buffer.from(e.substring(1),"base64");return{type:"message",data:eX(n,t)}}return KJ[n]?e.length>1?{type:KJ[n],data:e.substring(1)}:{type:KJ[n]}:YJ},eX=(e,t)=>"arraybuffer"===t?e instanceof ArrayBuffer?e:Buffer.isBuffer(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e.buffer:Buffer.isBuffer(e)?e:Buffer.from(e),tX=String.fromCharCode(30);function nX(){return new TransformStream({transform(e,t){!function(e,t){if(e.data instanceof ArrayBuffer||ArrayBuffer.isView(e.data))return t(QJ(e.data,!1));ZJ(e,!0,(e=>{JJ||(JJ=new TextEncoder),t(JJ.encode(e))}))}(e,(n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);const e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&"string"!=typeof e.data&&(i[0]|=128),t.enqueue(i),t.enqueue(n)}))}})}let rX;function iX(e){return e.reduce(((e,t)=>e+t.length),0)}function sX(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}const oX=global;function aX(e,...t){return t.reduce(((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t)),{})}const cX=oX.setTimeout,lX=oX.clearTimeout;function uX(e,t){t.useNativeTimers?(e.setTimeoutFn=cX.bind(oX),e.clearTimeoutFn=lX.bind(oX)):(e.setTimeoutFn=oX.setTimeout.bind(oX),e.clearTimeoutFn=oX.clearTimeout.bind(oX))}class pX extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}class hX extends OQ{constructor(e){super(),this.writable=!1,uX(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,n){return super.emitReserved("error",new pX(e,t,n)),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=XJ(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 n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}(e);return t.length?"?"+t:""}}const dX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),fX=64,mX={};let gX,yX=0,vX=0;function bX(e){let t="";do{t=dX[e%fX]+t,e=Math.floor(e/fX)}while(e>0);return t}function _X(){const e=bX(+new Date);return e!==gX?(yX=0,gX=e):e+"."+bX(yX++)}for(;vX<fX;vX++)mX[dX[vX]]=vX;
|
|
383
|
+
/*! https://mths.be/utf8js v2.1.2 by @mathias */function QG(e){for(var t,n,r=[],i=0,s=e.length;i<s;)(t=e.charCodeAt(i++))>=55296&&t<=56319&&i<s?56320==(64512&(n=e.charCodeAt(i++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),i--):r.push(t);return r}function JG(e,t){if(e>=55296&&e<=57343){if(t)throw Error("Lone surrogate U+"+e.toString(16).toUpperCase()+" is not a scalar value");return!1}return!0}function XG(e,t){return ZG(e>>t&63|128)}function eV(e,t){if(!(4294967168&e))return ZG(e);var n="";return 4294965248&e?4294901760&e?4292870144&e||(n=ZG(e>>18&7|240),n+=XG(e,12),n+=XG(e,6)):(JG(e,t)||(e=65533),n=ZG(e>>12&15|224),n+=XG(e,6)):n=ZG(e>>6&31|192),n+=ZG(63&e|128)}function tV(){if(KG>=VG)throw Error("Invalid byte index");var e=255&GG[KG];if(KG++,128==(192&e))return 63&e;throw Error("Invalid continuation byte")}function nV(e){var t,n;if(KG>VG)throw Error("Invalid byte index");if(KG==VG)return!1;if(t=255&GG[KG],KG++,!(128&t))return t;if(192==(224&t)){if((n=(31&t)<<6|tV())>=128)return n;throw Error("Invalid continuation byte")}if(224==(240&t)){if((n=(15&t)<<12|tV()<<6|tV())>=2048)return JG(n,e)?n:65533;throw Error("Invalid continuation byte")}if(240==(248&t)&&(n=(7&t)<<18|tV()<<12|tV()<<6|tV())>=65536&&n<=1114111)return n;throw Error("Invalid UTF-8 detected")}var rV={version:"2.1.2",encode:function(e,t){for(var n=!1!==(t=t||{}).strict,r=QG(e),i=r.length,s=-1,o="";++s<i;)o+=eV(r[s],n);return o},decode:function(e,t){var n=!1!==(t=t||{}).strict;GG=QG(e),VG=GG.length,KG=0;for(var r,i=[];!1!==(r=nV(n));)i.push(r);return function(e){for(var t,n=e.length,r=-1,i="";++r<n;)(t=e[r])>65535&&(i+=ZG((t-=65536)>>>10&1023|55296),t=56320|1023&t),i+=ZG(t);return i}(i)}};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.decodePayloadAsBinary=e.encodePayloadAsBinary=e.decodePayload=e.encodePayload=e.decodeBase64Packet=e.decodePacket=e.encodeBase64Packet=e.encodePacket=e.packets=e.protocol=void 0;var t=rV;e.protocol=3;e.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6};var n=Object.keys(e.packets),r={type:"error",data:"parser error"};const i=Buffer.concat([]);function s(n,r,i,s){if("function"==typeof r&&(s=r,r=null),"function"==typeof i&&(s=i,i=null),Buffer.isBuffer(n.data))return o(n,r,s);if(n.data&&(n.data.buffer||n.data)instanceof ArrayBuffer)return o({type:n.type,data:d(n.data)},r,s);var a=e.packets[n.type];return void 0!==n.data&&(a+=i?t.encode(String(n.data),{strict:!1}):String(n.data)),s(""+a)}function o(t,n,r){if(!n)return a(t,r);var i=t.data,s=Buffer.allocUnsafe(1);return s[0]=e.packets[t.type],r(Buffer.concat([s,i]))}function a(t,n){var r=Buffer.isBuffer(t.data)?t.data:d(t.data),i="b"+e.packets[t.type];return n(i+=r.toString("base64"))}function c(e,i,s){if(void 0===e)return r;var o;if("string"==typeof e)return"b"===(o=e.charAt(0))?l(e.slice(1),i):s&&!1===(e=function(e){try{e=t.decode(e,{strict:!1})}catch(e){return!1}return e}(e))?r:Number(o)==o&&n[o]?e.length>1?{type:n[o],data:e.slice(1)}:{type:n[o]}:r;if("arraybuffer"===i){var a=new Uint8Array(e);return o=a[0],{type:n[o],data:a.buffer.slice(1)}}return e instanceof ArrayBuffer&&(e=d(e)),o=e[0],{type:n[o],data:e.slice(1)}}function l(e,t){var r=n[e.charAt(0)],i=Buffer.from(e.slice(1),"base64");if("arraybuffer"===t){for(var s=new Uint8Array(i.length),o=0;o<s.length;o++)s[o]=i[o];i=s.buffer}return{type:r,data:i}}function u(e,t,n){const r=new Array(e.length);let i=0;for(let s=0;s<e.length;s++)t(e[s],((t,o)=>{r[s]=o,++i===e.length&&n(null,r)}))}function p(e){for(var t="",n=0,r=e.length;n<r;n++)t+=String.fromCharCode(e[n]);return t}function h(e){for(var t=Buffer.allocUnsafe(e.length),n=0,r=e.length;n<r;n++)t.writeUInt8(e.charCodeAt(n),n);return t}function d(e){var t=e.byteLength||e.length,n=e.byteOffset||0;return Buffer.from(e.buffer||e,n,t)}function f(e,t){if(!e.length)return t(i);u(e,m,(function(e,n){return t(Buffer.concat(n))}))}function m(e,t){s(e,!0,!0,(function(e){var n,r=""+e.length;if("string"==typeof e){(n=Buffer.allocUnsafe(r.length+2))[0]=0;for(var i=0;i<r.length;i++)n[i+1]=parseInt(r[i],10);return n[n.length-1]=255,t(null,Buffer.concat([n,h(e)]))}for((n=Buffer.allocUnsafe(r.length+2))[0]=1,i=0;i<r.length;i++)n[i+1]=parseInt(r[i],10);n[n.length-1]=255,t(null,Buffer.concat([n,e]))}))}function g(e,t,n){"function"==typeof t&&(n=t,t=null);for(var i,s=e,o=[];s.length>0;){var a="",l=0===s[0];for(i=1;255!==s[i];i++){if(a.length>310)return n(r,0,1);a+=""+s[i]}s=s.slice(a.length+1);var u=parseInt(a,10),h=s.slice(1,u+1);l&&(h=p(h)),o.push(h),s=s.slice(u+1)}var d=o.length;for(i=0;i<d;i++){n(c(o[i],t,!0),i,d)}}e.encodePacket=s,e.encodeBase64Packet=a,e.decodePacket=c,e.decodeBase64Packet=l,e.encodePayload=function(e,t,n){if("function"==typeof t&&(n=t,t=null),t&&(e=>{for(const t of e)if(t.data instanceof ArrayBuffer||ArrayBuffer.isView(t.data))return!0;return!1})(e))return f(e,n);if(!e.length)return n("0:");u(e,(function(e,n){s(e,t,!1,(function(e){n(null,function(e){return e.length+":"+e}(e))}))}),(function(e,t){return n(t.join(""))}))},e.decodePayload=function(e,t,n){if("string"!=typeof e)return g(e,t,n);if("function"==typeof t&&(n=t,t=null),""===e)return n(r,0,1);for(var i,s,o,a="",l=0,u=e.length;l<u;l++){var p=e.charAt(l);if(":"===p){if(""===a||a!=(i=Number(a)))return n(r,0,1);if(a!=(s=e.slice(l+1,l+1+i)).length)return n(r,0,1);if(s.length){if(o=c(s,t,!1),r.type===o.type&&r.data===o.data)return n(r,0,1);if(!1===n(o,l+i,u))return}l+=i,a=""}else a+=p}return""!==a?n(r,0,1):void 0},e.encodePayloadAsBinary=f,e.decodePayloadAsBinary=g}(YG),Object.defineProperty(FG,"__esModule",{value:!0}),FG.Transport=void 0;const iV=p,sV=BG,oV=YG,aV=(0,ah.default)("engine:transport");function cV(){}let lV=class extends iV.EventEmitter{constructor(e){super(),this.writable=!1,this._readyState="open",this.discarded=!1,this.protocol="4"===e._query.EIO?4:3,this.parser=4===this.protocol?sV:oV,this.supportsBinary=!(e._query&&e._query.b64)}get readyState(){return this._readyState}set readyState(e){aV("readyState updated from %s to %s (%s)",this._readyState,e,this.name),this._readyState=e}discard(){this.discarded=!0}onRequest(e){aV("setting request"),this.req=e}close(e){"closed"!==this.readyState&&"closing"!==this.readyState&&(this.readyState="closing",this.doClose(e||cV))}onError(e,t){if(this.listeners("error").length){const n=new Error(e);n.type="TransportError",n.description=t,this.emit("error",n)}else aV("ignored transport error %s (%s)",e,t)}onPacket(e){this.emit("packet",e)}onData(e){this.onPacket(this.parser.decodePacket(e))}onClose(){this.readyState="closed",this.emit("close")}};FG.Transport=lV,Object.defineProperty(jG,"__esModule",{value:!0}),jG.Polling=void 0;const uV=FG,pV=T,hV=KM,dV=(0,ah.default)("engine:polling"),fV={gzip:pV.createGzip,deflate:pV.createDeflate};let mV=class extends uV.Transport{constructor(e){super(e),this.closeTimeout=3e4}get name(){return"polling"}get supportsFraming(){return!1}onRequest(e){const t=e.res;e.res=null,"GET"===e.method?this.onPollRequest(e,t):"POST"===e.method?this.onDataRequest(e,t):(t.writeHead(500),t.end())}onPollRequest(e,t){if(this.req)return dV("request overlap"),this.onError("overlap from client"),t.writeHead(400),void t.end();dV("setting request"),this.req=e,this.res=t;const n=()=>{this.onError("poll connection closed prematurely")};e.cleanup=()=>{e.removeListener("close",n),this.req=this.res=null},e.on("close",n),this.writable=!0,this.emit("drain"),this.writable&&this.shouldClose&&(dV("triggering empty send to append close packet"),this.send([{type:"noop"}]))}onDataRequest(e,t){if(this.dataReq)return this.onError("data request overlap from client"),t.writeHead(400),void t.end();const n="application/octet-stream"===e.headers["content-type"];if(n&&4===this.protocol)return this.onError("invalid content");this.dataReq=e,this.dataRes=t;let r=n?Buffer.concat([]):"";const i=()=>{e.removeListener("data",o),e.removeListener("end",a),e.removeListener("close",s),this.dataReq=this.dataRes=r=null},s=()=>{i(),this.onError("data request connection closed prematurely")},o=e=>{let s;n?(r=Buffer.concat([r,e]),s=r.length):(r+=e,s=Buffer.byteLength(r)),s>this.maxHttpBufferSize&&(t.writeHead(413).end(),i())},a=()=>{this.onData(r);t.writeHead(200,this.headers(e,{"Content-Type":"text/html","Content-Length":2})),t.end("ok"),i()};e.on("close",s),n||e.setEncoding("utf8"),e.on("data",o),e.on("end",a)}onData(e){dV('received "%s"',e);const t=e=>{if("close"===e.type)return dV("got xhr close packet"),this.onClose(),!1;this.onPacket(e)};3===this.protocol?this.parser.decodePayload(e,t):this.parser.decodePayload(e).forEach(t)}onClose(){this.writable&&this.send([{type:"noop"}]),super.onClose()}send(e){this.writable=!1,this.shouldClose&&(dV("appending close packet to payload"),e.push({type:"close"}),this.shouldClose(),this.shouldClose=null);const t=t=>{const n=e.some((e=>e.options&&e.options.compress));this.write(t,{compress:n})};3===this.protocol?this.parser.encodePayload(e,this.supportsBinary,t):this.parser.encodePayload(e,t)}write(e,t){dV('writing "%s"',e),this.doWrite(e,t,(()=>{this.req.cleanup()}))}doWrite(e,t,n){const r="string"==typeof e,i={"Content-Type":r?"text/plain; charset=UTF-8":"application/octet-stream"},s=e=>{i["Content-Length"]="string"==typeof e?Buffer.byteLength(e):e.length,this.res.writeHead(200,this.headers(this.req,i)),this.res.end(e),n()};if(!this.httpCompression||!t.compress)return void s(e);if((r?Buffer.byteLength(e):e.length)<this.httpCompression.threshold)return void s(e);const o=hV(this.req).encodings(["gzip","deflate"]);o?this.compress(e,o,((e,t)=>{if(e)return this.res.writeHead(500),this.res.end(),void n(e);i["Content-Encoding"]=o,s(t)})):s(e)}compress(e,t,n){dV("compressing");const r=[];let i=0;fV[t](this.httpCompression).on("error",n).on("data",(function(e){r.push(e),i+=e.length})).on("end",(function(){n(null,Buffer.concat(r,i))})).end(e)}doClose(e){let t;dV("closing"),this.dataReq&&(dV("aborting ongoing data request"),this.dataReq.destroy());const n=()=>{clearTimeout(t),e(),this.onClose()};this.writable?(dV("transport writable - closing right away"),this.send([{type:"close"}]),n()):this.discarded?(dV("transport discarded - closing right away"),n()):(dV("transport not writable - buffering orderly close"),this.shouldClose=n,t=setTimeout(n,this.closeTimeout))}headers(e,t){t=t||{};const n=e.headers["user-agent"];return n&&(~n.indexOf(";MSIE")||~n.indexOf("Trident/"))&&(t["X-XSS-Protection"]="0"),t["cache-control"]="no-store",this.emit("headers",t,e),t}};jG.Polling=mV;var gV={};Object.defineProperty(gV,"__esModule",{value:!0}),gV.JSONP=void 0;const yV=jG,vV=L,bV=/\\\\n/g,_V=/(\\)?\\n/g;class xV extends yV.Polling{constructor(e){super(e),this.head="___eio["+(e._query.j||"").replace(/[^0-9]/g,"")+"](",this.foot=");"}onData(e){"string"==typeof(e=vV.parse(e).d)&&(e=e.replace(_V,(function(e,t){return t?e:"\n"})),super.onData(e.replace(bV,"\\n")))}doWrite(e,t,n){const r=JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029");e=this.head+r+this.foot,super.doWrite(e,t,n)}}gV.JSONP=xV;var wV={};Object.defineProperty(wV,"__esModule",{value:!0}),wV.WebSocket=void 0;const EV=FG,SV=(0,ah.default)("engine:ws");let TV=class extends EV.Transport{constructor(e){super(e),this.socket=e.websocket,this.socket.on("message",((e,t)=>{const n=t?e:e.toString();SV('received "%s"',n),super.onData(n)})),this.socket.once("close",this.onClose.bind(this)),this.socket.on("error",this.onError.bind(this)),this.writable=!0,this.perMessageDeflate=null}get name(){return"websocket"}get handlesUpgrades(){return!0}get supportsFraming(){return!0}send(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t+1===e.length,i={};n.options&&(i.compress=n.options.compress);const s=e=>{if(e)return this.onError("write error",e.stack);r&&(this.writable=!0,this.emit("drain"))},o=e=>{if(this.perMessageDeflate){("string"==typeof e?Buffer.byteLength(e):e.length)<this.perMessageDeflate.threshold&&(i.compress=!1)}SV('writing "%s"',e),this.socket.send(e,i,s)};n.options&&"string"==typeof n.options.wsPreEncoded?o(n.options.wsPreEncoded):this._canSendPreEncodedFrame(n)?this.socket._sender.sendFrame(n.options.wsPreEncodedFrame,s):this.parser.encodePacket(n,this.supportsBinary,o)}}_canSendPreEncodedFrame(e){var t,n,r;return!this.perMessageDeflate&&"function"==typeof(null===(n=null===(t=this.socket)||void 0===t?void 0:t._sender)||void 0===n?void 0:n.sendFrame)&&void 0!==(null===(r=e.options)||void 0===r?void 0:r.wsPreEncodedFrame)}doClose(e){SV("closing"),this.socket.close(),e&&e()}};wV.WebSocket=TV;var DV={};Object.defineProperty(DV,"__esModule",{value:!0}),DV.WebTransport=void 0;const kV=FG,AV=BG,CV=(0,ah.default)("engine:webtransport");let RV=class extends kV.Transport{constructor(e,t,n){super({_query:{EIO:"4"}}),this.session=e;const r=(0,AV.createPacketEncoderStream)();r.readable.pipeTo(t.writable).catch((()=>{CV("the stream was closed")})),this.writer=r.writable.getWriter(),(async()=>{try{for(;;){const{value:e,done:t}=await n.read();if(t){CV("session is closed");break}CV("received chunk: %o",e),this.onPacket(e)}}catch(e){CV("error while reading: %s",e.message)}})(),e.closed.then((()=>this.onClose())),this.writable=!0}get name(){return"webtransport"}get supportsFraming(){return!0}async send(e){this.writable=!1;try{for(let t=0;t<e.length;t++){const n=e[t];await this.writer.write(n)}}catch(e){CV("error while writing: %s",e.message)}this.writable=!0,this.emit("drain")}doClose(e){CV("closing WebTransport session"),this.session.close(),e&&e()}};DV.WebTransport=RV,Object.defineProperty(NG,"__esModule",{value:!0});const OV=jG,LV=gV,IV=wV,PV=DV;function NV(e){return"string"==typeof e._query.j?new LV.JSONP(e):new OV.Polling(e)}NG.default={polling:NV,websocket:IV.WebSocket,webtransport:PV.WebTransport},NV.upgradesTo=["websocket","webtransport"];var jV={};Object.defineProperty(jV,"__esModule",{value:!0}),jV.Socket=void 0;const FV=p,BV=P,MV=(0,ah.default)("engine:socket");let UV=class extends FV.EventEmitter{constructor(e,t,n,r,i){super(),this._readyState="opening",this.upgrading=!1,this.upgraded=!1,this.writeBuffer=[],this.packetsFn=[],this.sentCallbackFn=[],this.cleanupFn=[],this.id=e,this.server=t,this.request=r,this.protocol=i,r&&(r.websocket&&r.websocket._socket?this.remoteAddress=r.websocket._socket.remoteAddress:this.remoteAddress=r.connection.remoteAddress),this.pingTimeoutTimer=null,this.pingIntervalTimer=null,this.setTransport(n),this.onOpen()}get readyState(){return this._readyState}set readyState(e){MV("readyState updated from %s to %s",this._readyState,e),this._readyState=e}onOpen(){this.readyState="open",this.transport.sid=this.id,this.sendPacket("open",JSON.stringify({sid:this.id,upgrades:this.getAvailableUpgrades(),pingInterval:this.server.opts.pingInterval,pingTimeout:this.server.opts.pingTimeout,maxPayload:this.server.opts.maxHttpBufferSize})),this.server.opts.initialPacket&&this.sendPacket("message",this.server.opts.initialPacket),this.emit("open"),3===this.protocol?this.resetPingTimeout(this.server.opts.pingInterval+this.server.opts.pingTimeout):this.schedulePing()}onPacket(e){if("open"!==this.readyState)return MV("packet received with closed socket");switch(MV(`received packet ${e.type}`),this.emit("packet",e),this.resetPingTimeout(this.server.opts.pingInterval+this.server.opts.pingTimeout),e.type){case"ping":if(3!==this.transport.protocol)return void this.onError("invalid heartbeat direction");MV("got ping"),this.sendPacket("pong"),this.emit("heartbeat");break;case"pong":if(3===this.transport.protocol)return void this.onError("invalid heartbeat direction");MV("got pong"),this.pingIntervalTimer.refresh(),this.emit("heartbeat");break;case"error":this.onClose("parse error");break;case"message":this.emit("data",e.data),this.emit("message",e.data)}}onError(e){MV("transport error"),this.onClose("transport error",e)}schedulePing(){this.pingIntervalTimer=(0,BV.setTimeout)((()=>{MV("writing ping packet - expecting pong within %sms",this.server.opts.pingTimeout),this.sendPacket("ping"),this.resetPingTimeout(this.server.opts.pingTimeout)}),this.server.opts.pingInterval)}resetPingTimeout(e){(0,BV.clearTimeout)(this.pingTimeoutTimer),this.pingTimeoutTimer=(0,BV.setTimeout)((()=>{"closed"!==this.readyState&&this.onClose("ping timeout")}),e)}setTransport(e){const t=this.onError.bind(this),n=this.onPacket.bind(this),r=this.flush.bind(this),i=this.onClose.bind(this,"transport close");this.transport=e,this.transport.once("error",t),this.transport.on("packet",n),this.transport.on("drain",r),this.transport.once("close",i),this.setupSendCallback(),this.cleanupFn.push((function(){e.removeListener("error",t),e.removeListener("packet",n),e.removeListener("drain",r),e.removeListener("close",i)}))}maybeUpgrade(e){MV('might upgrade socket transport from "%s" to "%s"',this.transport.name,e.name),this.upgrading=!0;const t=(0,BV.setTimeout)((()=>{MV("client did not complete upgrade - closing transport"),s(),"open"===e.readyState&&e.close()}),this.server.opts.upgradeTimeout);let n;const r=t=>{"ping"===t.type&&"probe"===t.data?(MV("got probe ping packet, sending pong"),e.send([{type:"pong",data:"probe"}]),this.emit("upgrading",e),clearInterval(n),n=setInterval(i,100)):"upgrade"===t.type&&"closed"!==this.readyState?(MV("got upgrade packet - upgrading"),s(),this.transport.discard(),this.upgraded=!0,this.clearTransport(),this.setTransport(e),this.emit("upgrade",e),this.flush(),"closing"===this.readyState&&e.close((()=>{this.onClose("forced close")}))):(s(),e.close())},i=()=>{"polling"===this.transport.name&&this.transport.writable&&(MV("writing a noop packet to polling for fast upgrade"),this.transport.send([{type:"noop"}]))},s=()=>{this.upgrading=!1,clearInterval(n),(0,BV.clearTimeout)(t),e.removeListener("packet",r),e.removeListener("close",a),e.removeListener("error",o),this.removeListener("close",c)},o=t=>{MV("client did not complete upgrade - %s",t),s(),e.close(),e=null},a=()=>{o("transport closed")},c=()=>{o("socket closed")};e.on("packet",r),e.once("close",a),e.once("error",o),this.once("close",c)}clearTransport(){let e;const t=this.cleanupFn.length;for(let n=0;n<t;n++)e=this.cleanupFn.shift(),e();this.transport.on("error",(function(){MV("error triggered by discarded transport")})),this.transport.close(),(0,BV.clearTimeout)(this.pingTimeoutTimer)}onClose(e,t){"closed"!==this.readyState&&(this.readyState="closed",(0,BV.clearTimeout)(this.pingIntervalTimer),(0,BV.clearTimeout)(this.pingTimeoutTimer),process.nextTick((()=>{this.writeBuffer=[]})),this.packetsFn=[],this.sentCallbackFn=[],this.clearTransport(),this.emit("close",e,t))}setupSendCallback(){const e=()=>{if(this.sentCallbackFn.length>0){const e=this.sentCallbackFn.splice(0,1)[0];if("function"==typeof e)MV("executing send callback"),e(this.transport);else if(Array.isArray(e)){MV("executing batch send callback");const t=e.length;let n=0;for(;n<t;n++)"function"==typeof e[n]&&e[n](this.transport)}}};this.transport.on("drain",e),this.cleanupFn.push((()=>{this.transport.removeListener("drain",e)}))}send(e,t,n){return this.sendPacket("message",e,t,n),this}write(e,t,n){return this.sendPacket("message",e,t,n),this}sendPacket(e,t,n={},r){if("function"==typeof n&&(r=n,n={}),"closing"!==this.readyState&&"closed"!==this.readyState){MV('sending packet "%s" (%s)',e,t),n.compress=!1!==n.compress;const i={type:e,options:n};t&&(i.data=t),this.emit("packetCreate",i),this.writeBuffer.push(i),r&&this.packetsFn.push(r),this.flush()}}flush(){if("closed"!==this.readyState&&this.transport.writable&&this.writeBuffer.length){MV("flushing buffer to transport"),this.emit("flush",this.writeBuffer),this.server.emit("flush",this,this.writeBuffer);const e=this.writeBuffer;this.writeBuffer=[],this.transport.supportsFraming?this.sentCallbackFn.push.apply(this.sentCallbackFn,this.packetsFn):this.sentCallbackFn.push(this.packetsFn),this.packetsFn=[],this.transport.send(e),this.emit("drain"),this.server.emit("drain",this)}}getAvailableUpgrades(){const e=[],t=this.server.upgrades(this.transport.name);let n=0;const r=t.length;for(;n<r;++n){const r=t[n];-1!==this.server.opts.transports.indexOf(r)&&e.push(r)}return e}close(e){if("open"===this.readyState){if(this.readyState="closing",this.writeBuffer.length)return MV("there are %d remaining packets in the buffer, waiting for the 'drain' event",this.writeBuffer.length),void this.once("drain",(()=>{MV("all packets have been sent, closing the transport"),this.closeTransport(e)}));MV("the buffer is empty, closing the transport right away",e),this.closeTransport(e)}}closeTransport(e){MV("closing the transport (discard? %s)",e),e&&this.transport.discard(),this.transport.close(this.onClose.bind(this,"forced close"))}};jV.Socket=UV;var qV,HV,$V,zV,WV,GV,VV={exports:{}},KV={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}},YV={exports:{}},ZV={exports:{}};function QV(){if($V)return ZV.exports;$V=1;const e="function"==typeof __webpack_require__?__non_webpack_require__:rF;return"function"==typeof e.addon?ZV.exports=e.addon.bind(e):ZV.exports=function(){if(HV)return qV;HV=1;var e=s,t=o,n=a,r="function"==typeof __webpack_require__?__non_webpack_require__:rF,i=process.config&&process.config.variables||{},c=!!process.env.PREBUILDS_ONLY,l=process.versions.modules,u=process.versions&&process.versions.electron||process.env.ELECTRON_RUN_AS_NODE||"undefined"!=typeof window&&window.process&&"renderer"===window.process.type?"electron":process.versions&&process.versions.nw?"node-webkit":"node",p=process.env.npm_config_arch||n.arch(),h=process.env.npm_config_platform||n.platform(),d=process.env.LIBC||(function(t){return"linux"===t&&e.existsSync("/etc/alpine-release")}(h)?"musl":"glibc"),f=process.env.ARM_VERSION||("arm64"===p?"8":i.arm_version)||"",m=(process.versions.uv||"").split(".")[0];function g(e){return r(g.resolve(e))}function y(t){try{return e.readdirSync(t)}catch(e){return[]}}function v(e,n){var r=y(e).filter(n);return r[0]&&t.join(e,r[0])}function b(e){return/\.node$/.test(e)}function _(e){var t=e.split("-");if(2===t.length){var n=t[0],r=t[1].split("+");if(n&&r.length&&r.every(Boolean))return{name:e,platform:n,architectures:r}}}function x(e,t){return function(n){return null!=n&&n.platform===e&&n.architectures.includes(t)}}function w(e,t){return e.architectures.length-t.architectures.length}function E(e){var t=e.split("."),n={file:e,specificity:0};if("node"===t.pop()){for(var r=0;r<t.length;r++){var i=t[r];if("node"===i||"electron"===i||"node-webkit"===i)n.runtime=i;else if("napi"===i)n.napi=!0;else if("abi"===i.slice(0,3))n.abi=i.slice(3);else if("uv"===i.slice(0,2))n.uv=i.slice(2);else if("armv"===i.slice(0,4))n.armv=i.slice(4);else{if("glibc"!==i&&"musl"!==i)continue;n.libc=i}n.specificity++}return n}}function S(e,t){return function(n){return!(null==n||n.runtime&&n.runtime!==e&&!function(e){return"node"===e.runtime&&e.napi}(n)||n.abi&&n.abi!==t&&!n.napi||n.uv&&n.uv!==m||n.armv&&n.armv!==f||n.libc&&n.libc!==d)}}function T(e){return function(t,n){return t.runtime!==n.runtime?t.runtime===e?-1:1:t.abi!==n.abi?t.abi?-1:1:t.specificity!==n.specificity?t.specificity>n.specificity?-1:1:0}}return qV=g,g.resolve=g.path=function(e){e=t.resolve(e||".");try{var n=r(t.join(e,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[n+"_PREBUILD"]&&(e=process.env[n+"_PREBUILD"])}catch(e){}if(!c){var i=v(t.join(e,"build/Release"),b);if(i)return i;var s=v(t.join(e,"build/Debug"),b);if(s)return s}var o=D(e);if(o)return o;var a=D(t.dirname(process.execPath));if(a)return a;var g=["platform="+h,"arch="+p,"runtime="+u,"abi="+l,"uv="+m,f?"armv="+f:"","libc="+d,"node="+process.versions.node,process.versions.electron?"electron="+process.versions.electron:"","function"==typeof __webpack_require__?"webpack=true":""].filter(Boolean).join(" ");throw new Error("No native build was found for "+g+"\n loaded from: "+e+"\n");function D(e){var n=y(t.join(e,"prebuilds")).map(_).filter(x(h,p)).sort(w)[0];if(n){var r=t.join(e,"prebuilds",n.name),i=y(r).map(E).filter(S(u,l)).sort(T(u))[0];return i?t.join(r,i.file):void 0}}},g.parseTags=E,g.matchTags=S,g.compareTags=T,g.parseTuple=_,g.matchTuple=x,g.compareTuples=w,qV}(),ZV.exports}const{EMPTY_BUFFER:JV}=KV,XV=Buffer[Symbol.species];function eK(e,t,n,r,i){for(let s=0;s<i;s++)n[r+s]=e[s]^t[3&s]}function tK(e,t){for(let n=0;n<e.length;n++)e[n]^=t[3&n]}if(VV.exports={concat:function(e,t){if(0===e.length)return JV;if(1===e.length)return e[0];const n=Buffer.allocUnsafe(t);let r=0;for(let t=0;t<e.length;t++){const i=e[t];n.set(i,r),r+=i.length}return r<t?new XV(n.buffer,n.byteOffset,r):n},mask:eK,toArrayBuffer:function(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)},toBuffer:function e(t){if(e.readOnly=!0,Buffer.isBuffer(t))return t;let n;return t instanceof ArrayBuffer?n=new XV(t):ArrayBuffer.isView(t)?n=new XV(t.buffer,t.byteOffset,t.byteLength):(n=Buffer.from(t),e.readOnly=!1),n},unmask:tK},!process.env.WS_NO_BUFFER_UTIL)try{const e=function(){if(GV)return YV.exports;GV=1;try{YV.exports=QV()(__dirname)}catch(e){YV.exports=(WV||(WV=1,zV={mask:(e,t,n,r,i)=>{for(var s=0;s<i;s++)n[r+s]=e[s]^t[3&s]},unmask:(e,t)=>{const n=e.length;for(var r=0;r<n;r++)e[r]^=t[3&r]}}),zV)}return YV.exports}();VV.exports.mask=function(t,n,r,i,s){s<48?eK(t,n,r,i,s):e.mask(t,n,r,i,s)},VV.exports.unmask=function(t,n){t.length<32?tK(t,n):e.unmask(t,n)}}catch(e){}var nK=VV.exports;const rK=Symbol("kDone"),iK=Symbol("kRun");const sK=T,oK=nK,aK=class{constructor(e){this[rK]=()=>{this.pending--,this[iK]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[iK]()}[iK](){if(this.pending!==this.concurrency&&this.jobs.length){const e=this.jobs.shift();this.pending++,e(this[rK])}}},{kStatusCode:cK}=KV,lK=Buffer[Symbol.species],uK=Buffer.from([0,0,255,255]),pK=Symbol("permessage-deflate"),hK=Symbol("total-length"),dK=Symbol("callback"),fK=Symbol("buffers"),mK=Symbol("error");let gK;var yK=class{constructor(e,t,n){if(this._maxPayload=0|n,this._options=e||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._isServer=!!t,this._deflate=null,this._inflate=null,this.params=null,!gK){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;gK=new aK(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:null==this._options.clientMaxWindowBits&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){const e=this._deflate[dK];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){const t=this._options,n=e.find((e=>!(!1===t.serverNoContextTakeover&&e.server_no_context_takeover||e.server_max_window_bits&&(!1===t.serverMaxWindowBits||"number"==typeof t.serverMaxWindowBits&&t.serverMaxWindowBits>e.server_max_window_bits)||"number"==typeof t.clientMaxWindowBits&&!e.client_max_window_bits)));if(!n)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(n.server_no_context_takeover=!0),t.clientNoContextTakeover&&(n.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(n.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?n.client_max_window_bits=t.clientMaxWindowBits:!0!==n.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete n.client_max_window_bits,n}acceptAsClient(e){const t=e[0];if(!1===this._options.clientNoContextTakeover&&t.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(t.client_max_window_bits){if(!1===this._options.clientMaxWindowBits||"number"==typeof this._options.clientMaxWindowBits&&t.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}else"number"==typeof this._options.clientMaxWindowBits&&(t.client_max_window_bits=this._options.clientMaxWindowBits);return t}normalizeParams(e){return e.forEach((e=>{Object.keys(e).forEach((t=>{let n=e[t];if(n.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(n=n[0],"client_max_window_bits"===t){if(!0!==n){const e=+n;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${n}`);n=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${n}`)}else if("server_max_window_bits"===t){const e=+n;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${n}`);n=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==n)throw new TypeError(`Invalid value for parameter "${t}": ${n}`)}e[t]=n}))})),e}decompress(e,t,n){gK.add((r=>{this._decompress(e,t,((e,t)=>{r(),n(e,t)}))}))}compress(e,t,n){gK.add((r=>{this._compress(e,t,((e,t)=>{r(),n(e,t)}))}))}_decompress(e,t,n){const r=this._isServer?"client":"server";if(!this._inflate){const e=`${r}_max_window_bits`,t="number"!=typeof this.params[e]?sK.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=sK.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t}),this._inflate[pK]=this,this._inflate[hK]=0,this._inflate[fK]=[],this._inflate.on("error",_K),this._inflate.on("data",bK)}this._inflate[dK]=n,this._inflate.write(e),t&&this._inflate.write(uK),this._inflate.flush((()=>{const e=this._inflate[mK];if(e)return this._inflate.close(),this._inflate=null,void n(e);const i=oK.concat(this._inflate[fK],this._inflate[hK]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[hK]=0,this._inflate[fK]=[],t&&this.params[`${r}_no_context_takeover`]&&this._inflate.reset()),n(null,i)}))}_compress(e,t,n){const r=this._isServer?"server":"client";if(!this._deflate){const e=`${r}_max_window_bits`,t="number"!=typeof this.params[e]?sK.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=sK.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t}),this._deflate[hK]=0,this._deflate[fK]=[],this._deflate.on("data",vK)}this._deflate[dK]=n,this._deflate.write(e),this._deflate.flush(sK.Z_SYNC_FLUSH,(()=>{if(!this._deflate)return;let e=oK.concat(this._deflate[fK],this._deflate[hK]);t&&(e=new lK(e.buffer,e.byteOffset,e.length-4)),this._deflate[dK]=null,this._deflate[hK]=0,this._deflate[fK]=[],t&&this.params[`${r}_no_context_takeover`]&&this._deflate.reset(),n(null,e)}))}};function vK(e){this[fK].push(e),this[hK]+=e.length}function bK(e){this[hK]+=e.length,this[pK]._maxPayload<1||this[hK]<=this[pK]._maxPayload?this[fK].push(e):(this[mK]=new RangeError("Max payload size exceeded"),this[mK].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[mK][cK]=1009,this.removeListener("data",bK),this.reset())}function _K(e){this[pK]._inflate=null,e[cK]=1007,this[dK](e)}var xK,wK,EK,SK={exports:{}},TK={exports:{}};const{isUtf8:DK}=v;function kK(e){const t=e.length;let n=0;for(;n<t;)if(128&e[n])if(192==(224&e[n])){if(n+1===t||128!=(192&e[n+1])||192==(254&e[n]))return!1;n+=2}else if(224==(240&e[n])){if(n+2>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||224===e[n]&&128==(224&e[n+1])||237===e[n]&&160==(224&e[n+1]))return!1;n+=3}else{if(240!=(248&e[n]))return!1;if(n+3>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||128!=(192&e[n+3])||240===e[n]&&128==(240&e[n+1])||244===e[n]&&e[n+1]>143||e[n]>244)return!1;n+=4}else n++;return!0}if(SK.exports={isValidStatusCode:function(e){return e>=1e3&&e<=1014&&1004!==e&&1005!==e&&1006!==e||e>=3e3&&e<=4999},isValidUTF8:kK,tokenChars:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0]},DK)SK.exports.isValidUTF8=function(e){return e.length<24?kK(e):DK(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const e=function(){if(EK)return TK.exports;EK=1;try{TK.exports=QV()(__dirname)}catch(e){TK.exports=(wK||(wK=1,xK=function(e){const t=e.length;let n=0;for(;n<t;)if(128&e[n])if(192==(224&e[n])){if(n+1===t||128!=(192&e[n+1])||192==(254&e[n]))return!1;n+=2}else if(224==(240&e[n])){if(n+2>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||224===e[n]&&128==(224&e[n+1])||237===e[n]&&160==(224&e[n+1]))return!1;n+=3}else{if(240!=(248&e[n]))return!1;if(n+3>=t||128!=(192&e[n+1])||128!=(192&e[n+2])||128!=(192&e[n+3])||240===e[n]&&128==(240&e[n+1])||244===e[n]&&e[n+1]>143||e[n]>244)return!1;n+=4}else n++;return!0}),xK)}return TK.exports}();SK.exports.isValidUTF8=function(t){return t.length<32?kK(t):e(t)}}catch(e){}var AK=SK.exports;const{Writable:CK}=h,RK=yK,{BINARY_TYPES:OK,EMPTY_BUFFER:LK,kStatusCode:IK,kWebSocket:PK}=KV,{concat:NK,toArrayBuffer:jK,unmask:FK}=nK,{isValidStatusCode:BK,isValidUTF8:MK}=AK,UK=Buffer[Symbol.species];var qK=class extends CK{constructor(e={}){super(),this._allowSynchronousEvents=void 0===e.allowSynchronousEvents||e.allowSynchronousEvents,this._binaryType=e.binaryType||OK[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=0|e.maxPayload,this._skipUTF8Validation=!!e.skipUTF8Validation,this[PK]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=0}_write(e,t,n){if(8===this._opcode&&0==this._state)return n();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(n)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];return this._buffers[0]=new UK(t.buffer,t.byteOffset+e,t.length-e),new UK(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const n=this._buffers[0],r=t.length-e;e>=n.length?t.set(this._buffers.shift(),r):(t.set(new Uint8Array(n.buffer,n.byteOffset,e),r),this._buffers[0]=new UK(n.buffer,n.byteOffset+e,n.length-e)),e-=n.length}while(e>0);return t}startLoop(e){this._loop=!0;do{switch(this._state){case 0:this.getInfo(e);break;case 1:this.getPayloadLength16(e);break;case 2:this.getPayloadLength64(e);break;case 3:this.getMask();break;case 4:this.getData(e);break;case 5:case 6:return void(this._loop=!1)}}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2)return void(this._loop=!1);const t=this.consume(2);if(48&t[0]){return void e(this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3"))}const n=!(64&~t[0]);if(!n||this._extensions[RK.extensionName]){if(this._fin=!(128&~t[0]),this._opcode=15&t[0],this._payloadLength=127&t[1],0===this._opcode){if(n){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(!this._fragmented){return void e(this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE"))}this._opcode=this._fragmented}else if(1===this._opcode||2===this._opcode){if(this._fragmented){return void e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}this._compressed=n}else{if(!(this._opcode>7&&this._opcode<11)){return void e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}if(!this._fin){return void e(this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN"))}if(n){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(this._payloadLength>125||8===this._opcode&&1===this._payloadLength){return void e(this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"))}}if(this._fin||this._fragmented||(this._fragmented=this._opcode),this._masked=!(128&~t[1]),this._isServer){if(!this._masked){return void e(this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK"))}}else if(this._masked){return void e(this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK"))}126===this._payloadLength?this._state=1:127===this._payloadLength?this._state=2:this.haveLength(e)}else{e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}}getPayloadLength16(e){this._bufferedBytes<2?this._loop=!1:(this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e))}getPayloadLength64(e){if(this._bufferedBytes<8)return void(this._loop=!1);const t=this.consume(8),n=t.readUInt32BE(0);if(n>Math.pow(2,21)-1){e(this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"))}else this._payloadLength=n*Math.pow(2,32)+t.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){e(this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"))}else this._masked?this._state=3:this._state=4}getMask(){this._bufferedBytes<4?this._loop=!1:(this._mask=this.consume(4),this._state=4)}getData(e){let t=LK;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength)return void(this._loop=!1);t=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&FK(t,this._mask)}if(this._opcode>7)this.controlMessage(t,e);else{if(this._compressed)return this._state=5,void this.decompress(t,e);t.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(t)),this.dataMessage(e)}}decompress(e,t){this._extensions[RK.extensionName].decompress(e,this._fin,((e,n)=>{if(e)return t(e);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){const e=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");return void t(e)}this._fragments.push(n)}this.dataMessage(t),0===this._state&&this.startLoop(t)}))}dataMessage(e){if(!this._fin)return void(this._state=0);const t=this._messageLength,n=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],2===this._opcode){let r;r="nodebuffer"===this._binaryType?NK(n,t):"arraybuffer"===this._binaryType?jK(NK(n,t)):n,this._allowSynchronousEvents?(this.emit("message",r,!0),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",r,!0),this._state=0,this.startLoop(e)})))}else{const r=NK(n,t);if(!this._skipUTF8Validation&&!MK(r)){const t=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void e(t)}5===this._state||this._allowSynchronousEvents?(this.emit("message",r,!1),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",r,!1),this._state=0,this.startLoop(e)})))}}controlMessage(e,t){if(8!==this._opcode)this._allowSynchronousEvents?(this.emit(9===this._opcode?"ping":"pong",e),this._state=0):(this._state=6,setImmediate((()=>{this.emit(9===this._opcode?"ping":"pong",e),this._state=0,this.startLoop(t)})));else{if(0===e.length)this._loop=!1,this.emit("conclude",1005,LK),this.end();else{const n=e.readUInt16BE(0);if(!BK(n)){const e=this.createError(RangeError,`invalid status code ${n}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void t(e)}const r=new UK(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!MK(r)){const e=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void t(e)}this._loop=!1,this.emit("conclude",n,r),this.end()}this._state=0}}createError(e,t,n,r,i){this._loop=!1,this._errored=!0;const s=new e(n?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(s,this.createError),s.code=i,s[IK]=r,s}};const{randomFillSync:HK}=x,$K=yK,{EMPTY_BUFFER:zK}=KV,{isValidStatusCode:WK}=AK,{mask:GK,toBuffer:VK}=nK,KK=Symbol("kByteLength"),YK=Buffer.alloc(4),ZK=8192;let QK,JK=ZK;var XK=class e{constructor(e,t,n){this._extensions=t||{},n&&(this._generateMask=n,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(e,t){let n,r,i=!1,s=2,o=!1;t.mask&&(n=t.maskBuffer||YK,t.generateMask?t.generateMask(n):(JK===ZK&&(void 0===QK&&(QK=Buffer.alloc(ZK)),HK(QK,0,ZK),JK=0),n[0]=QK[JK++],n[1]=QK[JK++],n[2]=QK[JK++],n[3]=QK[JK++]),o=!(n[0]|n[1]|n[2]|n[3]),s=6),"string"==typeof e?r=t.mask&&!o||void 0===t[KK]?(e=Buffer.from(e)).length:t[KK]:(r=e.length,i=t.mask&&t.readOnly&&!o);let a=r;r>=65536?(s+=8,a=127):r>125&&(s+=2,a=126);const c=Buffer.allocUnsafe(i?r+s:s);return c[0]=t.fin?128|t.opcode:t.opcode,t.rsv1&&(c[0]|=64),c[1]=a,126===a?c.writeUInt16BE(r,2):127===a&&(c[2]=c[3]=0,c.writeUIntBE(r,4,6)),t.mask?(c[1]|=128,c[s-4]=n[0],c[s-3]=n[1],c[s-2]=n[2],c[s-1]=n[3],o?[c,e]:i?(GK(e,n,c,s,r),[c]):(GK(e,n,e,0,r),[c,e])):[c,e]}close(t,n,r,i){let s;if(void 0===t)s=zK;else{if("number"!=typeof t||!WK(t))throw new TypeError("First argument must be a valid error code number");if(void 0!==n&&n.length){const e=Buffer.byteLength(n);if(e>123)throw new RangeError("The message must not be greater than 123 bytes");s=Buffer.allocUnsafe(2+e),s.writeUInt16BE(t,0),"string"==typeof n?s.write(n,2):s.set(n,2)}else s=Buffer.allocUnsafe(2),s.writeUInt16BE(t,0)}const o={[KK]:s.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._deflating?this.enqueue([this.dispatch,s,!1,o,i]):this.sendFrame(e.frame(s,o),i)}ping(t,n,r){let i,s;if("string"==typeof t?(i=Buffer.byteLength(t),s=!1):(i=(t=VK(t)).length,s=VK.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[KK]:i,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:9,readOnly:s,rsv1:!1};this._deflating?this.enqueue([this.dispatch,t,!1,o,r]):this.sendFrame(e.frame(t,o),r)}pong(t,n,r){let i,s;if("string"==typeof t?(i=Buffer.byteLength(t),s=!1):(i=(t=VK(t)).length,s=VK.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[KK]:i,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:10,readOnly:s,rsv1:!1};this._deflating?this.enqueue([this.dispatch,t,!1,o,r]):this.sendFrame(e.frame(t,o),r)}send(t,n,r){const i=this._extensions[$K.extensionName];let s,o,a=n.binary?2:1,c=n.compress;if("string"==typeof t?(s=Buffer.byteLength(t),o=!1):(s=(t=VK(t)).length,o=VK.readOnly),this._firstFragment?(this._firstFragment=!1,c&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(c=s>=i._threshold),this._compress=c):(c=!1,a=0),n.fin&&(this._firstFragment=!0),i){const e={[KK]:s,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:a,readOnly:o,rsv1:c};this._deflating?this.enqueue([this.dispatch,t,this._compress,e,r]):this.dispatch(t,this._compress,e,r)}else this.sendFrame(e.frame(t,{[KK]:s,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:a,readOnly:o,rsv1:!1}),r)}dispatch(t,n,r,i){if(!n)return void this.sendFrame(e.frame(t,r),i);const s=this._extensions[$K.extensionName];this._bufferedBytes+=r[KK],this._deflating=!0,s.compress(t,r.fin,((t,n)=>{if(this._socket.destroyed){const e=new Error("The socket was closed while data was being compressed");"function"==typeof i&&i(e);for(let t=0;t<this._queue.length;t++){const n=this._queue[t],r=n[n.length-1];"function"==typeof r&&r(e)}}else this._bufferedBytes-=r[KK],this._deflating=!1,r.readOnly=!1,this.sendFrame(e.frame(n,r),i),this.dequeue()}))}dequeue(){for(;!this._deflating&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[3][KK],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][KK],this._queue.push(e)}sendFrame(e,t){2===e.length?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],t),this._socket.uncork()):this._socket.write(e[0],t)}};const{kForOnEventAttribute:eY,kListener:tY}=KV,nY=Symbol("kCode"),rY=Symbol("kData"),iY=Symbol("kError"),sY=Symbol("kMessage"),oY=Symbol("kReason"),aY=Symbol("kTarget"),cY=Symbol("kType"),lY=Symbol("kWasClean");class uY{constructor(e){this[aY]=null,this[cY]=e}get target(){return this[aY]}get type(){return this[cY]}}Object.defineProperty(uY.prototype,"target",{enumerable:!0}),Object.defineProperty(uY.prototype,"type",{enumerable:!0});class pY extends uY{constructor(e,t={}){super(e),this[nY]=void 0===t.code?0:t.code,this[oY]=void 0===t.reason?"":t.reason,this[lY]=void 0!==t.wasClean&&t.wasClean}get code(){return this[nY]}get reason(){return this[oY]}get wasClean(){return this[lY]}}Object.defineProperty(pY.prototype,"code",{enumerable:!0}),Object.defineProperty(pY.prototype,"reason",{enumerable:!0}),Object.defineProperty(pY.prototype,"wasClean",{enumerable:!0});class hY extends uY{constructor(e,t={}){super(e),this[iY]=void 0===t.error?null:t.error,this[sY]=void 0===t.message?"":t.message}get error(){return this[iY]}get message(){return this[sY]}}Object.defineProperty(hY.prototype,"error",{enumerable:!0}),Object.defineProperty(hY.prototype,"message",{enumerable:!0});class dY extends uY{constructor(e,t={}){super(e),this[rY]=void 0===t.data?null:t.data}get data(){return this[rY]}}Object.defineProperty(dY.prototype,"data",{enumerable:!0});const fY={addEventListener(e,t,n={}){for(const r of this.listeners(e))if(!n[eY]&&r[tY]===t&&!r[eY])return;let r;if("message"===e)r=function(e,n){const r=new dY("message",{data:n?e:e.toString()});r[aY]=this,gY(t,this,r)};else if("close"===e)r=function(e,n){const r=new pY("close",{code:e,reason:n.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});r[aY]=this,gY(t,this,r)};else if("error"===e)r=function(e){const n=new hY("error",{error:e,message:e.message});n[aY]=this,gY(t,this,n)};else{if("open"!==e)return;r=function(){const e=new uY("open");e[aY]=this,gY(t,this,e)}}r[eY]=!!n[eY],r[tY]=t,n.once?this.once(e,r):this.on(e,r)},removeEventListener(e,t){for(const n of this.listeners(e))if(n[tY]===t&&!n[eY]){this.removeListener(e,n);break}}};var mY={CloseEvent:pY,ErrorEvent:hY,Event:uY,EventTarget:fY,MessageEvent:dY};function gY(e,t,n){"object"==typeof e&&e.handleEvent?e.handleEvent.call(e,n):e.call(t,n)}const{tokenChars:yY}=AK;function vY(e,t,n){void 0===e[t]?e[t]=[n]:e[t].push(n)}var bY={format:function(e){return Object.keys(e).map((t=>{let n=e[t];return Array.isArray(n)||(n=[n]),n.map((e=>[t].concat(Object.keys(e).map((t=>{let n=e[t];return Array.isArray(n)||(n=[n]),n.map((e=>!0===e?t:`${t}=${e}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")},parse:function(e){const t=Object.create(null);let n,r,i=Object.create(null),s=!1,o=!1,a=!1,c=-1,l=-1,u=-1,p=0;for(;p<e.length;p++)if(l=e.charCodeAt(p),void 0===n)if(-1===u&&1===yY[l])-1===c&&(c=p);else if(0===p||32!==l&&9!==l){if(59!==l&&44!==l)throw new SyntaxError(`Unexpected character at index ${p}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===u&&(u=p);const r=e.slice(c,u);44===l?(vY(t,r,i),i=Object.create(null)):n=r,c=u=-1}}else-1===u&&-1!==c&&(u=p);else if(void 0===r)if(-1===u&&1===yY[l])-1===c&&(c=p);else if(32===l||9===l)-1===u&&-1!==c&&(u=p);else if(59===l||44===l){if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===u&&(u=p),vY(i,e.slice(c,u),!0),44===l&&(vY(t,n,i),i=Object.create(null),n=void 0),c=u=-1}else{if(61!==l||-1===c||-1!==u)throw new SyntaxError(`Unexpected character at index ${p}`);r=e.slice(c,p),c=u=-1}else if(o){if(1!==yY[l])throw new SyntaxError(`Unexpected character at index ${p}`);-1===c?c=p:s||(s=!0),o=!1}else if(a)if(1===yY[l])-1===c&&(c=p);else if(34===l&&-1!==c)a=!1,u=p;else{if(92!==l)throw new SyntaxError(`Unexpected character at index ${p}`);o=!0}else if(34===l&&61===e.charCodeAt(p-1))a=!0;else if(-1===u&&1===yY[l])-1===c&&(c=p);else if(-1===c||32!==l&&9!==l){if(59!==l&&44!==l)throw new SyntaxError(`Unexpected character at index ${p}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===u&&(u=p);let o=e.slice(c,u);s&&(o=o.replace(/\\/g,""),s=!1),vY(i,r,o),44===l&&(vY(t,n,i),i=Object.create(null),n=void 0),r=void 0,c=u=-1}}else-1===u&&(u=p);if(-1===c||a||32===l||9===l)throw new SyntaxError("Unexpected end of input");-1===u&&(u=p);const h=e.slice(c,u);return void 0===n?vY(t,h,i):(void 0===r?vY(i,h,!0):vY(i,r,s?h.replace(/\\/g,""):h),vY(t,n,i)),t}};const _Y=p,xY=E,wY=w,EY=O,SY=N,{randomBytes:TY,createHash:DY}=x,{URL:kY}=S,AY=yK,CY=qK,RY=XK,{BINARY_TYPES:OY,EMPTY_BUFFER:LY,GUID:IY,kForOnEventAttribute:PY,kListener:NY,kStatusCode:jY,kWebSocket:FY,NOOP:BY}=KV,{EventTarget:{addEventListener:MY,removeEventListener:UY}}=mY,{format:qY,parse:HY}=bY,{toBuffer:$Y}=nK,zY=Symbol("kAborted"),WY=[8,13],GY=["CONNECTING","OPEN","CLOSING","CLOSED"],VY=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;let KY=class e extends _Y{constructor(t,n,r){super(),this._binaryType=OY[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=LY,this._closeTimer=null,this._extensions={},this._paused=!1,this._protocol="",this._readyState=e.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,null!==t?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,void 0===n?n=[]:Array.isArray(n)||("object"==typeof n&&null!==n?(r=n,n=[]):n=[n]),ZY(this,t,n,r)):(this._autoPong=r.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){OY.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(t,n,r){const i=new CY({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation});this._sender=new RY(t,this._extensions,r.generateMask),this._receiver=i,this._socket=t,i[FY]=this,t[FY]=this,i.on("conclude",nZ),i.on("drain",rZ),i.on("error",iZ),i.on("message",oZ),i.on("ping",aZ),i.on("pong",cZ),t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),n.length>0&&t.unshift(n),t.on("close",uZ),t.on("data",pZ),t.on("end",hZ),t.on("error",dZ),this._readyState=e.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=e.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[AY.extensionName]&&this._extensions[AY.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(t,n){if(this.readyState!==e.CLOSED)if(this.readyState!==e.CONNECTING)this.readyState!==e.CLOSING?(this._readyState=e.CLOSING,this._sender.close(t,n,!this._isServer,(e=>{e||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())})),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),3e4)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();else{const e="WebSocket was closed before the connection was established";eZ(this,this._req,e)}}pause(){this.readyState!==e.CONNECTING&&this.readyState!==e.CLOSED&&(this._paused=!0,this._socket.pause())}ping(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(r=t,t=n=void 0):"function"==typeof n&&(r=n,n=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===e.OPEN?(void 0===n&&(n=!this._isServer),this._sender.ping(t||LY,n,r)):tZ(this,t,r)}pong(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(r=t,t=n=void 0):"function"==typeof n&&(r=n,n=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===e.OPEN?(void 0===n&&(n=!this._isServer),this._sender.pong(t||LY,n,r)):tZ(this,t,r)}resume(){this.readyState!==e.CONNECTING&&this.readyState!==e.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof n&&(r=n,n={}),"number"==typeof t&&(t=t.toString()),this.readyState!==e.OPEN)return void tZ(this,t,r);const i={binary:"string"!=typeof t,mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[AY.extensionName]||(i.compress=!1),this._sender.send(t||LY,i,r)}terminate(){if(this.readyState!==e.CLOSED)if(this.readyState!==e.CONNECTING)this._socket&&(this._readyState=e.CLOSING,this._socket.destroy());else{const e="WebSocket was closed before the connection was established";eZ(this,this._req,e)}}};Object.defineProperty(KY,"CONNECTING",{enumerable:!0,value:GY.indexOf("CONNECTING")}),Object.defineProperty(KY.prototype,"CONNECTING",{enumerable:!0,value:GY.indexOf("CONNECTING")}),Object.defineProperty(KY,"OPEN",{enumerable:!0,value:GY.indexOf("OPEN")}),Object.defineProperty(KY.prototype,"OPEN",{enumerable:!0,value:GY.indexOf("OPEN")}),Object.defineProperty(KY,"CLOSING",{enumerable:!0,value:GY.indexOf("CLOSING")}),Object.defineProperty(KY.prototype,"CLOSING",{enumerable:!0,value:GY.indexOf("CLOSING")}),Object.defineProperty(KY,"CLOSED",{enumerable:!0,value:GY.indexOf("CLOSED")}),Object.defineProperty(KY.prototype,"CLOSED",{enumerable:!0,value:GY.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(KY.prototype,e,{enumerable:!0})})),["open","error","close","message"].forEach((e=>{Object.defineProperty(KY.prototype,`on${e}`,{enumerable:!0,get(){for(const t of this.listeners(e))if(t[PY])return t[NY];return null},set(t){for(const t of this.listeners(e))if(t[PY]){this.removeListener(e,t);break}"function"==typeof t&&this.addEventListener(e,t,{[PY]:!0})}})})),KY.prototype.addEventListener=MY,KY.prototype.removeEventListener=UY;var YY=KY;function ZY(e,t,n,r){const i={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:WY[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(e._autoPong=i.autoPong,!WY.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${WY.join(", ")})`);let s;if(t instanceof kY)s=t;else try{s=new kY(t)}catch(e){throw new SyntaxError(`Invalid URL: ${t}`)}"http:"===s.protocol?s.protocol="ws:":"https:"===s.protocol&&(s.protocol="wss:"),e._url=s.href;const o="wss:"===s.protocol,a="ws+unix:"===s.protocol;let c;if("ws:"===s.protocol||o||a?a&&!s.pathname?c="The URL's pathname is empty":s.hash&&(c="The URL contains a fragment identifier"):c='The URL\'s protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"',c){const t=new SyntaxError(c);if(0===e._redirects)throw t;return void QY(e,t)}const l=o?443:80,u=TY(16).toString("base64"),p=o?xY.request:wY.request,h=new Set;let d,f;if(i.createConnection=i.createConnection||(o?XY:JY),i.defaultPort=i.defaultPort||l,i.port=s.port||l,i.host=s.hostname.startsWith("[")?s.hostname.slice(1,-1):s.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":u,Connection:"Upgrade",Upgrade:"websocket"},i.path=s.pathname+s.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(d=new AY(!0!==i.perMessageDeflate?i.perMessageDeflate:{},!1,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=qY({[AY.extensionName]:d.offer()})),n.length){for(const e of n){if("string"!=typeof e||!VY.test(e)||h.has(e))throw new SyntaxError("An invalid or duplicated subprotocol was specified");h.add(e)}i.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(s.username||s.password)&&(i.auth=`${s.username}:${s.password}`),a){const e=i.path.split(":");i.socketPath=e[0],i.path=e[1]}if(i.followRedirects){if(0===e._redirects){e._originalIpc=a,e._originalSecure=o,e._originalHostOrSocketPath=a?i.socketPath:s.host;const t=r&&r.headers;if(r={...r,headers:{}},t)for(const[e,n]of Object.entries(t))r.headers[e.toLowerCase()]=n}else if(0===e.listenerCount("redirect")){const t=a?!!e._originalIpc&&i.socketPath===e._originalHostOrSocketPath:!e._originalIpc&&s.host===e._originalHostOrSocketPath;(!t||e._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,t||delete i.headers.host,i.auth=void 0)}i.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),f=e._req=p(i),e._redirects&&e.emit("redirect",e.url,f)}else f=e._req=p(i);i.timeout&&f.on("timeout",(()=>{eZ(e,f,"Opening handshake has timed out")})),f.on("error",(t=>{null===f||f[zY]||(f=e._req=null,QY(e,t))})),f.on("response",(s=>{const o=s.headers.location,a=s.statusCode;if(o&&i.followRedirects&&a>=300&&a<400){if(++e._redirects>i.maxRedirects)return void eZ(e,f,"Maximum redirects exceeded");let s;f.abort();try{s=new kY(o,t)}catch(t){const n=new SyntaxError(`Invalid URL: ${o}`);return void QY(e,n)}ZY(e,s,n,r)}else e.emit("unexpected-response",f,s)||eZ(e,f,`Unexpected server response: ${s.statusCode}`)})),f.on("upgrade",((t,n,r)=>{if(e.emit("upgrade",t),e.readyState!==KY.CONNECTING)return;f=e._req=null;const s=t.headers.upgrade;if(void 0===s||"websocket"!==s.toLowerCase())return void eZ(e,n,"Invalid Upgrade header");const o=DY("sha1").update(u+IY).digest("base64");if(t.headers["sec-websocket-accept"]!==o)return void eZ(e,n,"Invalid Sec-WebSocket-Accept header");const a=t.headers["sec-websocket-protocol"];let c;if(void 0!==a?h.size?h.has(a)||(c="Server sent an invalid subprotocol"):c="Server sent a subprotocol but none was requested":h.size&&(c="Server sent no subprotocol"),c)return void eZ(e,n,c);a&&(e._protocol=a);const l=t.headers["sec-websocket-extensions"];if(void 0!==l){if(!d){return void eZ(e,n,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let t;try{t=HY(l)}catch(t){return void eZ(e,n,"Invalid Sec-WebSocket-Extensions header")}const r=Object.keys(t);if(1!==r.length||r[0]!==AY.extensionName){return void eZ(e,n,"Server indicated an extension that was not requested")}try{d.accept(t[AY.extensionName])}catch(t){return void eZ(e,n,"Invalid Sec-WebSocket-Extensions header")}e._extensions[AY.extensionName]=d}e.setSocket(n,r,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})})),i.finishRequest?i.finishRequest(f,e):f.end()}function QY(e,t){e._readyState=KY.CLOSING,e.emit("error",t),e.emitClose()}function JY(e){return e.path=e.socketPath,EY.connect(e)}function XY(e){return e.path=void 0,e.servername||""===e.servername||(e.servername=EY.isIP(e.host)?"":e.host),SY.connect(e)}function eZ(e,t,n){e._readyState=KY.CLOSING;const r=new Error(n);Error.captureStackTrace(r,eZ),t.setHeader?(t[zY]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(QY,e,r)):(t.destroy(r),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function tZ(e,t,n){if(t){const n=$Y(t).length;e._socket?e._sender._bufferedBytes+=n:e._bufferedAmount+=n}if(n){const t=new Error(`WebSocket is not open: readyState ${e.readyState} (${GY[e.readyState]})`);process.nextTick(n,t)}}function nZ(e,t){const n=this[FY];n._closeFrameReceived=!0,n._closeMessage=t,n._closeCode=e,void 0!==n._socket[FY]&&(n._socket.removeListener("data",pZ),process.nextTick(lZ,n._socket),1005===e?n.close():n.close(e,t))}function rZ(){const e=this[FY];e.isPaused||e._socket.resume()}function iZ(e){const t=this[FY];void 0!==t._socket[FY]&&(t._socket.removeListener("data",pZ),process.nextTick(lZ,t._socket),t.close(e[jY])),t.emit("error",e)}function sZ(){this[FY].emitClose()}function oZ(e,t){this[FY].emit("message",e,t)}function aZ(e){const t=this[FY];t._autoPong&&t.pong(e,!this._isServer,BY),t.emit("ping",e)}function cZ(e){this[FY].emit("pong",e)}function lZ(e){e.resume()}function uZ(){const e=this[FY];let t;this.removeListener("close",uZ),this.removeListener("data",pZ),this.removeListener("end",hZ),e._readyState=KY.CLOSING,this._readableState.endEmitted||e._closeFrameReceived||e._receiver._writableState.errorEmitted||null===(t=e._socket.read())||e._receiver.write(t),e._receiver.end(),this[FY]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",sZ),e._receiver.on("finish",sZ))}function pZ(e){this[FY]._receiver.write(e)||this.pause()}function hZ(){const e=this[FY];e._readyState=KY.CLOSING,e._receiver.end(),this.end()}function dZ(){const e=this[FY];this.removeListener("error",dZ),this.on("error",BY),e&&(e._readyState=KY.CLOSING,this.destroy())}var fZ=q(YY);const{Duplex:mZ}=h;function gZ(e){e.emit("close")}function yZ(){!this.destroyed&&this._writableState.finished&&this.destroy()}function vZ(e){this.removeListener("error",vZ),this.destroy(),0===this.listenerCount("error")&&this.emit("error",e)}var bZ=function(e,t){let n=!0;const r=new mZ({...t,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return e.on("message",(function(t,n){const i=!n&&r._readableState.objectMode?t.toString():t;r.push(i)||e.pause()})),e.once("error",(function(e){r.destroyed||(n=!1,r.destroy(e))})),e.once("close",(function(){r.destroyed||r.push(null)})),r._destroy=function(t,i){if(e.readyState===e.CLOSED)return i(t),void process.nextTick(gZ,r);let s=!1;e.once("error",(function(e){s=!0,i(e)})),e.once("close",(function(){s||i(t),process.nextTick(gZ,r)})),n&&e.terminate()},r._final=function(t){e.readyState!==e.CONNECTING?null!==e._socket&&(e._socket._writableState.finished?(t(),r._readableState.endEmitted&&r.destroy()):(e._socket.once("finish",(function(){t()})),e.close())):e.once("open",(function(){r._final(t)}))},r._read=function(){e.isPaused&&e.resume()},r._write=function(t,n,i){e.readyState!==e.CONNECTING?e.send(t,i):e.once("open",(function(){r._write(t,n,i)}))},r.on("end",yZ),r.on("error",vZ),r};const{tokenChars:_Z}=AK;var xZ={parse:function(e){const t=new Set;let n=-1,r=-1,i=0;for(;i<e.length;i++){const s=e.charCodeAt(i);if(-1===r&&1===_Z[s])-1===n&&(n=i);else if(0===i||32!==s&&9!==s){if(44!==s)throw new SyntaxError(`Unexpected character at index ${i}`);{if(-1===n)throw new SyntaxError(`Unexpected character at index ${i}`);-1===r&&(r=i);const s=e.slice(n,r);if(t.has(s))throw new SyntaxError(`The "${s}" subprotocol is duplicated`);t.add(s),n=r=-1}}else-1===r&&-1!==n&&(r=i)}if(-1===n||-1!==r)throw new SyntaxError("Unexpected end of input");const s=e.slice(n,i);if(t.has(s))throw new SyntaxError(`The "${s}" subprotocol is duplicated`);return t.add(s),t}};const wZ=p,EZ=w,{createHash:SZ}=x,TZ=bY,DZ=yK,kZ=xZ,AZ=YY,{GUID:CZ,kWebSocket:RZ}=KV,OZ=/^[+/0-9A-Za-z]{22}==$/;var LZ=class extends wZ{constructor(e,t){if(super(),null==(e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:AZ,...e}).port&&!e.server&&!e.noServer||null!=e.port&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(null!=e.port?(this._server=EZ.createServer(((e,t)=>{const n=EZ.STATUS_CODES[426];t.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),t.end(n)})),this._server.listen(e.port,e.host,e.backlog,t)):e.server&&(this._server=e.server),this._server){const e=this.emit.bind(this,"connection");this._removeListeners=function(e,t){for(const n of Object.keys(t))e.on(n,t[n]);return function(){for(const n of Object.keys(t))e.removeListener(n,t[n])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,n,r)=>{this.handleUpgrade(t,n,r,e)}})}!0===e.perMessageDeflate&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=0}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(2===this._state)return e&&this.once("close",(()=>{e(new Error("The server is not running"))})),void process.nextTick(IZ,this);if(e&&this.once("close",e),1!==this._state)if(this._state=1,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients&&this.clients.size?this._shouldEmitClose=!0:process.nextTick(IZ,this);else{const e=this._server;this._removeListeners(),this._removeListeners=this._server=null,e.close((()=>{IZ(this)}))}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");if((-1!==t?e.url.slice(0,t):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,t,n,r){t.on("error",PZ);const i=e.headers["sec-websocket-key"],s=e.headers.upgrade,o=+e.headers["sec-websocket-version"];if("GET"!==e.method){return void jZ(this,e,t,405,"Invalid HTTP method")}if(void 0===s||"websocket"!==s.toLowerCase()){return void jZ(this,e,t,400,"Invalid Upgrade header")}if(void 0===i||!OZ.test(i)){return void jZ(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header")}if(8!==o&&13!==o){return void jZ(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header")}if(!this.shouldHandle(e))return void NZ(t,400);const a=e.headers["sec-websocket-protocol"];let c=new Set;if(void 0!==a)try{c=kZ.parse(a)}catch(n){return void jZ(this,e,t,400,"Invalid Sec-WebSocket-Protocol header")}const l=e.headers["sec-websocket-extensions"],u={};if(this.options.perMessageDeflate&&void 0!==l){const n=new DZ(this.options.perMessageDeflate,!0,this.options.maxPayload);try{const e=TZ.parse(l);e[DZ.extensionName]&&(n.accept(e[DZ.extensionName]),u[DZ.extensionName]=n)}catch(n){return void jZ(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const s={origin:e.headers[""+(8===o?"sec-websocket-origin":"origin")],secure:!(!e.socket.authorized&&!e.socket.encrypted),req:e};if(2===this.options.verifyClient.length)return void this.options.verifyClient(s,((s,o,a,l)=>{if(!s)return NZ(t,o||401,a,l);this.completeUpgrade(u,i,c,e,t,n,r)}));if(!this.options.verifyClient(s))return NZ(t,401)}this.completeUpgrade(u,i,c,e,t,n,r)}completeUpgrade(e,t,n,r,i,s,o){if(!i.readable||!i.writable)return i.destroy();if(i[RZ])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return NZ(i,503);const a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${SZ("sha1").update(t+CZ).digest("base64")}`],c=new this.options.WebSocket(null,void 0,this.options);if(n.size){const e=this.options.handleProtocols?this.options.handleProtocols(n,r):n.values().next().value;e&&(a.push(`Sec-WebSocket-Protocol: ${e}`),c._protocol=e)}if(e[DZ.extensionName]){const t=e[DZ.extensionName].params,n=TZ.format({[DZ.extensionName]:[t]});a.push(`Sec-WebSocket-Extensions: ${n}`),c._extensions=e}this.emit("headers",a,r),i.write(a.concat("\r\n").join("\r\n")),i.removeListener("error",PZ),c.setSocket(i,s,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(c),c.on("close",(()=>{this.clients.delete(c),this._shouldEmitClose&&!this.clients.size&&process.nextTick(IZ,this)}))),o(c,r)}};function IZ(e){e._state=2,e.emit("close")}function PZ(){this.destroy()}function NZ(e,t,n,r){n=n||EZ.STATUS_CODES[t],r={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(n),...r},e.once("finish",e.destroy),e.end(`HTTP/1.1 ${t} ${EZ.STATUS_CODES[t]}\r\n`+Object.keys(r).map((e=>`${e}: ${r[e]}`)).join("\r\n")+"\r\n\r\n"+n)}function jZ(e,t,n,r,i){if(e.listenerCount("wsClientError")){const r=new Error(i);Error.captureStackTrace(r,jZ),e.emit("wsClientError",r,n,t)}else NZ(n,r,i)}const FZ=YY;FZ.createWebSocketStream=bZ,FZ.Server=LZ,FZ.Receiver=qK,FZ.Sender=XK,FZ.WebSocket=FZ,FZ.WebSocketServer=FZ.Server;var BZ=FZ,MZ={exports:{}},UZ=Object.getOwnPropertySymbols,qZ=Object.prototype.hasOwnProperty,HZ=Object.prototype.propertyIsEnumerable;var $Z=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,r,i=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),s=1;s<arguments.length;s++){for(var o in n=Object(arguments[s]))qZ.call(n,o)&&(i[o]=n[o]);if(UZ){r=UZ(n);for(var a=0;a<r.length;a++)HZ.call(n,r[a])&&(i[r[a]]=n[r[a]])}}return i};!function(){var e=$Z,t=xU,n={origin:"*",methods:"GET,HEAD,PUT,PATCH,POST,DELETE",preflightContinue:!1,optionsSuccessStatus:204};function r(e){return"string"==typeof e||e instanceof String}function i(e,t){if(Array.isArray(t)){for(var n=0;n<t.length;++n)if(i(e,t[n]))return!0;return!1}return r(t)?e===t:t instanceof RegExp?t.test(e):!!t}function s(e,t){var n,s=t.headers.origin,o=[];return e.origin&&"*"!==e.origin?r(e.origin)?(o.push([{key:"Access-Control-Allow-Origin",value:e.origin}]),o.push([{key:"Vary",value:"Origin"}])):(n=i(s,e.origin),o.push([{key:"Access-Control-Allow-Origin",value:!!n&&s}]),o.push([{key:"Vary",value:"Origin"}])):o.push([{key:"Access-Control-Allow-Origin",value:"*"}]),o}function o(e){return!0===e.credentials?{key:"Access-Control-Allow-Credentials",value:"true"}:null}function a(e){var t=e.exposedHeaders;return t?(t.join&&(t=t.join(",")),t&&t.length?{key:"Access-Control-Expose-Headers",value:t}:null):null}function c(e,n){for(var r=0,i=e.length;r<i;r++){var s=e[r];s&&(Array.isArray(s)?c(s,n):"Vary"===s.key&&s.value?t(n,s.value):s.value&&n.setHeader(s.key,s.value))}}MZ.exports=function(t){var r=null;return r="function"==typeof t?t:function(e,n){n(null,t)},function(t,i,l){r(t,(function(r,u){if(r)l(r);else{var p=e({},n,u),h=null;p.origin&&"function"==typeof p.origin?h=p.origin:p.origin&&(h=function(e,t){t(null,p.origin)}),h?h(t.headers.origin,(function(e,n){e||!n?l(e):(p.origin=n,function(e,t,n,r){var i=[];"OPTIONS"===(t.method&&t.method.toUpperCase&&t.method.toUpperCase())?(i.push(s(e,t)),i.push(o(e)),i.push(function(e){var t=e.methods;return t.join&&(t=e.methods.join(",")),{key:"Access-Control-Allow-Methods",value:t}}(e)),i.push(function(e,t){var n=e.allowedHeaders||e.headers,r=[];return n?n.join&&(n=n.join(",")):(n=t.headers["access-control-request-headers"],r.push([{key:"Vary",value:"Access-Control-Request-Headers"}])),n&&n.length&&r.push([{key:"Access-Control-Allow-Headers",value:n}]),r}(e,t)),i.push(function(e){var t=("number"==typeof e.maxAge||e.maxAge)&&e.maxAge.toString();return t&&t.length?{key:"Access-Control-Max-Age",value:t}:null}(e)),i.push(a(e)),c(i,n),e.preflightContinue?r():(n.statusCode=e.optionsSuccessStatus,n.setHeader("Content-Length","0"),n.end())):(i.push(s(e,t)),i.push(o(e)),i.push(a(e)),c(i,n),r())}(p,t,i,l))})):l()}}))}}}();var zZ=MZ.exports;Object.defineProperty(LG,"__esModule",{value:!0}),LG.Server=LG.BaseServer=void 0;const WZ=L,GZ=S,VZ=PG,KZ=NG,YZ=p,ZZ=jV,QZ=eq,JZ=BZ,XZ=DV,eQ=BG,tQ=(0,ah.default)("engine"),nQ=Symbol("responseHeaders");class rQ extends YZ.EventEmitter{constructor(e={}){super(),this.middlewares=[],this.clients={},this.clientsCount=0,this.opts=Object.assign({wsEngine:JZ.Server,pingTimeout:2e4,pingInterval:25e3,upgradeTimeout:1e4,maxHttpBufferSize:1e6,transports:["polling","websocket"],allowUpgrades:!0,httpCompression:{threshold:1024},cors:!1,allowEIO3:!1},e),e.cookie&&(this.opts.cookie=Object.assign({name:"io",path:"/",httpOnly:!1!==e.cookie.path,sameSite:"lax"},e.cookie)),this.opts.cors&&this.use(zZ(this.opts.cors)),e.perMessageDeflate&&(this.opts.perMessageDeflate=Object.assign({threshold:1024},e.perMessageDeflate)),this.init()}_computePath(e){let t=(e.path||"/engine.io").replace(/\/$/,"");return!1!==e.addTrailingSlash&&(t+="/"),t}upgrades(e){return this.opts.allowUpgrades&&KZ.default[e].upgradesTo||[]}verify(e,t,n){const r=e._query.transport;if(!~this.opts.transports.indexOf(r)||"webtransport"===r)return tQ('unknown transport "%s"',r),n(sQ.errors.UNKNOWN_TRANSPORT,{transport:r});const i=function(e){if((e+="").length<1)return!1;if(!cQ[e.charCodeAt(0)])return tQ('invalid header, index 0, char "%s"',e.charCodeAt(0)),!0;if(e.length<2)return!1;if(!cQ[e.charCodeAt(1)])return tQ('invalid header, index 1, char "%s"',e.charCodeAt(1)),!0;if(e.length<3)return!1;if(!cQ[e.charCodeAt(2)])return tQ('invalid header, index 2, char "%s"',e.charCodeAt(2)),!0;if(e.length<4)return!1;if(!cQ[e.charCodeAt(3)])return tQ('invalid header, index 3, char "%s"',e.charCodeAt(3)),!0;for(let t=4;t<e.length;++t)if(!cQ[e.charCodeAt(t)])return tQ('invalid header, index "%i", char "%s"',t,e.charCodeAt(t)),!0;return!1}(e.headers.origin);if(i){const t=e.headers.origin;return e.headers.origin=null,tQ("origin header invalid"),n(sQ.errors.BAD_REQUEST,{name:"INVALID_ORIGIN",origin:t})}const s=e._query.sid;if(!s)return"GET"!==e.method?n(sQ.errors.BAD_HANDSHAKE_METHOD,{method:e.method}):"websocket"!==r||t?this.opts.allowRequest?this.opts.allowRequest(e,((e,t)=>{if(!t)return n(sQ.errors.FORBIDDEN,{message:e});n()})):n():(tQ("invalid transport upgrade"),n(sQ.errors.BAD_REQUEST,{name:"TRANSPORT_HANDSHAKE_ERROR"}));{if(!this.clients.hasOwnProperty(s))return tQ('unknown sid "%s"',s),n(sQ.errors.UNKNOWN_SID,{sid:s});const e=this.clients[s].transport.name;if(!t&&e!==r)return tQ("bad request: unexpected transport without upgrade"),n(sQ.errors.BAD_REQUEST,{name:"TRANSPORT_MISMATCH",transport:r,previousTransport:e})}n()}use(e){this.middlewares.push(e)}_applyMiddlewares(e,t,n){if(0===this.middlewares.length)return tQ("no middleware to apply, skipping"),n();const r=i=>{tQ("applying middleware n°%d",i+1),this.middlewares[i](e,t,(e=>{if(e)return n(e);i+1<this.middlewares.length?r(i+1):n()}))};r(0)}close(){tQ("closing all open clients");for(let e in this.clients)this.clients.hasOwnProperty(e)&&this.clients[e].close(!0);return this.cleanup(),this}generateId(e){return VZ.generateId()}async handshake(e,t,n){const r="4"===t._query.EIO?4:3;if(3===r&&!this.opts.allowEIO3)return tQ("unsupported protocol version"),this.emit("connection_error",{req:t,code:sQ.errors.UNSUPPORTED_PROTOCOL_VERSION,message:sQ.errorMessages[sQ.errors.UNSUPPORTED_PROTOCOL_VERSION],context:{protocol:r}}),void n(sQ.errors.UNSUPPORTED_PROTOCOL_VERSION);let i;try{i=await this.generateId(t)}catch(e){return tQ("error while generating an id"),this.emit("connection_error",{req:t,code:sQ.errors.BAD_REQUEST,message:sQ.errorMessages[sQ.errors.BAD_REQUEST],context:{name:"ID_GENERATION_ERROR",error:e}}),void n(sQ.errors.BAD_REQUEST)}tQ('handshaking client "%s"',i);try{var s=this.createTransport(e,t);"polling"===e?(s.maxHttpBufferSize=this.opts.maxHttpBufferSize,s.httpCompression=this.opts.httpCompression):"websocket"===e&&(s.perMessageDeflate=this.opts.perMessageDeflate)}catch(r){return tQ('error handshaking to transport "%s"',e),this.emit("connection_error",{req:t,code:sQ.errors.BAD_REQUEST,message:sQ.errorMessages[sQ.errors.BAD_REQUEST],context:{name:"TRANSPORT_HANDSHAKE_ERROR",error:r}}),void n(sQ.errors.BAD_REQUEST)}const o=new ZZ.Socket(i,this,s,t,r);return s.on("headers",((e,t)=>{!t._query.sid&&(this.opts.cookie&&(e["Set-Cookie"]=[(0,QZ.serialize)(this.opts.cookie.name,i,this.opts.cookie)]),this.emit("initial_headers",e,t)),this.emit("headers",e,t)})),s.onRequest(t),this.clients[i]=o,this.clientsCount++,o.once("close",(()=>{delete this.clients[i],this.clientsCount--})),this.emit("connection",o),s}async onWebTransportSession(e){const t=setTimeout((()=>{tQ("the client failed to establish a bidirectional stream in the given period"),e.close()}),this.opts.upgradeTimeout),n=e.incomingBidirectionalStreams.getReader(),r=await n.read();if(r.done)return void tQ("session is closed");const i=r.value,s=(0,eQ.createPacketDecoderStream)(this.opts.maxHttpBufferSize,"nodebuffer"),o=i.readable.pipeThrough(s).getReader(),{value:a,done:c}=await o.read();if(c)return void tQ("stream is closed");if(clearTimeout(t),"open"!==a.type)return tQ("invalid WebTransport handshake"),e.close();if(void 0===a.data){const t=new XZ.WebTransport(e,i,o),n=VZ.generateId();tQ('handshaking client "%s" (WebTransport)',n);const r=new ZZ.Socket(n,this,t,null,4);return this.clients[n]=r,this.clientsCount++,r.once("close",(()=>{delete this.clients[n],this.clientsCount--})),void this.emit("connection",r)}const l=function(e){try{const t=JSON.parse(e);if("string"==typeof t.sid)return t.sid}catch(e){}}(a.data);if(!l)return tQ("invalid WebTransport handshake"),e.close();const u=this.clients[l];if(u)if(u.upgrading)tQ("transport has already been trying to upgrade"),e.close();else if(u.upgraded)tQ("transport had already been upgraded"),e.close();else{tQ("upgrading existing transport");const t=new XZ.WebTransport(e,i,o);u.maybeUpgrade(t)}else tQ("upgrade attempt for closed client"),e.close()}}LG.BaseServer=rQ,rQ.errors={UNKNOWN_TRANSPORT:0,UNKNOWN_SID:1,BAD_HANDSHAKE_METHOD:2,BAD_REQUEST:3,FORBIDDEN:4,UNSUPPORTED_PROTOCOL_VERSION:5},rQ.errorMessages={0:"Transport unknown",1:"Session ID unknown",2:"Bad handshake method",3:"Bad request",4:"Forbidden",5:"Unsupported protocol version"};class iQ{constructor(e,t){this.req=e,this.socket=t,e[nQ]={}}setHeader(e,t){this.req[nQ][e]=t}getHeader(e){return this.req[nQ][e]}removeHeader(e){delete this.req[nQ][e]}write(){}writeHead(){}end(){this.socket.destroy()}}let sQ=class e extends rQ{init(){~this.opts.transports.indexOf("websocket")&&(this.ws&&this.ws.close(),this.ws=new this.opts.wsEngine({noServer:!0,clientTracking:!1,perMessageDeflate:this.opts.perMessageDeflate,maxPayload:this.opts.maxHttpBufferSize}),"function"==typeof this.ws.on&&this.ws.on("headers",((e,t)=>{const n=t[nQ]||{};delete t[nQ];!t._query.sid&&this.emit("initial_headers",n,t),this.emit("headers",n,t),tQ("writing headers: %j",n),Object.keys(n).forEach((t=>{e.push(`${t}: ${n[t]}`)}))})))}cleanup(){this.ws&&(tQ("closing webSocketServer"),this.ws.close())}prepare(e){e._query||(e._query=~e.url.indexOf("?")?WZ.parse((0,GZ.parse)(e.url).query):{})}createTransport(e,t){return new KZ.default[e](t)}handleRequest(t,n){tQ('handling "%s" http request "%s"',t.method,t.url),this.prepare(t),t.res=n;const r=(r,i)=>{if(void 0!==r)return this.emit("connection_error",{req:t,code:r,message:e.errorMessages[r],context:i}),void oQ(n,r,i);if(t._query.sid)tQ("setting new request for existing client"),this.clients[t._query.sid].transport.onRequest(t);else{const e=(e,t)=>oQ(n,e,t);this.handshake(t._query.transport,t,e)}};this._applyMiddlewares(t,n,(n=>{n?r(e.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!1,r)}))}handleUpgrade(t,n,r){this.prepare(t);const i=new iQ(t,n),s=(s,o)=>{if(void 0!==s)return this.emit("connection_error",{req:t,code:s,message:e.errorMessages[s],context:o}),void aQ(n,s,o);const a=Buffer.from(r);r=null,i.writeHead(),this.ws.handleUpgrade(t,n,a,(e=>{this.onWebSocket(t,n,e)}))};this._applyMiddlewares(t,i,(n=>{n?s(e.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!0,s)}))}onWebSocket(e,t,n){if(n.on("error",i),void 0!==KZ.default[e._query.transport]&&!KZ.default[e._query.transport].prototype.handlesUpgrades)return tQ("transport doesnt handle upgraded requests"),void n.close();const r=e._query.sid;if(e.websocket=n,r){const t=this.clients[r];if(t)if(t.upgrading)tQ("transport has already been trying to upgrade"),n.close();else if(t.upgraded)tQ("transport had already been upgraded"),n.close();else{tQ("upgrading existing transport"),n.removeListener("error",i);const r=this.createTransport(e._query.transport,e);r.perMessageDeflate=this.opts.perMessageDeflate,t.maybeUpgrade(r)}else tQ("upgrade attempt for closed client"),n.close()}else{const n=(e,n)=>aQ(t,e,n);this.handshake(e._query.transport,e,n)}function i(){tQ("websocket error before upgrade")}}attach(e,t={}){const n=this._computePath(t),r=t.destroyUpgradeTimeout||1e3;function i(e){return n===e.url.slice(0,n.length)}const s=e.listeners("request").slice(0);e.removeAllListeners("request"),e.on("close",this.close.bind(this)),e.on("listening",this.init.bind(this)),e.on("request",((t,r)=>{if(i(t))tQ('intercepting request for path "%s"',n),this.handleRequest(t,r);else{let n=0;const i=s.length;for(;n<i;n++)s[n].call(e,t,r)}})),~this.opts.transports.indexOf("websocket")&&e.on("upgrade",((e,n,s)=>{i(e)?this.handleUpgrade(e,n,s):!1!==t.destroyUpgrade&&setTimeout((function(){if(n.writable&&n.bytesWritten<=0)return n.on("error",(e=>{tQ("error while destroying upgrade: %s",e.message)})),n.end()}),r)}))}};function oQ(e,t,n){const r=t===sQ.errors.FORBIDDEN?403:400,i=n&&n.message?n.message:sQ.errorMessages[t];e.writeHead(r,{"Content-Type":"application/json"}),e.end(JSON.stringify({code:t,message:i}))}function aQ(e,t,n={}){if(e.on("error",(()=>{tQ("ignoring error from closed connection")})),e.writable){const r=n.message||sQ.errorMessages[t],i=Buffer.byteLength(r);e.write("HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-type: text/html\r\nContent-Length: "+i+"\r\n\r\n"+r)}e.destroy()}LG.Server=sQ;const cQ=[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];var lQ={},uQ={},pQ={};Object.defineProperty(pQ,"__esModule",{value:!0}),pQ.Polling=void 0;const hQ=FG,dQ=T,fQ=KM,mQ=(0,ah.default)("engine:polling"),gQ={gzip:dQ.createGzip,deflate:dQ.createDeflate};let yQ=class extends hQ.Transport{constructor(e){super(e),this.closeTimeout=3e4}get name(){return"polling"}get supportsFraming(){return!1}onRequest(e){const t=e.res;e.res=null,"get"===e.getMethod()?this.onPollRequest(e,t):"post"===e.getMethod()?this.onDataRequest(e,t):(t.writeStatus("500 Internal Server Error"),t.end())}onPollRequest(e,t){if(this.req)return mQ("request overlap"),this.onError("overlap from client"),t.writeStatus("500 Internal Server Error"),void t.end();mQ("setting request"),this.req=e,this.res=t;e.cleanup=()=>{this.req=this.res=null},t.onAborted((()=>{this.writable=!1,this.onError("poll connection closed prematurely")})),this.writable=!0,this.emit("drain"),this.writable&&this.shouldClose&&(mQ("triggering empty send to append close packet"),this.send([{type:"noop"}]))}onDataRequest(e,t){if(this.dataReq)return this.onError("data request overlap from client"),t.writeStatus("500 Internal Server Error"),void t.end();const n=Number(e.headers["content-length"]);if(!n)return this.onError("content-length header required"),void t.writeStatus("411 Length Required").end();if(n>this.maxHttpBufferSize)return this.onError("payload too large"),void t.writeStatus("413 Payload Too Large").end();if("application/octet-stream"===e.headers["content-type"]&&4===this.protocol)return this.onError("invalid content");let r;this.dataReq=e,this.dataRes=t;let i=0;const s={"Content-Type":"text/html"};this.headers(e,s);for(let e in s)t.writeHeader(e,String(s[e]));const o=e=>{this.onData(e.toString()),this.onDataRequestCleanup(),t.cork((()=>{t.end("ok")}))};t.onAborted((()=>{this.onDataRequestCleanup(),this.onError("data request connection closed prematurely")})),t.onData(((e,s)=>{const a=i+e.byteLength;if(a>n)return this.onError("content-length mismatch"),void t.close();if(!r){if(s)return void o(Buffer.from(e));r=Buffer.allocUnsafe(n)}if(Buffer.from(e).copy(r,i),s)return a!=n?(this.onError("content-length mismatch"),t.writeStatus("400 Content-Length Mismatch").end(),void this.onDataRequestCleanup()):void o(r);i=a}))}onDataRequestCleanup(){this.dataReq=this.dataRes=null}onData(e){mQ('received "%s"',e);const t=e=>{if("close"===e.type)return mQ("got xhr close packet"),this.onClose(),!1;this.onPacket(e)};3===this.protocol?this.parser.decodePayload(e,t):this.parser.decodePayload(e).forEach(t)}onClose(){this.writable&&this.send([{type:"noop"}]),super.onClose()}send(e){this.writable=!1,this.shouldClose&&(mQ("appending close packet to payload"),e.push({type:"close"}),this.shouldClose(),this.shouldClose=null);const t=t=>{const n=e.some((e=>e.options&&e.options.compress));this.write(t,{compress:n})};3===this.protocol?this.parser.encodePayload(e,this.supportsBinary,t):this.parser.encodePayload(e,t)}write(e,t){mQ('writing "%s"',e),this.doWrite(e,t,(()=>{this.req.cleanup()}))}doWrite(e,t,n){const r="string"==typeof e,i={"Content-Type":r?"text/plain; charset=UTF-8":"application/octet-stream"},s=e=>{this.headers(this.req,i),this.res.cork((()=>{Object.keys(i).forEach((e=>{this.res.writeHeader(e,String(i[e]))})),this.res.end(e)})),n()};if(!this.httpCompression||!t.compress)return void s(e);if((r?Buffer.byteLength(e):e.length)<this.httpCompression.threshold)return void s(e);const o=fQ(this.req).encodings(["gzip","deflate"]);o?this.compress(e,o,((e,t)=>{if(e)return this.res.writeStatus("500 Internal Server Error"),this.res.end(),void n(e);i["Content-Encoding"]=o,s(t)})):s(e)}compress(e,t,n){mQ("compressing");const r=[];let i=0;gQ[t](this.httpCompression).on("error",n).on("data",(function(e){r.push(e),i+=e.length})).on("end",(function(){n(null,Buffer.concat(r,i))})).end(e)}doClose(e){let t;mQ("closing");const n=()=>{clearTimeout(t),e(),this.onClose()};this.writable?(mQ("transport writable - closing right away"),this.send([{type:"close"}]),n()):this.discarded?(mQ("transport discarded - closing right away"),n()):(mQ("transport not writable - buffering orderly close"),this.shouldClose=n,t=setTimeout(n,this.closeTimeout))}headers(e,t){t=t||{};const n=e.headers["user-agent"];return n&&(~n.indexOf(";MSIE")||~n.indexOf("Trident/"))&&(t["X-XSS-Protection"]="0"),t["cache-control"]="no-store",this.emit("headers",t,e),t}};pQ.Polling=yQ;var vQ={};Object.defineProperty(vQ,"__esModule",{value:!0}),vQ.WebSocket=void 0;const bQ=FG,_Q=(0,ah.default)("engine:ws");let xQ=class extends bQ.Transport{constructor(e){super(e),this.writable=!1,this.perMessageDeflate=null}get name(){return"websocket"}get handlesUpgrades(){return!0}get supportsFraming(){return!0}send(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t+1===e.length,i=e=>{const t="string"!=typeof e,n=this.perMessageDeflate&&Buffer.byteLength(e)>this.perMessageDeflate.threshold;_Q('writing "%s"',e),this.socket.send(e,t,n),r&&(this.writable=!0,this.emit("drain"))};n.options&&"string"==typeof n.options.wsPreEncoded?i(n.options.wsPreEncoded):this.parser.encodePacket(n,this.supportsBinary,i)}}doClose(e){_Q("closing"),e&&e(),this.socket.end()}};vQ.WebSocket=xQ,Object.defineProperty(uQ,"__esModule",{value:!0});const wQ=pQ,EQ=vQ;uQ.default={polling:wQ.Polling,websocket:EQ.WebSocket},Object.defineProperty(lQ,"__esModule",{value:!0}),lQ.uServer=void 0;const SQ=LG,TQ=uQ,DQ=(0,ah.default)("engine:uws");class kQ extends SQ.BaseServer{init(){}cleanup(){}prepare(e,t){e.method=e.getMethod().toUpperCase(),e.url=e.getUrl();const n=new URLSearchParams(e.getQuery());e._query=Object.fromEntries(n.entries()),e.headers={},e.forEach(((t,n)=>{e.headers[t]=n})),e.connection={remoteAddress:Buffer.from(t.getRemoteAddressAsText()).toString()},t.onAborted((()=>{DQ("response has been aborted")}))}createTransport(e,t){return new TQ.default[e](t)}attach(e,t={}){const n=this._computePath(t);e.any(n,this.handleRequest.bind(this)).ws(n,{compression:t.compression,idleTimeout:t.idleTimeout,maxBackpressure:t.maxBackpressure,maxPayloadLength:this.opts.maxHttpBufferSize,upgrade:this.handleUpgrade.bind(this),open:e=>{const t=e.getUserData().transport;t.socket=e,t.writable=!0,t.emit("drain")},message:(e,t,n)=>{e.getUserData().transport.onData(n?t:Buffer.from(t).toString())},close:(e,t,n)=>{e.getUserData().transport.onClose(t,n)}})}_applyMiddlewares(e,t,n){if(0===this.middlewares.length)return n();e.res=new AQ(t),super._applyMiddlewares(e,e.res,(t=>{e.res.writeHead(),n(t)}))}handleRequest(e,t){DQ('handling "%s" http request "%s"',t.getMethod(),t.getUrl()),this.prepare(t,e),t.res=e;const n=(n,r)=>{if(void 0!==n)return this.emit("connection_error",{req:t,code:n,message:SQ.Server.errorMessages[n],context:r}),void this.abortRequest(t.res,n,r);if(t._query.sid)DQ("setting new request for existing client"),this.clients[t._query.sid].transport.onRequest(t);else{const n=(t,n)=>this.abortRequest(e,t,n);this.handshake(t._query.transport,t,n)}};this._applyMiddlewares(t,e,(e=>{e?n(SQ.Server.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!1,n)}))}handleUpgrade(e,t,n){DQ("on upgrade"),this.prepare(t,e),t.res=e;const r=async(r,i)=>{if(void 0!==r)return this.emit("connection_error",{req:t,code:r,message:SQ.Server.errorMessages[r],context:i}),void this.abortRequest(e,r,i);const s=t._query.sid;let o;if(s){const n=this.clients[s];n?n.upgrading?(DQ("transport has already been trying to upgrade"),e.close()):n.upgraded?(DQ("transport had already been upgraded"),e.close()):(DQ("upgrading existing transport"),o=this.createTransport(t._query.transport,t),n.maybeUpgrade(o)):(DQ("upgrade attempt for closed client"),e.close())}else if(o=await this.handshake(t._query.transport,t,((t,n)=>this.abortRequest(e,t,n))),!o)return;t.res.writeStatus("101 Switching Protocols"),e.upgrade({transport:o},t.getHeader("sec-websocket-key"),t.getHeader("sec-websocket-protocol"),t.getHeader("sec-websocket-extensions"),n)};this._applyMiddlewares(t,e,(e=>{e?r(SQ.Server.errors.BAD_REQUEST,{name:"MIDDLEWARE_FAILURE"}):this.verify(t,!0,r)}))}abortRequest(e,t,n){const r=t===SQ.Server.errors.FORBIDDEN?"403 Forbidden":"400 Bad Request",i=n&&n.message?n.message:SQ.Server.errorMessages[t];e.writeStatus(r),e.writeHeader("Content-Type","application/json"),e.end(JSON.stringify({code:t,message:i}))}}lQ.uServer=kQ;class AQ{constructor(e){this.res=e,this.statusWritten=!1,this.headers=[],this.isAborted=!1}set statusCode(e){e&&this.writeStatus(200===e?"200 OK":"204 No Content")}writeHead(e){this.statusCode=e}setHeader(e,t){Array.isArray(t)?t.forEach((t=>{this.writeHeader(e,t)})):this.writeHeader(e,t)}removeHeader(){}getHeader(){}writeStatus(e){if(!this.isAborted)return this.res.writeStatus(e),this.statusWritten=!0,this.writeBufferedHeaders(),this}writeHeader(e,t){this.isAborted||"Content-Length"!==e&&(this.statusWritten?this.res.writeHeader(e,t):this.headers.push([e,t]))}writeBufferedHeaders(){this.headers.forEach((([e,t])=>{this.res.writeHeader(e,t)}))}end(e){this.isAborted||this.res.cork((()=>{this.statusWritten||this.writeBufferedHeaders(),this.res.end(e)}))}onData(e){this.isAborted||this.res.onData(e)}onAborted(e){this.isAborted||this.res.onAborted((()=>{this.isAborted=!0,e()}))}cork(e){this.isAborted||this.res.cork(e)}}!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.protocol=e.Transport=e.Socket=e.uServer=e.parser=e.attach=e.listen=e.transports=e.Server=void 0;const t=w,n=LG;Object.defineProperty(e,"Server",{enumerable:!0,get:function(){return n.Server}});const r=NG;e.transports=r.default;const i=BG;e.parser=i;var s=lQ;Object.defineProperty(e,"uServer",{enumerable:!0,get:function(){return s.uServer}});var o=jV;Object.defineProperty(e,"Socket",{enumerable:!0,get:function(){return o.Socket}});var a=FG;function c(e,t){const r=new n.Server(t);return r.attach(e,t),r}Object.defineProperty(e,"Transport",{enumerable:!0,get:function(){return a.Transport}}),e.protocol=i.protocol,e.listen=function(e,n,r){"function"==typeof n&&(r=n,n={});const i=(0,t.createServer)((function(e,t){t.writeHead(501),t.end("Not Implemented")})),s=c(i,n);return s.httpServer=i,i.listen(e,r),s},e.attach=c}(OG);var CQ={},RQ={};function OQ(e){if(e)return function(e){for(var t in OQ.prototype)e[t]=OQ.prototype[t];return e}(e)}OQ.prototype.on=OQ.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},OQ.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},OQ.prototype.off=OQ.prototype.removeListener=OQ.prototype.removeAllListeners=OQ.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<r.length;i++)if((n=r[i])===t||n.fn===t){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},OQ.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var i=(n=n.slice(0)).length;r<i;++r)n[r].apply(this,t)}return this},OQ.prototype.emitReserved=OQ.prototype.emit,OQ.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},OQ.prototype.hasListeners=function(e){return!!this.listeners(e).length};var LQ=H(Object.freeze({__proto__:null,Emitter:OQ})),IQ={},PQ={};Object.defineProperty(PQ,"__esModule",{value:!0}),PQ.hasBinary=PQ.isBinary=void 0;const NQ="function"==typeof ArrayBuffer,jQ=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,FQ=Object.prototype.toString,BQ="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===FQ.call(Blob),MQ="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===FQ.call(File);function UQ(e){return NQ&&(e instanceof ArrayBuffer||jQ(e))||BQ&&e instanceof Blob||MQ&&e instanceof File}PQ.isBinary=UQ,PQ.hasBinary=function e(t,n){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let n=0,r=t.length;n<r;n++)if(e(t[n]))return!0;return!1}if(UQ(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return e(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e(t[n]))return!0;return!1},Object.defineProperty(IQ,"__esModule",{value:!0}),IQ.reconstructPacket=IQ.deconstructPacket=void 0;const qQ=PQ;function HQ(e,t){if(!e)return e;if((0,qQ.isBinary)(e)){const n={_placeholder:!0,num:t.length};return t.push(e),n}if(Array.isArray(e)){const n=new Array(e.length);for(let r=0;r<e.length;r++)n[r]=HQ(e[r],t);return n}if("object"==typeof e&&!(e instanceof Date)){const n={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=HQ(e[r],t));return n}return e}function $Q(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 n=0;n<e.length;n++)e[n]=$Q(e[n],t);else if("object"==typeof e)for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=$Q(e[n],t));return e}IQ.deconstructPacket=function(e){const t=[],n=e.data,r=e;return r.data=HQ(n,t),r.attachments=t.length,{packet:r,buffers:t}},IQ.reconstructPacket=function(e,t){return e.data=$Q(e.data,t),delete e.attachments,e},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Decoder=e.Encoder=e.PacketType=e.protocol=void 0;const t=LQ,n=IQ,r=PQ,i=(0,ah.default)("socket.io-parser"),s=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var o;e.protocol=5,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"}(o=e.PacketType||(e.PacketType={}));function a(e){return"[object Object]"===Object.prototype.toString.call(e)}e.Encoder=class{constructor(e){this.replacer=e}encode(e){return i("encoding packet %j",e),e.type!==o.EVENT&&e.type!==o.ACK||!(0,r.hasBinary)(e)?[this.encodeAsString(e)]:this.encodeAsBinary({type:e.type===o.EVENT?o.BINARY_EVENT:o.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id})}encodeAsString(e){let t=""+e.type;return e.type!==o.BINARY_EVENT&&e.type!==o.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)),i("encoded %j as %s",e,t),t}encodeAsBinary(e){const t=(0,n.deconstructPacket)(e),r=this.encodeAsString(t.packet),i=t.buffers;return i.unshift(r),i}};class c extends t.Emitter{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 n=t.type===o.BINARY_EVENT;n||t.type===o.BINARY_ACK?(t.type=n?o.EVENT:o.ACK,this.reconstructor=new l(t),0===t.attachments&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else{if(!(0,r.isBinary)(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 n={type:Number(e.charAt(0))};if(void 0===o[n.type])throw new Error("unknown packet type "+n.type);if(n.type===o.BINARY_EVENT||n.type===o.BINARY_ACK){const r=t+1;for(;"-"!==e.charAt(++t)&&t!=e.length;);const i=e.substring(r,t);if(i!=Number(i)||"-"!==e.charAt(t))throw new Error("Illegal attachments");n.attachments=Number(i)}if("/"===e.charAt(t+1)){const r=t+1;for(;++t;){if(","===e.charAt(t))break;if(t===e.length)break}n.nsp=e.substring(r,t)}else n.nsp="/";const r=e.charAt(t+1);if(""!==r&&Number(r)==r){const r=t+1;for(;++t;){const n=e.charAt(t);if(null==n||Number(n)!=n){--t;break}if(t===e.length)break}n.id=Number(e.substring(r,t+1))}if(e.charAt(++t)){const r=this.tryParse(e.substr(t));if(!c.isPayloadValid(n.type,r))throw new Error("invalid payload");n.data=r}return i("decoded %s as %j",e,n),n}tryParse(e){try{return JSON.parse(e,this.reviver)}catch(e){return!1}}static isPayloadValid(e,t){switch(e){case o.CONNECT:return a(t);case o.DISCONNECT:return void 0===t;case o.CONNECT_ERROR:return"string"==typeof t||a(t);case o.EVENT:case o.BINARY_EVENT:return Array.isArray(t)&&("number"==typeof t[0]||"string"==typeof t[0]&&-1===s.indexOf(t[0]));case o.ACK:case o.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}e.Decoder=c;class l{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=(0,n.reconstructPacket)(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}}(RQ),Object.defineProperty(CQ,"__esModule",{value:!0}),CQ.Client=void 0;const zQ=RQ,WQ=S,GQ=ah("socket.io:client");CQ.Client=class{constructor(e,t){this.sockets=new Map,this.nsps=new Map,this.server=e,this.conn=t,this.encoder=e.encoder,this.decoder=new e._parser.Decoder,this.id=t.id,this.setup()}get request(){return this.conn.request}setup(){this.onclose=this.onclose.bind(this),this.ondata=this.ondata.bind(this),this.onerror=this.onerror.bind(this),this.ondecoded=this.ondecoded.bind(this),this.decoder.on("decoded",this.ondecoded),this.conn.on("data",this.ondata),this.conn.on("error",this.onerror),this.conn.on("close",this.onclose),this.connectTimeout=setTimeout((()=>{0===this.nsps.size?(GQ("no namespace joined yet, close the client"),this.close()):GQ("the client has already joined a namespace, nothing to do")}),this.server._connectTimeout)}connect(e,t={}){if(this.server._nsps.has(e))return GQ("connecting to namespace %s",e),this.doConnect(e,t);this.server._checkNamespace(e,t,(n=>{n?this.doConnect(e,t):(GQ("creation of namespace %s was denied",e),this._packet({type:zQ.PacketType.CONNECT_ERROR,nsp:e,data:{message:"Invalid namespace"}}))}))}doConnect(e,t){const n=this.server.of(e);n._add(this,t,(e=>{this.sockets.set(e.id,e),this.nsps.set(n.name,e),this.connectTimeout&&(clearTimeout(this.connectTimeout),this.connectTimeout=void 0)}))}_disconnect(){for(const e of this.sockets.values())e.disconnect();this.sockets.clear(),this.close()}_remove(e){if(this.sockets.has(e.id)){const t=this.sockets.get(e.id).nsp.name;this.sockets.delete(e.id),this.nsps.delete(t)}else GQ("ignoring remove for %s",e.id)}close(){"open"===this.conn.readyState&&(GQ("forcing transport close"),this.conn.close(),this.onclose("forced server close"))}_packet(e,t={}){if("open"!==this.conn.readyState)return void GQ("ignoring packet write %j",e);const n=t.preEncoded?e:this.encoder.encode(e);this.writeToEngine(n,t)}writeToEngine(e,t){if(t.volatile&&!this.conn.transport.writable)return void GQ("volatile packet is discarded since the transport is not currently writable");const n=Array.isArray(e)?e:[e];for(const e of n)this.conn.write(e,t)}ondata(e){try{this.decoder.add(e)}catch(e){GQ("invalid packet format"),this.onerror(e)}}ondecoded(e){let t,n;if(3===this.conn.protocol){const r=WQ.parse(e.nsp,!0);t=r.pathname,n=r.query}else t=e.nsp,n=e.data;const r=this.nsps.get(t);r||e.type!==zQ.PacketType.CONNECT?r&&e.type!==zQ.PacketType.CONNECT&&e.type!==zQ.PacketType.CONNECT_ERROR?process.nextTick((function(){r._onpacket(e)})):(GQ("invalid state (packet type: %s)",e.type),this.close()):this.connect(t,n)}onerror(e){for(const t of this.sockets.values())t._onerror(e);this.conn.close()}onclose(e,t){GQ("client close with reason %s",e),this.destroy();for(const n of this.sockets.values())n._onclose(e,t);this.sockets.clear(),this.decoder.destroy()}destroy(){this.conn.removeListener("data",this.ondata),this.conn.removeListener("error",this.onerror),this.conn.removeListener("close",this.onclose),this.decoder.removeListener("decoded",this.ondecoded),this.connectTimeout&&(clearTimeout(this.connectTimeout),this.connectTimeout=void 0)}};var VQ={},KQ={},YQ={};Object.defineProperty(YQ,"__esModule",{value:!0}),YQ.StrictEventEmitter=void 0;const ZQ=p;class QQ extends ZQ.EventEmitter{on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}emit(e,...t){return super.emit(e,...t)}emitReserved(e,...t){return super.emit(e,...t)}emitUntyped(e,...t){return super.emit(e,...t)}listeners(e){return super.listeners(e)}}YQ.StrictEventEmitter=QQ;var JQ,XQ,eJ={};function tJ(){if(JQ)return eJ;JQ=1,Object.defineProperty(eJ,"__esModule",{value:!0}),eJ.RemoteSocket=eJ.BroadcastOperator=void 0;const e=nJ(),t=RQ;class n{constructor(e,t=new Set,n=new Set,r={}){this.adapter=e,this.rooms=t,this.exceptRooms=n,this.flags=r}to(e){const t=new Set(this.rooms);return Array.isArray(e)?e.forEach((e=>t.add(e))):t.add(e),new n(this.adapter,t,this.exceptRooms,this.flags)}in(e){return this.to(e)}except(e){const t=new Set(this.exceptRooms);return Array.isArray(e)?e.forEach((e=>t.add(e))):t.add(e),new n(this.adapter,this.rooms,t,this.flags)}compress(e){const t=Object.assign({},this.flags,{compress:e});return new n(this.adapter,this.rooms,this.exceptRooms,t)}get volatile(){const e=Object.assign({},this.flags,{volatile:!0});return new n(this.adapter,this.rooms,this.exceptRooms,e)}get local(){const e=Object.assign({},this.flags,{local:!0});return new n(this.adapter,this.rooms,this.exceptRooms,e)}timeout(e){const t=Object.assign({},this.flags,{timeout:e});return new n(this.adapter,this.rooms,this.exceptRooms,t)}emit(n,...r){if(e.RESERVED_EVENTS.has(n))throw new Error(`"${String(n)}" is a reserved event name`);const i=[n,...r],s={type:t.PacketType.EVENT,data:i};if(!("function"==typeof i[i.length-1]))return this.adapter.broadcast(s,{rooms:this.rooms,except:this.exceptRooms,flags:this.flags}),!0;const o=i.pop();let a=!1,c=[];const l=setTimeout((()=>{a=!0,o.apply(this,[new Error("operation has timed out"),this.flags.expectSingleResponse?null:c])}),this.flags.timeout);let u=-1,p=0,h=0;const d=()=>{a||u!==p||c.length!==h||(clearTimeout(l),o.apply(this,[null,this.flags.expectSingleResponse?c[0]:c]))};return this.adapter.broadcastWithAck(s,{rooms:this.rooms,except:this.exceptRooms,flags:this.flags},(e=>{h+=e,p++,d()}),(e=>{c.push(e),d()})),this.adapter.serverCount().then((e=>{u=e,d()})),!0}emitWithAck(e,...t){return new Promise(((n,r)=>{t.push(((e,t)=>e?(e.responses=t,r(e)):n(t))),this.emit(e,...t)}))}allSockets(){if(!this.adapter)throw new Error("No adapter for this namespace, are you trying to get the list of clients of a dynamic namespace?");return this.adapter.sockets(this.rooms)}fetchSockets(){return this.adapter.fetchSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags}).then((t=>t.map((t=>t instanceof e.Socket?t:new r(this.adapter,t)))))}socketsJoin(e){this.adapter.addSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags},Array.isArray(e)?e:[e])}socketsLeave(e){this.adapter.delSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags},Array.isArray(e)?e:[e])}disconnectSockets(e=!1){this.adapter.disconnectSockets({rooms:this.rooms,except:this.exceptRooms,flags:this.flags},e)}}eJ.BroadcastOperator=n;class r{constructor(e,t){this.id=t.id,this.handshake=t.handshake,this.rooms=new Set(t.rooms),this.data=t.data,this.operator=new n(e,new Set([this.id]),new Set,{expectSingleResponse:!0})}timeout(e){return this.operator.timeout(e)}emit(e,...t){return this.operator.emit(e,...t)}join(e){return this.operator.socketsJoin(e)}leave(e){return this.operator.socketsLeave(e)}disconnect(e=!1){return this.operator.disconnectSockets(e),this}}return eJ.RemoteSocket=r,eJ}function nJ(){return XQ||(XQ=1,function(e){var t=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.Socket=e.RESERVED_EVENTS=void 0;const n=RQ,r=t(ah),i=YQ,s=t(PG),o=tJ(),a=(0,r.default)("socket.io:socket"),c=new Set(["transport error","transport close","forced close","ping timeout","server shutting down","forced server close"]);function l(){}e.RESERVED_EVENTS=new Set(["connect","connect_error","disconnect","disconnecting","newListener","removeListener"]);class u extends i.StrictEventEmitter{constructor(e,t,r,i){super(),this.nsp=e,this.client=t,this.recovered=!1,this.data={},this.connected=!1,this.acks=new Map,this.fns=[],this.flags={},this.server=e.server,this.adapter=this.nsp.adapter,i?(this.id=i.sid,this.pid=i.pid,i.rooms.forEach((e=>this.join(e))),this.data=i.data,i.missedPackets.forEach((e=>{this.packet({type:n.PacketType.EVENT,data:e})})),this.recovered=!0):(3===t.conn.protocol?this.id="/"!==e.name?e.name+"#"+t.id:t.id:this.id=s.default.generateId(),this.server._opts.connectionStateRecovery&&(this.pid=s.default.generateId())),this.handshake=this.buildHandshake(r),this.on("error",l)}buildHandshake(e){var t,n,r,i;return{headers:(null===(t=this.request)||void 0===t?void 0:t.headers)||{},time:new Date+"",address:this.conn.remoteAddress,xdomain:!!(null===(n=this.request)||void 0===n?void 0:n.headers.origin),secure:!this.request||!!this.request.connection.encrypted,issued:+new Date,url:null===(r=this.request)||void 0===r?void 0:r.url,query:(null===(i=this.request)||void 0===i?void 0:i._query)||{},auth:e}}emit(t,...r){if(e.RESERVED_EVENTS.has(t))throw new Error(`"${String(t)}" is a reserved event name`);const i=[t,...r],s={type:n.PacketType.EVENT,data:i};if("function"==typeof i[i.length-1]){const e=this.nsp._ids++;a("emitting packet with ack id %d",e),this.registerAckCallback(e,i.pop()),s.id=e}const o=Object.assign({},this.flags);return this.flags={},this.nsp.server.opts.connectionStateRecovery?this.adapter.broadcast(s,{rooms:new Set([this.id]),except:new Set,flags:o}):(this.notifyOutgoingListeners(s),this.packet(s,o)),!0}emitWithAck(e,...t){const n=void 0!==this.flags.timeout;return new Promise(((r,i)=>{t.push(((e,t)=>n?e?i(e):r(t):r(e))),this.emit(e,...t)}))}registerAckCallback(e,t){const n=this.flags.timeout;if(void 0===n)return void this.acks.set(e,t);const r=setTimeout((()=>{a("event with ack id %d has timed out after %d ms",e,n),this.acks.delete(e),t.call(this,new Error("operation has timed out"))}),n);this.acks.set(e,((...e)=>{clearTimeout(r),t.apply(this,[null,...e])}))}to(e){return this.newBroadcastOperator().to(e)}in(e){return this.newBroadcastOperator().in(e)}except(e){return this.newBroadcastOperator().except(e)}send(...e){return this.emit("message",...e),this}write(...e){return this.emit("message",...e),this}packet(e,t={}){e.nsp=this.nsp.name,t.compress=!1!==t.compress,this.client._packet(e,t)}join(e){return a("join room %s",e),this.adapter.addAll(this.id,new Set(Array.isArray(e)?e:[e]))}leave(e){return a("leave room %s",e),this.adapter.del(this.id,e)}leaveAll(){this.adapter.delAll(this.id)}_onconnect(){a("socket connected - writing packet"),this.connected=!0,this.join(this.id),3===this.conn.protocol?this.packet({type:n.PacketType.CONNECT}):this.packet({type:n.PacketType.CONNECT,data:{sid:this.id,pid:this.pid}})}_onpacket(e){switch(a("got packet %j",e),e.type){case n.PacketType.EVENT:case n.PacketType.BINARY_EVENT:this.onevent(e);break;case n.PacketType.ACK:case n.PacketType.BINARY_ACK:this.onack(e);break;case n.PacketType.DISCONNECT:this.ondisconnect()}}onevent(e){const t=e.data||[];if(a("emitting event %j",t),null!=e.id&&(a("attaching ack callback to event"),t.push(this.ack(e.id))),this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}this.dispatch(t)}ack(e){const t=this;let r=!1;return function(){if(r)return;const i=Array.prototype.slice.call(arguments);a("sending ack %j",i),t.packet({id:e,type:n.PacketType.ACK,data:i}),r=!0}}onack(e){const t=this.acks.get(e.id);"function"==typeof t?(a("calling ack %s with %j",e.id,e.data),t.apply(this,e.data),this.acks.delete(e.id)):a("bad ack %s",e.id)}ondisconnect(){a("got disconnect packet"),this._onclose("client namespace disconnect")}_onerror(e){this.emitReserved("error",e)}_onclose(e,t){if(!this.connected)return this;a("closing socket - reason %s",e),this.emitReserved("disconnecting",e,t),this.server._opts.connectionStateRecovery&&c.has(e)&&(a("connection state recovery is enabled for sid %s",this.id),this.adapter.persistSession({sid:this.id,pid:this.pid,rooms:[...this.rooms],data:this.data})),this._cleanup(),this.client._remove(this),this.connected=!1,this.emitReserved("disconnect",e,t)}_cleanup(){this.leaveAll(),this.nsp._remove(this),this.join=l}_error(e){this.packet({type:n.PacketType.CONNECT_ERROR,data:e})}disconnect(e=!1){return this.connected?(e?this.client._disconnect():(this.packet({type:n.PacketType.DISCONNECT}),this._onclose("server namespace disconnect")),this):this}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}get broadcast(){return this.newBroadcastOperator()}get local(){return this.newBroadcastOperator().local}timeout(e){return this.flags.timeout=e,this}dispatch(e){a("dispatching an event %j",e),this.run(e,(t=>{process.nextTick((()=>{if(t)return this._onerror(t);this.connected?super.emitUntyped.apply(this,e):a("ignore packet received after disconnection")}))}))}use(e){return this.fns.push(e),this}run(e,t){const n=this.fns.slice(0);if(!n.length)return t(null);!function r(i){n[i](e,(function(e){return e?t(e):n[i+1]?void r(i+1):t(null)}))}(0)}get disconnected(){return!this.connected}get request(){return this.client.request}get conn(){return this.client.conn}get rooms(){return this.adapter.socketRooms(this.id)||new Set}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 n=0;n<t.length;n++)if(e===t[n])return t.splice(n,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 n=0;n<t.length;n++)if(e===t[n])return t.splice(n,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 n of t)n.apply(this,e.data)}}newBroadcastOperator(){const e=Object.assign({},this.flags);return this.flags={},new o.BroadcastOperator(this.adapter,new Set,new Set([this.id]),e)}}e.Socket=u}(KQ)),KQ}!function(e){var t=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.Namespace=e.RESERVED_EVENTS=void 0;const n=nJ(),r=YQ,i=t(ah),s=tJ(),o=(0,i.default)("socket.io:namespace");e.RESERVED_EVENTS=new Set(["connect","connection","new_namespace"]);class a extends r.StrictEventEmitter{constructor(e,t){super(),this.sockets=new Map,this._fns=[],this._ids=0,this.server=e,this.name=t,this._initAdapter()}_initAdapter(){this.adapter=new(this.server.adapter())(this)}use(e){return this._fns.push(e),this}run(e,t){const n=this._fns.slice(0);if(!n.length)return t(null);!function r(i){n[i](e,(function(e){return e?t(e):n[i+1]?void r(i+1):t(null)}))}(0)}to(e){return new s.BroadcastOperator(this.adapter).to(e)}in(e){return new s.BroadcastOperator(this.adapter).in(e)}except(e){return new s.BroadcastOperator(this.adapter).except(e)}async _add(e,t,n){var r;o("adding socket to nsp %s",this.name);const i=await this._createSocket(e,t);if((null===(r=this.server.opts.connectionStateRecovery)||void 0===r?void 0:r.skipMiddlewares)&&i.recovered&&"open"===e.conn.readyState)return this._doConnect(i,n);this.run(i,(t=>{process.nextTick((()=>"open"!==e.conn.readyState?(o("next called after client was closed - ignoring socket"),void i._cleanup()):t?(o("middleware error, sending CONNECT_ERROR packet to the client"),i._cleanup(),3===e.conn.protocol?i._error(t.data||t.message):i._error({message:t.message,data:t.data})):void this._doConnect(i,n)))}))}async _createSocket(e,t){const r=t.pid,i=t.offset;if(this.server.opts.connectionStateRecovery&&"string"==typeof r&&"string"==typeof i){let s;try{s=await this.adapter.restoreSession(r,i)}catch(e){o("error while restoring session: %s",e)}if(s)return o("connection state recovered for sid %s",s.sid),new n.Socket(this,e,t,s)}return new n.Socket(this,e,t)}_doConnect(e,t){this.sockets.set(e.id,e),e._onconnect(),t&&t(e),this.emitReserved("connect",e),this.emitReserved("connection",e)}_remove(e){this.sockets.has(e.id)?this.sockets.delete(e.id):o("ignoring remove for %s",e.id)}emit(e,...t){return new s.BroadcastOperator(this.adapter).emit(e,...t)}send(...e){return this.emit("message",...e),this}write(...e){return this.emit("message",...e),this}serverSideEmit(t,...n){if(e.RESERVED_EVENTS.has(t))throw new Error(`"${String(t)}" is a reserved event name`);return n.unshift(t),this.adapter.serverSideEmit(n),!0}serverSideEmitWithAck(e,...t){return new Promise(((n,r)=>{t.push(((e,t)=>e?(e.responses=t,r(e)):n(t))),this.serverSideEmit(e,...t)}))}_onServerSideEmit(e){super.emitUntyped.apply(this,e)}allSockets(){return new s.BroadcastOperator(this.adapter).allSockets()}compress(e){return new s.BroadcastOperator(this.adapter).compress(e)}get volatile(){return new s.BroadcastOperator(this.adapter).volatile}get local(){return new s.BroadcastOperator(this.adapter).local}timeout(e){return new s.BroadcastOperator(this.adapter).timeout(e)}fetchSockets(){return new s.BroadcastOperator(this.adapter).fetchSockets()}socketsJoin(e){return new s.BroadcastOperator(this.adapter).socketsJoin(e)}socketsLeave(e){return new s.BroadcastOperator(this.adapter).socketsLeave(e)}disconnectSockets(e=!1){return new s.BroadcastOperator(this.adapter).disconnectSockets(e)}}e.Namespace=a}(VQ);var rJ={},iJ={},sJ={},oJ={};Object.defineProperty(oJ,"__esModule",{value:!0}),oJ.yeast=oJ.decode=oJ.encode=void 0;const aJ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),cJ=64,lJ={};let uJ,pJ=0,hJ=0;function dJ(e){let t="";do{t=aJ[e%cJ]+t,e=Math.floor(e/cJ)}while(e>0);return t}for(oJ.encode=dJ,oJ.decode=function(e){let t=0;for(hJ=0;hJ<e.length;hJ++)t=t*cJ+lJ[e.charAt(hJ)];return t},oJ.yeast=function(){const e=dJ(+new Date);return e!==uJ?(pJ=0,uJ=e):e+"."+dJ(pJ++)};hJ<cJ;hJ++)lJ[aJ[hJ]]=hJ;var fJ;Object.defineProperty(sJ,"__esModule",{value:!0}),sJ.SessionAwareAdapter=sJ.Adapter=void 0;const mJ=p,gJ=oJ,yJ=BZ,vJ="function"==typeof(null===(fJ=null==yJ?void 0:yJ.Sender)||void 0===fJ?void 0:fJ.frame);class bJ extends mJ.EventEmitter{constructor(e){super(),this.nsp=e,this.rooms=new Map,this.sids=new Map,this.encoder=e.server.encoder}init(){}close(){}serverCount(){return Promise.resolve(1)}addAll(e,t){this.sids.has(e)||this.sids.set(e,new Set);for(const n of t)this.sids.get(e).add(n),this.rooms.has(n)||(this.rooms.set(n,new Set),this.emit("create-room",n)),this.rooms.get(n).has(e)||(this.rooms.get(n).add(e),this.emit("join-room",n,e))}del(e,t){this.sids.has(e)&&this.sids.get(e).delete(t),this._del(t,e)}_del(e,t){const n=this.rooms.get(e);if(null!=n){n.delete(t)&&this.emit("leave-room",e,t),0===n.size&&this.rooms.delete(e)&&this.emit("delete-room",e)}}delAll(e){if(this.sids.has(e)){for(const t of this.sids.get(e))this._del(t,e);this.sids.delete(e)}}broadcast(e,t){const n=t.flags||{},r={preEncoded:!0,volatile:n.volatile,compress:n.compress};e.nsp=this.nsp.name;const i=this._encode(e,r);this.apply(t,(t=>{"function"==typeof t.notifyOutgoingListeners&&t.notifyOutgoingListeners(e),t.client.writeToEngine(i,r)}))}broadcastWithAck(e,t,n,r){const i=t.flags||{},s={preEncoded:!0,volatile:i.volatile,compress:i.compress};e.nsp=this.nsp.name,e.id=this.nsp._ids++;const o=this._encode(e,s);let a=0;this.apply(t,(t=>{a++,t.acks.set(e.id,r),"function"==typeof t.notifyOutgoingListeners&&t.notifyOutgoingListeners(e),t.client.writeToEngine(o,s)})),n(a)}_encode(e,t){const n=this.encoder.encode(e);if(vJ&&1===n.length&&"string"==typeof n[0]){const e=Buffer.from("4"+n[0]);t.wsPreEncodedFrame=yJ.Sender.frame(e,{readOnly:!1,mask:!1,rsv1:!1,opcode:1,fin:!0})}return n}sockets(e){const t=new Set;return this.apply({rooms:e},(e=>{t.add(e.id)})),Promise.resolve(t)}socketRooms(e){return this.sids.get(e)}fetchSockets(e){const t=[];return this.apply(e,(e=>{t.push(e)})),Promise.resolve(t)}addSockets(e,t){this.apply(e,(e=>{e.join(t)}))}delSockets(e,t){this.apply(e,(e=>{t.forEach((t=>e.leave(t)))}))}disconnectSockets(e,t){this.apply(e,(e=>{e.disconnect(t)}))}apply(e,t){const n=e.rooms,r=this.computeExceptSids(e.except);if(n.size){const e=new Set;for(const i of n)if(this.rooms.has(i))for(const n of this.rooms.get(i)){if(e.has(n)||r.has(n))continue;const i=this.nsp.sockets.get(n);i&&(t(i),e.add(n))}}else for(const[e]of this.sids){if(r.has(e))continue;const n=this.nsp.sockets.get(e);n&&t(n)}}computeExceptSids(e){const t=new Set;if(e&&e.size>0)for(const n of e)this.rooms.has(n)&&this.rooms.get(n).forEach((e=>t.add(e)));return t}serverSideEmit(e){console.warn("this adapter does not support the serverSideEmit() functionality")}persistSession(e){}restoreSession(e,t){return null}}sJ.Adapter=bJ;function _J(e,t){const n=0===t.rooms.size||e.some((e=>t.rooms.has(e))),r=e.every((e=>!t.except.has(e)));return n&&r}sJ.SessionAwareAdapter=class extends bJ{constructor(e){super(e),this.nsp=e,this.sessions=new Map,this.packets=[],this.maxDisconnectionDuration=e.server.opts.connectionStateRecovery.maxDisconnectionDuration;const t=setInterval((()=>{const e=Date.now()-this.maxDisconnectionDuration;this.sessions.forEach(((t,n)=>{t.disconnectedAt<e&&this.sessions.delete(n)}));for(let t=this.packets.length-1;t>=0;t--){if(this.packets[t].emittedAt<e){this.packets.splice(0,t+1);break}}}),6e4);t.unref()}persistSession(e){e.disconnectedAt=Date.now(),this.sessions.set(e.pid,e)}restoreSession(e,t){const n=this.sessions.get(e);if(!n)return null;if(n.disconnectedAt+this.maxDisconnectionDuration<Date.now())return this.sessions.delete(e),null;const r=this.packets.findIndex((e=>e.id===t));if(-1===r)return null;const i=[];for(let e=r+1;e<this.packets.length;e++){const t=this.packets[e];_J(n.rooms,t.opts)&&i.push(t.data)}return Promise.resolve(Object.assign(Object.assign({},n),{missedPackets:i}))}broadcast(e,t){var n;const r=2===e.type,i=void 0===e.id,s=void 0===(null===(n=t.flags)||void 0===n?void 0:n.volatile);if(r&&i&&s){const n=(0,gJ.yeast)();e.data.push(n),this.packets.push({id:n,opts:t,data:e.data,emittedAt:Date.now()})}super.broadcast(e,t)}};var xJ={};!function(e){var t=U&&U.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n};Object.defineProperty(e,"__esModule",{value:!0}),e.ClusterAdapterWithHeartbeat=e.ClusterAdapter=e.MessageType=void 0;const n=sJ,r=x,i=(0,ah.debug)("socket.io-adapter"),s=5e3;function o(){return(0,r.randomBytes)(8).toString("hex")}var a;function c(e){return{rooms:[...e.rooms],except:[...e.except],flags:e.flags}}function l(e){return{rooms:new Set(e.rooms),except:new Set(e.except),flags:e.flags}}!function(e){e[e.INITIAL_HEARTBEAT=1]="INITIAL_HEARTBEAT",e[e.HEARTBEAT=2]="HEARTBEAT",e[e.BROADCAST=3]="BROADCAST",e[e.SOCKETS_JOIN=4]="SOCKETS_JOIN",e[e.SOCKETS_LEAVE=5]="SOCKETS_LEAVE",e[e.DISCONNECT_SOCKETS=6]="DISCONNECT_SOCKETS",e[e.FETCH_SOCKETS=7]="FETCH_SOCKETS",e[e.FETCH_SOCKETS_RESPONSE=8]="FETCH_SOCKETS_RESPONSE",e[e.SERVER_SIDE_EMIT=9]="SERVER_SIDE_EMIT",e[e.SERVER_SIDE_EMIT_RESPONSE=10]="SERVER_SIDE_EMIT_RESPONSE",e[e.BROADCAST_CLIENT_COUNT=11]="BROADCAST_CLIENT_COUNT",e[e.BROADCAST_ACK=12]="BROADCAST_ACK",e[e.ADAPTER_CLOSE=13]="ADAPTER_CLOSE"}(a=e.MessageType||(e.MessageType={}));class u extends n.Adapter{constructor(e){super(e),this.requests=new Map,this.ackRequests=new Map,this.uid=o()}onMessage(e,n){if(e.uid===this.uid)return i("[%s] ignore message from self",this.uid);switch(i("[%s] new event of type %d from %s",this.uid,e.type,e.uid),e.type){case a.BROADCAST:if(void 0!==e.data.requestId)super.broadcastWithAck(e.data.packet,l(e.data.opts),(t=>{i("[%s] waiting for %d client acknowledgements",this.uid,t),this.publishResponse(e.uid,{type:a.BROADCAST_CLIENT_COUNT,data:{requestId:e.data.requestId,clientCount:t}})}),(t=>{i("[%s] received acknowledgement with value %j",this.uid,t),this.publishResponse(e.uid,{type:a.BROADCAST_ACK,data:{requestId:e.data.requestId,packet:t}})}));else{const t=e.data.packet,r=l(e.data.opts);this.addOffsetIfNecessary(t,r,n),super.broadcast(t,r)}break;case a.SOCKETS_JOIN:super.addSockets(l(e.data.opts),e.data.rooms);break;case a.SOCKETS_LEAVE:super.delSockets(l(e.data.opts),e.data.rooms);break;case a.DISCONNECT_SOCKETS:super.disconnectSockets(l(e.data.opts),e.data.close);break;case a.FETCH_SOCKETS:i("[%s] calling fetchSockets with opts %j",this.uid,e.data.opts),super.fetchSockets(l(e.data.opts)).then((n=>{this.publishResponse(e.uid,{type:a.FETCH_SOCKETS_RESPONSE,data:{requestId:e.data.requestId,sockets:n.map((e=>{const n=e.handshake,r=t(n,["sessionStore"]);return{id:e.id,handshake:r,rooms:[...e.rooms],data:e.data}}))}})}));break;case a.SERVER_SIDE_EMIT:{const t=e.data.packet;if(!(void 0!==e.data.requestId))return void this.nsp._onServerSideEmit(t);let n=!1;const r=t=>{n||(n=!0,i("[%s] calling acknowledgement with %j",this.uid,t),this.publishResponse(e.uid,{type:a.SERVER_SIDE_EMIT_RESPONSE,data:{requestId:e.data.requestId,packet:t}}))};this.nsp._onServerSideEmit([...t,r]);break}case a.BROADCAST_CLIENT_COUNT:case a.BROADCAST_ACK:case a.FETCH_SOCKETS_RESPONSE:case a.SERVER_SIDE_EMIT_RESPONSE:this.onResponse(e);break;default:i("[%s] unknown message type: %s",this.uid,e.type)}}onResponse(e){var t,n;const r=e.data.requestId;switch(i("[%s] received response %s to request %s",this.uid,e.type,r),e.type){case a.BROADCAST_CLIENT_COUNT:null===(t=this.ackRequests.get(r))||void 0===t||t.clientCountCallback(e.data.clientCount);break;case a.BROADCAST_ACK:null===(n=this.ackRequests.get(r))||void 0===n||n.ack(e.data.packet);break;case a.FETCH_SOCKETS_RESPONSE:{const t=this.requests.get(r);if(!t)return;t.current++,e.data.sockets.forEach((e=>t.responses.push(e))),t.current===t.expected&&(clearTimeout(t.timeout),t.resolve(t.responses),this.requests.delete(r));break}case a.SERVER_SIDE_EMIT_RESPONSE:{const t=this.requests.get(r);if(!t)return;t.current++,t.responses.push(e.data.packet),t.current===t.expected&&(clearTimeout(t.timeout),t.resolve(null,t.responses),this.requests.delete(r));break}default:i("[%s] unknown response type: %s",this.uid,e.type)}}async broadcast(e,t){var n;if(!(null===(n=t.flags)||void 0===n?void 0:n.local))try{const n=await this.publishAndReturnOffset({type:a.BROADCAST,data:{packet:e,opts:c(t)}});this.addOffsetIfNecessary(e,t,n)}catch(e){return i("[%s] error while broadcasting message: %s",this.uid,e.message)}super.broadcast(e,t)}addOffsetIfNecessary(e,t,n){var r;if(!this.nsp.server.opts.connectionStateRecovery)return;const i=2===e.type,s=void 0===e.id,o=void 0===(null===(r=t.flags)||void 0===r?void 0:r.volatile);i&&s&&o&&e.data.push(n)}broadcastWithAck(e,t,n,r){var i;if(!(null===(i=null==t?void 0:t.flags)||void 0===i?void 0:i.local)){const i=o();this.ackRequests.set(i,{clientCountCallback:n,ack:r}),this.publish({type:a.BROADCAST,data:{packet:e,requestId:i,opts:c(t)}}),setTimeout((()=>{this.ackRequests.delete(i)}),t.flags.timeout)}super.broadcastWithAck(e,t,n,r)}async addSockets(e,t){var n;if(!(null===(n=e.flags)||void 0===n?void 0:n.local))try{await this.publishAndReturnOffset({type:a.SOCKETS_JOIN,data:{opts:c(e),rooms:t}})}catch(e){i("[%s] error while publishing message: %s",this.uid,e.message)}super.addSockets(e,t)}async delSockets(e,t){var n;if(!(null===(n=e.flags)||void 0===n?void 0:n.local))try{await this.publishAndReturnOffset({type:a.SOCKETS_LEAVE,data:{opts:c(e),rooms:t}})}catch(e){i("[%s] error while publishing message: %s",this.uid,e.message)}super.delSockets(e,t)}async disconnectSockets(e,t){var n;if(!(null===(n=e.flags)||void 0===n?void 0:n.local))try{await this.publishAndReturnOffset({type:a.DISCONNECT_SOCKETS,data:{opts:c(e),close:t}})}catch(e){i("[%s] error while publishing message: %s",this.uid,e.message)}super.disconnectSockets(e,t)}async fetchSockets(e){var t;const[n,r]=await Promise.all([super.fetchSockets(e),this.serverCount()]),i=r-1;if((null===(t=e.flags)||void 0===t?void 0:t.local)||i<=0)return n;const l=o();return new Promise(((t,r)=>{const o=setTimeout((()=>{const e=this.requests.get(l);e&&(r(new Error(`timeout reached: only ${e.current} responses received out of ${e.expected}`)),this.requests.delete(l))}),e.flags.timeout||s),u={type:a.FETCH_SOCKETS,resolve:t,timeout:o,current:0,expected:i,responses:n};this.requests.set(l,u),this.publish({type:a.FETCH_SOCKETS,data:{opts:c(e),requestId:l}})}))}async serverSideEmit(e){if(!("function"==typeof e[e.length-1]))return this.publish({type:a.SERVER_SIDE_EMIT,data:{packet:e}});const t=e.pop(),n=await this.serverCount()-1;if(i('[%s] waiting for %d responses to "serverSideEmit" request',this.uid,n),n<=0)return t(null,[]);const r=o(),c=setTimeout((()=>{const e=this.requests.get(r);e&&(t(new Error(`timeout reached: only ${e.current} responses received out of ${e.expected}`),e.responses),this.requests.delete(r))}),s),l={type:a.SERVER_SIDE_EMIT,resolve:t,timeout:c,current:0,expected:n,responses:[]};this.requests.set(r,l),this.publish({type:a.SERVER_SIDE_EMIT,data:{requestId:r,packet:e}})}publish(e){this.publishAndReturnOffset(e).catch((e=>{i("[%s] error while publishing message: %s",this.uid,e)}))}publishAndReturnOffset(e){return e.uid=this.uid,e.nsp=this.nsp.name,this.doPublish(e)}publishResponse(e,t){t.uid=this.uid,t.nsp=this.nsp.name,this.doPublishResponse(e,t).catch((e=>{i("[%s] error while publishing response: %s",this.uid,e)}))}}e.ClusterAdapter=u;e.ClusterAdapterWithHeartbeat=class extends u{constructor(e,t){super(e),this.nodesMap=new Map,this.customRequests=new Map,this._opts=Object.assign({heartbeatInterval:5e3,heartbeatTimeout:1e4},t),this.cleanupTimer=setInterval((()=>{const e=Date.now();this.nodesMap.forEach(((t,n)=>{e-t>this._opts.heartbeatTimeout&&(i("[%s] node %s seems down",this.uid,n),this.removeNode(n))}))}),1e3)}init(){this.publish({type:a.INITIAL_HEARTBEAT})}scheduleHeartbeat(){this.heartbeatTimer?this.heartbeatTimer.refresh():this.heartbeatTimer=setTimeout((()=>{this.publish({type:a.HEARTBEAT})}),this._opts.heartbeatInterval)}close(){this.publish({type:a.ADAPTER_CLOSE}),clearTimeout(this.heartbeatTimer),this.cleanupTimer&&clearInterval(this.cleanupTimer)}onMessage(e,t){if(e.uid===this.uid)return i("[%s] ignore message from self",this.uid);switch(e.uid&&"emitter"!==e.uid&&this.nodesMap.set(e.uid,Date.now()),i("[%s] new event of type %d from %s",this.uid,e.type,e.uid),e.type){case a.INITIAL_HEARTBEAT:this.publish({type:a.HEARTBEAT});break;case a.HEARTBEAT:break;case a.ADAPTER_CLOSE:this.removeNode(e.uid);break;default:super.onMessage(e,t)}}serverCount(){return Promise.resolve(1+this.nodesMap.size)}publish(e){return this.scheduleHeartbeat(),super.publish(e)}async serverSideEmit(e){if(!("function"==typeof e[e.length-1]))return this.publish({type:a.SERVER_SIDE_EMIT,data:{packet:e}});const t=e.pop(),n=this.nodesMap.size;if(i('[%s] waiting for %d responses to "serverSideEmit" request',this.uid,n),n<=0)return t(null,[]);const r=o(),c=setTimeout((()=>{const e=this.customRequests.get(r);e&&(t(new Error(`timeout reached: missing ${e.missingUids.size} responses`),e.responses),this.customRequests.delete(r))}),s),l={type:a.SERVER_SIDE_EMIT,resolve:t,timeout:c,missingUids:new Set([...this.nodesMap.keys()]),responses:[]};this.customRequests.set(r,l),this.publish({type:a.SERVER_SIDE_EMIT,data:{requestId:r,packet:e}})}async fetchSockets(e){var t;const[n,r]=await Promise.all([super.fetchSockets({rooms:e.rooms,except:e.except,flags:{local:!0}}),this.serverCount()]),i=r-1;if((null===(t=e.flags)||void 0===t?void 0:t.local)||i<=0)return n;const l=o();return new Promise(((t,r)=>{const i=setTimeout((()=>{const e=this.customRequests.get(l);e&&(r(new Error(`timeout reached: missing ${e.missingUids.size} responses`)),this.customRequests.delete(l))}),e.flags.timeout||s),o={type:a.FETCH_SOCKETS,resolve:t,timeout:i,missingUids:new Set([...this.nodesMap.keys()]),responses:n};this.customRequests.set(l,o),this.publish({type:a.FETCH_SOCKETS,data:{opts:c(e),requestId:l}})}))}onResponse(e){const t=e.data.requestId;switch(i("[%s] received response %s to request %s",this.uid,e.type,t),e.type){case a.FETCH_SOCKETS_RESPONSE:{const n=this.customRequests.get(t);if(!n)return;e.data.sockets.forEach((e=>n.responses.push(e))),n.missingUids.delete(e.uid),0===n.missingUids.size&&(clearTimeout(n.timeout),n.resolve(n.responses),this.customRequests.delete(t));break}case a.SERVER_SIDE_EMIT_RESPONSE:{const n=this.customRequests.get(t);if(!n)return;n.responses.push(e.data.packet),n.missingUids.delete(e.uid),0===n.missingUids.size&&(clearTimeout(n.timeout),n.resolve(null,n.responses),this.customRequests.delete(t));break}default:super.onResponse(e)}}removeNode(e){this.customRequests.forEach(((t,n)=>{t.missingUids.delete(e),0===t.missingUids.size&&(clearTimeout(t.timeout),t.type===a.FETCH_SOCKETS?t.resolve(t.responses):t.type===a.SERVER_SIDE_EMIT&&t.resolve(null,t.responses),this.customRequests.delete(n))})),this.nodesMap.delete(e)}}}(xJ),function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.MessageType=e.ClusterAdapterWithHeartbeat=e.ClusterAdapter=e.SessionAwareAdapter=e.Adapter=void 0;var t=sJ;Object.defineProperty(e,"Adapter",{enumerable:!0,get:function(){return t.Adapter}}),Object.defineProperty(e,"SessionAwareAdapter",{enumerable:!0,get:function(){return t.SessionAwareAdapter}});var n=xJ;Object.defineProperty(e,"ClusterAdapter",{enumerable:!0,get:function(){return n.ClusterAdapter}}),Object.defineProperty(e,"ClusterAdapterWithHeartbeat",{enumerable:!0,get:function(){return n.ClusterAdapterWithHeartbeat}}),Object.defineProperty(e,"MessageType",{enumerable:!0,get:function(){return n.MessageType}})}(iJ);var wJ=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(rJ,"__esModule",{value:!0}),rJ.ParentNamespace=void 0;const EJ=VQ,SJ=iJ,TJ=(0,wJ(ah).default)("socket.io:parent-namespace");class DJ extends EJ.Namespace{constructor(e){super(e,"/_"+DJ.count++),this.children=new Set}_initAdapter(){this.adapter=new kJ(this,this.children)}emit(e,...t){return this.children.forEach((n=>{n.emit(e,...t)})),!0}createChild(e){TJ("creating child namespace %s",e);const t=new EJ.Namespace(this.server,e);if(t._fns=this._fns.slice(0),this.listeners("connect").forEach((e=>t.on("connect",e))),this.listeners("connection").forEach((e=>t.on("connection",e))),this.children.add(t),this.server._opts.cleanupEmptyChildNamespaces){const n=t._remove;t._remove=r=>{n.call(t,r),0===t.sockets.size&&(TJ("closing child namespace %s",e),t.adapter.close(),this.server._nsps.delete(t.name),this.children.delete(t))}}return this.server._nsps.set(e,t),this.server.sockets.emitReserved("new_namespace",t),t}fetchSockets(){throw new Error("fetchSockets() is not supported on parent namespaces")}}rJ.ParentNamespace=DJ,DJ.count=0;class kJ extends SJ.Adapter{constructor(e,t){super(e),this.children=t}broadcast(e,t){this.children.forEach((n=>{n.adapter.broadcast(e,t)}))}}var AJ={},CJ=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(AJ,"__esModule",{value:!0}),AJ.serveFile=AJ.restoreAdapter=AJ.patchAdapter=void 0;const RJ=iJ,OJ=s,LJ=(0,CJ(ah).default)("socket.io:adapter-uws"),IJ="",{addAll:PJ,del:NJ,broadcast:jJ}=RJ.Adapter.prototype;function FJ(e,t,n,r){const i=t.conn.id,s=t.conn.transport.socket;n&&(LJ("subscribe connection %s to topic %s",i,e),s.subscribe(e)),r.forEach((t=>{const n=`${e}${IJ}${t}`;LJ("subscribe connection %s to topic %s",i,n),s.subscribe(n)}))}AJ.patchAdapter=function(e){RJ.Adapter.prototype.addAll=function(e,t){const n=!this.sids.has(e);PJ.call(this,e,t);const r=this.nsp.sockets.get(e);r&&("websocket"!==r.conn.transport.name?n&&r.conn.on("upgrade",(()=>{const t=this.sids.get(e);t&&FJ(this.nsp.name,r,n,t)})):FJ(this.nsp.name,r,n,t))},RJ.Adapter.prototype.del=function(e,t){NJ.call(this,e,t);const n=this.nsp.sockets.get(e);if(n&&"websocket"===n.conn.transport.name){const e=n.conn.id,r=n.conn.transport.socket,i=`${this.nsp.name}${IJ}${t}`;LJ("unsubscribe connection %s from topic %s",e,i),r.unsubscribe(i)}},RJ.Adapter.prototype.broadcast=function(t,n){if(!(n.rooms.size<=1&&0===n.except.size))return void jJ.call(this,t,n);const r=n.flags||{},i={preEncoded:!0,volatile:r.volatile,compress:r.compress};t.nsp=this.nsp.name;const s=this.encoder.encode(t),o=0===n.rooms.size?this.nsp.name:`${this.nsp.name}${IJ}${n.rooms.keys().next().value}`;LJ("fast publish to %s",o),s.forEach((t=>{const n="string"!=typeof t;e.publish(o,n?t:"4"+t,n)})),this.apply(n,(e=>{"websocket"!==e.conn.transport.name&&e.client.writeToEngine(s,i)}))}},AJ.restoreAdapter=function(){RJ.Adapter.prototype.addAll=PJ,RJ.Adapter.prototype.del=NJ,RJ.Adapter.prototype.broadcast=jJ};AJ.serveFile=function(e,t){const{size:n}=(0,OJ.statSync)(t),r=(0,OJ.createReadStream)(t),i=()=>!r.destroyed&&r.destroy();e.onAborted(i),r.on("data",(t=>{const i=(e=>{const{buffer:t,byteOffset:n,byteLength:r}=e;return t.slice(n,n+r)})(t),s=e.getWriteOffset(),[o,a]=e.tryEnd(i,n);a||o||(r.pause(),e.onWritable((t=>{const[o,a]=e.tryEnd(i.slice(t-s),n);return!a&&o&&r.resume(),o})))})).on("error",(e=>{throw i(),e})).on("end",i)};var BJ="4.7.5";!function(e,t){var n=U&&U.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=U&&U.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=U&&U.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&n(t,e,i);return r(t,e),t},a=U&&U.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Namespace=t.Socket=t.Server=void 0;const c=w,l=s,u=T,d=KM,f=h,m=o,g=OG,y=CQ,v=p,b=VQ;Object.defineProperty(t,"Namespace",{enumerable:!0,get:function(){return b.Namespace}});const _=rJ,x=iJ,E=i(RQ),S=a(ah),D=nJ();Object.defineProperty(t,"Socket",{enumerable:!0,get:function(){return D.Socket}});const k=YQ,A=AJ,C=a(zZ),R=(0,S.default)("socket.io:server"),O=BJ,L=/\.map/;class I extends k.StrictEventEmitter{constructor(e,t={}){super(),this._nsps=new Map,this.parentNsps=new Map,this.parentNamespacesFromRegExp=new Map,"object"==typeof e&&e instanceof Object&&!e.listen&&(t=e,e=void 0),this.path(t.path||"/socket.io"),this.connectTimeout(t.connectTimeout||45e3),this.serveClient(!1!==t.serveClient),this._parser=t.parser||E,this.encoder=new this._parser.Encoder,this.opts=t,t.connectionStateRecovery?(t.connectionStateRecovery=Object.assign({maxDisconnectionDuration:12e4,skipMiddlewares:!0},t.connectionStateRecovery),this.adapter(t.adapter||x.SessionAwareAdapter)):this.adapter(t.adapter||x.Adapter),t.cleanupEmptyChildNamespaces=!!t.cleanupEmptyChildNamespaces,this.sockets=this.of("/"),(e||"number"==typeof e)&&this.attach(e),this.opts.cors&&(this._corsMiddleware=(0,C.default)(this.opts.cors))}get _opts(){return this.opts}serveClient(e){return arguments.length?(this._serveClient=e,this):this._serveClient}_checkNamespace(e,t,n){if(0===this.parentNsps.size)return n(!1);const r=this.parentNsps.keys(),i=()=>{const s=r.next();if(s.done)return n(!1);s.value(e,t,((t,r)=>{if(t||!r)return i();if(this._nsps.has(e))return R("dynamic namespace %s already exists",e),n(this._nsps.get(e));const o=this.parentNsps.get(s.value).createChild(e);R("dynamic namespace %s was created",e),n(o)}))};i()}path(e){if(!arguments.length)return this._path;this._path=e.replace(/\/$/,"");const t=this._path.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");return this.clientPathRegex=new RegExp("^"+t+"/socket\\.io(\\.msgpack|\\.esm)?(\\.min)?\\.js(\\.map)?(?:\\?|$)"),this}connectTimeout(e){return void 0===e?this._connectTimeout:(this._connectTimeout=e,this)}adapter(e){if(!arguments.length)return this._adapter;this._adapter=e;for(const e of this._nsps.values())e._initAdapter();return this}listen(e,t={}){return this.attach(e,t)}attach(e,t={}){if("function"==typeof e){throw new Error("You are trying to attach socket.io to an express request handler function. Please pass a http.Server instance.")}if(Number(e)==e&&(e=Number(e)),"number"==typeof e){R("creating http server and binding to %d",e);const t=e;e=c.createServer(((e,t)=>{t.writeHead(404),t.end()})),e.listen(t)}return Object.assign(t,this.opts),t.path=t.path||this._path,this.initEngine(e,t),this}attachApp(e,t={}){Object.assign(t,this.opts),t.path=t.path||this._path,R("creating uWebSockets.js-based engine with opts %j",t);const n=new g.uServer(t);n.attach(e,t),this.bind(n),this._serveClient&&e.get(`${this._path}/*`,((e,t)=>{if(!this.clientPathRegex.test(t.getUrl()))return void t.setYield(!0);const n=t.getUrl().replace(this._path,"").replace(/\?.*$/,"").replace(/^\//,""),r=L.test(n),i=r?"map":"source",s='"'+O+'"',o="W/"+s,a=t.getHeader("if-none-match");if(a&&(s===a||o===a))return R("serve client %s 304",i),e.writeStatus("304 Not Modified"),void e.end();R("serve client %s",i),e.writeHeader("cache-control","public, max-age=0"),e.writeHeader("content-type","application/"+(r?"json":"javascript")+"; charset=utf-8"),e.writeHeader("etag",s);const c=m.join(__dirname,"../client-dist/",n);(0,A.serveFile)(e,c)})),(0,A.patchAdapter)(e)}initEngine(e,t){R("creating engine.io instance with opts %j",t),this.eio=(0,g.attach)(e,t),this._serveClient&&this.attachServe(e),this.httpServer=e,this.bind(this.eio)}attachServe(e){R("attaching client serving req handler");const t=e.listeners("request").slice(0);e.removeAllListeners("request"),e.on("request",((n,r)=>{if(this.clientPathRegex.test(n.url))this._corsMiddleware?this._corsMiddleware(n,r,(()=>{this.serve(n,r)})):this.serve(n,r);else for(let i=0;i<t.length;i++)t[i].call(e,n,r)}))}serve(e,t){const n=e.url.replace(this._path,"").replace(/\?.*$/,""),r=L.test(n),i=r?"map":"source",s='"'+O+'"',o="W/"+s,a=e.headers["if-none-match"];if(a&&(s===a||o===a))return R("serve client %s 304",i),t.writeHead(304),void t.end();R("serve client %s",i),t.setHeader("Cache-Control","public, max-age=0"),t.setHeader("Content-Type","application/"+(r?"json":"javascript")+"; charset=utf-8"),t.setHeader("ETag",s),I.sendFile(n,e,t)}static sendFile(e,t,n){const r=(0,l.createReadStream)(m.join(__dirname,"../client-dist/",e)),i=e=>{e&&n.end()};switch(d(t).encodings(["br","gzip","deflate"])){case"br":n.writeHead(200,{"content-encoding":"br"}),(0,f.pipeline)(r,(0,u.createBrotliCompress)(),n,i);break;case"gzip":n.writeHead(200,{"content-encoding":"gzip"}),(0,f.pipeline)(r,(0,u.createGzip)(),n,i);break;case"deflate":n.writeHead(200,{"content-encoding":"deflate"}),(0,f.pipeline)(r,(0,u.createDeflate)(),n,i);break;default:n.writeHead(200),(0,f.pipeline)(r,n,i)}}bind(e){return this.engine=e,this.engine.on("connection",this.onconnection.bind(this)),this}onconnection(e){R("incoming connection with id %s",e.id);const t=new y.Client(this,e);return 3===e.protocol&&t.connect("/"),this}of(e,t){if("function"==typeof e||e instanceof RegExp){const n=new _.ParentNamespace(this);return R("initializing parent namespace %s",n.name),"function"==typeof e?this.parentNsps.set(e,n):(this.parentNsps.set(((t,n,r)=>r(null,e.test(t))),n),this.parentNamespacesFromRegExp.set(e,n)),t&&n.on("connect",t),n}"/"!==String(e)[0]&&(e="/"+e);let n=this._nsps.get(e);if(!n){for(const[t,n]of this.parentNamespacesFromRegExp)if(t.test(e))return R("attaching namespace %s to parent namespace %s",e,t),n.createChild(e);R("initializing namespace %s",e),n=new b.Namespace(this,e),this._nsps.set(e,n),"/"!==e&&this.sockets.emitReserved("new_namespace",n)}return t&&n.on("connect",t),n}close(e){this._nsps.forEach((e=>{e.sockets.forEach((e=>{e._onclose("server shutting down")})),e.adapter.close()})),this.engine.close(),(0,A.restoreAdapter)(),this.httpServer?this.httpServer.close(e):e&&e()}use(e){return this.sockets.use(e),this}to(e){return this.sockets.to(e)}in(e){return this.sockets.in(e)}except(e){return this.sockets.except(e)}send(...e){return this.sockets.emit("message",...e),this}write(...e){return this.sockets.emit("message",...e),this}serverSideEmit(e,...t){return this.sockets.serverSideEmit(e,...t)}serverSideEmitWithAck(e,...t){return this.sockets.serverSideEmitWithAck(e,...t)}allSockets(){return this.sockets.allSockets()}compress(e){return this.sockets.compress(e)}get volatile(){return this.sockets.volatile}get local(){return this.sockets.local}timeout(e){return this.sockets.timeout(e)}fetchSockets(){return this.sockets.fetchSockets()}socketsJoin(e){return this.sockets.socketsJoin(e)}socketsLeave(e){return this.sockets.socketsLeave(e)}disconnectSockets(e=!1){return this.sockets.disconnectSockets(e)}}t.Server=I;const P=Object.keys(v.EventEmitter.prototype).filter((function(e){return"function"==typeof v.EventEmitter.prototype[e]}));P.forEach((function(e){I.prototype[e]=function(){return this.sockets[e].apply(this.sockets,arguments)}})),e.exports=(e,t)=>new I(e,t),e.exports.Server=I,e.exports.Namespace=b.Namespace,e.exports.Socket=D.Socket,nJ()}(RG,RG.exports);var MJ=q(RG.exports);const{Server:UJ,Namespace:qJ,Socket:HJ}=MJ,$J=e=>new Promise(((t,n)=>{const r=a.platform();let i;if("win32"===r)i=`start ${e}`;else if("darwin"===r)i=`open ${e}`;else{if("linux"!==r)return n(new Error(`Unsupported platform: ${r}`));i=`xdg-open ${e}`}d.exec(i,(e=>{if(e)return n(new Error(`Failed to open URL on ${r}: ${e.message}`));t()}))})),zJ=process.cwd(),WJ=o.join(zJ,"src","views");const GJ=new ke;GJ.name("theme").description("dev, list"),GJ.command("create").description("Run development server with Webpack and BrowserSync").action(gf),GJ.command("check").description("Run development server with Webpack and BrowserSync").action((async function(){const e=zr("Checking files...").start();try{const t=await qO(WJ,"views"),n=Object.keys(t);await HO(n,e)}catch(t){e.fail("Failed to retrieve files"),console.error(_t.red(`Failed to retrieve files - Error: ${t.message}`))}})),GJ.command("dev").description("Run development server with Webpack and BrowserSync").action((async()=>{await mf();const{data:e}=await of.get("/apps"),t=e?.apps?.map((e=>({name:e.subdomain,value:e._id}))),n=await yl.prompt({type:"list",name:"app",message:"Choose the theme you want to use",choices:t});var r=e?.apps?.find((e=>e._id===n.app));const i=JU(),s=3e3,a=new w.Server(i),c=new UJ(a),l=zr("Start Server").start(),u=process.cwd(),p=o.join(u,"src"),h=o.join(u,"src","assets"),f=o.join(u,"dist");d.exec("npm run build",(async e=>{e&&console.log(e,"errrrrr");try{await I.access(p),await I.access(f)}catch{console.error("Error: Required directories do not exist."),process.exit(1)}i.use(JU.static(f)),i.get("*",j(i,{viewsDirectory:p,secretKey:r.secretKey,watch:!0})),hq.watch(h).on("change",(()=>{const e=zr("Building").start();d.exec(`cd ${u} && npm run build`,(t=>{if(t)return console.log(t),void e.fail(_t.red("Build failed"));e.succeed(_t.blue("Rebuilt successfully"))}))}));const t=zr("Connected");c.on("connection",(e=>{t.stop(),t.start();const n=hq.watch([p,o.join(u,"tailwind.config.js")]);n.on("change",(()=>{t.stop();const r=zr(_t.blue("Reloading")).start();e.emit("reload"),r.succeed(_t.blue("Reloaded successfully")),n.close()}))})),c.on("disconnect",(()=>{console.log(_t.blue("Disconnected")),t.stop(),reloadSpinner.stop()})),a.listen(s,(()=>{l.succeed("Server Started"),console.log("Server running at http://localhost:3000"),$J("http://localhost:3000")}))}))})),GJ.command("list").description("List available themes").action((async()=>{const e=zr("Fetching Data...").start();try{const{data:t}=await of.get("/themes");e.stop();const n=t?.themes?.map((e=>({name:e.title,value:e._id}))),r=await yl.prompt({type:"list",name:"selectedThemeId",message:"Choose the theme you want to use:",choices:n}),i=t?.themes.find((e=>e._id===r.selectedThemeId));console.log("🚀 ~ getThemes ~ selectedTheme:",i)}catch(t){e.stop(),console.error("Failed to fetch data:",t)}}));const VJ=Object.create(null);VJ.open="0",VJ.close="1",VJ.ping="2",VJ.pong="3",VJ.message="4",VJ.upgrade="5",VJ.noop="6";const KJ=Object.create(null);Object.keys(VJ).forEach((e=>{KJ[VJ[e]]=e}));const YJ={type:"error",data:"parser error"},ZJ=({type:e,data:t},n,r)=>t instanceof ArrayBuffer||ArrayBuffer.isView(t)?r(n?t:"b"+QJ(t,!0).toString("base64")):r(VJ[e]+(t||"")),QJ=(e,t)=>Buffer.isBuffer(e)||e instanceof Uint8Array&&!t?e:e instanceof ArrayBuffer?Buffer.from(e):Buffer.from(e.buffer,e.byteOffset,e.byteLength);let JJ;const XJ=(e,t)=>{if("string"!=typeof e)return{type:"message",data:eX(e,t)};const n=e.charAt(0);if("b"===n){const n=Buffer.from(e.substring(1),"base64");return{type:"message",data:eX(n,t)}}return KJ[n]?e.length>1?{type:KJ[n],data:e.substring(1)}:{type:KJ[n]}:YJ},eX=(e,t)=>"arraybuffer"===t?e instanceof ArrayBuffer?e:Buffer.isBuffer(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e.buffer:Buffer.isBuffer(e)?e:Buffer.from(e),tX=String.fromCharCode(30);function nX(){return new TransformStream({transform(e,t){!function(e,t){if(e.data instanceof ArrayBuffer||ArrayBuffer.isView(e.data))return t(QJ(e.data,!1));ZJ(e,!0,(e=>{JJ||(JJ=new TextEncoder),t(JJ.encode(e))}))}(e,(n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);const e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&"string"!=typeof e.data&&(i[0]|=128),t.enqueue(i),t.enqueue(n)}))}})}let rX;function iX(e){return e.reduce(((e,t)=>e+t.length),0)}function sX(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}const oX=global;function aX(e,...t){return t.reduce(((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t)),{})}const cX=oX.setTimeout,lX=oX.clearTimeout;function uX(e,t){t.useNativeTimers?(e.setTimeoutFn=cX.bind(oX),e.clearTimeoutFn=lX.bind(oX)):(e.setTimeoutFn=oX.setTimeout.bind(oX),e.clearTimeoutFn=oX.clearTimeout.bind(oX))}class pX extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}class hX extends OQ{constructor(e){super(),this.writable=!1,uX(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,n){return super.emitReserved("error",new pX(e,t,n)),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=XJ(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 n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}(e);return t.length?"?"+t:""}}const dX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),fX=64,mX={};let gX,yX=0,vX=0;function bX(e){let t="";do{t=dX[e%fX]+t,e=Math.floor(e/fX)}while(e>0);return t}function _X(){const e=bX(+new Date);return e!==gX?(yX=0,gX=e):e+"."+bX(yX++)}for(;vX<fX;vX++)mX[dX[vX]]=vX;
|
|
384
384
|
/**
|
|
385
385
|
* Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
|
|
386
386
|
*
|