@agentvault/secure-channel 0.6.8 → 0.6.9
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 +6 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/cli.js +37 -1
- package/dist/cli.js.map +2 -2
- package/dist/index.js +37 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/channel.d.ts
CHANGED
|
@@ -12,8 +12,12 @@ export declare class SecureChannel extends EventEmitter {
|
|
|
12
12
|
private _pollTimer;
|
|
13
13
|
private _reconnectAttempt;
|
|
14
14
|
private _reconnectTimer;
|
|
15
|
+
private _pingTimer;
|
|
16
|
+
private _pingTimeout;
|
|
15
17
|
private _stopped;
|
|
16
18
|
private _persisted;
|
|
19
|
+
private static readonly PING_INTERVAL_MS;
|
|
20
|
+
private static readonly PING_TIMEOUT_MS;
|
|
17
21
|
constructor(config: SecureChannelConfig);
|
|
18
22
|
get state(): ChannelState;
|
|
19
23
|
get deviceId(): string | null;
|
|
@@ -86,6 +90,8 @@ export declare class SecureChannel extends EventEmitter {
|
|
|
86
90
|
* For each conversation, fetches messages since last sync and decrypts.
|
|
87
91
|
*/
|
|
88
92
|
private _syncMissedMessages;
|
|
93
|
+
private _startPing;
|
|
94
|
+
private _stopPing;
|
|
89
95
|
private _scheduleReconnect;
|
|
90
96
|
private _setState;
|
|
91
97
|
private _handleError;
|
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;AAa3C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAKb,MAAM,YAAY,CAAC;AAiDpB,qBAAa,aAAc,SAAQ,YAAY;
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings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E,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAyCtE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB3B;;;OAGG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAsC1F;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;YAiCtE,OAAO;IAgDrB,OAAO,CAAC,KAAK;YAsCC,SAAS;IAyIvB,OAAO,CAAC,QAAQ;IAwEhB;;;;OAIG;YACW,sBAAsB;IAwFpC;;;OAGG;YACW,oBAAoB;IAqClC;;;OAGG;YACW,uBAAuB;IAkCrC;;;;OAIG;YACW,mBAAmB;IAkEjC;;;OAGG;YACW,mBAAmB;IA4FjC,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,YAAY;IAKpB;;;OAGG;YACW,aAAa;CAc5B"}
|
package/dist/cli.js
CHANGED
|
@@ -45061,7 +45061,8 @@ function migratePersistedState(raw) {
|
|
|
45061
45061
|
messageHistory: []
|
|
45062
45062
|
};
|
|
45063
45063
|
}
|
|
45064
|
-
var SecureChannel = class extends EventEmitter {
|
|
45064
|
+
var SecureChannel = class _SecureChannel extends EventEmitter {
|
|
45065
|
+
// Treat as dead if no pong within 10s
|
|
45065
45066
|
constructor(config) {
|
|
45066
45067
|
super();
|
|
45067
45068
|
this.config = config;
|
|
@@ -45076,8 +45077,13 @@ var SecureChannel = class extends EventEmitter {
|
|
|
45076
45077
|
_pollTimer = null;
|
|
45077
45078
|
_reconnectAttempt = 0;
|
|
45078
45079
|
_reconnectTimer = null;
|
|
45080
|
+
_pingTimer = null;
|
|
45081
|
+
_pingTimeout = null;
|
|
45079
45082
|
_stopped = false;
|
|
45080
45083
|
_persisted = null;
|
|
45084
|
+
static PING_INTERVAL_MS = 3e4;
|
|
45085
|
+
// Send ping every 30s
|
|
45086
|
+
static PING_TIMEOUT_MS = 1e4;
|
|
45081
45087
|
get state() {
|
|
45082
45088
|
return this._state;
|
|
45083
45089
|
}
|
|
@@ -45185,6 +45191,7 @@ var SecureChannel = class extends EventEmitter {
|
|
|
45185
45191
|
}
|
|
45186
45192
|
async stop() {
|
|
45187
45193
|
this._stopped = true;
|
|
45194
|
+
this._stopPing();
|
|
45188
45195
|
if (this._pollTimer) {
|
|
45189
45196
|
clearTimeout(this._pollTimer);
|
|
45190
45197
|
this._pollTimer = null;
|
|
@@ -45457,6 +45464,7 @@ var SecureChannel = class extends EventEmitter {
|
|
|
45457
45464
|
this._ws = ws;
|
|
45458
45465
|
ws.on("open", async () => {
|
|
45459
45466
|
this._reconnectAttempt = 0;
|
|
45467
|
+
this._startPing(ws);
|
|
45460
45468
|
await this._syncMissedMessages();
|
|
45461
45469
|
this._setState("ready");
|
|
45462
45470
|
this.emit("ready");
|
|
@@ -45485,6 +45493,7 @@ var SecureChannel = class extends EventEmitter {
|
|
|
45485
45493
|
}
|
|
45486
45494
|
});
|
|
45487
45495
|
ws.on("close", () => {
|
|
45496
|
+
this._stopPing();
|
|
45488
45497
|
if (this._stopped) return;
|
|
45489
45498
|
this._setState("disconnected");
|
|
45490
45499
|
this._scheduleReconnect();
|
|
@@ -45733,6 +45742,33 @@ var SecureChannel = class extends EventEmitter {
|
|
|
45733
45742
|
} catch {
|
|
45734
45743
|
}
|
|
45735
45744
|
}
|
|
45745
|
+
_startPing(ws) {
|
|
45746
|
+
this._stopPing();
|
|
45747
|
+
this._pingTimer = setInterval(() => {
|
|
45748
|
+
if (ws.readyState !== WebSocket.OPEN) return;
|
|
45749
|
+
this._pingTimeout = setTimeout(() => {
|
|
45750
|
+
console.log("[SecureChannel] Ping timeout \u2014 reconnecting stale WebSocket");
|
|
45751
|
+
ws.terminate();
|
|
45752
|
+
}, _SecureChannel.PING_TIMEOUT_MS);
|
|
45753
|
+
ws.ping();
|
|
45754
|
+
}, _SecureChannel.PING_INTERVAL_MS);
|
|
45755
|
+
ws.on("pong", () => {
|
|
45756
|
+
if (this._pingTimeout) {
|
|
45757
|
+
clearTimeout(this._pingTimeout);
|
|
45758
|
+
this._pingTimeout = null;
|
|
45759
|
+
}
|
|
45760
|
+
});
|
|
45761
|
+
}
|
|
45762
|
+
_stopPing() {
|
|
45763
|
+
if (this._pingTimer) {
|
|
45764
|
+
clearInterval(this._pingTimer);
|
|
45765
|
+
this._pingTimer = null;
|
|
45766
|
+
}
|
|
45767
|
+
if (this._pingTimeout) {
|
|
45768
|
+
clearTimeout(this._pingTimeout);
|
|
45769
|
+
this._pingTimeout = null;
|
|
45770
|
+
}
|
|
45771
|
+
}
|
|
45736
45772
|
_scheduleReconnect() {
|
|
45737
45773
|
if (this._stopped) return;
|
|
45738
45774
|
if (this._reconnectTimer) return;
|