@dxos/edge-client 0.8.2-main.36232bc → 0.8.2-main.5ca3450
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-TKYUZ5ZK.mjs +302 -0
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs.map +7 -0
- package/dist/lib/browser/edge-ws-muxer.mjs +11 -0
- package/dist/lib/browser/edge-ws-muxer.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +318 -58
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-ZOL3YSDR.cjs +322 -0
- package/dist/lib/node/chunk-ZOL3YSDR.cjs.map +7 -0
- package/dist/lib/node/edge-ws-muxer.cjs +33 -0
- package/dist/lib/node/edge-ws-muxer.cjs.map +7 -0
- package/dist/lib/node/index.cjs +322 -53
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +6 -5
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs +304 -0
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs.map +7 -0
- package/dist/lib/node-esm/edge-ws-muxer.mjs +12 -0
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +318 -58
- 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 +3 -3
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/auth.d.ts.map +1 -1
- package/dist/types/src/edge-identity.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts +0 -4
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +19 -7
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.test.d.ts +2 -0
- package/dist/types/src/edge-ws-muxer.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/protocol.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -14
- package/src/edge-ws-connection.ts +6 -11
- package/src/edge-ws-muxer.test.ts +55 -0
- package/src/edge-ws-muxer.ts +63 -33
- package/src/index.ts +1 -0
- package/src/testing/test-utils.ts +2 -2
- package/dist/lib/browser/chunk-XS3TKGM4.mjs +0 -545
- package/dist/lib/browser/chunk-XS3TKGM4.mjs.map +0 -7
- package/dist/lib/node/chunk-ZURVCY7K.cjs +0 -577
- package/dist/lib/node/chunk-ZURVCY7K.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs +0 -547
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/edge-client",
|
|
3
|
-
"version": "0.8.2-main.
|
|
3
|
+
"version": "0.8.2-main.5ca3450",
|
|
4
4
|
"description": "EDGE Client",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
15
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
16
|
},
|
|
17
|
+
"./muxer": {
|
|
18
|
+
"types": "./dist/types/src/edge-ws-muxer.d.ts",
|
|
19
|
+
"browser": "./dist/lib/browser/edge-ws-muxer.mjs",
|
|
20
|
+
"node": "./dist/lib/node-esm/edge-ws-muxer.mjs"
|
|
21
|
+
},
|
|
17
22
|
"./testing": {
|
|
18
23
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
19
24
|
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
@@ -36,21 +41,21 @@
|
|
|
36
41
|
"dependencies": {
|
|
37
42
|
"isomorphic-ws": "^5.0.0",
|
|
38
43
|
"ws": "^8.14.2",
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/credentials": "0.8.2-main.
|
|
42
|
-
"@dxos/debug": "0.8.2-main.
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/keys": "0.8.2-main.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
44
|
+
"@dxos/context": "0.8.2-main.5ca3450",
|
|
45
|
+
"@dxos/async": "0.8.2-main.5ca3450",
|
|
46
|
+
"@dxos/credentials": "0.8.2-main.5ca3450",
|
|
47
|
+
"@dxos/debug": "0.8.2-main.5ca3450",
|
|
48
|
+
"@dxos/invariant": "0.8.2-main.5ca3450",
|
|
49
|
+
"@dxos/keys": "0.8.2-main.5ca3450",
|
|
50
|
+
"@dxos/crypto": "0.8.2-main.5ca3450",
|
|
51
|
+
"@dxos/keyring": "0.8.2-main.5ca3450",
|
|
52
|
+
"@dxos/node-std": "0.8.2-main.5ca3450",
|
|
53
|
+
"@dxos/protocols": "0.8.2-main.5ca3450",
|
|
54
|
+
"@dxos/log": "0.8.2-main.5ca3450",
|
|
55
|
+
"@dxos/util": "0.8.2-main.5ca3450"
|
|
51
56
|
},
|
|
52
57
|
"devDependencies": {
|
|
53
|
-
"@dxos/test-utils": "0.8.2-main.
|
|
58
|
+
"@dxos/test-utils": "0.8.2-main.5ca3450"
|
|
54
59
|
},
|
|
55
60
|
"publishConfig": {
|
|
56
61
|
"access": "public"
|
|
@@ -8,23 +8,18 @@ import { scheduleTask, scheduleTaskInterval } from '@dxos/async';
|
|
|
8
8
|
import { Context, Resource } from '@dxos/context';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
10
|
import { log, logInfo } from '@dxos/log';
|
|
11
|
+
import { EdgeWebsocketProtocol } from '@dxos/protocols';
|
|
11
12
|
import { buf } from '@dxos/protocols/buf';
|
|
12
13
|
import { MessageSchema, type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
13
14
|
|
|
14
15
|
import { protocol } from './defs';
|
|
15
16
|
import { type EdgeIdentity } from './edge-identity';
|
|
16
|
-
import {
|
|
17
|
+
import { CLOUDFLARE_MESSAGE_MAX_BYTES, WebSocketMuxer } from './edge-ws-muxer';
|
|
17
18
|
import { toUint8Array } from './protocol';
|
|
18
19
|
|
|
19
20
|
const SIGNAL_KEEPALIVE_INTERVAL = 4_000;
|
|
20
21
|
const SIGNAL_KEEPALIVE_TIMEOUT = 12_000;
|
|
21
22
|
|
|
22
|
-
const EDGE_WEBSOCKET_PROTOCOL_V0 = 'edge-ws-v0';
|
|
23
|
-
/**
|
|
24
|
-
* Supports message segmentation and muxing.
|
|
25
|
-
*/
|
|
26
|
-
export const EDGE_WEBSOCKET_PROTOCOL_V1 = 'edge-ws-v1';
|
|
27
|
-
|
|
28
23
|
export type EdgeWsConnectionCallbacks = {
|
|
29
24
|
onConnected: () => void;
|
|
30
25
|
onMessage: (message: Message) => void;
|
|
@@ -57,9 +52,9 @@ export class EdgeWsConnection extends Resource {
|
|
|
57
52
|
invariant(this._ws);
|
|
58
53
|
invariant(this._wsMuxer);
|
|
59
54
|
log('sending...', { peerKey: this._identity.peerKey, payload: protocol.getPayloadType(message) });
|
|
60
|
-
if (this._ws?.protocol.includes(
|
|
55
|
+
if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {
|
|
61
56
|
const binary = buf.toBinary(MessageSchema, message);
|
|
62
|
-
if (binary.length >
|
|
57
|
+
if (binary.length > CLOUDFLARE_MESSAGE_MAX_BYTES) {
|
|
63
58
|
log.error('Message dropped because it was too large (>1MB).', {
|
|
64
59
|
byteLength: binary.byteLength,
|
|
65
60
|
serviceId: message.serviceId,
|
|
@@ -74,7 +69,7 @@ export class EdgeWsConnection extends Resource {
|
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
protected override async _open() {
|
|
77
|
-
const baseProtocols = [
|
|
72
|
+
const baseProtocols = [...Object.values(EdgeWebsocketProtocol)];
|
|
78
73
|
this._ws = new WebSocket(
|
|
79
74
|
this._connectionInfo.url.toString(),
|
|
80
75
|
this._connectionInfo.protocolHeader
|
|
@@ -125,7 +120,7 @@ export class EdgeWsConnection extends Resource {
|
|
|
125
120
|
return;
|
|
126
121
|
}
|
|
127
122
|
|
|
128
|
-
const message = this._ws?.protocol?.includes(
|
|
123
|
+
const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0)
|
|
129
124
|
? buf.fromBinary(MessageSchema, bytes)
|
|
130
125
|
: muxer.receiveData(bytes);
|
|
131
126
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { bufWkt } from '@dxos/protocols/buf';
|
|
8
|
+
import { TextMessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
9
|
+
|
|
10
|
+
import { protocol } from './defs';
|
|
11
|
+
import type { EdgeIdentity } from './edge-identity';
|
|
12
|
+
import { WebSocketMuxer } from './edge-ws-muxer';
|
|
13
|
+
|
|
14
|
+
const MAX_CHUNK_LENGTH = 16;
|
|
15
|
+
|
|
16
|
+
describe('WebSocketMuxerTest', () => {
|
|
17
|
+
test('basic message reassembly', async () => {
|
|
18
|
+
const { muxer: muxer1, sentMessages } = await createMuxer();
|
|
19
|
+
const { muxer: muxer2 } = await createMuxer();
|
|
20
|
+
const content = 'A'.repeat(MAX_CHUNK_LENGTH);
|
|
21
|
+
await muxer1.send(textMessage(content));
|
|
22
|
+
|
|
23
|
+
expect(sentMessages.length).toBeGreaterThan(1);
|
|
24
|
+
for (const chunk of sentMessages.slice(0, -1)) {
|
|
25
|
+
expect(muxer2.receiveData(chunk)).toBeUndefined();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const reassembledMessage = muxer2.receiveData(sentMessages.at(-1)!)!;
|
|
29
|
+
expect(reassembledMessage).toBeDefined();
|
|
30
|
+
|
|
31
|
+
const decoded = bufWkt.anyUnpack(reassembledMessage.payload!, TextMessageSchema);
|
|
32
|
+
expect(decoded?.message).toStrictEqual(content);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const textMessage = (message: string, source?: EdgeIdentity) =>
|
|
37
|
+
protocol.createMessage(TextMessageSchema, {
|
|
38
|
+
source: source && { peerKey: source.peerKey, identityKey: source.identityKey },
|
|
39
|
+
serviceId: 'test-service',
|
|
40
|
+
payload: { message },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const createMuxer = async () => {
|
|
44
|
+
const sentMessages: Uint8Array[] = [];
|
|
45
|
+
const muxer = new WebSocketMuxer(
|
|
46
|
+
{
|
|
47
|
+
readyState: 1,
|
|
48
|
+
send: (message: string) => {
|
|
49
|
+
sentMessages.push(Buffer.from(message));
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{ maxChunkLength: MAX_CHUNK_LENGTH },
|
|
53
|
+
);
|
|
54
|
+
return { muxer, sentMessages };
|
|
55
|
+
};
|
package/src/edge-ws-muxer.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
|
-
import WebSocket from 'isomorphic-ws';
|
|
5
4
|
|
|
6
5
|
import { Trigger } from '@dxos/async';
|
|
7
6
|
import { log } from '@dxos/log';
|
|
@@ -25,22 +24,30 @@ const FLAG_SEGMENT_SEQ = 1;
|
|
|
25
24
|
const FLAG_SEGMENT_SEQ_TERMINATED = 1 << 1;
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
27
|
+
* https://developers.cloudflare.com/durable-objects/platform/limits/
|
|
29
28
|
*/
|
|
30
|
-
export const
|
|
29
|
+
export const CLOUDFLARE_MESSAGE_MAX_BYTES = 1000 * 1000; // 1MB
|
|
30
|
+
export const CLOUDFLARE_RPC_MAX_BYTES = 32 * 1000 * 1000; // 32MB
|
|
31
31
|
|
|
32
32
|
const MAX_CHUNK_LENGTH = 16384;
|
|
33
|
-
const MAX_BUFFERED_AMOUNT =
|
|
33
|
+
const MAX_BUFFERED_AMOUNT = CLOUDFLARE_MESSAGE_MAX_BYTES;
|
|
34
34
|
const BUFFER_FULL_BACKOFF_TIMEOUT = 100;
|
|
35
35
|
|
|
36
36
|
export class WebSocketMuxer {
|
|
37
|
-
private readonly
|
|
38
|
-
private readonly
|
|
39
|
-
private readonly
|
|
37
|
+
private readonly _inMessageAccumulator = new Map<number, Buffer[]>();
|
|
38
|
+
private readonly _outMessageChunks = new Map<number, MessageChunk[]>();
|
|
39
|
+
private readonly _outMessageChannelByService = new Map<string, number>();
|
|
40
40
|
|
|
41
41
|
private _sendTimeout: any | undefined;
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
private readonly _maxChunkLength: number;
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
private readonly _ws: WebSocketCompat,
|
|
47
|
+
config?: { maxChunkLength: number },
|
|
48
|
+
) {
|
|
49
|
+
this._maxChunkLength = config?.maxChunkLength ?? MAX_CHUNK_LENGTH;
|
|
50
|
+
}
|
|
44
51
|
|
|
45
52
|
/**
|
|
46
53
|
* Resolves when all the message chunks get enqueued for sending.
|
|
@@ -48,16 +55,20 @@ export class WebSocketMuxer {
|
|
|
48
55
|
public async send(message: Message): Promise<void> {
|
|
49
56
|
const binary = buf.toBinary(MessageSchema, message);
|
|
50
57
|
const channelId = this._resolveChannel(message);
|
|
51
|
-
if (
|
|
52
|
-
|
|
58
|
+
if (
|
|
59
|
+
(channelId == null && binary.byteLength > CLOUDFLARE_MESSAGE_MAX_BYTES) ||
|
|
60
|
+
binary.byteLength > CLOUDFLARE_RPC_MAX_BYTES
|
|
61
|
+
) {
|
|
62
|
+
log.error('Large message dropped', {
|
|
53
63
|
byteLength: binary.byteLength,
|
|
54
64
|
serviceId: message.serviceId,
|
|
55
65
|
payload: protocol.getPayloadType(message),
|
|
66
|
+
channelId,
|
|
56
67
|
});
|
|
57
68
|
return;
|
|
58
69
|
}
|
|
59
70
|
|
|
60
|
-
if (channelId == null || binary.length <
|
|
71
|
+
if (channelId == null || binary.length < this._maxChunkLength) {
|
|
61
72
|
const flags = Buffer.from([0]);
|
|
62
73
|
this._ws.send(Buffer.concat([flags, binary]));
|
|
63
74
|
return;
|
|
@@ -65,23 +76,23 @@ export class WebSocketMuxer {
|
|
|
65
76
|
|
|
66
77
|
const terminatorSentTrigger = new Trigger();
|
|
67
78
|
const messageChunks: MessageChunk[] = [];
|
|
68
|
-
for (let i = 0; i < binary.length; i +=
|
|
69
|
-
const chunk = binary.slice(i, i +
|
|
70
|
-
const isLastChunk = i +
|
|
79
|
+
for (let i = 0; i < binary.length; i += this._maxChunkLength) {
|
|
80
|
+
const chunk = binary.slice(i, i + this._maxChunkLength);
|
|
81
|
+
const isLastChunk = i + this._maxChunkLength >= binary.length;
|
|
71
82
|
if (isLastChunk) {
|
|
72
83
|
const flags = Buffer.from([FLAG_SEGMENT_SEQ | FLAG_SEGMENT_SEQ_TERMINATED, channelId]);
|
|
73
84
|
messageChunks.push({ payload: Buffer.concat([flags, chunk]), trigger: terminatorSentTrigger });
|
|
74
85
|
} else {
|
|
75
|
-
const flags = Buffer.from([FLAG_SEGMENT_SEQ]);
|
|
86
|
+
const flags = Buffer.from([FLAG_SEGMENT_SEQ, channelId]);
|
|
76
87
|
messageChunks.push({ payload: Buffer.concat([flags, chunk]) });
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
90
|
|
|
80
|
-
const queuedMessages = this.
|
|
91
|
+
const queuedMessages = this._outMessageChunks.get(channelId);
|
|
81
92
|
if (queuedMessages) {
|
|
82
93
|
queuedMessages.push(...messageChunks);
|
|
83
94
|
} else {
|
|
84
|
-
this.
|
|
95
|
+
this._outMessageChunks.set(channelId, messageChunks);
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
this._sendChunkedMessages();
|
|
@@ -95,12 +106,12 @@ export class WebSocketMuxer {
|
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
const [flags, channelId, ...payload] = data;
|
|
98
|
-
let chunkAccumulator = this.
|
|
109
|
+
let chunkAccumulator = this._inMessageAccumulator.get(channelId);
|
|
99
110
|
if (chunkAccumulator) {
|
|
100
111
|
chunkAccumulator.push(Buffer.from(payload));
|
|
101
112
|
} else {
|
|
102
113
|
chunkAccumulator = [Buffer.from(payload)];
|
|
103
|
-
this.
|
|
114
|
+
this._inMessageAccumulator.set(channelId, chunkAccumulator);
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
if ((flags & FLAG_SEGMENT_SEQ_TERMINATED) === 0) {
|
|
@@ -108,7 +119,7 @@ export class WebSocketMuxer {
|
|
|
108
119
|
}
|
|
109
120
|
|
|
110
121
|
const message = buf.fromBinary(MessageSchema, Buffer.concat(chunkAccumulator));
|
|
111
|
-
this.
|
|
122
|
+
this._inMessageAccumulator.delete(channelId);
|
|
112
123
|
return message;
|
|
113
124
|
}
|
|
114
125
|
|
|
@@ -117,12 +128,12 @@ export class WebSocketMuxer {
|
|
|
117
128
|
clearTimeout(this._sendTimeout);
|
|
118
129
|
this._sendTimeout = undefined;
|
|
119
130
|
}
|
|
120
|
-
for (const channelChunks of this.
|
|
131
|
+
for (const channelChunks of this._outMessageChunks.values()) {
|
|
121
132
|
channelChunks.forEach((chunk) => chunk.trigger?.wake());
|
|
122
133
|
}
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
134
|
+
this._outMessageChunks.clear();
|
|
135
|
+
this._inMessageAccumulator.clear();
|
|
136
|
+
this._outMessageChannelByService.clear();
|
|
126
137
|
}
|
|
127
138
|
|
|
128
139
|
private _sendChunkedMessages() {
|
|
@@ -139,10 +150,12 @@ export class WebSocketMuxer {
|
|
|
139
150
|
|
|
140
151
|
let timeout = 0;
|
|
141
152
|
const emptyChannels: number[] = [];
|
|
142
|
-
for (const [channelId, messages] of this.
|
|
143
|
-
if (this._ws.bufferedAmount
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
for (const [channelId, messages] of this._outMessageChunks.entries()) {
|
|
154
|
+
if (this._ws.bufferedAmount != null) {
|
|
155
|
+
if (this._ws.bufferedAmount + MAX_CHUNK_LENGTH > MAX_BUFFERED_AMOUNT) {
|
|
156
|
+
timeout = BUFFER_FULL_BACKOFF_TIMEOUT;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
146
159
|
}
|
|
147
160
|
|
|
148
161
|
const nextMessage = messages.shift();
|
|
@@ -154,9 +167,9 @@ export class WebSocketMuxer {
|
|
|
154
167
|
}
|
|
155
168
|
}
|
|
156
169
|
|
|
157
|
-
emptyChannels.forEach((channelId) => this.
|
|
170
|
+
emptyChannels.forEach((channelId) => this._outMessageChunks.delete(channelId));
|
|
158
171
|
|
|
159
|
-
if (this.
|
|
172
|
+
if (this._outMessageChunks.size > 0) {
|
|
160
173
|
this._sendTimeout = setTimeout(send, timeout);
|
|
161
174
|
} else {
|
|
162
175
|
this._sendTimeout = undefined;
|
|
@@ -169,15 +182,24 @@ export class WebSocketMuxer {
|
|
|
169
182
|
if (!message.serviceId) {
|
|
170
183
|
return undefined;
|
|
171
184
|
}
|
|
172
|
-
let id = this.
|
|
185
|
+
let id = this._outMessageChannelByService.get(message.serviceId);
|
|
173
186
|
if (!id) {
|
|
174
|
-
id = this.
|
|
175
|
-
this.
|
|
187
|
+
id = this._outMessageChannelByService.size + 1;
|
|
188
|
+
this._outMessageChannelByService.set(message.serviceId, id);
|
|
176
189
|
}
|
|
177
190
|
return id;
|
|
178
191
|
}
|
|
179
192
|
}
|
|
180
193
|
|
|
194
|
+
type WebSocketCompat = {
|
|
195
|
+
readonly readyState: number;
|
|
196
|
+
/**
|
|
197
|
+
* Not available in workerd.
|
|
198
|
+
*/
|
|
199
|
+
bufferedAmount?: number;
|
|
200
|
+
send(message: (ArrayBuffer | ArrayBufferView) | string): void;
|
|
201
|
+
};
|
|
202
|
+
|
|
181
203
|
type MessageChunk = {
|
|
182
204
|
payload: Buffer;
|
|
183
205
|
/**
|
|
@@ -185,3 +207,11 @@ type MessageChunk = {
|
|
|
185
207
|
*/
|
|
186
208
|
trigger?: Trigger;
|
|
187
209
|
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* To avoid using isomorphic-ws on edge.
|
|
213
|
+
*/
|
|
214
|
+
enum WebSocket {
|
|
215
|
+
CLOSING = 2,
|
|
216
|
+
CLOSED = 3,
|
|
217
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,11 +6,11 @@ import WebSocket from 'isomorphic-ws';
|
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
+
import { EdgeWebsocketProtocol } from '@dxos/protocols';
|
|
9
10
|
import { buf } from '@dxos/protocols/buf';
|
|
10
11
|
import { MessageSchema, TextMessageSchema, type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
11
12
|
|
|
12
13
|
import { protocol } from '../defs';
|
|
13
|
-
import { EDGE_WEBSOCKET_PROTOCOL_V1 } from '../edge-ws-connection';
|
|
14
14
|
import { WebSocketMuxer } from '../edge-ws-muxer';
|
|
15
15
|
import { toUint8Array } from '../protocol';
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ export const createTestEdgeWsServer = async (port = DEFAULT_PORT, params?: TestE
|
|
|
26
26
|
const wsServer = new WebSocket.Server({
|
|
27
27
|
port,
|
|
28
28
|
verifyClient: createConnectionDelayHandler(params),
|
|
29
|
-
handleProtocols: () => [
|
|
29
|
+
handleProtocols: () => [EdgeWebsocketProtocol.V1],
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
let connection: { ws: WebSocket; muxer: WebSocketMuxer } | undefined;
|