@dxos/network-manager 0.1.22 → 0.1.23

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.
@@ -725,7 +725,7 @@ var Swarm = class {
725
725
  peerId: _ownPeerId
726
726
  }, {
727
727
  file: "swarm.ts",
728
- line: 80,
728
+ line: 83,
729
729
  scope: this,
730
730
  callSite: (f, a) => f(...a)
731
731
  });
@@ -742,7 +742,7 @@ var Swarm = class {
742
742
  onMessage: async (message) => await this._swarmMessenger.receiveMessage(message)
743
743
  }).catch((error) => log4.catch(error, {}, {
744
744
  file: "swarm.ts",
745
- line: 96,
745
+ line: 99,
746
746
  scope: this,
747
747
  callSite: (f, a) => f(...a)
748
748
  }));
@@ -766,7 +766,7 @@ var Swarm = class {
766
766
  async destroy() {
767
767
  log4("destroying...", {}, {
768
768
  file: "swarm.ts",
769
- line: 124,
769
+ line: 127,
770
770
  scope: this,
771
771
  callSite: (f, a) => f(...a)
772
772
  });
@@ -775,7 +775,7 @@ var Swarm = class {
775
775
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
776
776
  log4("destroyed", {}, {
777
777
  file: "swarm.ts",
778
- line: 128,
778
+ line: 131,
779
779
  scope: this,
780
780
  callSite: (f, a) => f(...a)
781
781
  });
@@ -790,7 +790,7 @@ var Swarm = class {
790
790
  topology: getClassName(topology)
791
791
  }, {
792
792
  file: "swarm.ts",
793
- line: 136,
793
+ line: 139,
794
794
  scope: this,
795
795
  callSite: (f, a) => f(...a)
796
796
  });
@@ -800,30 +800,31 @@ var Swarm = class {
800
800
  this._topology.update();
801
801
  }
802
802
  onSwarmEvent(swarmEvent) {
803
+ var _a;
803
804
  log4("swarm event", {
804
805
  swarmEvent
805
806
  }, {
806
807
  file: "swarm.ts",
807
- line: 149,
808
+ line: 152,
808
809
  scope: this,
809
810
  callSite: (f, a) => f(...a)
810
811
  });
812
+ if (this._ctx.disposed) {
813
+ log4.warn("ignored for offline swarm", {}, {
814
+ file: "swarm.ts",
815
+ line: 155,
816
+ scope: this,
817
+ callSite: (f, a) => f(...a)
818
+ });
819
+ return;
820
+ }
811
821
  if (swarmEvent.peerAvailable) {
812
- if (this._ctx.disposed) {
813
- log4.warn("ignored for offline swarm", {}, {
814
- file: "swarm.ts",
815
- line: 153,
816
- scope: this,
817
- callSite: (f, a) => f(...a)
818
- });
819
- return;
820
- }
821
822
  const peerId = PublicKey3.from(swarmEvent.peerAvailable.peer);
822
823
  log4("new peer", {
823
824
  peerId
824
825
  }, {
825
826
  file: "swarm.ts",
826
- line: 157,
827
+ line: 161,
827
828
  scope: this,
828
829
  callSite: (f, a) => f(...a)
829
830
  });
@@ -835,10 +836,10 @@ var Swarm = class {
835
836
  const peer1 = this._peers.get(PublicKey3.from(swarmEvent.peerLeft.peer));
836
837
  if (peer1) {
837
838
  peer1.advertizing = false;
838
- if (!peer1.connection || peer1.connection.state !== ConnectionState.CONNECTED) {
839
+ if (((_a = peer1.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
839
840
  void this._destroyPeer(peer1.id).catch((err) => log4.catch(err, {}, {
840
841
  file: "swarm.ts",
841
- line: 168,
842
+ line: 172,
842
843
  scope: this,
843
844
  callSite: (f, a) => f(...a)
844
845
  }));
@@ -853,14 +854,14 @@ var Swarm = class {
853
854
  message
854
855
  }, {
855
856
  file: "swarm.ts",
856
- line: 178,
857
+ line: 182,
857
858
  scope: this,
858
859
  callSite: (f, a) => f(...a)
859
860
  });
860
861
  if (this._ctx.disposed) {
861
862
  log4.info("ignored for offline swarm", {}, {
862
863
  file: "swarm.ts",
863
- line: 180,
864
+ line: 184,
864
865
  scope: this,
865
866
  callSite: (f, a) => f(...a)
866
867
  });
@@ -874,7 +875,7 @@ var Swarm = class {
874
875
  message
875
876
  }, {
876
877
  file: "swarm.ts",
877
- line: 187,
878
+ line: 191,
878
879
  scope: this,
879
880
  callSite: (f, a) => f(...a)
880
881
  });
@@ -887,7 +888,7 @@ var Swarm = class {
887
888
  message
888
889
  }, {
889
890
  file: "swarm.ts",
890
- line: 191,
891
+ line: 195,
891
892
  scope: this,
892
893
  callSite: (f, a) => f(...a)
893
894
  });
@@ -906,14 +907,14 @@ var Swarm = class {
906
907
  message
907
908
  }, {
908
909
  file: "swarm.ts",
909
- line: 202,
910
+ line: 207,
910
911
  scope: this,
911
912
  callSite: (f, a) => f(...a)
912
913
  });
913
914
  if (this._ctx.disposed) {
914
915
  log4.info("ignored for offline swarm", {}, {
915
916
  file: "swarm.ts",
916
- line: 204,
917
+ line: 209,
917
918
  scope: this,
918
919
  callSite: (f, a) => f(...a)
919
920
  });
@@ -928,24 +929,13 @@ var Swarm = class {
928
929
  // For debug purposes
929
930
  async goOffline() {
930
931
  await this._ctx.dispose();
931
- [
932
- ...this._peers.values()
933
- ].forEach((peer) => {
934
- peer.advertizing = false;
935
- });
936
932
  await Promise.all([
937
933
  ...this._peers.keys()
938
- ].map((peerId) => this._closeConnection(peerId)));
934
+ ].map((peerId) => this._destroyPeer(peerId)));
939
935
  }
940
936
  // For debug purposes
941
937
  async goOnline() {
942
938
  this._ctx = new Context();
943
- [
944
- ...this._peers.values()
945
- ].forEach((peer) => {
946
- peer.advertizing = true;
947
- });
948
- this._topology.update();
949
939
  }
950
940
  _getOrCreatePeer(peerId) {
951
941
  let peer = this._peers.get(peerId);
@@ -1002,7 +992,7 @@ var Swarm = class {
1002
992
  } catch (err) {
1003
993
  log4.warn("initiation error", err, {
1004
994
  file: "swarm.ts",
1005
- line: 311,
995
+ line: 309,
1006
996
  scope: this,
1007
997
  callSite: (f, a) => f(...a)
1008
998
  });
@@ -1024,6 +1014,7 @@ var Swarm = class {
1024
1014
  * Creates a connection then sends message over signal network.
1025
1015
  */
1026
1016
  async _initiateConnection(remoteId) {
1017
+ const ctx = this._ctx;
1027
1018
  if (remoteId.toHex() < this._ownPeerId.toHex()) {
1028
1019
  log4("initiation delay", {
1029
1020
  remoteId
@@ -1035,7 +1026,7 @@ var Swarm = class {
1035
1026
  });
1036
1027
  await sleep(INITIATION_DELAY);
1037
1028
  }
1038
- if (this._ctx.disposed) {
1029
+ if (ctx.disposed) {
1039
1030
  return;
1040
1031
  }
1041
1032
  const peer = this._getOrCreatePeer(remoteId);
@@ -1084,6 +1075,12 @@ __decorate3([
1084
1075
  __decorate3([
1085
1076
  synchronized3
1086
1077
  ], Swarm.prototype, "onOffer", null);
1078
+ __decorate3([
1079
+ synchronized3
1080
+ ], Swarm.prototype, "onSignal", null);
1081
+ __decorate3([
1082
+ synchronized3
1083
+ ], Swarm.prototype, "goOffline", null);
1087
1084
  __decorate3([
1088
1085
  synchronized3
1089
1086
  ], Swarm.prototype, "goOnline", null);
@@ -1402,20 +1399,20 @@ var NetworkManager = class {
1402
1399
  switch (state) {
1403
1400
  case ConnectionState2.OFFLINE: {
1404
1401
  this._connectionState = state;
1405
- await this._messenger.close();
1406
- await this._signalManager.close();
1407
1402
  await Promise.all([
1408
1403
  ...this._swarms.values()
1409
1404
  ].map((swarm) => swarm.goOffline()));
1405
+ await this._messenger.close();
1406
+ await this._signalManager.close();
1410
1407
  break;
1411
1408
  }
1412
1409
  case ConnectionState2.ONLINE: {
1413
1410
  this._connectionState = state;
1414
- this._messenger.open();
1415
- await this._signalManager.open();
1416
1411
  await Promise.all([
1417
1412
  ...this._swarms.values()
1418
1413
  ].map((swarm) => swarm.goOnline()));
1414
+ this._messenger.open();
1415
+ await this._signalManager.open();
1419
1416
  break;
1420
1417
  }
1421
1418
  }