@dxos/edge-client 0.8.2-main.12df754 → 0.8.2-main.36232bc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-XS3TKGM4.mjs +545 -0
- package/dist/lib/browser/chunk-XS3TKGM4.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +60 -282
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +32 -20
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-ZURVCY7K.cjs +577 -0
- package/dist/lib/node/chunk-ZURVCY7K.cjs.map +7 -0
- package/dist/lib/node/index.cjs +50 -281
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +31 -21
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs +547 -0
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +60 -282
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +32 -20
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-ws-connection.d.ts +5 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +23 -0
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -0
- package/dist/types/src/testing/test-utils.d.ts +6 -2
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/edge-client.ts +2 -2
- package/src/edge-ws-connection.ts +38 -15
- package/src/edge-ws-muxer.ts +187 -0
- package/src/testing/test-utils.ts +33 -26
- package/dist/lib/browser/chunk-ZWJXA37R.mjs +0 -113
- package/dist/lib/browser/chunk-ZWJXA37R.mjs.map +0 -7
- package/dist/lib/node/chunk-ANV2HBEH.cjs +0 -136
- package/dist/lib/node/chunk-ANV2HBEH.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs +0 -115
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs.map +0 -7
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
// packages/core/mesh/edge-client/src/protocol.ts
|
|
2
|
+
import { invariant } from "@dxos/invariant";
|
|
3
|
+
import { buf, bufWkt } from "@dxos/protocols/buf";
|
|
4
|
+
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
5
|
+
import { bufferToArray } from "@dxos/util";
|
|
6
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
|
|
7
|
+
var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
|
|
8
|
+
var Protocol = class {
|
|
9
|
+
constructor(types) {
|
|
10
|
+
this._typeRegistry = buf.createRegistry(...types);
|
|
11
|
+
}
|
|
12
|
+
get typeRegistry() {
|
|
13
|
+
return this._typeRegistry;
|
|
14
|
+
}
|
|
15
|
+
toJson(message) {
|
|
16
|
+
try {
|
|
17
|
+
return buf.toJson(MessageSchema, message, {
|
|
18
|
+
registry: this.typeRegistry
|
|
19
|
+
});
|
|
20
|
+
} catch (err) {
|
|
21
|
+
return {
|
|
22
|
+
type: this.getPayloadType(message)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return the payload with the given type.
|
|
28
|
+
*/
|
|
29
|
+
getPayload(message, type) {
|
|
30
|
+
invariant(message.payload, void 0, {
|
|
31
|
+
F: __dxlog_file,
|
|
32
|
+
L: 40,
|
|
33
|
+
S: this,
|
|
34
|
+
A: [
|
|
35
|
+
"message.payload",
|
|
36
|
+
""
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
const payloadTypename = this.getPayloadType(message);
|
|
40
|
+
if (type && type.typeName !== payloadTypename) {
|
|
41
|
+
throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);
|
|
42
|
+
}
|
|
43
|
+
invariant(bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`, {
|
|
44
|
+
F: __dxlog_file,
|
|
45
|
+
L: 46,
|
|
46
|
+
S: this,
|
|
47
|
+
A: [
|
|
48
|
+
"bufWkt.anyIs(message.payload, type)",
|
|
49
|
+
"`Unexpected payload type: ${payloadTypename}}`"
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
const payload = bufWkt.anyUnpack(message.payload, this.typeRegistry);
|
|
53
|
+
invariant(payload, `Empty payload: ${payloadTypename}}`, {
|
|
54
|
+
F: __dxlog_file,
|
|
55
|
+
L: 48,
|
|
56
|
+
S: this,
|
|
57
|
+
A: [
|
|
58
|
+
"payload",
|
|
59
|
+
"`Empty payload: ${payloadTypename}}`"
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
return payload;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the payload type.
|
|
66
|
+
*/
|
|
67
|
+
getPayloadType(message) {
|
|
68
|
+
if (!message.payload) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
const [, type] = message.payload.typeUrl.split("/");
|
|
72
|
+
return type;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a packed message.
|
|
76
|
+
*/
|
|
77
|
+
createMessage(type, { source, target, payload, serviceId }) {
|
|
78
|
+
return buf.create(MessageSchema, {
|
|
79
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
80
|
+
source,
|
|
81
|
+
target,
|
|
82
|
+
serviceId,
|
|
83
|
+
payload: payload ? bufWkt.anyPack(type, buf.create(type, payload)) : void 0
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var toUint8Array = async (data) => {
|
|
88
|
+
if (data instanceof Buffer) {
|
|
89
|
+
return bufferToArray(data);
|
|
90
|
+
}
|
|
91
|
+
if (data instanceof Blob) {
|
|
92
|
+
return new Uint8Array(await data.arrayBuffer());
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`Unexpected datatype: ${data}`);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// packages/core/mesh/edge-client/src/defs.ts
|
|
98
|
+
import { bufWkt as bufWkt2 } from "@dxos/protocols/buf";
|
|
99
|
+
import { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
100
|
+
var protocol = new Protocol([
|
|
101
|
+
SwarmRequestSchema,
|
|
102
|
+
SwarmResponseSchema,
|
|
103
|
+
TextMessageSchema,
|
|
104
|
+
bufWkt2.AnySchema
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
// packages/core/mesh/edge-client/src/edge-ws-muxer.ts
|
|
108
|
+
import WebSocket from "isomorphic-ws";
|
|
109
|
+
import { Trigger } from "@dxos/async";
|
|
110
|
+
import { log } from "@dxos/log";
|
|
111
|
+
import { buf as buf2 } from "@dxos/protocols/buf";
|
|
112
|
+
import { MessageSchema as MessageSchema2 } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
113
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-muxer.ts";
|
|
114
|
+
var FLAG_SEGMENT_SEQ = 1;
|
|
115
|
+
var FLAG_SEGMENT_SEQ_TERMINATED = 1 << 1;
|
|
116
|
+
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
117
|
+
var MAX_CHUNK_LENGTH = 16384;
|
|
118
|
+
var MAX_BUFFERED_AMOUNT = CLOUDFLARE_MESSAGE_LENGTH_LIMIT;
|
|
119
|
+
var BUFFER_FULL_BACKOFF_TIMEOUT = 100;
|
|
120
|
+
var WebSocketMuxer = class {
|
|
121
|
+
constructor(_ws) {
|
|
122
|
+
this._ws = _ws;
|
|
123
|
+
this._incomingMessageAccumulator = /* @__PURE__ */ new Map();
|
|
124
|
+
this._outgoingMessageChunks = /* @__PURE__ */ new Map();
|
|
125
|
+
this._serviceToChannel = /* @__PURE__ */ new Map();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resolves when all the message chunks get enqueued for sending.
|
|
129
|
+
*/
|
|
130
|
+
async send(message) {
|
|
131
|
+
const binary = buf2.toBinary(MessageSchema2, message);
|
|
132
|
+
const channelId = this._resolveChannel(message);
|
|
133
|
+
if (channelId == null && binary.length > CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
134
|
+
log.error("Large message dropped because channel resolution failed.", {
|
|
135
|
+
byteLength: binary.byteLength,
|
|
136
|
+
serviceId: message.serviceId,
|
|
137
|
+
payload: protocol.getPayloadType(message)
|
|
138
|
+
}, {
|
|
139
|
+
F: __dxlog_file2,
|
|
140
|
+
L: 52,
|
|
141
|
+
S: this,
|
|
142
|
+
C: (f, a) => f(...a)
|
|
143
|
+
});
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (channelId == null || binary.length < MAX_CHUNK_LENGTH) {
|
|
147
|
+
const flags = Buffer.from([
|
|
148
|
+
0
|
|
149
|
+
]);
|
|
150
|
+
this._ws.send(Buffer.concat([
|
|
151
|
+
flags,
|
|
152
|
+
binary
|
|
153
|
+
]));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const terminatorSentTrigger = new Trigger();
|
|
157
|
+
const messageChunks = [];
|
|
158
|
+
for (let i = 0; i < binary.length; i += MAX_CHUNK_LENGTH) {
|
|
159
|
+
const chunk = binary.slice(i, i + MAX_CHUNK_LENGTH);
|
|
160
|
+
const isLastChunk = i + MAX_CHUNK_LENGTH < binary.length;
|
|
161
|
+
if (isLastChunk) {
|
|
162
|
+
const flags = Buffer.from([
|
|
163
|
+
FLAG_SEGMENT_SEQ | FLAG_SEGMENT_SEQ_TERMINATED,
|
|
164
|
+
channelId
|
|
165
|
+
]);
|
|
166
|
+
messageChunks.push({
|
|
167
|
+
payload: Buffer.concat([
|
|
168
|
+
flags,
|
|
169
|
+
chunk
|
|
170
|
+
]),
|
|
171
|
+
trigger: terminatorSentTrigger
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
const flags = Buffer.from([
|
|
175
|
+
FLAG_SEGMENT_SEQ
|
|
176
|
+
]);
|
|
177
|
+
messageChunks.push({
|
|
178
|
+
payload: Buffer.concat([
|
|
179
|
+
flags,
|
|
180
|
+
chunk
|
|
181
|
+
])
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const queuedMessages = this._outgoingMessageChunks.get(channelId);
|
|
186
|
+
if (queuedMessages) {
|
|
187
|
+
queuedMessages.push(...messageChunks);
|
|
188
|
+
} else {
|
|
189
|
+
this._outgoingMessageChunks.set(channelId, messageChunks);
|
|
190
|
+
}
|
|
191
|
+
this._sendChunkedMessages();
|
|
192
|
+
return terminatorSentTrigger.wait();
|
|
193
|
+
}
|
|
194
|
+
receiveData(data) {
|
|
195
|
+
if ((data[0] & FLAG_SEGMENT_SEQ) === 0) {
|
|
196
|
+
return buf2.fromBinary(MessageSchema2, data.slice(1));
|
|
197
|
+
}
|
|
198
|
+
const [flags, channelId, ...payload] = data;
|
|
199
|
+
let chunkAccumulator = this._incomingMessageAccumulator.get(channelId);
|
|
200
|
+
if (chunkAccumulator) {
|
|
201
|
+
chunkAccumulator.push(Buffer.from(payload));
|
|
202
|
+
} else {
|
|
203
|
+
chunkAccumulator = [
|
|
204
|
+
Buffer.from(payload)
|
|
205
|
+
];
|
|
206
|
+
this._incomingMessageAccumulator.set(channelId, chunkAccumulator);
|
|
207
|
+
}
|
|
208
|
+
if ((flags & FLAG_SEGMENT_SEQ_TERMINATED) === 0) {
|
|
209
|
+
return void 0;
|
|
210
|
+
}
|
|
211
|
+
const message = buf2.fromBinary(MessageSchema2, Buffer.concat(chunkAccumulator));
|
|
212
|
+
this._incomingMessageAccumulator.delete(channelId);
|
|
213
|
+
return message;
|
|
214
|
+
}
|
|
215
|
+
destroy() {
|
|
216
|
+
if (this._sendTimeout) {
|
|
217
|
+
clearTimeout(this._sendTimeout);
|
|
218
|
+
this._sendTimeout = void 0;
|
|
219
|
+
}
|
|
220
|
+
for (const channelChunks of this._outgoingMessageChunks.values()) {
|
|
221
|
+
channelChunks.forEach((chunk) => chunk.trigger?.wake());
|
|
222
|
+
}
|
|
223
|
+
this._outgoingMessageChunks.clear();
|
|
224
|
+
this._incomingMessageAccumulator.clear();
|
|
225
|
+
this._serviceToChannel.clear();
|
|
226
|
+
}
|
|
227
|
+
_sendChunkedMessages() {
|
|
228
|
+
if (this._sendTimeout) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const send = () => {
|
|
232
|
+
if (this._ws.readyState === WebSocket.CLOSING || this._ws.readyState === WebSocket.CLOSED) {
|
|
233
|
+
log.warn("send called for closed websocket", void 0, {
|
|
234
|
+
F: __dxlog_file2,
|
|
235
|
+
L: 135,
|
|
236
|
+
S: this,
|
|
237
|
+
C: (f, a) => f(...a)
|
|
238
|
+
});
|
|
239
|
+
this._sendTimeout = void 0;
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
let timeout = 0;
|
|
243
|
+
const emptyChannels = [];
|
|
244
|
+
for (const [channelId, messages] of this._outgoingMessageChunks.entries()) {
|
|
245
|
+
if (this._ws.bufferedAmount + MAX_CHUNK_LENGTH > MAX_BUFFERED_AMOUNT) {
|
|
246
|
+
timeout = BUFFER_FULL_BACKOFF_TIMEOUT;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
const nextMessage = messages.shift();
|
|
250
|
+
if (nextMessage) {
|
|
251
|
+
this._ws.send(nextMessage.payload);
|
|
252
|
+
nextMessage.trigger?.wake();
|
|
253
|
+
} else {
|
|
254
|
+
emptyChannels.push(channelId);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
emptyChannels.forEach((channelId) => this._outgoingMessageChunks.delete(channelId));
|
|
258
|
+
if (this._outgoingMessageChunks.size > 0) {
|
|
259
|
+
this._sendTimeout = setTimeout(send, timeout);
|
|
260
|
+
} else {
|
|
261
|
+
this._sendTimeout = void 0;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
this._sendTimeout = setTimeout(send);
|
|
265
|
+
}
|
|
266
|
+
_resolveChannel(message) {
|
|
267
|
+
if (!message.serviceId) {
|
|
268
|
+
return void 0;
|
|
269
|
+
}
|
|
270
|
+
let id = this._serviceToChannel.get(message.serviceId);
|
|
271
|
+
if (!id) {
|
|
272
|
+
id = this._serviceToChannel.size + 1;
|
|
273
|
+
this._serviceToChannel.set(message.serviceId, id);
|
|
274
|
+
}
|
|
275
|
+
return id;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// packages/core/mesh/edge-client/src/edge-ws-connection.ts
|
|
280
|
+
import WebSocket2 from "isomorphic-ws";
|
|
281
|
+
import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
282
|
+
import { Context, Resource } from "@dxos/context";
|
|
283
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
284
|
+
import { log as log2, logInfo } from "@dxos/log";
|
|
285
|
+
import { buf as buf3 } from "@dxos/protocols/buf";
|
|
286
|
+
import { MessageSchema as MessageSchema3 } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
287
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
288
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
289
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
290
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
291
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
292
|
+
}
|
|
293
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
294
|
+
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
295
|
+
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
296
|
+
var EDGE_WEBSOCKET_PROTOCOL_V0 = "edge-ws-v0";
|
|
297
|
+
var EDGE_WEBSOCKET_PROTOCOL_V1 = "edge-ws-v1";
|
|
298
|
+
var EdgeWsConnection = class extends Resource {
|
|
299
|
+
constructor(_identity, _connectionInfo, _callbacks) {
|
|
300
|
+
super();
|
|
301
|
+
this._identity = _identity;
|
|
302
|
+
this._connectionInfo = _connectionInfo;
|
|
303
|
+
this._callbacks = _callbacks;
|
|
304
|
+
}
|
|
305
|
+
get info() {
|
|
306
|
+
return {
|
|
307
|
+
open: this.isOpen,
|
|
308
|
+
identity: this._identity.identityKey,
|
|
309
|
+
device: this._identity.peerKey
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
send(message) {
|
|
313
|
+
invariant2(this._ws, void 0, {
|
|
314
|
+
F: __dxlog_file3,
|
|
315
|
+
L: 57,
|
|
316
|
+
S: this,
|
|
317
|
+
A: [
|
|
318
|
+
"this._ws",
|
|
319
|
+
""
|
|
320
|
+
]
|
|
321
|
+
});
|
|
322
|
+
invariant2(this._wsMuxer, void 0, {
|
|
323
|
+
F: __dxlog_file3,
|
|
324
|
+
L: 58,
|
|
325
|
+
S: this,
|
|
326
|
+
A: [
|
|
327
|
+
"this._wsMuxer",
|
|
328
|
+
""
|
|
329
|
+
]
|
|
330
|
+
});
|
|
331
|
+
log2("sending...", {
|
|
332
|
+
peerKey: this._identity.peerKey,
|
|
333
|
+
payload: protocol.getPayloadType(message)
|
|
334
|
+
}, {
|
|
335
|
+
F: __dxlog_file3,
|
|
336
|
+
L: 59,
|
|
337
|
+
S: this,
|
|
338
|
+
C: (f, a) => f(...a)
|
|
339
|
+
});
|
|
340
|
+
if (this._ws?.protocol.includes(EDGE_WEBSOCKET_PROTOCOL_V0)) {
|
|
341
|
+
const binary = buf3.toBinary(MessageSchema3, message);
|
|
342
|
+
if (binary.length > CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
343
|
+
log2.error("Message dropped because it was too large (>1MB).", {
|
|
344
|
+
byteLength: binary.byteLength,
|
|
345
|
+
serviceId: message.serviceId,
|
|
346
|
+
payload: protocol.getPayloadType(message)
|
|
347
|
+
}, {
|
|
348
|
+
F: __dxlog_file3,
|
|
349
|
+
L: 63,
|
|
350
|
+
S: this,
|
|
351
|
+
C: (f, a) => f(...a)
|
|
352
|
+
});
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
this._ws.send(binary);
|
|
356
|
+
} else {
|
|
357
|
+
this._wsMuxer.send(message).catch((e) => log2.catch(e, void 0, {
|
|
358
|
+
F: __dxlog_file3,
|
|
359
|
+
L: 72,
|
|
360
|
+
S: this,
|
|
361
|
+
C: (f, a) => f(...a)
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
async _open() {
|
|
366
|
+
const baseProtocols = [
|
|
367
|
+
EDGE_WEBSOCKET_PROTOCOL_V0,
|
|
368
|
+
EDGE_WEBSOCKET_PROTOCOL_V1
|
|
369
|
+
];
|
|
370
|
+
this._ws = new WebSocket2(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
371
|
+
...baseProtocols,
|
|
372
|
+
this._connectionInfo.protocolHeader
|
|
373
|
+
] : [
|
|
374
|
+
...baseProtocols
|
|
375
|
+
]);
|
|
376
|
+
const muxer = new WebSocketMuxer(this._ws);
|
|
377
|
+
this._wsMuxer = muxer;
|
|
378
|
+
this._ws.onopen = () => {
|
|
379
|
+
if (this.isOpen) {
|
|
380
|
+
log2("connected", void 0, {
|
|
381
|
+
F: __dxlog_file3,
|
|
382
|
+
L: 89,
|
|
383
|
+
S: this,
|
|
384
|
+
C: (f, a) => f(...a)
|
|
385
|
+
});
|
|
386
|
+
this._callbacks.onConnected();
|
|
387
|
+
this._scheduleHeartbeats();
|
|
388
|
+
} else {
|
|
389
|
+
log2.verbose("connected after becoming inactive", {
|
|
390
|
+
currentIdentity: this._identity
|
|
391
|
+
}, {
|
|
392
|
+
F: __dxlog_file3,
|
|
393
|
+
L: 93,
|
|
394
|
+
S: this,
|
|
395
|
+
C: (f, a) => f(...a)
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
this._ws.onclose = (event) => {
|
|
400
|
+
if (this.isOpen) {
|
|
401
|
+
log2.warn("disconnected while being open", {
|
|
402
|
+
code: event.code,
|
|
403
|
+
reason: event.reason
|
|
404
|
+
}, {
|
|
405
|
+
F: __dxlog_file3,
|
|
406
|
+
L: 98,
|
|
407
|
+
S: this,
|
|
408
|
+
C: (f, a) => f(...a)
|
|
409
|
+
});
|
|
410
|
+
this._callbacks.onRestartRequired();
|
|
411
|
+
muxer.destroy();
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
this._ws.onerror = (event) => {
|
|
415
|
+
if (this.isOpen) {
|
|
416
|
+
log2.warn("edge connection socket error", {
|
|
417
|
+
error: event.error,
|
|
418
|
+
info: event.message
|
|
419
|
+
}, {
|
|
420
|
+
F: __dxlog_file3,
|
|
421
|
+
L: 105,
|
|
422
|
+
S: this,
|
|
423
|
+
C: (f, a) => f(...a)
|
|
424
|
+
});
|
|
425
|
+
this._callbacks.onRestartRequired();
|
|
426
|
+
} else {
|
|
427
|
+
log2.verbose("error ignored on closed connection", {
|
|
428
|
+
error: event.error
|
|
429
|
+
}, {
|
|
430
|
+
F: __dxlog_file3,
|
|
431
|
+
L: 108,
|
|
432
|
+
S: this,
|
|
433
|
+
C: (f, a) => f(...a)
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
this._ws.onmessage = async (event) => {
|
|
438
|
+
if (!this.isOpen) {
|
|
439
|
+
log2.verbose("message ignored on closed connection", {
|
|
440
|
+
event: event.type
|
|
441
|
+
}, {
|
|
442
|
+
F: __dxlog_file3,
|
|
443
|
+
L: 116,
|
|
444
|
+
S: this,
|
|
445
|
+
C: (f, a) => f(...a)
|
|
446
|
+
});
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (event.data === "__pong__") {
|
|
450
|
+
this._rescheduleHeartbeatTimeout();
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const bytes = await toUint8Array(event.data);
|
|
454
|
+
if (!this.isOpen) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const message = this._ws?.protocol?.includes(EDGE_WEBSOCKET_PROTOCOL_V0) ? buf3.fromBinary(MessageSchema3, bytes) : muxer.receiveData(bytes);
|
|
458
|
+
if (message) {
|
|
459
|
+
log2("received", {
|
|
460
|
+
from: message.source,
|
|
461
|
+
payload: protocol.getPayloadType(message)
|
|
462
|
+
}, {
|
|
463
|
+
F: __dxlog_file3,
|
|
464
|
+
L: 133,
|
|
465
|
+
S: this,
|
|
466
|
+
C: (f, a) => f(...a)
|
|
467
|
+
});
|
|
468
|
+
this._callbacks.onMessage(message);
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
async _close() {
|
|
473
|
+
void this._inactivityTimeoutCtx?.dispose().catch(() => {
|
|
474
|
+
});
|
|
475
|
+
try {
|
|
476
|
+
this._ws?.close();
|
|
477
|
+
this._ws = void 0;
|
|
478
|
+
this._wsMuxer?.destroy();
|
|
479
|
+
this._wsMuxer = void 0;
|
|
480
|
+
} catch (err) {
|
|
481
|
+
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
log2.warn("Error closing websocket", {
|
|
485
|
+
err
|
|
486
|
+
}, {
|
|
487
|
+
F: __dxlog_file3,
|
|
488
|
+
L: 151,
|
|
489
|
+
S: this,
|
|
490
|
+
C: (f, a) => f(...a)
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
_scheduleHeartbeats() {
|
|
495
|
+
invariant2(this._ws, void 0, {
|
|
496
|
+
F: __dxlog_file3,
|
|
497
|
+
L: 156,
|
|
498
|
+
S: this,
|
|
499
|
+
A: [
|
|
500
|
+
"this._ws",
|
|
501
|
+
""
|
|
502
|
+
]
|
|
503
|
+
});
|
|
504
|
+
scheduleTaskInterval(this._ctx, async () => {
|
|
505
|
+
this._ws?.send("__ping__");
|
|
506
|
+
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
507
|
+
this._ws.send("__ping__");
|
|
508
|
+
this._rescheduleHeartbeatTimeout();
|
|
509
|
+
}
|
|
510
|
+
_rescheduleHeartbeatTimeout() {
|
|
511
|
+
if (!this.isOpen) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
void this._inactivityTimeoutCtx?.dispose();
|
|
515
|
+
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
516
|
+
F: __dxlog_file3,
|
|
517
|
+
L: 175
|
|
518
|
+
});
|
|
519
|
+
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
520
|
+
if (this.isOpen) {
|
|
521
|
+
log2.warn("restart due to inactivity timeout", void 0, {
|
|
522
|
+
F: __dxlog_file3,
|
|
523
|
+
L: 180,
|
|
524
|
+
S: this,
|
|
525
|
+
C: (f, a) => f(...a)
|
|
526
|
+
});
|
|
527
|
+
this._callbacks.onRestartRequired();
|
|
528
|
+
}
|
|
529
|
+
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
_ts_decorate([
|
|
533
|
+
logInfo
|
|
534
|
+
], EdgeWsConnection.prototype, "info", null);
|
|
535
|
+
|
|
536
|
+
export {
|
|
537
|
+
getTypename,
|
|
538
|
+
Protocol,
|
|
539
|
+
toUint8Array,
|
|
540
|
+
protocol,
|
|
541
|
+
WebSocketMuxer,
|
|
542
|
+
EDGE_WEBSOCKET_PROTOCOL_V1,
|
|
543
|
+
EdgeWsConnection
|
|
544
|
+
};
|
|
545
|
+
//# sourceMappingURL=chunk-XS3TKGM4.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/protocol.ts", "../../../src/defs.ts", "../../../src/edge-ws-muxer.ts", "../../../src/edge-ws-connection.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { buf, bufWkt } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema, type PeerSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\nimport { bufferToArray } from '@dxos/util';\n\nexport type PeerData = buf.MessageInitShape<typeof PeerSchema>;\n\nexport const getTypename = (typeName: string) => `type.googleapis.com/${typeName}`;\n\n/**\n * NOTE: The type registry should be extended with all message types.\n */\nexport class Protocol {\n private readonly _typeRegistry: buf.Registry;\n\n constructor(types: buf.DescMessage[]) {\n this._typeRegistry = buf.createRegistry(...types);\n }\n\n get typeRegistry(): buf.Registry {\n return this._typeRegistry;\n }\n\n toJson(message: Message): any {\n try {\n return buf.toJson(MessageSchema, message, { registry: this.typeRegistry });\n } catch (err) {\n return { type: this.getPayloadType(message) };\n }\n }\n\n /**\n * Return the payload with the given type.\n */\n getPayload<Desc extends buf.DescMessage>(message: Message, type: Desc): buf.MessageShape<Desc> {\n invariant(message.payload);\n const payloadTypename = this.getPayloadType(message);\n if (type && type.typeName !== payloadTypename) {\n throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);\n }\n\n invariant(bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`);\n const payload = bufWkt.anyUnpack(message.payload, this.typeRegistry) as buf.MessageShape<Desc>;\n invariant(payload, `Empty payload: ${payloadTypename}}`);\n return payload;\n }\n\n /**\n * Get the payload type.\n */\n getPayloadType(message: Message): string | undefined {\n if (!message.payload) {\n return undefined;\n }\n\n const [, type] = message.payload.typeUrl.split('/');\n return type;\n }\n\n /**\n * Create a packed message.\n */\n createMessage<Desc extends buf.DescMessage>(\n type: Desc,\n {\n source,\n target,\n payload,\n serviceId,\n }: {\n source?: PeerData;\n target?: PeerData[];\n payload?: buf.MessageInitShape<Desc>;\n serviceId?: string;\n },\n ) {\n return buf.create(MessageSchema, {\n timestamp: new Date().toISOString(),\n source,\n target,\n serviceId,\n payload: payload ? bufWkt.anyPack(type, buf.create(type, payload)) : undefined,\n });\n }\n}\n\n/**\n * Convert websocket data to Uint8Array.\n */\nexport const toUint8Array = async (data: any): Promise<Uint8Array> => {\n // Node.\n if (data instanceof Buffer) {\n return bufferToArray(data);\n }\n\n // Browser.\n if (data instanceof Blob) {\n return new Uint8Array(await (data as Blob).arrayBuffer());\n }\n\n throw new Error(`Unexpected datatype: ${data}`);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { bufWkt } from '@dxos/protocols/buf';\nimport { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { Protocol } from './protocol';\n\nexport const protocol = new Protocol([SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema, bufWkt.AnySchema]);\n", "//\n// Copyright 2025 DXOS.org\n//\nimport WebSocket from 'isomorphic-ws';\n\nimport { Trigger } from '@dxos/async';\nimport { log } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { MessageSchema, type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\n\n/**\n * 0000 0001 - message contains a part of segmented message chunk sequence.\n * The next byte defines a channel id and the rest of the message contains a part of Message proto binary.\n * Messages from different channels might interleave.\n * When the flag is NOT set the rest of the message should be interpreted as the valid Message proto binary.\n */\nconst FLAG_SEGMENT_SEQ = 1;\n/**\n * 0000 0010 - message terminates a segmented message chunk sequence.\n * All the chunks accumulated for the channel specified by the second byte can be concatenated\n * and interpreted as a valid Message proto binary.\n */\nconst FLAG_SEGMENT_SEQ_TERMINATED = 1 << 1;\n\n/**\n * 1MB websocket message limit: https://developers.cloudflare.com/durable-objects/platform/limits/\n */\nexport const CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;\n\nconst MAX_CHUNK_LENGTH = 16384;\nconst MAX_BUFFERED_AMOUNT = CLOUDFLARE_MESSAGE_LENGTH_LIMIT;\nconst BUFFER_FULL_BACKOFF_TIMEOUT = 100;\n\nexport class WebSocketMuxer {\n private readonly _incomingMessageAccumulator = new Map<number, Buffer[]>();\n private readonly _outgoingMessageChunks = new Map<number, MessageChunk[]>();\n private readonly _serviceToChannel = new Map<string, number>();\n\n private _sendTimeout: any | undefined;\n\n constructor(private readonly _ws: WebSocket) {}\n\n /**\n * Resolves when all the message chunks get enqueued for sending.\n */\n public async send(message: Message): Promise<void> {\n const binary = buf.toBinary(MessageSchema, message);\n const channelId = this._resolveChannel(message);\n if (channelId == null && binary.length > CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {\n log.error('Large message dropped because channel resolution failed.', {\n byteLength: binary.byteLength,\n serviceId: message.serviceId,\n payload: protocol.getPayloadType(message),\n });\n return;\n }\n\n if (channelId == null || binary.length < MAX_CHUNK_LENGTH) {\n const flags = Buffer.from([0]);\n this._ws.send(Buffer.concat([flags, binary]));\n return;\n }\n\n const terminatorSentTrigger = new Trigger();\n const messageChunks: MessageChunk[] = [];\n for (let i = 0; i < binary.length; i += MAX_CHUNK_LENGTH) {\n const chunk = binary.slice(i, i + MAX_CHUNK_LENGTH);\n const isLastChunk = i + MAX_CHUNK_LENGTH < binary.length;\n if (isLastChunk) {\n const flags = Buffer.from([FLAG_SEGMENT_SEQ | FLAG_SEGMENT_SEQ_TERMINATED, channelId]);\n messageChunks.push({ payload: Buffer.concat([flags, chunk]), trigger: terminatorSentTrigger });\n } else {\n const flags = Buffer.from([FLAG_SEGMENT_SEQ]);\n messageChunks.push({ payload: Buffer.concat([flags, chunk]) });\n }\n }\n\n const queuedMessages = this._outgoingMessageChunks.get(channelId);\n if (queuedMessages) {\n queuedMessages.push(...messageChunks);\n } else {\n this._outgoingMessageChunks.set(channelId, messageChunks);\n }\n\n this._sendChunkedMessages();\n\n return terminatorSentTrigger.wait();\n }\n\n public receiveData(data: Uint8Array): Message | undefined {\n if ((data[0] & FLAG_SEGMENT_SEQ) === 0) {\n return buf.fromBinary(MessageSchema, data.slice(1));\n }\n\n const [flags, channelId, ...payload] = data;\n let chunkAccumulator = this._incomingMessageAccumulator.get(channelId);\n if (chunkAccumulator) {\n chunkAccumulator.push(Buffer.from(payload));\n } else {\n chunkAccumulator = [Buffer.from(payload)];\n this._incomingMessageAccumulator.set(channelId, chunkAccumulator);\n }\n\n if ((flags & FLAG_SEGMENT_SEQ_TERMINATED) === 0) {\n return undefined;\n }\n\n const message = buf.fromBinary(MessageSchema, Buffer.concat(chunkAccumulator));\n this._incomingMessageAccumulator.delete(channelId);\n return message;\n }\n\n public destroy() {\n if (this._sendTimeout) {\n clearTimeout(this._sendTimeout);\n this._sendTimeout = undefined;\n }\n for (const channelChunks of this._outgoingMessageChunks.values()) {\n channelChunks.forEach((chunk) => chunk.trigger?.wake());\n }\n this._outgoingMessageChunks.clear();\n this._incomingMessageAccumulator.clear();\n this._serviceToChannel.clear();\n }\n\n private _sendChunkedMessages() {\n if (this._sendTimeout) {\n return;\n }\n\n const send = () => {\n if (this._ws.readyState === WebSocket.CLOSING || this._ws.readyState === WebSocket.CLOSED) {\n log.warn('send called for closed websocket');\n this._sendTimeout = undefined;\n return;\n }\n\n let timeout = 0;\n const emptyChannels: number[] = [];\n for (const [channelId, messages] of this._outgoingMessageChunks.entries()) {\n if (this._ws.bufferedAmount + MAX_CHUNK_LENGTH > MAX_BUFFERED_AMOUNT) {\n timeout = BUFFER_FULL_BACKOFF_TIMEOUT;\n break;\n }\n\n const nextMessage = messages.shift();\n if (nextMessage) {\n this._ws.send(nextMessage.payload);\n nextMessage.trigger?.wake();\n } else {\n emptyChannels.push(channelId);\n }\n }\n\n emptyChannels.forEach((channelId) => this._outgoingMessageChunks.delete(channelId));\n\n if (this._outgoingMessageChunks.size > 0) {\n this._sendTimeout = setTimeout(send, timeout);\n } else {\n this._sendTimeout = undefined;\n }\n };\n this._sendTimeout = setTimeout(send);\n }\n\n private _resolveChannel(message: Message): number | undefined {\n if (!message.serviceId) {\n return undefined;\n }\n let id = this._serviceToChannel.get(message.serviceId);\n if (!id) {\n id = this._serviceToChannel.size + 1;\n this._serviceToChannel.set(message.serviceId, id);\n }\n return id;\n }\n}\n\ntype MessageChunk = {\n payload: Buffer;\n /**\n * Wakes when the payload is enqueued by WebSocket.\n */\n trigger?: Trigger;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'isomorphic-ws';\n\nimport { scheduleTask, scheduleTaskInterval } from '@dxos/async';\nimport { Context, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log, logInfo } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { MessageSchema, type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\nimport { type EdgeIdentity } from './edge-identity';\nimport { CLOUDFLARE_MESSAGE_LENGTH_LIMIT, WebSocketMuxer } from './edge-ws-muxer';\nimport { toUint8Array } from './protocol';\n\nconst SIGNAL_KEEPALIVE_INTERVAL = 4_000;\nconst SIGNAL_KEEPALIVE_TIMEOUT = 12_000;\n\nconst EDGE_WEBSOCKET_PROTOCOL_V0 = 'edge-ws-v0';\n/**\n * Supports message segmentation and muxing.\n */\nexport const EDGE_WEBSOCKET_PROTOCOL_V1 = 'edge-ws-v1';\n\nexport type EdgeWsConnectionCallbacks = {\n onConnected: () => void;\n onMessage: (message: Message) => void;\n onRestartRequired: () => void;\n};\n\nexport class EdgeWsConnection extends Resource {\n private _inactivityTimeoutCtx: Context | undefined;\n private _ws: WebSocket | undefined;\n private _wsMuxer: WebSocketMuxer | undefined;\n\n constructor(\n private readonly _identity: EdgeIdentity,\n private readonly _connectionInfo: { url: URL; protocolHeader?: string },\n private readonly _callbacks: EdgeWsConnectionCallbacks,\n ) {\n super();\n }\n\n @logInfo\n public get info() {\n return {\n open: this.isOpen,\n identity: this._identity.identityKey,\n device: this._identity.peerKey,\n };\n }\n\n public send(message: Message) {\n invariant(this._ws);\n invariant(this._wsMuxer);\n log('sending...', { peerKey: this._identity.peerKey, payload: protocol.getPayloadType(message) });\n if (this._ws?.protocol.includes(EDGE_WEBSOCKET_PROTOCOL_V0)) {\n const binary = buf.toBinary(MessageSchema, message);\n if (binary.length > CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {\n log.error('Message dropped because it was too large (>1MB).', {\n byteLength: binary.byteLength,\n serviceId: message.serviceId,\n payload: protocol.getPayloadType(message),\n });\n return;\n }\n this._ws.send(binary);\n } else {\n this._wsMuxer.send(message).catch((e) => log.catch(e));\n }\n }\n\n protected override async _open() {\n const baseProtocols = [EDGE_WEBSOCKET_PROTOCOL_V0, EDGE_WEBSOCKET_PROTOCOL_V1];\n this._ws = new WebSocket(\n this._connectionInfo.url.toString(),\n this._connectionInfo.protocolHeader\n ? [...baseProtocols, this._connectionInfo.protocolHeader]\n : [...baseProtocols],\n );\n const muxer = new WebSocketMuxer(this._ws);\n this._wsMuxer = muxer;\n\n this._ws.onopen = () => {\n if (this.isOpen) {\n log('connected');\n this._callbacks.onConnected();\n this._scheduleHeartbeats();\n } else {\n log.verbose('connected after becoming inactive', { currentIdentity: this._identity });\n }\n };\n this._ws.onclose = (event) => {\n if (this.isOpen) {\n log.warn('disconnected while being open', { code: event.code, reason: event.reason });\n this._callbacks.onRestartRequired();\n muxer.destroy();\n }\n };\n this._ws.onerror = (event) => {\n if (this.isOpen) {\n log.warn('edge connection socket error', { error: event.error, info: event.message });\n this._callbacks.onRestartRequired();\n } else {\n log.verbose('error ignored on closed connection', { error: event.error });\n }\n };\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data\n */\n this._ws.onmessage = async (event) => {\n if (!this.isOpen) {\n log.verbose('message ignored on closed connection', { event: event.type });\n return;\n }\n if (event.data === '__pong__') {\n this._rescheduleHeartbeatTimeout();\n return;\n }\n const bytes = await toUint8Array(event.data);\n if (!this.isOpen) {\n return;\n }\n\n const message = this._ws?.protocol?.includes(EDGE_WEBSOCKET_PROTOCOL_V0)\n ? buf.fromBinary(MessageSchema, bytes)\n : muxer.receiveData(bytes);\n\n if (message) {\n log('received', { from: message.source, payload: protocol.getPayloadType(message) });\n this._callbacks.onMessage(message);\n }\n };\n }\n\n protected override async _close() {\n void this._inactivityTimeoutCtx?.dispose().catch(() => {});\n\n try {\n this._ws?.close();\n this._ws = undefined;\n this._wsMuxer?.destroy();\n this._wsMuxer = undefined;\n } catch (err) {\n if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {\n return;\n }\n log.warn('Error closing websocket', { err });\n }\n }\n\n private _scheduleHeartbeats() {\n invariant(this._ws);\n scheduleTaskInterval(\n this._ctx,\n async () => {\n // TODO(mykola): use RFC6455 ping/pong once implemented in the browser?\n // Cloudflare's worker responds to this `without interrupting hibernation`. https://developers.cloudflare.com/durable-objects/api/websockets/#setwebsocketautoresponse\n this._ws?.send('__ping__');\n },\n SIGNAL_KEEPALIVE_INTERVAL,\n );\n this._ws.send('__ping__');\n this._rescheduleHeartbeatTimeout();\n }\n\n private _rescheduleHeartbeatTimeout() {\n if (!this.isOpen) {\n return;\n }\n void this._inactivityTimeoutCtx?.dispose();\n this._inactivityTimeoutCtx = new Context();\n scheduleTask(\n this._inactivityTimeoutCtx,\n () => {\n if (this.isOpen) {\n log.warn('restart due to inactivity timeout');\n this._callbacks.onRestartRequired();\n }\n },\n SIGNAL_KEEPALIVE_TIMEOUT,\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,iBAAiB;AAC1B,SAASC,KAAKC,cAAc;AAC5B,SAAuBC,qBAAsC;AAC7D,SAASC,qBAAqB;;AAIvB,IAAMC,cAAc,C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WAAKrD,UAAUoC,QAAAA;AACf,WAAKpC,WAAWqD;IAClB,SAASC,KAAK;AACZ,UAAIA,eAAeC,SAASD,IAAIzD,QAAQQ,SAAS,2DAAA,GAA8D;AAC7G;MACF;AACAJ,MAAAA,KAAI+B,KAAK,2BAA2B;QAAEsB;MAAI,GAAA;;;;;;IAC5C;EACF;EAEQ3B,sBAAsB;AAC5B7B,IAAAA,WAAU,KAAKC,KAAG,QAAA;;;;;;;;;AAClByD,yBACE,KAAKC,MACL,YAAA;AAGE,WAAK1D,KAAKH,KAAK,UAAA;IACjB,GACAjB,yBAAAA;AAEF,SAAKoB,IAAIH,KAAK,UAAA;AACd,SAAK6C,4BAA2B;EAClC;EAEQA,8BAA8B;AACpC,QAAI,CAAC,KAAKlD,QAAQ;AAChB;IACF;AACA,SAAK,KAAK2D,uBAAuBC,QAAAA;AACjC,SAAKD,wBAAwB,IAAIQ,QAAAA,QAAAA;;;;AACjCC,iBACE,KAAKT,uBACL,MAAA;AACE,UAAI,KAAK3D,QAAQ;AACfU,QAAAA,KAAI+B,KAAK,qCAAA,QAAA;;;;;;AACT,aAAK5C,WAAW+C,kBAAiB;MACnC;IACF,GACAvD,wBAAAA;EAEJ;AACF;;EA5IGgF;GAbU7E,iBAAAA,WAAAA,QAAAA,IAAAA;",
|
|
6
|
+
"names": ["invariant", "buf", "bufWkt", "MessageSchema", "bufferToArray", "getTypename", "typeName", "Protocol", "constructor", "types", "_typeRegistry", "createRegistry", "typeRegistry", "toJson", "message", "registry", "err", "type", "getPayloadType", "getPayload", "payload", "payloadTypename", "Error", "anyIs", "anyUnpack", "undefined", "typeUrl", "split", "createMessage", "source", "target", "serviceId", "create", "timestamp", "Date", "toISOString", "anyPack", "toUint8Array", "data", "Buffer", "Blob", "Uint8Array", "arrayBuffer", "bufWkt", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "protocol", "Protocol", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "bufWkt", "AnySchema", "WebSocket", "Trigger", "log", "buf", "MessageSchema", "FLAG_SEGMENT_SEQ", "FLAG_SEGMENT_SEQ_TERMINATED", "CLOUDFLARE_MESSAGE_LENGTH_LIMIT", "MAX_CHUNK_LENGTH", "MAX_BUFFERED_AMOUNT", "BUFFER_FULL_BACKOFF_TIMEOUT", "WebSocketMuxer", "constructor", "_ws", "_incomingMessageAccumulator", "Map", "_outgoingMessageChunks", "_serviceToChannel", "send", "message", "binary", "buf", "toBinary", "MessageSchema", "channelId", "_resolveChannel", "length", "log", "error", "byteLength", "serviceId", "payload", "protocol", "getPayloadType", "flags", "Buffer", "from", "concat", "terminatorSentTrigger", "Trigger", "messageChunks", "i", "chunk", "slice", "isLastChunk", "push", "trigger", "queuedMessages", "get", "set", "_sendChunkedMessages", "wait", "receiveData", "data", "fromBinary", "chunkAccumulator", "undefined", "delete", "destroy", "_sendTimeout", "clearTimeout", "channelChunks", "values", "forEach", "wake", "clear", "readyState", "WebSocket", "CLOSING", "CLOSED", "warn", "timeout", "emptyChannels", "messages", "entries", "bufferedAmount", "nextMessage", "shift", "size", "setTimeout", "id", "WebSocket", "scheduleTask", "scheduleTaskInterval", "Context", "Resource", "invariant", "log", "logInfo", "buf", "MessageSchema", "SIGNAL_KEEPALIVE_INTERVAL", "SIGNAL_KEEPALIVE_TIMEOUT", "EDGE_WEBSOCKET_PROTOCOL_V0", "EDGE_WEBSOCKET_PROTOCOL_V1", "EdgeWsConnection", "Resource", "constructor", "_identity", "_connectionInfo", "_callbacks", "info", "open", "isOpen", "identity", "identityKey", "device", "peerKey", "send", "message", "invariant", "_ws", "_wsMuxer", "log", "payload", "protocol", "getPayloadType", "includes", "binary", "buf", "toBinary", "MessageSchema", "length", "CLOUDFLARE_MESSAGE_LENGTH_LIMIT", "error", "byteLength", "serviceId", "catch", "e", "_open", "baseProtocols", "WebSocket", "url", "toString", "protocolHeader", "muxer", "WebSocketMuxer", "onopen", "onConnected", "_scheduleHeartbeats", "verbose", "currentIdentity", "onclose", "event", "warn", "code", "reason", "onRestartRequired", "destroy", "onerror", "onmessage", "type", "data", "_rescheduleHeartbeatTimeout", "bytes", "toUint8Array", "fromBinary", "receiveData", "from", "source", "onMessage", "_close", "_inactivityTimeoutCtx", "dispose", "close", "undefined", "err", "Error", "scheduleTaskInterval", "_ctx", "Context", "scheduleTask", "logInfo"]
|
|
7
|
+
}
|