@vielhuber/wahelper 1.6.0 → 1.6.1
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/package.json +1 -1
- package/wahelper-daemon.js +11 -8
package/package.json
CHANGED
package/wahelper-daemon.js
CHANGED
|
@@ -36,6 +36,7 @@ export default class wahelperDaemon {
|
|
|
36
36
|
this.lastError = null;
|
|
37
37
|
this.isFirstRun = false;
|
|
38
38
|
this.reconnectDelay = 1000;
|
|
39
|
+
this.consecutiveFailures = 0;
|
|
39
40
|
this.httpServer = null;
|
|
40
41
|
|
|
41
42
|
if (this.args.device) {
|
|
@@ -622,11 +623,16 @@ export default class wahelperDaemon {
|
|
|
622
623
|
(reason ? ' (' + reason + ')' : statusCode ? ' (statusCode=' + statusCode + ')' : ''),
|
|
623
624
|
at: Date.now()
|
|
624
625
|
};
|
|
626
|
+
this.consecutiveFailures++;
|
|
627
|
+
// first 3 attempts recover network blips fast (1s/2s/4s),
|
|
628
|
+
// after that back off to 15min so a persistent failure
|
|
629
|
+
// (rate-overlimit, bad auth) doesn't keep hammering whatsapp
|
|
630
|
+
let cap = this.consecutiveFailures > 3 ? 15 * 60 * 1000 : 30000;
|
|
625
631
|
let delay = this.reconnectDelay;
|
|
626
|
-
this.log('Reconnecting in ' + delay + 'ms');
|
|
627
|
-
console.log('Reconnecting in ' + delay + 'ms...');
|
|
632
|
+
this.log('Reconnecting in ' + delay + 'ms (attempt ' + this.consecutiveFailures + ')');
|
|
633
|
+
console.log('Reconnecting in ' + delay + 'ms (attempt ' + this.consecutiveFailures + ')...');
|
|
628
634
|
setTimeout(() => {
|
|
629
|
-
this.reconnectDelay = Math.min(this.reconnectDelay * 2,
|
|
635
|
+
this.reconnectDelay = Math.min(this.reconnectDelay * 2, cap);
|
|
630
636
|
this.connect();
|
|
631
637
|
}, delay);
|
|
632
638
|
}
|
|
@@ -639,6 +645,7 @@ export default class wahelperDaemon {
|
|
|
639
645
|
this.pairingCodeRequested = false;
|
|
640
646
|
this.lastError = null;
|
|
641
647
|
this.reconnectDelay = 1000;
|
|
648
|
+
this.consecutiveFailures = 0;
|
|
642
649
|
this.log('✅ Connected');
|
|
643
650
|
console.log('✅ Connected (device: ' + this.device + ')');
|
|
644
651
|
}
|
|
@@ -674,10 +681,6 @@ export default class wahelperDaemon {
|
|
|
674
681
|
|
|
675
682
|
try {
|
|
676
683
|
if (req.method === 'GET' && url === '/status') {
|
|
677
|
-
// trigger connect on first request
|
|
678
|
-
if (!this.connected && !this.connecting) {
|
|
679
|
-
this.connect();
|
|
680
|
-
}
|
|
681
684
|
this.sendJsonResponse(res, 200, {
|
|
682
685
|
success: true,
|
|
683
686
|
connected: this.connected,
|
|
@@ -821,7 +824,7 @@ export default class wahelperDaemon {
|
|
|
821
824
|
this.initDatabase();
|
|
822
825
|
this.initExitHooks();
|
|
823
826
|
this.startHttpServer();
|
|
824
|
-
|
|
827
|
+
this.connect();
|
|
825
828
|
}
|
|
826
829
|
}
|
|
827
830
|
|