@dxos/network-manager 0.6.12-main.5cc132e → 0.6.12-main.78ddbdf
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-GW3YM55A.mjs +14 -0
- package/dist/lib/browser/chunk-GW3YM55A.mjs.map +7 -0
- package/dist/lib/browser/{chunk-NMDGRINN.mjs → chunk-YOKKEU6T.mjs} +1216 -1037
- package/dist/lib/browser/chunk-YOKKEU6T.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +10 -19
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +18 -27
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/transport/tcp/index.mjs +39 -0
- package/dist/lib/browser/transport/tcp/index.mjs.map +7 -0
- package/dist/lib/node/{chunk-4K3JQNY3.cjs → chunk-7ZWQLO5T.cjs} +1229 -1177
- package/dist/lib/node/chunk-7ZWQLO5T.cjs.map +7 -0
- package/dist/lib/node/index.cjs +27 -37
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +20 -29
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node/transport/tcp/index.cjs +191 -0
- package/dist/lib/node/transport/tcp/index.cjs.map +7 -0
- package/dist/lib/node-esm/{chunk-X2RY5LSM.mjs → chunk-4VO725JT.mjs} +1249 -1185
- package/dist/lib/node-esm/chunk-4VO725JT.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +10 -19
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +16 -26
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/transport/tcp/index.mjs +159 -0
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +7 -0
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts +2 -2
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/transport/index.d.ts +1 -5
- package/dist/types/src/transport/index.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts +2 -2
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/index.d.ts +2 -0
- package/dist/types/src/transport/tcp/index.d.ts.map +1 -0
- package/dist/types/src/transport/{tcp-transport.browser.d.ts → tcp/tcp-transport.browser.d.ts} +3 -3
- package/dist/types/src/transport/tcp/tcp-transport.browser.d.ts.map +1 -0
- package/dist/types/src/transport/{tcp-transport.d.ts → tcp/tcp-transport.d.ts} +3 -3
- package/dist/types/src/transport/tcp/tcp-transport.d.ts.map +1 -0
- package/dist/types/src/transport/transport.d.ts +7 -6
- package/dist/types/src/transport/transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/index.d.ts +4 -0
- package/dist/types/src/transport/webrtc/index.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-connection-factory.d.ts +14 -0
- package/dist/types/src/transport/webrtc/rtc-connection-factory.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +68 -0
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +33 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.test.d.ts +2 -0
- package/dist/types/src/transport/webrtc/rtc-transport-channel.test.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts +4 -0
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -0
- package/dist/types/src/transport/{simplepeer-transport-proxy.d.ts → webrtc/rtc-transport-proxy.d.ts} +10 -12
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.test.d.ts +2 -0
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.test.d.ts.map +1 -0
- package/dist/types/src/transport/{simplepeer-transport-service.d.ts → webrtc/rtc-transport-service.d.ts} +9 -7
- package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts +4 -0
- package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/rtc-transport.test.d.ts +2 -0
- package/dist/types/src/transport/webrtc/rtc-transport.test.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/test-utils.d.ts +5 -0
- package/dist/types/src/transport/webrtc/test-utils.d.ts.map +1 -0
- package/dist/types/src/transport/webrtc/utils.d.ts +3 -0
- package/dist/types/src/transport/webrtc/utils.d.ts.map +1 -0
- package/package.json +44 -20
- package/src/signal/swarm-messenger.node.test.ts +1 -1
- package/src/swarm/connection.test.ts +61 -37
- package/src/swarm/connection.ts +5 -5
- package/src/swarm/swarm.test.ts +2 -3
- package/src/swarm/swarm.ts +1 -1
- package/src/testing/test-builder.ts +12 -28
- package/src/transport/index.ts +1 -5
- package/src/transport/memory-transport.ts +2 -0
- package/src/transport/tcp/index.ts +5 -0
- package/src/transport/{tcp-transport.browser.ts → tcp/tcp-transport.browser.ts} +7 -3
- package/src/transport/{tcp-transport.ts → tcp/tcp-transport.ts} +3 -1
- package/src/transport/transport.ts +8 -7
- package/src/transport/webrtc/index.ts +7 -0
- package/src/transport/webrtc/rtc-connection-factory.ts +82 -0
- package/src/transport/webrtc/rtc-peer-connection.ts +472 -0
- package/src/transport/webrtc/rtc-transport-channel.test.ts +176 -0
- package/src/transport/webrtc/rtc-transport-channel.ts +195 -0
- package/src/transport/webrtc/rtc-transport-factory.ts +28 -0
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +413 -0
- package/src/transport/webrtc/rtc-transport-proxy.ts +264 -0
- package/src/transport/webrtc/rtc-transport-service.ts +192 -0
- package/src/transport/webrtc/rtc-transport-stats.ts +67 -0
- package/src/transport/webrtc/rtc-transport.test.ts +198 -0
- package/src/transport/webrtc/test-utils.ts +22 -0
- package/src/transport/webrtc/utils.ts +36 -0
- package/dist/lib/browser/chunk-NMDGRINN.mjs.map +0 -7
- package/dist/lib/node/chunk-4K3JQNY3.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-X2RY5LSM.mjs.map +0 -7
- package/dist/types/src/transport/libdatachannel-transport.d.ts +0 -42
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +0 -1
- package/dist/types/src/transport/libdatachannel-transport.node.test.d.ts +0 -2
- package/dist/types/src/transport/libdatachannel-transport.node.test.d.ts.map +0 -1
- package/dist/types/src/transport/memory-transport.test.d.ts +0 -2
- package/dist/types/src/transport/memory-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-simple-peer.node.test.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-simple-peer.node.test.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.node.test.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-transport-proxy.node.test.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +0 -36
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport.test.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +0 -1
- package/dist/types/src/transport/tcp-transport.d.ts.map +0 -1
- package/dist/types/src/transport/webrtc.d.ts +0 -6
- package/dist/types/src/transport/webrtc.d.ts.map +0 -1
- package/src/transport/libdatachannel-transport.node.test.ts +0 -91
- package/src/transport/libdatachannel-transport.ts +0 -372
- package/src/transport/memory-transport.test.ts +0 -75
- package/src/transport/simplepeer-simple-peer.node.test.ts +0 -22
- package/src/transport/simplepeer-transport-proxy.node.test.ts +0 -180
- package/src/transport/simplepeer-transport-proxy.ts +0 -246
- package/src/transport/simplepeer-transport-service.ts +0 -160
- package/src/transport/simplepeer-transport.test.ts +0 -57
- package/src/transport/simplepeer-transport.ts +0 -250
- package/src/transport/webrtc.ts +0 -15
|
@@ -26,37 +26,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_7ZWQLO5T_exports = {};
|
|
30
|
+
__export(chunk_7ZWQLO5T_exports, {
|
|
31
31
|
Connection: () => Connection,
|
|
32
32
|
ConnectionLimiter: () => ConnectionLimiter,
|
|
33
33
|
ConnectionLog: () => ConnectionLog,
|
|
34
34
|
ConnectionState: () => ConnectionState,
|
|
35
35
|
EventType: () => EventType,
|
|
36
36
|
FullyConnectedTopology: () => FullyConnectedTopology,
|
|
37
|
-
LibDataChannelTransport: () => LibDataChannelTransport,
|
|
38
37
|
MAX_CONCURRENT_INITIATING_CONNECTIONS: () => MAX_CONCURRENT_INITIATING_CONNECTIONS,
|
|
39
38
|
MMSTTopology: () => MMSTTopology,
|
|
40
39
|
MemoryTransport: () => MemoryTransport,
|
|
41
40
|
MemoryTransportFactory: () => MemoryTransportFactory,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
SimplePeerTransportService: () => SimplePeerTransportService,
|
|
41
|
+
RtcTransportProxy: () => RtcTransportProxy,
|
|
42
|
+
RtcTransportProxyFactory: () => RtcTransportProxyFactory,
|
|
43
|
+
RtcTransportService: () => RtcTransportService,
|
|
46
44
|
StarTopology: () => StarTopology,
|
|
47
45
|
Swarm: () => Swarm,
|
|
48
46
|
SwarmMapper: () => SwarmMapper,
|
|
49
47
|
SwarmMessenger: () => SwarmMessenger,
|
|
50
48
|
SwarmNetworkManager: () => SwarmNetworkManager,
|
|
51
|
-
TcpTransport: () => TcpTransport,
|
|
52
|
-
TcpTransportFactory: () => TcpTransportFactory,
|
|
53
49
|
TransportKind: () => TransportKind,
|
|
54
50
|
createIceProvider: () => createIceProvider,
|
|
55
|
-
|
|
56
|
-
createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
|
|
51
|
+
createRtcTransportFactory: () => createRtcTransportFactory,
|
|
57
52
|
createTeleportProtocolFactory: () => createTeleportProtocolFactory
|
|
58
53
|
});
|
|
59
|
-
module.exports = __toCommonJS(
|
|
54
|
+
module.exports = __toCommonJS(chunk_7ZWQLO5T_exports);
|
|
60
55
|
var import_async = require("@dxos/async");
|
|
61
56
|
var import_context = require("@dxos/context");
|
|
62
57
|
var import_debug = require("@dxos/debug");
|
|
@@ -125,46 +120,37 @@ var import_invariant10 = require("@dxos/invariant");
|
|
|
125
120
|
var import_keys9 = require("@dxos/keys");
|
|
126
121
|
var import_log11 = require("@dxos/log");
|
|
127
122
|
var import_util8 = require("@dxos/util");
|
|
128
|
-
var import_simple_peer = __toESM(require("simple-peer"));
|
|
129
123
|
var import_async10 = require("@dxos/async");
|
|
130
|
-
var
|
|
124
|
+
var import_async11 = require("@dxos/async");
|
|
131
125
|
var import_invariant11 = require("@dxos/invariant");
|
|
132
|
-
var import_keys10 = require("@dxos/keys");
|
|
133
126
|
var import_log12 = require("@dxos/log");
|
|
134
127
|
var import_protocols7 = require("@dxos/protocols");
|
|
128
|
+
var import_tracing = require("@dxos/tracing");
|
|
135
129
|
var import_node_stream2 = require("node:stream");
|
|
136
|
-
var
|
|
130
|
+
var import_async12 = require("@dxos/async");
|
|
131
|
+
var import_context6 = require("@dxos/context");
|
|
132
|
+
var import_debug5 = require("@dxos/debug");
|
|
137
133
|
var import_invariant12 = require("@dxos/invariant");
|
|
138
|
-
var import_keys11 = require("@dxos/keys");
|
|
139
134
|
var import_log13 = require("@dxos/log");
|
|
140
|
-
var
|
|
141
|
-
var import_util9 = require("@dxos/util");
|
|
135
|
+
var import_protocols8 = require("@dxos/protocols");
|
|
142
136
|
var import_node_stream3 = require("node:stream");
|
|
143
|
-
var
|
|
144
|
-
var
|
|
137
|
+
var import_async13 = require("@dxos/async");
|
|
138
|
+
var import_context7 = require("@dxos/context");
|
|
145
139
|
var import_debug6 = require("@dxos/debug");
|
|
146
140
|
var import_invariant13 = require("@dxos/invariant");
|
|
147
|
-
var
|
|
141
|
+
var import_keys10 = require("@dxos/keys");
|
|
148
142
|
var import_log14 = require("@dxos/log");
|
|
149
|
-
var
|
|
150
|
-
var
|
|
151
|
-
var
|
|
152
|
-
var
|
|
153
|
-
var
|
|
154
|
-
var import_debug7 = require("@dxos/debug");
|
|
143
|
+
var import_protocols9 = require("@dxos/protocols");
|
|
144
|
+
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
145
|
+
var import_util9 = require("@dxos/util");
|
|
146
|
+
var import_node_stream4 = require("node:stream");
|
|
147
|
+
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
155
148
|
var import_invariant14 = require("@dxos/invariant");
|
|
149
|
+
var import_keys11 = require("@dxos/keys");
|
|
156
150
|
var import_log15 = require("@dxos/log");
|
|
157
|
-
var
|
|
158
|
-
var
|
|
159
|
-
var import_debug8 = require("@dxos/debug");
|
|
160
|
-
var import_log16 = require("@dxos/log");
|
|
151
|
+
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
152
|
+
var import_util10 = require("@dxos/util");
|
|
161
153
|
var import_teleport = require("@dxos/teleport");
|
|
162
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
163
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
164
|
-
}) : x)(function(x) {
|
|
165
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
166
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
167
|
-
});
|
|
168
154
|
function _ts_decorate(decorators, target, key, desc) {
|
|
169
155
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
170
156
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -200,11 +186,11 @@ var Connection = class {
|
|
|
200
186
|
this._callbacks = _callbacks;
|
|
201
187
|
this._ctx = new import_context.Context(void 0, {
|
|
202
188
|
F: __dxlog_file,
|
|
203
|
-
L:
|
|
189
|
+
L: 100
|
|
204
190
|
});
|
|
205
191
|
this.connectedTimeoutContext = new import_context.Context(void 0, {
|
|
206
192
|
F: __dxlog_file,
|
|
207
|
-
L:
|
|
193
|
+
L: 101
|
|
208
194
|
});
|
|
209
195
|
this._protocolClosed = new import_async.Trigger();
|
|
210
196
|
this._transportClosed = new import_async.Trigger();
|
|
@@ -227,7 +213,7 @@ var Connection = class {
|
|
|
227
213
|
initiator: this.initiator
|
|
228
214
|
}, {
|
|
229
215
|
F: __dxlog_file,
|
|
230
|
-
L:
|
|
216
|
+
L: 137,
|
|
231
217
|
S: this,
|
|
232
218
|
C: (f, a) => f(...a)
|
|
233
219
|
});
|
|
@@ -250,7 +236,7 @@ var Connection = class {
|
|
|
250
236
|
async openConnection() {
|
|
251
237
|
(0, import_invariant.invariant)(this._state === "INITIAL", "Invalid state.", {
|
|
252
238
|
F: __dxlog_file,
|
|
253
|
-
L:
|
|
239
|
+
L: 167,
|
|
254
240
|
S: this,
|
|
255
241
|
A: [
|
|
256
242
|
"this._state === ConnectionState.INITIAL",
|
|
@@ -261,7 +247,7 @@ var Connection = class {
|
|
|
261
247
|
id: this._instanceId
|
|
262
248
|
}), {
|
|
263
249
|
F: __dxlog_file,
|
|
264
|
-
L:
|
|
250
|
+
L: 168,
|
|
265
251
|
S: this,
|
|
266
252
|
C: (f, a) => f(...a)
|
|
267
253
|
});
|
|
@@ -273,7 +259,7 @@ var Connection = class {
|
|
|
273
259
|
initiator: this.initiator
|
|
274
260
|
}, {
|
|
275
261
|
F: __dxlog_file,
|
|
276
|
-
L:
|
|
262
|
+
L: 169,
|
|
277
263
|
S: this,
|
|
278
264
|
C: (f, a) => f(...a)
|
|
279
265
|
});
|
|
@@ -284,7 +270,7 @@ var Connection = class {
|
|
|
284
270
|
this._protocol.stream.on("close", () => {
|
|
285
271
|
(0, import_log.log)("protocol stream closed", void 0, {
|
|
286
272
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
273
|
+
L: 186,
|
|
288
274
|
S: this,
|
|
289
275
|
C: (f, a) => f(...a)
|
|
290
276
|
});
|
|
@@ -294,7 +280,7 @@ var Connection = class {
|
|
|
294
280
|
(0, import_async.scheduleTask)(this.connectedTimeoutContext, async () => {
|
|
295
281
|
import_log.log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
296
282
|
F: __dxlog_file,
|
|
297
|
-
L:
|
|
283
|
+
L: 194,
|
|
298
284
|
S: this,
|
|
299
285
|
C: (f, a) => f(...a)
|
|
300
286
|
});
|
|
@@ -302,7 +288,7 @@ var Connection = class {
|
|
|
302
288
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
303
289
|
(0, import_invariant.invariant)(!this._transport, void 0, {
|
|
304
290
|
F: __dxlog_file,
|
|
305
|
-
L:
|
|
291
|
+
L: 202,
|
|
306
292
|
S: this,
|
|
307
293
|
A: [
|
|
308
294
|
"!this._transport",
|
|
@@ -310,12 +296,14 @@ var Connection = class {
|
|
|
310
296
|
]
|
|
311
297
|
});
|
|
312
298
|
this._transport = this._transportFactory.createTransport({
|
|
299
|
+
ownPeerKey: this.localInfo.peerKey,
|
|
300
|
+
remotePeerKey: this.remoteInfo.peerKey,
|
|
301
|
+
topic: this.topic.toHex(),
|
|
313
302
|
initiator: this.initiator,
|
|
314
303
|
stream: this._protocol.stream,
|
|
315
304
|
sendSignal: async (signal) => this._sendSignal(signal),
|
|
316
305
|
sessionId: this.sessionId
|
|
317
306
|
});
|
|
318
|
-
await this._transport.open();
|
|
319
307
|
this._transport.connected.once(async () => {
|
|
320
308
|
this._changeState("CONNECTED");
|
|
321
309
|
await this.connectedTimeoutContext.dispose();
|
|
@@ -361,21 +349,13 @@ var Connection = class {
|
|
|
361
349
|
C: (f, a) => f(...a)
|
|
362
350
|
});
|
|
363
351
|
this.abort().catch((err2) => this.errors.raise(err2));
|
|
364
|
-
} else if (err instanceof import_protocols.UnknownProtocolError) {
|
|
365
|
-
import_log.log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
|
|
366
|
-
err
|
|
367
|
-
}, {
|
|
368
|
-
F: __dxlog_file,
|
|
369
|
-
L: 242,
|
|
370
|
-
S: this,
|
|
371
|
-
C: (f, a) => f(...a)
|
|
372
|
-
});
|
|
373
352
|
}
|
|
374
353
|
if (this._state !== "CLOSED" && this._state !== "CLOSING") {
|
|
375
354
|
await this.connectedTimeoutContext.dispose();
|
|
376
355
|
this.errors.raise(err);
|
|
377
356
|
}
|
|
378
357
|
});
|
|
358
|
+
await this._transport.open();
|
|
379
359
|
for (const signal of this._incomingSignalBuffer) {
|
|
380
360
|
void this._transport.onSignal(signal);
|
|
381
361
|
}
|
|
@@ -2912,11 +2892,12 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2912
2892
|
this.errors.raise(err);
|
|
2913
2893
|
});
|
|
2914
2894
|
}
|
|
2895
|
+
return this;
|
|
2915
2896
|
}
|
|
2916
2897
|
async close() {
|
|
2917
2898
|
(0, import_log11.log)("closing...", void 0, {
|
|
2918
2899
|
F: __dxlog_file12,
|
|
2919
|
-
L:
|
|
2900
|
+
L: 130,
|
|
2920
2901
|
S: this,
|
|
2921
2902
|
C: (f, a) => f(...a)
|
|
2922
2903
|
});
|
|
@@ -2937,17 +2918,18 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2937
2918
|
this.closed.emit();
|
|
2938
2919
|
(0, import_log11.log)("closed", void 0, {
|
|
2939
2920
|
F: __dxlog_file12,
|
|
2940
|
-
L:
|
|
2921
|
+
L: 158,
|
|
2941
2922
|
S: this,
|
|
2942
2923
|
C: (f, a) => f(...a)
|
|
2943
2924
|
});
|
|
2925
|
+
return this;
|
|
2944
2926
|
}
|
|
2945
2927
|
async onSignal({ payload }) {
|
|
2946
2928
|
(0, import_log11.log)("received signal", {
|
|
2947
2929
|
payload
|
|
2948
2930
|
}, {
|
|
2949
2931
|
F: __dxlog_file12,
|
|
2950
|
-
L:
|
|
2932
|
+
L: 163,
|
|
2951
2933
|
S: this,
|
|
2952
2934
|
C: (f, a) => f(...a)
|
|
2953
2935
|
});
|
|
@@ -2981,1293 +2963,1368 @@ _ts_decorate5([
|
|
|
2981
2963
|
var toError = (err) => err instanceof Error ? err : new Error(String(err));
|
|
2982
2964
|
var TransportKind;
|
|
2983
2965
|
(function(TransportKind2) {
|
|
2984
|
-
TransportKind2["
|
|
2985
|
-
TransportKind2["
|
|
2986
|
-
TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
|
|
2966
|
+
TransportKind2["WEB_RTC"] = "WEB-RTC";
|
|
2967
|
+
TransportKind2["WEB_RTC_PROXY"] = "WEB-RTC_PROXY";
|
|
2987
2968
|
TransportKind2["MEMORY"] = "MEMORY";
|
|
2988
2969
|
TransportKind2["TCP"] = "TCP";
|
|
2989
2970
|
})(TransportKind || (TransportKind = {}));
|
|
2990
|
-
var
|
|
2991
|
-
|
|
2992
|
-
wrtc = __require("@koush/wrtc");
|
|
2993
|
-
} catch {
|
|
2994
|
-
}
|
|
2995
|
-
function _ts_decorate6(decorators, target, key, desc) {
|
|
2996
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2997
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2998
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2999
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3000
|
-
}
|
|
3001
|
-
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
3002
|
-
var createSimplePeerTransportFactory = (webrtcConfig, iceProvider) => ({
|
|
3003
|
-
createTransport: (options) => new SimplePeerTransport({
|
|
3004
|
-
...options,
|
|
3005
|
-
webrtcConfig,
|
|
3006
|
-
iceProvider
|
|
3007
|
-
})
|
|
3008
|
-
});
|
|
3009
|
-
var SimplePeerTransport = class {
|
|
3010
|
-
get isOpen() {
|
|
3011
|
-
return this._piped && !this._closed;
|
|
2971
|
+
var BrowserRtcConnectionFactory = class {
|
|
2972
|
+
async initialize() {
|
|
3012
2973
|
}
|
|
3013
|
-
|
|
3014
|
-
* @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
|
|
3015
|
-
*/
|
|
3016
|
-
constructor(_params) {
|
|
3017
|
-
this._params = _params;
|
|
3018
|
-
this._peer = void 0;
|
|
3019
|
-
this._closed = false;
|
|
3020
|
-
this._piped = false;
|
|
3021
|
-
this.closed = new import_async10.Event();
|
|
3022
|
-
this.connected = new import_async10.Event();
|
|
3023
|
-
this.errors = new import_debug5.ErrorStream();
|
|
3024
|
-
this._instanceId = import_keys10.PublicKey.random().toHex();
|
|
2974
|
+
async onConnectionDestroyed() {
|
|
3025
2975
|
}
|
|
3026
|
-
async
|
|
3027
|
-
|
|
3028
|
-
if (!stats) {
|
|
3029
|
-
return {
|
|
3030
|
-
bytesSent: 0,
|
|
3031
|
-
bytesReceived: 0,
|
|
3032
|
-
packetsSent: 0,
|
|
3033
|
-
packetsReceived: 0,
|
|
3034
|
-
rawStats: {}
|
|
3035
|
-
};
|
|
3036
|
-
}
|
|
3037
|
-
return {
|
|
3038
|
-
bytesSent: stats.transport.bytesSent,
|
|
3039
|
-
bytesReceived: stats.transport.bytesReceived,
|
|
3040
|
-
packetsSent: stats.transport.packetsSent,
|
|
3041
|
-
packetsReceived: stats.transport.packetsReceived,
|
|
3042
|
-
rawStats: stats.raw
|
|
3043
|
-
};
|
|
2976
|
+
async createConnection(config) {
|
|
2977
|
+
return new RTCPeerConnection(config);
|
|
3044
2978
|
}
|
|
3045
|
-
async
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
2979
|
+
async initConnection(connection, info) {
|
|
2980
|
+
}
|
|
2981
|
+
};
|
|
2982
|
+
var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
|
|
2983
|
+
static {
|
|
2984
|
+
this._createdConnections = 0;
|
|
2985
|
+
}
|
|
2986
|
+
static {
|
|
2987
|
+
this._cleanupMutex = new import_async10.Mutex();
|
|
2988
|
+
}
|
|
2989
|
+
// This should be inside the function to avoid triggering `eval` in the global scope.
|
|
2990
|
+
// eslint-disable-next-line no-new-func
|
|
2991
|
+
// TODO(burdon): Do imports here?
|
|
2992
|
+
async initialize() {
|
|
2993
|
+
}
|
|
2994
|
+
async onConnectionDestroyed() {
|
|
2995
|
+
return _NodeRtcConnectionFactory._cleanupMutex.executeSynchronized(async () => {
|
|
2996
|
+
if (--_NodeRtcConnectionFactory._createdConnections === 0) {
|
|
2997
|
+
(await import("#node-datachannel")).cleanup();
|
|
3058
2998
|
}
|
|
3059
|
-
return {
|
|
3060
|
-
datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
|
|
3061
|
-
transport,
|
|
3062
|
-
selectedCandidatePair,
|
|
3063
|
-
remoteCandidate,
|
|
3064
|
-
raw: Object.fromEntries(stats.entries())
|
|
3065
|
-
};
|
|
3066
2999
|
});
|
|
3067
3000
|
}
|
|
3068
|
-
async
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
return
|
|
3001
|
+
async createConnection(config) {
|
|
3002
|
+
return _NodeRtcConnectionFactory._cleanupMutex.executeSynchronized(async () => {
|
|
3003
|
+
const { RTCPeerConnection: RTCPeerConnection1 } = await import("#node-datachannel/polyfill");
|
|
3004
|
+
_NodeRtcConnectionFactory._createdConnections++;
|
|
3005
|
+
return new RTCPeerConnection1(config);
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
3008
|
+
async initConnection(connection, info) {
|
|
3009
|
+
if (info.initiator) {
|
|
3010
|
+
connection.onnegotiationneeded?.(null);
|
|
3073
3011
|
}
|
|
3074
|
-
|
|
3075
|
-
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
var getRtcConnectionFactory = () => {
|
|
3015
|
+
return typeof globalThis.RTCPeerConnection === "undefined" ? new NodeRtcConnectionFactory() : new BrowserRtcConnectionFactory();
|
|
3016
|
+
};
|
|
3017
|
+
var describeSelectedRemoteCandidate = async (connection) => {
|
|
3018
|
+
const stats = connection && await getRtcConnectionStats(connection);
|
|
3019
|
+
const rc = stats?.remoteCandidate;
|
|
3020
|
+
if (!rc) {
|
|
3021
|
+
return "unavailable";
|
|
3022
|
+
}
|
|
3023
|
+
if (rc.candidateType === "relay") {
|
|
3024
|
+
return `${rc.ip}:${rc.port} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3025
|
+
}
|
|
3026
|
+
return `${rc.ip}:${rc.port} ${rc.candidateType}`;
|
|
3027
|
+
};
|
|
3028
|
+
var createRtcTransportStats = async (connection, topic) => {
|
|
3029
|
+
const stats = connection && await getRtcConnectionStats(connection, topic);
|
|
3030
|
+
if (!stats) {
|
|
3031
|
+
return {
|
|
3032
|
+
bytesSent: 0,
|
|
3033
|
+
bytesReceived: 0,
|
|
3034
|
+
packetsSent: 0,
|
|
3035
|
+
packetsReceived: 0,
|
|
3036
|
+
rawStats: {}
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
return {
|
|
3040
|
+
bytesSent: stats.dataChannel?.bytesSent,
|
|
3041
|
+
bytesReceived: stats.dataChannel?.bytesReceived,
|
|
3042
|
+
packetsSent: 0,
|
|
3043
|
+
packetsReceived: 0,
|
|
3044
|
+
rawStats: stats.raw
|
|
3045
|
+
};
|
|
3046
|
+
};
|
|
3047
|
+
var getRtcConnectionStats = async (connection, channelTopic) => {
|
|
3048
|
+
const stats = await connection.getStats();
|
|
3049
|
+
const statsEntries = Array.from(stats.entries());
|
|
3050
|
+
const transport = statsEntries.find(([_, entry]) => entry.type === "transport")?.[1];
|
|
3051
|
+
const selectedCandidatePair = transport && statsEntries.find(([entryId]) => entryId === transport.selectedCandidatePairId)?.[1];
|
|
3052
|
+
const remoteCandidate = selectedCandidatePair && statsEntries.find(([entryId]) => entryId === selectedCandidatePair.remoteCandidateId)?.[1];
|
|
3053
|
+
const dataChannel = channelTopic && statsEntries.find(([_, entry]) => entry.type === "data-channel" && entry.label === channelTopic)?.[1];
|
|
3054
|
+
return {
|
|
3055
|
+
transport,
|
|
3056
|
+
selectedCandidatePair,
|
|
3057
|
+
dataChannel,
|
|
3058
|
+
remoteCandidate,
|
|
3059
|
+
raw: Object.fromEntries(stats)
|
|
3060
|
+
};
|
|
3061
|
+
};
|
|
3062
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
|
|
3063
|
+
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3064
|
+
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3065
|
+
var RtcTransportChannel = class extends import_context6.Resource {
|
|
3066
|
+
constructor(_connection, _options) {
|
|
3067
|
+
super();
|
|
3068
|
+
this._connection = _connection;
|
|
3069
|
+
this._options = _options;
|
|
3070
|
+
this.closed = new import_async12.Event();
|
|
3071
|
+
this.connected = new import_async12.Event();
|
|
3072
|
+
this.errors = new import_debug5.ErrorStream();
|
|
3073
|
+
this._streamDataFlushedCallback = null;
|
|
3074
|
+
this._isChannelCreationInProgress = false;
|
|
3075
|
+
}
|
|
3076
|
+
get isRtcChannelCreationInProgress() {
|
|
3077
|
+
return this._isChannelCreationInProgress;
|
|
3078
|
+
}
|
|
3079
|
+
onConnectionError(error) {
|
|
3080
|
+
if (this.isOpen) {
|
|
3081
|
+
this.errors.raise(error);
|
|
3076
3082
|
}
|
|
3077
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3078
3083
|
}
|
|
3079
|
-
async
|
|
3080
|
-
|
|
3081
|
-
id: this._instanceId
|
|
3082
|
-
}), {
|
|
3084
|
+
async _open() {
|
|
3085
|
+
(0, import_invariant12.invariant)(!this._isChannelCreationInProgress, void 0, {
|
|
3083
3086
|
F: __dxlog_file13,
|
|
3084
|
-
L:
|
|
3087
|
+
L: 56,
|
|
3085
3088
|
S: this,
|
|
3086
|
-
|
|
3089
|
+
A: [
|
|
3090
|
+
"!this._isChannelCreationInProgress",
|
|
3091
|
+
""
|
|
3092
|
+
]
|
|
3087
3093
|
});
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3094
|
+
this._isChannelCreationInProgress = true;
|
|
3095
|
+
this._connection.createDataChannel(this._options.topic).then((channel) => {
|
|
3096
|
+
if (this.isOpen) {
|
|
3097
|
+
this._channel = channel;
|
|
3098
|
+
this._initChannel(this._channel);
|
|
3099
|
+
} else {
|
|
3100
|
+
this._safeCloseChannel(channel);
|
|
3101
|
+
}
|
|
3102
|
+
}).catch((err) => {
|
|
3103
|
+
if (this.isOpen) {
|
|
3104
|
+
this.errors.raise(new import_protocols8.ConnectivityError(`Failed to create a channel: ${err?.message ?? "unknown reason."}`));
|
|
3105
|
+
}
|
|
3106
|
+
}).finally(() => {
|
|
3107
|
+
this._isChannelCreationInProgress = false;
|
|
3108
|
+
});
|
|
3109
|
+
}
|
|
3110
|
+
async _close() {
|
|
3111
|
+
if (this._channel) {
|
|
3112
|
+
this._safeCloseChannel(this._channel);
|
|
3113
|
+
this._channel = void 0;
|
|
3114
|
+
this._stream = void 0;
|
|
3115
|
+
}
|
|
3116
|
+
this.closed.emit();
|
|
3117
|
+
(0, import_log13.log)("closed", void 0, {
|
|
3091
3118
|
F: __dxlog_file13,
|
|
3092
|
-
L:
|
|
3119
|
+
L: 86,
|
|
3093
3120
|
S: this,
|
|
3094
3121
|
C: (f, a) => f(...a)
|
|
3095
3122
|
});
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
];
|
|
3104
|
-
this._peer = new import_simple_peer.default({
|
|
3105
|
-
channelName: "dxos.mesh.transport",
|
|
3106
|
-
initiator: this._params.initiator,
|
|
3107
|
-
wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : wrtc ?? (0, import_debug5.raise)(new Error("wrtc not available")),
|
|
3108
|
-
config: this._params.webrtcConfig
|
|
3109
|
-
});
|
|
3110
|
-
this._peer.on("signal", async (data) => {
|
|
3111
|
-
(0, import_log12.log)("signal", data, {
|
|
3112
|
-
F: __dxlog_file13,
|
|
3113
|
-
L: 142,
|
|
3114
|
-
S: this,
|
|
3115
|
-
C: (f, a) => f(...a)
|
|
3116
|
-
});
|
|
3117
|
-
await this._params.sendSignal({
|
|
3118
|
-
payload: {
|
|
3119
|
-
data
|
|
3120
|
-
}
|
|
3121
|
-
});
|
|
3122
|
-
});
|
|
3123
|
-
this._peer.on("connect", () => {
|
|
3124
|
-
(0, import_log12.log)("connected", void 0, {
|
|
3125
|
-
F: __dxlog_file13,
|
|
3126
|
-
L: 147,
|
|
3127
|
-
S: this,
|
|
3128
|
-
C: (f, a) => f(...a)
|
|
3129
|
-
});
|
|
3130
|
-
this._params.stream.pipe(this._peer).pipe(this._params.stream);
|
|
3131
|
-
this._piped = true;
|
|
3132
|
-
this.connected.emit();
|
|
3133
|
-
});
|
|
3134
|
-
this._peer.on("close", async () => {
|
|
3135
|
-
(0, import_log12.log)("closed", void 0, {
|
|
3136
|
-
F: __dxlog_file13,
|
|
3137
|
-
L: 154,
|
|
3138
|
-
S: this,
|
|
3139
|
-
C: (f, a) => f(...a)
|
|
3140
|
-
});
|
|
3141
|
-
await this.close();
|
|
3142
|
-
});
|
|
3143
|
-
this._peer.on("error", async (err) => {
|
|
3144
|
-
if (typeof RTCError !== "undefined" && err instanceof RTCError) {
|
|
3145
|
-
if (err.errorDetail === "sctp-failure") {
|
|
3146
|
-
this.errors.raise(new import_protocols7.ConnectionResetError("sctp-failure from RTCError", err));
|
|
3147
|
-
} else {
|
|
3148
|
-
import_log12.log.info("unknown RTCError", {
|
|
3149
|
-
err
|
|
3123
|
+
}
|
|
3124
|
+
_initChannel(channel) {
|
|
3125
|
+
Object.assign(channel, {
|
|
3126
|
+
onopen: () => {
|
|
3127
|
+
if (!this.isOpen) {
|
|
3128
|
+
import_log13.log.warn("channel opened in a closed transport", {
|
|
3129
|
+
topic: this._options.topic
|
|
3150
3130
|
}, {
|
|
3151
3131
|
F: __dxlog_file13,
|
|
3152
|
-
L:
|
|
3132
|
+
L: 93,
|
|
3153
3133
|
S: this,
|
|
3154
3134
|
C: (f, a) => f(...a)
|
|
3155
3135
|
});
|
|
3156
|
-
this.
|
|
3136
|
+
this._safeCloseChannel(channel);
|
|
3137
|
+
return;
|
|
3157
3138
|
}
|
|
3158
|
-
|
|
3159
|
-
import_log12.log.info("simple-peer error", err, {
|
|
3139
|
+
(0, import_log13.log)("onopen", void 0, {
|
|
3160
3140
|
F: __dxlog_file13,
|
|
3161
|
-
L:
|
|
3141
|
+
L: 98,
|
|
3162
3142
|
S: this,
|
|
3163
3143
|
C: (f, a) => f(...a)
|
|
3164
3144
|
});
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
case "ERR_CREATE_OFFER":
|
|
3179
|
-
case "ERR_CREATE_ANSWER":
|
|
3180
|
-
case "ERR_SET_LOCAL_DESCRIPTION":
|
|
3181
|
-
case "ERR_SET_REMOTE_DESCRIPTION":
|
|
3182
|
-
case "ERR_ADD_ICE_CANDIDATE":
|
|
3183
|
-
this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
|
|
3184
|
-
break;
|
|
3185
|
-
default:
|
|
3186
|
-
this.errors.raise(new Error("unknown simple-peer error"));
|
|
3187
|
-
break;
|
|
3188
|
-
}
|
|
3189
|
-
} else {
|
|
3190
|
-
import_log12.log.info("unknown peer connection error", err, {
|
|
3145
|
+
const duplex = new import_node_stream2.Duplex({
|
|
3146
|
+
read: () => {
|
|
3147
|
+
},
|
|
3148
|
+
write: (chunk, encoding, callback) => {
|
|
3149
|
+
return this._handleChannelWrite(chunk, callback);
|
|
3150
|
+
}
|
|
3151
|
+
});
|
|
3152
|
+
duplex.pipe(this._options.stream).pipe(duplex);
|
|
3153
|
+
this._stream = duplex;
|
|
3154
|
+
this.connected.emit();
|
|
3155
|
+
},
|
|
3156
|
+
onclose: async () => {
|
|
3157
|
+
(0, import_log13.log)("onclose", void 0, {
|
|
3191
3158
|
F: __dxlog_file13,
|
|
3192
|
-
L:
|
|
3159
|
+
L: 111,
|
|
3193
3160
|
S: this,
|
|
3194
3161
|
C: (f, a) => f(...a)
|
|
3195
3162
|
});
|
|
3196
|
-
this.
|
|
3197
|
-
}
|
|
3198
|
-
|
|
3199
|
-
if (
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
F: __dxlog_file13,
|
|
3206
|
-
L: 204,
|
|
3207
|
-
S: this,
|
|
3208
|
-
C: (f, a) => f(...a)
|
|
3209
|
-
});
|
|
3163
|
+
await this.close();
|
|
3164
|
+
},
|
|
3165
|
+
onmessage: (event) => {
|
|
3166
|
+
if (!this._stream) {
|
|
3167
|
+
import_log13.log.warn("ignoring message on a closed channel", void 0, {
|
|
3168
|
+
F: __dxlog_file13,
|
|
3169
|
+
L: 117,
|
|
3170
|
+
S: this,
|
|
3171
|
+
C: (f, a) => f(...a)
|
|
3210
3172
|
});
|
|
3173
|
+
return;
|
|
3211
3174
|
}
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3175
|
+
let data = event.data;
|
|
3176
|
+
if (data instanceof ArrayBuffer) {
|
|
3177
|
+
data = Buffer.from(data);
|
|
3178
|
+
}
|
|
3179
|
+
this._stream.push(data);
|
|
3180
|
+
},
|
|
3181
|
+
onerror: (event) => {
|
|
3182
|
+
if (this.isOpen) {
|
|
3183
|
+
const err = event.error instanceof Error ? event.error : new Error(`Datachannel error: ${event.type}.`);
|
|
3184
|
+
this.errors.raise(err);
|
|
3185
|
+
}
|
|
3186
|
+
},
|
|
3187
|
+
onbufferedamountlow: () => {
|
|
3188
|
+
const cb = this._streamDataFlushedCallback;
|
|
3189
|
+
this._streamDataFlushedCallback = null;
|
|
3190
|
+
cb?.();
|
|
3219
3191
|
}
|
|
3220
|
-
await this.close();
|
|
3221
|
-
});
|
|
3222
|
-
import_log12.log.trace("dxos.mesh.webrtc-transport.open", import_protocols7.trace.end({
|
|
3223
|
-
id: this._instanceId
|
|
3224
|
-
}), {
|
|
3225
|
-
F: __dxlog_file13,
|
|
3226
|
-
L: 217,
|
|
3227
|
-
S: this,
|
|
3228
|
-
C: (f, a) => f(...a)
|
|
3229
3192
|
});
|
|
3230
3193
|
}
|
|
3231
|
-
async
|
|
3232
|
-
(
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3194
|
+
async _handleChannelWrite(chunk, callback) {
|
|
3195
|
+
if (!this._channel) {
|
|
3196
|
+
import_log13.log.warn("writing to a channel after a connection was closed", void 0, {
|
|
3197
|
+
F: __dxlog_file13,
|
|
3198
|
+
L: 145,
|
|
3199
|
+
S: this,
|
|
3200
|
+
C: (f, a) => f(...a)
|
|
3201
|
+
});
|
|
3239
3202
|
return;
|
|
3240
3203
|
}
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
(0, import_log12.log)("closed", void 0, {
|
|
3246
|
-
F: __dxlog_file13,
|
|
3247
|
-
L: 230,
|
|
3248
|
-
S: this,
|
|
3249
|
-
C: (f, a) => f(...a)
|
|
3250
|
-
});
|
|
3251
|
-
}
|
|
3252
|
-
async onSignal(signal) {
|
|
3253
|
-
if (this._closed) {
|
|
3204
|
+
if (chunk.length > MAX_MESSAGE_SIZE) {
|
|
3205
|
+
const error = new Error(`Message too large: ${chunk.length} > ${MAX_MESSAGE_SIZE}.`);
|
|
3206
|
+
this.errors.raise(error);
|
|
3207
|
+
callback();
|
|
3254
3208
|
return;
|
|
3255
3209
|
}
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
}
|
|
3274
|
-
|
|
3210
|
+
try {
|
|
3211
|
+
this._channel.send(chunk);
|
|
3212
|
+
} catch (err) {
|
|
3213
|
+
this.errors.raise(err);
|
|
3214
|
+
callback();
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3218
|
+
if (this._streamDataFlushedCallback !== null) {
|
|
3219
|
+
import_log13.log.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3220
|
+
F: __dxlog_file13,
|
|
3221
|
+
L: 166,
|
|
3222
|
+
S: this,
|
|
3223
|
+
C: (f, a) => f(...a)
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
this._streamDataFlushedCallback = callback;
|
|
3227
|
+
} else {
|
|
3228
|
+
callback();
|
|
3229
|
+
}
|
|
3275
3230
|
}
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3231
|
+
_safeCloseChannel(channel) {
|
|
3232
|
+
try {
|
|
3233
|
+
channel.close();
|
|
3234
|
+
} catch (error) {
|
|
3235
|
+
import_log13.log.catch(error, void 0, {
|
|
3236
|
+
F: __dxlog_file13,
|
|
3237
|
+
L: 178,
|
|
3238
|
+
S: this,
|
|
3239
|
+
C: (f, a) => f(...a)
|
|
3240
|
+
});
|
|
3279
3241
|
}
|
|
3280
3242
|
}
|
|
3243
|
+
onSignal(signal) {
|
|
3244
|
+
return this._connection.onSignal(signal);
|
|
3245
|
+
}
|
|
3246
|
+
async getDetails() {
|
|
3247
|
+
return describeSelectedRemoteCandidate(this._connection.currentConnection);
|
|
3248
|
+
}
|
|
3249
|
+
async getStats() {
|
|
3250
|
+
return createRtcTransportStats(this._connection.currentConnection, this._options.topic);
|
|
3251
|
+
}
|
|
3281
3252
|
};
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
var
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3253
|
+
var chooseInitiatorPeer = (peer1Key, peer2Key) => peer1Key < peer2Key ? peer1Key : peer2Key;
|
|
3254
|
+
var areSdpEqual = (sdp1, sdp2) => {
|
|
3255
|
+
const sdp1Lines = deduplicatedSdpLines(sdp1);
|
|
3256
|
+
const sdp2Lines = deduplicatedSdpLines(sdp2);
|
|
3257
|
+
if (sdp1Lines.length !== sdp2Lines.length) {
|
|
3258
|
+
return false;
|
|
3259
|
+
}
|
|
3260
|
+
return sdp1Lines.every((line, idx) => line === sdp2Lines[idx]);
|
|
3261
|
+
};
|
|
3262
|
+
var deduplicatedSdpLines = (sdp) => {
|
|
3263
|
+
const deduplicatedLines = [];
|
|
3264
|
+
const seenLines = [];
|
|
3265
|
+
for (const line of sdp.split("\r\n")) {
|
|
3266
|
+
if (line.startsWith("m")) {
|
|
3267
|
+
seenLines.length = 0;
|
|
3268
|
+
}
|
|
3269
|
+
if (seenLines.includes(line)) {
|
|
3270
|
+
continue;
|
|
3271
|
+
}
|
|
3272
|
+
seenLines.push(line);
|
|
3273
|
+
deduplicatedLines.push(line);
|
|
3297
3274
|
}
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
}
|
|
3343
|
-
});
|
|
3344
|
-
});
|
|
3345
|
-
transport.errors.handle((err) => {
|
|
3346
|
-
next({
|
|
3347
|
-
connection: {
|
|
3348
|
-
state: import_bridge.ConnectionState.CLOSED,
|
|
3349
|
-
error: err.toString()
|
|
3350
|
-
}
|
|
3351
|
-
});
|
|
3352
|
-
close(err);
|
|
3353
|
-
});
|
|
3354
|
-
transport.closed.on(() => {
|
|
3355
|
-
next({
|
|
3356
|
-
connection: {
|
|
3357
|
-
state: import_bridge.ConnectionState.CLOSED
|
|
3358
|
-
}
|
|
3359
|
-
});
|
|
3360
|
-
close();
|
|
3361
|
-
});
|
|
3362
|
-
const transportState = {
|
|
3363
|
-
transport,
|
|
3364
|
-
stream: duplex,
|
|
3365
|
-
writeCallbacks: [],
|
|
3366
|
-
state: "OPEN"
|
|
3367
|
-
};
|
|
3368
|
-
ready();
|
|
3369
|
-
this.transports.set(request.proxyId, transportState);
|
|
3370
|
-
});
|
|
3371
|
-
return rpcStream;
|
|
3372
|
-
}
|
|
3373
|
-
async sendSignal({ proxyId, signal }) {
|
|
3374
|
-
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
3375
|
-
F: __dxlog_file14,
|
|
3376
|
-
L: 124,
|
|
3377
|
-
S: this,
|
|
3378
|
-
A: [
|
|
3379
|
-
"this.transports.has(proxyId)",
|
|
3380
|
-
""
|
|
3381
|
-
]
|
|
3382
|
-
});
|
|
3383
|
-
await this.transports.get(proxyId).transport.onSignal(signal);
|
|
3384
|
-
}
|
|
3385
|
-
async getDetails({ proxyId }) {
|
|
3386
|
-
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
3387
|
-
F: __dxlog_file14,
|
|
3388
|
-
L: 129,
|
|
3389
|
-
S: this,
|
|
3390
|
-
A: [
|
|
3391
|
-
"this.transports.has(proxyId)",
|
|
3392
|
-
""
|
|
3393
|
-
]
|
|
3394
|
-
});
|
|
3395
|
-
return {
|
|
3396
|
-
details: await this.transports.get(proxyId).transport.getDetails()
|
|
3397
|
-
};
|
|
3398
|
-
}
|
|
3399
|
-
async getStats({ proxyId }) {
|
|
3400
|
-
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
3401
|
-
F: __dxlog_file14,
|
|
3402
|
-
L: 134,
|
|
3403
|
-
S: this,
|
|
3404
|
-
A: [
|
|
3405
|
-
"this.transports.has(proxyId)",
|
|
3406
|
-
""
|
|
3407
|
-
]
|
|
3408
|
-
});
|
|
3409
|
-
return {
|
|
3410
|
-
stats: await this.transports.get(proxyId).transport.getStats()
|
|
3411
|
-
};
|
|
3412
|
-
}
|
|
3413
|
-
async sendData({ proxyId, payload }) {
|
|
3414
|
-
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
3415
|
-
import_log13.log.debug("transport is closed", void 0, {
|
|
3275
|
+
return deduplicatedLines;
|
|
3276
|
+
};
|
|
3277
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
3278
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3279
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3280
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3281
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3282
|
+
}
|
|
3283
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3284
|
+
var RtcPeerConnection = class {
|
|
3285
|
+
constructor(_factory, _options) {
|
|
3286
|
+
this._factory = _factory;
|
|
3287
|
+
this._options = _options;
|
|
3288
|
+
this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
|
|
3289
|
+
this._transportChannels = /* @__PURE__ */ new Map();
|
|
3290
|
+
this._dataChannels = /* @__PURE__ */ new Map();
|
|
3291
|
+
this._readyForCandidates = new import_async11.Trigger();
|
|
3292
|
+
this._offerProcessingMutex = new import_async11.Mutex();
|
|
3293
|
+
this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
|
|
3294
|
+
}
|
|
3295
|
+
get transportChannelCount() {
|
|
3296
|
+
return this._transportChannels.size;
|
|
3297
|
+
}
|
|
3298
|
+
get currentConnection() {
|
|
3299
|
+
return this._connection;
|
|
3300
|
+
}
|
|
3301
|
+
async createDataChannel(topic) {
|
|
3302
|
+
const connection = await this._openConnection();
|
|
3303
|
+
if (!this._transportChannels.has(topic)) {
|
|
3304
|
+
if (!this._transportChannels.size) {
|
|
3305
|
+
this._lockAndCloseConnection();
|
|
3306
|
+
}
|
|
3307
|
+
throw new Error("Transport closed while connection was being open");
|
|
3308
|
+
}
|
|
3309
|
+
if (this._initiator) {
|
|
3310
|
+
const channel = connection.createDataChannel(topic);
|
|
3311
|
+
this._dataChannels.set(topic, channel);
|
|
3312
|
+
return channel;
|
|
3313
|
+
} else {
|
|
3314
|
+
const existingChannel = this._dataChannels.get(topic);
|
|
3315
|
+
if (existingChannel) {
|
|
3316
|
+
return existingChannel;
|
|
3317
|
+
}
|
|
3318
|
+
(0, import_log12.log)("waiting for initiator-peer to open a data channel", void 0, {
|
|
3416
3319
|
F: __dxlog_file14,
|
|
3417
|
-
L:
|
|
3320
|
+
L: 90,
|
|
3418
3321
|
S: this,
|
|
3419
3322
|
C: (f, a) => f(...a)
|
|
3420
3323
|
});
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
A: [
|
|
3427
|
-
"this.transports.has(proxyId)",
|
|
3428
|
-
""
|
|
3429
|
-
]
|
|
3430
|
-
});
|
|
3431
|
-
const state = this.transports.get(proxyId);
|
|
3432
|
-
const bufferHasSpace = state.stream.push(payload);
|
|
3433
|
-
if (!bufferHasSpace) {
|
|
3434
|
-
await new Promise((resolve) => {
|
|
3435
|
-
state.writeCallbacks.push(resolve);
|
|
3324
|
+
return new Promise((resolve, reject) => {
|
|
3325
|
+
this._channelCreatedCallbacks.set(topic, {
|
|
3326
|
+
resolve,
|
|
3327
|
+
reject
|
|
3328
|
+
});
|
|
3436
3329
|
});
|
|
3437
3330
|
}
|
|
3438
3331
|
}
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
this.
|
|
3332
|
+
createTransportChannel(options) {
|
|
3333
|
+
const channel = new RtcTransportChannel(this, options);
|
|
3334
|
+
this._transportChannels.set(options.topic, channel);
|
|
3335
|
+
channel.closed.on(() => {
|
|
3336
|
+
this._transportChannels.delete(options.topic);
|
|
3337
|
+
if (this._transportChannels.size === 0) {
|
|
3338
|
+
this._lockAndCloseConnection();
|
|
3339
|
+
}
|
|
3340
|
+
});
|
|
3341
|
+
return channel;
|
|
3342
|
+
}
|
|
3343
|
+
async _openConnection() {
|
|
3344
|
+
if (this._connection) {
|
|
3345
|
+
return this._connection;
|
|
3444
3346
|
}
|
|
3445
|
-
(0,
|
|
3347
|
+
(0, import_log12.log)("initializing connection...", () => ({
|
|
3348
|
+
remotePeer: this._options.remotePeerKey
|
|
3349
|
+
}), {
|
|
3446
3350
|
F: __dxlog_file14,
|
|
3447
|
-
L:
|
|
3351
|
+
L: 115,
|
|
3448
3352
|
S: this,
|
|
3449
3353
|
C: (f, a) => f(...a)
|
|
3450
3354
|
});
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
return !this._closed;
|
|
3473
|
-
}
|
|
3474
|
-
async open() {
|
|
3475
|
-
this._serviceStream = this._options.bridgeService.open({
|
|
3476
|
-
proxyId: this._proxyId,
|
|
3477
|
-
initiator: this._options.initiator
|
|
3478
|
-
}, {
|
|
3479
|
-
timeout: RPC_TIMEOUT
|
|
3480
|
-
});
|
|
3481
|
-
this._serviceStream.waitUntilReady().then(() => {
|
|
3482
|
-
this._serviceStream.subscribe(async (event) => {
|
|
3483
|
-
(0, import_log14.log)("SimplePeerTransportProxy: event", event, {
|
|
3484
|
-
F: __dxlog_file15,
|
|
3485
|
-
L: 66,
|
|
3355
|
+
const config = await this._loadConnectionConfig();
|
|
3356
|
+
const connection = await this._factory.createConnection(config);
|
|
3357
|
+
const iceCandidateErrors = [];
|
|
3358
|
+
Object.assign(connection, {
|
|
3359
|
+
onnegotiationneeded: async () => {
|
|
3360
|
+
(0, import_invariant11.invariant)(this._initiator, void 0, {
|
|
3361
|
+
F: __dxlog_file14,
|
|
3362
|
+
L: 130,
|
|
3363
|
+
S: this,
|
|
3364
|
+
A: [
|
|
3365
|
+
"this._initiator",
|
|
3366
|
+
""
|
|
3367
|
+
]
|
|
3368
|
+
});
|
|
3369
|
+
if (connection !== this._connection) {
|
|
3370
|
+
this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
|
|
3371
|
+
return;
|
|
3372
|
+
}
|
|
3373
|
+
(0, import_log12.log)("onnegotiationneeded", void 0, {
|
|
3374
|
+
F: __dxlog_file14,
|
|
3375
|
+
L: 137,
|
|
3486
3376
|
S: this,
|
|
3487
3377
|
C: (f, a) => f(...a)
|
|
3488
3378
|
});
|
|
3489
|
-
|
|
3490
|
-
await
|
|
3491
|
-
|
|
3492
|
-
this.
|
|
3493
|
-
}
|
|
3494
|
-
|
|
3379
|
+
try {
|
|
3380
|
+
const offer = await connection.createOffer();
|
|
3381
|
+
await connection.setLocalDescription(offer);
|
|
3382
|
+
await this._sendDescription(connection, offer);
|
|
3383
|
+
} catch (err) {
|
|
3384
|
+
this._lockAndAbort(connection, err);
|
|
3495
3385
|
}
|
|
3496
|
-
}
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3386
|
+
},
|
|
3387
|
+
// When ICE candidate identified (should be sent to remote peer) and when ICE gathering finalized.
|
|
3388
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/icecandidate_event
|
|
3389
|
+
onicecandidate: async (event) => {
|
|
3390
|
+
if (connection !== this._connection) {
|
|
3391
|
+
this._onConnectionCallbackAfterClose("onicecandidate", connection);
|
|
3392
|
+
return;
|
|
3393
|
+
}
|
|
3394
|
+
if (event.candidate) {
|
|
3395
|
+
(0, import_log12.log)("onicecandidate", {
|
|
3396
|
+
candidate: event.candidate.candidate
|
|
3503
3397
|
}, {
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
}
|
|
3517
|
-
this._timeoutCount = 0;
|
|
3518
|
-
}, (err) => {
|
|
3519
|
-
if (err instanceof import_protocols8.TimeoutError || err.constructor.name === "TimeoutError") {
|
|
3520
|
-
if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
|
|
3521
|
-
throw new import_protocols8.TimeoutError(`too many timeouts (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
|
|
3522
|
-
} else {
|
|
3523
|
-
(0, import_log14.log)("timeout error, but still invoking callback", void 0, {
|
|
3524
|
-
F: __dxlog_file15,
|
|
3525
|
-
L: 102,
|
|
3526
|
-
S: this,
|
|
3527
|
-
C: (f, a) => f(...a)
|
|
3528
|
-
});
|
|
3529
|
-
callback();
|
|
3530
|
-
}
|
|
3531
|
-
} else {
|
|
3532
|
-
import_log14.log.catch(err, void 0, {
|
|
3533
|
-
F: __dxlog_file15,
|
|
3534
|
-
L: 106,
|
|
3535
|
-
S: this,
|
|
3536
|
-
C: (f, a) => f(...a)
|
|
3537
|
-
});
|
|
3538
|
-
}
|
|
3398
|
+
F: __dxlog_file14,
|
|
3399
|
+
L: 156,
|
|
3400
|
+
S: this,
|
|
3401
|
+
C: (f, a) => f(...a)
|
|
3402
|
+
});
|
|
3403
|
+
await this._sendIceCandidate(event.candidate);
|
|
3404
|
+
} else {
|
|
3405
|
+
(0, import_log12.log)("onicecandidate gathering complete", void 0, {
|
|
3406
|
+
F: __dxlog_file14,
|
|
3407
|
+
L: 159,
|
|
3408
|
+
S: this,
|
|
3409
|
+
C: (f, a) => f(...a)
|
|
3539
3410
|
});
|
|
3540
3411
|
}
|
|
3541
|
-
}
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3412
|
+
},
|
|
3413
|
+
// When error occurs while performing ICE negotiations through a STUN or TURN server.
|
|
3414
|
+
// It's ok for some candidates to fail if a working pair is eventually found.
|
|
3415
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/icecandidateerror_event
|
|
3416
|
+
onicecandidateerror: (event) => {
|
|
3417
|
+
const { url, errorCode, errorText } = event;
|
|
3418
|
+
iceCandidateErrors.push({
|
|
3419
|
+
url,
|
|
3420
|
+
errorCode,
|
|
3421
|
+
errorText
|
|
3422
|
+
});
|
|
3423
|
+
},
|
|
3424
|
+
// When possible error during ICE gathering.
|
|
3425
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceconnectionstatechange_event
|
|
3426
|
+
oniceconnectionstatechange: () => {
|
|
3427
|
+
if (connection !== this._connection) {
|
|
3428
|
+
this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
|
|
3429
|
+
return;
|
|
3430
|
+
}
|
|
3431
|
+
(0, import_log12.log)("oniceconnectionstatechange", {
|
|
3432
|
+
state: connection.iceConnectionState
|
|
3545
3433
|
}, {
|
|
3546
|
-
F:
|
|
3547
|
-
L:
|
|
3434
|
+
F: __dxlog_file14,
|
|
3435
|
+
L: 179,
|
|
3548
3436
|
S: this,
|
|
3549
3437
|
C: (f, a) => f(...a)
|
|
3550
3438
|
});
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3439
|
+
if (connection.iceConnectionState === "failed") {
|
|
3440
|
+
this._lockAndAbort(connection, createIceFailureError(iceCandidateErrors));
|
|
3441
|
+
}
|
|
3442
|
+
},
|
|
3443
|
+
// When new track (or channel) is added.
|
|
3444
|
+
// State: { new, connecting, connected, disconnected, failed, closed }
|
|
3445
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionstatechange_event
|
|
3446
|
+
onconnectionstatechange: () => {
|
|
3447
|
+
if (connection !== this._connection) {
|
|
3448
|
+
if (connection.connectionState !== "closed" && connection.connectionState !== "failed") {
|
|
3449
|
+
this._onConnectionCallbackAfterClose("onconnectionstatechange", connection);
|
|
3450
|
+
}
|
|
3451
|
+
return;
|
|
3452
|
+
}
|
|
3453
|
+
(0, import_log12.log)("onconnectionstatechange", {
|
|
3454
|
+
state: connection.connectionState
|
|
3455
|
+
}, {
|
|
3456
|
+
F: __dxlog_file14,
|
|
3457
|
+
L: 196,
|
|
3458
|
+
S: this,
|
|
3459
|
+
C: (f, a) => f(...a)
|
|
3460
|
+
});
|
|
3461
|
+
if (connection.connectionState === "failed") {
|
|
3462
|
+
this._lockAndAbort(connection, new Error("Connection failed."));
|
|
3463
|
+
}
|
|
3464
|
+
},
|
|
3465
|
+
onsignalingstatechange: () => {
|
|
3466
|
+
(0, import_log12.log)("onsignalingstatechange", {
|
|
3467
|
+
state: connection.signalingState
|
|
3468
|
+
}, {
|
|
3469
|
+
F: __dxlog_file14,
|
|
3470
|
+
L: 203,
|
|
3471
|
+
S: this,
|
|
3472
|
+
C: (f, a) => f(...a)
|
|
3473
|
+
});
|
|
3474
|
+
},
|
|
3475
|
+
// When channel is added to connection.
|
|
3476
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
|
|
3477
|
+
ondatachannel: (event) => {
|
|
3478
|
+
(0, import_invariant11.invariant)(!this._initiator, "Initiator is expected to create data channels.", {
|
|
3479
|
+
F: __dxlog_file14,
|
|
3480
|
+
L: 209,
|
|
3481
|
+
S: this,
|
|
3482
|
+
A: [
|
|
3483
|
+
"!this._initiator",
|
|
3484
|
+
"'Initiator is expected to create data channels.'"
|
|
3485
|
+
]
|
|
3486
|
+
});
|
|
3487
|
+
if (connection !== this._connection) {
|
|
3488
|
+
this._onConnectionCallbackAfterClose("ondatachannel", connection);
|
|
3489
|
+
return;
|
|
3490
|
+
}
|
|
3491
|
+
(0, import_log12.log)("ondatachannel", {
|
|
3492
|
+
label: event.channel.label
|
|
3493
|
+
}, {
|
|
3494
|
+
F: __dxlog_file14,
|
|
3495
|
+
L: 216,
|
|
3496
|
+
S: this,
|
|
3497
|
+
C: (f, a) => f(...a)
|
|
3498
|
+
});
|
|
3499
|
+
this._dataChannels.set(event.channel.label, event.channel);
|
|
3500
|
+
const pendingCallback = this._channelCreatedCallbacks.get(event.channel.label);
|
|
3501
|
+
if (pendingCallback) {
|
|
3502
|
+
this._channelCreatedCallbacks.delete(event.channel.label);
|
|
3503
|
+
pendingCallback.resolve(event.channel);
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
});
|
|
3507
|
+
this._connection = connection;
|
|
3508
|
+
this._readyForCandidates.reset();
|
|
3509
|
+
await this._factory.initConnection(connection, {
|
|
3510
|
+
initiator: this._initiator
|
|
3511
|
+
});
|
|
3512
|
+
return this._connection;
|
|
3559
3513
|
}
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
await this._options.bridgeService.close({
|
|
3568
|
-
proxyId: this._proxyId
|
|
3514
|
+
_lockAndAbort(connection, error) {
|
|
3515
|
+
this._abortConnection(connection, error);
|
|
3516
|
+
}
|
|
3517
|
+
_abortConnection(connection, error) {
|
|
3518
|
+
if (connection !== this._connection) {
|
|
3519
|
+
import_log12.log.error("attempted to abort an inactive connection", {
|
|
3520
|
+
error
|
|
3569
3521
|
}, {
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
} catch (err) {
|
|
3573
|
-
import_log14.log.catch(err, void 0, {
|
|
3574
|
-
F: __dxlog_file15,
|
|
3575
|
-
L: 134,
|
|
3522
|
+
F: __dxlog_file14,
|
|
3523
|
+
L: 241,
|
|
3576
3524
|
S: this,
|
|
3577
3525
|
C: (f, a) => f(...a)
|
|
3578
3526
|
});
|
|
3527
|
+
this._safeCloseConnection(connection);
|
|
3528
|
+
return;
|
|
3579
3529
|
}
|
|
3580
|
-
this.
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
async onSignal(signal) {
|
|
3584
|
-
this._options.bridgeService.sendSignal({
|
|
3585
|
-
proxyId: this._proxyId,
|
|
3586
|
-
signal
|
|
3587
|
-
}, {
|
|
3588
|
-
timeout: RPC_TIMEOUT
|
|
3589
|
-
}).catch((err) => this.errors.raise(decodeError(err)));
|
|
3590
|
-
}
|
|
3591
|
-
async _handleConnection(connectionEvent) {
|
|
3592
|
-
if (connectionEvent.error) {
|
|
3593
|
-
this.errors.raise(decodeError(connectionEvent.error));
|
|
3530
|
+
for (const [topic, pendingCallback] of this._channelCreatedCallbacks.entries()) {
|
|
3531
|
+
pendingCallback.reject(error);
|
|
3532
|
+
this._transportChannels.delete(topic);
|
|
3594
3533
|
}
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
break;
|
|
3599
|
-
}
|
|
3600
|
-
case import_bridge2.ConnectionState.CLOSED: {
|
|
3601
|
-
await this.close();
|
|
3602
|
-
break;
|
|
3603
|
-
}
|
|
3534
|
+
this._channelCreatedCallbacks.clear();
|
|
3535
|
+
for (const channel of this._transportChannels.values()) {
|
|
3536
|
+
channel.onConnectionError(error);
|
|
3604
3537
|
}
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
async _handleSignal(signalEvent) {
|
|
3610
|
-
await this._options.sendSignal(signalEvent.payload);
|
|
3611
|
-
}
|
|
3612
|
-
async getDetails() {
|
|
3613
|
-
return (await this._options.bridgeService.getDetails({
|
|
3614
|
-
proxyId: this._proxyId
|
|
3615
|
-
}, {
|
|
3616
|
-
timeout: RPC_TIMEOUT
|
|
3617
|
-
})).details;
|
|
3618
|
-
}
|
|
3619
|
-
async getStats() {
|
|
3620
|
-
return (await this._options.bridgeService.getStats({
|
|
3621
|
-
proxyId: this._proxyId
|
|
3538
|
+
this._transportChannels.clear();
|
|
3539
|
+
this._safeCloseConnection();
|
|
3540
|
+
(0, import_log12.log)("connection aborted", {
|
|
3541
|
+
reason: error.message
|
|
3622
3542
|
}, {
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
*/
|
|
3629
|
-
// TODO(burdon): Option on close method.
|
|
3630
|
-
forceClose() {
|
|
3631
|
-
void this._serviceStream.close();
|
|
3632
|
-
this.closed.emit();
|
|
3633
|
-
this._closed = true;
|
|
3634
|
-
}
|
|
3635
|
-
};
|
|
3636
|
-
var SimplePeerTransportProxyFactory = class {
|
|
3637
|
-
constructor() {
|
|
3638
|
-
this._connections = /* @__PURE__ */ new Set();
|
|
3639
|
-
}
|
|
3640
|
-
/**
|
|
3641
|
-
* Sets the current BridgeService to be used to open connections.
|
|
3642
|
-
* Calling this method will close any existing connections.
|
|
3643
|
-
*/
|
|
3644
|
-
setBridgeService(bridgeService) {
|
|
3645
|
-
this._bridgeService = bridgeService;
|
|
3646
|
-
for (const connection of this._connections) {
|
|
3647
|
-
connection.forceClose();
|
|
3648
|
-
}
|
|
3649
|
-
return this;
|
|
3543
|
+
F: __dxlog_file14,
|
|
3544
|
+
L: 255,
|
|
3545
|
+
S: this,
|
|
3546
|
+
C: (f, a) => f(...a)
|
|
3547
|
+
});
|
|
3650
3548
|
}
|
|
3651
|
-
|
|
3652
|
-
(0,
|
|
3653
|
-
F:
|
|
3654
|
-
L:
|
|
3549
|
+
_lockAndCloseConnection() {
|
|
3550
|
+
(0, import_invariant11.invariant)(this._transportChannels.size === 0, void 0, {
|
|
3551
|
+
F: __dxlog_file14,
|
|
3552
|
+
L: 260,
|
|
3655
3553
|
S: this,
|
|
3656
3554
|
A: [
|
|
3657
|
-
"this.
|
|
3658
|
-
"
|
|
3555
|
+
"this._transportChannels.size === 0",
|
|
3556
|
+
""
|
|
3659
3557
|
]
|
|
3660
3558
|
});
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
transport.closed.on(() => this._connections.delete(transport));
|
|
3667
|
-
return transport;
|
|
3668
|
-
}
|
|
3669
|
-
};
|
|
3670
|
-
var decodeError = (err) => {
|
|
3671
|
-
const message = typeof err === "string" ? err : err.message;
|
|
3672
|
-
if (message.includes("CONNECTION_RESET")) {
|
|
3673
|
-
return new import_protocols8.ConnectionResetError(message);
|
|
3674
|
-
} else if (message.includes("TIMEOUT")) {
|
|
3675
|
-
return new import_protocols8.TimeoutError(message);
|
|
3676
|
-
} else if (message.includes("PROTOCOL_ERROR")) {
|
|
3677
|
-
return new import_protocols8.ProtocolError(message);
|
|
3678
|
-
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
3679
|
-
return new import_protocols8.ConnectivityError(message);
|
|
3680
|
-
} else if (message.includes("UNKNOWN_PROTOCOL_ERROR")) {
|
|
3681
|
-
return new import_protocols8.UnknownProtocolError(message);
|
|
3682
|
-
} else {
|
|
3683
|
-
return typeof err === "string" ? new Error(err) : err;
|
|
3684
|
-
}
|
|
3685
|
-
};
|
|
3686
|
-
function _ts_decorate7(decorators, target, key, desc) {
|
|
3687
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3688
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3689
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3690
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3691
|
-
}
|
|
3692
|
-
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
|
|
3693
|
-
var DATACHANNEL_LABEL = "dxos.mesh.transport";
|
|
3694
|
-
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3695
|
-
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3696
|
-
var createLibDataChannelTransportFactory = (webrtcConfig, iceProvider) => {
|
|
3697
|
-
return {
|
|
3698
|
-
createTransport: (options) => new LibDataChannelTransport({
|
|
3699
|
-
...options,
|
|
3700
|
-
webrtcConfig,
|
|
3701
|
-
iceProvider
|
|
3702
|
-
})
|
|
3703
|
-
};
|
|
3704
|
-
};
|
|
3705
|
-
var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
3706
|
-
static {
|
|
3707
|
-
this._instanceCount = 0;
|
|
3708
|
-
}
|
|
3709
|
-
constructor(_options) {
|
|
3710
|
-
this._options = _options;
|
|
3711
|
-
this._closed = false;
|
|
3712
|
-
this._connected = false;
|
|
3713
|
-
this._writeCallback = null;
|
|
3714
|
-
this._readyForCandidates = new import_async12.Trigger();
|
|
3715
|
-
this.closed = new import_async12.Event();
|
|
3716
|
-
this.connected = new import_async12.Event();
|
|
3717
|
-
this.errors = new import_debug7.ErrorStream();
|
|
3718
|
-
}
|
|
3719
|
-
get isOpen() {
|
|
3720
|
-
return !!this._peer && !this._closed;
|
|
3721
|
-
}
|
|
3722
|
-
async open() {
|
|
3723
|
-
if (this._closed) {
|
|
3724
|
-
this.errors.raise(new Error("connection already closed"));
|
|
3725
|
-
}
|
|
3726
|
-
const { RTCPeerConnection } = await import("#node-datachannel/polyfill");
|
|
3727
|
-
const providedIceServers = await this._options.iceProvider?.getIceServers();
|
|
3728
|
-
if (!this._options.webrtcConfig) {
|
|
3729
|
-
this._options.webrtcConfig = {};
|
|
3730
|
-
}
|
|
3731
|
-
this._options.webrtcConfig.iceServers = [
|
|
3732
|
-
...this._options.webrtcConfig.iceServers ?? [],
|
|
3733
|
-
...providedIceServers ?? []
|
|
3734
|
-
];
|
|
3735
|
-
this._peer = new RTCPeerConnection(this._options.webrtcConfig);
|
|
3736
|
-
this._peer.onicecandidateerror = (event) => {
|
|
3737
|
-
import_log15.log.error("peer.onicecandidateerror", {
|
|
3738
|
-
event
|
|
3739
|
-
}, {
|
|
3740
|
-
F: __dxlog_file16,
|
|
3741
|
-
L: 92,
|
|
3742
|
-
S: this,
|
|
3743
|
-
C: (f, a) => f(...a)
|
|
3744
|
-
});
|
|
3745
|
-
};
|
|
3746
|
-
this._peer.onconnectionstatechange = (event) => {
|
|
3747
|
-
import_log15.log.debug("peer.onconnectionstatechange", {
|
|
3748
|
-
event,
|
|
3749
|
-
peerConnectionState: this._peer?.connectionState,
|
|
3750
|
-
transportConnectionState: this._connected
|
|
3751
|
-
}, {
|
|
3752
|
-
F: __dxlog_file16,
|
|
3753
|
-
L: 96,
|
|
3559
|
+
if (this._connection) {
|
|
3560
|
+
this._safeCloseConnection();
|
|
3561
|
+
(0, import_log12.log)("connection closed", void 0, {
|
|
3562
|
+
F: __dxlog_file14,
|
|
3563
|
+
L: 263,
|
|
3754
3564
|
S: this,
|
|
3755
3565
|
C: (f, a) => f(...a)
|
|
3756
3566
|
});
|
|
3757
|
-
}
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
async onSignal(signal) {
|
|
3570
|
+
const connection = this._connection;
|
|
3571
|
+
if (!connection) {
|
|
3572
|
+
import_log12.log.warn("a signal ignored because the connection was closed", {
|
|
3573
|
+
type: signal.payload.data.type
|
|
3761
3574
|
}, {
|
|
3762
|
-
F:
|
|
3763
|
-
L:
|
|
3575
|
+
F: __dxlog_file14,
|
|
3576
|
+
L: 271,
|
|
3764
3577
|
S: this,
|
|
3765
3578
|
C: (f, a) => f(...a)
|
|
3766
3579
|
});
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3580
|
+
return;
|
|
3581
|
+
}
|
|
3582
|
+
const data = signal.payload.data;
|
|
3583
|
+
switch (data.type) {
|
|
3584
|
+
case "offer": {
|
|
3585
|
+
await this._offerProcessingMutex.executeSynchronized(async () => {
|
|
3586
|
+
if (isRemoteDescriptionSet(connection, data)) {
|
|
3587
|
+
return;
|
|
3588
|
+
}
|
|
3589
|
+
if (connection.connectionState !== "new") {
|
|
3590
|
+
this._abortConnection(connection, new Error(`Received an offer in ${connection.connectionState}.`));
|
|
3591
|
+
return;
|
|
3592
|
+
}
|
|
3593
|
+
try {
|
|
3594
|
+
await connection.setRemoteDescription({
|
|
3595
|
+
type: data.type,
|
|
3596
|
+
sdp: data.sdp
|
|
3597
|
+
});
|
|
3598
|
+
const answer = await connection.createAnswer();
|
|
3599
|
+
await connection.setLocalDescription(answer);
|
|
3600
|
+
await this._sendDescription(connection, answer);
|
|
3601
|
+
this._onSessionNegotiated(connection);
|
|
3602
|
+
} catch (err) {
|
|
3603
|
+
this._abortConnection(connection, new Error("Error handling a remote offer.", {
|
|
3604
|
+
cause: err
|
|
3605
|
+
}));
|
|
3606
|
+
}
|
|
3607
|
+
});
|
|
3608
|
+
break;
|
|
3792
3609
|
}
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3610
|
+
case "answer":
|
|
3611
|
+
await this._offerProcessingMutex.executeSynchronized(async () => {
|
|
3612
|
+
try {
|
|
3613
|
+
if (isRemoteDescriptionSet(connection, data)) {
|
|
3614
|
+
return;
|
|
3615
|
+
}
|
|
3616
|
+
if (connection.signalingState !== "have-local-offer") {
|
|
3617
|
+
this._abortConnection(connection, new Error(`Unexpected answer from remote peer, signalingState was ${connection.signalingState}.`));
|
|
3618
|
+
return;
|
|
3619
|
+
}
|
|
3620
|
+
await connection.setRemoteDescription({
|
|
3621
|
+
type: data.type,
|
|
3622
|
+
sdp: data.sdp
|
|
3623
|
+
});
|
|
3624
|
+
this._onSessionNegotiated(connection);
|
|
3625
|
+
} catch (err) {
|
|
3626
|
+
this._abortConnection(connection, new Error("Error handling a remote answer.", {
|
|
3627
|
+
cause: err
|
|
3628
|
+
}));
|
|
3629
|
+
}
|
|
3630
|
+
});
|
|
3631
|
+
break;
|
|
3632
|
+
case "candidate":
|
|
3633
|
+
void this._processIceCandidate(connection, data.candidate);
|
|
3634
|
+
break;
|
|
3635
|
+
default:
|
|
3636
|
+
this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
|
|
3637
|
+
break;
|
|
3638
|
+
}
|
|
3639
|
+
(0, import_log12.log)("signal processed", void 0, {
|
|
3640
|
+
F: __dxlog_file14,
|
|
3641
|
+
L: 330,
|
|
3642
|
+
S: this,
|
|
3643
|
+
C: (f, a) => f(...a)
|
|
3644
|
+
});
|
|
3645
|
+
}
|
|
3646
|
+
async _processIceCandidate(connection, candidate) {
|
|
3647
|
+
try {
|
|
3648
|
+
await this._readyForCandidates.wait();
|
|
3649
|
+
if (connection === this._connection) {
|
|
3650
|
+
(0, import_log12.log)("adding ice candidate", {
|
|
3651
|
+
candidate
|
|
3822
3652
|
}, {
|
|
3823
|
-
F:
|
|
3824
|
-
L:
|
|
3653
|
+
F: __dxlog_file14,
|
|
3654
|
+
L: 338,
|
|
3825
3655
|
S: this,
|
|
3826
3656
|
C: (f, a) => f(...a)
|
|
3827
3657
|
});
|
|
3828
|
-
await
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
});
|
|
3837
|
-
}).catch((err) => {
|
|
3838
|
-
this.errors.raise(err);
|
|
3658
|
+
await connection.addIceCandidate(candidate);
|
|
3659
|
+
}
|
|
3660
|
+
} catch (err) {
|
|
3661
|
+
import_log12.log.catch(err, void 0, {
|
|
3662
|
+
F: __dxlog_file14,
|
|
3663
|
+
L: 342,
|
|
3664
|
+
S: this,
|
|
3665
|
+
C: (f, a) => f(...a)
|
|
3839
3666
|
});
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
_onSessionNegotiated(connection) {
|
|
3670
|
+
if (connection === this._connection) {
|
|
3671
|
+
(0, import_log12.log)("ready to process ice candidates", void 0, {
|
|
3672
|
+
F: __dxlog_file14,
|
|
3673
|
+
L: 348,
|
|
3844
3674
|
S: this,
|
|
3845
3675
|
C: (f, a) => f(...a)
|
|
3846
3676
|
});
|
|
3847
|
-
this.
|
|
3848
|
-
this.errors.raise(new Error("unexpected ondatachannel event for initiator"));
|
|
3849
|
-
};
|
|
3677
|
+
this._readyForCandidates.wake();
|
|
3850
3678
|
} else {
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
S: this,
|
|
3858
|
-
C: (f, a) => f(...a)
|
|
3859
|
-
});
|
|
3860
|
-
if (event.channel.label !== DATACHANNEL_LABEL) {
|
|
3861
|
-
this.errors.raise(new Error(`unexpected channel label ${event.channel.label}`));
|
|
3862
|
-
}
|
|
3863
|
-
this._handleChannel(event.channel);
|
|
3864
|
-
};
|
|
3679
|
+
import_log12.log.warn("session was negotiated after connection became inactive", void 0, {
|
|
3680
|
+
F: __dxlog_file14,
|
|
3681
|
+
L: 351,
|
|
3682
|
+
S: this,
|
|
3683
|
+
C: (f, a) => f(...a)
|
|
3684
|
+
});
|
|
3865
3685
|
}
|
|
3866
|
-
_LibDataChannelTransport._instanceCount++;
|
|
3867
3686
|
}
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
}
|
|
3687
|
+
_onConnectionCallbackAfterClose(callback, connection) {
|
|
3688
|
+
import_log12.log.warn("callback invoked after a connection was destroyed, this is probably a bug", {
|
|
3689
|
+
callback,
|
|
3690
|
+
state: connection.connectionState
|
|
3691
|
+
}, {
|
|
3692
|
+
F: __dxlog_file14,
|
|
3693
|
+
L: 356,
|
|
3694
|
+
S: this,
|
|
3695
|
+
C: (f, a) => f(...a)
|
|
3696
|
+
});
|
|
3697
|
+
this._safeCloseConnection(connection);
|
|
3873
3698
|
}
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
return;
|
|
3877
|
-
}
|
|
3878
|
-
await this._disconnectStreams();
|
|
3699
|
+
_safeCloseConnection(connection = this._connection) {
|
|
3700
|
+
const resetFields = this._connection && connection === this._connection;
|
|
3879
3701
|
try {
|
|
3880
|
-
|
|
3702
|
+
connection?.close();
|
|
3881
3703
|
} catch (err) {
|
|
3882
|
-
|
|
3704
|
+
import_log12.log.catch(err, void 0, {
|
|
3705
|
+
F: __dxlog_file14,
|
|
3706
|
+
L: 368,
|
|
3707
|
+
S: this,
|
|
3708
|
+
C: (f, a) => f(...a)
|
|
3709
|
+
});
|
|
3710
|
+
}
|
|
3711
|
+
if (resetFields) {
|
|
3712
|
+
this._connection = void 0;
|
|
3713
|
+
this._dataChannels.clear();
|
|
3714
|
+
this._readyForCandidates.wake();
|
|
3715
|
+
void this._factory.onConnectionDestroyed().catch((err) => import_log12.log.catch(err, void 0, {
|
|
3716
|
+
F: __dxlog_file14,
|
|
3717
|
+
L: 374,
|
|
3718
|
+
S: this,
|
|
3719
|
+
C: (f, a) => f(...a)
|
|
3720
|
+
}));
|
|
3721
|
+
for (const [_, pendingCallback] of this._channelCreatedCallbacks.entries()) {
|
|
3722
|
+
pendingCallback.reject("Connection closed.");
|
|
3723
|
+
}
|
|
3724
|
+
this._channelCreatedCallbacks.clear();
|
|
3883
3725
|
}
|
|
3884
|
-
this._peer = void 0;
|
|
3885
|
-
this._closed = true;
|
|
3886
|
-
this.closed.emit();
|
|
3887
3726
|
}
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3727
|
+
async _loadConnectionConfig() {
|
|
3728
|
+
const config = {
|
|
3729
|
+
...this._options.webrtcConfig
|
|
3730
|
+
};
|
|
3731
|
+
try {
|
|
3732
|
+
const providedIceServers = await this._options.iceProvider?.getIceServers() ?? [];
|
|
3733
|
+
if (providedIceServers.length > 0) {
|
|
3734
|
+
config.iceServers = [
|
|
3735
|
+
...config.iceServers ?? [],
|
|
3736
|
+
...providedIceServers
|
|
3737
|
+
];
|
|
3738
|
+
}
|
|
3739
|
+
} catch (error) {
|
|
3740
|
+
import_log12.log.catch(error, void 0, {
|
|
3741
|
+
F: __dxlog_file14,
|
|
3742
|
+
L: 390,
|
|
3897
3743
|
S: this,
|
|
3898
3744
|
C: (f, a) => f(...a)
|
|
3899
3745
|
});
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
if (this._writeCallback !== null) {
|
|
3915
|
-
import_log15.log.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3916
|
-
F: __dxlog_file16,
|
|
3917
|
-
L: 222,
|
|
3918
|
-
S: this,
|
|
3919
|
-
C: (f, a) => f(...a)
|
|
3920
|
-
});
|
|
3746
|
+
}
|
|
3747
|
+
return config;
|
|
3748
|
+
}
|
|
3749
|
+
async _sendIceCandidate(candidate) {
|
|
3750
|
+
try {
|
|
3751
|
+
await this._options.sendSignal({
|
|
3752
|
+
payload: {
|
|
3753
|
+
data: {
|
|
3754
|
+
type: "candidate",
|
|
3755
|
+
candidate: {
|
|
3756
|
+
candidate: candidate.candidate,
|
|
3757
|
+
// These fields never seem to be not null, but connecting to Chrome doesn't work if they are.
|
|
3758
|
+
sdpMLineIndex: candidate.sdpMLineIndex ?? "0",
|
|
3759
|
+
sdpMid: candidate.sdpMid ?? "0"
|
|
3921
3760
|
}
|
|
3922
|
-
this._writeCallback = callback;
|
|
3923
|
-
} else {
|
|
3924
|
-
callback();
|
|
3925
3761
|
}
|
|
3926
3762
|
}
|
|
3927
3763
|
});
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
this._connected = true;
|
|
3931
|
-
this.connected.emit();
|
|
3932
|
-
};
|
|
3933
|
-
this._channel.onclose = async (err) => {
|
|
3934
|
-
import_log15.log.info("channel.onclose", {
|
|
3764
|
+
} catch (err) {
|
|
3765
|
+
import_log12.log.warn("signaling error", {
|
|
3935
3766
|
err
|
|
3936
3767
|
}, {
|
|
3937
|
-
F:
|
|
3938
|
-
L:
|
|
3768
|
+
F: __dxlog_file14,
|
|
3769
|
+
L: 411,
|
|
3939
3770
|
S: this,
|
|
3940
3771
|
C: (f, a) => f(...a)
|
|
3941
3772
|
});
|
|
3942
|
-
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
async _sendDescription(connection, description) {
|
|
3776
|
+
if (connection !== this._connection) {
|
|
3777
|
+
return;
|
|
3778
|
+
}
|
|
3779
|
+
const data = {
|
|
3780
|
+
type: description.type,
|
|
3781
|
+
sdp: description.sdp
|
|
3943
3782
|
};
|
|
3944
|
-
this.
|
|
3945
|
-
|
|
3946
|
-
|
|
3783
|
+
await this._options.sendSignal({
|
|
3784
|
+
payload: {
|
|
3785
|
+
data
|
|
3786
|
+
}
|
|
3787
|
+
});
|
|
3788
|
+
}
|
|
3789
|
+
get _connectionInfo() {
|
|
3790
|
+
const connectionInfo = this._connection && {
|
|
3791
|
+
connectionState: this._connection.connectionState,
|
|
3792
|
+
iceConnectionState: this._connection.iceConnectionState,
|
|
3793
|
+
iceGatheringState: this._connection.iceGatheringState,
|
|
3794
|
+
signalingState: this._connection.signalingState,
|
|
3795
|
+
remoteDescription: this._connection.remoteDescription,
|
|
3796
|
+
localDescription: this._connection.localDescription
|
|
3947
3797
|
};
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3798
|
+
return {
|
|
3799
|
+
...connectionInfo,
|
|
3800
|
+
ts: Date.now(),
|
|
3801
|
+
remotePeerKey: this._options.remotePeerKey,
|
|
3802
|
+
channels: [
|
|
3803
|
+
...this._transportChannels.keys()
|
|
3804
|
+
].map((topic) => topic),
|
|
3805
|
+
config: this._connection?.getConfiguration()
|
|
3952
3806
|
};
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
this.
|
|
3807
|
+
}
|
|
3808
|
+
get _loggerContext() {
|
|
3809
|
+
return {
|
|
3810
|
+
ownPeerKey: this._options.ownPeerKey,
|
|
3811
|
+
remotePeerKey: this._options.remotePeerKey,
|
|
3812
|
+
initiator: this._initiator,
|
|
3813
|
+
channels: this._transportChannels.size
|
|
3959
3814
|
};
|
|
3960
3815
|
}
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3816
|
+
};
|
|
3817
|
+
_ts_decorate6([
|
|
3818
|
+
import_async11.synchronized
|
|
3819
|
+
], RtcPeerConnection.prototype, "_openConnection", null);
|
|
3820
|
+
_ts_decorate6([
|
|
3821
|
+
import_async11.synchronized
|
|
3822
|
+
], RtcPeerConnection.prototype, "_lockAndAbort", null);
|
|
3823
|
+
_ts_decorate6([
|
|
3824
|
+
import_async11.synchronized
|
|
3825
|
+
], RtcPeerConnection.prototype, "_lockAndCloseConnection", null);
|
|
3826
|
+
_ts_decorate6([
|
|
3827
|
+
import_async11.synchronized
|
|
3828
|
+
], RtcPeerConnection.prototype, "onSignal", null);
|
|
3829
|
+
_ts_decorate6([
|
|
3830
|
+
import_tracing.trace.info()
|
|
3831
|
+
], RtcPeerConnection.prototype, "_connectionInfo", null);
|
|
3832
|
+
_ts_decorate6([
|
|
3833
|
+
import_log12.logInfo
|
|
3834
|
+
], RtcPeerConnection.prototype, "_loggerContext", null);
|
|
3835
|
+
RtcPeerConnection = _ts_decorate6([
|
|
3836
|
+
import_tracing.trace.resource()
|
|
3837
|
+
], RtcPeerConnection);
|
|
3838
|
+
var isRemoteDescriptionSet = (connection, data) => {
|
|
3839
|
+
if (!connection.remoteDescription?.type || connection.remoteDescription?.type !== data.type) {
|
|
3840
|
+
return false;
|
|
3841
|
+
}
|
|
3842
|
+
return areSdpEqual(connection.remoteDescription.sdp, data.sdp);
|
|
3843
|
+
};
|
|
3844
|
+
var createIceFailureError = (details) => {
|
|
3845
|
+
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
3846
|
+
return new import_protocols7.ConnectivityError(`ICE failed:
|
|
3847
|
+
${candidateErrors.join("\n")}`);
|
|
3848
|
+
};
|
|
3849
|
+
var createRtcTransportFactory = (webrtcConfig, iceProvider) => {
|
|
3850
|
+
const connectionFactory = getRtcConnectionFactory();
|
|
3851
|
+
return {
|
|
3852
|
+
createTransport: (options) => {
|
|
3853
|
+
const connection = new RtcPeerConnection(connectionFactory, {
|
|
3854
|
+
ownPeerKey: options.ownPeerKey,
|
|
3855
|
+
remotePeerKey: options.remotePeerKey,
|
|
3856
|
+
sendSignal: options.sendSignal,
|
|
3857
|
+
webrtcConfig,
|
|
3858
|
+
iceProvider
|
|
3859
|
+
});
|
|
3860
|
+
return connection.createTransportChannel(options);
|
|
3861
|
+
}
|
|
3862
|
+
};
|
|
3863
|
+
};
|
|
3864
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
|
|
3865
|
+
var RPC_TIMEOUT = 1e4;
|
|
3866
|
+
var CLOSE_RPC_TIMEOUT = 3e3;
|
|
3867
|
+
var RESP_MIN_THRESHOLD = 500;
|
|
3868
|
+
var RtcTransportProxy = class extends import_context7.Resource {
|
|
3869
|
+
constructor(_options) {
|
|
3870
|
+
super();
|
|
3871
|
+
this._options = _options;
|
|
3872
|
+
this._proxyId = import_keys10.PublicKey.random();
|
|
3873
|
+
this.closed = new import_async13.Event();
|
|
3874
|
+
this.connected = new import_async13.Event();
|
|
3875
|
+
this.errors = new import_debug6.ErrorStream();
|
|
3876
|
+
}
|
|
3877
|
+
async _open() {
|
|
3878
|
+
let stream;
|
|
3971
3879
|
try {
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
}
|
|
4001
|
-
});
|
|
4002
|
-
this._readyForCandidates.wake();
|
|
4003
|
-
} catch (err) {
|
|
4004
|
-
import_log15.log.error("cannot handle offer from signalling server", {
|
|
4005
|
-
err
|
|
4006
|
-
}, {
|
|
4007
|
-
F: __dxlog_file16,
|
|
4008
|
-
L: 283,
|
|
4009
|
-
S: this,
|
|
4010
|
-
C: (f, a) => f(...a)
|
|
4011
|
-
});
|
|
4012
|
-
this.errors.raise(new Error("error handling offer"));
|
|
4013
|
-
}
|
|
4014
|
-
break;
|
|
3880
|
+
stream = this._options.bridgeService.open({
|
|
3881
|
+
proxyId: this._proxyId,
|
|
3882
|
+
remotePeerKey: this._options.remotePeerKey,
|
|
3883
|
+
ownPeerKey: this._options.ownPeerKey,
|
|
3884
|
+
topic: this._options.topic,
|
|
3885
|
+
initiator: this._options.initiator ?? false
|
|
3886
|
+
}, {
|
|
3887
|
+
timeout: RPC_TIMEOUT
|
|
3888
|
+
});
|
|
3889
|
+
} catch (error) {
|
|
3890
|
+
this.errors.raise(error);
|
|
3891
|
+
return;
|
|
3892
|
+
}
|
|
3893
|
+
this._serviceStream = stream;
|
|
3894
|
+
stream.waitUntilReady().then(() => {
|
|
3895
|
+
stream.subscribe(async (event) => {
|
|
3896
|
+
(0, import_log14.log)("rtc transport proxy event", event, {
|
|
3897
|
+
F: __dxlog_file15,
|
|
3898
|
+
L: 66,
|
|
3899
|
+
S: this,
|
|
3900
|
+
C: (f, a) => f(...a)
|
|
3901
|
+
});
|
|
3902
|
+
if (event.connection) {
|
|
3903
|
+
await this._handleConnection(event.connection);
|
|
3904
|
+
} else if (event.data) {
|
|
3905
|
+
this._handleData(event.data);
|
|
3906
|
+
} else if (event.signal) {
|
|
3907
|
+
await this._handleSignal(event.signal);
|
|
4015
3908
|
}
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
await this._peer.addIceCandidate({
|
|
4038
|
-
candidate: data.candidate.candidate
|
|
4039
|
-
});
|
|
4040
|
-
break;
|
|
4041
|
-
default:
|
|
4042
|
-
import_log15.log.error("unhandled signal type", {
|
|
4043
|
-
type: data.type,
|
|
4044
|
-
signal
|
|
3909
|
+
}, (err) => {
|
|
3910
|
+
(0, import_log14.log)("rtc bridge stream closed", {
|
|
3911
|
+
err
|
|
3912
|
+
}, {
|
|
3913
|
+
F: __dxlog_file15,
|
|
3914
|
+
L: 76,
|
|
3915
|
+
S: this,
|
|
3916
|
+
C: (f, a) => f(...a)
|
|
3917
|
+
});
|
|
3918
|
+
if (err) {
|
|
3919
|
+
this._raiseIfOpen(err);
|
|
3920
|
+
} else {
|
|
3921
|
+
void this.close();
|
|
3922
|
+
}
|
|
3923
|
+
});
|
|
3924
|
+
const connectorStream = new import_node_stream3.Writable({
|
|
3925
|
+
write: (chunk, _, callback) => {
|
|
3926
|
+
const sendStartMs = Date.now();
|
|
3927
|
+
this._options.bridgeService.sendData({
|
|
3928
|
+
proxyId: this._proxyId,
|
|
3929
|
+
payload: chunk
|
|
4045
3930
|
}, {
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
3931
|
+
timeout: RPC_TIMEOUT
|
|
3932
|
+
}).then(() => {
|
|
3933
|
+
if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
|
|
3934
|
+
(0, import_log14.log)("slow response, delaying callback", void 0, {
|
|
3935
|
+
F: __dxlog_file15,
|
|
3936
|
+
L: 93,
|
|
3937
|
+
S: this,
|
|
3938
|
+
C: (f, a) => f(...a)
|
|
3939
|
+
});
|
|
3940
|
+
(0, import_async13.scheduleTask)(this._ctx, () => callback(), RESP_MIN_THRESHOLD);
|
|
3941
|
+
} else {
|
|
3942
|
+
callback();
|
|
3943
|
+
}
|
|
3944
|
+
}, (err) => {
|
|
3945
|
+
callback();
|
|
3946
|
+
this._raiseIfOpen(err);
|
|
4050
3947
|
});
|
|
4051
|
-
|
|
3948
|
+
}
|
|
3949
|
+
});
|
|
3950
|
+
connectorStream.on("error", (err) => {
|
|
3951
|
+
this._raiseIfOpen(err);
|
|
3952
|
+
});
|
|
3953
|
+
this._options.stream.pipe(connectorStream);
|
|
3954
|
+
}, (error) => {
|
|
3955
|
+
if (error) {
|
|
3956
|
+
this._raiseIfOpen(error);
|
|
3957
|
+
} else {
|
|
3958
|
+
void this.close();
|
|
4052
3959
|
}
|
|
3960
|
+
});
|
|
3961
|
+
}
|
|
3962
|
+
async _close() {
|
|
3963
|
+
try {
|
|
3964
|
+
await this._serviceStream?.close();
|
|
3965
|
+
this._serviceStream = void 0;
|
|
4053
3966
|
} catch (err) {
|
|
4054
|
-
|
|
4055
|
-
F:
|
|
4056
|
-
L:
|
|
3967
|
+
import_log14.log.catch(err, void 0, {
|
|
3968
|
+
F: __dxlog_file15,
|
|
3969
|
+
L: 128,
|
|
3970
|
+
S: this,
|
|
3971
|
+
C: (f, a) => f(...a)
|
|
3972
|
+
});
|
|
3973
|
+
}
|
|
3974
|
+
try {
|
|
3975
|
+
await this._options.bridgeService.close({
|
|
3976
|
+
proxyId: this._proxyId
|
|
3977
|
+
}, {
|
|
3978
|
+
timeout: CLOSE_RPC_TIMEOUT
|
|
3979
|
+
});
|
|
3980
|
+
} catch (err) {
|
|
3981
|
+
import_log14.log.catch(err, void 0, {
|
|
3982
|
+
F: __dxlog_file15,
|
|
3983
|
+
L: 134,
|
|
4057
3984
|
S: this,
|
|
4058
3985
|
C: (f, a) => f(...a)
|
|
4059
3986
|
});
|
|
4060
3987
|
}
|
|
3988
|
+
this.closed.emit();
|
|
4061
3989
|
}
|
|
4062
|
-
async
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
3990
|
+
async onSignal(signal) {
|
|
3991
|
+
this._options.bridgeService.sendSignal({
|
|
3992
|
+
proxyId: this._proxyId,
|
|
3993
|
+
signal
|
|
3994
|
+
}, {
|
|
3995
|
+
timeout: RPC_TIMEOUT
|
|
3996
|
+
}).catch((err) => this._raiseIfOpen(decodeError(err)));
|
|
3997
|
+
}
|
|
3998
|
+
async _handleConnection(connectionEvent) {
|
|
3999
|
+
if (connectionEvent.error) {
|
|
4000
|
+
this.errors.raise(decodeError(connectionEvent.error));
|
|
4001
|
+
return;
|
|
4002
|
+
}
|
|
4003
|
+
switch (connectionEvent.state) {
|
|
4004
|
+
case import_bridge.ConnectionState.CONNECTED: {
|
|
4005
|
+
this.connected.emit();
|
|
4006
|
+
break;
|
|
4007
|
+
}
|
|
4008
|
+
case import_bridge.ConnectionState.CLOSED: {
|
|
4009
|
+
await this.close();
|
|
4010
|
+
break;
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
_handleData(dataEvent) {
|
|
4015
|
+
try {
|
|
4016
|
+
this._options.stream.write((0, import_util9.arrayToBuffer)(dataEvent.payload));
|
|
4017
|
+
} catch (error) {
|
|
4018
|
+
this._raiseIfOpen(error);
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
async _handleSignal(signalEvent) {
|
|
4022
|
+
try {
|
|
4023
|
+
await this._options.sendSignal(signalEvent.payload);
|
|
4024
|
+
} catch (error) {
|
|
4025
|
+
const type = signalEvent.payload.payload.data?.type;
|
|
4026
|
+
if (type === "offer" || type === "answer") {
|
|
4027
|
+
this._raiseIfOpen(new import_protocols9.ConnectivityError(`Session establishment failed: ${type} couldn't be sent.`));
|
|
4028
|
+
}
|
|
4067
4029
|
}
|
|
4068
|
-
|
|
4069
|
-
|
|
4030
|
+
}
|
|
4031
|
+
async getDetails() {
|
|
4032
|
+
try {
|
|
4033
|
+
const response = await this._options.bridgeService.getDetails({
|
|
4034
|
+
proxyId: this._proxyId
|
|
4035
|
+
}, {
|
|
4036
|
+
timeout: RPC_TIMEOUT
|
|
4037
|
+
});
|
|
4038
|
+
return response.details;
|
|
4039
|
+
} catch (err) {
|
|
4040
|
+
return "bridge-svc unreachable";
|
|
4070
4041
|
}
|
|
4071
|
-
return `${rc.ip}:${rc.port} ${rc.candidateType}`;
|
|
4072
4042
|
}
|
|
4073
4043
|
async getStats() {
|
|
4074
|
-
|
|
4075
|
-
|
|
4044
|
+
try {
|
|
4045
|
+
const response = await this._options.bridgeService.getStats({
|
|
4046
|
+
proxyId: this._proxyId
|
|
4047
|
+
}, {
|
|
4048
|
+
timeout: RPC_TIMEOUT
|
|
4049
|
+
});
|
|
4050
|
+
return response.stats;
|
|
4051
|
+
} catch (err) {
|
|
4076
4052
|
return {
|
|
4077
4053
|
bytesSent: 0,
|
|
4078
4054
|
bytesReceived: 0,
|
|
4079
4055
|
packetsSent: 0,
|
|
4080
4056
|
packetsReceived: 0,
|
|
4081
|
-
rawStats:
|
|
4057
|
+
rawStats: "bridge-svc unreachable"
|
|
4082
4058
|
};
|
|
4083
4059
|
}
|
|
4084
|
-
return {
|
|
4085
|
-
bytesSent: stats.transport.bytesSent,
|
|
4086
|
-
bytesReceived: stats.transport.bytesReceived,
|
|
4087
|
-
packetsSent: 0,
|
|
4088
|
-
packetsReceived: 0,
|
|
4089
|
-
rawStats: stats.raw
|
|
4090
|
-
};
|
|
4091
4060
|
}
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4061
|
+
_raiseIfOpen(error) {
|
|
4062
|
+
if (this.isOpen) {
|
|
4063
|
+
this.errors.raise(error);
|
|
4064
|
+
} else {
|
|
4065
|
+
import_log14.log.info("error swallowed because transport was closed", {
|
|
4066
|
+
message: error.message
|
|
4067
|
+
}, {
|
|
4068
|
+
F: __dxlog_file15,
|
|
4069
|
+
L: 215,
|
|
4070
|
+
S: this,
|
|
4071
|
+
C: (f, a) => f(...a)
|
|
4072
|
+
});
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
/**
|
|
4076
|
+
* Called when underlying proxy service becomes unavailable.
|
|
4077
|
+
*/
|
|
4078
|
+
forceClose() {
|
|
4079
|
+
void this._serviceStream?.close();
|
|
4080
|
+
this.closed.emit();
|
|
4081
|
+
}
|
|
4082
|
+
};
|
|
4083
|
+
var RtcTransportProxyFactory = class {
|
|
4084
|
+
constructor() {
|
|
4085
|
+
this._connections = /* @__PURE__ */ new Set();
|
|
4086
|
+
}
|
|
4087
|
+
/**
|
|
4088
|
+
* Sets the current BridgeService to be used to open connections.
|
|
4089
|
+
* Calling this method will close any existing connections.
|
|
4090
|
+
*/
|
|
4091
|
+
setBridgeService(bridgeService) {
|
|
4092
|
+
this._bridgeService = bridgeService;
|
|
4093
|
+
for (const connection of this._connections) {
|
|
4094
|
+
connection.forceClose();
|
|
4095
|
+
}
|
|
4096
|
+
return this;
|
|
4097
|
+
}
|
|
4098
|
+
createTransport(options) {
|
|
4099
|
+
(0, import_invariant13.invariant)(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
|
|
4100
|
+
F: __dxlog_file15,
|
|
4101
|
+
L: 245,
|
|
4096
4102
|
S: this,
|
|
4097
4103
|
A: [
|
|
4098
|
-
"this.
|
|
4099
|
-
"'not open'"
|
|
4104
|
+
"this._bridgeService",
|
|
4105
|
+
"'RtcTransportProxyFactory is not ready to open connections'"
|
|
4100
4106
|
]
|
|
4101
4107
|
});
|
|
4102
|
-
const
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
selectedCandidatePair = candidatePair[0][1];
|
|
4110
|
-
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
4111
|
-
}
|
|
4112
|
-
return {
|
|
4113
|
-
transport,
|
|
4114
|
-
selectedCandidatePair,
|
|
4115
|
-
remoteCandidate,
|
|
4116
|
-
raw: Object.fromEntries(stats)
|
|
4117
|
-
};
|
|
4118
|
-
}
|
|
4119
|
-
async _disconnectStreams() {
|
|
4120
|
-
this._options.stream.unpipe?.(this._stream)?.unpipe?.(this._options.stream);
|
|
4108
|
+
const transport = new RtcTransportProxy({
|
|
4109
|
+
...options,
|
|
4110
|
+
bridgeService: this._bridgeService
|
|
4111
|
+
});
|
|
4112
|
+
this._connections.add(transport);
|
|
4113
|
+
transport.closed.on(() => this._connections.delete(transport));
|
|
4114
|
+
return transport;
|
|
4121
4115
|
}
|
|
4122
4116
|
};
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4117
|
+
var decodeError = (err) => {
|
|
4118
|
+
const message = typeof err === "string" ? err : err.message;
|
|
4119
|
+
if (message.includes("CONNECTION_RESET")) {
|
|
4120
|
+
return new import_protocols9.ConnectionResetError(message);
|
|
4121
|
+
} else if (message.includes("TIMEOUT")) {
|
|
4122
|
+
return new import_protocols9.TimeoutError(message);
|
|
4123
|
+
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
4124
|
+
return new import_protocols9.ConnectivityError(message);
|
|
4125
|
+
} else {
|
|
4126
|
+
return typeof err === "string" ? new Error(err) : err;
|
|
4127
|
+
}
|
|
4129
4128
|
};
|
|
4130
|
-
var
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
this.
|
|
4134
|
-
this.
|
|
4135
|
-
this._connected = false;
|
|
4136
|
-
this._closed = false;
|
|
4137
|
-
this.closed = new import_async13.Event();
|
|
4138
|
-
this.connected = new import_async13.Event();
|
|
4139
|
-
this.errors = new import_debug8.ErrorStream();
|
|
4129
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
4130
|
+
var RtcTransportService = class {
|
|
4131
|
+
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
4132
|
+
this._transportFactory = _transportFactory;
|
|
4133
|
+
this._openTransports = new import_util10.ComplexMap(import_keys11.PublicKey.hash);
|
|
4140
4134
|
}
|
|
4141
|
-
|
|
4142
|
-
return this.
|
|
4135
|
+
hasOpenTransports() {
|
|
4136
|
+
return this._openTransports.size > 0;
|
|
4143
4137
|
}
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
}
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
}, {
|
|
4171
|
-
F: __dxlog_file17,
|
|
4172
|
-
L: 56,
|
|
4173
|
-
S: this,
|
|
4174
|
-
C: (f, a) => f(...a)
|
|
4175
|
-
});
|
|
4176
|
-
void this.options.sendSignal({
|
|
4177
|
-
payload: {
|
|
4178
|
-
port
|
|
4138
|
+
open(request) {
|
|
4139
|
+
const existingTransport = this._openTransports.get(request.proxyId);
|
|
4140
|
+
if (existingTransport) {
|
|
4141
|
+
import_log15.log.error("requesting a new transport bridge for an existing proxy", void 0, {
|
|
4142
|
+
F: __dxlog_file16,
|
|
4143
|
+
L: 53,
|
|
4144
|
+
S: this,
|
|
4145
|
+
C: (f, a) => f(...a)
|
|
4146
|
+
});
|
|
4147
|
+
void this._safeCloseTransport(existingTransport);
|
|
4148
|
+
this._openTransports.delete(request.proxyId);
|
|
4149
|
+
}
|
|
4150
|
+
return new import_codec_protobuf.Stream(({ ready, next, close }) => {
|
|
4151
|
+
const pushNewState = createStateUpdater(next);
|
|
4152
|
+
const transportStream = new import_node_stream4.Duplex({
|
|
4153
|
+
read: () => {
|
|
4154
|
+
const callbacks = [
|
|
4155
|
+
...transportState.writeProcessedCallbacks
|
|
4156
|
+
];
|
|
4157
|
+
transportState.writeProcessedCallbacks.length = 0;
|
|
4158
|
+
callbacks.forEach((cb) => cb());
|
|
4159
|
+
},
|
|
4160
|
+
write: function(chunk, _, callback) {
|
|
4161
|
+
next({
|
|
4162
|
+
data: {
|
|
4163
|
+
payload: chunk
|
|
4179
4164
|
}
|
|
4180
|
-
})
|
|
4181
|
-
|
|
4182
|
-
|
|
4165
|
+
});
|
|
4166
|
+
callback();
|
|
4167
|
+
}
|
|
4168
|
+
});
|
|
4169
|
+
const transport = this._transportFactory.createTransport({
|
|
4170
|
+
initiator: request.initiator,
|
|
4171
|
+
topic: request.topic,
|
|
4172
|
+
ownPeerKey: request.ownPeerKey,
|
|
4173
|
+
remotePeerKey: request.remotePeerKey,
|
|
4174
|
+
stream: transportStream,
|
|
4175
|
+
sendSignal: async (signal) => {
|
|
4176
|
+
next({
|
|
4177
|
+
signal: {
|
|
4178
|
+
payload: signal
|
|
4183
4179
|
}
|
|
4184
4180
|
});
|
|
4185
|
-
}
|
|
4186
|
-
this._server.on("error", (err) => {
|
|
4187
|
-
this.errors.raise(err);
|
|
4188
|
-
});
|
|
4189
|
-
this._server.listen(0);
|
|
4181
|
+
}
|
|
4190
4182
|
});
|
|
4191
|
-
|
|
4183
|
+
const transportState = {
|
|
4184
|
+
proxyId: request.proxyId,
|
|
4185
|
+
transport,
|
|
4186
|
+
connectorStream: transportStream,
|
|
4187
|
+
writeProcessedCallbacks: []
|
|
4188
|
+
};
|
|
4189
|
+
pushNewState(import_bridge2.ConnectionState.CONNECTING);
|
|
4190
|
+
transport.connected.on(() => pushNewState(import_bridge2.ConnectionState.CONNECTED));
|
|
4191
|
+
transport.errors.handle(async (err) => {
|
|
4192
|
+
pushNewState(import_bridge2.ConnectionState.CLOSED, err);
|
|
4193
|
+
void this._safeCloseTransport(transportState);
|
|
4194
|
+
close(err);
|
|
4195
|
+
});
|
|
4196
|
+
transport.closed.on(async () => {
|
|
4197
|
+
pushNewState(import_bridge2.ConnectionState.CLOSED);
|
|
4198
|
+
void this._safeCloseTransport(transportState);
|
|
4199
|
+
close();
|
|
4200
|
+
});
|
|
4201
|
+
this._openTransports.set(request.proxyId, transportState);
|
|
4202
|
+
transport.open().catch(async (err) => {
|
|
4203
|
+
pushNewState(import_bridge2.ConnectionState.CLOSED, err);
|
|
4204
|
+
void this._safeCloseTransport(transportState);
|
|
4205
|
+
close(err);
|
|
4206
|
+
});
|
|
4207
|
+
ready();
|
|
4208
|
+
});
|
|
4192
4209
|
}
|
|
4193
|
-
async
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4210
|
+
async sendSignal({ proxyId, signal }) {
|
|
4211
|
+
const transport = this._openTransports.get(proxyId);
|
|
4212
|
+
(0, import_invariant14.invariant)(transport, void 0, {
|
|
4213
|
+
F: __dxlog_file16,
|
|
4214
|
+
L: 121,
|
|
4197
4215
|
S: this,
|
|
4198
|
-
|
|
4216
|
+
A: [
|
|
4217
|
+
"transport",
|
|
4218
|
+
""
|
|
4219
|
+
]
|
|
4199
4220
|
});
|
|
4200
|
-
|
|
4201
|
-
this._server?.close();
|
|
4202
|
-
this._closed = true;
|
|
4221
|
+
await transport.transport.onSignal(signal);
|
|
4203
4222
|
}
|
|
4204
|
-
async
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
L: 85,
|
|
4223
|
+
async getDetails({ proxyId }) {
|
|
4224
|
+
const transport = this._openTransports.get(proxyId);
|
|
4225
|
+
(0, import_invariant14.invariant)(transport, void 0, {
|
|
4226
|
+
F: __dxlog_file16,
|
|
4227
|
+
L: 128,
|
|
4210
4228
|
S: this,
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
}
|
|
4216
|
-
const socket = new import_node_net.Socket();
|
|
4217
|
-
this._handleSocket(socket);
|
|
4218
|
-
socket.connect({
|
|
4219
|
-
port: payload.port,
|
|
4220
|
-
host: "localhost"
|
|
4229
|
+
A: [
|
|
4230
|
+
"transport",
|
|
4231
|
+
""
|
|
4232
|
+
]
|
|
4221
4233
|
});
|
|
4234
|
+
return {
|
|
4235
|
+
details: await transport.transport.getDetails()
|
|
4236
|
+
};
|
|
4222
4237
|
}
|
|
4223
|
-
async
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4238
|
+
async getStats({ proxyId }) {
|
|
4239
|
+
const transport = this._openTransports.get(proxyId);
|
|
4240
|
+
(0, import_invariant14.invariant)(transport, void 0, {
|
|
4241
|
+
F: __dxlog_file16,
|
|
4242
|
+
L: 135,
|
|
4243
|
+
S: this,
|
|
4244
|
+
A: [
|
|
4245
|
+
"transport",
|
|
4246
|
+
""
|
|
4247
|
+
]
|
|
4248
|
+
});
|
|
4232
4249
|
return {
|
|
4233
|
-
|
|
4234
|
-
bytesReceived: 0,
|
|
4235
|
-
packetsSent: 0,
|
|
4236
|
-
packetsReceived: 0
|
|
4250
|
+
stats: await transport.transport.getStats()
|
|
4237
4251
|
};
|
|
4238
4252
|
}
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
F: __dxlog_file17,
|
|
4245
|
-
L: 115,
|
|
4253
|
+
async sendData({ proxyId, payload }) {
|
|
4254
|
+
const transport = this._openTransports.get(proxyId);
|
|
4255
|
+
(0, import_invariant14.invariant)(transport, void 0, {
|
|
4256
|
+
F: __dxlog_file16,
|
|
4257
|
+
L: 142,
|
|
4246
4258
|
S: this,
|
|
4247
|
-
|
|
4259
|
+
A: [
|
|
4260
|
+
"transport",
|
|
4261
|
+
""
|
|
4262
|
+
]
|
|
4248
4263
|
});
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
(
|
|
4252
|
-
|
|
4264
|
+
const bufferHasSpace = transport.connectorStream.push(payload);
|
|
4265
|
+
if (!bufferHasSpace) {
|
|
4266
|
+
await new Promise((resolve) => {
|
|
4267
|
+
transport.writeProcessedCallbacks.push(resolve);
|
|
4268
|
+
});
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
async close({ proxyId }) {
|
|
4272
|
+
const transport = this._openTransports.get(proxyId);
|
|
4273
|
+
if (!transport) {
|
|
4274
|
+
return;
|
|
4275
|
+
}
|
|
4276
|
+
this._openTransports.delete(proxyId);
|
|
4277
|
+
await this._safeCloseTransport(transport);
|
|
4278
|
+
}
|
|
4279
|
+
async _safeCloseTransport(transport) {
|
|
4280
|
+
if (this._openTransports.get(transport.proxyId) === transport) {
|
|
4281
|
+
this._openTransports.delete(transport.proxyId);
|
|
4282
|
+
}
|
|
4283
|
+
transport.writeProcessedCallbacks.forEach((cb) => cb());
|
|
4284
|
+
try {
|
|
4285
|
+
await transport.transport.close();
|
|
4286
|
+
} catch (error) {
|
|
4287
|
+
import_log15.log.warn("transport close error", {
|
|
4288
|
+
message: error?.message
|
|
4253
4289
|
}, {
|
|
4254
|
-
F:
|
|
4255
|
-
L:
|
|
4290
|
+
F: __dxlog_file16,
|
|
4291
|
+
L: 172,
|
|
4256
4292
|
S: this,
|
|
4257
4293
|
C: (f, a) => f(...a)
|
|
4258
4294
|
});
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4295
|
+
}
|
|
4296
|
+
try {
|
|
4297
|
+
transport.connectorStream.end();
|
|
4298
|
+
} catch (error) {
|
|
4299
|
+
import_log15.log.warn("connectorStream close error", {
|
|
4300
|
+
message: error?.message
|
|
4301
|
+
}, {
|
|
4302
|
+
F: __dxlog_file16,
|
|
4303
|
+
L: 177,
|
|
4304
|
+
S: this,
|
|
4305
|
+
C: (f, a) => f(...a)
|
|
4306
|
+
});
|
|
4307
|
+
}
|
|
4308
|
+
(0, import_log15.log)("closed", void 0, {
|
|
4309
|
+
F: __dxlog_file16,
|
|
4310
|
+
L: 179,
|
|
4311
|
+
S: this,
|
|
4312
|
+
C: (f, a) => f(...a)
|
|
4266
4313
|
});
|
|
4267
|
-
this.connected.emit();
|
|
4268
|
-
this.options.stream.pipe(this._socket).pipe(this.options.stream);
|
|
4269
4314
|
}
|
|
4270
4315
|
};
|
|
4316
|
+
var createStateUpdater = (next) => {
|
|
4317
|
+
return (state, err) => {
|
|
4318
|
+
next({
|
|
4319
|
+
connection: {
|
|
4320
|
+
state,
|
|
4321
|
+
...err ? {
|
|
4322
|
+
error: err.message
|
|
4323
|
+
} : void 0
|
|
4324
|
+
}
|
|
4325
|
+
});
|
|
4326
|
+
};
|
|
4327
|
+
};
|
|
4271
4328
|
var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
4272
4329
|
return (params) => {
|
|
4273
4330
|
const teleport = new import_teleport.Teleport({
|
|
@@ -4297,26 +4354,21 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
|
4297
4354
|
ConnectionState,
|
|
4298
4355
|
EventType,
|
|
4299
4356
|
FullyConnectedTopology,
|
|
4300
|
-
LibDataChannelTransport,
|
|
4301
4357
|
MAX_CONCURRENT_INITIATING_CONNECTIONS,
|
|
4302
4358
|
MMSTTopology,
|
|
4303
4359
|
MemoryTransport,
|
|
4304
4360
|
MemoryTransportFactory,
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
SimplePeerTransportService,
|
|
4361
|
+
RtcTransportProxy,
|
|
4362
|
+
RtcTransportProxyFactory,
|
|
4363
|
+
RtcTransportService,
|
|
4309
4364
|
StarTopology,
|
|
4310
4365
|
Swarm,
|
|
4311
4366
|
SwarmMapper,
|
|
4312
4367
|
SwarmMessenger,
|
|
4313
4368
|
SwarmNetworkManager,
|
|
4314
|
-
TcpTransport,
|
|
4315
|
-
TcpTransportFactory,
|
|
4316
4369
|
TransportKind,
|
|
4317
4370
|
createIceProvider,
|
|
4318
|
-
|
|
4319
|
-
createSimplePeerTransportFactory,
|
|
4371
|
+
createRtcTransportFactory,
|
|
4320
4372
|
createTeleportProtocolFactory
|
|
4321
4373
|
});
|
|
4322
|
-
//# sourceMappingURL=chunk-
|
|
4374
|
+
//# sourceMappingURL=chunk-7ZWQLO5T.cjs.map
|