@actuallab/rpc 12.3.49 → 12.3.60

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/index.d.cts CHANGED
@@ -782,6 +782,14 @@ declare abstract class RpcPeer {
782
782
  * entered only after the handshake has succeeded. */
783
783
  readonly connectionStateChanged: EventHandlerSet<RpcConnectionState>;
784
784
  protected _connection: RpcConnection | undefined;
785
+ /** Mirror of `_connectionState === Connected` — true only after the
786
+ * handshake round-trip completes. Kept as its own field (rather than
787
+ * derived from `_connection`) so outbound calls can be gated on
788
+ * handshake completion, not merely WS-open: previously the run loop
789
+ * nulled `_connection` during the handshake window to suppress calls,
790
+ * which made `close()` a silent no-op and left a zombie peer when the
791
+ * hub removed it mid-handshake. */
792
+ protected _isConnected: boolean;
785
793
  protected _connectionState: RpcConnectionState;
786
794
  protected _pendingSends: RpcOutboundCall[];
787
795
  private _keepAliveTimer;
package/dist/index.d.ts CHANGED
@@ -782,6 +782,14 @@ declare abstract class RpcPeer {
782
782
  * entered only after the handshake has succeeded. */
783
783
  readonly connectionStateChanged: EventHandlerSet<RpcConnectionState>;
784
784
  protected _connection: RpcConnection | undefined;
785
+ /** Mirror of `_connectionState === Connected` — true only after the
786
+ * handshake round-trip completes. Kept as its own field (rather than
787
+ * derived from `_connection`) so outbound calls can be gated on
788
+ * handshake completion, not merely WS-open: previously the run loop
789
+ * nulled `_connection` during the handshake window to suppress calls,
790
+ * which made `close()` a silent no-op and left a zombie peer when the
791
+ * hub removed it mid-handshake. */
792
+ protected _isConnected: boolean;
785
793
  protected _connectionState: RpcConnectionState;
786
794
  protected _pendingSends: RpcOutboundCall[];
787
795
  private _keepAliveTimer;
package/dist/index.js CHANGED
@@ -2205,6 +2205,14 @@ var RpcPeer = class {
2205
2205
  * entered only after the handshake has succeeded. */
2206
2206
  connectionStateChanged = new EventHandlerSet3();
2207
2207
  _connection;
2208
+ /** Mirror of `_connectionState === Connected` — true only after the
2209
+ * handshake round-trip completes. Kept as its own field (rather than
2210
+ * derived from `_connection`) so outbound calls can be gated on
2211
+ * handshake completion, not merely WS-open: previously the run loop
2212
+ * nulled `_connection` during the handshake window to suppress calls,
2213
+ * which made `close()` a silent no-op and left a zombie peer when the
2214
+ * hub removed it mid-handshake. */
2215
+ _isConnected = false;
2208
2216
  _connectionState = 0 /* Disconnected */;
2209
2217
  _pendingSends = [];
2210
2218
  _keepAliveTimer;
@@ -2227,15 +2235,20 @@ var RpcPeer = class {
2227
2235
  return this._connectionState;
2228
2236
  }
2229
2237
  get isConnected() {
2230
- return this._connection?.isOpen ?? false;
2238
+ return this._isConnected;
2231
2239
  }
2232
2240
  _setConnectionState(value) {
2233
2241
  if (this._connectionState === value) return;
2242
+ const previousState = this._connectionState;
2234
2243
  this._connectionState = value;
2235
- if (value === 2 /* Connected */)
2244
+ if (value === 2 /* Connected */) {
2245
+ this._isConnected = true;
2236
2246
  this._armKeepAliveWatchdog();
2237
- else if (value === 0 /* Disconnected */)
2247
+ } else if (value === 0 /* Disconnected */) {
2248
+ if (previousState === 2 /* Connected */)
2249
+ this._isConnected = false;
2238
2250
  this._disarmKeepAliveWatchdog();
2251
+ }
2239
2252
  this.connectionStateChanged.trigger(value);
2240
2253
  }
2241
2254
  /** Resolves on the next transition into `Connected` — or immediately if
@@ -2257,6 +2270,7 @@ var RpcPeer = class {
2257
2270
  conn.messageReceived.add((raw) => this._handleMessage(raw));
2258
2271
  conn.closed.add((ev) => {
2259
2272
  this._connection = void 0;
2273
+ this._isConnected = false;
2260
2274
  if (ev.reason)
2261
2275
  infoLog?.log(`'${this.ref}': Disconnected: ${ev.reason} (code=${ev.code})`);
2262
2276
  else
@@ -2293,7 +2307,7 @@ var RpcPeer = class {
2293
2307
  this._connection?.encoder,
2294
2308
  this.hub.registry
2295
2309
  );
2296
- if (this._connection !== void 0) {
2310
+ if (this._isConnected) {
2297
2311
  this.outboundCalls.register(outboundCall);
2298
2312
  this._sendWireData(outboundCall.serializedWireData);
2299
2313
  } else {
@@ -2326,12 +2340,13 @@ var RpcPeer = class {
2326
2340
  return outboundCall;
2327
2341
  }
2328
2342
  callNoWait(method, args) {
2329
- if (this._connection === void 0) return;
2343
+ if (!this._isConnected) return;
2344
+ const conn = this._connection;
2330
2345
  const envelope = { Method: method, RelatedId: 0 };
2331
2346
  const wireData = this.serializationFormat.serializeMessage(
2332
2347
  envelope,
2333
2348
  args,
2334
- this._connection.encoder,
2349
+ conn.encoder,
2335
2350
  this.hub.registry
2336
2351
  );
2337
2352
  this._sendWireData(wireData);
@@ -2588,6 +2603,7 @@ var RpcClientPeer = class extends RpcPeer {
2588
2603
  * to simulate a same-peer reconnect in tests. */
2589
2604
  connectWith(conn, isPeerChanged = true) {
2590
2605
  this.setupConnection(conn);
2606
+ this._isConnected = true;
2591
2607
  void this._reconnect(isPeerChanged);
2592
2608
  }
2593
2609
  /** Kick off the reconnect loop. Idempotent — subsequent calls are
@@ -2648,7 +2664,6 @@ var RpcClientPeer = class extends RpcPeer {
2648
2664
  });
2649
2665
  this._pendingHandshake = new PromiseSource5();
2650
2666
  this.setupConnection(conn);
2651
- this._connection = void 0;
2652
2667
  await Promise.race([conn.whenConnected, closedRejection]);
2653
2668
  try {
2654
2669
  this.hub.systemCallSender.handshake(
@@ -2701,7 +2716,6 @@ var RpcClientPeer = class extends RpcPeer {
2701
2716
  this._lastRemoteHubId = remoteHubId;
2702
2717
  }
2703
2718
  infoLog?.log(`'${this.ref}': Handshake succeeded, peerChanged=${isPeerChanged}`);
2704
- this._connection = conn;
2705
2719
  this._setConnectionState(2 /* Connected */);
2706
2720
  this._tryIndex = 0;
2707
2721
  await this._reconnect(isPeerChanged, closedController.signal);