@camstack/sdk 1.2.29 → 1.2.30

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.cjs CHANGED
@@ -700,6 +700,13 @@ var System = class {
700
700
  connectedPromise = null;
701
701
  _systemProxy;
702
702
  _connectionVersion = 0;
703
+ /**
704
+ * Bumped on every `reconnect()` BEFORE the previous socket is closed.
705
+ * WS `onOpen`/`onClose` close over the epoch at `createWSClient` time
706
+ * so a delayed close from a torn-down socket cannot mark the replacement
707
+ * as disconnected (the LAN-switch shape: health 3/3, APIs then "offline").
708
+ */
709
+ _wsEpoch = 0;
703
710
  connectionListeners = /* @__PURE__ */ new Set();
704
711
  constructor(config) {
705
712
  this._serverUrl = config.serverUrl.replace(/\/+$/, "");
@@ -834,6 +841,7 @@ var System = class {
834
841
  */
835
842
  reconnect() {
836
843
  if (!this.useWs) return;
844
+ this._wsEpoch += 1;
837
845
  this.emitConnectionEvent("connecting");
838
846
  this._wsClient?.close();
839
847
  this.disposeMirror();
@@ -901,7 +909,8 @@ var System = class {
901
909
  endpoints = (await cap.query({
902
910
  port,
903
911
  ipv4Only: options?.ipv4Only,
904
- scheme
912
+ scheme,
913
+ includeLoopback: false
905
914
  })).endpoints;
906
915
  } catch {
907
916
  return {
@@ -1309,6 +1318,7 @@ var System = class {
1309
1318
  const wsUrl = this._serverUrl.replace(/^http/, "ws") + "/trpc";
1310
1319
  const baseRetryMs = this.baseRetryMs;
1311
1320
  const maxRetryMs = this.maxRetryMs;
1321
+ const epoch = this._wsEpoch;
1312
1322
  this._wsClient = (0, _trpc_client.createWSClient)({
1313
1323
  url: wsUrl,
1314
1324
  connectionParams: () => ({ token: this.token }),
@@ -1319,10 +1329,12 @@ var System = class {
1319
1329
  pongTimeoutMs: WS_KEEP_ALIVE_PONG_TIMEOUT_MS
1320
1330
  },
1321
1331
  onOpen: () => {
1332
+ if (epoch !== this._wsEpoch) return;
1322
1333
  this._connectionVersion += 1;
1323
1334
  this.emitConnectionEvent("connected");
1324
1335
  },
1325
1336
  onClose: () => {
1337
+ if (epoch !== this._wsEpoch) return;
1326
1338
  this.emitConnectionEvent("disconnected");
1327
1339
  }
1328
1340
  });
package/dist/index.js CHANGED
@@ -699,6 +699,13 @@ var System = class {
699
699
  connectedPromise = null;
700
700
  _systemProxy;
701
701
  _connectionVersion = 0;
702
+ /**
703
+ * Bumped on every `reconnect()` BEFORE the previous socket is closed.
704
+ * WS `onOpen`/`onClose` close over the epoch at `createWSClient` time
705
+ * so a delayed close from a torn-down socket cannot mark the replacement
706
+ * as disconnected (the LAN-switch shape: health 3/3, APIs then "offline").
707
+ */
708
+ _wsEpoch = 0;
702
709
  connectionListeners = /* @__PURE__ */ new Set();
703
710
  constructor(config) {
704
711
  this._serverUrl = config.serverUrl.replace(/\/+$/, "");
@@ -833,6 +840,7 @@ var System = class {
833
840
  */
834
841
  reconnect() {
835
842
  if (!this.useWs) return;
843
+ this._wsEpoch += 1;
836
844
  this.emitConnectionEvent("connecting");
837
845
  this._wsClient?.close();
838
846
  this.disposeMirror();
@@ -900,7 +908,8 @@ var System = class {
900
908
  endpoints = (await cap.query({
901
909
  port,
902
910
  ipv4Only: options?.ipv4Only,
903
- scheme
911
+ scheme,
912
+ includeLoopback: false
904
913
  })).endpoints;
905
914
  } catch {
906
915
  return {
@@ -1308,6 +1317,7 @@ var System = class {
1308
1317
  const wsUrl = this._serverUrl.replace(/^http/, "ws") + "/trpc";
1309
1318
  const baseRetryMs = this.baseRetryMs;
1310
1319
  const maxRetryMs = this.maxRetryMs;
1320
+ const epoch = this._wsEpoch;
1311
1321
  this._wsClient = createWSClient({
1312
1322
  url: wsUrl,
1313
1323
  connectionParams: () => ({ token: this.token }),
@@ -1318,10 +1328,12 @@ var System = class {
1318
1328
  pongTimeoutMs: WS_KEEP_ALIVE_PONG_TIMEOUT_MS
1319
1329
  },
1320
1330
  onOpen: () => {
1331
+ if (epoch !== this._wsEpoch) return;
1321
1332
  this._connectionVersion += 1;
1322
1333
  this.emitConnectionEvent("connected");
1323
1334
  },
1324
1335
  onClose: () => {
1336
+ if (epoch !== this._wsEpoch) return;
1325
1337
  this.emitConnectionEvent("disconnected");
1326
1338
  }
1327
1339
  });
package/dist/system.d.ts CHANGED
@@ -92,6 +92,13 @@ export declare class System {
92
92
  private connectedPromise;
93
93
  private _systemProxy;
94
94
  private _connectionVersion;
95
+ /**
96
+ * Bumped on every `reconnect()` BEFORE the previous socket is closed.
97
+ * WS `onOpen`/`onClose` close over the epoch at `createWSClient` time
98
+ * so a delayed close from a torn-down socket cannot mark the replacement
99
+ * as disconnected (the LAN-switch shape: health 3/3, APIs then "offline").
100
+ */
101
+ private _wsEpoch;
95
102
  private readonly connectionListeners;
96
103
  constructor(config: SystemConfig);
97
104
  /** Active server base URL (no trailing slash). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/sdk",
3
- "version": "1.2.29",
3
+ "version": "1.2.30",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",