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