This commit is contained in:
Adhiraj
2020-09-07 20:22:28 +05:30
parent 16ef8a617e
commit f9f109e134
3 changed files with 9 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 */