@dxos/network-manager 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/{chunk-HQNQOWFA.mjs → chunk-UFYPMUBI.mjs} +599 -1973
- package/dist/lib/browser/chunk-UFYPMUBI.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +198 -4
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +65 -70
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/transport/tcp/index.mjs +2 -35
- package/dist/lib/browser/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs +125 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-JPPMRZTH.mjs → chunk-3KIKKHMP.mjs} +599 -1973
- package/dist/lib/node-esm/chunk-3KIKKHMP.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +198 -4
- 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 +65 -70
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/transport/tcp/index.mjs +2 -156
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs +125 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/network-manager.d.ts +6 -6
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/ice.d.ts.map +1 -1
- package/dist/types/src/signal/index.d.ts +2 -2
- package/dist/types/src/signal/index.d.ts.map +1 -1
- package/dist/types/src/signal/signal-connection.d.ts +3 -2
- package/dist/types/src/signal/signal-connection.d.ts.map +1 -1
- package/dist/types/src/signal/signal-messenger.d.ts +3 -2
- package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +8 -8
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +2 -2
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +6 -5
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +6 -8
- package/dist/types/src/swarm/swarm.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-wire-protocol.d.ts +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/utils.d.ts.map +1 -1
- package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
- package/dist/types/src/topology/index.d.ts +1 -1
- package/dist/types/src/topology/index.d.ts.map +1 -1
- package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
- package/dist/types/src/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/index.d.ts +1 -1
- package/dist/types/src/transport/tcp/index.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/tcp-transport.browser.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/tcp-transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +6 -6
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/test-utils.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/utils.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts +5 -5
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -44
- package/src/connection-log.ts +1 -1
- package/src/index.ts +1 -1
- package/src/network-manager.ts +22 -20
- package/src/signal/ice.test.ts +1 -1
- package/src/signal/index.ts +2 -2
- package/src/signal/integration.node.test.ts +13 -12
- package/src/signal/signal-connection.ts +3 -2
- package/src/signal/signal-messenger.ts +3 -2
- package/src/signal/swarm-messenger.node.test.ts +26 -25
- package/src/signal/swarm-messenger.ts +66 -56
- package/src/swarm/connection.test.ts +9 -8
- package/src/swarm/connection.ts +18 -25
- package/src/swarm/peer.ts +9 -8
- package/src/swarm/swarm-mapper.ts +1 -1
- package/src/swarm/swarm.test.ts +8 -7
- package/src/swarm/swarm.ts +14 -20
- package/src/testing/test-builder.ts +15 -7
- package/src/testing/test-wire-protocol.ts +2 -2
- package/src/tests/basic-test-suite.ts +2 -2
- package/src/tests/memory-transport.test.ts +2 -2
- package/src/tests/property-test-suite.ts +4 -3
- package/src/tests/tcp-transport.node.test.ts +2 -2
- package/src/tests/webrtc-transport.test.ts +5 -3
- package/src/topology/index.ts +1 -1
- package/src/transport/tcp/index.ts +1 -1
- package/src/transport/tcp/tcp-transport.ts +1 -1
- package/src/transport/webrtc/rtc-connection-factory.ts +1 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +4 -4
- package/src/transport/webrtc/rtc-transport-channel.test.ts +1 -1
- package/src/transport/webrtc/rtc-transport-channel.ts +2 -2
- package/src/transport/webrtc/rtc-transport-factory.ts +2 -2
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +5 -4
- package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
- package/src/transport/webrtc/rtc-transport-service.ts +5 -5
- package/src/transport/webrtc/rtc-transport.test.ts +5 -4
- package/src/wire-protocol.ts +6 -6
- package/dist/lib/browser/chunk-HQNQOWFA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JPPMRZTH.mjs.map +0 -7
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Event, asyncTimeout } from '@dxos/async';
|
|
6
6
|
import { PublicKey } from '@dxos/keys';
|
|
7
7
|
import { log } from '@dxos/log';
|
|
8
8
|
import { TestExtension, TestExtensionWithStreams } from '@dxos/teleport';
|
|
9
|
-
import type {
|
|
9
|
+
import type { TeleportExtension, TestStreamStats } from '@dxos/teleport';
|
|
10
10
|
import { ComplexMap } from '@dxos/util';
|
|
11
11
|
|
|
12
12
|
import { createTeleportProtocolFactory } from '../wire-protocol';
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout } from '@dxos/async';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { range } from '@dxos/util';
|
|
11
11
|
|
|
12
|
-
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
13
12
|
import { type TestBuilder } from '../testing';
|
|
14
13
|
import { FullyConnectedTopology, StarTopology } from '../topology';
|
|
14
|
+
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
15
15
|
|
|
16
16
|
// TODO(burdon): Use PublicKey throughout (remove conversion to strings, from buffers, etc.)
|
|
17
17
|
|
|
@@ -8,10 +8,10 @@ import { describe, test } from 'vitest';
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { range } from '@dxos/util';
|
|
10
10
|
|
|
11
|
-
import { basicTestSuite } from './basic-test-suite';
|
|
12
|
-
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
13
11
|
import { TestBuilder } from '../testing';
|
|
14
12
|
import { FullyConnectedTopology } from '../topology';
|
|
13
|
+
import { basicTestSuite } from './basic-test-suite';
|
|
14
|
+
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
15
15
|
|
|
16
16
|
describe('Memory transport', () => {
|
|
17
17
|
const testBuilder = new TestBuilder();
|
|
@@ -6,6 +6,7 @@ import * as fc from 'fast-check';
|
|
|
6
6
|
import { type ModelRunSetup } from 'fast-check';
|
|
7
7
|
import { test } from 'vitest';
|
|
8
8
|
|
|
9
|
+
import { Context } from '@dxos/context';
|
|
9
10
|
import { todo } from '@dxos/debug';
|
|
10
11
|
import { PublicKey } from '@dxos/keys';
|
|
11
12
|
import { ComplexMap, ComplexSet, range } from '@dxos/util';
|
|
@@ -97,7 +98,7 @@ export const propertyTestSuite = () => {
|
|
|
97
98
|
model.joinedPeers.delete(this.peerId);
|
|
98
99
|
|
|
99
100
|
const peer = real.peers.get(this.peerId);
|
|
100
|
-
await peer!.networkManager.close();
|
|
101
|
+
await peer!.networkManager.close(Context.default());
|
|
101
102
|
real.peers.delete(this.peerId);
|
|
102
103
|
|
|
103
104
|
await assertState(model, real);
|
|
@@ -119,7 +120,7 @@ export const propertyTestSuite = () => {
|
|
|
119
120
|
// afterTest(() => presence.stop());
|
|
120
121
|
// const protocol = createProtocolFactory(model.topic, this.peerId, [presence]);
|
|
121
122
|
|
|
122
|
-
await peer.networkManager.joinSwarm({
|
|
123
|
+
await peer.networkManager.joinSwarm(Context.default(), {
|
|
123
124
|
peerInfo: {
|
|
124
125
|
peerKey: this.peerId.toHex(),
|
|
125
126
|
identityKey: this.peerId.toHex(),
|
|
@@ -146,7 +147,7 @@ export const propertyTestSuite = () => {
|
|
|
146
147
|
model.joinedPeers.delete(this.peerId);
|
|
147
148
|
|
|
148
149
|
const peer = real.peers.get(this.peerId)!;
|
|
149
|
-
await peer.networkManager.leaveSwarm(model.topic);
|
|
150
|
+
await peer.networkManager.leaveSwarm(Context.default(), model.topic);
|
|
150
151
|
peer.presence = undefined;
|
|
151
152
|
|
|
152
153
|
await assertState(model, real);
|
|
@@ -8,11 +8,11 @@ import { describe, test } from 'vitest';
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { range } from '@dxos/util';
|
|
10
10
|
|
|
11
|
-
import { basicTestSuite } from './basic-test-suite';
|
|
12
|
-
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
13
11
|
import { TestBuilder } from '../testing';
|
|
14
12
|
import { FullyConnectedTopology } from '../topology';
|
|
15
13
|
import { TransportKind } from '../transport';
|
|
14
|
+
import { basicTestSuite } from './basic-test-suite';
|
|
15
|
+
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
16
16
|
|
|
17
17
|
describe('Tcp transport', () => {
|
|
18
18
|
const testBuilder = new TestBuilder({
|
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { basicTestSuite } from './basic-test-suite';
|
|
8
7
|
import { TEST_SIGNAL_HOSTS, TestBuilder } from '../testing';
|
|
8
|
+
import { basicTestSuite } from './basic-test-suite';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// Segfault in node-datachannel.
|
|
11
|
+
describe.skip('WebRTC transport', { timeout: 10_000 }, () => {
|
|
11
12
|
const testBuilder = new TestBuilder();
|
|
12
13
|
basicTestSuite(testBuilder);
|
|
13
14
|
});
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
// Segfault in node-datachannel.
|
|
17
|
+
describe.skip('WebRTC transport proxy', { timeout: 10_000 }, () => {
|
|
16
18
|
const testBuilder = new TestBuilder({ bridge: true });
|
|
17
19
|
basicTestSuite(testBuilder);
|
|
18
20
|
});
|
package/src/topology/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ class NodeRtcConnectionFactory implements RtcConnectionFactory {
|
|
|
38
38
|
private static _cleanupMutex = new Mutex();
|
|
39
39
|
|
|
40
40
|
// This should be inside the function to avoid triggering `eval` in the global scope.
|
|
41
|
-
// eslint-disable-next-line no-
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
42
42
|
|
|
43
43
|
// TODO(burdon): Do imports here?
|
|
44
44
|
async initialize(): Promise<void> {}
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Mutex, Trigger, synchronized } from '@dxos/async';
|
|
6
6
|
import { invariant } from '@dxos/invariant';
|
|
7
7
|
import { log, logInfo } from '@dxos/log';
|
|
8
8
|
import { ConnectivityError } from '@dxos/protocols';
|
|
9
9
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
10
10
|
import { trace } from '@dxos/tracing';
|
|
11
11
|
|
|
12
|
+
import type { IceProvider } from '../../signal';
|
|
13
|
+
import { type TransportOptions } from '../transport';
|
|
12
14
|
import { type RtcConnectionFactory } from './rtc-connection-factory';
|
|
13
15
|
import { RtcTransportChannel } from './rtc-transport-channel';
|
|
14
16
|
import { areSdpEqual, chooseInitiatorPeer } from './utils';
|
|
15
|
-
import type { IceProvider } from '../../signal';
|
|
16
|
-
import { type TransportOptions } from '../transport';
|
|
17
17
|
|
|
18
18
|
export type RtcPeerChannelFactoryOptions = {
|
|
19
19
|
ownPeerKey: string;
|
|
@@ -468,7 +468,7 @@ type IceCandidateErrorDetails = { url: string; errorCode: number; errorText: str
|
|
|
468
468
|
|
|
469
469
|
const createIceFailureError = (details: IceCandidateErrorDetails[]) => {
|
|
470
470
|
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
471
|
-
return new ConnectivityError(`ICE failed:\n${candidateErrors.join('\n')}`);
|
|
471
|
+
return new ConnectivityError({ message: `ICE failed:\n${candidateErrors.join('\n')}` });
|
|
472
472
|
};
|
|
473
473
|
|
|
474
474
|
type ChannelCreatedCallback = {
|
|
@@ -7,10 +7,10 @@ import { describe, expect, test } from 'vitest';
|
|
|
7
7
|
|
|
8
8
|
import { sleep } from '@dxos/async';
|
|
9
9
|
|
|
10
|
+
import { type TransportOptions } from '../transport';
|
|
10
11
|
import { type RtcPeerConnection } from './rtc-peer-connection';
|
|
11
12
|
import { RtcTransportChannel } from './rtc-transport-channel';
|
|
12
13
|
import { handleChannelErrors } from './test-utils';
|
|
13
|
-
import { type TransportOptions } from '../transport';
|
|
14
14
|
|
|
15
15
|
describe('RtcTransportChannel', () => {
|
|
16
16
|
test('transport error raised if channel creation fails', async () => {
|
|
@@ -12,9 +12,9 @@ import { log } from '@dxos/log';
|
|
|
12
12
|
import { ConnectivityError } from '@dxos/protocols';
|
|
13
13
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
14
14
|
|
|
15
|
+
import { type Transport, type TransportOptions, type TransportStats } from '../transport';
|
|
15
16
|
import { type RtcPeerConnection } from './rtc-peer-connection';
|
|
16
17
|
import { createRtcTransportStats, describeSelectedRemoteCandidate } from './rtc-transport-stats';
|
|
17
|
-
import { type Transport, type TransportOptions, type TransportStats } from '../transport';
|
|
18
18
|
|
|
19
19
|
// https://viblast.com/blog/2015/2/5/webrtc-data-channel-message-size
|
|
20
20
|
const MAX_MESSAGE_SIZE = 64 * 1024;
|
|
@@ -70,7 +70,7 @@ export class RtcTransportChannel extends Resource implements Transport {
|
|
|
70
70
|
const error =
|
|
71
71
|
err instanceof Error
|
|
72
72
|
? err
|
|
73
|
-
: new ConnectivityError(`Failed to create a channel: ${JSON.stringify(err?.message)}`);
|
|
73
|
+
: new ConnectivityError({ message: `Failed to create a channel: ${JSON.stringify(err?.message)}` });
|
|
74
74
|
this.errors.raise(error);
|
|
75
75
|
} else {
|
|
76
76
|
log.verbose('connection establishment failed after transport was closed', { err });
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { getRtcConnectionFactory } from './rtc-connection-factory';
|
|
6
|
-
import { RtcPeerConnection } from './rtc-peer-connection';
|
|
7
5
|
import type { IceProvider } from '../../signal';
|
|
8
6
|
import type { TransportFactory } from '../transport';
|
|
7
|
+
import { getRtcConnectionFactory } from './rtc-connection-factory';
|
|
8
|
+
import { RtcPeerConnection } from './rtc-peer-connection';
|
|
9
9
|
|
|
10
10
|
export const createRtcTransportFactory = (
|
|
11
11
|
webrtcConfig?: RTCConfiguration,
|
|
@@ -3,21 +3,22 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Duplex } from 'stream';
|
|
6
|
-
import {
|
|
6
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { Event as AsyncEvent, TestStream, Trigger, sleep } from '@dxos/async';
|
|
9
9
|
import { ErrorStream } from '@dxos/debug';
|
|
10
10
|
import { PublicKey } from '@dxos/keys';
|
|
11
11
|
import { schema } from '@dxos/protocols/proto';
|
|
12
12
|
import { type BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
13
|
-
import { createLinkedPorts, createProtoRpcPeer
|
|
13
|
+
import { type RpcPort, createLinkedPorts, createProtoRpcPeer } from '@dxos/rpc';
|
|
14
14
|
|
|
15
|
+
import { type Transport, type TransportFactory, type TransportOptions, type TransportStats } from '../transport';
|
|
15
16
|
import { RtcTransportProxy } from './rtc-transport-proxy';
|
|
16
17
|
import { RtcTransportService } from './rtc-transport-service';
|
|
17
18
|
import { handleChannelErrors } from './test-utils';
|
|
18
|
-
import { type Transport, type TransportFactory, type TransportOptions, type TransportStats } from '../transport';
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// Segfault in node-datachannel.
|
|
21
|
+
describe.skip('RtcPeerTransportProxy', () => {
|
|
21
22
|
test('open and close', async () => {
|
|
22
23
|
const { proxy } = await setupProxy();
|
|
23
24
|
await proxy.open();
|
|
@@ -176,7 +176,9 @@ export class RtcTransportProxy extends Resource implements Transport {
|
|
|
176
176
|
} catch (error) {
|
|
177
177
|
const type = signalEvent.payload.payload.data?.type;
|
|
178
178
|
if (type === 'offer' || type === 'answer') {
|
|
179
|
-
this._raiseIfOpen(
|
|
179
|
+
this._raiseIfOpen(
|
|
180
|
+
new ConnectivityError({ message: `Session establishment failed: ${type} couldn't be sent.` }),
|
|
181
|
+
);
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
}
|
|
@@ -255,11 +257,11 @@ export class RtcTransportProxyFactory implements TransportFactory {
|
|
|
255
257
|
const decodeError = (err: Error | string) => {
|
|
256
258
|
const message = typeof err === 'string' ? err : err.message;
|
|
257
259
|
if (message.includes('CONNECTION_RESET')) {
|
|
258
|
-
return new ConnectionResetError(message);
|
|
260
|
+
return new ConnectionResetError({ message });
|
|
259
261
|
} else if (message.includes('TIMEOUT')) {
|
|
260
|
-
return new TimeoutError(message);
|
|
262
|
+
return new TimeoutError({ message });
|
|
261
263
|
} else if (message.includes('CONNECTIVITY_ERROR')) {
|
|
262
|
-
return new ConnectivityError(message);
|
|
264
|
+
return new ConnectivityError({ message });
|
|
263
265
|
} else {
|
|
264
266
|
return typeof err === 'string' ? new Error(err) : err;
|
|
265
267
|
}
|
|
@@ -9,23 +9,23 @@ import { invariant } from '@dxos/invariant';
|
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import {
|
|
12
|
+
type BridgeEvent,
|
|
12
13
|
type BridgeService,
|
|
14
|
+
type CloseRequest,
|
|
13
15
|
type ConnectionRequest,
|
|
14
|
-
type SignalRequest,
|
|
15
|
-
type DataRequest,
|
|
16
|
-
type BridgeEvent,
|
|
17
16
|
ConnectionState,
|
|
18
|
-
type
|
|
17
|
+
type DataRequest,
|
|
19
18
|
type DetailsRequest,
|
|
20
19
|
type DetailsResponse,
|
|
20
|
+
type SignalRequest,
|
|
21
21
|
type StatsRequest,
|
|
22
22
|
type StatsResponse,
|
|
23
23
|
} from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
24
24
|
import { ComplexMap } from '@dxos/util';
|
|
25
25
|
|
|
26
|
-
import { createRtcTransportFactory } from './rtc-transport-factory';
|
|
27
26
|
import { type IceProvider } from '../../signal';
|
|
28
27
|
import { type Transport, type TransportFactory } from '../transport';
|
|
28
|
+
import { createRtcTransportFactory } from './rtc-transport-factory';
|
|
29
29
|
|
|
30
30
|
type TransportState = {
|
|
31
31
|
proxyId: PublicKey;
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { TestStream, sleep } from '@dxos/async';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
|
|
10
|
+
import { type TransportOptions } from '../transport';
|
|
10
11
|
import { getRtcConnectionFactory } from './rtc-connection-factory';
|
|
11
12
|
import { RtcPeerConnection } from './rtc-peer-connection';
|
|
12
13
|
import { type RtcTransportChannel } from './rtc-transport-channel';
|
|
13
14
|
import { chooseInitiatorPeer } from './utils';
|
|
14
|
-
import { type TransportOptions } from '../transport';
|
|
15
15
|
|
|
16
16
|
const connectionFactory = getRtcConnectionFactory();
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// Segfault in node-datachannel.
|
|
19
|
+
describe.skip('RtcTransport', () => {
|
|
19
20
|
test('channel open and close', async () => {
|
|
20
21
|
const peer = await createConnection();
|
|
21
22
|
const channel = createChannel(peer);
|
package/src/wire-protocol.ts
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
import { type Duplex } from 'node:stream';
|
|
6
6
|
|
|
7
7
|
import { type PublicKey } from '@dxos/keys';
|
|
8
|
-
import { Teleport, type
|
|
8
|
+
import { Teleport, type TeleportProps } from '@dxos/teleport';
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type WireProtocolProps = {
|
|
11
11
|
initiator: boolean;
|
|
12
12
|
localPeerId: PublicKey;
|
|
13
13
|
remotePeerId: PublicKey;
|
|
14
14
|
topic: PublicKey;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export type WireProtocolProvider = (params:
|
|
17
|
+
export type WireProtocolProvider = (params: WireProtocolProps) => WireProtocol;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Application-specific network protocol that is used when a connection to a peer is established.
|
|
@@ -31,15 +31,15 @@ export interface WireProtocol {
|
|
|
31
31
|
/**
|
|
32
32
|
* Create a wire-protocol provider backed by a teleport instance.
|
|
33
33
|
* @param onConnection Called after teleport is initialized for the session. Protocol extensions could be attached here.
|
|
34
|
-
* @param
|
|
34
|
+
* @param defaultProps Optionally provide default Teleport params that might be overridden by factory callers.
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
37
|
export const createTeleportProtocolFactory = (
|
|
38
38
|
onConnection: (teleport: Teleport) => Promise<void>,
|
|
39
|
-
|
|
39
|
+
defaultProps?: Partial<TeleportProps>,
|
|
40
40
|
): WireProtocolProvider => {
|
|
41
41
|
return (params) => {
|
|
42
|
-
const teleport = new Teleport({ ...
|
|
42
|
+
const teleport = new Teleport({ ...defaultProps, ...params });
|
|
43
43
|
return {
|
|
44
44
|
stream: teleport.stream,
|
|
45
45
|
open: async (sessionId?: PublicKey) => {
|