@pingagent/sdk 0.1.5 → 0.1.6
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/chunk-OHS3SA5V.js +1451 -0
- package/dist/index.js +1 -1
- package/dist/web-server.js +1 -1
- package/package.json +1 -1
- package/src/ws-subscription.ts +13 -5
package/dist/index.js
CHANGED
package/dist/web-server.js
CHANGED
package/package.json
CHANGED
package/src/ws-subscription.ts
CHANGED
|
@@ -50,8 +50,8 @@ const LIST_CONVERSATIONS_INTERVAL_MS = 60_000;
|
|
|
50
50
|
|
|
51
51
|
const DEFAULT_HEARTBEAT = {
|
|
52
52
|
enable: true,
|
|
53
|
-
idleThresholdMs:
|
|
54
|
-
pingIntervalMs:
|
|
53
|
+
idleThresholdMs: 10_000,
|
|
54
|
+
pingIntervalMs: 15_000,
|
|
55
55
|
pongTimeoutMs: 10_000,
|
|
56
56
|
maxMissedPongs: 2,
|
|
57
57
|
tickMs: 5_000,
|
|
@@ -189,8 +189,6 @@ export class WsSubscription {
|
|
|
189
189
|
|
|
190
190
|
ws.on('message', (data: Buffer | string) => {
|
|
191
191
|
try {
|
|
192
|
-
const msg = JSON.parse(data.toString());
|
|
193
|
-
|
|
194
192
|
// Any server frame counts as activity; keep connection stable and avoid unnecessary pings.
|
|
195
193
|
const state = this.heartbeatStates.get(conversationId);
|
|
196
194
|
if (state) {
|
|
@@ -202,6 +200,8 @@ export class WsSubscription {
|
|
|
202
200
|
}
|
|
203
201
|
}
|
|
204
202
|
|
|
203
|
+
const msg = JSON.parse(data.toString());
|
|
204
|
+
|
|
205
205
|
if (msg.type === 'ws_message' && msg.envelope) {
|
|
206
206
|
const env = msg.envelope;
|
|
207
207
|
if (env.sender_did !== this.opts.myDid) {
|
|
@@ -271,6 +271,14 @@ export class WsSubscription {
|
|
|
271
271
|
continue;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
// Application-level keepalive for CDN/NAT idle timeouts (more reliable than ping/pong alone).
|
|
275
|
+
// Receiver can ignore this message.
|
|
276
|
+
try {
|
|
277
|
+
ws.send(JSON.stringify({ type: 'hb' }));
|
|
278
|
+
} catch {
|
|
279
|
+
// ignore; ping/pong + reconnect will handle dead sockets
|
|
280
|
+
}
|
|
281
|
+
|
|
274
282
|
ws.ping();
|
|
275
283
|
state.lastPingAt = now;
|
|
276
284
|
const jitterFactor = 1 + (Math.random() - 0.5) * 2 * jitter;
|
|
@@ -280,7 +288,7 @@ export class WsSubscription {
|
|
|
280
288
|
state.missedPongs += 1;
|
|
281
289
|
state.pongTimeout = null;
|
|
282
290
|
|
|
283
|
-
if (state.missedPongs
|
|
291
|
+
if (state.missedPongs >= maxMissedPongs) {
|
|
284
292
|
try {
|
|
285
293
|
// Trigger close handler -> scheduleReconnect
|
|
286
294
|
ws.close(1001, 'pong timeout');
|