@dxos/network-manager 0.6.13-main.ed424a1 → 0.6.13

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.
Files changed (163) hide show
  1. package/dist/lib/browser/{chunk-MKIVP7G3.mjs → chunk-XYSYUN63.mjs} +1064 -1248
  2. package/dist/lib/browser/chunk-XYSYUN63.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +19 -10
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +32 -22
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-D6P7ACEM.cjs → chunk-4YAYC7WN.cjs} +1207 -1264
  8. package/dist/lib/node/chunk-4YAYC7WN.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +37 -27
  10. package/dist/lib/node/index.cjs.map +2 -2
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/testing/index.cjs +34 -24
  13. package/dist/lib/node/testing/index.cjs.map +3 -3
  14. package/dist/types/src/network-manager.d.ts +1 -2
  15. package/dist/types/src/network-manager.d.ts.map +1 -1
  16. package/dist/types/src/signal/ice.d.ts.map +1 -1
  17. package/dist/types/src/signal/integration.test.d.ts +2 -0
  18. package/dist/types/src/signal/integration.test.d.ts.map +1 -0
  19. package/dist/types/src/signal/swarm-messenger.test.d.ts +2 -0
  20. package/dist/types/src/signal/swarm-messenger.test.d.ts.map +1 -0
  21. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  22. package/dist/types/src/swarm/swarm.d.ts +1 -1
  23. package/dist/types/src/testing/test-builder.d.ts +2 -2
  24. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  25. package/dist/types/src/testing/test-wire-protocol.d.ts +2 -1
  26. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  27. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  28. package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
  29. package/dist/types/src/tests/tcp-transport.test.d.ts +2 -0
  30. package/dist/types/src/tests/tcp-transport.test.d.ts.map +1 -0
  31. package/dist/types/src/tests/utils.d.ts.map +1 -1
  32. package/dist/types/src/transport/index.d.ts +5 -1
  33. package/dist/types/src/transport/index.d.ts.map +1 -1
  34. package/dist/types/src/transport/libdatachannel-transport.d.ts +42 -0
  35. package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -0
  36. package/dist/types/src/transport/libdatachannel-transport.test.d.ts +2 -0
  37. package/dist/types/src/transport/libdatachannel-transport.test.d.ts.map +1 -0
  38. package/dist/types/src/transport/memory-transport.d.ts +2 -2
  39. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  40. package/dist/types/src/transport/memory-transport.test.d.ts +2 -0
  41. package/dist/types/src/transport/memory-transport.test.d.ts.map +1 -0
  42. package/dist/types/src/transport/simplepeer-simple-peer.d.ts +2 -0
  43. package/dist/types/src/transport/simplepeer-simple-peer.d.ts.map +1 -0
  44. package/dist/types/src/transport/simplepeer-transport-proxy-test.d.ts +2 -0
  45. package/dist/types/src/transport/simplepeer-transport-proxy-test.d.ts.map +1 -0
  46. package/dist/types/src/transport/{webrtc/rtc-transport-proxy.d.ts → simplepeer-transport-proxy.d.ts} +12 -10
  47. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -0
  48. package/dist/types/src/transport/{webrtc/rtc-transport-service.d.ts → simplepeer-transport-service.d.ts} +7 -9
  49. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -0
  50. package/dist/types/src/transport/simplepeer-transport.d.ts +36 -0
  51. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -0
  52. package/dist/types/src/transport/simplepeer-transport.test.d.ts +2 -0
  53. package/dist/types/src/transport/simplepeer-transport.test.d.ts.map +1 -0
  54. package/dist/types/src/transport/{tcp/tcp-transport.browser.d.ts → tcp-transport.browser.d.ts} +3 -3
  55. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -0
  56. package/dist/types/src/transport/{tcp/tcp-transport.d.ts → tcp-transport.d.ts} +3 -3
  57. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -0
  58. package/dist/types/src/transport/transport.d.ts +6 -7
  59. package/dist/types/src/transport/transport.d.ts.map +1 -1
  60. package/dist/types/src/transport/webrtc.d.ts +6 -0
  61. package/dist/types/src/transport/webrtc.d.ts.map +1 -0
  62. package/package.json +30 -55
  63. package/src/globals.d.ts +7 -0
  64. package/src/network-manager.ts +13 -5
  65. package/src/signal/ice.test.ts +3 -1
  66. package/src/signal/ice.ts +1 -6
  67. package/src/signal/{integration.node.test.ts → integration.test.ts} +15 -9
  68. package/src/signal/{swarm-messenger.node.test.ts → swarm-messenger.test.ts} +23 -13
  69. package/src/swarm/connection-limiter.test.ts +6 -3
  70. package/src/swarm/connection.test.ts +38 -63
  71. package/src/swarm/connection.ts +5 -5
  72. package/src/swarm/swarm.test.ts +12 -10
  73. package/src/swarm/swarm.ts +1 -1
  74. package/src/testing/test-builder.ts +29 -13
  75. package/src/testing/test-wire-protocol.ts +4 -1
  76. package/src/tests/basic-test-suite.ts +33 -34
  77. package/src/tests/memory-transport.test.ts +42 -40
  78. package/src/tests/property-test-suite.ts +22 -21
  79. package/src/tests/tcp-transport.test.ts +67 -0
  80. package/src/tests/utils.ts +2 -3
  81. package/src/tests/webrtc-transport.test.ts +9 -9
  82. package/src/transport/index.ts +5 -1
  83. package/src/transport/libdatachannel-transport.test.ts +100 -0
  84. package/src/transport/libdatachannel-transport.ts +376 -0
  85. package/src/transport/memory-transport.test.ts +74 -0
  86. package/src/transport/memory-transport.ts +0 -2
  87. package/src/transport/simplepeer-simple-peer.ts +26 -0
  88. package/src/transport/simplepeer-transport-proxy-test.ts +181 -0
  89. package/src/transport/simplepeer-transport-proxy.ts +246 -0
  90. package/src/transport/simplepeer-transport-service.ts +160 -0
  91. package/src/transport/simplepeer-transport.test.ts +61 -0
  92. package/src/transport/simplepeer-transport.ts +250 -0
  93. package/src/transport/{tcp/tcp-transport.browser.ts → tcp-transport.browser.ts} +3 -7
  94. package/src/transport/{tcp/tcp-transport.ts → tcp-transport.ts} +1 -3
  95. package/src/transport/transport.ts +7 -8
  96. package/src/transport/webrtc.ts +15 -0
  97. package/src/typings.d.ts +2 -8
  98. package/dist/lib/browser/chunk-GW3YM55A.mjs +0 -14
  99. package/dist/lib/browser/chunk-GW3YM55A.mjs.map +0 -7
  100. package/dist/lib/browser/chunk-MKIVP7G3.mjs.map +0 -7
  101. package/dist/lib/browser/transport/tcp/index.mjs +0 -39
  102. package/dist/lib/browser/transport/tcp/index.mjs.map +0 -7
  103. package/dist/lib/node/chunk-D6P7ACEM.cjs.map +0 -7
  104. package/dist/lib/node/transport/tcp/index.cjs +0 -191
  105. package/dist/lib/node/transport/tcp/index.cjs.map +0 -7
  106. package/dist/lib/node-esm/chunk-22DA2US6.mjs +0 -4373
  107. package/dist/lib/node-esm/chunk-22DA2US6.mjs.map +0 -7
  108. package/dist/lib/node-esm/index.mjs +0 -50
  109. package/dist/lib/node-esm/index.mjs.map +0 -7
  110. package/dist/lib/node-esm/meta.json +0 -1
  111. package/dist/lib/node-esm/testing/index.mjs +0 -279
  112. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  113. package/dist/lib/node-esm/transport/tcp/index.mjs +0 -159
  114. package/dist/lib/node-esm/transport/tcp/index.mjs.map +0 -7
  115. package/dist/types/src/signal/integration.node.test.d.ts +0 -2
  116. package/dist/types/src/signal/integration.node.test.d.ts.map +0 -1
  117. package/dist/types/src/signal/swarm-messenger.node.test.d.ts +0 -2
  118. package/dist/types/src/signal/swarm-messenger.node.test.d.ts.map +0 -1
  119. package/dist/types/src/tests/tcp-transport.node.test.d.ts +0 -2
  120. package/dist/types/src/tests/tcp-transport.node.test.d.ts.map +0 -1
  121. package/dist/types/src/transport/tcp/index.d.ts +0 -2
  122. package/dist/types/src/transport/tcp/index.d.ts.map +0 -1
  123. package/dist/types/src/transport/tcp/tcp-transport.browser.d.ts.map +0 -1
  124. package/dist/types/src/transport/tcp/tcp-transport.d.ts.map +0 -1
  125. package/dist/types/src/transport/webrtc/index.d.ts +0 -4
  126. package/dist/types/src/transport/webrtc/index.d.ts.map +0 -1
  127. package/dist/types/src/transport/webrtc/rtc-connection-factory.d.ts +0 -14
  128. package/dist/types/src/transport/webrtc/rtc-connection-factory.d.ts.map +0 -1
  129. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +0 -68
  130. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +0 -1
  131. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +0 -33
  132. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +0 -1
  133. package/dist/types/src/transport/webrtc/rtc-transport-channel.test.d.ts +0 -2
  134. package/dist/types/src/transport/webrtc/rtc-transport-channel.test.d.ts.map +0 -1
  135. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts +0 -4
  136. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +0 -1
  137. package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +0 -1
  138. package/dist/types/src/transport/webrtc/rtc-transport-proxy.test.d.ts +0 -2
  139. package/dist/types/src/transport/webrtc/rtc-transport-proxy.test.d.ts.map +0 -1
  140. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +0 -1
  141. package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts +0 -4
  142. package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts.map +0 -1
  143. package/dist/types/src/transport/webrtc/rtc-transport.test.d.ts +0 -2
  144. package/dist/types/src/transport/webrtc/rtc-transport.test.d.ts.map +0 -1
  145. package/dist/types/src/transport/webrtc/test-utils.d.ts +0 -5
  146. package/dist/types/src/transport/webrtc/test-utils.d.ts.map +0 -1
  147. package/dist/types/src/transport/webrtc/utils.d.ts +0 -3
  148. package/dist/types/src/transport/webrtc/utils.d.ts.map +0 -1
  149. package/src/tests/tcp-transport.node.test.ts +0 -65
  150. package/src/transport/tcp/index.ts +0 -5
  151. package/src/transport/webrtc/index.ts +0 -7
  152. package/src/transport/webrtc/rtc-connection-factory.ts +0 -82
  153. package/src/transport/webrtc/rtc-peer-connection.ts +0 -472
  154. package/src/transport/webrtc/rtc-transport-channel.test.ts +0 -176
  155. package/src/transport/webrtc/rtc-transport-channel.ts +0 -195
  156. package/src/transport/webrtc/rtc-transport-factory.ts +0 -28
  157. package/src/transport/webrtc/rtc-transport-proxy.test.ts +0 -413
  158. package/src/transport/webrtc/rtc-transport-proxy.ts +0 -264
  159. package/src/transport/webrtc/rtc-transport-service.ts +0 -192
  160. package/src/transport/webrtc/rtc-transport-stats.ts +0 -67
  161. package/src/transport/webrtc/rtc-transport.test.ts +0 -198
  162. package/src/transport/webrtc/test-utils.ts +0 -22
  163. package/src/transport/webrtc/utils.ts +0 -36
@@ -1,7 +1,17 @@
1
1
  import "@dxos/node-std/globals";
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // inject-globals:@inject-globals
2
10
  import {
3
- Buffer
4
- } from "./chunk-GW3YM55A.mjs";
11
+ global,
12
+ Buffer as Buffer2,
13
+ process
14
+ } from "@dxos/node-std/inject-globals";
5
15
 
6
16
  // packages/core/mesh/network-manager/src/swarm/connection.ts
7
17
  import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized, Trigger } from "@dxos/async";
@@ -10,7 +20,7 @@ import { ErrorStream } from "@dxos/debug";
10
20
  import { invariant } from "@dxos/invariant";
11
21
  import { PublicKey } from "@dxos/keys";
12
22
  import { log, logInfo } from "@dxos/log";
13
- import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, TimeoutError, trace } from "@dxos/protocols";
23
+ import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, TimeoutError, UnknownProtocolError, trace } from "@dxos/protocols";
14
24
  function _ts_decorate(decorators, target, key, desc) {
15
25
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
26
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -46,11 +56,11 @@ var Connection = class {
46
56
  this._callbacks = _callbacks;
47
57
  this._ctx = new Context(void 0, {
48
58
  F: __dxlog_file,
49
- L: 100
59
+ L: 101
50
60
  });
51
61
  this.connectedTimeoutContext = new Context(void 0, {
52
62
  F: __dxlog_file,
53
- L: 101
63
+ L: 102
54
64
  });
55
65
  this._protocolClosed = new Trigger();
56
66
  this._transportClosed = new Trigger();
@@ -73,7 +83,7 @@ var Connection = class {
73
83
  initiator: this.initiator
74
84
  }, {
75
85
  F: __dxlog_file,
76
- L: 137,
86
+ L: 138,
77
87
  S: this,
78
88
  C: (f, a) => f(...a)
79
89
  });
@@ -96,7 +106,7 @@ var Connection = class {
96
106
  async openConnection() {
97
107
  invariant(this._state === "INITIAL", "Invalid state.", {
98
108
  F: __dxlog_file,
99
- L: 167,
109
+ L: 168,
100
110
  S: this,
101
111
  A: [
102
112
  "this._state === ConnectionState.INITIAL",
@@ -107,7 +117,7 @@ var Connection = class {
107
117
  id: this._instanceId
108
118
  }), {
109
119
  F: __dxlog_file,
110
- L: 168,
120
+ L: 169,
111
121
  S: this,
112
122
  C: (f, a) => f(...a)
113
123
  });
@@ -119,7 +129,7 @@ var Connection = class {
119
129
  initiator: this.initiator
120
130
  }, {
121
131
  F: __dxlog_file,
122
- L: 169,
132
+ L: 170,
123
133
  S: this,
124
134
  C: (f, a) => f(...a)
125
135
  });
@@ -130,7 +140,7 @@ var Connection = class {
130
140
  this._protocol.stream.on("close", () => {
131
141
  log("protocol stream closed", void 0, {
132
142
  F: __dxlog_file,
133
- L: 186,
143
+ L: 187,
134
144
  S: this,
135
145
  C: (f, a) => f(...a)
136
146
  });
@@ -140,7 +150,7 @@ var Connection = class {
140
150
  scheduleTask(this.connectedTimeoutContext, async () => {
141
151
  log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
142
152
  F: __dxlog_file,
143
- L: 194,
153
+ L: 195,
144
154
  S: this,
145
155
  C: (f, a) => f(...a)
146
156
  });
@@ -148,7 +158,7 @@ var Connection = class {
148
158
  }, TRANSPORT_CONNECTION_TIMEOUT);
149
159
  invariant(!this._transport, void 0, {
150
160
  F: __dxlog_file,
151
- L: 202,
161
+ L: 203,
152
162
  S: this,
153
163
  A: [
154
164
  "!this._transport",
@@ -156,14 +166,12 @@ var Connection = class {
156
166
  ]
157
167
  });
158
168
  this._transport = this._transportFactory.createTransport({
159
- ownPeerKey: this.localInfo.peerKey,
160
- remotePeerKey: this.remoteInfo.peerKey,
161
- topic: this.topic.toHex(),
162
169
  initiator: this.initiator,
163
170
  stream: this._protocol.stream,
164
171
  sendSignal: async (signal) => this._sendSignal(signal),
165
172
  sessionId: this.sessionId
166
173
  });
174
+ await this._transport.open();
167
175
  this._transport.connected.once(async () => {
168
176
  this._changeState("CONNECTED");
169
177
  await this.connectedTimeoutContext.dispose();
@@ -209,13 +217,21 @@ var Connection = class {
209
217
  C: (f, a) => f(...a)
210
218
  });
211
219
  this.abort().catch((err2) => this.errors.raise(err2));
220
+ } else if (err instanceof UnknownProtocolError) {
221
+ log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
222
+ err
223
+ }, {
224
+ F: __dxlog_file,
225
+ L: 242,
226
+ S: this,
227
+ C: (f, a) => f(...a)
228
+ });
212
229
  }
213
230
  if (this._state !== "CLOSED" && this._state !== "CLOSING") {
214
231
  await this.connectedTimeoutContext.dispose();
215
232
  this.errors.raise(err);
216
233
  }
217
234
  });
218
- await this._transport.open();
219
235
  for (const signal of this._incomingSignalBuffer) {
220
236
  void this._transport.onSignal(signal);
221
237
  }
@@ -582,20 +598,15 @@ var createIceProvider = (iceProviders) => {
582
598
  }
583
599
  cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
584
600
  method: "GET"
585
- }), 1e4).then((response) => response.json()).catch((err) => {
586
- const isDev = typeof window !== "undefined" && window.location.href.includes("localhost");
587
- if (!isDev) {
588
- log2.error("Failed to fetch ICE servers from provider", {
589
- urls,
590
- err
591
- }, {
592
- F: __dxlog_file2,
593
- L: 30,
594
- S: void 0,
595
- C: (f, a) => f(...a)
596
- });
597
- }
598
- })))).filter(isNotNullOrUndefined).map(({ iceServers }) => iceServers).flat();
601
+ }), 1e4).then((response) => response.json()).catch((err) => log2.error("Failed to fetch ICE servers from provider", {
602
+ urls,
603
+ err
604
+ }, {
605
+ F: __dxlog_file2,
606
+ L: 27,
607
+ S: void 0,
608
+ C: (f, a) => f(...a)
609
+ }))))).filter(isNotNullOrUndefined).map(({ iceServers }) => iceServers).flat();
599
610
  return cachedIceServers;
600
611
  }
601
612
  };
@@ -2215,37 +2226,52 @@ var SwarmNetworkManager = class {
2215
2226
  /**
2216
2227
  * Join the swarm.
2217
2228
  */
2218
- async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
2229
+ async joinSwarm({ topic, peerInfo, topology, protocolProvider: protocol, label }) {
2219
2230
  invariant6(PublicKey8.isPublicKey(topic), void 0, {
2220
2231
  F: __dxlog_file8,
2221
- L: 160,
2232
+ L: 161,
2222
2233
  S: this,
2223
2234
  A: [
2224
2235
  "PublicKey.isPublicKey(topic)",
2225
2236
  ""
2226
2237
  ]
2227
2238
  });
2228
- invariant6(topology, void 0, {
2239
+ if (!peerInfo) {
2240
+ peerInfo = {
2241
+ peerKey: this._peerInfo?.peerKey ?? PublicKey8.random().toHex(),
2242
+ identityKey: this._peerInfo?.identityKey ?? PublicKey8.random().toHex()
2243
+ };
2244
+ }
2245
+ invariant6(PublicKey8.from(peerInfo.peerKey), void 0, {
2229
2246
  F: __dxlog_file8,
2230
- L: 161,
2247
+ L: 168,
2231
2248
  S: this,
2232
2249
  A: [
2233
- "topology",
2250
+ "PublicKey.from(peerInfo.peerKey)",
2234
2251
  ""
2235
2252
  ]
2236
2253
  });
2237
- invariant6(this._peerInfo, void 0, {
2254
+ invariant6(PublicKey8.from(peerInfo.identityKey), void 0, {
2238
2255
  F: __dxlog_file8,
2239
- L: 162,
2256
+ L: 169,
2257
+ S: this,
2258
+ A: [
2259
+ "PublicKey.from(peerInfo.identityKey!)",
2260
+ ""
2261
+ ]
2262
+ });
2263
+ invariant6(topology, void 0, {
2264
+ F: __dxlog_file8,
2265
+ L: 170,
2240
2266
  S: this,
2241
2267
  A: [
2242
- "this._peerInfo",
2268
+ "topology",
2243
2269
  ""
2244
2270
  ]
2245
2271
  });
2246
2272
  invariant6(typeof protocol === "function", void 0, {
2247
2273
  F: __dxlog_file8,
2248
- L: 163,
2274
+ L: 171,
2249
2275
  S: this,
2250
2276
  A: [
2251
2277
  "typeof protocol === 'function'",
@@ -2257,21 +2283,21 @@ var SwarmNetworkManager = class {
2257
2283
  }
2258
2284
  log8("joining", {
2259
2285
  topic: PublicKey8.from(topic),
2260
- peerInfo: this._peerInfo,
2286
+ peerInfo,
2261
2287
  topology: topology.toString()
2262
2288
  }, {
2263
2289
  F: __dxlog_file8,
2264
- L: 168,
2290
+ L: 176,
2265
2291
  S: this,
2266
2292
  C: (f, a) => f(...a)
2267
2293
  });
2268
- const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
2294
+ const swarm = new Swarm(topic, peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
2269
2295
  swarm.errors.handle((error) => {
2270
2296
  log8("swarm error", {
2271
2297
  error
2272
2298
  }, {
2273
2299
  F: __dxlog_file8,
2274
- L: 181,
2300
+ L: 189,
2275
2301
  S: this,
2276
2302
  C: (f, a) => f(...a)
2277
2303
  });
@@ -2281,10 +2307,10 @@ var SwarmNetworkManager = class {
2281
2307
  await swarm.open();
2282
2308
  this._signalConnection.join({
2283
2309
  topic,
2284
- peer: this._peerInfo
2310
+ peer: peerInfo
2285
2311
  }).catch((error) => log8.catch(error, void 0, {
2286
2312
  F: __dxlog_file8,
2287
- L: 190,
2313
+ L: 198,
2288
2314
  S: this,
2289
2315
  C: (f, a) => f(...a)
2290
2316
  }));
@@ -2295,7 +2321,7 @@ var SwarmNetworkManager = class {
2295
2321
  count: this._swarms.size
2296
2322
  }, {
2297
2323
  F: __dxlog_file8,
2298
- L: 194,
2324
+ L: 202,
2299
2325
  S: this,
2300
2326
  C: (f, a) => f(...a)
2301
2327
  });
@@ -2314,7 +2340,7 @@ var SwarmNetworkManager = class {
2314
2340
  topic: PublicKey8.from(topic)
2315
2341
  }, {
2316
2342
  F: __dxlog_file8,
2317
- L: 211,
2343
+ L: 219,
2318
2344
  S: this,
2319
2345
  C: (f, a) => f(...a)
2320
2346
  });
@@ -2335,7 +2361,7 @@ var SwarmNetworkManager = class {
2335
2361
  count: this._swarms.size
2336
2362
  }, {
2337
2363
  F: __dxlog_file8,
2338
- L: 225,
2364
+ L: 233,
2339
2365
  S: this,
2340
2366
  C: (f, a) => f(...a)
2341
2367
  });
@@ -2604,7 +2630,7 @@ var sortByXorDistance = (keys, reference) => {
2604
2630
  };
2605
2631
  var distXor = (a, b) => {
2606
2632
  const maxLength = Math.max(a.length, b.length);
2607
- const result = Buffer.allocUnsafe(maxLength);
2633
+ const result = Buffer2.allocUnsafe(maxLength);
2608
2634
  for (let i = 0; i < maxLength; i++) {
2609
2635
  result[i] = (a[i] || 0) ^ (b[i] || 0);
2610
2636
  }
@@ -2839,12 +2865,11 @@ var MemoryTransport = class _MemoryTransport {
2839
2865
  this.errors.raise(err);
2840
2866
  });
2841
2867
  }
2842
- return this;
2843
2868
  }
2844
2869
  async close() {
2845
2870
  log11("closing...", void 0, {
2846
2871
  F: __dxlog_file12,
2847
- L: 130,
2872
+ L: 129,
2848
2873
  S: this,
2849
2874
  C: (f, a) => f(...a)
2850
2875
  });
@@ -2865,18 +2890,17 @@ var MemoryTransport = class _MemoryTransport {
2865
2890
  this.closed.emit();
2866
2891
  log11("closed", void 0, {
2867
2892
  F: __dxlog_file12,
2868
- L: 158,
2893
+ L: 157,
2869
2894
  S: this,
2870
2895
  C: (f, a) => f(...a)
2871
2896
  });
2872
- return this;
2873
2897
  }
2874
2898
  async onSignal({ payload }) {
2875
2899
  log11("received signal", {
2876
2900
  payload
2877
2901
  }, {
2878
2902
  F: __dxlog_file12,
2879
- L: 163,
2903
+ L: 161,
2880
2904
  S: this,
2881
2905
  C: (f, a) => f(...a)
2882
2906
  });
@@ -2912,978 +2936,524 @@ var toError = (err) => err instanceof Error ? err : new Error(String(err));
2912
2936
  // packages/core/mesh/network-manager/src/transport/transport.ts
2913
2937
  var TransportKind;
2914
2938
  (function(TransportKind2) {
2915
- TransportKind2["WEB_RTC"] = "WEB-RTC";
2916
- TransportKind2["WEB_RTC_PROXY"] = "WEB-RTC_PROXY";
2939
+ TransportKind2["SIMPLE_PEER"] = "SIMPLE_PEER";
2940
+ TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
2941
+ TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
2917
2942
  TransportKind2["MEMORY"] = "MEMORY";
2918
2943
  TransportKind2["TCP"] = "TCP";
2919
2944
  })(TransportKind || (TransportKind = {}));
2920
2945
 
2921
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-connection-factory.ts
2922
- import { Mutex } from "@dxos/async";
2923
- var BrowserRtcConnectionFactory = class {
2924
- async initialize() {
2925
- }
2926
- async onConnectionDestroyed() {
2927
- }
2928
- async createConnection(config) {
2929
- return new RTCPeerConnection(config);
2930
- }
2931
- async initConnection(connection, info) {
2932
- }
2933
- };
2934
- var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
2935
- static {
2936
- this._createdConnections = 0;
2937
- }
2938
- static {
2939
- this._cleanupMutex = new Mutex();
2940
- }
2941
- // This should be inside the function to avoid triggering `eval` in the global scope.
2942
- // eslint-disable-next-line no-new-func
2943
- // TODO(burdon): Do imports here?
2944
- async initialize() {
2945
- }
2946
- async onConnectionDestroyed() {
2947
- return _NodeRtcConnectionFactory._cleanupMutex.executeSynchronized(async () => {
2948
- if (--_NodeRtcConnectionFactory._createdConnections === 0) {
2949
- (await import("#node-datachannel")).cleanup();
2950
- }
2951
- });
2952
- }
2953
- async createConnection(config) {
2954
- return _NodeRtcConnectionFactory._cleanupMutex.executeSynchronized(async () => {
2955
- const { RTCPeerConnection: RTCPeerConnection1 } = await import("#node-datachannel/polyfill");
2956
- _NodeRtcConnectionFactory._createdConnections++;
2957
- return new RTCPeerConnection1(config);
2958
- });
2959
- }
2960
- async initConnection(connection, info) {
2961
- if (info.initiator) {
2962
- connection.onnegotiationneeded?.(null);
2963
- }
2964
- }
2965
- };
2966
- var getRtcConnectionFactory = () => {
2967
- return typeof globalThis.RTCPeerConnection === "undefined" ? new NodeRtcConnectionFactory() : new BrowserRtcConnectionFactory();
2968
- };
2969
-
2970
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts
2971
- import { synchronized as synchronized5, Trigger as Trigger3, Mutex as Mutex2 } from "@dxos/async";
2972
- import { invariant as invariant12 } from "@dxos/invariant";
2973
- import { log as log13, logInfo as logInfo4 } from "@dxos/log";
2974
- import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
2975
- import { trace as trace4 } from "@dxos/tracing";
2976
-
2977
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts
2978
- import { Duplex } from "@dxos/node-std/stream";
2979
- import { Event as AsyncEvent } from "@dxos/async";
2980
- import { Resource } from "@dxos/context";
2981
- import { ErrorStream as ErrorStream4 } from "@dxos/debug";
2982
- import { invariant as invariant11 } from "@dxos/invariant";
2946
+ // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2947
+ import SimplePeerConstructor from "simple-peer";
2948
+ import invariant11 from "tiny-invariant";
2949
+ import { Event as Event8, synchronized as synchronized5 } from "@dxos/async";
2950
+ import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
2951
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
2983
2952
  import { log as log12 } from "@dxos/log";
2984
- import { ConnectivityError as ConnectivityError2 } from "@dxos/protocols";
2953
+ import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError2, ProtocolError as ProtocolError2, UnknownProtocolError as UnknownProtocolError2, trace as trace4 } from "@dxos/protocols";
2954
+
2955
+ // packages/core/mesh/network-manager/src/transport/webrtc.ts
2956
+ var wrtc = null;
2957
+ try {
2958
+ wrtc = __require("@koush/wrtc");
2959
+ } catch {
2960
+ }
2985
2961
 
2986
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-stats.ts
2987
- var describeSelectedRemoteCandidate = async (connection) => {
2988
- const stats = connection && await getRtcConnectionStats(connection);
2989
- const rc = stats?.remoteCandidate;
2990
- if (!rc) {
2991
- return "unavailable";
2962
+ // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2963
+ function _ts_decorate6(decorators, target, key, desc) {
2964
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2965
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2966
+ 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;
2967
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2968
+ }
2969
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2970
+ var createSimplePeerTransportFactory = (webrtcConfig, iceProvider) => ({
2971
+ createTransport: (options) => new SimplePeerTransport({
2972
+ ...options,
2973
+ webrtcConfig,
2974
+ iceProvider
2975
+ })
2976
+ });
2977
+ var SimplePeerTransport = class {
2978
+ get isOpen() {
2979
+ return this._piped && !this._closed;
2992
2980
  }
2993
- if (rc.candidateType === "relay") {
2994
- return `${rc.ip}:${rc.port} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
2981
+ /**
2982
+ * @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
2983
+ */
2984
+ constructor(_params) {
2985
+ this._params = _params;
2986
+ this._peer = void 0;
2987
+ this._closed = false;
2988
+ this._piped = false;
2989
+ this.closed = new Event8();
2990
+ this.connected = new Event8();
2991
+ this.errors = new ErrorStream4();
2992
+ this._instanceId = PublicKey10.random().toHex();
2995
2993
  }
2996
- return `${rc.ip}:${rc.port} ${rc.candidateType}`;
2997
- };
2998
- var createRtcTransportStats = async (connection, topic) => {
2999
- const stats = connection && await getRtcConnectionStats(connection, topic);
3000
- if (!stats) {
2994
+ async getStats() {
2995
+ const stats = await this._getStats();
2996
+ if (!stats) {
2997
+ return {
2998
+ bytesSent: 0,
2999
+ bytesReceived: 0,
3000
+ packetsSent: 0,
3001
+ packetsReceived: 0,
3002
+ rawStats: {}
3003
+ };
3004
+ }
3001
3005
  return {
3002
- bytesSent: 0,
3003
- bytesReceived: 0,
3004
- packetsSent: 0,
3005
- packetsReceived: 0,
3006
- rawStats: {}
3006
+ bytesSent: stats.transport.bytesSent,
3007
+ bytesReceived: stats.transport.bytesReceived,
3008
+ packetsSent: stats.transport.packetsSent,
3009
+ packetsReceived: stats.transport.packetsReceived,
3010
+ rawStats: stats.raw
3007
3011
  };
3008
3012
  }
3009
- return {
3010
- bytesSent: stats.dataChannel?.bytesSent,
3011
- bytesReceived: stats.dataChannel?.bytesReceived,
3012
- packetsSent: 0,
3013
- packetsReceived: 0,
3014
- rawStats: stats.raw
3015
- };
3016
- };
3017
- var getRtcConnectionStats = async (connection, channelTopic) => {
3018
- const stats = await connection.getStats();
3019
- const statsEntries = Array.from(stats.entries());
3020
- const transport = statsEntries.find(([_, entry]) => entry.type === "transport")?.[1];
3021
- const selectedCandidatePair = transport && statsEntries.find(([entryId]) => entryId === transport.selectedCandidatePairId)?.[1];
3022
- const remoteCandidate = selectedCandidatePair && statsEntries.find(([entryId]) => entryId === selectedCandidatePair.remoteCandidateId)?.[1];
3023
- const dataChannel = channelTopic && statsEntries.find(([_, entry]) => entry.type === "data-channel" && entry.label === channelTopic)?.[1];
3024
- return {
3025
- transport,
3026
- selectedCandidatePair,
3027
- dataChannel,
3028
- remoteCandidate,
3029
- raw: Object.fromEntries(stats)
3030
- };
3031
- };
3032
-
3033
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts
3034
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
3035
- var MAX_MESSAGE_SIZE = 64 * 1024;
3036
- var MAX_BUFFERED_AMOUNT = 64 * 1024;
3037
- var RtcTransportChannel = class extends Resource {
3038
- constructor(_connection, _options) {
3039
- super();
3040
- this._connection = _connection;
3041
- this._options = _options;
3042
- this.closed = new AsyncEvent();
3043
- this.connected = new AsyncEvent();
3044
- this.errors = new ErrorStream4();
3045
- this._streamDataFlushedCallback = null;
3046
- this._isChannelCreationInProgress = false;
3047
- }
3048
- get isRtcChannelCreationInProgress() {
3049
- return this._isChannelCreationInProgress;
3013
+ async _getStats() {
3014
+ if (typeof this._peer?._pc?.getStats !== "function") {
3015
+ return null;
3016
+ }
3017
+ return await this._peer._pc.getStats().then((stats) => {
3018
+ const statsEntries = Array.from(stats.entries());
3019
+ const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
3020
+ const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
3021
+ let selectedCandidatePair;
3022
+ let remoteCandidate;
3023
+ if (candidatePair.length > 0) {
3024
+ selectedCandidatePair = candidatePair[0][1];
3025
+ remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
3026
+ }
3027
+ return {
3028
+ datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
3029
+ transport,
3030
+ selectedCandidatePair,
3031
+ remoteCandidate,
3032
+ raw: Object.fromEntries(stats.entries())
3033
+ };
3034
+ });
3050
3035
  }
3051
- onConnectionError(error) {
3052
- if (this.isOpen) {
3053
- this.errors.raise(error);
3036
+ async getDetails() {
3037
+ const stats = await this._getStats();
3038
+ const rc = stats?.remoteCandidate;
3039
+ if (!rc) {
3040
+ return "unavailable";
3041
+ }
3042
+ if (rc.candidateType === "relay") {
3043
+ return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
3054
3044
  }
3045
+ return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
3055
3046
  }
3056
- async _open() {
3057
- invariant11(!this._isChannelCreationInProgress, void 0, {
3047
+ async open() {
3048
+ log12.trace("dxos.mesh.webrtc-transport.open", trace4.begin({
3049
+ id: this._instanceId
3050
+ }), {
3058
3051
  F: __dxlog_file13,
3059
- L: 56,
3052
+ L: 122,
3060
3053
  S: this,
3061
- A: [
3062
- "!this._isChannelCreationInProgress",
3063
- ""
3064
- ]
3065
- });
3066
- this._isChannelCreationInProgress = true;
3067
- this._connection.createDataChannel(this._options.topic).then((channel) => {
3068
- if (this.isOpen) {
3069
- this._channel = channel;
3070
- this._initChannel(this._channel);
3071
- } else {
3072
- this._safeCloseChannel(channel);
3073
- }
3074
- }).catch((err) => {
3075
- if (this.isOpen) {
3076
- this.errors.raise(new ConnectivityError2(`Failed to create a channel: ${err?.message ?? "unknown reason."}`));
3077
- }
3078
- }).finally(() => {
3079
- this._isChannelCreationInProgress = false;
3054
+ C: (f, a) => f(...a)
3080
3055
  });
3081
- }
3082
- async _close() {
3083
- if (this._channel) {
3084
- this._safeCloseChannel(this._channel);
3085
- this._channel = void 0;
3086
- this._stream = void 0;
3087
- }
3088
- this.closed.emit();
3089
- log12("closed", void 0, {
3056
+ log12("created connection", {
3057
+ params: this._params
3058
+ }, {
3090
3059
  F: __dxlog_file13,
3091
- L: 86,
3060
+ L: 123,
3092
3061
  S: this,
3093
3062
  C: (f, a) => f(...a)
3094
3063
  });
3095
- }
3096
- _initChannel(channel) {
3097
- Object.assign(channel, {
3098
- onopen: () => {
3099
- if (!this.isOpen) {
3100
- log12.warn("channel opened in a closed transport", {
3101
- topic: this._options.topic
3064
+ const providedIceServers = await this._params.iceProvider?.getIceServers();
3065
+ if (!this._params.webrtcConfig) {
3066
+ this._params.webrtcConfig = {};
3067
+ }
3068
+ this._params.webrtcConfig.iceServers = [
3069
+ ...this._params.webrtcConfig.iceServers ?? [],
3070
+ ...providedIceServers ?? []
3071
+ ];
3072
+ this._peer = new SimplePeerConstructor({
3073
+ channelName: "dxos.mesh.transport",
3074
+ initiator: this._params.initiator,
3075
+ wrtc: SimplePeerConstructor.WEBRTC_SUPPORT ? void 0 : wrtc ?? raise2(new Error("wrtc not available")),
3076
+ config: this._params.webrtcConfig
3077
+ });
3078
+ this._peer.on("signal", async (data) => {
3079
+ log12("signal", data, {
3080
+ F: __dxlog_file13,
3081
+ L: 142,
3082
+ S: this,
3083
+ C: (f, a) => f(...a)
3084
+ });
3085
+ await this._params.sendSignal({
3086
+ payload: {
3087
+ data
3088
+ }
3089
+ });
3090
+ });
3091
+ this._peer.on("connect", () => {
3092
+ log12("connected", void 0, {
3093
+ F: __dxlog_file13,
3094
+ L: 147,
3095
+ S: this,
3096
+ C: (f, a) => f(...a)
3097
+ });
3098
+ this._params.stream.pipe(this._peer).pipe(this._params.stream);
3099
+ this._piped = true;
3100
+ this.connected.emit();
3101
+ });
3102
+ this._peer.on("close", async () => {
3103
+ log12("closed", void 0, {
3104
+ F: __dxlog_file13,
3105
+ L: 154,
3106
+ S: this,
3107
+ C: (f, a) => f(...a)
3108
+ });
3109
+ await this.close();
3110
+ });
3111
+ this._peer.on("error", async (err) => {
3112
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
3113
+ if (err.errorDetail === "sctp-failure") {
3114
+ this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
3115
+ } else {
3116
+ log12.info("unknown RTCError", {
3117
+ err
3102
3118
  }, {
3103
3119
  F: __dxlog_file13,
3104
- L: 93,
3120
+ L: 165,
3105
3121
  S: this,
3106
3122
  C: (f, a) => f(...a)
3107
3123
  });
3108
- this._safeCloseChannel(channel);
3109
- return;
3124
+ this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
3110
3125
  }
3111
- log12("onopen", void 0, {
3126
+ } else if ("code" in err) {
3127
+ log12.info("simple-peer error", err, {
3112
3128
  F: __dxlog_file13,
3113
- L: 98,
3129
+ L: 170,
3114
3130
  S: this,
3115
3131
  C: (f, a) => f(...a)
3116
3132
  });
3117
- const duplex = new Duplex({
3118
- read: () => {
3119
- },
3120
- write: (chunk, encoding, callback) => {
3121
- return this._handleChannelWrite(chunk, callback);
3122
- }
3123
- });
3124
- duplex.pipe(this._options.stream).pipe(duplex);
3125
- this._stream = duplex;
3126
- this.connected.emit();
3127
- },
3128
- onclose: async () => {
3129
- log12("onclose", void 0, {
3133
+ switch (err.code) {
3134
+ case "ERR_WEBRTC_SUPPORT":
3135
+ this.errors.raise(new ProtocolError2("WebRTC not supported", err));
3136
+ break;
3137
+ case "ERR_SIGNALING":
3138
+ this.errors.raise(new ConnectivityError2("signaling failure", err));
3139
+ break;
3140
+ case "ERR_ICE_CONNECTION_FAILURE":
3141
+ case "ERR_DATA_CHANNEL":
3142
+ case "ERR_CONNECTION_FAILURE":
3143
+ this.errors.raise(new ConnectivityError2("unknown communication failure", err));
3144
+ break;
3145
+ // errors due to library issues or improper API usage
3146
+ case "ERR_CREATE_OFFER":
3147
+ case "ERR_CREATE_ANSWER":
3148
+ case "ERR_SET_LOCAL_DESCRIPTION":
3149
+ case "ERR_SET_REMOTE_DESCRIPTION":
3150
+ case "ERR_ADD_ICE_CANDIDATE":
3151
+ this.errors.raise(new UnknownProtocolError2("unknown simple-peer library failure", err));
3152
+ break;
3153
+ default:
3154
+ this.errors.raise(new Error("unknown simple-peer error"));
3155
+ break;
3156
+ }
3157
+ } else {
3158
+ log12.info("unknown peer connection error", err, {
3130
3159
  F: __dxlog_file13,
3131
- L: 111,
3160
+ L: 196,
3132
3161
  S: this,
3133
3162
  C: (f, a) => f(...a)
3134
3163
  });
3135
- await this.close();
3136
- },
3137
- onmessage: (event) => {
3138
- if (!this._stream) {
3139
- log12.warn("ignoring message on a closed channel", void 0, {
3140
- F: __dxlog_file13,
3141
- L: 117,
3142
- S: this,
3143
- C: (f, a) => f(...a)
3164
+ this.errors.raise(err);
3165
+ }
3166
+ try {
3167
+ if (typeof this._peer?._pc?.getStats === "function") {
3168
+ this._peer._pc.getStats().then((stats) => {
3169
+ log12.info("report after webrtc error", {
3170
+ config: this._params.webrtcConfig,
3171
+ stats: Object.fromEntries(stats.entries())
3172
+ }, {
3173
+ F: __dxlog_file13,
3174
+ L: 204,
3175
+ S: this,
3176
+ C: (f, a) => f(...a)
3177
+ });
3144
3178
  });
3145
- return;
3146
3179
  }
3147
- let data = event.data;
3148
- if (data instanceof ArrayBuffer) {
3149
- data = Buffer.from(data);
3150
- }
3151
- this._stream.push(data);
3152
- },
3153
- onerror: (event) => {
3154
- if (this.isOpen) {
3155
- const err = event.error instanceof Error ? event.error : new Error(`Datachannel error: ${event.type}.`);
3156
- this.errors.raise(err);
3157
- }
3158
- },
3159
- onbufferedamountlow: () => {
3160
- const cb = this._streamDataFlushedCallback;
3161
- this._streamDataFlushedCallback = null;
3162
- cb?.();
3163
- }
3164
- });
3165
- }
3166
- async _handleChannelWrite(chunk, callback) {
3167
- if (!this._channel) {
3168
- log12.warn("writing to a channel after a connection was closed", void 0, {
3169
- F: __dxlog_file13,
3170
- L: 145,
3171
- S: this,
3172
- C: (f, a) => f(...a)
3173
- });
3174
- return;
3175
- }
3176
- if (chunk.length > MAX_MESSAGE_SIZE) {
3177
- const error = new Error(`Message too large: ${chunk.length} > ${MAX_MESSAGE_SIZE}.`);
3178
- this.errors.raise(error);
3179
- callback();
3180
- return;
3181
- }
3182
- try {
3183
- this._channel.send(chunk);
3184
- } catch (err) {
3185
- this.errors.raise(err);
3186
- callback();
3187
- return;
3188
- }
3189
- if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3190
- if (this._streamDataFlushedCallback !== null) {
3191
- log12.error("consumer trying to write before we are ready for more data", void 0, {
3180
+ } catch (err2) {
3181
+ log12.catch(err2, void 0, {
3192
3182
  F: __dxlog_file13,
3193
- L: 166,
3183
+ L: 211,
3194
3184
  S: this,
3195
3185
  C: (f, a) => f(...a)
3196
3186
  });
3197
3187
  }
3198
- this._streamDataFlushedCallback = callback;
3199
- } else {
3200
- callback();
3201
- }
3188
+ await this.close();
3189
+ });
3190
+ log12.trace("dxos.mesh.webrtc-transport.open", trace4.end({
3191
+ id: this._instanceId
3192
+ }), {
3193
+ F: __dxlog_file13,
3194
+ L: 217,
3195
+ S: this,
3196
+ C: (f, a) => f(...a)
3197
+ });
3202
3198
  }
3203
- _safeCloseChannel(channel) {
3204
- try {
3205
- channel.close();
3206
- } catch (error) {
3207
- log12.catch(error, void 0, {
3208
- F: __dxlog_file13,
3209
- L: 178,
3210
- S: this,
3211
- C: (f, a) => f(...a)
3212
- });
3199
+ async close() {
3200
+ log12("closing...", void 0, {
3201
+ F: __dxlog_file13,
3202
+ L: 222,
3203
+ S: this,
3204
+ C: (f, a) => f(...a)
3205
+ });
3206
+ if (this._closed) {
3207
+ return;
3213
3208
  }
3209
+ this._disconnectStreams();
3210
+ this._peer.destroy();
3211
+ this._closed = true;
3212
+ this.closed.emit();
3213
+ log12("closed", void 0, {
3214
+ F: __dxlog_file13,
3215
+ L: 230,
3216
+ S: this,
3217
+ C: (f, a) => f(...a)
3218
+ });
3214
3219
  }
3215
- onSignal(signal) {
3216
- return this._connection.onSignal(signal);
3217
- }
3218
- async getDetails() {
3219
- return describeSelectedRemoteCandidate(this._connection.currentConnection);
3220
- }
3221
- async getStats() {
3222
- return createRtcTransportStats(this._connection.currentConnection, this._options.topic);
3223
- }
3224
- };
3225
-
3226
- // packages/core/mesh/network-manager/src/transport/webrtc/utils.ts
3227
- var chooseInitiatorPeer = (peer1Key, peer2Key) => peer1Key < peer2Key ? peer1Key : peer2Key;
3228
- var areSdpEqual = (sdp1, sdp2) => {
3229
- const sdp1Lines = deduplicatedSdpLines(sdp1);
3230
- const sdp2Lines = deduplicatedSdpLines(sdp2);
3231
- if (sdp1Lines.length !== sdp2Lines.length) {
3232
- return false;
3233
- }
3234
- return sdp1Lines.every((line, idx) => line === sdp2Lines[idx]);
3235
- };
3236
- var deduplicatedSdpLines = (sdp) => {
3237
- const deduplicatedLines = [];
3238
- const seenLines = [];
3239
- for (const line of sdp.split("\r\n")) {
3240
- if (line.startsWith("m")) {
3241
- seenLines.length = 0;
3220
+ async onSignal(signal) {
3221
+ if (this._closed) {
3222
+ return;
3242
3223
  }
3243
- if (seenLines.includes(line)) {
3244
- continue;
3224
+ invariant11(signal.payload.data, "Signal message must contain signal data.");
3225
+ invariant11(this._peer, "Peer must be initialized before receiving signals.");
3226
+ this._peer.signal(signal.payload.data);
3227
+ }
3228
+ _disconnectStreams() {
3229
+ if (this._piped) {
3230
+ this._params.stream.unpipe?.(this._peer)?.unpipe?.(this._params.stream);
3245
3231
  }
3246
- seenLines.push(line);
3247
- deduplicatedLines.push(line);
3248
3232
  }
3249
- return deduplicatedLines;
3250
3233
  };
3234
+ _ts_decorate6([
3235
+ synchronized5
3236
+ ], SimplePeerTransport.prototype, "open", null);
3237
+ _ts_decorate6([
3238
+ synchronized5
3239
+ ], SimplePeerTransport.prototype, "close", null);
3240
+ _ts_decorate6([
3241
+ synchronized5
3242
+ ], SimplePeerTransport.prototype, "onSignal", null);
3251
3243
 
3252
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts
3253
- function _ts_decorate6(decorators, target, key, desc) {
3254
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3255
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3256
- 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;
3257
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3258
- }
3259
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3260
- var RtcPeerConnection = class {
3261
- constructor(_factory, _options) {
3262
- this._factory = _factory;
3263
- this._options = _options;
3264
- this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
3265
- this._transportChannels = /* @__PURE__ */ new Map();
3266
- this._dataChannels = /* @__PURE__ */ new Map();
3267
- this._readyForCandidates = new Trigger3();
3268
- this._offerProcessingMutex = new Mutex2();
3269
- this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
3270
- }
3271
- get transportChannelCount() {
3272
- return this._transportChannels.size;
3273
- }
3274
- get currentConnection() {
3275
- return this._connection;
3276
- }
3277
- async createDataChannel(topic) {
3278
- const connection = await this._openConnection();
3279
- if (!this._transportChannels.has(topic)) {
3280
- if (!this._transportChannels.size) {
3281
- this._lockAndCloseConnection();
3282
- }
3283
- throw new Error("Transport closed while connection was being open");
3284
- }
3285
- if (this._initiator) {
3286
- const channel = connection.createDataChannel(topic);
3287
- this._dataChannels.set(topic, channel);
3288
- return channel;
3289
- } else {
3290
- const existingChannel = this._dataChannels.get(topic);
3291
- if (existingChannel) {
3292
- return existingChannel;
3293
- }
3294
- log13("waiting for initiator-peer to open a data channel", void 0, {
3295
- F: __dxlog_file14,
3296
- L: 90,
3297
- S: this,
3298
- C: (f, a) => f(...a)
3299
- });
3300
- return new Promise((resolve, reject) => {
3301
- this._channelCreatedCallbacks.set(topic, {
3302
- resolve,
3303
- reject
3304
- });
3305
- });
3306
- }
3307
- }
3308
- createTransportChannel(options) {
3309
- const channel = new RtcTransportChannel(this, options);
3310
- this._transportChannels.set(options.topic, channel);
3311
- channel.closed.on(() => {
3312
- this._transportChannels.delete(options.topic);
3313
- if (this._transportChannels.size === 0) {
3314
- this._lockAndCloseConnection();
3315
- }
3316
- });
3317
- return channel;
3244
+ // packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts
3245
+ import { Duplex } from "@dxos/node-std/stream";
3246
+ import { Stream } from "@dxos/codec-protobuf";
3247
+ import { invariant as invariant12 } from "@dxos/invariant";
3248
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
3249
+ import { log as log13 } from "@dxos/log";
3250
+ import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3251
+ import { ComplexMap as ComplexMap8 } from "@dxos/util";
3252
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3253
+ var SimplePeerTransportService = class {
3254
+ constructor(_webrtcConfig, _iceProvider) {
3255
+ this._webrtcConfig = _webrtcConfig;
3256
+ this._iceProvider = _iceProvider;
3257
+ this.transports = new ComplexMap8(PublicKey11.hash);
3318
3258
  }
3319
- async _openConnection() {
3320
- if (this._connection) {
3321
- return this._connection;
3322
- }
3323
- log13("initializing connection...", () => ({
3324
- remotePeer: this._options.remotePeerKey
3325
- }), {
3326
- F: __dxlog_file14,
3327
- L: 115,
3328
- S: this,
3329
- C: (f, a) => f(...a)
3330
- });
3331
- const config = await this._loadConnectionConfig();
3332
- const connection = await this._factory.createConnection(config);
3333
- const iceCandidateErrors = [];
3334
- Object.assign(connection, {
3335
- onnegotiationneeded: async () => {
3336
- invariant12(this._initiator, void 0, {
3337
- F: __dxlog_file14,
3338
- L: 130,
3339
- S: this,
3340
- A: [
3341
- "this._initiator",
3342
- ""
3343
- ]
3344
- });
3345
- if (connection !== this._connection) {
3346
- this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
3347
- return;
3348
- }
3349
- log13("onnegotiationneeded", void 0, {
3350
- F: __dxlog_file14,
3351
- L: 137,
3352
- S: this,
3353
- C: (f, a) => f(...a)
3354
- });
3355
- try {
3356
- const offer = await connection.createOffer();
3357
- await connection.setLocalDescription(offer);
3358
- await this._sendDescription(connection, offer);
3359
- } catch (err) {
3360
- this._lockAndAbort(connection, err);
3361
- }
3362
- },
3363
- // When ICE candidate identified (should be sent to remote peer) and when ICE gathering finalized.
3364
- // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/icecandidate_event
3365
- onicecandidate: async (event) => {
3366
- if (connection !== this._connection) {
3367
- this._onConnectionCallbackAfterClose("onicecandidate", connection);
3368
- return;
3369
- }
3370
- if (event.candidate) {
3371
- log13("onicecandidate", {
3372
- candidate: event.candidate.candidate
3373
- }, {
3374
- F: __dxlog_file14,
3375
- L: 156,
3376
- S: this,
3377
- C: (f, a) => f(...a)
3378
- });
3379
- await this._sendIceCandidate(event.candidate);
3380
- } else {
3381
- log13("onicecandidate gathering complete", void 0, {
3382
- F: __dxlog_file14,
3383
- L: 159,
3384
- S: this,
3385
- C: (f, a) => f(...a)
3259
+ open(request) {
3260
+ const rpcStream = new Stream(({ ready, next, close }) => {
3261
+ const duplex = new Duplex({
3262
+ read: () => {
3263
+ const callbacks = [
3264
+ ...transportState.writeCallbacks
3265
+ ];
3266
+ transportState.writeCallbacks.length = 0;
3267
+ for (const cb of callbacks) {
3268
+ cb();
3269
+ }
3270
+ },
3271
+ write: function(chunk, _, callback) {
3272
+ next({
3273
+ data: {
3274
+ payload: chunk
3275
+ }
3386
3276
  });
3277
+ callback();
3387
3278
  }
3388
- },
3389
- // When error occurs while performing ICE negotiations through a STUN or TURN server.
3390
- // It's ok for some candidates to fail if a working pair is eventually found.
3391
- // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/icecandidateerror_event
3392
- onicecandidateerror: (event) => {
3393
- const { url, errorCode, errorText } = event;
3394
- iceCandidateErrors.push({
3395
- url,
3396
- errorCode,
3397
- errorText
3398
- });
3399
- },
3400
- // When possible error during ICE gathering.
3401
- // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceconnectionstatechange_event
3402
- oniceconnectionstatechange: () => {
3403
- if (connection !== this._connection) {
3404
- this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
3405
- return;
3406
- }
3407
- log13("oniceconnectionstatechange", {
3408
- state: connection.iceConnectionState
3409
- }, {
3410
- F: __dxlog_file14,
3411
- L: 179,
3412
- S: this,
3413
- C: (f, a) => f(...a)
3414
- });
3415
- if (connection.iceConnectionState === "failed") {
3416
- this._lockAndAbort(connection, createIceFailureError(iceCandidateErrors));
3279
+ });
3280
+ const transport = new SimplePeerTransport({
3281
+ initiator: request.initiator,
3282
+ stream: duplex,
3283
+ webrtcConfig: this._webrtcConfig,
3284
+ sendSignal: async (signal) => {
3285
+ next({
3286
+ signal: {
3287
+ payload: signal
3288
+ }
3289
+ });
3290
+ },
3291
+ iceProvider: this._iceProvider
3292
+ });
3293
+ void transport.open();
3294
+ next({
3295
+ connection: {
3296
+ state: ConnectionState3.CONNECTING
3417
3297
  }
3418
- },
3419
- // When new track (or channel) is added.
3420
- // State: { new, connecting, connected, disconnected, failed, closed }
3421
- // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionstatechange_event
3422
- onconnectionstatechange: () => {
3423
- if (connection !== this._connection) {
3424
- if (connection.connectionState !== "closed" && connection.connectionState !== "failed") {
3425
- this._onConnectionCallbackAfterClose("onconnectionstatechange", connection);
3298
+ });
3299
+ transport.connected.on(() => {
3300
+ next({
3301
+ connection: {
3302
+ state: ConnectionState3.CONNECTED
3426
3303
  }
3427
- return;
3428
- }
3429
- log13("onconnectionstatechange", {
3430
- state: connection.connectionState
3431
- }, {
3432
- F: __dxlog_file14,
3433
- L: 196,
3434
- S: this,
3435
- C: (f, a) => f(...a)
3436
3304
  });
3437
- if (connection.connectionState === "failed") {
3438
- this._lockAndAbort(connection, new Error("Connection failed."));
3439
- }
3440
- },
3441
- onsignalingstatechange: () => {
3442
- log13("onsignalingstatechange", {
3443
- state: connection.signalingState
3444
- }, {
3445
- F: __dxlog_file14,
3446
- L: 203,
3447
- S: this,
3448
- C: (f, a) => f(...a)
3449
- });
3450
- },
3451
- // When channel is added to connection.
3452
- // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
3453
- ondatachannel: (event) => {
3454
- invariant12(!this._initiator, "Initiator is expected to create data channels.", {
3455
- F: __dxlog_file14,
3456
- L: 209,
3457
- S: this,
3458
- A: [
3459
- "!this._initiator",
3460
- "'Initiator is expected to create data channels.'"
3461
- ]
3305
+ });
3306
+ transport.errors.handle((err) => {
3307
+ next({
3308
+ connection: {
3309
+ state: ConnectionState3.CLOSED,
3310
+ error: err.toString()
3311
+ }
3462
3312
  });
3463
- if (connection !== this._connection) {
3464
- this._onConnectionCallbackAfterClose("ondatachannel", connection);
3465
- return;
3466
- }
3467
- log13("ondatachannel", {
3468
- label: event.channel.label
3469
- }, {
3470
- F: __dxlog_file14,
3471
- L: 216,
3472
- S: this,
3473
- C: (f, a) => f(...a)
3313
+ close(err);
3314
+ });
3315
+ transport.closed.on(() => {
3316
+ next({
3317
+ connection: {
3318
+ state: ConnectionState3.CLOSED
3319
+ }
3474
3320
  });
3475
- this._dataChannels.set(event.channel.label, event.channel);
3476
- const pendingCallback = this._channelCreatedCallbacks.get(event.channel.label);
3477
- if (pendingCallback) {
3478
- this._channelCreatedCallbacks.delete(event.channel.label);
3479
- pendingCallback.resolve(event.channel);
3480
- }
3481
- }
3482
- });
3483
- this._connection = connection;
3484
- this._readyForCandidates.reset();
3485
- await this._factory.initConnection(connection, {
3486
- initiator: this._initiator
3321
+ close();
3322
+ });
3323
+ const transportState = {
3324
+ transport,
3325
+ stream: duplex,
3326
+ writeCallbacks: [],
3327
+ state: "OPEN"
3328
+ };
3329
+ ready();
3330
+ this.transports.set(request.proxyId, transportState);
3487
3331
  });
3488
- return this._connection;
3489
- }
3490
- _lockAndAbort(connection, error) {
3491
- this._abortConnection(connection, error);
3332
+ return rpcStream;
3492
3333
  }
3493
- _abortConnection(connection, error) {
3494
- if (connection !== this._connection) {
3495
- log13.error("attempted to abort an inactive connection", {
3496
- error
3497
- }, {
3498
- F: __dxlog_file14,
3499
- L: 241,
3500
- S: this,
3501
- C: (f, a) => f(...a)
3502
- });
3503
- this._safeCloseConnection(connection);
3504
- return;
3505
- }
3506
- for (const [topic, pendingCallback] of this._channelCreatedCallbacks.entries()) {
3507
- pendingCallback.reject(error);
3508
- this._transportChannels.delete(topic);
3509
- }
3510
- this._channelCreatedCallbacks.clear();
3511
- for (const channel of this._transportChannels.values()) {
3512
- channel.onConnectionError(error);
3513
- }
3514
- this._transportChannels.clear();
3515
- this._safeCloseConnection();
3516
- log13("connection aborted", {
3517
- reason: error.message
3518
- }, {
3334
+ async sendSignal({ proxyId, signal }) {
3335
+ invariant12(this.transports.has(proxyId), void 0, {
3519
3336
  F: __dxlog_file14,
3520
- L: 255,
3337
+ L: 124,
3521
3338
  S: this,
3522
- C: (f, a) => f(...a)
3339
+ A: [
3340
+ "this.transports.has(proxyId)",
3341
+ ""
3342
+ ]
3523
3343
  });
3344
+ await this.transports.get(proxyId).transport.onSignal(signal);
3524
3345
  }
3525
- _lockAndCloseConnection() {
3526
- invariant12(this._transportChannels.size === 0, void 0, {
3346
+ async getDetails({ proxyId }) {
3347
+ invariant12(this.transports.has(proxyId), void 0, {
3527
3348
  F: __dxlog_file14,
3528
- L: 260,
3349
+ L: 129,
3529
3350
  S: this,
3530
3351
  A: [
3531
- "this._transportChannels.size === 0",
3352
+ "this.transports.has(proxyId)",
3532
3353
  ""
3533
3354
  ]
3534
3355
  });
3535
- if (this._connection) {
3536
- this._safeCloseConnection();
3537
- log13("connection closed", void 0, {
3538
- F: __dxlog_file14,
3539
- L: 263,
3540
- S: this,
3541
- C: (f, a) => f(...a)
3542
- });
3543
- }
3356
+ return {
3357
+ details: await this.transports.get(proxyId).transport.getDetails()
3358
+ };
3544
3359
  }
3545
- async onSignal(signal) {
3546
- const connection = this._connection;
3547
- if (!connection) {
3548
- log13.warn("a signal ignored because the connection was closed", {
3549
- type: signal.payload.data.type
3550
- }, {
3551
- F: __dxlog_file14,
3552
- L: 271,
3553
- S: this,
3554
- C: (f, a) => f(...a)
3555
- });
3556
- return;
3557
- }
3558
- const data = signal.payload.data;
3559
- switch (data.type) {
3560
- case "offer": {
3561
- await this._offerProcessingMutex.executeSynchronized(async () => {
3562
- if (isRemoteDescriptionSet(connection, data)) {
3563
- return;
3564
- }
3565
- if (connection.connectionState !== "new") {
3566
- this._abortConnection(connection, new Error(`Received an offer in ${connection.connectionState}.`));
3567
- return;
3568
- }
3569
- try {
3570
- await connection.setRemoteDescription({
3571
- type: data.type,
3572
- sdp: data.sdp
3573
- });
3574
- const answer = await connection.createAnswer();
3575
- await connection.setLocalDescription(answer);
3576
- await this._sendDescription(connection, answer);
3577
- this._onSessionNegotiated(connection);
3578
- } catch (err) {
3579
- this._abortConnection(connection, new Error("Error handling a remote offer.", {
3580
- cause: err
3581
- }));
3582
- }
3583
- });
3584
- break;
3585
- }
3586
- case "answer":
3587
- await this._offerProcessingMutex.executeSynchronized(async () => {
3588
- try {
3589
- if (isRemoteDescriptionSet(connection, data)) {
3590
- return;
3591
- }
3592
- if (connection.signalingState !== "have-local-offer") {
3593
- this._abortConnection(connection, new Error(`Unexpected answer from remote peer, signalingState was ${connection.signalingState}.`));
3594
- return;
3595
- }
3596
- await connection.setRemoteDescription({
3597
- type: data.type,
3598
- sdp: data.sdp
3599
- });
3600
- this._onSessionNegotiated(connection);
3601
- } catch (err) {
3602
- this._abortConnection(connection, new Error("Error handling a remote answer.", {
3603
- cause: err
3604
- }));
3605
- }
3606
- });
3607
- break;
3608
- case "candidate":
3609
- void this._processIceCandidate(connection, data.candidate);
3610
- break;
3611
- default:
3612
- this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
3613
- break;
3614
- }
3615
- log13("signal processed", void 0, {
3360
+ async getStats({ proxyId }) {
3361
+ invariant12(this.transports.has(proxyId), void 0, {
3616
3362
  F: __dxlog_file14,
3617
- L: 330,
3363
+ L: 134,
3618
3364
  S: this,
3619
- C: (f, a) => f(...a)
3365
+ A: [
3366
+ "this.transports.has(proxyId)",
3367
+ ""
3368
+ ]
3620
3369
  });
3370
+ return {
3371
+ stats: await this.transports.get(proxyId).transport.getStats()
3372
+ };
3621
3373
  }
3622
- async _processIceCandidate(connection, candidate) {
3623
- try {
3624
- await this._readyForCandidates.wait();
3625
- if (connection === this._connection) {
3626
- log13("adding ice candidate", {
3627
- candidate
3628
- }, {
3629
- F: __dxlog_file14,
3630
- L: 338,
3631
- S: this,
3632
- C: (f, a) => f(...a)
3633
- });
3634
- await connection.addIceCandidate(candidate);
3635
- }
3636
- } catch (err) {
3637
- log13.catch(err, void 0, {
3638
- F: __dxlog_file14,
3639
- L: 342,
3640
- S: this,
3641
- C: (f, a) => f(...a)
3642
- });
3643
- }
3644
- }
3645
- _onSessionNegotiated(connection) {
3646
- if (connection === this._connection) {
3647
- log13("ready to process ice candidates", void 0, {
3648
- F: __dxlog_file14,
3649
- L: 348,
3650
- S: this,
3651
- C: (f, a) => f(...a)
3652
- });
3653
- this._readyForCandidates.wake();
3654
- } else {
3655
- log13.warn("session was negotiated after connection became inactive", void 0, {
3374
+ async sendData({ proxyId, payload }) {
3375
+ if (this.transports.get(proxyId)?.state !== "OPEN") {
3376
+ log13.debug("transport is closed", void 0, {
3656
3377
  F: __dxlog_file14,
3657
- L: 351,
3378
+ L: 140,
3658
3379
  S: this,
3659
3380
  C: (f, a) => f(...a)
3660
3381
  });
3661
3382
  }
3662
- }
3663
- _onConnectionCallbackAfterClose(callback, connection) {
3664
- log13.warn("callback invoked after a connection was destroyed, this is probably a bug", {
3665
- callback,
3666
- state: connection.connectionState
3667
- }, {
3383
+ invariant12(this.transports.has(proxyId), void 0, {
3668
3384
  F: __dxlog_file14,
3669
- L: 356,
3385
+ L: 142,
3670
3386
  S: this,
3671
- C: (f, a) => f(...a)
3387
+ A: [
3388
+ "this.transports.has(proxyId)",
3389
+ ""
3390
+ ]
3672
3391
  });
3673
- this._safeCloseConnection(connection);
3674
- }
3675
- _safeCloseConnection(connection = this._connection) {
3676
- const resetFields = this._connection && connection === this._connection;
3677
- try {
3678
- connection?.close();
3679
- } catch (err) {
3680
- log13.catch(err, void 0, {
3681
- F: __dxlog_file14,
3682
- L: 368,
3683
- S: this,
3684
- C: (f, a) => f(...a)
3685
- });
3686
- }
3687
- if (resetFields) {
3688
- this._connection = void 0;
3689
- this._dataChannels.clear();
3690
- this._readyForCandidates.wake();
3691
- void this._factory.onConnectionDestroyed().catch((err) => log13.catch(err, void 0, {
3692
- F: __dxlog_file14,
3693
- L: 374,
3694
- S: this,
3695
- C: (f, a) => f(...a)
3696
- }));
3697
- for (const [_, pendingCallback] of this._channelCreatedCallbacks.entries()) {
3698
- pendingCallback.reject("Connection closed.");
3699
- }
3700
- this._channelCreatedCallbacks.clear();
3701
- }
3702
- }
3703
- async _loadConnectionConfig() {
3704
- const config = {
3705
- ...this._options.webrtcConfig
3706
- };
3707
- try {
3708
- const providedIceServers = await this._options.iceProvider?.getIceServers() ?? [];
3709
- if (providedIceServers.length > 0) {
3710
- config.iceServers = [
3711
- ...config.iceServers ?? [],
3712
- ...providedIceServers
3713
- ];
3714
- }
3715
- } catch (error) {
3716
- log13.catch(error, void 0, {
3717
- F: __dxlog_file14,
3718
- L: 390,
3719
- S: this,
3720
- C: (f, a) => f(...a)
3721
- });
3722
- }
3723
- return config;
3724
- }
3725
- async _sendIceCandidate(candidate) {
3726
- try {
3727
- await this._options.sendSignal({
3728
- payload: {
3729
- data: {
3730
- type: "candidate",
3731
- candidate: {
3732
- candidate: candidate.candidate,
3733
- // These fields never seem to be not null, but connecting to Chrome doesn't work if they are.
3734
- sdpMLineIndex: candidate.sdpMLineIndex ?? "0",
3735
- sdpMid: candidate.sdpMid ?? "0"
3736
- }
3737
- }
3738
- }
3739
- });
3740
- } catch (err) {
3741
- log13.warn("signaling error", {
3742
- err
3743
- }, {
3744
- F: __dxlog_file14,
3745
- L: 411,
3746
- S: this,
3747
- C: (f, a) => f(...a)
3392
+ const state = this.transports.get(proxyId);
3393
+ const bufferHasSpace = state.stream.push(payload);
3394
+ if (!bufferHasSpace) {
3395
+ await new Promise((resolve) => {
3396
+ state.writeCallbacks.push(resolve);
3748
3397
  });
3749
3398
  }
3750
3399
  }
3751
- async _sendDescription(connection, description) {
3752
- if (connection !== this._connection) {
3753
- return;
3400
+ async close({ proxyId }) {
3401
+ await this.transports.get(proxyId)?.transport.close();
3402
+ await this.transports.get(proxyId)?.stream.end();
3403
+ if (this.transports.get(proxyId)) {
3404
+ this.transports.get(proxyId).state = "CLOSED";
3754
3405
  }
3755
- const data = {
3756
- type: description.type,
3757
- sdp: description.sdp
3758
- };
3759
- await this._options.sendSignal({
3760
- payload: {
3761
- data
3762
- }
3406
+ log13("Closed.", void 0, {
3407
+ F: __dxlog_file14,
3408
+ L: 158,
3409
+ S: this,
3410
+ C: (f, a) => f(...a)
3763
3411
  });
3764
3412
  }
3765
- get _connectionInfo() {
3766
- const connectionInfo = this._connection && {
3767
- connectionState: this._connection.connectionState,
3768
- iceConnectionState: this._connection.iceConnectionState,
3769
- iceGatheringState: this._connection.iceGatheringState,
3770
- signalingState: this._connection.signalingState,
3771
- remoteDescription: this._connection.remoteDescription,
3772
- localDescription: this._connection.localDescription
3773
- };
3774
- return {
3775
- ...connectionInfo,
3776
- ts: Date.now(),
3777
- remotePeerKey: this._options.remotePeerKey,
3778
- channels: [
3779
- ...this._transportChannels.keys()
3780
- ].map((topic) => topic),
3781
- config: this._connection?.getConfiguration()
3782
- };
3783
- }
3784
- get _loggerContext() {
3785
- return {
3786
- ownPeerKey: this._options.ownPeerKey,
3787
- remotePeerKey: this._options.remotePeerKey,
3788
- initiator: this._initiator,
3789
- channels: this._transportChannels.size
3790
- };
3791
- }
3792
- };
3793
- _ts_decorate6([
3794
- synchronized5
3795
- ], RtcPeerConnection.prototype, "_openConnection", null);
3796
- _ts_decorate6([
3797
- synchronized5
3798
- ], RtcPeerConnection.prototype, "_lockAndAbort", null);
3799
- _ts_decorate6([
3800
- synchronized5
3801
- ], RtcPeerConnection.prototype, "_lockAndCloseConnection", null);
3802
- _ts_decorate6([
3803
- synchronized5
3804
- ], RtcPeerConnection.prototype, "onSignal", null);
3805
- _ts_decorate6([
3806
- trace4.info()
3807
- ], RtcPeerConnection.prototype, "_connectionInfo", null);
3808
- _ts_decorate6([
3809
- logInfo4
3810
- ], RtcPeerConnection.prototype, "_loggerContext", null);
3811
- RtcPeerConnection = _ts_decorate6([
3812
- trace4.resource()
3813
- ], RtcPeerConnection);
3814
- var isRemoteDescriptionSet = (connection, data) => {
3815
- if (!connection.remoteDescription?.type || connection.remoteDescription?.type !== data.type) {
3816
- return false;
3817
- }
3818
- return areSdpEqual(connection.remoteDescription.sdp, data.sdp);
3819
- };
3820
- var createIceFailureError = (details) => {
3821
- const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
3822
- return new ConnectivityError3(`ICE failed:
3823
- ${candidateErrors.join("\n")}`);
3824
- };
3825
-
3826
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-factory.ts
3827
- var createRtcTransportFactory = (webrtcConfig, iceProvider) => {
3828
- const connectionFactory = getRtcConnectionFactory();
3829
- return {
3830
- createTransport: (options) => {
3831
- const connection = new RtcPeerConnection(connectionFactory, {
3832
- ownPeerKey: options.ownPeerKey,
3833
- remotePeerKey: options.remotePeerKey,
3834
- sendSignal: options.sendSignal,
3835
- webrtcConfig,
3836
- iceProvider
3837
- });
3838
- return connection.createTransportChannel(options);
3839
- }
3840
- };
3841
3413
  };
3842
3414
 
3843
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts
3415
+ // packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts
3844
3416
  import { Writable } from "@dxos/node-std/stream";
3845
- import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
3846
- import { Resource as Resource2 } from "@dxos/context";
3417
+ import { Event as Event9, scheduleTask as scheduleTask4 } from "@dxos/async";
3418
+ import { Context as Context6 } from "@dxos/context";
3847
3419
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
3848
3420
  import { invariant as invariant13 } from "@dxos/invariant";
3849
- import { PublicKey as PublicKey10 } from "@dxos/keys";
3421
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
3850
3422
  import { log as log14 } from "@dxos/log";
3851
- import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
3852
- import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3423
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError3, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
3424
+ import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3853
3425
  import { arrayToBuffer } from "@dxos/util";
3854
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
3426
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3855
3427
  var RPC_TIMEOUT = 1e4;
3856
- var CLOSE_RPC_TIMEOUT = 3e3;
3857
3428
  var RESP_MIN_THRESHOLD = 500;
3858
- var RtcTransportProxy = class extends Resource2 {
3429
+ var TIMEOUT_THRESHOLD = 10;
3430
+ var SimplePeerTransportProxy = class {
3859
3431
  constructor(_options) {
3860
- super();
3861
3432
  this._options = _options;
3862
- this._proxyId = PublicKey10.random();
3863
- this.closed = new Event8();
3864
- this.connected = new Event8();
3433
+ this._proxyId = PublicKey12.random();
3434
+ this._ctx = new Context6(void 0, {
3435
+ F: __dxlog_file15,
3436
+ L: 37
3437
+ });
3438
+ this._timeoutCount = 0;
3439
+ this.closed = new Event9();
3440
+ this.connected = new Event9();
3865
3441
  this.errors = new ErrorStream5();
3442
+ this._closed = false;
3866
3443
  }
3867
- async _open() {
3868
- let stream;
3869
- try {
3870
- stream = this._options.bridgeService.open({
3871
- proxyId: this._proxyId,
3872
- remotePeerKey: this._options.remotePeerKey,
3873
- ownPeerKey: this._options.ownPeerKey,
3874
- topic: this._options.topic,
3875
- initiator: this._options.initiator ?? false
3876
- }, {
3877
- timeout: RPC_TIMEOUT
3878
- });
3879
- } catch (error) {
3880
- this.errors.raise(error);
3881
- return;
3882
- }
3883
- this._serviceStream = stream;
3884
- stream.waitUntilReady().then(() => {
3885
- stream.subscribe(async (event) => {
3886
- log14("rtc transport proxy event", event, {
3444
+ get isOpen() {
3445
+ return !this._closed;
3446
+ }
3447
+ async open() {
3448
+ this._serviceStream = this._options.bridgeService.open({
3449
+ proxyId: this._proxyId,
3450
+ initiator: this._options.initiator
3451
+ }, {
3452
+ timeout: RPC_TIMEOUT
3453
+ });
3454
+ this._serviceStream.waitUntilReady().then(() => {
3455
+ this._serviceStream.subscribe(async (event) => {
3456
+ log14("SimplePeerTransportProxy: event", event, {
3887
3457
  F: __dxlog_file15,
3888
3458
  L: 66,
3889
3459
  S: this,
@@ -3896,34 +3466,20 @@ var RtcTransportProxy = class extends Resource2 {
3896
3466
  } else if (event.signal) {
3897
3467
  await this._handleSignal(event.signal);
3898
3468
  }
3899
- }, (err) => {
3900
- log14("rtc bridge stream closed", {
3901
- err
3902
- }, {
3903
- F: __dxlog_file15,
3904
- L: 76,
3905
- S: this,
3906
- C: (f, a) => f(...a)
3907
- });
3908
- if (err) {
3909
- this._raiseIfOpen(err);
3910
- } else {
3911
- void this.close();
3912
- }
3913
3469
  });
3914
- const connectorStream = new Writable({
3470
+ const proxyStream = new Writable({
3915
3471
  write: (chunk, _, callback) => {
3916
- const sendStartMs = Date.now();
3472
+ const then = performance.now();
3917
3473
  this._options.bridgeService.sendData({
3918
3474
  proxyId: this._proxyId,
3919
3475
  payload: chunk
3920
3476
  }, {
3921
3477
  timeout: RPC_TIMEOUT
3922
3478
  }).then(() => {
3923
- if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
3479
+ if (performance.now() - then > RESP_MIN_THRESHOLD) {
3924
3480
  log14("slow response, delaying callback", void 0, {
3925
3481
  F: __dxlog_file15,
3926
- L: 93,
3482
+ L: 90,
3927
3483
  S: this,
3928
3484
  C: (f, a) => f(...a)
3929
3485
  });
@@ -3931,41 +3487,60 @@ var RtcTransportProxy = class extends Resource2 {
3931
3487
  } else {
3932
3488
  callback();
3933
3489
  }
3490
+ this._timeoutCount = 0;
3934
3491
  }, (err) => {
3935
- callback();
3936
- this._raiseIfOpen(err);
3492
+ if (err instanceof TimeoutError3 || err.constructor.name === "TimeoutError") {
3493
+ if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
3494
+ throw new TimeoutError3(`too many timeouts (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
3495
+ } else {
3496
+ log14("timeout error, but still invoking callback", void 0, {
3497
+ F: __dxlog_file15,
3498
+ L: 102,
3499
+ S: this,
3500
+ C: (f, a) => f(...a)
3501
+ });
3502
+ callback();
3503
+ }
3504
+ } else {
3505
+ log14.catch(err, void 0, {
3506
+ F: __dxlog_file15,
3507
+ L: 106,
3508
+ S: this,
3509
+ C: (f, a) => f(...a)
3510
+ });
3511
+ }
3937
3512
  });
3938
3513
  }
3939
3514
  });
3940
- connectorStream.on("error", (err) => {
3941
- this._raiseIfOpen(err);
3515
+ proxyStream.on("error", (err) => {
3516
+ log14("proxystream error", {
3517
+ err
3518
+ }, {
3519
+ F: __dxlog_file15,
3520
+ L: 114,
3521
+ S: this,
3522
+ C: (f, a) => f(...a)
3523
+ });
3942
3524
  });
3943
- this._options.stream.pipe(connectorStream);
3944
- }, (error) => {
3945
- if (error) {
3946
- this._raiseIfOpen(error);
3947
- } else {
3948
- void this.close();
3949
- }
3950
- });
3525
+ this._options.stream.pipe(proxyStream);
3526
+ }, (error) => log14.catch(error, void 0, {
3527
+ F: __dxlog_file15,
3528
+ L: 119,
3529
+ S: this,
3530
+ C: (f, a) => f(...a)
3531
+ }));
3951
3532
  }
3952
- async _close() {
3953
- try {
3954
- await this._serviceStream?.close();
3955
- this._serviceStream = void 0;
3956
- } catch (err) {
3957
- log14.catch(err, void 0, {
3958
- F: __dxlog_file15,
3959
- L: 128,
3960
- S: this,
3961
- C: (f, a) => f(...a)
3962
- });
3533
+ async close() {
3534
+ await this._ctx.dispose();
3535
+ if (this._closed) {
3536
+ return;
3963
3537
  }
3538
+ await this._serviceStream.close();
3964
3539
  try {
3965
3540
  await this._options.bridgeService.close({
3966
3541
  proxyId: this._proxyId
3967
3542
  }, {
3968
- timeout: CLOSE_RPC_TIMEOUT
3543
+ timeout: RPC_TIMEOUT
3969
3544
  });
3970
3545
  } catch (err) {
3971
3546
  log14.catch(err, void 0, {
@@ -3976,6 +3551,7 @@ var RtcTransportProxy = class extends Resource2 {
3976
3551
  });
3977
3552
  }
3978
3553
  this.closed.emit();
3554
+ this._closed = true;
3979
3555
  }
3980
3556
  async onSignal(signal) {
3981
3557
  this._options.bridgeService.sendSignal({
@@ -3983,346 +3559,580 @@ var RtcTransportProxy = class extends Resource2 {
3983
3559
  signal
3984
3560
  }, {
3985
3561
  timeout: RPC_TIMEOUT
3986
- }).catch((err) => this._raiseIfOpen(decodeError(err)));
3562
+ }).catch((err) => this.errors.raise(decodeError(err)));
3987
3563
  }
3988
3564
  async _handleConnection(connectionEvent) {
3989
3565
  if (connectionEvent.error) {
3990
3566
  this.errors.raise(decodeError(connectionEvent.error));
3991
- return;
3992
3567
  }
3993
3568
  switch (connectionEvent.state) {
3994
- case ConnectionState3.CONNECTED: {
3569
+ case ConnectionState4.CONNECTED: {
3995
3570
  this.connected.emit();
3996
3571
  break;
3997
3572
  }
3998
- case ConnectionState3.CLOSED: {
3573
+ case ConnectionState4.CLOSED: {
3999
3574
  await this.close();
4000
3575
  break;
4001
3576
  }
4002
3577
  }
4003
3578
  }
4004
3579
  _handleData(dataEvent) {
4005
- try {
4006
- this._options.stream.write(arrayToBuffer(dataEvent.payload));
4007
- } catch (error) {
4008
- this._raiseIfOpen(error);
4009
- }
3580
+ this._options.stream.write(arrayToBuffer(dataEvent.payload));
4010
3581
  }
4011
3582
  async _handleSignal(signalEvent) {
4012
- try {
4013
- await this._options.sendSignal(signalEvent.payload);
4014
- } catch (error) {
4015
- const type = signalEvent.payload.payload.data?.type;
4016
- if (type === "offer" || type === "answer") {
4017
- this._raiseIfOpen(new ConnectivityError4(`Session establishment failed: ${type} couldn't be sent.`));
4018
- }
4019
- }
3583
+ await this._options.sendSignal(signalEvent.payload);
4020
3584
  }
4021
3585
  async getDetails() {
4022
- try {
4023
- const response = await this._options.bridgeService.getDetails({
4024
- proxyId: this._proxyId
4025
- }, {
4026
- timeout: RPC_TIMEOUT
4027
- });
4028
- return response.details;
4029
- } catch (err) {
4030
- return "bridge-svc unreachable";
4031
- }
3586
+ return (await this._options.bridgeService.getDetails({
3587
+ proxyId: this._proxyId
3588
+ }, {
3589
+ timeout: RPC_TIMEOUT
3590
+ })).details;
4032
3591
  }
4033
3592
  async getStats() {
4034
- try {
4035
- const response = await this._options.bridgeService.getStats({
4036
- proxyId: this._proxyId
3593
+ return (await this._options.bridgeService.getStats({
3594
+ proxyId: this._proxyId
3595
+ }, {
3596
+ timeout: RPC_TIMEOUT
3597
+ })).stats;
3598
+ }
3599
+ /**
3600
+ * Called when underlying proxy service becomes unavailable.
3601
+ */
3602
+ // TODO(burdon): Option on close method.
3603
+ forceClose() {
3604
+ void this._serviceStream.close();
3605
+ this.closed.emit();
3606
+ this._closed = true;
3607
+ }
3608
+ };
3609
+ var SimplePeerTransportProxyFactory = class {
3610
+ constructor() {
3611
+ this._connections = /* @__PURE__ */ new Set();
3612
+ }
3613
+ /**
3614
+ * Sets the current BridgeService to be used to open connections.
3615
+ * Calling this method will close any existing connections.
3616
+ */
3617
+ setBridgeService(bridgeService) {
3618
+ this._bridgeService = bridgeService;
3619
+ for (const connection of this._connections) {
3620
+ connection.forceClose();
3621
+ }
3622
+ return this;
3623
+ }
3624
+ createTransport(options) {
3625
+ invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3626
+ F: __dxlog_file15,
3627
+ L: 218,
3628
+ S: this,
3629
+ A: [
3630
+ "this._bridgeService",
3631
+ "'SimplePeerTransportProxyFactory is not ready to open connections'"
3632
+ ]
3633
+ });
3634
+ const transport = new SimplePeerTransportProxy({
3635
+ ...options,
3636
+ bridgeService: this._bridgeService
3637
+ });
3638
+ this._connections.add(transport);
3639
+ transport.closed.on(() => this._connections.delete(transport));
3640
+ return transport;
3641
+ }
3642
+ };
3643
+ var decodeError = (err) => {
3644
+ const message = typeof err === "string" ? err : err.message;
3645
+ if (message.includes("CONNECTION_RESET")) {
3646
+ return new ConnectionResetError3(message);
3647
+ } else if (message.includes("TIMEOUT")) {
3648
+ return new TimeoutError3(message);
3649
+ } else if (message.includes("PROTOCOL_ERROR")) {
3650
+ return new ProtocolError3(message);
3651
+ } else if (message.includes("CONNECTIVITY_ERROR")) {
3652
+ return new ConnectivityError3(message);
3653
+ } else if (message.includes("UNKNOWN_PROTOCOL_ERROR")) {
3654
+ return new UnknownProtocolError3(message);
3655
+ } else {
3656
+ return typeof err === "string" ? new Error(err) : err;
3657
+ }
3658
+ };
3659
+
3660
+ // packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
3661
+ import { Duplex as Duplex2 } from "stream";
3662
+ import { Event as Event10, Trigger as Trigger3, synchronized as synchronized6 } from "@dxos/async";
3663
+ import { ErrorStream as ErrorStream6 } from "@dxos/debug";
3664
+ import { invariant as invariant14 } from "@dxos/invariant";
3665
+ import { log as log15 } from "@dxos/log";
3666
+ function _ts_decorate7(decorators, target, key, desc) {
3667
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3668
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3669
+ 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;
3670
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3671
+ }
3672
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3673
+ var DATACHANNEL_LABEL = "dxos.mesh.transport";
3674
+ var MAX_BUFFERED_AMOUNT = 64 * 1024;
3675
+ var MAX_MESSAGE_SIZE = 64 * 1024;
3676
+ var createLibDataChannelTransportFactory = (webrtcConfig, iceProvider) => {
3677
+ return {
3678
+ createTransport: (options) => new LibDataChannelTransport({
3679
+ ...options,
3680
+ webrtcConfig,
3681
+ iceProvider
3682
+ })
3683
+ };
3684
+ };
3685
+ var LibDataChannelTransport = class _LibDataChannelTransport {
3686
+ static {
3687
+ this._instanceCount = 0;
3688
+ }
3689
+ constructor(_options) {
3690
+ this._options = _options;
3691
+ this._closed = false;
3692
+ this._connected = false;
3693
+ this._writeCallback = null;
3694
+ this._readyForCandidates = new Trigger3();
3695
+ this.closed = new Event10();
3696
+ this.connected = new Event10();
3697
+ this.errors = new ErrorStream6();
3698
+ }
3699
+ get isOpen() {
3700
+ return !!this._peer && !this._closed;
3701
+ }
3702
+ async open() {
3703
+ if (this._closed) {
3704
+ this.errors.raise(new Error("connection already closed"));
3705
+ }
3706
+ const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
3707
+ const providedIceServers = await this._options.iceProvider?.getIceServers();
3708
+ if (!this._options.webrtcConfig) {
3709
+ this._options.webrtcConfig = {};
3710
+ }
3711
+ this._options.webrtcConfig.iceServers = [
3712
+ ...this._options.webrtcConfig.iceServers ?? [],
3713
+ ...providedIceServers ?? []
3714
+ ];
3715
+ this._peer = new RTCPeerConnection(this._options.webrtcConfig);
3716
+ this._peer.onicecandidateerror = (event) => {
3717
+ log15.error("peer.onicecandidateerror", {
3718
+ event
4037
3719
  }, {
4038
- timeout: RPC_TIMEOUT
3720
+ F: __dxlog_file16,
3721
+ L: 93,
3722
+ S: this,
3723
+ C: (f, a) => f(...a)
3724
+ });
3725
+ };
3726
+ this._peer.onconnectionstatechange = (event) => {
3727
+ log15.debug("peer.onconnectionstatechange", {
3728
+ event,
3729
+ peerConnectionState: this._peer?.connectionState,
3730
+ transportConnectionState: this._connected
3731
+ }, {
3732
+ F: __dxlog_file16,
3733
+ L: 97,
3734
+ S: this,
3735
+ C: (f, a) => f(...a)
3736
+ });
3737
+ };
3738
+ this._peer.onicecandidate = async (event) => {
3739
+ log15.debug("peer.onicecandidate", {
3740
+ event
3741
+ }, {
3742
+ F: __dxlog_file16,
3743
+ L: 107,
3744
+ S: this,
3745
+ C: (f, a) => f(...a)
3746
+ });
3747
+ if (event.candidate) {
3748
+ try {
3749
+ await this._options.sendSignal({
3750
+ payload: {
3751
+ data: {
3752
+ type: "candidate",
3753
+ candidate: {
3754
+ candidate: event.candidate.candidate,
3755
+ // These fields never seem to be not null, but connecting to Chrome doesn't work if they are.
3756
+ sdpMLineIndex: event.candidate.sdpMLineIndex ?? 0,
3757
+ sdpMid: event.candidate.sdpMid ?? 0
3758
+ }
3759
+ }
3760
+ }
3761
+ });
3762
+ } catch (err) {
3763
+ log15.info("signaling error", {
3764
+ err
3765
+ }, {
3766
+ F: __dxlog_file16,
3767
+ L: 124,
3768
+ S: this,
3769
+ C: (f, a) => f(...a)
3770
+ });
3771
+ }
3772
+ }
3773
+ };
3774
+ if (this._options.initiator) {
3775
+ invariant14(this._peer, "not open", {
3776
+ F: __dxlog_file16,
3777
+ L: 130,
3778
+ S: this,
3779
+ A: [
3780
+ "this._peer",
3781
+ "'not open'"
3782
+ ]
3783
+ });
3784
+ this._peer.createOffer().then(async (offer) => {
3785
+ if (this._closed) {
3786
+ return;
3787
+ }
3788
+ if (this._peer?.connectionState !== "connecting") {
3789
+ log15.error("peer not connecting", {
3790
+ peer: this._peer
3791
+ }, {
3792
+ F: __dxlog_file16,
3793
+ L: 141,
3794
+ S: this,
3795
+ C: (f, a) => f(...a)
3796
+ });
3797
+ this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
3798
+ }
3799
+ log15.debug("creating offer", {
3800
+ peer: this._peer,
3801
+ offer
3802
+ }, {
3803
+ F: __dxlog_file16,
3804
+ L: 145,
3805
+ S: this,
3806
+ C: (f, a) => f(...a)
3807
+ });
3808
+ await this._peer.setLocalDescription(offer);
3809
+ await this._options.sendSignal({
3810
+ payload: {
3811
+ data: {
3812
+ type: offer.type,
3813
+ sdp: offer.sdp
3814
+ }
3815
+ }
3816
+ });
3817
+ }).catch((err) => {
3818
+ this.errors.raise(err);
3819
+ });
3820
+ this._handleChannel(this._peer.createDataChannel(DATACHANNEL_LABEL));
3821
+ log15.debug("created data channel", void 0, {
3822
+ F: __dxlog_file16,
3823
+ L: 155,
3824
+ S: this,
3825
+ C: (f, a) => f(...a)
4039
3826
  });
4040
- return response.stats;
4041
- } catch (err) {
4042
- return {
4043
- bytesSent: 0,
4044
- bytesReceived: 0,
4045
- packetsSent: 0,
4046
- packetsReceived: 0,
4047
- rawStats: "bridge-svc unreachable"
3827
+ this._peer.ondatachannel = () => {
3828
+ this.errors.raise(new Error("unexpected ondatachannel event for initiator"));
3829
+ };
3830
+ } else {
3831
+ this._peer.ondatachannel = (event) => {
3832
+ log15.debug("peer.ondatachannel (non-initiator)", {
3833
+ event
3834
+ }, {
3835
+ F: __dxlog_file16,
3836
+ L: 161,
3837
+ S: this,
3838
+ C: (f, a) => f(...a)
3839
+ });
3840
+ if (event.channel.label !== DATACHANNEL_LABEL) {
3841
+ this.errors.raise(new Error(`unexpected channel label ${event.channel.label}`));
3842
+ }
3843
+ this._handleChannel(event.channel);
4048
3844
  };
4049
3845
  }
3846
+ _LibDataChannelTransport._instanceCount++;
4050
3847
  }
4051
- _raiseIfOpen(error) {
4052
- if (this.isOpen) {
4053
- this.errors.raise(error);
4054
- } else {
4055
- log14.info("error swallowed because transport was closed", {
4056
- message: error.message
4057
- }, {
4058
- F: __dxlog_file15,
4059
- L: 215,
4060
- S: this,
4061
- C: (f, a) => f(...a)
4062
- });
3848
+ async close() {
3849
+ await this._close();
3850
+ if (--_LibDataChannelTransport._instanceCount === 0) {
3851
+ (await importESM("node-datachannel")).cleanup();
4063
3852
  }
4064
3853
  }
4065
- /**
4066
- * Called when underlying proxy service becomes unavailable.
4067
- */
4068
- forceClose() {
4069
- void this._serviceStream?.close();
3854
+ async _close() {
3855
+ if (this._closed) {
3856
+ return;
3857
+ }
3858
+ await this._disconnectStreams();
3859
+ try {
3860
+ this._peer?.close();
3861
+ } catch (err) {
3862
+ this.errors.raise(err);
3863
+ }
3864
+ this._peer = void 0;
3865
+ this._closed = true;
4070
3866
  this.closed.emit();
4071
3867
  }
4072
- };
4073
- var RtcTransportProxyFactory = class {
4074
- constructor() {
4075
- this._connections = /* @__PURE__ */ new Set();
4076
- }
4077
3868
  /**
4078
- * Sets the current BridgeService to be used to open connections.
4079
- * Calling this method will close any existing connections.
3869
+ * Handle data channel events.
4080
3870
  */
4081
- setBridgeService(bridgeService) {
4082
- this._bridgeService = bridgeService;
4083
- for (const connection of this._connections) {
4084
- connection.forceClose();
4085
- }
4086
- return this;
4087
- }
4088
- createTransport(options) {
4089
- invariant13(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
4090
- F: __dxlog_file15,
4091
- L: 245,
4092
- S: this,
4093
- A: [
4094
- "this._bridgeService",
4095
- "'RtcTransportProxyFactory is not ready to open connections'"
4096
- ]
4097
- });
4098
- const transport = new RtcTransportProxy({
4099
- ...options,
4100
- bridgeService: this._bridgeService
4101
- });
4102
- this._connections.add(transport);
4103
- transport.closed.on(() => this._connections.delete(transport));
4104
- return transport;
4105
- }
4106
- };
4107
- var decodeError = (err) => {
4108
- const message = typeof err === "string" ? err : err.message;
4109
- if (message.includes("CONNECTION_RESET")) {
4110
- return new ConnectionResetError2(message);
4111
- } else if (message.includes("TIMEOUT")) {
4112
- return new TimeoutError3(message);
4113
- } else if (message.includes("CONNECTIVITY_ERROR")) {
4114
- return new ConnectivityError4(message);
4115
- } else {
4116
- return typeof err === "string" ? new Error(err) : err;
4117
- }
4118
- };
4119
-
4120
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts
4121
- import { Duplex as Duplex2 } from "@dxos/node-std/stream";
4122
- import { Stream } from "@dxos/codec-protobuf";
4123
- import { invariant as invariant14 } from "@dxos/invariant";
4124
- import { PublicKey as PublicKey11 } from "@dxos/keys";
4125
- import { log as log15 } from "@dxos/log";
4126
- import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
4127
- import { ComplexMap as ComplexMap8 } from "@dxos/util";
4128
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
4129
- var RtcTransportService = class {
4130
- constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
4131
- this._transportFactory = _transportFactory;
4132
- this._openTransports = new ComplexMap8(PublicKey11.hash);
4133
- }
4134
- hasOpenTransports() {
4135
- return this._openTransports.size > 0;
4136
- }
4137
- open(request) {
4138
- const existingTransport = this._openTransports.get(request.proxyId);
4139
- if (existingTransport) {
4140
- log15.error("requesting a new transport bridge for an existing proxy", void 0, {
3871
+ _handleChannel(dataChannel) {
3872
+ this._channel = dataChannel;
3873
+ this._channel.onopen = () => {
3874
+ log15.debug("channel.onopen", void 0, {
4141
3875
  F: __dxlog_file16,
4142
- L: 53,
3876
+ L: 206,
4143
3877
  S: this,
4144
3878
  C: (f, a) => f(...a)
4145
3879
  });
4146
- void this._safeCloseTransport(existingTransport);
4147
- this._openTransports.delete(request.proxyId);
4148
- }
4149
- return new Stream(({ ready, next, close }) => {
4150
- const pushNewState = createStateUpdater(next);
4151
- const transportStream = new Duplex2({
3880
+ const duplex = new Duplex2({
4152
3881
  read: () => {
4153
- const callbacks = [
4154
- ...transportState.writeProcessedCallbacks
4155
- ];
4156
- transportState.writeProcessedCallbacks.length = 0;
4157
- callbacks.forEach((cb) => cb());
4158
3882
  },
4159
- write: function(chunk, _, callback) {
4160
- next({
4161
- data: {
4162
- payload: chunk
4163
- }
4164
- });
4165
- callback();
4166
- }
4167
- });
4168
- const transport = this._transportFactory.createTransport({
4169
- initiator: request.initiator,
4170
- topic: request.topic,
4171
- ownPeerKey: request.ownPeerKey,
4172
- remotePeerKey: request.remotePeerKey,
4173
- stream: transportStream,
4174
- sendSignal: async (signal) => {
4175
- next({
4176
- signal: {
4177
- payload: signal
3883
+ write: async (chunk, encoding, callback) => {
3884
+ if (chunk.length > MAX_MESSAGE_SIZE) {
3885
+ this.errors.raise(new Error(`message too large: ${chunk.length} > ${MAX_MESSAGE_SIZE}`));
3886
+ }
3887
+ try {
3888
+ dataChannel.send(chunk);
3889
+ } catch (err) {
3890
+ this.errors.raise(err);
3891
+ await this._close();
3892
+ }
3893
+ if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3894
+ if (this._writeCallback !== null) {
3895
+ log15.error("consumer trying to write before we are ready for more data", void 0, {
3896
+ F: __dxlog_file16,
3897
+ L: 223,
3898
+ S: this,
3899
+ C: (f, a) => f(...a)
3900
+ });
4178
3901
  }
4179
- });
3902
+ this._writeCallback = callback;
3903
+ } else {
3904
+ callback();
3905
+ }
4180
3906
  }
4181
3907
  });
4182
- const transportState = {
4183
- proxyId: request.proxyId,
4184
- transport,
4185
- connectorStream: transportStream,
4186
- writeProcessedCallbacks: []
4187
- };
4188
- pushNewState(ConnectionState4.CONNECTING);
4189
- transport.connected.on(() => pushNewState(ConnectionState4.CONNECTED));
4190
- transport.errors.handle(async (err) => {
4191
- pushNewState(ConnectionState4.CLOSED, err);
4192
- void this._safeCloseTransport(transportState);
4193
- close(err);
4194
- });
4195
- transport.closed.on(async () => {
4196
- pushNewState(ConnectionState4.CLOSED);
4197
- void this._safeCloseTransport(transportState);
4198
- close();
4199
- });
4200
- this._openTransports.set(request.proxyId, transportState);
4201
- transport.open().catch(async (err) => {
4202
- pushNewState(ConnectionState4.CLOSED, err);
4203
- void this._safeCloseTransport(transportState);
4204
- close(err);
3908
+ duplex.pipe(this._options.stream).pipe(duplex);
3909
+ this._stream = duplex;
3910
+ this._connected = true;
3911
+ this.connected.emit();
3912
+ };
3913
+ this._channel.onclose = async (err) => {
3914
+ log15.info("channel.onclose", {
3915
+ err
3916
+ }, {
3917
+ F: __dxlog_file16,
3918
+ L: 239,
3919
+ S: this,
3920
+ C: (f, a) => f(...a)
4205
3921
  });
4206
- ready();
4207
- });
3922
+ await this._close();
3923
+ };
3924
+ this._channel.onerror = async (err) => {
3925
+ this.errors.raise(new Error("channel error: " + err.toString()));
3926
+ await this._close();
3927
+ };
3928
+ this._channel.onbufferedamountlow = () => {
3929
+ const cb = this._writeCallback;
3930
+ this._writeCallback = null;
3931
+ cb?.();
3932
+ };
3933
+ this._channel.onmessage = (event) => {
3934
+ let data = event.data;
3935
+ if (data instanceof ArrayBuffer) {
3936
+ data = Buffer2.from(data);
3937
+ }
3938
+ this._stream.push(data);
3939
+ };
4208
3940
  }
4209
- async sendSignal({ proxyId, signal }) {
4210
- const transport = this._openTransports.get(proxyId);
4211
- invariant14(transport, void 0, {
3941
+ async onSignal(signal) {
3942
+ invariant14(this._peer, "not open", {
4212
3943
  F: __dxlog_file16,
4213
- L: 121,
3944
+ L: 265,
4214
3945
  S: this,
4215
3946
  A: [
4216
- "transport",
4217
- ""
3947
+ "this._peer",
3948
+ "'not open'"
4218
3949
  ]
4219
3950
  });
4220
- await transport.transport.onSignal(signal);
3951
+ try {
3952
+ const data = signal.payload.data;
3953
+ switch (data.type) {
3954
+ case "offer": {
3955
+ if (this._peer.connectionState !== "new") {
3956
+ log15.error("received offer but peer not in state new", {
3957
+ peer: this._peer
3958
+ }, {
3959
+ F: __dxlog_file16,
3960
+ L: 272,
3961
+ S: this,
3962
+ C: (f, a) => f(...a)
3963
+ });
3964
+ this.errors.raise(new Error("invalid signalling state: received offer when peer is not in state new"));
3965
+ break;
3966
+ }
3967
+ try {
3968
+ await this._peer.setRemoteDescription({
3969
+ type: data.type,
3970
+ sdp: data.sdp
3971
+ });
3972
+ const answer = await this._peer.createAnswer();
3973
+ await this._peer.setLocalDescription(answer);
3974
+ await this._options.sendSignal({
3975
+ payload: {
3976
+ data: {
3977
+ type: answer.type,
3978
+ sdp: answer.sdp
3979
+ }
3980
+ }
3981
+ });
3982
+ this._readyForCandidates.wake();
3983
+ } catch (err) {
3984
+ log15.error("cannot handle offer from signalling server", {
3985
+ err
3986
+ }, {
3987
+ F: __dxlog_file16,
3988
+ L: 284,
3989
+ S: this,
3990
+ C: (f, a) => f(...a)
3991
+ });
3992
+ this.errors.raise(new Error("error handling offer"));
3993
+ }
3994
+ break;
3995
+ }
3996
+ case "answer":
3997
+ try {
3998
+ await this._peer.setRemoteDescription({
3999
+ type: data.type,
4000
+ sdp: data.sdp
4001
+ });
4002
+ this._readyForCandidates.wake();
4003
+ } catch (err) {
4004
+ log15.error("cannot handle answer from signalling server", {
4005
+ err
4006
+ }, {
4007
+ F: __dxlog_file16,
4008
+ L: 295,
4009
+ S: this,
4010
+ C: (f, a) => f(...a)
4011
+ });
4012
+ this.errors.raise(new Error("error handling answer"));
4013
+ }
4014
+ break;
4015
+ case "candidate":
4016
+ await this._readyForCandidates.wait();
4017
+ await this._peer.addIceCandidate({
4018
+ candidate: data.candidate.candidate
4019
+ });
4020
+ break;
4021
+ default:
4022
+ log15.error("unhandled signal type", {
4023
+ type: data.type,
4024
+ signal
4025
+ }, {
4026
+ F: __dxlog_file16,
4027
+ L: 306,
4028
+ S: this,
4029
+ C: (f, a) => f(...a)
4030
+ });
4031
+ this.errors.raise(new Error(`unhandled signal type ${data.type}`));
4032
+ }
4033
+ } catch (err) {
4034
+ log15.catch(err, void 0, {
4035
+ F: __dxlog_file16,
4036
+ L: 310,
4037
+ S: this,
4038
+ C: (f, a) => f(...a)
4039
+ });
4040
+ }
4221
4041
  }
4222
- async getDetails({ proxyId }) {
4223
- const transport = this._openTransports.get(proxyId);
4224
- invariant14(transport, void 0, {
4225
- F: __dxlog_file16,
4226
- L: 128,
4227
- S: this,
4228
- A: [
4229
- "transport",
4230
- ""
4231
- ]
4232
- });
4042
+ async getDetails() {
4043
+ const stats = await this._getStats();
4044
+ const rc = stats?.remoteCandidate;
4045
+ if (!rc) {
4046
+ return "unavailable";
4047
+ }
4048
+ if (rc.candidateType === "relay") {
4049
+ return `${rc.ip}:${rc.port} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
4050
+ }
4051
+ return `${rc.ip}:${rc.port} ${rc.candidateType}`;
4052
+ }
4053
+ async getStats() {
4054
+ const stats = await this._getStats();
4055
+ if (!stats) {
4056
+ return {
4057
+ bytesSent: 0,
4058
+ bytesReceived: 0,
4059
+ packetsSent: 0,
4060
+ packetsReceived: 0,
4061
+ rawStats: {}
4062
+ };
4063
+ }
4233
4064
  return {
4234
- details: await transport.transport.getDetails()
4065
+ bytesSent: stats.transport.bytesSent,
4066
+ bytesReceived: stats.transport.bytesReceived,
4067
+ packetsSent: 0,
4068
+ packetsReceived: 0,
4069
+ rawStats: stats.raw
4235
4070
  };
4236
4071
  }
4237
- async getStats({ proxyId }) {
4238
- const transport = this._openTransports.get(proxyId);
4239
- invariant14(transport, void 0, {
4072
+ async _getStats() {
4073
+ invariant14(this._peer, "not open", {
4240
4074
  F: __dxlog_file16,
4241
- L: 135,
4075
+ L: 350,
4242
4076
  S: this,
4243
4077
  A: [
4244
- "transport",
4245
- ""
4078
+ "this._peer",
4079
+ "'not open'"
4246
4080
  ]
4247
4081
  });
4082
+ const stats = await this._peer.getStats();
4083
+ const statsEntries = Array.from(stats.entries());
4084
+ const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
4085
+ const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
4086
+ let selectedCandidatePair;
4087
+ let remoteCandidate;
4088
+ if (candidatePair.length > 0) {
4089
+ selectedCandidatePair = candidatePair[0][1];
4090
+ remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
4091
+ }
4248
4092
  return {
4249
- stats: await transport.transport.getStats()
4093
+ transport,
4094
+ selectedCandidatePair,
4095
+ remoteCandidate,
4096
+ raw: Object.fromEntries(stats)
4250
4097
  };
4251
4098
  }
4252
- async sendData({ proxyId, payload }) {
4253
- const transport = this._openTransports.get(proxyId);
4254
- invariant14(transport, void 0, {
4255
- F: __dxlog_file16,
4256
- L: 142,
4257
- S: this,
4258
- A: [
4259
- "transport",
4260
- ""
4261
- ]
4262
- });
4263
- const bufferHasSpace = transport.connectorStream.push(payload);
4264
- if (!bufferHasSpace) {
4265
- await new Promise((resolve) => {
4266
- transport.writeProcessedCallbacks.push(resolve);
4267
- });
4268
- }
4099
+ async _disconnectStreams() {
4100
+ this._options.stream.unpipe?.(this._stream)?.unpipe?.(this._options.stream);
4269
4101
  }
4270
- async close({ proxyId }) {
4271
- const transport = this._openTransports.get(proxyId);
4272
- if (!transport) {
4273
- return;
4274
- }
4275
- this._openTransports.delete(proxyId);
4276
- await this._safeCloseTransport(transport);
4102
+ };
4103
+ _ts_decorate7([
4104
+ synchronized6
4105
+ ], LibDataChannelTransport.prototype, "_close", null);
4106
+ var importESM = Function("path", "return import(path)");
4107
+
4108
+ // packages/core/mesh/network-manager/src/transport/tcp-transport.browser.ts
4109
+ import { Event as Event11 } from "@dxos/async";
4110
+ import { ErrorStream as ErrorStream7 } from "@dxos/debug";
4111
+ var TcpTransportFactory = {
4112
+ createTransport: () => new TcpTransport()
4113
+ };
4114
+ var TcpTransport = class {
4115
+ constructor() {
4116
+ this.closed = new Event11();
4117
+ this.connected = new Event11();
4118
+ this.errors = new ErrorStream7();
4277
4119
  }
4278
- async _safeCloseTransport(transport) {
4279
- if (this._openTransports.get(transport.proxyId) === transport) {
4280
- this._openTransports.delete(transport.proxyId);
4281
- }
4282
- transport.writeProcessedCallbacks.forEach((cb) => cb());
4283
- try {
4284
- await transport.transport.close();
4285
- } catch (error) {
4286
- log15.warn("transport close error", {
4287
- message: error?.message
4288
- }, {
4289
- F: __dxlog_file16,
4290
- L: 172,
4291
- S: this,
4292
- C: (f, a) => f(...a)
4293
- });
4294
- }
4295
- try {
4296
- transport.connectorStream.end();
4297
- } catch (error) {
4298
- log15.warn("connectorStream close error", {
4299
- message: error?.message
4300
- }, {
4301
- F: __dxlog_file16,
4302
- L: 177,
4303
- S: this,
4304
- C: (f, a) => f(...a)
4305
- });
4306
- }
4307
- log15("closed", void 0, {
4308
- F: __dxlog_file16,
4309
- L: 179,
4310
- S: this,
4311
- C: (f, a) => f(...a)
4312
- });
4120
+ get isOpen() {
4121
+ return true;
4122
+ }
4123
+ async open() {
4124
+ }
4125
+ async close() {
4126
+ }
4127
+ async onSignal() {
4128
+ throw new Error("Method not implemented.");
4129
+ }
4130
+ async getStats() {
4131
+ throw new Error("Method not implemented.");
4132
+ }
4133
+ async getDetails() {
4134
+ throw new Error("Method not implemented.");
4313
4135
  }
4314
- };
4315
- var createStateUpdater = (next) => {
4316
- return (state, err) => {
4317
- next({
4318
- connection: {
4319
- state,
4320
- ...err ? {
4321
- error: err.message
4322
- } : void 0
4323
- }
4324
- });
4325
- };
4326
4136
  };
4327
4137
 
4328
4138
  // packages/core/mesh/network-manager/src/wire-protocol.ts
@@ -4350,6 +4160,7 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
4350
4160
  };
4351
4161
 
4352
4162
  export {
4163
+ process,
4353
4164
  ConnectionState,
4354
4165
  Connection,
4355
4166
  createIceProvider,
@@ -4367,10 +4178,15 @@ export {
4367
4178
  MemoryTransportFactory,
4368
4179
  MemoryTransport,
4369
4180
  TransportKind,
4370
- createRtcTransportFactory,
4371
- RtcTransportProxy,
4372
- RtcTransportProxyFactory,
4373
- RtcTransportService,
4181
+ createSimplePeerTransportFactory,
4182
+ SimplePeerTransport,
4183
+ SimplePeerTransportService,
4184
+ SimplePeerTransportProxy,
4185
+ SimplePeerTransportProxyFactory,
4186
+ createLibDataChannelTransportFactory,
4187
+ LibDataChannelTransport,
4188
+ TcpTransportFactory,
4189
+ TcpTransport,
4374
4190
  createTeleportProtocolFactory
4375
4191
  };
4376
- //# sourceMappingURL=chunk-MKIVP7G3.mjs.map
4192
+ //# sourceMappingURL=chunk-XYSYUN63.mjs.map