UNPKG

next

Version:

The React Framework

1 lines • 45.7 kB
module.exports=(()=>{var __webpack_modules__={867:(e,t,i)=>{"use strict";const s=i(518);s.createWebSocketStream=i(658);s.Server=i(887);s.Receiver=i(66);s.Sender=i(947);s.WebSocket=s;s.WebSocketServer=s.Server;e.exports=s},436:(e,t,i)=>{"use strict";const{EMPTY_BUFFER:s}=i(949);function concat(e,t){if(e.length===0)return s;if(e.length===1)return e[0];const i=Buffer.allocUnsafe(t);let r=0;for(let t=0;t<e.length;t++){const s=e[t];i.set(s,r);r+=s.length}if(r<t)return i.slice(0,r);return i}function _mask(e,t,i,s,r){for(let n=0;n<r;n++){i[s+n]=e[n]^t[n&3]}}function _unmask(e,t){for(let i=0;i<e.length;i++){e[i]^=t[i&3]}}function toArrayBuffer(e){if(e.byteLength===e.buffer.byteLength){return e.buffer}return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function toBuffer(e){toBuffer.readOnly=true;if(Buffer.isBuffer(e))return e;let t;if(e instanceof ArrayBuffer){t=Buffer.from(e)}else if(ArrayBuffer.isView(e)){t=Buffer.from(e.buffer,e.byteOffset,e.byteLength)}else{t=Buffer.from(e);toBuffer.readOnly=false}return t}try{const t=i(269);e.exports={concat:concat,mask(e,i,s,r,n){if(n<48)_mask(e,i,s,r,n);else t.mask(e,i,s,r,n)},toArrayBuffer:toArrayBuffer,toBuffer:toBuffer,unmask(e,i){if(e.length<32)_unmask(e,i);else t.unmask(e,i)}}}catch(t){e.exports={concat:concat,mask:_mask,toArrayBuffer:toArrayBuffer,toBuffer:toBuffer,unmask:_unmask}}},949:e=>{"use strict";e.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}},561:(e,t,i)=>{"use strict";const{kForOnEventAttribute:s,kListener:r}=i(949);const n=Symbol("kCode");const o=Symbol("kData");const l=Symbol("kError");const h=Symbol("kMessage");const c=Symbol("kReason");const f=Symbol("kTarget");const _=Symbol("kType");const a=Symbol("kWasClean");class Event{constructor(e){this[f]=null;this[_]=e}get target(){return this[f]}get type(){return this[_]}}Object.defineProperty(Event.prototype,"target",{enumerable:true});Object.defineProperty(Event.prototype,"type",{enumerable:true});class CloseEvent extends Event{constructor(e,t={}){super(e);this[n]=t.code===undefined?0:t.code;this[c]=t.reason===undefined?"":t.reason;this[a]=t.wasClean===undefined?false:t.wasClean}get code(){return this[n]}get reason(){return this[c]}get wasClean(){return this[a]}}Object.defineProperty(CloseEvent.prototype,"code",{enumerable:true});Object.defineProperty(CloseEvent.prototype,"reason",{enumerable:true});Object.defineProperty(CloseEvent.prototype,"wasClean",{enumerable:true});class ErrorEvent extends Event{constructor(e,t={}){super(e);this[l]=t.error===undefined?null:t.error;this[h]=t.message===undefined?"":t.message}get error(){return this[l]}get message(){return this[h]}}Object.defineProperty(ErrorEvent.prototype,"error",{enumerable:true});Object.defineProperty(ErrorEvent.prototype,"message",{enumerable:true});class MessageEvent extends Event{constructor(e,t={}){super(e);this[o]=t.data===undefined?null:t.data}get data(){return this[o]}}Object.defineProperty(MessageEvent.prototype,"data",{enumerable:true});const u={addEventListener(e,t,i={}){let n;if(e==="message"){n=function onMessage(e,i){const s=new MessageEvent("message",{data:i?e:e.toString()});s[f]=this;t.call(this,s)}}else if(e==="close"){n=function onClose(e,i){const s=new CloseEvent("close",{code:e,reason:i.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});s[f]=this;t.call(this,s)}}else if(e==="error"){n=function onError(e){const i=new ErrorEvent("error",{error:e,message:e.message});i[f]=this;t.call(this,i)}}else if(e==="open"){n=function onOpen(){const e=new Event("open");e[f]=this;t.call(this,e)}}else{return}n[s]=!!i[s];n[r]=t;if(i.once){this.once(e,n)}else{this.on(e,n)}},removeEventListener(e,t){for(const i of this.listeners(e)){if(i[r]===t&&!i[s]){this.removeListener(e,i);break}}}};e.exports={CloseEvent:CloseEvent,ErrorEvent:ErrorEvent,Event:Event,EventTarget:u,MessageEvent:MessageEvent}},35:(e,t,i)=>{"use strict";const{tokenChars:s}=i(279);function push(e,t,i){if(e[t]===undefined)e[t]=[i];else e[t].push(i)}function parse(e){const t=Object.create(null);let i=Object.create(null);let r=false;let n=false;let o=false;let l;let h;let c=-1;let f=-1;let _=-1;let a=0;for(;a<e.length;a++){f=e.charCodeAt(a);if(l===undefined){if(_===-1&&s[f]===1){if(c===-1)c=a}else if(a!==0&&(f===32||f===9)){if(_===-1&&c!==-1)_=a}else if(f===59||f===44){if(c===-1){throw new SyntaxError(`Unexpected character at index ${a}`)}if(_===-1)_=a;const s=e.slice(c,_);if(f===44){push(t,s,i);i=Object.create(null)}else{l=s}c=_=-1}else{throw new SyntaxError(`Unexpected character at index ${a}`)}}else if(h===undefined){if(_===-1&&s[f]===1){if(c===-1)c=a}else if(f===32||f===9){if(_===-1&&c!==-1)_=a}else if(f===59||f===44){if(c===-1){throw new SyntaxError(`Unexpected character at index ${a}`)}if(_===-1)_=a;push(i,e.slice(c,_),true);if(f===44){push(t,l,i);i=Object.create(null);l=undefined}c=_=-1}else if(f===61&&c!==-1&&_===-1){h=e.slice(c,a);c=_=-1}else{throw new SyntaxError(`Unexpected character at index ${a}`)}}else{if(n){if(s[f]!==1){throw new SyntaxError(`Unexpected character at index ${a}`)}if(c===-1)c=a;else if(!r)r=true;n=false}else if(o){if(s[f]===1){if(c===-1)c=a}else if(f===34&&c!==-1){o=false;_=a}else if(f===92){n=true}else{throw new SyntaxError(`Unexpected character at index ${a}`)}}else if(f===34&&e.charCodeAt(a-1)===61){o=true}else if(_===-1&&s[f]===1){if(c===-1)c=a}else if(c!==-1&&(f===32||f===9)){if(_===-1)_=a}else if(f===59||f===44){if(c===-1){throw new SyntaxError(`Unexpected character at index ${a}`)}if(_===-1)_=a;let s=e.slice(c,_);if(r){s=s.replace(/\\/g,"");r=false}push(i,h,s);if(f===44){push(t,l,i);i=Object.create(null);l=undefined}h=undefined;c=_=-1}else{throw new SyntaxError(`Unexpected character at index ${a}`)}}}if(c===-1||o||f===32||f===9){throw new SyntaxError("Unexpected end of input")}if(_===-1)_=a;const u=e.slice(c,_);if(l===undefined){push(t,u,i)}else{if(h===undefined){push(i,u,true)}else if(r){push(i,h,u.replace(/\\/g,""))}else{push(i,h,u)}push(t,l,i)}return t}function format(e){return Object.keys(e).map(t=>{let i=e[t];if(!Array.isArray(i))i=[i];return i.map(e=>{return[t].concat(Object.keys(e).map(t=>{let i=e[t];if(!Array.isArray(i))i=[i];return i.map(e=>e===true?t:`${t}=${e}`).join("; ")})).join("; ")}).join(", ")}).join(", ")}e.exports={format:format,parse:parse}},356:e=>{"use strict";const t=Symbol("kDone");const i=Symbol("kRun");class Limiter{constructor(e){this[t]=(()=>{this.pending--;this[i]()});this.concurrency=e||Infinity;this.jobs=[];this.pending=0}add(e){this.jobs.push(e);this[i]()}[i](){if(this.pending===this.concurrency)return;if(this.jobs.length){const e=this.jobs.shift();this.pending++;e(this[t])}}}e.exports=Limiter},684:(e,t,i)=>{"use strict";const s=i(761);const r=i(436);const n=i(356);const{kStatusCode:o}=i(949);const l=Buffer.from([0,0,255,255]);const h=Symbol("permessage-deflate");const c=Symbol("total-length");const f=Symbol("callback");const _=Symbol("buffers");const a=Symbol("error");let u;class PerMessageDeflate{constructor(e,t,i){this._maxPayload=i|0;this._options=e||{};this._threshold=this._options.threshold!==undefined?this._options.threshold:1024;this._isServer=!!t;this._deflate=null;this._inflate=null;this.params=null;if(!u){const e=this._options.concurrencyLimit!==undefined?this._options.concurrencyLimit:10;u=new n(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};if(this._options.serverNoContextTakeover){e.server_no_context_takeover=true}if(this._options.clientNoContextTakeover){e.client_no_context_takeover=true}if(this._options.serverMaxWindowBits){e.server_max_window_bits=this._options.serverMaxWindowBits}if(this._options.clientMaxWindowBits){e.client_max_window_bits=this._options.clientMaxWindowBits}else if(this._options.clientMaxWindowBits==null){e.client_max_window_bits=true}return e}accept(e){e=this.normalizeParams(e);this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e);return this.params}cleanup(){if(this._inflate){this._inflate.close();this._inflate=null}if(this._deflate){const e=this._deflate[f];this._deflate.close();this._deflate=null;if(e){e(new Error("The deflate stream was closed while data was being processed"))}}}acceptAsServer(e){const t=this._options;const i=e.find(e=>{if(t.serverNoContextTakeover===false&&e.server_no_context_takeover||e.server_max_window_bits&&(t.serverMaxWindowBits===false||typeof t.serverMaxWindowBits==="number"&&t.serverMaxWindowBits>e.server_max_window_bits)||typeof t.clientMaxWindowBits==="number"&&!e.client_max_window_bits){return false}return true});if(!i){throw new Error("None of the extension offers can be accepted")}if(t.serverNoContextTakeover){i.server_no_context_takeover=true}if(t.clientNoContextTakeover){i.client_no_context_takeover=true}if(typeof t.serverMaxWindowBits==="number"){i.server_max_window_bits=t.serverMaxWindowBits}if(typeof t.clientMaxWindowBits==="number"){i.client_max_window_bits=t.clientMaxWindowBits}else if(i.client_max_window_bits===true||t.clientMaxWindowBits===false){delete i.client_max_window_bits}return i}acceptAsClient(e){const t=e[0];if(this._options.clientNoContextTakeover===false&&t.client_no_context_takeover){throw new Error('Unexpected parameter "client_no_context_takeover"')}if(!t.client_max_window_bits){if(typeof this._options.clientMaxWindowBits==="number"){t.client_max_window_bits=this._options.clientMaxWindowBits}}else if(this._options.clientMaxWindowBits===false||typeof this._options.clientMaxWindowBits==="number"&&t.client_max_window_bits>this._options.clientMaxWindowBits){throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}return t}normalizeParams(e){e.forEach(e=>{Object.keys(e).forEach(t=>{let i=e[t];if(i.length>1){throw new Error(`Parameter "${t}" must have only a single value`)}i=i[0];if(t==="client_max_window_bits"){if(i!==true){const e=+i;if(!Number.isInteger(e)||e<8||e>15){throw new TypeError(`Invalid value for parameter "${t}": ${i}`)}i=e}else if(!this._isServer){throw new TypeError(`Invalid value for parameter "${t}": ${i}`)}}else if(t==="server_max_window_bits"){const e=+i;if(!Number.isInteger(e)||e<8||e>15){throw new TypeError(`Invalid value for parameter "${t}": ${i}`)}i=e}else if(t==="client_no_context_takeover"||t==="server_no_context_takeover"){if(i!==true){throw new TypeError(`Invalid value for parameter "${t}": ${i}`)}}else{throw new Error(`Unknown parameter "${t}"`)}e[t]=i})});return e}decompress(e,t,i){u.add(s=>{this._decompress(e,t,(e,t)=>{s();i(e,t)})})}compress(e,t,i){u.add(s=>{this._compress(e,t,(e,t)=>{s();i(e,t)})})}_decompress(e,t,i){const n=this._isServer?"client":"server";if(!this._inflate){const e=`${n}_max_window_bits`;const t=typeof this.params[e]!=="number"?s.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=s.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t});this._inflate[h]=this;this._inflate[c]=0;this._inflate[_]=[];this._inflate.on("error",inflateOnError);this._inflate.on("data",inflateOnData)}this._inflate[f]=i;this._inflate.write(e);if(t)this._inflate.write(l);this._inflate.flush(()=>{const e=this._inflate[a];if(e){this._inflate.close();this._inflate=null;i(e);return}const s=r.concat(this._inflate[_],this._inflate[c]);if(this._inflate._readableState.endEmitted){this._inflate.close();this._inflate=null}else{this._inflate[c]=0;this._inflate[_]=[];if(t&&this.params[`${n}_no_context_takeover`]){this._inflate.reset()}}i(null,s)})}_compress(e,t,i){const n=this._isServer?"server":"client";if(!this._deflate){const e=`${n}_max_window_bits`;const t=typeof this.params[e]!=="number"?s.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=s.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t});this._deflate[c]=0;this._deflate[_]=[];this._deflate.on("data",deflateOnData)}this._deflate[f]=i;this._deflate.write(e);this._deflate.flush(s.Z_SYNC_FLUSH,()=>{if(!this._deflate){return}let e=r.concat(this._deflate[_],this._deflate[c]);if(t)e=e.slice(0,e.length-4);this._deflate[f]=null;this._deflate[c]=0;this._deflate[_]=[];if(t&&this.params[`${n}_no_context_takeover`]){this._deflate.reset()}i(null,e)})}}e.exports=PerMessageDeflate;function deflateOnData(e){this[_].push(e);this[c]+=e.length}function inflateOnData(e){this[c]+=e.length;if(this[h]._maxPayload<1||this[c]<=this[h]._maxPayload){this[_].push(e);return}this[a]=new RangeError("Max payload size exceeded");this[a].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";this[a][o]=1009;this.removeListener("data",inflateOnData);this.reset()}function inflateOnError(e){this[h]._inflate=null;e[o]=1007;this[f](e)}},66:(e,t,i)=>{"use strict";const{Writable:s}=i(413);const r=i(684);const{BINARY_TYPES:n,EMPTY_BUFFER:o,kStatusCode:l,kWebSocket:h}=i(949);const{concat:c,toArrayBuffer:f,unmask:_}=i(436);const{isValidStatusCode:a,isValidUTF8:u}=i(279);const d=0;const S=1;const y=2;const p=3;const b=4;const k=5;class Receiver extends s{constructor(e={}){super();this._binaryType=e.binaryType||n[0];this._extensions=e.extensions||{};this._isServer=!!e.isServer;this._maxPayload=e.maxPayload|0;this._skipUTF8Validation=!!e.skipUTF8Validation;this[h]=undefined;this._bufferedBytes=0;this._buffers=[];this._compressed=false;this._payloadLength=0;this._mask=undefined;this._fragmented=0;this._masked=false;this._fin=false;this._opcode=0;this._totalPayloadLength=0;this._messageLength=0;this._fragments=[];this._state=d;this._loop=false}_write(e,t,i){if(this._opcode===8&&this._state==d)return i();this._bufferedBytes+=e.length;this._buffers.push(e);this.startLoop(i)}consume(e){this._bufferedBytes-=e;if(e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];this._buffers[0]=t.slice(e);return t.slice(0,e)}const t=Buffer.allocUnsafe(e);do{const i=this._buffers[0];const s=t.length-e;if(e>=i.length){t.set(this._buffers.shift(),s)}else{t.set(new Uint8Array(i.buffer,i.byteOffset,e),s);this._buffers[0]=i.slice(e)}e-=i.length}while(e>0);return t}startLoop(e){let t;this._loop=true;do{switch(this._state){case d:t=this.getInfo();break;case S:t=this.getPayloadLength16();break;case y:t=this.getPayloadLength64();break;case p:this.getMask();break;case b:t=this.getData(e);break;default:this._loop=false;return}}while(this._loop);e(t)}getInfo(){if(this._bufferedBytes<2){this._loop=false;return}const e=this.consume(2);if((e[0]&48)!==0){this._loop=false;return error(RangeError,"RSV2 and RSV3 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_2_3")}const t=(e[0]&64)===64;if(t&&!this._extensions[r.extensionName]){this._loop=false;return error(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1")}this._fin=(e[0]&128)===128;this._opcode=e[0]&15;this._payloadLength=e[1]&127;if(this._opcode===0){if(t){this._loop=false;return error(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1")}if(!this._fragmented){this._loop=false;return error(RangeError,"invalid opcode 0",true,1002,"WS_ERR_INVALID_OPCODE")}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){this._loop=false;return error(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE")}this._compressed=t}else if(this._opcode>7&&this._opcode<11){if(!this._fin){this._loop=false;return error(RangeError,"FIN must be set",true,1002,"WS_ERR_EXPECTED_FIN")}if(t){this._loop=false;return error(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1")}if(this._payloadLength>125){this._loop=false;return error(RangeError,`invalid payload length ${this._payloadLength}`,true,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH")}}else{this._loop=false;return error(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE")}if(!this._fin&&!this._fragmented)this._fragmented=this._opcode;this._masked=(e[1]&128)===128;if(this._isServer){if(!this._masked){this._loop=false;return error(RangeError,"MASK must be set",true,1002,"WS_ERR_EXPECTED_MASK")}}else if(this._masked){this._loop=false;return error(RangeError,"MASK must be clear",true,1002,"WS_ERR_UNEXPECTED_MASK")}if(this._payloadLength===126)this._state=S;else if(this._payloadLength===127)this._state=y;else return this.haveLength()}getPayloadLength16(){if(this._bufferedBytes<2){this._loop=false;return}this._payloadLength=this.consume(2).readUInt16BE(0);return this.haveLength()}getPayloadLength64(){if(this._bufferedBytes<8){this._loop=false;return}const e=this.consume(8);const t=e.readUInt32BE(0);if(t>Math.pow(2,53-32)-1){this._loop=false;return error(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",false,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH")}this._payloadLength=t*Math.pow(2,32)+e.readUInt32BE(4);return this.haveLength()}haveLength(){if(this._payloadLength&&this._opcode<8){this._totalPayloadLength+=this._payloadLength;if(this._totalPayloadLength>this._maxPayload&&this._maxPayload>0){this._loop=false;return error(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH")}}if(this._masked)this._state=p;else this._state=b}getMask(){if(this._bufferedBytes<4){this._loop=false;return}this._mask=this.consume(4);this._state=b}getData(e){let t=o;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=false;return}t=this.consume(this._payloadLength);if(this._masked)_(t,this._mask)}if(this._opcode>7)return this.controlMessage(t);if(this._compressed){this._state=k;this.decompress(t,e);return}if(t.length){this._messageLength=this._totalPayloadLength;this._fragments.push(t)}return this.dataMessage()}decompress(e,t){const i=this._extensions[r.extensionName];i.decompress(e,this._fin,(e,i)=>{if(e)return t(e);if(i.length){this._messageLength+=i.length;if(this._messageLength>this._maxPayload&&this._maxPayload>0){return t(error(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"))}this._fragments.push(i)}const s=this.dataMessage();if(s)return t(s);this.startLoop(t)})}dataMessage(){if(this._fin){const e=this._messageLength;const t=this._fragments;this._totalPayloadLength=0;this._messageLength=0;this._fragmented=0;this._fragments=[];if(this._opcode===2){let i;if(this._binaryType==="nodebuffer"){i=c(t,e)}else if(this._binaryType==="arraybuffer"){i=f(c(t,e))}else{i=t}this.emit("message",i,true)}else{const i=c(t,e);if(!this._skipUTF8Validation&&!u(i)){this._loop=false;return error(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8")}this.emit("message",i,false)}}this._state=d}controlMessage(e){if(this._opcode===8){this._loop=false;if(e.length===0){this.emit("conclude",1005,o);this.end()}else if(e.length===1){return error(RangeError,"invalid payload length 1",true,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH")}else{const t=e.readUInt16BE(0);if(!a(t)){return error(RangeError,`invalid status code ${t}`,true,1002,"WS_ERR_INVALID_CLOSE_CODE")}const i=e.slice(2);if(!this._skipUTF8Validation&&!u(i)){return error(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8")}this.emit("conclude",t,i);this.end()}}else if(this._opcode===9){this.emit("ping",e)}else{this.emit("pong",e)}this._state=d}}e.exports=Receiver;function error(e,t,i,s,r){const n=new e(i?`Invalid WebSocket frame: ${t}`:t);Error.captureStackTrace(n,error);n.code=r;n[l]=s;return n}},947:(e,t,i)=>{"use strict";const s=i(631);const r=i(16);const{randomFillSync:n}=i(417);const o=i(684);const{EMPTY_BUFFER:l}=i(949);const{isValidStatusCode:h}=i(279);const{mask:c,toBuffer:f}=i(436);const _=Buffer.alloc(4);class Sender{constructor(e,t){this._extensions=t||{};this._socket=e;this._firstFragment=true;this._compress=false;this._bufferedBytes=0;this._deflating=false;this._queue=[]}static frame(e,t){const i=t.mask&&t.readOnly;let s=t.mask?6:2;let r=e.length;if(e.length>=65536){s+=8;r=127}else if(e.length>125){s+=2;r=126}const o=Buffer.allocUnsafe(i?e.length+s:s);o[0]=t.fin?t.opcode|128:t.opcode;if(t.rsv1)o[0]|=64;o[1]=r;if(r===126){o.writeUInt16BE(e.length,2)}else if(r===127){o.writeUInt32BE(0,2);o.writeUInt32BE(e.length,6)}if(!t.mask)return[o,e];n(_,0,4);o[1]|=128;o[s-4]=_[0];o[s-3]=_[1];o[s-2]=_[2];o[s-1]=_[3];if(i){c(e,_,o,s,e.length);return[o]}c(e,_,e,0,e.length);return[o,e]}close(e,t,i,s){let r;if(e===undefined){r=l}else if(typeof e!=="number"||!h(e)){throw new TypeError("First argument must be a valid error code number")}else if(t===undefined||!t.length){r=Buffer.allocUnsafe(2);r.writeUInt16BE(e,0)}else{const i=Buffer.byteLength(t);if(i>123){throw new RangeError("The message must not be greater than 123 bytes")}r=Buffer.allocUnsafe(2+i);r.writeUInt16BE(e,0);if(typeof t==="string"){r.write(t,2)}else{r.set(t,2)}}if(this._deflating){this.enqueue([this.doClose,r,i,s])}else{this.doClose(r,i,s)}}doClose(e,t,i){this.sendFrame(Sender.frame(e,{fin:true,rsv1:false,opcode:8,mask:t,readOnly:false}),i)}ping(e,t,i){const s=f(e);if(s.length>125){throw new RangeError("The data size must not be greater than 125 bytes")}if(this._deflating){this.enqueue([this.doPing,s,t,f.readOnly,i])}else{this.doPing(s,t,f.readOnly,i)}}doPing(e,t,i,s){this.sendFrame(Sender.frame(e,{fin:true,rsv1:false,opcode:9,mask:t,readOnly:i}),s)}pong(e,t,i){const s=f(e);if(s.length>125){throw new RangeError("The data size must not be greater than 125 bytes")}if(this._deflating){this.enqueue([this.doPong,s,t,f.readOnly,i])}else{this.doPong(s,t,f.readOnly,i)}}doPong(e,t,i,s){this.sendFrame(Sender.frame(e,{fin:true,rsv1:false,opcode:10,mask:t,readOnly:i}),s)}send(e,t,i){const s=f(e);const r=this._extensions[o.extensionName];let n=t.binary?2:1;let l=t.compress;if(this._firstFragment){this._firstFragment=false;if(l&&r&&r.params[r._isServer?"server_no_context_takeover":"client_no_context_takeover"]){l=s.length>=r._threshold}this._compress=l}else{l=false;n=0}if(t.fin)this._firstFragment=true;if(r){const e={fin:t.fin,rsv1:l,opcode:n,mask:t.mask,readOnly:f.readOnly};if(this._deflating){this.enqueue([this.dispatch,s,this._compress,e,i])}else{this.dispatch(s,this._compress,e,i)}}else{this.sendFrame(Sender.frame(s,{fin:t.fin,rsv1:false,opcode:n,mask:t.mask,readOnly:f.readOnly}),i)}}dispatch(e,t,i,s){if(!t){this.sendFrame(Sender.frame(e,i),s);return}const r=this._extensions[o.extensionName];this._bufferedBytes+=e.length;this._deflating=true;r.compress(e,i.fin,(t,r)=>{if(this._socket.destroyed){const e=new Error("The socket was closed while data was being compressed");if(typeof s==="function")s(e);for(let t=0;t<this._queue.length;t++){const i=this._queue[t][4];if(typeof i==="function")i(e)}return}this._bufferedBytes-=e.length;this._deflating=false;i.readOnly=false;this.sendFrame(Sender.frame(r,i),s);this.dequeue()})}dequeue(){while(!this._deflating&&this._queue.length){const e=this._queue.shift();this._bufferedBytes-=e[1].length;Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[1].length;this._queue.push(e)}sendFrame(e,t){if(e.length===2){this._socket.cork();this._socket.write(e[0]);this._socket.write(e[1],t);this._socket.uncork()}else{this._socket.write(e[0],t)}}}e.exports=Sender},658:(e,t,i)=>{"use strict";const{Duplex:s}=i(413);function emitClose(e){e.emit("close")}function duplexOnEnd(){if(!this.destroyed&&this._writableState.finished){this.destroy()}}function duplexOnError(e){this.removeListener("error",duplexOnError);this.destroy();if(this.listenerCount("error")===0){this.emit("error",e)}}function createWebSocketStream(e,t){let i=true;let r=true;function receiverOnDrain(){if(i)e._socket.resume()}if(e.readyState===e.CONNECTING){e.once("open",function open(){e._receiver.removeAllListeners("drain");e._receiver.on("drain",receiverOnDrain)})}else{e._receiver.removeAllListeners("drain");e._receiver.on("drain",receiverOnDrain)}const n=new s({...t,autoDestroy:false,emitClose:false,objectMode:false,writableObjectMode:false});e.on("message",function message(t,s){const r=!s&&n._readableState.objectMode?t.toString():t;if(!n.push(r)){i=false;e._socket.pause()}});e.once("error",function error(e){if(n.destroyed)return;r=false;n.destroy(e)});e.once("close",function close(){if(n.destroyed)return;n.push(null)});n._destroy=function(t,i){if(e.readyState===e.CLOSED){i(t);process.nextTick(emitClose,n);return}let s=false;e.once("error",function error(e){s=true;i(e)});e.once("close",function close(){if(!s)i(t);process.nextTick(emitClose,n)});if(r)e.terminate()};n._final=function(t){if(e.readyState===e.CONNECTING){e.once("open",function open(){n._final(t)});return}if(e._socket===null)return;if(e._socket._writableState.finished){t();if(n._readableState.endEmitted)n.destroy()}else{e._socket.once("finish",function finish(){t()});e.close()}};n._read=function(){if(e.readyState===e.OPEN&&!i){i=true;if(!e._receiver._writableState.needDrain)e._socket.resume()}};n._write=function(t,i,s){if(e.readyState===e.CONNECTING){e.once("open",function open(){n._write(t,i,s)});return}e.send(t,s)};n.on("end",duplexOnEnd);n.on("error",duplexOnError);return n}e.exports=createWebSocketStream},668:(e,t,i)=>{"use strict";const{tokenChars:s}=i(279);function parse(e){const t=new Set;let i=-1;let r=-1;let n=0;for(n;n<e.length;n++){const o=e.charCodeAt(n);if(r===-1&&s[o]===1){if(i===-1)i=n}else if(n!==0&&(o===32||o===9)){if(r===-1&&i!==-1)r=n}else if(o===44){if(i===-1){throw new SyntaxError(`Unexpected character at index ${n}`)}if(r===-1)r=n;const s=e.slice(i,r);if(t.has(s)){throw new SyntaxError(`The "${s}" subprotocol is duplicated`)}t.add(s);i=r=-1}else{throw new SyntaxError(`Unexpected character at index ${n}`)}}if(i===-1||r!==-1){throw new SyntaxError("Unexpected end of input")}const o=e.slice(i,n);if(t.has(o)){throw new SyntaxError(`The "${o}" subprotocol is duplicated`)}t.add(o);return t}e.exports={parse:parse}},279:(e,t,i)=>{"use strict";const s=[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];function isValidStatusCode(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function _isValidUTF8(e){const t=e.length;let i=0;while(i<t){if((e[i]&128)===0){i++}else if((e[i]&224)===192){if(i+1===t||(e[i+1]&192)!==128||(e[i]&254)===192){return false}i+=2}else if((e[i]&240)===224){if(i+2>=t||(e[i+1]&192)!==128||(e[i+2]&192)!==128||e[i]===224&&(e[i+1]&224)===128||e[i]===237&&(e[i+1]&224)===160){return false}i+=3}else if((e[i]&248)===240){if(i+3>=t||(e[i+1]&192)!==128||(e[i+2]&192)!==128||(e[i+3]&192)!==128||e[i]===240&&(e[i+1]&240)===128||e[i]===244&&e[i+1]>143||e[i]>244){return false}i+=4}else{return false}}return true}try{const t=i(592);e.exports={isValidStatusCode:isValidStatusCode,isValidUTF8(e){return e.length<150?_isValidUTF8(e):t(e)},tokenChars:s}}catch(t){e.exports={isValidStatusCode:isValidStatusCode,isValidUTF8:_isValidUTF8,tokenChars:s}}},887:(e,t,i)=>{"use strict";const s=i(614);const r=i(605);const n=i(211);const o=i(631);const l=i(16);const{createHash:h}=i(417);const c=i(35);const f=i(684);const _=i(668);const a=i(518);const{GUID:u,kWebSocket:d}=i(949);const S=/^[+/0-9A-Za-z]{22}==$/;const y=0;const p=1;const b=2;class WebSocketServer extends s{constructor(e,t){super();e={maxPayload:100*1024*1024,skipUTF8Validation:false,perMessageDeflate:false,handleProtocols:null,clientTracking:true,verifyClient:null,noServer:false,backlog:null,server:null,host:null,path:null,port:null,...e};if(e.port==null&&!e.server&&!e.noServer||e.port!=null&&(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(e.port!=null){this._server=r.createServer((e,t)=>{const i=r.STATUS_CODES[426];t.writeHead(426,{"Content-Length":i.length,"Content-Type":"text/plain"});t.end(i)});this._server.listen(e.port,e.host,e.backlog,t)}else if(e.server){this._server=e.server}if(this._server){const e=this.emit.bind(this,"connection");this._removeListeners=addListeners(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,i,s)=>{this.handleUpgrade(t,i,s,e)}})}if(e.perMessageDeflate===true)e.perMessageDeflate={};if(e.clientTracking){this.clients=new Set;this._shouldEmitClose=false}this.options=e;this._state=y}address(){if(this.options.noServer){throw new Error('The server is operating in "noServer" mode')}if(!this._server)return null;return this._server.address()}close(e){if(this._state===b){if(e){this.once("close",()=>{e(new Error("The server is not running"))})}process.nextTick(emitClose,this);return}if(e)this.once("close",e);if(this._state===p)return;this._state=p;if(this.options.noServer||this.options.server){if(this._server){this._removeListeners();this._removeListeners=this._server=null}if(this.clients){if(!this.clients.size){process.nextTick(emitClose,this)}else{this._shouldEmitClose=true}}else{process.nextTick(emitClose,this)}}else{const e=this._server;this._removeListeners();this._removeListeners=this._server=null;e.close(()=>{emitClose(this)})}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");const i=t!==-1?e.url.slice(0,t):e.url;if(i!==this.options.path)return false}return true}handleUpgrade(e,t,i,s){t.on("error",socketOnError);const r=e.headers["sec-websocket-key"]!==undefined?e.headers["sec-websocket-key"]:false;const n=+e.headers["sec-websocket-version"];if(e.method!=="GET"||e.headers.upgrade.toLowerCase()!=="websocket"||!r||!S.test(r)||n!==8&&n!==13||!this.shouldHandle(e)){return abortHandshake(t,400)}const o=e.headers["sec-websocket-protocol"];let l=new Set;if(o!==undefined){try{l=_.parse(o)}catch(e){return abortHandshake(t,400)}}const h=e.headers["sec-websocket-extensions"];const a={};if(this.options.perMessageDeflate&&h!==undefined){const e=new f(this.options.perMessageDeflate,true,this.options.maxPayload);try{const i=c.parse(h);if(i[f.extensionName]){e.accept(i[f.extensionName]);a[f.extensionName]=e}}catch(e){return abortHandshake(t,400)}}if(this.options.verifyClient){const o={origin:e.headers[`${n===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(o,(n,o,h,c)=>{if(!n){return abortHandshake(t,o||401,h,c)}this.completeUpgrade(a,r,l,e,t,i,s)});return}if(!this.options.verifyClient(o))return abortHandshake(t,401)}this.completeUpgrade(a,r,l,e,t,i,s)}completeUpgrade(e,t,i,s,r,n,o){if(!r.readable||!r.writable)return r.destroy();if(r[d]){throw new Error("server.handleUpgrade() was called more than once with the same "+"socket, possibly due to a misconfiguration")}if(this._state>y)return abortHandshake(r,503);const l=h("sha1").update(t+u).digest("base64");const _=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${l}`];const S=new a(null);if(i.size){const e=this.options.handleProtocols?this.options.handleProtocols(i,s):i.values().next().value;if(e){_.push(`Sec-WebSocket-Protocol: ${e}`);S._protocol=e}}if(e[f.extensionName]){const t=e[f.extensionName].params;const i=c.format({[f.extensionName]:[t]});_.push(`Sec-WebSocket-Extensions: ${i}`);S._extensions=e}this.emit("headers",_,s);r.write(_.concat("\r\n").join("\r\n"));r.removeListener("error",socketOnError);S.setSocket(r,n,{maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation});if(this.clients){this.clients.add(S);S.on("close",()=>{this.clients.delete(S);if(this._shouldEmitClose&&!this.clients.size){process.nextTick(emitClose,this)}})}o(S,s)}}e.exports=WebSocketServer;function addListeners(e,t){for(const i of Object.keys(t))e.on(i,t[i]);return function removeListeners(){for(const i of Object.keys(t)){e.removeListener(i,t[i])}}}function emitClose(e){e._state=b;e.emit("close")}function socketOnError(){this.destroy()}function abortHandshake(e,t,i,s){if(e.writable){i=i||r.STATUS_CODES[t];s={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(i),...s};e.write(`HTTP/1.1 ${t} ${r.STATUS_CODES[t]}\r\n`+Object.keys(s).map(e=>`${e}: ${s[e]}`).join("\r\n")+"\r\n\r\n"+i)}e.removeListener("error",socketOnError);e.destroy()}},518:(e,t,i)=>{"use strict";const s=i(614);const r=i(211);const n=i(605);const o=i(631);const l=i(16);const{randomBytes:h,createHash:c}=i(417);const{Readable:f}=i(413);const{URL:_}=i(835);const a=i(684);const u=i(66);const d=i(947);const{BINARY_TYPES:S,EMPTY_BUFFER:y,GUID:p,kForOnEventAttribute:b,kListener:k,kStatusCode:E,kWebSocket:g,NOOP:w}=i(949);const{EventTarget:{addEventListener:x,removeEventListener:v}}=i(561);const{format:O,parse:C}=i(35);const{toBuffer:m}=i(436);const T=["CONNECTING","OPEN","CLOSING","CLOSED"];const W=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;const L=[8,13];const P=30*1e3;class WebSocket extends s{constructor(e,t,i){super();this._binaryType=S[0];this._closeCode=1006;this._closeFrameReceived=false;this._closeFrameSent=false;this._closeMessage=y;this._closeTimer=null;this._extensions={};this._protocol="";this._readyState=WebSocket.CONNECTING;this._receiver=null;this._sender=null;this._socket=null;if(e!==null){this._bufferedAmount=0;this._isServer=false;this._redirects=0;if(t===undefined){t=[]}else if(!Array.isArray(t)){if(typeof t==="object"&&t!==null){i=t;t=[]}else{t=[t]}}initAsClient(this,e,t,i)}else{this._isServer=true}}get binaryType(){return this._binaryType}set binaryType(e){if(!S.includes(e))return;this._binaryType=e;if(this._receiver)this._receiver._binaryType=e}get bufferedAmount(){if(!this._socket)return this._bufferedAmount;return this._socket._writableState.length+this._sender._bufferedBytes}get extensions(){return Object.keys(this._extensions).join()}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,i){const s=new u({binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation});this._sender=new d(e,this._extensions);this._receiver=s;this._socket=e;s[g]=this;e[g]=this;s.on("conclude",receiverOnConclude);s.on("drain",receiverOnDrain);s.on("error",receiverOnError);s.on("message",receiverOnMessage);s.on("ping",receiverOnPing);s.on("pong",receiverOnPong);e.setTimeout(0);e.setNoDelay();if(t.length>0)e.unshift(t);e.on("close",socketOnClose);e.on("data",socketOnData);e.on("end",socketOnEnd);e.on("error",socketOnError);this._readyState=WebSocket.OPEN;this.emit("open")}emitClose(){if(!this._socket){this._readyState=WebSocket.CLOSED;this.emit("close",this._closeCode,this._closeMessage);return}if(this._extensions[a.extensionName]){this._extensions[a.extensionName].cleanup()}this._receiver.removeAllListeners();this._readyState=WebSocket.CLOSED;this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState===WebSocket.CLOSED)return;if(this.readyState===WebSocket.CONNECTING){const e="WebSocket was closed before the connection was established";return abortHandshake(this,this._req,e)}if(this.readyState===WebSocket.CLOSING){if(this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)){this._socket.end()}return}this._readyState=WebSocket.CLOSING;this._sender.close(e,t,!this._isServer,e=>{if(e)return;this._closeFrameSent=true;if(this._closeFrameReceived||this._receiver._writableState.errorEmitted){this._socket.end()}});this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),P)}ping(e,t,i){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof e==="function"){i=e;e=t=undefined}else if(typeof t==="function"){i=t;t=undefined}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,i);return}if(t===undefined)t=!this._isServer;this._sender.ping(e||y,t,i)}pong(e,t,i){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof e==="function"){i=e;e=t=undefined}else if(typeof t==="function"){i=t;t=undefined}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,i);return}if(t===undefined)t=!this._isServer;this._sender.pong(e||y,t,i)}send(e,t,i){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof t==="function"){i=t;t={}}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,i);return}const s={binary:typeof e!=="string",mask:!this._isServer,compress:true,fin:true,...t};if(!this._extensions[a.extensionName]){s.compress=false}this._sender.send(e||y,s,i)}terminate(){if(this.readyState===WebSocket.CLOSED)return;if(this.readyState===WebSocket.CONNECTING){const e="WebSocket was closed before the connection was established";return abortHandshake(this,this._req,e)}if(this._socket){this._readyState=WebSocket.CLOSING;this._socket.destroy()}}}Object.defineProperty(WebSocket,"CONNECTING",{enumerable:true,value:T.indexOf("CONNECTING")});Object.defineProperty(WebSocket.prototype,"CONNECTING",{enumerable:true,value:T.indexOf("CONNECTING")});Object.defineProperty(WebSocket,"OPEN",{enumerable:true,value:T.indexOf("OPEN")});Object.defineProperty(WebSocket.prototype,"OPEN",{enumerable:true,value:T.indexOf("OPEN")});Object.defineProperty(WebSocket,"CLOSING",{enumerable:true,value:T.indexOf("CLOSING")});Object.defineProperty(WebSocket.prototype,"CLOSING",{enumerable:true,value:T.indexOf("CLOSING")});Object.defineProperty(WebSocket,"CLOSED",{enumerable:true,value:T.indexOf("CLOSED")});Object.defineProperty(WebSocket.prototype,"CLOSED",{enumerable:true,value:T.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","protocol","readyState","url"].forEach(e=>{Object.defineProperty(WebSocket.prototype,e,{enumerable:true})});["open","error","close","message"].forEach(e=>{Object.defineProperty(WebSocket.prototype,`on${e}`,{enumerable:true,get(){for(const t of this.listeners(e)){if(t[b])return t[k]}return null},set(t){for(const t of this.listeners(e)){if(t[b]){this.removeListener(e,t);break}}if(typeof t!=="function")return;this.addEventListener(e,t,{[b]:true})}})});WebSocket.prototype.addEventListener=x;WebSocket.prototype.removeEventListener=v;e.exports=WebSocket;function initAsClient(e,t,i,s){const o={protocolVersion:L[1],maxPayload:100*1024*1024,skipUTF8Validation:false,perMessageDeflate:true,followRedirects:false,maxRedirects:10,...s,createConnection:undefined,socketPath:undefined,hostname:undefined,protocol:undefined,timeout:undefined,method:undefined,host:undefined,path:undefined,port:undefined};if(!L.includes(o.protocolVersion)){throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} `+`(supported versions: ${L.join(", ")})`)}let l;if(t instanceof _){l=t;e._url=t.href}else{try{l=new _(t)}catch(e){throw new SyntaxError(`Invalid URL: ${t}`)}e._url=t}const f=l.protocol==="wss:";const u=l.protocol==="ws+unix:";if(l.protocol!=="ws:"&&!f&&!u){throw new SyntaxError('The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"')}if(u&&!l.pathname){throw new SyntaxError("The URL's pathname is empty")}if(l.hash){throw new SyntaxError("The URL contains a fragment identifier")}const d=f?443:80;const S=h(16).toString("base64");const y=f?r.get:n.get;const b=new Set;let k;o.createConnection=f?tlsConnect:netConnect;o.defaultPort=o.defaultPort||d;o.port=l.port||d;o.host=l.hostname.startsWith("[")?l.hostname.slice(1,-1):l.hostname;o.headers={"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":S,Connection:"Upgrade",Upgrade:"websocket",...o.headers};o.path=l.pathname+l.search;o.timeout=o.handshakeTimeout;if(o.perMessageDeflate){k=new a(o.perMessageDeflate!==true?o.perMessageDeflate:{},false,o.maxPayload);o.headers["Sec-WebSocket-Extensions"]=O({[a.extensionName]:k.offer()})}if(i.length){for(const e of i){if(typeof e!=="string"||!W.test(e)||b.has(e)){throw new SyntaxError("An invalid or duplicated subprotocol was specified")}b.add(e)}o.headers["Sec-WebSocket-Protocol"]=i.join(",")}if(o.origin){if(o.protocolVersion<13){o.headers["Sec-WebSocket-Origin"]=o.origin}else{o.headers.Origin=o.origin}}if(l.username||l.password){o.auth=`${l.username}:${l.password}`}if(u){const e=o.path.split(":");o.socketPath=e[0];o.path=e[1]}let E=e._req=y(o);if(o.timeout){E.on("timeout",()=>{abortHandshake(e,E,"Opening handshake has timed out")})}E.on("error",t=>{if(E===null||E.aborted)return;E=e._req=null;e._readyState=WebSocket.CLOSING;e.emit("error",t);e.emitClose()});E.on("response",r=>{const n=r.headers.location;const l=r.statusCode;if(n&&o.followRedirects&&l>=300&&l<400){if(++e._redirects>o.maxRedirects){abortHandshake(e,E,"Maximum redirects exceeded");return}E.abort();const r=new _(n,t);initAsClient(e,r,i,s)}else if(!e.emit("unexpected-response",E,r)){abortHandshake(e,E,`Unexpected server response: ${r.statusCode}`)}});E.on("upgrade",(t,i,s)=>{e.emit("upgrade",t);if(e.readyState!==WebSocket.CONNECTING)return;E=e._req=null;const r=c("sha1").update(S+p).digest("base64");if(t.headers["sec-websocket-accept"]!==r){abortHandshake(e,i,"Invalid Sec-WebSocket-Accept header");return}const n=t.headers["sec-websocket-protocol"];let l;if(n!==undefined){if(!b.size){l="Server sent a subprotocol but none was requested"}else if(!b.has(n)){l="Server sent an invalid subprotocol"}}else if(b.size){l="Server sent no subprotocol"}if(l){abortHandshake(e,i,l);return}if(n)e._protocol=n;const h=t.headers["sec-websocket-extensions"];if(h!==undefined){if(!k){const t="Server sent a Sec-WebSocket-Extensions header but no extension "+"was requested";abortHandshake(e,i,t);return}let t;try{t=C(h)}catch(t){const s="Invalid Sec-WebSocket-Extensions header";abortHandshake(e,i,s);return}const s=Object.keys(t);if(s.length!==1||s[0]!==a.extensionName){const t="Server indicated an extension that was not requested";abortHandshake(e,i,t);return}try{k.accept(t[a.extensionName])}catch(t){const s="Invalid Sec-WebSocket-Extensions header";abortHandshake(e,i,s);return}e._extensions[a.extensionName]=k}e.setSocket(i,s,{maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})})}function netConnect(e){e.path=e.socketPath;return o.connect(e)}function tlsConnect(e){e.path=undefined;if(!e.servername&&e.servername!==""){e.servername=o.isIP(e.host)?"":e.host}return l.connect(e)}function abortHandshake(e,t,i){e._readyState=WebSocket.CLOSING;const s=new Error(i);Error.captureStackTrace(s,abortHandshake);if(t.setHeader){t.abort();if(t.socket&&!t.socket.destroyed){t.socket.destroy()}t.once("abort",e.emitClose.bind(e));e.emit("error",s)}else{t.destroy(s);t.once("error",e.emit.bind(e,"error"));t.once("close",e.emitClose.bind(e))}}function sendAfterClose(e,t,i){if(t){const i=m(t).length;if(e._socket)e._sender._bufferedBytes+=i;else e._bufferedAmount+=i}if(i){const t=new Error(`WebSocket is not open: readyState ${e.readyState} `+`(${T[e.readyState]})`);i(t)}}function receiverOnConclude(e,t){const i=this[g];i._closeFrameReceived=true;i._closeMessage=t;i._closeCode=e;if(i._socket[g]===undefined)return;i._socket.removeListener("data",socketOnData);process.nextTick(resume,i._socket);if(e===1005)i.close();else i.close(e,t)}function receiverOnDrain(){this[g]._socket.resume()}function receiverOnError(e){const t=this[g];if(t._socket[g]!==undefined){t._socket.removeListener("data",socketOnData);process.nextTick(resume,t._socket);t.close(e[E])}t.emit("error",e)}function receiverOnFinish(){this[g].emitClose()}function receiverOnMessage(e,t){this[g].emit("message",e,t)}function receiverOnPing(e){const t=this[g];t.pong(e,!t._isServer,w);t.emit("ping",e)}function receiverOnPong(e){this[g].emit("pong",e)}function resume(e){e.resume()}function socketOnClose(){const e=this[g];this.removeListener("close",socketOnClose);this.removeListener("data",socketOnData);this.removeListener("end",socketOnEnd);e._readyState=WebSocket.CLOSING;let t;if(!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&(t=e._socket.read())!==null){e._receiver.write(t)}e._receiver.end();this[g]=undefined;clearTimeout(e._closeTimer);if(e._receiver._writableState.finished||e._receiver._writableState.errorEmitted){e.emitClose()}else{e._receiver.on("error",receiverOnFinish);e._receiver.on("finish",receiverOnFinish)}}function socketOnData(e){if(!this[g]._receiver.write(e)){this.pause()}}function socketOnEnd(){const e=this[g];e._readyState=WebSocket.CLOSING;e._receiver.end();this.end()}function socketOnError(){const e=this[g];this.removeListener("error",socketOnError);this.on("error",w);if(e){e._readyState=WebSocket.CLOSING;this.destroy()}}},269:module=>{module.exports=eval("require")("bufferutil")},592:module=>{module.exports=eval("require")("utf-8-validate")},417:e=>{"use strict";e.exports=require("crypto")},614:e=>{"use strict";e.exports=require("events")},605:e=>{"use strict";e.exports=require("http")},211:e=>{"use strict";e.exports=require("https")},631:e=>{"use strict";e.exports=require("net")},413:e=>{"use strict";e.exports=require("stream")},16:e=>{"use strict";e.exports=require("tls")},835:e=>{"use strict";e.exports=require("url")},761:e=>{"use strict";e.exports=require("zlib")}};var __webpack_module_cache__={};function __nccwpck_require__(e){if(__webpack_module_cache__[e]){return __webpack_module_cache__[e].exports}var t=__webpack_module_cache__[e]={exports:{}};var i=true;try{__webpack_modules__[e](t,t.exports,__nccwpck_require__);i=false}finally{if(i)delete __webpack_module_cache__[e]}return t.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(867)})();