@agentvault/secure-channel 0.6.16 → 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/channel.d.ts +2 -2
- package/dist/channel.d.ts.map +1 -1
- package/dist/cli.js +18 -18
- package/dist/cli.js.map +2 -2
- package/dist/index.js +18 -18
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/channel.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class SecureChannel extends EventEmitter {
|
|
|
13
13
|
private _reconnectAttempt;
|
|
14
14
|
private _reconnectTimer;
|
|
15
15
|
private _pingTimer;
|
|
16
|
-
private
|
|
16
|
+
private _lastServerMessage;
|
|
17
17
|
private _pendingAcks;
|
|
18
18
|
private _ackTimer;
|
|
19
19
|
private _stopped;
|
|
@@ -22,7 +22,7 @@ export declare class SecureChannel extends EventEmitter {
|
|
|
22
22
|
private _pollFallbackTimer;
|
|
23
23
|
private _syncMessageIds;
|
|
24
24
|
private static readonly PING_INTERVAL_MS;
|
|
25
|
-
private static readonly
|
|
25
|
+
private static readonly SILENCE_TIMEOUT_MS;
|
|
26
26
|
private static readonly POLL_FALLBACK_INTERVAL_MS;
|
|
27
27
|
private static readonly POLL_FALLBACK_IDLE_MS;
|
|
28
28
|
constructor(config: SecureChannelConfig);
|
package/dist/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoB3C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAMb,MAAM,YAAY,CAAC;AAmDpB,qBAAa,aAAc,SAAQ,YAAY;
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoB3C,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B;IA8GjC,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,UAAU;YAMJ,mBAAmB;IAmCjC,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,kBAAkB;IAiH1B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,YAAY;IAKpB;;;OAGG;YACW,aAAa;CAc5B"}
|
package/dist/cli.js
CHANGED
|
@@ -45182,7 +45182,7 @@ var init_channel = __esm({
|
|
|
45182
45182
|
_reconnectAttempt = 0;
|
|
45183
45183
|
_reconnectTimer = null;
|
|
45184
45184
|
_pingTimer = null;
|
|
45185
|
-
|
|
45185
|
+
_lastServerMessage = 0;
|
|
45186
45186
|
_pendingAcks = [];
|
|
45187
45187
|
_ackTimer = null;
|
|
45188
45188
|
_stopped = false;
|
|
@@ -45190,10 +45190,10 @@ var init_channel = __esm({
|
|
|
45190
45190
|
_httpServer = null;
|
|
45191
45191
|
_pollFallbackTimer = null;
|
|
45192
45192
|
_syncMessageIds = null;
|
|
45193
|
+
// Liveness detection: server sends app-level {"event":"ping"} every 30s.
|
|
45194
|
+
// We check every 30s; if no data received in 90s (3 missed pings), connection is dead.
|
|
45193
45195
|
static PING_INTERVAL_MS = 3e4;
|
|
45194
|
-
|
|
45195
|
-
static PING_TIMEOUT_MS = 1e4;
|
|
45196
|
-
// Treat as dead if no pong within 10s
|
|
45196
|
+
static SILENCE_TIMEOUT_MS = 9e4;
|
|
45197
45197
|
static POLL_FALLBACK_INTERVAL_MS = 3e4;
|
|
45198
45198
|
// 30s when messages found
|
|
45199
45199
|
static POLL_FALLBACK_IDLE_MS = 6e4;
|
|
@@ -45648,6 +45648,10 @@ var init_channel = __esm({
|
|
|
45648
45648
|
}
|
|
45649
45649
|
_connect() {
|
|
45650
45650
|
if (this._stopped) return;
|
|
45651
|
+
if (this._reconnectTimer) {
|
|
45652
|
+
clearTimeout(this._reconnectTimer);
|
|
45653
|
+
this._reconnectTimer = null;
|
|
45654
|
+
}
|
|
45651
45655
|
if (this._ws) {
|
|
45652
45656
|
this._ws.removeAllListeners();
|
|
45653
45657
|
try {
|
|
@@ -45670,6 +45674,7 @@ var init_channel = __esm({
|
|
|
45670
45674
|
this.emit("ready");
|
|
45671
45675
|
});
|
|
45672
45676
|
ws.on("message", async (raw) => {
|
|
45677
|
+
this._lastServerMessage = Date.now();
|
|
45673
45678
|
try {
|
|
45674
45679
|
const data = JSON.parse(raw.toString());
|
|
45675
45680
|
if (data.event === "ping") {
|
|
@@ -46160,30 +46165,23 @@ ${messageText}`;
|
|
|
46160
46165
|
}
|
|
46161
46166
|
_startPing(ws) {
|
|
46162
46167
|
this._stopPing();
|
|
46168
|
+
this._lastServerMessage = Date.now();
|
|
46163
46169
|
this._pingTimer = setInterval(() => {
|
|
46164
46170
|
if (ws.readyState !== WebSocket.OPEN) return;
|
|
46165
|
-
|
|
46166
|
-
|
|
46171
|
+
const silence = Date.now() - this._lastServerMessage;
|
|
46172
|
+
if (silence > _SecureChannel.SILENCE_TIMEOUT_MS) {
|
|
46173
|
+
console.log(
|
|
46174
|
+
`[SecureChannel] No server data for ${Math.round(silence / 1e3)}s \u2014 reconnecting stale WebSocket`
|
|
46175
|
+
);
|
|
46167
46176
|
ws.terminate();
|
|
46168
|
-
}, _SecureChannel.PING_TIMEOUT_MS);
|
|
46169
|
-
ws.ping();
|
|
46170
|
-
}, _SecureChannel.PING_INTERVAL_MS);
|
|
46171
|
-
ws.on("pong", () => {
|
|
46172
|
-
if (this._pingTimeout) {
|
|
46173
|
-
clearTimeout(this._pingTimeout);
|
|
46174
|
-
this._pingTimeout = null;
|
|
46175
46177
|
}
|
|
46176
|
-
});
|
|
46178
|
+
}, _SecureChannel.PING_INTERVAL_MS);
|
|
46177
46179
|
}
|
|
46178
46180
|
_stopPing() {
|
|
46179
46181
|
if (this._pingTimer) {
|
|
46180
46182
|
clearInterval(this._pingTimer);
|
|
46181
46183
|
this._pingTimer = null;
|
|
46182
46184
|
}
|
|
46183
|
-
if (this._pingTimeout) {
|
|
46184
|
-
clearTimeout(this._pingTimeout);
|
|
46185
|
-
this._pingTimeout = null;
|
|
46186
|
-
}
|
|
46187
46185
|
}
|
|
46188
46186
|
_scheduleReconnect() {
|
|
46189
46187
|
if (this._stopped) return;
|
|
@@ -46193,7 +46191,9 @@ ${messageText}`;
|
|
|
46193
46191
|
RECONNECT_MAX_MS
|
|
46194
46192
|
);
|
|
46195
46193
|
this._reconnectAttempt++;
|
|
46194
|
+
console.log(`[SecureChannel] Scheduling reconnect in ${delay}ms (attempt ${this._reconnectAttempt})`);
|
|
46196
46195
|
this._reconnectTimer = setTimeout(() => {
|
|
46196
|
+
this._reconnectTimer = null;
|
|
46197
46197
|
if (!this._stopped) {
|
|
46198
46198
|
this._connect();
|
|
46199
46199
|
}
|