fix: emit disconnected event on page navigation

This also addresses an issue due to a change in behavior from WhatsApp Web when the session is logged out from the device.
This commit is contained in:
Pedro Lopez
2021-04-20 20:02:22 -04:00
parent f1e2f32988
commit 6cece4a006
3 changed files with 14 additions and 3 deletions

View File

@@ -335,7 +335,7 @@ class Client extends EventEmitter {
/**
* Emitted when the client has been disconnected
* @event Client#disconnected
* @param {WAState} reason state that caused the disconnect
* @param {WAState|"NAVIGATION"} reason reason that caused the disconnect
*/
this.emit(Events.DISCONNECTED, state);
this.destroy();
@@ -373,6 +373,13 @@ class Client extends EventEmitter {
* @event Client#ready
*/
this.emit(Events.READY);
// Disconnect when navigating away
// Because WhatsApp Web now reloads when logging out from the device, this also covers that case
this.pupPage.on('framenavigated', async () => {
this.emit(Events.DISCONNECTED, 'NAVIGATION');
await this.destroy();
});
}
/**