@blade-hq/agent-client 2612.0.0-beta.2 → 2612.0.0-beta.21
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 +203 -19
- package/dist/blade-client.d.ts +13 -1
- package/dist/{chunk-PWJJJATA.js → chunk-J3XXTHHK.js} +1723 -701
- package/dist/chunk-J3XXTHHK.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +9 -1
- package/dist/internal.d.ts +9 -3
- package/dist/internal.js +13 -1
- package/dist/internal.js.map +1 -1
- package/dist/resources/auth.d.ts +3 -1
- package/dist/resources/chat-groups.d.ts +92 -0
- package/dist/resources/headless.d.ts +5 -0
- package/dist/resources/models.d.ts +6 -1
- package/dist/resources/plugins.d.ts +1 -0
- package/dist/resources/sessions.d.ts +96 -11
- package/dist/schemas/context-attachments.d.ts +16 -0
- package/dist/schemas/event.d.ts +2 -0
- package/dist/schemas/message-utils.d.ts +3 -9
- package/dist/schemas/message.d.ts +18 -1
- package/dist/schemas/plugin-refs.d.ts +15 -0
- package/dist/schemas/projection.d.ts +31 -0
- package/dist/schemas/session.d.ts +2 -42
- package/dist/schemas/topic-assets.d.ts +7 -0
- package/dist/server-clock.d.ts +2 -0
- package/dist/session/agent-session.d.ts +51 -7
- package/dist/session/background.d.ts +14 -0
- package/dist/session/events.d.ts +0 -1
- package/dist/session/hub.d.ts +3 -0
- package/dist/session/log-cursor.d.ts +14 -0
- package/dist/session/state.d.ts +2 -1
- package/dist/session/workflow.d.ts +10 -3
- package/dist/shared/projection/builder.d.ts +5 -0
- package/dist/shared/projection/helpers.d.ts +2 -0
- package/dist/shared/projection/index.d.ts +1 -0
- package/dist/shared/projection/workflow.d.ts +24 -0
- package/dist/tool-provider.d.ts +51 -0
- package/dist/types/socket-events.d.ts +179 -6
- package/node_modules/engine.io-client/build/cjs/globals.node.d.ts +2 -3
- package/node_modules/engine.io-client/build/cjs/index.d.ts +3 -3
- package/node_modules/engine.io-client/build/cjs/index.js +1 -4
- package/node_modules/engine.io-client/build/cjs/socket.d.ts +39 -82
- package/node_modules/engine.io-client/build/cjs/socket.js +151 -218
- package/node_modules/engine.io-client/build/cjs/transport.d.ts +1 -1
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts +4 -4
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js +2 -2
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js +17 -7
- package/node_modules/engine.io-client/build/cjs/transports/websocket.node.js +17 -7
- package/node_modules/engine.io-client/build/esm/globals.node.d.ts +2 -3
- package/node_modules/engine.io-client/build/esm/index.d.ts +3 -3
- package/node_modules/engine.io-client/build/esm/index.js +1 -2
- package/node_modules/engine.io-client/build/esm/socket.d.ts +39 -82
- package/node_modules/engine.io-client/build/esm/socket.js +141 -206
- package/node_modules/engine.io-client/build/esm/transport.d.ts +1 -1
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.d.ts +4 -4
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +2 -2
- package/node_modules/engine.io-client/build/esm-debug/globals.node.d.ts +2 -3
- package/node_modules/engine.io-client/build/esm-debug/index.d.ts +3 -3
- package/node_modules/engine.io-client/build/esm-debug/index.js +1 -2
- package/node_modules/engine.io-client/build/esm-debug/socket.d.ts +39 -82
- package/node_modules/engine.io-client/build/esm-debug/socket.js +150 -215
- package/node_modules/engine.io-client/build/esm-debug/transport.d.ts +1 -1
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.d.ts +4 -4
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js +2 -2
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js +3 -3
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js.map +1 -1
- package/node_modules/engine.io-client/dist/engine.io.js +164 -239
- package/node_modules/engine.io-client/dist/engine.io.js.map +1 -1
- package/node_modules/engine.io-client/dist/engine.io.min.js +3 -3
- package/node_modules/engine.io-client/dist/engine.io.min.js.map +1 -1
- package/node_modules/engine.io-client/package.json +2 -2
- package/node_modules/socket.io-parser/build/cjs/binary.js +4 -1
- package/node_modules/socket.io-parser/build/cjs/index.d.ts +14 -4
- package/node_modules/socket.io-parser/build/cjs/index.js +18 -11
- package/node_modules/socket.io-parser/build/esm/binary.js +4 -1
- package/node_modules/socket.io-parser/build/esm/index.d.ts +14 -4
- package/node_modules/socket.io-parser/build/esm/index.js +14 -10
- package/node_modules/socket.io-parser/build/esm-debug/binary.js +4 -1
- package/node_modules/socket.io-parser/build/esm-debug/index.d.ts +14 -4
- package/node_modules/socket.io-parser/build/esm-debug/index.js +14 -10
- package/node_modules/socket.io-parser/package.json +1 -1
- package/node_modules/ws/index.js +15 -6
- package/node_modules/ws/lib/constants.js +1 -0
- package/node_modules/ws/lib/permessage-deflate.js +9 -7
- package/node_modules/ws/lib/receiver.js +37 -0
- package/node_modules/ws/lib/sender.js +6 -1
- package/node_modules/ws/lib/websocket-server.js +18 -6
- package/node_modules/ws/lib/websocket.js +50 -17
- package/node_modules/ws/package.json +8 -3
- package/node_modules/ws/wrapper.mjs +14 -1
- package/package.json +4 -4
- package/public-api.md +335 -28
- package/dist/chunk-PWJJJATA.js.map +0 -1
|
@@ -64,7 +64,20 @@ export interface SocketOptions {
|
|
|
64
64
|
*
|
|
65
65
|
* @default ['polling','websocket', 'webtransport']
|
|
66
66
|
*/
|
|
67
|
-
transports?:
|
|
67
|
+
transports?: TransportName[] | TransportCtor[];
|
|
68
|
+
/**
|
|
69
|
+
* A list of low-level transport implementations to use instead of the defaults.
|
|
70
|
+
*
|
|
71
|
+
* The order of the array determines the order in which transports are tried.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* import { Fetch, WebSocket } from "engine.io-client";
|
|
75
|
+
*
|
|
76
|
+
* const socket = new Socket({
|
|
77
|
+
* transportImplementations: [Fetch, WebSocket]
|
|
78
|
+
* });
|
|
79
|
+
*/
|
|
80
|
+
transportImplementations?: TransportCtor[];
|
|
68
81
|
/**
|
|
69
82
|
* Whether all the transports should be tested, instead of just the first one.
|
|
70
83
|
*
|
|
@@ -197,20 +210,18 @@ export interface SocketOptions {
|
|
|
197
210
|
*/
|
|
198
211
|
protocols?: string | string[];
|
|
199
212
|
}
|
|
200
|
-
type
|
|
213
|
+
export type TransportName = "polling" | "websocket" | "webtransport" | (string & {});
|
|
214
|
+
export type TransportCtor = {
|
|
201
215
|
new (o: any): Transport;
|
|
202
216
|
};
|
|
203
|
-
|
|
204
|
-
transports: TransportCtor[];
|
|
205
|
-
};
|
|
206
|
-
interface HandshakeData {
|
|
217
|
+
export interface HandshakeData {
|
|
207
218
|
sid: string;
|
|
208
219
|
upgrades: string[];
|
|
209
220
|
pingInterval: number;
|
|
210
221
|
pingTimeout: number;
|
|
211
222
|
maxPayload: number;
|
|
212
223
|
}
|
|
213
|
-
interface SocketReservedEvents {
|
|
224
|
+
export interface SocketReservedEvents {
|
|
214
225
|
open: () => void;
|
|
215
226
|
handshake: (data: HandshakeData) => void;
|
|
216
227
|
packet: (packet: Packet) => void;
|
|
@@ -229,43 +240,38 @@ interface SocketReservedEvents {
|
|
|
229
240
|
close: (reason: string, description?: CloseDetails | Error) => void;
|
|
230
241
|
}
|
|
231
242
|
type SocketState = "opening" | "open" | "closing" | "closed";
|
|
232
|
-
interface WriteOptions {
|
|
243
|
+
export interface WriteOptions {
|
|
233
244
|
compress?: boolean;
|
|
234
245
|
}
|
|
235
246
|
/**
|
|
236
247
|
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
237
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
248
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket, or WebTransport.
|
|
238
249
|
*
|
|
239
|
-
* This class comes
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
250
|
+
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
251
|
+
* low-level transport, it will try to upgrade to a better transport.
|
|
243
252
|
*
|
|
244
253
|
* @example
|
|
245
|
-
* import {
|
|
254
|
+
* import { Socket } from "engine.io-client";
|
|
246
255
|
*
|
|
247
|
-
* const socket = new
|
|
248
|
-
* transports: [WebSocket]
|
|
249
|
-
* });
|
|
256
|
+
* const socket = new Socket();
|
|
250
257
|
*
|
|
251
258
|
* socket.on("open", () => {
|
|
252
259
|
* socket.send("hello");
|
|
253
260
|
* });
|
|
254
261
|
*
|
|
255
|
-
* @see SocketWithUpgrade
|
|
256
|
-
* @see Socket
|
|
257
262
|
*/
|
|
258
|
-
export declare class
|
|
263
|
+
export declare class Socket extends Emitter<Record<never, never>, Record<never, never>, SocketReservedEvents> {
|
|
259
264
|
id: string;
|
|
260
265
|
transport: Transport;
|
|
261
266
|
binaryType: BinaryType;
|
|
262
267
|
readyState: SocketState;
|
|
263
268
|
writeBuffer: Packet[];
|
|
264
|
-
protected readonly opts:
|
|
265
|
-
protected readonly transports:
|
|
269
|
+
protected readonly opts: SocketOptions;
|
|
270
|
+
protected readonly transports: TransportName[];
|
|
266
271
|
protected upgrading: boolean;
|
|
267
272
|
protected setTimeoutFn: typeof setTimeout;
|
|
268
273
|
private _prevBufferLen;
|
|
274
|
+
private _upgrades;
|
|
269
275
|
private _pingInterval;
|
|
270
276
|
private _pingTimeout;
|
|
271
277
|
private _maxPayload?;
|
|
@@ -294,7 +300,9 @@ export declare class SocketWithoutUpgrade extends Emitter<Record<never, never>,
|
|
|
294
300
|
* @param {String|Object} uri - uri or options
|
|
295
301
|
* @param {Object} opts - options
|
|
296
302
|
*/
|
|
297
|
-
constructor(
|
|
303
|
+
constructor();
|
|
304
|
+
constructor(uri: string, opts?: SocketOptions);
|
|
305
|
+
constructor(opts: SocketOptions);
|
|
298
306
|
/**
|
|
299
307
|
* Creates transport of the given type.
|
|
300
308
|
*
|
|
@@ -315,6 +323,13 @@ export declare class SocketWithoutUpgrade extends Emitter<Record<never, never>,
|
|
|
315
323
|
* @private
|
|
316
324
|
*/
|
|
317
325
|
protected setTransport(transport: Transport): void;
|
|
326
|
+
/**
|
|
327
|
+
* Probes a transport.
|
|
328
|
+
*
|
|
329
|
+
* @param {String} name - transport name
|
|
330
|
+
* @private
|
|
331
|
+
*/
|
|
332
|
+
private _probe;
|
|
318
333
|
/**
|
|
319
334
|
* Called when connection is deemed open.
|
|
320
335
|
*
|
|
@@ -390,7 +405,7 @@ export declare class SocketWithoutUpgrade extends Emitter<Record<never, never>,
|
|
|
390
405
|
/**
|
|
391
406
|
* Sends a packet.
|
|
392
407
|
*
|
|
393
|
-
* @param {String} type
|
|
408
|
+
* @param {String} type - packet type.
|
|
394
409
|
* @param {String} data.
|
|
395
410
|
* @param {Object} options.
|
|
396
411
|
* @param {Function} fn - callback function.
|
|
@@ -413,41 +428,6 @@ export declare class SocketWithoutUpgrade extends Emitter<Record<never, never>,
|
|
|
413
428
|
* @private
|
|
414
429
|
*/
|
|
415
430
|
private _onClose;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
419
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
420
|
-
*
|
|
421
|
-
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
422
|
-
* low-level transport, it will try to upgrade to a better transport.
|
|
423
|
-
*
|
|
424
|
-
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
425
|
-
*
|
|
426
|
-
* @example
|
|
427
|
-
* import { SocketWithUpgrade, WebSocket } from "engine.io-client";
|
|
428
|
-
*
|
|
429
|
-
* const socket = new SocketWithUpgrade({
|
|
430
|
-
* transports: [WebSocket]
|
|
431
|
-
* });
|
|
432
|
-
*
|
|
433
|
-
* socket.on("open", () => {
|
|
434
|
-
* socket.send("hello");
|
|
435
|
-
* });
|
|
436
|
-
*
|
|
437
|
-
* @see SocketWithoutUpgrade
|
|
438
|
-
* @see Socket
|
|
439
|
-
*/
|
|
440
|
-
export declare class SocketWithUpgrade extends SocketWithoutUpgrade {
|
|
441
|
-
private _upgrades;
|
|
442
|
-
onOpen(): void;
|
|
443
|
-
/**
|
|
444
|
-
* Probes a transport.
|
|
445
|
-
*
|
|
446
|
-
* @param {String} name - transport name
|
|
447
|
-
* @private
|
|
448
|
-
*/
|
|
449
|
-
private _probe;
|
|
450
|
-
onHandshake(data: HandshakeData): void;
|
|
451
431
|
/**
|
|
452
432
|
* Filters upgrades, returning only those matching client transports.
|
|
453
433
|
*
|
|
@@ -456,27 +436,4 @@ export declare class SocketWithUpgrade extends SocketWithoutUpgrade {
|
|
|
456
436
|
*/
|
|
457
437
|
private _filterUpgrades;
|
|
458
438
|
}
|
|
459
|
-
/**
|
|
460
|
-
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
461
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
462
|
-
*
|
|
463
|
-
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
464
|
-
* low-level transport, it will try to upgrade to a better transport.
|
|
465
|
-
*
|
|
466
|
-
* @example
|
|
467
|
-
* import { Socket } from "engine.io-client";
|
|
468
|
-
*
|
|
469
|
-
* const socket = new Socket();
|
|
470
|
-
*
|
|
471
|
-
* socket.on("open", () => {
|
|
472
|
-
* socket.send("hello");
|
|
473
|
-
* });
|
|
474
|
-
*
|
|
475
|
-
* @see SocketWithoutUpgrade
|
|
476
|
-
* @see SocketWithUpgrade
|
|
477
|
-
*/
|
|
478
|
-
export declare class Socket extends SocketWithUpgrade {
|
|
479
|
-
constructor(uri?: string, opts?: SocketOptions);
|
|
480
|
-
constructor(opts: SocketOptions);
|
|
481
|
-
}
|
|
482
439
|
export {};
|
|
@@ -17,39 +17,29 @@ if (withEventListeners) {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
20
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
20
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket, or WebTransport.
|
|
21
21
|
*
|
|
22
|
-
* This class comes
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
22
|
+
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
23
|
+
* low-level transport, it will try to upgrade to a better transport.
|
|
26
24
|
*
|
|
27
25
|
* @example
|
|
28
|
-
* import {
|
|
26
|
+
* import { Socket } from "engine.io-client";
|
|
29
27
|
*
|
|
30
|
-
* const socket = new
|
|
31
|
-
* transports: [WebSocket]
|
|
32
|
-
* });
|
|
28
|
+
* const socket = new Socket();
|
|
33
29
|
*
|
|
34
30
|
* socket.on("open", () => {
|
|
35
31
|
* socket.send("hello");
|
|
36
32
|
* });
|
|
37
33
|
*
|
|
38
|
-
* @see SocketWithUpgrade
|
|
39
|
-
* @see Socket
|
|
40
34
|
*/
|
|
41
|
-
export class
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
* @param {String|Object} uri - uri or options
|
|
46
|
-
* @param {Object} opts - options
|
|
47
|
-
*/
|
|
48
|
-
constructor(uri, opts) {
|
|
35
|
+
export class Socket extends Emitter {
|
|
36
|
+
constructor(uri, opts = {}) {
|
|
37
|
+
var _a, _b;
|
|
49
38
|
super();
|
|
50
39
|
this.binaryType = defaultBinaryType;
|
|
51
40
|
this.writeBuffer = [];
|
|
52
41
|
this._prevBufferLen = 0;
|
|
42
|
+
this._upgrades = [];
|
|
53
43
|
this._pingInterval = -1;
|
|
54
44
|
this._pingTimeout = -1;
|
|
55
45
|
this._maxPayload = -1;
|
|
@@ -93,13 +83,26 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
93
83
|
: this.secure
|
|
94
84
|
? "443"
|
|
95
85
|
: "80");
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
86
|
+
if (opts.transportImplementations && opts.transports) {
|
|
87
|
+
throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");
|
|
88
|
+
}
|
|
89
|
+
if (opts.transportImplementations ||
|
|
90
|
+
(((_a = opts.transports) === null || _a === void 0 ? void 0 : _a.length) && typeof opts.transports[0] === "function")) {
|
|
91
|
+
// 'transports' option as an array of transport implementations is kept for backward compatibility
|
|
92
|
+
this.transports = [];
|
|
93
|
+
this._transportsByName = Object.create(null);
|
|
94
|
+
((_b = opts.transportImplementations) !== null && _b !== void 0 ? _b : opts.transports).forEach((t) => {
|
|
95
|
+
const transportName = t.prototype.name;
|
|
96
|
+
this.transports.push(transportName);
|
|
97
|
+
this._transportsByName[transportName] = t;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.transports = opts.transports
|
|
102
|
+
? [...opts.transports]
|
|
103
|
+
: ["polling", "websocket", "webtransport"];
|
|
104
|
+
this._transportsByName = DEFAULT_TRANSPORTS;
|
|
105
|
+
}
|
|
103
106
|
this.opts = Object.assign({
|
|
104
107
|
path: "/engine.io",
|
|
105
108
|
agent: false,
|
|
@@ -188,7 +191,7 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
188
191
|
return;
|
|
189
192
|
}
|
|
190
193
|
const transportName = this.opts.rememberUpgrade &&
|
|
191
|
-
|
|
194
|
+
Socket.priorWebsocketSuccess &&
|
|
192
195
|
this.transports.indexOf("websocket") !== -1
|
|
193
196
|
? "websocket"
|
|
194
197
|
: this.transports[0];
|
|
@@ -215,6 +218,107 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
215
218
|
.on("error", this._onError.bind(this))
|
|
216
219
|
.on("close", (reason) => this._onClose("transport close", reason));
|
|
217
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Probes a transport.
|
|
223
|
+
*
|
|
224
|
+
* @param {String} name - transport name
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
227
|
+
_probe(name) {
|
|
228
|
+
let transport = this.createTransport(name);
|
|
229
|
+
let failed = false;
|
|
230
|
+
Socket.priorWebsocketSuccess = false;
|
|
231
|
+
const onTransportOpen = () => {
|
|
232
|
+
if (failed)
|
|
233
|
+
return;
|
|
234
|
+
transport.send([{ type: "ping", data: "probe" }]);
|
|
235
|
+
transport.once("packet", (msg) => {
|
|
236
|
+
if (failed)
|
|
237
|
+
return;
|
|
238
|
+
if ("pong" === msg.type && "probe" === msg.data) {
|
|
239
|
+
this.upgrading = true;
|
|
240
|
+
this.emitReserved("upgrading", transport);
|
|
241
|
+
if (!transport)
|
|
242
|
+
return;
|
|
243
|
+
Socket.priorWebsocketSuccess = "websocket" === transport.name;
|
|
244
|
+
this.transport.pause(() => {
|
|
245
|
+
if (failed)
|
|
246
|
+
return;
|
|
247
|
+
if ("closed" === this.readyState)
|
|
248
|
+
return;
|
|
249
|
+
cleanup();
|
|
250
|
+
this.setTransport(transport);
|
|
251
|
+
transport.send([{ type: "upgrade" }]);
|
|
252
|
+
this.emitReserved("upgrade", transport);
|
|
253
|
+
transport = null;
|
|
254
|
+
this.upgrading = false;
|
|
255
|
+
this.flush();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const err = new Error("probe error");
|
|
260
|
+
// @ts-ignore
|
|
261
|
+
err.transport = transport.name;
|
|
262
|
+
this.emitReserved("upgradeError", err);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
function freezeTransport() {
|
|
267
|
+
if (failed)
|
|
268
|
+
return;
|
|
269
|
+
// Any callback called by transport should be ignored since now
|
|
270
|
+
failed = true;
|
|
271
|
+
cleanup();
|
|
272
|
+
transport.close();
|
|
273
|
+
transport = null;
|
|
274
|
+
}
|
|
275
|
+
// Handle any error that happens while probing
|
|
276
|
+
const onerror = (err) => {
|
|
277
|
+
const error = new Error("probe error: " + err);
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
error.transport = transport.name;
|
|
280
|
+
freezeTransport();
|
|
281
|
+
this.emitReserved("upgradeError", error);
|
|
282
|
+
};
|
|
283
|
+
function onTransportClose() {
|
|
284
|
+
onerror("transport closed");
|
|
285
|
+
}
|
|
286
|
+
// When the socket is closed while we're probing
|
|
287
|
+
function onclose() {
|
|
288
|
+
onerror("socket closed");
|
|
289
|
+
}
|
|
290
|
+
// When the socket is upgraded while we're probing
|
|
291
|
+
function onupgrade(to) {
|
|
292
|
+
if (transport && to.name !== transport.name) {
|
|
293
|
+
freezeTransport();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Remove all listeners on the transport and on self
|
|
297
|
+
const cleanup = () => {
|
|
298
|
+
transport.removeListener("open", onTransportOpen);
|
|
299
|
+
transport.removeListener("error", onerror);
|
|
300
|
+
transport.removeListener("close", onTransportClose);
|
|
301
|
+
this.off("close", onclose);
|
|
302
|
+
this.off("upgrading", onupgrade);
|
|
303
|
+
};
|
|
304
|
+
transport.once("open", onTransportOpen);
|
|
305
|
+
transport.once("error", onerror);
|
|
306
|
+
transport.once("close", onTransportClose);
|
|
307
|
+
this.once("close", onclose);
|
|
308
|
+
this.once("upgrading", onupgrade);
|
|
309
|
+
if (this._upgrades.indexOf("webtransport") !== -1 &&
|
|
310
|
+
name !== "webtransport") {
|
|
311
|
+
// favor WebTransport
|
|
312
|
+
this.setTimeoutFn(() => {
|
|
313
|
+
if (!failed) {
|
|
314
|
+
transport.open();
|
|
315
|
+
}
|
|
316
|
+
}, 200);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
transport.open();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
218
322
|
/**
|
|
219
323
|
* Called when connection is deemed open.
|
|
220
324
|
*
|
|
@@ -222,10 +326,14 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
222
326
|
*/
|
|
223
327
|
onOpen() {
|
|
224
328
|
this.readyState = "open";
|
|
225
|
-
|
|
226
|
-
"websocket" === this.transport.name;
|
|
329
|
+
Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
|
|
227
330
|
this.emitReserved("open");
|
|
228
331
|
this.flush();
|
|
332
|
+
if ("open" === this.readyState && this.opts.upgrade) {
|
|
333
|
+
for (let i = 0; i < this._upgrades.length; i++) {
|
|
334
|
+
this._probe(this._upgrades[i]);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
229
337
|
}
|
|
230
338
|
/**
|
|
231
339
|
* Handles a packet.
|
|
@@ -274,6 +382,7 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
274
382
|
this.emitReserved("handshake", data);
|
|
275
383
|
this.id = data.sid;
|
|
276
384
|
this.transport.query.sid = data.sid;
|
|
385
|
+
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
277
386
|
this._pingInterval = data.pingInterval;
|
|
278
387
|
this._pingTimeout = data.pingTimeout;
|
|
279
388
|
this._maxPayload = data.maxPayload;
|
|
@@ -409,7 +518,7 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
409
518
|
/**
|
|
410
519
|
* Sends a packet.
|
|
411
520
|
*
|
|
412
|
-
* @param {String} type
|
|
521
|
+
* @param {String} type - packet type.
|
|
413
522
|
* @param {String} data.
|
|
414
523
|
* @param {Object} options.
|
|
415
524
|
* @param {Function} fn - callback function.
|
|
@@ -485,7 +594,7 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
485
594
|
* @private
|
|
486
595
|
*/
|
|
487
596
|
_onError(err) {
|
|
488
|
-
|
|
597
|
+
Socket.priorWebsocketSuccess = false;
|
|
489
598
|
if (this.opts.tryAllTransports &&
|
|
490
599
|
this.transports.length > 1 &&
|
|
491
600
|
this.readyState === "opening") {
|
|
@@ -535,150 +644,6 @@ export class SocketWithoutUpgrade extends Emitter {
|
|
|
535
644
|
this._prevBufferLen = 0;
|
|
536
645
|
}
|
|
537
646
|
}
|
|
538
|
-
}
|
|
539
|
-
SocketWithoutUpgrade.protocol = protocol;
|
|
540
|
-
/**
|
|
541
|
-
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
542
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
543
|
-
*
|
|
544
|
-
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
545
|
-
* low-level transport, it will try to upgrade to a better transport.
|
|
546
|
-
*
|
|
547
|
-
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
548
|
-
*
|
|
549
|
-
* @example
|
|
550
|
-
* import { SocketWithUpgrade, WebSocket } from "engine.io-client";
|
|
551
|
-
*
|
|
552
|
-
* const socket = new SocketWithUpgrade({
|
|
553
|
-
* transports: [WebSocket]
|
|
554
|
-
* });
|
|
555
|
-
*
|
|
556
|
-
* socket.on("open", () => {
|
|
557
|
-
* socket.send("hello");
|
|
558
|
-
* });
|
|
559
|
-
*
|
|
560
|
-
* @see SocketWithoutUpgrade
|
|
561
|
-
* @see Socket
|
|
562
|
-
*/
|
|
563
|
-
export class SocketWithUpgrade extends SocketWithoutUpgrade {
|
|
564
|
-
constructor() {
|
|
565
|
-
super(...arguments);
|
|
566
|
-
this._upgrades = [];
|
|
567
|
-
}
|
|
568
|
-
onOpen() {
|
|
569
|
-
super.onOpen();
|
|
570
|
-
if ("open" === this.readyState && this.opts.upgrade) {
|
|
571
|
-
for (let i = 0; i < this._upgrades.length; i++) {
|
|
572
|
-
this._probe(this._upgrades[i]);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Probes a transport.
|
|
578
|
-
*
|
|
579
|
-
* @param {String} name - transport name
|
|
580
|
-
* @private
|
|
581
|
-
*/
|
|
582
|
-
_probe(name) {
|
|
583
|
-
let transport = this.createTransport(name);
|
|
584
|
-
let failed = false;
|
|
585
|
-
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
586
|
-
const onTransportOpen = () => {
|
|
587
|
-
if (failed)
|
|
588
|
-
return;
|
|
589
|
-
transport.send([{ type: "ping", data: "probe" }]);
|
|
590
|
-
transport.once("packet", (msg) => {
|
|
591
|
-
if (failed)
|
|
592
|
-
return;
|
|
593
|
-
if ("pong" === msg.type && "probe" === msg.data) {
|
|
594
|
-
this.upgrading = true;
|
|
595
|
-
this.emitReserved("upgrading", transport);
|
|
596
|
-
if (!transport)
|
|
597
|
-
return;
|
|
598
|
-
SocketWithoutUpgrade.priorWebsocketSuccess =
|
|
599
|
-
"websocket" === transport.name;
|
|
600
|
-
this.transport.pause(() => {
|
|
601
|
-
if (failed)
|
|
602
|
-
return;
|
|
603
|
-
if ("closed" === this.readyState)
|
|
604
|
-
return;
|
|
605
|
-
cleanup();
|
|
606
|
-
this.setTransport(transport);
|
|
607
|
-
transport.send([{ type: "upgrade" }]);
|
|
608
|
-
this.emitReserved("upgrade", transport);
|
|
609
|
-
transport = null;
|
|
610
|
-
this.upgrading = false;
|
|
611
|
-
this.flush();
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
const err = new Error("probe error");
|
|
616
|
-
// @ts-ignore
|
|
617
|
-
err.transport = transport.name;
|
|
618
|
-
this.emitReserved("upgradeError", err);
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
};
|
|
622
|
-
function freezeTransport() {
|
|
623
|
-
if (failed)
|
|
624
|
-
return;
|
|
625
|
-
// Any callback called by transport should be ignored since now
|
|
626
|
-
failed = true;
|
|
627
|
-
cleanup();
|
|
628
|
-
transport.close();
|
|
629
|
-
transport = null;
|
|
630
|
-
}
|
|
631
|
-
// Handle any error that happens while probing
|
|
632
|
-
const onerror = (err) => {
|
|
633
|
-
const error = new Error("probe error: " + err);
|
|
634
|
-
// @ts-ignore
|
|
635
|
-
error.transport = transport.name;
|
|
636
|
-
freezeTransport();
|
|
637
|
-
this.emitReserved("upgradeError", error);
|
|
638
|
-
};
|
|
639
|
-
function onTransportClose() {
|
|
640
|
-
onerror("transport closed");
|
|
641
|
-
}
|
|
642
|
-
// When the socket is closed while we're probing
|
|
643
|
-
function onclose() {
|
|
644
|
-
onerror("socket closed");
|
|
645
|
-
}
|
|
646
|
-
// When the socket is upgraded while we're probing
|
|
647
|
-
function onupgrade(to) {
|
|
648
|
-
if (transport && to.name !== transport.name) {
|
|
649
|
-
freezeTransport();
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
// Remove all listeners on the transport and on self
|
|
653
|
-
const cleanup = () => {
|
|
654
|
-
transport.removeListener("open", onTransportOpen);
|
|
655
|
-
transport.removeListener("error", onerror);
|
|
656
|
-
transport.removeListener("close", onTransportClose);
|
|
657
|
-
this.off("close", onclose);
|
|
658
|
-
this.off("upgrading", onupgrade);
|
|
659
|
-
};
|
|
660
|
-
transport.once("open", onTransportOpen);
|
|
661
|
-
transport.once("error", onerror);
|
|
662
|
-
transport.once("close", onTransportClose);
|
|
663
|
-
this.once("close", onclose);
|
|
664
|
-
this.once("upgrading", onupgrade);
|
|
665
|
-
if (this._upgrades.indexOf("webtransport") !== -1 &&
|
|
666
|
-
name !== "webtransport") {
|
|
667
|
-
// favor WebTransport
|
|
668
|
-
this.setTimeoutFn(() => {
|
|
669
|
-
if (!failed) {
|
|
670
|
-
transport.open();
|
|
671
|
-
}
|
|
672
|
-
}, 200);
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
transport.open();
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
onHandshake(data) {
|
|
679
|
-
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
680
|
-
super.onHandshake(data);
|
|
681
|
-
}
|
|
682
647
|
/**
|
|
683
648
|
* Filters upgrades, returning only those matching client transports.
|
|
684
649
|
*
|
|
@@ -694,34 +659,4 @@ export class SocketWithUpgrade extends SocketWithoutUpgrade {
|
|
|
694
659
|
return filteredUpgrades;
|
|
695
660
|
}
|
|
696
661
|
}
|
|
697
|
-
|
|
698
|
-
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
699
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
700
|
-
*
|
|
701
|
-
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
702
|
-
* low-level transport, it will try to upgrade to a better transport.
|
|
703
|
-
*
|
|
704
|
-
* @example
|
|
705
|
-
* import { Socket } from "engine.io-client";
|
|
706
|
-
*
|
|
707
|
-
* const socket = new Socket();
|
|
708
|
-
*
|
|
709
|
-
* socket.on("open", () => {
|
|
710
|
-
* socket.send("hello");
|
|
711
|
-
* });
|
|
712
|
-
*
|
|
713
|
-
* @see SocketWithoutUpgrade
|
|
714
|
-
* @see SocketWithUpgrade
|
|
715
|
-
*/
|
|
716
|
-
export class Socket extends SocketWithUpgrade {
|
|
717
|
-
constructor(uri, opts = {}) {
|
|
718
|
-
const o = typeof uri === "object" ? uri : opts;
|
|
719
|
-
if (!o.transports ||
|
|
720
|
-
(o.transports && typeof o.transports[0] === "string")) {
|
|
721
|
-
o.transports = (o.transports || ["polling", "websocket", "webtransport"])
|
|
722
|
-
.map((transportName) => DEFAULT_TRANSPORTS[transportName])
|
|
723
|
-
.filter((t) => !!t);
|
|
724
|
-
}
|
|
725
|
-
super(uri, o);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
662
|
+
Socket.protocol = protocol;
|
|
@@ -11,7 +11,7 @@ export interface CloseDetails {
|
|
|
11
11
|
description: string;
|
|
12
12
|
context?: unknown;
|
|
13
13
|
}
|
|
14
|
-
interface TransportReservedEvents {
|
|
14
|
+
export interface TransportReservedEvents {
|
|
15
15
|
open: () => void;
|
|
16
16
|
error: (err: TransportError) => void;
|
|
17
17
|
packet: (packet: Packet) => void;
|
|
@@ -22,11 +22,11 @@ export declare abstract class BaseXHR extends Polling {
|
|
|
22
22
|
/**
|
|
23
23
|
* Sends data.
|
|
24
24
|
*
|
|
25
|
-
* @param {String} data to send.
|
|
26
|
-
* @param {Function} called upon flush.
|
|
25
|
+
* @param {String} data - data to send.
|
|
26
|
+
* @param {Function} fn - called upon flush.
|
|
27
27
|
* @private
|
|
28
28
|
*/
|
|
29
|
-
doWrite(data:
|
|
29
|
+
doWrite(data: string, fn: () => void): void;
|
|
30
30
|
/**
|
|
31
31
|
* Starts a poll cycle.
|
|
32
32
|
*
|
|
@@ -62,7 +62,7 @@ export declare class Request extends Emitter<Record<never, never>, Record<never,
|
|
|
62
62
|
* @param {Object} options
|
|
63
63
|
* @package
|
|
64
64
|
*/
|
|
65
|
-
constructor(createRequest: (opts: RequestOptions) =>
|
|
65
|
+
constructor(createRequest: (opts: RequestOptions) => any, uri: string, opts: RequestOptions);
|
|
66
66
|
/**
|
|
67
67
|
* Creates the XHR object and sends the request.
|
|
68
68
|
*
|
|
@@ -29,8 +29,8 @@ export class BaseXHR extends Polling {
|
|
|
29
29
|
/**
|
|
30
30
|
* Sends data.
|
|
31
31
|
*
|
|
32
|
-
* @param {String} data to send.
|
|
33
|
-
* @param {Function} called upon flush.
|
|
32
|
+
* @param {String} data - data to send.
|
|
33
|
+
* @param {Function} fn - called upon flush.
|
|
34
34
|
* @private
|
|
35
35
|
*/
|
|
36
36
|
doWrite(data, fn) {
|