added experimental always use takeover

This commit is contained in:
Adhiraj Singh
2020-10-13 14:49:36 +05:30
parent 163497964c
commit 16b138c759
3 changed files with 5 additions and 2 deletions

View File

@@ -48,7 +48,8 @@ export class WAConnection extends EventEmitter {
waitForChats: true,
maxRetries: 5,
connectCooldownMs: 3000,
phoneResponseTime: 7500
phoneResponseTime: 7500,
alwaysUseTakeover: false
}
/** When to auto-reconnect */
autoReconnect = ReconnectMode.onConnectionLost

View File

@@ -79,7 +79,7 @@ export class WAConnection extends Base {
// determine whether reconnect should be used or not
const shouldUseReconnect = (this.lastDisconnectReason === DisconnectReason.close ||
this.lastDisconnectReason === DisconnectReason.lost) &&
this.user?.jid
!this.connectOptions.alwaysUseTakeover
const reconnectID = shouldUseReconnect && this.user.jid.replace ('@s.whatsapp.net', '@c.us')
this.conn = new WS(WS_URL, null, {

View File

@@ -88,6 +88,8 @@ export type WAConnectOptions = {
agent?: Agent
/** agent used for fetch requests -- uploading/downloading media */
fetchAgent?: Agent
/** Always uses takeover for connections */
alwaysUseTakeover?: boolean
}
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
export const URL_REGEX = /[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)?/gi