@agentvault/secure-channel 0.6.17 → 0.6.18

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.js CHANGED
@@ -45113,7 +45113,7 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45113
45113
  _reconnectAttempt = 0;
45114
45114
  _reconnectTimer = null;
45115
45115
  _pingTimer = null;
45116
- _pingTimeout = null;
45116
+ _lastServerMessage = 0;
45117
45117
  _pendingAcks = [];
45118
45118
  _ackTimer = null;
45119
45119
  _stopped = false;
@@ -45121,10 +45121,10 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45121
45121
  _httpServer = null;
45122
45122
  _pollFallbackTimer = null;
45123
45123
  _syncMessageIds = null;
45124
+ // Liveness detection: server sends app-level {"event":"ping"} every 30s.
45125
+ // We check every 30s; if no data received in 90s (3 missed pings), connection is dead.
45124
45126
  static PING_INTERVAL_MS = 3e4;
45125
- // Send ping every 30s
45126
- static PING_TIMEOUT_MS = 1e4;
45127
- // Treat as dead if no pong within 10s
45127
+ static SILENCE_TIMEOUT_MS = 9e4;
45128
45128
  static POLL_FALLBACK_INTERVAL_MS = 3e4;
45129
45129
  // 30s when messages found
45130
45130
  static POLL_FALLBACK_IDLE_MS = 6e4;
@@ -45605,6 +45605,7 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45605
45605
  this.emit("ready");
45606
45606
  });
45607
45607
  ws.on("message", async (raw) => {
45608
+ this._lastServerMessage = Date.now();
45608
45609
  try {
45609
45610
  const data = JSON.parse(raw.toString());
45610
45611
  if (data.event === "ping") {
@@ -46095,30 +46096,23 @@ ${messageText}`;
46095
46096
  }
46096
46097
  _startPing(ws) {
46097
46098
  this._stopPing();
46099
+ this._lastServerMessage = Date.now();
46098
46100
  this._pingTimer = setInterval(() => {
46099
46101
  if (ws.readyState !== WebSocket.OPEN) return;
46100
- this._pingTimeout = setTimeout(() => {
46101
- console.log("[SecureChannel] Ping timeout \u2014 reconnecting stale WebSocket");
46102
+ const silence = Date.now() - this._lastServerMessage;
46103
+ if (silence > _SecureChannel.SILENCE_TIMEOUT_MS) {
46104
+ console.log(
46105
+ `[SecureChannel] No server data for ${Math.round(silence / 1e3)}s \u2014 reconnecting stale WebSocket`
46106
+ );
46102
46107
  ws.terminate();
46103
- }, _SecureChannel.PING_TIMEOUT_MS);
46104
- ws.ping();
46105
- }, _SecureChannel.PING_INTERVAL_MS);
46106
- ws.on("pong", () => {
46107
- if (this._pingTimeout) {
46108
- clearTimeout(this._pingTimeout);
46109
- this._pingTimeout = null;
46110
46108
  }
46111
- });
46109
+ }, _SecureChannel.PING_INTERVAL_MS);
46112
46110
  }
46113
46111
  _stopPing() {
46114
46112
  if (this._pingTimer) {
46115
46113
  clearInterval(this._pingTimer);
46116
46114
  this._pingTimer = null;
46117
46115
  }
46118
- if (this._pingTimeout) {
46119
- clearTimeout(this._pingTimeout);
46120
- this._pingTimeout = null;
46121
- }
46122
46116
  }
46123
46117
  _scheduleReconnect() {
46124
46118
  if (this._stopped) return;