whalibmob 5.5.33 → 5.5.35
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/lib/Client.js +24 -11
- package/lib/DeviceManager.js +11 -5
- package/package.json +1 -1
package/lib/Client.js
CHANGED
|
@@ -117,8 +117,11 @@ class WhalibmobClient extends EventEmitter {
|
|
|
117
117
|
this._signal = null;
|
|
118
118
|
this._devMgr = null;
|
|
119
119
|
this._sessionDir = opts.sessionDir || process.env.HOME + '/.waSession';
|
|
120
|
-
this._pingTimer
|
|
121
|
-
this._keepTimer
|
|
120
|
+
this._pingTimer = null;
|
|
121
|
+
this._keepTimer = null;
|
|
122
|
+
this._watchdogTimer = null;
|
|
123
|
+
this._watchdogLastPingSentAt = 0; // timestamp when last keepalive ping was sent
|
|
124
|
+
this._watchdogPongReceived = true; // true = server responded after last ping (or no ping sent yet)
|
|
122
125
|
this._connected = false;
|
|
123
126
|
this._reconnecting = false;
|
|
124
127
|
this._reconnectTry = 0;
|
|
@@ -259,6 +262,8 @@ class WhalibmobClient extends EventEmitter {
|
|
|
259
262
|
|
|
260
263
|
_onOpen(successNode) {
|
|
261
264
|
this._connected = true;
|
|
265
|
+
this._watchdogLastPingSentAt = 0;
|
|
266
|
+
this._watchdogPongReceived = true;
|
|
262
267
|
this._startTimers();
|
|
263
268
|
|
|
264
269
|
// ── Feature 1: Parse <success> node ──────────────────────────────────────
|
|
@@ -495,6 +500,9 @@ class WhalibmobClient extends EventEmitter {
|
|
|
495
500
|
|
|
496
501
|
this._keepTimer = setInterval(() => {
|
|
497
502
|
if (this._socket && this._connected) {
|
|
503
|
+
// Record the time we sent this ping so the watchdog can check for missing pongs.
|
|
504
|
+
this._watchdogLastPingSentAt = Date.now();
|
|
505
|
+
this._watchdogPongReceived = false;
|
|
498
506
|
this._socket.sendNode(new BinaryNode('iq', {
|
|
499
507
|
id: this._genMsgId(),
|
|
500
508
|
to: 's.whatsapp.net',
|
|
@@ -504,18 +512,21 @@ class WhalibmobClient extends EventEmitter {
|
|
|
504
512
|
}
|
|
505
513
|
}, KEEPALIVE_INTERVAL);
|
|
506
514
|
|
|
507
|
-
// Watchdog:
|
|
508
|
-
//
|
|
509
|
-
//
|
|
515
|
+
// Watchdog: detects a truly dead TCP connection where the OS never emits 'close'
|
|
516
|
+
// (common with NAT/firewall drops). Logic: if we sent a keepalive ping and the
|
|
517
|
+
// server did NOT reply within 2× keepalive window, the connection is dead.
|
|
518
|
+
// NOTE: idleness alone (bot sleeping between sends) is NOT treated as dead —
|
|
519
|
+
// only an unanswered ping triggers the close, so any delay is safe.
|
|
510
520
|
const WATCHDOG_INTERVAL = KEEPALIVE_INTERVAL * 2 + 5000;
|
|
511
521
|
this._watchdogTimer = setInterval(() => {
|
|
512
522
|
if (!this._socket || !this._connected) return;
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
523
|
+
if (!this._watchdogPongReceived &&
|
|
524
|
+
this._watchdogLastPingSentAt > 0 &&
|
|
525
|
+
Date.now() - this._watchdogLastPingSentAt > WATCHDOG_INTERVAL) {
|
|
526
|
+
_whaDbg('[DBG] WATCHDOG: keepalive ping sent ' +
|
|
527
|
+
Math.round((Date.now() - this._watchdogLastPingSentAt) / 1000) +
|
|
528
|
+
's ago with no server response — force-closing dead connection');
|
|
529
|
+
try { this._socket.close(); } catch (_) {}
|
|
519
530
|
}
|
|
520
531
|
}, KEEPALIVE_INTERVAL);
|
|
521
532
|
}
|
|
@@ -530,6 +541,8 @@ class WhalibmobClient extends EventEmitter {
|
|
|
530
541
|
|
|
531
542
|
_onNode(node) {
|
|
532
543
|
if (!node || !node.description) return;
|
|
544
|
+
// Any node from the server means the connection is alive — reset watchdog state.
|
|
545
|
+
this._watchdogPongReceived = true;
|
|
533
546
|
const tag = node.description;
|
|
534
547
|
// Debug: log every node received
|
|
535
548
|
_whaDbg('[DBG] _onNode tag=' + tag + ' attrs=' + JSON.stringify(node.attrs || {}));
|
package/lib/DeviceManager.js
CHANGED
|
@@ -445,13 +445,16 @@ class DeviceManager {
|
|
|
445
445
|
const iqNode = new BinaryNode('iq',
|
|
446
446
|
{ id: iqId, to: 's.whatsapp.net', type: 'get', xmlns: 'usync' },
|
|
447
447
|
[new BinaryNode('usync',
|
|
448
|
-
{ sid, mode: 'query', last: 'true', index: '0', context: '
|
|
448
|
+
{ sid, mode: 'query', last: 'true', index: '0', context: 'message' },
|
|
449
449
|
[
|
|
450
450
|
new BinaryNode('query', {},
|
|
451
|
-
[
|
|
451
|
+
[
|
|
452
|
+
new BinaryNode('devices', { version: '2' }, null),
|
|
453
|
+
new BinaryNode('lid', {}, null)
|
|
454
|
+
]
|
|
452
455
|
),
|
|
453
456
|
new BinaryNode('list', {}, listChildren),
|
|
454
|
-
new BinaryNode('side_list', {}, null)
|
|
457
|
+
new BinaryNode('side_list', {}, null)
|
|
455
458
|
]
|
|
456
459
|
)]
|
|
457
460
|
);
|
|
@@ -771,10 +774,13 @@ class DeviceManager {
|
|
|
771
774
|
const iqNode = new BinaryNode('iq',
|
|
772
775
|
{ id: iqId, to: 's.whatsapp.net', type: 'get', xmlns: 'usync' },
|
|
773
776
|
[new BinaryNode('usync',
|
|
774
|
-
{ sid, mode: 'query', last: 'true', index: '0', context: '
|
|
777
|
+
{ sid, mode: 'query', last: 'true', index: '0', context: 'message' },
|
|
775
778
|
[
|
|
776
779
|
new BinaryNode('query', {},
|
|
777
|
-
[
|
|
780
|
+
[
|
|
781
|
+
new BinaryNode('devices', { version: '2' }, null),
|
|
782
|
+
new BinaryNode('lid', {}, null)
|
|
783
|
+
]
|
|
778
784
|
),
|
|
779
785
|
new BinaryNode('list', {},
|
|
780
786
|
[new BinaryNode('user', { jid }, null)]
|