-
Notifications
You must be signed in to change notification settings - Fork 16
/
node.js
1 lines (1 loc) · 48.9 KB
/
node.js
1
import{g as e}from"./lib/__bundle-5dbfca78.js";import"./lib/__bundle-46d64517.js";import t from"events";import s from"https";import r from"http";import i from"net";import o from"tls";import n from"crypto";import a from"stream";import c from"url";import h from"zlib";import l from"fs";import d from"path";import f from"os";import u from"buffer";var _={exports:{}};const p=["nodebuffer","arraybuffer","fragments"],m="undefined"!=typeof Blob;m&&p.push("blob");var v={BINARY_TYPES:p,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:m,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}};e(v);var y={exports:{}};function b(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var g,S,w,E,k,x,T={exports:{}};function O(){if(w)return T.exports;w=1;const e="function"==typeof __webpack_require__?__non_webpack_require__:b;return"function"==typeof e.addon?T.exports=e.addon.bind(e):T.exports=function(){if(S)return g;S=1;var e=l,t=d,s=f,r="function"==typeof __webpack_require__?__non_webpack_require__:b,i=process.config&&process.config.variables||{},o=!!process.env.PREBUILDS_ONLY,n=process.versions.modules,a=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",c=process.env.npm_config_arch||s.arch(),h=process.env.npm_config_platform||s.platform(),u=process.env.LIBC||(function(t){return"linux"===t&&e.existsSync("/etc/alpine-release")}(h)?"musl":"glibc"),_=process.env.ARM_VERSION||("arm64"===c?"8":i.arm_version)||"",p=(process.versions.uv||"").split(".")[0];function m(e){return r(m.resolve(e))}function v(t){try{return e.readdirSync(t)}catch(e){return[]}}function y(e,s){var r=v(e).filter(s);return r[0]&&t.join(e,r[0])}function w(e){return/\.node$/.test(e)}function E(e){var t=e.split("-");if(2===t.length){var s=t[0],r=t[1].split("+");if(s&&r.length&&r.every(Boolean))return{name:e,platform:s,architectures:r}}}function k(e,t){return function(s){return null!=s&&s.platform===e&&s.architectures.includes(t)}}function x(e,t){return e.architectures.length-t.architectures.length}function T(e){var t=e.split("."),s={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)s.runtime=i;else if("napi"===i)s.napi=!0;else if("abi"===i.slice(0,3))s.abi=i.slice(3);else if("uv"===i.slice(0,2))s.uv=i.slice(2);else if("armv"===i.slice(0,4))s.armv=i.slice(4);else{if("glibc"!==i&&"musl"!==i)continue;s.libc=i}s.specificity++}return s}}function O(e,t){return function(s){return!(null==s||s.runtime&&s.runtime!==e&&!function(e){return"node"===e.runtime&&e.napi}(s)||s.abi&&s.abi!==t&&!s.napi||s.uv&&s.uv!==p||s.armv&&s.armv!==_||s.libc&&s.libc!==u)}}function C(e){return function(t,s){return t.runtime!==s.runtime?t.runtime===e?-1:1:t.abi!==s.abi?t.abi?-1:1:t.specificity!==s.specificity?t.specificity>s.specificity?-1:1:0}}return g=m,m.resolve=m.path=function(e){e=t.resolve(e||".");try{var s=r(t.join(e,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[s+"_PREBUILD"]&&(e=process.env[s+"_PREBUILD"])}catch(e){}if(!o){var i=y(t.join(e,"build/Release"),w);if(i)return i;var l=y(t.join(e,"build/Debug"),w);if(l)return l}var d=b(e);if(d)return d;var f=b(t.dirname(process.execPath));if(f)return f;var m=["platform="+h,"arch="+c,"runtime="+a,"abi="+n,"uv="+p,_?"armv="+_:"","libc="+u,"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 "+m+"\n loaded from: "+e+"\n");function b(e){var s=v(t.join(e,"prebuilds")).map(E).filter(k(h,c)).sort(x)[0];if(s){var r=t.join(e,"prebuilds",s.name),i=v(r).map(T).filter(O(a,n)).sort(C(a))[0];return i?t.join(r,i.file):void 0}}},m.parseTags=T,m.matchTags=O,m.compareTags=C,m.parseTuple=E,m.matchTuple=k,m.compareTuples=x,g}(),T.exports}const{EMPTY_BUFFER:C}=v,N=Buffer[Symbol.species];function L(e,t,s,r,i){for(let o=0;o<i;o++)s[r+o]=e[o]^t[3&o]}function P(e,t){for(let s=0;s<e.length;s++)e[s]^=t[3&s]}if(_.exports={concat:function(e,t){if(0===e.length)return C;if(1===e.length)return e[0];const s=Buffer.allocUnsafe(t);let r=0;for(let t=0;t<e.length;t++){const i=e[t];s.set(i,r),r+=i.length}return r<t?new N(s.buffer,s.byteOffset,r):s},mask:L,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 s;return t instanceof ArrayBuffer?s=new N(t):ArrayBuffer.isView(t)?s=new N(t.buffer,t.byteOffset,t.byteLength):(s=Buffer.from(t),e.readOnly=!1),s},unmask:P},!process.env.WS_NO_BUFFER_UTIL)try{const e=function(){if(x)return y.exports;x=1;try{y.exports=O()(__dirname)}catch(e){y.exports=(k||(k=1,E={mask:(e,t,s,r,i)=>{for(var o=0;o<i;o++)s[r+o]=e[o]^t[3&o]},unmask:(e,t)=>{const s=e.length;for(var r=0;r<s;r++)e[r]^=t[3&r]}}),E)}return y.exports}();_.exports.mask=function(t,s,r,i,o){o<48?L(t,s,r,i,o):e.mask(t,s,r,i,o)},_.exports.unmask=function(t,s){t.length<32?P(t,s):e.unmask(t,s)}}catch(e){}var B=_.exports;e(B);const R=Symbol("kDone"),U=Symbol("kRun");var I=class{constructor(e){this[R]=()=>{this.pending--,this[U]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[U]()}[U](){if(this.pending!==this.concurrency&&this.jobs.length){const e=this.jobs.shift();this.pending++,e(this[R])}}};e(I);const D=h,W=B,M=I,{kStatusCode:A}=v,F=Buffer[Symbol.species],j=Buffer.from([0,0,255,255]),$=Symbol("permessage-deflate"),G=Symbol("total-length"),V=Symbol("callback"),q=Symbol("buffers"),z=Symbol("error");let H;var Y=class{constructor(e,t,s){if(this._maxPayload=0|s,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,!H){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;H=new M(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[V];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,s=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(!s)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(s.server_no_context_takeover=!0),t.clientNoContextTakeover&&(s.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(s.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?s.client_max_window_bits=t.clientMaxWindowBits:!0!==s.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete s.client_max_window_bits,s}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 s=e[t];if(s.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(s=s[0],"client_max_window_bits"===t){if(!0!==s){const e=+s;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${s}`);s=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}else if("server_max_window_bits"===t){const e=+s;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${s}`);s=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==s)throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}e[t]=s}))})),e}decompress(e,t,s){H.add((r=>{this._decompress(e,t,((e,t)=>{r(),s(e,t)}))}))}compress(e,t,s){H.add((r=>{this._compress(e,t,((e,t)=>{r(),s(e,t)}))}))}_decompress(e,t,s){const r=this._isServer?"client":"server";if(!this._inflate){const e=`${r}_max_window_bits`,t="number"!=typeof this.params[e]?D.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=D.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t}),this._inflate[$]=this,this._inflate[G]=0,this._inflate[q]=[],this._inflate.on("error",Z),this._inflate.on("data",K)}this._inflate[V]=s,this._inflate.write(e),t&&this._inflate.write(j),this._inflate.flush((()=>{const e=this._inflate[z];if(e)return this._inflate.close(),this._inflate=null,void s(e);const i=W.concat(this._inflate[q],this._inflate[G]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[G]=0,this._inflate[q]=[],t&&this.params[`${r}_no_context_takeover`]&&this._inflate.reset()),s(null,i)}))}_compress(e,t,s){const r=this._isServer?"server":"client";if(!this._deflate){const e=`${r}_max_window_bits`,t="number"!=typeof this.params[e]?D.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=D.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t}),this._deflate[G]=0,this._deflate[q]=[],this._deflate.on("data",X)}this._deflate[V]=s,this._deflate.write(e),this._deflate.flush(D.Z_SYNC_FLUSH,(()=>{if(!this._deflate)return;let e=W.concat(this._deflate[q],this._deflate[G]);t&&(e=new F(e.buffer,e.byteOffset,e.length-4)),this._deflate[V]=null,this._deflate[G]=0,this._deflate[q]=[],t&&this.params[`${r}_no_context_takeover`]&&this._deflate.reset(),s(null,e)}))}};function X(e){this[q].push(e),this[G]+=e.length}function K(e){this[G]+=e.length,this[$]._maxPayload<1||this[G]<=this[$]._maxPayload?this[q].push(e):(this[z]=new RangeError("Max payload size exceeded"),this[z].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[z][A]=1009,this.removeListener("data",K),this.reset())}function Z(e){this[$]._inflate=null,e[A]=1007,this[V](e)}e(Y);var J={exports:{}};const{isUtf8:Q}=u,{hasBlob:ee}=v;function te(e){const t=e.length;let s=0;for(;s<t;)if(128&e[s])if(192==(224&e[s])){if(s+1===t||128!=(192&e[s+1])||192==(254&e[s]))return!1;s+=2}else if(224==(240&e[s])){if(s+2>=t||128!=(192&e[s+1])||128!=(192&e[s+2])||224===e[s]&&128==(224&e[s+1])||237===e[s]&&160==(224&e[s+1]))return!1;s+=3}else{if(240!=(248&e[s]))return!1;if(s+3>=t||128!=(192&e[s+1])||128!=(192&e[s+2])||128!=(192&e[s+3])||240===e[s]&&128==(240&e[s+1])||244===e[s]&&e[s+1]>143||e[s]>244)return!1;s+=4}else s++;return!0}if(J.exports={isBlob:function(e){return ee&&"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&("Blob"===e[Symbol.toStringTag]||"File"===e[Symbol.toStringTag])},isValidStatusCode:function(e){return e>=1e3&&e<=1014&&1004!==e&&1005!==e&&1006!==e||e>=3e3&&e<=4999},isValidUTF8:te,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]},Q)J.exports.isValidUTF8=function(e){return e.length<24?te(e):Q(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const e=require("utf-8-validate");J.exports.isValidUTF8=function(t){return t.length<32?te(t):e(t)}}catch(e){}var se=J.exports;e(se);const{Writable:re}=a,ie=Y,{BINARY_TYPES:oe,EMPTY_BUFFER:ne,kStatusCode:ae,kWebSocket:ce}=v,{concat:he,toArrayBuffer:le,unmask:de}=B,{isValidStatusCode:fe,isValidUTF8:ue}=se,_e=Buffer[Symbol.species];var pe=class extends re{constructor(e={}){super(),this._allowSynchronousEvents=void 0===e.allowSynchronousEvents||e.allowSynchronousEvents,this._binaryType=e.binaryType||oe[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=0|e.maxPayload,this._skipUTF8Validation=!!e.skipUTF8Validation,this[ce]=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,s){if(8===this._opcode&&0==this._state)return s();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(s)}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 _e(t.buffer,t.byteOffset+e,t.length-e),new _e(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const s=this._buffers[0],r=t.length-e;e>=s.length?t.set(this._buffers.shift(),r):(t.set(new Uint8Array(s.buffer,s.byteOffset,e),r),this._buffers[0]=new _e(s.buffer,s.byteOffset+e,s.length-e)),e-=s.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 s=!(64&~t[0]);if(!s||this._extensions[ie.extensionName]){if(this._fin=!(128&~t[0]),this._opcode=15&t[0],this._payloadLength=127&t[1],0===this._opcode){if(s){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=s}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(s){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),s=t.readUInt32BE(0);if(s>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=s*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=ne;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]&&de(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[ie.extensionName].decompress(e,this._fin,((e,s)=>{if(e)return t(e);if(s.length){if(this._messageLength+=s.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(s)}this.dataMessage(t),0===this._state&&this.startLoop(t)}))}dataMessage(e){if(!this._fin)return void(this._state=0);const t=this._messageLength,s=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],2===this._opcode){let r;r="nodebuffer"===this._binaryType?he(s,t):"arraybuffer"===this._binaryType?le(he(s,t)):"blob"===this._binaryType?new Blob(s):s,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=he(s,t);if(!this._skipUTF8Validation&&!ue(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,ne),this.end();else{const s=e.readUInt16BE(0);if(!fe(s)){const e=this.createError(RangeError,`invalid status code ${s}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void t(e)}const r=new _e(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!ue(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",s,r),this.end()}this._state=0}}createError(e,t,s,r,i){this._loop=!1,this._errored=!0;const o=new e(s?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(o,this.createError),o.code=i,o[ae]=r,o}};e(pe);const{randomFillSync:me}=n,ve=Y,{EMPTY_BUFFER:ye,kWebSocket:be,NOOP:ge}=v,{isBlob:Se,isValidStatusCode:we}=se,{mask:Ee,toBuffer:ke}=B,xe=Symbol("kByteLength"),Te=Buffer.alloc(4),Oe=8192;let Ce,Ne=Oe;class Le{constructor(e,t,s){this._extensions=t||{},s&&(this._generateMask=s,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=0,this.onerror=ge,this[be]=void 0}static frame(e,t){let s,r,i=!1,o=2,n=!1;t.mask&&(s=t.maskBuffer||Te,t.generateMask?t.generateMask(s):(Ne===Oe&&(void 0===Ce&&(Ce=Buffer.alloc(Oe)),me(Ce,0,Oe),Ne=0),s[0]=Ce[Ne++],s[1]=Ce[Ne++],s[2]=Ce[Ne++],s[3]=Ce[Ne++]),n=!(s[0]|s[1]|s[2]|s[3]),o=6),"string"==typeof e?r=t.mask&&!n||void 0===t[xe]?(e=Buffer.from(e)).length:t[xe]:(r=e.length,i=t.mask&&t.readOnly&&!n);let a=r;r>=65536?(o+=8,a=127):r>125&&(o+=2,a=126);const c=Buffer.allocUnsafe(i?r+o:o);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[o-4]=s[0],c[o-3]=s[1],c[o-2]=s[2],c[o-1]=s[3],n?[c,e]:i?(Ee(e,s,c,o,r),[c]):(Ee(e,s,e,0,r),[c,e])):[c,e]}close(e,t,s,r){let i;if(void 0===e)i=ye;else{if("number"!=typeof e||!we(e))throw new TypeError("First argument must be a valid error code number");if(void 0!==t&&t.length){const s=Buffer.byteLength(t);if(s>123)throw new RangeError("The message must not be greater than 123 bytes");i=Buffer.allocUnsafe(2+s),i.writeUInt16BE(e,0),"string"==typeof t?i.write(t,2):i.set(t,2)}else i=Buffer.allocUnsafe(2),i.writeUInt16BE(e,0)}const o={[xe]:i.length,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};0!==this._state?this.enqueue([this.dispatch,i,!1,o,r]):this.sendFrame(Le.frame(i,o),r)}ping(e,t,s){let r,i;if("string"==typeof e?(r=Buffer.byteLength(e),i=!1):Se(e)?(r=e.size,i=!1):(r=(e=ke(e)).length,i=ke.readOnly),r>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[xe]:r,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:9,readOnly:i,rsv1:!1};Se(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,o,s]):this.getBlobData(e,!1,o,s):0!==this._state?this.enqueue([this.dispatch,e,!1,o,s]):this.sendFrame(Le.frame(e,o),s)}pong(e,t,s){let r,i;if("string"==typeof e?(r=Buffer.byteLength(e),i=!1):Se(e)?(r=e.size,i=!1):(r=(e=ke(e)).length,i=ke.readOnly),r>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[xe]:r,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:10,readOnly:i,rsv1:!1};Se(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,o,s]):this.getBlobData(e,!1,o,s):0!==this._state?this.enqueue([this.dispatch,e,!1,o,s]):this.sendFrame(Le.frame(e,o),s)}send(e,t,s){const r=this._extensions[ve.extensionName];let i,o,n=t.binary?2:1,a=t.compress;"string"==typeof e?(i=Buffer.byteLength(e),o=!1):Se(e)?(i=e.size,o=!1):(i=(e=ke(e)).length,o=ke.readOnly),this._firstFragment?(this._firstFragment=!1,a&&r&&r.params[r._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(a=i>=r._threshold),this._compress=a):(a=!1,n=0),t.fin&&(this._firstFragment=!0);const c={[xe]:i,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:o,rsv1:a};Se(e)?0!==this._state?this.enqueue([this.getBlobData,e,this._compress,c,s]):this.getBlobData(e,this._compress,c,s):0!==this._state?this.enqueue([this.dispatch,e,this._compress,c,s]):this.dispatch(e,this._compress,c,s)}getBlobData(e,t,s,r){this._bufferedBytes+=s[xe],this._state=2,e.arrayBuffer().then((e=>{if(this._socket.destroyed){const e=new Error("The socket was closed while the blob was being read");return void process.nextTick(Be,this,e,r)}this._bufferedBytes-=s[xe];const i=ke(e);t?this.dispatch(i,t,s,r):(this._state=0,this.sendFrame(Le.frame(i,s),r),this.dequeue())})).catch((e=>{process.nextTick(Re,this,e,r)}))}dispatch(e,t,s,r){if(!t)return void this.sendFrame(Le.frame(e,s),r);const i=this._extensions[ve.extensionName];this._bufferedBytes+=s[xe],this._state=1,i.compress(e,s.fin,((e,t)=>{if(this._socket.destroyed){Be(this,new Error("The socket was closed while data was being compressed"),r)}else this._bufferedBytes-=s[xe],this._state=0,s.readOnly=!1,this.sendFrame(Le.frame(t,s),r),this.dequeue()}))}dequeue(){for(;0===this._state&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[3][xe],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][xe],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)}}var Pe=Le;function Be(e,t,s){"function"==typeof s&&s(t);for(let s=0;s<e._queue.length;s++){const r=e._queue[s],i=r[r.length-1];"function"==typeof i&&i(t)}}function Re(e,t,s){Be(e,t,s),e.onerror(t)}e(Pe);const{kForOnEventAttribute:Ue,kListener:Ie}=v,De=Symbol("kCode"),We=Symbol("kData"),Me=Symbol("kError"),Ae=Symbol("kMessage"),Fe=Symbol("kReason"),je=Symbol("kTarget"),$e=Symbol("kType"),Ge=Symbol("kWasClean");class Ve{constructor(e){this[je]=null,this[$e]=e}get target(){return this[je]}get type(){return this[$e]}}Object.defineProperty(Ve.prototype,"target",{enumerable:!0}),Object.defineProperty(Ve.prototype,"type",{enumerable:!0});class qe extends Ve{constructor(e,t={}){super(e),this[De]=void 0===t.code?0:t.code,this[Fe]=void 0===t.reason?"":t.reason,this[Ge]=void 0!==t.wasClean&&t.wasClean}get code(){return this[De]}get reason(){return this[Fe]}get wasClean(){return this[Ge]}}Object.defineProperty(qe.prototype,"code",{enumerable:!0}),Object.defineProperty(qe.prototype,"reason",{enumerable:!0}),Object.defineProperty(qe.prototype,"wasClean",{enumerable:!0});class ze extends Ve{constructor(e,t={}){super(e),this[Me]=void 0===t.error?null:t.error,this[Ae]=void 0===t.message?"":t.message}get error(){return this[Me]}get message(){return this[Ae]}}Object.defineProperty(ze.prototype,"error",{enumerable:!0}),Object.defineProperty(ze.prototype,"message",{enumerable:!0});class He extends Ve{constructor(e,t={}){super(e),this[We]=void 0===t.data?null:t.data}get data(){return this[We]}}Object.defineProperty(He.prototype,"data",{enumerable:!0});const Ye={addEventListener(e,t,s={}){for(const r of this.listeners(e))if(!s[Ue]&&r[Ie]===t&&!r[Ue])return;let r;if("message"===e)r=function(e,s){const r=new He("message",{data:s?e:e.toString()});r[je]=this,Ke(t,this,r)};else if("close"===e)r=function(e,s){const r=new qe("close",{code:e,reason:s.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});r[je]=this,Ke(t,this,r)};else if("error"===e)r=function(e){const s=new ze("error",{error:e,message:e.message});s[je]=this,Ke(t,this,s)};else{if("open"!==e)return;r=function(){const e=new Ve("open");e[je]=this,Ke(t,this,e)}}r[Ue]=!!s[Ue],r[Ie]=t,s.once?this.once(e,r):this.on(e,r)},removeEventListener(e,t){for(const s of this.listeners(e))if(s[Ie]===t&&!s[Ue]){this.removeListener(e,s);break}}};var Xe={CloseEvent:qe,ErrorEvent:ze,Event:Ve,EventTarget:Ye,MessageEvent:He};function Ke(e,t,s){"object"==typeof e&&e.handleEvent?e.handleEvent.call(e,s):e.call(t,s)}e(Xe);const{tokenChars:Ze}=se;function Je(e,t,s){void 0===e[t]?e[t]=[s]:e[t].push(s)}var Qe={format:function(e){return Object.keys(e).map((t=>{let s=e[t];return Array.isArray(s)||(s=[s]),s.map((e=>[t].concat(Object.keys(e).map((t=>{let s=e[t];return Array.isArray(s)||(s=[s]),s.map((e=>!0===e?t:`${t}=${e}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")},parse:function(e){const t=Object.create(null);let s,r,i=Object.create(null),o=!1,n=!1,a=!1,c=-1,h=-1,l=-1,d=0;for(;d<e.length;d++)if(h=e.charCodeAt(d),void 0===s)if(-1===l&&1===Ze[h])-1===c&&(c=d);else if(0===d||32!==h&&9!==h){if(59!==h&&44!==h)throw new SyntaxError(`Unexpected character at index ${d}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${d}`);-1===l&&(l=d);const r=e.slice(c,l);44===h?(Je(t,r,i),i=Object.create(null)):s=r,c=l=-1}}else-1===l&&-1!==c&&(l=d);else if(void 0===r)if(-1===l&&1===Ze[h])-1===c&&(c=d);else if(32===h||9===h)-1===l&&-1!==c&&(l=d);else if(59===h||44===h){if(-1===c)throw new SyntaxError(`Unexpected character at index ${d}`);-1===l&&(l=d),Je(i,e.slice(c,l),!0),44===h&&(Je(t,s,i),i=Object.create(null),s=void 0),c=l=-1}else{if(61!==h||-1===c||-1!==l)throw new SyntaxError(`Unexpected character at index ${d}`);r=e.slice(c,d),c=l=-1}else if(n){if(1!==Ze[h])throw new SyntaxError(`Unexpected character at index ${d}`);-1===c?c=d:o||(o=!0),n=!1}else if(a)if(1===Ze[h])-1===c&&(c=d);else if(34===h&&-1!==c)a=!1,l=d;else{if(92!==h)throw new SyntaxError(`Unexpected character at index ${d}`);n=!0}else if(34===h&&61===e.charCodeAt(d-1))a=!0;else if(-1===l&&1===Ze[h])-1===c&&(c=d);else if(-1===c||32!==h&&9!==h){if(59!==h&&44!==h)throw new SyntaxError(`Unexpected character at index ${d}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${d}`);-1===l&&(l=d);let n=e.slice(c,l);o&&(n=n.replace(/\\/g,""),o=!1),Je(i,r,n),44===h&&(Je(t,s,i),i=Object.create(null),s=void 0),r=void 0,c=l=-1}}else-1===l&&(l=d);if(-1===c||a||32===h||9===h)throw new SyntaxError("Unexpected end of input");-1===l&&(l=d);const f=e.slice(c,l);return void 0===s?Je(t,f,i):(void 0===r?Je(i,f,!0):Je(i,r,o?f.replace(/\\/g,""):f),Je(t,s,i)),t}};e(Qe);const et=t,tt=s,st=r,rt=i,it=o,{randomBytes:ot,createHash:nt}=n,{URL:at}=c,ct=Y,ht=pe,lt=Pe,{isBlob:dt}=se,{BINARY_TYPES:ft,EMPTY_BUFFER:ut,GUID:_t,kForOnEventAttribute:pt,kListener:mt,kStatusCode:vt,kWebSocket:yt,NOOP:bt}=v,{EventTarget:{addEventListener:gt,removeEventListener:St}}=Xe,{format:wt,parse:Et}=Qe,{toBuffer:kt}=B,xt=Symbol("kAborted"),Tt=[8,13],Ot=["CONNECTING","OPEN","CLOSING","CLOSED"],Ct=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;class Nt extends et{constructor(e,t,s){super(),this._binaryType=ft[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ut,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=Nt.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,null!==e?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,void 0===t?t=[]:Array.isArray(t)||("object"==typeof t&&null!==t?(s=t,t=[]):t=[t]),Pt(this,e,t,s)):(this._autoPong=s.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){ft.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(e,t,s){const r=new ht({allowSynchronousEvents:s.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation}),i=new lt(e,this._extensions,s.generateMask);this._receiver=r,this._sender=i,this._socket=e,r[yt]=this,i[yt]=this,e[yt]=this,r.on("conclude",Wt),r.on("drain",Mt),r.on("error",At),r.on("message",jt),r.on("ping",$t),r.on("pong",Gt),i.onerror=qt,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),t.length>0&&e.unshift(t),e.on("close",Ht),e.on("data",Yt),e.on("end",Xt),e.on("error",Kt),this._readyState=Nt.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=Nt.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[ct.extensionName]&&this._extensions[ct.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=Nt.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState!==Nt.CLOSED)if(this.readyState!==Nt.CONNECTING)this.readyState!==Nt.CLOSING?(this._readyState=Nt.CLOSING,this._sender.close(e,t,!this._isServer,(e=>{e||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())})),zt(this)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();else{const e="WebSocket was closed before the connection was established";It(this,this._req,e)}}pause(){this.readyState!==Nt.CONNECTING&&this.readyState!==Nt.CLOSED&&(this._paused=!0,this._socket.pause())}ping(e,t,s){if(this.readyState===Nt.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(s=e,e=t=void 0):"function"==typeof t&&(s=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===Nt.OPEN?(void 0===t&&(t=!this._isServer),this._sender.ping(e||ut,t,s)):Dt(this,e,s)}pong(e,t,s){if(this.readyState===Nt.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(s=e,e=t=void 0):"function"==typeof t&&(s=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===Nt.OPEN?(void 0===t&&(t=!this._isServer),this._sender.pong(e||ut,t,s)):Dt(this,e,s)}resume(){this.readyState!==Nt.CONNECTING&&this.readyState!==Nt.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,t,s){if(this.readyState===Nt.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof t&&(s=t,t={}),"number"==typeof e&&(e=e.toString()),this.readyState!==Nt.OPEN)return void Dt(this,e,s);const r={binary:"string"!=typeof e,mask:!this._isServer,compress:!0,fin:!0,...t};this._extensions[ct.extensionName]||(r.compress=!1),this._sender.send(e||ut,r,s)}terminate(){if(this.readyState!==Nt.CLOSED)if(this.readyState!==Nt.CONNECTING)this._socket&&(this._readyState=Nt.CLOSING,this._socket.destroy());else{const e="WebSocket was closed before the connection was established";It(this,this._req,e)}}}Object.defineProperty(Nt,"CONNECTING",{enumerable:!0,value:Ot.indexOf("CONNECTING")}),Object.defineProperty(Nt.prototype,"CONNECTING",{enumerable:!0,value:Ot.indexOf("CONNECTING")}),Object.defineProperty(Nt,"OPEN",{enumerable:!0,value:Ot.indexOf("OPEN")}),Object.defineProperty(Nt.prototype,"OPEN",{enumerable:!0,value:Ot.indexOf("OPEN")}),Object.defineProperty(Nt,"CLOSING",{enumerable:!0,value:Ot.indexOf("CLOSING")}),Object.defineProperty(Nt.prototype,"CLOSING",{enumerable:!0,value:Ot.indexOf("CLOSING")}),Object.defineProperty(Nt,"CLOSED",{enumerable:!0,value:Ot.indexOf("CLOSED")}),Object.defineProperty(Nt.prototype,"CLOSED",{enumerable:!0,value:Ot.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(Nt.prototype,e,{enumerable:!0})})),["open","error","close","message"].forEach((e=>{Object.defineProperty(Nt.prototype,`on${e}`,{enumerable:!0,get(){for(const t of this.listeners(e))if(t[pt])return t[mt];return null},set(t){for(const t of this.listeners(e))if(t[pt]){this.removeListener(e,t);break}"function"==typeof t&&this.addEventListener(e,t,{[pt]:!0})}})})),Nt.prototype.addEventListener=gt,Nt.prototype.removeEventListener=St;var Lt=Nt;function Pt(e,t,s,r){const i={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Tt[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,!Tt.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Tt.join(", ")})`);let o;if(t instanceof at)o=t;else try{o=new at(t)}catch(e){throw new SyntaxError(`Invalid URL: ${t}`)}"http:"===o.protocol?o.protocol="ws:":"https:"===o.protocol&&(o.protocol="wss:"),e._url=o.href;const n="wss:"===o.protocol,a="ws+unix:"===o.protocol;let c;if("ws:"===o.protocol||n||a?a&&!o.pathname?c="The URL's pathname is empty":o.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 Bt(e,t)}const h=n?443:80,l=ot(16).toString("base64"),d=n?tt.request:st.request,f=new Set;let u,_;if(i.createConnection=i.createConnection||(n?Ut:Rt),i.defaultPort=i.defaultPort||h,i.port=o.port||h,i.host=o.hostname.startsWith("[")?o.hostname.slice(1,-1):o.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":l,Connection:"Upgrade",Upgrade:"websocket"},i.path=o.pathname+o.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(u=new ct(!0!==i.perMessageDeflate?i.perMessageDeflate:{},!1,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=wt({[ct.extensionName]:u.offer()})),s.length){for(const e of s){if("string"!=typeof e||!Ct.test(e)||f.has(e))throw new SyntaxError("An invalid or duplicated subprotocol was specified");f.add(e)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(o.username||o.password)&&(i.auth=`${o.username}:${o.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=n,e._originalHostOrSocketPath=a?i.socketPath:o.host;const t=r&&r.headers;if(r={...r,headers:{}},t)for(const[e,s]of Object.entries(t))r.headers[e.toLowerCase()]=s}else if(0===e.listenerCount("redirect")){const t=a?!!e._originalIpc&&i.socketPath===e._originalHostOrSocketPath:!e._originalIpc&&o.host===e._originalHostOrSocketPath;(!t||e._originalSecure&&!n)&&(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")),_=e._req=d(i),e._redirects&&e.emit("redirect",e.url,_)}else _=e._req=d(i);i.timeout&&_.on("timeout",(()=>{It(e,_,"Opening handshake has timed out")})),_.on("error",(t=>{null===_||_[xt]||(_=e._req=null,Bt(e,t))})),_.on("response",(o=>{const n=o.headers.location,a=o.statusCode;if(n&&i.followRedirects&&a>=300&&a<400){if(++e._redirects>i.maxRedirects)return void It(e,_,"Maximum redirects exceeded");let o;_.abort();try{o=new at(n,t)}catch(t){const s=new SyntaxError(`Invalid URL: ${n}`);return void Bt(e,s)}Pt(e,o,s,r)}else e.emit("unexpected-response",_,o)||It(e,_,`Unexpected server response: ${o.statusCode}`)})),_.on("upgrade",((t,s,r)=>{if(e.emit("upgrade",t),e.readyState!==Nt.CONNECTING)return;_=e._req=null;const o=t.headers.upgrade;if(void 0===o||"websocket"!==o.toLowerCase())return void It(e,s,"Invalid Upgrade header");const n=nt("sha1").update(l+_t).digest("base64");if(t.headers["sec-websocket-accept"]!==n)return void It(e,s,"Invalid Sec-WebSocket-Accept header");const a=t.headers["sec-websocket-protocol"];let c;if(void 0!==a?f.size?f.has(a)||(c="Server sent an invalid subprotocol"):c="Server sent a subprotocol but none was requested":f.size&&(c="Server sent no subprotocol"),c)return void It(e,s,c);a&&(e._protocol=a);const h=t.headers["sec-websocket-extensions"];if(void 0!==h){if(!u){return void It(e,s,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let t;try{t=Et(h)}catch(t){return void It(e,s,"Invalid Sec-WebSocket-Extensions header")}const r=Object.keys(t);if(1!==r.length||r[0]!==ct.extensionName){return void It(e,s,"Server indicated an extension that was not requested")}try{u.accept(t[ct.extensionName])}catch(t){return void It(e,s,"Invalid Sec-WebSocket-Extensions header")}e._extensions[ct.extensionName]=u}e.setSocket(s,r,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})})),i.finishRequest?i.finishRequest(_,e):_.end()}function Bt(e,t){e._readyState=Nt.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function Rt(e){return e.path=e.socketPath,rt.connect(e)}function Ut(e){return e.path=void 0,e.servername||""===e.servername||(e.servername=rt.isIP(e.host)?"":e.host),it.connect(e)}function It(e,t,s){e._readyState=Nt.CLOSING;const r=new Error(s);Error.captureStackTrace(r,It),t.setHeader?(t[xt]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(Bt,e,r)):(t.destroy(r),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function Dt(e,t,s){if(t){const s=dt(t)?t.size:kt(t).length;e._socket?e._sender._bufferedBytes+=s:e._bufferedAmount+=s}if(s){const t=new Error(`WebSocket is not open: readyState ${e.readyState} (${Ot[e.readyState]})`);process.nextTick(s,t)}}function Wt(e,t){const s=this[yt];s._closeFrameReceived=!0,s._closeMessage=t,s._closeCode=e,void 0!==s._socket[yt]&&(s._socket.removeListener("data",Yt),process.nextTick(Vt,s._socket),1005===e?s.close():s.close(e,t))}function Mt(){const e=this[yt];e.isPaused||e._socket.resume()}function At(e){const t=this[yt];void 0!==t._socket[yt]&&(t._socket.removeListener("data",Yt),process.nextTick(Vt,t._socket),t.close(e[vt])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function Ft(){this[yt].emitClose()}function jt(e,t){this[yt].emit("message",e,t)}function $t(e){const t=this[yt];t._autoPong&&t.pong(e,!this._isServer,bt),t.emit("ping",e)}function Gt(e){this[yt].emit("pong",e)}function Vt(e){e.resume()}function qt(e){const t=this[yt];t.readyState!==Nt.CLOSED&&(t.readyState===Nt.OPEN&&(t._readyState=Nt.CLOSING,zt(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function zt(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),3e4)}function Ht(){const e=this[yt];let t;this.removeListener("close",Ht),this.removeListener("data",Yt),this.removeListener("end",Xt),e._readyState=Nt.CLOSING,this._readableState.endEmitted||e._closeFrameReceived||e._receiver._writableState.errorEmitted||null===(t=e._socket.read())||e._receiver.write(t),e._receiver.end(),this[yt]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",Ft),e._receiver.on("finish",Ft))}function Yt(e){this[yt]._receiver.write(e)||this.pause()}function Xt(){const e=this[yt];e._readyState=Nt.CLOSING,e._receiver.end(),this.end()}function Kt(){const e=this[yt];this.removeListener("error",Kt),this.on("error",bt),e&&(e._readyState=Nt.CLOSING,this.destroy())}e(Lt);const{Duplex:Zt}=a;function Jt(e){e.emit("close")}function Qt(){!this.destroyed&&this._writableState.finished&&this.destroy()}function es(e){this.removeListener("error",es),this.destroy(),0===this.listenerCount("error")&&this.emit("error",e)}var ts=function(e,t){let s=!0;const r=new Zt({...t,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return e.on("message",(function(t,s){const i=!s&&r._readableState.objectMode?t.toString():t;r.push(i)||e.pause()})),e.once("error",(function(e){r.destroyed||(s=!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(Jt,r);let o=!1;e.once("error",(function(e){o=!0,i(e)})),e.once("close",(function(){o||i(t),process.nextTick(Jt,r)})),s&&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,s,i){e.readyState!==e.CONNECTING?e.send(t,i):e.once("open",(function(){r._write(t,s,i)}))},r.on("end",Qt),r.on("error",es),r};e(ts);const{tokenChars:ss}=se;var rs={parse:function(e){const t=new Set;let s=-1,r=-1,i=0;for(;i<e.length;i++){const o=e.charCodeAt(i);if(-1===r&&1===ss[o])-1===s&&(s=i);else if(0===i||32!==o&&9!==o){if(44!==o)throw new SyntaxError(`Unexpected character at index ${i}`);{if(-1===s)throw new SyntaxError(`Unexpected character at index ${i}`);-1===r&&(r=i);const o=e.slice(s,r);if(t.has(o))throw new SyntaxError(`The "${o}" subprotocol is duplicated`);t.add(o),s=r=-1}}else-1===r&&-1!==s&&(r=i)}if(-1===s||-1!==r)throw new SyntaxError("Unexpected end of input");const o=e.slice(s,i);if(t.has(o))throw new SyntaxError(`The "${o}" subprotocol is duplicated`);return t.add(o),t}};e(rs);const is=t,os=r,{createHash:ns}=n,as=Qe,cs=Y,hs=rs,ls=Lt,{GUID:ds,kWebSocket:fs}=v,us=/^[+/0-9A-Za-z]{22}==$/;var _s=class extends is{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:ls,...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=os.createServer(((e,t)=>{const s=os.STATUS_CODES[426];t.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"}),t.end(s)})),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 s of Object.keys(t))e.on(s,t[s]);return function(){for(const s of Object.keys(t))e.removeListener(s,t[s])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,s,r)=>{this.handleUpgrade(t,s,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(ps,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(ps,this);else{const e=this._server;this._removeListeners(),this._removeListeners=this._server=null,e.close((()=>{ps(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,s,r){t.on("error",ms);const i=e.headers["sec-websocket-key"],o=e.headers.upgrade,n=+e.headers["sec-websocket-version"];if("GET"!==e.method){return void ys(this,e,t,405,"Invalid HTTP method")}if(void 0===o||"websocket"!==o.toLowerCase()){return void ys(this,e,t,400,"Invalid Upgrade header")}if(void 0===i||!us.test(i)){return void ys(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header")}if(8!==n&&13!==n){return void ys(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header")}if(!this.shouldHandle(e))return void vs(t,400);const a=e.headers["sec-websocket-protocol"];let c=new Set;if(void 0!==a)try{c=hs.parse(a)}catch(s){return void ys(this,e,t,400,"Invalid Sec-WebSocket-Protocol header")}const h=e.headers["sec-websocket-extensions"],l={};if(this.options.perMessageDeflate&&void 0!==h){const s=new cs(this.options.perMessageDeflate,!0,this.options.maxPayload);try{const e=as.parse(h);e[cs.extensionName]&&(s.accept(e[cs.extensionName]),l[cs.extensionName]=s)}catch(s){return void ys(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const o={origin:e.headers[""+(8===n?"sec-websocket-origin":"origin")],secure:!(!e.socket.authorized&&!e.socket.encrypted),req:e};if(2===this.options.verifyClient.length)return void this.options.verifyClient(o,((o,n,a,h)=>{if(!o)return vs(t,n||401,a,h);this.completeUpgrade(l,i,c,e,t,s,r)}));if(!this.options.verifyClient(o))return vs(t,401)}this.completeUpgrade(l,i,c,e,t,s,r)}completeUpgrade(e,t,s,r,i,o,n){if(!i.readable||!i.writable)return i.destroy();if(i[fs])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return vs(i,503);const a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${ns("sha1").update(t+ds).digest("base64")}`],c=new this.options.WebSocket(null,void 0,this.options);if(s.size){const e=this.options.handleProtocols?this.options.handleProtocols(s,r):s.values().next().value;e&&(a.push(`Sec-WebSocket-Protocol: ${e}`),c._protocol=e)}if(e[cs.extensionName]){const t=e[cs.extensionName].params,s=as.format({[cs.extensionName]:[t]});a.push(`Sec-WebSocket-Extensions: ${s}`),c._extensions=e}this.emit("headers",a,r),i.write(a.concat("\r\n").join("\r\n")),i.removeListener("error",ms),c.setSocket(i,o,{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(ps,this)}))),n(c,r)}};function ps(e){e._state=2,e.emit("close")}function ms(){this.destroy()}function vs(e,t,s,r){s=s||os.STATUS_CODES[t],r={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(s),...r},e.once("finish",e.destroy),e.end(`HTTP/1.1 ${t} ${os.STATUS_CODES[t]}\r\n`+Object.keys(r).map((e=>`${e}: ${r[e]}`)).join("\r\n")+"\r\n\r\n"+s)}function ys(e,t,s,r,i){if(e.listenerCount("wsClientError")){const r=new Error(i);Error.captureStackTrace(r,ys),e.emit("wsClientError",r,s,t)}else vs(s,r,i)}e(_s);const bs=Lt;bs.createWebSocketStream=ts,bs.Server=_s,bs.Receiver=pe,bs.Sender=Pe,bs.WebSocket=bs,bs.WebSocketServer=bs.Server;var gs=bs;e(gs);var Ss="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{WebSocket:null};Ss.WebSocket||(Ss.WebSocket=gs.WebSocket);