@dxos/messaging 0.8.0 → 0.8.1-main.a06ad20
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-ANUNQFFZ.mjs → chunk-ROBIGCQ6.mjs} +99 -78
- package/dist/lib/browser/chunk-ROBIGCQ6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-JAKUUZJC.cjs → chunk-P6CBW4WG.cjs} +98 -80
- package/dist/lib/node/chunk-P6CBW4WG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +9 -9
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +4 -4
- package/dist/lib/node-esm/{chunk-LTIOKLM3.mjs → chunk-T7M7M5VK.mjs} +99 -78
- package/dist/lib/node-esm/chunk-T7M7M5VK.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +1 -1
- package/dist/types/src/signal-client/signal-client.d.ts +5 -9
- package/dist/types/src/signal-client/signal-client.d.ts.map +1 -1
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts +7 -1
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts +3 -0
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts +5 -9
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-methods.d.ts +8 -12
- package/dist/types/src/signal-methods.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/signal-client/signal-client.ts +8 -2
- package/src/signal-manager/edge-signal-manager.ts +26 -3
- package/src/signal-manager/memory-signal-manager.ts +6 -0
- package/src/signal-manager/websocket-signal-manager.ts +8 -2
- package/src/signal-methods.ts +15 -6
- package/dist/lib/browser/chunk-ANUNQFFZ.mjs.map +0 -7
- package/dist/lib/node/chunk-JAKUUZJC.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-LTIOKLM3.mjs.map +0 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Event } from '@dxos/async';
|
|
2
2
|
import { Resource } from '@dxos/context';
|
|
3
|
-
import { PublicKey } from '@dxos/keys';
|
|
4
3
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
4
|
+
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
5
|
+
import { type JoinRequest, type LeaveRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
5
6
|
import { type SignalManager } from './signal-manager';
|
|
6
7
|
import { type PeerInfo, type Message, type SignalStatus, type SwarmEvent } from '../signal-methods';
|
|
7
8
|
/**
|
|
@@ -28,14 +29,9 @@ export declare class WebsocketSignalManager extends Resource implements SignalMa
|
|
|
28
29
|
protected _close(): Promise<void>;
|
|
29
30
|
restartServer(serverName: string): Promise<void>;
|
|
30
31
|
getStatus(): SignalStatus[];
|
|
31
|
-
join({ topic, peer }:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}): Promise<void>;
|
|
35
|
-
leave({ topic, peer }: {
|
|
36
|
-
topic: PublicKey;
|
|
37
|
-
peer: PeerInfo;
|
|
38
|
-
}): Promise<void>;
|
|
32
|
+
join({ topic, peer }: JoinRequest): Promise<void>;
|
|
33
|
+
leave({ topic, peer }: LeaveRequest): Promise<void>;
|
|
34
|
+
query({ topic }: QueryRequest): Promise<SwarmResponse>;
|
|
39
35
|
sendMessage({ author, recipient, payload }: Message): Promise<void>;
|
|
40
36
|
checkServerFailure(serverName: string, index: number): Promise<void>;
|
|
41
37
|
private _clearServerFailedFlag;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-signal-manager.d.ts","sourceRoot":"","sources":["../../../../src/signal-manager/websocket-signal-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAuB,MAAM,aAAa,CAAC;AACzD,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"websocket-signal-manager.d.ts","sourceRoot":"","sources":["../../../../src/signal-manager/websocket-signal-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAuB,MAAM,aAAa,CAAC;AACzD,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAKzD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAGhH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,OAAO,EAGZ,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAK3B;;;;GAIG;AACH,qBAAa,sBAAuB,SAAQ,QAAS,YAAW,aAAa;IAkBzE,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAlBhC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IACnE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;IAEhE;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAa;IAEpD,QAAQ,CAAC,YAAY,sBAA6B;IAClD,QAAQ,CAAC,aAAa,wBAA+B;IACrD,QAAQ,CAAC,UAAU,oBAA2B;IAE9C,QAAQ,CAAC,SAAS,iBAAwB;IAE1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA8B;gBAGvC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EACjC,YAAY,CAAC,GAAE,MAAM,GAAG,aAAA;cAsBlB,KAAK;cASL,MAAM;IAIzB,aAAa,CAAC,UAAU,EAAE,MAAM;IAYtC,SAAS,IAAI,YAAY,EAAE;IAKrB,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,WAAW;IAOjC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,YAAY;IAMnC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAItD,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBnE,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAiB1D,OAAO,CAAC,sBAAsB;IAQxB,iBAAiB,CAAC,IAAI,EAAE,QAAQ;IAOhC,mBAAmB,CAAC,IAAI,EAAE,QAAQ;YAO1B,cAAc;CAO7B"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { type Event } from '@dxos/async';
|
|
2
2
|
import { type Lifecycle } from '@dxos/context';
|
|
3
|
-
import { type
|
|
4
|
-
import { type
|
|
5
|
-
import { type Peer } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
6
|
-
import { type Message, type SwarmEvent } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
3
|
+
import { type SwarmResponse, type Peer } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
4
|
+
import { type LeaveRequest, type Message, type SwarmEvent, type JoinRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
7
5
|
import { type SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
8
6
|
export type { Message, SwarmEvent };
|
|
9
7
|
export type PeerInfo = Peer;
|
|
@@ -37,17 +35,15 @@ export interface SignalMethods {
|
|
|
37
35
|
/**
|
|
38
36
|
* Join topic on signal network, to be discoverable by other peers.
|
|
39
37
|
*/
|
|
40
|
-
join: (params:
|
|
41
|
-
topic: PublicKey;
|
|
42
|
-
peer: PeerInfo;
|
|
43
|
-
}) => Promise<void>;
|
|
38
|
+
join: (params: JoinRequest) => Promise<void>;
|
|
44
39
|
/**
|
|
45
40
|
* Leave topic on signal network, to stop being discoverable by other peers.
|
|
46
41
|
*/
|
|
47
|
-
leave: (params:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
leave: (params: LeaveRequest) => Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Query peers in the swarm without joining it.
|
|
45
|
+
*/
|
|
46
|
+
query: (params: QueryRequest) => Promise<SwarmResponse>;
|
|
51
47
|
/**
|
|
52
48
|
* Send message to peer.
|
|
53
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal-methods.d.ts","sourceRoot":"","sources":["../../../src/signal-methods.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"signal-methods.d.ts","sourceRoot":"","sources":["../../../src/signal-methods.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,IAAI,EAAE,MAAM,2CAA2C,CAAC;AAC1F,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAE1E,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACpC,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC;AAC5B,eAAO,MAAM,YAAY,gBAAiB,QAAQ,WAAY,CAAC;AAE/D,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,IAAI,CAAC;IACxB,eAAe,EAAE,IAAI,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAE9B;;OAEG;IACH,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAE1B;;OAEG;IACH,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAElC;;OAEG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;OAEG;IACH,KAAK,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;OAEG;IACH,KAAK,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAExD;;OAEG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD;;;OAGG;IAEH,iBAAiB,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD;;;OAGG;IACH,mBAAmB,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,aAAa,EAAE,QAAQ,CAAC,SAAS,CAAC;IAC7E,SAAS,IAAI,YAAY,CAAC;CAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/messaging",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-main.a06ad20",
|
|
4
4
|
"description": "Messaging",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -36,23 +36,23 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"isomorphic-ws": "^5.0.0",
|
|
38
38
|
"ws": "^8.14.2",
|
|
39
|
-
"@dxos/async": "0.8.
|
|
40
|
-
"@dxos/codec-protobuf": "0.8.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/node-std": "0.8.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/util": "0.8.
|
|
39
|
+
"@dxos/async": "0.8.1-main.a06ad20",
|
|
40
|
+
"@dxos/codec-protobuf": "0.8.1-main.a06ad20",
|
|
41
|
+
"@dxos/invariant": "0.8.1-main.a06ad20",
|
|
42
|
+
"@dxos/keys": "0.8.1-main.a06ad20",
|
|
43
|
+
"@dxos/edge-client": "0.8.1-main.a06ad20",
|
|
44
|
+
"@dxos/log": "0.8.1-main.a06ad20",
|
|
45
|
+
"@dxos/protocols": "0.8.1-main.a06ad20",
|
|
46
|
+
"@dxos/node-std": "0.8.1-main.a06ad20",
|
|
47
|
+
"@dxos/context": "0.8.1-main.a06ad20",
|
|
48
|
+
"@dxos/rpc": "0.8.1-main.a06ad20",
|
|
49
|
+
"@dxos/tracing": "0.8.1-main.a06ad20",
|
|
50
|
+
"@dxos/util": "0.8.1-main.a06ad20"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@dxos/signal": "0.8.
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
53
|
+
"@dxos/signal": "0.8.1-main.a06ad20",
|
|
54
|
+
"@dxos/test-utils": "0.8.1-main.a06ad20",
|
|
55
|
+
"@dxos/keyring": "0.8.1-main.a06ad20"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
@@ -8,6 +8,8 @@ import { invariant } from '@dxos/invariant';
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { trace } from '@dxos/protocols';
|
|
11
|
+
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
12
|
+
import { type QueryRequest, type JoinRequest, type LeaveRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
11
13
|
import { SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
12
14
|
|
|
13
15
|
import { SignalClientMonitor } from './signal-client-monitor';
|
|
@@ -170,19 +172,23 @@ export class SignalClient extends Resource implements SignalClientMethods {
|
|
|
170
172
|
};
|
|
171
173
|
}
|
|
172
174
|
|
|
173
|
-
async join(args:
|
|
175
|
+
async join(args: JoinRequest): Promise<void> {
|
|
174
176
|
log('joining', { topic: args.topic, peerId: args.peer.peerKey });
|
|
175
177
|
this._monitor.recordJoin();
|
|
176
178
|
this.localState.join({ topic: args.topic, peerId: PublicKey.from(args.peer.peerKey) });
|
|
177
179
|
this._reconcileTask?.schedule();
|
|
178
180
|
}
|
|
179
181
|
|
|
180
|
-
async leave(args:
|
|
182
|
+
async leave(args: LeaveRequest): Promise<void> {
|
|
181
183
|
log('leaving', { topic: args.topic, peerId: args.peer.peerKey });
|
|
182
184
|
this._monitor.recordLeave();
|
|
183
185
|
this.localState.leave({ topic: args.topic, peerId: PublicKey.from(args.peer.peerKey) });
|
|
184
186
|
}
|
|
185
187
|
|
|
188
|
+
async query(params: QueryRequest): Promise<SwarmResponse> {
|
|
189
|
+
throw new Error('Not implemented');
|
|
190
|
+
}
|
|
191
|
+
|
|
186
192
|
async sendMessage(msg: Message): Promise<void> {
|
|
187
193
|
return this._monitor.recordMessageSending(msg, async () => {
|
|
188
194
|
await this._clientReady.wait();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Event, scheduleMicroTask } from '@dxos/async';
|
|
6
|
-
import { Resource } from '@dxos/context';
|
|
6
|
+
import { cancelWithContext, Resource } from '@dxos/context';
|
|
7
7
|
import { type EdgeConnection, protocol } from '@dxos/edge-client';
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -16,14 +16,17 @@ import {
|
|
|
16
16
|
SwarmResponseSchema,
|
|
17
17
|
type Message as EdgeMessage,
|
|
18
18
|
type PeerSchema,
|
|
19
|
-
type SwarmResponse,
|
|
20
19
|
} from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
20
|
+
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
21
21
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
22
22
|
|
|
23
23
|
import { type SignalManager } from './signal-manager';
|
|
24
24
|
import { type PeerInfo, type Message, type SwarmEvent, PeerInfoHash } from '../signal-methods';
|
|
25
25
|
|
|
26
26
|
export class EdgeSignalManager extends Resource implements SignalManager {
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated
|
|
29
|
+
*/
|
|
27
30
|
public swarmEvent = new Event<SwarmEvent>();
|
|
28
31
|
public swarmState = new Event<SwarmResponse>();
|
|
29
32
|
public onMessage = new Event<Message>();
|
|
@@ -92,6 +95,26 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
92
95
|
);
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
async query({ topic }: { topic: PublicKey }): Promise<SwarmResponse> {
|
|
99
|
+
const response = cancelWithContext(
|
|
100
|
+
this._ctx,
|
|
101
|
+
this.swarmState.waitFor((state) => state.swarmKey === topic.toHex()),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
await this._edgeConnection.send(
|
|
105
|
+
protocol.createMessage(SwarmRequestSchema, {
|
|
106
|
+
serviceId: EdgeService.SWARM,
|
|
107
|
+
source: createMessageSource(topic, {
|
|
108
|
+
peerKey: this._edgeConnection.peerKey,
|
|
109
|
+
identityKey: this._edgeConnection.identityKey,
|
|
110
|
+
}),
|
|
111
|
+
payload: { action: SwarmRequestAction.INFO, swarmKeys: [topic.toHex()] },
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return response;
|
|
116
|
+
}
|
|
117
|
+
|
|
95
118
|
async sendMessage(message: Message): Promise<void> {
|
|
96
119
|
if (!this._matchSelfPeerInfo(message.author)) {
|
|
97
120
|
// NOTE: Could only join swarm with the same peer info as the edge connection.
|
|
@@ -137,9 +160,9 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
137
160
|
this.swarmState.emit(payload);
|
|
138
161
|
const topic = PublicKey.from(payload.swarmKey);
|
|
139
162
|
if (!this._swarmPeers.has(topic)) {
|
|
140
|
-
log.warn('Received message from wrong topic', { topic });
|
|
141
163
|
return;
|
|
142
164
|
}
|
|
165
|
+
|
|
143
166
|
const { joinedPeers: oldPeers } = this._swarmPeers.get(topic)!;
|
|
144
167
|
const timestamp = message.timestamp ? new Date(Date.parse(message.timestamp)) : new Date();
|
|
145
168
|
const newPeers = new ComplexSet<PeerInfo>(PeerInfoHash, payload.peers);
|
|
@@ -9,6 +9,8 @@ import { invariant } from '@dxos/invariant';
|
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { schema } from '@dxos/protocols/proto';
|
|
12
|
+
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
13
|
+
import { type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
12
14
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
13
15
|
|
|
14
16
|
import { type SignalManager } from './signal-manager';
|
|
@@ -138,6 +140,10 @@ export class MemorySignalManager implements SignalManager {
|
|
|
138
140
|
this._context.swarmEvent.emit(swarmEvent);
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
async query(request: QueryRequest): Promise<SwarmResponse> {
|
|
144
|
+
throw new Error('Not implemented');
|
|
145
|
+
}
|
|
146
|
+
|
|
141
147
|
async sendMessage({ author, recipient, payload }: { author: PeerInfo; recipient: PeerInfo; payload: Any }) {
|
|
142
148
|
log('send message', { author, recipient, ...dec(payload) });
|
|
143
149
|
|
|
@@ -9,6 +9,8 @@ import { PublicKey } from '@dxos/keys';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { RateLimitExceededError, TimeoutError, trace } from '@dxos/protocols';
|
|
11
11
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
12
|
+
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
13
|
+
import { type JoinRequest, type LeaveRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
12
14
|
import { BitField, safeAwaitAll } from '@dxos/util';
|
|
13
15
|
|
|
14
16
|
import { type SignalManager } from './signal-manager';
|
|
@@ -102,19 +104,23 @@ export class WebsocketSignalManager extends Resource implements SignalManager {
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
@synchronized
|
|
105
|
-
async join({ topic, peer }:
|
|
107
|
+
async join({ topic, peer }: JoinRequest) {
|
|
106
108
|
log('join', { topic, peer });
|
|
107
109
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
|
108
110
|
await this._forEachServer((server) => server.join({ topic, peer }));
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
@synchronized
|
|
112
|
-
async leave({ topic, peer }:
|
|
114
|
+
async leave({ topic, peer }: LeaveRequest) {
|
|
113
115
|
log('leaving', { topic, peer });
|
|
114
116
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
|
115
117
|
await this._forEachServer((server) => server.leave({ topic, peer }));
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
async query({ topic }: QueryRequest): Promise<SwarmResponse> {
|
|
121
|
+
throw new Error('Not implemented');
|
|
122
|
+
}
|
|
123
|
+
|
|
118
124
|
async sendMessage({ author, recipient, payload }: Message): Promise<void> {
|
|
119
125
|
log('signal', { recipient });
|
|
120
126
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
package/src/signal-methods.ts
CHANGED
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
6
|
import { type Lifecycle } from '@dxos/context';
|
|
7
|
-
import { type
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { type SwarmResponse, type Peer } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
8
|
+
import {
|
|
9
|
+
type LeaveRequest,
|
|
10
|
+
type Message,
|
|
11
|
+
type SwarmEvent,
|
|
12
|
+
type JoinRequest,
|
|
13
|
+
type QueryRequest,
|
|
14
|
+
} from '@dxos/protocols/proto/dxos/edge/signal';
|
|
11
15
|
import { type SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
12
16
|
|
|
13
17
|
export type { Message, SwarmEvent };
|
|
@@ -47,12 +51,17 @@ export interface SignalMethods {
|
|
|
47
51
|
/**
|
|
48
52
|
* Join topic on signal network, to be discoverable by other peers.
|
|
49
53
|
*/
|
|
50
|
-
join: (params:
|
|
54
|
+
join: (params: JoinRequest) => Promise<void>;
|
|
51
55
|
|
|
52
56
|
/**
|
|
53
57
|
* Leave topic on signal network, to stop being discoverable by other peers.
|
|
54
58
|
*/
|
|
55
|
-
leave: (params:
|
|
59
|
+
leave: (params: LeaveRequest) => Promise<void>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Query peers in the swarm without joining it.
|
|
63
|
+
*/
|
|
64
|
+
query: (params: QueryRequest) => Promise<SwarmResponse>;
|
|
56
65
|
|
|
57
66
|
/**
|
|
58
67
|
* Send message to peer.
|