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