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:
parent
f1e2f32988
commit
6cece4a006
1 changed files with 14 additions and 3 deletions
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue