From 67784bc797afba33e3e66d8a1e983269d23fd170 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Tue, 11 Feb 2020 22:26:33 -0400 Subject: [PATCH] feat: get current connection state Note: This only partly works, since the state may not be updated on WhatsApp's end. In the case of not being able to reach the phone, the state is only updated when the user performs an action, such as sending a message. This means that the state may be CONNECTED when we check, but the phone's really not connected. ref #43 --- src/Client.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Client.js b/src/Client.js index 1c72354..4cbe929 100644 --- a/src/Client.js +++ b/src/Client.js @@ -352,6 +352,16 @@ class Client extends EventEmitter { }, status); } + /** + * Gets the current connection state for the client + * @returns {WAState} + */ + async getState() { + return await this.pupPage.evaluate(() => { + return window.Store.AppState.state; + }); + } + } module.exports = Client;