@dxos/messaging 0.7.4 → 0.7.5-labs.071a3e2
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-U5OG65N2.mjs → chunk-KWCKO7OY.mjs} +91 -84
- package/dist/lib/browser/chunk-KWCKO7OY.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-ZWQVINAC.cjs → chunk-ISUSZ44G.cjs} +92 -85
- package/dist/lib/node/chunk-ISUSZ44G.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-NCL2P63O.mjs → chunk-6MNUCAS7.mjs} +91 -84
- package/dist/lib/node-esm/chunk-6MNUCAS7.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 +2 -0
- package/dist/types/src/signal-client/signal-client.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-rpc-client.d.ts +5 -0
- package/dist/types/src/signal-client/signal-rpc-client.d.ts.map +1 -1
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts +3 -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 +2 -2
- 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 +2 -0
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-methods.d.ts +15 -26
- package/dist/types/src/signal-methods.d.ts.map +1 -1
- package/dist/types/src/testing/test-peer.d.ts +2 -2
- package/dist/types/src/testing/utils.d.ts +2 -2
- package/dist/types/src/testing/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +16 -16
- package/src/signal-client/signal-client.ts +2 -0
- package/src/signal-client/signal-local-state.ts +1 -1
- package/src/signal-client/signal-rpc-client.ts +5 -0
- package/src/signal-manager/edge-signal-manager.ts +28 -15
- package/src/signal-manager/websocket-signal-manager.ts +2 -0
- package/src/signal-methods.ts +16 -30
- package/dist/lib/browser/chunk-U5OG65N2.mjs.map +0 -7
- package/dist/lib/node/chunk-ZWQVINAC.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-NCL2P63O.mjs.map +0 -7
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { type Event } from '@dxos/async';
|
|
2
2
|
import { type Lifecycle } from '@dxos/context';
|
|
3
3
|
import { type PublicKey } from '@dxos/keys';
|
|
4
|
-
import { type
|
|
4
|
+
import { type SwarmResponse } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
5
|
+
import { type Peer } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
6
|
+
import { type Message, type SwarmEvent } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
5
7
|
import { type SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
6
|
-
export type
|
|
8
|
+
export type { Message, SwarmEvent };
|
|
9
|
+
export type PeerInfo = Peer;
|
|
7
10
|
export declare const PeerInfoHash: ({ peerKey }: PeerInfo) => string;
|
|
8
|
-
export interface Message {
|
|
9
|
-
author: PeerInfo;
|
|
10
|
-
recipient: PeerInfo;
|
|
11
|
-
payload: {
|
|
12
|
-
type_url: string;
|
|
13
|
-
value: Uint8Array;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
11
|
export type SignalStatus = {
|
|
17
12
|
host: string;
|
|
18
13
|
state: SignalState;
|
|
@@ -21,34 +16,24 @@ export type SignalStatus = {
|
|
|
21
16
|
connectionStarted: Date;
|
|
22
17
|
lastStateChange: Date;
|
|
23
18
|
};
|
|
24
|
-
export type SwarmEvent = {
|
|
25
|
-
topic: PublicKey;
|
|
26
|
-
/**
|
|
27
|
-
* The peer was announced as available on the swarm.
|
|
28
|
-
*/
|
|
29
|
-
peerAvailable?: {
|
|
30
|
-
peer: PeerInfo;
|
|
31
|
-
since: Date;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* The peer left, or their announcement timed out.
|
|
35
|
-
*/
|
|
36
|
-
peerLeft?: {
|
|
37
|
-
peer: PeerInfo;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
19
|
/**
|
|
41
20
|
* Message routing interface.
|
|
42
21
|
*/
|
|
43
22
|
export interface SignalMethods {
|
|
44
23
|
/**
|
|
45
24
|
* Emits when other peers join or leave the swarm.
|
|
25
|
+
* @deprecated
|
|
26
|
+
* TODO(mykola): Use swarmState in network-manager instead.
|
|
46
27
|
*/
|
|
47
28
|
swarmEvent: Event<SwarmEvent>;
|
|
48
29
|
/**
|
|
49
30
|
* Emits when a message is received.
|
|
50
31
|
*/
|
|
51
32
|
onMessage: Event<Message>;
|
|
33
|
+
/**
|
|
34
|
+
* Emits when the swarm state changes.
|
|
35
|
+
*/
|
|
36
|
+
swarmState?: Event<SwarmResponse>;
|
|
52
37
|
/**
|
|
53
38
|
* Join topic on signal network, to be discoverable by other peers.
|
|
54
39
|
*/
|
|
@@ -69,15 +54,19 @@ export interface SignalMethods {
|
|
|
69
54
|
sendMessage: (message: Message) => Promise<void>;
|
|
70
55
|
/**
|
|
71
56
|
* Start receiving messages from peer.
|
|
57
|
+
* @deprecated
|
|
72
58
|
*/
|
|
73
59
|
subscribeMessages: (peer: PeerInfo) => Promise<void>;
|
|
74
60
|
/**
|
|
75
61
|
* Stop receiving messages from peer.
|
|
62
|
+
* @deprecated
|
|
76
63
|
*/
|
|
77
64
|
unsubscribeMessages: (peer: PeerInfo) => Promise<void>;
|
|
78
65
|
}
|
|
79
66
|
/**
|
|
80
67
|
* Signaling client.
|
|
68
|
+
* TODO(mykola): Delete.
|
|
69
|
+
* @deprecated
|
|
81
70
|
*/
|
|
82
71
|
export interface SignalClientMethods extends SignalMethods, Required<Lifecycle> {
|
|
83
72
|
getStatus(): SignalStatus;
|
|
@@ -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,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,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,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACvF,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;QAAE,KAAK,EAAE,SAAS,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;OAEG;IACH,KAAK,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,SAAS,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvE;;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"}
|
|
@@ -14,8 +14,8 @@ export declare class TestPeer extends Resource {
|
|
|
14
14
|
constructor(testBuilder: TestBuilder);
|
|
15
15
|
get peerInfo(): PeerInfo;
|
|
16
16
|
waitTillReceive(message: Message): Promise<Message>;
|
|
17
|
-
waitForPeerAvailable(topic: PublicKey, peer: PeerInfo): Promise<import("
|
|
18
|
-
waitForPeerLeft(topic: PublicKey, peer: PeerInfo): Promise<import("
|
|
17
|
+
waitForPeerAvailable(topic: PublicKey, peer: PeerInfo): Promise<import("packages/core/protocols/dist/esm/src/proto/gen/dxos/edge/signal").SwarmEvent>;
|
|
18
|
+
waitForPeerLeft(topic: PublicKey, peer: PeerInfo): Promise<import("packages/core/protocols/dist/esm/src/proto/gen/dxos/edge/signal").SwarmEvent>;
|
|
19
19
|
protected _open(): Promise<void>;
|
|
20
20
|
protected _close(): Promise<void>;
|
|
21
21
|
}
|
|
@@ -2,8 +2,8 @@ import { type Event } from '@dxos/async';
|
|
|
2
2
|
import { type Any } from '@dxos/codec-protobuf';
|
|
3
3
|
import { PublicKey } from '@dxos/keys';
|
|
4
4
|
import { type SignalMethods, type Message, type PeerInfo } from '../signal-methods';
|
|
5
|
-
export declare const expectPeerAvailable: (client: SignalMethods, expectedTopic: PublicKey, peer: PeerInfo) => Promise<import("
|
|
6
|
-
export declare const expectPeerLeft: (client: SignalMethods, expectedTopic: PublicKey, peer: PeerInfo) => Promise<import("
|
|
5
|
+
export declare const expectPeerAvailable: (client: SignalMethods, expectedTopic: PublicKey, peer: PeerInfo) => Promise<import("packages/core/protocols/dist/esm/src/proto/gen/dxos/edge/signal").SwarmEvent>;
|
|
6
|
+
export declare const expectPeerLeft: (client: SignalMethods, expectedTopic: PublicKey, peer: PeerInfo) => Promise<import("packages/core/protocols/dist/esm/src/proto/gen/dxos/edge/signal").SwarmEvent>;
|
|
7
7
|
export declare const expectReceivedMessage: (event: Event<Message>, expectedMessage: Message) => Promise<Message>;
|
|
8
8
|
export declare const createMessage: (author: PeerInfo, recipient: PeerInfo, payload?: Any) => Message;
|
|
9
9
|
export declare const messageEqual: (msg1: Message, msg2: Message) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/testing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEpF,eAAO,MAAM,mBAAmB,WAAY,aAAa,iBAAiB,SAAS,QAAQ,QAAQ,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/testing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEpF,eAAO,MAAM,mBAAmB,WAAY,aAAa,iBAAiB,SAAS,QAAQ,QAAQ,kGAOhG,CAAC;AAEJ,eAAO,MAAM,cAAc,WAAY,aAAa,iBAAiB,SAAS,QAAQ,QAAQ,kGAM3F,CAAC;AAEJ,eAAO,MAAM,qBAAqB,UAAW,KAAK,CAAC,OAAO,CAAC,mBAAmB,OAAO,qBAUpF,CAAC;AAEF,eAAO,MAAM,aAAa,WAAY,QAAQ,aAAa,QAAQ,YAAW,GAAG,KAAe,OAI9F,CAAC;AAEH,eAAO,MAAM,YAAY,SAAU,OAAO,QAAQ,OAAO,YAGM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/messaging",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5-labs.071a3e2",
|
|
4
4
|
"description": "Messaging",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -35,23 +35,23 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"isomorphic-ws": "^5.0.0",
|
|
37
37
|
"ws": "^8.14.2",
|
|
38
|
-
"@dxos/async": "0.7.
|
|
39
|
-
"@dxos/codec-protobuf": "0.7.
|
|
40
|
-
"@dxos/edge-client": "0.7.
|
|
41
|
-
"@dxos/invariant": "0.7.
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/log": "0.7.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/rpc": "0.7.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/tracing": "0.7.
|
|
49
|
-
"@dxos/
|
|
38
|
+
"@dxos/async": "0.7.5-labs.071a3e2",
|
|
39
|
+
"@dxos/codec-protobuf": "0.7.5-labs.071a3e2",
|
|
40
|
+
"@dxos/edge-client": "0.7.5-labs.071a3e2",
|
|
41
|
+
"@dxos/invariant": "0.7.5-labs.071a3e2",
|
|
42
|
+
"@dxos/keys": "0.7.5-labs.071a3e2",
|
|
43
|
+
"@dxos/context": "0.7.5-labs.071a3e2",
|
|
44
|
+
"@dxos/log": "0.7.5-labs.071a3e2",
|
|
45
|
+
"@dxos/node-std": "0.7.5-labs.071a3e2",
|
|
46
|
+
"@dxos/rpc": "0.7.5-labs.071a3e2",
|
|
47
|
+
"@dxos/util": "0.7.5-labs.071a3e2",
|
|
48
|
+
"@dxos/tracing": "0.7.5-labs.071a3e2",
|
|
49
|
+
"@dxos/protocols": "0.7.5-labs.071a3e2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@dxos/keyring": "0.7.
|
|
53
|
-
"@dxos/signal": "0.7.
|
|
54
|
-
"@dxos/test-utils": "0.7.
|
|
52
|
+
"@dxos/keyring": "0.7.5-labs.071a3e2",
|
|
53
|
+
"@dxos/signal": "0.7.5-labs.071a3e2",
|
|
54
|
+
"@dxos/test-utils": "0.7.5-labs.071a3e2"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
@@ -31,6 +31,8 @@ const RECONCILE_INTERVAL = 5_000;
|
|
|
31
31
|
* Establishes a websocket connection to signal server and provides RPC methods.
|
|
32
32
|
* Subscription state updates are executed immediately against the local state which
|
|
33
33
|
* is reconciled periodically.
|
|
34
|
+
* TODO(mykola): Delete.
|
|
35
|
+
* @deprecated
|
|
34
36
|
*/
|
|
35
37
|
// TODO(burdon): Rename impl.
|
|
36
38
|
export class SignalClient extends Resource implements SignalClientMethods {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { asyncTimeout, Event } from '@dxos/async';
|
|
6
|
-
import type { Stream } from '@dxos/codec-protobuf';
|
|
6
|
+
import type { Stream } from '@dxos/codec-protobuf/stream';
|
|
7
7
|
import { cancelWithContext, type Context } from '@dxos/context';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
@@ -41,6 +41,11 @@ export type SignalRPCClientParams = {
|
|
|
41
41
|
callbacks?: SignalCallbacks;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Signal RPC client.
|
|
46
|
+
* TODO(mykola): Delete.
|
|
47
|
+
* @deprecated
|
|
48
|
+
*/
|
|
44
49
|
export class SignalRPCClient {
|
|
45
50
|
private readonly _socket: WebSocket;
|
|
46
51
|
private readonly _rpc: ProtoRpcPeer<Services>;
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
SwarmResponseSchema,
|
|
17
17
|
type Message as EdgeMessage,
|
|
18
18
|
type PeerSchema,
|
|
19
|
+
type SwarmResponse,
|
|
19
20
|
} from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
20
21
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
21
22
|
|
|
@@ -24,13 +25,18 @@ import { type PeerInfo, type Message, type SwarmEvent, PeerInfoHash } from '../s
|
|
|
24
25
|
|
|
25
26
|
export class EdgeSignalManager extends Resource implements SignalManager {
|
|
26
27
|
public swarmEvent = new Event<SwarmEvent>();
|
|
28
|
+
public swarmState = new Event<SwarmResponse>();
|
|
27
29
|
public onMessage = new Event<Message>();
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
|
-
*
|
|
32
|
+
* Swarm key -> { peer: <own peer info>, joinedPeers: <state of swarm> }.
|
|
31
33
|
*/
|
|
32
|
-
// TODO(mykola): This class should not contain swarm state. Temporary before network-manager API changes to accept list of peers.
|
|
33
|
-
private readonly _swarmPeers = new ComplexMap<
|
|
34
|
+
// TODO(mykola): This class should not contain swarm state joinedPeers. Temporary before network-manager API changes to accept list of peers.
|
|
35
|
+
private readonly _swarmPeers = new ComplexMap<
|
|
36
|
+
PublicKey,
|
|
37
|
+
{ lastState?: Uint8Array; joinedPeers: ComplexSet<PeerInfo> }
|
|
38
|
+
>(PublicKey.hash);
|
|
39
|
+
|
|
34
40
|
private readonly _edgeConnection: EdgeConnection;
|
|
35
41
|
|
|
36
42
|
constructor({ edgeConnection }: { edgeConnection: EdgeConnection }) {
|
|
@@ -60,12 +66,15 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
60
66
|
identityKey: this._edgeConnection.identityKey,
|
|
61
67
|
},
|
|
62
68
|
});
|
|
69
|
+
|
|
70
|
+
peer.identityKey = this._edgeConnection.identityKey;
|
|
71
|
+
peer.peerKey = this._edgeConnection.peerKey;
|
|
63
72
|
}
|
|
64
73
|
|
|
65
|
-
this._swarmPeers.set(topic, new ComplexSet<PeerInfo>(PeerInfoHash));
|
|
74
|
+
this._swarmPeers.set(topic, { lastState: peer.state, joinedPeers: new ComplexSet<PeerInfo>(PeerInfoHash) });
|
|
66
75
|
await this._edgeConnection.send(
|
|
67
76
|
protocol.createMessage(SwarmRequestSchema, {
|
|
68
|
-
serviceId: EdgeService.
|
|
77
|
+
serviceId: EdgeService.SWARM,
|
|
69
78
|
source: createMessageSource(topic, peer),
|
|
70
79
|
payload: { action: SwarmRequestAction.JOIN, swarmKeys: [topic.toHex()] },
|
|
71
80
|
}),
|
|
@@ -76,7 +85,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
76
85
|
this._swarmPeers.delete(topic);
|
|
77
86
|
await this._edgeConnection.send(
|
|
78
87
|
protocol.createMessage(SwarmRequestSchema, {
|
|
79
|
-
serviceId: EdgeService.
|
|
88
|
+
serviceId: EdgeService.SWARM,
|
|
80
89
|
source: createMessageSource(topic, peer),
|
|
81
90
|
payload: { action: SwarmRequestAction.LEAVE, swarmKeys: [topic.toHex()] },
|
|
82
91
|
}),
|
|
@@ -94,7 +103,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
94
103
|
|
|
95
104
|
await this._edgeConnection.send(
|
|
96
105
|
protocol.createMessage(bufWkt.AnySchema, {
|
|
97
|
-
serviceId: EdgeService.
|
|
106
|
+
serviceId: EdgeService.SIGNAL,
|
|
98
107
|
source: message.author,
|
|
99
108
|
target: [message.recipient],
|
|
100
109
|
payload: { typeUrl: message.payload.type_url, value: message.payload.value },
|
|
@@ -112,11 +121,11 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
112
121
|
|
|
113
122
|
private _onMessage(message: EdgeMessage) {
|
|
114
123
|
switch (message.serviceId) {
|
|
115
|
-
case EdgeService.
|
|
124
|
+
case EdgeService.SWARM: {
|
|
116
125
|
this._processSwarmResponse(message);
|
|
117
126
|
break;
|
|
118
127
|
}
|
|
119
|
-
case EdgeService.
|
|
128
|
+
case EdgeService.SIGNAL: {
|
|
120
129
|
this._processMessage(message);
|
|
121
130
|
}
|
|
122
131
|
}
|
|
@@ -125,12 +134,13 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
125
134
|
private _processSwarmResponse(message: EdgeMessage) {
|
|
126
135
|
invariant(protocol.getPayloadType(message) === SwarmResponseSchema.typeName, 'Wrong payload type');
|
|
127
136
|
const payload = protocol.getPayload(message, SwarmResponseSchema);
|
|
137
|
+
this.swarmState.emit(payload);
|
|
128
138
|
const topic = PublicKey.from(payload.swarmKey);
|
|
129
139
|
if (!this._swarmPeers.has(topic)) {
|
|
130
140
|
log.warn('Received message from wrong topic', { topic });
|
|
131
141
|
return;
|
|
132
142
|
}
|
|
133
|
-
const oldPeers = this._swarmPeers.get(topic)!;
|
|
143
|
+
const { joinedPeers: oldPeers } = this._swarmPeers.get(topic)!;
|
|
134
144
|
const timestamp = message.timestamp ? new Date(Date.parse(message.timestamp)) : new Date();
|
|
135
145
|
const newPeers = new ComplexSet<PeerInfo>(PeerInfoHash, payload.peers);
|
|
136
146
|
|
|
@@ -156,7 +166,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
156
166
|
});
|
|
157
167
|
}
|
|
158
168
|
|
|
159
|
-
this._swarmPeers.
|
|
169
|
+
this._swarmPeers.get(topic)!.joinedPeers = newPeers;
|
|
160
170
|
}
|
|
161
171
|
|
|
162
172
|
private _processMessage(message: EdgeMessage) {
|
|
@@ -185,10 +195,14 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
185
195
|
private async _rejoinAllSwarms() {
|
|
186
196
|
log('rejoin swarms', { swarms: Array.from(this._swarmPeers.keys()) });
|
|
187
197
|
// Clear all swarms. But leave keys in the map.
|
|
188
|
-
for (const topic of this._swarmPeers.
|
|
198
|
+
for (const [topic, { lastState }] of this._swarmPeers.entries()) {
|
|
189
199
|
await this.join({
|
|
190
200
|
topic,
|
|
191
|
-
peer: {
|
|
201
|
+
peer: {
|
|
202
|
+
peerKey: this._edgeConnection.peerKey,
|
|
203
|
+
identityKey: this._edgeConnection.identityKey,
|
|
204
|
+
state: lastState,
|
|
205
|
+
},
|
|
192
206
|
});
|
|
193
207
|
}
|
|
194
208
|
}
|
|
@@ -197,7 +211,6 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
197
211
|
const createMessageSource = (topic: PublicKey, peerInfo: PeerInfo): buf.MessageInitShape<typeof PeerSchema> => {
|
|
198
212
|
return {
|
|
199
213
|
swarmKey: topic.toHex(),
|
|
200
|
-
|
|
201
|
-
peerKey: peerInfo.peerKey,
|
|
214
|
+
...peerInfo,
|
|
202
215
|
};
|
|
203
216
|
};
|
|
@@ -28,6 +28,8 @@ const WSS_SIGNAL_SERVER_REBOOT_DELAY = 3_000;
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Manages connection to multiple Signal Servers over WebSocket
|
|
31
|
+
* TODO(mykola): Delete.
|
|
32
|
+
* @deprecated
|
|
31
33
|
*/
|
|
32
34
|
export class WebsocketSignalManager extends Resource implements SignalManager {
|
|
33
35
|
private readonly _servers = new Map<string, SignalClientMethods>();
|
package/src/signal-methods.ts
CHANGED
|
@@ -5,21 +5,15 @@
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
6
|
import { type Lifecycle } from '@dxos/context';
|
|
7
7
|
import { type PublicKey } from '@dxos/keys';
|
|
8
|
-
import { type
|
|
8
|
+
import { type SwarmResponse } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
9
|
+
import { type Peer } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
10
|
+
import { type Message, type SwarmEvent } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
9
11
|
import { type SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
10
12
|
|
|
11
|
-
export type
|
|
13
|
+
export type { Message, SwarmEvent };
|
|
14
|
+
export type PeerInfo = Peer;
|
|
12
15
|
export const PeerInfoHash = ({ peerKey }: PeerInfo) => peerKey;
|
|
13
16
|
|
|
14
|
-
export interface Message {
|
|
15
|
-
author: PeerInfo;
|
|
16
|
-
recipient: PeerInfo;
|
|
17
|
-
payload: {
|
|
18
|
-
type_url: string;
|
|
19
|
-
value: Uint8Array;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
17
|
export type SignalStatus = {
|
|
24
18
|
host: string;
|
|
25
19
|
state: SignalState;
|
|
@@ -29,31 +23,14 @@ export type SignalStatus = {
|
|
|
29
23
|
lastStateChange: Date;
|
|
30
24
|
};
|
|
31
25
|
|
|
32
|
-
export type SwarmEvent = {
|
|
33
|
-
topic: PublicKey;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The peer was announced as available on the swarm.
|
|
37
|
-
*/
|
|
38
|
-
peerAvailable?: {
|
|
39
|
-
peer: PeerInfo;
|
|
40
|
-
since: Date;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The peer left, or their announcement timed out.
|
|
45
|
-
*/
|
|
46
|
-
peerLeft?: {
|
|
47
|
-
peer: PeerInfo;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
26
|
/**
|
|
52
27
|
* Message routing interface.
|
|
53
28
|
*/
|
|
54
29
|
export interface SignalMethods {
|
|
55
30
|
/**
|
|
56
31
|
* Emits when other peers join or leave the swarm.
|
|
32
|
+
* @deprecated
|
|
33
|
+
* TODO(mykola): Use swarmState in network-manager instead.
|
|
57
34
|
*/
|
|
58
35
|
swarmEvent: Event<SwarmEvent>;
|
|
59
36
|
|
|
@@ -62,6 +39,11 @@ export interface SignalMethods {
|
|
|
62
39
|
*/
|
|
63
40
|
onMessage: Event<Message>;
|
|
64
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Emits when the swarm state changes.
|
|
44
|
+
*/
|
|
45
|
+
swarmState?: Event<SwarmResponse>;
|
|
46
|
+
|
|
65
47
|
/**
|
|
66
48
|
* Join topic on signal network, to be discoverable by other peers.
|
|
67
49
|
*/
|
|
@@ -79,18 +61,22 @@ export interface SignalMethods {
|
|
|
79
61
|
|
|
80
62
|
/**
|
|
81
63
|
* Start receiving messages from peer.
|
|
64
|
+
* @deprecated
|
|
82
65
|
*/
|
|
83
66
|
// TODO(burdon): Return unsubscribe function. Encapsulate callback/routing here.
|
|
84
67
|
subscribeMessages: (peer: PeerInfo) => Promise<void>;
|
|
85
68
|
|
|
86
69
|
/**
|
|
87
70
|
* Stop receiving messages from peer.
|
|
71
|
+
* @deprecated
|
|
88
72
|
*/
|
|
89
73
|
unsubscribeMessages: (peer: PeerInfo) => Promise<void>;
|
|
90
74
|
}
|
|
91
75
|
|
|
92
76
|
/**
|
|
93
77
|
* Signaling client.
|
|
78
|
+
* TODO(mykola): Delete.
|
|
79
|
+
* @deprecated
|
|
94
80
|
*/
|
|
95
81
|
export interface SignalClientMethods extends SignalMethods, Required<Lifecycle> {
|
|
96
82
|
getStatus(): SignalStatus;
|