@dxos/network-manager 0.1.58-main.0fabfcd → 0.1.58-main.31dfb10

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.
@@ -7,7 +7,7 @@ import {
7
7
  import { DeferredTask, Event, sleep, synchronized } from "@dxos/async";
8
8
  import { Context, cancelWithContext } from "@dxos/context";
9
9
  import { ErrorStream } from "@dxos/debug";
10
- import { CancelledError } from "@dxos/errors";
10
+ import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, UnknownProtocolError } from "@dxos/errors";
11
11
  import { invariant } from "@dxos/invariant";
12
12
  import { PublicKey } from "@dxos/keys";
13
13
  import { log } from "@dxos/log";
@@ -64,6 +64,8 @@ var ConnectionState;
64
64
  */
65
65
  "CLOSED"
66
66
  ] = "CLOSED";
67
+ ConnectionState5["ABORTING"] = "ABORTING";
68
+ ConnectionState5["ABORTED"] = "ABORTED";
67
69
  })(ConnectionState || (ConnectionState = {}));
68
70
  var Connection = class {
69
71
  constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -95,7 +97,7 @@ var Connection = class {
95
97
  initiator: this.initiator
96
98
  }, {
97
99
  F: __dxlog_file,
98
- L: 114,
100
+ L: 123,
99
101
  S: this,
100
102
  C: (f, a) => f(...a)
101
103
  });
@@ -115,7 +117,7 @@ var Connection = class {
115
117
  async openConnection() {
116
118
  invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
117
119
  F: __dxlog_file,
118
- L: 139,
120
+ L: 148,
119
121
  S: this,
120
122
  A: [
121
123
  "this._state === ConnectionState.INITIAL",
@@ -126,7 +128,7 @@ var Connection = class {
126
128
  id: this._instanceId
127
129
  }), {
128
130
  F: __dxlog_file,
129
- L: 140,
131
+ L: 149,
130
132
  S: this,
131
133
  C: (f, a) => f(...a)
132
134
  });
@@ -138,7 +140,7 @@ var Connection = class {
138
140
  initiator: this.initiator
139
141
  }, {
140
142
  F: __dxlog_file,
141
- L: 141,
143
+ L: 150,
142
144
  S: this,
143
145
  C: (f, a) => f(...a)
144
146
  });
@@ -149,15 +151,15 @@ var Connection = class {
149
151
  this._protocol.stream.on("close", () => {
150
152
  log("protocol stream closed", void 0, {
151
153
  F: __dxlog_file,
152
- L: 158,
154
+ L: 167,
153
155
  S: this,
154
156
  C: (f, a) => f(...a)
155
157
  });
156
- this.close().catch((err) => this.errors.raise(err));
158
+ this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
157
159
  });
158
160
  invariant(!this._transport, void 0, {
159
161
  F: __dxlog_file,
160
- L: 162,
162
+ L: 171,
161
163
  S: this,
162
164
  A: [
163
165
  "!this._transport",
@@ -177,7 +179,7 @@ var Connection = class {
177
179
  this._transport = void 0;
178
180
  log("abort triggered by transport close", void 0, {
179
181
  F: __dxlog_file,
180
- L: 176,
182
+ L: 185,
181
183
  S: this,
182
184
  C: (f, a) => f(...a)
183
185
  });
@@ -188,21 +190,38 @@ var Connection = class {
188
190
  err
189
191
  }, {
190
192
  F: __dxlog_file,
191
- L: 181,
193
+ L: 190,
192
194
  S: this,
193
195
  C: (f, a) => f(...a)
194
196
  });
195
197
  if (!this.closeReason) {
196
198
  this.closeReason = err?.message;
197
199
  }
198
- if (err?.message.includes("OperationError")) {
199
- log("aborting due to transport OperationError", void 0, {
200
+ if (err instanceof ConnectionResetError) {
201
+ log("aborting due to transport ConnectionResetError", void 0, {
200
202
  F: __dxlog_file,
201
- L: 187,
203
+ L: 197,
202
204
  S: this,
203
205
  C: (f, a) => f(...a)
204
206
  });
205
207
  this.abort().catch((err2) => this.errors.raise(err2));
208
+ } else if (err instanceof ConnectivityError) {
209
+ log("aborting due to transport ConnectivityError", void 0, {
210
+ F: __dxlog_file,
211
+ L: 200,
212
+ S: this,
213
+ C: (f, a) => f(...a)
214
+ });
215
+ this.abort().catch((err2) => this.errors.raise(err2));
216
+ } else if (err instanceof UnknownProtocolError) {
217
+ log("unsure what to do for UnknownProtocolError", {
218
+ err
219
+ }, {
220
+ F: __dxlog_file,
221
+ L: 203,
222
+ S: this,
223
+ C: (f, a) => f(...a)
224
+ });
206
225
  }
207
226
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
208
227
  this.errors.raise(err);
@@ -216,7 +235,7 @@ var Connection = class {
216
235
  id: this._instanceId
217
236
  }), {
218
237
  F: __dxlog_file,
219
- L: 203,
238
+ L: 218,
220
239
  S: this,
221
240
  C: (f, a) => f(...a)
222
241
  });
@@ -226,30 +245,30 @@ var Connection = class {
226
245
  err
227
246
  }, {
228
247
  F: __dxlog_file,
229
- L: 209,
248
+ L: 224,
230
249
  S: this,
231
250
  C: (f, a) => f(...a)
232
251
  });
233
- if (!this.closeReason) {
234
- this.closeReason = err?.message;
235
- }
236
- if (this._state === ConnectionState.CLOSED) {
237
- log("abort ignored: already closed", this.closeReason, {
252
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
253
+ log(`abort ignored: already ${this._state}`, this.closeReason, {
238
254
  F: __dxlog_file,
239
- L: 214,
255
+ L: 226,
240
256
  S: this,
241
257
  C: (f, a) => f(...a)
242
258
  });
243
259
  return;
244
260
  }
245
- this._changeState(ConnectionState.CLOSING);
261
+ this._changeState(ConnectionState.ABORTING);
262
+ if (!this.closeReason) {
263
+ this.closeReason = err?.message;
264
+ }
246
265
  await this._ctx.dispose();
247
266
  try {
248
267
  log("aborting protocol... ", {
249
268
  proto: this._protocol
250
269
  }, {
251
270
  F: __dxlog_file,
252
- L: 224,
271
+ L: 239,
253
272
  S: this,
254
273
  C: (f, a) => f(...a)
255
274
  });
@@ -257,7 +276,7 @@ var Connection = class {
257
276
  } catch (err2) {
258
277
  log.catch(err2, void 0, {
259
278
  F: __dxlog_file,
260
- L: 227,
279
+ L: 242,
261
280
  S: this,
262
281
  C: (f, a) => f(...a)
263
282
  });
@@ -267,56 +286,68 @@ var Connection = class {
267
286
  } catch (err2) {
268
287
  log.catch(err2, void 0, {
269
288
  F: __dxlog_file,
270
- L: 234,
289
+ L: 249,
271
290
  S: this,
272
291
  C: (f, a) => f(...a)
273
292
  });
274
293
  }
275
- this._changeState(ConnectionState.CLOSED);
276
- this._callbacks?.onClosed?.(err);
294
+ try {
295
+ this._callbacks?.onClosed?.(err);
296
+ } catch (err2) {
297
+ log.catch(err2, void 0, {
298
+ F: __dxlog_file,
299
+ L: 255,
300
+ S: this,
301
+ C: (f, a) => f(...a)
302
+ });
303
+ }
304
+ this._changeState(ConnectionState.ABORTED);
277
305
  }
278
306
  async close(err) {
279
307
  if (!this.closeReason) {
280
308
  this.closeReason = err?.message;
281
309
  }
282
- if (this._state === ConnectionState.CLOSED) {
310
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
283
311
  return;
284
312
  }
313
+ const lastState = this._state;
285
314
  this._changeState(ConnectionState.CLOSING);
286
315
  await this._ctx.dispose();
287
316
  log("closing...", {
288
317
  peerId: this.ownId
289
318
  }, {
290
319
  F: __dxlog_file,
291
- L: 253,
320
+ L: 277,
292
321
  S: this,
293
322
  C: (f, a) => f(...a)
294
323
  });
295
- try {
296
- await this._protocol.close();
297
- } catch (err2) {
298
- log.catch(err2, void 0, {
299
- F: __dxlog_file,
300
- L: 259,
301
- S: this,
302
- C: (f, a) => f(...a)
303
- });
304
- }
305
- try {
306
- await this._transport?.destroy();
307
- } catch (err2) {
308
- log.catch(err2, void 0, {
309
- F: __dxlog_file,
310
- L: 266,
311
- S: this,
312
- C: (f, a) => f(...a)
313
- });
324
+ if (lastState === ConnectionState.CONNECTED) {
325
+ try {
326
+ await this._protocol.close();
327
+ } catch (err2) {
328
+ log.catch(err2, void 0, {
329
+ F: __dxlog_file,
330
+ L: 284,
331
+ S: this,
332
+ C: (f, a) => f(...a)
333
+ });
334
+ }
335
+ try {
336
+ await this._transport?.destroy();
337
+ } catch (err2) {
338
+ log.catch(err2, void 0, {
339
+ F: __dxlog_file,
340
+ L: 291,
341
+ S: this,
342
+ C: (f, a) => f(...a)
343
+ });
344
+ }
314
345
  }
315
346
  log("closed", {
316
347
  peerId: this.ownId
317
348
  }, {
318
349
  F: __dxlog_file,
319
- L: 269,
350
+ L: 295,
320
351
  S: this,
321
352
  C: (f, a) => f(...a)
322
353
  });
@@ -359,7 +390,7 @@ var Connection = class {
359
390
  err
360
391
  }, {
361
392
  F: __dxlog_file,
362
- L: 306,
393
+ L: 332,
363
394
  S: this,
364
395
  C: (f, a) => f(...a)
365
396
  });
@@ -372,7 +403,7 @@ var Connection = class {
372
403
  async signal(msg) {
373
404
  invariant(msg.sessionId, void 0, {
374
405
  F: __dxlog_file,
375
- L: 315,
406
+ L: 341,
376
407
  S: this,
377
408
  A: [
378
409
  "msg.sessionId",
@@ -382,7 +413,7 @@ var Connection = class {
382
413
  if (!msg.sessionId.equals(this.sessionId)) {
383
414
  log("dropping signal for incorrect session id", void 0, {
384
415
  F: __dxlog_file,
385
- L: 317,
416
+ L: 343,
386
417
  S: this,
387
418
  C: (f, a) => f(...a)
388
419
  });
@@ -390,7 +421,7 @@ var Connection = class {
390
421
  }
391
422
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
392
423
  F: __dxlog_file,
393
- L: 320,
424
+ L: 346,
394
425
  S: this,
395
426
  A: [
396
427
  "msg.data.signal || msg.data.signalBatch",
@@ -399,7 +430,7 @@ var Connection = class {
399
430
  });
400
431
  invariant(msg.author?.equals(this.remoteId), void 0, {
401
432
  F: __dxlog_file,
402
- L: 321,
433
+ L: 347,
403
434
  S: this,
404
435
  A: [
405
436
  "msg.author?.equals(this.remoteId)",
@@ -408,7 +439,7 @@ var Connection = class {
408
439
  });
409
440
  invariant(msg.recipient?.equals(this.ownId), void 0, {
410
441
  F: __dxlog_file,
411
- L: 322,
442
+ L: 348,
412
443
  S: this,
413
444
  A: [
414
445
  "msg.recipient?.equals(this.ownId)",
@@ -432,7 +463,7 @@ var Connection = class {
432
463
  msg: msg.data
433
464
  }, {
434
465
  F: __dxlog_file,
435
- L: 331,
466
+ L: 357,
436
467
  S: this,
437
468
  C: (f, a) => f(...a)
438
469
  });
@@ -440,7 +471,7 @@ var Connection = class {
440
471
  } else {
441
472
  invariant(this._transport, "Connection not ready to accept signals.", {
442
473
  F: __dxlog_file,
443
- L: 334,
474
+ L: 360,
444
475
  S: this,
445
476
  A: [
446
477
  "this._transport",
@@ -453,7 +484,7 @@ var Connection = class {
453
484
  msg: msg.data
454
485
  }, {
455
486
  F: __dxlog_file,
456
- L: 335,
487
+ L: 361,
457
488
  S: this,
458
489
  C: (f, a) => f(...a)
459
490
  });
@@ -467,17 +498,17 @@ var Connection = class {
467
498
  _changeState(state) {
468
499
  log("stateChanged", {
469
500
  from: this._state,
470
- too: state,
501
+ to: state,
471
502
  peerId: this.ownId
472
503
  }, {
473
504
  F: __dxlog_file,
474
- L: 346,
505
+ L: 372,
475
506
  S: this,
476
507
  C: (f, a) => f(...a)
477
508
  });
478
509
  invariant(state !== this._state, "Already in this state.", {
479
510
  F: __dxlog_file,
480
- L: 347,
511
+ L: 373,
481
512
  S: this,
482
513
  A: [
483
514
  "state !== this._state",
@@ -740,7 +771,7 @@ import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
740
771
  // packages/core/mesh/network-manager/src/swarm/peer.ts
741
772
  import { Event as Event2, scheduleTask, synchronized as synchronized2 } from "@dxos/async";
742
773
  import { Context as Context3 } from "@dxos/context";
743
- import { CancelledError as CancelledError2, SystemError } from "@dxos/errors";
774
+ import { CancelledError as CancelledError2, SystemError, TimeoutError } from "@dxos/errors";
744
775
  import { invariant as invariant3 } from "@dxos/invariant";
745
776
  import { PublicKey as PublicKey3 } from "@dxos/keys";
746
777
  import { log as log3 } from "@dxos/log";
@@ -933,6 +964,9 @@ var Peer = class {
933
964
  S: this,
934
965
  C: (f, a) => f(...a)
935
966
  });
967
+ if (err instanceof TimeoutError) {
968
+ await connection.abort(err);
969
+ }
936
970
  await this.closeConnection(err);
937
971
  throw err;
938
972
  } finally {
@@ -952,13 +986,13 @@ var Peer = class {
952
986
  sessionId
953
987
  }, {
954
988
  F: __dxlog_file3,
955
- L: 210,
989
+ L: 213,
956
990
  S: this,
957
991
  C: (f, a) => f(...a)
958
992
  });
959
993
  invariant3(!this.connection, "Already connected.", {
960
994
  F: __dxlog_file3,
961
- L: 217,
995
+ L: 220,
962
996
  S: this,
963
997
  A: [
964
998
  "!this.connection",
@@ -994,7 +1028,7 @@ var Peer = class {
994
1028
  initiator
995
1029
  }, {
996
1030
  F: __dxlog_file3,
997
- L: 236,
1031
+ L: 239,
998
1032
  S: this,
999
1033
  C: (f, a) => f(...a)
1000
1034
  });
@@ -1007,14 +1041,14 @@ var Peer = class {
1007
1041
  initiator
1008
1042
  }, {
1009
1043
  F: __dxlog_file3,
1010
- L: 245,
1044
+ L: 248,
1011
1045
  S: this,
1012
1046
  C: (f, a) => f(...a)
1013
1047
  });
1014
1048
  this._connectionLimiter.doneConnecting(sessionId);
1015
1049
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1016
1050
  F: __dxlog_file3,
1017
- L: 250,
1051
+ L: 253,
1018
1052
  S: this,
1019
1053
  A: [
1020
1054
  "this.connection === connection",
@@ -1029,7 +1063,7 @@ var Peer = class {
1029
1063
  initiator
1030
1064
  }, {
1031
1065
  F: __dxlog_file3,
1032
- L: 252,
1066
+ L: 255,
1033
1067
  S: this,
1034
1068
  C: (f, a) => f(...a)
1035
1069
  });
@@ -1064,7 +1098,7 @@ var Peer = class {
1064
1098
  err
1065
1099
  }, {
1066
1100
  F: __dxlog_file3,
1067
- L: 292,
1101
+ L: 295,
1068
1102
  S: this,
1069
1103
  C: (f, a) => f(...a)
1070
1104
  });
@@ -1077,7 +1111,7 @@ var Peer = class {
1077
1111
  err
1078
1112
  }, {
1079
1113
  F: __dxlog_file3,
1080
- L: 293,
1114
+ L: 296,
1081
1115
  S: this,
1082
1116
  C: (f, a) => f(...a)
1083
1117
  });
@@ -1096,7 +1130,7 @@ var Peer = class {
1096
1130
  sessionId: connection.sessionId
1097
1131
  }, {
1098
1132
  F: __dxlog_file3,
1099
- L: 318,
1133
+ L: 321,
1100
1134
  S: this,
1101
1135
  C: (f, a) => f(...a)
1102
1136
  });
@@ -1106,7 +1140,7 @@ var Peer = class {
1106
1140
  sessionId: connection.sessionId
1107
1141
  }, {
1108
1142
  F: __dxlog_file3,
1109
- L: 324,
1143
+ L: 327,
1110
1144
  S: this,
1111
1145
  C: (f, a) => f(...a)
1112
1146
  });
@@ -1117,7 +1151,7 @@ var Peer = class {
1117
1151
  message
1118
1152
  }, {
1119
1153
  F: __dxlog_file3,
1120
- L: 329,
1154
+ L: 332,
1121
1155
  S: this,
1122
1156
  C: (f, a) => f(...a)
1123
1157
  });
@@ -1132,7 +1166,7 @@ var Peer = class {
1132
1166
  topic: this.topic
1133
1167
  }, {
1134
1168
  F: __dxlog_file3,
1135
- L: 339,
1169
+ L: 342,
1136
1170
  S: this,
1137
1171
  C: (f, a) => f(...a)
1138
1172
  });
@@ -2548,6 +2582,7 @@ import SimplePeerConstructor from "simple-peer";
2548
2582
  import invariant11 from "tiny-invariant";
2549
2583
  import { Event as Event8 } from "@dxos/async";
2550
2584
  import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
2585
+ import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError2, ProtocolError as ProtocolError2, UnknownProtocolError as UnknownProtocolError2 } from "@dxos/errors";
2551
2586
  import { PublicKey as PublicKey10 } from "@dxos/keys";
2552
2587
  import { log as log11 } from "@dxos/log";
2553
2588
  import { trace as trace4 } from "@dxos/protocols";
@@ -2573,13 +2608,13 @@ var SimplePeerTransport = class {
2573
2608
  id: this._instanceId
2574
2609
  }), {
2575
2610
  F: __dxlog_file12,
2576
- L: 39,
2611
+ L: 41,
2577
2612
  S: this,
2578
2613
  C: (f, a) => f(...a)
2579
2614
  });
2580
2615
  log11("created connection", params, {
2581
2616
  F: __dxlog_file12,
2582
- L: 40,
2617
+ L: 42,
2583
2618
  S: this,
2584
2619
  C: (f, a) => f(...a)
2585
2620
  });
@@ -2592,7 +2627,7 @@ var SimplePeerTransport = class {
2592
2627
  this._peer.on("signal", async (data) => {
2593
2628
  log11("signal", data, {
2594
2629
  F: __dxlog_file12,
2595
- L: 49,
2630
+ L: 51,
2596
2631
  S: this,
2597
2632
  C: (f, a) => f(...a)
2598
2633
  });
@@ -2605,7 +2640,7 @@ var SimplePeerTransport = class {
2605
2640
  this._peer.on("connect", () => {
2606
2641
  log11("connected", void 0, {
2607
2642
  F: __dxlog_file12,
2608
- L: 54,
2643
+ L: 56,
2609
2644
  S: this,
2610
2645
  C: (f, a) => f(...a)
2611
2646
  });
@@ -2615,7 +2650,7 @@ var SimplePeerTransport = class {
2615
2650
  this._peer.on("close", async () => {
2616
2651
  log11("closed", void 0, {
2617
2652
  F: __dxlog_file12,
2618
- L: 60,
2653
+ L: 62,
2619
2654
  S: this,
2620
2655
  C: (f, a) => f(...a)
2621
2656
  });
@@ -2623,7 +2658,35 @@ var SimplePeerTransport = class {
2623
2658
  this.closed.emit();
2624
2659
  });
2625
2660
  this._peer.on("error", async (err) => {
2626
- this.errors.raise(err);
2661
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
2662
+ if (err.errorDetail === "sctp-failure") {
2663
+ this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
2664
+ } else {
2665
+ this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
2666
+ }
2667
+ } else if (err.name === "InvalidStateError") {
2668
+ this.errors.raise(new ConnectionResetError2("safari WebRTC error", err));
2669
+ } else if ("code" in err) {
2670
+ switch (err.code) {
2671
+ case "ERR_WEBRTC_SUPPORT":
2672
+ this.errors.raise(new ProtocolError2("WebRTC not supported", err));
2673
+ case "ERR_ICE_CONNECTION_FAILURE":
2674
+ case "ERR_DATA_CHANNEL":
2675
+ case "ERR_CONNECTION_FAILURE":
2676
+ case "ERR_SIGNALING":
2677
+ this.errors.raise(new ConnectivityError2("unknown communication failure", err));
2678
+ case "ERR_CREATE_OFFER":
2679
+ case "ERR_CREATE_ANSWER":
2680
+ case "ERR_SET_LOCAL_DESCRIPTION":
2681
+ case "ERR_SET_REMOTE_DESCRIPTION":
2682
+ case "ERR_ADD_ICE_CANDIDATE":
2683
+ this.errors.raise(new UnknownProtocolError2("unknown simple-peer library failure", err));
2684
+ default:
2685
+ this.errors.raise(new Error("unknown simple-peer error"));
2686
+ }
2687
+ } else {
2688
+ this.errors.raise(err);
2689
+ }
2627
2690
  try {
2628
2691
  if (typeof this._peer?._pc.getStats === "function") {
2629
2692
  this._peer._pc.getStats().then((stats) => {
@@ -2632,13 +2695,19 @@ var SimplePeerTransport = class {
2632
2695
  stats
2633
2696
  }, {
2634
2697
  F: __dxlog_file12,
2635
- L: 72,
2698
+ L: 107,
2636
2699
  S: this,
2637
2700
  C: (f, a) => f(...a)
2638
2701
  });
2639
2702
  });
2640
2703
  }
2641
- } catch {
2704
+ } catch (err2) {
2705
+ log11.catch(err2, void 0, {
2706
+ F: __dxlog_file12,
2707
+ L: 114,
2708
+ S: this,
2709
+ C: (f, a) => f(...a)
2710
+ });
2642
2711
  }
2643
2712
  await this.destroy();
2644
2713
  });
@@ -2646,7 +2715,7 @@ var SimplePeerTransport = class {
2646
2715
  id: this._instanceId
2647
2716
  }), {
2648
2717
  F: __dxlog_file12,
2649
- L: 82,
2718
+ L: 119,
2650
2719
  S: this,
2651
2720
  C: (f, a) => f(...a)
2652
2721
  });
@@ -2654,7 +2723,7 @@ var SimplePeerTransport = class {
2654
2723
  async destroy() {
2655
2724
  log11("closing...", void 0, {
2656
2725
  F: __dxlog_file12,
2657
- L: 86,
2726
+ L: 123,
2658
2727
  S: this,
2659
2728
  C: (f, a) => f(...a)
2660
2729
  });
@@ -2664,7 +2733,7 @@ var SimplePeerTransport = class {
2664
2733
  this.closed.emit();
2665
2734
  log11("closed", void 0, {
2666
2735
  F: __dxlog_file12,
2667
- L: 91,
2736
+ L: 128,
2668
2737
  S: this,
2669
2738
  C: (f, a) => f(...a)
2670
2739
  });
@@ -2822,6 +2891,7 @@ import { Writable } from "@dxos/node-std/stream";
2822
2891
  import { Event as Event9 } from "@dxos/async";
2823
2892
  import { Context as Context6 } from "@dxos/context";
2824
2893
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
2894
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/errors";
2825
2895
  import { invariant as invariant13 } from "@dxos/invariant";
2826
2896
  import { PublicKey as PublicKey12 } from "@dxos/keys";
2827
2897
  import { log as log13 } from "@dxos/log";
@@ -2846,7 +2916,7 @@ var SimplePeerTransportProxy = class {
2846
2916
  this._serviceStream.subscribe(async (event) => {
2847
2917
  log13("SimplePeerTransportProxy: event", event, {
2848
2918
  F: __dxlog_file14,
2849
- L: 51,
2919
+ L: 58,
2850
2920
  S: this,
2851
2921
  C: (f, a) => f(...a)
2852
2922
  });
@@ -2866,7 +2936,7 @@ var SimplePeerTransportProxy = class {
2866
2936
  }).then(() => callback(), (err) => {
2867
2937
  log13.catch(err, void 0, {
2868
2938
  F: __dxlog_file14,
2869
- L: 69,
2939
+ L: 76,
2870
2940
  S: this,
2871
2941
  C: (f, a) => f(...a)
2872
2942
  });
@@ -2875,14 +2945,14 @@ var SimplePeerTransportProxy = class {
2875
2945
  }));
2876
2946
  }, (error) => log13.catch(error, void 0, {
2877
2947
  F: __dxlog_file14,
2878
- L: 75,
2948
+ L: 82,
2879
2949
  S: this,
2880
2950
  C: (f, a) => f(...a)
2881
2951
  }));
2882
2952
  }
2883
2953
  async _handleConnection(connectionEvent) {
2884
2954
  if (connectionEvent.error) {
2885
- this.errors.raise(new Error(connectionEvent.error));
2955
+ this.errors.raise(decodeError(connectionEvent.error));
2886
2956
  }
2887
2957
  switch (connectionEvent.state) {
2888
2958
  case ConnectionState4.CONNECTED: {
@@ -2905,7 +2975,7 @@ var SimplePeerTransportProxy = class {
2905
2975
  this._params.bridgeService.sendSignal({
2906
2976
  proxyId: this._proxyId,
2907
2977
  signal
2908
- }).catch((err) => this.errors.raise(err));
2978
+ }).catch((err) => this.errors.raise(decodeError(err)));
2909
2979
  }
2910
2980
  // TODO(burdon): Move open from constructor.
2911
2981
  async destroy() {
@@ -2921,7 +2991,7 @@ var SimplePeerTransportProxy = class {
2921
2991
  } catch (err) {
2922
2992
  log13.catch(err, void 0, {
2923
2993
  F: __dxlog_file14,
2924
- L: 126,
2994
+ L: 133,
2925
2995
  S: this,
2926
2996
  C: (f, a) => f(...a)
2927
2997
  });
@@ -2957,7 +3027,7 @@ var SimplePeerTransportProxyFactory = class {
2957
3027
  createTransport(options) {
2958
3028
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
2959
3029
  F: __dxlog_file14,
2960
- L: 163,
3030
+ L: 170,
2961
3031
  S: this,
2962
3032
  A: [
2963
3033
  "this._bridgeService",
@@ -2973,6 +3043,22 @@ var SimplePeerTransportProxyFactory = class {
2973
3043
  return transport;
2974
3044
  }
2975
3045
  };
3046
+ var decodeError = (err) => {
3047
+ const message = typeof err === "string" ? err : err.message;
3048
+ if (message.includes("ConnectionResetError")) {
3049
+ return new ConnectionResetError3(message);
3050
+ } else if (message.includes("TimeoutError")) {
3051
+ return new TimeoutError2(message);
3052
+ } else if (message.includes("ProtocolError")) {
3053
+ return new ProtocolError3(message);
3054
+ } else if (message.includes("ConnectivityError")) {
3055
+ return new ConnectivityError3(message);
3056
+ } else if (message.includes("UnknownProtocolError")) {
3057
+ return new UnknownProtocolError3(message);
3058
+ } else {
3059
+ return typeof err === "string" ? new Error(err) : err;
3060
+ }
3061
+ };
2976
3062
 
2977
3063
  // packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
2978
3064
  import { Duplex as Duplex2 } from "stream";
@@ -3360,4 +3446,4 @@ export {
3360
3446
  createLibDataChannelTransportFactory,
3361
3447
  createTeleportProtocolFactory
3362
3448
  };
3363
- //# sourceMappingURL=chunk-VP6DWC3F.mjs.map
3449
+ //# sourceMappingURL=chunk-O2SMNRBC.mjs.map