EventEmitter fix

This commit is contained in:
Adhiraj Singh
2020-10-29 17:29:38 +05:30
parent 7b2aa7dd8a
commit 92c15b477b
2 changed files with 20 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@adiwajshing/baileys",
"version": "3.2.2",
"version": "3.2.3",
"description": "WhatsApp Web API",
"homepage": "https://github.com/adiwajshing/Baileys",
"main": "lib/WAConnection/WAConnection.js",

View File

@@ -308,22 +308,27 @@ export class WAConnection extends EventEmitter {
protected async waitForConnection () {
if (this.state === 'open') return
await Utils.promiseTimeout (
this.pendingRequestTimeoutMs,
(resolve, reject) => {
const onClose = ({ reason }) => {
if (reason === DisconnectReason.invalidSession || reason === DisconnectReason.intentional) {
reject (new Error(reason))
let onOpen: () => void
let onClose: ({ reason }) => void
await (
Utils.promiseTimeout (
this.pendingRequestTimeoutMs,
(resolve, reject) => {
onClose = ({ reason }) => {
if (reason === DisconnectReason.invalidSession || reason === DisconnectReason.intentional) {
reject (new Error(reason))
}
}
this.off ('open', onOpen)
onOpen = resolve
this.once ('close', onClose)
this.once ('open', onOpen)
}
const onOpen = () => {
resolve ()
this.off ('close', onClose)
}
this.once ('close', onClose)
this.once ('open', onOpen)
}
)
.finally(() => {
this.off ('open', onOpen)
this.off ('close', onClose)
})
)
}
/**