From f9f109e134905e7c969d0354269a2ea2e436f4d2 Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Mon, 7 Sep 2020 20:22:28 +0530 Subject: [PATCH] updates --- src/WAConnection/0.Base.ts | 3 ++- src/WAConnection/3.Connect.ts | 6 +++++- src/WAConnection/Constants.ts | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/WAConnection/0.Base.ts b/src/WAConnection/0.Base.ts index e77123c..9885754 100644 --- a/src/WAConnection/0.Base.ts +++ b/src/WAConnection/0.Base.ts @@ -47,7 +47,8 @@ export class WAConnection extends EventEmitter { timeoutMs: 60*1000, waitForChats: true, maxRetries: 5, - connectCooldownMs: 2250 + connectCooldownMs: 2250, + phoneResponseTime: 7500 } /** When to auto-reconnect */ autoReconnect = ReconnectMode.onConnectionLost diff --git a/src/WAConnection/3.Connect.ts b/src/WAConnection/3.Connect.ts index 9a9866e..a90f772 100644 --- a/src/WAConnection/3.Connect.ts +++ b/src/WAConnection/3.Connect.ts @@ -275,6 +275,10 @@ export class WAConnection extends Base { if (this.logLevel === MessageLogLevel.all) { this.log(messageTag + ', ' + JSON.stringify(json), MessageLogLevel.all) } + if (!this.phoneConnected) { + this.phoneConnected = true + this.emit ('connection-phone-change', { connected: true }) + } /* Check if this is a response to a message we sent */ @@ -340,7 +344,7 @@ export class WAConnection extends Base { // poll phone connection as well, // 5000 ms for timeout - this.checkPhoneConnection (5000) + this.checkPhoneConnection (this.connectOptions.phoneResponseTime || 7500) .then (connected => { this.phoneConnected !== connected && this.emit ('connection-phone-change', {connected}) this.phoneConnected = connected diff --git a/src/WAConnection/Constants.ts b/src/WAConnection/Constants.ts index e28d744..c151436 100644 --- a/src/WAConnection/Constants.ts +++ b/src/WAConnection/Constants.ts @@ -72,6 +72,8 @@ export type WAConnectOptions = { maxRetries?: number /** should the chats be waited for */ waitForChats?: boolean + /** max time for the phone to respond to a connectivity test */ + phoneResponseTime?: number connectCooldownMs?: number /** agent which can be used for proxying connections */