mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
EventEmitter fix
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
)
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user