@dxos/network-manager 0.1.58-main.7858df5 → 0.1.58-main.82680ea

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.
@@ -735,7 +735,7 @@ var Connection = class {
735
735
  this.closeReason = err?.message;
736
736
  }
737
737
  if (err instanceof import_protocols.ConnectionResetError) {
738
- (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
738
+ import_log.log.warn("aborting due to transport ConnectionResetError", void 0, {
739
739
  F: __dxlog_file,
740
740
  L: 197,
741
741
  S: this,
@@ -743,7 +743,7 @@ var Connection = class {
743
743
  });
744
744
  this.abort().catch((err2) => this.errors.raise(err2));
745
745
  } else if (err instanceof import_protocols.ConnectivityError) {
746
- (0, import_log.log)("aborting due to transport ConnectivityError", void 0, {
746
+ import_log.log.warn("aborting due to transport ConnectivityError", void 0, {
747
747
  F: __dxlog_file,
748
748
  L: 200,
749
749
  S: this,
@@ -751,7 +751,7 @@ var Connection = class {
751
751
  });
752
752
  this.abort().catch((err2) => this.errors.raise(err2));
753
753
  } else if (err instanceof import_protocols.UnknownProtocolError) {
754
- (0, import_log.log)("unsure what to do for UnknownProtocolError", {
754
+ import_log.log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
755
755
  err
756
756
  }, {
757
757
  F: __dxlog_file,
@@ -782,14 +782,14 @@ var Connection = class {
782
782
  err
783
783
  }, {
784
784
  F: __dxlog_file,
785
- L: 224,
785
+ L: 225,
786
786
  S: this,
787
787
  C: (f, a) => f(...a)
788
788
  });
789
789
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
790
790
  (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
791
791
  F: __dxlog_file,
792
- L: 226,
792
+ L: 227,
793
793
  S: this,
794
794
  C: (f, a) => f(...a)
795
795
  });
@@ -805,7 +805,7 @@ var Connection = class {
805
805
  proto: this._protocol
806
806
  }, {
807
807
  F: __dxlog_file,
808
- L: 239,
808
+ L: 240,
809
809
  S: this,
810
810
  C: (f, a) => f(...a)
811
811
  });
@@ -813,7 +813,7 @@ var Connection = class {
813
813
  } catch (err2) {
814
814
  import_log.log.catch(err2, void 0, {
815
815
  F: __dxlog_file,
816
- L: 242,
816
+ L: 243,
817
817
  S: this,
818
818
  C: (f, a) => f(...a)
819
819
  });
@@ -823,7 +823,7 @@ var Connection = class {
823
823
  } catch (err2) {
824
824
  import_log.log.catch(err2, void 0, {
825
825
  F: __dxlog_file,
826
- L: 249,
826
+ L: 250,
827
827
  S: this,
828
828
  C: (f, a) => f(...a)
829
829
  });
@@ -833,7 +833,7 @@ var Connection = class {
833
833
  } catch (err2) {
834
834
  import_log.log.catch(err2, void 0, {
835
835
  F: __dxlog_file,
836
- L: 255,
836
+ L: 256,
837
837
  S: this,
838
838
  C: (f, a) => f(...a)
839
839
  });
@@ -854,7 +854,7 @@ var Connection = class {
854
854
  peerId: this.ownId
855
855
  }, {
856
856
  F: __dxlog_file,
857
- L: 277,
857
+ L: 278,
858
858
  S: this,
859
859
  C: (f, a) => f(...a)
860
860
  });
@@ -864,7 +864,7 @@ var Connection = class {
864
864
  } catch (err2) {
865
865
  import_log.log.catch(err2, void 0, {
866
866
  F: __dxlog_file,
867
- L: 284,
867
+ L: 285,
868
868
  S: this,
869
869
  C: (f, a) => f(...a)
870
870
  });
@@ -874,7 +874,7 @@ var Connection = class {
874
874
  } catch (err2) {
875
875
  import_log.log.catch(err2, void 0, {
876
876
  F: __dxlog_file,
877
- L: 291,
877
+ L: 292,
878
878
  S: this,
879
879
  C: (f, a) => f(...a)
880
880
  });
@@ -884,7 +884,7 @@ var Connection = class {
884
884
  peerId: this.ownId
885
885
  }, {
886
886
  F: __dxlog_file,
887
- L: 295,
887
+ L: 296,
888
888
  S: this,
889
889
  C: (f, a) => f(...a)
890
890
  });
@@ -927,7 +927,7 @@ var Connection = class {
927
927
  err
928
928
  }, {
929
929
  F: __dxlog_file,
930
- L: 332,
930
+ L: 333,
931
931
  S: this,
932
932
  C: (f, a) => f(...a)
933
933
  });
@@ -940,7 +940,7 @@ var Connection = class {
940
940
  async signal(msg) {
941
941
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
942
942
  F: __dxlog_file,
943
- L: 341,
943
+ L: 342,
944
944
  S: this,
945
945
  A: [
946
946
  "msg.sessionId",
@@ -950,7 +950,7 @@ var Connection = class {
950
950
  if (!msg.sessionId.equals(this.sessionId)) {
951
951
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
952
952
  F: __dxlog_file,
953
- L: 343,
953
+ L: 344,
954
954
  S: this,
955
955
  C: (f, a) => f(...a)
956
956
  });
@@ -958,7 +958,7 @@ var Connection = class {
958
958
  }
959
959
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
960
960
  F: __dxlog_file,
961
- L: 346,
961
+ L: 347,
962
962
  S: this,
963
963
  A: [
964
964
  "msg.data.signal || msg.data.signalBatch",
@@ -967,7 +967,7 @@ var Connection = class {
967
967
  });
968
968
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
969
969
  F: __dxlog_file,
970
- L: 347,
970
+ L: 348,
971
971
  S: this,
972
972
  A: [
973
973
  "msg.author?.equals(this.remoteId)",
@@ -976,7 +976,7 @@ var Connection = class {
976
976
  });
977
977
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
978
978
  F: __dxlog_file,
979
- L: 348,
979
+ L: 349,
980
980
  S: this,
981
981
  A: [
982
982
  "msg.recipient?.equals(this.ownId)",
@@ -1000,7 +1000,7 @@ var Connection = class {
1000
1000
  msg: msg.data
1001
1001
  }, {
1002
1002
  F: __dxlog_file,
1003
- L: 357,
1003
+ L: 358,
1004
1004
  S: this,
1005
1005
  C: (f, a) => f(...a)
1006
1006
  });
@@ -1008,7 +1008,7 @@ var Connection = class {
1008
1008
  } else {
1009
1009
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
1010
1010
  F: __dxlog_file,
1011
- L: 360,
1011
+ L: 361,
1012
1012
  S: this,
1013
1013
  A: [
1014
1014
  "this._transport",
@@ -1021,7 +1021,7 @@ var Connection = class {
1021
1021
  msg: msg.data
1022
1022
  }, {
1023
1023
  F: __dxlog_file,
1024
- L: 361,
1024
+ L: 362,
1025
1025
  S: this,
1026
1026
  C: (f, a) => f(...a)
1027
1027
  });
@@ -1039,13 +1039,13 @@ var Connection = class {
1039
1039
  peerId: this.ownId
1040
1040
  }, {
1041
1041
  F: __dxlog_file,
1042
- L: 372,
1042
+ L: 373,
1043
1043
  S: this,
1044
1044
  C: (f, a) => f(...a)
1045
1045
  });
1046
1046
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
1047
1047
  F: __dxlog_file,
1048
- L: 373,
1048
+ L: 374,
1049
1049
  S: this,
1050
1050
  A: [
1051
1051
  "state !== this._state",
@@ -1120,6 +1120,20 @@ var Peer = class {
1120
1120
  */
1121
1121
  async onOffer(message) {
1122
1122
  const remoteId = message.author;
1123
+ if (this.connection && ![
1124
+ ConnectionState.CREATED,
1125
+ ConnectionState.INITIAL
1126
+ ].includes(this.connection.state)) {
1127
+ import_log2.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
1128
+ F: __dxlog_file2,
1129
+ L: 112,
1130
+ S: this,
1131
+ C: (f, a) => f(...a)
1132
+ });
1133
+ return {
1134
+ accept: false
1135
+ };
1136
+ }
1123
1137
  if (this.connection || this.initiating) {
1124
1138
  if (remoteId.toHex() < this.localPeerId.toHex()) {
1125
1139
  (0, import_log2.log)("close local connection", {
@@ -1129,7 +1143,7 @@ var Peer = class {
1129
1143
  sessionId: this.connection?.sessionId
1130
1144
  }, {
1131
1145
  F: __dxlog_file2,
1132
- L: 117,
1146
+ L: 121,
1133
1147
  S: this,
1134
1148
  C: (f, a) => f(...a)
1135
1149
  });
@@ -1146,7 +1160,7 @@ var Peer = class {
1146
1160
  if (!this.connection) {
1147
1161
  (0, import_invariant2.invariant)(message.sessionId, void 0, {
1148
1162
  F: __dxlog_file2,
1149
- L: 137,
1163
+ L: 141,
1150
1164
  S: this,
1151
1165
  A: [
1152
1166
  "message.sessionId",
@@ -1167,7 +1181,7 @@ var Peer = class {
1167
1181
  err
1168
1182
  }, {
1169
1183
  F: __dxlog_file2,
1170
- L: 147,
1184
+ L: 151,
1171
1185
  S: this,
1172
1186
  C: (f, a) => f(...a)
1173
1187
  });
@@ -1189,7 +1203,7 @@ var Peer = class {
1189
1203
  async initiateConnection() {
1190
1204
  (0, import_invariant2.invariant)(!this.initiating, "Initiation in progress.", {
1191
1205
  F: __dxlog_file2,
1192
- L: 164,
1206
+ L: 168,
1193
1207
  S: this,
1194
1208
  A: [
1195
1209
  "!this.initiating",
@@ -1198,7 +1212,7 @@ var Peer = class {
1198
1212
  });
1199
1213
  (0, import_invariant2.invariant)(!this.connection, "Already connected.", {
1200
1214
  F: __dxlog_file2,
1201
- L: 165,
1215
+ L: 169,
1202
1216
  S: this,
1203
1217
  A: [
1204
1218
  "!this.connection",
@@ -1213,7 +1227,7 @@ var Peer = class {
1213
1227
  sessionId
1214
1228
  }, {
1215
1229
  F: __dxlog_file2,
1216
- L: 167,
1230
+ L: 171,
1217
1231
  S: this,
1218
1232
  C: (f, a) => f(...a)
1219
1233
  });
@@ -1238,14 +1252,14 @@ var Peer = class {
1238
1252
  remoteId: this.id
1239
1253
  }, {
1240
1254
  F: __dxlog_file2,
1241
- L: 183,
1255
+ L: 187,
1242
1256
  S: this,
1243
1257
  C: (f, a) => f(...a)
1244
1258
  });
1245
1259
  if (connection.state !== ConnectionState.INITIAL) {
1246
1260
  (0, import_log2.log)("ignoring response", void 0, {
1247
1261
  F: __dxlog_file2,
1248
- L: 185,
1262
+ L: 189,
1249
1263
  S: this,
1250
1264
  C: (f, a) => f(...a)
1251
1265
  });
@@ -1265,11 +1279,17 @@ var Peer = class {
1265
1279
  remoteId: this.id
1266
1280
  }, {
1267
1281
  F: __dxlog_file2,
1268
- L: 196,
1282
+ L: 200,
1269
1283
  S: this,
1270
1284
  C: (f, a) => f(...a)
1271
1285
  });
1272
1286
  if (err instanceof import_protocols2.TimeoutError) {
1287
+ import_log2.log.warn("aborting connection due to signalling failure", void 0, {
1288
+ F: __dxlog_file2,
1289
+ L: 202,
1290
+ S: this,
1291
+ C: (f, a) => f(...a)
1292
+ });
1273
1293
  await connection.abort(err);
1274
1294
  }
1275
1295
  await this.closeConnection(err);
@@ -1291,13 +1311,13 @@ var Peer = class {
1291
1311
  sessionId
1292
1312
  }, {
1293
1313
  F: __dxlog_file2,
1294
- L: 213,
1314
+ L: 218,
1295
1315
  S: this,
1296
1316
  C: (f, a) => f(...a)
1297
1317
  });
1298
1318
  (0, import_invariant2.invariant)(!this.connection, "Already connected.", {
1299
1319
  F: __dxlog_file2,
1300
- L: 220,
1320
+ L: 225,
1301
1321
  S: this,
1302
1322
  A: [
1303
1323
  "!this.connection",
@@ -1333,7 +1353,7 @@ var Peer = class {
1333
1353
  initiator
1334
1354
  }, {
1335
1355
  F: __dxlog_file2,
1336
- L: 239,
1356
+ L: 244,
1337
1357
  S: this,
1338
1358
  C: (f, a) => f(...a)
1339
1359
  });
@@ -1346,14 +1366,14 @@ var Peer = class {
1346
1366
  initiator
1347
1367
  }, {
1348
1368
  F: __dxlog_file2,
1349
- L: 248,
1369
+ L: 253,
1350
1370
  S: this,
1351
1371
  C: (f, a) => f(...a)
1352
1372
  });
1353
1373
  this._connectionLimiter.doneConnecting(sessionId);
1354
1374
  (0, import_invariant2.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1355
1375
  F: __dxlog_file2,
1356
- L: 253,
1376
+ L: 258,
1357
1377
  S: this,
1358
1378
  A: [
1359
1379
  "this.connection === connection",
@@ -1368,7 +1388,7 @@ var Peer = class {
1368
1388
  initiator
1369
1389
  }, {
1370
1390
  F: __dxlog_file2,
1371
- L: 255,
1391
+ L: 260,
1372
1392
  S: this,
1373
1393
  C: (f, a) => f(...a)
1374
1394
  });
@@ -1403,7 +1423,7 @@ var Peer = class {
1403
1423
  err
1404
1424
  }, {
1405
1425
  F: __dxlog_file2,
1406
- L: 295,
1426
+ L: 300,
1407
1427
  S: this,
1408
1428
  C: (f, a) => f(...a)
1409
1429
  });
@@ -1416,7 +1436,7 @@ var Peer = class {
1416
1436
  err
1417
1437
  }, {
1418
1438
  F: __dxlog_file2,
1419
- L: 296,
1439
+ L: 301,
1420
1440
  S: this,
1421
1441
  C: (f, a) => f(...a)
1422
1442
  });
@@ -1435,7 +1455,7 @@ var Peer = class {
1435
1455
  sessionId: connection.sessionId
1436
1456
  }, {
1437
1457
  F: __dxlog_file2,
1438
- L: 321,
1458
+ L: 326,
1439
1459
  S: this,
1440
1460
  C: (f, a) => f(...a)
1441
1461
  });
@@ -1445,7 +1465,7 @@ var Peer = class {
1445
1465
  sessionId: connection.sessionId
1446
1466
  }, {
1447
1467
  F: __dxlog_file2,
1448
- L: 327,
1468
+ L: 332,
1449
1469
  S: this,
1450
1470
  C: (f, a) => f(...a)
1451
1471
  });
@@ -1456,7 +1476,7 @@ var Peer = class {
1456
1476
  message
1457
1477
  }, {
1458
1478
  F: __dxlog_file2,
1459
- L: 332,
1479
+ L: 337,
1460
1480
  S: this,
1461
1481
  C: (f, a) => f(...a)
1462
1482
  });
@@ -1471,7 +1491,7 @@ var Peer = class {
1471
1491
  topic: this.topic
1472
1492
  }, {
1473
1493
  F: __dxlog_file2,
1474
- L: 342,
1494
+ L: 347,
1475
1495
  S: this,
1476
1496
  C: (f, a) => f(...a)
1477
1497
  });
@@ -3205,24 +3225,28 @@ var SimplePeerTransport = class {
3205
3225
  switch (err.code) {
3206
3226
  case "ERR_WEBRTC_SUPPORT":
3207
3227
  this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
3228
+ break;
3208
3229
  case "ERR_ICE_CONNECTION_FAILURE":
3209
3230
  case "ERR_DATA_CHANNEL":
3210
3231
  case "ERR_CONNECTION_FAILURE":
3211
3232
  case "ERR_SIGNALING":
3212
3233
  this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
3234
+ break;
3213
3235
  case "ERR_CREATE_OFFER":
3214
3236
  case "ERR_CREATE_ANSWER":
3215
3237
  case "ERR_SET_LOCAL_DESCRIPTION":
3216
3238
  case "ERR_SET_REMOTE_DESCRIPTION":
3217
3239
  case "ERR_ADD_ICE_CANDIDATE":
3218
3240
  this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
3241
+ break;
3219
3242
  default:
3220
3243
  this.errors.raise(new Error("unknown simple-peer error"));
3244
+ break;
3221
3245
  }
3222
3246
  } else {
3223
3247
  import_log11.log.info("unknown peer connection error", err, {
3224
3248
  F: __dxlog_file12,
3225
- L: 96,
3249
+ L: 101,
3226
3250
  S: this,
3227
3251
  C: (f, a) => f(...a)
3228
3252
  });
@@ -3236,7 +3260,7 @@ var SimplePeerTransport = class {
3236
3260
  stats
3237
3261
  }, {
3238
3262
  F: __dxlog_file12,
3239
- L: 104,
3263
+ L: 109,
3240
3264
  S: this,
3241
3265
  C: (f, a) => f(...a)
3242
3266
  });
@@ -3245,7 +3269,7 @@ var SimplePeerTransport = class {
3245
3269
  } catch (err2) {
3246
3270
  import_log11.log.catch(err2, void 0, {
3247
3271
  F: __dxlog_file12,
3248
- L: 111,
3272
+ L: 116,
3249
3273
  S: this,
3250
3274
  C: (f, a) => f(...a)
3251
3275
  });
@@ -3256,7 +3280,7 @@ var SimplePeerTransport = class {
3256
3280
  id: this._instanceId
3257
3281
  }), {
3258
3282
  F: __dxlog_file12,
3259
- L: 116,
3283
+ L: 121,
3260
3284
  S: this,
3261
3285
  C: (f, a) => f(...a)
3262
3286
  });
@@ -3264,7 +3288,7 @@ var SimplePeerTransport = class {
3264
3288
  async destroy() {
3265
3289
  (0, import_log11.log)("closing...", void 0, {
3266
3290
  F: __dxlog_file12,
3267
- L: 120,
3291
+ L: 125,
3268
3292
  S: this,
3269
3293
  C: (f, a) => f(...a)
3270
3294
  });
@@ -3274,7 +3298,7 @@ var SimplePeerTransport = class {
3274
3298
  this.closed.emit();
3275
3299
  (0, import_log11.log)("closed", void 0, {
3276
3300
  F: __dxlog_file12,
3277
- L: 125,
3301
+ L: 130,
3278
3302
  S: this,
3279
3303
  C: (f, a) => f(...a)
3280
3304
  });
@@ -3376,7 +3400,8 @@ var SimplePeerTransportService = class {
3376
3400
  const transportState = {
3377
3401
  transport,
3378
3402
  stream: duplex,
3379
- writeCallbacks: []
3403
+ writeCallbacks: [],
3404
+ state: "OPEN"
3380
3405
  };
3381
3406
  ready();
3382
3407
  this.transports.set(request.proxyId, transportState);
@@ -3386,7 +3411,7 @@ var SimplePeerTransportService = class {
3386
3411
  async sendSignal({ proxyId, signal }) {
3387
3412
  (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3388
3413
  F: __dxlog_file13,
3389
- L: 110,
3414
+ L: 112,
3390
3415
  S: this,
3391
3416
  A: [
3392
3417
  "this.transports.has(proxyId)",
@@ -3396,9 +3421,17 @@ var SimplePeerTransportService = class {
3396
3421
  await this.transports.get(proxyId).transport.signal(signal);
3397
3422
  }
3398
3423
  async sendData({ proxyId, payload }) {
3424
+ if (this.transports.get(proxyId)?.state !== "OPEN") {
3425
+ import_log12.log.debug("transport is closed", void 0, {
3426
+ F: __dxlog_file13,
3427
+ L: 118,
3428
+ S: this,
3429
+ C: (f, a) => f(...a)
3430
+ });
3431
+ }
3399
3432
  (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3400
3433
  F: __dxlog_file13,
3401
- L: 115,
3434
+ L: 120,
3402
3435
  S: this,
3403
3436
  A: [
3404
3437
  "this.transports.has(proxyId)",
@@ -3416,10 +3449,12 @@ var SimplePeerTransportService = class {
3416
3449
  async close({ proxyId }) {
3417
3450
  await this.transports.get(proxyId)?.transport.destroy();
3418
3451
  await this.transports.get(proxyId)?.stream.end();
3419
- this.transports.delete(proxyId);
3452
+ if (this.transports.get(proxyId)) {
3453
+ this.transports.get(proxyId).state = "CLOSED";
3454
+ }
3420
3455
  (0, import_log12.log)("Closed.", void 0, {
3421
3456
  F: __dxlog_file13,
3422
- L: 129,
3457
+ L: 136,
3423
3458
  S: this,
3424
3459
  C: (f, a) => f(...a)
3425
3460
  });