@saar-ai/web-widget 0.2.0

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 (72) hide show
  1. package/README.md +209 -0
  2. package/dist/bot-avatar.d.ts +41 -0
  3. package/dist/bot-avatar.d.ts.map +1 -0
  4. package/dist/bot-face.d.ts +39 -0
  5. package/dist/bot-face.d.ts.map +1 -0
  6. package/dist/bot-state.d.ts +39 -0
  7. package/dist/bot-state.d.ts.map +1 -0
  8. package/dist/chunks/chat-ZLxYRTml.js +173 -0
  9. package/dist/chunks/esm-DSxqq2-d.js +3299 -0
  10. package/dist/chunks/host-widget-iy3qC-1p.js +7677 -0
  11. package/dist/chunks/livekit-client.esm-OPuvn_z-.js +26600 -0
  12. package/dist/chunks/schemas-Bl_6mxe4.js +4123 -0
  13. package/dist/chunks/telemetry-Bw-3F_Zk.js +290 -0
  14. package/dist/cn.d.ts +14 -0
  15. package/dist/cn.d.ts.map +1 -0
  16. package/dist/concierge-launcher.d.ts +50 -0
  17. package/dist/concierge-launcher.d.ts.map +1 -0
  18. package/dist/concierge-shell.d.ts +194 -0
  19. package/dist/concierge-shell.d.ts.map +1 -0
  20. package/dist/error-boundary.d.ts +34 -0
  21. package/dist/error-boundary.d.ts.map +1 -0
  22. package/dist/format-money.d.ts +20 -0
  23. package/dist/format-money.d.ts.map +1 -0
  24. package/dist/generated/widget-css.d.ts +2 -0
  25. package/dist/generated/widget-css.d.ts.map +1 -0
  26. package/dist/host-widget.d.ts +165 -0
  27. package/dist/host-widget.d.ts.map +1 -0
  28. package/dist/index.d.ts +28 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +583 -0
  31. package/dist/messages.d.ts +116 -0
  32. package/dist/messages.d.ts.map +1 -0
  33. package/dist/morphing-loader.d.ts +16 -0
  34. package/dist/morphing-loader.d.ts.map +1 -0
  35. package/dist/mount.d.ts +45 -0
  36. package/dist/mount.d.ts.map +1 -0
  37. package/dist/next/index.d.ts +3 -0
  38. package/dist/next/index.d.ts.map +1 -0
  39. package/dist/next/index.js +86 -0
  40. package/dist/next/use-next-bridge.d.ts +113 -0
  41. package/dist/next/use-next-bridge.d.ts.map +1 -0
  42. package/dist/position.d.ts +65 -0
  43. package/dist/position.d.ts.map +1 -0
  44. package/dist/session-log.d.ts +84 -0
  45. package/dist/session-log.d.ts.map +1 -0
  46. package/dist/session-panel.d.ts +15 -0
  47. package/dist/session-panel.d.ts.map +1 -0
  48. package/dist/sse-parser.d.ts +38 -0
  49. package/dist/sse-parser.d.ts.map +1 -0
  50. package/dist/styles.d.ts +19 -0
  51. package/dist/styles.d.ts.map +1 -0
  52. package/dist/text-direction.d.ts +49 -0
  53. package/dist/text-direction.d.ts.map +1 -0
  54. package/dist/use-chat-session.d.ts +344 -0
  55. package/dist/use-chat-session.d.ts.map +1 -0
  56. package/dist/use-voice-session.d.ts +273 -0
  57. package/dist/use-voice-session.d.ts.map +1 -0
  58. package/dist/voice-session-state.d.ts +44 -0
  59. package/dist/voice-session-state.d.ts.map +1 -0
  60. package/dist/voice-widget.d.ts +167 -0
  61. package/dist/voice-widget.d.ts.map +1 -0
  62. package/dist/widget-cards.d.ts +69 -0
  63. package/dist/widget-cards.d.ts.map +1 -0
  64. package/dist/widget-cart-summary.d.ts +66 -0
  65. package/dist/widget-cart-summary.d.ts.map +1 -0
  66. package/dist/widget-markdown.d.ts +33 -0
  67. package/dist/widget-markdown.d.ts.map +1 -0
  68. package/dist/widget.css +2 -0
  69. package/package.json +88 -0
  70. package/src/styles/concierge.css +351 -0
  71. package/src/styles/tokens.css +67 -0
  72. package/src/styles/widget-entry.css +13 -0
@@ -0,0 +1,3299 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ //#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/commons.js
14
+ var PACKET_TYPES = Object.create(null);
15
+ PACKET_TYPES["open"] = "0";
16
+ PACKET_TYPES["close"] = "1";
17
+ PACKET_TYPES["ping"] = "2";
18
+ PACKET_TYPES["pong"] = "3";
19
+ PACKET_TYPES["message"] = "4";
20
+ PACKET_TYPES["upgrade"] = "5";
21
+ PACKET_TYPES["noop"] = "6";
22
+ var PACKET_TYPES_REVERSE = Object.create(null);
23
+ Object.keys(PACKET_TYPES).forEach((key) => {
24
+ PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
25
+ });
26
+ var ERROR_PACKET = {
27
+ type: "error",
28
+ data: "parser error"
29
+ };
30
+ //#endregion
31
+ //#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/encodePacket.browser.js
32
+ var withNativeBlob$1 = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
33
+ var withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
34
+ var isView$1 = (obj) => {
35
+ return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
36
+ };
37
+ var encodePacket = ({ type, data }, supportsBinary, callback) => {
38
+ if (withNativeBlob$1 && data instanceof Blob) if (supportsBinary) return callback(data);
39
+ else return encodeBlobAsBase64(data, callback);
40
+ else if (withNativeArrayBuffer$2 && (data instanceof ArrayBuffer || isView$1(data))) if (supportsBinary) return callback(data);
41
+ else return encodeBlobAsBase64(new Blob([data]), callback);
42
+ return callback(PACKET_TYPES[type] + (data || ""));
43
+ };
44
+ var encodeBlobAsBase64 = (data, callback) => {
45
+ const fileReader = new FileReader();
46
+ fileReader.onload = function() {
47
+ const content = fileReader.result.split(",")[1];
48
+ callback("b" + (content || ""));
49
+ };
50
+ return fileReader.readAsDataURL(data);
51
+ };
52
+ function toArray(data) {
53
+ if (data instanceof Uint8Array) return data;
54
+ else if (data instanceof ArrayBuffer) return new Uint8Array(data);
55
+ else return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
56
+ }
57
+ var TEXT_ENCODER;
58
+ function encodePacketToBinary(packet, callback) {
59
+ if (withNativeBlob$1 && packet.data instanceof Blob) return packet.data.arrayBuffer().then(toArray).then(callback);
60
+ else if (withNativeArrayBuffer$2 && (packet.data instanceof ArrayBuffer || isView$1(packet.data))) return callback(toArray(packet.data));
61
+ encodePacket(packet, false, (encoded) => {
62
+ if (!TEXT_ENCODER) TEXT_ENCODER = new TextEncoder();
63
+ callback(TEXT_ENCODER.encode(encoded));
64
+ });
65
+ }
66
+ //#endregion
67
+ //#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
68
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
69
+ var lookup$1 = typeof Uint8Array === "undefined" ? [] : new Uint8Array(256);
70
+ for (let i = 0; i < 64; i++) lookup$1[chars.charCodeAt(i)] = i;
71
+ var decode$1 = (base64) => {
72
+ let bufferLength = base64.length * .75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
73
+ if (base64[base64.length - 1] === "=") {
74
+ bufferLength--;
75
+ if (base64[base64.length - 2] === "=") bufferLength--;
76
+ }
77
+ const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
78
+ for (i = 0; i < len; i += 4) {
79
+ encoded1 = lookup$1[base64.charCodeAt(i)];
80
+ encoded2 = lookup$1[base64.charCodeAt(i + 1)];
81
+ encoded3 = lookup$1[base64.charCodeAt(i + 2)];
82
+ encoded4 = lookup$1[base64.charCodeAt(i + 3)];
83
+ bytes[p++] = encoded1 << 2 | encoded2 >> 4;
84
+ bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
85
+ bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
86
+ }
87
+ return arraybuffer;
88
+ };
89
+ //#endregion
90
+ //#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/decodePacket.browser.js
91
+ var withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
92
+ var decodePacket = (encodedPacket, binaryType) => {
93
+ if (typeof encodedPacket !== "string") return {
94
+ type: "message",
95
+ data: mapBinary(encodedPacket, binaryType)
96
+ };
97
+ const type = encodedPacket.charAt(0);
98
+ if (type === "b") return {
99
+ type: "message",
100
+ data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
101
+ };
102
+ if (!PACKET_TYPES_REVERSE[type]) return ERROR_PACKET;
103
+ return encodedPacket.length > 1 ? {
104
+ type: PACKET_TYPES_REVERSE[type],
105
+ data: encodedPacket.substring(1)
106
+ } : { type: PACKET_TYPES_REVERSE[type] };
107
+ };
108
+ var decodeBase64Packet = (data, binaryType) => {
109
+ if (withNativeArrayBuffer$1) return mapBinary(decode$1(data), binaryType);
110
+ else return {
111
+ base64: true,
112
+ data
113
+ };
114
+ };
115
+ var mapBinary = (data, binaryType) => {
116
+ switch (binaryType) {
117
+ case "blob": if (data instanceof Blob) return data;
118
+ else return new Blob([data]);
119
+ default: if (data instanceof ArrayBuffer) return data;
120
+ else return data.buffer;
121
+ }
122
+ };
123
+ //#endregion
124
+ //#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/index.js
125
+ var SEPARATOR = String.fromCharCode(30);
126
+ var encodePayload = (packets, callback) => {
127
+ const length = packets.length;
128
+ const encodedPackets = new Array(length);
129
+ let count = 0;
130
+ packets.forEach((packet, i) => {
131
+ encodePacket(packet, false, (encodedPacket) => {
132
+ encodedPackets[i] = encodedPacket;
133
+ if (++count === length) callback(encodedPackets.join(SEPARATOR));
134
+ });
135
+ });
136
+ };
137
+ var decodePayload = (encodedPayload, binaryType) => {
138
+ const encodedPackets = encodedPayload.split(SEPARATOR);
139
+ const packets = [];
140
+ for (let i = 0; i < encodedPackets.length; i++) {
141
+ const decodedPacket = decodePacket(encodedPackets[i], binaryType);
142
+ packets.push(decodedPacket);
143
+ if (decodedPacket.type === "error") break;
144
+ }
145
+ return packets;
146
+ };
147
+ function createPacketEncoderStream() {
148
+ return new TransformStream({ transform(packet, controller) {
149
+ encodePacketToBinary(packet, (encodedPacket) => {
150
+ const payloadLength = encodedPacket.length;
151
+ let header;
152
+ if (payloadLength < 126) {
153
+ header = new Uint8Array(1);
154
+ new DataView(header.buffer).setUint8(0, payloadLength);
155
+ } else if (payloadLength < 65536) {
156
+ header = new Uint8Array(3);
157
+ const view = new DataView(header.buffer);
158
+ view.setUint8(0, 126);
159
+ view.setUint16(1, payloadLength);
160
+ } else {
161
+ header = new Uint8Array(9);
162
+ const view = new DataView(header.buffer);
163
+ view.setUint8(0, 127);
164
+ view.setBigUint64(1, BigInt(payloadLength));
165
+ }
166
+ if (packet.data && typeof packet.data !== "string") header[0] |= 128;
167
+ controller.enqueue(header);
168
+ controller.enqueue(encodedPacket);
169
+ });
170
+ } });
171
+ }
172
+ var TEXT_DECODER;
173
+ function totalLength(chunks) {
174
+ return chunks.reduce((acc, chunk) => acc + chunk.length, 0);
175
+ }
176
+ function concatChunks(chunks, size) {
177
+ if (chunks[0].length === size) return chunks.shift();
178
+ const buffer = new Uint8Array(size);
179
+ let j = 0;
180
+ for (let i = 0; i < size; i++) {
181
+ buffer[i] = chunks[0][j++];
182
+ if (j === chunks[0].length) {
183
+ chunks.shift();
184
+ j = 0;
185
+ }
186
+ }
187
+ if (chunks.length && j < chunks[0].length) chunks[0] = chunks[0].slice(j);
188
+ return buffer;
189
+ }
190
+ function createPacketDecoderStream(maxPayload, binaryType) {
191
+ if (!TEXT_DECODER) TEXT_DECODER = new TextDecoder();
192
+ const chunks = [];
193
+ let state = 0;
194
+ let expectedLength = -1;
195
+ let isBinary = false;
196
+ return new TransformStream({ transform(chunk, controller) {
197
+ chunks.push(chunk);
198
+ while (true) {
199
+ if (state === 0) {
200
+ if (totalLength(chunks) < 1) break;
201
+ const header = concatChunks(chunks, 1);
202
+ isBinary = (header[0] & 128) === 128;
203
+ expectedLength = header[0] & 127;
204
+ if (expectedLength < 126) state = 3;
205
+ else if (expectedLength === 126) state = 1;
206
+ else state = 2;
207
+ } else if (state === 1) {
208
+ if (totalLength(chunks) < 2) break;
209
+ const headerArray = concatChunks(chunks, 2);
210
+ expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
211
+ state = 3;
212
+ } else if (state === 2) {
213
+ if (totalLength(chunks) < 8) break;
214
+ const headerArray = concatChunks(chunks, 8);
215
+ const view = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length);
216
+ const n = view.getUint32(0);
217
+ if (n > Math.pow(2, 21) - 1) {
218
+ controller.enqueue(ERROR_PACKET);
219
+ break;
220
+ }
221
+ expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
222
+ state = 3;
223
+ } else {
224
+ if (totalLength(chunks) < expectedLength) break;
225
+ const data = concatChunks(chunks, expectedLength);
226
+ controller.enqueue(decodePacket(isBinary ? data : TEXT_DECODER.decode(data), binaryType));
227
+ state = 0;
228
+ }
229
+ if (expectedLength === 0 || expectedLength > maxPayload) {
230
+ controller.enqueue(ERROR_PACKET);
231
+ break;
232
+ }
233
+ }
234
+ } });
235
+ }
236
+ //#endregion
237
+ //#region ../../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
238
+ /**
239
+ * Initialize a new `Emitter`.
240
+ *
241
+ * @api public
242
+ */
243
+ function Emitter(obj) {
244
+ if (obj) return mixin(obj);
245
+ }
246
+ /**
247
+ * Mixin the emitter properties.
248
+ *
249
+ * @param {Object} obj
250
+ * @return {Object}
251
+ * @api private
252
+ */
253
+ function mixin(obj) {
254
+ for (var key in Emitter.prototype) obj[key] = Emitter.prototype[key];
255
+ return obj;
256
+ }
257
+ /**
258
+ * Listen on the given `event` with `fn`.
259
+ *
260
+ * @param {String} event
261
+ * @param {Function} fn
262
+ * @return {Emitter}
263
+ * @api public
264
+ */
265
+ Emitter.prototype.on = Emitter.prototype.addEventListener = function(event, fn) {
266
+ this._callbacks = this._callbacks || {};
267
+ (this._callbacks["$" + event] = this._callbacks["$" + event] || []).push(fn);
268
+ return this;
269
+ };
270
+ /**
271
+ * Adds an `event` listener that will be invoked a single
272
+ * time then automatically removed.
273
+ *
274
+ * @param {String} event
275
+ * @param {Function} fn
276
+ * @return {Emitter}
277
+ * @api public
278
+ */
279
+ Emitter.prototype.once = function(event, fn) {
280
+ function on() {
281
+ this.off(event, on);
282
+ fn.apply(this, arguments);
283
+ }
284
+ on.fn = fn;
285
+ this.on(event, on);
286
+ return this;
287
+ };
288
+ /**
289
+ * Remove the given callback for `event` or all
290
+ * registered callbacks.
291
+ *
292
+ * @param {String} event
293
+ * @param {Function} fn
294
+ * @return {Emitter}
295
+ * @api public
296
+ */
297
+ Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function(event, fn) {
298
+ this._callbacks = this._callbacks || {};
299
+ if (0 == arguments.length) {
300
+ this._callbacks = {};
301
+ return this;
302
+ }
303
+ var callbacks = this._callbacks["$" + event];
304
+ if (!callbacks) return this;
305
+ if (1 == arguments.length) {
306
+ delete this._callbacks["$" + event];
307
+ return this;
308
+ }
309
+ var cb;
310
+ for (var i = 0; i < callbacks.length; i++) {
311
+ cb = callbacks[i];
312
+ if (cb === fn || cb.fn === fn) {
313
+ callbacks.splice(i, 1);
314
+ break;
315
+ }
316
+ }
317
+ if (callbacks.length === 0) delete this._callbacks["$" + event];
318
+ return this;
319
+ };
320
+ /**
321
+ * Emit `event` with the given args.
322
+ *
323
+ * @param {String} event
324
+ * @param {Mixed} ...
325
+ * @return {Emitter}
326
+ */
327
+ Emitter.prototype.emit = function(event) {
328
+ this._callbacks = this._callbacks || {};
329
+ var args = new Array(arguments.length - 1), callbacks = this._callbacks["$" + event];
330
+ for (var i = 1; i < arguments.length; i++) args[i - 1] = arguments[i];
331
+ if (callbacks) {
332
+ callbacks = callbacks.slice(0);
333
+ for (var i = 0, len = callbacks.length; i < len; ++i) callbacks[i].apply(this, args);
334
+ }
335
+ return this;
336
+ };
337
+ Emitter.prototype.emitReserved = Emitter.prototype.emit;
338
+ /**
339
+ * Return array of callbacks for `event`.
340
+ *
341
+ * @param {String} event
342
+ * @return {Array}
343
+ * @api public
344
+ */
345
+ Emitter.prototype.listeners = function(event) {
346
+ this._callbacks = this._callbacks || {};
347
+ return this._callbacks["$" + event] || [];
348
+ };
349
+ /**
350
+ * Check if this emitter has `event` handlers.
351
+ *
352
+ * @param {String} event
353
+ * @return {Boolean}
354
+ * @api public
355
+ */
356
+ Emitter.prototype.hasListeners = function(event) {
357
+ return !!this.listeners(event).length;
358
+ };
359
+ //#endregion
360
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/globals.js
361
+ var nextTick = (() => {
362
+ if (typeof Promise === "function" && typeof Promise.resolve === "function") return (cb) => Promise.resolve().then(cb);
363
+ else return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
364
+ })();
365
+ var globalThisShim = (() => {
366
+ if (typeof self !== "undefined") return self;
367
+ else if (typeof window !== "undefined") return window;
368
+ else return Function("return this")();
369
+ })();
370
+ var defaultBinaryType = "arraybuffer";
371
+ //#endregion
372
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/util.js
373
+ function pick(obj, ...attr) {
374
+ return attr.reduce((acc, k) => {
375
+ if (obj.hasOwnProperty(k)) acc[k] = obj[k];
376
+ return acc;
377
+ }, {});
378
+ }
379
+ var NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
380
+ var NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
381
+ function installTimerFunctions(obj, opts) {
382
+ if (opts.useNativeTimers) {
383
+ obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
384
+ obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
385
+ } else {
386
+ obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
387
+ obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
388
+ }
389
+ }
390
+ var BASE64_OVERHEAD = 1.33;
391
+ function byteLength(obj) {
392
+ if (typeof obj === "string") return utf8Length(obj);
393
+ return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
394
+ }
395
+ function utf8Length(str) {
396
+ let c = 0, length = 0;
397
+ for (let i = 0, l = str.length; i < l; i++) {
398
+ c = str.charCodeAt(i);
399
+ if (c < 128) length += 1;
400
+ else if (c < 2048) length += 2;
401
+ else if (c < 55296 || c >= 57344) length += 3;
402
+ else {
403
+ i++;
404
+ length += 4;
405
+ }
406
+ }
407
+ return length;
408
+ }
409
+ /**
410
+ * Generates a random 8-characters string.
411
+ */
412
+ function randomString() {
413
+ return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
414
+ }
415
+ //#endregion
416
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/contrib/parseqs.js
417
+ /**
418
+ * Compiles a querystring
419
+ * Returns string representation of the object
420
+ *
421
+ * @param {Object}
422
+ * @api private
423
+ */
424
+ function encode(obj) {
425
+ let str = "";
426
+ for (let i in obj) if (obj.hasOwnProperty(i)) {
427
+ if (str.length) str += "&";
428
+ str += encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]);
429
+ }
430
+ return str;
431
+ }
432
+ /**
433
+ * Parses a simple querystring into an object
434
+ *
435
+ * @param {String} qs
436
+ * @api private
437
+ */
438
+ function decode(qs) {
439
+ let qry = {};
440
+ let pairs = qs.split("&");
441
+ for (let i = 0, l = pairs.length; i < l; i++) {
442
+ let pair = pairs[i].split("=");
443
+ qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
444
+ }
445
+ return qry;
446
+ }
447
+ //#endregion
448
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/transport.js
449
+ var TransportError = class extends Error {
450
+ constructor(reason, description, context) {
451
+ super(reason);
452
+ this.description = description;
453
+ this.context = context;
454
+ this.type = "TransportError";
455
+ }
456
+ };
457
+ var Transport = class extends Emitter {
458
+ /**
459
+ * Transport abstract constructor.
460
+ *
461
+ * @param {Object} opts - options
462
+ * @protected
463
+ */
464
+ constructor(opts) {
465
+ super();
466
+ this.writable = false;
467
+ installTimerFunctions(this, opts);
468
+ this.opts = opts;
469
+ this.query = opts.query;
470
+ this.socket = opts.socket;
471
+ this.supportsBinary = !opts.forceBase64;
472
+ }
473
+ /**
474
+ * Emits an error.
475
+ *
476
+ * @param {String} reason
477
+ * @param description
478
+ * @param context - the error context
479
+ * @return {Transport} for chaining
480
+ * @protected
481
+ */
482
+ onError(reason, description, context) {
483
+ super.emitReserved("error", new TransportError(reason, description, context));
484
+ return this;
485
+ }
486
+ /**
487
+ * Opens the transport.
488
+ */
489
+ open() {
490
+ this.readyState = "opening";
491
+ this.doOpen();
492
+ return this;
493
+ }
494
+ /**
495
+ * Closes the transport.
496
+ */
497
+ close() {
498
+ if (this.readyState === "opening" || this.readyState === "open") {
499
+ this.doClose();
500
+ this.onClose();
501
+ }
502
+ return this;
503
+ }
504
+ /**
505
+ * Sends multiple packets.
506
+ *
507
+ * @param {Array} packets
508
+ */
509
+ send(packets) {
510
+ if (this.readyState === "open") this.write(packets);
511
+ }
512
+ /**
513
+ * Called upon open
514
+ *
515
+ * @protected
516
+ */
517
+ onOpen() {
518
+ this.readyState = "open";
519
+ this.writable = true;
520
+ super.emitReserved("open");
521
+ }
522
+ /**
523
+ * Called with data.
524
+ *
525
+ * @param {String} data
526
+ * @protected
527
+ */
528
+ onData(data) {
529
+ const packet = decodePacket(data, this.socket.binaryType);
530
+ this.onPacket(packet);
531
+ }
532
+ /**
533
+ * Called with a decoded packet.
534
+ *
535
+ * @protected
536
+ */
537
+ onPacket(packet) {
538
+ super.emitReserved("packet", packet);
539
+ }
540
+ /**
541
+ * Called upon close.
542
+ *
543
+ * @protected
544
+ */
545
+ onClose(details) {
546
+ this.readyState = "closed";
547
+ super.emitReserved("close", details);
548
+ }
549
+ /**
550
+ * Pauses the transport, in order not to lose packets during an upgrade.
551
+ *
552
+ * @param onPause
553
+ */
554
+ pause(onPause) {}
555
+ createUri(schema, query = {}) {
556
+ return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
557
+ }
558
+ _hostname() {
559
+ const hostname = this.opts.hostname;
560
+ return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]";
561
+ }
562
+ _port() {
563
+ if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) return ":" + this.opts.port;
564
+ else return "";
565
+ }
566
+ _query(query) {
567
+ const encodedQuery = encode(query);
568
+ return encodedQuery.length ? "?" + encodedQuery : "";
569
+ }
570
+ };
571
+ //#endregion
572
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/transports/polling.js
573
+ var Polling = class extends Transport {
574
+ constructor() {
575
+ super(...arguments);
576
+ this._polling = false;
577
+ }
578
+ get name() {
579
+ return "polling";
580
+ }
581
+ /**
582
+ * Opens the socket (triggers polling). We write a PING message to determine
583
+ * when the transport is open.
584
+ *
585
+ * @protected
586
+ */
587
+ doOpen() {
588
+ this._poll();
589
+ }
590
+ /**
591
+ * Pauses polling.
592
+ *
593
+ * @param {Function} onPause - callback upon buffers are flushed and transport is paused
594
+ * @package
595
+ */
596
+ pause(onPause) {
597
+ this.readyState = "pausing";
598
+ const pause = () => {
599
+ this.readyState = "paused";
600
+ onPause();
601
+ };
602
+ if (this._polling || !this.writable) {
603
+ let total = 0;
604
+ if (this._polling) {
605
+ total++;
606
+ this.once("pollComplete", function() {
607
+ --total || pause();
608
+ });
609
+ }
610
+ if (!this.writable) {
611
+ total++;
612
+ this.once("drain", function() {
613
+ --total || pause();
614
+ });
615
+ }
616
+ } else pause();
617
+ }
618
+ /**
619
+ * Starts polling cycle.
620
+ *
621
+ * @private
622
+ */
623
+ _poll() {
624
+ this._polling = true;
625
+ this.doPoll();
626
+ this.emitReserved("poll");
627
+ }
628
+ /**
629
+ * Overloads onData to detect payloads.
630
+ *
631
+ * @protected
632
+ */
633
+ onData(data) {
634
+ const callback = (packet) => {
635
+ if ("opening" === this.readyState && packet.type === "open") this.onOpen();
636
+ if ("close" === packet.type) {
637
+ this.onClose({ description: "transport closed by the server" });
638
+ return false;
639
+ }
640
+ this.onPacket(packet);
641
+ };
642
+ decodePayload(data, this.socket.binaryType).forEach(callback);
643
+ if ("closed" !== this.readyState) {
644
+ this._polling = false;
645
+ this.emitReserved("pollComplete");
646
+ if ("open" === this.readyState) this._poll();
647
+ }
648
+ }
649
+ /**
650
+ * For polling, send a close packet.
651
+ *
652
+ * @protected
653
+ */
654
+ doClose() {
655
+ const close = () => {
656
+ this.write([{ type: "close" }]);
657
+ };
658
+ if ("open" === this.readyState) close();
659
+ else this.once("open", close);
660
+ }
661
+ /**
662
+ * Writes a packets payload.
663
+ *
664
+ * @param {Array} packets - data packets
665
+ * @protected
666
+ */
667
+ write(packets) {
668
+ this.writable = false;
669
+ encodePayload(packets, (data) => {
670
+ this.doWrite(data, () => {
671
+ this.writable = true;
672
+ this.emitReserved("drain");
673
+ });
674
+ });
675
+ }
676
+ /**
677
+ * Generates uri for connection.
678
+ *
679
+ * @private
680
+ */
681
+ uri() {
682
+ const schema = this.opts.secure ? "https" : "http";
683
+ const query = this.query || {};
684
+ if (false !== this.opts.timestampRequests) query[this.opts.timestampParam] = randomString();
685
+ if (!this.supportsBinary && !query.sid) query.b64 = 1;
686
+ return this.createUri(schema, query);
687
+ }
688
+ };
689
+ //#endregion
690
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/contrib/has-cors.js
691
+ var value = false;
692
+ try {
693
+ value = typeof XMLHttpRequest !== "undefined" && "withCredentials" in new XMLHttpRequest();
694
+ } catch (err) {}
695
+ var hasCORS = value;
696
+ //#endregion
697
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/transports/polling-xhr.js
698
+ function empty() {}
699
+ var BaseXHR = class extends Polling {
700
+ /**
701
+ * XHR Polling constructor.
702
+ *
703
+ * @param {Object} opts
704
+ * @package
705
+ */
706
+ constructor(opts) {
707
+ super(opts);
708
+ if (typeof location !== "undefined") {
709
+ const isSSL = "https:" === location.protocol;
710
+ let port = location.port;
711
+ if (!port) port = isSSL ? "443" : "80";
712
+ this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
713
+ }
714
+ }
715
+ /**
716
+ * Sends data.
717
+ *
718
+ * @param {String} data - data to send.
719
+ * @param {Function} fn - called upon flush.
720
+ * @private
721
+ */
722
+ doWrite(data, fn) {
723
+ const req = this.request({
724
+ method: "POST",
725
+ data
726
+ });
727
+ req.on("success", fn);
728
+ req.on("error", (xhrStatus, context) => {
729
+ this.onError("xhr post error", xhrStatus, context);
730
+ });
731
+ }
732
+ /**
733
+ * Starts a poll cycle.
734
+ *
735
+ * @private
736
+ */
737
+ doPoll() {
738
+ const req = this.request();
739
+ req.on("data", this.onData.bind(this));
740
+ req.on("error", (xhrStatus, context) => {
741
+ this.onError("xhr poll error", xhrStatus, context);
742
+ });
743
+ this.pollXhr = req;
744
+ }
745
+ };
746
+ var Request = class Request extends Emitter {
747
+ /**
748
+ * Request constructor
749
+ *
750
+ * @param {Object} options
751
+ * @package
752
+ */
753
+ constructor(createRequest, uri, opts) {
754
+ super();
755
+ this.createRequest = createRequest;
756
+ installTimerFunctions(this, opts);
757
+ this._opts = opts;
758
+ this._method = opts.method || "GET";
759
+ this._uri = uri;
760
+ this._data = void 0 !== opts.data ? opts.data : null;
761
+ this._create();
762
+ }
763
+ /**
764
+ * Creates the XHR object and sends the request.
765
+ *
766
+ * @private
767
+ */
768
+ _create() {
769
+ var _a;
770
+ const opts = pick(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
771
+ opts.xdomain = !!this._opts.xd;
772
+ const xhr = this._xhr = this.createRequest(opts);
773
+ try {
774
+ xhr.open(this._method, this._uri, true);
775
+ try {
776
+ if (this._opts.extraHeaders) {
777
+ xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
778
+ for (let i in this._opts.extraHeaders) if (this._opts.extraHeaders.hasOwnProperty(i)) xhr.setRequestHeader(i, this._opts.extraHeaders[i]);
779
+ }
780
+ } catch (e) {}
781
+ if ("POST" === this._method) try {
782
+ xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
783
+ } catch (e) {}
784
+ try {
785
+ xhr.setRequestHeader("Accept", "*/*");
786
+ } catch (e) {}
787
+ (_a = this._opts.cookieJar) === null || _a === void 0 || _a.addCookies(xhr);
788
+ if ("withCredentials" in xhr) xhr.withCredentials = this._opts.withCredentials;
789
+ if (this._opts.requestTimeout) xhr.timeout = this._opts.requestTimeout;
790
+ xhr.onreadystatechange = () => {
791
+ var _a;
792
+ if (xhr.readyState === 3) (_a = this._opts.cookieJar) === null || _a === void 0 || _a.parseCookies(xhr.getResponseHeader("set-cookie"));
793
+ if (4 !== xhr.readyState) return;
794
+ if (200 === xhr.status || 1223 === xhr.status) this._onLoad();
795
+ else this.setTimeoutFn(() => {
796
+ this._onError(typeof xhr.status === "number" ? xhr.status : 0);
797
+ }, 0);
798
+ };
799
+ xhr.send(this._data);
800
+ } catch (e) {
801
+ this.setTimeoutFn(() => {
802
+ this._onError(e);
803
+ }, 0);
804
+ return;
805
+ }
806
+ if (typeof document !== "undefined") {
807
+ this._index = Request.requestsCount++;
808
+ Request.requests[this._index] = this;
809
+ }
810
+ }
811
+ /**
812
+ * Called upon error.
813
+ *
814
+ * @private
815
+ */
816
+ _onError(err) {
817
+ this.emitReserved("error", err, this._xhr);
818
+ this._cleanup(true);
819
+ }
820
+ /**
821
+ * Cleans up house.
822
+ *
823
+ * @private
824
+ */
825
+ _cleanup(fromError) {
826
+ if ("undefined" === typeof this._xhr || null === this._xhr) return;
827
+ this._xhr.onreadystatechange = empty;
828
+ if (fromError) try {
829
+ this._xhr.abort();
830
+ } catch (e) {}
831
+ if (typeof document !== "undefined") delete Request.requests[this._index];
832
+ this._xhr = null;
833
+ }
834
+ /**
835
+ * Called upon load.
836
+ *
837
+ * @private
838
+ */
839
+ _onLoad() {
840
+ const data = this._xhr.responseText;
841
+ if (data !== null) {
842
+ this.emitReserved("data", data);
843
+ this.emitReserved("success");
844
+ this._cleanup();
845
+ }
846
+ }
847
+ /**
848
+ * Aborts the request.
849
+ *
850
+ * @package
851
+ */
852
+ abort() {
853
+ this._cleanup();
854
+ }
855
+ };
856
+ Request.requestsCount = 0;
857
+ Request.requests = {};
858
+ /**
859
+ * Aborts pending requests when unloading the window. This is needed to prevent
860
+ * memory leaks (e.g. when using IE) and to ensure that no spurious error is
861
+ * emitted.
862
+ */
863
+ if (typeof document !== "undefined") {
864
+ if (typeof attachEvent === "function") attachEvent("onunload", unloadHandler);
865
+ else if (typeof addEventListener === "function") {
866
+ const terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
867
+ addEventListener(terminationEvent, unloadHandler, false);
868
+ }
869
+ }
870
+ function unloadHandler() {
871
+ for (let i in Request.requests) if (Request.requests.hasOwnProperty(i)) Request.requests[i].abort();
872
+ }
873
+ var hasXHR2 = (function() {
874
+ const xhr = newRequest({ xdomain: false });
875
+ return xhr && xhr.responseType !== null;
876
+ })();
877
+ /**
878
+ * HTTP long-polling based on the built-in `XMLHttpRequest` object.
879
+ *
880
+ * Usage: browser
881
+ *
882
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
883
+ */
884
+ var XHR = class extends BaseXHR {
885
+ constructor(opts) {
886
+ super(opts);
887
+ const forceBase64 = opts && opts.forceBase64;
888
+ this.supportsBinary = hasXHR2 && !forceBase64;
889
+ }
890
+ request(opts = {}) {
891
+ Object.assign(opts, { xd: this.xd }, this.opts);
892
+ return new Request(newRequest, this.uri(), opts);
893
+ }
894
+ };
895
+ function newRequest(opts) {
896
+ const xdomain = opts.xdomain;
897
+ try {
898
+ if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) return new XMLHttpRequest();
899
+ } catch (e) {}
900
+ if (!xdomain) try {
901
+ return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
902
+ } catch (e) {}
903
+ }
904
+ //#endregion
905
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/transports/websocket.js
906
+ var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
907
+ var BaseWS = class extends Transport {
908
+ get name() {
909
+ return "websocket";
910
+ }
911
+ doOpen() {
912
+ const uri = this.uri();
913
+ const protocols = this.opts.protocols;
914
+ const opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
915
+ if (this.opts.extraHeaders) opts.headers = this.opts.extraHeaders;
916
+ try {
917
+ this.ws = this.createSocket(uri, protocols, opts);
918
+ } catch (err) {
919
+ return this.emitReserved("error", err);
920
+ }
921
+ this.ws.binaryType = this.socket.binaryType;
922
+ this.addEventListeners();
923
+ }
924
+ /**
925
+ * Adds event listeners to the socket
926
+ *
927
+ * @private
928
+ */
929
+ addEventListeners() {
930
+ this.ws.onopen = () => {
931
+ if (this.opts.autoUnref) this.ws._socket.unref();
932
+ this.onOpen();
933
+ };
934
+ this.ws.onclose = (closeEvent) => this.onClose({
935
+ description: "websocket connection closed",
936
+ context: closeEvent
937
+ });
938
+ this.ws.onmessage = (ev) => this.onData(ev.data);
939
+ this.ws.onerror = (e) => this.onError("websocket error", e);
940
+ }
941
+ write(packets) {
942
+ this.writable = false;
943
+ for (let i = 0; i < packets.length; i++) {
944
+ const packet = packets[i];
945
+ const lastPacket = i === packets.length - 1;
946
+ encodePacket(packet, this.supportsBinary, (data) => {
947
+ try {
948
+ this.doWrite(packet, data);
949
+ } catch (e) {}
950
+ if (lastPacket) nextTick(() => {
951
+ this.writable = true;
952
+ this.emitReserved("drain");
953
+ }, this.setTimeoutFn);
954
+ });
955
+ }
956
+ }
957
+ doClose() {
958
+ if (typeof this.ws !== "undefined") {
959
+ this.ws.onerror = () => {};
960
+ this.ws.close();
961
+ this.ws = null;
962
+ }
963
+ }
964
+ /**
965
+ * Generates uri for connection.
966
+ *
967
+ * @private
968
+ */
969
+ uri() {
970
+ const schema = this.opts.secure ? "wss" : "ws";
971
+ const query = this.query || {};
972
+ if (this.opts.timestampRequests) query[this.opts.timestampParam] = randomString();
973
+ if (!this.supportsBinary) query.b64 = 1;
974
+ return this.createUri(schema, query);
975
+ }
976
+ };
977
+ var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
978
+ /**
979
+ * WebSocket transport based on the built-in `WebSocket` object.
980
+ *
981
+ * Usage: browser, Node.js (since v21), Deno, Bun
982
+ *
983
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
984
+ * @see https://caniuse.com/mdn-api_websocket
985
+ * @see https://nodejs.org/api/globals.html#websocket
986
+ */
987
+ var WS = class extends BaseWS {
988
+ createSocket(uri, protocols, opts) {
989
+ return !isReactNative ? protocols ? new WebSocketCtor(uri, protocols) : new WebSocketCtor(uri) : new WebSocketCtor(uri, protocols, opts);
990
+ }
991
+ doWrite(_packet, data) {
992
+ this.ws.send(data);
993
+ }
994
+ };
995
+ //#endregion
996
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/transports/webtransport.js
997
+ /**
998
+ * WebTransport transport based on the built-in `WebTransport` object.
999
+ *
1000
+ * Usage: browser, Node.js (with the `@fails-components/webtransport` package)
1001
+ *
1002
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
1003
+ * @see https://caniuse.com/webtransport
1004
+ */
1005
+ var WT = class extends Transport {
1006
+ get name() {
1007
+ return "webtransport";
1008
+ }
1009
+ doOpen() {
1010
+ try {
1011
+ this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
1012
+ } catch (err) {
1013
+ return this.emitReserved("error", err);
1014
+ }
1015
+ this._transport.closed.then(() => {
1016
+ this.onClose();
1017
+ }).catch((err) => {
1018
+ this.onError("webtransport error", err);
1019
+ });
1020
+ this._transport.ready.then(() => {
1021
+ this._transport.createBidirectionalStream().then((stream) => {
1022
+ const decoderStream = createPacketDecoderStream(Number.MAX_SAFE_INTEGER, this.socket.binaryType);
1023
+ const reader = stream.readable.pipeThrough(decoderStream).getReader();
1024
+ const encoderStream = createPacketEncoderStream();
1025
+ encoderStream.readable.pipeTo(stream.writable);
1026
+ this._writer = encoderStream.writable.getWriter();
1027
+ const read = () => {
1028
+ reader.read().then(({ done, value }) => {
1029
+ if (done) return;
1030
+ this.onPacket(value);
1031
+ read();
1032
+ }).catch((err) => {});
1033
+ };
1034
+ read();
1035
+ const packet = { type: "open" };
1036
+ if (this.query.sid) packet.data = `{"sid":"${this.query.sid}"}`;
1037
+ this._writer.write(packet).then(() => this.onOpen());
1038
+ });
1039
+ });
1040
+ }
1041
+ write(packets) {
1042
+ this.writable = false;
1043
+ for (let i = 0; i < packets.length; i++) {
1044
+ const packet = packets[i];
1045
+ const lastPacket = i === packets.length - 1;
1046
+ this._writer.write(packet).then(() => {
1047
+ if (lastPacket) nextTick(() => {
1048
+ this.writable = true;
1049
+ this.emitReserved("drain");
1050
+ }, this.setTimeoutFn);
1051
+ });
1052
+ }
1053
+ }
1054
+ doClose() {
1055
+ var _a;
1056
+ (_a = this._transport) === null || _a === void 0 || _a.close();
1057
+ }
1058
+ };
1059
+ //#endregion
1060
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/transports/index.js
1061
+ var transports = {
1062
+ websocket: WS,
1063
+ webtransport: WT,
1064
+ polling: XHR
1065
+ };
1066
+ //#endregion
1067
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/contrib/parseuri.js
1068
+ /**
1069
+ * Parses a URI
1070
+ *
1071
+ * Note: we could also have used the built-in URL object, but it isn't supported on all platforms.
1072
+ *
1073
+ * See:
1074
+ * - https://developer.mozilla.org/en-US/docs/Web/API/URL
1075
+ * - https://caniuse.com/url
1076
+ * - https://www.rfc-editor.org/rfc/rfc3986#appendix-B
1077
+ *
1078
+ * History of the parse() method:
1079
+ * - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c
1080
+ * - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3
1081
+ * - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242
1082
+ *
1083
+ * @author Steven Levithan <stevenlevithan.com> (MIT license)
1084
+ * @api private
1085
+ */
1086
+ var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
1087
+ var parts = [
1088
+ "source",
1089
+ "protocol",
1090
+ "authority",
1091
+ "userInfo",
1092
+ "user",
1093
+ "password",
1094
+ "host",
1095
+ "port",
1096
+ "relative",
1097
+ "path",
1098
+ "directory",
1099
+ "file",
1100
+ "query",
1101
+ "anchor"
1102
+ ];
1103
+ function parse(str) {
1104
+ if (str.length > 8e3) throw "URI too long";
1105
+ const src = str, b = str.indexOf("["), e = str.indexOf("]");
1106
+ if (b != -1 && e != -1) str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ";") + str.substring(e, str.length);
1107
+ let m = re.exec(str || ""), uri = {}, i = 14;
1108
+ while (i--) uri[parts[i]] = m[i] || "";
1109
+ if (b != -1 && e != -1) {
1110
+ uri.source = src;
1111
+ uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ":");
1112
+ uri.authority = uri.authority.replace("[", "").replace("]", "").replace(/;/g, ":");
1113
+ uri.ipv6uri = true;
1114
+ }
1115
+ uri.pathNames = pathNames(uri, uri["path"]);
1116
+ uri.queryKey = queryKey(uri, uri["query"]);
1117
+ return uri;
1118
+ }
1119
+ function pathNames(obj, path) {
1120
+ const names = path.replace(/\/{2,9}/g, "/").split("/");
1121
+ if (path.slice(0, 1) == "/" || path.length === 0) names.splice(0, 1);
1122
+ if (path.slice(-1) == "/") names.splice(names.length - 1, 1);
1123
+ return names;
1124
+ }
1125
+ function queryKey(uri, query) {
1126
+ const data = {};
1127
+ query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function($0, $1, $2) {
1128
+ if ($1) data[$1] = $2;
1129
+ });
1130
+ return data;
1131
+ }
1132
+ //#endregion
1133
+ //#region ../../node_modules/.pnpm/engine.io-client@6.6.6/node_modules/engine.io-client/build/esm/socket.js
1134
+ var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function";
1135
+ var OFFLINE_EVENT_LISTENERS = [];
1136
+ if (withEventListeners) addEventListener("offline", () => {
1137
+ OFFLINE_EVENT_LISTENERS.forEach((listener) => listener());
1138
+ }, false);
1139
+ /**
1140
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
1141
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
1142
+ *
1143
+ * This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
1144
+ * successfully establishes the connection.
1145
+ *
1146
+ * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
1147
+ *
1148
+ * @example
1149
+ * import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
1150
+ *
1151
+ * const socket = new SocketWithoutUpgrade({
1152
+ * transports: [WebSocket]
1153
+ * });
1154
+ *
1155
+ * socket.on("open", () => {
1156
+ * socket.send("hello");
1157
+ * });
1158
+ *
1159
+ * @see SocketWithUpgrade
1160
+ * @see Socket
1161
+ */
1162
+ var SocketWithoutUpgrade = class SocketWithoutUpgrade extends Emitter {
1163
+ /**
1164
+ * Socket constructor.
1165
+ *
1166
+ * @param {String|Object} uri - uri or options
1167
+ * @param {Object} opts - options
1168
+ */
1169
+ constructor(uri, opts) {
1170
+ super();
1171
+ this.binaryType = defaultBinaryType;
1172
+ this.writeBuffer = [];
1173
+ this._prevBufferLen = 0;
1174
+ this._pingInterval = -1;
1175
+ this._pingTimeout = -1;
1176
+ this._maxPayload = -1;
1177
+ /**
1178
+ * The expiration timestamp of the {@link _pingTimeoutTimer} object is tracked, in case the timer is throttled and the
1179
+ * callback is not fired on time. This can happen for example when a laptop is suspended or when a phone is locked.
1180
+ */
1181
+ this._pingTimeoutTime = Infinity;
1182
+ if (uri && "object" === typeof uri) {
1183
+ opts = uri;
1184
+ uri = null;
1185
+ }
1186
+ if (uri) {
1187
+ const parsedUri = parse(uri);
1188
+ opts.hostname = parsedUri.host;
1189
+ opts.secure = parsedUri.protocol === "https" || parsedUri.protocol === "wss";
1190
+ opts.port = parsedUri.port;
1191
+ if (parsedUri.query) opts.query = parsedUri.query;
1192
+ } else if (opts.host) opts.hostname = parse(opts.host).host;
1193
+ installTimerFunctions(this, opts);
1194
+ this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
1195
+ if (opts.hostname && !opts.port) opts.port = this.secure ? "443" : "80";
1196
+ this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
1197
+ this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : this.secure ? "443" : "80");
1198
+ this.transports = [];
1199
+ this._transportsByName = {};
1200
+ opts.transports.forEach((t) => {
1201
+ const transportName = t.prototype.name;
1202
+ this.transports.push(transportName);
1203
+ this._transportsByName[transportName] = t;
1204
+ });
1205
+ this.opts = Object.assign({
1206
+ path: "/engine.io",
1207
+ agent: false,
1208
+ withCredentials: false,
1209
+ upgrade: true,
1210
+ timestampParam: "t",
1211
+ rememberUpgrade: false,
1212
+ addTrailingSlash: true,
1213
+ rejectUnauthorized: true,
1214
+ perMessageDeflate: { threshold: 1024 },
1215
+ transportOptions: {},
1216
+ closeOnBeforeunload: false
1217
+ }, opts);
1218
+ this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : "");
1219
+ if (typeof this.opts.query === "string") this.opts.query = decode(this.opts.query);
1220
+ if (withEventListeners) {
1221
+ if (this.opts.closeOnBeforeunload) {
1222
+ this._beforeunloadEventListener = () => {
1223
+ if (this.transport) {
1224
+ this.transport.removeAllListeners();
1225
+ this.transport.close();
1226
+ }
1227
+ };
1228
+ addEventListener("beforeunload", this._beforeunloadEventListener, false);
1229
+ }
1230
+ if (this.hostname !== "localhost") {
1231
+ this._offlineEventListener = () => {
1232
+ this._onClose("transport close", { description: "network connection lost" });
1233
+ };
1234
+ OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
1235
+ }
1236
+ }
1237
+ if (this.opts.withCredentials) this._cookieJar = void 0;
1238
+ this._open();
1239
+ }
1240
+ /**
1241
+ * Creates transport of the given type.
1242
+ *
1243
+ * @param {String} name - transport name
1244
+ * @return {Transport}
1245
+ * @private
1246
+ */
1247
+ createTransport(name) {
1248
+ const query = Object.assign({}, this.opts.query);
1249
+ query.EIO = 4;
1250
+ query.transport = name;
1251
+ if (this.id) query.sid = this.id;
1252
+ const opts = Object.assign({}, this.opts, {
1253
+ query,
1254
+ socket: this,
1255
+ hostname: this.hostname,
1256
+ secure: this.secure,
1257
+ port: this.port
1258
+ }, this.opts.transportOptions[name]);
1259
+ return new this._transportsByName[name](opts);
1260
+ }
1261
+ /**
1262
+ * Initializes transport to use and starts probe.
1263
+ *
1264
+ * @private
1265
+ */
1266
+ _open() {
1267
+ if (this.transports.length === 0) {
1268
+ this.setTimeoutFn(() => {
1269
+ this.emitReserved("error", "No transports available");
1270
+ }, 0);
1271
+ return;
1272
+ }
1273
+ const transportName = this.opts.rememberUpgrade && SocketWithoutUpgrade.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
1274
+ this.readyState = "opening";
1275
+ const transport = this.createTransport(transportName);
1276
+ transport.open();
1277
+ this.setTransport(transport);
1278
+ }
1279
+ /**
1280
+ * Sets the current transport. Disables the existing one (if any).
1281
+ *
1282
+ * @private
1283
+ */
1284
+ setTransport(transport) {
1285
+ if (this.transport) this.transport.removeAllListeners();
1286
+ this.transport = transport;
1287
+ transport.on("drain", this._onDrain.bind(this)).on("packet", this._onPacket.bind(this)).on("error", this._onError.bind(this)).on("close", (reason) => this._onClose("transport close", reason));
1288
+ }
1289
+ /**
1290
+ * Called when connection is deemed open.
1291
+ *
1292
+ * @private
1293
+ */
1294
+ onOpen() {
1295
+ this.readyState = "open";
1296
+ SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === this.transport.name;
1297
+ this.emitReserved("open");
1298
+ this.flush();
1299
+ }
1300
+ /**
1301
+ * Handles a packet.
1302
+ *
1303
+ * @private
1304
+ */
1305
+ _onPacket(packet) {
1306
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
1307
+ this.emitReserved("packet", packet);
1308
+ this.emitReserved("heartbeat");
1309
+ switch (packet.type) {
1310
+ case "open":
1311
+ this.onHandshake(JSON.parse(packet.data));
1312
+ break;
1313
+ case "ping":
1314
+ this._sendPacket("pong");
1315
+ this.emitReserved("ping");
1316
+ this.emitReserved("pong");
1317
+ this._resetPingTimeout();
1318
+ break;
1319
+ case "error":
1320
+ const err = /* @__PURE__ */ new Error("server error");
1321
+ err.code = packet.data;
1322
+ this._onError(err);
1323
+ break;
1324
+ case "message":
1325
+ this.emitReserved("data", packet.data);
1326
+ this.emitReserved("message", packet.data);
1327
+ break;
1328
+ }
1329
+ }
1330
+ }
1331
+ /**
1332
+ * Called upon handshake completion.
1333
+ *
1334
+ * @param {Object} data - handshake obj
1335
+ * @private
1336
+ */
1337
+ onHandshake(data) {
1338
+ this.emitReserved("handshake", data);
1339
+ this.id = data.sid;
1340
+ this.transport.query.sid = data.sid;
1341
+ this._pingInterval = data.pingInterval;
1342
+ this._pingTimeout = data.pingTimeout;
1343
+ this._maxPayload = data.maxPayload;
1344
+ this.onOpen();
1345
+ if ("closed" === this.readyState) return;
1346
+ this._resetPingTimeout();
1347
+ }
1348
+ /**
1349
+ * Sets and resets ping timeout timer based on server pings.
1350
+ *
1351
+ * @private
1352
+ */
1353
+ _resetPingTimeout() {
1354
+ this.clearTimeoutFn(this._pingTimeoutTimer);
1355
+ const delay = this._pingInterval + this._pingTimeout;
1356
+ this._pingTimeoutTime = Date.now() + delay;
1357
+ this._pingTimeoutTimer = this.setTimeoutFn(() => {
1358
+ this._onClose("ping timeout");
1359
+ }, delay);
1360
+ if (this.opts.autoUnref) this._pingTimeoutTimer.unref();
1361
+ }
1362
+ /**
1363
+ * Called on `drain` event
1364
+ *
1365
+ * @private
1366
+ */
1367
+ _onDrain() {
1368
+ this.writeBuffer.splice(0, this._prevBufferLen);
1369
+ this._prevBufferLen = 0;
1370
+ if (0 === this.writeBuffer.length) this.emitReserved("drain");
1371
+ else this.flush();
1372
+ }
1373
+ /**
1374
+ * Flush write buffers.
1375
+ *
1376
+ * @private
1377
+ */
1378
+ flush() {
1379
+ if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
1380
+ const packets = this._getWritablePackets();
1381
+ this.transport.send(packets);
1382
+ this._prevBufferLen = packets.length;
1383
+ this.emitReserved("flush");
1384
+ }
1385
+ }
1386
+ /**
1387
+ * Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
1388
+ * long-polling)
1389
+ *
1390
+ * @private
1391
+ */
1392
+ _getWritablePackets() {
1393
+ if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1)) return this.writeBuffer;
1394
+ let payloadSize = 1;
1395
+ for (let i = 0; i < this.writeBuffer.length; i++) {
1396
+ const data = this.writeBuffer[i].data;
1397
+ if (data) payloadSize += byteLength(data);
1398
+ if (i > 0 && payloadSize > this._maxPayload) return this.writeBuffer.slice(0, i);
1399
+ payloadSize += 2;
1400
+ }
1401
+ return this.writeBuffer;
1402
+ }
1403
+ /**
1404
+ * Checks whether the heartbeat timer has expired but the socket has not yet been notified.
1405
+ *
1406
+ * Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
1407
+ * `write()` method then the message would not be buffered by the Socket.IO client.
1408
+ *
1409
+ * @return {boolean}
1410
+ * @private
1411
+ */
1412
+ _hasPingExpired() {
1413
+ if (!this._pingTimeoutTime) return true;
1414
+ const hasExpired = Date.now() > this._pingTimeoutTime;
1415
+ if (hasExpired) {
1416
+ this._pingTimeoutTime = 0;
1417
+ nextTick(() => {
1418
+ this._onClose("ping timeout");
1419
+ }, this.setTimeoutFn);
1420
+ }
1421
+ return hasExpired;
1422
+ }
1423
+ /**
1424
+ * Sends a message.
1425
+ *
1426
+ * @param {String} msg - message.
1427
+ * @param {Object} options.
1428
+ * @param {Function} fn - callback function.
1429
+ * @return {Socket} for chaining.
1430
+ */
1431
+ write(msg, options, fn) {
1432
+ this._sendPacket("message", msg, options, fn);
1433
+ return this;
1434
+ }
1435
+ /**
1436
+ * Sends a message. Alias of {@link Socket#write}.
1437
+ *
1438
+ * @param {String} msg - message.
1439
+ * @param {Object} options.
1440
+ * @param {Function} fn - callback function.
1441
+ * @return {Socket} for chaining.
1442
+ */
1443
+ send(msg, options, fn) {
1444
+ this._sendPacket("message", msg, options, fn);
1445
+ return this;
1446
+ }
1447
+ /**
1448
+ * Sends a packet.
1449
+ *
1450
+ * @param {String} type - packet type.
1451
+ * @param {String} data.
1452
+ * @param {Object} options.
1453
+ * @param {Function} fn - callback function.
1454
+ * @private
1455
+ */
1456
+ _sendPacket(type, data, options, fn) {
1457
+ if ("function" === typeof data) {
1458
+ fn = data;
1459
+ data = void 0;
1460
+ }
1461
+ if ("function" === typeof options) {
1462
+ fn = options;
1463
+ options = null;
1464
+ }
1465
+ if ("closing" === this.readyState || "closed" === this.readyState) return;
1466
+ options = options || {};
1467
+ options.compress = false !== options.compress;
1468
+ const packet = {
1469
+ type,
1470
+ data,
1471
+ options
1472
+ };
1473
+ this.emitReserved("packetCreate", packet);
1474
+ this.writeBuffer.push(packet);
1475
+ if (fn) this.once("flush", fn);
1476
+ this.flush();
1477
+ }
1478
+ /**
1479
+ * Closes the connection.
1480
+ */
1481
+ close() {
1482
+ const close = () => {
1483
+ this._onClose("forced close");
1484
+ this.transport.close();
1485
+ };
1486
+ const cleanupAndClose = () => {
1487
+ this.off("upgrade", cleanupAndClose);
1488
+ this.off("upgradeError", cleanupAndClose);
1489
+ close();
1490
+ };
1491
+ const waitForUpgrade = () => {
1492
+ this.once("upgrade", cleanupAndClose);
1493
+ this.once("upgradeError", cleanupAndClose);
1494
+ };
1495
+ if ("opening" === this.readyState || "open" === this.readyState) {
1496
+ this.readyState = "closing";
1497
+ if (this.writeBuffer.length) this.once("drain", () => {
1498
+ if (this.upgrading) waitForUpgrade();
1499
+ else close();
1500
+ });
1501
+ else if (this.upgrading) waitForUpgrade();
1502
+ else close();
1503
+ }
1504
+ return this;
1505
+ }
1506
+ /**
1507
+ * Called upon transport error
1508
+ *
1509
+ * @private
1510
+ */
1511
+ _onError(err) {
1512
+ SocketWithoutUpgrade.priorWebsocketSuccess = false;
1513
+ if (this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") {
1514
+ this.transports.shift();
1515
+ return this._open();
1516
+ }
1517
+ this.emitReserved("error", err);
1518
+ this._onClose("transport error", err);
1519
+ }
1520
+ /**
1521
+ * Called upon transport close.
1522
+ *
1523
+ * @private
1524
+ */
1525
+ _onClose(reason, description) {
1526
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
1527
+ this.clearTimeoutFn(this._pingTimeoutTimer);
1528
+ this.transport.removeAllListeners("close");
1529
+ this.transport.close();
1530
+ this.transport.removeAllListeners();
1531
+ if (withEventListeners) {
1532
+ if (this._beforeunloadEventListener) removeEventListener("beforeunload", this._beforeunloadEventListener, false);
1533
+ if (this._offlineEventListener) {
1534
+ const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
1535
+ if (i !== -1) OFFLINE_EVENT_LISTENERS.splice(i, 1);
1536
+ }
1537
+ }
1538
+ this.readyState = "closed";
1539
+ this.id = null;
1540
+ this.emitReserved("close", reason, description);
1541
+ this.writeBuffer = [];
1542
+ this._prevBufferLen = 0;
1543
+ }
1544
+ }
1545
+ };
1546
+ SocketWithoutUpgrade.protocol = 4;
1547
+ /**
1548
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
1549
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
1550
+ *
1551
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
1552
+ * low-level transport, it will try to upgrade to a better transport.
1553
+ *
1554
+ * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
1555
+ *
1556
+ * @example
1557
+ * import { SocketWithUpgrade, WebSocket } from "engine.io-client";
1558
+ *
1559
+ * const socket = new SocketWithUpgrade({
1560
+ * transports: [WebSocket]
1561
+ * });
1562
+ *
1563
+ * socket.on("open", () => {
1564
+ * socket.send("hello");
1565
+ * });
1566
+ *
1567
+ * @see SocketWithoutUpgrade
1568
+ * @see Socket
1569
+ */
1570
+ var SocketWithUpgrade = class extends SocketWithoutUpgrade {
1571
+ constructor() {
1572
+ super(...arguments);
1573
+ this._upgrades = [];
1574
+ }
1575
+ onOpen() {
1576
+ super.onOpen();
1577
+ if ("open" === this.readyState && this.opts.upgrade) for (let i = 0; i < this._upgrades.length; i++) this._probe(this._upgrades[i]);
1578
+ }
1579
+ /**
1580
+ * Probes a transport.
1581
+ *
1582
+ * @param {String} name - transport name
1583
+ * @private
1584
+ */
1585
+ _probe(name) {
1586
+ let transport = this.createTransport(name);
1587
+ let failed = false;
1588
+ SocketWithoutUpgrade.priorWebsocketSuccess = false;
1589
+ const onTransportOpen = () => {
1590
+ if (failed) return;
1591
+ transport.send([{
1592
+ type: "ping",
1593
+ data: "probe"
1594
+ }]);
1595
+ transport.once("packet", (msg) => {
1596
+ if (failed) return;
1597
+ if ("pong" === msg.type && "probe" === msg.data) {
1598
+ this.upgrading = true;
1599
+ this.emitReserved("upgrading", transport);
1600
+ if (!transport) return;
1601
+ SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === transport.name;
1602
+ this.transport.pause(() => {
1603
+ if (failed) return;
1604
+ if ("closed" === this.readyState) return;
1605
+ cleanup();
1606
+ this.setTransport(transport);
1607
+ transport.send([{ type: "upgrade" }]);
1608
+ this.emitReserved("upgrade", transport);
1609
+ transport = null;
1610
+ this.upgrading = false;
1611
+ this.flush();
1612
+ });
1613
+ } else {
1614
+ const err = /* @__PURE__ */ new Error("probe error");
1615
+ err.transport = transport.name;
1616
+ this.emitReserved("upgradeError", err);
1617
+ }
1618
+ });
1619
+ };
1620
+ function freezeTransport() {
1621
+ if (failed) return;
1622
+ failed = true;
1623
+ cleanup();
1624
+ transport.close();
1625
+ transport = null;
1626
+ }
1627
+ const onerror = (err) => {
1628
+ const error = /* @__PURE__ */ new Error("probe error: " + err);
1629
+ error.transport = transport.name;
1630
+ freezeTransport();
1631
+ this.emitReserved("upgradeError", error);
1632
+ };
1633
+ function onTransportClose() {
1634
+ onerror("transport closed");
1635
+ }
1636
+ function onclose() {
1637
+ onerror("socket closed");
1638
+ }
1639
+ function onupgrade(to) {
1640
+ if (transport && to.name !== transport.name) freezeTransport();
1641
+ }
1642
+ const cleanup = () => {
1643
+ transport.removeListener("open", onTransportOpen);
1644
+ transport.removeListener("error", onerror);
1645
+ transport.removeListener("close", onTransportClose);
1646
+ this.off("close", onclose);
1647
+ this.off("upgrading", onupgrade);
1648
+ };
1649
+ transport.once("open", onTransportOpen);
1650
+ transport.once("error", onerror);
1651
+ transport.once("close", onTransportClose);
1652
+ this.once("close", onclose);
1653
+ this.once("upgrading", onupgrade);
1654
+ if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") this.setTimeoutFn(() => {
1655
+ if (!failed) transport.open();
1656
+ }, 200);
1657
+ else transport.open();
1658
+ }
1659
+ onHandshake(data) {
1660
+ this._upgrades = this._filterUpgrades(data.upgrades);
1661
+ super.onHandshake(data);
1662
+ }
1663
+ /**
1664
+ * Filters upgrades, returning only those matching client transports.
1665
+ *
1666
+ * @param {Array} upgrades - server upgrades
1667
+ * @private
1668
+ */
1669
+ _filterUpgrades(upgrades) {
1670
+ const filteredUpgrades = [];
1671
+ for (let i = 0; i < upgrades.length; i++) if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
1672
+ return filteredUpgrades;
1673
+ }
1674
+ };
1675
+ /**
1676
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
1677
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
1678
+ *
1679
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
1680
+ * low-level transport, it will try to upgrade to a better transport.
1681
+ *
1682
+ * @example
1683
+ * import { Socket } from "engine.io-client";
1684
+ *
1685
+ * const socket = new Socket();
1686
+ *
1687
+ * socket.on("open", () => {
1688
+ * socket.send("hello");
1689
+ * });
1690
+ *
1691
+ * @see SocketWithoutUpgrade
1692
+ * @see SocketWithUpgrade
1693
+ */
1694
+ var Socket$1 = class extends SocketWithUpgrade {
1695
+ constructor(uri, opts = {}) {
1696
+ const isOptionsOnly = typeof uri === "object";
1697
+ const o = isOptionsOnly ? { ...uri } : { ...opts };
1698
+ if (!o.transports || o.transports && typeof o.transports[0] === "string") o.transports = (o.transports || [
1699
+ "polling",
1700
+ "websocket",
1701
+ "webtransport"
1702
+ ]).map((transportName) => transports[transportName]).filter((t) => !!t);
1703
+ super(isOptionsOnly ? o : uri, o);
1704
+ }
1705
+ };
1706
+ Socket$1.protocol;
1707
+ //#endregion
1708
+ //#region ../../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/url.js
1709
+ /**
1710
+ * URL parser.
1711
+ *
1712
+ * @param uri - url
1713
+ * @param path - the request path of the connection
1714
+ * @param loc - An object meant to mimic window.location.
1715
+ * Defaults to window.location.
1716
+ * @public
1717
+ */
1718
+ function url(uri, path = "", loc) {
1719
+ let obj = uri;
1720
+ loc = loc || typeof location !== "undefined" && location;
1721
+ if (null == uri) uri = loc.protocol + "//" + loc.host;
1722
+ if (typeof uri === "string") {
1723
+ if ("/" === uri.charAt(0)) if ("/" === uri.charAt(1)) uri = loc.protocol + uri;
1724
+ else uri = loc.host + uri;
1725
+ if (!/^(https?|wss?):\/\//.test(uri)) if ("undefined" !== typeof loc) uri = loc.protocol + "//" + uri;
1726
+ else uri = "https://" + uri;
1727
+ obj = parse(uri);
1728
+ }
1729
+ if (!obj.port) {
1730
+ if (/^(http|ws)$/.test(obj.protocol)) obj.port = "80";
1731
+ else if (/^(http|ws)s$/.test(obj.protocol)) obj.port = "443";
1732
+ }
1733
+ obj.path = obj.path || "/";
1734
+ const host = obj.host.indexOf(":") !== -1 ? "[" + obj.host + "]" : obj.host;
1735
+ obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
1736
+ obj.href = obj.protocol + "://" + host + (loc && loc.port === obj.port ? "" : ":" + obj.port);
1737
+ return obj;
1738
+ }
1739
+ //#endregion
1740
+ //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7/node_modules/socket.io-parser/build/esm/is-binary.js
1741
+ var withNativeArrayBuffer = typeof ArrayBuffer === "function";
1742
+ var isView = (obj) => {
1743
+ return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj.buffer instanceof ArrayBuffer;
1744
+ };
1745
+ var toString = Object.prototype.toString;
1746
+ var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && toString.call(Blob) === "[object BlobConstructor]";
1747
+ var withNativeFile = typeof File === "function" || typeof File !== "undefined" && toString.call(File) === "[object FileConstructor]";
1748
+ /**
1749
+ * Returns true if obj is a Buffer, an ArrayBuffer, a Blob or a File.
1750
+ *
1751
+ * @private
1752
+ */
1753
+ function isBinary(obj) {
1754
+ return withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)) || withNativeBlob && obj instanceof Blob || withNativeFile && obj instanceof File;
1755
+ }
1756
+ function hasBinary(obj, toJSON) {
1757
+ if (!obj || typeof obj !== "object") return false;
1758
+ if (Array.isArray(obj)) {
1759
+ for (let i = 0, l = obj.length; i < l; i++) if (hasBinary(obj[i])) return true;
1760
+ return false;
1761
+ }
1762
+ if (isBinary(obj)) return true;
1763
+ if (obj.toJSON && typeof obj.toJSON === "function" && arguments.length === 1) return hasBinary(obj.toJSON(), true);
1764
+ for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) return true;
1765
+ return false;
1766
+ }
1767
+ //#endregion
1768
+ //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7/node_modules/socket.io-parser/build/esm/binary.js
1769
+ /**
1770
+ * Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
1771
+ *
1772
+ * @param {Object} packet - socket.io event packet
1773
+ * @return {Object} with deconstructed packet and list of buffers
1774
+ * @public
1775
+ */
1776
+ function deconstructPacket(packet) {
1777
+ const buffers = [];
1778
+ const packetData = packet.data;
1779
+ const pack = packet;
1780
+ pack.data = _deconstructPacket(packetData, buffers);
1781
+ pack.attachments = buffers.length;
1782
+ return {
1783
+ packet: pack,
1784
+ buffers
1785
+ };
1786
+ }
1787
+ function _deconstructPacket(data, buffers, toJSON) {
1788
+ if (!data) return data;
1789
+ if (isBinary(data)) {
1790
+ const placeholder = {
1791
+ _placeholder: true,
1792
+ num: buffers.length
1793
+ };
1794
+ buffers.push(data);
1795
+ return placeholder;
1796
+ } else if (Array.isArray(data)) {
1797
+ const newData = new Array(data.length);
1798
+ for (let i = 0; i < data.length; i++) newData[i] = _deconstructPacket(data[i], buffers);
1799
+ return newData;
1800
+ } else if (typeof data === "object" && !(data instanceof Date)) {
1801
+ if (data.toJSON && typeof data.toJSON === "function" && !toJSON) return _deconstructPacket(data.toJSON(), buffers, true);
1802
+ const newData = {};
1803
+ for (const key in data) if (Object.prototype.hasOwnProperty.call(data, key)) newData[key] = _deconstructPacket(data[key], buffers);
1804
+ return newData;
1805
+ }
1806
+ return data;
1807
+ }
1808
+ /**
1809
+ * Reconstructs a binary packet from its placeholder packet and buffers
1810
+ *
1811
+ * @param {Object} packet - event packet with placeholders
1812
+ * @param {Array} buffers - binary buffers to put in placeholder positions
1813
+ * @return {Object} reconstructed packet
1814
+ * @public
1815
+ */
1816
+ function reconstructPacket(packet, buffers) {
1817
+ packet.data = _reconstructPacket(packet.data, buffers);
1818
+ delete packet.attachments;
1819
+ return packet;
1820
+ }
1821
+ function _reconstructPacket(data, buffers) {
1822
+ if (!data) return data;
1823
+ if (data && data._placeholder === true) if (typeof data.num === "number" && data.num >= 0 && data.num < buffers.length) return buffers[data.num];
1824
+ else throw new Error("illegal attachments");
1825
+ else if (Array.isArray(data)) for (let i = 0; i < data.length; i++) data[i] = _reconstructPacket(data[i], buffers);
1826
+ else if (typeof data === "object") {
1827
+ for (const key in data) if (Object.prototype.hasOwnProperty.call(data, key)) data[key] = _reconstructPacket(data[key], buffers);
1828
+ }
1829
+ return data;
1830
+ }
1831
+ //#endregion
1832
+ //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7/node_modules/socket.io-parser/build/esm/index.js
1833
+ var esm_exports = /* @__PURE__ */ __exportAll({
1834
+ Decoder: () => Decoder,
1835
+ Encoder: () => Encoder,
1836
+ PacketType: () => PacketType,
1837
+ isPacketValid: () => isPacketValid,
1838
+ protocol: () => 5
1839
+ });
1840
+ /**
1841
+ * These strings must not be used as event names, as they have a special meaning.
1842
+ */
1843
+ var RESERVED_EVENTS$1 = [
1844
+ "connect",
1845
+ "connect_error",
1846
+ "disconnect",
1847
+ "disconnecting",
1848
+ "newListener",
1849
+ "removeListener"
1850
+ ];
1851
+ var PacketType;
1852
+ (function(PacketType) {
1853
+ PacketType[PacketType["CONNECT"] = 0] = "CONNECT";
1854
+ PacketType[PacketType["DISCONNECT"] = 1] = "DISCONNECT";
1855
+ PacketType[PacketType["EVENT"] = 2] = "EVENT";
1856
+ PacketType[PacketType["ACK"] = 3] = "ACK";
1857
+ PacketType[PacketType["CONNECT_ERROR"] = 4] = "CONNECT_ERROR";
1858
+ PacketType[PacketType["BINARY_EVENT"] = 5] = "BINARY_EVENT";
1859
+ PacketType[PacketType["BINARY_ACK"] = 6] = "BINARY_ACK";
1860
+ })(PacketType || (PacketType = {}));
1861
+ /**
1862
+ * A socket.io Encoder instance
1863
+ */
1864
+ var Encoder = class {
1865
+ /**
1866
+ * Encoder constructor
1867
+ *
1868
+ * @param {function} replacer - custom replacer to pass down to JSON.parse
1869
+ */
1870
+ constructor(replacer) {
1871
+ this.replacer = replacer;
1872
+ }
1873
+ /**
1874
+ * Encode a packet as a single string if non-binary, or as a
1875
+ * buffer sequence, depending on packet type.
1876
+ *
1877
+ * @param {Object} obj - packet object
1878
+ */
1879
+ encode(obj) {
1880
+ if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
1881
+ if (hasBinary(obj)) return this.encodeAsBinary({
1882
+ type: obj.type === PacketType.EVENT ? PacketType.BINARY_EVENT : PacketType.BINARY_ACK,
1883
+ nsp: obj.nsp,
1884
+ data: obj.data,
1885
+ id: obj.id
1886
+ });
1887
+ }
1888
+ return [this.encodeAsString(obj)];
1889
+ }
1890
+ /**
1891
+ * Encode packet as string.
1892
+ */
1893
+ encodeAsString(obj) {
1894
+ let str = "" + obj.type;
1895
+ if (obj.type === PacketType.BINARY_EVENT || obj.type === PacketType.BINARY_ACK) str += obj.attachments + "-";
1896
+ if (obj.nsp && "/" !== obj.nsp) str += obj.nsp + ",";
1897
+ if (null != obj.id) str += obj.id;
1898
+ if (null != obj.data) str += JSON.stringify(obj.data, this.replacer);
1899
+ return str;
1900
+ }
1901
+ /**
1902
+ * Encode packet as 'buffer sequence' by removing blobs, and
1903
+ * deconstructing packet into object with placeholders and
1904
+ * a list of buffers.
1905
+ */
1906
+ encodeAsBinary(obj) {
1907
+ const deconstruction = deconstructPacket(obj);
1908
+ const pack = this.encodeAsString(deconstruction.packet);
1909
+ const buffers = deconstruction.buffers;
1910
+ buffers.unshift(pack);
1911
+ return buffers;
1912
+ }
1913
+ };
1914
+ /**
1915
+ * A socket.io Decoder instance
1916
+ *
1917
+ * @return {Object} decoder
1918
+ */
1919
+ var Decoder = class Decoder extends Emitter {
1920
+ /**
1921
+ * Decoder constructor
1922
+ */
1923
+ constructor(opts) {
1924
+ super();
1925
+ this.opts = Object.assign({
1926
+ reviver: void 0,
1927
+ maxAttachments: 10
1928
+ }, typeof opts === "function" ? { reviver: opts } : opts);
1929
+ }
1930
+ /**
1931
+ * Decodes an encoded packet string into packet JSON.
1932
+ *
1933
+ * @param {String} obj - encoded packet
1934
+ */
1935
+ add(obj) {
1936
+ let packet;
1937
+ if (typeof obj === "string") {
1938
+ if (this.reconstructor) throw new Error("got plaintext data when reconstructing a packet");
1939
+ packet = this.decodeString(obj);
1940
+ const isBinaryEvent = packet.type === PacketType.BINARY_EVENT;
1941
+ if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
1942
+ packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
1943
+ this.reconstructor = new BinaryReconstructor(packet);
1944
+ } else super.emitReserved("decoded", packet);
1945
+ } else if (isBinary(obj) || obj.base64) if (!this.reconstructor) throw new Error("got binary data when not reconstructing a packet");
1946
+ else {
1947
+ packet = this.reconstructor.takeBinaryData(obj);
1948
+ if (packet) {
1949
+ this.reconstructor = null;
1950
+ super.emitReserved("decoded", packet);
1951
+ }
1952
+ }
1953
+ else throw new Error("Unknown type: " + obj);
1954
+ }
1955
+ /**
1956
+ * Decode a packet String (JSON data)
1957
+ *
1958
+ * @param {String} str
1959
+ * @return {Object} packet
1960
+ */
1961
+ decodeString(str) {
1962
+ let i = 0;
1963
+ const p = { type: Number(str.charAt(0)) };
1964
+ if (PacketType[p.type] === void 0) throw new Error("unknown packet type " + p.type);
1965
+ if (p.type === PacketType.BINARY_EVENT || p.type === PacketType.BINARY_ACK) {
1966
+ const start = i + 1;
1967
+ while (str.charAt(++i) !== "-" && i != str.length);
1968
+ const buf = str.substring(start, i);
1969
+ if (buf != Number(buf) || str.charAt(i) !== "-") throw new Error("Illegal attachments");
1970
+ const n = Number(buf);
1971
+ if (!isInteger(n) || n < 1) throw new Error("Illegal attachments");
1972
+ else if (n > this.opts.maxAttachments) throw new Error("too many attachments");
1973
+ p.attachments = n;
1974
+ }
1975
+ if ("/" === str.charAt(i + 1)) {
1976
+ const start = i + 1;
1977
+ while (++i) {
1978
+ if ("," === str.charAt(i)) break;
1979
+ if (i === str.length) break;
1980
+ }
1981
+ p.nsp = str.substring(start, i);
1982
+ } else p.nsp = "/";
1983
+ const next = str.charAt(i + 1);
1984
+ if ("" !== next && Number(next) == next) {
1985
+ const start = i + 1;
1986
+ while (++i) {
1987
+ const c = str.charAt(i);
1988
+ if (null == c || Number(c) != c) {
1989
+ --i;
1990
+ break;
1991
+ }
1992
+ if (i === str.length) break;
1993
+ }
1994
+ p.id = Number(str.substring(start, i + 1));
1995
+ }
1996
+ if (str.charAt(++i)) {
1997
+ const payload = this.tryParse(str.substr(i));
1998
+ if (Decoder.isPayloadValid(p.type, payload)) p.data = payload;
1999
+ else throw new Error("invalid payload");
2000
+ }
2001
+ return p;
2002
+ }
2003
+ tryParse(str) {
2004
+ try {
2005
+ return JSON.parse(str, this.opts.reviver);
2006
+ } catch (e) {
2007
+ return false;
2008
+ }
2009
+ }
2010
+ static isPayloadValid(type, payload) {
2011
+ switch (type) {
2012
+ case PacketType.CONNECT: return isObject(payload);
2013
+ case PacketType.DISCONNECT: return payload === void 0;
2014
+ case PacketType.CONNECT_ERROR: return typeof payload === "string" || isObject(payload);
2015
+ case PacketType.EVENT:
2016
+ case PacketType.BINARY_EVENT: return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS$1.indexOf(payload[0]) === -1);
2017
+ case PacketType.ACK:
2018
+ case PacketType.BINARY_ACK: return Array.isArray(payload);
2019
+ }
2020
+ }
2021
+ /**
2022
+ * Deallocates a parser's resources
2023
+ */
2024
+ destroy() {
2025
+ if (this.reconstructor) {
2026
+ this.reconstructor.finishedReconstruction();
2027
+ this.reconstructor = null;
2028
+ }
2029
+ }
2030
+ };
2031
+ /**
2032
+ * A manager of a binary event's 'buffer sequence'. Should
2033
+ * be constructed whenever a packet of type BINARY_EVENT is
2034
+ * decoded.
2035
+ *
2036
+ * @param {Object} packet
2037
+ * @return {BinaryReconstructor} initialized reconstructor
2038
+ */
2039
+ var BinaryReconstructor = class {
2040
+ constructor(packet) {
2041
+ this.packet = packet;
2042
+ this.buffers = [];
2043
+ this.reconPack = packet;
2044
+ }
2045
+ /**
2046
+ * Method to be called when binary data received from connection
2047
+ * after a BINARY_EVENT packet.
2048
+ *
2049
+ * @param {Buffer | ArrayBuffer} binData - the raw binary data received
2050
+ * @return {null | Object} returns null if more binary data is expected or
2051
+ * a reconstructed packet object if all buffers have been received.
2052
+ */
2053
+ takeBinaryData(binData) {
2054
+ this.buffers.push(binData);
2055
+ if (this.buffers.length === this.reconPack.attachments) {
2056
+ const packet = reconstructPacket(this.reconPack, this.buffers);
2057
+ this.finishedReconstruction();
2058
+ return packet;
2059
+ }
2060
+ return null;
2061
+ }
2062
+ /**
2063
+ * Cleans up binary packet reconstruction variables.
2064
+ */
2065
+ finishedReconstruction() {
2066
+ this.reconPack = null;
2067
+ this.buffers = [];
2068
+ }
2069
+ };
2070
+ function isNamespaceValid(nsp) {
2071
+ return typeof nsp === "string";
2072
+ }
2073
+ var isInteger = Number.isInteger || function(value) {
2074
+ return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
2075
+ };
2076
+ function isAckIdValid(id) {
2077
+ return id === void 0 || isInteger(id);
2078
+ }
2079
+ function isObject(value) {
2080
+ return Object.prototype.toString.call(value) === "[object Object]";
2081
+ }
2082
+ function isDataValid(type, payload) {
2083
+ switch (type) {
2084
+ case PacketType.CONNECT: return payload === void 0 || isObject(payload);
2085
+ case PacketType.DISCONNECT: return payload === void 0;
2086
+ case PacketType.EVENT: return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS$1.indexOf(payload[0]) === -1);
2087
+ case PacketType.ACK: return Array.isArray(payload);
2088
+ case PacketType.CONNECT_ERROR: return typeof payload === "string" || isObject(payload);
2089
+ default: return false;
2090
+ }
2091
+ }
2092
+ function isPacketValid(packet) {
2093
+ return isNamespaceValid(packet.nsp) && isAckIdValid(packet.id) && isDataValid(packet.type, packet.data);
2094
+ }
2095
+ //#endregion
2096
+ //#region ../../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/on.js
2097
+ function on(obj, ev, fn) {
2098
+ obj.on(ev, fn);
2099
+ return function subDestroy() {
2100
+ obj.off(ev, fn);
2101
+ };
2102
+ }
2103
+ //#endregion
2104
+ //#region ../../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/socket.js
2105
+ /**
2106
+ * Internal events.
2107
+ * These events can't be emitted by the user.
2108
+ */
2109
+ var RESERVED_EVENTS = Object.freeze({
2110
+ connect: 1,
2111
+ connect_error: 1,
2112
+ disconnect: 1,
2113
+ disconnecting: 1,
2114
+ newListener: 1,
2115
+ removeListener: 1
2116
+ });
2117
+ /**
2118
+ * A Socket is the fundamental class for interacting with the server.
2119
+ *
2120
+ * A Socket belongs to a certain Namespace (by default /) and uses an underlying {@link Manager} to communicate.
2121
+ *
2122
+ * @example
2123
+ * const socket = io();
2124
+ *
2125
+ * socket.on("connect", () => {
2126
+ * console.log("connected");
2127
+ * });
2128
+ *
2129
+ * // send an event to the server
2130
+ * socket.emit("foo", "bar");
2131
+ *
2132
+ * socket.on("foobar", () => {
2133
+ * // an event was received from the server
2134
+ * });
2135
+ *
2136
+ * // upon disconnection
2137
+ * socket.on("disconnect", (reason) => {
2138
+ * console.log(`disconnected due to ${reason}`);
2139
+ * });
2140
+ */
2141
+ var Socket = class extends Emitter {
2142
+ /**
2143
+ * `Socket` constructor.
2144
+ */
2145
+ constructor(io, nsp, opts) {
2146
+ super();
2147
+ /**
2148
+ * Whether the socket is currently connected to the server.
2149
+ *
2150
+ * @example
2151
+ * const socket = io();
2152
+ *
2153
+ * socket.on("connect", () => {
2154
+ * console.log(socket.connected); // true
2155
+ * });
2156
+ *
2157
+ * socket.on("disconnect", () => {
2158
+ * console.log(socket.connected); // false
2159
+ * });
2160
+ */
2161
+ this.connected = false;
2162
+ /**
2163
+ * Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
2164
+ * be transmitted by the server.
2165
+ */
2166
+ this.recovered = false;
2167
+ /**
2168
+ * Buffer for packets received before the CONNECT packet
2169
+ */
2170
+ this.receiveBuffer = [];
2171
+ /**
2172
+ * Buffer for packets that will be sent once the socket is connected
2173
+ */
2174
+ this.sendBuffer = [];
2175
+ /**
2176
+ * The queue of packets to be sent with retry in case of failure.
2177
+ *
2178
+ * Packets are sent one by one, each waiting for the server acknowledgement, in order to guarantee the delivery order.
2179
+ * @private
2180
+ */
2181
+ this._queue = [];
2182
+ /**
2183
+ * A sequence to generate the ID of the {@link QueuedPacket}.
2184
+ * @private
2185
+ */
2186
+ this._queueSeq = 0;
2187
+ this.ids = 0;
2188
+ /**
2189
+ * A map containing acknowledgement handlers.
2190
+ *
2191
+ * The `withError` attribute is used to differentiate handlers that accept an error as first argument:
2192
+ *
2193
+ * - `socket.emit("test", (err, value) => { ... })` with `ackTimeout` option
2194
+ * - `socket.timeout(5000).emit("test", (err, value) => { ... })`
2195
+ * - `const value = await socket.emitWithAck("test")`
2196
+ *
2197
+ * From those that don't:
2198
+ *
2199
+ * - `socket.emit("test", (value) => { ... });`
2200
+ *
2201
+ * In the first case, the handlers will be called with an error when:
2202
+ *
2203
+ * - the timeout is reached
2204
+ * - the socket gets disconnected
2205
+ *
2206
+ * In the second case, the handlers will be simply discarded upon disconnection, since the client will never receive
2207
+ * an acknowledgement from the server.
2208
+ *
2209
+ * @private
2210
+ */
2211
+ this.acks = {};
2212
+ this.flags = {};
2213
+ this.io = io;
2214
+ this.nsp = nsp;
2215
+ if (opts && opts.auth) this.auth = opts.auth;
2216
+ this._opts = Object.assign({}, opts);
2217
+ if (this.io._autoConnect) this.open();
2218
+ }
2219
+ /**
2220
+ * Whether the socket is currently disconnected
2221
+ *
2222
+ * @example
2223
+ * const socket = io();
2224
+ *
2225
+ * socket.on("connect", () => {
2226
+ * console.log(socket.disconnected); // false
2227
+ * });
2228
+ *
2229
+ * socket.on("disconnect", () => {
2230
+ * console.log(socket.disconnected); // true
2231
+ * });
2232
+ */
2233
+ get disconnected() {
2234
+ return !this.connected;
2235
+ }
2236
+ /**
2237
+ * Subscribe to open, close and packet events
2238
+ *
2239
+ * @private
2240
+ */
2241
+ subEvents() {
2242
+ if (this.subs) return;
2243
+ const io = this.io;
2244
+ this.subs = [
2245
+ on(io, "open", this.onopen.bind(this)),
2246
+ on(io, "packet", this.onpacket.bind(this)),
2247
+ on(io, "error", this.onerror.bind(this)),
2248
+ on(io, "close", this.onclose.bind(this))
2249
+ ];
2250
+ }
2251
+ /**
2252
+ * Whether the Socket will try to reconnect when its Manager connects or reconnects.
2253
+ *
2254
+ * @example
2255
+ * const socket = io();
2256
+ *
2257
+ * console.log(socket.active); // true
2258
+ *
2259
+ * socket.on("disconnect", (reason) => {
2260
+ * if (reason === "io server disconnect") {
2261
+ * // the disconnection was initiated by the server, you need to manually reconnect
2262
+ * console.log(socket.active); // false
2263
+ * }
2264
+ * // else the socket will automatically try to reconnect
2265
+ * console.log(socket.active); // true
2266
+ * });
2267
+ */
2268
+ get active() {
2269
+ return !!this.subs;
2270
+ }
2271
+ /**
2272
+ * "Opens" the socket.
2273
+ *
2274
+ * @example
2275
+ * const socket = io({
2276
+ * autoConnect: false
2277
+ * });
2278
+ *
2279
+ * socket.connect();
2280
+ */
2281
+ connect() {
2282
+ if (this.connected) return this;
2283
+ this.subEvents();
2284
+ if (!this.io["_reconnecting"]) this.io.open();
2285
+ if ("open" === this.io._readyState) this.onopen();
2286
+ return this;
2287
+ }
2288
+ /**
2289
+ * Alias for {@link connect()}.
2290
+ */
2291
+ open() {
2292
+ return this.connect();
2293
+ }
2294
+ /**
2295
+ * Sends a `message` event.
2296
+ *
2297
+ * This method mimics the WebSocket.send() method.
2298
+ *
2299
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
2300
+ *
2301
+ * @example
2302
+ * socket.send("hello");
2303
+ *
2304
+ * // this is equivalent to
2305
+ * socket.emit("message", "hello");
2306
+ *
2307
+ * @return self
2308
+ */
2309
+ send(...args) {
2310
+ args.unshift("message");
2311
+ this.emit.apply(this, args);
2312
+ return this;
2313
+ }
2314
+ /**
2315
+ * Override `emit`.
2316
+ * If the event is in `events`, it's emitted normally.
2317
+ *
2318
+ * @example
2319
+ * socket.emit("hello", "world");
2320
+ *
2321
+ * // all serializable datastructures are supported (no need to call JSON.stringify)
2322
+ * socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
2323
+ *
2324
+ * // with an acknowledgement from the server
2325
+ * socket.emit("hello", "world", (val) => {
2326
+ * // ...
2327
+ * });
2328
+ *
2329
+ * @return self
2330
+ */
2331
+ emit(ev, ...args) {
2332
+ var _a, _b, _c;
2333
+ if (RESERVED_EVENTS.hasOwnProperty(ev)) throw new Error("\"" + ev.toString() + "\" is a reserved event name");
2334
+ args.unshift(ev);
2335
+ if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) {
2336
+ this._addToQueue(args);
2337
+ return this;
2338
+ }
2339
+ const packet = {
2340
+ type: PacketType.EVENT,
2341
+ data: args
2342
+ };
2343
+ packet.options = {};
2344
+ packet.options.compress = this.flags.compress !== false;
2345
+ if ("function" === typeof args[args.length - 1]) {
2346
+ const id = this.ids++;
2347
+ const ack = args.pop();
2348
+ this._registerAckCallback(id, ack);
2349
+ packet.id = id;
2350
+ }
2351
+ const isTransportWritable = (_b = (_a = this.io.engine) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.writable;
2352
+ const isConnected = this.connected && !((_c = this.io.engine) === null || _c === void 0 ? void 0 : _c._hasPingExpired());
2353
+ if (this.flags.volatile && !isTransportWritable) {} else if (isConnected) {
2354
+ this.notifyOutgoingListeners(packet);
2355
+ this.packet(packet);
2356
+ } else this.sendBuffer.push(packet);
2357
+ this.flags = {};
2358
+ return this;
2359
+ }
2360
+ /**
2361
+ * @private
2362
+ */
2363
+ _registerAckCallback(id, ack) {
2364
+ var _a;
2365
+ const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
2366
+ if (timeout === void 0) {
2367
+ this.acks[id] = ack;
2368
+ return;
2369
+ }
2370
+ const timer = this.io.setTimeoutFn(() => {
2371
+ delete this.acks[id];
2372
+ for (let i = 0; i < this.sendBuffer.length; i++) if (this.sendBuffer[i].id === id) this.sendBuffer.splice(i, 1);
2373
+ ack.call(this, /* @__PURE__ */ new Error("operation has timed out"));
2374
+ }, timeout);
2375
+ const fn = (...args) => {
2376
+ this.io.clearTimeoutFn(timer);
2377
+ ack.apply(this, args);
2378
+ };
2379
+ fn.withError = true;
2380
+ this.acks[id] = fn;
2381
+ }
2382
+ /**
2383
+ * Emits an event and waits for an acknowledgement
2384
+ *
2385
+ * @example
2386
+ * // without timeout
2387
+ * const response = await socket.emitWithAck("hello", "world");
2388
+ *
2389
+ * // with a specific timeout
2390
+ * try {
2391
+ * const response = await socket.timeout(1000).emitWithAck("hello", "world");
2392
+ * } catch (err) {
2393
+ * // the server did not acknowledge the event in the given delay
2394
+ * }
2395
+ *
2396
+ * @return a Promise that will be fulfilled when the server acknowledges the event
2397
+ */
2398
+ emitWithAck(ev, ...args) {
2399
+ return new Promise((resolve, reject) => {
2400
+ const fn = (arg1, arg2) => {
2401
+ return arg1 ? reject(arg1) : resolve(arg2);
2402
+ };
2403
+ fn.withError = true;
2404
+ args.push(fn);
2405
+ this.emit(ev, ...args);
2406
+ });
2407
+ }
2408
+ /**
2409
+ * Add the packet to the queue.
2410
+ * @param args
2411
+ * @private
2412
+ */
2413
+ _addToQueue(args) {
2414
+ let ack;
2415
+ if (typeof args[args.length - 1] === "function") ack = args.pop();
2416
+ const packet = {
2417
+ id: this._queueSeq++,
2418
+ tryCount: 0,
2419
+ pending: false,
2420
+ args,
2421
+ flags: Object.assign({ fromQueue: true }, this.flags)
2422
+ };
2423
+ args.push((err, ...responseArgs) => {
2424
+ if (packet !== this._queue[0]) {}
2425
+ if (err !== null) {
2426
+ if (packet.tryCount > this._opts.retries) {
2427
+ this._queue.shift();
2428
+ if (ack) ack(err);
2429
+ }
2430
+ } else {
2431
+ this._queue.shift();
2432
+ if (ack) ack(null, ...responseArgs);
2433
+ }
2434
+ packet.pending = false;
2435
+ return this._drainQueue();
2436
+ });
2437
+ this._queue.push(packet);
2438
+ this._drainQueue();
2439
+ }
2440
+ /**
2441
+ * Send the first packet of the queue, and wait for an acknowledgement from the server.
2442
+ * @param force - whether to resend a packet that has not been acknowledged yet
2443
+ *
2444
+ * @private
2445
+ */
2446
+ _drainQueue(force = false) {
2447
+ if (!this.connected || this._queue.length === 0) return;
2448
+ const packet = this._queue[0];
2449
+ if (packet.pending && !force) return;
2450
+ packet.pending = true;
2451
+ packet.tryCount++;
2452
+ this.flags = packet.flags;
2453
+ this.emit.apply(this, packet.args);
2454
+ }
2455
+ /**
2456
+ * Sends a packet.
2457
+ *
2458
+ * @param packet
2459
+ * @private
2460
+ */
2461
+ packet(packet) {
2462
+ packet.nsp = this.nsp;
2463
+ this.io._packet(packet);
2464
+ }
2465
+ /**
2466
+ * Called upon engine `open`.
2467
+ *
2468
+ * @private
2469
+ */
2470
+ onopen() {
2471
+ if (typeof this.auth == "function") this.auth((data) => {
2472
+ this._sendConnectPacket(data);
2473
+ });
2474
+ else this._sendConnectPacket(this.auth);
2475
+ }
2476
+ /**
2477
+ * Sends a CONNECT packet to initiate the Socket.IO session.
2478
+ *
2479
+ * @param data
2480
+ * @private
2481
+ */
2482
+ _sendConnectPacket(data) {
2483
+ this.packet({
2484
+ type: PacketType.CONNECT,
2485
+ data: this._pid ? Object.assign({
2486
+ pid: this._pid,
2487
+ offset: this._lastOffset
2488
+ }, data) : data
2489
+ });
2490
+ }
2491
+ /**
2492
+ * Called upon engine or manager `error`.
2493
+ *
2494
+ * @param err
2495
+ * @private
2496
+ */
2497
+ onerror(err) {
2498
+ if (!this.connected) this.emitReserved("connect_error", err);
2499
+ }
2500
+ /**
2501
+ * Called upon engine `close`.
2502
+ *
2503
+ * @param reason
2504
+ * @param description
2505
+ * @private
2506
+ */
2507
+ onclose(reason, description) {
2508
+ this.connected = false;
2509
+ delete this.id;
2510
+ this.emitReserved("disconnect", reason, description);
2511
+ this._clearAcks();
2512
+ }
2513
+ /**
2514
+ * Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
2515
+ * the server.
2516
+ *
2517
+ * @private
2518
+ */
2519
+ _clearAcks() {
2520
+ Object.keys(this.acks).forEach((id) => {
2521
+ if (!this.sendBuffer.some((packet) => String(packet.id) === id)) {
2522
+ const ack = this.acks[id];
2523
+ delete this.acks[id];
2524
+ if (ack.withError) ack.call(this, /* @__PURE__ */ new Error("socket has been disconnected"));
2525
+ }
2526
+ });
2527
+ }
2528
+ /**
2529
+ * Called with socket packet.
2530
+ *
2531
+ * @param packet
2532
+ * @private
2533
+ */
2534
+ onpacket(packet) {
2535
+ if (!(packet.nsp === this.nsp)) return;
2536
+ switch (packet.type) {
2537
+ case PacketType.CONNECT:
2538
+ if (packet.data && packet.data.sid) this.onconnect(packet.data.sid, packet.data.pid);
2539
+ else this.emitReserved("connect_error", /* @__PURE__ */ 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/)"));
2540
+ break;
2541
+ case PacketType.EVENT:
2542
+ case PacketType.BINARY_EVENT:
2543
+ this.onevent(packet);
2544
+ break;
2545
+ case PacketType.ACK:
2546
+ case PacketType.BINARY_ACK:
2547
+ this.onack(packet);
2548
+ break;
2549
+ case PacketType.DISCONNECT:
2550
+ this.ondisconnect();
2551
+ break;
2552
+ case PacketType.CONNECT_ERROR:
2553
+ this.destroy();
2554
+ const err = new Error(packet.data.message);
2555
+ err.data = packet.data.data;
2556
+ this.emitReserved("connect_error", err);
2557
+ break;
2558
+ }
2559
+ }
2560
+ /**
2561
+ * Called upon a server event.
2562
+ *
2563
+ * @param packet
2564
+ * @private
2565
+ */
2566
+ onevent(packet) {
2567
+ const args = packet.data || [];
2568
+ if (null != packet.id) args.push(this.ack(packet.id));
2569
+ if (this.connected) this.emitEvent(args);
2570
+ else this.receiveBuffer.push(Object.freeze(args));
2571
+ }
2572
+ emitEvent(args) {
2573
+ if (this._anyListeners && this._anyListeners.length) {
2574
+ const listeners = this._anyListeners.slice();
2575
+ for (const listener of listeners) listener.apply(this, args);
2576
+ }
2577
+ super.emit.apply(this, args);
2578
+ if (this._pid && args.length && typeof args[args.length - 1] === "string") this._lastOffset = args[args.length - 1];
2579
+ }
2580
+ /**
2581
+ * Produces an ack callback to emit with an event.
2582
+ *
2583
+ * @private
2584
+ */
2585
+ ack(id) {
2586
+ const self = this;
2587
+ let sent = false;
2588
+ return function(...args) {
2589
+ if (sent) return;
2590
+ sent = true;
2591
+ self.packet({
2592
+ type: PacketType.ACK,
2593
+ id,
2594
+ data: args
2595
+ });
2596
+ };
2597
+ }
2598
+ /**
2599
+ * Called upon a server acknowledgement.
2600
+ *
2601
+ * @param packet
2602
+ * @private
2603
+ */
2604
+ onack(packet) {
2605
+ const ack = this.acks[packet.id];
2606
+ if (typeof ack !== "function") return;
2607
+ delete this.acks[packet.id];
2608
+ if (ack.withError) packet.data.unshift(null);
2609
+ ack.apply(this, packet.data);
2610
+ }
2611
+ /**
2612
+ * Called upon server connect.
2613
+ *
2614
+ * @private
2615
+ */
2616
+ onconnect(id, pid) {
2617
+ this.id = id;
2618
+ this.recovered = pid && this._pid === pid;
2619
+ this._pid = pid;
2620
+ this.connected = true;
2621
+ this.emitBuffered();
2622
+ this._drainQueue(true);
2623
+ this.emitReserved("connect");
2624
+ }
2625
+ /**
2626
+ * Emit buffered events (received and emitted).
2627
+ *
2628
+ * @private
2629
+ */
2630
+ emitBuffered() {
2631
+ this.receiveBuffer.forEach((args) => this.emitEvent(args));
2632
+ this.receiveBuffer = [];
2633
+ this.sendBuffer.forEach((packet) => {
2634
+ this.notifyOutgoingListeners(packet);
2635
+ this.packet(packet);
2636
+ });
2637
+ this.sendBuffer = [];
2638
+ }
2639
+ /**
2640
+ * Called upon server disconnect.
2641
+ *
2642
+ * @private
2643
+ */
2644
+ ondisconnect() {
2645
+ this.destroy();
2646
+ this.onclose("io server disconnect");
2647
+ }
2648
+ /**
2649
+ * Called upon forced client/server side disconnections,
2650
+ * this method ensures the manager stops tracking us and
2651
+ * that reconnections don't get triggered for this.
2652
+ *
2653
+ * @private
2654
+ */
2655
+ destroy() {
2656
+ if (this.subs) {
2657
+ this.subs.forEach((subDestroy) => subDestroy());
2658
+ this.subs = void 0;
2659
+ }
2660
+ this.io["_destroy"](this);
2661
+ }
2662
+ /**
2663
+ * Disconnects the socket manually. In that case, the socket will not try to reconnect.
2664
+ *
2665
+ * If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
2666
+ *
2667
+ * @example
2668
+ * const socket = io();
2669
+ *
2670
+ * socket.on("disconnect", (reason) => {
2671
+ * // console.log(reason); prints "io client disconnect"
2672
+ * });
2673
+ *
2674
+ * socket.disconnect();
2675
+ *
2676
+ * @return self
2677
+ */
2678
+ disconnect() {
2679
+ if (this.connected) this.packet({ type: PacketType.DISCONNECT });
2680
+ this.destroy();
2681
+ if (this.connected) this.onclose("io client disconnect");
2682
+ return this;
2683
+ }
2684
+ /**
2685
+ * Alias for {@link disconnect()}.
2686
+ *
2687
+ * @return self
2688
+ */
2689
+ close() {
2690
+ return this.disconnect();
2691
+ }
2692
+ /**
2693
+ * Sets the compress flag.
2694
+ *
2695
+ * @example
2696
+ * socket.compress(false).emit("hello");
2697
+ *
2698
+ * @param compress - if `true`, compresses the sending data
2699
+ * @return self
2700
+ */
2701
+ compress(compress) {
2702
+ this.flags.compress = compress;
2703
+ return this;
2704
+ }
2705
+ /**
2706
+ * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
2707
+ * ready to send messages.
2708
+ *
2709
+ * @example
2710
+ * socket.volatile.emit("hello"); // the server may or may not receive it
2711
+ *
2712
+ * @returns self
2713
+ */
2714
+ get volatile() {
2715
+ this.flags.volatile = true;
2716
+ return this;
2717
+ }
2718
+ /**
2719
+ * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
2720
+ * given number of milliseconds have elapsed without an acknowledgement from the server:
2721
+ *
2722
+ * @example
2723
+ * socket.timeout(5000).emit("my-event", (err) => {
2724
+ * if (err) {
2725
+ * // the server did not acknowledge the event in the given delay
2726
+ * }
2727
+ * });
2728
+ *
2729
+ * @returns self
2730
+ */
2731
+ timeout(timeout) {
2732
+ this.flags.timeout = timeout;
2733
+ return this;
2734
+ }
2735
+ /**
2736
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2737
+ * callback.
2738
+ *
2739
+ * @example
2740
+ * socket.onAny((event, ...args) => {
2741
+ * console.log(`got ${event}`);
2742
+ * });
2743
+ *
2744
+ * @param listener
2745
+ */
2746
+ onAny(listener) {
2747
+ this._anyListeners = this._anyListeners || [];
2748
+ this._anyListeners.push(listener);
2749
+ return this;
2750
+ }
2751
+ /**
2752
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2753
+ * callback. The listener is added to the beginning of the listeners array.
2754
+ *
2755
+ * @example
2756
+ * socket.prependAny((event, ...args) => {
2757
+ * console.log(`got event ${event}`);
2758
+ * });
2759
+ *
2760
+ * @param listener
2761
+ */
2762
+ prependAny(listener) {
2763
+ this._anyListeners = this._anyListeners || [];
2764
+ this._anyListeners.unshift(listener);
2765
+ return this;
2766
+ }
2767
+ /**
2768
+ * Removes the listener that will be fired when any event is emitted.
2769
+ *
2770
+ * @example
2771
+ * const catchAllListener = (event, ...args) => {
2772
+ * console.log(`got event ${event}`);
2773
+ * }
2774
+ *
2775
+ * socket.onAny(catchAllListener);
2776
+ *
2777
+ * // remove a specific listener
2778
+ * socket.offAny(catchAllListener);
2779
+ *
2780
+ * // or remove all listeners
2781
+ * socket.offAny();
2782
+ *
2783
+ * @param listener
2784
+ */
2785
+ offAny(listener) {
2786
+ if (!this._anyListeners) return this;
2787
+ if (listener) {
2788
+ const listeners = this._anyListeners;
2789
+ for (let i = 0; i < listeners.length; i++) if (listener === listeners[i]) {
2790
+ listeners.splice(i, 1);
2791
+ return this;
2792
+ }
2793
+ } else this._anyListeners = [];
2794
+ return this;
2795
+ }
2796
+ /**
2797
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
2798
+ * e.g. to remove listeners.
2799
+ */
2800
+ listenersAny() {
2801
+ return this._anyListeners || [];
2802
+ }
2803
+ /**
2804
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2805
+ * callback.
2806
+ *
2807
+ * Note: acknowledgements sent to the server are not included.
2808
+ *
2809
+ * @example
2810
+ * socket.onAnyOutgoing((event, ...args) => {
2811
+ * console.log(`sent event ${event}`);
2812
+ * });
2813
+ *
2814
+ * @param listener
2815
+ */
2816
+ onAnyOutgoing(listener) {
2817
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
2818
+ this._anyOutgoingListeners.push(listener);
2819
+ return this;
2820
+ }
2821
+ /**
2822
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2823
+ * callback. The listener is added to the beginning of the listeners array.
2824
+ *
2825
+ * Note: acknowledgements sent to the server are not included.
2826
+ *
2827
+ * @example
2828
+ * socket.prependAnyOutgoing((event, ...args) => {
2829
+ * console.log(`sent event ${event}`);
2830
+ * });
2831
+ *
2832
+ * @param listener
2833
+ */
2834
+ prependAnyOutgoing(listener) {
2835
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
2836
+ this._anyOutgoingListeners.unshift(listener);
2837
+ return this;
2838
+ }
2839
+ /**
2840
+ * Removes the listener that will be fired when any event is emitted.
2841
+ *
2842
+ * @example
2843
+ * const catchAllListener = (event, ...args) => {
2844
+ * console.log(`sent event ${event}`);
2845
+ * }
2846
+ *
2847
+ * socket.onAnyOutgoing(catchAllListener);
2848
+ *
2849
+ * // remove a specific listener
2850
+ * socket.offAnyOutgoing(catchAllListener);
2851
+ *
2852
+ * // or remove all listeners
2853
+ * socket.offAnyOutgoing();
2854
+ *
2855
+ * @param [listener] - the catch-all listener (optional)
2856
+ */
2857
+ offAnyOutgoing(listener) {
2858
+ if (!this._anyOutgoingListeners) return this;
2859
+ if (listener) {
2860
+ const listeners = this._anyOutgoingListeners;
2861
+ for (let i = 0; i < listeners.length; i++) if (listener === listeners[i]) {
2862
+ listeners.splice(i, 1);
2863
+ return this;
2864
+ }
2865
+ } else this._anyOutgoingListeners = [];
2866
+ return this;
2867
+ }
2868
+ /**
2869
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
2870
+ * e.g. to remove listeners.
2871
+ */
2872
+ listenersAnyOutgoing() {
2873
+ return this._anyOutgoingListeners || [];
2874
+ }
2875
+ /**
2876
+ * Notify the listeners for each packet sent
2877
+ *
2878
+ * @param packet
2879
+ *
2880
+ * @private
2881
+ */
2882
+ notifyOutgoingListeners(packet) {
2883
+ if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
2884
+ const listeners = this._anyOutgoingListeners.slice();
2885
+ for (const listener of listeners) listener.apply(this, packet.data);
2886
+ }
2887
+ }
2888
+ };
2889
+ //#endregion
2890
+ //#region ../../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/contrib/backo2.js
2891
+ /**
2892
+ * Initialize backoff timer with `opts`.
2893
+ *
2894
+ * - `min` initial timeout in milliseconds [100]
2895
+ * - `max` max timeout [10000]
2896
+ * - `jitter` [0]
2897
+ * - `factor` [2]
2898
+ *
2899
+ * @param {Object} opts
2900
+ * @api public
2901
+ */
2902
+ function Backoff(opts) {
2903
+ opts = opts || {};
2904
+ this.ms = opts.min || 100;
2905
+ this.max = opts.max || 1e4;
2906
+ this.factor = opts.factor || 2;
2907
+ this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
2908
+ this.attempts = 0;
2909
+ }
2910
+ /**
2911
+ * Return the backoff duration.
2912
+ *
2913
+ * @return {Number}
2914
+ * @api public
2915
+ */
2916
+ Backoff.prototype.duration = function() {
2917
+ var ms = this.ms * Math.pow(this.factor, this.attempts++);
2918
+ if (this.jitter) {
2919
+ var rand = Math.random();
2920
+ var deviation = Math.floor(rand * this.jitter * ms);
2921
+ ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
2922
+ }
2923
+ return Math.min(ms, this.max) | 0;
2924
+ };
2925
+ /**
2926
+ * Reset the number of attempts.
2927
+ *
2928
+ * @api public
2929
+ */
2930
+ Backoff.prototype.reset = function() {
2931
+ this.attempts = 0;
2932
+ };
2933
+ /**
2934
+ * Set the minimum duration
2935
+ *
2936
+ * @api public
2937
+ */
2938
+ Backoff.prototype.setMin = function(min) {
2939
+ this.ms = min;
2940
+ };
2941
+ /**
2942
+ * Set the maximum duration
2943
+ *
2944
+ * @api public
2945
+ */
2946
+ Backoff.prototype.setMax = function(max) {
2947
+ this.max = max;
2948
+ };
2949
+ /**
2950
+ * Set the jitter
2951
+ *
2952
+ * @api public
2953
+ */
2954
+ Backoff.prototype.setJitter = function(jitter) {
2955
+ this.jitter = jitter;
2956
+ };
2957
+ //#endregion
2958
+ //#region ../../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/manager.js
2959
+ var Manager = class extends Emitter {
2960
+ constructor(uri, opts) {
2961
+ var _a;
2962
+ super();
2963
+ this.nsps = {};
2964
+ this.subs = [];
2965
+ if (uri && "object" === typeof uri) {
2966
+ opts = uri;
2967
+ uri = void 0;
2968
+ }
2969
+ opts = opts || {};
2970
+ opts.path = opts.path || "/socket.io";
2971
+ this.opts = opts;
2972
+ installTimerFunctions(this, opts);
2973
+ this.reconnection(opts.reconnection !== false);
2974
+ this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
2975
+ this.reconnectionDelay(opts.reconnectionDelay || 1e3);
2976
+ this.reconnectionDelayMax(opts.reconnectionDelayMax || 5e3);
2977
+ this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : .5);
2978
+ this.backoff = new Backoff({
2979
+ min: this.reconnectionDelay(),
2980
+ max: this.reconnectionDelayMax(),
2981
+ jitter: this.randomizationFactor()
2982
+ });
2983
+ this.timeout(null == opts.timeout ? 2e4 : opts.timeout);
2984
+ this._readyState = "closed";
2985
+ this.uri = uri;
2986
+ const _parser = opts.parser || esm_exports;
2987
+ this.encoder = new _parser.Encoder();
2988
+ this.decoder = new _parser.Decoder();
2989
+ this._autoConnect = opts.autoConnect !== false;
2990
+ if (this._autoConnect) this.open();
2991
+ }
2992
+ reconnection(v) {
2993
+ if (!arguments.length) return this._reconnection;
2994
+ this._reconnection = !!v;
2995
+ if (!v) this.skipReconnect = true;
2996
+ return this;
2997
+ }
2998
+ reconnectionAttempts(v) {
2999
+ if (v === void 0) return this._reconnectionAttempts;
3000
+ this._reconnectionAttempts = v;
3001
+ return this;
3002
+ }
3003
+ reconnectionDelay(v) {
3004
+ var _a;
3005
+ if (v === void 0) return this._reconnectionDelay;
3006
+ this._reconnectionDelay = v;
3007
+ (_a = this.backoff) === null || _a === void 0 || _a.setMin(v);
3008
+ return this;
3009
+ }
3010
+ randomizationFactor(v) {
3011
+ var _a;
3012
+ if (v === void 0) return this._randomizationFactor;
3013
+ this._randomizationFactor = v;
3014
+ (_a = this.backoff) === null || _a === void 0 || _a.setJitter(v);
3015
+ return this;
3016
+ }
3017
+ reconnectionDelayMax(v) {
3018
+ var _a;
3019
+ if (v === void 0) return this._reconnectionDelayMax;
3020
+ this._reconnectionDelayMax = v;
3021
+ (_a = this.backoff) === null || _a === void 0 || _a.setMax(v);
3022
+ return this;
3023
+ }
3024
+ timeout(v) {
3025
+ if (!arguments.length) return this._timeout;
3026
+ this._timeout = v;
3027
+ return this;
3028
+ }
3029
+ /**
3030
+ * Starts trying to reconnect if reconnection is enabled and we have not
3031
+ * started reconnecting yet
3032
+ *
3033
+ * @private
3034
+ */
3035
+ maybeReconnectOnOpen() {
3036
+ if (!this._reconnecting && this._reconnection && this.backoff.attempts === 0) this.reconnect();
3037
+ }
3038
+ /**
3039
+ * Sets the current transport `socket`.
3040
+ *
3041
+ * @param {Function} fn - optional, callback
3042
+ * @return self
3043
+ * @public
3044
+ */
3045
+ open(fn) {
3046
+ if (~this._readyState.indexOf("open")) return this;
3047
+ this.engine = new Socket$1(this.uri, this.opts);
3048
+ const socket = this.engine;
3049
+ const self = this;
3050
+ this._readyState = "opening";
3051
+ this.skipReconnect = false;
3052
+ const openSubDestroy = on(socket, "open", function() {
3053
+ self.onopen();
3054
+ fn && fn();
3055
+ });
3056
+ const onError = (err) => {
3057
+ this.cleanup();
3058
+ this._readyState = "closed";
3059
+ this.emitReserved("error", err);
3060
+ if (fn) fn(err);
3061
+ else this.maybeReconnectOnOpen();
3062
+ };
3063
+ const errorSub = on(socket, "error", onError);
3064
+ if (false !== this._timeout) {
3065
+ const timeout = this._timeout;
3066
+ const timer = this.setTimeoutFn(() => {
3067
+ openSubDestroy();
3068
+ onError(/* @__PURE__ */ new Error("timeout"));
3069
+ socket.close();
3070
+ }, timeout);
3071
+ if (this.opts.autoUnref) timer.unref();
3072
+ this.subs.push(() => {
3073
+ this.clearTimeoutFn(timer);
3074
+ });
3075
+ }
3076
+ this.subs.push(openSubDestroy);
3077
+ this.subs.push(errorSub);
3078
+ return this;
3079
+ }
3080
+ /**
3081
+ * Alias for open()
3082
+ *
3083
+ * @return self
3084
+ * @public
3085
+ */
3086
+ connect(fn) {
3087
+ return this.open(fn);
3088
+ }
3089
+ /**
3090
+ * Called upon transport open.
3091
+ *
3092
+ * @private
3093
+ */
3094
+ onopen() {
3095
+ this.cleanup();
3096
+ this._readyState = "open";
3097
+ this.emitReserved("open");
3098
+ const socket = this.engine;
3099
+ this.subs.push(on(socket, "ping", this.onping.bind(this)), on(socket, "data", this.ondata.bind(this)), on(socket, "error", this.onerror.bind(this)), on(socket, "close", this.onclose.bind(this)), on(this.decoder, "decoded", this.ondecoded.bind(this)));
3100
+ }
3101
+ /**
3102
+ * Called upon a ping.
3103
+ *
3104
+ * @private
3105
+ */
3106
+ onping() {
3107
+ this.emitReserved("ping");
3108
+ }
3109
+ /**
3110
+ * Called with data.
3111
+ *
3112
+ * @private
3113
+ */
3114
+ ondata(data) {
3115
+ try {
3116
+ this.decoder.add(data);
3117
+ } catch (e) {
3118
+ this.onclose("parse error", e);
3119
+ }
3120
+ }
3121
+ /**
3122
+ * Called when parser fully decodes a packet.
3123
+ *
3124
+ * @private
3125
+ */
3126
+ ondecoded(packet) {
3127
+ nextTick(() => {
3128
+ this.emitReserved("packet", packet);
3129
+ }, this.setTimeoutFn);
3130
+ }
3131
+ /**
3132
+ * Called upon socket error.
3133
+ *
3134
+ * @private
3135
+ */
3136
+ onerror(err) {
3137
+ this.emitReserved("error", err);
3138
+ }
3139
+ /**
3140
+ * Creates a new socket for the given `nsp`.
3141
+ *
3142
+ * @return {Socket}
3143
+ * @public
3144
+ */
3145
+ socket(nsp, opts) {
3146
+ let socket = this.nsps[nsp];
3147
+ if (!socket) {
3148
+ socket = new Socket(this, nsp, opts);
3149
+ this.nsps[nsp] = socket;
3150
+ } else if (this._autoConnect && !socket.active) socket.connect();
3151
+ return socket;
3152
+ }
3153
+ /**
3154
+ * Called upon a socket close.
3155
+ *
3156
+ * @param socket
3157
+ * @private
3158
+ */
3159
+ _destroy(socket) {
3160
+ const nsps = Object.keys(this.nsps);
3161
+ for (const nsp of nsps) if (this.nsps[nsp].active) return;
3162
+ this._close();
3163
+ }
3164
+ /**
3165
+ * Writes a packet.
3166
+ *
3167
+ * @param packet
3168
+ * @private
3169
+ */
3170
+ _packet(packet) {
3171
+ const encodedPackets = this.encoder.encode(packet);
3172
+ for (let i = 0; i < encodedPackets.length; i++) this.engine.write(encodedPackets[i], packet.options);
3173
+ }
3174
+ /**
3175
+ * Clean up transport subscriptions and packet buffer.
3176
+ *
3177
+ * @private
3178
+ */
3179
+ cleanup() {
3180
+ this.subs.forEach((subDestroy) => subDestroy());
3181
+ this.subs.length = 0;
3182
+ this.decoder.destroy();
3183
+ }
3184
+ /**
3185
+ * Close the current socket.
3186
+ *
3187
+ * @private
3188
+ */
3189
+ _close() {
3190
+ this.skipReconnect = true;
3191
+ this._reconnecting = false;
3192
+ this.onclose("forced close");
3193
+ }
3194
+ /**
3195
+ * Alias for close()
3196
+ *
3197
+ * @private
3198
+ */
3199
+ disconnect() {
3200
+ return this._close();
3201
+ }
3202
+ /**
3203
+ * Called when:
3204
+ *
3205
+ * - the low-level engine is closed
3206
+ * - the parser encountered a badly formatted packet
3207
+ * - all sockets are disconnected
3208
+ *
3209
+ * @private
3210
+ */
3211
+ onclose(reason, description) {
3212
+ var _a;
3213
+ this.cleanup();
3214
+ (_a = this.engine) === null || _a === void 0 || _a.close();
3215
+ this.backoff.reset();
3216
+ this._readyState = "closed";
3217
+ this.emitReserved("close", reason, description);
3218
+ if (this._reconnection && !this.skipReconnect) this.reconnect();
3219
+ }
3220
+ /**
3221
+ * Attempt a reconnection.
3222
+ *
3223
+ * @private
3224
+ */
3225
+ reconnect() {
3226
+ if (this._reconnecting || this.skipReconnect) return this;
3227
+ const self = this;
3228
+ if (this.backoff.attempts >= this._reconnectionAttempts) {
3229
+ this.backoff.reset();
3230
+ this.emitReserved("reconnect_failed");
3231
+ this._reconnecting = false;
3232
+ } else {
3233
+ const delay = this.backoff.duration();
3234
+ this._reconnecting = true;
3235
+ const timer = this.setTimeoutFn(() => {
3236
+ if (self.skipReconnect) return;
3237
+ this.emitReserved("reconnect_attempt", self.backoff.attempts);
3238
+ if (self.skipReconnect) return;
3239
+ self.open((err) => {
3240
+ if (err) {
3241
+ self._reconnecting = false;
3242
+ self.reconnect();
3243
+ this.emitReserved("reconnect_error", err);
3244
+ } else self.onreconnect();
3245
+ });
3246
+ }, delay);
3247
+ if (this.opts.autoUnref) timer.unref();
3248
+ this.subs.push(() => {
3249
+ this.clearTimeoutFn(timer);
3250
+ });
3251
+ }
3252
+ }
3253
+ /**
3254
+ * Called upon successful reconnect.
3255
+ *
3256
+ * @private
3257
+ */
3258
+ onreconnect() {
3259
+ const attempt = this.backoff.attempts;
3260
+ this._reconnecting = false;
3261
+ this.backoff.reset();
3262
+ this.emitReserved("reconnect", attempt);
3263
+ }
3264
+ };
3265
+ //#endregion
3266
+ //#region ../../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/index.js
3267
+ /**
3268
+ * Managers cache.
3269
+ */
3270
+ var cache = {};
3271
+ function lookup(uri, opts) {
3272
+ if (typeof uri === "object") {
3273
+ opts = uri;
3274
+ uri = void 0;
3275
+ }
3276
+ opts = opts || {};
3277
+ const parsed = url(uri, opts.path || "/socket.io");
3278
+ const source = parsed.source;
3279
+ const id = parsed.id;
3280
+ const path = parsed.path;
3281
+ const sameNamespace = cache[id] && path in cache[id]["nsps"];
3282
+ const newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace;
3283
+ let io;
3284
+ if (newConnection) io = new Manager(source, opts);
3285
+ else {
3286
+ if (!cache[id]) cache[id] = new Manager(source, opts);
3287
+ io = cache[id];
3288
+ }
3289
+ if (parsed.query && !opts.query) opts.query = parsed.queryKey;
3290
+ return io.socket(parsed.path, opts);
3291
+ }
3292
+ Object.assign(lookup, {
3293
+ Manager,
3294
+ Socket,
3295
+ io: lookup,
3296
+ connect: lookup
3297
+ });
3298
+ //#endregion
3299
+ export { lookup as connect, lookup as default, lookup as io };