| import { n as __exportAll, r as __toESM, t as __commonJSMin } from "./chunk-CYJPkc-J.js"; |
| |
| var PACKET_TYPES = Object.create(null); |
| PACKET_TYPES["open"] = "0"; |
| PACKET_TYPES["close"] = "1"; |
| PACKET_TYPES["ping"] = "2"; |
| PACKET_TYPES["pong"] = "3"; |
| PACKET_TYPES["message"] = "4"; |
| PACKET_TYPES["upgrade"] = "5"; |
| PACKET_TYPES["noop"] = "6"; |
| var PACKET_TYPES_REVERSE = Object.create(null); |
| Object.keys(PACKET_TYPES).forEach((key) => { |
| PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key; |
| }); |
| var ERROR_PACKET = { |
| type: "error", |
| data: "parser error" |
| }; |
| |
| |
| var withNativeBlob$1 = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]"; |
| var withNativeArrayBuffer$2 = typeof ArrayBuffer === "function"; |
| var isView$1 = (obj) => { |
| return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer; |
| }; |
| var encodePacket = ({ type, data }, supportsBinary, callback) => { |
| if (withNativeBlob$1 && data instanceof Blob) if (supportsBinary) return callback(data); |
| else return encodeBlobAsBase64(data, callback); |
| else if (withNativeArrayBuffer$2 && (data instanceof ArrayBuffer || isView$1(data))) if (supportsBinary) return callback(data); |
| else return encodeBlobAsBase64(new Blob([data]), callback); |
| return callback(PACKET_TYPES[type] + (data || "")); |
| }; |
| var encodeBlobAsBase64 = (data, callback) => { |
| const fileReader = new FileReader(); |
| fileReader.onload = function() { |
| const content = fileReader.result.split(",")[1]; |
| callback("b" + (content || "")); |
| }; |
| return fileReader.readAsDataURL(data); |
| }; |
| function toArray(data) { |
| if (data instanceof Uint8Array) return data; |
| else if (data instanceof ArrayBuffer) return new Uint8Array(data); |
| else return new Uint8Array(data.buffer, data.byteOffset, data.byteLength); |
| } |
| var TEXT_ENCODER; |
| function encodePacketToBinary(packet, callback) { |
| if (withNativeBlob$1 && packet.data instanceof Blob) return packet.data.arrayBuffer().then(toArray).then(callback); |
| else if (withNativeArrayBuffer$2 && (packet.data instanceof ArrayBuffer || isView$1(packet.data))) return callback(toArray(packet.data)); |
| encodePacket(packet, false, (encoded) => { |
| if (!TEXT_ENCODER) TEXT_ENCODER = new TextEncoder(); |
| callback(TEXT_ENCODER.encode(encoded)); |
| }); |
| } |
| |
| |
| var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| var lookup$1 = typeof Uint8Array === "undefined" ? [] : new Uint8Array(256); |
| for (let i = 0; i < 64; i++) lookup$1[chars.charCodeAt(i)] = i; |
| var decode$1 = (base64) => { |
| let bufferLength = base64.length * .75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4; |
| if (base64[base64.length - 1] === "=") { |
| bufferLength--; |
| if (base64[base64.length - 2] === "=") bufferLength--; |
| } |
| const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer); |
| for (i = 0; i < len; i += 4) { |
| encoded1 = lookup$1[base64.charCodeAt(i)]; |
| encoded2 = lookup$1[base64.charCodeAt(i + 1)]; |
| encoded3 = lookup$1[base64.charCodeAt(i + 2)]; |
| encoded4 = lookup$1[base64.charCodeAt(i + 3)]; |
| bytes[p++] = encoded1 << 2 | encoded2 >> 4; |
| bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2; |
| bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63; |
| } |
| return arraybuffer; |
| }; |
| |
| |
| var withNativeArrayBuffer$1 = typeof ArrayBuffer === "function"; |
| var decodePacket = (encodedPacket, binaryType) => { |
| if (typeof encodedPacket !== "string") return { |
| type: "message", |
| data: mapBinary(encodedPacket, binaryType) |
| }; |
| const type = encodedPacket.charAt(0); |
| if (type === "b") return { |
| type: "message", |
| data: decodeBase64Packet(encodedPacket.substring(1), binaryType) |
| }; |
| if (!PACKET_TYPES_REVERSE[type]) return ERROR_PACKET; |
| return encodedPacket.length > 1 ? { |
| type: PACKET_TYPES_REVERSE[type], |
| data: encodedPacket.substring(1) |
| } : { type: PACKET_TYPES_REVERSE[type] }; |
| }; |
| var decodeBase64Packet = (data, binaryType) => { |
| if (withNativeArrayBuffer$1) return mapBinary(decode$1(data), binaryType); |
| else return { |
| base64: true, |
| data |
| }; |
| }; |
| var mapBinary = (data, binaryType) => { |
| switch (binaryType) { |
| case "blob": if (data instanceof Blob) return data; |
| else return new Blob([data]); |
| default: if (data instanceof ArrayBuffer) return data; |
| else return data.buffer; |
| } |
| }; |
| |
| |
| var SEPARATOR = String.fromCharCode(30); |
| var encodePayload = (packets, callback) => { |
| const length = packets.length; |
| const encodedPackets = new Array(length); |
| let count = 0; |
| packets.forEach((packet, i) => { |
| encodePacket(packet, false, (encodedPacket) => { |
| encodedPackets[i] = encodedPacket; |
| if (++count === length) callback(encodedPackets.join(SEPARATOR)); |
| }); |
| }); |
| }; |
| var decodePayload = (encodedPayload, binaryType) => { |
| const encodedPackets = encodedPayload.split(SEPARATOR); |
| const packets = []; |
| for (let i = 0; i < encodedPackets.length; i++) { |
| const decodedPacket = decodePacket(encodedPackets[i], binaryType); |
| packets.push(decodedPacket); |
| if (decodedPacket.type === "error") break; |
| } |
| return packets; |
| }; |
| function createPacketEncoderStream() { |
| return new TransformStream({ transform(packet, controller) { |
| encodePacketToBinary(packet, (encodedPacket) => { |
| const payloadLength = encodedPacket.length; |
| let header; |
| if (payloadLength < 126) { |
| header = new Uint8Array(1); |
| new DataView(header.buffer).setUint8(0, payloadLength); |
| } else if (payloadLength < 65536) { |
| header = new Uint8Array(3); |
| const view = new DataView(header.buffer); |
| view.setUint8(0, 126); |
| view.setUint16(1, payloadLength); |
| } else { |
| header = new Uint8Array(9); |
| const view = new DataView(header.buffer); |
| view.setUint8(0, 127); |
| view.setBigUint64(1, BigInt(payloadLength)); |
| } |
| if (packet.data && typeof packet.data !== "string") header[0] |= 128; |
| controller.enqueue(header); |
| controller.enqueue(encodedPacket); |
| }); |
| } }); |
| } |
| var TEXT_DECODER; |
| function totalLength(chunks) { |
| return chunks.reduce((acc, chunk) => acc + chunk.length, 0); |
| } |
| function concatChunks(chunks, size) { |
| if (chunks[0].length === size) return chunks.shift(); |
| const buffer = new Uint8Array(size); |
| let j = 0; |
| for (let i = 0; i < size; i++) { |
| buffer[i] = chunks[0][j++]; |
| if (j === chunks[0].length) { |
| chunks.shift(); |
| j = 0; |
| } |
| } |
| if (chunks.length && j < chunks[0].length) chunks[0] = chunks[0].slice(j); |
| return buffer; |
| } |
| function createPacketDecoderStream(maxPayload, binaryType) { |
| if (!TEXT_DECODER) TEXT_DECODER = new TextDecoder(); |
| const chunks = []; |
| let state = 0; |
| let expectedLength = -1; |
| let isBinary = false; |
| return new TransformStream({ transform(chunk, controller) { |
| chunks.push(chunk); |
| while (true) { |
| if (state === 0) { |
| if (totalLength(chunks) < 1) break; |
| const header = concatChunks(chunks, 1); |
| isBinary = (header[0] & 128) === 128; |
| expectedLength = header[0] & 127; |
| if (expectedLength < 126) state = 3; |
| else if (expectedLength === 126) state = 1; |
| else state = 2; |
| } else if (state === 1) { |
| if (totalLength(chunks) < 2) break; |
| const headerArray = concatChunks(chunks, 2); |
| expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0); |
| state = 3; |
| } else if (state === 2) { |
| if (totalLength(chunks) < 8) break; |
| const headerArray = concatChunks(chunks, 8); |
| const view = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length); |
| const n = view.getUint32(0); |
| if (n > Math.pow(2, 21) - 1) { |
| controller.enqueue(ERROR_PACKET); |
| break; |
| } |
| expectedLength = n * Math.pow(2, 32) + view.getUint32(4); |
| state = 3; |
| } else { |
| if (totalLength(chunks) < expectedLength) break; |
| const data = concatChunks(chunks, expectedLength); |
| controller.enqueue(decodePacket(isBinary ? data : TEXT_DECODER.decode(data), binaryType)); |
| state = 0; |
| } |
| if (expectedLength === 0 || expectedLength > maxPayload) { |
| controller.enqueue(ERROR_PACKET); |
| break; |
| } |
| } |
| } }); |
| } |
| |
| |
| |
| |
| |
| |
| |
| function Emitter(obj) { |
| if (obj) return mixin(obj); |
| } |
| |
| |
| |
| |
| |
| |
| |
| function mixin(obj) { |
| for (var key in Emitter.prototype) obj[key] = Emitter.prototype[key]; |
| return obj; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| Emitter.prototype.on = Emitter.prototype.addEventListener = function(event, fn) { |
| this._callbacks = this._callbacks || {}; |
| (this._callbacks["$" + event] = this._callbacks["$" + event] || []).push(fn); |
| return this; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Emitter.prototype.once = function(event, fn) { |
| function on() { |
| this.off(event, on); |
| fn.apply(this, arguments); |
| } |
| on.fn = fn; |
| this.on(event, on); |
| return this; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function(event, fn) { |
| this._callbacks = this._callbacks || {}; |
| if (0 == arguments.length) { |
| this._callbacks = {}; |
| return this; |
| } |
| var callbacks = this._callbacks["$" + event]; |
| if (!callbacks) return this; |
| if (1 == arguments.length) { |
| delete this._callbacks["$" + event]; |
| return this; |
| } |
| var cb; |
| for (var i = 0; i < callbacks.length; i++) { |
| cb = callbacks[i]; |
| if (cb === fn || cb.fn === fn) { |
| callbacks.splice(i, 1); |
| break; |
| } |
| } |
| if (callbacks.length === 0) delete this._callbacks["$" + event]; |
| return this; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| Emitter.prototype.emit = function(event) { |
| this._callbacks = this._callbacks || {}; |
| var args = new Array(arguments.length - 1), callbacks = this._callbacks["$" + event]; |
| for (var i = 1; i < arguments.length; i++) args[i - 1] = arguments[i]; |
| if (callbacks) { |
| callbacks = callbacks.slice(0); |
| for (var i = 0, len = callbacks.length; i < len; ++i) callbacks[i].apply(this, args); |
| } |
| return this; |
| }; |
| Emitter.prototype.emitReserved = Emitter.prototype.emit; |
| |
| |
| |
| |
| |
| |
| |
| Emitter.prototype.listeners = function(event) { |
| this._callbacks = this._callbacks || {}; |
| return this._callbacks["$" + event] || []; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| Emitter.prototype.hasListeners = function(event) { |
| return !!this.listeners(event).length; |
| }; |
| |
| |
| var nextTick = (() => { |
| if (typeof Promise === "function" && typeof Promise.resolve === "function") return (cb) => Promise.resolve().then(cb); |
| else return (cb, setTimeoutFn) => setTimeoutFn(cb, 0); |
| })(); |
| var globalThisShim = (() => { |
| if (typeof self !== "undefined") return self; |
| else if (typeof window !== "undefined") return window; |
| else return Function("return this")(); |
| })(); |
| var defaultBinaryType = "arraybuffer"; |
| |
| |
| function pick(obj, ...attr) { |
| return attr.reduce((acc, k) => { |
| if (obj.hasOwnProperty(k)) acc[k] = obj[k]; |
| return acc; |
| }, {}); |
| } |
| var NATIVE_SET_TIMEOUT = globalThisShim.setTimeout; |
| var NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout; |
| function installTimerFunctions(obj, opts) { |
| if (opts.useNativeTimers) { |
| obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim); |
| obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim); |
| } else { |
| obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim); |
| obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim); |
| } |
| } |
| var BASE64_OVERHEAD = 1.33; |
| function byteLength(obj) { |
| if (typeof obj === "string") return utf8Length(obj); |
| return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD); |
| } |
| function utf8Length(str) { |
| let c = 0, length = 0; |
| for (let i = 0, l = str.length; i < l; i++) { |
| c = str.charCodeAt(i); |
| if (c < 128) length += 1; |
| else if (c < 2048) length += 2; |
| else if (c < 55296 || c >= 57344) length += 3; |
| else { |
| i++; |
| length += 4; |
| } |
| } |
| return length; |
| } |
| |
| |
| |
| function randomString() { |
| return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function encode(obj) { |
| let str = ""; |
| for (let i in obj) if (obj.hasOwnProperty(i)) { |
| if (str.length) str += "&"; |
| str += encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]); |
| } |
| return str; |
| } |
| |
| |
| |
| |
| |
| |
| function decode(qs) { |
| let qry = {}; |
| let pairs = qs.split("&"); |
| for (let i = 0, l = pairs.length; i < l; i++) { |
| let pair = pairs[i].split("="); |
| qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); |
| } |
| return qry; |
| } |
| |
| |
| var TransportError = class extends Error { |
| constructor(reason, description, context) { |
| super(reason); |
| this.description = description; |
| this.context = context; |
| this.type = "TransportError"; |
| } |
| }; |
| var Transport = class extends Emitter { |
| |
| |
| |
| |
| |
| |
| constructor(opts) { |
| super(); |
| this.writable = false; |
| installTimerFunctions(this, opts); |
| this.opts = opts; |
| this.query = opts.query; |
| this.socket = opts.socket; |
| this.supportsBinary = !opts.forceBase64; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| onError(reason, description, context) { |
| super.emitReserved("error", new TransportError(reason, description, context)); |
| return this; |
| } |
| |
| |
| |
| open() { |
| this.readyState = "opening"; |
| this.doOpen(); |
| return this; |
| } |
| |
| |
| |
| close() { |
| if (this.readyState === "opening" || this.readyState === "open") { |
| this.doClose(); |
| this.onClose(); |
| } |
| return this; |
| } |
| |
| |
| |
| |
| |
| send(packets) { |
| if (this.readyState === "open") this.write(packets); |
| } |
| |
| |
| |
| |
| |
| onOpen() { |
| this.readyState = "open"; |
| this.writable = true; |
| super.emitReserved("open"); |
| } |
| |
| |
| |
| |
| |
| |
| onData(data) { |
| const packet = decodePacket(data, this.socket.binaryType); |
| this.onPacket(packet); |
| } |
| |
| |
| |
| |
| |
| onPacket(packet) { |
| super.emitReserved("packet", packet); |
| } |
| |
| |
| |
| |
| |
| onClose(details) { |
| this.readyState = "closed"; |
| super.emitReserved("close", details); |
| } |
| |
| |
| |
| |
| |
| pause(onPause) {} |
| createUri(schema, query = {}) { |
| return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query); |
| } |
| _hostname() { |
| const hostname = this.opts.hostname; |
| return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]"; |
| } |
| _port() { |
| if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) return ":" + this.opts.port; |
| else return ""; |
| } |
| _query(query) { |
| const encodedQuery = encode(query); |
| return encodedQuery.length ? "?" + encodedQuery : ""; |
| } |
| }; |
| |
| |
| var Polling = class extends Transport { |
| constructor() { |
| super(...arguments); |
| this._polling = false; |
| } |
| get name() { |
| return "polling"; |
| } |
| |
| |
| |
| |
| |
| |
| doOpen() { |
| this._poll(); |
| } |
| |
| |
| |
| |
| |
| |
| pause(onPause) { |
| this.readyState = "pausing"; |
| const pause = () => { |
| this.readyState = "paused"; |
| onPause(); |
| }; |
| if (this._polling || !this.writable) { |
| let total = 0; |
| if (this._polling) { |
| total++; |
| this.once("pollComplete", function() { |
| --total || pause(); |
| }); |
| } |
| if (!this.writable) { |
| total++; |
| this.once("drain", function() { |
| --total || pause(); |
| }); |
| } |
| } else pause(); |
| } |
| |
| |
| |
| |
| |
| _poll() { |
| this._polling = true; |
| this.doPoll(); |
| this.emitReserved("poll"); |
| } |
| |
| |
| |
| |
| |
| onData(data) { |
| const callback = (packet) => { |
| if ("opening" === this.readyState && packet.type === "open") this.onOpen(); |
| if ("close" === packet.type) { |
| this.onClose({ description: "transport closed by the server" }); |
| return false; |
| } |
| this.onPacket(packet); |
| }; |
| decodePayload(data, this.socket.binaryType).forEach(callback); |
| if ("closed" !== this.readyState) { |
| this._polling = false; |
| this.emitReserved("pollComplete"); |
| if ("open" === this.readyState) this._poll(); |
| } |
| } |
| |
| |
| |
| |
| |
| doClose() { |
| const close = () => { |
| this.write([{ type: "close" }]); |
| }; |
| if ("open" === this.readyState) close(); |
| else this.once("open", close); |
| } |
| |
| |
| |
| |
| |
| |
| write(packets) { |
| this.writable = false; |
| encodePayload(packets, (data) => { |
| this.doWrite(data, () => { |
| this.writable = true; |
| this.emitReserved("drain"); |
| }); |
| }); |
| } |
| |
| |
| |
| |
| |
| uri() { |
| const schema = this.opts.secure ? "https" : "http"; |
| const query = this.query || {}; |
| if (false !== this.opts.timestampRequests) query[this.opts.timestampParam] = randomString(); |
| if (!this.supportsBinary && !query.sid) query.b64 = 1; |
| return this.createUri(schema, query); |
| } |
| }; |
| |
| |
| var value = false; |
| try { |
| value = typeof XMLHttpRequest !== "undefined" && "withCredentials" in new XMLHttpRequest(); |
| } catch (err) {} |
| var hasCORS = value; |
| |
| |
| function empty() {} |
| var BaseXHR = class extends Polling { |
| |
| |
| |
| |
| |
| |
| constructor(opts) { |
| super(opts); |
| if (typeof location !== "undefined") { |
| const isSSL = "https:" === location.protocol; |
| let port = location.port; |
| if (!port) port = isSSL ? "443" : "80"; |
| this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| doWrite(data, fn) { |
| const req = this.request({ |
| method: "POST", |
| data |
| }); |
| req.on("success", fn); |
| req.on("error", (xhrStatus, context) => { |
| this.onError("xhr post error", xhrStatus, context); |
| }); |
| } |
| |
| |
| |
| |
| |
| doPoll() { |
| const req = this.request(); |
| req.on("data", this.onData.bind(this)); |
| req.on("error", (xhrStatus, context) => { |
| this.onError("xhr poll error", xhrStatus, context); |
| }); |
| this.pollXhr = req; |
| } |
| }; |
| var Request = class Request extends Emitter { |
| |
| |
| |
| |
| |
| |
| constructor(createRequest, uri, opts) { |
| super(); |
| this.createRequest = createRequest; |
| installTimerFunctions(this, opts); |
| this._opts = opts; |
| this._method = opts.method || "GET"; |
| this._uri = uri; |
| this._data = void 0 !== opts.data ? opts.data : null; |
| this._create(); |
| } |
| |
| |
| |
| |
| |
| _create() { |
| var _a; |
| const opts = pick(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref"); |
| opts.xdomain = !!this._opts.xd; |
| const xhr = this._xhr = this.createRequest(opts); |
| try { |
| xhr.open(this._method, this._uri, true); |
| try { |
| if (this._opts.extraHeaders) { |
| xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true); |
| for (let i in this._opts.extraHeaders) if (this._opts.extraHeaders.hasOwnProperty(i)) xhr.setRequestHeader(i, this._opts.extraHeaders[i]); |
| } |
| } catch (e) {} |
| if ("POST" === this._method) try { |
| xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8"); |
| } catch (e) {} |
| try { |
| xhr.setRequestHeader("Accept", "*/*"); |
| } catch (e) {} |
| (_a = this._opts.cookieJar) === null || _a === void 0 || _a.addCookies(xhr); |
| if ("withCredentials" in xhr) xhr.withCredentials = this._opts.withCredentials; |
| if (this._opts.requestTimeout) xhr.timeout = this._opts.requestTimeout; |
| xhr.onreadystatechange = () => { |
| var _a; |
| if (xhr.readyState === 3) (_a = this._opts.cookieJar) === null || _a === void 0 || _a.parseCookies(xhr.getResponseHeader("set-cookie")); |
| if (4 !== xhr.readyState) return; |
| if (200 === xhr.status || 1223 === xhr.status) this._onLoad(); |
| else this.setTimeoutFn(() => { |
| this._onError(typeof xhr.status === "number" ? xhr.status : 0); |
| }, 0); |
| }; |
| xhr.send(this._data); |
| } catch (e) { |
| this.setTimeoutFn(() => { |
| this._onError(e); |
| }, 0); |
| return; |
| } |
| if (typeof document !== "undefined") { |
| this._index = Request.requestsCount++; |
| Request.requests[this._index] = this; |
| } |
| } |
| |
| |
| |
| |
| |
| _onError(err) { |
| this.emitReserved("error", err, this._xhr); |
| this._cleanup(true); |
| } |
| |
| |
| |
| |
| |
| _cleanup(fromError) { |
| if ("undefined" === typeof this._xhr || null === this._xhr) return; |
| this._xhr.onreadystatechange = empty; |
| if (fromError) try { |
| this._xhr.abort(); |
| } catch (e) {} |
| if (typeof document !== "undefined") delete Request.requests[this._index]; |
| this._xhr = null; |
| } |
| |
| |
| |
| |
| |
| _onLoad() { |
| const data = this._xhr.responseText; |
| if (data !== null) { |
| this.emitReserved("data", data); |
| this.emitReserved("success"); |
| this._cleanup(); |
| } |
| } |
| |
| |
| |
| |
| |
| abort() { |
| this._cleanup(); |
| } |
| }; |
| Request.requestsCount = 0; |
| Request.requests = {}; |
| |
| |
| |
| |
| |
| if (typeof document !== "undefined") { |
| if (typeof attachEvent === "function") attachEvent("onunload", unloadHandler); |
| else if (typeof addEventListener === "function") { |
| const terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload"; |
| addEventListener(terminationEvent, unloadHandler, false); |
| } |
| } |
| function unloadHandler() { |
| for (let i in Request.requests) if (Request.requests.hasOwnProperty(i)) Request.requests[i].abort(); |
| } |
| var hasXHR2 = (function() { |
| const xhr = newRequest({ xdomain: false }); |
| return xhr && xhr.responseType !== null; |
| })(); |
| |
| |
| |
| |
| |
| |
| |
| var XHR = class extends BaseXHR { |
| constructor(opts) { |
| super(opts); |
| const forceBase64 = opts && opts.forceBase64; |
| this.supportsBinary = hasXHR2 && !forceBase64; |
| } |
| request(opts = {}) { |
| Object.assign(opts, { xd: this.xd }, this.opts); |
| return new Request(newRequest, this.uri(), opts); |
| } |
| }; |
| function newRequest(opts) { |
| const xdomain = opts.xdomain; |
| try { |
| if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) return new XMLHttpRequest(); |
| } catch (e) {} |
| if (!xdomain) try { |
| return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP"); |
| } catch (e) {} |
| } |
| |
| |
| var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative"; |
| var BaseWS = class extends Transport { |
| get name() { |
| return "websocket"; |
| } |
| doOpen() { |
| const uri = this.uri(); |
| const protocols = this.opts.protocols; |
| const opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity"); |
| if (this.opts.extraHeaders) opts.headers = this.opts.extraHeaders; |
| try { |
| this.ws = this.createSocket(uri, protocols, opts); |
| } catch (err) { |
| return this.emitReserved("error", err); |
| } |
| this.ws.binaryType = this.socket.binaryType; |
| this.addEventListeners(); |
| } |
| |
| |
| |
| |
| |
| addEventListeners() { |
| this.ws.onopen = () => { |
| if (this.opts.autoUnref) this.ws._socket.unref(); |
| this.onOpen(); |
| }; |
| this.ws.onclose = (closeEvent) => this.onClose({ |
| description: "websocket connection closed", |
| context: closeEvent |
| }); |
| this.ws.onmessage = (ev) => this.onData(ev.data); |
| this.ws.onerror = (e) => this.onError("websocket error", e); |
| } |
| write(packets) { |
| this.writable = false; |
| for (let i = 0; i < packets.length; i++) { |
| const packet = packets[i]; |
| const lastPacket = i === packets.length - 1; |
| encodePacket(packet, this.supportsBinary, (data) => { |
| try { |
| this.doWrite(packet, data); |
| } catch (e) {} |
| if (lastPacket) nextTick(() => { |
| this.writable = true; |
| this.emitReserved("drain"); |
| }, this.setTimeoutFn); |
| }); |
| } |
| } |
| doClose() { |
| if (typeof this.ws !== "undefined") { |
| this.ws.onerror = () => {}; |
| this.ws.close(); |
| this.ws = null; |
| } |
| } |
| |
| |
| |
| |
| |
| uri() { |
| const schema = this.opts.secure ? "wss" : "ws"; |
| const query = this.query || {}; |
| if (this.opts.timestampRequests) query[this.opts.timestampParam] = randomString(); |
| if (!this.supportsBinary) query.b64 = 1; |
| return this.createUri(schema, query); |
| } |
| }; |
| var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var WS = class extends BaseWS { |
| createSocket(uri, protocols, opts) { |
| return !isReactNative ? protocols ? new WebSocketCtor(uri, protocols) : new WebSocketCtor(uri) : new WebSocketCtor(uri, protocols, opts); |
| } |
| doWrite(_packet, data) { |
| this.ws.send(data); |
| } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var WT = class extends Transport { |
| get name() { |
| return "webtransport"; |
| } |
| doOpen() { |
| try { |
| this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]); |
| } catch (err) { |
| return this.emitReserved("error", err); |
| } |
| this._transport.closed.then(() => { |
| this.onClose(); |
| }).catch((err) => { |
| this.onError("webtransport error", err); |
| }); |
| this._transport.ready.then(() => { |
| this._transport.createBidirectionalStream().then((stream) => { |
| const decoderStream = createPacketDecoderStream(Number.MAX_SAFE_INTEGER, this.socket.binaryType); |
| const reader = stream.readable.pipeThrough(decoderStream).getReader(); |
| const encoderStream = createPacketEncoderStream(); |
| encoderStream.readable.pipeTo(stream.writable); |
| this._writer = encoderStream.writable.getWriter(); |
| const read = () => { |
| reader.read().then(({ done, value }) => { |
| if (done) return; |
| this.onPacket(value); |
| read(); |
| }).catch((err) => {}); |
| }; |
| read(); |
| const packet = { type: "open" }; |
| if (this.query.sid) packet.data = `{"sid":"${this.query.sid}"}`; |
| this._writer.write(packet).then(() => this.onOpen()); |
| }); |
| }); |
| } |
| write(packets) { |
| this.writable = false; |
| for (let i = 0; i < packets.length; i++) { |
| const packet = packets[i]; |
| const lastPacket = i === packets.length - 1; |
| this._writer.write(packet).then(() => { |
| if (lastPacket) nextTick(() => { |
| this.writable = true; |
| this.emitReserved("drain"); |
| }, this.setTimeoutFn); |
| }); |
| } |
| } |
| doClose() { |
| var _a; |
| (_a = this._transport) === null || _a === void 0 || _a.close(); |
| } |
| }; |
| |
| |
| var transports = { |
| websocket: WS, |
| webtransport: WT, |
| polling: XHR |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; |
| var parts = [ |
| "source", |
| "protocol", |
| "authority", |
| "userInfo", |
| "user", |
| "password", |
| "host", |
| "port", |
| "relative", |
| "path", |
| "directory", |
| "file", |
| "query", |
| "anchor" |
| ]; |
| function parse(str) { |
| if (str.length > 8e3) throw "URI too long"; |
| const src = str, b = str.indexOf("["), e = str.indexOf("]"); |
| if (b != -1 && e != -1) str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ";") + str.substring(e, str.length); |
| let m = re.exec(str || ""), uri = {}, i = 14; |
| while (i--) uri[parts[i]] = m[i] || ""; |
| if (b != -1 && e != -1) { |
| uri.source = src; |
| uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ":"); |
| uri.authority = uri.authority.replace("[", "").replace("]", "").replace(/;/g, ":"); |
| uri.ipv6uri = true; |
| } |
| uri.pathNames = pathNames(uri, uri["path"]); |
| uri.queryKey = queryKey(uri, uri["query"]); |
| return uri; |
| } |
| function pathNames(obj, path) { |
| const names = path.replace(/\/{2,9}/g, "/").split("/"); |
| if (path.slice(0, 1) == "/" || path.length === 0) names.splice(0, 1); |
| if (path.slice(-1) == "/") names.splice(names.length - 1, 1); |
| return names; |
| } |
| function queryKey(uri, query) { |
| const data = {}; |
| query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function($0, $1, $2) { |
| if ($1) data[$1] = $2; |
| }); |
| return data; |
| } |
| |
| |
| var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function"; |
| var OFFLINE_EVENT_LISTENERS = []; |
| if (withEventListeners) addEventListener("offline", () => { |
| OFFLINE_EVENT_LISTENERS.forEach((listener) => listener()); |
| }, false); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var SocketWithoutUpgrade = class SocketWithoutUpgrade extends Emitter { |
| |
| |
| |
| |
| |
| |
| constructor(uri, opts) { |
| super(); |
| this.binaryType = defaultBinaryType; |
| this.writeBuffer = []; |
| this._prevBufferLen = 0; |
| this._pingInterval = -1; |
| this._pingTimeout = -1; |
| this._maxPayload = -1; |
| |
| |
| |
| |
| this._pingTimeoutTime = Infinity; |
| if (uri && "object" === typeof uri) { |
| opts = uri; |
| uri = null; |
| } |
| if (uri) { |
| const parsedUri = parse(uri); |
| opts.hostname = parsedUri.host; |
| opts.secure = parsedUri.protocol === "https" || parsedUri.protocol === "wss"; |
| opts.port = parsedUri.port; |
| if (parsedUri.query) opts.query = parsedUri.query; |
| } else if (opts.host) opts.hostname = parse(opts.host).host; |
| installTimerFunctions(this, opts); |
| this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol; |
| if (opts.hostname && !opts.port) opts.port = this.secure ? "443" : "80"; |
| this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost"); |
| this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : this.secure ? "443" : "80"); |
| this.transports = []; |
| this._transportsByName = {}; |
| opts.transports.forEach((t) => { |
| const transportName = t.prototype.name; |
| this.transports.push(transportName); |
| this._transportsByName[transportName] = t; |
| }); |
| this.opts = Object.assign({ |
| path: "/engine.io", |
| agent: false, |
| withCredentials: false, |
| upgrade: true, |
| timestampParam: "t", |
| rememberUpgrade: false, |
| addTrailingSlash: true, |
| rejectUnauthorized: true, |
| perMessageDeflate: { threshold: 1024 }, |
| transportOptions: {}, |
| closeOnBeforeunload: false |
| }, opts); |
| this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""); |
| if (typeof this.opts.query === "string") this.opts.query = decode(this.opts.query); |
| if (withEventListeners) { |
| if (this.opts.closeOnBeforeunload) { |
| this._beforeunloadEventListener = () => { |
| if (this.transport) { |
| this.transport.removeAllListeners(); |
| this.transport.close(); |
| } |
| }; |
| addEventListener("beforeunload", this._beforeunloadEventListener, false); |
| } |
| if (this.hostname !== "localhost") { |
| this._offlineEventListener = () => { |
| this._onClose("transport close", { description: "network connection lost" }); |
| }; |
| OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener); |
| } |
| } |
| if (this.opts.withCredentials) this._cookieJar = void 0; |
| this._open(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| createTransport(name) { |
| const query = Object.assign({}, this.opts.query); |
| query.EIO = 4; |
| query.transport = name; |
| if (this.id) query.sid = this.id; |
| const opts = Object.assign({}, this.opts, { |
| query, |
| socket: this, |
| hostname: this.hostname, |
| secure: this.secure, |
| port: this.port |
| }, this.opts.transportOptions[name]); |
| return new this._transportsByName[name](opts); |
| } |
| |
| |
| |
| |
| |
| _open() { |
| if (this.transports.length === 0) { |
| this.setTimeoutFn(() => { |
| this.emitReserved("error", "No transports available"); |
| }, 0); |
| return; |
| } |
| const transportName = this.opts.rememberUpgrade && SocketWithoutUpgrade.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0]; |
| this.readyState = "opening"; |
| const transport = this.createTransport(transportName); |
| transport.open(); |
| this.setTransport(transport); |
| } |
| |
| |
| |
| |
| |
| setTransport(transport) { |
| if (this.transport) this.transport.removeAllListeners(); |
| this.transport = transport; |
| transport.on("drain", this._onDrain.bind(this)).on("packet", this._onPacket.bind(this)).on("error", this._onError.bind(this)).on("close", (reason) => this._onClose("transport close", reason)); |
| } |
| |
| |
| |
| |
| |
| onOpen() { |
| this.readyState = "open"; |
| SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === this.transport.name; |
| this.emitReserved("open"); |
| this.flush(); |
| } |
| |
| |
| |
| |
| |
| _onPacket(packet) { |
| if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) { |
| this.emitReserved("packet", packet); |
| this.emitReserved("heartbeat"); |
| switch (packet.type) { |
| case "open": |
| this.onHandshake(JSON.parse(packet.data)); |
| break; |
| case "ping": |
| this._sendPacket("pong"); |
| this.emitReserved("ping"); |
| this.emitReserved("pong"); |
| this._resetPingTimeout(); |
| break; |
| case "error": |
| const err = new Error("server error"); |
| err.code = packet.data; |
| this._onError(err); |
| break; |
| case "message": |
| this.emitReserved("data", packet.data); |
| this.emitReserved("message", packet.data); |
| break; |
| } |
| } |
| } |
| |
| |
| |
| |
| |
| |
| onHandshake(data) { |
| this.emitReserved("handshake", data); |
| this.id = data.sid; |
| this.transport.query.sid = data.sid; |
| this._pingInterval = data.pingInterval; |
| this._pingTimeout = data.pingTimeout; |
| this._maxPayload = data.maxPayload; |
| this.onOpen(); |
| if ("closed" === this.readyState) return; |
| this._resetPingTimeout(); |
| } |
| |
| |
| |
| |
| |
| _resetPingTimeout() { |
| this.clearTimeoutFn(this._pingTimeoutTimer); |
| const delay = this._pingInterval + this._pingTimeout; |
| this._pingTimeoutTime = Date.now() + delay; |
| this._pingTimeoutTimer = this.setTimeoutFn(() => { |
| this._onClose("ping timeout"); |
| }, delay); |
| if (this.opts.autoUnref) this._pingTimeoutTimer.unref(); |
| } |
| |
| |
| |
| |
| |
| _onDrain() { |
| this.writeBuffer.splice(0, this._prevBufferLen); |
| this._prevBufferLen = 0; |
| if (0 === this.writeBuffer.length) this.emitReserved("drain"); |
| else this.flush(); |
| } |
| |
| |
| |
| |
| |
| flush() { |
| if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) { |
| const packets = this._getWritablePackets(); |
| this.transport.send(packets); |
| this._prevBufferLen = packets.length; |
| this.emitReserved("flush"); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| _getWritablePackets() { |
| if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1)) return this.writeBuffer; |
| let payloadSize = 1; |
| for (let i = 0; i < this.writeBuffer.length; i++) { |
| const data = this.writeBuffer[i].data; |
| if (data) payloadSize += byteLength(data); |
| if (i > 0 && payloadSize > this._maxPayload) return this.writeBuffer.slice(0, i); |
| payloadSize += 2; |
| } |
| return this.writeBuffer; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _hasPingExpired() { |
| if (!this._pingTimeoutTime) return true; |
| const hasExpired = Date.now() > this._pingTimeoutTime; |
| if (hasExpired) { |
| this._pingTimeoutTime = 0; |
| nextTick(() => { |
| this._onClose("ping timeout"); |
| }, this.setTimeoutFn); |
| } |
| return hasExpired; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| write(msg, options, fn) { |
| this._sendPacket("message", msg, options, fn); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| send(msg, options, fn) { |
| this._sendPacket("message", msg, options, fn); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _sendPacket(type, data, options, fn) { |
| if ("function" === typeof data) { |
| fn = data; |
| data = void 0; |
| } |
| if ("function" === typeof options) { |
| fn = options; |
| options = null; |
| } |
| if ("closing" === this.readyState || "closed" === this.readyState) return; |
| options = options || {}; |
| options.compress = false !== options.compress; |
| const packet = { |
| type, |
| data, |
| options |
| }; |
| this.emitReserved("packetCreate", packet); |
| this.writeBuffer.push(packet); |
| if (fn) this.once("flush", fn); |
| this.flush(); |
| } |
| |
| |
| |
| close() { |
| const close = () => { |
| this._onClose("forced close"); |
| this.transport.close(); |
| }; |
| const cleanupAndClose = () => { |
| this.off("upgrade", cleanupAndClose); |
| this.off("upgradeError", cleanupAndClose); |
| close(); |
| }; |
| const waitForUpgrade = () => { |
| this.once("upgrade", cleanupAndClose); |
| this.once("upgradeError", cleanupAndClose); |
| }; |
| if ("opening" === this.readyState || "open" === this.readyState) { |
| this.readyState = "closing"; |
| if (this.writeBuffer.length) this.once("drain", () => { |
| if (this.upgrading) waitForUpgrade(); |
| else close(); |
| }); |
| else if (this.upgrading) waitForUpgrade(); |
| else close(); |
| } |
| return this; |
| } |
| |
| |
| |
| |
| |
| _onError(err) { |
| SocketWithoutUpgrade.priorWebsocketSuccess = false; |
| if (this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") { |
| this.transports.shift(); |
| return this._open(); |
| } |
| this.emitReserved("error", err); |
| this._onClose("transport error", err); |
| } |
| |
| |
| |
| |
| |
| _onClose(reason, description) { |
| if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) { |
| this.clearTimeoutFn(this._pingTimeoutTimer); |
| this.transport.removeAllListeners("close"); |
| this.transport.close(); |
| this.transport.removeAllListeners(); |
| if (withEventListeners) { |
| if (this._beforeunloadEventListener) removeEventListener("beforeunload", this._beforeunloadEventListener, false); |
| if (this._offlineEventListener) { |
| const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener); |
| if (i !== -1) OFFLINE_EVENT_LISTENERS.splice(i, 1); |
| } |
| } |
| this.readyState = "closed"; |
| this.id = null; |
| this.emitReserved("close", reason, description); |
| this.writeBuffer = []; |
| this._prevBufferLen = 0; |
| } |
| } |
| }; |
| SocketWithoutUpgrade.protocol = 4; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var SocketWithUpgrade = class extends SocketWithoutUpgrade { |
| constructor() { |
| super(...arguments); |
| this._upgrades = []; |
| } |
| onOpen() { |
| super.onOpen(); |
| if ("open" === this.readyState && this.opts.upgrade) for (let i = 0; i < this._upgrades.length; i++) this._probe(this._upgrades[i]); |
| } |
| |
| |
| |
| |
| |
| |
| _probe(name) { |
| let transport = this.createTransport(name); |
| let failed = false; |
| SocketWithoutUpgrade.priorWebsocketSuccess = false; |
| const onTransportOpen = () => { |
| if (failed) return; |
| transport.send([{ |
| type: "ping", |
| data: "probe" |
| }]); |
| transport.once("packet", (msg) => { |
| if (failed) return; |
| if ("pong" === msg.type && "probe" === msg.data) { |
| this.upgrading = true; |
| this.emitReserved("upgrading", transport); |
| if (!transport) return; |
| SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === transport.name; |
| this.transport.pause(() => { |
| if (failed) return; |
| if ("closed" === this.readyState) return; |
| cleanup(); |
| this.setTransport(transport); |
| transport.send([{ type: "upgrade" }]); |
| this.emitReserved("upgrade", transport); |
| transport = null; |
| this.upgrading = false; |
| this.flush(); |
| }); |
| } else { |
| const err = new Error("probe error"); |
| err.transport = transport.name; |
| this.emitReserved("upgradeError", err); |
| } |
| }); |
| }; |
| function freezeTransport() { |
| if (failed) return; |
| failed = true; |
| cleanup(); |
| transport.close(); |
| transport = null; |
| } |
| const onerror = (err) => { |
| const error = new Error("probe error: " + err); |
| error.transport = transport.name; |
| freezeTransport(); |
| this.emitReserved("upgradeError", error); |
| }; |
| function onTransportClose() { |
| onerror("transport closed"); |
| } |
| function onclose() { |
| onerror("socket closed"); |
| } |
| function onupgrade(to) { |
| if (transport && to.name !== transport.name) freezeTransport(); |
| } |
| const cleanup = () => { |
| transport.removeListener("open", onTransportOpen); |
| transport.removeListener("error", onerror); |
| transport.removeListener("close", onTransportClose); |
| this.off("close", onclose); |
| this.off("upgrading", onupgrade); |
| }; |
| transport.once("open", onTransportOpen); |
| transport.once("error", onerror); |
| transport.once("close", onTransportClose); |
| this.once("close", onclose); |
| this.once("upgrading", onupgrade); |
| if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") this.setTimeoutFn(() => { |
| if (!failed) transport.open(); |
| }, 200); |
| else transport.open(); |
| } |
| onHandshake(data) { |
| this._upgrades = this._filterUpgrades(data.upgrades); |
| super.onHandshake(data); |
| } |
| |
| |
| |
| |
| |
| |
| _filterUpgrades(upgrades) { |
| const filteredUpgrades = []; |
| for (let i = 0; i < upgrades.length; i++) if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]); |
| return filteredUpgrades; |
| } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var Socket$1 = class extends SocketWithUpgrade { |
| constructor(uri, opts = {}) { |
| const o = typeof uri === "object" ? uri : opts; |
| if (!o.transports || o.transports && typeof o.transports[0] === "string") o.transports = (o.transports || [ |
| "polling", |
| "websocket", |
| "webtransport" |
| ]).map((transportName) => transports[transportName]).filter((t) => !!t); |
| super(uri, o); |
| } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var Fetch = class extends Polling { |
| doPoll() { |
| this._fetch().then((res) => { |
| if (!res.ok) return this.onError("fetch read error", res.status, res); |
| res.text().then((data) => this.onData(data)); |
| }).catch((err) => { |
| this.onError("fetch read error", err); |
| }); |
| } |
| doWrite(data, callback) { |
| this._fetch(data).then((res) => { |
| if (!res.ok) return this.onError("fetch write error", res.status, res); |
| callback(); |
| }).catch((err) => { |
| this.onError("fetch write error", err); |
| }); |
| } |
| _fetch(data) { |
| var _a; |
| const isPost = data !== void 0; |
| const headers = new Headers(this.opts.extraHeaders); |
| if (isPost) headers.set("content-type", "text/plain;charset=UTF-8"); |
| (_a = this.socket._cookieJar) === null || _a === void 0 || _a.appendCookies(headers); |
| return fetch(this.uri(), { |
| method: isPost ? "POST" : "GET", |
| body: isPost ? data : null, |
| headers, |
| credentials: this.opts.withCredentials ? "include" : "omit" |
| }).then((res) => { |
| var _a; |
| (_a = this.socket._cookieJar) === null || _a === void 0 || _a.parseCookies(res.headers.getSetCookie()); |
| return res; |
| }); |
| } |
| }; |
| Socket$1.protocol; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function url(uri, path = "", loc) { |
| let obj = uri; |
| loc = loc || typeof location !== "undefined" && location; |
| if (null == uri) uri = loc.protocol + "//" + loc.host; |
| if (typeof uri === "string") { |
| if ("/" === uri.charAt(0)) if ("/" === uri.charAt(1)) uri = loc.protocol + uri; |
| else uri = loc.host + uri; |
| if (!/^(https?|wss?):\/\//.test(uri)) if ("undefined" !== typeof loc) uri = loc.protocol + "//" + uri; |
| else uri = "https://" + uri; |
| obj = parse(uri); |
| } |
| if (!obj.port) { |
| if (/^(http|ws)$/.test(obj.protocol)) obj.port = "80"; |
| else if (/^(http|ws)s$/.test(obj.protocol)) obj.port = "443"; |
| } |
| obj.path = obj.path || "/"; |
| const host = obj.host.indexOf(":") !== -1 ? "[" + obj.host + "]" : obj.host; |
| obj.id = obj.protocol + "://" + host + ":" + obj.port + path; |
| obj.href = obj.protocol + "://" + host + (loc && loc.port === obj.port ? "" : ":" + obj.port); |
| return obj; |
| } |
| |
| |
| var withNativeArrayBuffer = typeof ArrayBuffer === "function"; |
| var isView = (obj) => { |
| return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj.buffer instanceof ArrayBuffer; |
| }; |
| var toString = Object.prototype.toString; |
| var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && toString.call(Blob) === "[object BlobConstructor]"; |
| var withNativeFile = typeof File === "function" || typeof File !== "undefined" && toString.call(File) === "[object FileConstructor]"; |
| |
| |
| |
| |
| |
| function isBinary(obj) { |
| return withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)) || withNativeBlob && obj instanceof Blob || withNativeFile && obj instanceof File; |
| } |
| function hasBinary(obj, toJSON) { |
| if (!obj || typeof obj !== "object") return false; |
| if (Array.isArray(obj)) { |
| for (let i = 0, l = obj.length; i < l; i++) if (hasBinary(obj[i])) return true; |
| return false; |
| } |
| if (isBinary(obj)) return true; |
| if (obj.toJSON && typeof obj.toJSON === "function" && arguments.length === 1) return hasBinary(obj.toJSON(), true); |
| for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) return true; |
| return false; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function deconstructPacket(packet) { |
| const buffers = []; |
| const packetData = packet.data; |
| const pack = packet; |
| pack.data = _deconstructPacket(packetData, buffers); |
| pack.attachments = buffers.length; |
| return { |
| packet: pack, |
| buffers |
| }; |
| } |
| function _deconstructPacket(data, buffers) { |
| if (!data) return data; |
| if (isBinary(data)) { |
| const placeholder = { |
| _placeholder: true, |
| num: buffers.length |
| }; |
| buffers.push(data); |
| return placeholder; |
| } else if (Array.isArray(data)) { |
| const newData = new Array(data.length); |
| for (let i = 0; i < data.length; i++) newData[i] = _deconstructPacket(data[i], buffers); |
| return newData; |
| } else if (typeof data === "object" && !(data instanceof Date)) { |
| const newData = {}; |
| for (const key in data) if (Object.prototype.hasOwnProperty.call(data, key)) newData[key] = _deconstructPacket(data[key], buffers); |
| return newData; |
| } |
| return data; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| function reconstructPacket(packet, buffers) { |
| packet.data = _reconstructPacket(packet.data, buffers); |
| delete packet.attachments; |
| return packet; |
| } |
| function _reconstructPacket(data, buffers) { |
| if (!data) return data; |
| if (data && data._placeholder === true) if (typeof data.num === "number" && data.num >= 0 && data.num < buffers.length) return buffers[data.num]; |
| else throw new Error("illegal attachments"); |
| else if (Array.isArray(data)) for (let i = 0; i < data.length; i++) data[i] = _reconstructPacket(data[i], buffers); |
| else if (typeof data === "object") { |
| for (const key in data) if (Object.prototype.hasOwnProperty.call(data, key)) data[key] = _reconstructPacket(data[key], buffers); |
| } |
| return data; |
| } |
| |
| |
| var require_ms = __commonJSMin(((exports, module) => { |
| |
| |
| |
| var s = 1e3; |
| var m = s * 60; |
| var h = m * 60; |
| var d = h * 24; |
| var w = d * 7; |
| var y = d * 365.25; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| module.exports = function(val, options) { |
| options = options || {}; |
| var type = typeof val; |
| if (type === "string" && val.length > 0) return parse(val); |
| else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val); |
| throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val)); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| function parse(str) { |
| str = String(str); |
| if (str.length > 100) return; |
| var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str); |
| if (!match) return; |
| var n = parseFloat(match[1]); |
| switch ((match[2] || "ms").toLowerCase()) { |
| case "years": |
| case "year": |
| case "yrs": |
| case "yr": |
| case "y": return n * y; |
| case "weeks": |
| case "week": |
| case "w": return n * w; |
| case "days": |
| case "day": |
| case "d": return n * d; |
| case "hours": |
| case "hour": |
| case "hrs": |
| case "hr": |
| case "h": return n * h; |
| case "minutes": |
| case "minute": |
| case "mins": |
| case "min": |
| case "m": return n * m; |
| case "seconds": |
| case "second": |
| case "secs": |
| case "sec": |
| case "s": return n * s; |
| case "milliseconds": |
| case "millisecond": |
| case "msecs": |
| case "msec": |
| case "ms": return n; |
| default: return; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| function fmtShort(ms) { |
| var msAbs = Math.abs(ms); |
| if (msAbs >= d) return Math.round(ms / d) + "d"; |
| if (msAbs >= h) return Math.round(ms / h) + "h"; |
| if (msAbs >= m) return Math.round(ms / m) + "m"; |
| if (msAbs >= s) return Math.round(ms / s) + "s"; |
| return ms + "ms"; |
| } |
| |
| |
| |
| |
| |
| |
| |
| function fmtLong(ms) { |
| var msAbs = Math.abs(ms); |
| if (msAbs >= d) return plural(ms, msAbs, d, "day"); |
| if (msAbs >= h) return plural(ms, msAbs, h, "hour"); |
| if (msAbs >= m) return plural(ms, msAbs, m, "minute"); |
| if (msAbs >= s) return plural(ms, msAbs, s, "second"); |
| return ms + " ms"; |
| } |
| |
| |
| |
| function plural(ms, msAbs, n, name) { |
| var isPlural = msAbs >= n * 1.5; |
| return Math.round(ms / n) + " " + name + (isPlural ? "s" : ""); |
| } |
| })); |
| |
| |
| var require_common = __commonJSMin(((exports, module) => { |
| |
| |
| |
| |
| function setup(env) { |
| createDebug.debug = createDebug; |
| createDebug.default = createDebug; |
| createDebug.coerce = coerce; |
| createDebug.disable = disable; |
| createDebug.enable = enable; |
| createDebug.enabled = enabled; |
| createDebug.humanize = require_ms(); |
| createDebug.destroy = destroy; |
| Object.keys(env).forEach((key) => { |
| createDebug[key] = env[key]; |
| }); |
| |
| |
| |
| createDebug.names = []; |
| createDebug.skips = []; |
| |
| |
| |
| |
| |
| createDebug.formatters = {}; |
| |
| |
| |
| |
| |
| |
| function selectColor(namespace) { |
| let hash = 0; |
| for (let i = 0; i < namespace.length; i++) { |
| hash = (hash << 5) - hash + namespace.charCodeAt(i); |
| hash |= 0; |
| } |
| return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; |
| } |
| createDebug.selectColor = selectColor; |
| |
| |
| |
| |
| |
| |
| |
| function createDebug(namespace) { |
| let prevTime; |
| let enableOverride = null; |
| let namespacesCache; |
| let enabledCache; |
| function debug(...args) { |
| if (!debug.enabled) return; |
| const self = debug; |
| const curr = Number( new Date()); |
| self.diff = curr - (prevTime || curr); |
| self.prev = prevTime; |
| self.curr = curr; |
| prevTime = curr; |
| args[0] = createDebug.coerce(args[0]); |
| if (typeof args[0] !== "string") args.unshift("%O"); |
| let index = 0; |
| args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { |
| if (match === "%%") return "%"; |
| index++; |
| const formatter = createDebug.formatters[format]; |
| if (typeof formatter === "function") { |
| const val = args[index]; |
| match = formatter.call(self, val); |
| args.splice(index, 1); |
| index--; |
| } |
| return match; |
| }); |
| createDebug.formatArgs.call(self, args); |
| (self.log || createDebug.log).apply(self, args); |
| } |
| debug.namespace = namespace; |
| debug.useColors = createDebug.useColors(); |
| debug.color = createDebug.selectColor(namespace); |
| debug.extend = extend; |
| debug.destroy = createDebug.destroy; |
| Object.defineProperty(debug, "enabled", { |
| enumerable: true, |
| configurable: false, |
| get: () => { |
| if (enableOverride !== null) return enableOverride; |
| if (namespacesCache !== createDebug.namespaces) { |
| namespacesCache = createDebug.namespaces; |
| enabledCache = createDebug.enabled(namespace); |
| } |
| return enabledCache; |
| }, |
| set: (v) => { |
| enableOverride = v; |
| } |
| }); |
| if (typeof createDebug.init === "function") createDebug.init(debug); |
| return debug; |
| } |
| function extend(namespace, delimiter) { |
| const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace); |
| newDebug.log = this.log; |
| return newDebug; |
| } |
| |
| |
| |
| |
| |
| |
| |
| function enable(namespaces) { |
| createDebug.save(namespaces); |
| createDebug.namespaces = namespaces; |
| createDebug.names = []; |
| createDebug.skips = []; |
| const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean); |
| for (const ns of split) if (ns[0] === "-") createDebug.skips.push(ns.slice(1)); |
| else createDebug.names.push(ns); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| function matchesTemplate(search, template) { |
| let searchIndex = 0; |
| let templateIndex = 0; |
| let starIndex = -1; |
| let matchIndex = 0; |
| while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) if (template[templateIndex] === "*") { |
| starIndex = templateIndex; |
| matchIndex = searchIndex; |
| templateIndex++; |
| } else { |
| searchIndex++; |
| templateIndex++; |
| } |
| else if (starIndex !== -1) { |
| templateIndex = starIndex + 1; |
| matchIndex++; |
| searchIndex = matchIndex; |
| } else return false; |
| while (templateIndex < template.length && template[templateIndex] === "*") templateIndex++; |
| return templateIndex === template.length; |
| } |
| |
| |
| |
| |
| |
| |
| function disable() { |
| const namespaces = [...createDebug.names, ...createDebug.skips.map((namespace) => "-" + namespace)].join(","); |
| createDebug.enable(""); |
| return namespaces; |
| } |
| |
| |
| |
| |
| |
| |
| |
| function enabled(name) { |
| for (const skip of createDebug.skips) if (matchesTemplate(name, skip)) return false; |
| for (const ns of createDebug.names) if (matchesTemplate(name, ns)) return true; |
| return false; |
| } |
| |
| |
| |
| |
| |
| |
| |
| function coerce(val) { |
| if (val instanceof Error) return val.stack || val.message; |
| return val; |
| } |
| |
| |
| |
| |
| function destroy() { |
| console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); |
| } |
| createDebug.enable(createDebug.load()); |
| return createDebug; |
| } |
| module.exports = setup; |
| })); |
| |
| |
| var require_browser = __commonJSMin(((exports, module) => { |
| |
| |
| |
| exports.formatArgs = formatArgs; |
| exports.save = save; |
| exports.load = load; |
| exports.useColors = useColors; |
| exports.storage = localstorage(); |
| exports.destroy = (() => { |
| let warned = false; |
| return () => { |
| if (!warned) { |
| warned = true; |
| console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); |
| } |
| }; |
| })(); |
| |
| |
| |
| exports.colors = [ |
| "#0000CC", |
| "#0000FF", |
| "#0033CC", |
| "#0033FF", |
| "#0066CC", |
| "#0066FF", |
| "#0099CC", |
| "#0099FF", |
| "#00CC00", |
| "#00CC33", |
| "#00CC66", |
| "#00CC99", |
| "#00CCCC", |
| "#00CCFF", |
| "#3300CC", |
| "#3300FF", |
| "#3333CC", |
| "#3333FF", |
| "#3366CC", |
| "#3366FF", |
| "#3399CC", |
| "#3399FF", |
| "#33CC00", |
| "#33CC33", |
| "#33CC66", |
| "#33CC99", |
| "#33CCCC", |
| "#33CCFF", |
| "#6600CC", |
| "#6600FF", |
| "#6633CC", |
| "#6633FF", |
| "#66CC00", |
| "#66CC33", |
| "#9900CC", |
| "#9900FF", |
| "#9933CC", |
| "#9933FF", |
| "#99CC00", |
| "#99CC33", |
| "#CC0000", |
| "#CC0033", |
| "#CC0066", |
| "#CC0099", |
| "#CC00CC", |
| "#CC00FF", |
| "#CC3300", |
| "#CC3333", |
| "#CC3366", |
| "#CC3399", |
| "#CC33CC", |
| "#CC33FF", |
| "#CC6600", |
| "#CC6633", |
| "#CC9900", |
| "#CC9933", |
| "#CCCC00", |
| "#CCCC33", |
| "#FF0000", |
| "#FF0033", |
| "#FF0066", |
| "#FF0099", |
| "#FF00CC", |
| "#FF00FF", |
| "#FF3300", |
| "#FF3333", |
| "#FF3366", |
| "#FF3399", |
| "#FF33CC", |
| "#FF33FF", |
| "#FF6600", |
| "#FF6633", |
| "#FF9900", |
| "#FF9933", |
| "#FFCC00", |
| "#FFCC33" |
| ]; |
| |
| |
| |
| |
| |
| |
| |
| function useColors() { |
| if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return true; |
| if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return false; |
| let m; |
| return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); |
| } |
| |
| |
| |
| |
| |
| function formatArgs(args) { |
| args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff); |
| if (!this.useColors) return; |
| const c = "color: " + this.color; |
| args.splice(1, 0, c, "color: inherit"); |
| let index = 0; |
| let lastC = 0; |
| args[0].replace(/%[a-zA-Z%]/g, (match) => { |
| if (match === "%%") return; |
| index++; |
| if (match === "%c") lastC = index; |
| }); |
| args.splice(lastC, 0, c); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| exports.log = console.debug || console.log || (() => {}); |
| |
| |
| |
| |
| |
| |
| function save(namespaces) { |
| try { |
| if (namespaces) exports.storage.setItem("debug", namespaces); |
| else exports.storage.removeItem("debug"); |
| } catch (error) {} |
| } |
| |
| |
| |
| |
| |
| |
| function load() { |
| let r; |
| try { |
| r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG"); |
| } catch (error) {} |
| if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG; |
| return r; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function localstorage() { |
| try { |
| return localStorage; |
| } catch (error) {} |
| } |
| module.exports = require_common()(exports); |
| var { formatters } = module.exports; |
| |
| |
| |
| formatters.j = function(v) { |
| try { |
| return JSON.stringify(v); |
| } catch (error) { |
| return "[UnexpectedJSONParseError]: " + error.message; |
| } |
| }; |
| })); |
| |
| |
| var esm_debug_exports = __exportAll({ |
| Decoder: () => Decoder, |
| Encoder: () => Encoder, |
| PacketType: () => PacketType, |
| isPacketValid: () => isPacketValid, |
| protocol: () => 5 |
| }); |
| var debug = (0, ( __toESM(require_browser())).default)("socket.io-parser"); |
| |
| |
| |
| var RESERVED_EVENTS$1 = [ |
| "connect", |
| "connect_error", |
| "disconnect", |
| "disconnecting", |
| "newListener", |
| "removeListener" |
| ]; |
| |
| |
| |
| |
| |
| var protocol = 5; |
| var PacketType; |
| (function(PacketType) { |
| PacketType[PacketType["CONNECT"] = 0] = "CONNECT"; |
| PacketType[PacketType["DISCONNECT"] = 1] = "DISCONNECT"; |
| PacketType[PacketType["EVENT"] = 2] = "EVENT"; |
| PacketType[PacketType["ACK"] = 3] = "ACK"; |
| PacketType[PacketType["CONNECT_ERROR"] = 4] = "CONNECT_ERROR"; |
| PacketType[PacketType["BINARY_EVENT"] = 5] = "BINARY_EVENT"; |
| PacketType[PacketType["BINARY_ACK"] = 6] = "BINARY_ACK"; |
| })(PacketType || (PacketType = {})); |
| |
| |
| |
| var Encoder = class { |
| |
| |
| |
| |
| |
| constructor(replacer) { |
| this.replacer = replacer; |
| } |
| |
| |
| |
| |
| |
| |
| encode(obj) { |
| debug("encoding packet %j", obj); |
| if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) { |
| if (hasBinary(obj)) return this.encodeAsBinary({ |
| type: obj.type === PacketType.EVENT ? PacketType.BINARY_EVENT : PacketType.BINARY_ACK, |
| nsp: obj.nsp, |
| data: obj.data, |
| id: obj.id |
| }); |
| } |
| return [this.encodeAsString(obj)]; |
| } |
| |
| |
| |
| encodeAsString(obj) { |
| let str = "" + obj.type; |
| if (obj.type === PacketType.BINARY_EVENT || obj.type === PacketType.BINARY_ACK) str += obj.attachments + "-"; |
| if (obj.nsp && "/" !== obj.nsp) str += obj.nsp + ","; |
| if (null != obj.id) str += obj.id; |
| if (null != obj.data) str += JSON.stringify(obj.data, this.replacer); |
| debug("encoded %j as %s", obj, str); |
| return str; |
| } |
| |
| |
| |
| |
| |
| encodeAsBinary(obj) { |
| const deconstruction = deconstructPacket(obj); |
| const pack = this.encodeAsString(deconstruction.packet); |
| const buffers = deconstruction.buffers; |
| buffers.unshift(pack); |
| return buffers; |
| } |
| }; |
| |
| |
| |
| |
| |
| var Decoder = class Decoder extends Emitter { |
| |
| |
| |
| constructor(opts) { |
| super(); |
| this.opts = Object.assign({ |
| reviver: void 0, |
| maxAttachments: 10 |
| }, typeof opts === "function" ? { reviver: opts } : opts); |
| } |
| |
| |
| |
| |
| |
| add(obj) { |
| let packet; |
| if (typeof obj === "string") { |
| if (this.reconstructor) throw new Error("got plaintext data when reconstructing a packet"); |
| packet = this.decodeString(obj); |
| const isBinaryEvent = packet.type === PacketType.BINARY_EVENT; |
| if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) { |
| packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK; |
| this.reconstructor = new BinaryReconstructor(packet); |
| if (packet.attachments === 0) super.emitReserved("decoded", packet); |
| } else super.emitReserved("decoded", packet); |
| } else if (isBinary(obj) || obj.base64) if (!this.reconstructor) throw new Error("got binary data when not reconstructing a packet"); |
| else { |
| packet = this.reconstructor.takeBinaryData(obj); |
| if (packet) { |
| this.reconstructor = null; |
| super.emitReserved("decoded", packet); |
| } |
| } |
| else throw new Error("Unknown type: " + obj); |
| } |
| |
| |
| |
| |
| |
| |
| decodeString(str) { |
| let i = 0; |
| const p = { type: Number(str.charAt(0)) }; |
| if (PacketType[p.type] === void 0) throw new Error("unknown packet type " + p.type); |
| if (p.type === PacketType.BINARY_EVENT || p.type === PacketType.BINARY_ACK) { |
| const start = i + 1; |
| while (str.charAt(++i) !== "-" && i != str.length); |
| const buf = str.substring(start, i); |
| if (buf != Number(buf) || str.charAt(i) !== "-") throw new Error("Illegal attachments"); |
| const n = Number(buf); |
| if (!isInteger(n) || n < 0) throw new Error("Illegal attachments"); |
| else if (n > this.opts.maxAttachments) throw new Error("too many attachments"); |
| p.attachments = n; |
| } |
| if ("/" === str.charAt(i + 1)) { |
| const start = i + 1; |
| while (++i) { |
| if ("," === str.charAt(i)) break; |
| if (i === str.length) break; |
| } |
| p.nsp = str.substring(start, i); |
| } else p.nsp = "/"; |
| const next = str.charAt(i + 1); |
| if ("" !== next && Number(next) == next) { |
| const start = i + 1; |
| while (++i) { |
| const c = str.charAt(i); |
| if (null == c || Number(c) != c) { |
| --i; |
| break; |
| } |
| if (i === str.length) break; |
| } |
| p.id = Number(str.substring(start, i + 1)); |
| } |
| if (str.charAt(++i)) { |
| const payload = this.tryParse(str.substr(i)); |
| if (Decoder.isPayloadValid(p.type, payload)) p.data = payload; |
| else throw new Error("invalid payload"); |
| } |
| debug("decoded %s as %j", str, p); |
| return p; |
| } |
| tryParse(str) { |
| try { |
| return JSON.parse(str, this.opts.reviver); |
| } catch (e) { |
| return false; |
| } |
| } |
| static isPayloadValid(type, payload) { |
| switch (type) { |
| case PacketType.CONNECT: return isObject(payload); |
| case PacketType.DISCONNECT: return payload === void 0; |
| case PacketType.CONNECT_ERROR: return typeof payload === "string" || isObject(payload); |
| case PacketType.EVENT: |
| case PacketType.BINARY_EVENT: return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS$1.indexOf(payload[0]) === -1); |
| case PacketType.ACK: |
| case PacketType.BINARY_ACK: return Array.isArray(payload); |
| } |
| } |
| |
| |
| |
| destroy() { |
| if (this.reconstructor) { |
| this.reconstructor.finishedReconstruction(); |
| this.reconstructor = null; |
| } |
| } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| var BinaryReconstructor = class { |
| constructor(packet) { |
| this.packet = packet; |
| this.buffers = []; |
| this.reconPack = packet; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| takeBinaryData(binData) { |
| this.buffers.push(binData); |
| if (this.buffers.length === this.reconPack.attachments) { |
| const packet = reconstructPacket(this.reconPack, this.buffers); |
| this.finishedReconstruction(); |
| return packet; |
| } |
| return null; |
| } |
| |
| |
| |
| finishedReconstruction() { |
| this.reconPack = null; |
| this.buffers = []; |
| } |
| }; |
| function isNamespaceValid(nsp) { |
| return typeof nsp === "string"; |
| } |
| var isInteger = Number.isInteger || function(value) { |
| return typeof value === "number" && isFinite(value) && Math.floor(value) === value; |
| }; |
| function isAckIdValid(id) { |
| return id === void 0 || isInteger(id); |
| } |
| function isObject(value) { |
| return Object.prototype.toString.call(value) === "[object Object]"; |
| } |
| function isDataValid(type, payload) { |
| switch (type) { |
| case PacketType.CONNECT: return payload === void 0 || isObject(payload); |
| case PacketType.DISCONNECT: return payload === void 0; |
| case PacketType.EVENT: return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS$1.indexOf(payload[0]) === -1); |
| case PacketType.ACK: return Array.isArray(payload); |
| case PacketType.CONNECT_ERROR: return typeof payload === "string" || isObject(payload); |
| default: return false; |
| } |
| } |
| function isPacketValid(packet) { |
| return isNamespaceValid(packet.nsp) && isAckIdValid(packet.id) && isDataValid(packet.type, packet.data); |
| } |
| |
| |
| function on(obj, ev, fn) { |
| obj.on(ev, fn); |
| return function subDestroy() { |
| obj.off(ev, fn); |
| }; |
| } |
| |
| |
| |
| |
| |
| |
| var RESERVED_EVENTS = Object.freeze({ |
| connect: 1, |
| connect_error: 1, |
| disconnect: 1, |
| disconnecting: 1, |
| newListener: 1, |
| removeListener: 1 |
| }); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var Socket = class extends Emitter { |
| |
| |
| |
| constructor(io, nsp, opts) { |
| super(); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| this.connected = false; |
| |
| |
| |
| |
| this.recovered = false; |
| |
| |
| |
| this.receiveBuffer = []; |
| |
| |
| |
| this.sendBuffer = []; |
| |
| |
| |
| |
| |
| |
| this._queue = []; |
| |
| |
| |
| |
| this._queueSeq = 0; |
| this.ids = 0; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| this.acks = {}; |
| this.flags = {}; |
| this.io = io; |
| this.nsp = nsp; |
| if (opts && opts.auth) this.auth = opts.auth; |
| this._opts = Object.assign({}, opts); |
| if (this.io._autoConnect) this.open(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| get disconnected() { |
| return !this.connected; |
| } |
| |
| |
| |
| |
| |
| subEvents() { |
| if (this.subs) return; |
| const io = this.io; |
| this.subs = [ |
| on(io, "open", this.onopen.bind(this)), |
| on(io, "packet", this.onpacket.bind(this)), |
| on(io, "error", this.onerror.bind(this)), |
| on(io, "close", this.onclose.bind(this)) |
| ]; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| get active() { |
| return !!this.subs; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| connect() { |
| if (this.connected) return this; |
| this.subEvents(); |
| if (!this.io["_reconnecting"]) this.io.open(); |
| if ("open" === this.io._readyState) this.onopen(); |
| return this; |
| } |
| |
| |
| |
| open() { |
| return this.connect(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| send(...args) { |
| args.unshift("message"); |
| this.emit.apply(this, args); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| emit(ev, ...args) { |
| var _a, _b, _c; |
| if (RESERVED_EVENTS.hasOwnProperty(ev)) throw new Error("\"" + ev.toString() + "\" is a reserved event name"); |
| args.unshift(ev); |
| if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) { |
| this._addToQueue(args); |
| return this; |
| } |
| const packet = { |
| type: PacketType.EVENT, |
| data: args |
| }; |
| packet.options = {}; |
| packet.options.compress = this.flags.compress !== false; |
| if ("function" === typeof args[args.length - 1]) { |
| const id = this.ids++; |
| const ack = args.pop(); |
| this._registerAckCallback(id, ack); |
| packet.id = id; |
| } |
| const isTransportWritable = (_b = (_a = this.io.engine) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.writable; |
| const isConnected = this.connected && !((_c = this.io.engine) === null || _c === void 0 ? void 0 : _c._hasPingExpired()); |
| if (this.flags.volatile && !isTransportWritable) {} else if (isConnected) { |
| this.notifyOutgoingListeners(packet); |
| this.packet(packet); |
| } else this.sendBuffer.push(packet); |
| this.flags = {}; |
| return this; |
| } |
| |
| |
| |
| _registerAckCallback(id, ack) { |
| var _a; |
| const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout; |
| if (timeout === void 0) { |
| this.acks[id] = ack; |
| return; |
| } |
| const timer = this.io.setTimeoutFn(() => { |
| delete this.acks[id]; |
| for (let i = 0; i < this.sendBuffer.length; i++) if (this.sendBuffer[i].id === id) this.sendBuffer.splice(i, 1); |
| ack.call(this, new Error("operation has timed out")); |
| }, timeout); |
| const fn = (...args) => { |
| this.io.clearTimeoutFn(timer); |
| ack.apply(this, args); |
| }; |
| fn.withError = true; |
| this.acks[id] = fn; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| emitWithAck(ev, ...args) { |
| return new Promise((resolve, reject) => { |
| const fn = (arg1, arg2) => { |
| return arg1 ? reject(arg1) : resolve(arg2); |
| }; |
| fn.withError = true; |
| args.push(fn); |
| this.emit(ev, ...args); |
| }); |
| } |
| |
| |
| |
| |
| |
| _addToQueue(args) { |
| let ack; |
| if (typeof args[args.length - 1] === "function") ack = args.pop(); |
| const packet = { |
| id: this._queueSeq++, |
| tryCount: 0, |
| pending: false, |
| args, |
| flags: Object.assign({ fromQueue: true }, this.flags) |
| }; |
| args.push((err, ...responseArgs) => { |
| if (packet !== this._queue[0]) {} |
| if (err !== null) { |
| if (packet.tryCount > this._opts.retries) { |
| this._queue.shift(); |
| if (ack) ack(err); |
| } |
| } else { |
| this._queue.shift(); |
| if (ack) ack(null, ...responseArgs); |
| } |
| packet.pending = false; |
| return this._drainQueue(); |
| }); |
| this._queue.push(packet); |
| this._drainQueue(); |
| } |
| |
| |
| |
| |
| |
| |
| _drainQueue(force = false) { |
| if (!this.connected || this._queue.length === 0) return; |
| const packet = this._queue[0]; |
| if (packet.pending && !force) return; |
| packet.pending = true; |
| packet.tryCount++; |
| this.flags = packet.flags; |
| this.emit.apply(this, packet.args); |
| } |
| |
| |
| |
| |
| |
| |
| packet(packet) { |
| packet.nsp = this.nsp; |
| this.io._packet(packet); |
| } |
| |
| |
| |
| |
| |
| onopen() { |
| if (typeof this.auth == "function") this.auth((data) => { |
| this._sendConnectPacket(data); |
| }); |
| else this._sendConnectPacket(this.auth); |
| } |
| |
| |
| |
| |
| |
| |
| _sendConnectPacket(data) { |
| this.packet({ |
| type: PacketType.CONNECT, |
| data: this._pid ? Object.assign({ |
| pid: this._pid, |
| offset: this._lastOffset |
| }, data) : data |
| }); |
| } |
| |
| |
| |
| |
| |
| |
| onerror(err) { |
| if (!this.connected) this.emitReserved("connect_error", err); |
| } |
| |
| |
| |
| |
| |
| |
| |
| onclose(reason, description) { |
| this.connected = false; |
| delete this.id; |
| this.emitReserved("disconnect", reason, description); |
| this._clearAcks(); |
| } |
| |
| |
| |
| |
| |
| |
| _clearAcks() { |
| Object.keys(this.acks).forEach((id) => { |
| if (!this.sendBuffer.some((packet) => String(packet.id) === id)) { |
| const ack = this.acks[id]; |
| delete this.acks[id]; |
| if (ack.withError) ack.call(this, new Error("socket has been disconnected")); |
| } |
| }); |
| } |
| |
| |
| |
| |
| |
| |
| onpacket(packet) { |
| if (!(packet.nsp === this.nsp)) return; |
| switch (packet.type) { |
| case PacketType.CONNECT: |
| if (packet.data && packet.data.sid) this.onconnect(packet.data.sid, packet.data.pid); |
| else this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)")); |
| break; |
| case PacketType.EVENT: |
| case PacketType.BINARY_EVENT: |
| this.onevent(packet); |
| break; |
| case PacketType.ACK: |
| case PacketType.BINARY_ACK: |
| this.onack(packet); |
| break; |
| case PacketType.DISCONNECT: |
| this.ondisconnect(); |
| break; |
| case PacketType.CONNECT_ERROR: |
| this.destroy(); |
| const err = new Error(packet.data.message); |
| err.data = packet.data.data; |
| this.emitReserved("connect_error", err); |
| break; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| onevent(packet) { |
| const args = packet.data || []; |
| if (null != packet.id) args.push(this.ack(packet.id)); |
| if (this.connected) this.emitEvent(args); |
| else this.receiveBuffer.push(Object.freeze(args)); |
| } |
| emitEvent(args) { |
| if (this._anyListeners && this._anyListeners.length) { |
| const listeners = this._anyListeners.slice(); |
| for (const listener of listeners) listener.apply(this, args); |
| } |
| super.emit.apply(this, args); |
| if (this._pid && args.length && typeof args[args.length - 1] === "string") this._lastOffset = args[args.length - 1]; |
| } |
| |
| |
| |
| |
| |
| ack(id) { |
| const self = this; |
| let sent = false; |
| return function(...args) { |
| if (sent) return; |
| sent = true; |
| self.packet({ |
| type: PacketType.ACK, |
| id, |
| data: args |
| }); |
| }; |
| } |
| |
| |
| |
| |
| |
| |
| onack(packet) { |
| const ack = this.acks[packet.id]; |
| if (typeof ack !== "function") return; |
| delete this.acks[packet.id]; |
| if (ack.withError) packet.data.unshift(null); |
| ack.apply(this, packet.data); |
| } |
| |
| |
| |
| |
| |
| onconnect(id, pid) { |
| this.id = id; |
| this.recovered = pid && this._pid === pid; |
| this._pid = pid; |
| this.connected = true; |
| this.emitBuffered(); |
| this._drainQueue(true); |
| this.emitReserved("connect"); |
| } |
| |
| |
| |
| |
| |
| emitBuffered() { |
| this.receiveBuffer.forEach((args) => this.emitEvent(args)); |
| this.receiveBuffer = []; |
| this.sendBuffer.forEach((packet) => { |
| this.notifyOutgoingListeners(packet); |
| this.packet(packet); |
| }); |
| this.sendBuffer = []; |
| } |
| |
| |
| |
| |
| |
| ondisconnect() { |
| this.destroy(); |
| this.onclose("io server disconnect"); |
| } |
| |
| |
| |
| |
| |
| |
| |
| destroy() { |
| if (this.subs) { |
| this.subs.forEach((subDestroy) => subDestroy()); |
| this.subs = void 0; |
| } |
| this.io["_destroy"](this); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| disconnect() { |
| if (this.connected) this.packet({ type: PacketType.DISCONNECT }); |
| this.destroy(); |
| if (this.connected) this.onclose("io client disconnect"); |
| return this; |
| } |
| |
| |
| |
| |
| |
| close() { |
| return this.disconnect(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| compress(compress) { |
| this.flags.compress = compress; |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| get volatile() { |
| this.flags.volatile = true; |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| timeout(timeout) { |
| this.flags.timeout = timeout; |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| onAny(listener) { |
| this._anyListeners = this._anyListeners || []; |
| this._anyListeners.push(listener); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| prependAny(listener) { |
| this._anyListeners = this._anyListeners || []; |
| this._anyListeners.unshift(listener); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| offAny(listener) { |
| if (!this._anyListeners) return this; |
| if (listener) { |
| const listeners = this._anyListeners; |
| for (let i = 0; i < listeners.length; i++) if (listener === listeners[i]) { |
| listeners.splice(i, 1); |
| return this; |
| } |
| } else this._anyListeners = []; |
| return this; |
| } |
| |
| |
| |
| |
| listenersAny() { |
| return this._anyListeners || []; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| onAnyOutgoing(listener) { |
| this._anyOutgoingListeners = this._anyOutgoingListeners || []; |
| this._anyOutgoingListeners.push(listener); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| prependAnyOutgoing(listener) { |
| this._anyOutgoingListeners = this._anyOutgoingListeners || []; |
| this._anyOutgoingListeners.unshift(listener); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| offAnyOutgoing(listener) { |
| if (!this._anyOutgoingListeners) return this; |
| if (listener) { |
| const listeners = this._anyOutgoingListeners; |
| for (let i = 0; i < listeners.length; i++) if (listener === listeners[i]) { |
| listeners.splice(i, 1); |
| return this; |
| } |
| } else this._anyOutgoingListeners = []; |
| return this; |
| } |
| |
| |
| |
| |
| listenersAnyOutgoing() { |
| return this._anyOutgoingListeners || []; |
| } |
| |
| |
| |
| |
| |
| |
| |
| notifyOutgoingListeners(packet) { |
| if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) { |
| const listeners = this._anyOutgoingListeners.slice(); |
| for (const listener of listeners) listener.apply(this, packet.data); |
| } |
| } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function Backoff(opts) { |
| opts = opts || {}; |
| this.ms = opts.min || 100; |
| this.max = opts.max || 1e4; |
| this.factor = opts.factor || 2; |
| this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0; |
| this.attempts = 0; |
| } |
| |
| |
| |
| |
| |
| |
| Backoff.prototype.duration = function() { |
| var ms = this.ms * Math.pow(this.factor, this.attempts++); |
| if (this.jitter) { |
| var rand = Math.random(); |
| var deviation = Math.floor(rand * this.jitter * ms); |
| ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation; |
| } |
| return Math.min(ms, this.max) | 0; |
| }; |
| |
| |
| |
| |
| |
| Backoff.prototype.reset = function() { |
| this.attempts = 0; |
| }; |
| |
| |
| |
| |
| |
| Backoff.prototype.setMin = function(min) { |
| this.ms = min; |
| }; |
| |
| |
| |
| |
| |
| Backoff.prototype.setMax = function(max) { |
| this.max = max; |
| }; |
| |
| |
| |
| |
| |
| Backoff.prototype.setJitter = function(jitter) { |
| this.jitter = jitter; |
| }; |
| |
| |
| var Manager = class extends Emitter { |
| constructor(uri, opts) { |
| var _a; |
| super(); |
| this.nsps = {}; |
| this.subs = []; |
| if (uri && "object" === typeof uri) { |
| opts = uri; |
| uri = void 0; |
| } |
| opts = opts || {}; |
| opts.path = opts.path || "/socket.io"; |
| this.opts = opts; |
| installTimerFunctions(this, opts); |
| this.reconnection(opts.reconnection !== false); |
| this.reconnectionAttempts(opts.reconnectionAttempts || Infinity); |
| this.reconnectionDelay(opts.reconnectionDelay || 1e3); |
| this.reconnectionDelayMax(opts.reconnectionDelayMax || 5e3); |
| this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : .5); |
| this.backoff = new Backoff({ |
| min: this.reconnectionDelay(), |
| max: this.reconnectionDelayMax(), |
| jitter: this.randomizationFactor() |
| }); |
| this.timeout(null == opts.timeout ? 2e4 : opts.timeout); |
| this._readyState = "closed"; |
| this.uri = uri; |
| const _parser = opts.parser || esm_debug_exports; |
| this.encoder = new _parser.Encoder(); |
| this.decoder = new _parser.Decoder(); |
| this._autoConnect = opts.autoConnect !== false; |
| if (this._autoConnect) this.open(); |
| } |
| reconnection(v) { |
| if (!arguments.length) return this._reconnection; |
| this._reconnection = !!v; |
| if (!v) this.skipReconnect = true; |
| return this; |
| } |
| reconnectionAttempts(v) { |
| if (v === void 0) return this._reconnectionAttempts; |
| this._reconnectionAttempts = v; |
| return this; |
| } |
| reconnectionDelay(v) { |
| var _a; |
| if (v === void 0) return this._reconnectionDelay; |
| this._reconnectionDelay = v; |
| (_a = this.backoff) === null || _a === void 0 || _a.setMin(v); |
| return this; |
| } |
| randomizationFactor(v) { |
| var _a; |
| if (v === void 0) return this._randomizationFactor; |
| this._randomizationFactor = v; |
| (_a = this.backoff) === null || _a === void 0 || _a.setJitter(v); |
| return this; |
| } |
| reconnectionDelayMax(v) { |
| var _a; |
| if (v === void 0) return this._reconnectionDelayMax; |
| this._reconnectionDelayMax = v; |
| (_a = this.backoff) === null || _a === void 0 || _a.setMax(v); |
| return this; |
| } |
| timeout(v) { |
| if (!arguments.length) return this._timeout; |
| this._timeout = v; |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| maybeReconnectOnOpen() { |
| if (!this._reconnecting && this._reconnection && this.backoff.attempts === 0) this.reconnect(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| open(fn) { |
| if (~this._readyState.indexOf("open")) return this; |
| this.engine = new Socket$1(this.uri, this.opts); |
| const socket = this.engine; |
| const self = this; |
| this._readyState = "opening"; |
| this.skipReconnect = false; |
| const openSubDestroy = on(socket, "open", function() { |
| self.onopen(); |
| fn && fn(); |
| }); |
| const onError = (err) => { |
| this.cleanup(); |
| this._readyState = "closed"; |
| this.emitReserved("error", err); |
| if (fn) fn(err); |
| else this.maybeReconnectOnOpen(); |
| }; |
| const errorSub = on(socket, "error", onError); |
| if (false !== this._timeout) { |
| const timeout = this._timeout; |
| const timer = this.setTimeoutFn(() => { |
| openSubDestroy(); |
| onError( new Error("timeout")); |
| socket.close(); |
| }, timeout); |
| if (this.opts.autoUnref) timer.unref(); |
| this.subs.push(() => { |
| this.clearTimeoutFn(timer); |
| }); |
| } |
| this.subs.push(openSubDestroy); |
| this.subs.push(errorSub); |
| return this; |
| } |
| |
| |
| |
| |
| |
| |
| connect(fn) { |
| return this.open(fn); |
| } |
| |
| |
| |
| |
| |
| onopen() { |
| this.cleanup(); |
| this._readyState = "open"; |
| this.emitReserved("open"); |
| const socket = this.engine; |
| this.subs.push(on(socket, "ping", this.onping.bind(this)), on(socket, "data", this.ondata.bind(this)), on(socket, "error", this.onerror.bind(this)), on(socket, "close", this.onclose.bind(this)), on(this.decoder, "decoded", this.ondecoded.bind(this))); |
| } |
| |
| |
| |
| |
| |
| onping() { |
| this.emitReserved("ping"); |
| } |
| |
| |
| |
| |
| |
| ondata(data) { |
| try { |
| this.decoder.add(data); |
| } catch (e) { |
| this.onclose("parse error", e); |
| } |
| } |
| |
| |
| |
| |
| |
| ondecoded(packet) { |
| nextTick(() => { |
| this.emitReserved("packet", packet); |
| }, this.setTimeoutFn); |
| } |
| |
| |
| |
| |
| |
| onerror(err) { |
| this.emitReserved("error", err); |
| } |
| |
| |
| |
| |
| |
| |
| socket(nsp, opts) { |
| let socket = this.nsps[nsp]; |
| if (!socket) { |
| socket = new Socket(this, nsp, opts); |
| this.nsps[nsp] = socket; |
| } else if (this._autoConnect && !socket.active) socket.connect(); |
| return socket; |
| } |
| |
| |
| |
| |
| |
| |
| _destroy(socket) { |
| const nsps = Object.keys(this.nsps); |
| for (const nsp of nsps) if (this.nsps[nsp].active) return; |
| this._close(); |
| } |
| |
| |
| |
| |
| |
| |
| _packet(packet) { |
| const encodedPackets = this.encoder.encode(packet); |
| for (let i = 0; i < encodedPackets.length; i++) this.engine.write(encodedPackets[i], packet.options); |
| } |
| |
| |
| |
| |
| |
| cleanup() { |
| this.subs.forEach((subDestroy) => subDestroy()); |
| this.subs.length = 0; |
| this.decoder.destroy(); |
| } |
| |
| |
| |
| |
| |
| _close() { |
| this.skipReconnect = true; |
| this._reconnecting = false; |
| this.onclose("forced close"); |
| } |
| |
| |
| |
| |
| |
| disconnect() { |
| return this._close(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| onclose(reason, description) { |
| var _a; |
| this.cleanup(); |
| (_a = this.engine) === null || _a === void 0 || _a.close(); |
| this.backoff.reset(); |
| this._readyState = "closed"; |
| this.emitReserved("close", reason, description); |
| if (this._reconnection && !this.skipReconnect) this.reconnect(); |
| } |
| |
| |
| |
| |
| |
| reconnect() { |
| if (this._reconnecting || this.skipReconnect) return this; |
| const self = this; |
| if (this.backoff.attempts >= this._reconnectionAttempts) { |
| this.backoff.reset(); |
| this.emitReserved("reconnect_failed"); |
| this._reconnecting = false; |
| } else { |
| const delay = this.backoff.duration(); |
| this._reconnecting = true; |
| const timer = this.setTimeoutFn(() => { |
| if (self.skipReconnect) return; |
| this.emitReserved("reconnect_attempt", self.backoff.attempts); |
| if (self.skipReconnect) return; |
| self.open((err) => { |
| if (err) { |
| self._reconnecting = false; |
| self.reconnect(); |
| this.emitReserved("reconnect_error", err); |
| } else self.onreconnect(); |
| }); |
| }, delay); |
| if (this.opts.autoUnref) timer.unref(); |
| this.subs.push(() => { |
| this.clearTimeoutFn(timer); |
| }); |
| } |
| } |
| |
| |
| |
| |
| |
| onreconnect() { |
| const attempt = this.backoff.attempts; |
| this._reconnecting = false; |
| this.backoff.reset(); |
| this.emitReserved("reconnect", attempt); |
| } |
| }; |
| |
| |
| |
| |
| |
| var cache = {}; |
| function lookup(uri, opts) { |
| if (typeof uri === "object") { |
| opts = uri; |
| uri = void 0; |
| } |
| opts = opts || {}; |
| const parsed = url(uri, opts.path || "/socket.io"); |
| const source = parsed.source; |
| const id = parsed.id; |
| const path = parsed.path; |
| const sameNamespace = cache[id] && path in cache[id]["nsps"]; |
| const newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace; |
| let io; |
| if (newConnection) io = new Manager(source, opts); |
| else { |
| if (!cache[id]) cache[id] = new Manager(source, opts); |
| io = cache[id]; |
| } |
| if (parsed.query && !opts.query) opts.query = parsed.queryKey; |
| return io.socket(parsed.path, opts); |
| } |
| Object.assign(lookup, { |
| Manager, |
| Socket, |
| io: lookup, |
| connect: lookup |
| }); |
| |
| export { Fetch, Manager, WS as NodeWebSocket, WS as WebSocket, XHR as NodeXHR, XHR, Socket, WT as WebTransport, lookup as connect, lookup as default, lookup as io, protocol }; |
|
|
| |