@meshagent/meshagent 0.39.3 → 0.39.5
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/CHANGELOG.md +10 -0
- package/README.md +134 -21
- package/dist/browser/entrypoint.d.ts +1426 -1464
- package/dist/browser/meshagent-client.js +7 -2
- package/dist/browser/package.json +1 -0
- package/dist/browser/room-client.d.ts +3 -1
- package/dist/browser/room-client.js +23 -7
- package/dist/esm/agent-client.js +18 -12
- package/dist/esm/agent.js +26 -18
- package/dist/esm/api_keys.js +21 -11
- package/dist/esm/client.js +13 -7
- package/dist/esm/completer.js +5 -1
- package/dist/esm/containers-client.js +85 -80
- package/dist/esm/datasets-client.js +105 -95
- package/dist/esm/developer-client.js +15 -11
- package/dist/esm/document.js +20 -11
- package/dist/esm/entrypoint.d.ts +1426 -1464
- package/dist/esm/entrypoint.js +12 -1
- package/dist/esm/event-emitter.js +5 -1
- package/dist/esm/helpers.js +23 -15
- package/dist/esm/index.js +49 -33
- package/dist/esm/lk-client.js +12 -7
- package/dist/esm/lk-protocol.js +8 -4
- package/dist/esm/memory-client.js +11 -7
- package/dist/esm/meshagent-client.js +88 -79
- package/dist/esm/messaging-client.js +37 -33
- package/dist/esm/package.json +1 -0
- package/dist/esm/participant-token.js +62 -34
- package/dist/esm/participant.js +9 -3
- package/dist/esm/protocol.js +43 -29
- package/dist/esm/queues-client.js +17 -12
- package/dist/esm/requirement.js +11 -4
- package/dist/esm/response.js +34 -22
- package/dist/esm/room-client.d.ts +3 -1
- package/dist/esm/room-client.js +154 -133
- package/dist/esm/room-event.js +21 -9
- package/dist/esm/room-server-client.js +18 -13
- package/dist/esm/runtime.js +10 -1
- package/dist/esm/schema.js +18 -9
- package/dist/esm/secrets-client.js +35 -31
- package/dist/esm/services-client.js +13 -9
- package/dist/esm/storage-client.js +38 -32
- package/dist/esm/stream-controller.js +5 -1
- package/dist/esm/sync-client.js +42 -38
- package/dist/esm/tool-content-type.js +5 -1
- package/dist/esm/utils.js +20 -10
- package/dist/esm/version.js +4 -1
- package/dist/node/entrypoint.d.ts +1426 -1464
- package/dist/node/meshagent-client.js +7 -2
- package/dist/node/package.json +1 -0
- package/dist/node/room-client.d.ts +3 -1
- package/dist/node/room-client.js +23 -7
- package/package.json +1 -1
package/dist/esm/protocol.js
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebSocketClientProtocol = exports.Protocol = exports.ProtocolMessageStream = exports.WebSocketProtocolChannel = exports.StreamProtocolChannel = exports.ProtocolHandshakeException = exports.ProtocolCloseException = exports.ProtocolReconnectUnsupportedException = exports.ProtocolCloseKind = void 0;
|
|
7
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
8
|
+
const completer_1 = require("./completer");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
4
10
|
class ProtocolMessage {
|
|
5
11
|
constructor({ id, type, data }) {
|
|
6
12
|
this.id = id;
|
|
7
13
|
this.type = type;
|
|
8
14
|
this.data = data;
|
|
9
|
-
this.sent = new Completer();
|
|
15
|
+
this.sent = new completer_1.Completer();
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
|
-
|
|
18
|
+
var ProtocolCloseKind;
|
|
13
19
|
(function (ProtocolCloseKind) {
|
|
14
20
|
ProtocolCloseKind["CLIENT"] = "client";
|
|
15
21
|
ProtocolCloseKind["SERVER"] = "server";
|
|
16
22
|
ProtocolCloseKind["ERROR"] = "error";
|
|
17
|
-
})(ProtocolCloseKind || (ProtocolCloseKind = {}));
|
|
18
|
-
|
|
23
|
+
})(ProtocolCloseKind || (exports.ProtocolCloseKind = ProtocolCloseKind = {}));
|
|
24
|
+
class ProtocolReconnectUnsupportedException extends Error {
|
|
19
25
|
constructor(message) {
|
|
20
26
|
super(message);
|
|
21
27
|
this.name = "ProtocolReconnectUnsupportedException";
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
|
-
|
|
30
|
+
exports.ProtocolReconnectUnsupportedException = ProtocolReconnectUnsupportedException;
|
|
31
|
+
class ProtocolCloseException extends Error {
|
|
25
32
|
constructor({ closeCode, reason }) {
|
|
26
33
|
super(reason == null || reason.trim().length === 0 ? `connection closed with status ${closeCode}` : reason);
|
|
27
34
|
this.name = "ProtocolCloseException";
|
|
@@ -29,7 +36,8 @@ export class ProtocolCloseException extends Error {
|
|
|
29
36
|
this.reason = reason;
|
|
30
37
|
}
|
|
31
38
|
}
|
|
32
|
-
|
|
39
|
+
exports.ProtocolCloseException = ProtocolCloseException;
|
|
40
|
+
class ProtocolHandshakeException extends Error {
|
|
33
41
|
constructor({ statusCode, statusText }) {
|
|
34
42
|
const normalizedStatusText = statusText?.trim();
|
|
35
43
|
super(normalizedStatusText == null || normalizedStatusText.length === 0
|
|
@@ -40,10 +48,11 @@ export class ProtocolHandshakeException extends Error {
|
|
|
40
48
|
this.statusText = normalizedStatusText;
|
|
41
49
|
}
|
|
42
50
|
}
|
|
51
|
+
exports.ProtocolHandshakeException = ProtocolHandshakeException;
|
|
43
52
|
function isNodeRuntime() {
|
|
44
53
|
return typeof process !== "undefined" && process.release?.name === "node";
|
|
45
54
|
}
|
|
46
|
-
|
|
55
|
+
class StreamProtocolChannel {
|
|
47
56
|
constructor({ input, output, }) {
|
|
48
57
|
this.started = false;
|
|
49
58
|
this._iterator = null;
|
|
@@ -81,10 +90,11 @@ export class StreamProtocolChannel {
|
|
|
81
90
|
this.output.add(data);
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
|
-
|
|
93
|
+
exports.StreamProtocolChannel = StreamProtocolChannel;
|
|
94
|
+
class WebSocketProtocolChannel {
|
|
85
95
|
constructor({ url, jwt }) {
|
|
86
96
|
this.webSocket = null;
|
|
87
|
-
this._opened = new Completer();
|
|
97
|
+
this._opened = new completer_1.Completer();
|
|
88
98
|
this._finished = false;
|
|
89
99
|
this._onUnexpectedResponse = (_request, response) => {
|
|
90
100
|
const statusCode = response.statusCode;
|
|
@@ -111,7 +121,7 @@ export class WebSocketProtocolChannel {
|
|
|
111
121
|
return;
|
|
112
122
|
}
|
|
113
123
|
if (typeof data === "string") {
|
|
114
|
-
this._onDataReceived?.(encoder.encode(data));
|
|
124
|
+
this._onDataReceived?.(utils_1.encoder.encode(data));
|
|
115
125
|
return;
|
|
116
126
|
}
|
|
117
127
|
if (data instanceof ArrayBuffer) {
|
|
@@ -143,12 +153,12 @@ export class WebSocketProtocolChannel {
|
|
|
143
153
|
start(onDataReceived, { onDone, onError }) {
|
|
144
154
|
const url = new URL(this.url);
|
|
145
155
|
url.searchParams.set("token", this.jwt);
|
|
146
|
-
this._opened = new Completer();
|
|
156
|
+
this._opened = new completer_1.Completer();
|
|
147
157
|
this._finished = false;
|
|
148
158
|
this._onDataReceived = onDataReceived;
|
|
149
159
|
this._doneHandler = onDone;
|
|
150
160
|
this._errorHandler = onError;
|
|
151
|
-
const socket = new
|
|
161
|
+
const socket = new isomorphic_ws_1.default(url.toString());
|
|
152
162
|
this.webSocket = socket;
|
|
153
163
|
if (isNodeRuntime()) {
|
|
154
164
|
socket.on("unexpected-response", this._onUnexpectedResponse);
|
|
@@ -183,7 +193,7 @@ export class WebSocketProtocolChannel {
|
|
|
183
193
|
if (isNodeRuntime()) {
|
|
184
194
|
socket.off("unexpected-response", this._onUnexpectedResponse);
|
|
185
195
|
}
|
|
186
|
-
if (socket.readyState ===
|
|
196
|
+
if (socket.readyState === isomorphic_ws_1.default.CONNECTING || socket.readyState === isomorphic_ws_1.default.OPEN) {
|
|
187
197
|
socket.close(1000);
|
|
188
198
|
}
|
|
189
199
|
}
|
|
@@ -196,10 +206,11 @@ export class WebSocketProtocolChannel {
|
|
|
196
206
|
socket.send(data);
|
|
197
207
|
}
|
|
198
208
|
}
|
|
199
|
-
|
|
209
|
+
exports.WebSocketProtocolChannel = WebSocketProtocolChannel;
|
|
210
|
+
class ProtocolMessageStream {
|
|
200
211
|
constructor() {
|
|
201
212
|
this._messages = [];
|
|
202
|
-
this._messageAdded = new Completer();
|
|
213
|
+
this._messageAdded = new completer_1.Completer();
|
|
203
214
|
this._closed = false;
|
|
204
215
|
}
|
|
205
216
|
add(message) {
|
|
@@ -217,7 +228,7 @@ export class ProtocolMessageStream {
|
|
|
217
228
|
async *stream() {
|
|
218
229
|
while (!this._closed) {
|
|
219
230
|
await this._messageAdded.fut;
|
|
220
|
-
this._messageAdded = new Completer();
|
|
231
|
+
this._messageAdded = new completer_1.Completer();
|
|
221
232
|
while (this._messages.length > 0 && !this._closed) {
|
|
222
233
|
const message = this._messages.shift();
|
|
223
234
|
if (message !== undefined) {
|
|
@@ -227,12 +238,13 @@ export class ProtocolMessageStream {
|
|
|
227
238
|
}
|
|
228
239
|
}
|
|
229
240
|
}
|
|
230
|
-
|
|
241
|
+
exports.ProtocolMessageStream = ProtocolMessageStream;
|
|
242
|
+
class Protocol {
|
|
231
243
|
constructor({ channel }) {
|
|
232
244
|
this.handlers = {};
|
|
233
245
|
this._id = 0;
|
|
234
246
|
this._send = new ProtocolMessageStream();
|
|
235
|
-
this._done = new Completer();
|
|
247
|
+
this._done = new completer_1.Completer();
|
|
236
248
|
this._sendLoop = null;
|
|
237
249
|
this._open = false;
|
|
238
250
|
this._closed = false;
|
|
@@ -311,7 +323,7 @@ export class Protocol {
|
|
|
311
323
|
async handleMessage(messageId, type, data) {
|
|
312
324
|
const handler = this.handlers[type] ?? this.handlers["*"];
|
|
313
325
|
if (handler == null) {
|
|
314
|
-
const unpacked = unpackMessage(data);
|
|
326
|
+
const unpacked = (0, utils_1.unpackMessage)(data);
|
|
315
327
|
console.warn(`No handler for message type ${type}; data:`, unpacked);
|
|
316
328
|
return;
|
|
317
329
|
}
|
|
@@ -343,7 +355,7 @@ export class Protocol {
|
|
|
343
355
|
await message.sent.fut;
|
|
344
356
|
}
|
|
345
357
|
async sendJson(object) {
|
|
346
|
-
await this.send("application/json", encoder.encode(JSON.stringify(object)));
|
|
358
|
+
await this.send("application/json", utils_1.encoder.encode(JSON.stringify(object)));
|
|
347
359
|
}
|
|
348
360
|
start({ onMessage, onDone, onError, } = {}) {
|
|
349
361
|
if (this._sendLoop != null) {
|
|
@@ -405,14 +417,14 @@ export class Protocol {
|
|
|
405
417
|
headerView.setUint32(4, message.id & 0xffffffff, false);
|
|
406
418
|
headerView.setUint32(8, 0, false);
|
|
407
419
|
headerView.setUint32(12, packets, false);
|
|
408
|
-
await this.channel.sendData(mergeUint8Arrays(header, encoder.encode(message.type)));
|
|
420
|
+
await this.channel.sendData((0, utils_1.mergeUint8Arrays)(header, utils_1.encoder.encode(message.type)));
|
|
409
421
|
for (let i = 0; i < packets; i += 1) {
|
|
410
422
|
const packetHeader = new Uint8Array(12);
|
|
411
423
|
const packetHeaderView = new DataView(packetHeader.buffer);
|
|
412
424
|
packetHeaderView.setUint32(0, Math.floor(message.id / 2 ** 32), false);
|
|
413
425
|
packetHeaderView.setUint32(4, message.id & 0xffffffff, false);
|
|
414
426
|
packetHeaderView.setUint32(8, i + 1, false);
|
|
415
|
-
await this.channel.sendData(mergeUint8Arrays(packetHeader, message.data.subarray(i * 1024, Math.min((i + 1) * 1024, message.data.length))));
|
|
427
|
+
await this.channel.sendData((0, utils_1.mergeUint8Arrays)(packetHeader, message.data.subarray(i * 1024, Math.min((i + 1) * 1024, message.data.length))));
|
|
416
428
|
}
|
|
417
429
|
if (!message.sent.completed) {
|
|
418
430
|
message.sent.complete();
|
|
@@ -447,10 +459,10 @@ export class Protocol {
|
|
|
447
459
|
if (this._recvState === "ready" || this._recvState === "error") {
|
|
448
460
|
this._recvPacketTotal = dataView.getUint32(12, false);
|
|
449
461
|
this._recvMessageId = messageId;
|
|
450
|
-
this._recvType = decoder.decode(dataPacket.subarray(16));
|
|
462
|
+
this._recvType = utils_1.decoder.decode(dataPacket.subarray(16));
|
|
451
463
|
if (this._recvPacketTotal === 0) {
|
|
452
464
|
try {
|
|
453
|
-
const merged = mergeUint8Arrays(...this._recvPackets);
|
|
465
|
+
const merged = (0, utils_1.mergeUint8Arrays)(...this._recvPackets);
|
|
454
466
|
this._recvPackets.length = 0;
|
|
455
467
|
this._dispatchMessage({ messageId, type: this._recvType, data: merged });
|
|
456
468
|
}
|
|
@@ -484,7 +496,7 @@ export class Protocol {
|
|
|
484
496
|
this._recvPackets.push(dataPacket.subarray(12));
|
|
485
497
|
if (this._recvPacketTotal === this._recvPacketId) {
|
|
486
498
|
try {
|
|
487
|
-
const merged = mergeUint8Arrays(...this._recvPackets);
|
|
499
|
+
const merged = (0, utils_1.mergeUint8Arrays)(...this._recvPackets);
|
|
488
500
|
this._recvPackets.length = 0;
|
|
489
501
|
this._dispatchMessage({ messageId, type: this._recvType, data: merged });
|
|
490
502
|
}
|
|
@@ -504,7 +516,8 @@ export class Protocol {
|
|
|
504
516
|
});
|
|
505
517
|
}
|
|
506
518
|
}
|
|
507
|
-
|
|
519
|
+
exports.Protocol = Protocol;
|
|
520
|
+
class WebSocketClientProtocol extends Protocol {
|
|
508
521
|
constructor({ url, token }) {
|
|
509
522
|
super({
|
|
510
523
|
channel: new WebSocketProtocolChannel({ url, jwt: token }),
|
|
@@ -519,3 +532,4 @@ export class WebSocketClientProtocol extends Protocol {
|
|
|
519
532
|
return this._token;
|
|
520
533
|
}
|
|
521
534
|
}
|
|
535
|
+
exports.WebSocketClientProtocol = WebSocketClientProtocol;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueuesClient = exports.Queue = void 0;
|
|
4
|
+
const response_1 = require("./response");
|
|
5
|
+
const room_server_client_1 = require("./room-server-client");
|
|
6
|
+
class Queue {
|
|
4
7
|
constructor({ name, size }) {
|
|
5
8
|
this.name = name;
|
|
6
9
|
this.size = size;
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
|
-
|
|
12
|
+
exports.Queue = Queue;
|
|
13
|
+
class QueuesClient {
|
|
10
14
|
constructor({ room }) {
|
|
11
15
|
this.client = room;
|
|
12
16
|
}
|
|
13
17
|
_unexpectedResponseError(operation) {
|
|
14
|
-
return new RoomServerException(`unexpected return type from queues.${operation}`);
|
|
18
|
+
return new room_server_client_1.RoomServerException(`unexpected return type from queues.${operation}`);
|
|
15
19
|
}
|
|
16
20
|
async _invoke(operation, arguments_) {
|
|
17
21
|
return await this.client.invoke({
|
|
@@ -22,7 +26,7 @@ export class QueuesClient {
|
|
|
22
26
|
}
|
|
23
27
|
async list() {
|
|
24
28
|
const response = await this._invoke("list", {});
|
|
25
|
-
if (!(response instanceof JsonContent)) {
|
|
29
|
+
if (!(response instanceof response_1.JsonContent)) {
|
|
26
30
|
throw this._unexpectedResponseError("list");
|
|
27
31
|
}
|
|
28
32
|
const queues = response.json["queues"];
|
|
@@ -30,25 +34,25 @@ export class QueuesClient {
|
|
|
30
34
|
}
|
|
31
35
|
async open(name) {
|
|
32
36
|
const response = await this._invoke("open", { name });
|
|
33
|
-
if (!(response instanceof EmptyContent)) {
|
|
37
|
+
if (!(response instanceof response_1.EmptyContent)) {
|
|
34
38
|
throw this._unexpectedResponseError("open");
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
async drain(name) {
|
|
38
42
|
const response = await this._invoke("drain", { name });
|
|
39
|
-
if (!(response instanceof EmptyContent)) {
|
|
43
|
+
if (!(response instanceof response_1.EmptyContent)) {
|
|
40
44
|
throw this._unexpectedResponseError("drain");
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
async close(name) {
|
|
44
48
|
const response = await this._invoke("close", { name });
|
|
45
|
-
if (!(response instanceof EmptyContent)) {
|
|
49
|
+
if (!(response instanceof response_1.EmptyContent)) {
|
|
46
50
|
throw this._unexpectedResponseError("close");
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
async send(name, message, { create = true }) {
|
|
50
54
|
const response = await this._invoke("send", { name, create, message });
|
|
51
|
-
if (!(response instanceof EmptyContent)) {
|
|
55
|
+
if (!(response instanceof response_1.EmptyContent)) {
|
|
52
56
|
throw this._unexpectedResponseError("send");
|
|
53
57
|
}
|
|
54
58
|
}
|
|
@@ -58,12 +62,13 @@ export class QueuesClient {
|
|
|
58
62
|
create,
|
|
59
63
|
wait,
|
|
60
64
|
});
|
|
61
|
-
if (response instanceof EmptyContent) {
|
|
65
|
+
if (response instanceof response_1.EmptyContent) {
|
|
62
66
|
return null;
|
|
63
67
|
}
|
|
64
|
-
if (response instanceof JsonContent) {
|
|
68
|
+
if (response instanceof response_1.JsonContent) {
|
|
65
69
|
return response.json;
|
|
66
70
|
}
|
|
67
71
|
throw this._unexpectedResponseError("receive");
|
|
68
72
|
}
|
|
69
73
|
}
|
|
74
|
+
exports.QueuesClient = QueuesClient;
|
package/dist/esm/requirement.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequiredSchema = exports.RequiredToolkit = exports.Requirement = exports.RoomException = void 0;
|
|
4
|
+
class RoomException extends Error {
|
|
2
5
|
constructor(message) {
|
|
3
6
|
super(message);
|
|
4
7
|
this.name = "RoomException";
|
|
5
8
|
}
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
exports.RoomException = RoomException;
|
|
11
|
+
class Requirement {
|
|
8
12
|
constructor({ name }) {
|
|
9
13
|
this.name = name;
|
|
10
14
|
}
|
|
@@ -22,7 +26,8 @@ export class Requirement {
|
|
|
22
26
|
throw new RoomException("invalid requirement json");
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
|
-
|
|
29
|
+
exports.Requirement = Requirement;
|
|
30
|
+
class RequiredToolkit extends Requirement {
|
|
26
31
|
constructor({ name, tools, participantName, }) {
|
|
27
32
|
super({ name });
|
|
28
33
|
this.tools = tools;
|
|
@@ -36,7 +41,8 @@ export class RequiredToolkit extends Requirement {
|
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
|
-
|
|
44
|
+
exports.RequiredToolkit = RequiredToolkit;
|
|
45
|
+
class RequiredSchema extends Requirement {
|
|
40
46
|
constructor({ name }) {
|
|
41
47
|
super({ name });
|
|
42
48
|
}
|
|
@@ -46,3 +52,4 @@ export class RequiredSchema extends Requirement {
|
|
|
46
52
|
};
|
|
47
53
|
}
|
|
48
54
|
}
|
|
55
|
+
exports.RequiredSchema = RequiredSchema;
|
package/dist/esm/response.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ControlContent = exports.ControlCloseStatus = exports.EmptyContent = exports.ErrorContent = exports.JsonContent = exports.TextContent = exports.FileContent = exports.LinkContent = exports.BinaryContent = void 0;
|
|
4
|
+
exports.unpackContent = unpackContent;
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
class BinaryContent {
|
|
3
7
|
constructor({ data, headers = {} }) {
|
|
4
8
|
this.data = data;
|
|
5
9
|
this.headers = headers;
|
|
@@ -11,7 +15,7 @@ export class BinaryContent {
|
|
|
11
15
|
});
|
|
12
16
|
}
|
|
13
17
|
pack() {
|
|
14
|
-
return packMessage({
|
|
18
|
+
return (0, utils_1.packMessage)({
|
|
15
19
|
type: "binary",
|
|
16
20
|
headers: this.headers,
|
|
17
21
|
}, this.data);
|
|
@@ -20,7 +24,8 @@ export class BinaryContent {
|
|
|
20
24
|
return `BinaryContent: headers=${JSON.stringify(this.headers)} length=${this.data.length}`;
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
exports.BinaryContent = BinaryContent;
|
|
28
|
+
class LinkContent {
|
|
24
29
|
constructor({ url, name }) {
|
|
25
30
|
this.url = url;
|
|
26
31
|
this.name = name;
|
|
@@ -32,7 +37,7 @@ export class LinkContent {
|
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
39
|
pack() {
|
|
35
|
-
return packMessage({
|
|
40
|
+
return (0, utils_1.packMessage)({
|
|
36
41
|
type: "link",
|
|
37
42
|
name: this.name,
|
|
38
43
|
url: this.url,
|
|
@@ -42,7 +47,8 @@ export class LinkContent {
|
|
|
42
47
|
return `LinkContent (${this.name}): ${this.url}`;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
|
-
|
|
50
|
+
exports.LinkContent = LinkContent;
|
|
51
|
+
class FileContent {
|
|
46
52
|
constructor({ data, name, mimeType }) {
|
|
47
53
|
this.data = data;
|
|
48
54
|
this.name = name;
|
|
@@ -56,7 +62,7 @@ export class FileContent {
|
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
64
|
pack() {
|
|
59
|
-
return packMessage({
|
|
65
|
+
return (0, utils_1.packMessage)({
|
|
60
66
|
type: "file",
|
|
61
67
|
name: this.name,
|
|
62
68
|
mime_type: this.mimeType,
|
|
@@ -66,7 +72,8 @@ export class FileContent {
|
|
|
66
72
|
return `FileContent (${this.name}): ${this.mimeType}`;
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
|
-
|
|
75
|
+
exports.FileContent = FileContent;
|
|
76
|
+
class TextContent {
|
|
70
77
|
constructor({ text }) {
|
|
71
78
|
this.text = text;
|
|
72
79
|
}
|
|
@@ -76,7 +83,7 @@ export class TextContent {
|
|
|
76
83
|
});
|
|
77
84
|
}
|
|
78
85
|
pack() {
|
|
79
|
-
return packMessage({
|
|
86
|
+
return (0, utils_1.packMessage)({
|
|
80
87
|
type: "text",
|
|
81
88
|
text: this.text,
|
|
82
89
|
});
|
|
@@ -85,7 +92,8 @@ export class TextContent {
|
|
|
85
92
|
return `TextContent: ${this.text}`;
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
|
-
|
|
95
|
+
exports.TextContent = TextContent;
|
|
96
|
+
class JsonContent {
|
|
89
97
|
constructor({ json }) {
|
|
90
98
|
this.json = json;
|
|
91
99
|
}
|
|
@@ -93,7 +101,7 @@ export class JsonContent {
|
|
|
93
101
|
return new JsonContent({ json: header["json"] });
|
|
94
102
|
}
|
|
95
103
|
pack() {
|
|
96
|
-
return packMessage({
|
|
104
|
+
return (0, utils_1.packMessage)({
|
|
97
105
|
type: "json",
|
|
98
106
|
json: this.json,
|
|
99
107
|
});
|
|
@@ -102,7 +110,8 @@ export class JsonContent {
|
|
|
102
110
|
return `JsonContent: ${JSON.stringify(this.json)}`;
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
|
-
|
|
113
|
+
exports.JsonContent = JsonContent;
|
|
114
|
+
class ErrorContent {
|
|
106
115
|
constructor({ text, code }) {
|
|
107
116
|
this.text = text;
|
|
108
117
|
this.code = code;
|
|
@@ -129,7 +138,7 @@ export class ErrorContent {
|
|
|
129
138
|
if (this.code !== undefined) {
|
|
130
139
|
header["code"] = this.code;
|
|
131
140
|
}
|
|
132
|
-
return packMessage(header);
|
|
141
|
+
return (0, utils_1.packMessage)(header);
|
|
133
142
|
}
|
|
134
143
|
toString() {
|
|
135
144
|
return this.code !== undefined
|
|
@@ -137,23 +146,25 @@ export class ErrorContent {
|
|
|
137
146
|
: `ErrorContent: ${this.text}`;
|
|
138
147
|
}
|
|
139
148
|
}
|
|
140
|
-
|
|
149
|
+
exports.ErrorContent = ErrorContent;
|
|
150
|
+
class EmptyContent {
|
|
141
151
|
static unpack(_header, _payload) {
|
|
142
152
|
return new EmptyContent();
|
|
143
153
|
}
|
|
144
154
|
pack() {
|
|
145
|
-
return packMessage({ type: "empty" });
|
|
155
|
+
return (0, utils_1.packMessage)({ type: "empty" });
|
|
146
156
|
}
|
|
147
157
|
toString() {
|
|
148
158
|
return `EmptyContent`;
|
|
149
159
|
}
|
|
150
160
|
}
|
|
151
|
-
|
|
161
|
+
exports.EmptyContent = EmptyContent;
|
|
162
|
+
var ControlCloseStatus;
|
|
152
163
|
(function (ControlCloseStatus) {
|
|
153
164
|
ControlCloseStatus[ControlCloseStatus["NORMAL"] = 1000] = "NORMAL";
|
|
154
165
|
ControlCloseStatus[ControlCloseStatus["INVALID_DATA"] = 1007] = "INVALID_DATA";
|
|
155
|
-
})(ControlCloseStatus || (ControlCloseStatus = {}));
|
|
156
|
-
|
|
166
|
+
})(ControlCloseStatus || (exports.ControlCloseStatus = ControlCloseStatus = {}));
|
|
167
|
+
class ControlContent {
|
|
157
168
|
constructor({ method, statusCode, message, }) {
|
|
158
169
|
this.method = method;
|
|
159
170
|
this.statusCode = method === "close" ? statusCode ?? ControlCloseStatus.NORMAL : statusCode;
|
|
@@ -192,12 +203,13 @@ export class ControlContent {
|
|
|
192
203
|
header["message"] = this.message;
|
|
193
204
|
}
|
|
194
205
|
}
|
|
195
|
-
return packMessage(header);
|
|
206
|
+
return (0, utils_1.packMessage)(header);
|
|
196
207
|
}
|
|
197
208
|
toString() {
|
|
198
209
|
return `ControlContent: ${this.method}`;
|
|
199
210
|
}
|
|
200
211
|
}
|
|
212
|
+
exports.ControlContent = ControlContent;
|
|
201
213
|
const _contentTypes = {
|
|
202
214
|
binary: BinaryContent.unpack,
|
|
203
215
|
control: ControlContent.unpack,
|
|
@@ -208,9 +220,9 @@ const _contentTypes = {
|
|
|
208
220
|
link: LinkContent.unpack,
|
|
209
221
|
text: TextContent.unpack,
|
|
210
222
|
};
|
|
211
|
-
|
|
212
|
-
const header = JSON.parse(splitMessageHeader(data));
|
|
213
|
-
const payload = splitMessagePayload(data);
|
|
223
|
+
function unpackContent(data) {
|
|
224
|
+
const header = JSON.parse((0, utils_1.splitMessageHeader)(data));
|
|
225
|
+
const payload = (0, utils_1.splitMessagePayload)(data);
|
|
214
226
|
const typeKey = header["type"];
|
|
215
227
|
if (!_contentTypes[typeKey]) {
|
|
216
228
|
throw new Error(`Unknown content type: ${typeKey}`);
|
|
@@ -85,7 +85,8 @@ export declare class RoomClient {
|
|
|
85
85
|
private _roomName;
|
|
86
86
|
private _roomUrl;
|
|
87
87
|
private _sessionId;
|
|
88
|
-
private static readonly
|
|
88
|
+
private static readonly RECONNECT_RETRY_BASE_DELAY_MS;
|
|
89
|
+
private static readonly RECONNECT_RETRY_MAX_DELAY_MS;
|
|
89
90
|
private readonly _handleRoomReadyBound;
|
|
90
91
|
private readonly _handleRoomStatusBound;
|
|
91
92
|
private readonly _handleParticipantBound;
|
|
@@ -151,6 +152,7 @@ export declare class RoomClient {
|
|
|
151
152
|
private _completeReconnect;
|
|
152
153
|
private _replaceProtocol;
|
|
153
154
|
private _remainingReconnectTimeout;
|
|
155
|
+
private _reconnectRetryDelay;
|
|
154
156
|
private _attemptInitialProtocolStartup;
|
|
155
157
|
private _attemptReconnect;
|
|
156
158
|
private _formatDuration;
|