engine.io-client
Advanced tools
Comparing version 6.2.3 to 6.3.0
@@ -6,8 +6,20 @@ "use strict"; | ||
/** | ||
* Parses an URI | ||
* Parses a URI | ||
* | ||
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms. | ||
* | ||
* See: | ||
* - https://developer.mozilla.org/en-US/docs/Web/API/URL | ||
* - https://caniuse.com/url | ||
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B | ||
* | ||
* History of the parse() method: | ||
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c | ||
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3 | ||
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242 | ||
* | ||
* @author Steven Levithan <stevenlevithan.com> (MIT license) | ||
* @api private | ||
*/ | ||
const re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; | ||
const re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; | ||
const parts = [ | ||
@@ -14,0 +26,0 @@ 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor' |
@@ -19,8 +19,8 @@ "use strict"; | ||
* | ||
* @param {String|Object} uri or options | ||
* @param {String|Object} uri - uri or options | ||
* @param {Object} opts - options | ||
* @api public | ||
*/ | ||
constructor(uri, opts = {}) { | ||
super(); | ||
this.writeBuffer = []; | ||
if (uri && "object" === typeof uri) { | ||
@@ -61,3 +61,2 @@ opts = uri; | ||
this.transports = opts.transports || ["polling", "websocket"]; | ||
this.readyState = ""; | ||
this.writeBuffer = []; | ||
@@ -72,10 +71,13 @@ this.prevBufferLen = 0; | ||
rememberUpgrade: false, | ||
addTrailingSlash: true, | ||
rejectUnauthorized: true, | ||
perMessageDeflate: { | ||
threshold: 1024 | ||
threshold: 1024, | ||
}, | ||
transportOptions: {}, | ||
closeOnBeforeunload: true | ||
closeOnBeforeunload: true, | ||
}, opts); | ||
this.opts.path = this.opts.path.replace(/\/$/, "") + "/"; | ||
this.opts.path = | ||
this.opts.path.replace(/\/$/, "") + | ||
(this.opts.addTrailingSlash ? "/" : ""); | ||
if (typeof this.opts.query === "string") { | ||
@@ -108,3 +110,3 @@ this.opts.query = (0, parseqs_js_1.decode)(this.opts.query); | ||
this.onClose("transport close", { | ||
description: "network connection lost" | ||
description: "network connection lost", | ||
}); | ||
@@ -120,5 +122,5 @@ }; | ||
* | ||
* @param {String} transport name | ||
* @param {String} name - transport name | ||
* @return {Transport} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -140,3 +142,3 @@ createTransport(name) { | ||
secure: this.secure, | ||
port: this.port | ||
port: this.port, | ||
}); | ||
@@ -149,3 +151,3 @@ debug("options: %j", opts); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -186,3 +188,3 @@ open() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -202,3 +204,3 @@ setTransport(transport) { | ||
.on("error", this.onError.bind(this)) | ||
.on("close", reason => this.onClose("transport close", reason)); | ||
.on("close", (reason) => this.onClose("transport close", reason)); | ||
} | ||
@@ -208,4 +210,4 @@ /** | ||
* | ||
* @param {String} transport name | ||
* @api private | ||
* @param {String} name - transport name | ||
* @private | ||
*/ | ||
@@ -222,3 +224,3 @@ probe(name) { | ||
transport.send([{ type: "ping", data: "probe" }]); | ||
transport.once("packet", msg => { | ||
transport.once("packet", (msg) => { | ||
if (failed) | ||
@@ -268,3 +270,3 @@ return; | ||
// Handle any error that happens while probing | ||
const onerror = err => { | ||
const onerror = (err) => { | ||
const error = new Error("probe error: " + err); | ||
@@ -309,3 +311,3 @@ // @ts-ignore | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -320,5 +322,3 @@ onOpen() { | ||
// listener already closed the socket | ||
if ("open" === this.readyState && | ||
this.opts.upgrade && | ||
this.transport.pause) { | ||
if ("open" === this.readyState && this.opts.upgrade) { | ||
debug("starting upgrade probes"); | ||
@@ -335,3 +335,3 @@ let i = 0; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -376,3 +376,3 @@ onPacket(packet) { | ||
* @param {Object} data - handshake obj | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -396,3 +396,3 @@ onHandshake(data) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -411,3 +411,3 @@ resetPingTimeout() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -430,3 +430,3 @@ onDrain() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -478,7 +478,6 @@ flush() { | ||
* | ||
* @param {String} message. | ||
* @param {String} msg - message. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @param {Object} options. | ||
* @return {Socket} for chaining. | ||
* @api public | ||
*/ | ||
@@ -496,7 +495,7 @@ write(msg, options, fn) { | ||
* | ||
* @param {String} packet type. | ||
* @param {String} type: packet type. | ||
* @param {String} data. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @api private | ||
* @param {Function} fn - callback function. | ||
* @private | ||
*/ | ||
@@ -520,3 +519,3 @@ sendPacket(type, data, options, fn) { | ||
data: data, | ||
options: options | ||
options: options, | ||
}; | ||
@@ -531,4 +530,2 @@ this.emitReserved("packetCreate", packet); | ||
* Closes the connection. | ||
* | ||
* @api public | ||
*/ | ||
@@ -575,3 +572,3 @@ close() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -587,3 +584,3 @@ onError(err) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -622,5 +619,4 @@ onClose(reason, description) { | ||
* | ||
* @param {Array} server upgrades | ||
* @api private | ||
* | ||
* @param {Array} upgrades - server upgrades | ||
* @private | ||
*/ | ||
@@ -627,0 +623,0 @@ filterUpgrades(upgrades) { |
@@ -24,4 +24,4 @@ "use strict"; | ||
* | ||
* @param {Object} options. | ||
* @api private | ||
* @param {Object} opts - options | ||
* @protected | ||
*/ | ||
@@ -34,3 +34,2 @@ constructor(opts) { | ||
this.query = opts.query; | ||
this.readyState = ""; | ||
this.socket = opts.socket; | ||
@@ -45,3 +44,3 @@ } | ||
* @return {Transport} for chaining | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -54,10 +53,6 @@ onError(reason, description, context) { | ||
* Opens the transport. | ||
* | ||
* @api public | ||
*/ | ||
open() { | ||
if ("closed" === this.readyState || "" === this.readyState) { | ||
this.readyState = "opening"; | ||
this.doOpen(); | ||
} | ||
this.readyState = "opening"; | ||
this.doOpen(); | ||
return this; | ||
@@ -67,7 +62,5 @@ } | ||
* Closes the transport. | ||
* | ||
* @api public | ||
*/ | ||
close() { | ||
if ("opening" === this.readyState || "open" === this.readyState) { | ||
if (this.readyState === "opening" || this.readyState === "open") { | ||
this.doClose(); | ||
@@ -82,6 +75,5 @@ this.onClose(); | ||
* @param {Array} packets | ||
* @api public | ||
*/ | ||
send(packets) { | ||
if ("open" === this.readyState) { | ||
if (this.readyState === "open") { | ||
this.write(packets); | ||
@@ -97,3 +89,3 @@ } | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -109,3 +101,3 @@ onOpen() { | ||
* @param {String} data | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -119,3 +111,3 @@ onData(data) { | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -128,3 +120,3 @@ onPacket(packet) { | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -135,3 +127,9 @@ onClose(details) { | ||
} | ||
/** | ||
* Pauses the transport, in order not to lose packets during an upgrade. | ||
* | ||
* @param onPause | ||
*/ | ||
pause(onPause) { } | ||
} | ||
exports.Transport = Transport; |
@@ -8,3 +8,3 @@ "use strict"; | ||
websocket: websocket_js_1.WS, | ||
polling: polling_js_1.Polling | ||
polling: polling_js_1.Polling, | ||
}; |
@@ -20,3 +20,3 @@ "use strict"; | ||
const xhr = new xmlhttprequest_js_1.XHR({ | ||
xdomain: false | ||
xdomain: false, | ||
}); | ||
@@ -30,3 +30,3 @@ return null != xhr.responseType; | ||
* @param {Object} opts | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -55,5 +55,2 @@ constructor(opts) { | ||
} | ||
/** | ||
* Transport name. | ||
*/ | ||
get name() { | ||
@@ -66,3 +63,3 @@ return "polling"; | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -75,4 +72,4 @@ doOpen() { | ||
* | ||
* @param {Function} callback upon buffers are flushed and transport is paused | ||
* @api private | ||
* @param {Function} onPause - callback upon buffers are flushed and transport is paused | ||
* @package | ||
*/ | ||
@@ -112,3 +109,3 @@ pause(onPause) { | ||
* | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -124,7 +121,7 @@ poll() { | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
onData(data) { | ||
debug("polling got data %s", data); | ||
const callback = packet => { | ||
const callback = (packet) => { | ||
// if its the first message we consider the transport open | ||
@@ -160,3 +157,3 @@ if ("opening" === this.readyState && packet.type === "open") { | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -182,9 +179,8 @@ doClose() { | ||
* | ||
* @param {Array} data packets | ||
* @param {Function} drain callback | ||
* @api private | ||
* @param {Array} packets - data packets | ||
* @protected | ||
*/ | ||
write(packets) { | ||
this.writable = false; | ||
(0, engine_io_parser_1.encodePayload)(packets, data => { | ||
(0, engine_io_parser_1.encodePayload)(packets, (data) => { | ||
this.doWrite(data, () => { | ||
@@ -199,3 +195,3 @@ this.writable = true; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -232,3 +228,3 @@ uri() { | ||
* @param {String} method | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -244,3 +240,3 @@ request(opts = {}) { | ||
* @param {Function} called upon flush. | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -250,3 +246,3 @@ doWrite(data, fn) { | ||
method: "POST", | ||
data: data | ||
data: data, | ||
}); | ||
@@ -261,3 +257,3 @@ req.on("success", fn); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -280,3 +276,3 @@ doPoll() { | ||
* @param {Object} options | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -296,3 +292,3 @@ constructor(uri, opts) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -369,3 +365,3 @@ create() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -379,3 +375,3 @@ onError(err) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -401,3 +397,3 @@ cleanup(fromError) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -415,3 +411,3 @@ onLoad() { | ||
* | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -418,0 +414,0 @@ abort() { |
@@ -8,3 +8,3 @@ "use strict"; | ||
if (isPromiseAvailable) { | ||
return cb => Promise.resolve().then(cb); | ||
return (cb) => Promise.resolve().then(cb); | ||
} | ||
@@ -11,0 +11,0 @@ else { |
@@ -23,4 +23,4 @@ "use strict"; | ||
* | ||
* @api {Object} connection options | ||
* @api public | ||
* @param {Object} opts - connection options | ||
* @protected | ||
*/ | ||
@@ -31,15 +31,5 @@ constructor(opts) { | ||
} | ||
/** | ||
* Transport name. | ||
* | ||
* @api public | ||
*/ | ||
get name() { | ||
return "websocket"; | ||
} | ||
/** | ||
* Opens socket. | ||
* | ||
* @api private | ||
*/ | ||
doOpen() { | ||
@@ -76,3 +66,3 @@ if (!this.check()) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -86,15 +76,9 @@ addEventListeners() { | ||
}; | ||
this.ws.onclose = closeEvent => this.onClose({ | ||
this.ws.onclose = (closeEvent) => this.onClose({ | ||
description: "websocket connection closed", | ||
context: closeEvent | ||
context: closeEvent, | ||
}); | ||
this.ws.onmessage = ev => this.onData(ev.data); | ||
this.ws.onerror = e => this.onError("websocket error", e); | ||
this.ws.onmessage = (ev) => this.onData(ev.data); | ||
this.ws.onerror = (e) => this.onError("websocket error", e); | ||
} | ||
/** | ||
* Writes data to socket. | ||
* | ||
* @param {Array} array of packets. | ||
* @api private | ||
*/ | ||
write(packets) { | ||
@@ -107,3 +91,3 @@ this.writable = false; | ||
const lastPacket = i === packets.length - 1; | ||
(0, engine_io_parser_1.encodePacket)(packet, this.supportsBinary, data => { | ||
(0, engine_io_parser_1.encodePacket)(packet, this.supportsBinary, (data) => { | ||
// always create a new object (GH-437) | ||
@@ -150,7 +134,2 @@ const opts = {}; | ||
} | ||
/** | ||
* Closes socket. | ||
* | ||
* @api private | ||
*/ | ||
doClose() { | ||
@@ -165,3 +144,3 @@ if (typeof this.ws !== "undefined") { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -199,3 +178,3 @@ uri() { | ||
* @return {Boolean} whether this transport is available. | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -202,0 +181,0 @@ check() { |
@@ -15,4 +15,4 @@ "use strict"; | ||
// Keep a reference to the real timeout functions so they can be used when overridden | ||
const NATIVE_SET_TIMEOUT = setTimeout; | ||
const NATIVE_CLEAR_TIMEOUT = clearTimeout; | ||
const NATIVE_SET_TIMEOUT = globalThis_js_1.globalThisShim.setTimeout; | ||
const NATIVE_CLEAR_TIMEOUT = globalThis_js_1.globalThisShim.clearTimeout; | ||
function installTimerFunctions(obj, opts) { | ||
@@ -24,4 +24,4 @@ if (opts.useNativeTimers) { | ||
else { | ||
obj.setTimeoutFn = setTimeout.bind(globalThis_js_1.globalThisShim); | ||
obj.clearTimeoutFn = clearTimeout.bind(globalThis_js_1.globalThisShim); | ||
obj.setTimeoutFn = globalThis_js_1.globalThisShim.setTimeout.bind(globalThis_js_1.globalThisShim); | ||
obj.clearTimeoutFn = globalThis_js_1.globalThisShim.clearTimeout.bind(globalThis_js_1.globalThisShim); | ||
} | ||
@@ -28,0 +28,0 @@ } |
// imported from https://github.com/galkn/parseuri | ||
/** | ||
* Parses an URI | ||
* Parses a URI | ||
* | ||
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms. | ||
* | ||
* See: | ||
* - https://developer.mozilla.org/en-US/docs/Web/API/URL | ||
* - https://caniuse.com/url | ||
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B | ||
* | ||
* History of the parse() method: | ||
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c | ||
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3 | ||
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242 | ||
* | ||
* @author Steven Levithan <stevenlevithan.com> (MIT license) | ||
* @api private | ||
*/ | ||
const re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; | ||
const re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; | ||
const parts = [ | ||
@@ -10,0 +22,0 @@ 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor' |
import { Emitter } from "@socket.io/component-emitter"; | ||
import { CloseDetails } from "./transport.js"; | ||
import { type Packet, type BinaryType, RawData } from "engine.io-parser"; | ||
import { CloseDetails, Transport } from "./transport.js"; | ||
export interface SocketOptions { | ||
@@ -62,7 +63,2 @@ /** | ||
/** | ||
* The port the policy server listens on | ||
* @default 843 | ||
*/ | ||
policyPost: number; | ||
/** | ||
* If true and if the previous websocket connection to the server succeeded, | ||
@@ -178,2 +174,7 @@ * the connection attempt will bypass the normal upgrade process and will | ||
/** | ||
* Whether we should add a trailing slash to the request path. | ||
* @default true | ||
*/ | ||
addTrailingSlash: boolean; | ||
/** | ||
* Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, | ||
@@ -186,7 +187,14 @@ * so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to | ||
} | ||
interface HandshakeData { | ||
sid: string; | ||
upgrades: string[]; | ||
pingInterval: number; | ||
pingTimeout: number; | ||
maxPayload: number; | ||
} | ||
interface SocketReservedEvents { | ||
open: () => void; | ||
handshake: (data: any) => void; | ||
packet: (packet: any) => void; | ||
packetCreate: (packet: any) => void; | ||
handshake: (data: HandshakeData) => void; | ||
packet: (packet: Packet) => void; | ||
packetCreate: (packet: Packet) => void; | ||
data: (data: any) => void; | ||
@@ -205,8 +213,9 @@ message: (data: any) => void; | ||
} | ||
export declare class Socket extends Emitter<{}, {}, SocketReservedEvents> { | ||
declare type SocketState = "opening" | "open" | "closing" | "closed"; | ||
export declare class Socket extends Emitter<Record<never, never>, Record<never, never>, SocketReservedEvents> { | ||
id: string; | ||
transport: any; | ||
binaryType: string; | ||
private readyState; | ||
private writeBuffer; | ||
transport: Transport; | ||
binaryType: BinaryType; | ||
readyState: SocketState; | ||
writeBuffer: Packet[]; | ||
private prevBufferLen; | ||
@@ -233,5 +242,4 @@ private upgrades; | ||
* | ||
* @param {String|Object} uri or options | ||
* @param {String|Object} uri - uri or options | ||
* @param {Object} opts - options | ||
* @api public | ||
*/ | ||
@@ -242,5 +250,5 @@ constructor(uri: any, opts?: Partial<SocketOptions>); | ||
* | ||
* @param {String} transport name | ||
* @param {String} name - transport name | ||
* @return {Transport} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -251,3 +259,3 @@ private createTransport; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -258,3 +266,3 @@ private open; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -265,4 +273,4 @@ private setTransport; | ||
* | ||
* @param {String} transport name | ||
* @api private | ||
* @param {String} name - transport name | ||
* @private | ||
*/ | ||
@@ -273,3 +281,3 @@ private probe; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -280,3 +288,3 @@ private onOpen; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -288,3 +296,3 @@ private onPacket; | ||
* @param {Object} data - handshake obj | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -295,3 +303,3 @@ private onHandshake; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -302,3 +310,3 @@ private resetPingTimeout; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -309,3 +317,3 @@ private onDrain; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -323,18 +331,17 @@ private flush; | ||
* | ||
* @param {String} message. | ||
* @param {String} msg - message. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @param {Object} options. | ||
* @return {Socket} for chaining. | ||
* @api public | ||
*/ | ||
write(msg: any, options: any, fn?: any): this; | ||
send(msg: any, options: any, fn?: any): this; | ||
write(msg: RawData, options?: any, fn?: any): this; | ||
send(msg: RawData, options?: any, fn?: any): this; | ||
/** | ||
* Sends a packet. | ||
* | ||
* @param {String} packet type. | ||
* @param {String} type: packet type. | ||
* @param {String} data. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @api private | ||
* @param {Function} fn - callback function. | ||
* @private | ||
*/ | ||
@@ -344,4 +351,2 @@ private sendPacket; | ||
* Closes the connection. | ||
* | ||
* @api public | ||
*/ | ||
@@ -352,3 +357,3 @@ close(): this; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -359,3 +364,3 @@ private onError; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -366,5 +371,4 @@ private onClose; | ||
* | ||
* @param {Array} server upgrades | ||
* @api private | ||
* | ||
* @param {Array} upgrades - server upgrades | ||
* @private | ||
*/ | ||
@@ -371,0 +375,0 @@ private filterUpgrades; |
@@ -7,3 +7,3 @@ import { transports } from "./transports/index.js"; | ||
import { Emitter } from "@socket.io/component-emitter"; | ||
import { protocol } from "engine.io-parser"; | ||
import { protocol, } from "engine.io-parser"; | ||
const debug = debugModule("engine.io-client:socket"); // debug() | ||
@@ -14,8 +14,8 @@ export class Socket extends Emitter { | ||
* | ||
* @param {String|Object} uri or options | ||
* @param {String|Object} uri - uri or options | ||
* @param {Object} opts - options | ||
* @api public | ||
*/ | ||
constructor(uri, opts = {}) { | ||
super(); | ||
this.writeBuffer = []; | ||
if (uri && "object" === typeof uri) { | ||
@@ -56,3 +56,2 @@ opts = uri; | ||
this.transports = opts.transports || ["polling", "websocket"]; | ||
this.readyState = ""; | ||
this.writeBuffer = []; | ||
@@ -67,10 +66,13 @@ this.prevBufferLen = 0; | ||
rememberUpgrade: false, | ||
addTrailingSlash: true, | ||
rejectUnauthorized: true, | ||
perMessageDeflate: { | ||
threshold: 1024 | ||
threshold: 1024, | ||
}, | ||
transportOptions: {}, | ||
closeOnBeforeunload: true | ||
closeOnBeforeunload: true, | ||
}, opts); | ||
this.opts.path = this.opts.path.replace(/\/$/, "") + "/"; | ||
this.opts.path = | ||
this.opts.path.replace(/\/$/, "") + | ||
(this.opts.addTrailingSlash ? "/" : ""); | ||
if (typeof this.opts.query === "string") { | ||
@@ -103,3 +105,3 @@ this.opts.query = decode(this.opts.query); | ||
this.onClose("transport close", { | ||
description: "network connection lost" | ||
description: "network connection lost", | ||
}); | ||
@@ -115,5 +117,5 @@ }; | ||
* | ||
* @param {String} transport name | ||
* @param {String} name - transport name | ||
* @return {Transport} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -135,3 +137,3 @@ createTransport(name) { | ||
secure: this.secure, | ||
port: this.port | ||
port: this.port, | ||
}); | ||
@@ -144,3 +146,3 @@ debug("options: %j", opts); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -181,3 +183,3 @@ open() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -197,3 +199,3 @@ setTransport(transport) { | ||
.on("error", this.onError.bind(this)) | ||
.on("close", reason => this.onClose("transport close", reason)); | ||
.on("close", (reason) => this.onClose("transport close", reason)); | ||
} | ||
@@ -203,4 +205,4 @@ /** | ||
* | ||
* @param {String} transport name | ||
* @api private | ||
* @param {String} name - transport name | ||
* @private | ||
*/ | ||
@@ -217,3 +219,3 @@ probe(name) { | ||
transport.send([{ type: "ping", data: "probe" }]); | ||
transport.once("packet", msg => { | ||
transport.once("packet", (msg) => { | ||
if (failed) | ||
@@ -263,3 +265,3 @@ return; | ||
// Handle any error that happens while probing | ||
const onerror = err => { | ||
const onerror = (err) => { | ||
const error = new Error("probe error: " + err); | ||
@@ -304,3 +306,3 @@ // @ts-ignore | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -315,5 +317,3 @@ onOpen() { | ||
// listener already closed the socket | ||
if ("open" === this.readyState && | ||
this.opts.upgrade && | ||
this.transport.pause) { | ||
if ("open" === this.readyState && this.opts.upgrade) { | ||
debug("starting upgrade probes"); | ||
@@ -330,3 +330,3 @@ let i = 0; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -371,3 +371,3 @@ onPacket(packet) { | ||
* @param {Object} data - handshake obj | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -391,3 +391,3 @@ onHandshake(data) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -406,3 +406,3 @@ resetPingTimeout() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -425,3 +425,3 @@ onDrain() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -473,7 +473,6 @@ flush() { | ||
* | ||
* @param {String} message. | ||
* @param {String} msg - message. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @param {Object} options. | ||
* @return {Socket} for chaining. | ||
* @api public | ||
*/ | ||
@@ -491,7 +490,7 @@ write(msg, options, fn) { | ||
* | ||
* @param {String} packet type. | ||
* @param {String} type: packet type. | ||
* @param {String} data. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @api private | ||
* @param {Function} fn - callback function. | ||
* @private | ||
*/ | ||
@@ -515,3 +514,3 @@ sendPacket(type, data, options, fn) { | ||
data: data, | ||
options: options | ||
options: options, | ||
}; | ||
@@ -526,4 +525,2 @@ this.emitReserved("packetCreate", packet); | ||
* Closes the connection. | ||
* | ||
* @api public | ||
*/ | ||
@@ -570,3 +567,3 @@ close() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -582,3 +579,3 @@ onError(err) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -617,5 +614,4 @@ onClose(reason, description) { | ||
* | ||
* @param {Array} server upgrades | ||
* @api private | ||
* | ||
* @param {Array} upgrades - server upgrades | ||
* @private | ||
*/ | ||
@@ -622,0 +618,0 @@ filterUpgrades(upgrades) { |
@@ -1,2 +0,2 @@ | ||
import { Packet, RawData } from "engine.io-parser"; | ||
import { type Packet, type RawData } from "engine.io-parser"; | ||
import { Emitter } from "@socket.io/component-emitter"; | ||
@@ -23,8 +23,9 @@ import { SocketOptions } from "./socket.js"; | ||
} | ||
export declare abstract class Transport extends Emitter<{}, {}, TransportReservedEvents> { | ||
declare type TransportState = "opening" | "open" | "closed" | "pausing" | "paused"; | ||
export declare abstract class Transport extends Emitter<Record<never, never>, Record<never, never>, TransportReservedEvents> { | ||
query: Record<string, string>; | ||
writable: boolean; | ||
protected opts: SocketOptions; | ||
protected supportsBinary: boolean; | ||
protected query: object; | ||
protected readyState: string; | ||
protected writable: boolean; | ||
protected readyState: TransportState; | ||
protected socket: any; | ||
@@ -35,4 +36,4 @@ protected setTimeoutFn: typeof setTimeout; | ||
* | ||
* @param {Object} options. | ||
* @api private | ||
* @param {Object} opts - options | ||
* @protected | ||
*/ | ||
@@ -47,3 +48,3 @@ constructor(opts: any); | ||
* @return {Transport} for chaining | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -53,10 +54,6 @@ protected onError(reason: string, description: any, context?: any): this; | ||
* Opens the transport. | ||
* | ||
* @api public | ||
*/ | ||
private open; | ||
open(): this; | ||
/** | ||
* Closes the transport. | ||
* | ||
* @api public | ||
*/ | ||
@@ -68,3 +65,2 @@ close(): this; | ||
* @param {Array} packets | ||
* @api public | ||
*/ | ||
@@ -75,3 +71,3 @@ send(packets: any): void; | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -83,3 +79,3 @@ protected onOpen(): void; | ||
* @param {String} data | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -90,3 +86,3 @@ protected onData(data: RawData): void; | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -97,9 +93,19 @@ protected onPacket(packet: Packet): void; | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
protected onClose(details?: CloseDetails): void; | ||
/** | ||
* The name of the transport | ||
*/ | ||
abstract get name(): string; | ||
/** | ||
* Pauses the transport, in order not to lose packets during an upgrade. | ||
* | ||
* @param onPause | ||
*/ | ||
pause(onPause: () => void): void; | ||
protected abstract doOpen(): any; | ||
protected abstract doClose(): any; | ||
protected abstract write(packets: any): any; | ||
protected abstract write(packets: Packet[]): any; | ||
} | ||
export {}; |
@@ -18,4 +18,4 @@ import { decodePacket } from "engine.io-parser"; | ||
* | ||
* @param {Object} options. | ||
* @api private | ||
* @param {Object} opts - options | ||
* @protected | ||
*/ | ||
@@ -28,3 +28,2 @@ constructor(opts) { | ||
this.query = opts.query; | ||
this.readyState = ""; | ||
this.socket = opts.socket; | ||
@@ -39,3 +38,3 @@ } | ||
* @return {Transport} for chaining | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -48,10 +47,6 @@ onError(reason, description, context) { | ||
* Opens the transport. | ||
* | ||
* @api public | ||
*/ | ||
open() { | ||
if ("closed" === this.readyState || "" === this.readyState) { | ||
this.readyState = "opening"; | ||
this.doOpen(); | ||
} | ||
this.readyState = "opening"; | ||
this.doOpen(); | ||
return this; | ||
@@ -61,7 +56,5 @@ } | ||
* Closes the transport. | ||
* | ||
* @api public | ||
*/ | ||
close() { | ||
if ("opening" === this.readyState || "open" === this.readyState) { | ||
if (this.readyState === "opening" || this.readyState === "open") { | ||
this.doClose(); | ||
@@ -76,6 +69,5 @@ this.onClose(); | ||
* @param {Array} packets | ||
* @api public | ||
*/ | ||
send(packets) { | ||
if ("open" === this.readyState) { | ||
if (this.readyState === "open") { | ||
this.write(packets); | ||
@@ -91,3 +83,3 @@ } | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -103,3 +95,3 @@ onOpen() { | ||
* @param {String} data | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -113,3 +105,3 @@ onData(data) { | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -122,3 +114,3 @@ onPacket(packet) { | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -129,2 +121,8 @@ onClose(details) { | ||
} | ||
/** | ||
* Pauses the transport, in order not to lose packets during an upgrade. | ||
* | ||
* @param onPause | ||
*/ | ||
pause(onPause) { } | ||
} |
@@ -5,3 +5,3 @@ import { Polling } from "./polling.js"; | ||
websocket: WS, | ||
polling: Polling | ||
polling: Polling, | ||
}; |
@@ -13,8 +13,5 @@ import { Transport } from "../transport.js"; | ||
* @param {Object} opts | ||
* @api public | ||
* @package | ||
*/ | ||
constructor(opts: any); | ||
/** | ||
* Transport name. | ||
*/ | ||
get name(): string; | ||
@@ -25,3 +22,3 @@ /** | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -32,4 +29,4 @@ doOpen(): void; | ||
* | ||
* @param {Function} callback upon buffers are flushed and transport is paused | ||
* @api private | ||
* @param {Function} onPause - callback upon buffers are flushed and transport is paused | ||
* @package | ||
*/ | ||
@@ -40,3 +37,3 @@ pause(onPause: any): void; | ||
* | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -47,3 +44,3 @@ poll(): void; | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -54,3 +51,3 @@ onData(data: any): void; | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -61,5 +58,4 @@ doClose(): void; | ||
* | ||
* @param {Array} data packets | ||
* @param {Function} drain callback | ||
* @api private | ||
* @param {Array} packets - data packets | ||
* @protected | ||
*/ | ||
@@ -70,3 +66,3 @@ write(packets: any): void; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -78,3 +74,3 @@ uri(): string; | ||
* @param {String} method | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -87,11 +83,11 @@ request(opts?: {}): Request; | ||
* @param {Function} called upon flush. | ||
* @api private | ||
* @private | ||
*/ | ||
doWrite(data: any, fn: any): void; | ||
private doWrite; | ||
/** | ||
* Starts a poll cycle. | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
doPoll(): void; | ||
private doPoll; | ||
} | ||
@@ -118,3 +114,3 @@ interface RequestReservedEvents { | ||
* @param {Object} options | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -125,3 +121,3 @@ constructor(uri: any, opts: any); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -132,3 +128,3 @@ private create; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -139,3 +135,3 @@ private onError; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -146,3 +142,3 @@ private cleanup; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -153,3 +149,3 @@ private onLoad; | ||
* | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -156,0 +152,0 @@ abort(): void; |
@@ -14,3 +14,3 @@ import { Transport } from "../transport.js"; | ||
const xhr = new XMLHttpRequest({ | ||
xdomain: false | ||
xdomain: false, | ||
}); | ||
@@ -24,3 +24,3 @@ return null != xhr.responseType; | ||
* @param {Object} opts | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -49,5 +49,2 @@ constructor(opts) { | ||
} | ||
/** | ||
* Transport name. | ||
*/ | ||
get name() { | ||
@@ -60,3 +57,3 @@ return "polling"; | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -69,4 +66,4 @@ doOpen() { | ||
* | ||
* @param {Function} callback upon buffers are flushed and transport is paused | ||
* @api private | ||
* @param {Function} onPause - callback upon buffers are flushed and transport is paused | ||
* @package | ||
*/ | ||
@@ -106,3 +103,3 @@ pause(onPause) { | ||
* | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -118,7 +115,7 @@ poll() { | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
onData(data) { | ||
debug("polling got data %s", data); | ||
const callback = packet => { | ||
const callback = (packet) => { | ||
// if its the first message we consider the transport open | ||
@@ -154,3 +151,3 @@ if ("opening" === this.readyState && packet.type === "open") { | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -176,9 +173,8 @@ doClose() { | ||
* | ||
* @param {Array} data packets | ||
* @param {Function} drain callback | ||
* @api private | ||
* @param {Array} packets - data packets | ||
* @protected | ||
*/ | ||
write(packets) { | ||
this.writable = false; | ||
encodePayload(packets, data => { | ||
encodePayload(packets, (data) => { | ||
this.doWrite(data, () => { | ||
@@ -193,3 +189,3 @@ this.writable = true; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -226,3 +222,3 @@ uri() { | ||
* @param {String} method | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -238,3 +234,3 @@ request(opts = {}) { | ||
* @param {Function} called upon flush. | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -244,3 +240,3 @@ doWrite(data, fn) { | ||
method: "POST", | ||
data: data | ||
data: data, | ||
}); | ||
@@ -255,3 +251,3 @@ req.on("success", fn); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -273,3 +269,3 @@ doPoll() { | ||
* @param {Object} options | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -289,3 +285,3 @@ constructor(uri, opts) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -362,3 +358,3 @@ create() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -372,3 +368,3 @@ onError(err) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -394,3 +390,3 @@ cleanup(fromError) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -408,3 +404,3 @@ onLoad() { | ||
* | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -411,0 +407,0 @@ abort() { |
@@ -5,3 +5,3 @@ import { globalThisShim as globalThis } from "../globalThis.js"; | ||
if (isPromiseAvailable) { | ||
return cb => Promise.resolve().then(cb); | ||
return (cb) => Promise.resolve().then(cb); | ||
} | ||
@@ -8,0 +8,0 @@ else { |
@@ -7,17 +7,7 @@ import { Transport } from "../transport.js"; | ||
* | ||
* @api {Object} connection options | ||
* @api public | ||
* @param {Object} opts - connection options | ||
* @protected | ||
*/ | ||
constructor(opts: any); | ||
/** | ||
* Transport name. | ||
* | ||
* @api public | ||
*/ | ||
get name(): string; | ||
/** | ||
* Opens socket. | ||
* | ||
* @api private | ||
*/ | ||
doOpen(): this; | ||
@@ -27,17 +17,6 @@ /** | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
addEventListeners(): void; | ||
/** | ||
* Writes data to socket. | ||
* | ||
* @param {Array} array of packets. | ||
* @api private | ||
*/ | ||
private addEventListeners; | ||
write(packets: any): void; | ||
/** | ||
* Closes socket. | ||
* | ||
* @api private | ||
*/ | ||
doClose(): void; | ||
@@ -47,3 +26,3 @@ /** | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -55,5 +34,5 @@ uri(): string; | ||
* @return {Boolean} whether this transport is available. | ||
* @api public | ||
* @private | ||
*/ | ||
check(): boolean; | ||
private check; | ||
} |
@@ -5,3 +5,3 @@ import { Transport } from "../transport.js"; | ||
import { pick } from "../util.js"; | ||
import { defaultBinaryType, nextTick, usingBrowserWebSocket, WebSocket } from "./websocket-constructor.js"; | ||
import { defaultBinaryType, nextTick, usingBrowserWebSocket, WebSocket, } from "./websocket-constructor.js"; | ||
import debugModule from "debug"; // debug() | ||
@@ -18,4 +18,4 @@ import { encodePacket } from "engine.io-parser"; | ||
* | ||
* @api {Object} connection options | ||
* @api public | ||
* @param {Object} opts - connection options | ||
* @protected | ||
*/ | ||
@@ -26,15 +26,5 @@ constructor(opts) { | ||
} | ||
/** | ||
* Transport name. | ||
* | ||
* @api public | ||
*/ | ||
get name() { | ||
return "websocket"; | ||
} | ||
/** | ||
* Opens socket. | ||
* | ||
* @api private | ||
*/ | ||
doOpen() { | ||
@@ -71,3 +61,3 @@ if (!this.check()) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -81,15 +71,9 @@ addEventListeners() { | ||
}; | ||
this.ws.onclose = closeEvent => this.onClose({ | ||
this.ws.onclose = (closeEvent) => this.onClose({ | ||
description: "websocket connection closed", | ||
context: closeEvent | ||
context: closeEvent, | ||
}); | ||
this.ws.onmessage = ev => this.onData(ev.data); | ||
this.ws.onerror = e => this.onError("websocket error", e); | ||
this.ws.onmessage = (ev) => this.onData(ev.data); | ||
this.ws.onerror = (e) => this.onError("websocket error", e); | ||
} | ||
/** | ||
* Writes data to socket. | ||
* | ||
* @param {Array} array of packets. | ||
* @api private | ||
*/ | ||
write(packets) { | ||
@@ -102,3 +86,3 @@ this.writable = false; | ||
const lastPacket = i === packets.length - 1; | ||
encodePacket(packet, this.supportsBinary, data => { | ||
encodePacket(packet, this.supportsBinary, (data) => { | ||
// always create a new object (GH-437) | ||
@@ -145,7 +129,2 @@ const opts = {}; | ||
} | ||
/** | ||
* Closes socket. | ||
* | ||
* @api private | ||
*/ | ||
doClose() { | ||
@@ -160,3 +139,3 @@ if (typeof this.ws !== "undefined") { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -194,3 +173,3 @@ uri() { | ||
* @return {Boolean} whether this transport is available. | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -197,0 +176,0 @@ check() { |
@@ -11,4 +11,4 @@ import { globalThisShim as globalThis } from "./globalThis.js"; | ||
// Keep a reference to the real timeout functions so they can be used when overridden | ||
const NATIVE_SET_TIMEOUT = setTimeout; | ||
const NATIVE_CLEAR_TIMEOUT = clearTimeout; | ||
const NATIVE_SET_TIMEOUT = globalThis.setTimeout; | ||
const NATIVE_CLEAR_TIMEOUT = globalThis.clearTimeout; | ||
export function installTimerFunctions(obj, opts) { | ||
@@ -20,4 +20,4 @@ if (opts.useNativeTimers) { | ||
else { | ||
obj.setTimeoutFn = setTimeout.bind(globalThis); | ||
obj.clearTimeoutFn = clearTimeout.bind(globalThis); | ||
obj.setTimeoutFn = globalThis.setTimeout.bind(globalThis); | ||
obj.clearTimeoutFn = globalThis.clearTimeout.bind(globalThis); | ||
} | ||
@@ -24,0 +24,0 @@ } |
// imported from https://github.com/galkn/parseuri | ||
/** | ||
* Parses an URI | ||
* Parses a URI | ||
* | ||
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms. | ||
* | ||
* See: | ||
* - https://developer.mozilla.org/en-US/docs/Web/API/URL | ||
* - https://caniuse.com/url | ||
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B | ||
* | ||
* History of the parse() method: | ||
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c | ||
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3 | ||
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242 | ||
* | ||
* @author Steven Levithan <stevenlevithan.com> (MIT license) | ||
* @api private | ||
*/ | ||
const re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; | ||
const re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; | ||
const parts = [ | ||
@@ -10,0 +22,0 @@ 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor' |
import { Emitter } from "@socket.io/component-emitter"; | ||
import { CloseDetails } from "./transport.js"; | ||
import { type Packet, type BinaryType, RawData } from "engine.io-parser"; | ||
import { CloseDetails, Transport } from "./transport.js"; | ||
export interface SocketOptions { | ||
@@ -62,7 +63,2 @@ /** | ||
/** | ||
* The port the policy server listens on | ||
* @default 843 | ||
*/ | ||
policyPost: number; | ||
/** | ||
* If true and if the previous websocket connection to the server succeeded, | ||
@@ -178,2 +174,7 @@ * the connection attempt will bypass the normal upgrade process and will | ||
/** | ||
* Whether we should add a trailing slash to the request path. | ||
* @default true | ||
*/ | ||
addTrailingSlash: boolean; | ||
/** | ||
* Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, | ||
@@ -186,7 +187,14 @@ * so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to | ||
} | ||
interface HandshakeData { | ||
sid: string; | ||
upgrades: string[]; | ||
pingInterval: number; | ||
pingTimeout: number; | ||
maxPayload: number; | ||
} | ||
interface SocketReservedEvents { | ||
open: () => void; | ||
handshake: (data: any) => void; | ||
packet: (packet: any) => void; | ||
packetCreate: (packet: any) => void; | ||
handshake: (data: HandshakeData) => void; | ||
packet: (packet: Packet) => void; | ||
packetCreate: (packet: Packet) => void; | ||
data: (data: any) => void; | ||
@@ -205,8 +213,9 @@ message: (data: any) => void; | ||
} | ||
export declare class Socket extends Emitter<{}, {}, SocketReservedEvents> { | ||
declare type SocketState = "opening" | "open" | "closing" | "closed"; | ||
export declare class Socket extends Emitter<Record<never, never>, Record<never, never>, SocketReservedEvents> { | ||
id: string; | ||
transport: any; | ||
binaryType: string; | ||
private readyState; | ||
private writeBuffer; | ||
transport: Transport; | ||
binaryType: BinaryType; | ||
readyState: SocketState; | ||
writeBuffer: Packet[]; | ||
private prevBufferLen; | ||
@@ -233,5 +242,4 @@ private upgrades; | ||
* | ||
* @param {String|Object} uri or options | ||
* @param {String|Object} uri - uri or options | ||
* @param {Object} opts - options | ||
* @api public | ||
*/ | ||
@@ -242,5 +250,5 @@ constructor(uri: any, opts?: Partial<SocketOptions>); | ||
* | ||
* @param {String} transport name | ||
* @param {String} name - transport name | ||
* @return {Transport} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -251,3 +259,3 @@ private createTransport; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -258,3 +266,3 @@ private open; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -265,4 +273,4 @@ private setTransport; | ||
* | ||
* @param {String} transport name | ||
* @api private | ||
* @param {String} name - transport name | ||
* @private | ||
*/ | ||
@@ -273,3 +281,3 @@ private probe; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -280,3 +288,3 @@ private onOpen; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -288,3 +296,3 @@ private onPacket; | ||
* @param {Object} data - handshake obj | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -295,3 +303,3 @@ private onHandshake; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -302,3 +310,3 @@ private resetPingTimeout; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -309,3 +317,3 @@ private onDrain; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -323,18 +331,17 @@ private flush; | ||
* | ||
* @param {String} message. | ||
* @param {String} msg - message. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @param {Object} options. | ||
* @return {Socket} for chaining. | ||
* @api public | ||
*/ | ||
write(msg: any, options: any, fn?: any): this; | ||
send(msg: any, options: any, fn?: any): this; | ||
write(msg: RawData, options?: any, fn?: any): this; | ||
send(msg: RawData, options?: any, fn?: any): this; | ||
/** | ||
* Sends a packet. | ||
* | ||
* @param {String} packet type. | ||
* @param {String} type: packet type. | ||
* @param {String} data. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @api private | ||
* @param {Function} fn - callback function. | ||
* @private | ||
*/ | ||
@@ -344,4 +351,2 @@ private sendPacket; | ||
* Closes the connection. | ||
* | ||
* @api public | ||
*/ | ||
@@ -352,3 +357,3 @@ close(): this; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -359,3 +364,3 @@ private onError; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -366,5 +371,4 @@ private onClose; | ||
* | ||
* @param {Array} server upgrades | ||
* @api private | ||
* | ||
* @param {Array} upgrades - server upgrades | ||
* @private | ||
*/ | ||
@@ -371,0 +375,0 @@ private filterUpgrades; |
@@ -6,3 +6,3 @@ import { transports } from "./transports/index.js"; | ||
import { Emitter } from "@socket.io/component-emitter"; | ||
import { protocol } from "engine.io-parser"; | ||
import { protocol, } from "engine.io-parser"; | ||
export class Socket extends Emitter { | ||
@@ -12,8 +12,8 @@ /** | ||
* | ||
* @param {String|Object} uri or options | ||
* @param {String|Object} uri - uri or options | ||
* @param {Object} opts - options | ||
* @api public | ||
*/ | ||
constructor(uri, opts = {}) { | ||
super(); | ||
this.writeBuffer = []; | ||
if (uri && "object" === typeof uri) { | ||
@@ -54,3 +54,2 @@ opts = uri; | ||
this.transports = opts.transports || ["polling", "websocket"]; | ||
this.readyState = ""; | ||
this.writeBuffer = []; | ||
@@ -65,10 +64,13 @@ this.prevBufferLen = 0; | ||
rememberUpgrade: false, | ||
addTrailingSlash: true, | ||
rejectUnauthorized: true, | ||
perMessageDeflate: { | ||
threshold: 1024 | ||
threshold: 1024, | ||
}, | ||
transportOptions: {}, | ||
closeOnBeforeunload: true | ||
closeOnBeforeunload: true, | ||
}, opts); | ||
this.opts.path = this.opts.path.replace(/\/$/, "") + "/"; | ||
this.opts.path = | ||
this.opts.path.replace(/\/$/, "") + | ||
(this.opts.addTrailingSlash ? "/" : ""); | ||
if (typeof this.opts.query === "string") { | ||
@@ -101,3 +103,3 @@ this.opts.query = decode(this.opts.query); | ||
this.onClose("transport close", { | ||
description: "network connection lost" | ||
description: "network connection lost", | ||
}); | ||
@@ -113,5 +115,5 @@ }; | ||
* | ||
* @param {String} transport name | ||
* @param {String} name - transport name | ||
* @return {Transport} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -132,3 +134,3 @@ createTransport(name) { | ||
secure: this.secure, | ||
port: this.port | ||
port: this.port, | ||
}); | ||
@@ -140,3 +142,3 @@ return new transports[name](opts); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -176,3 +178,3 @@ open() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -190,3 +192,3 @@ setTransport(transport) { | ||
.on("error", this.onError.bind(this)) | ||
.on("close", reason => this.onClose("transport close", reason)); | ||
.on("close", (reason) => this.onClose("transport close", reason)); | ||
} | ||
@@ -196,4 +198,4 @@ /** | ||
* | ||
* @param {String} transport name | ||
* @api private | ||
* @param {String} name - transport name | ||
* @private | ||
*/ | ||
@@ -208,3 +210,3 @@ probe(name) { | ||
transport.send([{ type: "ping", data: "probe" }]); | ||
transport.once("packet", msg => { | ||
transport.once("packet", (msg) => { | ||
if (failed) | ||
@@ -250,3 +252,3 @@ return; | ||
// Handle any error that happens while probing | ||
const onerror = err => { | ||
const onerror = (err) => { | ||
const error = new Error("probe error: " + err); | ||
@@ -289,3 +291,3 @@ // @ts-ignore | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -299,5 +301,3 @@ onOpen() { | ||
// listener already closed the socket | ||
if ("open" === this.readyState && | ||
this.opts.upgrade && | ||
this.transport.pause) { | ||
if ("open" === this.readyState && this.opts.upgrade) { | ||
let i = 0; | ||
@@ -313,3 +313,3 @@ const l = this.upgrades.length; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -352,3 +352,3 @@ onPacket(packet) { | ||
* @param {Object} data - handshake obj | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -372,3 +372,3 @@ onHandshake(data) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -387,3 +387,3 @@ resetPingTimeout() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -406,3 +406,3 @@ onDrain() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -451,7 +451,6 @@ flush() { | ||
* | ||
* @param {String} message. | ||
* @param {String} msg - message. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @param {Object} options. | ||
* @return {Socket} for chaining. | ||
* @api public | ||
*/ | ||
@@ -469,7 +468,7 @@ write(msg, options, fn) { | ||
* | ||
* @param {String} packet type. | ||
* @param {String} type: packet type. | ||
* @param {String} data. | ||
* @param {Object} options. | ||
* @param {Function} callback function. | ||
* @api private | ||
* @param {Function} fn - callback function. | ||
* @private | ||
*/ | ||
@@ -493,3 +492,3 @@ sendPacket(type, data, options, fn) { | ||
data: data, | ||
options: options | ||
options: options, | ||
}; | ||
@@ -504,4 +503,2 @@ this.emitReserved("packetCreate", packet); | ||
* Closes the connection. | ||
* | ||
* @api public | ||
*/ | ||
@@ -547,3 +544,3 @@ close() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -558,3 +555,3 @@ onError(err) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -592,5 +589,4 @@ onClose(reason, description) { | ||
* | ||
* @param {Array} server upgrades | ||
* @api private | ||
* | ||
* @param {Array} upgrades - server upgrades | ||
* @private | ||
*/ | ||
@@ -597,0 +593,0 @@ filterUpgrades(upgrades) { |
@@ -1,2 +0,2 @@ | ||
import { Packet, RawData } from "engine.io-parser"; | ||
import { type Packet, type RawData } from "engine.io-parser"; | ||
import { Emitter } from "@socket.io/component-emitter"; | ||
@@ -23,8 +23,9 @@ import { SocketOptions } from "./socket.js"; | ||
} | ||
export declare abstract class Transport extends Emitter<{}, {}, TransportReservedEvents> { | ||
declare type TransportState = "opening" | "open" | "closed" | "pausing" | "paused"; | ||
export declare abstract class Transport extends Emitter<Record<never, never>, Record<never, never>, TransportReservedEvents> { | ||
query: Record<string, string>; | ||
writable: boolean; | ||
protected opts: SocketOptions; | ||
protected supportsBinary: boolean; | ||
protected query: object; | ||
protected readyState: string; | ||
protected writable: boolean; | ||
protected readyState: TransportState; | ||
protected socket: any; | ||
@@ -35,4 +36,4 @@ protected setTimeoutFn: typeof setTimeout; | ||
* | ||
* @param {Object} options. | ||
* @api private | ||
* @param {Object} opts - options | ||
* @protected | ||
*/ | ||
@@ -47,3 +48,3 @@ constructor(opts: any); | ||
* @return {Transport} for chaining | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -53,10 +54,6 @@ protected onError(reason: string, description: any, context?: any): this; | ||
* Opens the transport. | ||
* | ||
* @api public | ||
*/ | ||
private open; | ||
open(): this; | ||
/** | ||
* Closes the transport. | ||
* | ||
* @api public | ||
*/ | ||
@@ -68,3 +65,2 @@ close(): this; | ||
* @param {Array} packets | ||
* @api public | ||
*/ | ||
@@ -75,3 +71,3 @@ send(packets: any): void; | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -83,3 +79,3 @@ protected onOpen(): void; | ||
* @param {String} data | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -90,3 +86,3 @@ protected onData(data: RawData): void; | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -97,9 +93,19 @@ protected onPacket(packet: Packet): void; | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
protected onClose(details?: CloseDetails): void; | ||
/** | ||
* The name of the transport | ||
*/ | ||
abstract get name(): string; | ||
/** | ||
* Pauses the transport, in order not to lose packets during an upgrade. | ||
* | ||
* @param onPause | ||
*/ | ||
pause(onPause: () => void): void; | ||
protected abstract doOpen(): any; | ||
protected abstract doClose(): any; | ||
protected abstract write(packets: any): any; | ||
protected abstract write(packets: Packet[]): any; | ||
} | ||
export {}; |
@@ -16,4 +16,4 @@ import { decodePacket } from "engine.io-parser"; | ||
* | ||
* @param {Object} options. | ||
* @api private | ||
* @param {Object} opts - options | ||
* @protected | ||
*/ | ||
@@ -26,3 +26,2 @@ constructor(opts) { | ||
this.query = opts.query; | ||
this.readyState = ""; | ||
this.socket = opts.socket; | ||
@@ -37,3 +36,3 @@ } | ||
* @return {Transport} for chaining | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -46,10 +45,6 @@ onError(reason, description, context) { | ||
* Opens the transport. | ||
* | ||
* @api public | ||
*/ | ||
open() { | ||
if ("closed" === this.readyState || "" === this.readyState) { | ||
this.readyState = "opening"; | ||
this.doOpen(); | ||
} | ||
this.readyState = "opening"; | ||
this.doOpen(); | ||
return this; | ||
@@ -59,7 +54,5 @@ } | ||
* Closes the transport. | ||
* | ||
* @api public | ||
*/ | ||
close() { | ||
if ("opening" === this.readyState || "open" === this.readyState) { | ||
if (this.readyState === "opening" || this.readyState === "open") { | ||
this.doClose(); | ||
@@ -74,6 +67,5 @@ this.onClose(); | ||
* @param {Array} packets | ||
* @api public | ||
*/ | ||
send(packets) { | ||
if ("open" === this.readyState) { | ||
if (this.readyState === "open") { | ||
this.write(packets); | ||
@@ -88,3 +80,3 @@ } | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -100,3 +92,3 @@ onOpen() { | ||
* @param {String} data | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -110,3 +102,3 @@ onData(data) { | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -119,3 +111,3 @@ onPacket(packet) { | ||
* | ||
* @api protected | ||
* @protected | ||
*/ | ||
@@ -126,2 +118,8 @@ onClose(details) { | ||
} | ||
/** | ||
* Pauses the transport, in order not to lose packets during an upgrade. | ||
* | ||
* @param onPause | ||
*/ | ||
pause(onPause) { } | ||
} |
@@ -5,3 +5,3 @@ import { Polling } from "./polling.js"; | ||
websocket: WS, | ||
polling: Polling | ||
polling: Polling, | ||
}; |
@@ -13,8 +13,5 @@ import { Transport } from "../transport.js"; | ||
* @param {Object} opts | ||
* @api public | ||
* @package | ||
*/ | ||
constructor(opts: any); | ||
/** | ||
* Transport name. | ||
*/ | ||
get name(): string; | ||
@@ -25,3 +22,3 @@ /** | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -32,4 +29,4 @@ doOpen(): void; | ||
* | ||
* @param {Function} callback upon buffers are flushed and transport is paused | ||
* @api private | ||
* @param {Function} onPause - callback upon buffers are flushed and transport is paused | ||
* @package | ||
*/ | ||
@@ -40,3 +37,3 @@ pause(onPause: any): void; | ||
* | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -47,3 +44,3 @@ poll(): void; | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -54,3 +51,3 @@ onData(data: any): void; | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -61,5 +58,4 @@ doClose(): void; | ||
* | ||
* @param {Array} data packets | ||
* @param {Function} drain callback | ||
* @api private | ||
* @param {Array} packets - data packets | ||
* @protected | ||
*/ | ||
@@ -70,3 +66,3 @@ write(packets: any): void; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -78,3 +74,3 @@ uri(): string; | ||
* @param {String} method | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -87,11 +83,11 @@ request(opts?: {}): Request; | ||
* @param {Function} called upon flush. | ||
* @api private | ||
* @private | ||
*/ | ||
doWrite(data: any, fn: any): void; | ||
private doWrite; | ||
/** | ||
* Starts a poll cycle. | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
doPoll(): void; | ||
private doPoll; | ||
} | ||
@@ -118,3 +114,3 @@ interface RequestReservedEvents { | ||
* @param {Object} options | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -125,3 +121,3 @@ constructor(uri: any, opts: any); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -132,3 +128,3 @@ private create; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -139,3 +135,3 @@ private onError; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -146,3 +142,3 @@ private cleanup; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -153,3 +149,3 @@ private onLoad; | ||
* | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -156,0 +152,0 @@ abort(): void; |
@@ -12,3 +12,3 @@ import { Transport } from "../transport.js"; | ||
const xhr = new XMLHttpRequest({ | ||
xdomain: false | ||
xdomain: false, | ||
}); | ||
@@ -22,3 +22,3 @@ return null != xhr.responseType; | ||
* @param {Object} opts | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -47,5 +47,2 @@ constructor(opts) { | ||
} | ||
/** | ||
* Transport name. | ||
*/ | ||
get name() { | ||
@@ -58,3 +55,3 @@ return "polling"; | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -67,4 +64,4 @@ doOpen() { | ||
* | ||
* @param {Function} callback upon buffers are flushed and transport is paused | ||
* @api private | ||
* @param {Function} onPause - callback upon buffers are flushed and transport is paused | ||
* @package | ||
*/ | ||
@@ -99,3 +96,3 @@ pause(onPause) { | ||
* | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -110,6 +107,6 @@ poll() { | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
onData(data) { | ||
const callback = packet => { | ||
const callback = (packet) => { | ||
// if its the first message we consider the transport open | ||
@@ -144,3 +141,3 @@ if ("opening" === this.readyState && packet.type === "open") { | ||
* | ||
* @api private | ||
* @protected | ||
*/ | ||
@@ -163,9 +160,8 @@ doClose() { | ||
* | ||
* @param {Array} data packets | ||
* @param {Function} drain callback | ||
* @api private | ||
* @param {Array} packets - data packets | ||
* @protected | ||
*/ | ||
write(packets) { | ||
this.writable = false; | ||
encodePayload(packets, data => { | ||
encodePayload(packets, (data) => { | ||
this.doWrite(data, () => { | ||
@@ -180,3 +176,3 @@ this.writable = true; | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -213,3 +209,3 @@ uri() { | ||
* @param {String} method | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -225,3 +221,3 @@ request(opts = {}) { | ||
* @param {Function} called upon flush. | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -231,3 +227,3 @@ doWrite(data, fn) { | ||
method: "POST", | ||
data: data | ||
data: data, | ||
}); | ||
@@ -242,3 +238,3 @@ req.on("success", fn); | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -259,3 +255,3 @@ doPoll() { | ||
* @param {Object} options | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -275,3 +271,3 @@ constructor(uri, opts) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -346,3 +342,3 @@ create() { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -356,3 +352,3 @@ onError(err) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -378,3 +374,3 @@ cleanup(fromError) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -392,3 +388,3 @@ onLoad() { | ||
* | ||
* @api public | ||
* @package | ||
*/ | ||
@@ -395,0 +391,0 @@ abort() { |
@@ -5,3 +5,3 @@ import { globalThisShim as globalThis } from "../globalThis.js"; | ||
if (isPromiseAvailable) { | ||
return cb => Promise.resolve().then(cb); | ||
return (cb) => Promise.resolve().then(cb); | ||
} | ||
@@ -8,0 +8,0 @@ else { |
@@ -7,17 +7,7 @@ import { Transport } from "../transport.js"; | ||
* | ||
* @api {Object} connection options | ||
* @api public | ||
* @param {Object} opts - connection options | ||
* @protected | ||
*/ | ||
constructor(opts: any); | ||
/** | ||
* Transport name. | ||
* | ||
* @api public | ||
*/ | ||
get name(): string; | ||
/** | ||
* Opens socket. | ||
* | ||
* @api private | ||
*/ | ||
doOpen(): this; | ||
@@ -27,17 +17,6 @@ /** | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
addEventListeners(): void; | ||
/** | ||
* Writes data to socket. | ||
* | ||
* @param {Array} array of packets. | ||
* @api private | ||
*/ | ||
private addEventListeners; | ||
write(packets: any): void; | ||
/** | ||
* Closes socket. | ||
* | ||
* @api private | ||
*/ | ||
doClose(): void; | ||
@@ -47,3 +26,3 @@ /** | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -55,5 +34,5 @@ uri(): string; | ||
* @return {Boolean} whether this transport is available. | ||
* @api public | ||
* @private | ||
*/ | ||
check(): boolean; | ||
private check; | ||
} |
@@ -5,3 +5,3 @@ import { Transport } from "../transport.js"; | ||
import { pick } from "../util.js"; | ||
import { defaultBinaryType, nextTick, usingBrowserWebSocket, WebSocket } from "./websocket-constructor.js"; | ||
import { defaultBinaryType, nextTick, usingBrowserWebSocket, WebSocket, } from "./websocket-constructor.js"; | ||
import { encodePacket } from "engine.io-parser"; | ||
@@ -16,4 +16,4 @@ // detect ReactNative environment | ||
* | ||
* @api {Object} connection options | ||
* @api public | ||
* @param {Object} opts - connection options | ||
* @protected | ||
*/ | ||
@@ -24,15 +24,5 @@ constructor(opts) { | ||
} | ||
/** | ||
* Transport name. | ||
* | ||
* @api public | ||
*/ | ||
get name() { | ||
return "websocket"; | ||
} | ||
/** | ||
* Opens socket. | ||
* | ||
* @api private | ||
*/ | ||
doOpen() { | ||
@@ -69,3 +59,3 @@ if (!this.check()) { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -79,15 +69,9 @@ addEventListeners() { | ||
}; | ||
this.ws.onclose = closeEvent => this.onClose({ | ||
this.ws.onclose = (closeEvent) => this.onClose({ | ||
description: "websocket connection closed", | ||
context: closeEvent | ||
context: closeEvent, | ||
}); | ||
this.ws.onmessage = ev => this.onData(ev.data); | ||
this.ws.onerror = e => this.onError("websocket error", e); | ||
this.ws.onmessage = (ev) => this.onData(ev.data); | ||
this.ws.onerror = (e) => this.onError("websocket error", e); | ||
} | ||
/** | ||
* Writes data to socket. | ||
* | ||
* @param {Array} array of packets. | ||
* @api private | ||
*/ | ||
write(packets) { | ||
@@ -100,3 +84,3 @@ this.writable = false; | ||
const lastPacket = i === packets.length - 1; | ||
encodePacket(packet, this.supportsBinary, data => { | ||
encodePacket(packet, this.supportsBinary, (data) => { | ||
// always create a new object (GH-437) | ||
@@ -142,7 +126,2 @@ const opts = {}; | ||
} | ||
/** | ||
* Closes socket. | ||
* | ||
* @api private | ||
*/ | ||
doClose() { | ||
@@ -157,3 +136,3 @@ if (typeof this.ws !== "undefined") { | ||
* | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -191,3 +170,3 @@ uri() { | ||
* @return {Boolean} whether this transport is available. | ||
* @api public | ||
* @private | ||
*/ | ||
@@ -194,0 +173,0 @@ check() { |
@@ -11,4 +11,4 @@ import { globalThisShim as globalThis } from "./globalThis.js"; | ||
// Keep a reference to the real timeout functions so they can be used when overridden | ||
const NATIVE_SET_TIMEOUT = setTimeout; | ||
const NATIVE_CLEAR_TIMEOUT = clearTimeout; | ||
const NATIVE_SET_TIMEOUT = globalThis.setTimeout; | ||
const NATIVE_CLEAR_TIMEOUT = globalThis.clearTimeout; | ||
export function installTimerFunctions(obj, opts) { | ||
@@ -20,4 +20,4 @@ if (opts.useNativeTimers) { | ||
else { | ||
obj.setTimeoutFn = setTimeout.bind(globalThis); | ||
obj.clearTimeoutFn = clearTimeout.bind(globalThis); | ||
obj.setTimeoutFn = globalThis.setTimeout.bind(globalThis); | ||
obj.clearTimeoutFn = globalThis.clearTimeout.bind(globalThis); | ||
} | ||
@@ -24,0 +24,0 @@ } |
/*! | ||
* Engine.IO v6.2.3 | ||
* (c) 2014-2022 Guillermo Rauch | ||
* Engine.IO v6.3.0 | ||
* (c) 2014-2023 Guillermo Rauch | ||
* Released under the MIT License. | ||
*/ | ||
const t=Object.create(null);t.open="0",t.close="1",t.ping="2",t.pong="3",t.message="4",t.upgrade="5",t.noop="6";const e=Object.create(null);Object.keys(t).forEach((s=>{e[t[s]]=s}));const s={type:"error",data:"parser error"},r="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),o="function"==typeof ArrayBuffer,i=({type:e,data:s},i,a)=>{return r&&s instanceof Blob?i?a(s):n(s,a):o&&(s instanceof ArrayBuffer||(h=s,"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(h):h&&h.buffer instanceof ArrayBuffer))?i?a(s):n(new Blob([s]),a):a(t[e]+(s||""));var h},n=(t,e)=>{const s=new FileReader;return s.onload=function(){const t=s.result.split(",")[1];e("b"+t)},s.readAsDataURL(t)};for(var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h="undefined"==typeof Uint8Array?[]:new Uint8Array(256),p=0;p<a.length;p++)h[a.charCodeAt(p)]=p;const c="function"==typeof ArrayBuffer,l=(t,r)=>{if("string"!=typeof t)return{type:"message",data:d(t,r)};const o=t.charAt(0);if("b"===o)return{type:"message",data:u(t.substring(1),r)};return e[o]?t.length>1?{type:e[o],data:t.substring(1)}:{type:e[o]}:s},u=(t,e)=>{if(c){const s=function(t){var e,s,r,o,i,n=.75*t.length,a=t.length,p=0;"="===t[t.length-1]&&(n--,"="===t[t.length-2]&&n--);var c=new ArrayBuffer(n),l=new Uint8Array(c);for(e=0;e<a;e+=4)s=h[t.charCodeAt(e)],r=h[t.charCodeAt(e+1)],o=h[t.charCodeAt(e+2)],i=h[t.charCodeAt(e+3)],l[p++]=s<<2|r>>4,l[p++]=(15&r)<<4|o>>2,l[p++]=(3&o)<<6|63&i;return c}(t);return d(s,e)}return{base64:!0,data:t}},d=(t,e)=>"blob"===e&&t instanceof ArrayBuffer?new Blob([t]):t,f=String.fromCharCode(30);function y(t){if(t)return function(t){for(var e in y.prototype)t[e]=y.prototype[e];return t}(t)}y.prototype.on=y.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},y.prototype.once=function(t,e){function s(){this.off(t,s),e.apply(this,arguments)}return s.fn=e,this.on(t,s),this},y.prototype.off=y.prototype.removeListener=y.prototype.removeAllListeners=y.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var s,r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var o=0;o<r.length;o++)if((s=r[o])===e||s.fn===e){r.splice(o,1);break}return 0===r.length&&delete this._callbacks["$"+t],this},y.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),s=this._callbacks["$"+t],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(s){r=0;for(var o=(s=s.slice(0)).length;r<o;++r)s[r].apply(this,e)}return this},y.prototype.emitReserved=y.prototype.emit,y.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},y.prototype.hasListeners=function(t){return!!this.listeners(t).length};const m="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function g(t,...e){return e.reduce(((e,s)=>(t.hasOwnProperty(s)&&(e[s]=t[s]),e)),{})}const b=setTimeout,v=clearTimeout;function w(t,e){e.useNativeTimers?(t.setTimeoutFn=b.bind(m),t.clearTimeoutFn=v.bind(m)):(t.setTimeoutFn=setTimeout.bind(m),t.clearTimeoutFn=clearTimeout.bind(m))}class k extends Error{constructor(t,e,s){super(t),this.description=e,this.context=s,this.type="TransportError"}}class x extends y{constructor(t){super(),this.writable=!1,w(this,t),this.opts=t,this.query=t.query,this.readyState="",this.socket=t.socket}onError(t,e,s){return super.emitReserved("error",new k(t,e,s)),this}open(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=l(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}}const T="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),S={};let R,E=0,L=0;function B(t){let e="";do{e=T[t%64]+e,t=Math.floor(t/64)}while(t>0);return e}function C(){const t=B(+new Date);return t!==R?(E=0,R=t):t+"."+B(E++)}for(;L<64;L++)S[T[L]]=L;function q(t){let e="";for(let s in t)t.hasOwnProperty(s)&&(e.length&&(e+="&"),e+=encodeURIComponent(s)+"="+encodeURIComponent(t[s]));return e}let O=!1;try{O="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const P=O;function A(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||P))return new XMLHttpRequest}catch(t){}if(!e)try{return new(m[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}function U(){}const H=null!=new A({xdomain:!1}).responseType;class j extends y{constructor(t,e){super(),w(this,e),this.opts=e,this.method=e.method||"GET",this.uri=t,this.async=!1!==e.async,this.data=void 0!==e.data?e.data:null,this.create()}create(){const t=g(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd,t.xscheme=!!this.opts.xs;const e=this.xhr=new A(t);try{e.open(this.method,this.uri,this.async);try{if(this.opts.extraHeaders){e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0);for(let t in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(t)&&e.setRequestHeader(t,this.opts.extraHeaders[t])}}catch(t){}if("POST"===this.method)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}"withCredentials"in e&&(e.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(e.timeout=this.opts.requestTimeout),e.onreadystatechange=()=>{4===e.readyState&&(200===e.status||1223===e.status?this.onLoad():this.setTimeoutFn((()=>{this.onError("number"==typeof e.status?e.status:0)}),0))},e.send(this.data)}catch(t){return void this.setTimeoutFn((()=>{this.onError(t)}),0)}"undefined"!=typeof document&&(this.index=j.requestsCount++,j.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=U,t)try{this.xhr.abort()}catch(t){}"undefined"!=typeof document&&delete j.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}if(j.requestsCount=0,j.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",_);else if("function"==typeof addEventListener){addEventListener("onpagehide"in m?"pagehide":"unload",_,!1)}function _(){for(let t in j.requests)j.requests.hasOwnProperty(t)&&j.requests[t].abort()}const F="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),D=m.WebSocket||m.MozWebSocket,I="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();const M={websocket:class extends x{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),e=this.opts.protocols,s=I?{}:g(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=I?new D(t,e,s):e?new D(t,e):new D(t)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType||"arraybuffer",this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const s=t[e],r=e===t.length-1;i(s,this.supportsBinary,(t=>{try{this.ws.send(t)}catch(t){}r&&F((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){let t=this.query||{};const e=this.opts.secure?"wss":"ws";let s="";this.opts.port&&("wss"===e&&443!==Number(this.opts.port)||"ws"===e&&80!==Number(this.opts.port))&&(s=":"+this.opts.port),this.opts.timestampRequests&&(t[this.opts.timestampParam]=C()),this.supportsBinary||(t.b64=1);const r=q(t);return e+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+s+this.opts.path+(r.length?"?"+r:"")}check(){return!!D}},polling:class extends x{constructor(t){if(super(t),this.polling=!1,"undefined"!=typeof location){const e="https:"===location.protocol;let s=location.port;s||(s=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||s!==t.port,this.xs=t.secure!==e}const e=t&&t.forceBase64;this.supportsBinary=H&&!e}get name(){return"polling"}doOpen(){this.poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this.polling||!this.writable){let t=0;this.polling&&(t++,this.once("pollComplete",(function(){--t||e()}))),this.writable||(t++,this.once("drain",(function(){--t||e()})))}else e()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const s=t.split(f),r=[];for(let t=0;t<s.length;t++){const o=l(s[t],e);if(r.push(o),"error"===o.type)break}return r})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const s=t.length,r=new Array(s);let o=0;t.forEach(((t,n)=>{i(t,!1,(t=>{r[n]=t,++o===s&&e(r.join(f))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){let t=this.query||{};const e=this.opts.secure?"https":"http";let s="";!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=C()),this.supportsBinary||t.sid||(t.b64=1),this.opts.port&&("https"===e&&443!==Number(this.opts.port)||"http"===e&&80!==Number(this.opts.port))&&(s=":"+this.opts.port);const r=q(t);return e+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+s+this.opts.path+(r.length?"?"+r:"")}request(t={}){return Object.assign(t,{xd:this.xd,xs:this.xs},this.opts),new j(this.uri(),t)}doWrite(t,e){const s=this.request({method:"POST",data:t});s.on("success",e),s.on("error",((t,e)=>{this.onError("xhr post error",t,e)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,e)=>{this.onError("xhr poll error",t,e)})),this.pollXhr=t}}},W=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,N=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function X(t){const e=t,s=t.indexOf("["),r=t.indexOf("]");-1!=s&&-1!=r&&(t=t.substring(0,s)+t.substring(s,r).replace(/:/g,";")+t.substring(r,t.length));let o=W.exec(t||""),i={},n=14;for(;n--;)i[N[n]]=o[n]||"";return-1!=s&&-1!=r&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=function(t,e){const s=/\/{2,9}/g,r=e.replace(s,"/").split("/");"/"!=e.slice(0,1)&&0!==e.length||r.splice(0,1);"/"==e.slice(-1)&&r.splice(r.length-1,1);return r}(0,i.path),i.queryKey=function(t,e){const s={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,e,r){e&&(s[e]=r)})),s}(0,i.query),i}class $ extends y{constructor(t,e={}){super(),t&&"object"==typeof t&&(e=t,t=null),t?(t=X(t),e.hostname=t.host,e.secure="https"===t.protocol||"wss"===t.protocol,e.port=t.port,t.query&&(e.query=t.query)):e.host&&(e.hostname=X(e.host).host),w(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=e.transports||["polling","websocket"],this.readyState="",this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!0},e),this.opts.path=this.opts.path.replace(/\/$/,"")+"/","string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},s=t.split("&");for(let t=0,r=s.length;t<r;t++){let r=s[t].split("=");e[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return e}(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,"function"==typeof addEventListener&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const s=Object.assign({},this.opts.transportOptions[t],this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port});return new M[t](s)}open(){let t;if(this.opts.rememberUpgrade&&$.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))t="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(t){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(t=>this.onClose("transport close",t)))}probe(t){let e=this.createTransport(t),s=!1;$.priorWebsocketSuccess=!1;const r=()=>{s||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(t=>{if(!s)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;$.priorWebsocketSuccess="websocket"===e.name,this.transport.pause((()=>{s||"closed"!==this.readyState&&(p(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}})))};function o(){s||(s=!0,p(),e.close(),e=null)}const i=t=>{const s=new Error("probe error: "+t);s.transport=e.name,o(),this.emitReserved("upgradeError",s)};function n(){i("transport closed")}function a(){i("socket closed")}function h(t){e&&t.name!==e.name&&o()}const p=()=>{e.removeListener("open",r),e.removeListener("error",i),e.removeListener("close",n),this.off("close",a),this.off("upgrading",h)};e.once("open",r),e.once("error",i),e.once("close",n),this.once("close",a),this.once("upgrading",h),e.open()}onOpen(){if(this.readyState="open",$.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade&&this.transport.pause){let t=0;const e=this.upgrades.length;for(;t<e;t++)this.probe(this.upgrades[t])}}onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this.resetPingTimeout(),this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const e=new Error("server error");e.code=t.data,this.onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.upgrades=this.filterUpgrades(t.upgrades),this.pingInterval=t.pingInterval,this.pingTimeout=t.pingTimeout,this.maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((()=>{this.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s<this.writeBuffer.length;s++){const r=this.writeBuffer[s].data;if(r&&(t+="string"==typeof(e=r)?function(t){let e=0,s=0;for(let r=0,o=t.length;r<o;r++)e=t.charCodeAt(r),e<128?s+=1:e<2048?s+=2:e<55296||e>=57344?s+=3:(r++,s+=4);return s}(e):Math.ceil(1.33*(e.byteLength||e.size))),s>0&&t>this.maxPayload)return this.writeBuffer.slice(0,s);t+=2}var e;return this.writeBuffer}write(t,e,s){return this.sendPacket("message",t,e,s),this}send(t,e,s){return this.sendPacket("message",t,e,s),this}sendPacket(t,e,s,r){if("function"==typeof e&&(r=e,e=void 0),"function"==typeof s&&(r=s,s=null),"closing"===this.readyState||"closed"===this.readyState)return;(s=s||{}).compress=!1!==s.compress;const o={type:t,data:e,options:s};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),r&&this.once("flush",r),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},s=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?s():t()})):this.upgrading?s():t()),this}onError(t){$.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,e){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const e=[];let s=0;const r=t.length;for(;s<r;s++)~this.transports.indexOf(t[s])&&e.push(t[s]);return e}}$.protocol=4;const z=$.protocol;export{$ as Socket,x as Transport,w as installTimerFunctions,F as nextTick,X as parse,z as protocol,M as transports}; | ||
const t=Object.create(null);t.open="0",t.close="1",t.ping="2",t.pong="3",t.message="4",t.upgrade="5",t.noop="6";const e=Object.create(null);Object.keys(t).forEach((s=>{e[t[s]]=s}));const s={type:"error",data:"parser error"},r="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),o="function"==typeof ArrayBuffer,i=({type:e,data:s},i,a)=>{return r&&s instanceof Blob?i?a(s):n(s,a):o&&(s instanceof ArrayBuffer||(h=s,"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(h):h&&h.buffer instanceof ArrayBuffer))?i?a(s):n(new Blob([s]),a):a(t[e]+(s||""));var h},n=(t,e)=>{const s=new FileReader;return s.onload=function(){const t=s.result.split(",")[1];e("b"+t)},s.readAsDataURL(t)};for(var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h="undefined"==typeof Uint8Array?[]:new Uint8Array(256),p=0;p<a.length;p++)h[a.charCodeAt(p)]=p;const c="function"==typeof ArrayBuffer,l=(t,r)=>{if("string"!=typeof t)return{type:"message",data:d(t,r)};const o=t.charAt(0);if("b"===o)return{type:"message",data:u(t.substring(1),r)};return e[o]?t.length>1?{type:e[o],data:t.substring(1)}:{type:e[o]}:s},u=(t,e)=>{if(c){const s=function(t){var e,s,r,o,i,n=.75*t.length,a=t.length,p=0;"="===t[t.length-1]&&(n--,"="===t[t.length-2]&&n--);var c=new ArrayBuffer(n),l=new Uint8Array(c);for(e=0;e<a;e+=4)s=h[t.charCodeAt(e)],r=h[t.charCodeAt(e+1)],o=h[t.charCodeAt(e+2)],i=h[t.charCodeAt(e+3)],l[p++]=s<<2|r>>4,l[p++]=(15&r)<<4|o>>2,l[p++]=(3&o)<<6|63&i;return c}(t);return d(s,e)}return{base64:!0,data:t}},d=(t,e)=>"blob"===e&&t instanceof ArrayBuffer?new Blob([t]):t,f=String.fromCharCode(30);function y(t){if(t)return function(t){for(var e in y.prototype)t[e]=y.prototype[e];return t}(t)}y.prototype.on=y.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},y.prototype.once=function(t,e){function s(){this.off(t,s),e.apply(this,arguments)}return s.fn=e,this.on(t,s),this},y.prototype.off=y.prototype.removeListener=y.prototype.removeAllListeners=y.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var s,r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var o=0;o<r.length;o++)if((s=r[o])===e||s.fn===e){r.splice(o,1);break}return 0===r.length&&delete this._callbacks["$"+t],this},y.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),s=this._callbacks["$"+t],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(s){r=0;for(var o=(s=s.slice(0)).length;r<o;++r)s[r].apply(this,e)}return this},y.prototype.emitReserved=y.prototype.emit,y.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},y.prototype.hasListeners=function(t){return!!this.listeners(t).length};const m="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function g(t,...e){return e.reduce(((e,s)=>(t.hasOwnProperty(s)&&(e[s]=t[s]),e)),{})}const b=m.setTimeout,v=m.clearTimeout;function w(t,e){e.useNativeTimers?(t.setTimeoutFn=b.bind(m),t.clearTimeoutFn=v.bind(m)):(t.setTimeoutFn=m.setTimeout.bind(m),t.clearTimeoutFn=m.clearTimeout.bind(m))}class k extends Error{constructor(t,e,s){super(t),this.description=e,this.context=s,this.type="TransportError"}}class x extends y{constructor(t){super(),this.writable=!1,w(this,t),this.opts=t,this.query=t.query,this.socket=t.socket}onError(t,e,s){return super.emitReserved("error",new k(t,e,s)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=l(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}}const T="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),R={};let S,E=0,B=0;function L(t){let e="";do{e=T[t%64]+e,t=Math.floor(t/64)}while(t>0);return e}function C(){const t=L(+new Date);return t!==S?(E=0,S=t):t+"."+L(E++)}for(;B<64;B++)R[T[B]]=B;function q(t){let e="";for(let s in t)t.hasOwnProperty(s)&&(e.length&&(e+="&"),e+=encodeURIComponent(s)+"="+encodeURIComponent(t[s]));return e}let O=!1;try{O="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const P=O;function A(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||P))return new XMLHttpRequest}catch(t){}if(!e)try{return new(m[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}function U(){}const H=null!=new A({xdomain:!1}).responseType;class j extends y{constructor(t,e){super(),w(this,e),this.opts=e,this.method=e.method||"GET",this.uri=t,this.async=!1!==e.async,this.data=void 0!==e.data?e.data:null,this.create()}create(){const t=g(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd,t.xscheme=!!this.opts.xs;const e=this.xhr=new A(t);try{e.open(this.method,this.uri,this.async);try{if(this.opts.extraHeaders){e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0);for(let t in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(t)&&e.setRequestHeader(t,this.opts.extraHeaders[t])}}catch(t){}if("POST"===this.method)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}"withCredentials"in e&&(e.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(e.timeout=this.opts.requestTimeout),e.onreadystatechange=()=>{4===e.readyState&&(200===e.status||1223===e.status?this.onLoad():this.setTimeoutFn((()=>{this.onError("number"==typeof e.status?e.status:0)}),0))},e.send(this.data)}catch(t){return void this.setTimeoutFn((()=>{this.onError(t)}),0)}"undefined"!=typeof document&&(this.index=j.requestsCount++,j.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=U,t)try{this.xhr.abort()}catch(t){}"undefined"!=typeof document&&delete j.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}if(j.requestsCount=0,j.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",_);else if("function"==typeof addEventListener){addEventListener("onpagehide"in m?"pagehide":"unload",_,!1)}function _(){for(let t in j.requests)j.requests.hasOwnProperty(t)&&j.requests[t].abort()}const F="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),D=m.WebSocket||m.MozWebSocket,I="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();const M={websocket:class extends x{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),e=this.opts.protocols,s=I?{}:g(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=I?new D(t,e,s):e?new D(t,e):new D(t)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType||"arraybuffer",this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const s=t[e],r=e===t.length-1;i(s,this.supportsBinary,(t=>{try{this.ws.send(t)}catch(t){}r&&F((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){let t=this.query||{};const e=this.opts.secure?"wss":"ws";let s="";this.opts.port&&("wss"===e&&443!==Number(this.opts.port)||"ws"===e&&80!==Number(this.opts.port))&&(s=":"+this.opts.port),this.opts.timestampRequests&&(t[this.opts.timestampParam]=C()),this.supportsBinary||(t.b64=1);const r=q(t);return e+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+s+this.opts.path+(r.length?"?"+r:"")}check(){return!!D}},polling:class extends x{constructor(t){if(super(t),this.polling=!1,"undefined"!=typeof location){const e="https:"===location.protocol;let s=location.port;s||(s=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||s!==t.port,this.xs=t.secure!==e}const e=t&&t.forceBase64;this.supportsBinary=H&&!e}get name(){return"polling"}doOpen(){this.poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this.polling||!this.writable){let t=0;this.polling&&(t++,this.once("pollComplete",(function(){--t||e()}))),this.writable||(t++,this.once("drain",(function(){--t||e()})))}else e()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const s=t.split(f),r=[];for(let t=0;t<s.length;t++){const o=l(s[t],e);if(r.push(o),"error"===o.type)break}return r})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const s=t.length,r=new Array(s);let o=0;t.forEach(((t,n)=>{i(t,!1,(t=>{r[n]=t,++o===s&&e(r.join(f))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){let t=this.query||{};const e=this.opts.secure?"https":"http";let s="";!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=C()),this.supportsBinary||t.sid||(t.b64=1),this.opts.port&&("https"===e&&443!==Number(this.opts.port)||"http"===e&&80!==Number(this.opts.port))&&(s=":"+this.opts.port);const r=q(t);return e+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+s+this.opts.path+(r.length?"?"+r:"")}request(t={}){return Object.assign(t,{xd:this.xd,xs:this.xs},this.opts),new j(this.uri(),t)}doWrite(t,e){const s=this.request({method:"POST",data:t});s.on("success",e),s.on("error",((t,e)=>{this.onError("xhr post error",t,e)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,e)=>{this.onError("xhr poll error",t,e)})),this.pollXhr=t}}},W=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,N=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function X(t){const e=t,s=t.indexOf("["),r=t.indexOf("]");-1!=s&&-1!=r&&(t=t.substring(0,s)+t.substring(s,r).replace(/:/g,";")+t.substring(r,t.length));let o=W.exec(t||""),i={},n=14;for(;n--;)i[N[n]]=o[n]||"";return-1!=s&&-1!=r&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=function(t,e){const s=/\/{2,9}/g,r=e.replace(s,"/").split("/");"/"!=e.slice(0,1)&&0!==e.length||r.splice(0,1);"/"==e.slice(-1)&&r.splice(r.length-1,1);return r}(0,i.path),i.queryKey=function(t,e){const s={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,e,r){e&&(s[e]=r)})),s}(0,i.query),i}class $ extends y{constructor(t,e={}){super(),this.writeBuffer=[],t&&"object"==typeof t&&(e=t,t=null),t?(t=X(t),e.hostname=t.host,e.secure="https"===t.protocol||"wss"===t.protocol,e.port=t.port,t.query&&(e.query=t.query)):e.host&&(e.hostname=X(e.host).host),w(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=e.transports||["polling","websocket"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!0},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},s=t.split("&");for(let t=0,r=s.length;t<r;t++){let r=s[t].split("=");e[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return e}(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,"function"==typeof addEventListener&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const s=Object.assign({},this.opts.transportOptions[t],this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port});return new M[t](s)}open(){let t;if(this.opts.rememberUpgrade&&$.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))t="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(t){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(t=>this.onClose("transport close",t)))}probe(t){let e=this.createTransport(t),s=!1;$.priorWebsocketSuccess=!1;const r=()=>{s||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(t=>{if(!s)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;$.priorWebsocketSuccess="websocket"===e.name,this.transport.pause((()=>{s||"closed"!==this.readyState&&(p(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}})))};function o(){s||(s=!0,p(),e.close(),e=null)}const i=t=>{const s=new Error("probe error: "+t);s.transport=e.name,o(),this.emitReserved("upgradeError",s)};function n(){i("transport closed")}function a(){i("socket closed")}function h(t){e&&t.name!==e.name&&o()}const p=()=>{e.removeListener("open",r),e.removeListener("error",i),e.removeListener("close",n),this.off("close",a),this.off("upgrading",h)};e.once("open",r),e.once("error",i),e.once("close",n),this.once("close",a),this.once("upgrading",h),e.open()}onOpen(){if(this.readyState="open",$.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade){let t=0;const e=this.upgrades.length;for(;t<e;t++)this.probe(this.upgrades[t])}}onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this.resetPingTimeout(),this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const e=new Error("server error");e.code=t.data,this.onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.upgrades=this.filterUpgrades(t.upgrades),this.pingInterval=t.pingInterval,this.pingTimeout=t.pingTimeout,this.maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((()=>{this.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s<this.writeBuffer.length;s++){const r=this.writeBuffer[s].data;if(r&&(t+="string"==typeof(e=r)?function(t){let e=0,s=0;for(let r=0,o=t.length;r<o;r++)e=t.charCodeAt(r),e<128?s+=1:e<2048?s+=2:e<55296||e>=57344?s+=3:(r++,s+=4);return s}(e):Math.ceil(1.33*(e.byteLength||e.size))),s>0&&t>this.maxPayload)return this.writeBuffer.slice(0,s);t+=2}var e;return this.writeBuffer}write(t,e,s){return this.sendPacket("message",t,e,s),this}send(t,e,s){return this.sendPacket("message",t,e,s),this}sendPacket(t,e,s,r){if("function"==typeof e&&(r=e,e=void 0),"function"==typeof s&&(r=s,s=null),"closing"===this.readyState||"closed"===this.readyState)return;(s=s||{}).compress=!1!==s.compress;const o={type:t,data:e,options:s};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),r&&this.once("flush",r),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},s=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?s():t()})):this.upgrading?s():t()),this}onError(t){$.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,e){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const e=[];let s=0;const r=t.length;for(;s<r;s++)~this.transports.indexOf(t[s])&&e.push(t[s]);return e}}$.protocol=4;const z=$.protocol;export{$ as Socket,x as Transport,w as installTimerFunctions,F as nextTick,X as parse,z as protocol,M as transports}; | ||
//# sourceMappingURL=engine.io.esm.min.js.map |
/*! | ||
* Engine.IO v6.2.3 | ||
* (c) 2014-2022 Guillermo Rauch | ||
* Engine.IO v6.3.0 | ||
* (c) 2014-2023 Guillermo Rauch | ||
* Released under the MIT License. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).eio=t()}(this,(function(){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function n(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}function i(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}}),t&&a(e,t)}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(e,t)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function c(e,t,r){return c=u()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&a(o,r.prototype),o},c.apply(null,arguments)}function p(e){var t="function"==typeof Map?new Map:void 0;return p=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return c(e,arguments,s(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,e)},p(e)}function h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?h(e):t}function f(e){var t=u();return function(){var r,n=s(e);if(t){var o=s(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return l(this,r)}}function d(e,t,r){return d="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,r){var n=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=s(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(r):o.value}},d(e,t,r||e)}var y=Object.create(null);y.open="0",y.close="1",y.ping="2",y.pong="3",y.message="4",y.upgrade="5",y.noop="6";var v=Object.create(null);Object.keys(y).forEach((function(e){v[y[e]]=e}));for(var m={type:"error",data:"parser error"},g="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),b="function"==typeof ArrayBuffer,k=function(e,t,r){var n,o=e.type,i=e.data;return g&&i instanceof Blob?t?r(i):w(i,r):b&&(i instanceof ArrayBuffer||(n=i,"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(n):n&&n.buffer instanceof ArrayBuffer))?t?r(i):w(new Blob([i]),r):r(y[o]+(i||""))},w=function(e,t){var r=new FileReader;return r.onload=function(){var e=r.result.split(",")[1];t("b"+e)},r.readAsDataURL(e)},T="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S="undefined"==typeof Uint8Array?[]:new Uint8Array(256),R=0;R<T.length;R++)S[T.charCodeAt(R)]=R;var x="function"==typeof ArrayBuffer,O=function(e,t){if("string"!=typeof e)return{type:"message",data:L(e,t)};var r=e.charAt(0);return"b"===r?{type:"message",data:E(e.substring(1),t)}:v[r]?e.length>1?{type:v[r],data:e.substring(1)}:{type:v[r]}:m},E=function(e,t){if(x){var r=function(e){var t,r,n,o,i,s=.75*e.length,a=e.length,u=0;"="===e[e.length-1]&&(s--,"="===e[e.length-2]&&s--);var c=new ArrayBuffer(s),p=new Uint8Array(c);for(t=0;t<a;t+=4)r=S[e.charCodeAt(t)],n=S[e.charCodeAt(t+1)],o=S[e.charCodeAt(t+2)],i=S[e.charCodeAt(t+3)],p[u++]=r<<2|n>>4,p[u++]=(15&n)<<4|o>>2,p[u++]=(3&o)<<6|63&i;return c}(e);return L(r,t)}return{base64:!0,data:e}},L=function(e,t){return"blob"===t&&e instanceof ArrayBuffer?new Blob([e]):e},P=String.fromCharCode(30);function B(e){if(e)return function(e){for(var t in B.prototype)e[t]=B.prototype[t];return e}(e)}B.prototype.on=B.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},B.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this},B.prototype.off=B.prototype.removeListener=B.prototype.removeAllListeners=B.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r,n=this._callbacks["$"+e];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;o<n.length;o++)if((r=n[o])===t||r.fn===t){n.splice(o,1);break}return 0===n.length&&delete this._callbacks["$"+e],this},B.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),r=this._callbacks["$"+e],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(r){n=0;for(var o=(r=r.slice(0)).length;n<o;++n)r[n].apply(this,t)}return this},B.prototype.emitReserved=B.prototype.emit,B.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},B.prototype.hasListeners=function(e){return!!this.listeners(e).length};var C="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function q(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return r.reduce((function(t,r){return e.hasOwnProperty(r)&&(t[r]=e[r]),t}),{})}var A=setTimeout,j=clearTimeout;function _(e,t){t.useNativeTimers?(e.setTimeoutFn=A.bind(C),e.clearTimeoutFn=j.bind(C)):(e.setTimeoutFn=setTimeout.bind(C),e.clearTimeoutFn=clearTimeout.bind(C))}var U,H=function(e){i(n,e);var r=f(n);function n(e,o,i){var s;return t(this,n),(s=r.call(this,e)).description=o,s.context=i,s.type="TransportError",s}return n}(p(Error)),F=function(e){i(o,e);var r=f(o);function o(e){var n;return t(this,o),(n=r.call(this)).writable=!1,_(h(n),e),n.opts=e,n.query=e.query,n.readyState="",n.socket=e.socket,n}return n(o,[{key:"onError",value:function(e,t,r){return d(s(o.prototype),"emitReserved",this).call(this,"error",new H(e,t,r)),this}},{key:"open",value:function(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this}},{key:"close",value:function(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}},{key:"send",value:function(e){"open"===this.readyState&&this.write(e)}},{key:"onOpen",value:function(){this.readyState="open",this.writable=!0,d(s(o.prototype),"emitReserved",this).call(this,"open")}},{key:"onData",value:function(e){var t=O(e,this.socket.binaryType);this.onPacket(t)}},{key:"onPacket",value:function(e){d(s(o.prototype),"emitReserved",this).call(this,"packet",e)}},{key:"onClose",value:function(e){this.readyState="closed",d(s(o.prototype),"emitReserved",this).call(this,"close",e)}}]),o}(B),D="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),M={},I=0,W=0;function N(e){var t="";do{t=D[e%64]+t,e=Math.floor(e/64)}while(e>0);return t}function X(){var e=N(+new Date);return e!==U?(I=0,U=e):e+"."+N(I++)}for(;W<64;W++)M[D[W]]=W;function $(e){var t="";for(var r in e)e.hasOwnProperty(r)&&(t.length&&(t+="&"),t+=encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return t}function z(e){for(var t={},r=e.split("&"),n=0,o=r.length;n<o;n++){var i=r[n].split("=");t[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return t}var V=!1;try{V="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(e){}var G=V;function J(e){var t=e.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!t||G))return new XMLHttpRequest}catch(e){}if(!t)try{return new(C[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}}function K(){}var Q=null!=new J({xdomain:!1}).responseType,Y=function(e){i(s,e);var r=f(s);function s(e){var n;if(t(this,s),(n=r.call(this,e)).polling=!1,"undefined"!=typeof location){var o="https:"===location.protocol,i=location.port;i||(i=o?"443":"80"),n.xd="undefined"!=typeof location&&e.hostname!==location.hostname||i!==e.port,n.xs=e.secure!==o}var a=e&&e.forceBase64;return n.supportsBinary=Q&&!a,n}return n(s,[{key:"doOpen",value:function(){this.poll()}},{key:"pause",value:function(e){var t=this;this.readyState="pausing";var r=function(){t.readyState="paused",e()};if(this.polling||!this.writable){var n=0;this.polling&&(n++,this.once("pollComplete",(function(){--n||r()}))),this.writable||(n++,this.once("drain",(function(){--n||r()})))}else r()}},{key:"poll",value:function(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}},{key:"onData",value:function(e){var t=this;(function(e,t){for(var r=e.split(P),n=[],o=0;o<r.length;o++){var i=O(r[o],t);if(n.push(i),"error"===i.type)break}return n})(e,this.socket.binaryType).forEach((function(e){if("opening"===t.readyState&&"open"===e.type&&t.onOpen(),"close"===e.type)return t.onClose({description:"transport closed by the server"}),!1;t.onPacket(e)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}},{key:"doClose",value:function(){var e=this,t=function(){e.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}},{key:"write",value:function(e){var t=this;this.writable=!1,function(e,t){var r=e.length,n=new Array(r),o=0;e.forEach((function(e,i){k(e,!1,(function(e){n[i]=e,++o===r&&t(n.join(P))}))}))}(e,(function(e){t.doWrite(e,(function(){t.writable=!0,t.emitReserved("drain")}))}))}},{key:"uri",value:function(){var e=this.query||{},t=this.opts.secure?"https":"http",r="";!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=X()),this.supportsBinary||e.sid||(e.b64=1),this.opts.port&&("https"===t&&443!==Number(this.opts.port)||"http"===t&&80!==Number(this.opts.port))&&(r=":"+this.opts.port);var n=$(e);return t+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+r+this.opts.path+(n.length?"?"+n:"")}},{key:"request",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return o(e,{xd:this.xd,xs:this.xs},this.opts),new Z(this.uri(),e)}},{key:"doWrite",value:function(e,t){var r=this,n=this.request({method:"POST",data:e});n.on("success",t),n.on("error",(function(e,t){r.onError("xhr post error",e,t)}))}},{key:"doPoll",value:function(){var e=this,t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(function(t,r){e.onError("xhr poll error",t,r)})),this.pollXhr=t}},{key:"name",get:function(){return"polling"}}]),s}(F),Z=function(e){i(o,e);var r=f(o);function o(e,n){var i;return t(this,o),_(h(i=r.call(this)),n),i.opts=n,i.method=n.method||"GET",i.uri=e,i.async=!1!==n.async,i.data=void 0!==n.data?n.data:null,i.create(),i}return n(o,[{key:"create",value:function(){var e=this,t=q(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd,t.xscheme=!!this.opts.xs;var r=this.xhr=new J(t);try{r.open(this.method,this.uri,this.async);try{if(this.opts.extraHeaders)for(var n in r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0),this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(n)&&r.setRequestHeader(n,this.opts.extraHeaders[n])}catch(e){}if("POST"===this.method)try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{r.setRequestHeader("Accept","*/*")}catch(e){}"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=function(){4===r.readyState&&(200===r.status||1223===r.status?e.onLoad():e.setTimeoutFn((function(){e.onError("number"==typeof r.status?r.status:0)}),0))},r.send(this.data)}catch(t){return void this.setTimeoutFn((function(){e.onError(t)}),0)}"undefined"!=typeof document&&(this.index=o.requestsCount++,o.requests[this.index]=this)}},{key:"onError",value:function(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}},{key:"cleanup",value:function(e){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=K,e)try{this.xhr.abort()}catch(e){}"undefined"!=typeof document&&delete o.requests[this.index],this.xhr=null}}},{key:"onLoad",value:function(){var e=this.xhr.responseText;null!==e&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}},{key:"abort",value:function(){this.cleanup()}}]),o}(B);if(Z.requestsCount=0,Z.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",ee);else if("function"==typeof addEventListener){addEventListener("onpagehide"in C?"pagehide":"unload",ee,!1)}function ee(){for(var e in Z.requests)Z.requests.hasOwnProperty(e)&&Z.requests[e].abort()}var te="function"==typeof Promise&&"function"==typeof Promise.resolve?function(e){return Promise.resolve().then(e)}:function(e,t){return t(e,0)},re=C.WebSocket||C.MozWebSocket,ne="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),oe=function(e){i(o,e);var r=f(o);function o(e){var n;return t(this,o),(n=r.call(this,e)).supportsBinary=!e.forceBase64,n}return n(o,[{key:"doOpen",value:function(){if(this.check()){var e=this.uri(),t=this.opts.protocols,r=ne?{}:q(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=ne?new re(e,t,r):t?new re(e,t):new re(e)}catch(e){return this.emitReserved("error",e)}this.ws.binaryType=this.socket.binaryType||"arraybuffer",this.addEventListeners()}}},{key:"addEventListeners",value:function(){var e=this;this.ws.onopen=function(){e.opts.autoUnref&&e.ws._socket.unref(),e.onOpen()},this.ws.onclose=function(t){return e.onClose({description:"websocket connection closed",context:t})},this.ws.onmessage=function(t){return e.onData(t.data)},this.ws.onerror=function(t){return e.onError("websocket error",t)}}},{key:"write",value:function(e){var t=this;this.writable=!1;for(var r=function(r){var n=e[r],o=r===e.length-1;k(n,t.supportsBinary,(function(e){try{t.ws.send(e)}catch(e){}o&&te((function(){t.writable=!0,t.emitReserved("drain")}),t.setTimeoutFn)}))},n=0;n<e.length;n++)r(n)}},{key:"doClose",value:function(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}},{key:"uri",value:function(){var e=this.query||{},t=this.opts.secure?"wss":"ws",r="";this.opts.port&&("wss"===t&&443!==Number(this.opts.port)||"ws"===t&&80!==Number(this.opts.port))&&(r=":"+this.opts.port),this.opts.timestampRequests&&(e[this.opts.timestampParam]=X()),this.supportsBinary||(e.b64=1);var n=$(e);return t+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+r+this.opts.path+(n.length?"?"+n:"")}},{key:"check",value:function(){return!!re}},{key:"name",get:function(){return"websocket"}}]),o}(F),ie={websocket:oe,polling:Y},se=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,ae=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ue(e){var t=e,r=e.indexOf("["),n=e.indexOf("]");-1!=r&&-1!=n&&(e=e.substring(0,r)+e.substring(r,n).replace(/:/g,";")+e.substring(n,e.length));for(var o,i,s=se.exec(e||""),a={},u=14;u--;)a[ae[u]]=s[u]||"";return-1!=r&&-1!=n&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=function(e,t){var r=/\/{2,9}/g,n=t.replace(r,"/").split("/");"/"!=t.slice(0,1)&&0!==t.length||n.splice(0,1);"/"==t.slice(-1)&&n.splice(n.length-1,1);return n}(0,a.path),a.queryKey=(o=a.query,i={},o.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(e,t,r){t&&(i[t]=r)})),i),a}var ce=function(r){i(a,r);var s=f(a);function a(r){var n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t(this,a),n=s.call(this),r&&"object"===e(r)&&(i=r,r=null),r?(r=ue(r),i.hostname=r.host,i.secure="https"===r.protocol||"wss"===r.protocol,i.port=r.port,r.query&&(i.query=r.query)):i.host&&(i.hostname=ue(i.host).host),_(h(n),i),n.secure=null!=i.secure?i.secure:"undefined"!=typeof location&&"https:"===location.protocol,i.hostname&&!i.port&&(i.port=n.secure?"443":"80"),n.hostname=i.hostname||("undefined"!=typeof location?location.hostname:"localhost"),n.port=i.port||("undefined"!=typeof location&&location.port?location.port:n.secure?"443":"80"),n.transports=i.transports||["polling","websocket"],n.readyState="",n.writeBuffer=[],n.prevBufferLen=0,n.opts=o({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!0},i),n.opts.path=n.opts.path.replace(/\/$/,"")+"/","string"==typeof n.opts.query&&(n.opts.query=z(n.opts.query)),n.id=null,n.upgrades=null,n.pingInterval=null,n.pingTimeout=null,n.pingTimeoutTimer=null,"function"==typeof addEventListener&&(n.opts.closeOnBeforeunload&&(n.beforeunloadEventListener=function(){n.transport&&(n.transport.removeAllListeners(),n.transport.close())},addEventListener("beforeunload",n.beforeunloadEventListener,!1)),"localhost"!==n.hostname&&(n.offlineEventListener=function(){n.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",n.offlineEventListener,!1))),n.open(),n}return n(a,[{key:"createTransport",value:function(e){var t=o({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);var r=o({},this.opts.transportOptions[e],this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port});return new ie[e](r)}},{key:"open",value:function(){var e,t=this;if(this.opts.rememberUpgrade&&a.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))e="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((function(){t.emitReserved("error","No transports available")}),0);e=this.transports[0]}this.readyState="opening";try{e=this.createTransport(e)}catch(e){return this.transports.shift(),void this.open()}e.open(),this.setTransport(e)}},{key:"setTransport",value:function(e){var t=this;this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(function(e){return t.onClose("transport close",e)}))}},{key:"probe",value:function(e){var t=this,r=this.createTransport(e),n=!1;a.priorWebsocketSuccess=!1;var o=function(){n||(r.send([{type:"ping",data:"probe"}]),r.once("packet",(function(e){if(!n)if("pong"===e.type&&"probe"===e.data){if(t.upgrading=!0,t.emitReserved("upgrading",r),!r)return;a.priorWebsocketSuccess="websocket"===r.name,t.transport.pause((function(){n||"closed"!==t.readyState&&(h(),t.setTransport(r),r.send([{type:"upgrade"}]),t.emitReserved("upgrade",r),r=null,t.upgrading=!1,t.flush())}))}else{var o=new Error("probe error");o.transport=r.name,t.emitReserved("upgradeError",o)}})))};function i(){n||(n=!0,h(),r.close(),r=null)}var s=function(e){var n=new Error("probe error: "+e);n.transport=r.name,i(),t.emitReserved("upgradeError",n)};function u(){s("transport closed")}function c(){s("socket closed")}function p(e){r&&e.name!==r.name&&i()}var h=function(){r.removeListener("open",o),r.removeListener("error",s),r.removeListener("close",u),t.off("close",c),t.off("upgrading",p)};r.once("open",o),r.once("error",s),r.once("close",u),this.once("close",c),this.once("upgrading",p),r.open()}},{key:"onOpen",value:function(){if(this.readyState="open",a.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade&&this.transport.pause)for(var e=0,t=this.upgrades.length;e<t;e++)this.probe(this.upgrades[e])}},{key:"onPacket",value:function(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.resetPingTimeout(),this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":var t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data)}}},{key:"onHandshake",value:function(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}},{key:"resetPingTimeout",value:function(){var e=this;this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((function(){e.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}},{key:"onDrain",value:function(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}},{key:"flush",value:function(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){var e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}},{key:"getWritablePackets",value:function(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;for(var e,t=1,r=0;r<this.writeBuffer.length;r++){var n=this.writeBuffer[r].data;if(n&&(t+="string"==typeof(e=n)?function(e){for(var t=0,r=0,n=0,o=e.length;n<o;n++)(t=e.charCodeAt(n))<128?r+=1:t<2048?r+=2:t<55296||t>=57344?r+=3:(n++,r+=4);return r}(e):Math.ceil(1.33*(e.byteLength||e.size))),r>0&&t>this.maxPayload)return this.writeBuffer.slice(0,r);t+=2}return this.writeBuffer}},{key:"write",value:function(e,t,r){return this.sendPacket("message",e,t,r),this}},{key:"send",value:function(e,t,r){return this.sendPacket("message",e,t,r),this}},{key:"sendPacket",value:function(e,t,r,n){if("function"==typeof t&&(n=t,t=void 0),"function"==typeof r&&(n=r,r=null),"closing"!==this.readyState&&"closed"!==this.readyState){(r=r||{}).compress=!1!==r.compress;var o={type:e,data:t,options:r};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),n&&this.once("flush",n),this.flush()}}},{key:"close",value:function(){var e=this,t=function(){e.onClose("forced close"),e.transport.close()},r=function r(){e.off("upgrade",r),e.off("upgradeError",r),t()},n=function(){e.once("upgrade",r),e.once("upgradeError",r)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(function(){e.upgrading?n():t()})):this.upgrading?n():t()),this}},{key:"onError",value:function(e){a.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}},{key:"onClose",value:function(e,t){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}},{key:"filterUpgrades",value:function(e){for(var t=[],r=0,n=e.length;r<n;r++)~this.transports.indexOf(e[r])&&t.push(e[r]);return t}}]),a}(B);ce.protocol=4;return function(e,t){return new ce(e,t)}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).eio=t()}(this,(function(){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(o=n.key,i=void 0,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"))?i:String(i)),n)}var o,i}function n(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}function i(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&&a(e,t)}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function u(){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 c(e,t,r){return c=u()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&a(o,r.prototype),o},c.apply(null,arguments)}function p(e){var t="function"==typeof Map?new Map:void 0;return p=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return c(e,arguments,s(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,e)},p(e)}function h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(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 h(e)}function f(e){var t=u();return function(){var r,n=s(e);if(t){var o=s(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return l(this,r)}}function d(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=s(e)););return e}function y(){return y="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=d(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},y.apply(this,arguments)}var v=Object.create(null);v.open="0",v.close="1",v.ping="2",v.pong="3",v.message="4",v.upgrade="5",v.noop="6";var m=Object.create(null);Object.keys(v).forEach((function(e){m[v[e]]=e}));for(var g={type:"error",data:"parser error"},b="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),k="function"==typeof ArrayBuffer,w=function(e,t,r){var n,o=e.type,i=e.data;return b&&i instanceof Blob?t?r(i):T(i,r):k&&(i instanceof ArrayBuffer||(n=i,"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(n):n&&n.buffer instanceof ArrayBuffer))?t?r(i):T(new Blob([i]),r):r(v[o]+(i||""))},T=function(e,t){var r=new FileReader;return r.onload=function(){var e=r.result.split(",")[1];t("b"+e)},r.readAsDataURL(e)},S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",O="undefined"==typeof Uint8Array?[]:new Uint8Array(256),R=0;R<S.length;R++)O[S.charCodeAt(R)]=R;var x="function"==typeof ArrayBuffer,E=function(e,t){if("string"!=typeof e)return{type:"message",data:B(e,t)};var r=e.charAt(0);return"b"===r?{type:"message",data:P(e.substring(1),t)}:m[r]?e.length>1?{type:m[r],data:e.substring(1)}:{type:m[r]}:g},P=function(e,t){if(x){var r=function(e){var t,r,n,o,i,s=.75*e.length,a=e.length,u=0;"="===e[e.length-1]&&(s--,"="===e[e.length-2]&&s--);var c=new ArrayBuffer(s),p=new Uint8Array(c);for(t=0;t<a;t+=4)r=O[e.charCodeAt(t)],n=O[e.charCodeAt(t+1)],o=O[e.charCodeAt(t+2)],i=O[e.charCodeAt(t+3)],p[u++]=r<<2|n>>4,p[u++]=(15&n)<<4|o>>2,p[u++]=(3&o)<<6|63&i;return c}(e);return B(r,t)}return{base64:!0,data:e}},B=function(e,t){return"blob"===t&&e instanceof ArrayBuffer?new Blob([e]):e},L=String.fromCharCode(30);function C(e){if(e)return function(e){for(var t in C.prototype)e[t]=C.prototype[t];return e}(e)}C.prototype.on=C.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},C.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this},C.prototype.off=C.prototype.removeListener=C.prototype.removeAllListeners=C.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r,n=this._callbacks["$"+e];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;o<n.length;o++)if((r=n[o])===t||r.fn===t){n.splice(o,1);break}return 0===n.length&&delete this._callbacks["$"+e],this},C.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),r=this._callbacks["$"+e],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(r){n=0;for(var o=(r=r.slice(0)).length;n<o;++n)r[n].apply(this,t)}return this},C.prototype.emitReserved=C.prototype.emit,C.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},C.prototype.hasListeners=function(e){return!!this.listeners(e).length};var q="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function j(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return r.reduce((function(t,r){return e.hasOwnProperty(r)&&(t[r]=e[r]),t}),{})}var A=q.setTimeout,_=q.clearTimeout;function U(e,t){t.useNativeTimers?(e.setTimeoutFn=A.bind(q),e.clearTimeoutFn=_.bind(q)):(e.setTimeoutFn=q.setTimeout.bind(q),e.clearTimeoutFn=q.clearTimeout.bind(q))}var H,F=function(e){i(o,e);var r=f(o);function o(e,n,i){var s;return t(this,o),(s=r.call(this,e)).description=n,s.context=i,s.type="TransportError",s}return n(o)}(p(Error)),D=function(e){i(o,e);var r=f(o);function o(e){var n;return t(this,o),(n=r.call(this)).writable=!1,U(h(n),e),n.opts=e,n.query=e.query,n.socket=e.socket,n}return n(o,[{key:"onError",value:function(e,t,r){return y(s(o.prototype),"emitReserved",this).call(this,"error",new F(e,t,r)),this}},{key:"open",value:function(){return this.readyState="opening",this.doOpen(),this}},{key:"close",value:function(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}},{key:"send",value:function(e){"open"===this.readyState&&this.write(e)}},{key:"onOpen",value:function(){this.readyState="open",this.writable=!0,y(s(o.prototype),"emitReserved",this).call(this,"open")}},{key:"onData",value:function(e){var t=E(e,this.socket.binaryType);this.onPacket(t)}},{key:"onPacket",value:function(e){y(s(o.prototype),"emitReserved",this).call(this,"packet",e)}},{key:"onClose",value:function(e){this.readyState="closed",y(s(o.prototype),"emitReserved",this).call(this,"close",e)}},{key:"pause",value:function(e){}}]),o}(C),M="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),I={},W=0,N=0;function X(e){var t="";do{t=M[e%64]+t,e=Math.floor(e/64)}while(e>0);return t}function $(){var e=X(+new Date);return e!==H?(W=0,H=e):e+"."+X(W++)}for(;N<64;N++)I[M[N]]=N;function z(e){var t="";for(var r in e)e.hasOwnProperty(r)&&(t.length&&(t+="&"),t+=encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return t}function V(e){for(var t={},r=e.split("&"),n=0,o=r.length;n<o;n++){var i=r[n].split("=");t[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return t}var G=!1;try{G="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(e){}var J=G;function K(e){var t=e.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!t||J))return new XMLHttpRequest}catch(e){}if(!t)try{return new(q[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}}function Q(){}var Y=null!=new K({xdomain:!1}).responseType,Z=function(e){i(s,e);var r=f(s);function s(e){var n;if(t(this,s),(n=r.call(this,e)).polling=!1,"undefined"!=typeof location){var o="https:"===location.protocol,i=location.port;i||(i=o?"443":"80"),n.xd="undefined"!=typeof location&&e.hostname!==location.hostname||i!==e.port,n.xs=e.secure!==o}var a=e&&e.forceBase64;return n.supportsBinary=Y&&!a,n}return n(s,[{key:"name",get:function(){return"polling"}},{key:"doOpen",value:function(){this.poll()}},{key:"pause",value:function(e){var t=this;this.readyState="pausing";var r=function(){t.readyState="paused",e()};if(this.polling||!this.writable){var n=0;this.polling&&(n++,this.once("pollComplete",(function(){--n||r()}))),this.writable||(n++,this.once("drain",(function(){--n||r()})))}else r()}},{key:"poll",value:function(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}},{key:"onData",value:function(e){var t=this;(function(e,t){for(var r=e.split(L),n=[],o=0;o<r.length;o++){var i=E(r[o],t);if(n.push(i),"error"===i.type)break}return n})(e,this.socket.binaryType).forEach((function(e){if("opening"===t.readyState&&"open"===e.type&&t.onOpen(),"close"===e.type)return t.onClose({description:"transport closed by the server"}),!1;t.onPacket(e)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}},{key:"doClose",value:function(){var e=this,t=function(){e.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}},{key:"write",value:function(e){var t=this;this.writable=!1,function(e,t){var r=e.length,n=new Array(r),o=0;e.forEach((function(e,i){w(e,!1,(function(e){n[i]=e,++o===r&&t(n.join(L))}))}))}(e,(function(e){t.doWrite(e,(function(){t.writable=!0,t.emitReserved("drain")}))}))}},{key:"uri",value:function(){var e=this.query||{},t=this.opts.secure?"https":"http",r="";!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=$()),this.supportsBinary||e.sid||(e.b64=1),this.opts.port&&("https"===t&&443!==Number(this.opts.port)||"http"===t&&80!==Number(this.opts.port))&&(r=":"+this.opts.port);var n=z(e);return t+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+r+this.opts.path+(n.length?"?"+n:"")}},{key:"request",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return o(e,{xd:this.xd,xs:this.xs},this.opts),new ee(this.uri(),e)}},{key:"doWrite",value:function(e,t){var r=this,n=this.request({method:"POST",data:e});n.on("success",t),n.on("error",(function(e,t){r.onError("xhr post error",e,t)}))}},{key:"doPoll",value:function(){var e=this,t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(function(t,r){e.onError("xhr poll error",t,r)})),this.pollXhr=t}}]),s}(D),ee=function(e){i(o,e);var r=f(o);function o(e,n){var i;return t(this,o),U(h(i=r.call(this)),n),i.opts=n,i.method=n.method||"GET",i.uri=e,i.async=!1!==n.async,i.data=void 0!==n.data?n.data:null,i.create(),i}return n(o,[{key:"create",value:function(){var e=this,t=j(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd,t.xscheme=!!this.opts.xs;var r=this.xhr=new K(t);try{r.open(this.method,this.uri,this.async);try{if(this.opts.extraHeaders)for(var n in r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0),this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(n)&&r.setRequestHeader(n,this.opts.extraHeaders[n])}catch(e){}if("POST"===this.method)try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{r.setRequestHeader("Accept","*/*")}catch(e){}"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=function(){4===r.readyState&&(200===r.status||1223===r.status?e.onLoad():e.setTimeoutFn((function(){e.onError("number"==typeof r.status?r.status:0)}),0))},r.send(this.data)}catch(t){return void this.setTimeoutFn((function(){e.onError(t)}),0)}"undefined"!=typeof document&&(this.index=o.requestsCount++,o.requests[this.index]=this)}},{key:"onError",value:function(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}},{key:"cleanup",value:function(e){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=Q,e)try{this.xhr.abort()}catch(e){}"undefined"!=typeof document&&delete o.requests[this.index],this.xhr=null}}},{key:"onLoad",value:function(){var e=this.xhr.responseText;null!==e&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}},{key:"abort",value:function(){this.cleanup()}}]),o}(C);if(ee.requestsCount=0,ee.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",te);else if("function"==typeof addEventListener){addEventListener("onpagehide"in q?"pagehide":"unload",te,!1)}function te(){for(var e in ee.requests)ee.requests.hasOwnProperty(e)&&ee.requests[e].abort()}var re="function"==typeof Promise&&"function"==typeof Promise.resolve?function(e){return Promise.resolve().then(e)}:function(e,t){return t(e,0)},ne=q.WebSocket||q.MozWebSocket,oe="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),ie=function(e){i(o,e);var r=f(o);function o(e){var n;return t(this,o),(n=r.call(this,e)).supportsBinary=!e.forceBase64,n}return n(o,[{key:"name",get:function(){return"websocket"}},{key:"doOpen",value:function(){if(this.check()){var e=this.uri(),t=this.opts.protocols,r=oe?{}:j(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=oe?new ne(e,t,r):t?new ne(e,t):new ne(e)}catch(e){return this.emitReserved("error",e)}this.ws.binaryType=this.socket.binaryType||"arraybuffer",this.addEventListeners()}}},{key:"addEventListeners",value:function(){var e=this;this.ws.onopen=function(){e.opts.autoUnref&&e.ws._socket.unref(),e.onOpen()},this.ws.onclose=function(t){return e.onClose({description:"websocket connection closed",context:t})},this.ws.onmessage=function(t){return e.onData(t.data)},this.ws.onerror=function(t){return e.onError("websocket error",t)}}},{key:"write",value:function(e){var t=this;this.writable=!1;for(var r=function(r){var n=e[r],o=r===e.length-1;w(n,t.supportsBinary,(function(e){try{t.ws.send(e)}catch(e){}o&&re((function(){t.writable=!0,t.emitReserved("drain")}),t.setTimeoutFn)}))},n=0;n<e.length;n++)r(n)}},{key:"doClose",value:function(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}},{key:"uri",value:function(){var e=this.query||{},t=this.opts.secure?"wss":"ws",r="";this.opts.port&&("wss"===t&&443!==Number(this.opts.port)||"ws"===t&&80!==Number(this.opts.port))&&(r=":"+this.opts.port),this.opts.timestampRequests&&(e[this.opts.timestampParam]=$()),this.supportsBinary||(e.b64=1);var n=z(e);return t+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+r+this.opts.path+(n.length?"?"+n:"")}},{key:"check",value:function(){return!!ne}}]),o}(D),se={websocket:ie,polling:Z},ae=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,ue=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ce(e){var t=e,r=e.indexOf("["),n=e.indexOf("]");-1!=r&&-1!=n&&(e=e.substring(0,r)+e.substring(r,n).replace(/:/g,";")+e.substring(n,e.length));for(var o,i,s=ae.exec(e||""),a={},u=14;u--;)a[ue[u]]=s[u]||"";return-1!=r&&-1!=n&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=function(e,t){var r=/\/{2,9}/g,n=t.replace(r,"/").split("/");"/"!=t.slice(0,1)&&0!==t.length||n.splice(0,1);"/"==t.slice(-1)&&n.splice(n.length-1,1);return n}(0,a.path),a.queryKey=(o=a.query,i={},o.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(e,t,r){t&&(i[t]=r)})),i),a}var pe=function(r){i(a,r);var s=f(a);function a(r){var n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t(this,a),(n=s.call(this)).writeBuffer=[],r&&"object"===e(r)&&(i=r,r=null),r?(r=ce(r),i.hostname=r.host,i.secure="https"===r.protocol||"wss"===r.protocol,i.port=r.port,r.query&&(i.query=r.query)):i.host&&(i.hostname=ce(i.host).host),U(h(n),i),n.secure=null!=i.secure?i.secure:"undefined"!=typeof location&&"https:"===location.protocol,i.hostname&&!i.port&&(i.port=n.secure?"443":"80"),n.hostname=i.hostname||("undefined"!=typeof location?location.hostname:"localhost"),n.port=i.port||("undefined"!=typeof location&&location.port?location.port:n.secure?"443":"80"),n.transports=i.transports||["polling","websocket"],n.writeBuffer=[],n.prevBufferLen=0,n.opts=o({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!0},i),n.opts.path=n.opts.path.replace(/\/$/,"")+(n.opts.addTrailingSlash?"/":""),"string"==typeof n.opts.query&&(n.opts.query=V(n.opts.query)),n.id=null,n.upgrades=null,n.pingInterval=null,n.pingTimeout=null,n.pingTimeoutTimer=null,"function"==typeof addEventListener&&(n.opts.closeOnBeforeunload&&(n.beforeunloadEventListener=function(){n.transport&&(n.transport.removeAllListeners(),n.transport.close())},addEventListener("beforeunload",n.beforeunloadEventListener,!1)),"localhost"!==n.hostname&&(n.offlineEventListener=function(){n.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",n.offlineEventListener,!1))),n.open(),n}return n(a,[{key:"createTransport",value:function(e){var t=o({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);var r=o({},this.opts.transportOptions[e],this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port});return new se[e](r)}},{key:"open",value:function(){var e,t=this;if(this.opts.rememberUpgrade&&a.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))e="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((function(){t.emitReserved("error","No transports available")}),0);e=this.transports[0]}this.readyState="opening";try{e=this.createTransport(e)}catch(e){return this.transports.shift(),void this.open()}e.open(),this.setTransport(e)}},{key:"setTransport",value:function(e){var t=this;this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(function(e){return t.onClose("transport close",e)}))}},{key:"probe",value:function(e){var t=this,r=this.createTransport(e),n=!1;a.priorWebsocketSuccess=!1;var o=function(){n||(r.send([{type:"ping",data:"probe"}]),r.once("packet",(function(e){if(!n)if("pong"===e.type&&"probe"===e.data){if(t.upgrading=!0,t.emitReserved("upgrading",r),!r)return;a.priorWebsocketSuccess="websocket"===r.name,t.transport.pause((function(){n||"closed"!==t.readyState&&(h(),t.setTransport(r),r.send([{type:"upgrade"}]),t.emitReserved("upgrade",r),r=null,t.upgrading=!1,t.flush())}))}else{var o=new Error("probe error");o.transport=r.name,t.emitReserved("upgradeError",o)}})))};function i(){n||(n=!0,h(),r.close(),r=null)}var s=function(e){var n=new Error("probe error: "+e);n.transport=r.name,i(),t.emitReserved("upgradeError",n)};function u(){s("transport closed")}function c(){s("socket closed")}function p(e){r&&e.name!==r.name&&i()}var h=function(){r.removeListener("open",o),r.removeListener("error",s),r.removeListener("close",u),t.off("close",c),t.off("upgrading",p)};r.once("open",o),r.once("error",s),r.once("close",u),this.once("close",c),this.once("upgrading",p),r.open()}},{key:"onOpen",value:function(){if(this.readyState="open",a.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade)for(var e=0,t=this.upgrades.length;e<t;e++)this.probe(this.upgrades[e])}},{key:"onPacket",value:function(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.resetPingTimeout(),this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":var t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data)}}},{key:"onHandshake",value:function(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}},{key:"resetPingTimeout",value:function(){var e=this;this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((function(){e.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}},{key:"onDrain",value:function(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}},{key:"flush",value:function(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){var e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}},{key:"getWritablePackets",value:function(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;for(var e,t=1,r=0;r<this.writeBuffer.length;r++){var n=this.writeBuffer[r].data;if(n&&(t+="string"==typeof(e=n)?function(e){for(var t=0,r=0,n=0,o=e.length;n<o;n++)(t=e.charCodeAt(n))<128?r+=1:t<2048?r+=2:t<55296||t>=57344?r+=3:(n++,r+=4);return r}(e):Math.ceil(1.33*(e.byteLength||e.size))),r>0&&t>this.maxPayload)return this.writeBuffer.slice(0,r);t+=2}return this.writeBuffer}},{key:"write",value:function(e,t,r){return this.sendPacket("message",e,t,r),this}},{key:"send",value:function(e,t,r){return this.sendPacket("message",e,t,r),this}},{key:"sendPacket",value:function(e,t,r,n){if("function"==typeof t&&(n=t,t=void 0),"function"==typeof r&&(n=r,r=null),"closing"!==this.readyState&&"closed"!==this.readyState){(r=r||{}).compress=!1!==r.compress;var o={type:e,data:t,options:r};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),n&&this.once("flush",n),this.flush()}}},{key:"close",value:function(){var e=this,t=function(){e.onClose("forced close"),e.transport.close()},r=function r(){e.off("upgrade",r),e.off("upgradeError",r),t()},n=function(){e.once("upgrade",r),e.once("upgradeError",r)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(function(){e.upgrading?n():t()})):this.upgrading?n():t()),this}},{key:"onError",value:function(e){a.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}},{key:"onClose",value:function(e,t){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}},{key:"filterUpgrades",value:function(e){for(var t=[],r=0,n=e.length;r<n;r++)~this.transports.indexOf(e[r])&&t.push(e[r]);return t}}]),a}(C);pe.protocol=4;return function(e,t){return new pe(e,t)}})); | ||
//# sourceMappingURL=engine.io.min.js.map |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "6.2.3", | ||
"version": "6.3.0", | ||
"main": "./build/cjs/index.js", | ||
@@ -46,3 +46,3 @@ "module": "./build/esm/index.js", | ||
"engine.io-parser": "~5.0.3", | ||
"ws": "~8.2.3", | ||
"ws": "~8.11.0", | ||
"xmlhttprequest-ssl": "~2.0.0" | ||
@@ -67,3 +67,3 @@ }, | ||
"mocha": "^3.2.0", | ||
"prettier": "^1.19.1", | ||
"prettier": "^2.8.1", | ||
"rollup": "^2.58.0", | ||
@@ -70,0 +70,0 @@ "rollup-plugin-terser": "^7.0.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
610244
8448
+ Addedws@8.11.0(transitive)
- Removedws@8.2.3(transitive)
Updatedws@~8.11.0