@vielhuber/wahelper 1.5.9 → 1.6.0
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 +17 -1
- package/wahelper.js +13 -3
package/package.json
CHANGED
package/wahelper-daemon.js
CHANGED
|
@@ -33,6 +33,7 @@ export default class wahelperDaemon {
|
|
|
33
33
|
this.qr = null;
|
|
34
34
|
this.pairingCode = null;
|
|
35
35
|
this.pairingCodeRequested = false;
|
|
36
|
+
this.lastError = null;
|
|
36
37
|
this.isFirstRun = false;
|
|
37
38
|
this.reconnectDelay = 1000;
|
|
38
39
|
this.httpServer = null;
|
|
@@ -571,6 +572,7 @@ export default class wahelperDaemon {
|
|
|
571
572
|
console.log('\nPairing code: ' + code);
|
|
572
573
|
})
|
|
573
574
|
.catch(err => {
|
|
575
|
+
this.lastError = { source: 'pairing', message: err.message, at: Date.now() };
|
|
574
576
|
this.log('Pairing code request failed: ' + err.message);
|
|
575
577
|
});
|
|
576
578
|
}
|
|
@@ -609,6 +611,17 @@ export default class wahelperDaemon {
|
|
|
609
611
|
}
|
|
610
612
|
|
|
611
613
|
// reconnect on all other disconnect reasons with exponential backoff
|
|
614
|
+
let reason =
|
|
615
|
+
DisconnectReason && statusCode
|
|
616
|
+
? Object.keys(DisconnectReason).find(k => DisconnectReason[k] === statusCode)
|
|
617
|
+
: null;
|
|
618
|
+
this.lastError = {
|
|
619
|
+
source: 'disconnect',
|
|
620
|
+
message:
|
|
621
|
+
'connection closed' +
|
|
622
|
+
(reason ? ' (' + reason + ')' : statusCode ? ' (statusCode=' + statusCode + ')' : ''),
|
|
623
|
+
at: Date.now()
|
|
624
|
+
};
|
|
612
625
|
let delay = this.reconnectDelay;
|
|
613
626
|
this.log('Reconnecting in ' + delay + 'ms');
|
|
614
627
|
console.log('Reconnecting in ' + delay + 'ms...');
|
|
@@ -624,6 +637,7 @@ export default class wahelperDaemon {
|
|
|
624
637
|
this.qr = null;
|
|
625
638
|
this.pairingCode = null;
|
|
626
639
|
this.pairingCodeRequested = false;
|
|
640
|
+
this.lastError = null;
|
|
627
641
|
this.reconnectDelay = 1000;
|
|
628
642
|
this.log('✅ Connected');
|
|
629
643
|
console.log('✅ Connected (device: ' + this.device + ')');
|
|
@@ -633,6 +647,7 @@ export default class wahelperDaemon {
|
|
|
633
647
|
})
|
|
634
648
|
.catch(error => {
|
|
635
649
|
this.connecting = false;
|
|
650
|
+
this.lastError = { source: 'connect', message: error.message, at: Date.now() };
|
|
636
651
|
this.log('⛔ Connect error: ' + error.message);
|
|
637
652
|
console.log('⛔ Connect error: ' + error.message);
|
|
638
653
|
setTimeout(() => this.connect(), this.reconnectDelay);
|
|
@@ -668,7 +683,8 @@ export default class wahelperDaemon {
|
|
|
668
683
|
connected: this.connected,
|
|
669
684
|
device: this.device,
|
|
670
685
|
qr: this.qr,
|
|
671
|
-
pairingCode: this.pairingCode
|
|
686
|
+
pairingCode: this.pairingCode,
|
|
687
|
+
lastError: this.lastError
|
|
672
688
|
});
|
|
673
689
|
return;
|
|
674
690
|
}
|
package/wahelper.js
CHANGED
|
@@ -95,11 +95,15 @@ export default class wahelper {
|
|
|
95
95
|
console.log('\n⚠️ Pairing required. Scan the QR code with WhatsApp, then retry.\n');
|
|
96
96
|
console.log(daemonStatus.qrString);
|
|
97
97
|
}
|
|
98
|
+
if (daemonStatus.message === 'daemon_error' || daemonStatus.message === 'daemon_timeout') {
|
|
99
|
+
console.log('⛔ ' + (daemonStatus.public_message || daemonStatus.message));
|
|
100
|
+
}
|
|
98
101
|
this.write(
|
|
99
102
|
{
|
|
100
103
|
success: false,
|
|
101
104
|
message: daemonStatus.message,
|
|
102
|
-
|
|
105
|
+
public_message: daemonStatus.public_message || null,
|
|
106
|
+
data: daemonStatus.data || daemonStatus.pairingCode || daemonStatus.qrString || null
|
|
103
107
|
},
|
|
104
108
|
true
|
|
105
109
|
);
|
|
@@ -251,14 +255,20 @@ export default class wahelper {
|
|
|
251
255
|
return { connected: false, message: 'pairing_required', pairingCode: status.pairingCode };
|
|
252
256
|
}
|
|
253
257
|
if (status.qr) {
|
|
254
|
-
// render QR to ASCII string for display
|
|
255
258
|
let qrString = await new Promise(resolve => {
|
|
256
259
|
qrcodeTerminal.generate(status.qr, { small: true }, str => resolve('\n' + str));
|
|
257
260
|
});
|
|
258
261
|
return { connected: false, message: 'qr_required', qrString };
|
|
259
262
|
}
|
|
263
|
+
if (status.lastError) {
|
|
264
|
+
return {
|
|
265
|
+
connected: false,
|
|
266
|
+
message: 'daemon_error',
|
|
267
|
+
public_message: status.lastError.source + ': ' + status.lastError.message,
|
|
268
|
+
data: status.lastError
|
|
269
|
+
};
|
|
270
|
+
}
|
|
260
271
|
}
|
|
261
|
-
|
|
262
272
|
return { connected: false, message: 'daemon_timeout' };
|
|
263
273
|
}
|
|
264
274
|
|