@aiqa/sdk 0.0.1 → 0.0.2

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