@aiqa/sdk 0.0.2 → 0.0.3
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.
- package/dist/browser/browser.mjs +555 -493
- package/dist/browser/browser.mjs.map +1 -1
- package/dist/node/node.d.mts +1 -1
- package/dist/node/node.mjs +3 -2
- package/dist/node/node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/browser.mjs
CHANGED
|
@@ -76,11 +76,11 @@ function encodePacketToBinary(packet, callback) {
|
|
|
76
76
|
// node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
|
|
77
77
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
78
78
|
var lookup = typeof Uint8Array === "undefined" ? [] : new Uint8Array(256);
|
|
79
|
-
for (let
|
|
80
|
-
lookup[chars.charCodeAt(
|
|
79
|
+
for (let i = 0; i < chars.length; i++) {
|
|
80
|
+
lookup[chars.charCodeAt(i)] = i;
|
|
81
81
|
}
|
|
82
82
|
var decode = (base64) => {
|
|
83
|
-
let bufferLength = base64.length * 0.75, len = base64.length,
|
|
83
|
+
let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
|
84
84
|
if (base64[base64.length - 1] === "=") {
|
|
85
85
|
bufferLength--;
|
|
86
86
|
if (base64[base64.length - 2] === "=") {
|
|
@@ -88,11 +88,11 @@ var decode = (base64) => {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
|
|
91
|
-
for (
|
|
92
|
-
encoded1 = lookup[base64.charCodeAt(
|
|
93
|
-
encoded2 = lookup[base64.charCodeAt(
|
|
94
|
-
encoded3 = lookup[base64.charCodeAt(
|
|
95
|
-
encoded4 = lookup[base64.charCodeAt(
|
|
91
|
+
for (i = 0; i < len; i += 4) {
|
|
92
|
+
encoded1 = lookup[base64.charCodeAt(i)];
|
|
93
|
+
encoded2 = lookup[base64.charCodeAt(i + 1)];
|
|
94
|
+
encoded3 = lookup[base64.charCodeAt(i + 2)];
|
|
95
|
+
encoded4 = lookup[base64.charCodeAt(i + 3)];
|
|
96
96
|
bytes[p++] = encoded1 << 2 | encoded2 >> 4;
|
|
97
97
|
bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
|
|
98
98
|
bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
|
|
@@ -156,13 +156,13 @@ var mapBinary = (data, binaryType) => {
|
|
|
156
156
|
// node_modules/engine.io-parser/build/esm/index.js
|
|
157
157
|
var SEPARATOR = String.fromCharCode(30);
|
|
158
158
|
var encodePayload = (packets, callback) => {
|
|
159
|
-
const
|
|
160
|
-
const encodedPackets = new Array(
|
|
159
|
+
const length = packets.length;
|
|
160
|
+
const encodedPackets = new Array(length);
|
|
161
161
|
let count = 0;
|
|
162
|
-
packets.forEach((packet,
|
|
162
|
+
packets.forEach((packet, i) => {
|
|
163
163
|
encodePacket(packet, false, (encodedPacket) => {
|
|
164
|
-
encodedPackets[
|
|
165
|
-
if (++count ===
|
|
164
|
+
encodedPackets[i] = encodedPacket;
|
|
165
|
+
if (++count === length) {
|
|
166
166
|
callback(encodedPackets.join(SEPARATOR));
|
|
167
167
|
}
|
|
168
168
|
});
|
|
@@ -171,8 +171,8 @@ var encodePayload = (packets, callback) => {
|
|
|
171
171
|
var decodePayload = (encodedPayload, binaryType) => {
|
|
172
172
|
const encodedPackets = encodedPayload.split(SEPARATOR);
|
|
173
173
|
const packets = [];
|
|
174
|
-
for (let
|
|
175
|
-
const decodedPacket = decodePacket(encodedPackets[
|
|
174
|
+
for (let i = 0; i < encodedPackets.length; i++) {
|
|
175
|
+
const decodedPacket = decodePacket(encodedPackets[i], binaryType);
|
|
176
176
|
packets.push(decodedPacket);
|
|
177
177
|
if (decodedPacket.type === "error") {
|
|
178
178
|
break;
|
|
@@ -219,8 +219,8 @@ function concatChunks(chunks, size) {
|
|
|
219
219
|
}
|
|
220
220
|
const buffer = new Uint8Array(size);
|
|
221
221
|
let j = 0;
|
|
222
|
-
for (let
|
|
223
|
-
buffer[
|
|
222
|
+
for (let i = 0; i < size; i++) {
|
|
223
|
+
buffer[i] = chunks[0][j++];
|
|
224
224
|
if (j === chunks[0].length) {
|
|
225
225
|
chunks.shift();
|
|
226
226
|
j = 0;
|
|
@@ -332,10 +332,10 @@ Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.rem
|
|
|
332
332
|
return this;
|
|
333
333
|
}
|
|
334
334
|
var cb;
|
|
335
|
-
for (var
|
|
336
|
-
cb = callbacks[
|
|
335
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
336
|
+
cb = callbacks[i];
|
|
337
337
|
if (cb === fn || cb.fn === fn) {
|
|
338
|
-
callbacks.splice(
|
|
338
|
+
callbacks.splice(i, 1);
|
|
339
339
|
break;
|
|
340
340
|
}
|
|
341
341
|
}
|
|
@@ -347,13 +347,13 @@ Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.rem
|
|
|
347
347
|
Emitter.prototype.emit = function(event) {
|
|
348
348
|
this._callbacks = this._callbacks || {};
|
|
349
349
|
var args = new Array(arguments.length - 1), callbacks = this._callbacks["$" + event];
|
|
350
|
-
for (var
|
|
351
|
-
args[
|
|
350
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
351
|
+
args[i - 1] = arguments[i];
|
|
352
352
|
}
|
|
353
353
|
if (callbacks) {
|
|
354
354
|
callbacks = callbacks.slice(0);
|
|
355
|
-
for (var
|
|
356
|
-
callbacks[
|
|
355
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
356
|
+
callbacks[i].apply(this, args);
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
return this;
|
|
@@ -367,7 +367,15 @@ Emitter.prototype.hasListeners = function(event) {
|
|
|
367
367
|
return !!this.listeners(event).length;
|
|
368
368
|
};
|
|
369
369
|
|
|
370
|
-
// node_modules/engine.io-client/build/esm/
|
|
370
|
+
// node_modules/engine.io-client/build/esm/globals.js
|
|
371
|
+
var nextTick = (() => {
|
|
372
|
+
const isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
|
|
373
|
+
if (isPromiseAvailable) {
|
|
374
|
+
return (cb) => Promise.resolve().then(cb);
|
|
375
|
+
} else {
|
|
376
|
+
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
|
377
|
+
}
|
|
378
|
+
})();
|
|
371
379
|
var globalThisShim = (() => {
|
|
372
380
|
if (typeof self !== "undefined") {
|
|
373
381
|
return self;
|
|
@@ -377,6 +385,9 @@ var globalThisShim = (() => {
|
|
|
377
385
|
return Function("return this")();
|
|
378
386
|
}
|
|
379
387
|
})();
|
|
388
|
+
var defaultBinaryType = "arraybuffer";
|
|
389
|
+
function createCookieJar() {
|
|
390
|
+
}
|
|
380
391
|
|
|
381
392
|
// node_modules/engine.io-client/build/esm/util.js
|
|
382
393
|
function pick(obj, ...attr) {
|
|
@@ -406,31 +417,34 @@ function byteLength(obj) {
|
|
|
406
417
|
return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
|
|
407
418
|
}
|
|
408
419
|
function utf8Length(str) {
|
|
409
|
-
let c = 0,
|
|
410
|
-
for (let
|
|
411
|
-
c = str.charCodeAt(
|
|
420
|
+
let c = 0, length = 0;
|
|
421
|
+
for (let i = 0, l = str.length; i < l; i++) {
|
|
422
|
+
c = str.charCodeAt(i);
|
|
412
423
|
if (c < 128) {
|
|
413
|
-
|
|
424
|
+
length += 1;
|
|
414
425
|
} else if (c < 2048) {
|
|
415
|
-
|
|
426
|
+
length += 2;
|
|
416
427
|
} else if (c < 55296 || c >= 57344) {
|
|
417
|
-
|
|
428
|
+
length += 3;
|
|
418
429
|
} else {
|
|
419
|
-
|
|
420
|
-
|
|
430
|
+
i++;
|
|
431
|
+
length += 4;
|
|
421
432
|
}
|
|
422
433
|
}
|
|
423
|
-
return
|
|
434
|
+
return length;
|
|
435
|
+
}
|
|
436
|
+
function randomString() {
|
|
437
|
+
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
424
438
|
}
|
|
425
439
|
|
|
426
440
|
// node_modules/engine.io-client/build/esm/contrib/parseqs.js
|
|
427
441
|
function encode(obj) {
|
|
428
442
|
let str = "";
|
|
429
|
-
for (let
|
|
430
|
-
if (obj.hasOwnProperty(
|
|
443
|
+
for (let i in obj) {
|
|
444
|
+
if (obj.hasOwnProperty(i)) {
|
|
431
445
|
if (str.length)
|
|
432
446
|
str += "&";
|
|
433
|
-
str += encodeURIComponent(
|
|
447
|
+
str += encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]);
|
|
434
448
|
}
|
|
435
449
|
}
|
|
436
450
|
return str;
|
|
@@ -438,8 +452,8 @@ function encode(obj) {
|
|
|
438
452
|
function decode2(qs) {
|
|
439
453
|
let qry = {};
|
|
440
454
|
let pairs = qs.split("&");
|
|
441
|
-
for (let
|
|
442
|
-
let pair = pairs[
|
|
455
|
+
for (let i = 0, l = pairs.length; i < l; i++) {
|
|
456
|
+
let pair = pairs[i].split("=");
|
|
443
457
|
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
|
444
458
|
}
|
|
445
459
|
return qry;
|
|
@@ -468,6 +482,7 @@ var Transport = class extends Emitter {
|
|
|
468
482
|
this.opts = opts;
|
|
469
483
|
this.query = opts.query;
|
|
470
484
|
this.socket = opts.socket;
|
|
485
|
+
this.supportsBinary = !opts.forceBase64;
|
|
471
486
|
}
|
|
472
487
|
/**
|
|
473
488
|
* Emits an error.
|
|
@@ -563,7 +578,7 @@ var Transport = class extends Emitter {
|
|
|
563
578
|
return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]";
|
|
564
579
|
}
|
|
565
580
|
_port() {
|
|
566
|
-
if (this.opts.port && (this.opts.secure && Number(this.opts.port !== 443
|
|
581
|
+
if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) {
|
|
567
582
|
return ":" + this.opts.port;
|
|
568
583
|
} else {
|
|
569
584
|
return "";
|
|
@@ -575,89 +590,11 @@ var Transport = class extends Emitter {
|
|
|
575
590
|
}
|
|
576
591
|
};
|
|
577
592
|
|
|
578
|
-
// node_modules/engine.io-client/build/esm/contrib/yeast.js
|
|
579
|
-
var alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split("");
|
|
580
|
-
var length = 64;
|
|
581
|
-
var map = {};
|
|
582
|
-
var seed = 0;
|
|
583
|
-
var i = 0;
|
|
584
|
-
var prev;
|
|
585
|
-
function encode2(num) {
|
|
586
|
-
let encoded = "";
|
|
587
|
-
do {
|
|
588
|
-
encoded = alphabet[num % length] + encoded;
|
|
589
|
-
num = Math.floor(num / length);
|
|
590
|
-
} while (num > 0);
|
|
591
|
-
return encoded;
|
|
592
|
-
}
|
|
593
|
-
function yeast() {
|
|
594
|
-
const now = encode2(+/* @__PURE__ */ new Date());
|
|
595
|
-
if (now !== prev)
|
|
596
|
-
return seed = 0, prev = now;
|
|
597
|
-
return now + "." + encode2(seed++);
|
|
598
|
-
}
|
|
599
|
-
for (; i < length; i++)
|
|
600
|
-
map[alphabet[i]] = i;
|
|
601
|
-
|
|
602
|
-
// node_modules/engine.io-client/build/esm/contrib/has-cors.js
|
|
603
|
-
var value = false;
|
|
604
|
-
try {
|
|
605
|
-
value = typeof XMLHttpRequest !== "undefined" && "withCredentials" in new XMLHttpRequest();
|
|
606
|
-
} catch (err) {
|
|
607
|
-
}
|
|
608
|
-
var hasCORS = value;
|
|
609
|
-
|
|
610
|
-
// node_modules/engine.io-client/build/esm/transports/xmlhttprequest.browser.js
|
|
611
|
-
function XHR(opts) {
|
|
612
|
-
const xdomain = opts.xdomain;
|
|
613
|
-
try {
|
|
614
|
-
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
|
615
|
-
return new XMLHttpRequest();
|
|
616
|
-
}
|
|
617
|
-
} catch (e) {
|
|
618
|
-
}
|
|
619
|
-
if (!xdomain) {
|
|
620
|
-
try {
|
|
621
|
-
return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
622
|
-
} catch (e) {
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
function createCookieJar() {
|
|
627
|
-
}
|
|
628
|
-
|
|
629
593
|
// node_modules/engine.io-client/build/esm/transports/polling.js
|
|
630
|
-
function empty() {
|
|
631
|
-
}
|
|
632
|
-
var hasXHR2 = (function() {
|
|
633
|
-
const xhr = new XHR({
|
|
634
|
-
xdomain: false
|
|
635
|
-
});
|
|
636
|
-
return null != xhr.responseType;
|
|
637
|
-
})();
|
|
638
594
|
var Polling = class extends Transport {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
* @param {Object} opts
|
|
643
|
-
* @package
|
|
644
|
-
*/
|
|
645
|
-
constructor(opts) {
|
|
646
|
-
super(opts);
|
|
647
|
-
this.polling = false;
|
|
648
|
-
if (typeof location !== "undefined") {
|
|
649
|
-
const isSSL = "https:" === location.protocol;
|
|
650
|
-
let port = location.port;
|
|
651
|
-
if (!port) {
|
|
652
|
-
port = isSSL ? "443" : "80";
|
|
653
|
-
}
|
|
654
|
-
this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
|
|
655
|
-
}
|
|
656
|
-
const forceBase64 = opts && opts.forceBase64;
|
|
657
|
-
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
658
|
-
if (this.opts.withCredentials) {
|
|
659
|
-
this.cookieJar = createCookieJar();
|
|
660
|
-
}
|
|
595
|
+
constructor() {
|
|
596
|
+
super(...arguments);
|
|
597
|
+
this._polling = false;
|
|
661
598
|
}
|
|
662
599
|
get name() {
|
|
663
600
|
return "polling";
|
|
@@ -669,7 +606,7 @@ var Polling = class extends Transport {
|
|
|
669
606
|
* @protected
|
|
670
607
|
*/
|
|
671
608
|
doOpen() {
|
|
672
|
-
this.
|
|
609
|
+
this._poll();
|
|
673
610
|
}
|
|
674
611
|
/**
|
|
675
612
|
* Pauses polling.
|
|
@@ -683,9 +620,9 @@ var Polling = class extends Transport {
|
|
|
683
620
|
this.readyState = "paused";
|
|
684
621
|
onPause();
|
|
685
622
|
};
|
|
686
|
-
if (this.
|
|
623
|
+
if (this._polling || !this.writable) {
|
|
687
624
|
let total = 0;
|
|
688
|
-
if (this.
|
|
625
|
+
if (this._polling) {
|
|
689
626
|
total++;
|
|
690
627
|
this.once("pollComplete", function() {
|
|
691
628
|
--total || pause();
|
|
@@ -706,8 +643,8 @@ var Polling = class extends Transport {
|
|
|
706
643
|
*
|
|
707
644
|
* @private
|
|
708
645
|
*/
|
|
709
|
-
|
|
710
|
-
this.
|
|
646
|
+
_poll() {
|
|
647
|
+
this._polling = true;
|
|
711
648
|
this.doPoll();
|
|
712
649
|
this.emitReserved("poll");
|
|
713
650
|
}
|
|
@@ -729,10 +666,10 @@ var Polling = class extends Transport {
|
|
|
729
666
|
};
|
|
730
667
|
decodePayload(data, this.socket.binaryType).forEach(callback);
|
|
731
668
|
if ("closed" !== this.readyState) {
|
|
732
|
-
this.
|
|
669
|
+
this._polling = false;
|
|
733
670
|
this.emitReserved("pollComplete");
|
|
734
671
|
if ("open" === this.readyState) {
|
|
735
|
-
this.
|
|
672
|
+
this._poll();
|
|
736
673
|
} else {
|
|
737
674
|
}
|
|
738
675
|
}
|
|
@@ -776,22 +713,43 @@ var Polling = class extends Transport {
|
|
|
776
713
|
const schema = this.opts.secure ? "https" : "http";
|
|
777
714
|
const query = this.query || {};
|
|
778
715
|
if (false !== this.opts.timestampRequests) {
|
|
779
|
-
query[this.opts.timestampParam] =
|
|
716
|
+
query[this.opts.timestampParam] = randomString();
|
|
780
717
|
}
|
|
781
718
|
if (!this.supportsBinary && !query.sid) {
|
|
782
719
|
query.b64 = 1;
|
|
783
720
|
}
|
|
784
721
|
return this.createUri(schema, query);
|
|
785
722
|
}
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
// node_modules/engine.io-client/build/esm/contrib/has-cors.js
|
|
726
|
+
var value = false;
|
|
727
|
+
try {
|
|
728
|
+
value = typeof XMLHttpRequest !== "undefined" && "withCredentials" in new XMLHttpRequest();
|
|
729
|
+
} catch (err) {
|
|
730
|
+
}
|
|
731
|
+
var hasCORS = value;
|
|
732
|
+
|
|
733
|
+
// node_modules/engine.io-client/build/esm/transports/polling-xhr.js
|
|
734
|
+
function empty() {
|
|
735
|
+
}
|
|
736
|
+
var BaseXHR = class extends Polling {
|
|
786
737
|
/**
|
|
787
|
-
*
|
|
738
|
+
* XHR Polling constructor.
|
|
788
739
|
*
|
|
789
|
-
* @param {
|
|
790
|
-
* @
|
|
740
|
+
* @param {Object} opts
|
|
741
|
+
* @package
|
|
791
742
|
*/
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
743
|
+
constructor(opts) {
|
|
744
|
+
super(opts);
|
|
745
|
+
if (typeof location !== "undefined") {
|
|
746
|
+
const isSSL = "https:" === location.protocol;
|
|
747
|
+
let port = location.port;
|
|
748
|
+
if (!port) {
|
|
749
|
+
port = isSSL ? "443" : "80";
|
|
750
|
+
}
|
|
751
|
+
this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
|
|
752
|
+
}
|
|
795
753
|
}
|
|
796
754
|
/**
|
|
797
755
|
* Sends data.
|
|
@@ -831,39 +789,40 @@ var Request = class _Request extends Emitter {
|
|
|
831
789
|
* @param {Object} options
|
|
832
790
|
* @package
|
|
833
791
|
*/
|
|
834
|
-
constructor(uri, opts) {
|
|
792
|
+
constructor(createRequest, uri, opts) {
|
|
835
793
|
super();
|
|
794
|
+
this.createRequest = createRequest;
|
|
836
795
|
installTimerFunctions(this, opts);
|
|
837
|
-
this.
|
|
838
|
-
this.
|
|
839
|
-
this.
|
|
840
|
-
this.
|
|
841
|
-
this.
|
|
796
|
+
this._opts = opts;
|
|
797
|
+
this._method = opts.method || "GET";
|
|
798
|
+
this._uri = uri;
|
|
799
|
+
this._data = void 0 !== opts.data ? opts.data : null;
|
|
800
|
+
this._create();
|
|
842
801
|
}
|
|
843
802
|
/**
|
|
844
803
|
* Creates the XHR object and sends the request.
|
|
845
804
|
*
|
|
846
805
|
* @private
|
|
847
806
|
*/
|
|
848
|
-
|
|
807
|
+
_create() {
|
|
849
808
|
var _a;
|
|
850
|
-
const opts = pick(this.
|
|
851
|
-
opts.xdomain = !!this.
|
|
852
|
-
const xhr = this.
|
|
809
|
+
const opts = pick(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
810
|
+
opts.xdomain = !!this._opts.xd;
|
|
811
|
+
const xhr = this._xhr = this.createRequest(opts);
|
|
853
812
|
try {
|
|
854
|
-
xhr.open(this.
|
|
813
|
+
xhr.open(this._method, this._uri, true);
|
|
855
814
|
try {
|
|
856
|
-
if (this.
|
|
815
|
+
if (this._opts.extraHeaders) {
|
|
857
816
|
xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
|
|
858
|
-
for (let
|
|
859
|
-
if (this.
|
|
860
|
-
xhr.setRequestHeader(
|
|
817
|
+
for (let i in this._opts.extraHeaders) {
|
|
818
|
+
if (this._opts.extraHeaders.hasOwnProperty(i)) {
|
|
819
|
+
xhr.setRequestHeader(i, this._opts.extraHeaders[i]);
|
|
861
820
|
}
|
|
862
821
|
}
|
|
863
822
|
}
|
|
864
823
|
} catch (e) {
|
|
865
824
|
}
|
|
866
|
-
if ("POST" === this.
|
|
825
|
+
if ("POST" === this._method) {
|
|
867
826
|
try {
|
|
868
827
|
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
869
828
|
} catch (e) {
|
|
@@ -873,38 +832,41 @@ var Request = class _Request extends Emitter {
|
|
|
873
832
|
xhr.setRequestHeader("Accept", "*/*");
|
|
874
833
|
} catch (e) {
|
|
875
834
|
}
|
|
876
|
-
(_a = this.
|
|
835
|
+
(_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
|
|
877
836
|
if ("withCredentials" in xhr) {
|
|
878
|
-
xhr.withCredentials = this.
|
|
837
|
+
xhr.withCredentials = this._opts.withCredentials;
|
|
879
838
|
}
|
|
880
|
-
if (this.
|
|
881
|
-
xhr.timeout = this.
|
|
839
|
+
if (this._opts.requestTimeout) {
|
|
840
|
+
xhr.timeout = this._opts.requestTimeout;
|
|
882
841
|
}
|
|
883
842
|
xhr.onreadystatechange = () => {
|
|
884
843
|
var _a2;
|
|
885
844
|
if (xhr.readyState === 3) {
|
|
886
|
-
(_a2 = this.
|
|
845
|
+
(_a2 = this._opts.cookieJar) === null || _a2 === void 0 ? void 0 : _a2.parseCookies(
|
|
846
|
+
// @ts-ignore
|
|
847
|
+
xhr.getResponseHeader("set-cookie")
|
|
848
|
+
);
|
|
887
849
|
}
|
|
888
850
|
if (4 !== xhr.readyState)
|
|
889
851
|
return;
|
|
890
852
|
if (200 === xhr.status || 1223 === xhr.status) {
|
|
891
|
-
this.
|
|
853
|
+
this._onLoad();
|
|
892
854
|
} else {
|
|
893
855
|
this.setTimeoutFn(() => {
|
|
894
|
-
this.
|
|
856
|
+
this._onError(typeof xhr.status === "number" ? xhr.status : 0);
|
|
895
857
|
}, 0);
|
|
896
858
|
}
|
|
897
859
|
};
|
|
898
|
-
xhr.send(this.
|
|
860
|
+
xhr.send(this._data);
|
|
899
861
|
} catch (e) {
|
|
900
862
|
this.setTimeoutFn(() => {
|
|
901
|
-
this.
|
|
863
|
+
this._onError(e);
|
|
902
864
|
}, 0);
|
|
903
865
|
return;
|
|
904
866
|
}
|
|
905
867
|
if (typeof document !== "undefined") {
|
|
906
|
-
this.
|
|
907
|
-
_Request.requests[this.
|
|
868
|
+
this._index = _Request.requestsCount++;
|
|
869
|
+
_Request.requests[this._index] = this;
|
|
908
870
|
}
|
|
909
871
|
}
|
|
910
872
|
/**
|
|
@@ -912,42 +874,42 @@ var Request = class _Request extends Emitter {
|
|
|
912
874
|
*
|
|
913
875
|
* @private
|
|
914
876
|
*/
|
|
915
|
-
|
|
916
|
-
this.emitReserved("error", err, this.
|
|
917
|
-
this.
|
|
877
|
+
_onError(err) {
|
|
878
|
+
this.emitReserved("error", err, this._xhr);
|
|
879
|
+
this._cleanup(true);
|
|
918
880
|
}
|
|
919
881
|
/**
|
|
920
882
|
* Cleans up house.
|
|
921
883
|
*
|
|
922
884
|
* @private
|
|
923
885
|
*/
|
|
924
|
-
|
|
925
|
-
if ("undefined" === typeof this.
|
|
886
|
+
_cleanup(fromError) {
|
|
887
|
+
if ("undefined" === typeof this._xhr || null === this._xhr) {
|
|
926
888
|
return;
|
|
927
889
|
}
|
|
928
|
-
this.
|
|
890
|
+
this._xhr.onreadystatechange = empty;
|
|
929
891
|
if (fromError) {
|
|
930
892
|
try {
|
|
931
|
-
this.
|
|
893
|
+
this._xhr.abort();
|
|
932
894
|
} catch (e) {
|
|
933
895
|
}
|
|
934
896
|
}
|
|
935
897
|
if (typeof document !== "undefined") {
|
|
936
|
-
delete _Request.requests[this.
|
|
898
|
+
delete _Request.requests[this._index];
|
|
937
899
|
}
|
|
938
|
-
this.
|
|
900
|
+
this._xhr = null;
|
|
939
901
|
}
|
|
940
902
|
/**
|
|
941
903
|
* Called upon load.
|
|
942
904
|
*
|
|
943
905
|
* @private
|
|
944
906
|
*/
|
|
945
|
-
|
|
946
|
-
const data = this.
|
|
907
|
+
_onLoad() {
|
|
908
|
+
const data = this._xhr.responseText;
|
|
947
909
|
if (data !== null) {
|
|
948
910
|
this.emitReserved("data", data);
|
|
949
911
|
this.emitReserved("success");
|
|
950
|
-
this.
|
|
912
|
+
this._cleanup();
|
|
951
913
|
}
|
|
952
914
|
}
|
|
953
915
|
/**
|
|
@@ -956,7 +918,7 @@ var Request = class _Request extends Emitter {
|
|
|
956
918
|
* @package
|
|
957
919
|
*/
|
|
958
920
|
abort() {
|
|
959
|
-
this.
|
|
921
|
+
this._cleanup();
|
|
960
922
|
}
|
|
961
923
|
};
|
|
962
924
|
Request.requestsCount = 0;
|
|
@@ -970,46 +932,52 @@ if (typeof document !== "undefined") {
|
|
|
970
932
|
}
|
|
971
933
|
}
|
|
972
934
|
function unloadHandler() {
|
|
973
|
-
for (let
|
|
974
|
-
if (Request.requests.hasOwnProperty(
|
|
975
|
-
Request.requests[
|
|
935
|
+
for (let i in Request.requests) {
|
|
936
|
+
if (Request.requests.hasOwnProperty(i)) {
|
|
937
|
+
Request.requests[i].abort();
|
|
976
938
|
}
|
|
977
939
|
}
|
|
978
940
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
return (cb) => Promise.resolve().then(cb);
|
|
985
|
-
} else {
|
|
986
|
-
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
|
987
|
-
}
|
|
941
|
+
var hasXHR2 = (function() {
|
|
942
|
+
const xhr = newRequest({
|
|
943
|
+
xdomain: false
|
|
944
|
+
});
|
|
945
|
+
return xhr && xhr.responseType !== null;
|
|
988
946
|
})();
|
|
989
|
-
var
|
|
990
|
-
var usingBrowserWebSocket = true;
|
|
991
|
-
var defaultBinaryType = "arraybuffer";
|
|
992
|
-
|
|
993
|
-
// node_modules/engine.io-client/build/esm/transports/websocket.js
|
|
994
|
-
var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
|
|
995
|
-
var WS = class extends Transport {
|
|
996
|
-
/**
|
|
997
|
-
* WebSocket transport constructor.
|
|
998
|
-
*
|
|
999
|
-
* @param {Object} opts - connection options
|
|
1000
|
-
* @protected
|
|
1001
|
-
*/
|
|
947
|
+
var XHR = class extends BaseXHR {
|
|
1002
948
|
constructor(opts) {
|
|
1003
949
|
super(opts);
|
|
1004
|
-
|
|
950
|
+
const forceBase64 = opts && opts.forceBase64;
|
|
951
|
+
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
1005
952
|
}
|
|
953
|
+
request(opts = {}) {
|
|
954
|
+
Object.assign(opts, { xd: this.xd }, this.opts);
|
|
955
|
+
return new Request(newRequest, this.uri(), opts);
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
function newRequest(opts) {
|
|
959
|
+
const xdomain = opts.xdomain;
|
|
960
|
+
try {
|
|
961
|
+
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
|
962
|
+
return new XMLHttpRequest();
|
|
963
|
+
}
|
|
964
|
+
} catch (e) {
|
|
965
|
+
}
|
|
966
|
+
if (!xdomain) {
|
|
967
|
+
try {
|
|
968
|
+
return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
969
|
+
} catch (e) {
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// node_modules/engine.io-client/build/esm/transports/websocket.js
|
|
975
|
+
var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
|
|
976
|
+
var BaseWS = class extends Transport {
|
|
1006
977
|
get name() {
|
|
1007
978
|
return "websocket";
|
|
1008
979
|
}
|
|
1009
980
|
doOpen() {
|
|
1010
|
-
if (!this.check()) {
|
|
1011
|
-
return;
|
|
1012
|
-
}
|
|
1013
981
|
const uri = this.uri();
|
|
1014
982
|
const protocols = this.opts.protocols;
|
|
1015
983
|
const opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
@@ -1017,7 +985,7 @@ var WS = class extends Transport {
|
|
|
1017
985
|
opts.headers = this.opts.extraHeaders;
|
|
1018
986
|
}
|
|
1019
987
|
try {
|
|
1020
|
-
this.ws =
|
|
988
|
+
this.ws = this.createSocket(uri, protocols, opts);
|
|
1021
989
|
} catch (err) {
|
|
1022
990
|
return this.emitReserved("error", err);
|
|
1023
991
|
}
|
|
@@ -1045,31 +1013,12 @@ var WS = class extends Transport {
|
|
|
1045
1013
|
}
|
|
1046
1014
|
write(packets) {
|
|
1047
1015
|
this.writable = false;
|
|
1048
|
-
for (let
|
|
1049
|
-
const packet = packets[
|
|
1050
|
-
const lastPacket =
|
|
1016
|
+
for (let i = 0; i < packets.length; i++) {
|
|
1017
|
+
const packet = packets[i];
|
|
1018
|
+
const lastPacket = i === packets.length - 1;
|
|
1051
1019
|
encodePacket(packet, this.supportsBinary, (data) => {
|
|
1052
|
-
const opts = {};
|
|
1053
|
-
if (!usingBrowserWebSocket) {
|
|
1054
|
-
if (packet.options) {
|
|
1055
|
-
opts.compress = packet.options.compress;
|
|
1056
|
-
}
|
|
1057
|
-
if (this.opts.perMessageDeflate) {
|
|
1058
|
-
const len = (
|
|
1059
|
-
// @ts-ignore
|
|
1060
|
-
"string" === typeof data ? Buffer.byteLength(data) : data.length
|
|
1061
|
-
);
|
|
1062
|
-
if (len < this.opts.perMessageDeflate.threshold) {
|
|
1063
|
-
opts.compress = false;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
1020
|
try {
|
|
1068
|
-
|
|
1069
|
-
this.ws.send(data);
|
|
1070
|
-
} else {
|
|
1071
|
-
this.ws.send(data, opts);
|
|
1072
|
-
}
|
|
1021
|
+
this.doWrite(packet, data);
|
|
1073
1022
|
} catch (e) {
|
|
1074
1023
|
}
|
|
1075
1024
|
if (lastPacket) {
|
|
@@ -1083,6 +1032,8 @@ var WS = class extends Transport {
|
|
|
1083
1032
|
}
|
|
1084
1033
|
doClose() {
|
|
1085
1034
|
if (typeof this.ws !== "undefined") {
|
|
1035
|
+
this.ws.onerror = () => {
|
|
1036
|
+
};
|
|
1086
1037
|
this.ws.close();
|
|
1087
1038
|
this.ws = null;
|
|
1088
1039
|
}
|
|
@@ -1096,21 +1047,21 @@ var WS = class extends Transport {
|
|
|
1096
1047
|
const schema = this.opts.secure ? "wss" : "ws";
|
|
1097
1048
|
const query = this.query || {};
|
|
1098
1049
|
if (this.opts.timestampRequests) {
|
|
1099
|
-
query[this.opts.timestampParam] =
|
|
1050
|
+
query[this.opts.timestampParam] = randomString();
|
|
1100
1051
|
}
|
|
1101
1052
|
if (!this.supportsBinary) {
|
|
1102
1053
|
query.b64 = 1;
|
|
1103
1054
|
}
|
|
1104
1055
|
return this.createUri(schema, query);
|
|
1105
1056
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1057
|
+
};
|
|
1058
|
+
var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
1059
|
+
var WS = class extends BaseWS {
|
|
1060
|
+
createSocket(uri, protocols, opts) {
|
|
1061
|
+
return !isReactNative ? protocols ? new WebSocketCtor(uri, protocols) : new WebSocketCtor(uri) : new WebSocketCtor(uri, protocols, opts);
|
|
1062
|
+
}
|
|
1063
|
+
doWrite(_packet, data) {
|
|
1064
|
+
this.ws.send(data);
|
|
1114
1065
|
}
|
|
1115
1066
|
};
|
|
1116
1067
|
|
|
@@ -1120,22 +1071,23 @@ var WT = class extends Transport {
|
|
|
1120
1071
|
return "webtransport";
|
|
1121
1072
|
}
|
|
1122
1073
|
doOpen() {
|
|
1123
|
-
|
|
1124
|
-
|
|
1074
|
+
try {
|
|
1075
|
+
this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
|
|
1076
|
+
} catch (err) {
|
|
1077
|
+
return this.emitReserved("error", err);
|
|
1125
1078
|
}
|
|
1126
|
-
this.
|
|
1127
|
-
this.transport.closed.then(() => {
|
|
1079
|
+
this._transport.closed.then(() => {
|
|
1128
1080
|
this.onClose();
|
|
1129
1081
|
}).catch((err) => {
|
|
1130
1082
|
this.onError("webtransport error", err);
|
|
1131
1083
|
});
|
|
1132
|
-
this.
|
|
1133
|
-
this.
|
|
1084
|
+
this._transport.ready.then(() => {
|
|
1085
|
+
this._transport.createBidirectionalStream().then((stream) => {
|
|
1134
1086
|
const decoderStream = createPacketDecoderStream(Number.MAX_SAFE_INTEGER, this.socket.binaryType);
|
|
1135
1087
|
const reader = stream.readable.pipeThrough(decoderStream).getReader();
|
|
1136
1088
|
const encoderStream = createPacketEncoderStream();
|
|
1137
1089
|
encoderStream.readable.pipeTo(stream.writable);
|
|
1138
|
-
this.
|
|
1090
|
+
this._writer = encoderStream.writable.getWriter();
|
|
1139
1091
|
const read = () => {
|
|
1140
1092
|
reader.read().then(({ done, value: value2 }) => {
|
|
1141
1093
|
if (done) {
|
|
@@ -1151,16 +1103,16 @@ var WT = class extends Transport {
|
|
|
1151
1103
|
if (this.query.sid) {
|
|
1152
1104
|
packet.data = `{"sid":"${this.query.sid}"}`;
|
|
1153
1105
|
}
|
|
1154
|
-
this.
|
|
1106
|
+
this._writer.write(packet).then(() => this.onOpen());
|
|
1155
1107
|
});
|
|
1156
1108
|
});
|
|
1157
1109
|
}
|
|
1158
1110
|
write(packets) {
|
|
1159
1111
|
this.writable = false;
|
|
1160
|
-
for (let
|
|
1161
|
-
const packet = packets[
|
|
1162
|
-
const lastPacket =
|
|
1163
|
-
this.
|
|
1112
|
+
for (let i = 0; i < packets.length; i++) {
|
|
1113
|
+
const packet = packets[i];
|
|
1114
|
+
const lastPacket = i === packets.length - 1;
|
|
1115
|
+
this._writer.write(packet).then(() => {
|
|
1164
1116
|
if (lastPacket) {
|
|
1165
1117
|
nextTick(() => {
|
|
1166
1118
|
this.writable = true;
|
|
@@ -1172,7 +1124,7 @@ var WT = class extends Transport {
|
|
|
1172
1124
|
}
|
|
1173
1125
|
doClose() {
|
|
1174
1126
|
var _a;
|
|
1175
|
-
(_a = this.
|
|
1127
|
+
(_a = this._transport) === null || _a === void 0 ? void 0 : _a.close();
|
|
1176
1128
|
}
|
|
1177
1129
|
};
|
|
1178
1130
|
|
|
@@ -1180,7 +1132,7 @@ var WT = class extends Transport {
|
|
|
1180
1132
|
var transports = {
|
|
1181
1133
|
websocket: WS,
|
|
1182
1134
|
webtransport: WT,
|
|
1183
|
-
polling:
|
|
1135
|
+
polling: XHR
|
|
1184
1136
|
};
|
|
1185
1137
|
|
|
1186
1138
|
// node_modules/engine.io-client/build/esm/contrib/parseuri.js
|
|
@@ -1202,16 +1154,16 @@ var parts = [
|
|
|
1202
1154
|
"anchor"
|
|
1203
1155
|
];
|
|
1204
1156
|
function parse(str) {
|
|
1205
|
-
if (str.length >
|
|
1157
|
+
if (str.length > 8e3) {
|
|
1206
1158
|
throw "URI too long";
|
|
1207
1159
|
}
|
|
1208
1160
|
const src = str, b = str.indexOf("["), e = str.indexOf("]");
|
|
1209
1161
|
if (b != -1 && e != -1) {
|
|
1210
1162
|
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ";") + str.substring(e, str.length);
|
|
1211
1163
|
}
|
|
1212
|
-
let m = re.exec(str || ""), uri = {},
|
|
1213
|
-
while (
|
|
1214
|
-
uri[parts[
|
|
1164
|
+
let m = re.exec(str || ""), uri = {}, i = 14;
|
|
1165
|
+
while (i--) {
|
|
1166
|
+
uri[parts[i]] = m[i] || "";
|
|
1215
1167
|
}
|
|
1216
1168
|
if (b != -1 && e != -1) {
|
|
1217
1169
|
uri.source = src;
|
|
@@ -1244,28 +1196,40 @@ function queryKey(uri, query) {
|
|
|
1244
1196
|
}
|
|
1245
1197
|
|
|
1246
1198
|
// node_modules/engine.io-client/build/esm/socket.js
|
|
1247
|
-
var
|
|
1199
|
+
var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function";
|
|
1200
|
+
var OFFLINE_EVENT_LISTENERS = [];
|
|
1201
|
+
if (withEventListeners) {
|
|
1202
|
+
addEventListener("offline", () => {
|
|
1203
|
+
OFFLINE_EVENT_LISTENERS.forEach((listener) => listener());
|
|
1204
|
+
}, false);
|
|
1205
|
+
}
|
|
1206
|
+
var SocketWithoutUpgrade = class _SocketWithoutUpgrade extends Emitter {
|
|
1248
1207
|
/**
|
|
1249
1208
|
* Socket constructor.
|
|
1250
1209
|
*
|
|
1251
1210
|
* @param {String|Object} uri - uri or options
|
|
1252
1211
|
* @param {Object} opts - options
|
|
1253
1212
|
*/
|
|
1254
|
-
constructor(uri, opts
|
|
1213
|
+
constructor(uri, opts) {
|
|
1255
1214
|
super();
|
|
1256
1215
|
this.binaryType = defaultBinaryType;
|
|
1257
1216
|
this.writeBuffer = [];
|
|
1217
|
+
this._prevBufferLen = 0;
|
|
1218
|
+
this._pingInterval = -1;
|
|
1219
|
+
this._pingTimeout = -1;
|
|
1220
|
+
this._maxPayload = -1;
|
|
1221
|
+
this._pingTimeoutTime = Infinity;
|
|
1258
1222
|
if (uri && "object" === typeof uri) {
|
|
1259
1223
|
opts = uri;
|
|
1260
1224
|
uri = null;
|
|
1261
1225
|
}
|
|
1262
1226
|
if (uri) {
|
|
1263
|
-
|
|
1264
|
-
opts.hostname =
|
|
1265
|
-
opts.secure =
|
|
1266
|
-
opts.port =
|
|
1267
|
-
if (
|
|
1268
|
-
opts.query =
|
|
1227
|
+
const parsedUri = parse(uri);
|
|
1228
|
+
opts.hostname = parsedUri.host;
|
|
1229
|
+
opts.secure = parsedUri.protocol === "https" || parsedUri.protocol === "wss";
|
|
1230
|
+
opts.port = parsedUri.port;
|
|
1231
|
+
if (parsedUri.query)
|
|
1232
|
+
opts.query = parsedUri.query;
|
|
1269
1233
|
} else if (opts.host) {
|
|
1270
1234
|
opts.hostname = parse(opts.host).host;
|
|
1271
1235
|
}
|
|
@@ -1276,13 +1240,13 @@ var Socket = class _Socket extends Emitter {
|
|
|
1276
1240
|
}
|
|
1277
1241
|
this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
|
|
1278
1242
|
this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : this.secure ? "443" : "80");
|
|
1279
|
-
this.transports =
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1243
|
+
this.transports = [];
|
|
1244
|
+
this._transportsByName = {};
|
|
1245
|
+
opts.transports.forEach((t) => {
|
|
1246
|
+
const transportName = t.prototype.name;
|
|
1247
|
+
this.transports.push(transportName);
|
|
1248
|
+
this._transportsByName[transportName] = t;
|
|
1249
|
+
});
|
|
1286
1250
|
this.opts = Object.assign({
|
|
1287
1251
|
path: "/engine.io",
|
|
1288
1252
|
agent: false,
|
|
@@ -1302,31 +1266,29 @@ var Socket = class _Socket extends Emitter {
|
|
|
1302
1266
|
if (typeof this.opts.query === "string") {
|
|
1303
1267
|
this.opts.query = decode2(this.opts.query);
|
|
1304
1268
|
}
|
|
1305
|
-
|
|
1306
|
-
this.upgrades = null;
|
|
1307
|
-
this.pingInterval = null;
|
|
1308
|
-
this.pingTimeout = null;
|
|
1309
|
-
this.pingTimeoutTimer = null;
|
|
1310
|
-
if (typeof addEventListener === "function") {
|
|
1269
|
+
if (withEventListeners) {
|
|
1311
1270
|
if (this.opts.closeOnBeforeunload) {
|
|
1312
|
-
this.
|
|
1271
|
+
this._beforeunloadEventListener = () => {
|
|
1313
1272
|
if (this.transport) {
|
|
1314
1273
|
this.transport.removeAllListeners();
|
|
1315
1274
|
this.transport.close();
|
|
1316
1275
|
}
|
|
1317
1276
|
};
|
|
1318
|
-
addEventListener("beforeunload", this.
|
|
1277
|
+
addEventListener("beforeunload", this._beforeunloadEventListener, false);
|
|
1319
1278
|
}
|
|
1320
1279
|
if (this.hostname !== "localhost") {
|
|
1321
|
-
this.
|
|
1322
|
-
this.
|
|
1280
|
+
this._offlineEventListener = () => {
|
|
1281
|
+
this._onClose("transport close", {
|
|
1323
1282
|
description: "network connection lost"
|
|
1324
1283
|
});
|
|
1325
1284
|
};
|
|
1326
|
-
|
|
1285
|
+
OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
|
|
1327
1286
|
}
|
|
1328
1287
|
}
|
|
1329
|
-
this.
|
|
1288
|
+
if (this.opts.withCredentials) {
|
|
1289
|
+
this._cookieJar = createCookieJar();
|
|
1290
|
+
}
|
|
1291
|
+
this._open();
|
|
1330
1292
|
}
|
|
1331
1293
|
/**
|
|
1332
1294
|
* Creates transport of the given type.
|
|
@@ -1348,33 +1310,23 @@ var Socket = class _Socket extends Emitter {
|
|
|
1348
1310
|
secure: this.secure,
|
|
1349
1311
|
port: this.port
|
|
1350
1312
|
}, this.opts.transportOptions[name]);
|
|
1351
|
-
return new
|
|
1313
|
+
return new this._transportsByName[name](opts);
|
|
1352
1314
|
}
|
|
1353
1315
|
/**
|
|
1354
1316
|
* Initializes transport to use and starts probe.
|
|
1355
1317
|
*
|
|
1356
1318
|
* @private
|
|
1357
1319
|
*/
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
if (this.opts.rememberUpgrade && _Socket.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1) {
|
|
1361
|
-
transport = "websocket";
|
|
1362
|
-
} else if (0 === this.transports.length) {
|
|
1320
|
+
_open() {
|
|
1321
|
+
if (this.transports.length === 0) {
|
|
1363
1322
|
this.setTimeoutFn(() => {
|
|
1364
1323
|
this.emitReserved("error", "No transports available");
|
|
1365
1324
|
}, 0);
|
|
1366
1325
|
return;
|
|
1367
|
-
} else {
|
|
1368
|
-
transport = this.transports[0];
|
|
1369
1326
|
}
|
|
1327
|
+
const transportName = this.opts.rememberUpgrade && _SocketWithoutUpgrade.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
|
|
1370
1328
|
this.readyState = "opening";
|
|
1371
|
-
|
|
1372
|
-
transport = this.createTransport(transport);
|
|
1373
|
-
} catch (e) {
|
|
1374
|
-
this.transports.shift();
|
|
1375
|
-
this.open();
|
|
1376
|
-
return;
|
|
1377
|
-
}
|
|
1329
|
+
const transport = this.createTransport(transportName);
|
|
1378
1330
|
transport.open();
|
|
1379
1331
|
this.setTransport(transport);
|
|
1380
1332
|
}
|
|
@@ -1388,97 +1340,7 @@ var Socket = class _Socket extends Emitter {
|
|
|
1388
1340
|
this.transport.removeAllListeners();
|
|
1389
1341
|
}
|
|
1390
1342
|
this.transport = transport;
|
|
1391
|
-
transport.on("drain", this.
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* Probes a transport.
|
|
1395
|
-
*
|
|
1396
|
-
* @param {String} name - transport name
|
|
1397
|
-
* @private
|
|
1398
|
-
*/
|
|
1399
|
-
probe(name) {
|
|
1400
|
-
let transport = this.createTransport(name);
|
|
1401
|
-
let failed = false;
|
|
1402
|
-
_Socket.priorWebsocketSuccess = false;
|
|
1403
|
-
const onTransportOpen = () => {
|
|
1404
|
-
if (failed)
|
|
1405
|
-
return;
|
|
1406
|
-
transport.send([{ type: "ping", data: "probe" }]);
|
|
1407
|
-
transport.once("packet", (msg) => {
|
|
1408
|
-
if (failed)
|
|
1409
|
-
return;
|
|
1410
|
-
if ("pong" === msg.type && "probe" === msg.data) {
|
|
1411
|
-
this.upgrading = true;
|
|
1412
|
-
this.emitReserved("upgrading", transport);
|
|
1413
|
-
if (!transport)
|
|
1414
|
-
return;
|
|
1415
|
-
_Socket.priorWebsocketSuccess = "websocket" === transport.name;
|
|
1416
|
-
this.transport.pause(() => {
|
|
1417
|
-
if (failed)
|
|
1418
|
-
return;
|
|
1419
|
-
if ("closed" === this.readyState)
|
|
1420
|
-
return;
|
|
1421
|
-
cleanup();
|
|
1422
|
-
this.setTransport(transport);
|
|
1423
|
-
transport.send([{ type: "upgrade" }]);
|
|
1424
|
-
this.emitReserved("upgrade", transport);
|
|
1425
|
-
transport = null;
|
|
1426
|
-
this.upgrading = false;
|
|
1427
|
-
this.flush();
|
|
1428
|
-
});
|
|
1429
|
-
} else {
|
|
1430
|
-
const err = new Error("probe error");
|
|
1431
|
-
err.transport = transport.name;
|
|
1432
|
-
this.emitReserved("upgradeError", err);
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
};
|
|
1436
|
-
function freezeTransport() {
|
|
1437
|
-
if (failed)
|
|
1438
|
-
return;
|
|
1439
|
-
failed = true;
|
|
1440
|
-
cleanup();
|
|
1441
|
-
transport.close();
|
|
1442
|
-
transport = null;
|
|
1443
|
-
}
|
|
1444
|
-
const onerror = (err) => {
|
|
1445
|
-
const error = new Error("probe error: " + err);
|
|
1446
|
-
error.transport = transport.name;
|
|
1447
|
-
freezeTransport();
|
|
1448
|
-
this.emitReserved("upgradeError", error);
|
|
1449
|
-
};
|
|
1450
|
-
function onTransportClose() {
|
|
1451
|
-
onerror("transport closed");
|
|
1452
|
-
}
|
|
1453
|
-
function onclose() {
|
|
1454
|
-
onerror("socket closed");
|
|
1455
|
-
}
|
|
1456
|
-
function onupgrade(to) {
|
|
1457
|
-
if (transport && to.name !== transport.name) {
|
|
1458
|
-
freezeTransport();
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
const cleanup = () => {
|
|
1462
|
-
transport.removeListener("open", onTransportOpen);
|
|
1463
|
-
transport.removeListener("error", onerror);
|
|
1464
|
-
transport.removeListener("close", onTransportClose);
|
|
1465
|
-
this.off("close", onclose);
|
|
1466
|
-
this.off("upgrading", onupgrade);
|
|
1467
|
-
};
|
|
1468
|
-
transport.once("open", onTransportOpen);
|
|
1469
|
-
transport.once("error", onerror);
|
|
1470
|
-
transport.once("close", onTransportClose);
|
|
1471
|
-
this.once("close", onclose);
|
|
1472
|
-
this.once("upgrading", onupgrade);
|
|
1473
|
-
if (this.upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
|
|
1474
|
-
this.setTimeoutFn(() => {
|
|
1475
|
-
if (!failed) {
|
|
1476
|
-
transport.open();
|
|
1477
|
-
}
|
|
1478
|
-
}, 200);
|
|
1479
|
-
} else {
|
|
1480
|
-
transport.open();
|
|
1481
|
-
}
|
|
1343
|
+
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));
|
|
1482
1344
|
}
|
|
1483
1345
|
/**
|
|
1484
1346
|
* Called when connection is deemed open.
|
|
@@ -1487,40 +1349,33 @@ var Socket = class _Socket extends Emitter {
|
|
|
1487
1349
|
*/
|
|
1488
1350
|
onOpen() {
|
|
1489
1351
|
this.readyState = "open";
|
|
1490
|
-
|
|
1352
|
+
_SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === this.transport.name;
|
|
1491
1353
|
this.emitReserved("open");
|
|
1492
1354
|
this.flush();
|
|
1493
|
-
if ("open" === this.readyState && this.opts.upgrade) {
|
|
1494
|
-
let i2 = 0;
|
|
1495
|
-
const l = this.upgrades.length;
|
|
1496
|
-
for (; i2 < l; i2++) {
|
|
1497
|
-
this.probe(this.upgrades[i2]);
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
1355
|
}
|
|
1501
1356
|
/**
|
|
1502
1357
|
* Handles a packet.
|
|
1503
1358
|
*
|
|
1504
1359
|
* @private
|
|
1505
1360
|
*/
|
|
1506
|
-
|
|
1361
|
+
_onPacket(packet) {
|
|
1507
1362
|
if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
|
|
1508
1363
|
this.emitReserved("packet", packet);
|
|
1509
1364
|
this.emitReserved("heartbeat");
|
|
1510
|
-
this.resetPingTimeout();
|
|
1511
1365
|
switch (packet.type) {
|
|
1512
1366
|
case "open":
|
|
1513
1367
|
this.onHandshake(JSON.parse(packet.data));
|
|
1514
1368
|
break;
|
|
1515
1369
|
case "ping":
|
|
1516
|
-
this.
|
|
1370
|
+
this._sendPacket("pong");
|
|
1517
1371
|
this.emitReserved("ping");
|
|
1518
1372
|
this.emitReserved("pong");
|
|
1373
|
+
this._resetPingTimeout();
|
|
1519
1374
|
break;
|
|
1520
1375
|
case "error":
|
|
1521
1376
|
const err = new Error("server error");
|
|
1522
1377
|
err.code = packet.data;
|
|
1523
|
-
this.
|
|
1378
|
+
this._onError(err);
|
|
1524
1379
|
break;
|
|
1525
1380
|
case "message":
|
|
1526
1381
|
this.emitReserved("data", packet.data);
|
|
@@ -1540,27 +1395,28 @@ var Socket = class _Socket extends Emitter {
|
|
|
1540
1395
|
this.emitReserved("handshake", data);
|
|
1541
1396
|
this.id = data.sid;
|
|
1542
1397
|
this.transport.query.sid = data.sid;
|
|
1543
|
-
this.
|
|
1544
|
-
this.
|
|
1545
|
-
this.
|
|
1546
|
-
this.maxPayload = data.maxPayload;
|
|
1398
|
+
this._pingInterval = data.pingInterval;
|
|
1399
|
+
this._pingTimeout = data.pingTimeout;
|
|
1400
|
+
this._maxPayload = data.maxPayload;
|
|
1547
1401
|
this.onOpen();
|
|
1548
1402
|
if ("closed" === this.readyState)
|
|
1549
1403
|
return;
|
|
1550
|
-
this.
|
|
1404
|
+
this._resetPingTimeout();
|
|
1551
1405
|
}
|
|
1552
1406
|
/**
|
|
1553
1407
|
* Sets and resets ping timeout timer based on server pings.
|
|
1554
1408
|
*
|
|
1555
1409
|
* @private
|
|
1556
1410
|
*/
|
|
1557
|
-
|
|
1558
|
-
this.clearTimeoutFn(this.
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1411
|
+
_resetPingTimeout() {
|
|
1412
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
1413
|
+
const delay = this._pingInterval + this._pingTimeout;
|
|
1414
|
+
this._pingTimeoutTime = Date.now() + delay;
|
|
1415
|
+
this._pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
1416
|
+
this._onClose("ping timeout");
|
|
1417
|
+
}, delay);
|
|
1562
1418
|
if (this.opts.autoUnref) {
|
|
1563
|
-
this.
|
|
1419
|
+
this._pingTimeoutTimer.unref();
|
|
1564
1420
|
}
|
|
1565
1421
|
}
|
|
1566
1422
|
/**
|
|
@@ -1568,9 +1424,9 @@ var Socket = class _Socket extends Emitter {
|
|
|
1568
1424
|
*
|
|
1569
1425
|
* @private
|
|
1570
1426
|
*/
|
|
1571
|
-
|
|
1572
|
-
this.writeBuffer.splice(0, this.
|
|
1573
|
-
this.
|
|
1427
|
+
_onDrain() {
|
|
1428
|
+
this.writeBuffer.splice(0, this._prevBufferLen);
|
|
1429
|
+
this._prevBufferLen = 0;
|
|
1574
1430
|
if (0 === this.writeBuffer.length) {
|
|
1575
1431
|
this.emitReserved("drain");
|
|
1576
1432
|
} else {
|
|
@@ -1584,9 +1440,9 @@ var Socket = class _Socket extends Emitter {
|
|
|
1584
1440
|
*/
|
|
1585
1441
|
flush() {
|
|
1586
1442
|
if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
|
|
1587
|
-
const packets = this.
|
|
1443
|
+
const packets = this._getWritablePackets();
|
|
1588
1444
|
this.transport.send(packets);
|
|
1589
|
-
this.
|
|
1445
|
+
this._prevBufferLen = packets.length;
|
|
1590
1446
|
this.emitReserved("flush");
|
|
1591
1447
|
}
|
|
1592
1448
|
}
|
|
@@ -1596,38 +1452,68 @@ var Socket = class _Socket extends Emitter {
|
|
|
1596
1452
|
*
|
|
1597
1453
|
* @private
|
|
1598
1454
|
*/
|
|
1599
|
-
|
|
1600
|
-
const shouldCheckPayloadSize = this.
|
|
1455
|
+
_getWritablePackets() {
|
|
1456
|
+
const shouldCheckPayloadSize = this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1;
|
|
1601
1457
|
if (!shouldCheckPayloadSize) {
|
|
1602
1458
|
return this.writeBuffer;
|
|
1603
1459
|
}
|
|
1604
1460
|
let payloadSize = 1;
|
|
1605
|
-
for (let
|
|
1606
|
-
const data = this.writeBuffer[
|
|
1461
|
+
for (let i = 0; i < this.writeBuffer.length; i++) {
|
|
1462
|
+
const data = this.writeBuffer[i].data;
|
|
1607
1463
|
if (data) {
|
|
1608
1464
|
payloadSize += byteLength(data);
|
|
1609
1465
|
}
|
|
1610
|
-
if (
|
|
1611
|
-
return this.writeBuffer.slice(0,
|
|
1466
|
+
if (i > 0 && payloadSize > this._maxPayload) {
|
|
1467
|
+
return this.writeBuffer.slice(0, i);
|
|
1612
1468
|
}
|
|
1613
1469
|
payloadSize += 2;
|
|
1614
1470
|
}
|
|
1615
1471
|
return this.writeBuffer;
|
|
1616
1472
|
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Checks whether the heartbeat timer has expired but the socket has not yet been notified.
|
|
1475
|
+
*
|
|
1476
|
+
* Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
|
|
1477
|
+
* `write()` method then the message would not be buffered by the Socket.IO client.
|
|
1478
|
+
*
|
|
1479
|
+
* @return {boolean}
|
|
1480
|
+
* @private
|
|
1481
|
+
*/
|
|
1482
|
+
/* private */
|
|
1483
|
+
_hasPingExpired() {
|
|
1484
|
+
if (!this._pingTimeoutTime)
|
|
1485
|
+
return true;
|
|
1486
|
+
const hasExpired = Date.now() > this._pingTimeoutTime;
|
|
1487
|
+
if (hasExpired) {
|
|
1488
|
+
this._pingTimeoutTime = 0;
|
|
1489
|
+
nextTick(() => {
|
|
1490
|
+
this._onClose("ping timeout");
|
|
1491
|
+
}, this.setTimeoutFn);
|
|
1492
|
+
}
|
|
1493
|
+
return hasExpired;
|
|
1494
|
+
}
|
|
1617
1495
|
/**
|
|
1618
1496
|
* Sends a message.
|
|
1619
1497
|
*
|
|
1620
1498
|
* @param {String} msg - message.
|
|
1621
1499
|
* @param {Object} options.
|
|
1622
|
-
* @param {Function} callback function.
|
|
1500
|
+
* @param {Function} fn - callback function.
|
|
1623
1501
|
* @return {Socket} for chaining.
|
|
1624
1502
|
*/
|
|
1625
1503
|
write(msg, options, fn) {
|
|
1626
|
-
this.
|
|
1504
|
+
this._sendPacket("message", msg, options, fn);
|
|
1627
1505
|
return this;
|
|
1628
1506
|
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Sends a message. Alias of {@link Socket#write}.
|
|
1509
|
+
*
|
|
1510
|
+
* @param {String} msg - message.
|
|
1511
|
+
* @param {Object} options.
|
|
1512
|
+
* @param {Function} fn - callback function.
|
|
1513
|
+
* @return {Socket} for chaining.
|
|
1514
|
+
*/
|
|
1629
1515
|
send(msg, options, fn) {
|
|
1630
|
-
this.
|
|
1516
|
+
this._sendPacket("message", msg, options, fn);
|
|
1631
1517
|
return this;
|
|
1632
1518
|
}
|
|
1633
1519
|
/**
|
|
@@ -1639,7 +1525,7 @@ var Socket = class _Socket extends Emitter {
|
|
|
1639
1525
|
* @param {Function} fn - callback function.
|
|
1640
1526
|
* @private
|
|
1641
1527
|
*/
|
|
1642
|
-
|
|
1528
|
+
_sendPacket(type, data, options, fn) {
|
|
1643
1529
|
if ("function" === typeof data) {
|
|
1644
1530
|
fn = data;
|
|
1645
1531
|
data = void 0;
|
|
@@ -1669,7 +1555,7 @@ var Socket = class _Socket extends Emitter {
|
|
|
1669
1555
|
*/
|
|
1670
1556
|
close() {
|
|
1671
1557
|
const close = () => {
|
|
1672
|
-
this.
|
|
1558
|
+
this._onClose("forced close");
|
|
1673
1559
|
this.transport.close();
|
|
1674
1560
|
};
|
|
1675
1561
|
const cleanupAndClose = () => {
|
|
@@ -1704,51 +1590,177 @@ var Socket = class _Socket extends Emitter {
|
|
|
1704
1590
|
*
|
|
1705
1591
|
* @private
|
|
1706
1592
|
*/
|
|
1707
|
-
|
|
1708
|
-
|
|
1593
|
+
_onError(err) {
|
|
1594
|
+
_SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
1595
|
+
if (this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") {
|
|
1596
|
+
this.transports.shift();
|
|
1597
|
+
return this._open();
|
|
1598
|
+
}
|
|
1709
1599
|
this.emitReserved("error", err);
|
|
1710
|
-
this.
|
|
1600
|
+
this._onClose("transport error", err);
|
|
1711
1601
|
}
|
|
1712
1602
|
/**
|
|
1713
1603
|
* Called upon transport close.
|
|
1714
1604
|
*
|
|
1715
1605
|
* @private
|
|
1716
1606
|
*/
|
|
1717
|
-
|
|
1607
|
+
_onClose(reason, description) {
|
|
1718
1608
|
if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
|
|
1719
|
-
this.clearTimeoutFn(this.
|
|
1609
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
1720
1610
|
this.transport.removeAllListeners("close");
|
|
1721
1611
|
this.transport.close();
|
|
1722
1612
|
this.transport.removeAllListeners();
|
|
1723
|
-
if (
|
|
1724
|
-
|
|
1725
|
-
|
|
1613
|
+
if (withEventListeners) {
|
|
1614
|
+
if (this._beforeunloadEventListener) {
|
|
1615
|
+
removeEventListener("beforeunload", this._beforeunloadEventListener, false);
|
|
1616
|
+
}
|
|
1617
|
+
if (this._offlineEventListener) {
|
|
1618
|
+
const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
|
|
1619
|
+
if (i !== -1) {
|
|
1620
|
+
OFFLINE_EVENT_LISTENERS.splice(i, 1);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1726
1623
|
}
|
|
1727
1624
|
this.readyState = "closed";
|
|
1728
1625
|
this.id = null;
|
|
1729
1626
|
this.emitReserved("close", reason, description);
|
|
1730
1627
|
this.writeBuffer = [];
|
|
1731
|
-
this.
|
|
1628
|
+
this._prevBufferLen = 0;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
SocketWithoutUpgrade.protocol = protocol;
|
|
1633
|
+
var SocketWithUpgrade = class extends SocketWithoutUpgrade {
|
|
1634
|
+
constructor() {
|
|
1635
|
+
super(...arguments);
|
|
1636
|
+
this._upgrades = [];
|
|
1637
|
+
}
|
|
1638
|
+
onOpen() {
|
|
1639
|
+
super.onOpen();
|
|
1640
|
+
if ("open" === this.readyState && this.opts.upgrade) {
|
|
1641
|
+
for (let i = 0; i < this._upgrades.length; i++) {
|
|
1642
|
+
this._probe(this._upgrades[i]);
|
|
1643
|
+
}
|
|
1732
1644
|
}
|
|
1733
1645
|
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Probes a transport.
|
|
1648
|
+
*
|
|
1649
|
+
* @param {String} name - transport name
|
|
1650
|
+
* @private
|
|
1651
|
+
*/
|
|
1652
|
+
_probe(name) {
|
|
1653
|
+
let transport = this.createTransport(name);
|
|
1654
|
+
let failed = false;
|
|
1655
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
1656
|
+
const onTransportOpen = () => {
|
|
1657
|
+
if (failed)
|
|
1658
|
+
return;
|
|
1659
|
+
transport.send([{ type: "ping", data: "probe" }]);
|
|
1660
|
+
transport.once("packet", (msg) => {
|
|
1661
|
+
if (failed)
|
|
1662
|
+
return;
|
|
1663
|
+
if ("pong" === msg.type && "probe" === msg.data) {
|
|
1664
|
+
this.upgrading = true;
|
|
1665
|
+
this.emitReserved("upgrading", transport);
|
|
1666
|
+
if (!transport)
|
|
1667
|
+
return;
|
|
1668
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === transport.name;
|
|
1669
|
+
this.transport.pause(() => {
|
|
1670
|
+
if (failed)
|
|
1671
|
+
return;
|
|
1672
|
+
if ("closed" === this.readyState)
|
|
1673
|
+
return;
|
|
1674
|
+
cleanup();
|
|
1675
|
+
this.setTransport(transport);
|
|
1676
|
+
transport.send([{ type: "upgrade" }]);
|
|
1677
|
+
this.emitReserved("upgrade", transport);
|
|
1678
|
+
transport = null;
|
|
1679
|
+
this.upgrading = false;
|
|
1680
|
+
this.flush();
|
|
1681
|
+
});
|
|
1682
|
+
} else {
|
|
1683
|
+
const err = new Error("probe error");
|
|
1684
|
+
err.transport = transport.name;
|
|
1685
|
+
this.emitReserved("upgradeError", err);
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
};
|
|
1689
|
+
function freezeTransport() {
|
|
1690
|
+
if (failed)
|
|
1691
|
+
return;
|
|
1692
|
+
failed = true;
|
|
1693
|
+
cleanup();
|
|
1694
|
+
transport.close();
|
|
1695
|
+
transport = null;
|
|
1696
|
+
}
|
|
1697
|
+
const onerror = (err) => {
|
|
1698
|
+
const error = new Error("probe error: " + err);
|
|
1699
|
+
error.transport = transport.name;
|
|
1700
|
+
freezeTransport();
|
|
1701
|
+
this.emitReserved("upgradeError", error);
|
|
1702
|
+
};
|
|
1703
|
+
function onTransportClose() {
|
|
1704
|
+
onerror("transport closed");
|
|
1705
|
+
}
|
|
1706
|
+
function onclose() {
|
|
1707
|
+
onerror("socket closed");
|
|
1708
|
+
}
|
|
1709
|
+
function onupgrade(to) {
|
|
1710
|
+
if (transport && to.name !== transport.name) {
|
|
1711
|
+
freezeTransport();
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
const cleanup = () => {
|
|
1715
|
+
transport.removeListener("open", onTransportOpen);
|
|
1716
|
+
transport.removeListener("error", onerror);
|
|
1717
|
+
transport.removeListener("close", onTransportClose);
|
|
1718
|
+
this.off("close", onclose);
|
|
1719
|
+
this.off("upgrading", onupgrade);
|
|
1720
|
+
};
|
|
1721
|
+
transport.once("open", onTransportOpen);
|
|
1722
|
+
transport.once("error", onerror);
|
|
1723
|
+
transport.once("close", onTransportClose);
|
|
1724
|
+
this.once("close", onclose);
|
|
1725
|
+
this.once("upgrading", onupgrade);
|
|
1726
|
+
if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
|
|
1727
|
+
this.setTimeoutFn(() => {
|
|
1728
|
+
if (!failed) {
|
|
1729
|
+
transport.open();
|
|
1730
|
+
}
|
|
1731
|
+
}, 200);
|
|
1732
|
+
} else {
|
|
1733
|
+
transport.open();
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
onHandshake(data) {
|
|
1737
|
+
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
1738
|
+
super.onHandshake(data);
|
|
1739
|
+
}
|
|
1734
1740
|
/**
|
|
1735
1741
|
* Filters upgrades, returning only those matching client transports.
|
|
1736
1742
|
*
|
|
1737
1743
|
* @param {Array} upgrades - server upgrades
|
|
1738
1744
|
* @private
|
|
1739
1745
|
*/
|
|
1740
|
-
|
|
1746
|
+
_filterUpgrades(upgrades) {
|
|
1741
1747
|
const filteredUpgrades = [];
|
|
1742
|
-
let
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
if (~this.transports.indexOf(upgrades[i2]))
|
|
1746
|
-
filteredUpgrades.push(upgrades[i2]);
|
|
1748
|
+
for (let i = 0; i < upgrades.length; i++) {
|
|
1749
|
+
if (~this.transports.indexOf(upgrades[i]))
|
|
1750
|
+
filteredUpgrades.push(upgrades[i]);
|
|
1747
1751
|
}
|
|
1748
1752
|
return filteredUpgrades;
|
|
1749
1753
|
}
|
|
1750
1754
|
};
|
|
1751
|
-
Socket
|
|
1755
|
+
var Socket = class extends SocketWithUpgrade {
|
|
1756
|
+
constructor(uri, opts = {}) {
|
|
1757
|
+
const o = typeof uri === "object" ? uri : opts;
|
|
1758
|
+
if (!o.transports || o.transports && typeof o.transports[0] === "string") {
|
|
1759
|
+
o.transports = (o.transports || ["polling", "websocket", "webtransport"]).map((transportName) => transports[transportName]).filter((t) => !!t);
|
|
1760
|
+
}
|
|
1761
|
+
super(uri, o);
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1752
1764
|
|
|
1753
1765
|
// node_modules/engine.io-client/build/esm/index.js
|
|
1754
1766
|
var protocol2 = Socket.protocol;
|
|
@@ -1797,6 +1809,7 @@ __export(esm_exports, {
|
|
|
1797
1809
|
Decoder: () => Decoder,
|
|
1798
1810
|
Encoder: () => Encoder,
|
|
1799
1811
|
PacketType: () => PacketType,
|
|
1812
|
+
isPacketValid: () => isPacketValid,
|
|
1800
1813
|
protocol: () => protocol3
|
|
1801
1814
|
});
|
|
1802
1815
|
|
|
@@ -1816,8 +1829,8 @@ function hasBinary(obj, toJSON) {
|
|
|
1816
1829
|
return false;
|
|
1817
1830
|
}
|
|
1818
1831
|
if (Array.isArray(obj)) {
|
|
1819
|
-
for (let
|
|
1820
|
-
if (hasBinary(obj[
|
|
1832
|
+
for (let i = 0, l = obj.length; i < l; i++) {
|
|
1833
|
+
if (hasBinary(obj[i])) {
|
|
1821
1834
|
return true;
|
|
1822
1835
|
}
|
|
1823
1836
|
}
|
|
@@ -1855,8 +1868,8 @@ function _deconstructPacket(data, buffers) {
|
|
|
1855
1868
|
return placeholder;
|
|
1856
1869
|
} else if (Array.isArray(data)) {
|
|
1857
1870
|
const newData = new Array(data.length);
|
|
1858
|
-
for (let
|
|
1859
|
-
newData[
|
|
1871
|
+
for (let i = 0; i < data.length; i++) {
|
|
1872
|
+
newData[i] = _deconstructPacket(data[i], buffers);
|
|
1860
1873
|
}
|
|
1861
1874
|
return newData;
|
|
1862
1875
|
} else if (typeof data === "object" && !(data instanceof Date)) {
|
|
@@ -1886,8 +1899,8 @@ function _reconstructPacket(data, buffers) {
|
|
|
1886
1899
|
throw new Error("illegal attachments");
|
|
1887
1900
|
}
|
|
1888
1901
|
} else if (Array.isArray(data)) {
|
|
1889
|
-
for (let
|
|
1890
|
-
data[
|
|
1902
|
+
for (let i = 0; i < data.length; i++) {
|
|
1903
|
+
data[i] = _reconstructPacket(data[i], buffers);
|
|
1891
1904
|
}
|
|
1892
1905
|
} else if (typeof data === "object") {
|
|
1893
1906
|
for (const key in data) {
|
|
@@ -1902,10 +1915,15 @@ function _reconstructPacket(data, buffers) {
|
|
|
1902
1915
|
// node_modules/socket.io-parser/build/esm/index.js
|
|
1903
1916
|
var RESERVED_EVENTS = [
|
|
1904
1917
|
"connect",
|
|
1918
|
+
// used on the client side
|
|
1905
1919
|
"connect_error",
|
|
1920
|
+
// used on the client side
|
|
1906
1921
|
"disconnect",
|
|
1922
|
+
// used on both sides
|
|
1907
1923
|
"disconnecting",
|
|
1924
|
+
// used on the server side
|
|
1908
1925
|
"newListener",
|
|
1926
|
+
// used by the Node.js EventEmitter
|
|
1909
1927
|
"removeListener"
|
|
1910
1928
|
// used by the Node.js EventEmitter
|
|
1911
1929
|
];
|
|
@@ -1980,9 +1998,6 @@ var Encoder = class {
|
|
|
1980
1998
|
return buffers;
|
|
1981
1999
|
}
|
|
1982
2000
|
};
|
|
1983
|
-
function isObject(value2) {
|
|
1984
|
-
return Object.prototype.toString.call(value2) === "[object Object]";
|
|
1985
|
-
}
|
|
1986
2001
|
var Decoder = class _Decoder extends Emitter {
|
|
1987
2002
|
/**
|
|
1988
2003
|
* Decoder constructor
|
|
@@ -2036,7 +2051,7 @@ var Decoder = class _Decoder extends Emitter {
|
|
|
2036
2051
|
* @return {Object} packet
|
|
2037
2052
|
*/
|
|
2038
2053
|
decodeString(str) {
|
|
2039
|
-
let
|
|
2054
|
+
let i = 0;
|
|
2040
2055
|
const p = {
|
|
2041
2056
|
type: Number(str.charAt(0))
|
|
2042
2057
|
};
|
|
@@ -2044,44 +2059,44 @@ var Decoder = class _Decoder extends Emitter {
|
|
|
2044
2059
|
throw new Error("unknown packet type " + p.type);
|
|
2045
2060
|
}
|
|
2046
2061
|
if (p.type === PacketType.BINARY_EVENT || p.type === PacketType.BINARY_ACK) {
|
|
2047
|
-
const start =
|
|
2048
|
-
while (str.charAt(++
|
|
2062
|
+
const start = i + 1;
|
|
2063
|
+
while (str.charAt(++i) !== "-" && i != str.length) {
|
|
2049
2064
|
}
|
|
2050
|
-
const buf = str.substring(start,
|
|
2051
|
-
if (buf != Number(buf) || str.charAt(
|
|
2065
|
+
const buf = str.substring(start, i);
|
|
2066
|
+
if (buf != Number(buf) || str.charAt(i) !== "-") {
|
|
2052
2067
|
throw new Error("Illegal attachments");
|
|
2053
2068
|
}
|
|
2054
2069
|
p.attachments = Number(buf);
|
|
2055
2070
|
}
|
|
2056
|
-
if ("/" === str.charAt(
|
|
2057
|
-
const start =
|
|
2058
|
-
while (++
|
|
2059
|
-
const c = str.charAt(
|
|
2071
|
+
if ("/" === str.charAt(i + 1)) {
|
|
2072
|
+
const start = i + 1;
|
|
2073
|
+
while (++i) {
|
|
2074
|
+
const c = str.charAt(i);
|
|
2060
2075
|
if ("," === c)
|
|
2061
2076
|
break;
|
|
2062
|
-
if (
|
|
2077
|
+
if (i === str.length)
|
|
2063
2078
|
break;
|
|
2064
2079
|
}
|
|
2065
|
-
p.nsp = str.substring(start,
|
|
2080
|
+
p.nsp = str.substring(start, i);
|
|
2066
2081
|
} else {
|
|
2067
2082
|
p.nsp = "/";
|
|
2068
2083
|
}
|
|
2069
|
-
const next = str.charAt(
|
|
2084
|
+
const next = str.charAt(i + 1);
|
|
2070
2085
|
if ("" !== next && Number(next) == next) {
|
|
2071
|
-
const start =
|
|
2072
|
-
while (++
|
|
2073
|
-
const c = str.charAt(
|
|
2086
|
+
const start = i + 1;
|
|
2087
|
+
while (++i) {
|
|
2088
|
+
const c = str.charAt(i);
|
|
2074
2089
|
if (null == c || Number(c) != c) {
|
|
2075
|
-
--
|
|
2090
|
+
--i;
|
|
2076
2091
|
break;
|
|
2077
2092
|
}
|
|
2078
|
-
if (
|
|
2093
|
+
if (i === str.length)
|
|
2079
2094
|
break;
|
|
2080
2095
|
}
|
|
2081
|
-
p.id = Number(str.substring(start,
|
|
2096
|
+
p.id = Number(str.substring(start, i + 1));
|
|
2082
2097
|
}
|
|
2083
|
-
if (str.charAt(++
|
|
2084
|
-
const payload = this.tryParse(str.substr(
|
|
2098
|
+
if (str.charAt(++i)) {
|
|
2099
|
+
const payload = this.tryParse(str.substr(i));
|
|
2085
2100
|
if (_Decoder.isPayloadValid(p.type, payload)) {
|
|
2086
2101
|
p.data = payload;
|
|
2087
2102
|
} else {
|
|
@@ -2154,6 +2169,37 @@ var BinaryReconstructor = class {
|
|
|
2154
2169
|
this.buffers = [];
|
|
2155
2170
|
}
|
|
2156
2171
|
};
|
|
2172
|
+
function isNamespaceValid(nsp) {
|
|
2173
|
+
return typeof nsp === "string";
|
|
2174
|
+
}
|
|
2175
|
+
var isInteger = Number.isInteger || function(value2) {
|
|
2176
|
+
return typeof value2 === "number" && isFinite(value2) && Math.floor(value2) === value2;
|
|
2177
|
+
};
|
|
2178
|
+
function isAckIdValid(id) {
|
|
2179
|
+
return id === void 0 || isInteger(id);
|
|
2180
|
+
}
|
|
2181
|
+
function isObject(value2) {
|
|
2182
|
+
return Object.prototype.toString.call(value2) === "[object Object]";
|
|
2183
|
+
}
|
|
2184
|
+
function isDataValid(type, payload) {
|
|
2185
|
+
switch (type) {
|
|
2186
|
+
case PacketType.CONNECT:
|
|
2187
|
+
return payload === void 0 || isObject(payload);
|
|
2188
|
+
case PacketType.DISCONNECT:
|
|
2189
|
+
return payload === void 0;
|
|
2190
|
+
case PacketType.EVENT:
|
|
2191
|
+
return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS.indexOf(payload[0]) === -1);
|
|
2192
|
+
case PacketType.ACK:
|
|
2193
|
+
return Array.isArray(payload);
|
|
2194
|
+
case PacketType.CONNECT_ERROR:
|
|
2195
|
+
return typeof payload === "string" || isObject(payload);
|
|
2196
|
+
default:
|
|
2197
|
+
return false;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
function isPacketValid(packet) {
|
|
2201
|
+
return isNamespaceValid(packet.nsp) && isAckIdValid(packet.id) && isDataValid(packet.type, packet.data);
|
|
2202
|
+
}
|
|
2157
2203
|
|
|
2158
2204
|
// node_modules/socket.io-client/build/esm/on.js
|
|
2159
2205
|
function on(obj, ev, fn) {
|
|
@@ -2314,6 +2360,7 @@ var Socket2 = class extends Emitter {
|
|
|
2314
2360
|
* @return self
|
|
2315
2361
|
*/
|
|
2316
2362
|
emit(ev, ...args) {
|
|
2363
|
+
var _a, _b, _c;
|
|
2317
2364
|
if (RESERVED_EVENTS2.hasOwnProperty(ev)) {
|
|
2318
2365
|
throw new Error('"' + ev.toString() + '" is a reserved event name');
|
|
2319
2366
|
}
|
|
@@ -2334,10 +2381,11 @@ var Socket2 = class extends Emitter {
|
|
|
2334
2381
|
this._registerAckCallback(id, ack);
|
|
2335
2382
|
packet.id = id;
|
|
2336
2383
|
}
|
|
2337
|
-
const isTransportWritable = this.io.engine
|
|
2338
|
-
const
|
|
2384
|
+
const isTransportWritable = (_b = (_a = this.io.engine) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.writable;
|
|
2385
|
+
const isConnected = this.connected && !((_c = this.io.engine) === null || _c === void 0 ? void 0 : _c._hasPingExpired());
|
|
2386
|
+
const discardPacket = this.flags.volatile && !isTransportWritable;
|
|
2339
2387
|
if (discardPacket) {
|
|
2340
|
-
} else if (
|
|
2388
|
+
} else if (isConnected) {
|
|
2341
2389
|
this.notifyOutgoingListeners(packet);
|
|
2342
2390
|
this.packet(packet);
|
|
2343
2391
|
} else {
|
|
@@ -2358,9 +2406,9 @@ var Socket2 = class extends Emitter {
|
|
|
2358
2406
|
}
|
|
2359
2407
|
const timer = this.io.setTimeoutFn(() => {
|
|
2360
2408
|
delete this.acks[id];
|
|
2361
|
-
for (let
|
|
2362
|
-
if (this.sendBuffer[
|
|
2363
|
-
this.sendBuffer.splice(
|
|
2409
|
+
for (let i = 0; i < this.sendBuffer.length; i++) {
|
|
2410
|
+
if (this.sendBuffer[i].id === id) {
|
|
2411
|
+
this.sendBuffer.splice(i, 1);
|
|
2364
2412
|
}
|
|
2365
2413
|
}
|
|
2366
2414
|
ack.call(this, new Error("operation has timed out"));
|
|
@@ -2417,7 +2465,6 @@ var Socket2 = class extends Emitter {
|
|
|
2417
2465
|
};
|
|
2418
2466
|
args.push((err, ...responseArgs) => {
|
|
2419
2467
|
if (packet !== this._queue[0]) {
|
|
2420
|
-
return;
|
|
2421
2468
|
}
|
|
2422
2469
|
const hasError = err !== null;
|
|
2423
2470
|
if (hasError) {
|
|
@@ -2649,8 +2696,8 @@ var Socket2 = class extends Emitter {
|
|
|
2649
2696
|
this._pid = pid;
|
|
2650
2697
|
this.connected = true;
|
|
2651
2698
|
this.emitBuffered();
|
|
2652
|
-
this.emitReserved("connect");
|
|
2653
2699
|
this._drainQueue(true);
|
|
2700
|
+
this.emitReserved("connect");
|
|
2654
2701
|
}
|
|
2655
2702
|
/**
|
|
2656
2703
|
* Emit buffered events (received and emitted).
|
|
@@ -2822,9 +2869,9 @@ var Socket2 = class extends Emitter {
|
|
|
2822
2869
|
}
|
|
2823
2870
|
if (listener) {
|
|
2824
2871
|
const listeners = this._anyListeners;
|
|
2825
|
-
for (let
|
|
2826
|
-
if (listener === listeners[
|
|
2827
|
-
listeners.splice(
|
|
2872
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
2873
|
+
if (listener === listeners[i]) {
|
|
2874
|
+
listeners.splice(i, 1);
|
|
2828
2875
|
return this;
|
|
2829
2876
|
}
|
|
2830
2877
|
}
|
|
@@ -2900,9 +2947,9 @@ var Socket2 = class extends Emitter {
|
|
|
2900
2947
|
}
|
|
2901
2948
|
if (listener) {
|
|
2902
2949
|
const listeners = this._anyOutgoingListeners;
|
|
2903
|
-
for (let
|
|
2904
|
-
if (listener === listeners[
|
|
2905
|
-
listeners.splice(
|
|
2950
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
2951
|
+
if (listener === listeners[i]) {
|
|
2952
|
+
listeners.splice(i, 1);
|
|
2906
2953
|
return this;
|
|
2907
2954
|
}
|
|
2908
2955
|
}
|
|
@@ -3005,6 +3052,9 @@ var Manager = class extends Emitter {
|
|
|
3005
3052
|
if (!arguments.length)
|
|
3006
3053
|
return this._reconnection;
|
|
3007
3054
|
this._reconnection = !!v;
|
|
3055
|
+
if (!v) {
|
|
3056
|
+
this.skipReconnect = true;
|
|
3057
|
+
}
|
|
3008
3058
|
return this;
|
|
3009
3059
|
}
|
|
3010
3060
|
reconnectionAttempts(v) {
|
|
@@ -3121,7 +3171,14 @@ var Manager = class extends Emitter {
|
|
|
3121
3171
|
this._readyState = "open";
|
|
3122
3172
|
this.emitReserved("open");
|
|
3123
3173
|
const socket = this.engine;
|
|
3124
|
-
this.subs.push(
|
|
3174
|
+
this.subs.push(
|
|
3175
|
+
on(socket, "ping", this.onping.bind(this)),
|
|
3176
|
+
on(socket, "data", this.ondata.bind(this)),
|
|
3177
|
+
on(socket, "error", this.onerror.bind(this)),
|
|
3178
|
+
on(socket, "close", this.onclose.bind(this)),
|
|
3179
|
+
// @ts-ignore
|
|
3180
|
+
on(this.decoder, "decoded", this.ondecoded.bind(this))
|
|
3181
|
+
);
|
|
3125
3182
|
}
|
|
3126
3183
|
/**
|
|
3127
3184
|
* Called upon a ping.
|
|
@@ -3201,8 +3258,8 @@ var Manager = class extends Emitter {
|
|
|
3201
3258
|
*/
|
|
3202
3259
|
_packet(packet) {
|
|
3203
3260
|
const encodedPackets = this.encoder.encode(packet);
|
|
3204
|
-
for (let
|
|
3205
|
-
this.engine.write(encodedPackets[
|
|
3261
|
+
for (let i = 0; i < encodedPackets.length; i++) {
|
|
3262
|
+
this.engine.write(encodedPackets[i], packet.options);
|
|
3206
3263
|
}
|
|
3207
3264
|
}
|
|
3208
3265
|
/**
|
|
@@ -3224,8 +3281,6 @@ var Manager = class extends Emitter {
|
|
|
3224
3281
|
this.skipReconnect = true;
|
|
3225
3282
|
this._reconnecting = false;
|
|
3226
3283
|
this.onclose("forced close");
|
|
3227
|
-
if (this.engine)
|
|
3228
|
-
this.engine.close();
|
|
3229
3284
|
}
|
|
3230
3285
|
/**
|
|
3231
3286
|
* Alias for close()
|
|
@@ -3236,12 +3291,18 @@ var Manager = class extends Emitter {
|
|
|
3236
3291
|
return this._close();
|
|
3237
3292
|
}
|
|
3238
3293
|
/**
|
|
3239
|
-
* Called
|
|
3294
|
+
* Called when:
|
|
3295
|
+
*
|
|
3296
|
+
* - the low-level engine is closed
|
|
3297
|
+
* - the parser encountered a badly formatted packet
|
|
3298
|
+
* - all sockets are disconnected
|
|
3240
3299
|
*
|
|
3241
3300
|
* @private
|
|
3242
3301
|
*/
|
|
3243
3302
|
onclose(reason, description) {
|
|
3303
|
+
var _a;
|
|
3244
3304
|
this.cleanup();
|
|
3305
|
+
(_a = this.engine) === null || _a === void 0 ? void 0 : _a.close();
|
|
3245
3306
|
this.backoff.reset();
|
|
3246
3307
|
this._readyState = "closed";
|
|
3247
3308
|
this.emitReserved("close", reason, description);
|
|
@@ -3340,10 +3401,11 @@ Object.assign(lookup2, {
|
|
|
3340
3401
|
// package.json
|
|
3341
3402
|
var package_default = {
|
|
3342
3403
|
name: "@aiqa/sdk",
|
|
3343
|
-
version: "0.0.
|
|
3404
|
+
version: "0.0.3",
|
|
3344
3405
|
main: "dist/node/node.js",
|
|
3345
3406
|
module: "dist/node/node.js",
|
|
3346
3407
|
types: "dist/node/node.d.ts",
|
|
3408
|
+
engines: { node: ">=18" },
|
|
3347
3409
|
scripts: {
|
|
3348
3410
|
build: "tsup",
|
|
3349
3411
|
"dev:node": "tsx src/node.ts",
|