@pixotope/socket.io-client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2338 @@
1
+ const y = /* @__PURE__ */ Object.create(null);
2
+ y.open = "0";
3
+ y.close = "1";
4
+ y.ping = "2";
5
+ y.pong = "3";
6
+ y.message = "4";
7
+ y.upgrade = "5";
8
+ y.noop = "6";
9
+ const A = /* @__PURE__ */ Object.create(null);
10
+ Object.keys(y).forEach((i) => {
11
+ A[y[i]] = i;
12
+ });
13
+ const P = { type: "error", data: "parser error" }, Q = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", G = typeof ArrayBuffer == "function", j = (i) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(i) : i && i.buffer instanceof ArrayBuffer, V = ({ type: i, data: e }, t, s) => Q && e instanceof Blob ? t ? s(e) : $(e, s) : G && (e instanceof ArrayBuffer || j(e)) ? t ? s(e) : $(new Blob([e]), s) : s(y[i] + (e || "")), $ = (i, e) => {
14
+ const t = new FileReader();
15
+ return t.onload = function() {
16
+ const s = t.result.split(",")[1];
17
+ e("b" + (s || ""));
18
+ }, t.readAsDataURL(i);
19
+ };
20
+ function Y(i) {
21
+ return i instanceof Uint8Array ? i : i instanceof ArrayBuffer ? new Uint8Array(i) : new Uint8Array(i.buffer, i.byteOffset, i.byteLength);
22
+ }
23
+ let B;
24
+ function ue(i, e) {
25
+ if (Q && i.data instanceof Blob)
26
+ return i.data.arrayBuffer().then(Y).then(e);
27
+ if (G && (i.data instanceof ArrayBuffer || j(i.data)))
28
+ return e(Y(i.data));
29
+ V(i, !1, (t) => {
30
+ B || (B = new TextEncoder()), e(B.encode(t));
31
+ });
32
+ }
33
+ const z = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", E = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
34
+ for (let i = 0; i < z.length; i++)
35
+ E[z.charCodeAt(i)] = i;
36
+ const fe = (i) => {
37
+ let e = i.length * 0.75, t = i.length, s, n = 0, r, o, c, h;
38
+ i[i.length - 1] === "=" && (e--, i[i.length - 2] === "=" && e--);
39
+ const g = new ArrayBuffer(e), f = new Uint8Array(g);
40
+ for (s = 0; s < t; s += 4)
41
+ r = E[i.charCodeAt(s)], o = E[i.charCodeAt(s + 1)], c = E[i.charCodeAt(s + 2)], h = E[i.charCodeAt(s + 3)], f[n++] = r << 2 | o >> 4, f[n++] = (o & 15) << 4 | c >> 2, f[n++] = (c & 3) << 6 | h & 63;
42
+ return g;
43
+ }, le = typeof ArrayBuffer == "function", M = (i, e) => {
44
+ if (typeof i != "string")
45
+ return {
46
+ type: "message",
47
+ data: Z(i, e)
48
+ };
49
+ const t = i.charAt(0);
50
+ return t === "b" ? {
51
+ type: "message",
52
+ data: pe(i.substring(1), e)
53
+ } : A[t] ? i.length > 1 ? {
54
+ type: A[t],
55
+ data: i.substring(1)
56
+ } : {
57
+ type: A[t]
58
+ } : P;
59
+ }, pe = (i, e) => {
60
+ if (le) {
61
+ const t = fe(i);
62
+ return Z(t, e);
63
+ } else
64
+ return { base64: !0, data: i };
65
+ }, Z = (i, e) => {
66
+ switch (e) {
67
+ case "blob":
68
+ return i instanceof Blob ? i : new Blob([i]);
69
+ case "arraybuffer":
70
+ default:
71
+ return i instanceof ArrayBuffer ? i : i.buffer;
72
+ }
73
+ }, ee = "", de = (i, e) => {
74
+ const t = i.length, s = new Array(t);
75
+ let n = 0;
76
+ i.forEach((r, o) => {
77
+ V(r, !1, (c) => {
78
+ s[o] = c, ++n === t && e(s.join(ee));
79
+ });
80
+ });
81
+ }, ye = (i, e) => {
82
+ const t = i.split(ee), s = [];
83
+ for (let n = 0; n < t.length; n++) {
84
+ const r = M(t[n], e);
85
+ if (s.push(r), r.type === "error")
86
+ break;
87
+ }
88
+ return s;
89
+ };
90
+ function ge() {
91
+ return new TransformStream({
92
+ transform(i, e) {
93
+ ue(i, (t) => {
94
+ const s = t.length;
95
+ let n;
96
+ if (s < 126)
97
+ n = new Uint8Array(1), new DataView(n.buffer).setUint8(0, s);
98
+ else if (s < 65536) {
99
+ n = new Uint8Array(3);
100
+ const r = new DataView(n.buffer);
101
+ r.setUint8(0, 126), r.setUint16(1, s);
102
+ } else {
103
+ n = new Uint8Array(9);
104
+ const r = new DataView(n.buffer);
105
+ r.setUint8(0, 127), r.setBigUint64(1, BigInt(s));
106
+ }
107
+ i.data && typeof i.data != "string" && (n[0] |= 128), e.enqueue(n), e.enqueue(t);
108
+ });
109
+ }
110
+ });
111
+ }
112
+ let x;
113
+ function k(i) {
114
+ return i.reduce((e, t) => e + t.length, 0);
115
+ }
116
+ function T(i, e) {
117
+ if (i[0].length === e)
118
+ return i.shift();
119
+ const t = new Uint8Array(e);
120
+ let s = 0;
121
+ for (let n = 0; n < e; n++)
122
+ t[n] = i[0][s++], s === i[0].length && (i.shift(), s = 0);
123
+ return i.length && s < i[0].length && (i[0] = i[0].slice(s)), t;
124
+ }
125
+ function me(i, e) {
126
+ x || (x = new TextDecoder());
127
+ const t = [];
128
+ let s = 0, n = -1, r = !1;
129
+ return new TransformStream({
130
+ transform(o, c) {
131
+ for (t.push(o); ; ) {
132
+ if (s === 0) {
133
+ if (k(t) < 1)
134
+ break;
135
+ const h = T(t, 1);
136
+ r = (h[0] & 128) === 128, n = h[0] & 127, n < 126 ? s = 3 : n === 126 ? s = 1 : s = 2;
137
+ } else if (s === 1) {
138
+ if (k(t) < 2)
139
+ break;
140
+ const h = T(t, 2);
141
+ n = new DataView(h.buffer, h.byteOffset, h.length).getUint16(0), s = 3;
142
+ } else if (s === 2) {
143
+ if (k(t) < 8)
144
+ break;
145
+ const h = T(t, 8), g = new DataView(h.buffer, h.byteOffset, h.length), f = g.getUint32(0);
146
+ if (f > Math.pow(2, 21) - 1) {
147
+ c.enqueue(P);
148
+ break;
149
+ }
150
+ n = f * Math.pow(2, 32) + g.getUint32(4), s = 3;
151
+ } else {
152
+ if (k(t) < n)
153
+ break;
154
+ const h = T(t, n);
155
+ c.enqueue(M(r ? h : x.decode(h), e)), s = 0;
156
+ }
157
+ if (n === 0 || n > i) {
158
+ c.enqueue(P);
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ });
164
+ }
165
+ const te = 4;
166
+ function u(i) {
167
+ if (i) return _e(i);
168
+ }
169
+ function _e(i) {
170
+ for (var e in u.prototype)
171
+ i[e] = u.prototype[e];
172
+ return i;
173
+ }
174
+ u.prototype.on = u.prototype.addEventListener = function(i, e) {
175
+ return this._callbacks = this._callbacks || {}, (this._callbacks["$" + i] = this._callbacks["$" + i] || []).push(e), this;
176
+ };
177
+ u.prototype.once = function(i, e) {
178
+ function t() {
179
+ this.off(i, t), e.apply(this, arguments);
180
+ }
181
+ return t.fn = e, this.on(i, t), this;
182
+ };
183
+ u.prototype.off = u.prototype.removeListener = u.prototype.removeAllListeners = u.prototype.removeEventListener = function(i, e) {
184
+ if (this._callbacks = this._callbacks || {}, arguments.length == 0)
185
+ return this._callbacks = {}, this;
186
+ var t = this._callbacks["$" + i];
187
+ if (!t) return this;
188
+ if (arguments.length == 1)
189
+ return delete this._callbacks["$" + i], this;
190
+ for (var s, n = 0; n < t.length; n++)
191
+ if (s = t[n], s === e || s.fn === e) {
192
+ t.splice(n, 1);
193
+ break;
194
+ }
195
+ return t.length === 0 && delete this._callbacks["$" + i], this;
196
+ };
197
+ u.prototype.emit = function(i) {
198
+ this._callbacks = this._callbacks || {};
199
+ for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + i], s = 1; s < arguments.length; s++)
200
+ e[s - 1] = arguments[s];
201
+ if (t) {
202
+ t = t.slice(0);
203
+ for (var s = 0, n = t.length; s < n; ++s)
204
+ t[s].apply(this, e);
205
+ }
206
+ return this;
207
+ };
208
+ u.prototype.emitReserved = u.prototype.emit;
209
+ u.prototype.listeners = function(i) {
210
+ return this._callbacks = this._callbacks || {}, this._callbacks["$" + i] || [];
211
+ };
212
+ u.prototype.hasListeners = function(i) {
213
+ return !!this.listeners(i).length;
214
+ };
215
+ const C = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), l = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), be = "arraybuffer";
216
+ function se(i, ...e) {
217
+ return e.reduce((t, s) => (i.hasOwnProperty(s) && (t[s] = i[s]), t), {});
218
+ }
219
+ const we = l.setTimeout, ve = l.clearTimeout;
220
+ function S(i, e) {
221
+ e.useNativeTimers ? (i.setTimeoutFn = we.bind(l), i.clearTimeoutFn = ve.bind(l)) : (i.setTimeoutFn = l.setTimeout.bind(l), i.clearTimeoutFn = l.clearTimeout.bind(l));
222
+ }
223
+ const Ee = 1.33;
224
+ function ke(i) {
225
+ return typeof i == "string" ? Te(i) : Math.ceil((i.byteLength || i.size) * Ee);
226
+ }
227
+ function Te(i) {
228
+ let e = 0, t = 0;
229
+ for (let s = 0, n = i.length; s < n; s++)
230
+ e = i.charCodeAt(s), e < 128 ? t += 1 : e < 2048 ? t += 2 : e < 55296 || e >= 57344 ? t += 3 : (s++, t += 4);
231
+ return t;
232
+ }
233
+ function ie() {
234
+ return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
235
+ }
236
+ function Ae(i) {
237
+ let e = "";
238
+ for (let t in i)
239
+ i.hasOwnProperty(t) && (e.length && (e += "&"), e += encodeURIComponent(t) + "=" + encodeURIComponent(i[t]));
240
+ return e;
241
+ }
242
+ function Re(i) {
243
+ let e = {}, t = i.split("&");
244
+ for (let s = 0, n = t.length; s < n; s++) {
245
+ let r = t[s].split("=");
246
+ e[decodeURIComponent(r[0])] = decodeURIComponent(r[1]);
247
+ }
248
+ return e;
249
+ }
250
+ class Oe extends Error {
251
+ constructor(e, t, s) {
252
+ super(e), this.description = t, this.context = s, this.type = "TransportError";
253
+ }
254
+ }
255
+ class H extends u {
256
+ /**
257
+ * Transport abstract constructor.
258
+ *
259
+ * @param {Object} opts - options
260
+ * @protected
261
+ */
262
+ constructor(e) {
263
+ super(), this.writable = !1, S(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
264
+ }
265
+ /**
266
+ * Emits an error.
267
+ *
268
+ * @param {String} reason
269
+ * @param description
270
+ * @param context - the error context
271
+ * @return {Transport} for chaining
272
+ * @protected
273
+ */
274
+ onError(e, t, s) {
275
+ return super.emitReserved("error", new Oe(e, t, s)), this;
276
+ }
277
+ /**
278
+ * Opens the transport.
279
+ */
280
+ open() {
281
+ return this.readyState = "opening", this.doOpen(), this;
282
+ }
283
+ /**
284
+ * Closes the transport.
285
+ */
286
+ close() {
287
+ return (this.readyState === "opening" || this.readyState === "open") && (this.doClose(), this.onClose()), this;
288
+ }
289
+ /**
290
+ * Sends multiple packets.
291
+ *
292
+ * @param {Array} packets
293
+ */
294
+ send(e) {
295
+ this.readyState === "open" && this.write(e);
296
+ }
297
+ /**
298
+ * Called upon open
299
+ *
300
+ * @protected
301
+ */
302
+ onOpen() {
303
+ this.readyState = "open", this.writable = !0, super.emitReserved("open");
304
+ }
305
+ /**
306
+ * Called with data.
307
+ *
308
+ * @param {String} data
309
+ * @protected
310
+ */
311
+ onData(e) {
312
+ const t = M(e, this.socket.binaryType);
313
+ this.onPacket(t);
314
+ }
315
+ /**
316
+ * Called with a decoded packet.
317
+ *
318
+ * @protected
319
+ */
320
+ onPacket(e) {
321
+ super.emitReserved("packet", e);
322
+ }
323
+ /**
324
+ * Called upon close.
325
+ *
326
+ * @protected
327
+ */
328
+ onClose(e) {
329
+ this.readyState = "closed", super.emitReserved("close", e);
330
+ }
331
+ /**
332
+ * Pauses the transport, in order not to lose packets during an upgrade.
333
+ *
334
+ * @param onPause
335
+ */
336
+ pause(e) {
337
+ }
338
+ createUri(e, t = {}) {
339
+ return e + "://" + this._hostname() + this._port() + this.opts.path + this._query(t);
340
+ }
341
+ _hostname() {
342
+ const e = this.opts.hostname;
343
+ return e.indexOf(":") === -1 ? e : "[" + e + "]";
344
+ }
345
+ _port() {
346
+ return this.opts.port && (this.opts.secure && +(this.opts.port !== 443) || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
347
+ }
348
+ _query(e) {
349
+ const t = Ae(e);
350
+ return t.length ? "?" + t : "";
351
+ }
352
+ }
353
+ class ne extends H {
354
+ constructor() {
355
+ super(...arguments), this._polling = !1;
356
+ }
357
+ get name() {
358
+ return "polling";
359
+ }
360
+ /**
361
+ * Opens the socket (triggers polling). We write a PING message to determine
362
+ * when the transport is open.
363
+ *
364
+ * @protected
365
+ */
366
+ doOpen() {
367
+ this._poll();
368
+ }
369
+ /**
370
+ * Pauses polling.
371
+ *
372
+ * @param {Function} onPause - callback upon buffers are flushed and transport is paused
373
+ * @package
374
+ */
375
+ pause(e) {
376
+ this.readyState = "pausing";
377
+ const t = () => {
378
+ this.readyState = "paused", e();
379
+ };
380
+ if (this._polling || !this.writable) {
381
+ let s = 0;
382
+ this._polling && (s++, this.once("pollComplete", function() {
383
+ --s || t();
384
+ })), this.writable || (s++, this.once("drain", function() {
385
+ --s || t();
386
+ }));
387
+ } else
388
+ t();
389
+ }
390
+ /**
391
+ * Starts polling cycle.
392
+ *
393
+ * @private
394
+ */
395
+ _poll() {
396
+ this._polling = !0, this.doPoll(), this.emitReserved("poll");
397
+ }
398
+ /**
399
+ * Overloads onData to detect payloads.
400
+ *
401
+ * @protected
402
+ */
403
+ onData(e) {
404
+ const t = (s) => {
405
+ if (this.readyState === "opening" && s.type === "open" && this.onOpen(), s.type === "close")
406
+ return this.onClose({ description: "transport closed by the server" }), !1;
407
+ this.onPacket(s);
408
+ };
409
+ ye(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
410
+ }
411
+ /**
412
+ * For polling, send a close packet.
413
+ *
414
+ * @protected
415
+ */
416
+ doClose() {
417
+ const e = () => {
418
+ this.write([{ type: "close" }]);
419
+ };
420
+ this.readyState === "open" ? e() : this.once("open", e);
421
+ }
422
+ /**
423
+ * Writes a packets payload.
424
+ *
425
+ * @param {Array} packets - data packets
426
+ * @protected
427
+ */
428
+ write(e) {
429
+ this.writable = !1, de(e, (t) => {
430
+ this.doWrite(t, () => {
431
+ this.writable = !0, this.emitReserved("drain");
432
+ });
433
+ });
434
+ }
435
+ /**
436
+ * Generates uri for connection.
437
+ *
438
+ * @private
439
+ */
440
+ uri() {
441
+ const e = this.opts.secure ? "https" : "http", t = this.query || {};
442
+ return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = ie()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
443
+ }
444
+ }
445
+ let re = !1;
446
+ try {
447
+ re = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
448
+ } catch {
449
+ }
450
+ const Ce = re;
451
+ function Se() {
452
+ }
453
+ class Be extends ne {
454
+ /**
455
+ * XHR Polling constructor.
456
+ *
457
+ * @param {Object} opts
458
+ * @package
459
+ */
460
+ constructor(e) {
461
+ if (super(e), typeof location < "u") {
462
+ const t = location.protocol === "https:";
463
+ let s = location.port;
464
+ s || (s = t ? "443" : "80"), this.xd = typeof location < "u" && e.hostname !== location.hostname || s !== e.port;
465
+ }
466
+ }
467
+ /**
468
+ * Sends data.
469
+ *
470
+ * @param {String} data to send.
471
+ * @param {Function} called upon flush.
472
+ * @private
473
+ */
474
+ doWrite(e, t) {
475
+ const s = this.request({
476
+ method: "POST",
477
+ data: e
478
+ });
479
+ s.on("success", t), s.on("error", (n, r) => {
480
+ this.onError("xhr post error", n, r);
481
+ });
482
+ }
483
+ /**
484
+ * Starts a poll cycle.
485
+ *
486
+ * @private
487
+ */
488
+ doPoll() {
489
+ const e = this.request();
490
+ e.on("data", this.onData.bind(this)), e.on("error", (t, s) => {
491
+ this.onError("xhr poll error", t, s);
492
+ }), this.pollXhr = e;
493
+ }
494
+ }
495
+ class d extends u {
496
+ /**
497
+ * Request constructor
498
+ *
499
+ * @param {Object} options
500
+ * @package
501
+ */
502
+ constructor(e, t, s) {
503
+ super(), this.createRequest = e, S(this, s), this._opts = s, this._method = s.method || "GET", this._uri = t, this._data = s.data !== void 0 ? s.data : null, this._create();
504
+ }
505
+ /**
506
+ * Creates the XHR object and sends the request.
507
+ *
508
+ * @private
509
+ */
510
+ _create() {
511
+ var e;
512
+ const t = se(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
513
+ t.xdomain = !!this._opts.xd;
514
+ const s = this._xhr = this.createRequest(t);
515
+ try {
516
+ s.open(this._method, this._uri, !0);
517
+ try {
518
+ if (this._opts.extraHeaders) {
519
+ s.setDisableHeaderCheck && s.setDisableHeaderCheck(!0);
520
+ for (let n in this._opts.extraHeaders)
521
+ this._opts.extraHeaders.hasOwnProperty(n) && s.setRequestHeader(n, this._opts.extraHeaders[n]);
522
+ }
523
+ } catch {
524
+ }
525
+ if (this._method === "POST")
526
+ try {
527
+ s.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
528
+ } catch {
529
+ }
530
+ try {
531
+ s.setRequestHeader("Accept", "*/*");
532
+ } catch {
533
+ }
534
+ (e = this._opts.cookieJar) === null || e === void 0 || e.addCookies(s), "withCredentials" in s && (s.withCredentials = this._opts.withCredentials), this._opts.requestTimeout && (s.timeout = this._opts.requestTimeout), s.onreadystatechange = () => {
535
+ var n;
536
+ s.readyState === 3 && ((n = this._opts.cookieJar) === null || n === void 0 || n.parseCookies(
537
+ // @ts-ignore
538
+ s.getResponseHeader("set-cookie")
539
+ )), s.readyState === 4 && (s.status === 200 || s.status === 1223 ? this._onLoad() : this.setTimeoutFn(() => {
540
+ this._onError(typeof s.status == "number" ? s.status : 0);
541
+ }, 0));
542
+ }, s.send(this._data);
543
+ } catch (n) {
544
+ this.setTimeoutFn(() => {
545
+ this._onError(n);
546
+ }, 0);
547
+ return;
548
+ }
549
+ typeof document < "u" && (this._index = d.requestsCount++, d.requests[this._index] = this);
550
+ }
551
+ /**
552
+ * Called upon error.
553
+ *
554
+ * @private
555
+ */
556
+ _onError(e) {
557
+ this.emitReserved("error", e, this._xhr), this._cleanup(!0);
558
+ }
559
+ /**
560
+ * Cleans up house.
561
+ *
562
+ * @private
563
+ */
564
+ _cleanup(e) {
565
+ if (!(typeof this._xhr > "u" || this._xhr === null)) {
566
+ if (this._xhr.onreadystatechange = Se, e)
567
+ try {
568
+ this._xhr.abort();
569
+ } catch {
570
+ }
571
+ typeof document < "u" && delete d.requests[this._index], this._xhr = null;
572
+ }
573
+ }
574
+ /**
575
+ * Called upon load.
576
+ *
577
+ * @private
578
+ */
579
+ _onLoad() {
580
+ const e = this._xhr.responseText;
581
+ e !== null && (this.emitReserved("data", e), this.emitReserved("success"), this._cleanup());
582
+ }
583
+ /**
584
+ * Aborts the request.
585
+ *
586
+ * @package
587
+ */
588
+ abort() {
589
+ this._cleanup();
590
+ }
591
+ }
592
+ d.requestsCount = 0;
593
+ d.requests = {};
594
+ if (typeof document < "u") {
595
+ if (typeof attachEvent == "function")
596
+ attachEvent("onunload", J);
597
+ else if (typeof addEventListener == "function") {
598
+ const i = "onpagehide" in l ? "pagehide" : "unload";
599
+ addEventListener(i, J, !1);
600
+ }
601
+ }
602
+ function J() {
603
+ for (let i in d.requests)
604
+ d.requests.hasOwnProperty(i) && d.requests[i].abort();
605
+ }
606
+ const xe = function() {
607
+ const i = oe({
608
+ xdomain: !1
609
+ });
610
+ return i && i.responseType !== null;
611
+ }();
612
+ class Ne extends Be {
613
+ constructor(e) {
614
+ super(e);
615
+ const t = e && e.forceBase64;
616
+ this.supportsBinary = xe && !t;
617
+ }
618
+ request(e = {}) {
619
+ return Object.assign(e, { xd: this.xd }, this.opts), new d(oe, this.uri(), e);
620
+ }
621
+ }
622
+ function oe(i) {
623
+ const e = i.xdomain;
624
+ try {
625
+ if (typeof XMLHttpRequest < "u" && (!e || Ce))
626
+ return new XMLHttpRequest();
627
+ } catch {
628
+ }
629
+ if (!e)
630
+ try {
631
+ return new l[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
632
+ } catch {
633
+ }
634
+ }
635
+ const ae = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
636
+ class Le extends H {
637
+ get name() {
638
+ return "websocket";
639
+ }
640
+ doOpen() {
641
+ const e = this.uri(), t = this.opts.protocols, s = ae ? {} : se(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
642
+ this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
643
+ try {
644
+ this.ws = this.createSocket(e, t, s);
645
+ } catch (n) {
646
+ return this.emitReserved("error", n);
647
+ }
648
+ this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
649
+ }
650
+ /**
651
+ * Adds event listeners to the socket
652
+ *
653
+ * @private
654
+ */
655
+ addEventListeners() {
656
+ this.ws.onopen = () => {
657
+ this.opts.autoUnref && this.ws._socket.unref(), this.onOpen();
658
+ }, this.ws.onclose = (e) => this.onClose({
659
+ description: "websocket connection closed",
660
+ context: e
661
+ }), this.ws.onmessage = (e) => this.onData(e.data), this.ws.onerror = (e) => this.onError("websocket error", e);
662
+ }
663
+ write(e) {
664
+ this.writable = !1;
665
+ for (let t = 0; t < e.length; t++) {
666
+ const s = e[t], n = t === e.length - 1;
667
+ V(s, this.supportsBinary, (r) => {
668
+ try {
669
+ this.doWrite(s, r);
670
+ } catch {
671
+ }
672
+ n && C(() => {
673
+ this.writable = !0, this.emitReserved("drain");
674
+ }, this.setTimeoutFn);
675
+ });
676
+ }
677
+ }
678
+ doClose() {
679
+ typeof this.ws < "u" && (this.ws.onerror = () => {
680
+ }, this.ws.close(), this.ws = null);
681
+ }
682
+ /**
683
+ * Generates uri for connection.
684
+ *
685
+ * @private
686
+ */
687
+ uri() {
688
+ const e = this.opts.secure ? "wss" : "ws", t = this.query || {};
689
+ return this.opts.timestampRequests && (t[this.opts.timestampParam] = ie()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
690
+ }
691
+ }
692
+ const N = l.WebSocket || l.MozWebSocket;
693
+ class Pe extends Le {
694
+ createSocket(e, t, s) {
695
+ return ae ? new N(e, t, s) : t ? new N(e, t) : new N(e);
696
+ }
697
+ doWrite(e, t) {
698
+ this.ws.send(t);
699
+ }
700
+ }
701
+ class qe extends H {
702
+ get name() {
703
+ return "webtransport";
704
+ }
705
+ doOpen() {
706
+ try {
707
+ this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
708
+ } catch (e) {
709
+ return this.emitReserved("error", e);
710
+ }
711
+ this._transport.closed.then(() => {
712
+ this.onClose();
713
+ }).catch((e) => {
714
+ this.onError("webtransport error", e);
715
+ }), this._transport.ready.then(() => {
716
+ this._transport.createBidirectionalStream().then((e) => {
717
+ const t = me(Number.MAX_SAFE_INTEGER, this.socket.binaryType), s = e.readable.pipeThrough(t).getReader(), n = ge();
718
+ n.readable.pipeTo(e.writable), this._writer = n.writable.getWriter();
719
+ const r = () => {
720
+ s.read().then(({ done: c, value: h }) => {
721
+ c || (this.onPacket(h), r());
722
+ }).catch((c) => {
723
+ });
724
+ };
725
+ r();
726
+ const o = { type: "open" };
727
+ this.query.sid && (o.data = `{"sid":"${this.query.sid}"}`), this._writer.write(o).then(() => this.onOpen());
728
+ });
729
+ });
730
+ }
731
+ write(e) {
732
+ this.writable = !1;
733
+ for (let t = 0; t < e.length; t++) {
734
+ const s = e[t], n = t === e.length - 1;
735
+ this._writer.write(s).then(() => {
736
+ n && C(() => {
737
+ this.writable = !0, this.emitReserved("drain");
738
+ }, this.setTimeoutFn);
739
+ });
740
+ }
741
+ }
742
+ doClose() {
743
+ var e;
744
+ (e = this._transport) === null || e === void 0 || e.close();
745
+ }
746
+ }
747
+ const De = {
748
+ websocket: Pe,
749
+ webtransport: qe,
750
+ polling: Ne
751
+ }, Ie = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, Ue = [
752
+ "source",
753
+ "protocol",
754
+ "authority",
755
+ "userInfo",
756
+ "user",
757
+ "password",
758
+ "host",
759
+ "port",
760
+ "relative",
761
+ "path",
762
+ "directory",
763
+ "file",
764
+ "query",
765
+ "anchor"
766
+ ];
767
+ function q(i) {
768
+ if (i.length > 8e3)
769
+ throw "URI too long";
770
+ const e = i, t = i.indexOf("["), s = i.indexOf("]");
771
+ t != -1 && s != -1 && (i = i.substring(0, t) + i.substring(t, s).replace(/:/g, ";") + i.substring(s, i.length));
772
+ let n = Ie.exec(i || ""), r = {}, o = 14;
773
+ for (; o--; )
774
+ r[Ue[o]] = n[o] || "";
775
+ return t != -1 && s != -1 && (r.source = e, r.host = r.host.substring(1, r.host.length - 1).replace(/;/g, ":"), r.authority = r.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), r.ipv6uri = !0), r.pathNames = Fe(r, r.path), r.queryKey = Ve(r, r.query), r;
776
+ }
777
+ function Fe(i, e) {
778
+ const t = /\/{2,9}/g, s = e.replace(t, "/").split("/");
779
+ return (e.slice(0, 1) == "/" || e.length === 0) && s.splice(0, 1), e.slice(-1) == "/" && s.splice(s.length - 1, 1), s;
780
+ }
781
+ function Ve(i, e) {
782
+ const t = {};
783
+ return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(s, n, r) {
784
+ n && (t[n] = r);
785
+ }), t;
786
+ }
787
+ const D = typeof addEventListener == "function" && typeof removeEventListener == "function", R = [];
788
+ D && addEventListener("offline", () => {
789
+ R.forEach((i) => i());
790
+ }, !1);
791
+ class _ extends u {
792
+ /**
793
+ * Socket constructor.
794
+ *
795
+ * @param {String|Object} uri - uri or options
796
+ * @param {Object} opts - options
797
+ */
798
+ constructor(e, t) {
799
+ if (super(), this.binaryType = be, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = 1 / 0, e && typeof e == "object" && (t = e, e = null), e) {
800
+ const s = q(e);
801
+ t.hostname = s.host, t.secure = s.protocol === "https" || s.protocol === "wss", t.port = s.port, s.query && (t.query = s.query);
802
+ } else t.host && (t.hostname = q(t.host).host);
803
+ S(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((s) => {
804
+ const n = s.prototype.name;
805
+ this.transports.push(n), this._transportsByName[n] = s;
806
+ }), this.opts = Object.assign({
807
+ path: "/engine.io",
808
+ agent: !1,
809
+ withCredentials: !1,
810
+ upgrade: !0,
811
+ timestampParam: "t",
812
+ rememberUpgrade: !1,
813
+ addTrailingSlash: !0,
814
+ rejectUnauthorized: !0,
815
+ perMessageDeflate: {
816
+ threshold: 1024
817
+ },
818
+ transportOptions: {},
819
+ closeOnBeforeunload: !1
820
+ }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Re(this.opts.query)), D && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
821
+ this.transport && (this.transport.removeAllListeners(), this.transport.close());
822
+ }, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
823
+ this._onClose("transport close", {
824
+ description: "network connection lost"
825
+ });
826
+ }, R.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
827
+ }
828
+ /**
829
+ * Creates transport of the given type.
830
+ *
831
+ * @param {String} name - transport name
832
+ * @return {Transport}
833
+ * @private
834
+ */
835
+ createTransport(e) {
836
+ const t = Object.assign({}, this.opts.query);
837
+ t.EIO = te, t.transport = e, this.id && (t.sid = this.id);
838
+ const s = Object.assign({}, this.opts, {
839
+ query: t,
840
+ socket: this,
841
+ hostname: this.hostname,
842
+ secure: this.secure,
843
+ port: this.port
844
+ }, this.opts.transportOptions[e]);
845
+ return new this._transportsByName[e](s);
846
+ }
847
+ /**
848
+ * Initializes transport to use and starts probe.
849
+ *
850
+ * @private
851
+ */
852
+ _open() {
853
+ if (this.transports.length === 0) {
854
+ this.setTimeoutFn(() => {
855
+ this.emitReserved("error", "No transports available");
856
+ }, 0);
857
+ return;
858
+ }
859
+ const e = this.opts.rememberUpgrade && _.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
860
+ this.readyState = "opening";
861
+ const t = this.createTransport(e);
862
+ t.open(), this.setTransport(t);
863
+ }
864
+ /**
865
+ * Sets the current transport. Disables the existing one (if any).
866
+ *
867
+ * @private
868
+ */
869
+ setTransport(e) {
870
+ 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", (t) => this._onClose("transport close", t));
871
+ }
872
+ /**
873
+ * Called when connection is deemed open.
874
+ *
875
+ * @private
876
+ */
877
+ onOpen() {
878
+ this.readyState = "open", _.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
879
+ }
880
+ /**
881
+ * Handles a packet.
882
+ *
883
+ * @private
884
+ */
885
+ _onPacket(e) {
886
+ if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing")
887
+ switch (this.emitReserved("packet", e), this.emitReserved("heartbeat"), e.type) {
888
+ case "open":
889
+ this.onHandshake(JSON.parse(e.data));
890
+ break;
891
+ case "ping":
892
+ this._sendPacket("pong"), this.emitReserved("ping"), this.emitReserved("pong"), this._resetPingTimeout();
893
+ break;
894
+ case "error":
895
+ const t = new Error("server error");
896
+ t.code = e.data, this._onError(t);
897
+ break;
898
+ case "message":
899
+ this.emitReserved("data", e.data), this.emitReserved("message", e.data);
900
+ break;
901
+ }
902
+ }
903
+ /**
904
+ * Called upon handshake completion.
905
+ *
906
+ * @param {Object} data - handshake obj
907
+ * @private
908
+ */
909
+ onHandshake(e) {
910
+ this.emitReserved("handshake", e), this.id = e.sid, this.transport.query.sid = e.sid, this._pingInterval = e.pingInterval, this._pingTimeout = e.pingTimeout, this._maxPayload = e.maxPayload, this.onOpen(), this.readyState !== "closed" && this._resetPingTimeout();
911
+ }
912
+ /**
913
+ * Sets and resets ping timeout timer based on server pings.
914
+ *
915
+ * @private
916
+ */
917
+ _resetPingTimeout() {
918
+ this.clearTimeoutFn(this._pingTimeoutTimer);
919
+ const e = this._pingInterval + this._pingTimeout;
920
+ this._pingTimeoutTime = Date.now() + e, this._pingTimeoutTimer = this.setTimeoutFn(() => {
921
+ this._onClose("ping timeout");
922
+ }, e), this.opts.autoUnref && this._pingTimeoutTimer.unref();
923
+ }
924
+ /**
925
+ * Called on `drain` event
926
+ *
927
+ * @private
928
+ */
929
+ _onDrain() {
930
+ this.writeBuffer.splice(0, this._prevBufferLen), this._prevBufferLen = 0, this.writeBuffer.length === 0 ? this.emitReserved("drain") : this.flush();
931
+ }
932
+ /**
933
+ * Flush write buffers.
934
+ *
935
+ * @private
936
+ */
937
+ flush() {
938
+ if (this.readyState !== "closed" && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
939
+ const e = this._getWritablePackets();
940
+ this.transport.send(e), this._prevBufferLen = e.length, this.emitReserved("flush");
941
+ }
942
+ }
943
+ /**
944
+ * Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
945
+ * long-polling)
946
+ *
947
+ * @private
948
+ */
949
+ _getWritablePackets() {
950
+ if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1))
951
+ return this.writeBuffer;
952
+ let t = 1;
953
+ for (let s = 0; s < this.writeBuffer.length; s++) {
954
+ const n = this.writeBuffer[s].data;
955
+ if (n && (t += ke(n)), s > 0 && t > this._maxPayload)
956
+ return this.writeBuffer.slice(0, s);
957
+ t += 2;
958
+ }
959
+ return this.writeBuffer;
960
+ }
961
+ /**
962
+ * Checks whether the heartbeat timer has expired but the socket has not yet been notified.
963
+ *
964
+ * Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
965
+ * `write()` method then the message would not be buffered by the Socket.IO client.
966
+ *
967
+ * @return {boolean}
968
+ * @private
969
+ */
970
+ /* private */
971
+ _hasPingExpired() {
972
+ if (!this._pingTimeoutTime)
973
+ return !0;
974
+ const e = Date.now() > this._pingTimeoutTime;
975
+ return e && (this._pingTimeoutTime = 0, C(() => {
976
+ this._onClose("ping timeout");
977
+ }, this.setTimeoutFn)), e;
978
+ }
979
+ /**
980
+ * Sends a message.
981
+ *
982
+ * @param {String} msg - message.
983
+ * @param {Object} options.
984
+ * @param {Function} fn - callback function.
985
+ * @return {Socket} for chaining.
986
+ */
987
+ write(e, t, s) {
988
+ return this._sendPacket("message", e, t, s), this;
989
+ }
990
+ /**
991
+ * Sends a message. Alias of {@link Socket#write}.
992
+ *
993
+ * @param {String} msg - message.
994
+ * @param {Object} options.
995
+ * @param {Function} fn - callback function.
996
+ * @return {Socket} for chaining.
997
+ */
998
+ send(e, t, s) {
999
+ return this._sendPacket("message", e, t, s), this;
1000
+ }
1001
+ /**
1002
+ * Sends a packet.
1003
+ *
1004
+ * @param {String} type: packet type.
1005
+ * @param {String} data.
1006
+ * @param {Object} options.
1007
+ * @param {Function} fn - callback function.
1008
+ * @private
1009
+ */
1010
+ _sendPacket(e, t, s, n) {
1011
+ if (typeof t == "function" && (n = t, t = void 0), typeof s == "function" && (n = s, s = null), this.readyState === "closing" || this.readyState === "closed")
1012
+ return;
1013
+ s = s || {}, s.compress = s.compress !== !1;
1014
+ const r = {
1015
+ type: e,
1016
+ data: t,
1017
+ options: s
1018
+ };
1019
+ this.emitReserved("packetCreate", r), this.writeBuffer.push(r), n && this.once("flush", n), this.flush();
1020
+ }
1021
+ /**
1022
+ * Closes the connection.
1023
+ */
1024
+ close() {
1025
+ const e = () => {
1026
+ this._onClose("forced close"), this.transport.close();
1027
+ }, t = () => {
1028
+ this.off("upgrade", t), this.off("upgradeError", t), e();
1029
+ }, s = () => {
1030
+ this.once("upgrade", t), this.once("upgradeError", t);
1031
+ };
1032
+ return (this.readyState === "opening" || this.readyState === "open") && (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
1033
+ this.upgrading ? s() : e();
1034
+ }) : this.upgrading ? s() : e()), this;
1035
+ }
1036
+ /**
1037
+ * Called upon transport error
1038
+ *
1039
+ * @private
1040
+ */
1041
+ _onError(e) {
1042
+ if (_.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening")
1043
+ return this.transports.shift(), this._open();
1044
+ this.emitReserved("error", e), this._onClose("transport error", e);
1045
+ }
1046
+ /**
1047
+ * Called upon transport close.
1048
+ *
1049
+ * @private
1050
+ */
1051
+ _onClose(e, t) {
1052
+ if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
1053
+ if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), D && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
1054
+ const s = R.indexOf(this._offlineEventListener);
1055
+ s !== -1 && R.splice(s, 1);
1056
+ }
1057
+ this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
1058
+ }
1059
+ }
1060
+ }
1061
+ _.protocol = te;
1062
+ class Me extends _ {
1063
+ constructor() {
1064
+ super(...arguments), this._upgrades = [];
1065
+ }
1066
+ onOpen() {
1067
+ if (super.onOpen(), this.readyState === "open" && this.opts.upgrade)
1068
+ for (let e = 0; e < this._upgrades.length; e++)
1069
+ this._probe(this._upgrades[e]);
1070
+ }
1071
+ /**
1072
+ * Probes a transport.
1073
+ *
1074
+ * @param {String} name - transport name
1075
+ * @private
1076
+ */
1077
+ _probe(e) {
1078
+ let t = this.createTransport(e), s = !1;
1079
+ _.priorWebsocketSuccess = !1;
1080
+ const n = () => {
1081
+ s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (m) => {
1082
+ if (!s)
1083
+ if (m.type === "pong" && m.data === "probe") {
1084
+ if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
1085
+ return;
1086
+ _.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1087
+ s || this.readyState !== "closed" && (f(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
1088
+ });
1089
+ } else {
1090
+ const w = new Error("probe error");
1091
+ w.transport = t.name, this.emitReserved("upgradeError", w);
1092
+ }
1093
+ }));
1094
+ };
1095
+ function r() {
1096
+ s || (s = !0, f(), t.close(), t = null);
1097
+ }
1098
+ const o = (m) => {
1099
+ const w = new Error("probe error: " + m);
1100
+ w.transport = t.name, r(), this.emitReserved("upgradeError", w);
1101
+ };
1102
+ function c() {
1103
+ o("transport closed");
1104
+ }
1105
+ function h() {
1106
+ o("socket closed");
1107
+ }
1108
+ function g(m) {
1109
+ t && m.name !== t.name && r();
1110
+ }
1111
+ const f = () => {
1112
+ t.removeListener("open", n), t.removeListener("error", o), t.removeListener("close", c), this.off("close", h), this.off("upgrading", g);
1113
+ };
1114
+ t.once("open", n), t.once("error", o), t.once("close", c), this.once("close", h), this.once("upgrading", g), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
1115
+ s || t.open();
1116
+ }, 200) : t.open();
1117
+ }
1118
+ onHandshake(e) {
1119
+ this._upgrades = this._filterUpgrades(e.upgrades), super.onHandshake(e);
1120
+ }
1121
+ /**
1122
+ * Filters upgrades, returning only those matching client transports.
1123
+ *
1124
+ * @param {Array} upgrades - server upgrades
1125
+ * @private
1126
+ */
1127
+ _filterUpgrades(e) {
1128
+ const t = [];
1129
+ for (let s = 0; s < e.length; s++)
1130
+ ~this.transports.indexOf(e[s]) && t.push(e[s]);
1131
+ return t;
1132
+ }
1133
+ }
1134
+ let He = class extends Me {
1135
+ constructor(e, t = {}) {
1136
+ const s = typeof e == "object" ? e : t;
1137
+ (!s.transports || s.transports && typeof s.transports[0] == "string") && (s.transports = (s.transports || ["polling", "websocket", "webtransport"]).map((n) => De[n]).filter((n) => !!n)), super(e, s);
1138
+ }
1139
+ };
1140
+ class it extends ne {
1141
+ doPoll() {
1142
+ this._fetch().then((e) => {
1143
+ if (!e.ok)
1144
+ return this.onError("fetch read error", e.status, e);
1145
+ e.text().then((t) => this.onData(t));
1146
+ }).catch((e) => {
1147
+ this.onError("fetch read error", e);
1148
+ });
1149
+ }
1150
+ doWrite(e, t) {
1151
+ this._fetch(e).then((s) => {
1152
+ if (!s.ok)
1153
+ return this.onError("fetch write error", s.status, s);
1154
+ t();
1155
+ }).catch((s) => {
1156
+ this.onError("fetch write error", s);
1157
+ });
1158
+ }
1159
+ _fetch(e) {
1160
+ var t;
1161
+ const s = e !== void 0, n = new Headers(this.opts.extraHeaders);
1162
+ return s && n.set("content-type", "text/plain;charset=UTF-8"), (t = this.socket._cookieJar) === null || t === void 0 || t.appendCookies(n), fetch(this.uri(), {
1163
+ method: s ? "POST" : "GET",
1164
+ body: s ? e : null,
1165
+ headers: n,
1166
+ credentials: this.opts.withCredentials ? "include" : "omit"
1167
+ }).then((r) => {
1168
+ var o;
1169
+ return (o = this.socket._cookieJar) === null || o === void 0 || o.parseCookies(r.headers.getSetCookie()), r;
1170
+ });
1171
+ }
1172
+ }
1173
+ function We(i, e = "", t) {
1174
+ let s = i;
1175
+ t = t || typeof location < "u" && location, i == null && (i = t.protocol + "//" + t.host), typeof i == "string" && (i.charAt(0) === "/" && (i.charAt(1) === "/" ? i = t.protocol + i : i = t.host + i), /^(https?|wss?):\/\//.test(i) || (typeof t < "u" ? i = t.protocol + "//" + i : i = "https://" + i), s = q(i)), s.port || (/^(http|ws)$/.test(s.protocol) ? s.port = "80" : /^(http|ws)s$/.test(s.protocol) && (s.port = "443")), s.path = s.path || "/";
1176
+ const r = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
1177
+ return s.id = s.protocol + "://" + r + ":" + s.port + e, s.href = s.protocol + "://" + r + (t && t.port === s.port ? "" : ":" + s.port), s;
1178
+ }
1179
+ const Ke = typeof ArrayBuffer == "function", $e = (i) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(i) : i.buffer instanceof ArrayBuffer, ce = Object.prototype.toString, Ye = typeof Blob == "function" || typeof Blob < "u" && ce.call(Blob) === "[object BlobConstructor]", ze = typeof File == "function" || typeof File < "u" && ce.call(File) === "[object FileConstructor]";
1180
+ function W(i) {
1181
+ return Ke && (i instanceof ArrayBuffer || $e(i)) || Ye && i instanceof Blob || ze && i instanceof File;
1182
+ }
1183
+ function O(i, e) {
1184
+ if (!i || typeof i != "object")
1185
+ return !1;
1186
+ if (Array.isArray(i)) {
1187
+ for (let t = 0, s = i.length; t < s; t++)
1188
+ if (O(i[t]))
1189
+ return !0;
1190
+ return !1;
1191
+ }
1192
+ if (W(i))
1193
+ return !0;
1194
+ if (i.toJSON && typeof i.toJSON == "function" && arguments.length === 1)
1195
+ return O(i.toJSON(), !0);
1196
+ for (const t in i)
1197
+ if (Object.prototype.hasOwnProperty.call(i, t) && O(i[t]))
1198
+ return !0;
1199
+ return !1;
1200
+ }
1201
+ function Je(i) {
1202
+ const e = [], t = i.data, s = i;
1203
+ return s.data = I(t, e), s.attachments = e.length, { packet: s, buffers: e };
1204
+ }
1205
+ function I(i, e) {
1206
+ if (!i)
1207
+ return i;
1208
+ if (W(i)) {
1209
+ const t = { _placeholder: !0, num: e.length };
1210
+ return e.push(i), t;
1211
+ } else if (Array.isArray(i)) {
1212
+ const t = new Array(i.length);
1213
+ for (let s = 0; s < i.length; s++)
1214
+ t[s] = I(i[s], e);
1215
+ return t;
1216
+ } else if (typeof i == "object" && !(i instanceof Date)) {
1217
+ const t = {};
1218
+ for (const s in i)
1219
+ Object.prototype.hasOwnProperty.call(i, s) && (t[s] = I(i[s], e));
1220
+ return t;
1221
+ }
1222
+ return i;
1223
+ }
1224
+ function Xe(i, e) {
1225
+ return i.data = U(i.data, e), delete i.attachments, i;
1226
+ }
1227
+ function U(i, e) {
1228
+ if (!i)
1229
+ return i;
1230
+ if (i && i._placeholder === !0) {
1231
+ if (typeof i.num == "number" && i.num >= 0 && i.num < e.length)
1232
+ return e[i.num];
1233
+ throw new Error("illegal attachments");
1234
+ } else if (Array.isArray(i))
1235
+ for (let t = 0; t < i.length; t++)
1236
+ i[t] = U(i[t], e);
1237
+ else if (typeof i == "object")
1238
+ for (const t in i)
1239
+ Object.prototype.hasOwnProperty.call(i, t) && (i[t] = U(i[t], e));
1240
+ return i;
1241
+ }
1242
+ const Qe = [
1243
+ "connect",
1244
+ "connect_error",
1245
+ "disconnect",
1246
+ "disconnecting",
1247
+ "newListener",
1248
+ "removeListener"
1249
+ // used by the Node.js EventEmitter
1250
+ ], Ge = 5;
1251
+ var a;
1252
+ (function(i) {
1253
+ i[i.CONNECT = 0] = "CONNECT", i[i.DISCONNECT = 1] = "DISCONNECT", i[i.EVENT = 2] = "EVENT", i[i.ACK = 3] = "ACK", i[i.CONNECT_ERROR = 4] = "CONNECT_ERROR", i[i.BINARY_EVENT = 5] = "BINARY_EVENT", i[i.BINARY_ACK = 6] = "BINARY_ACK";
1254
+ })(a || (a = {}));
1255
+ class je {
1256
+ /**
1257
+ * Encoder constructor
1258
+ *
1259
+ * @param {function} replacer - custom replacer to pass down to JSON.parse
1260
+ */
1261
+ constructor(e) {
1262
+ this.replacer = e;
1263
+ }
1264
+ /**
1265
+ * Encode a packet as a single string if non-binary, or as a
1266
+ * buffer sequence, depending on packet type.
1267
+ *
1268
+ * @param {Object} obj - packet object
1269
+ */
1270
+ encode(e) {
1271
+ return (e.type === a.EVENT || e.type === a.ACK) && O(e) ? this.encodeAsBinary({
1272
+ type: e.type === a.EVENT ? a.BINARY_EVENT : a.BINARY_ACK,
1273
+ nsp: e.nsp,
1274
+ data: e.data,
1275
+ id: e.id
1276
+ }) : [this.encodeAsString(e)];
1277
+ }
1278
+ /**
1279
+ * Encode packet as string.
1280
+ */
1281
+ encodeAsString(e) {
1282
+ let t = "" + e.type;
1283
+ return (e.type === a.BINARY_EVENT || e.type === a.BINARY_ACK) && (t += e.attachments + "-"), e.nsp && e.nsp !== "/" && (t += e.nsp + ","), e.id != null && (t += e.id), e.data != null && (t += JSON.stringify(e.data, this.replacer)), t;
1284
+ }
1285
+ /**
1286
+ * Encode packet as 'buffer sequence' by removing blobs, and
1287
+ * deconstructing packet into object with placeholders and
1288
+ * a list of buffers.
1289
+ */
1290
+ encodeAsBinary(e) {
1291
+ const t = Je(e), s = this.encodeAsString(t.packet), n = t.buffers;
1292
+ return n.unshift(s), n;
1293
+ }
1294
+ }
1295
+ function X(i) {
1296
+ return Object.prototype.toString.call(i) === "[object Object]";
1297
+ }
1298
+ class K extends u {
1299
+ /**
1300
+ * Decoder constructor
1301
+ *
1302
+ * @param {function} reviver - custom reviver to pass down to JSON.stringify
1303
+ */
1304
+ constructor(e) {
1305
+ super(), this.reviver = e;
1306
+ }
1307
+ /**
1308
+ * Decodes an encoded packet string into packet JSON.
1309
+ *
1310
+ * @param {String} obj - encoded packet
1311
+ */
1312
+ add(e) {
1313
+ let t;
1314
+ if (typeof e == "string") {
1315
+ if (this.reconstructor)
1316
+ throw new Error("got plaintext data when reconstructing a packet");
1317
+ t = this.decodeString(e);
1318
+ const s = t.type === a.BINARY_EVENT;
1319
+ s || t.type === a.BINARY_ACK ? (t.type = s ? a.EVENT : a.ACK, this.reconstructor = new Ze(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
1320
+ } else if (W(e) || e.base64)
1321
+ if (this.reconstructor)
1322
+ t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
1323
+ else
1324
+ throw new Error("got binary data when not reconstructing a packet");
1325
+ else
1326
+ throw new Error("Unknown type: " + e);
1327
+ }
1328
+ /**
1329
+ * Decode a packet String (JSON data)
1330
+ *
1331
+ * @param {String} str
1332
+ * @return {Object} packet
1333
+ */
1334
+ decodeString(e) {
1335
+ let t = 0;
1336
+ const s = {
1337
+ type: Number(e.charAt(0))
1338
+ };
1339
+ if (a[s.type] === void 0)
1340
+ throw new Error("unknown packet type " + s.type);
1341
+ if (s.type === a.BINARY_EVENT || s.type === a.BINARY_ACK) {
1342
+ const r = t + 1;
1343
+ for (; e.charAt(++t) !== "-" && t != e.length; )
1344
+ ;
1345
+ const o = e.substring(r, t);
1346
+ if (o != Number(o) || e.charAt(t) !== "-")
1347
+ throw new Error("Illegal attachments");
1348
+ s.attachments = Number(o);
1349
+ }
1350
+ if (e.charAt(t + 1) === "/") {
1351
+ const r = t + 1;
1352
+ for (; ++t && !(e.charAt(t) === "," || t === e.length); )
1353
+ ;
1354
+ s.nsp = e.substring(r, t);
1355
+ } else
1356
+ s.nsp = "/";
1357
+ const n = e.charAt(t + 1);
1358
+ if (n !== "" && Number(n) == n) {
1359
+ const r = t + 1;
1360
+ for (; ++t; ) {
1361
+ const o = e.charAt(t);
1362
+ if (o == null || Number(o) != o) {
1363
+ --t;
1364
+ break;
1365
+ }
1366
+ if (t === e.length)
1367
+ break;
1368
+ }
1369
+ s.id = Number(e.substring(r, t + 1));
1370
+ }
1371
+ if (e.charAt(++t)) {
1372
+ const r = this.tryParse(e.substr(t));
1373
+ if (K.isPayloadValid(s.type, r))
1374
+ s.data = r;
1375
+ else
1376
+ throw new Error("invalid payload");
1377
+ }
1378
+ return s;
1379
+ }
1380
+ tryParse(e) {
1381
+ try {
1382
+ return JSON.parse(e, this.reviver);
1383
+ } catch {
1384
+ return !1;
1385
+ }
1386
+ }
1387
+ static isPayloadValid(e, t) {
1388
+ switch (e) {
1389
+ case a.CONNECT:
1390
+ return X(t);
1391
+ case a.DISCONNECT:
1392
+ return t === void 0;
1393
+ case a.CONNECT_ERROR:
1394
+ return typeof t == "string" || X(t);
1395
+ case a.EVENT:
1396
+ case a.BINARY_EVENT:
1397
+ return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && Qe.indexOf(t[0]) === -1);
1398
+ case a.ACK:
1399
+ case a.BINARY_ACK:
1400
+ return Array.isArray(t);
1401
+ }
1402
+ }
1403
+ /**
1404
+ * Deallocates a parser's resources
1405
+ */
1406
+ destroy() {
1407
+ this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
1408
+ }
1409
+ }
1410
+ class Ze {
1411
+ constructor(e) {
1412
+ this.packet = e, this.buffers = [], this.reconPack = e;
1413
+ }
1414
+ /**
1415
+ * Method to be called when binary data received from connection
1416
+ * after a BINARY_EVENT packet.
1417
+ *
1418
+ * @param {Buffer | ArrayBuffer} binData - the raw binary data received
1419
+ * @return {null | Object} returns null if more binary data is expected or
1420
+ * a reconstructed packet object if all buffers have been received.
1421
+ */
1422
+ takeBinaryData(e) {
1423
+ if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
1424
+ const t = Xe(this.reconPack, this.buffers);
1425
+ return this.finishedReconstruction(), t;
1426
+ }
1427
+ return null;
1428
+ }
1429
+ /**
1430
+ * Cleans up binary packet reconstruction variables.
1431
+ */
1432
+ finishedReconstruction() {
1433
+ this.reconPack = null, this.buffers = [];
1434
+ }
1435
+ }
1436
+ const et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1437
+ __proto__: null,
1438
+ Decoder: K,
1439
+ Encoder: je,
1440
+ get PacketType() {
1441
+ return a;
1442
+ },
1443
+ protocol: Ge
1444
+ }, Symbol.toStringTag, { value: "Module" }));
1445
+ function p(i, e, t) {
1446
+ return i.on(e, t), function() {
1447
+ i.off(e, t);
1448
+ };
1449
+ }
1450
+ const tt = Object.freeze({
1451
+ connect: 1,
1452
+ connect_error: 1,
1453
+ disconnect: 1,
1454
+ disconnecting: 1,
1455
+ // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
1456
+ newListener: 1,
1457
+ removeListener: 1
1458
+ });
1459
+ class he extends u {
1460
+ /**
1461
+ * `Socket` constructor.
1462
+ */
1463
+ constructor(e, t, s) {
1464
+ super(), this.connected = !1, this.recovered = !1, this.receiveBuffer = [], this.sendBuffer = [], this._queue = [], this._queueSeq = 0, this.ids = 0, this.acks = {}, this.flags = {}, this.io = e, this.nsp = t, s && s.auth && (this.auth = s.auth), this._opts = Object.assign({}, s), this.io._autoConnect && this.open();
1465
+ }
1466
+ /**
1467
+ * Whether the socket is currently disconnected
1468
+ *
1469
+ * @example
1470
+ * const socket = io();
1471
+ *
1472
+ * socket.on("connect", () => {
1473
+ * console.log(socket.disconnected); // false
1474
+ * });
1475
+ *
1476
+ * socket.on("disconnect", () => {
1477
+ * console.log(socket.disconnected); // true
1478
+ * });
1479
+ */
1480
+ get disconnected() {
1481
+ return !this.connected;
1482
+ }
1483
+ /**
1484
+ * Subscribe to open, close and packet events
1485
+ *
1486
+ * @private
1487
+ */
1488
+ subEvents() {
1489
+ if (this.subs)
1490
+ return;
1491
+ const e = this.io;
1492
+ this.subs = [
1493
+ p(e, "open", this.onopen.bind(this)),
1494
+ p(e, "packet", this.onpacket.bind(this)),
1495
+ p(e, "error", this.onerror.bind(this)),
1496
+ p(e, "close", this.onclose.bind(this))
1497
+ ];
1498
+ }
1499
+ /**
1500
+ * Whether the Socket will try to reconnect when its Manager connects or reconnects.
1501
+ *
1502
+ * @example
1503
+ * const socket = io();
1504
+ *
1505
+ * console.log(socket.active); // true
1506
+ *
1507
+ * socket.on("disconnect", (reason) => {
1508
+ * if (reason === "io server disconnect") {
1509
+ * // the disconnection was initiated by the server, you need to manually reconnect
1510
+ * console.log(socket.active); // false
1511
+ * }
1512
+ * // else the socket will automatically try to reconnect
1513
+ * console.log(socket.active); // true
1514
+ * });
1515
+ */
1516
+ get active() {
1517
+ return !!this.subs;
1518
+ }
1519
+ /**
1520
+ * "Opens" the socket.
1521
+ *
1522
+ * @example
1523
+ * const socket = io({
1524
+ * autoConnect: false
1525
+ * });
1526
+ *
1527
+ * socket.connect();
1528
+ */
1529
+ connect() {
1530
+ return this.connected ? this : (this.subEvents(), this.io._reconnecting || this.io.open(), this.io._readyState === "open" && this.onopen(), this);
1531
+ }
1532
+ /**
1533
+ * Alias for {@link connect()}.
1534
+ */
1535
+ open() {
1536
+ return this.connect();
1537
+ }
1538
+ /**
1539
+ * Sends a `message` event.
1540
+ *
1541
+ * This method mimics the WebSocket.send() method.
1542
+ *
1543
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
1544
+ *
1545
+ * @example
1546
+ * socket.send("hello");
1547
+ *
1548
+ * // this is equivalent to
1549
+ * socket.emit("message", "hello");
1550
+ *
1551
+ * @return self
1552
+ */
1553
+ send(...e) {
1554
+ return e.unshift("message"), this.emit.apply(this, e), this;
1555
+ }
1556
+ /**
1557
+ * Override `emit`.
1558
+ * If the event is in `events`, it's emitted normally.
1559
+ *
1560
+ * @example
1561
+ * socket.emit("hello", "world");
1562
+ *
1563
+ * // all serializable datastructures are supported (no need to call JSON.stringify)
1564
+ * socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
1565
+ *
1566
+ * // with an acknowledgement from the server
1567
+ * socket.emit("hello", "world", (val) => {
1568
+ * // ...
1569
+ * });
1570
+ *
1571
+ * @return self
1572
+ */
1573
+ emit(e, ...t) {
1574
+ var s, n, r;
1575
+ if (tt.hasOwnProperty(e))
1576
+ throw new Error('"' + e.toString() + '" is a reserved event name');
1577
+ if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile)
1578
+ return this._addToQueue(t), this;
1579
+ const o = {
1580
+ type: a.EVENT,
1581
+ data: t
1582
+ };
1583
+ if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
1584
+ const f = this.ids++, m = t.pop();
1585
+ this._registerAckCallback(f, m), o.id = f;
1586
+ }
1587
+ const c = (n = (s = this.io.engine) === null || s === void 0 ? void 0 : s.transport) === null || n === void 0 ? void 0 : n.writable, h = this.connected && !(!((r = this.io.engine) === null || r === void 0) && r._hasPingExpired());
1588
+ return this.flags.volatile && !c || (h ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
1589
+ }
1590
+ /**
1591
+ * @private
1592
+ */
1593
+ _registerAckCallback(e, t) {
1594
+ var s;
1595
+ const n = (s = this.flags.timeout) !== null && s !== void 0 ? s : this._opts.ackTimeout;
1596
+ if (n === void 0) {
1597
+ this.acks[e] = t;
1598
+ return;
1599
+ }
1600
+ const r = this.io.setTimeoutFn(() => {
1601
+ delete this.acks[e];
1602
+ for (let c = 0; c < this.sendBuffer.length; c++)
1603
+ this.sendBuffer[c].id === e && this.sendBuffer.splice(c, 1);
1604
+ t.call(this, new Error("operation has timed out"));
1605
+ }, n), o = (...c) => {
1606
+ this.io.clearTimeoutFn(r), t.apply(this, c);
1607
+ };
1608
+ o.withError = !0, this.acks[e] = o;
1609
+ }
1610
+ /**
1611
+ * Emits an event and waits for an acknowledgement
1612
+ *
1613
+ * @example
1614
+ * // without timeout
1615
+ * const response = await socket.emitWithAck("hello", "world");
1616
+ *
1617
+ * // with a specific timeout
1618
+ * try {
1619
+ * const response = await socket.timeout(1000).emitWithAck("hello", "world");
1620
+ * } catch (err) {
1621
+ * // the server did not acknowledge the event in the given delay
1622
+ * }
1623
+ *
1624
+ * @return a Promise that will be fulfilled when the server acknowledges the event
1625
+ */
1626
+ emitWithAck(e, ...t) {
1627
+ return new Promise((s, n) => {
1628
+ const r = (o, c) => o ? n(o) : s(c);
1629
+ r.withError = !0, t.push(r), this.emit(e, ...t);
1630
+ });
1631
+ }
1632
+ /**
1633
+ * Add the packet to the queue.
1634
+ * @param args
1635
+ * @private
1636
+ */
1637
+ _addToQueue(e) {
1638
+ let t;
1639
+ typeof e[e.length - 1] == "function" && (t = e.pop());
1640
+ const s = {
1641
+ id: this._queueSeq++,
1642
+ tryCount: 0,
1643
+ pending: !1,
1644
+ args: e,
1645
+ flags: Object.assign({ fromQueue: !0 }, this.flags)
1646
+ };
1647
+ e.push((n, ...r) => s !== this._queue[0] ? void 0 : (n !== null ? s.tryCount > this._opts.retries && (this._queue.shift(), t && t(n)) : (this._queue.shift(), t && t(null, ...r)), s.pending = !1, this._drainQueue())), this._queue.push(s), this._drainQueue();
1648
+ }
1649
+ /**
1650
+ * Send the first packet of the queue, and wait for an acknowledgement from the server.
1651
+ * @param force - whether to resend a packet that has not been acknowledged yet
1652
+ *
1653
+ * @private
1654
+ */
1655
+ _drainQueue(e = !1) {
1656
+ if (!this.connected || this._queue.length === 0)
1657
+ return;
1658
+ const t = this._queue[0];
1659
+ t.pending && !e || (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
1660
+ }
1661
+ /**
1662
+ * Sends a packet.
1663
+ *
1664
+ * @param packet
1665
+ * @private
1666
+ */
1667
+ packet(e) {
1668
+ e.nsp = this.nsp, this.io._packet(e);
1669
+ }
1670
+ /**
1671
+ * Called upon engine `open`.
1672
+ *
1673
+ * @private
1674
+ */
1675
+ onopen() {
1676
+ typeof this.auth == "function" ? this.auth((e) => {
1677
+ this._sendConnectPacket(e);
1678
+ }) : this._sendConnectPacket(this.auth);
1679
+ }
1680
+ /**
1681
+ * Sends a CONNECT packet to initiate the Socket.IO session.
1682
+ *
1683
+ * @param data
1684
+ * @private
1685
+ */
1686
+ _sendConnectPacket(e) {
1687
+ this.packet({
1688
+ type: a.CONNECT,
1689
+ data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, e) : e
1690
+ });
1691
+ }
1692
+ /**
1693
+ * Called upon engine or manager `error`.
1694
+ *
1695
+ * @param err
1696
+ * @private
1697
+ */
1698
+ onerror(e) {
1699
+ this.connected || this.emitReserved("connect_error", e);
1700
+ }
1701
+ /**
1702
+ * Called upon engine `close`.
1703
+ *
1704
+ * @param reason
1705
+ * @param description
1706
+ * @private
1707
+ */
1708
+ onclose(e, t) {
1709
+ this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
1710
+ }
1711
+ /**
1712
+ * Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
1713
+ * the server.
1714
+ *
1715
+ * @private
1716
+ */
1717
+ _clearAcks() {
1718
+ Object.keys(this.acks).forEach((e) => {
1719
+ if (!this.sendBuffer.some((s) => String(s.id) === e)) {
1720
+ const s = this.acks[e];
1721
+ delete this.acks[e], s.withError && s.call(this, new Error("socket has been disconnected"));
1722
+ }
1723
+ });
1724
+ }
1725
+ /**
1726
+ * Called with socket packet.
1727
+ *
1728
+ * @param packet
1729
+ * @private
1730
+ */
1731
+ onpacket(e) {
1732
+ if (e.nsp === this.nsp)
1733
+ switch (e.type) {
1734
+ case a.CONNECT:
1735
+ e.data && e.data.sid ? this.onconnect(e.data.sid, e.data.pid) : 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/)"));
1736
+ break;
1737
+ case a.EVENT:
1738
+ case a.BINARY_EVENT:
1739
+ this.onevent(e);
1740
+ break;
1741
+ case a.ACK:
1742
+ case a.BINARY_ACK:
1743
+ this.onack(e);
1744
+ break;
1745
+ case a.DISCONNECT:
1746
+ this.ondisconnect();
1747
+ break;
1748
+ case a.CONNECT_ERROR:
1749
+ this.destroy();
1750
+ const s = new Error(e.data.message);
1751
+ s.data = e.data.data, this.emitReserved("connect_error", s);
1752
+ break;
1753
+ }
1754
+ }
1755
+ /**
1756
+ * Called upon a server event.
1757
+ *
1758
+ * @param packet
1759
+ * @private
1760
+ */
1761
+ onevent(e) {
1762
+ const t = e.data || [];
1763
+ e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
1764
+ }
1765
+ emitEvent(e) {
1766
+ if (this._anyListeners && this._anyListeners.length) {
1767
+ const t = this._anyListeners.slice();
1768
+ for (const s of t)
1769
+ s.apply(this, e);
1770
+ }
1771
+ super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
1772
+ }
1773
+ /**
1774
+ * Produces an ack callback to emit with an event.
1775
+ *
1776
+ * @private
1777
+ */
1778
+ ack(e) {
1779
+ const t = this;
1780
+ let s = !1;
1781
+ return function(...n) {
1782
+ s || (s = !0, t.packet({
1783
+ type: a.ACK,
1784
+ id: e,
1785
+ data: n
1786
+ }));
1787
+ };
1788
+ }
1789
+ /**
1790
+ * Called upon a server acknowledgement.
1791
+ *
1792
+ * @param packet
1793
+ * @private
1794
+ */
1795
+ onack(e) {
1796
+ const t = this.acks[e.id];
1797
+ typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
1798
+ }
1799
+ /**
1800
+ * Called upon server connect.
1801
+ *
1802
+ * @private
1803
+ */
1804
+ onconnect(e, t) {
1805
+ this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this.emitReserved("connect"), this._drainQueue(!0);
1806
+ }
1807
+ /**
1808
+ * Emit buffered events (received and emitted).
1809
+ *
1810
+ * @private
1811
+ */
1812
+ emitBuffered() {
1813
+ this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
1814
+ this.notifyOutgoingListeners(e), this.packet(e);
1815
+ }), this.sendBuffer = [];
1816
+ }
1817
+ /**
1818
+ * Called upon server disconnect.
1819
+ *
1820
+ * @private
1821
+ */
1822
+ ondisconnect() {
1823
+ this.destroy(), this.onclose("io server disconnect");
1824
+ }
1825
+ /**
1826
+ * Called upon forced client/server side disconnections,
1827
+ * this method ensures the manager stops tracking us and
1828
+ * that reconnections don't get triggered for this.
1829
+ *
1830
+ * @private
1831
+ */
1832
+ destroy() {
1833
+ this.subs && (this.subs.forEach((e) => e()), this.subs = void 0), this.io._destroy(this);
1834
+ }
1835
+ /**
1836
+ * Disconnects the socket manually. In that case, the socket will not try to reconnect.
1837
+ *
1838
+ * If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
1839
+ *
1840
+ * @example
1841
+ * const socket = io();
1842
+ *
1843
+ * socket.on("disconnect", (reason) => {
1844
+ * // console.log(reason); prints "io client disconnect"
1845
+ * });
1846
+ *
1847
+ * socket.disconnect();
1848
+ *
1849
+ * @return self
1850
+ */
1851
+ disconnect() {
1852
+ return this.connected && this.packet({ type: a.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1853
+ }
1854
+ /**
1855
+ * Alias for {@link disconnect()}.
1856
+ *
1857
+ * @return self
1858
+ */
1859
+ close() {
1860
+ return this.disconnect();
1861
+ }
1862
+ /**
1863
+ * Sets the compress flag.
1864
+ *
1865
+ * @example
1866
+ * socket.compress(false).emit("hello");
1867
+ *
1868
+ * @param compress - if `true`, compresses the sending data
1869
+ * @return self
1870
+ */
1871
+ compress(e) {
1872
+ return this.flags.compress = e, this;
1873
+ }
1874
+ /**
1875
+ * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
1876
+ * ready to send messages.
1877
+ *
1878
+ * @example
1879
+ * socket.volatile.emit("hello"); // the server may or may not receive it
1880
+ *
1881
+ * @returns self
1882
+ */
1883
+ get volatile() {
1884
+ return this.flags.volatile = !0, this;
1885
+ }
1886
+ /**
1887
+ * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
1888
+ * given number of milliseconds have elapsed without an acknowledgement from the server:
1889
+ *
1890
+ * @example
1891
+ * socket.timeout(5000).emit("my-event", (err) => {
1892
+ * if (err) {
1893
+ * // the server did not acknowledge the event in the given delay
1894
+ * }
1895
+ * });
1896
+ *
1897
+ * @returns self
1898
+ */
1899
+ timeout(e) {
1900
+ return this.flags.timeout = e, this;
1901
+ }
1902
+ /**
1903
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
1904
+ * callback.
1905
+ *
1906
+ * @example
1907
+ * socket.onAny((event, ...args) => {
1908
+ * console.log(`got ${event}`);
1909
+ * });
1910
+ *
1911
+ * @param listener
1912
+ */
1913
+ onAny(e) {
1914
+ return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
1915
+ }
1916
+ /**
1917
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
1918
+ * callback. The listener is added to the beginning of the listeners array.
1919
+ *
1920
+ * @example
1921
+ * socket.prependAny((event, ...args) => {
1922
+ * console.log(`got event ${event}`);
1923
+ * });
1924
+ *
1925
+ * @param listener
1926
+ */
1927
+ prependAny(e) {
1928
+ return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
1929
+ }
1930
+ /**
1931
+ * Removes the listener that will be fired when any event is emitted.
1932
+ *
1933
+ * @example
1934
+ * const catchAllListener = (event, ...args) => {
1935
+ * console.log(`got event ${event}`);
1936
+ * }
1937
+ *
1938
+ * socket.onAny(catchAllListener);
1939
+ *
1940
+ * // remove a specific listener
1941
+ * socket.offAny(catchAllListener);
1942
+ *
1943
+ * // or remove all listeners
1944
+ * socket.offAny();
1945
+ *
1946
+ * @param listener
1947
+ */
1948
+ offAny(e) {
1949
+ if (!this._anyListeners)
1950
+ return this;
1951
+ if (e) {
1952
+ const t = this._anyListeners;
1953
+ for (let s = 0; s < t.length; s++)
1954
+ if (e === t[s])
1955
+ return t.splice(s, 1), this;
1956
+ } else
1957
+ this._anyListeners = [];
1958
+ return this;
1959
+ }
1960
+ /**
1961
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
1962
+ * e.g. to remove listeners.
1963
+ */
1964
+ listenersAny() {
1965
+ return this._anyListeners || [];
1966
+ }
1967
+ /**
1968
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
1969
+ * callback.
1970
+ *
1971
+ * Note: acknowledgements sent to the server are not included.
1972
+ *
1973
+ * @example
1974
+ * socket.onAnyOutgoing((event, ...args) => {
1975
+ * console.log(`sent event ${event}`);
1976
+ * });
1977
+ *
1978
+ * @param listener
1979
+ */
1980
+ onAnyOutgoing(e) {
1981
+ return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
1982
+ }
1983
+ /**
1984
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
1985
+ * callback. The listener is added to the beginning of the listeners array.
1986
+ *
1987
+ * Note: acknowledgements sent to the server are not included.
1988
+ *
1989
+ * @example
1990
+ * socket.prependAnyOutgoing((event, ...args) => {
1991
+ * console.log(`sent event ${event}`);
1992
+ * });
1993
+ *
1994
+ * @param listener
1995
+ */
1996
+ prependAnyOutgoing(e) {
1997
+ return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
1998
+ }
1999
+ /**
2000
+ * Removes the listener that will be fired when any event is emitted.
2001
+ *
2002
+ * @example
2003
+ * const catchAllListener = (event, ...args) => {
2004
+ * console.log(`sent event ${event}`);
2005
+ * }
2006
+ *
2007
+ * socket.onAnyOutgoing(catchAllListener);
2008
+ *
2009
+ * // remove a specific listener
2010
+ * socket.offAnyOutgoing(catchAllListener);
2011
+ *
2012
+ * // or remove all listeners
2013
+ * socket.offAnyOutgoing();
2014
+ *
2015
+ * @param [listener] - the catch-all listener (optional)
2016
+ */
2017
+ offAnyOutgoing(e) {
2018
+ if (!this._anyOutgoingListeners)
2019
+ return this;
2020
+ if (e) {
2021
+ const t = this._anyOutgoingListeners;
2022
+ for (let s = 0; s < t.length; s++)
2023
+ if (e === t[s])
2024
+ return t.splice(s, 1), this;
2025
+ } else
2026
+ this._anyOutgoingListeners = [];
2027
+ return this;
2028
+ }
2029
+ /**
2030
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
2031
+ * e.g. to remove listeners.
2032
+ */
2033
+ listenersAnyOutgoing() {
2034
+ return this._anyOutgoingListeners || [];
2035
+ }
2036
+ /**
2037
+ * Notify the listeners for each packet sent
2038
+ *
2039
+ * @param packet
2040
+ *
2041
+ * @private
2042
+ */
2043
+ notifyOutgoingListeners(e) {
2044
+ if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
2045
+ const t = this._anyOutgoingListeners.slice();
2046
+ for (const s of t)
2047
+ s.apply(this, e.data);
2048
+ }
2049
+ }
2050
+ }
2051
+ function b(i) {
2052
+ i = i || {}, this.ms = i.min || 100, this.max = i.max || 1e4, this.factor = i.factor || 2, this.jitter = i.jitter > 0 && i.jitter <= 1 ? i.jitter : 0, this.attempts = 0;
2053
+ }
2054
+ b.prototype.duration = function() {
2055
+ var i = this.ms * Math.pow(this.factor, this.attempts++);
2056
+ if (this.jitter) {
2057
+ var e = Math.random(), t = Math.floor(e * this.jitter * i);
2058
+ i = Math.floor(e * 10) & 1 ? i + t : i - t;
2059
+ }
2060
+ return Math.min(i, this.max) | 0;
2061
+ };
2062
+ b.prototype.reset = function() {
2063
+ this.attempts = 0;
2064
+ };
2065
+ b.prototype.setMin = function(i) {
2066
+ this.ms = i;
2067
+ };
2068
+ b.prototype.setMax = function(i) {
2069
+ this.max = i;
2070
+ };
2071
+ b.prototype.setJitter = function(i) {
2072
+ this.jitter = i;
2073
+ };
2074
+ class F extends u {
2075
+ constructor(e, t) {
2076
+ var s;
2077
+ super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, S(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((s = t.randomizationFactor) !== null && s !== void 0 ? s : 0.5), this.backoff = new b({
2078
+ min: this.reconnectionDelay(),
2079
+ max: this.reconnectionDelayMax(),
2080
+ jitter: this.randomizationFactor()
2081
+ }), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
2082
+ const n = t.parser || et;
2083
+ this.encoder = new n.Encoder(), this.decoder = new n.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
2084
+ }
2085
+ reconnection(e) {
2086
+ return arguments.length ? (this._reconnection = !!e, e || (this.skipReconnect = !0), this) : this._reconnection;
2087
+ }
2088
+ reconnectionAttempts(e) {
2089
+ return e === void 0 ? this._reconnectionAttempts : (this._reconnectionAttempts = e, this);
2090
+ }
2091
+ reconnectionDelay(e) {
2092
+ var t;
2093
+ return e === void 0 ? this._reconnectionDelay : (this._reconnectionDelay = e, (t = this.backoff) === null || t === void 0 || t.setMin(e), this);
2094
+ }
2095
+ randomizationFactor(e) {
2096
+ var t;
2097
+ return e === void 0 ? this._randomizationFactor : (this._randomizationFactor = e, (t = this.backoff) === null || t === void 0 || t.setJitter(e), this);
2098
+ }
2099
+ reconnectionDelayMax(e) {
2100
+ var t;
2101
+ return e === void 0 ? this._reconnectionDelayMax : (this._reconnectionDelayMax = e, (t = this.backoff) === null || t === void 0 || t.setMax(e), this);
2102
+ }
2103
+ timeout(e) {
2104
+ return arguments.length ? (this._timeout = e, this) : this._timeout;
2105
+ }
2106
+ /**
2107
+ * Starts trying to reconnect if reconnection is enabled and we have not
2108
+ * started reconnecting yet
2109
+ *
2110
+ * @private
2111
+ */
2112
+ maybeReconnectOnOpen() {
2113
+ !this._reconnecting && this._reconnection && this.backoff.attempts === 0 && this.reconnect();
2114
+ }
2115
+ /**
2116
+ * Sets the current transport `socket`.
2117
+ *
2118
+ * @param {Function} fn - optional, callback
2119
+ * @return self
2120
+ * @public
2121
+ */
2122
+ open(e) {
2123
+ if (~this._readyState.indexOf("open"))
2124
+ return this;
2125
+ this.engine = new He(this.uri, this.opts);
2126
+ const t = this.engine, s = this;
2127
+ this._readyState = "opening", this.skipReconnect = !1;
2128
+ const n = p(t, "open", function() {
2129
+ s.onopen(), e && e();
2130
+ }), r = (c) => {
2131
+ this.cleanup(), this._readyState = "closed", this.emitReserved("error", c), e ? e(c) : this.maybeReconnectOnOpen();
2132
+ }, o = p(t, "error", r);
2133
+ if (this._timeout !== !1) {
2134
+ const c = this._timeout, h = this.setTimeoutFn(() => {
2135
+ n(), r(new Error("timeout")), t.close();
2136
+ }, c);
2137
+ this.opts.autoUnref && h.unref(), this.subs.push(() => {
2138
+ this.clearTimeoutFn(h);
2139
+ });
2140
+ }
2141
+ return this.subs.push(n), this.subs.push(o), this;
2142
+ }
2143
+ /**
2144
+ * Alias for open()
2145
+ *
2146
+ * @return self
2147
+ * @public
2148
+ */
2149
+ connect(e) {
2150
+ return this.open(e);
2151
+ }
2152
+ /**
2153
+ * Called upon transport open.
2154
+ *
2155
+ * @private
2156
+ */
2157
+ onopen() {
2158
+ this.cleanup(), this._readyState = "open", this.emitReserved("open");
2159
+ const e = this.engine;
2160
+ this.subs.push(
2161
+ p(e, "ping", this.onping.bind(this)),
2162
+ p(e, "data", this.ondata.bind(this)),
2163
+ p(e, "error", this.onerror.bind(this)),
2164
+ p(e, "close", this.onclose.bind(this)),
2165
+ // @ts-ignore
2166
+ p(this.decoder, "decoded", this.ondecoded.bind(this))
2167
+ );
2168
+ }
2169
+ /**
2170
+ * Called upon a ping.
2171
+ *
2172
+ * @private
2173
+ */
2174
+ onping() {
2175
+ this.emitReserved("ping");
2176
+ }
2177
+ /**
2178
+ * Called with data.
2179
+ *
2180
+ * @private
2181
+ */
2182
+ ondata(e) {
2183
+ try {
2184
+ this.decoder.add(e);
2185
+ } catch (t) {
2186
+ this.onclose("parse error", t);
2187
+ }
2188
+ }
2189
+ /**
2190
+ * Called when parser fully decodes a packet.
2191
+ *
2192
+ * @private
2193
+ */
2194
+ ondecoded(e) {
2195
+ C(() => {
2196
+ this.emitReserved("packet", e);
2197
+ }, this.setTimeoutFn);
2198
+ }
2199
+ /**
2200
+ * Called upon socket error.
2201
+ *
2202
+ * @private
2203
+ */
2204
+ onerror(e) {
2205
+ this.emitReserved("error", e);
2206
+ }
2207
+ /**
2208
+ * Creates a new socket for the given `nsp`.
2209
+ *
2210
+ * @return {Socket}
2211
+ * @public
2212
+ */
2213
+ socket(e, t) {
2214
+ let s = this.nsps[e];
2215
+ return s ? this._autoConnect && !s.active && s.connect() : (s = new he(this, e, t), this.nsps[e] = s), s;
2216
+ }
2217
+ /**
2218
+ * Called upon a socket close.
2219
+ *
2220
+ * @param socket
2221
+ * @private
2222
+ */
2223
+ _destroy(e) {
2224
+ const t = Object.keys(this.nsps);
2225
+ for (const s of t)
2226
+ if (this.nsps[s].active)
2227
+ return;
2228
+ this._close();
2229
+ }
2230
+ /**
2231
+ * Writes a packet.
2232
+ *
2233
+ * @param packet
2234
+ * @private
2235
+ */
2236
+ _packet(e) {
2237
+ const t = this.encoder.encode(e);
2238
+ for (let s = 0; s < t.length; s++)
2239
+ this.engine.write(t[s], e.options);
2240
+ }
2241
+ /**
2242
+ * Clean up transport subscriptions and packet buffer.
2243
+ *
2244
+ * @private
2245
+ */
2246
+ cleanup() {
2247
+ this.subs.forEach((e) => e()), this.subs.length = 0, this.decoder.destroy();
2248
+ }
2249
+ /**
2250
+ * Close the current socket.
2251
+ *
2252
+ * @private
2253
+ */
2254
+ _close() {
2255
+ this.skipReconnect = !0, this._reconnecting = !1, this.onclose("forced close");
2256
+ }
2257
+ /**
2258
+ * Alias for close()
2259
+ *
2260
+ * @private
2261
+ */
2262
+ disconnect() {
2263
+ return this._close();
2264
+ }
2265
+ /**
2266
+ * Called when:
2267
+ *
2268
+ * - the low-level engine is closed
2269
+ * - the parser encountered a badly formatted packet
2270
+ * - all sockets are disconnected
2271
+ *
2272
+ * @private
2273
+ */
2274
+ onclose(e, t) {
2275
+ var s;
2276
+ this.cleanup(), (s = this.engine) === null || s === void 0 || s.close(), this.backoff.reset(), this._readyState = "closed", this.emitReserved("close", e, t), this._reconnection && !this.skipReconnect && this.reconnect();
2277
+ }
2278
+ /**
2279
+ * Attempt a reconnection.
2280
+ *
2281
+ * @private
2282
+ */
2283
+ reconnect() {
2284
+ if (this._reconnecting || this.skipReconnect)
2285
+ return this;
2286
+ const e = this;
2287
+ if (this.backoff.attempts >= this._reconnectionAttempts)
2288
+ this.backoff.reset(), this.emitReserved("reconnect_failed"), this._reconnecting = !1;
2289
+ else {
2290
+ const t = this.backoff.duration();
2291
+ this._reconnecting = !0;
2292
+ const s = this.setTimeoutFn(() => {
2293
+ e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((n) => {
2294
+ n ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", n)) : e.onreconnect();
2295
+ }));
2296
+ }, t);
2297
+ this.opts.autoUnref && s.unref(), this.subs.push(() => {
2298
+ this.clearTimeoutFn(s);
2299
+ });
2300
+ }
2301
+ }
2302
+ /**
2303
+ * Called upon successful reconnect.
2304
+ *
2305
+ * @private
2306
+ */
2307
+ onreconnect() {
2308
+ const e = this.backoff.attempts;
2309
+ this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
2310
+ }
2311
+ }
2312
+ const v = {};
2313
+ function L(i, e) {
2314
+ typeof i == "object" && (e = i, i = void 0), e = e || {};
2315
+ const t = We(i, e.path || "/socket.io"), s = t.source, n = t.id, r = t.path, o = v[n] && r in v[n].nsps, c = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
2316
+ let h;
2317
+ return c ? h = new F(s, e) : (v[n] || (v[n] = new F(s, e)), h = v[n]), t.query && !e.query && (e.query = t.queryKey), h.socket(t.path, e);
2318
+ }
2319
+ Object.assign(L, {
2320
+ Manager: F,
2321
+ Socket: he,
2322
+ io: L,
2323
+ connect: L
2324
+ });
2325
+ export {
2326
+ it as Fetch,
2327
+ F as Manager,
2328
+ Pe as NodeWebSocket,
2329
+ Ne as NodeXHR,
2330
+ he as Socket,
2331
+ Pe as WebSocket,
2332
+ qe as WebTransport,
2333
+ Ne as XHR,
2334
+ L as connect,
2335
+ L as io,
2336
+ Ge as protocol
2337
+ };
2338
+ //# sourceMappingURL=index.es.js.map