@dxos/messaging 0.8.3 → 0.8.4-main.1da679c
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-ISA3S2ZX.mjs → chunk-46VUJLOF.mjs} +451 -334
- package/dist/lib/browser/chunk-46VUJLOF.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 +46 -17
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-SO4RY3ON.mjs → chunk-4SVYY5G5.mjs} +451 -334
- package/dist/lib/node-esm/chunk-4SVYY5G5.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 +46 -17
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/messenger.blueprint-test.d.ts.map +1 -1
- package/dist/types/src/messenger.d.ts +1 -1
- package/dist/types/src/messenger.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-client.d.ts +2 -2
- package/dist/types/src/signal-client/signal-client.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-local-state.d.ts +1 -1
- package/dist/types/src/signal-client/signal-local-state.d.ts.map +1 -1
- 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 +1 -1
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/index.d.ts +1 -1
- package/dist/types/src/signal-manager/index.d.ts.map +1 -1
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts +1 -1
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/signal-manager.d.ts +1 -1
- package/dist/types/src/signal-manager/signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-methods.d.ts +2 -2
- package/dist/types/src/signal-methods.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-peer.d.ts +1 -1
- package/dist/types/src/testing/test-peer.d.ts.map +1 -1
- package/dist/types/src/testing/utils.d.ts +1 -1
- package/dist/types/src/testing/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -16
- package/src/messenger.blueprint-test.ts +2 -2
- package/src/messenger.node.test.ts +2 -2
- package/src/messenger.ts +1 -1
- package/src/signal-client/signal-client.node.test.ts +4 -3
- package/src/signal-client/signal-client.ts +7 -6
- package/src/signal-client/signal-local-state.ts +4 -3
- package/src/signal-client/signal-rpc-client.node.test.ts +1 -1
- package/src/signal-client/signal-rpc-client.ts +4 -4
- package/src/signal-manager/edge-signal-manager.ts +6 -5
- package/src/signal-manager/index.ts +1 -1
- package/src/signal-manager/memory-signal-manager.ts +2 -1
- package/src/signal-manager/signal-manager.ts +1 -1
- package/src/signal-manager/websocket-signal-manager.node.test.ts +3 -2
- package/src/signal-manager/websocket-signal-manager.ts +4 -3
- package/src/signal-methods.ts +3 -3
- package/src/testing/test-builder.ts +3 -2
- package/src/testing/test-peer.ts +3 -2
- package/src/testing/utils.ts +3 -2
- package/dist/lib/browser/chunk-ISA3S2ZX.mjs.map +0 -7
- package/dist/lib/node/chunk-GMND65DN.cjs +0 -2291
- package/dist/lib/node/chunk-GMND65DN.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -43
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -159
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-SO4RY3ON.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/messaging",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.1da679c",
|
|
4
4
|
"description": "Messaging",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"source": "./src/index.ts",
|
|
13
14
|
"types": "./dist/types/src/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
16
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
17
|
},
|
|
17
18
|
"./testing": {
|
|
19
|
+
"source": "./src/testing/index.ts",
|
|
18
20
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
19
21
|
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
20
22
|
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
@@ -36,23 +38,23 @@
|
|
|
36
38
|
"dependencies": {
|
|
37
39
|
"isomorphic-ws": "^5.0.0",
|
|
38
40
|
"ws": "^8.14.2",
|
|
39
|
-
"@dxos/async": "0.8.
|
|
40
|
-
"@dxos/context": "0.8.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/keys": "0.8.
|
|
45
|
-
"@dxos/log": "0.8.
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/protocols": "0.8.
|
|
48
|
-
"@dxos/rpc": "0.8.
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
41
|
+
"@dxos/async": "0.8.4-main.1da679c",
|
|
42
|
+
"@dxos/context": "0.8.4-main.1da679c",
|
|
43
|
+
"@dxos/codec-protobuf": "0.8.4-main.1da679c",
|
|
44
|
+
"@dxos/invariant": "0.8.4-main.1da679c",
|
|
45
|
+
"@dxos/node-std": "0.8.4-main.1da679c",
|
|
46
|
+
"@dxos/keys": "0.8.4-main.1da679c",
|
|
47
|
+
"@dxos/log": "0.8.4-main.1da679c",
|
|
48
|
+
"@dxos/edge-client": "0.8.4-main.1da679c",
|
|
49
|
+
"@dxos/protocols": "0.8.4-main.1da679c",
|
|
50
|
+
"@dxos/rpc": "0.8.4-main.1da679c",
|
|
51
|
+
"@dxos/util": "0.8.4-main.1da679c",
|
|
52
|
+
"@dxos/tracing": "0.8.4-main.1da679c"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
55
|
+
"@dxos/test-utils": "0.8.4-main.1da679c",
|
|
56
|
+
"@dxos/signal": "0.8.4-main.1da679c",
|
|
57
|
+
"@dxos/keyring": "0.8.4-main.1da679c"
|
|
56
58
|
},
|
|
57
59
|
"publishConfig": {
|
|
58
60
|
"access": "public"
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe, expect,
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, latch, sleep } from '@dxos/async';
|
|
8
8
|
import { range } from '@dxos/util';
|
|
9
9
|
|
|
10
10
|
import { WebsocketSignalManager } from './signal-manager';
|
|
11
11
|
import { type Message } from './signal-methods';
|
|
12
|
-
import {
|
|
12
|
+
import { PAYLOAD_1, PAYLOAD_2, PAYLOAD_3, TestBuilder, messageEqual } from './testing';
|
|
13
13
|
|
|
14
14
|
export const messengerTests = (signalManagerFactory: TestBuilder['createSignalManager']) => {
|
|
15
15
|
test('Message between peers', async () => {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { afterAll,
|
|
5
|
+
import { afterAll, beforeAll, describe, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout } from '@dxos/async';
|
|
8
|
-
import {
|
|
8
|
+
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
9
9
|
|
|
10
10
|
import { messengerTests } from './messenger.blueprint-test';
|
|
11
11
|
import { WebsocketSignalManager } from './signal-manager';
|
package/src/messenger.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
|
15
15
|
|
|
16
16
|
import { MessengerMonitor } from './messenger-monitor';
|
|
17
17
|
import { type SignalManager } from './signal-manager';
|
|
18
|
-
import { type
|
|
18
|
+
import { type Message, type PeerInfo } from './signal-methods';
|
|
19
19
|
import { MESSAGE_TIMEOUT } from './timeouts';
|
|
20
20
|
|
|
21
21
|
export type OnMessage = (params: Message) => Promise<void>;
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { afterAll, beforeAll, describe, expect,
|
|
5
|
+
import { afterAll, beforeAll, describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, waitForCondition } from '@dxos/async';
|
|
8
8
|
import { type Any, type TaggedType } from '@dxos/codec-protobuf';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { type TYPES } from '@dxos/protocols/proto';
|
|
12
|
-
import {
|
|
12
|
+
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
13
13
|
import { ComplexSet, range } from '@dxos/util';
|
|
14
14
|
|
|
15
|
-
import { SignalClient } from './signal-client';
|
|
16
15
|
import { type Message, type PeerInfo } from '../signal-methods';
|
|
17
16
|
|
|
17
|
+
import { SignalClient } from './signal-client';
|
|
18
|
+
|
|
18
19
|
const PAYLOAD: TaggedType<TYPES, 'google.protobuf.Any'> = {
|
|
19
20
|
'@type': 'google.protobuf.Any',
|
|
20
21
|
type_url: 'google.protobuf.Any',
|
|
@@ -3,26 +3,27 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { DeferredTask, Event, Trigger, scheduleTask, scheduleTaskInterval, sleep } from '@dxos/async';
|
|
6
|
-
import { type Context,
|
|
6
|
+
import { type Context, Resource, cancelWithContext } from '@dxos/context';
|
|
7
7
|
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
11
|
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
12
|
-
import { type
|
|
12
|
+
import { type JoinRequest, type LeaveRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
13
13
|
import { SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
14
14
|
|
|
15
|
-
import { SignalClientMonitor } from './signal-client-monitor';
|
|
16
|
-
import { SignalLocalState } from './signal-local-state';
|
|
17
|
-
import { SignalRPCClient } from './signal-rpc-client';
|
|
18
15
|
import {
|
|
19
|
-
type PeerInfo,
|
|
20
16
|
type Message,
|
|
17
|
+
type PeerInfo,
|
|
21
18
|
type SignalClientMethods,
|
|
22
19
|
type SignalStatus,
|
|
23
20
|
type SwarmEvent,
|
|
24
21
|
} from '../signal-methods';
|
|
25
22
|
|
|
23
|
+
import { SignalClientMonitor } from './signal-client-monitor';
|
|
24
|
+
import { SignalLocalState } from './signal-local-state';
|
|
25
|
+
import { SignalRPCClient } from './signal-rpc-client';
|
|
26
|
+
|
|
26
27
|
const DEFAULT_RECONNECT_TIMEOUT = 100;
|
|
27
28
|
const MAX_RECONNECT_TIMEOUT = 5_000;
|
|
28
29
|
const ERROR_RECONCILE_DELAY = 1_000;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Event, asyncTimeout } from '@dxos/async';
|
|
6
6
|
import type { Stream } from '@dxos/codec-protobuf/stream';
|
|
7
|
-
import {
|
|
7
|
+
import { type Context, cancelWithContext } from '@dxos/context';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import {
|
|
@@ -13,9 +13,10 @@ import {
|
|
|
13
13
|
} from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
14
14
|
import { ComplexMap, ComplexSet, safeAwaitAll } from '@dxos/util';
|
|
15
15
|
|
|
16
|
-
import { type SignalRPCClient } from './signal-rpc-client';
|
|
17
16
|
import type { Message, SwarmEvent } from '../signal-methods';
|
|
18
17
|
|
|
18
|
+
import { type SignalRPCClient } from './signal-rpc-client';
|
|
19
|
+
|
|
19
20
|
export class SignalLocalState {
|
|
20
21
|
/**
|
|
21
22
|
* Swarm events streams. Keys represent actually joined topic and peerId.
|
|
@@ -9,7 +9,7 @@ import { PublicKey } from '@dxos/keys';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { schema } from '@dxos/protocols/proto';
|
|
11
11
|
import { type Message as SignalMessage, type SwarmEvent } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
12
|
-
import {
|
|
12
|
+
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
13
13
|
|
|
14
14
|
import { SignalRPCClient } from './signal-rpc-client';
|
|
15
15
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import WebSocket from 'isomorphic-ws';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { TimeoutError, Trigger, scheduleTaskInterval } from '@dxos/async';
|
|
8
8
|
import { type Any, type Stream } from '@dxos/codec-protobuf';
|
|
9
9
|
import { Context } from '@dxos/context';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
@@ -12,8 +12,8 @@ import { PublicKey } from '@dxos/keys';
|
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { trace } from '@dxos/protocols';
|
|
14
14
|
import { schema } from '@dxos/protocols/proto';
|
|
15
|
-
import { type Message as SignalMessage
|
|
16
|
-
import {
|
|
15
|
+
import { type Signal, type Message as SignalMessage } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
16
|
+
import { type ProtoRpcPeer, createProtoRpcPeer } from '@dxos/rpc';
|
|
17
17
|
|
|
18
18
|
import { SignalRpcClientMonitor } from './signal-rpc-client-monitor';
|
|
19
19
|
|
|
@@ -169,7 +169,7 @@ export class SignalRPCClient {
|
|
|
169
169
|
|
|
170
170
|
await this._closeComplete.wait({ timeout: 1_000 });
|
|
171
171
|
} catch (err) {
|
|
172
|
-
const failureReason = err instanceof TimeoutError ? 'timeout' : err?.constructor?.name ?? 'unknown';
|
|
172
|
+
const failureReason = err instanceof TimeoutError ? 'timeout' : (err?.constructor?.name ?? 'unknown');
|
|
173
173
|
this._monitor.recordClientCloseFailure({ failureReason });
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Event, scheduleMicroTask } from '@dxos/async';
|
|
6
|
-
import {
|
|
6
|
+
import { Resource, cancelWithContext } 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';
|
|
@@ -11,17 +11,18 @@ import { log } from '@dxos/log';
|
|
|
11
11
|
import { EdgeService } from '@dxos/protocols';
|
|
12
12
|
import { type buf, bufWkt } from '@dxos/protocols/buf';
|
|
13
13
|
import {
|
|
14
|
-
SwarmRequestSchema,
|
|
15
|
-
SwarmRequest_Action as SwarmRequestAction,
|
|
16
|
-
SwarmResponseSchema,
|
|
17
14
|
type Message as EdgeMessage,
|
|
18
15
|
type PeerSchema,
|
|
16
|
+
SwarmRequest_Action as SwarmRequestAction,
|
|
17
|
+
SwarmRequestSchema,
|
|
18
|
+
SwarmResponseSchema,
|
|
19
19
|
} from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
20
20
|
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
21
21
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
22
22
|
|
|
23
|
+
import { type Message, type PeerInfo, PeerInfoHash, type SwarmEvent } from '../signal-methods';
|
|
24
|
+
|
|
23
25
|
import { type SignalManager } from './signal-manager';
|
|
24
|
-
import { type PeerInfo, type Message, type SwarmEvent, PeerInfoHash } from '../signal-methods';
|
|
25
26
|
|
|
26
27
|
export class EdgeSignalManager extends Resource implements SignalManager {
|
|
27
28
|
/**
|
|
@@ -13,8 +13,9 @@ import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
|
13
13
|
import { type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
14
14
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
15
15
|
|
|
16
|
+
import { type Message, type PeerInfo, PeerInfoHash, type SignalStatus, type SwarmEvent } from '../signal-methods';
|
|
17
|
+
|
|
16
18
|
import { type SignalManager } from './signal-manager';
|
|
17
|
-
import { type SwarmEvent, type PeerInfo, type SignalStatus, type Message, PeerInfoHash } from '../signal-methods';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Common signaling context that connects multiple MemorySignalManager instances.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
6
|
import { type Lifecycle } from '@dxos/context';
|
|
7
7
|
|
|
8
|
-
import { type
|
|
8
|
+
import { type SignalMethods, type SignalStatus } from '../signal-methods';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Manages a collection of signaling clients.
|
|
@@ -6,12 +6,13 @@ import { afterAll, beforeAll, describe, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, sleep } from '@dxos/async';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
|
-
import {
|
|
9
|
+
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
10
10
|
import { openAndClose } from '@dxos/test-utils';
|
|
11
11
|
|
|
12
|
-
import { WebsocketSignalManager } from './websocket-signal-manager';
|
|
13
12
|
import { createMessage, expectPeerAvailable, expectReceivedMessage } from '../testing';
|
|
14
13
|
|
|
14
|
+
import { WebsocketSignalManager } from './websocket-signal-manager';
|
|
15
|
+
|
|
15
16
|
describe.skip('WebSocketSignalManager', () => {
|
|
16
17
|
let broker1: SignalServerRunner;
|
|
17
18
|
let broker2: SignalServerRunner;
|
|
@@ -13,18 +13,19 @@ import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
|
13
13
|
import { type JoinRequest, type LeaveRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
14
14
|
import { BitField, safeAwaitAll } from '@dxos/util';
|
|
15
15
|
|
|
16
|
-
import { type SignalManager } from './signal-manager';
|
|
17
|
-
import { WebsocketSignalManagerMonitor } from './websocket-signal-manager-monitor';
|
|
18
16
|
import { SignalClient } from '../signal-client';
|
|
19
17
|
import {
|
|
20
|
-
type PeerInfo,
|
|
21
18
|
type Message,
|
|
19
|
+
type PeerInfo,
|
|
22
20
|
type SignalClientMethods,
|
|
23
21
|
type SignalMethods,
|
|
24
22
|
type SignalStatus,
|
|
25
23
|
type SwarmEvent,
|
|
26
24
|
} from '../signal-methods';
|
|
27
25
|
|
|
26
|
+
import { type SignalManager } from './signal-manager';
|
|
27
|
+
import { WebsocketSignalManagerMonitor } from './websocket-signal-manager-monitor';
|
|
28
|
+
|
|
28
29
|
const MAX_SERVER_FAILURES = 5;
|
|
29
30
|
const WSS_SIGNAL_SERVER_REBOOT_DELAY = 3_000;
|
|
30
31
|
|
package/src/signal-methods.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
6
|
import { type Lifecycle } from '@dxos/context';
|
|
7
|
-
import { type
|
|
7
|
+
import { type Peer, type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
8
8
|
import {
|
|
9
|
+
type JoinRequest,
|
|
9
10
|
type LeaveRequest,
|
|
10
11
|
type Message,
|
|
11
|
-
type SwarmEvent,
|
|
12
|
-
type JoinRequest,
|
|
13
12
|
type QueryRequest,
|
|
13
|
+
type SwarmEvent,
|
|
14
14
|
} from '@dxos/protocols/proto/dxos/edge/signal';
|
|
15
15
|
import { type SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
16
16
|
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { type SignalManager, MemorySignalManager, MemorySignalManagerContext } from '../signal-manager';
|
|
5
|
+
import { MemorySignalManager, MemorySignalManagerContext, type SignalManager } from '../signal-manager';
|
|
7
6
|
import { type Message } from '../signal-methods';
|
|
8
7
|
|
|
8
|
+
import { TestPeer } from './test-peer';
|
|
9
|
+
|
|
9
10
|
export type TestBuilderOptions = {
|
|
10
11
|
signalManagerFactory?: (peer: TestPeer) => Promise<SignalManager>;
|
|
11
12
|
messageDisruption?: (msg: Message) => Message[];
|
package/src/testing/test-peer.ts
CHANGED
|
@@ -9,12 +9,13 @@ import { PublicKey } from '@dxos/keys';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { buf } from '@dxos/protocols/buf';
|
|
11
11
|
|
|
12
|
-
import { type TestBuilder } from './test-builder';
|
|
13
|
-
import { expectPeerAvailable, expectPeerLeft, expectReceivedMessage } from './utils';
|
|
14
12
|
import { Messenger } from '../messenger';
|
|
15
13
|
import { type SignalManager } from '../signal-manager';
|
|
16
14
|
import { type Message, type PeerInfo } from '../signal-methods';
|
|
17
15
|
|
|
16
|
+
import { type TestBuilder } from './test-builder';
|
|
17
|
+
import { expectPeerAvailable, expectPeerLeft, expectReceivedMessage } from './utils';
|
|
18
|
+
|
|
18
19
|
export class TestPeer extends Resource {
|
|
19
20
|
public peerId = PublicKey.random();
|
|
20
21
|
public signalManager!: SignalManager;
|
package/src/testing/utils.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type Event, asyncTimeout } from '@dxos/async';
|
|
6
6
|
import { type Any } from '@dxos/codec-protobuf';
|
|
7
7
|
import { PublicKey } from '@dxos/keys';
|
|
8
8
|
|
|
9
|
+
import { type Message, type PeerInfo, type SignalMethods } from '../signal-methods';
|
|
10
|
+
|
|
9
11
|
import { PAYLOAD_1 } from './test-messages';
|
|
10
|
-
import { type SignalMethods, type Message, type PeerInfo } from '../signal-methods';
|
|
11
12
|
|
|
12
13
|
export const expectPeerAvailable = (client: SignalMethods, expectedTopic: PublicKey, peer: PeerInfo) =>
|
|
13
14
|
asyncTimeout(
|