@blade-hq/agent-client 2612.0.0-beta.11 → 2612.0.0-beta.13

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.
Files changed (66) hide show
  1. package/README.md +59 -2
  2. package/dist/{chunk-SCG5SRXE.js → chunk-KPS6X6QX.js} +13 -16
  3. package/dist/chunk-KPS6X6QX.js.map +1 -0
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/internal.d.ts +1 -1
  7. package/dist/internal.js +1 -1
  8. package/dist/resources/sessions.d.ts +42 -6
  9. package/dist/schemas/session.d.ts +1 -42
  10. package/dist/session/agent-session.d.ts +0 -1
  11. package/dist/session/events.d.ts +0 -1
  12. package/node_modules/engine.io-client/build/cjs/globals.node.d.ts +2 -3
  13. package/node_modules/engine.io-client/build/cjs/index.d.ts +3 -3
  14. package/node_modules/engine.io-client/build/cjs/index.js +1 -4
  15. package/node_modules/engine.io-client/build/cjs/socket.d.ts +39 -82
  16. package/node_modules/engine.io-client/build/cjs/socket.js +151 -218
  17. package/node_modules/engine.io-client/build/cjs/transport.d.ts +1 -1
  18. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts +4 -4
  19. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js +2 -2
  20. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js +17 -7
  21. package/node_modules/engine.io-client/build/cjs/transports/websocket.node.js +17 -7
  22. package/node_modules/engine.io-client/build/esm/globals.node.d.ts +2 -3
  23. package/node_modules/engine.io-client/build/esm/index.d.ts +3 -3
  24. package/node_modules/engine.io-client/build/esm/index.js +1 -2
  25. package/node_modules/engine.io-client/build/esm/socket.d.ts +39 -82
  26. package/node_modules/engine.io-client/build/esm/socket.js +141 -206
  27. package/node_modules/engine.io-client/build/esm/transport.d.ts +1 -1
  28. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.d.ts +4 -4
  29. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +2 -2
  30. package/node_modules/engine.io-client/build/esm-debug/globals.node.d.ts +2 -3
  31. package/node_modules/engine.io-client/build/esm-debug/index.d.ts +3 -3
  32. package/node_modules/engine.io-client/build/esm-debug/index.js +1 -2
  33. package/node_modules/engine.io-client/build/esm-debug/socket.d.ts +39 -82
  34. package/node_modules/engine.io-client/build/esm-debug/socket.js +150 -215
  35. package/node_modules/engine.io-client/build/esm-debug/transport.d.ts +1 -1
  36. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.d.ts +4 -4
  37. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js +2 -2
  38. package/node_modules/engine.io-client/dist/engine.io.esm.min.js +3 -3
  39. package/node_modules/engine.io-client/dist/engine.io.esm.min.js.map +1 -1
  40. package/node_modules/engine.io-client/dist/engine.io.js +164 -239
  41. package/node_modules/engine.io-client/dist/engine.io.js.map +1 -1
  42. package/node_modules/engine.io-client/dist/engine.io.min.js +3 -3
  43. package/node_modules/engine.io-client/dist/engine.io.min.js.map +1 -1
  44. package/node_modules/engine.io-client/package.json +2 -2
  45. package/node_modules/socket.io-parser/build/cjs/binary.js +4 -1
  46. package/node_modules/socket.io-parser/build/cjs/index.d.ts +14 -4
  47. package/node_modules/socket.io-parser/build/cjs/index.js +18 -11
  48. package/node_modules/socket.io-parser/build/esm/binary.js +4 -1
  49. package/node_modules/socket.io-parser/build/esm/index.d.ts +14 -4
  50. package/node_modules/socket.io-parser/build/esm/index.js +14 -10
  51. package/node_modules/socket.io-parser/build/esm-debug/binary.js +4 -1
  52. package/node_modules/socket.io-parser/build/esm-debug/index.d.ts +14 -4
  53. package/node_modules/socket.io-parser/build/esm-debug/index.js +14 -10
  54. package/node_modules/socket.io-parser/package.json +1 -1
  55. package/node_modules/ws/index.js +15 -6
  56. package/node_modules/ws/lib/constants.js +1 -0
  57. package/node_modules/ws/lib/permessage-deflate.js +9 -7
  58. package/node_modules/ws/lib/receiver.js +37 -0
  59. package/node_modules/ws/lib/sender.js +6 -1
  60. package/node_modules/ws/lib/websocket-server.js +18 -6
  61. package/node_modules/ws/lib/websocket.js +50 -17
  62. package/node_modules/ws/package.json +8 -3
  63. package/node_modules/ws/wrapper.mjs +14 -1
  64. package/package.json +4 -4
  65. package/public-api.md +36 -17
  66. package/dist/chunk-SCG5SRXE.js.map +0 -1
@@ -20,39 +20,29 @@ if (withEventListeners) {
20
20
  }
21
21
  /**
22
22
  * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
23
- * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
23
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket, or WebTransport.
24
24
  *
25
- * This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
26
- * successfully establishes the connection.
27
- *
28
- * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
25
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
26
+ * low-level transport, it will try to upgrade to a better transport.
29
27
  *
30
28
  * @example
31
- * import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
29
+ * import { Socket } from "engine.io-client";
32
30
  *
33
- * const socket = new SocketWithoutUpgrade({
34
- * transports: [WebSocket]
35
- * });
31
+ * const socket = new Socket();
36
32
  *
37
33
  * socket.on("open", () => {
38
34
  * socket.send("hello");
39
35
  * });
40
36
  *
41
- * @see SocketWithUpgrade
42
- * @see Socket
43
37
  */
44
- export class SocketWithoutUpgrade extends Emitter {
45
- /**
46
- * Socket constructor.
47
- *
48
- * @param {String|Object} uri - uri or options
49
- * @param {Object} opts - options
50
- */
51
- constructor(uri, opts) {
38
+ export class Socket extends Emitter {
39
+ constructor(uri, opts = {}) {
40
+ var _a, _b;
52
41
  super();
53
42
  this.binaryType = defaultBinaryType;
54
43
  this.writeBuffer = [];
55
44
  this._prevBufferLen = 0;
45
+ this._upgrades = [];
56
46
  this._pingInterval = -1;
57
47
  this._pingTimeout = -1;
58
48
  this._maxPayload = -1;
@@ -96,13 +86,26 @@ export class SocketWithoutUpgrade extends Emitter {
96
86
  : this.secure
97
87
  ? "443"
98
88
  : "80");
99
- this.transports = [];
100
- this._transportsByName = {};
101
- opts.transports.forEach((t) => {
102
- const transportName = t.prototype.name;
103
- this.transports.push(transportName);
104
- this._transportsByName[transportName] = t;
105
- });
89
+ if (opts.transportImplementations && opts.transports) {
90
+ throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");
91
+ }
92
+ if (opts.transportImplementations ||
93
+ (((_a = opts.transports) === null || _a === void 0 ? void 0 : _a.length) && typeof opts.transports[0] === "function")) {
94
+ // 'transports' option as an array of transport implementations is kept for backward compatibility
95
+ this.transports = [];
96
+ this._transportsByName = Object.create(null);
97
+ ((_b = opts.transportImplementations) !== null && _b !== void 0 ? _b : opts.transports).forEach((t) => {
98
+ const transportName = t.prototype.name;
99
+ this.transports.push(transportName);
100
+ this._transportsByName[transportName] = t;
101
+ });
102
+ }
103
+ else {
104
+ this.transports = opts.transports
105
+ ? [...opts.transports]
106
+ : ["polling", "websocket", "webtransport"];
107
+ this._transportsByName = DEFAULT_TRANSPORTS;
108
+ }
106
109
  this.opts = Object.assign({
107
110
  path: "/engine.io",
108
111
  agent: false,
@@ -194,7 +197,7 @@ export class SocketWithoutUpgrade extends Emitter {
194
197
  return;
195
198
  }
196
199
  const transportName = this.opts.rememberUpgrade &&
197
- SocketWithoutUpgrade.priorWebsocketSuccess &&
200
+ Socket.priorWebsocketSuccess &&
198
201
  this.transports.indexOf("websocket") !== -1
199
202
  ? "websocket"
200
203
  : this.transports[0];
@@ -223,6 +226,115 @@ export class SocketWithoutUpgrade extends Emitter {
223
226
  .on("error", this._onError.bind(this))
224
227
  .on("close", (reason) => this._onClose("transport close", reason));
225
228
  }
229
+ /**
230
+ * Probes a transport.
231
+ *
232
+ * @param {String} name - transport name
233
+ * @private
234
+ */
235
+ _probe(name) {
236
+ debug('probing transport "%s"', name);
237
+ let transport = this.createTransport(name);
238
+ let failed = false;
239
+ Socket.priorWebsocketSuccess = false;
240
+ const onTransportOpen = () => {
241
+ if (failed)
242
+ return;
243
+ debug('probe transport "%s" opened', name);
244
+ transport.send([{ type: "ping", data: "probe" }]);
245
+ transport.once("packet", (msg) => {
246
+ if (failed)
247
+ return;
248
+ if ("pong" === msg.type && "probe" === msg.data) {
249
+ debug('probe transport "%s" pong', name);
250
+ this.upgrading = true;
251
+ this.emitReserved("upgrading", transport);
252
+ if (!transport)
253
+ return;
254
+ Socket.priorWebsocketSuccess = "websocket" === transport.name;
255
+ debug('pausing current transport "%s"', this.transport.name);
256
+ this.transport.pause(() => {
257
+ if (failed)
258
+ return;
259
+ if ("closed" === this.readyState)
260
+ return;
261
+ debug("changing transport and sending upgrade packet");
262
+ cleanup();
263
+ this.setTransport(transport);
264
+ transport.send([{ type: "upgrade" }]);
265
+ this.emitReserved("upgrade", transport);
266
+ transport = null;
267
+ this.upgrading = false;
268
+ this.flush();
269
+ });
270
+ }
271
+ else {
272
+ debug('probe transport "%s" failed', name);
273
+ const err = new Error("probe error");
274
+ // @ts-ignore
275
+ err.transport = transport.name;
276
+ this.emitReserved("upgradeError", err);
277
+ }
278
+ });
279
+ };
280
+ function freezeTransport() {
281
+ if (failed)
282
+ return;
283
+ // Any callback called by transport should be ignored since now
284
+ failed = true;
285
+ cleanup();
286
+ transport.close();
287
+ transport = null;
288
+ }
289
+ // Handle any error that happens while probing
290
+ const onerror = (err) => {
291
+ const error = new Error("probe error: " + err);
292
+ // @ts-ignore
293
+ error.transport = transport.name;
294
+ freezeTransport();
295
+ debug('probe transport "%s" failed because of error: %s', name, err);
296
+ this.emitReserved("upgradeError", error);
297
+ };
298
+ function onTransportClose() {
299
+ onerror("transport closed");
300
+ }
301
+ // When the socket is closed while we're probing
302
+ function onclose() {
303
+ onerror("socket closed");
304
+ }
305
+ // When the socket is upgraded while we're probing
306
+ function onupgrade(to) {
307
+ if (transport && to.name !== transport.name) {
308
+ debug('"%s" works - aborting "%s"', to.name, transport.name);
309
+ freezeTransport();
310
+ }
311
+ }
312
+ // Remove all listeners on the transport and on self
313
+ const cleanup = () => {
314
+ transport.removeListener("open", onTransportOpen);
315
+ transport.removeListener("error", onerror);
316
+ transport.removeListener("close", onTransportClose);
317
+ this.off("close", onclose);
318
+ this.off("upgrading", onupgrade);
319
+ };
320
+ transport.once("open", onTransportOpen);
321
+ transport.once("error", onerror);
322
+ transport.once("close", onTransportClose);
323
+ this.once("close", onclose);
324
+ this.once("upgrading", onupgrade);
325
+ if (this._upgrades.indexOf("webtransport") !== -1 &&
326
+ name !== "webtransport") {
327
+ // favor WebTransport
328
+ this.setTimeoutFn(() => {
329
+ if (!failed) {
330
+ transport.open();
331
+ }
332
+ }, 200);
333
+ }
334
+ else {
335
+ transport.open();
336
+ }
337
+ }
226
338
  /**
227
339
  * Called when connection is deemed open.
228
340
  *
@@ -231,10 +343,15 @@ export class SocketWithoutUpgrade extends Emitter {
231
343
  onOpen() {
232
344
  debug("socket open");
233
345
  this.readyState = "open";
234
- SocketWithoutUpgrade.priorWebsocketSuccess =
235
- "websocket" === this.transport.name;
346
+ Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
236
347
  this.emitReserved("open");
237
348
  this.flush();
349
+ if ("open" === this.readyState && this.opts.upgrade) {
350
+ debug("starting upgrade probes");
351
+ for (let i = 0; i < this._upgrades.length; i++) {
352
+ this._probe(this._upgrades[i]);
353
+ }
354
+ }
238
355
  }
239
356
  /**
240
357
  * Handles a packet.
@@ -285,6 +402,7 @@ export class SocketWithoutUpgrade extends Emitter {
285
402
  this.emitReserved("handshake", data);
286
403
  this.id = data.sid;
287
404
  this.transport.query.sid = data.sid;
405
+ this._upgrades = this._filterUpgrades(data.upgrades);
288
406
  this._pingInterval = data.pingInterval;
289
407
  this._pingTimeout = data.pingTimeout;
290
408
  this._maxPayload = data.maxPayload;
@@ -424,7 +542,7 @@ export class SocketWithoutUpgrade extends Emitter {
424
542
  /**
425
543
  * Sends a packet.
426
544
  *
427
- * @param {String} type: packet type.
545
+ * @param {String} type - packet type.
428
546
  * @param {String} data.
429
547
  * @param {Object} options.
430
548
  * @param {Function} fn - callback function.
@@ -502,7 +620,7 @@ export class SocketWithoutUpgrade extends Emitter {
502
620
  */
503
621
  _onError(err) {
504
622
  debug("socket error %j", err);
505
- SocketWithoutUpgrade.priorWebsocketSuccess = false;
623
+ Socket.priorWebsocketSuccess = false;
506
624
  if (this.opts.tryAllTransports &&
507
625
  this.transports.length > 1 &&
508
626
  this.readyState === "opening") {
@@ -555,159 +673,6 @@ export class SocketWithoutUpgrade extends Emitter {
555
673
  this._prevBufferLen = 0;
556
674
  }
557
675
  }
558
- }
559
- SocketWithoutUpgrade.protocol = protocol;
560
- /**
561
- * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
562
- * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
563
- *
564
- * This class comes with an upgrade mechanism, which means that once the connection is established with the first
565
- * low-level transport, it will try to upgrade to a better transport.
566
- *
567
- * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
568
- *
569
- * @example
570
- * import { SocketWithUpgrade, WebSocket } from "engine.io-client";
571
- *
572
- * const socket = new SocketWithUpgrade({
573
- * transports: [WebSocket]
574
- * });
575
- *
576
- * socket.on("open", () => {
577
- * socket.send("hello");
578
- * });
579
- *
580
- * @see SocketWithoutUpgrade
581
- * @see Socket
582
- */
583
- export class SocketWithUpgrade extends SocketWithoutUpgrade {
584
- constructor() {
585
- super(...arguments);
586
- this._upgrades = [];
587
- }
588
- onOpen() {
589
- super.onOpen();
590
- if ("open" === this.readyState && this.opts.upgrade) {
591
- debug("starting upgrade probes");
592
- for (let i = 0; i < this._upgrades.length; i++) {
593
- this._probe(this._upgrades[i]);
594
- }
595
- }
596
- }
597
- /**
598
- * Probes a transport.
599
- *
600
- * @param {String} name - transport name
601
- * @private
602
- */
603
- _probe(name) {
604
- debug('probing transport "%s"', name);
605
- let transport = this.createTransport(name);
606
- let failed = false;
607
- SocketWithoutUpgrade.priorWebsocketSuccess = false;
608
- const onTransportOpen = () => {
609
- if (failed)
610
- return;
611
- debug('probe transport "%s" opened', name);
612
- transport.send([{ type: "ping", data: "probe" }]);
613
- transport.once("packet", (msg) => {
614
- if (failed)
615
- return;
616
- if ("pong" === msg.type && "probe" === msg.data) {
617
- debug('probe transport "%s" pong', name);
618
- this.upgrading = true;
619
- this.emitReserved("upgrading", transport);
620
- if (!transport)
621
- return;
622
- SocketWithoutUpgrade.priorWebsocketSuccess =
623
- "websocket" === transport.name;
624
- debug('pausing current transport "%s"', this.transport.name);
625
- this.transport.pause(() => {
626
- if (failed)
627
- return;
628
- if ("closed" === this.readyState)
629
- return;
630
- debug("changing transport and sending upgrade packet");
631
- cleanup();
632
- this.setTransport(transport);
633
- transport.send([{ type: "upgrade" }]);
634
- this.emitReserved("upgrade", transport);
635
- transport = null;
636
- this.upgrading = false;
637
- this.flush();
638
- });
639
- }
640
- else {
641
- debug('probe transport "%s" failed', name);
642
- const err = new Error("probe error");
643
- // @ts-ignore
644
- err.transport = transport.name;
645
- this.emitReserved("upgradeError", err);
646
- }
647
- });
648
- };
649
- function freezeTransport() {
650
- if (failed)
651
- return;
652
- // Any callback called by transport should be ignored since now
653
- failed = true;
654
- cleanup();
655
- transport.close();
656
- transport = null;
657
- }
658
- // Handle any error that happens while probing
659
- const onerror = (err) => {
660
- const error = new Error("probe error: " + err);
661
- // @ts-ignore
662
- error.transport = transport.name;
663
- freezeTransport();
664
- debug('probe transport "%s" failed because of error: %s', name, err);
665
- this.emitReserved("upgradeError", error);
666
- };
667
- function onTransportClose() {
668
- onerror("transport closed");
669
- }
670
- // When the socket is closed while we're probing
671
- function onclose() {
672
- onerror("socket closed");
673
- }
674
- // When the socket is upgraded while we're probing
675
- function onupgrade(to) {
676
- if (transport && to.name !== transport.name) {
677
- debug('"%s" works - aborting "%s"', to.name, transport.name);
678
- freezeTransport();
679
- }
680
- }
681
- // Remove all listeners on the transport and on self
682
- const cleanup = () => {
683
- transport.removeListener("open", onTransportOpen);
684
- transport.removeListener("error", onerror);
685
- transport.removeListener("close", onTransportClose);
686
- this.off("close", onclose);
687
- this.off("upgrading", onupgrade);
688
- };
689
- transport.once("open", onTransportOpen);
690
- transport.once("error", onerror);
691
- transport.once("close", onTransportClose);
692
- this.once("close", onclose);
693
- this.once("upgrading", onupgrade);
694
- if (this._upgrades.indexOf("webtransport") !== -1 &&
695
- name !== "webtransport") {
696
- // favor WebTransport
697
- this.setTimeoutFn(() => {
698
- if (!failed) {
699
- transport.open();
700
- }
701
- }, 200);
702
- }
703
- else {
704
- transport.open();
705
- }
706
- }
707
- onHandshake(data) {
708
- this._upgrades = this._filterUpgrades(data.upgrades);
709
- super.onHandshake(data);
710
- }
711
676
  /**
712
677
  * Filters upgrades, returning only those matching client transports.
713
678
  *
@@ -723,34 +688,4 @@ export class SocketWithUpgrade extends SocketWithoutUpgrade {
723
688
  return filteredUpgrades;
724
689
  }
725
690
  }
726
- /**
727
- * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
728
- * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
729
- *
730
- * This class comes with an upgrade mechanism, which means that once the connection is established with the first
731
- * low-level transport, it will try to upgrade to a better transport.
732
- *
733
- * @example
734
- * import { Socket } from "engine.io-client";
735
- *
736
- * const socket = new Socket();
737
- *
738
- * socket.on("open", () => {
739
- * socket.send("hello");
740
- * });
741
- *
742
- * @see SocketWithoutUpgrade
743
- * @see SocketWithUpgrade
744
- */
745
- export class Socket extends SocketWithUpgrade {
746
- constructor(uri, opts = {}) {
747
- const o = typeof uri === "object" ? uri : opts;
748
- if (!o.transports ||
749
- (o.transports && typeof o.transports[0] === "string")) {
750
- o.transports = (o.transports || ["polling", "websocket", "webtransport"])
751
- .map((transportName) => DEFAULT_TRANSPORTS[transportName])
752
- .filter((t) => !!t);
753
- }
754
- super(uri, o);
755
- }
756
- }
691
+ Socket.protocol = protocol;
@@ -11,7 +11,7 @@ export interface CloseDetails {
11
11
  description: string;
12
12
  context?: unknown;
13
13
  }
14
- interface TransportReservedEvents {
14
+ export interface TransportReservedEvents {
15
15
  open: () => void;
16
16
  error: (err: TransportError) => void;
17
17
  packet: (packet: Packet) => void;
@@ -22,11 +22,11 @@ export declare abstract class BaseXHR extends Polling {
22
22
  /**
23
23
  * Sends data.
24
24
  *
25
- * @param {String} data to send.
26
- * @param {Function} called upon flush.
25
+ * @param {String} data - data to send.
26
+ * @param {Function} fn - called upon flush.
27
27
  * @private
28
28
  */
29
- doWrite(data: any, fn: any): void;
29
+ doWrite(data: string, fn: () => void): void;
30
30
  /**
31
31
  * Starts a poll cycle.
32
32
  *
@@ -62,7 +62,7 @@ export declare class Request extends Emitter<Record<never, never>, Record<never,
62
62
  * @param {Object} options
63
63
  * @package
64
64
  */
65
- constructor(createRequest: (opts: RequestOptions) => XMLHttpRequest, uri: string, opts: RequestOptions);
65
+ constructor(createRequest: (opts: RequestOptions) => any, uri: string, opts: RequestOptions);
66
66
  /**
67
67
  * Creates the XHR object and sends the request.
68
68
  *
@@ -31,8 +31,8 @@ export class BaseXHR extends Polling {
31
31
  /**
32
32
  * Sends data.
33
33
  *
34
- * @param {String} data to send.
35
- * @param {Function} called upon flush.
34
+ * @param {String} data - data to send.
35
+ * @param {Function} fn - called upon flush.
36
36
  * @private
37
37
  */
38
38
  doWrite(data, fn) {
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * Engine.IO v6.6.4
3
- * (c) 2014-2025 Guillermo Rauch
2
+ * Engine.IO v6.6.7
3
+ * (c) 2014-2026 Guillermo Rauch
4
4
  * Released under the MIT License.
5
5
  */
6
- const t=Object.create(null);t.open="0",t.close="1",t.ping="2",t.pong="3",t.message="4",t.upgrade="5",t.noop="6";const s=Object.create(null);Object.keys(t).forEach((e=>{s[t[e]]=e}));const e={type:"error",data:"parser error"},i="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),n="function"==typeof ArrayBuffer,r=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,o=({type:s,data:e},o,c)=>i&&e instanceof Blob?o?c(e):h(e,c):n&&(e instanceof ArrayBuffer||r(e))?o?c(e):h(new Blob([e]),c):c(t[s]+(e||"")),h=(t,s)=>{const e=new FileReader;return e.onload=function(){const t=e.result.split(",")[1];s("b"+(t||""))},e.readAsDataURL(t)};function c(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let a;const u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)f[u.charCodeAt(t)]=t;const l="function"==typeof ArrayBuffer,p=(t,i)=>{if("string"!=typeof t)return{type:"message",data:y(t,i)};const n=t.charAt(0);if("b"===n)return{type:"message",data:d(t.substring(1),i)};return s[n]?t.length>1?{type:s[n],data:t.substring(1)}:{type:s[n]}:e},d=(t,s)=>{if(l){const e=(t=>{let s,e,i,n,r,o=.75*t.length,h=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const a=new ArrayBuffer(o),u=new Uint8Array(a);for(s=0;s<h;s+=4)e=f[t.charCodeAt(s)],i=f[t.charCodeAt(s+1)],n=f[t.charCodeAt(s+2)],r=f[t.charCodeAt(s+3)],u[c++]=e<<2|i>>4,u[c++]=(15&i)<<4|n>>2,u[c++]=(3&n)<<6|63&r;return a})(t);return y(e,s)}return{base64:!0,data:t}},y=(t,s)=>"blob"===s?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,g=String.fromCharCode(30);function w(){return new TransformStream({transform(t,s){!function(t,s){i&&t.data instanceof Blob?t.data.arrayBuffer().then(c).then(s):n&&(t.data instanceof ArrayBuffer||r(t.data))?s(c(t.data)):o(t,!1,(t=>{a||(a=new TextEncoder),s(a.encode(t))}))}(t,(e=>{const i=e.length;let n;if(i<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,i);else if(i<65536){n=new Uint8Array(3);const t=new DataView(n.buffer);t.setUint8(0,126),t.setUint16(1,i)}else{n=new Uint8Array(9);const t=new DataView(n.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(i))}t.data&&"string"!=typeof t.data&&(n[0]|=128),s.enqueue(n),s.enqueue(e)}))}})}let b;function m(t){return t.reduce(((t,s)=>t+s.length),0)}function v(t,s){if(t[0].length===s)return t.shift();const e=new Uint8Array(s);let i=0;for(let n=0;n<s;n++)e[n]=t[0][i++],i===t[0].length&&(t.shift(),i=0);return t.length&&i<t[0].length&&(t[0]=t[0].slice(i)),e}function k(t){if(t)return function(t){for(var s in k.prototype)t[s]=k.prototype[s];return t}(t)}k.prototype.on=k.prototype.addEventListener=function(t,s){return this.t=this.t||{},(this.t["$"+t]=this.t["$"+t]||[]).push(s),this},k.prototype.once=function(t,s){function e(){this.off(t,e),s.apply(this,arguments)}return e.fn=s,this.on(t,e),this},k.prototype.off=k.prototype.removeListener=k.prototype.removeAllListeners=k.prototype.removeEventListener=function(t,s){if(this.t=this.t||{},0==arguments.length)return this.t={},this;var e,i=this.t["$"+t];if(!i)return this;if(1==arguments.length)return delete this.t["$"+t],this;for(var n=0;n<i.length;n++)if((e=i[n])===s||e.fn===s){i.splice(n,1);break}return 0===i.length&&delete this.t["$"+t],this},k.prototype.emit=function(t){this.t=this.t||{};for(var s=new Array(arguments.length-1),e=this.t["$"+t],i=1;i<arguments.length;i++)s[i-1]=arguments[i];if(e){i=0;for(var n=(e=e.slice(0)).length;i<n;++i)e[i].apply(this,s)}return this},k.prototype.emitReserved=k.prototype.emit,k.prototype.listeners=function(t){return this.t=this.t||{},this.t["$"+t]||[]},k.prototype.hasListeners=function(t){return!!this.listeners(t).length};const x="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,s)=>s(t,0),E="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function A(t,...s){return s.reduce(((s,e)=>(t.hasOwnProperty(e)&&(s[e]=t[e]),s)),{})}const U=E.setTimeout,B=E.clearTimeout;function O(t,s){s.useNativeTimers?(t.setTimeoutFn=U.bind(E),t.clearTimeoutFn=B.bind(E)):(t.setTimeoutFn=E.setTimeout.bind(E),t.clearTimeoutFn=E.clearTimeout.bind(E))}function T(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class _ extends Error{constructor(t,s,e){super(t),this.description=s,this.context=e,this.type="TransportError"}}class C extends k{constructor(t){super(),this.writable=!1,O(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,e){return super.emitReserved("error",new _(t,s,e)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=p(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this.i()+this.o()+this.opts.path+this.h(s)}i(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}o(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}h(t){const s=function(t){let s="";for(let e in t)t.hasOwnProperty(e)&&(s.length&&(s+="&"),s+=encodeURIComponent(e)+"="+encodeURIComponent(t[e]));return s}(t);return s.length?"?"+s:""}}class P extends C{constructor(){super(...arguments),this.u=!1}get name(){return"polling"}doOpen(){this.l()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this.u||!this.writable){let t=0;this.u&&(t++,this.once("pollComplete",(function(){--t||s()}))),this.writable||(t++,this.once("drain",(function(){--t||s()})))}else s()}l(){this.u=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,s)=>{const e=t.split(g),i=[];for(let t=0;t<e.length;t++){const n=p(e[t],s);if(i.push(n),"error"===n.type)break}return i})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this.u=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.l())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,s)=>{const e=t.length,i=new Array(e);let n=0;t.forEach(((t,r)=>{o(t,!1,(t=>{i[r]=t,++n===e&&s(i.join(g))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return!1!==this.opts.timestampRequests&&(s[this.opts.timestampParam]=T()),this.supportsBinary||s.sid||(s.b64=1),this.createUri(t,s)}}let j=!1;try{j="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const D=j;function L(){}class M extends P{constructor(t){if(super(t),"undefined"!=typeof location){const s="https:"===location.protocol;let e=location.port;e||(e=s?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||e!==t.port}}doWrite(t,s){const e=this.request({method:"POST",data:t});e.on("success",s),e.on("error",((t,s)=>{this.onError("xhr post error",t,s)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,s)=>{this.onError("xhr poll error",t,s)})),this.pollXhr=t}}class S extends k{constructor(t,s,e){super(),this.createRequest=t,O(this,e),this.p=e,this.m=e.method||"GET",this.v=s,this.k=void 0!==e.data?e.data:null,this.A()}A(){var t;const s=A(this.p,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this.p.xd;const e=this.U=this.createRequest(s);try{e.open(this.m,this.v,!0);try{if(this.p.extraHeaders){e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0);for(let t in this.p.extraHeaders)this.p.extraHeaders.hasOwnProperty(t)&&e.setRequestHeader(t,this.p.extraHeaders[t])}}catch(t){}if("POST"===this.m)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this.p.cookieJar)||void 0===t||t.addCookies(e),"withCredentials"in e&&(e.withCredentials=this.p.withCredentials),this.p.requestTimeout&&(e.timeout=this.p.requestTimeout),e.onreadystatechange=()=>{var t;3===e.readyState&&(null===(t=this.p.cookieJar)||void 0===t||t.parseCookies(e.getResponseHeader("set-cookie"))),4===e.readyState&&(200===e.status||1223===e.status?this.B():this.setTimeoutFn((()=>{this.O("number"==typeof e.status?e.status:0)}),0))},e.send(this.k)}catch(t){return void this.setTimeoutFn((()=>{this.O(t)}),0)}"undefined"!=typeof document&&(this.T=S.requestsCount++,S.requests[this.T]=this)}O(t){this.emitReserved("error",t,this.U),this._(!0)}_(t){if(void 0!==this.U&&null!==this.U){if(this.U.onreadystatechange=L,t)try{this.U.abort()}catch(t){}"undefined"!=typeof document&&delete S.requests[this.T],this.U=null}}B(){const t=this.U.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._())}abort(){this._()}}if(S.requestsCount=0,S.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",R);else if("function"==typeof addEventListener){addEventListener("onpagehide"in E?"pagehide":"unload",R,!1)}function R(){for(let t in S.requests)S.requests.hasOwnProperty(t)&&S.requests[t].abort()}const H=function(){const t=q({xdomain:!1});return t&&null!==t.responseType}();class $ extends M{constructor(t){super(t);const s=t&&t.forceBase64;this.supportsBinary=H&&!s}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new S(q,this.uri(),t)}}function q(t){const s=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!s||D))return new XMLHttpRequest}catch(t){}if(!s)try{return new(E[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const I="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class W extends C{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,e=I?{}:A(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(e.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,e)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws.C.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const e=t[s],i=s===t.length-1;o(e,this.supportsBinary,(t=>{try{this.doWrite(e,t)}catch(t){}i&&x((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=T()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const N=E.WebSocket||E.MozWebSocket;class X extends W{createSocket(t,s,e){return I?new N(t,s,e):s?new N(t,s):new N(t)}doWrite(t,s){this.ws.send(s)}}class V extends C{get name(){return"webtransport"}doOpen(){try{this.P=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this.P.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this.P.ready.then((()=>{this.P.createBidirectionalStream().then((t=>{const s=function(t,s){b||(b=new TextDecoder);const i=[];let n=0,r=-1,o=!1;return new TransformStream({transform(h,c){for(i.push(h);;){if(0===n){if(m(i)<1)break;const t=v(i,1);o=!(128&~t[0]),r=127&t[0],n=r<126?3:126===r?1:2}else if(1===n){if(m(i)<2)break;const t=v(i,2);r=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),n=3}else if(2===n){if(m(i)<8)break;const t=v(i,8),s=new DataView(t.buffer,t.byteOffset,t.length),o=s.getUint32(0);if(o>Math.pow(2,21)-1){c.enqueue(e);break}r=o*Math.pow(2,32)+s.getUint32(4),n=3}else{if(m(i)<r)break;const t=v(i,r);c.enqueue(p(o?t:b.decode(t),s)),n=0}if(0===r||r>t){c.enqueue(e);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=t.readable.pipeThrough(s).getReader(),n=w();n.readable.pipeTo(t.writable),this.j=n.writable.getWriter();const r=()=>{i.read().then((({done:t,value:s})=>{t||(this.onPacket(s),r())})).catch((t=>{}))};r();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.j.write(o).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const e=t[s],i=s===t.length-1;this.j.write(e).then((()=>{i&&x((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this.P)||void 0===t||t.close()}}const F={websocket:X,webtransport:V,polling:$},z=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,G=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function J(t){if(t.length>8e3)throw"URI too long";const s=t,e=t.indexOf("["),i=t.indexOf("]");-1!=e&&-1!=i&&(t=t.substring(0,e)+t.substring(e,i).replace(/:/g,";")+t.substring(i,t.length));let n=z.exec(t||""),r={},o=14;for(;o--;)r[G[o]]=n[o]||"";return-1!=e&&-1!=i&&(r.source=s,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=function(t,s){const e=/\/{2,9}/g,i=s.replace(e,"/").split("/");"/"!=s.slice(0,1)&&0!==s.length||i.splice(0,1);"/"==s.slice(-1)&&i.splice(i.length-1,1);return i}(0,r.path),r.queryKey=function(t,s){const e={};return s.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,s,i){s&&(e[s]=i)})),e}(0,r.query),r}const K="function"==typeof addEventListener&&"function"==typeof removeEventListener,Q=[];K&&addEventListener("offline",(()=>{Q.forEach((t=>t()))}),!1);class Y extends k{constructor(t,s){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this.D=0,this.L=-1,this.M=-1,this.S=-1,this.R=1/0,t&&"object"==typeof t&&(s=t,t=null),t){const e=J(t);s.hostname=e.host,s.secure="https"===e.protocol||"wss"===e.protocol,s.port=e.port,e.query&&(s.query=e.query)}else s.host&&(s.hostname=J(s.host).host);O(this,s),this.secure=null!=s.secure?s.secure:"undefined"!=typeof location&&"https:"===location.protocol,s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=s.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this.H={},s.transports.forEach((t=>{const s=t.prototype.name;this.transports.push(s),this.H[s]=t})),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let s={},e=t.split("&");for(let t=0,i=e.length;t<i;t++){let i=e[t].split("=");s[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return s}(this.opts.query)),K&&(this.opts.closeOnBeforeunload&&(this.$=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.$,!1)),"localhost"!==this.hostname&&(this.q=()=>{this.I("transport close",{description:"network connection lost"})},Q.push(this.q))),this.opts.withCredentials&&(this.W=void 0),this.N()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=4,s.transport=t,this.id&&(s.sid=this.id);const e=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this.H[t](e)}N(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const t=this.opts.rememberUpgrade&&Y.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const s=this.createTransport(t);s.open(),this.setTransport(s)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.X.bind(this)).on("packet",this.V.bind(this)).on("error",this.O.bind(this)).on("close",(t=>this.I("transport close",t)))}onOpen(){this.readyState="open",Y.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}V(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this.F("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this.G();break;case"error":const s=new Error("server error");s.code=t.data,this.O(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.L=t.pingInterval,this.M=t.pingTimeout,this.S=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.G()}G(){this.clearTimeoutFn(this.J);const t=this.L+this.M;this.R=Date.now()+t,this.J=this.setTimeoutFn((()=>{this.I("ping timeout")}),t),this.opts.autoUnref&&this.J.unref()}X(){this.writeBuffer.splice(0,this.D),this.D=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.K();this.transport.send(t),this.D=t.length,this.emitReserved("flush")}}K(){if(!(this.S&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let e=0;e<this.writeBuffer.length;e++){const i=this.writeBuffer[e].data;if(i&&(t+="string"==typeof(s=i)?function(t){let s=0,e=0;for(let i=0,n=t.length;i<n;i++)s=t.charCodeAt(i),s<128?e+=1:s<2048?e+=2:s<55296||s>=57344?e+=3:(i++,e+=4);return e}(s):Math.ceil(1.33*(s.byteLength||s.size))),e>0&&t>this.S)return this.writeBuffer.slice(0,e);t+=2}var s;return this.writeBuffer}Y(){if(!this.R)return!0;const t=Date.now()>this.R;return t&&(this.R=0,x((()=>{this.I("ping timeout")}),this.setTimeoutFn)),t}write(t,s,e){return this.F("message",t,s,e),this}send(t,s,e){return this.F("message",t,s,e),this}F(t,s,e,i){if("function"==typeof s&&(i=s,s=void 0),"function"==typeof e&&(i=e,e=null),"closing"===this.readyState||"closed"===this.readyState)return;(e=e||{}).compress=!1!==e.compress;const n={type:t,data:s,options:e};this.emitReserved("packetCreate",n),this.writeBuffer.push(n),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this.I("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},e=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?e():t()})):this.upgrading?e():t()),this}O(t){if(Y.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this.N();this.emitReserved("error",t),this.I("transport error",t)}I(t,s){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this.J),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),K&&(this.$&&removeEventListener("beforeunload",this.$,!1),this.q)){const t=Q.indexOf(this.q);-1!==t&&Q.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this.D=0}}}Y.protocol=4;class Z extends Y{constructor(){super(...arguments),this.Z=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this.Z.length;t++)this.tt(this.Z[t])}tt(t){let s=this.createTransport(t),e=!1;Y.priorWebsocketSuccess=!1;const i=()=>{e||(s.send([{type:"ping",data:"probe"}]),s.once("packet",(t=>{if(!e)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;Y.priorWebsocketSuccess="websocket"===s.name,this.transport.pause((()=>{e||"closed"!==this.readyState&&(a(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=s.name,this.emitReserved("upgradeError",t)}})))};function n(){e||(e=!0,a(),s.close(),s=null)}const r=t=>{const e=new Error("probe error: "+t);e.transport=s.name,n(),this.emitReserved("upgradeError",e)};function o(){r("transport closed")}function h(){r("socket closed")}function c(t){s&&t.name!==s.name&&n()}const a=()=>{s.removeListener("open",i),s.removeListener("error",r),s.removeListener("close",o),this.off("close",h),this.off("upgrading",c)};s.once("open",i),s.once("error",r),s.once("close",o),this.once("close",h),this.once("upgrading",c),-1!==this.Z.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn((()=>{e||s.open()}),200):s.open()}onHandshake(t){this.Z=this.st(t.upgrades),super.onHandshake(t)}st(t){const s=[];for(let e=0;e<t.length;e++)~this.transports.indexOf(t[e])&&s.push(t[e]);return s}}class tt extends Z{constructor(t,s={}){const e="object"==typeof t?t:s;(!e.transports||e.transports&&"string"==typeof e.transports[0])&&(e.transports=(e.transports||["polling","websocket","webtransport"]).map((t=>F[t])).filter((t=>!!t))),super(t,e)}}class st extends P{doPoll(){this.et().then((t=>{if(!t.ok)return this.onError("fetch read error",t.status,t);t.text().then((t=>this.onData(t)))})).catch((t=>{this.onError("fetch read error",t)}))}doWrite(t,s){this.et(t).then((t=>{if(!t.ok)return this.onError("fetch write error",t.status,t);s()})).catch((t=>{this.onError("fetch write error",t)}))}et(t){var s;const e=void 0!==t,i=new Headers(this.opts.extraHeaders);return e&&i.set("content-type","text/plain;charset=UTF-8"),null===(s=this.socket.W)||void 0===s||s.appendCookies(i),fetch(this.uri(),{method:e?"POST":"GET",body:e?t:null,headers:i,credentials:this.opts.withCredentials?"include":"omit"}).then((t=>{var s;return null===(s=this.socket.W)||void 0===s||s.parseCookies(t.headers.getSetCookie()),t}))}}const et=tt.protocol;export{st as Fetch,X as NodeWebSocket,$ as NodeXHR,tt as Socket,Z as SocketWithUpgrade,Y as SocketWithoutUpgrade,C as Transport,_ as TransportError,X as WebSocket,V as WebTransport,$ as XHR,O as installTimerFunctions,x as nextTick,J as parse,et as protocol,F as transports};
6
+ const t=Object.create(null);t.open="0",t.close="1",t.ping="2",t.pong="3",t.message="4",t.upgrade="5",t.noop="6";const s=Object.create(null);Object.keys(t).forEach((e=>{s[t[e]]=e}));const e={type:"error",data:"parser error"},i="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),n="function"==typeof ArrayBuffer,r=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,o=({type:s,data:e},o,c)=>i&&e instanceof Blob?o?c(e):h(e,c):n&&(e instanceof ArrayBuffer||r(e))?o?c(e):h(new Blob([e]),c):c(t[s]+(e||"")),h=(t,s)=>{const e=new FileReader;return e.onload=function(){const t=e.result.split(",")[1];s("b"+(t||""))},e.readAsDataURL(t)};function c(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let a;const u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)f[u.charCodeAt(t)]=t;const l="function"==typeof ArrayBuffer,p=(t,i)=>{if("string"!=typeof t)return{type:"message",data:y(t,i)};const n=t.charAt(0);if("b"===n)return{type:"message",data:d(t.substring(1),i)};return s[n]?t.length>1?{type:s[n],data:t.substring(1)}:{type:s[n]}:e},d=(t,s)=>{if(l){const e=(t=>{let s,e,i,n,r,o=.75*t.length,h=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const a=new ArrayBuffer(o),u=new Uint8Array(a);for(s=0;s<h;s+=4)e=f[t.charCodeAt(s)],i=f[t.charCodeAt(s+1)],n=f[t.charCodeAt(s+2)],r=f[t.charCodeAt(s+3)],u[c++]=e<<2|i>>4,u[c++]=(15&i)<<4|n>>2,u[c++]=(3&n)<<6|63&r;return a})(t);return y(e,s)}return{base64:!0,data:t}},y=(t,s)=>"blob"===s?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,g=String.fromCharCode(30);function w(){return new TransformStream({transform(t,s){!function(t,s){i&&t.data instanceof Blob?t.data.arrayBuffer().then(c).then(s):n&&(t.data instanceof ArrayBuffer||r(t.data))?s(c(t.data)):o(t,!1,(t=>{a||(a=new TextEncoder),s(a.encode(t))}))}(t,(e=>{const i=e.length;let n;if(i<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,i);else if(i<65536){n=new Uint8Array(3);const t=new DataView(n.buffer);t.setUint8(0,126),t.setUint16(1,i)}else{n=new Uint8Array(9);const t=new DataView(n.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(i))}t.data&&"string"!=typeof t.data&&(n[0]|=128),s.enqueue(n),s.enqueue(e)}))}})}let b;function m(t){return t.reduce(((t,s)=>t+s.length),0)}function v(t,s){if(t[0].length===s)return t.shift();const e=new Uint8Array(s);let i=0;for(let n=0;n<s;n++)e[n]=t[0][i++],i===t[0].length&&(t.shift(),i=0);return t.length&&i<t[0].length&&(t[0]=t[0].slice(i)),e}function k(t){if(t)return function(t){for(var s in k.prototype)t[s]=k.prototype[s];return t}(t)}k.prototype.on=k.prototype.addEventListener=function(t,s){return this.t=this.t||{},(this.t["$"+t]=this.t["$"+t]||[]).push(s),this},k.prototype.once=function(t,s){function e(){this.off(t,e),s.apply(this,arguments)}return e.fn=s,this.on(t,e),this},k.prototype.off=k.prototype.removeListener=k.prototype.removeAllListeners=k.prototype.removeEventListener=function(t,s){if(this.t=this.t||{},0==arguments.length)return this.t={},this;var e,i=this.t["$"+t];if(!i)return this;if(1==arguments.length)return delete this.t["$"+t],this;for(var n=0;n<i.length;n++)if((e=i[n])===s||e.fn===s){i.splice(n,1);break}return 0===i.length&&delete this.t["$"+t],this},k.prototype.emit=function(t){this.t=this.t||{};for(var s=new Array(arguments.length-1),e=this.t["$"+t],i=1;i<arguments.length;i++)s[i-1]=arguments[i];if(e){i=0;for(var n=(e=e.slice(0)).length;i<n;++i)e[i].apply(this,s)}return this},k.prototype.emitReserved=k.prototype.emit,k.prototype.listeners=function(t){return this.t=this.t||{},this.t["$"+t]||[]},k.prototype.hasListeners=function(t){return!!this.listeners(t).length};const E="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,s)=>s(t,0),x="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function A(t,...s){return s.reduce(((s,e)=>(t.hasOwnProperty(e)&&(s[e]=t[e]),s)),{})}const U=x.setTimeout,B=x.clearTimeout;function O(t,s){s.useNativeTimers?(t.setTimeoutFn=U.bind(x),t.clearTimeoutFn=B.bind(x)):(t.setTimeoutFn=x.setTimeout.bind(x),t.clearTimeoutFn=x.clearTimeout.bind(x))}function T(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class _ extends Error{constructor(t,s,e){super(t),this.description=s,this.context=e,this.type="TransportError"}}class C extends k{constructor(t){super(),this.writable=!1,O(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,e){return super.emitReserved("error",new _(t,s,e)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=p(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this.i()+this.o()+this.opts.path+this.h(s)}i(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}o(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}h(t){const s=function(t){let s="";for(let e in t)t.hasOwnProperty(e)&&(s.length&&(s+="&"),s+=encodeURIComponent(e)+"="+encodeURIComponent(t[e]));return s}(t);return s.length?"?"+s:""}}class P extends C{constructor(){super(...arguments),this.u=!1}get name(){return"polling"}doOpen(){this.l()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this.u||!this.writable){let t=0;this.u&&(t++,this.once("pollComplete",(function(){--t||s()}))),this.writable||(t++,this.once("drain",(function(){--t||s()})))}else s()}l(){this.u=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,s)=>{const e=t.split(g),i=[];for(let t=0;t<e.length;t++){const n=p(e[t],s);if(i.push(n),"error"===n.type)break}return i})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this.u=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.l())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,s)=>{const e=t.length,i=new Array(e);let n=0;t.forEach(((t,r)=>{o(t,!1,(t=>{i[r]=t,++n===e&&s(i.join(g))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return!1!==this.opts.timestampRequests&&(s[this.opts.timestampParam]=T()),this.supportsBinary||s.sid||(s.b64=1),this.createUri(t,s)}}let j=!1;try{j="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const D=j;function L(){}class M extends P{constructor(t){if(super(t),"undefined"!=typeof location){const s="https:"===location.protocol;let e=location.port;e||(e=s?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||e!==t.port}}doWrite(t,s){const e=this.request({method:"POST",data:t});e.on("success",s),e.on("error",((t,s)=>{this.onError("xhr post error",t,s)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,s)=>{this.onError("xhr poll error",t,s)})),this.pollXhr=t}}class S extends k{constructor(t,s,e){super(),this.createRequest=t,O(this,e),this.p=e,this.m=e.method||"GET",this.v=s,this.k=void 0!==e.data?e.data:null,this.A()}A(){var t;const s=A(this.p,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this.p.xd;const e=this.U=this.createRequest(s);try{e.open(this.m,this.v,!0);try{if(this.p.extraHeaders){e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0);for(let t in this.p.extraHeaders)this.p.extraHeaders.hasOwnProperty(t)&&e.setRequestHeader(t,this.p.extraHeaders[t])}}catch(t){}if("POST"===this.m)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this.p.cookieJar)||void 0===t||t.addCookies(e),"withCredentials"in e&&(e.withCredentials=this.p.withCredentials),this.p.requestTimeout&&(e.timeout=this.p.requestTimeout),e.onreadystatechange=()=>{var t;3===e.readyState&&(null===(t=this.p.cookieJar)||void 0===t||t.parseCookies(e.getResponseHeader("set-cookie"))),4===e.readyState&&(200===e.status||1223===e.status?this.B():this.setTimeoutFn((()=>{this.O("number"==typeof e.status?e.status:0)}),0))},e.send(this.k)}catch(t){return void this.setTimeoutFn((()=>{this.O(t)}),0)}"undefined"!=typeof document&&(this.T=S.requestsCount++,S.requests[this.T]=this)}O(t){this.emitReserved("error",t,this.U),this._(!0)}_(t){if(void 0!==this.U&&null!==this.U){if(this.U.onreadystatechange=L,t)try{this.U.abort()}catch(t){}"undefined"!=typeof document&&delete S.requests[this.T],this.U=null}}B(){const t=this.U.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._())}abort(){this._()}}if(S.requestsCount=0,S.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",R);else if("function"==typeof addEventListener){addEventListener("onpagehide"in x?"pagehide":"unload",R,!1)}function R(){for(let t in S.requests)S.requests.hasOwnProperty(t)&&S.requests[t].abort()}const I=function(){const t=q({xdomain:!1});return t&&null!==t.responseType}();class $ extends M{constructor(t){super(t);const s=t&&t.forceBase64;this.supportsBinary=I&&!s}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new S(q,this.uri(),t)}}function q(t){const s=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!s||D))return new XMLHttpRequest}catch(t){}if(!s)try{return new(x[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const H="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class W extends C{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,e=H?{}:A(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(e.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,e)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws.C.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const e=t[s],i=s===t.length-1;o(e,this.supportsBinary,(t=>{try{this.doWrite(e,t)}catch(t){}i&&E((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=T()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const N=x.WebSocket||x.MozWebSocket;class X extends W{createSocket(t,s,e){return H?new N(t,s,e):s?new N(t,s):new N(t)}doWrite(t,s){this.ws.send(s)}}class V extends C{get name(){return"webtransport"}doOpen(){try{this.P=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this.P.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this.P.ready.then((()=>{this.P.createBidirectionalStream().then((t=>{const s=function(t,s){b||(b=new TextDecoder);const i=[];let n=0,r=-1,o=!1;return new TransformStream({transform(h,c){for(i.push(h);;){if(0===n){if(m(i)<1)break;const t=v(i,1);o=!(128&~t[0]),r=127&t[0],n=r<126?3:126===r?1:2}else if(1===n){if(m(i)<2)break;const t=v(i,2);r=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),n=3}else if(2===n){if(m(i)<8)break;const t=v(i,8),s=new DataView(t.buffer,t.byteOffset,t.length),o=s.getUint32(0);if(o>Math.pow(2,21)-1){c.enqueue(e);break}r=o*Math.pow(2,32)+s.getUint32(4),n=3}else{if(m(i)<r)break;const t=v(i,r);c.enqueue(p(o?t:b.decode(t),s)),n=0}if(0===r||r>t){c.enqueue(e);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=t.readable.pipeThrough(s).getReader(),n=w();n.readable.pipeTo(t.writable),this.j=n.writable.getWriter();const r=()=>{i.read().then((({done:t,value:s})=>{t||(this.onPacket(s),r())})).catch((t=>{}))};r();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.j.write(o).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const e=t[s],i=s===t.length-1;this.j.write(e).then((()=>{i&&E((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this.P)||void 0===t||t.close()}}const F={websocket:X,webtransport:V,polling:$},z=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,G=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function J(t){if(t.length>8e3)throw"URI too long";const s=t,e=t.indexOf("["),i=t.indexOf("]");-1!=e&&-1!=i&&(t=t.substring(0,e)+t.substring(e,i).replace(/:/g,";")+t.substring(i,t.length));let n=z.exec(t||""),r={},o=14;for(;o--;)r[G[o]]=n[o]||"";return-1!=e&&-1!=i&&(r.source=s,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=function(t,s){const e=/\/{2,9}/g,i=s.replace(e,"/").split("/");"/"!=s.slice(0,1)&&0!==s.length||i.splice(0,1);"/"==s.slice(-1)&&i.splice(i.length-1,1);return i}(0,r.path),r.queryKey=function(t,s){const e={};return s.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,s,i){s&&(e[s]=i)})),e}(0,r.query),r}const K="function"==typeof addEventListener&&"function"==typeof removeEventListener,Q=[];K&&addEventListener("offline",(()=>{Q.forEach((t=>t()))}),!1);class Y extends k{constructor(t,s={}){var e,i;if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this.D=0,this.L=[],this.M=-1,this.S=-1,this.R=-1,this.I=1/0,t&&"object"==typeof t&&(s=t,t=null),t){const e=J(t);s.hostname=e.host,s.secure="https"===e.protocol||"wss"===e.protocol,s.port=e.port,e.query&&(s.query=e.query)}else s.host&&(s.hostname=J(s.host).host);if(O(this,s),this.secure=null!=s.secure?s.secure:"undefined"!=typeof location&&"https:"===location.protocol,s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=s.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),s.transportImplementations&&s.transports)throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");s.transportImplementations||(null===(e=s.transports)||void 0===e?void 0:e.length)&&"function"==typeof s.transports[0]?(this.transports=[],this.$=Object.create(null),(null!==(i=s.transportImplementations)&&void 0!==i?i:s.transports).forEach((t=>{const s=t.prototype.name;this.transports.push(s),this.$[s]=t}))):(this.transports=s.transports?[...s.transports]:["polling","websocket","webtransport"],this.$=F),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let s={},e=t.split("&");for(let t=0,i=e.length;t<i;t++){let i=e[t].split("=");s[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return s}(this.opts.query)),K&&(this.opts.closeOnBeforeunload&&(this.q=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.q,!1)),"localhost"!==this.hostname&&(this.H=()=>{this.W("transport close",{description:"network connection lost"})},Q.push(this.H))),this.opts.withCredentials&&(this.N=void 0),this.X()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=4,s.transport=t,this.id&&(s.sid=this.id);const e=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this.$[t](e)}X(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const t=this.opts.rememberUpgrade&&Y.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const s=this.createTransport(t);s.open(),this.setTransport(s)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.V.bind(this)).on("packet",this.F.bind(this)).on("error",this.O.bind(this)).on("close",(t=>this.W("transport close",t)))}G(t){let s=this.createTransport(t),e=!1;Y.priorWebsocketSuccess=!1;const i=()=>{e||(s.send([{type:"ping",data:"probe"}]),s.once("packet",(t=>{if(!e)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;Y.priorWebsocketSuccess="websocket"===s.name,this.transport.pause((()=>{e||"closed"!==this.readyState&&(a(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=s.name,this.emitReserved("upgradeError",t)}})))};function n(){e||(e=!0,a(),s.close(),s=null)}const r=t=>{const e=new Error("probe error: "+t);e.transport=s.name,n(),this.emitReserved("upgradeError",e)};function o(){r("transport closed")}function h(){r("socket closed")}function c(t){s&&t.name!==s.name&&n()}const a=()=>{s.removeListener("open",i),s.removeListener("error",r),s.removeListener("close",o),this.off("close",h),this.off("upgrading",c)};s.once("open",i),s.once("error",r),s.once("close",o),this.once("close",h),this.once("upgrading",c),-1!==this.L.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn((()=>{e||s.open()}),200):s.open()}onOpen(){if(this.readyState="open",Y.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this.L.length;t++)this.G(this.L[t])}F(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this.J("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this.K();break;case"error":const s=new Error("server error");s.code=t.data,this.O(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.L=this.Y(t.upgrades),this.M=t.pingInterval,this.S=t.pingTimeout,this.R=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.K()}K(){this.clearTimeoutFn(this.Z);const t=this.M+this.S;this.I=Date.now()+t,this.Z=this.setTimeoutFn((()=>{this.W("ping timeout")}),t),this.opts.autoUnref&&this.Z.unref()}V(){this.writeBuffer.splice(0,this.D),this.D=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.tt();this.transport.send(t),this.D=t.length,this.emitReserved("flush")}}tt(){if(!(this.R&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let e=0;e<this.writeBuffer.length;e++){const i=this.writeBuffer[e].data;if(i&&(t+="string"==typeof(s=i)?function(t){let s=0,e=0;for(let i=0,n=t.length;i<n;i++)s=t.charCodeAt(i),s<128?e+=1:s<2048?e+=2:s<55296||s>=57344?e+=3:(i++,e+=4);return e}(s):Math.ceil(1.33*(s.byteLength||s.size))),e>0&&t>this.R)return this.writeBuffer.slice(0,e);t+=2}var s;return this.writeBuffer}st(){if(!this.I)return!0;const t=Date.now()>this.I;return t&&(this.I=0,E((()=>{this.W("ping timeout")}),this.setTimeoutFn)),t}write(t,s,e){return this.J("message",t,s,e),this}send(t,s,e){return this.J("message",t,s,e),this}J(t,s,e,i){if("function"==typeof s&&(i=s,s=void 0),"function"==typeof e&&(i=e,e=null),"closing"===this.readyState||"closed"===this.readyState)return;(e=e||{}).compress=!1!==e.compress;const n={type:t,data:s,options:e};this.emitReserved("packetCreate",n),this.writeBuffer.push(n),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this.W("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},e=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?e():t()})):this.upgrading?e():t()),this}O(t){if(Y.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this.X();this.emitReserved("error",t),this.W("transport error",t)}W(t,s){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this.Z),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),K&&(this.q&&removeEventListener("beforeunload",this.q,!1),this.H)){const t=Q.indexOf(this.H);-1!==t&&Q.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this.D=0}}Y(t){const s=[];for(let e=0;e<t.length;e++)~this.transports.indexOf(t[e])&&s.push(t[e]);return s}}Y.protocol=4;class Z extends P{doPoll(){this.et().then((t=>{if(!t.ok)return this.onError("fetch read error",t.status,t);t.text().then((t=>this.onData(t)))})).catch((t=>{this.onError("fetch read error",t)}))}doWrite(t,s){this.et(t).then((t=>{if(!t.ok)return this.onError("fetch write error",t.status,t);s()})).catch((t=>{this.onError("fetch write error",t)}))}et(t){var s;const e=void 0!==t,i=new Headers(this.opts.extraHeaders);return e&&i.set("content-type","text/plain;charset=UTF-8"),null===(s=this.socket.N)||void 0===s||s.appendCookies(i),fetch(this.uri(),{method:e?"POST":"GET",body:e?t:null,headers:i,credentials:this.opts.withCredentials?"include":"omit"}).then((t=>{var s;return null===(s=this.socket.N)||void 0===s||s.parseCookies(t.headers.getSetCookie()),t}))}}const tt=Y.protocol;export{Z as Fetch,X as NodeWebSocket,$ as NodeXHR,Y as Socket,C as Transport,_ as TransportError,X as WebSocket,V as WebTransport,$ as XHR,O as installTimerFunctions,E as nextTick,J as parse,tt as protocol,F as transports};
7
7
  //# sourceMappingURL=engine.io.esm.min.js.map