-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathnode.js
More file actions
1 lines (1 loc) · 67.6 KB
/
node.js
File metadata and controls
1 lines (1 loc) · 67.6 KB
1
import e from"events";import t from"https";import r from"http";import s from"net";import o from"tls";import n from"crypto";import i from"stream";import a from"url";import c from"zlib";import h from"fs";import l from"path";import f from"os";import u from"buffer";import d from"util";var p="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function _(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}!function(){function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function r(e,r,s){return r&&t(e.prototype,r),s&&t(e,s),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&n(e,t)}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return a(e)}function h(e){var t=i();return function(){var r,s=o(e);if(t){var n=o(this).constructor;r=Reflect.construct(s,arguments,n)}else r=s.apply(this,arguments);return c(this,r)}}function l(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=o(e)););return e}function f(){return f="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var s=l(e,t);if(s){var o=Object.getOwnPropertyDescriptor(s,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},f.apply(this,arguments)}function u(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,s=new Array(t);r<t;r++)s[r]=e[r];return s}function _(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=u(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var s=0,o=function(){};return{s:o,n:function(){return s>=e.length?{done:!0}:{done:!1,value:e[s++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var n,i=!0,a=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){a=!0,n=e},f:function(){try{i||null==r.return||r.return()}finally{if(a)throw n}}}}var y=function(){function t(){e(this,t),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return r(t,[{key:"addEventListener",value:function(e,t,r){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:r})}},{key:"removeEventListener",value:function(e,t){if(e in this.listeners)for(var r=this.listeners[e],s=0,o=r.length;s<o;s++)if(r[s].callback===t)return void r.splice(s,1)}},{key:"dispatchEvent",value:function(e){if(e.type in this.listeners){for(var t=this.listeners[e.type].slice(),r=0,s=t.length;r<s;r++){var o=t[r];try{o.callback.call(this,e)}catch(e){Promise.resolve().then((function(){throw e}))}o.options&&o.options.once&&this.removeEventListener(e.type,o.callback)}return!e.defaultPrevented}}}]),t}(),m=function(t){s(i,t);var n=h(i);function i(){var t;return e(this,i),(t=n.call(this)).listeners||y.call(a(t)),Object.defineProperty(a(t),"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(a(t),"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(a(t),"reason",{value:void 0,writable:!0,configurable:!0}),t}return r(i,[{key:"toString",value:function(){return"[object AbortSignal]"}},{key:"dispatchEvent",value:function(e){"abort"===e.type&&(this.aborted=!0,"function"==typeof this.onabort&&this.onabort.call(this,e)),f(o(i.prototype),"dispatchEvent",this).call(this,e)}},{key:"throwIfAborted",value:function(){var e=this.aborted,t=this.reason;if(e)throw void 0===t?"Aborted":t}}],[{key:"timeout",value:function(e){var t=new b;return setTimeout((function(){return t.abort(new DOMException("This signal is timeout in ".concat(e,"ms"),"TimeoutError"))}),e),t.signal}},{key:"any",value:function(e){var t=new b;function r(){t.abort(this.reason),s()}function s(){var t,s=_(e);try{for(s.s();!(t=s.n()).done;)t.value.removeEventListener("abort",r)}catch(e){s.e(e)}finally{s.f()}}var o,n=_(e);try{for(n.s();!(o=n.n()).done;){var i=o.value;if(i.aborted){t.abort(i.reason);break}i.addEventListener("abort",r)}}catch(e){n.e(e)}finally{n.f()}return t.signal}}]),i}(y),b=function(){function t(){e(this,t),Object.defineProperty(this,"signal",{value:new m,writable:!0,configurable:!0})}return r(t,[{key:"abort",value:function(e){var t;try{t=new Event("abort")}catch(e){"undefined"!=typeof document?document.createEvent?(t=document.createEvent("Event")).initEvent("abort",!1,!1):(t=document.createEventObject()).type="abort":t={type:"abort",bubbles:!1,cancelable:!1}}var r=e;if(void 0===r)if("undefined"==typeof document)(r=new Error("This operation was aborted")).name="AbortError";else try{(r=new DOMException("signal is aborted without reason")).name="AbortError"}catch(e){(r=new Error("This operation was aborted")).name="AbortError"}this.signal.reason=r,this.signal.dispatchEvent(t)}},{key:"toString",value:function(){return"[object AbortController]"}}]),t}();function v(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):"function"==typeof e.Request&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function g(e){"function"==typeof e&&(e={fetch:e});var t=e,r=t.fetch,s=t.Request,o=void 0===s?r.Request:s,n=t.AbortController,i=t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,a=void 0!==i&&i;if(!v({fetch:r,Request:o,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:a}))return{fetch:r,Request:c};var c=o;(c&&!c.prototype.hasOwnProperty("signal")||a)&&((c=function(e,t){var r;t&&t.signal&&(r=t.signal,delete t.signal);var s=new o(e,t);return r&&Object.defineProperty(s,"signal",{writable:!1,enumerable:!1,configurable:!0,value:r}),s}).prototype=o.prototype);var h=r;return{fetch:function(e,t){var r=c&&c.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(r){var s;try{s=new DOMException("Aborted","AbortError")}catch(e){(s=new Error("Aborted")).name="AbortError"}if(r.aborted)return Promise.reject(s);var o=new Promise((function(e,t){r.addEventListener("abort",(function(){return t(s)}),{once:!0})}));return t&&t.signal&&delete t.signal,Promise.race([o,h(e,t)])}return h(e,t)},Request:c}}"undefined"!=typeof Symbol&&Symbol.toStringTag&&(b.prototype[Symbol.toStringTag]="AbortController",m.prototype[Symbol.toStringTag]="AbortSignal"),function(e){if(v(e))if(e.fetch){var t=g(e),r=t.fetch,s=t.Request;e.fetch=r,e.Request=s,Object.defineProperty(e,"AbortController",{writable:!0,enumerable:!1,configurable:!0,value:b}),Object.defineProperty(e,"AbortSignal",{writable:!0,enumerable:!1,configurable:!0,value:m})}else console.warn("fetch() is not available, cannot install abortcontroller-polyfill")}("undefined"!=typeof self?self:p)}();var y="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},m="URLSearchParams"in y,b="Symbol"in y&&"iterator"in Symbol,v="FileReader"in y&&"Blob"in y&&function(){try{return new Blob,!0}catch(e){return!1}}(),g="FormData"in y,w="ArrayBuffer"in y;if(w)var E=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],S=ArrayBuffer.isView||function(e){return e&&E.indexOf(Object.prototype.toString.call(e))>-1};function k(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function x(e){return"string"!=typeof e&&(e=String(e)),e}function T(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return b&&(t[Symbol.iterator]=function(){return t}),t}function O(e){this.map={},e instanceof O?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){if(2!=e.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+e.length);this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function C(e){if(!e._noBody)return e.bodyUsed?Promise.reject(new TypeError("Already read")):void(e.bodyUsed=!0)}function P(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function L(e){var t=new FileReader,r=P(t);return t.readAsArrayBuffer(e),r}function B(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function R(){return this.bodyUsed=!1,this._initBody=function(e){var t;this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:v&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:g&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:m&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():w&&v&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=B(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):w&&(ArrayBuffer.prototype.isPrototypeOf(e)||S(e))?this._bodyArrayBuffer=B(e):this._bodyText=e=Object.prototype.toString.call(e):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):m&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},v&&(this.blob=function(){var e=C(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=C(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}if(v)return this.blob().then(L);throw new Error("could not read as ArrayBuffer")},this.text=function(){var e,t,r,s,o,n=C(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=P(t),s=/charset=([A-Za-z0-9_-]+)/.exec(e.type),o=s?s[1]:"utf-8",t.readAsText(e,o),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),s=0;s<t.length;s++)r[s]=String.fromCharCode(t[s]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},g&&(this.formData=function(){return this.text().then(U)}),this.json=function(){return this.text().then(JSON.parse)},this}O.prototype.append=function(e,t){e=k(e),t=x(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},O.prototype.delete=function(e){delete this.map[k(e)]},O.prototype.get=function(e){return e=k(e),this.has(e)?this.map[e]:null},O.prototype.has=function(e){return this.map.hasOwnProperty(k(e))},O.prototype.set=function(e,t){this.map[k(e)]=x(t)},O.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},O.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),T(e)},O.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),T(e)},O.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),T(e)},b&&(O.prototype[Symbol.iterator]=O.prototype.entries);var N=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function A(e,t){if(!(this instanceof A))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,s,o=(t=t||{}).body;if(e instanceof A){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new O(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new O(t.headers)),this.method=(r=t.method||this.method||"GET",s=r.toUpperCase(),N.indexOf(s)>-1?s:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal||function(){if("AbortController"in y)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(o),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var n=/([?&])_=[^&]*/;if(n.test(this.url))this.url=this.url.replace(n,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function U(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),s=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(s),decodeURIComponent(o))}})),t}function I(e,t){if(!(this instanceof I))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new O(t.headers),this.url=t.url||"",this._initBody(e)}A.prototype.clone=function(){return new A(this,{body:this._bodyInit})},R.call(A.prototype),R.call(I.prototype),I.prototype.clone=function(){return new I(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new O(this.headers),url:this.url})},I.error=function(){var e=new I(null,{status:200,statusText:""});return e.ok=!1,e.status=0,e.type="error",e};var j=[301,302,303,307,308];I.redirect=function(e,t){if(-1===j.indexOf(t))throw new RangeError("Invalid status code");return new I(null,{status:t,headers:{location:e}})};var D=y.DOMException;try{new D}catch(e){(D=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack}).prototype=Object.create(Error.prototype),D.prototype.constructor=D}function F(e,t){return new Promise((function(r,s){var o=new A(e,t);if(o.signal&&o.signal.aborted)return s(new D("Aborted","AbortError"));var n=new XMLHttpRequest;function i(){n.abort()}if(n.onload=function(){var e,t,s={statusText:n.statusText,headers:(e=n.getAllResponseHeaders()||"",t=new O,e.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e})).forEach((function(e){var r=e.split(":"),s=r.shift().trim();if(s){var o=r.join(":").trim();try{t.append(s,o)}catch(e){console.warn("Response "+e.message)}}})),t)};0===o.url.indexOf("file://")&&(n.status<200||n.status>599)?s.status=200:s.status=n.status,s.url="responseURL"in n?n.responseURL:s.headers.get("X-Request-URL");var i="response"in n?n.response:n.responseText;setTimeout((function(){r(new I(i,s))}),0)},n.onerror=function(){setTimeout((function(){s(new TypeError("Network request failed"))}),0)},n.ontimeout=function(){setTimeout((function(){s(new TypeError("Network request timed out"))}),0)},n.onabort=function(){setTimeout((function(){s(new D("Aborted","AbortError"))}),0)},n.open(o.method,function(e){try{return""===e&&y.location.href?y.location.href:e}catch(t){return e}}(o.url),!0),"include"===o.credentials?n.withCredentials=!0:"omit"===o.credentials&&(n.withCredentials=!1),"responseType"in n&&(v?n.responseType="blob":w&&(n.responseType="arraybuffer")),t&&"object"==typeof t.headers&&!(t.headers instanceof O||y.Headers&&t.headers instanceof y.Headers)){var a=[];Object.getOwnPropertyNames(t.headers).forEach((function(e){a.push(k(e)),n.setRequestHeader(e,x(t.headers[e]))})),o.headers.forEach((function(e,t){-1===a.indexOf(t)&&n.setRequestHeader(t,e)}))}else o.headers.forEach((function(e,t){n.setRequestHeader(t,e)}));o.signal&&(o.signal.addEventListener("abort",i),n.onreadystatechange=function(){4===n.readyState&&o.signal.removeEventListener("abort",i)}),n.send(void 0===o._bodyInit?null:o._bodyInit)}))}F.polyfill=!0,y.fetch||(y.fetch=F,y.Headers=O,y.Request=A,y.Response=I);var M="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{fetch:null};M.fetch||(M.fetch=F);var W={exports:{}};const q=["nodebuffer","arraybuffer","fragments"],$="undefined"!=typeof Blob;$&&q.push("blob");var G={BINARY_TYPES:q,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:$,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}};_(G);var V={exports:{}};function H(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 z,Y,X,K,Z,J,Q={exports:{}};function ee(){if(X)return Q.exports;X=1;const e="function"==typeof __webpack_require__?__non_webpack_require__:H;return"function"==typeof e.addon?Q.exports=e.addon.bind(e):Q.exports=function(){if(Y)return z;Y=1;var e=h,t=l,r=f,s="function"==typeof __webpack_require__?__non_webpack_require__:H,o=process.config&&process.config.variables||{},n=!!process.env.PREBUILDS_ONLY,i=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||r.arch(),u=process.env.npm_config_platform||r.platform(),d=process.env.LIBC||(function(t){return"linux"===t&&e.existsSync("/etc/alpine-release")}(u)?"musl":"glibc"),p=process.env.ARM_VERSION||("arm64"===c?"8":o.arm_version)||"",_=(process.versions.uv||"").split(".")[0];function y(e){return s(y.resolve(e))}function m(t){try{return e.readdirSync(t)}catch(e){return[]}}function b(e,r){var s=m(e).filter(r);return s[0]&&t.join(e,s[0])}function v(e){return/\.node$/.test(e)}function g(e){var t=e.split("-");if(2===t.length){var r=t[0],s=t[1].split("+");if(r&&s.length&&s.every(Boolean))return{name:e,platform:r,architectures:s}}}function w(e,t){return function(r){return null!=r&&r.platform===e&&r.architectures.includes(t)}}function E(e,t){return e.architectures.length-t.architectures.length}function S(e){var t=e.split("."),r={file:e,specificity:0};if("node"===t.pop()){for(var s=0;s<t.length;s++){var o=t[s];if("node"===o||"electron"===o||"node-webkit"===o)r.runtime=o;else if("napi"===o)r.napi=!0;else if("abi"===o.slice(0,3))r.abi=o.slice(3);else if("uv"===o.slice(0,2))r.uv=o.slice(2);else if("armv"===o.slice(0,4))r.armv=o.slice(4);else{if("glibc"!==o&&"musl"!==o)continue;r.libc=o}r.specificity++}return r}}function k(e,t){return function(r){return!(null==r||r.runtime&&r.runtime!==e&&!function(e){return"node"===e.runtime&&e.napi}(r)||r.abi&&r.abi!==t&&!r.napi||r.uv&&r.uv!==_||r.armv&&r.armv!==p||r.libc&&r.libc!==d)}}function x(e){return function(t,r){return t.runtime!==r.runtime?t.runtime===e?-1:1:t.abi!==r.abi?t.abi?-1:1:t.specificity!==r.specificity?t.specificity>r.specificity?-1:1:0}}return z=y,y.resolve=y.path=function(e){e=t.resolve(e||".");try{var r=s(t.join(e,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[r+"_PREBUILD"]&&(e=process.env[r+"_PREBUILD"])}catch(e){}if(!n){var o=b(t.join(e,"build/Release"),v);if(o)return o;var h=b(t.join(e,"build/Debug"),v);if(h)return h}var l=T(e);if(l)return l;var f=T(t.dirname(process.execPath));if(f)return f;var y=["platform="+u,"arch="+c,"runtime="+a,"abi="+i,"uv="+_,p?"armv="+p:"","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 "+y+"\n loaded from: "+e+"\n");function T(e){var r=m(t.join(e,"prebuilds")).map(g).filter(w(u,c)).sort(E)[0];if(r){var s=t.join(e,"prebuilds",r.name),o=m(s).map(S).filter(k(a,i)).sort(x(a))[0];return o?t.join(s,o.file):void 0}}},y.parseTags=S,y.matchTags=k,y.compareTags=x,y.parseTuple=g,y.matchTuple=w,y.compareTuples=E,z}(),Q.exports}const{EMPTY_BUFFER:te}=G,re=Buffer[Symbol.species];function se(e,t,r,s,o){for(let n=0;n<o;n++)r[s+n]=e[n]^t[3&n]}function oe(e,t){for(let r=0;r<e.length;r++)e[r]^=t[3&r]}if(W.exports={concat:function(e,t){if(0===e.length)return te;if(1===e.length)return e[0];const r=Buffer.allocUnsafe(t);let s=0;for(let t=0;t<e.length;t++){const o=e[t];r.set(o,s),s+=o.length}return s<t?new re(r.buffer,r.byteOffset,s):r},mask:se,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 r;return t instanceof ArrayBuffer?r=new re(t):ArrayBuffer.isView(t)?r=new re(t.buffer,t.byteOffset,t.byteLength):(r=Buffer.from(t),e.readOnly=!1),r},unmask:oe},!process.env.WS_NO_BUFFER_UTIL)try{const e=function(){if(J)return V.exports;J=1;try{V.exports=ee()(__dirname)}catch(e){V.exports=(Z||(Z=1,K={mask:(e,t,r,s,o)=>{for(var n=0;n<o;n++)r[s+n]=e[n]^t[3&n]},unmask:(e,t)=>{const r=e.length;for(var s=0;s<r;s++)e[s]^=t[3&s]}}),K)}return V.exports}();W.exports.mask=function(t,r,s,o,n){n<48?se(t,r,s,o,n):e.mask(t,r,s,o,n)},W.exports.unmask=function(t,r){t.length<32?oe(t,r):e.unmask(t,r)}}catch(e){}var ne=W.exports;_(ne);const ie=Symbol("kDone"),ae=Symbol("kRun");var ce=class{constructor(e){this[ie]=()=>{this.pending--,this[ae]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[ae]()}[ae](){if(this.pending!==this.concurrency&&this.jobs.length){const e=this.jobs.shift();this.pending++,e(this[ie])}}};_(ce);const he=c,le=ne,fe=ce,{kStatusCode:ue}=G,de=Buffer[Symbol.species],pe=Buffer.from([0,0,255,255]),_e=Symbol("permessage-deflate"),ye=Symbol("total-length"),me=Symbol("callback"),be=Symbol("buffers"),ve=Symbol("error");let ge;var we=class{constructor(e){if(this._options=e||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._maxPayload=0|this._options.maxPayload,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!ge){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;ge=new fe(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[me];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,r=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(!r)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(r.server_no_context_takeover=!0),t.clientNoContextTakeover&&(r.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(r.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?r.client_max_window_bits=t.clientMaxWindowBits:!0!==r.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete r.client_max_window_bits,r}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 r=e[t];if(r.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(r=r[0],"client_max_window_bits"===t){if(!0!==r){const e=+r;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${r}`);r=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${r}`)}else if("server_max_window_bits"===t){const e=+r;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${r}`);r=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==r)throw new TypeError(`Invalid value for parameter "${t}": ${r}`)}e[t]=r}))})),e}decompress(e,t,r){ge.add((s=>{this._decompress(e,t,((e,t)=>{s(),r(e,t)}))}))}compress(e,t,r){ge.add((s=>{this._compress(e,t,((e,t)=>{s(),r(e,t)}))}))}_decompress(e,t,r){const s=this._isServer?"client":"server";if(!this._inflate){const e=`${s}_max_window_bits`,t="number"!=typeof this.params[e]?he.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=he.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t}),this._inflate[_e]=this,this._inflate[ye]=0,this._inflate[be]=[],this._inflate.on("error",ke),this._inflate.on("data",Se)}this._inflate[me]=r,this._inflate.write(e),t&&this._inflate.write(pe),this._inflate.flush((()=>{const e=this._inflate[ve];if(e)return this._inflate.close(),this._inflate=null,void r(e);const o=le.concat(this._inflate[be],this._inflate[ye]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[ye]=0,this._inflate[be]=[],t&&this.params[`${s}_no_context_takeover`]&&this._inflate.reset()),r(null,o)}))}_compress(e,t,r){const s=this._isServer?"server":"client";if(!this._deflate){const e=`${s}_max_window_bits`,t="number"!=typeof this.params[e]?he.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=he.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t}),this._deflate[ye]=0,this._deflate[be]=[],this._deflate.on("data",Ee)}this._deflate[me]=r,this._deflate.write(e),this._deflate.flush(he.Z_SYNC_FLUSH,(()=>{if(!this._deflate)return;let e=le.concat(this._deflate[be],this._deflate[ye]);t&&(e=new de(e.buffer,e.byteOffset,e.length-4)),this._deflate[me]=null,this._deflate[ye]=0,this._deflate[be]=[],t&&this.params[`${s}_no_context_takeover`]&&this._deflate.reset(),r(null,e)}))}};function Ee(e){this[be].push(e),this[ye]+=e.length}function Se(e){this[ye]+=e.length,this[_e]._maxPayload<1||this[ye]<=this[_e]._maxPayload?this[be].push(e):(this[ve]=new RangeError("Max payload size exceeded"),this[ve].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[ve][ue]=1009,this.removeListener("data",Se),this.reset())}function ke(e){this[_e]._inflate=null,this[ve]?this[me](this[ve]):(e[ue]=1007,this[me](e))}_(we);var xe={exports:{}};const{isUtf8:Te}=u,{hasBlob:Oe}=G;function Ce(e){const t=e.length;let r=0;for(;r<t;)if(128&e[r])if(192==(224&e[r])){if(r+1===t||128!=(192&e[r+1])||192==(254&e[r]))return!1;r+=2}else if(224==(240&e[r])){if(r+2>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||224===e[r]&&128==(224&e[r+1])||237===e[r]&&160==(224&e[r+1]))return!1;r+=3}else{if(240!=(248&e[r]))return!1;if(r+3>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||128!=(192&e[r+3])||240===e[r]&&128==(240&e[r+1])||244===e[r]&&e[r+1]>143||e[r]>244)return!1;r+=4}else r++;return!0}if(xe.exports={isBlob:function(e){return Oe&&"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:Ce,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]},Te)xe.exports.isValidUTF8=function(e){return e.length<24?Ce(e):Te(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const e=require("utf-8-validate");xe.exports.isValidUTF8=function(t){return t.length<32?Ce(t):e(t)}}catch(e){}var Pe=xe.exports;_(Pe);const{Writable:Le}=i,Be=we,{BINARY_TYPES:Re,EMPTY_BUFFER:Ne,kStatusCode:Ae,kWebSocket:Ue}=G,{concat:Ie,toArrayBuffer:je,unmask:De}=ne,{isValidStatusCode:Fe,isValidUTF8:Me}=Pe,We=Buffer[Symbol.species];var qe=class extends Le{constructor(e={}){super(),this._allowSynchronousEvents=void 0===e.allowSynchronousEvents||e.allowSynchronousEvents,this._binaryType=e.binaryType||Re[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=0|e.maxBufferedChunks,this._maxFragments=0|e.maxFragments,this._maxPayload=0|e.maxPayload,this._skipUTF8Validation=!!e.skipUTF8Validation,this[Ue]=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,r){if(8===this._opcode&&0==this._state)return r();this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks?r(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS")):(this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r))}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 We(t.buffer,t.byteOffset+e,t.length-e),new We(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const r=this._buffers[0],s=t.length-e;e>=r.length?t.set(this._buffers.shift(),s):(t.set(new Uint8Array(r.buffer,r.byteOffset,e),s),this._buffers[0]=new We(r.buffer,r.byteOffset+e,r.length-e)),e-=r.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 r=!(64&~t[0]);if(!r||this._extensions[Be.extensionName]){if(this._fin=!(128&~t[0]),this._opcode=15&t[0],this._payloadLength=127&t[1],0===this._opcode){if(r){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=r}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(r){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),r=t.readUInt32BE(0);if(r>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=r*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);if(t.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){return void e(this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"))}this._messageLength=this._totalPayloadLength,this._fragments.push(t)}this.dataMessage(e)}}decompress(e,t){this._extensions[Be.extensionName].decompress(e,this._fin,((e,r)=>{if(e)return t(e);if(r.length){if(this._messageLength+=r.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)}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){const e=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");return void t(e)}this._fragments.push(r)}this.dataMessage(t),0===this._state&&this.startLoop(t)}))}dataMessage(e){if(!this._fin)return void(this._state=0);const t=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],2===this._opcode){let s;s="nodebuffer"===this._binaryType?Ie(r,t):"arraybuffer"===this._binaryType?je(Ie(r,t)):"blob"===this._binaryType?new Blob(r):r,this._allowSynchronousEvents?(this.emit("message",s,!0),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",s,!0),this._state=0,this.startLoop(e)})))}else{const s=Ie(r,t);if(!this._skipUTF8Validation&&!Me(s)){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",s,!1),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",s,!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 r=e.readUInt16BE(0);if(!Fe(r)){const e=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void t(e)}const s=new We(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Me(s)){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",r,s),this.end()}this._state=0}}createError(e,t,r,s,o){this._loop=!1,this._errored=!0;const n=new e(r?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(n,this.createError),n.code=o,n[Ae]=s,n}};_(qe);const{randomFillSync:$e}=n,{types:{isUint8Array:Ge}}=d,Ve=we,{EMPTY_BUFFER:He,kWebSocket:ze,NOOP:Ye}=G,{isBlob:Xe,isValidStatusCode:Ke}=Pe,{mask:Ze,toBuffer:Je}=ne,Qe=Symbol("kByteLength"),et=Buffer.alloc(4),tt=8192;let rt,st=tt;class ot{constructor(e,t,r){this._extensions=t||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=0,this.onerror=Ye,this[ze]=void 0}static frame(e,t){let r,s,o=!1,n=2,i=!1;t.mask&&(r=t.maskBuffer||et,t.generateMask?t.generateMask(r):(st===tt&&(void 0===rt&&(rt=Buffer.alloc(tt)),$e(rt,0,tt),st=0),r[0]=rt[st++],r[1]=rt[st++],r[2]=rt[st++],r[3]=rt[st++]),i=!(r[0]|r[1]|r[2]|r[3]),n=6),"string"==typeof e?s=t.mask&&!i||void 0===t[Qe]?(e=Buffer.from(e)).length:t[Qe]:(s=e.length,o=t.mask&&t.readOnly&&!i);let a=s;s>=65536?(n+=8,a=127):s>125&&(n+=2,a=126);const c=Buffer.allocUnsafe(o?s+n:n);return c[0]=t.fin?128|t.opcode:t.opcode,t.rsv1&&(c[0]|=64),c[1]=a,126===a?c.writeUInt16BE(s,2):127===a&&(c[2]=c[3]=0,c.writeUIntBE(s,4,6)),t.mask?(c[1]|=128,c[n-4]=r[0],c[n-3]=r[1],c[n-2]=r[2],c[n-1]=r[3],i?[c,e]:o?(Ze(e,r,c,n,s),[c]):(Ze(e,r,e,0,s),[c,e])):[c,e]}close(e,t,r,s){let o;if(void 0===e)o=He;else{if("number"!=typeof e||!Ke(e))throw new TypeError("First argument must be a valid error code number");if(void 0!==t&&t.length){const r=Buffer.byteLength(t);if(r>123)throw new RangeError("The message must not be greater than 123 bytes");if(o=Buffer.allocUnsafe(2+r),o.writeUInt16BE(e,0),"string"==typeof t)o.write(t,2);else{if(!Ge(t))throw new TypeError("Second argument must be a string or a Uint8Array");o.set(t,2)}}else o=Buffer.allocUnsafe(2),o.writeUInt16BE(e,0)}const n={[Qe]:o.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};0!==this._state?this.enqueue([this.dispatch,o,!1,n,s]):this.sendFrame(ot.frame(o,n),s)}ping(e,t,r){let s,o;if("string"==typeof e?(s=Buffer.byteLength(e),o=!1):Xe(e)?(s=e.size,o=!1):(s=(e=Je(e)).length,o=Je.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");const n={[Qe]:s,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:9,readOnly:o,rsv1:!1};Xe(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,n,r]):this.getBlobData(e,!1,n,r):0!==this._state?this.enqueue([this.dispatch,e,!1,n,r]):this.sendFrame(ot.frame(e,n),r)}pong(e,t,r){let s,o;if("string"==typeof e?(s=Buffer.byteLength(e),o=!1):Xe(e)?(s=e.size,o=!1):(s=(e=Je(e)).length,o=Je.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");const n={[Qe]:s,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:10,readOnly:o,rsv1:!1};Xe(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,n,r]):this.getBlobData(e,!1,n,r):0!==this._state?this.enqueue([this.dispatch,e,!1,n,r]):this.sendFrame(ot.frame(e,n),r)}send(e,t,r){const s=this._extensions[Ve.extensionName];let o,n,i=t.binary?2:1,a=t.compress;"string"==typeof e?(o=Buffer.byteLength(e),n=!1):Xe(e)?(o=e.size,n=!1):(o=(e=Je(e)).length,n=Je.readOnly),this._firstFragment?(this._firstFragment=!1,a&&s&&s.params[s._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(a=o>=s._threshold),this._compress=a):(a=!1,i=0),t.fin&&(this._firstFragment=!0);const c={[Qe]:o,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:i,readOnly:n,rsv1:a};Xe(e)?0!==this._state?this.enqueue([this.getBlobData,e,this._compress,c,r]):this.getBlobData(e,this._compress,c,r):0!==this._state?this.enqueue([this.dispatch,e,this._compress,c,r]):this.dispatch(e,this._compress,c,r)}getBlobData(e,t,r,s){this._bufferedBytes+=r[Qe],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(it,this,e,s)}this._bufferedBytes-=r[Qe];const o=Je(e);t?this.dispatch(o,t,r,s):(this._state=0,this.sendFrame(ot.frame(o,r),s),this.dequeue())})).catch((e=>{process.nextTick(at,this,e,s)}))}dispatch(e,t,r,s){if(!t)return void this.sendFrame(ot.frame(e,r),s);const o=this._extensions[Ve.extensionName];this._bufferedBytes+=r[Qe],this._state=1,o.compress(e,r.fin,((e,t)=>{if(this._socket.destroyed){it(this,new Error("The socket was closed while data was being compressed"),s)}else this._bufferedBytes-=r[Qe],this._state=0,r.readOnly=!1,this.sendFrame(ot.frame(t,r),s),this.dequeue()}))}dequeue(){for(;0===this._state&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[3][Qe],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][Qe],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 nt=ot;function it(e,t,r){"function"==typeof r&&r(t);for(let r=0;r<e._queue.length;r++){const s=e._queue[r],o=s[s.length-1];"function"==typeof o&&o(t)}}function at(e,t,r){it(e,t,r),e.onerror(t)}_(nt);const{kForOnEventAttribute:ct,kListener:ht}=G,lt=Symbol("kCode"),ft=Symbol("kData"),ut=Symbol("kError"),dt=Symbol("kMessage"),pt=Symbol("kReason"),_t=Symbol("kTarget"),yt=Symbol("kType"),mt=Symbol("kWasClean");class bt{constructor(e){this[_t]=null,this[yt]=e}get target(){return this[_t]}get type(){return this[yt]}}Object.defineProperty(bt.prototype,"target",{enumerable:!0}),Object.defineProperty(bt.prototype,"type",{enumerable:!0});class vt extends bt{constructor(e,t={}){super(e),this[lt]=void 0===t.code?0:t.code,this[pt]=void 0===t.reason?"":t.reason,this[mt]=void 0!==t.wasClean&&t.wasClean}get code(){return this[lt]}get reason(){return this[pt]}get wasClean(){return this[mt]}}Object.defineProperty(vt.prototype,"code",{enumerable:!0}),Object.defineProperty(vt.prototype,"reason",{enumerable:!0}),Object.defineProperty(vt.prototype,"wasClean",{enumerable:!0});class gt extends bt{constructor(e,t={}){super(e),this[ut]=void 0===t.error?null:t.error,this[dt]=void 0===t.message?"":t.message}get error(){return this[ut]}get message(){return this[dt]}}Object.defineProperty(gt.prototype,"error",{enumerable:!0}),Object.defineProperty(gt.prototype,"message",{enumerable:!0});class wt extends bt{constructor(e,t={}){super(e),this[ft]=void 0===t.data?null:t.data}get data(){return this[ft]}}Object.defineProperty(wt.prototype,"data",{enumerable:!0});const Et={addEventListener(e,t,r={}){for(const s of this.listeners(e))if(!r[ct]&&s[ht]===t&&!s[ct])return;let s;if("message"===e)s=function(e,r){const s=new wt("message",{data:r?e:e.toString()});s[_t]=this,kt(t,this,s)};else if("close"===e)s=function(e,r){const s=new vt("close",{code:e,reason:r.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});s[_t]=this,kt(t,this,s)};else if("error"===e)s=function(e){const r=new gt("error",{error:e,message:e.message});r[_t]=this,kt(t,this,r)};else{if("open"!==e)return;s=function(){const e=new bt("open");e[_t]=this,kt(t,this,e)}}s[ct]=!!r[ct],s[ht]=t,r.once?this.once(e,s):this.on(e,s)},removeEventListener(e,t){for(const r of this.listeners(e))if(r[ht]===t&&!r[ct]){this.removeListener(e,r);break}}};var St={CloseEvent:vt,ErrorEvent:gt,Event:bt,EventTarget:Et,MessageEvent:wt};function kt(e,t,r){"object"==typeof e&&e.handleEvent?e.handleEvent.call(e,r):e.call(t,r)}_(St);const{tokenChars:xt}=Pe;function Tt(e,t,r){void 0===e[t]?e[t]=[r]:e[t].push(r)}var Ot={format:function(e){return Object.keys(e).map((t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map((e=>[t].concat(Object.keys(e).map((t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map((e=>!0===e?t:`${t}=${e}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")},parse:function(e){const t=Object.create(null);let r,s,o=Object.create(null),n=!1,i=!1,a=!1,c=-1,h=-1,l=-1,f=0;for(;f<e.length;f++)if(h=e.charCodeAt(f),void 0===r)if(-1===l&&1===xt[h])-1===c&&(c=f);else if(0===f||32!==h&&9!==h){if(59!==h&&44!==h)throw new SyntaxError(`Unexpected character at index ${f}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${f}`);-1===l&&(l=f);const s=e.slice(c,l);44===h?(Tt(t,s,o),o=Object.create(null)):r=s,c=l=-1}}else-1===l&&-1!==c&&(l=f);else if(void 0===s)if(-1===l&&1===xt[h])-1===c&&(c=f);else if(32===h||9===h)-1===l&&-1!==c&&(l=f);else if(59===h||44===h){if(-1===c)throw new SyntaxError(`Unexpected character at index ${f}`);-1===l&&(l=f),Tt(o,e.slice(c,l),!0),44===h&&(Tt(t,r,o),o=Object.create(null),r=void 0),c=l=-1}else{if(61!==h||-1===c||-1!==l)throw new SyntaxError(`Unexpected character at index ${f}`);s=e.slice(c,f),c=l=-1}else if(i){if(1!==xt[h])throw new SyntaxError(`Unexpected character at index ${f}`);-1===c?c=f:n||(n=!0),i=!1}else if(a)if(1===xt[h])-1===c&&(c=f);else if(34===h&&-1!==c)a=!1,l=f;else{if(92!==h)throw new SyntaxError(`Unexpected character at index ${f}`);i=!0}else if(34===h&&61===e.charCodeAt(f-1))a=!0;else if(-1===l&&1===xt[h])-1===c&&(c=f);else if(-1===c||32!==h&&9!==h){if(59!==h&&44!==h)throw new SyntaxError(`Unexpected character at index ${f}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${f}`);-1===l&&(l=f);let i=e.slice(c,l);n&&(i=i.replace(/\\/g,""),n=!1),Tt(o,s,i),44===h&&(Tt(t,r,o),o=Object.create(null),r=void 0),s=void 0,c=l=-1}}else-1===l&&(l=f);if(-1===c||a||32===h||9===h)throw new SyntaxError("Unexpected end of input");-1===l&&(l=f);const u=e.slice(c,l);return void 0===r?Tt(t,u,o):(void 0===s?Tt(o,u,!0):Tt(o,s,n?u.replace(/\\/g,""):u),Tt(t,r,o)),t}};_(Ot);const Ct=e,Pt=t,Lt=r,Bt=s,Rt=o,{randomBytes:Nt,createHash:At}=n,{URL:Ut}=a,It=we,jt=qe,Dt=nt,{isBlob:Ft}=Pe,{BINARY_TYPES:Mt,CLOSE_TIMEOUT:Wt,EMPTY_BUFFER:qt,GUID:$t,kForOnEventAttribute:Gt,kListener:Vt,kStatusCode:Ht,kWebSocket:zt,NOOP:Yt}=G,{EventTarget:{addEventListener:Xt,removeEventListener:Kt}}=St,{format:Zt,parse:Jt}=Ot,{toBuffer:Qt}=ne,er=Symbol("kAborted"),tr=[8,13],rr=["CONNECTING","OPEN","CLOSING","CLOSED"],sr=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;class or extends Ct{constructor(e,t,r){super(),this._binaryType=Mt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=qt,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=or.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?(r=t,t=[]):t=[t]),ir(this,e,t,r)):(this._autoPong=r.autoPong,this._closeTimeout=r.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Mt.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,r){const s=new jt({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:r.maxBufferedChunks,maxFragments:r.maxFragments,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),o=new Dt(e,this._extensions,r.generateMask);this._receiver=s,this._sender=o,this._socket=e,s[zt]=this,o[zt]=this,e[zt]=this,s.on("conclude",ur),s.on("drain",dr),s.on("error",pr),s.on("message",yr),s.on("ping",mr),s.on("pong",br),o.onerror=gr,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),t.length>0&&e.unshift(t),e.on("close",Er),e.on("data",Sr),e.on("end",kr),e.on("error",xr),this._readyState=or.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=or.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[It.extensionName]&&this._extensions[It.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=or.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState!==or.CLOSED)if(this.readyState!==or.CONNECTING)this.readyState!==or.CLOSING?(this._readyState=or.CLOSING,this._sender.close(e,t,!this._isServer,(e=>{e||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())})),wr(this)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();else{const e="WebSocket was closed before the connection was established";lr(this,this._req,e)}}pause(){this.readyState!==or.CONNECTING&&this.readyState!==or.CLOSED&&(this._paused=!0,this._socket.pause())}ping(e,t,r){if(this.readyState===or.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(r=e,e=t=void 0):"function"==typeof t&&(r=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===or.OPEN?(void 0===t&&(t=!this._isServer),this._sender.ping(e||qt,t,r)):fr(this,e,r)}pong(e,t,r){if(this.readyState===or.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(r=e,e=t=void 0):"function"==typeof t&&(r=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===or.OPEN?(void 0===t&&(t=!this._isServer),this._sender.pong(e||qt,t,r)):fr(this,e,r)}resume(){this.readyState!==or.CONNECTING&&this.readyState!==or.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,t,r){if(this.readyState===or.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof t&&(r=t,t={}),"number"==typeof e&&(e=e.toString()),this.readyState!==or.OPEN)return void fr(this,e,r);const s={binary:"string"!=typeof e,mask:!this._isServer,compress:!0,fin:!0,...t};this._extensions[It.extensionName]||(s.compress=!1),this._sender.send(e||qt,s,r)}terminate(){if(this.readyState!==or.CLOSED)if(this.readyState!==or.CONNECTING)this._socket&&(this._readyState=or.CLOSING,this._socket.destroy());else{const e="WebSocket was closed before the connection was established";lr(this,this._req,e)}}}Object.defineProperty(or,"CONNECTING",{enumerable:!0,value:rr.indexOf("CONNECTING")}),Object.defineProperty(or.prototype,"CONNECTING",{enumerable:!0,value:rr.indexOf("CONNECTING")}),Object.defineProperty(or,"OPEN",{enumerable:!0,value:rr.indexOf("OPEN")}),Object.defineProperty(or.prototype,"OPEN",{enumerable:!0,value:rr.indexOf("OPEN")}),Object.defineProperty(or,"CLOSING",{enumerable:!0,value:rr.indexOf("CLOSING")}),Object.defineProperty(or.prototype,"CLOSING",{enumerable:!0,value:rr.indexOf("CLOSING")}),Object.defineProperty(or,"CLOSED",{enumerable:!0,value:rr.indexOf("CLOSED")}),Object.defineProperty(or.prototype,"CLOSED",{enumerable:!0,value:rr.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(or.prototype,e,{enumerable:!0})})),["open","error","close","message"].forEach((e=>{Object.defineProperty(or.prototype,`on${e}`,{enumerable:!0,get(){for(const t of this.listeners(e))if(t[Gt])return t[Vt];return null},set(t){for(const t of this.listeners(e))if(t[Gt]){this.removeListener(e,t);break}"function"==typeof t&&this.addEventListener(e,t,{[Gt]:!0})}})})),or.prototype.addEventListener=Xt,or.prototype.removeEventListener=Kt;var nr=or;function ir(e,t,r,s){const o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Wt,protocolVersion:tr[1],maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...s,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=o.autoPong,e._closeTimeout=o.closeTimeout,!tr.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${tr.join(", ")})`);let n;if(t instanceof Ut)n=t;else try{n=new Ut(t)}catch{throw new SyntaxError(`Invalid URL: ${t}`)}"http:"===n.protocol?n.protocol="ws:":"https:"===n.protocol&&(n.protocol="wss:"),e._url=n.href;const i="wss:"===n.protocol,a="ws+unix:"===n.protocol;let c;if("ws:"===n.protocol||i||a?a&&!n.pathname?c="The URL's pathname is empty":n.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 ar(e,t)}const h=i?443:80,l=Nt(16).toString("base64"),f=i?Pt.request:Lt.request,u=new Set;let d,p;if(o.createConnection=o.createConnection||(i?hr:cr),o.defaultPort=o.defaultPort||h,o.port=n.port||h,o.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":l,Connection:"Upgrade",Upgrade:"websocket"},o.path=n.pathname+n.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(d=new It({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Zt({[It.extensionName]:d.offer()})),r.length){for(const e of r){if("string"!=typeof e||!sr.test(e)||u.has(e))throw new SyntaxError("An invalid or duplicated subprotocol was specified");u.add(e)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(n.username||n.password)&&(o.auth=`${n.username}:${n.password}`),a){const e=o.path.split(":");o.socketPath=e[0],o.path=e[1]}if(o.followRedirects){if(0===e._redirects){e._originalIpc=a,e._originalSecure=i,e._originalHostOrSocketPath=a?o.socketPath:n.host;const t=s&&s.headers;if(s={...s,headers:{}},t)for(const[e,r]of Object.entries(t))s.headers[e.toLowerCase()]=r}else if(0===e.listenerCount("redirect")){const t=a?!!e._originalIpc&&o.socketPath===e._originalHostOrSocketPath:!e._originalIpc&&n.host===e._originalHostOrSocketPath;(!t||e._originalSecure&&!i)&&(delete o.headers.authorization,delete o.headers.cookie,t||delete o.headers.host,o.auth=void 0)}o.auth&&!s.headers.authorization&&(s.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),p=e._req=f(o),e._redirects&&e.emit("redirect",e.url,p)}else p=e._req=f(o);o.timeout&&p.on("timeout",(()=>{lr(e,p,"Opening handshake has timed out")})),p.on("error",(t=>{null===p||p[er]||(p=e._req=null,ar(e,t))})),p.on("response",(n=>{const i=n.headers.location,a=n.statusCode;if(i&&o.followRedirects&&a>=300&&a<400){if(++e._redirects>o.maxRedirects)return void lr(e,p,"Maximum redirects exceeded");let n;p.abort();try{n=new Ut(i,t)}catch(t){const r=new SyntaxError(`Invalid URL: ${i}`);return void ar(e,r)}ir(e,n,r,s)}else e.emit("unexpected-response",p,n)||lr(e,p,`Unexpected server response: ${n.statusCode}`)})),p.on("upgrade",((t,r,s)=>{if(e.emit("upgrade",t),e.readyState!==or.CONNECTING)return;p=e._req=null;const n=t.headers.upgrade;if(void 0===n||"websocket"!==n.toLowerCase())return void lr(e,r,"Invalid Upgrade header");const i=At("sha1").update(l+$t).digest("base64");if(t.headers["sec-websocket-accept"]!==i)return void lr(e,r,"Invalid Sec-WebSocket-Accept header");const a=t.headers["sec-websocket-protocol"];let c;if(void 0!==a?u.size?u.has(a)||(c="Server sent an invalid subprotocol"):c="Server sent a subprotocol but none was requested":u.size&&(c="Server sent no subprotocol"),c)return void lr(e,r,c);a&&(e._protocol=a);const h=t.headers["sec-websocket-extensions"];if(void 0!==h){if(!d){return void lr(e,r,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let t;try{t=Jt(h)}catch(t){return void lr(e,r,"Invalid Sec-WebSocket-Extensions header")}const s=Object.keys(t);if(1!==s.length||s[0]!==It.extensionName){return void lr(e,r,"Server indicated an extension that was not requested")}try{d.accept(t[It.extensionName])}catch(t){return void lr(e,r,"Invalid Sec-WebSocket-Extensions header")}e._extensions[It.extensionName]=d}e.setSocket(r,s,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})})),o.finishRequest?o.finishRequest(p,e):p.end()}function ar(e,t){e._readyState=or.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function cr(e){return e.path=e.socketPath,Bt.connect(e)}function hr(e){return e.path=void 0,e.servername||""===e.servername||(e.servername=Bt.isIP(e.host)?"":e.host),Rt.connect(e)}function lr(e,t,r){e._readyState=or.CLOSING;const s=new Error(r);Error.captureStackTrace(s,lr),t.setHeader?(t[er]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(ar,e,s)):(t.destroy(s),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function fr(e,t,r){if(t){const r=Ft(t)?t.size:Qt(t).length;e._socket?e._sender._bufferedBytes+=r:e._bufferedAmount+=r}if(r){const t=new Error(`WebSocket is not open: readyState ${e.readyState} (${rr[e.readyState]})`);process.nextTick(r,t)}}function ur(e,t){const r=this[zt];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,void 0!==r._socket[zt]&&(r._socket.removeListener("data",Sr),process.nextTick(vr,r._socket),1005===e?r.close():r.close(e,t))}function dr(){const e=this[zt];e.isPaused||e._socket.resume()}function pr(e){const t=this[zt];void 0!==t._socket[zt]&&(t._socket.removeListener("data",Sr),process.nextTick(vr,t._socket),t.close(e[Ht])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function _r(){this[zt].emitClose()}function yr(e,t){this[zt].emit("message",e,t)}function mr(e){const t=this[zt];t._autoPong&&t.pong(e,!this._isServer,Yt),t.emit("ping",e)}function br(e){this[zt].emit("pong",e)}function vr(e){e.resume()}function gr(e){const t=this[zt];t.readyState!==or.CLOSED&&(t.readyState===or.OPEN&&(t._readyState=or.CLOSING,wr(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function wr(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),e._closeTimeout)}function Er(){const e=this[zt];if(this.removeListener("close",Er),this.removeListener("data",Sr),this.removeListener("end",kr),e._readyState=or.CLOSING,!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&0!==this._readableState.length){const t=this.read(this._readableState.length);e._receiver.write(t)}e._receiver.end(),this[zt]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",_r),e._receiver.on("finish",_r))}function Sr(e){this[zt]._receiver.write(e)||this.pause()}function kr(){const e=this[zt];e._readyState=or.CLOSING,e._receiver.end(),this.end()}function xr(){const e=this[zt];this.removeListener("error",xr),this.on("error",Yt),e&&(e._readyState=or.CLOSING,this.destroy())}var Tr=_(nr);const{Duplex:Or}=i;function Cr(e){e.emit("close")}function Pr(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Lr(e){this.removeListener("error",Lr),this.destroy(),0===this.listenerCount("error")&&this.emit("error",e)}_((function(e,t){let r=!0;const s=new Or({...t,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return e.on("message",(function(t,r){const o=!r&&s._readableState.objectMode?t.toString():t;s.push(o)||e.pause()})),e.once("error",(function(e){s.destroyed||(r=!1,s.destroy(e))})),e.once("close",(function(){s.destroyed||s.push(null)})),s._destroy=function(t,o){if(e.readyState===e.CLOSED)return o(t),void process.nextTick(Cr,s);let n=!1;e.once("error",(function(e){n=!0,o(e)})),e.once("close",(function(){n||o(t),process.nextTick(Cr,s)})),r&&e.terminate()},s._final=function(t){e.readyState!==e.CONNECTING?null!==e._socket&&(e._socket._writableState.finished?(t(),s._readableState.endEmitted&&s.destroy()):(e._socket.once("finish",(function(){t()})),e.close())):e.once("open",(function(){s._final(t)}))},s._read=function(){e.isPaused&&e.resume()},s._write=function(t,r,o){e.readyState!==e.CONNECTING?e.send(t,o):e.once("open",(function(){s._write(t,r,o)}))},s.on("end",Pr),s.on("error",Lr),s}));const{tokenChars:Br}=Pe;var Rr={parse:function(e){const t=new Set;let r=-1,s=-1,o=0;for(;o<e.length;o++){const n=e.charCodeAt(o);if(-1===s&&1===Br[n])-1===r&&(r=o);else if(0===o||32!==n&&9!==n){if(44!==n)throw new SyntaxError(`Unexpected character at index ${o}`);{if(-1===r)throw new SyntaxError(`Unexpected character at index ${o}`);-1===s&&(s=o);const n=e.slice(r,s);if(t.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);t.add(n),r=s=-1}}else-1===s&&-1!==r&&(s=o)}if(-1===r||-1!==s)throw new SyntaxError("Unexpected end of input");const n=e.slice(r,o);if(t.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return t.add(n),t}};_(Rr);const Nr=e,Ar=r,{createHash:Ur}=n,Ir=Ot,jr=we,Dr=Rr,Fr=nr,{CLOSE_TIMEOUT:Mr,GUID:Wr,kWebSocket:qr}=G,$r=/^[+/0-9A-Za-z]{22}==$/;function Gr(e){e._state=2,e.emit("close")}function Vr(){this.destroy()}function Hr(e,t,r,s){r=r||Ar.STATUS_CODES[t],s={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...s},e.once("finish",e.destroy),e.end(`HTTP/1.1 ${t} ${Ar.STATUS_CODES[t]}\r\n`+Object.keys(s).map((e=>`${e}: ${s[e]}`)).join("\r\n")+"\r\n\r\n"+r)}function zr(e,t,r,s,o,n){if(e.listenerCount("wsClientError")){const s=new Error(o);Error.captureStackTrace(s,zr),e.emit("wsClientError",s,r,t)}else Hr(r,s,o,n)}_(class extends Nr{constructor(e,t){if(super(),null==(e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Mr,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Fr,...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=Ar.createServer(((e,t)=>{const r=Ar.STATUS_CODES[426];t.writeHead(426,{"Content-Length":r.length,"Content-Type":"text/plain"}),t.end(r)})),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 r of Object.keys(t))e.on(r,t[r]);return function(){for(const r of Object.keys(t))e.removeListener(r,t[r])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,r,s)=>{this.handleUpgrade(t,r,s,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(Gr,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(Gr,this);else{const e=this._server;this._removeListeners(),this._removeListeners=this._server=null,e.close((()=>{Gr(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,r,s){t.on("error",Vr);const o=e.headers["sec-websocket-key"],n=e.headers.upgrade,i=+e.headers["sec-websocket-version"];if("GET"!==e.method){return void zr(this,e,t,405,"Invalid HTTP method")}if(void 0===n||"websocket"!==n.toLowerCase()){return void zr(this,e,t,400,"Invalid Upgrade header")}if(void 0===o||!$r.test(o)){return void zr(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header")}if(13!==i&&8!==i){return void zr(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"})}if(!this.shouldHandle(e))return void Hr(t,400);const a=e.headers["sec-websocket-protocol"];let c=new Set;if(void 0!==a)try{c=Dr.parse(a)}catch(r){return void zr(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 r=new jr({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{const e=Ir.parse(h);e[jr.extensionName]&&(r.accept(e[jr.extensionName]),l[jr.extensionName]=r)}catch(r){return void zr(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const n={origin:e.headers[""+(8===i?"sec-websocket-origin":"origin")],secure:!(!e.socket.authorized&&!e.socket.encrypted),req:e};if(2===this.options.verifyClient.length)return void this.options.verifyClient(n,((n,i,a,h)=>{if(!n)return Hr(t,i||401,a,h);this.completeUpgrade(l,o,c,e,t,r,s)}));if(!this.options.verifyClient(n))return Hr(t,401)}this.completeUpgrade(l,o,c,e,t,r,s)}completeUpgrade(e,t,r,s,o,n,i){if(!o.readable||!o.writable)return o.destroy();if(o[qr])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return Hr(o,503);const a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Ur("sha1").update(t+Wr).digest("base64")}`],c=new this.options.WebSocket(null,void 0,this.options);if(r.size){const e=this.options.handleProtocols?this.options.handleProtocols(r,s):r.values().next().value;e&&(a.push(`Sec-WebSocket-Protocol: ${e}`),c._protocol=e)}if(e[jr.extensionName]){const t=e[jr.extensionName].params,r=Ir.format({[jr.extensionName]:[t]});a.push(`Sec-WebSocket-Extensions: ${r}`),c._extensions=e}this.emit("headers",a,s),o.write(a.concat("\r\n").join("\r\n")),o.removeListener("error",Vr),c.setSocket(o,n,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,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(Gr,this)}))),i(c,s)}});var Yr="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{WebSocket:null};Yr.WebSocket||(Yr.WebSocket=Tr);