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",
|
"name": "@adiwajshing/baileys",
|
||||||
"version": "3.2.2",
|
"version": "3.2.3",
|
||||||
"description": "WhatsApp Web API",
|
"description": "WhatsApp Web API",
|
||||||
"homepage": "https://github.com/adiwajshing/Baileys",
|
"homepage": "https://github.com/adiwajshing/Baileys",
|
||||||
"main": "lib/WAConnection/WAConnection.js",
|
"main": "lib/WAConnection/WAConnection.js",
|
||||||
|
|||||||
@@ -308,22 +308,27 @@ export class WAConnection extends EventEmitter {
|
|||||||
protected async waitForConnection () {
|
protected async waitForConnection () {
|
||||||
if (this.state === 'open') return
|
if (this.state === 'open') return
|
||||||
|
|
||||||
await Utils.promiseTimeout (
|
let onOpen: () => void
|
||||||
this.pendingRequestTimeoutMs,
|
let onClose: ({ reason }) => void
|
||||||
(resolve, reject) => {
|
|
||||||
const onClose = ({ reason }) => {
|
await (
|
||||||
if (reason === DisconnectReason.invalidSession || reason === DisconnectReason.intentional) {
|
Utils.promiseTimeout (
|
||||||
reject (new Error(reason))
|
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 ()
|
.finally(() => {
|
||||||
this.off ('close', onClose)
|
this.off ('open', onOpen)
|
||||||
}
|
this.off ('close', onClose)
|
||||||
this.once ('close', onClose)
|
})
|
||||||
this.once ('open', onOpen)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user