@rljson/server 0.0.16 → 0.0.17
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 +7 -0
- package/dist/server.js +14 -0
- package/package.json +1 -1
package/dist/node.d.ts
CHANGED
|
@@ -121,6 +121,7 @@ export declare class Node {
|
|
|
121
121
|
private _bsMem?;
|
|
122
122
|
private _role;
|
|
123
123
|
private _running;
|
|
124
|
+
private _transportReady;
|
|
124
125
|
private _transitioning?;
|
|
125
126
|
private _listeners;
|
|
126
127
|
private readonly _logger;
|
|
@@ -149,6 +150,12 @@ export declare class Node {
|
|
|
149
150
|
get socket(): SocketLike | undefined;
|
|
150
151
|
/** Whether the node is currently running. */
|
|
151
152
|
get isRunning(): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Whether the node's transport is fully ready.
|
|
155
|
+
* `false` during role transitions and before the first transition completes.
|
|
156
|
+
* `true` only after `_becomeHub()` or `_becomeClient()` has finished.
|
|
157
|
+
*/
|
|
158
|
+
get isTransportReady(): boolean;
|
|
152
159
|
/** The underlying NetworkManager. */
|
|
153
160
|
get networkManager(): NetworkManager;
|
|
154
161
|
/**
|
package/dist/server.js
CHANGED
|
@@ -1488,6 +1488,7 @@ class Node {
|
|
|
1488
1488
|
_bsMem;
|
|
1489
1489
|
_role = "unassigned";
|
|
1490
1490
|
_running = false;
|
|
1491
|
+
_transportReady = false;
|
|
1491
1492
|
_transitioning;
|
|
1492
1493
|
_listeners = /* @__PURE__ */ new Map();
|
|
1493
1494
|
_logger;
|
|
@@ -1514,6 +1515,7 @@ class Node {
|
|
|
1514
1515
|
async stop() {
|
|
1515
1516
|
if (!this._running) return;
|
|
1516
1517
|
this._running = false;
|
|
1518
|
+
this._transportReady = false;
|
|
1517
1519
|
this._networkManager.off("role-changed", this._onRoleChanged);
|
|
1518
1520
|
this._networkManager.off("hub-changed", this._onHubChanged);
|
|
1519
1521
|
if (this._transitioning) {
|
|
@@ -1560,6 +1562,14 @@ class Node {
|
|
|
1560
1562
|
get isRunning() {
|
|
1561
1563
|
return this._running;
|
|
1562
1564
|
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Whether the node's transport is fully ready.
|
|
1567
|
+
* `false` during role transitions and before the first transition completes.
|
|
1568
|
+
* `true` only after `_becomeHub()` or `_becomeClient()` has finished.
|
|
1569
|
+
*/
|
|
1570
|
+
get isTransportReady() {
|
|
1571
|
+
return this._transportReady;
|
|
1572
|
+
}
|
|
1563
1573
|
/** The underlying NetworkManager. */
|
|
1564
1574
|
get networkManager() {
|
|
1565
1575
|
return this._networkManager;
|
|
@@ -1607,6 +1617,7 @@ class Node {
|
|
|
1607
1617
|
const prev = this._transitioning ?? Promise.resolve();
|
|
1608
1618
|
this._transitioning = prev.then(async () => {
|
|
1609
1619
|
if (!this._running || this._role !== "client") return;
|
|
1620
|
+
this._transportReady = false;
|
|
1610
1621
|
await this._tearDownCurrentRole();
|
|
1611
1622
|
await this._becomeClient();
|
|
1612
1623
|
});
|
|
@@ -1622,6 +1633,7 @@ class Node {
|
|
|
1622
1633
|
if (!this._running) return;
|
|
1623
1634
|
const { current } = event;
|
|
1624
1635
|
if (current === this._role) return;
|
|
1636
|
+
this._transportReady = false;
|
|
1625
1637
|
this._logger.info("Node", `Role changing: ${this._role} → ${current}`);
|
|
1626
1638
|
await this._tearDownCurrentRole();
|
|
1627
1639
|
this._role = current;
|
|
@@ -1670,6 +1682,7 @@ class Node {
|
|
|
1670
1682
|
`Hub transport failed (no incoming connections): ${err}`
|
|
1671
1683
|
);
|
|
1672
1684
|
}
|
|
1685
|
+
this._transportReady = true;
|
|
1673
1686
|
const ctx = { role: "hub", server: this._server };
|
|
1674
1687
|
this._emit("ready", ctx);
|
|
1675
1688
|
await this._startAgent(ctx);
|
|
@@ -1707,6 +1720,7 @@ class Node {
|
|
|
1707
1720
|
);
|
|
1708
1721
|
await this._client.init();
|
|
1709
1722
|
this._logger.info("Node", `Now client — connected to hub ${hubAddress}`);
|
|
1723
|
+
this._transportReady = true;
|
|
1710
1724
|
const ctx = {
|
|
1711
1725
|
role: "client",
|
|
1712
1726
|
client: this._client,
|