@rljson/server 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.d.ts CHANGED
@@ -163,6 +163,13 @@ export declare class Node {
163
163
  * @param cb - Callback
164
164
  */
165
165
  off<E extends NodeEventName>(event: E, cb: NodeEvents[E]): void;
166
+ /**
167
+ * Handle hub-changed while role stays 'client'.
168
+ * When NetworkManager emits hub-changed but NOT role-changed (because
169
+ * old role === new role === 'client'), the Node must tear down the old
170
+ * client connection and reconnect to the new hub.
171
+ */
172
+ private _onHubChanged;
166
173
  private _onRoleChanged;
167
174
  private _performTransition;
168
175
  private _becomeHub;
package/dist/server.js CHANGED
@@ -1440,6 +1440,7 @@ class Node {
1440
1440
  this._bsMem = new BsMem();
1441
1441
  this._running = true;
1442
1442
  this._networkManager.on("role-changed", this._onRoleChanged);
1443
+ this._networkManager.on("hub-changed", this._onHubChanged);
1443
1444
  await this._networkManager.start();
1444
1445
  }
1445
1446
  /**
@@ -1449,6 +1450,7 @@ class Node {
1449
1450
  if (!this._running) return;
1450
1451
  this._running = false;
1451
1452
  this._networkManager.off("role-changed", this._onRoleChanged);
1453
+ this._networkManager.off("hub-changed", this._onHubChanged);
1452
1454
  if (this._transitioning) {
1453
1455
  await this._transitioning;
1454
1456
  this._transitioning = void 0;
@@ -1526,6 +1528,24 @@ class Node {
1526
1528
  // .........................................................................
1527
1529
  // Role transitions
1528
1530
  // .........................................................................
1531
+ /**
1532
+ * Handle hub-changed while role stays 'client'.
1533
+ * When NetworkManager emits hub-changed but NOT role-changed (because
1534
+ * old role === new role === 'client'), the Node must tear down the old
1535
+ * client connection and reconnect to the new hub.
1536
+ */
1537
+ _onHubChanged = () => {
1538
+ if (!this._running || this._role !== "client") return;
1539
+ const topology = this._networkManager.getTopology();
1540
+ if (topology.myRole !== "client") return;
1541
+ this._logger.info("Node", "Hub changed while client — reconnecting");
1542
+ const prev = this._transitioning ?? Promise.resolve();
1543
+ this._transitioning = prev.then(async () => {
1544
+ if (!this._running || this._role !== "client") return;
1545
+ await this._tearDownCurrentRole();
1546
+ await this._becomeClient();
1547
+ });
1548
+ };
1529
1549
  _onRoleChanged = (event) => {
1530
1550
  if (!this._running) return;
1531
1551
  const { current } = event;
@@ -1635,6 +1655,9 @@ class Node {
1635
1655
  await this._client.tearDown();
1636
1656
  this._client = void 0;
1637
1657
  }
1658
+ if (this._clientSocket && "disconnect" in this._clientSocket) {
1659
+ this._clientSocket.disconnect();
1660
+ }
1638
1661
  this._clientSocket = void 0;
1639
1662
  }
1640
1663
  async _startAgent(ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/server",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Rljson server description",
5
5
  "homepage": "https://github.com/rljson/server",
6
6
  "bugs": "https://github.com/rljson/server/issues",
@@ -48,7 +48,7 @@
48
48
  "@rljson/hash": "^0.0.18",
49
49
  "@rljson/io": "^0.0.66",
50
50
  "@rljson/json": "^0.0.23",
51
- "@rljson/network": "^0.0.1",
51
+ "@rljson/network": "^0.0.9",
52
52
  "@rljson/rljson": "^0.0.78"
53
53
  },
54
54
  "scripts": {