mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: timeout send call
This commit is contained in:
@@ -41,7 +41,7 @@ const startSock = async() => {
|
||||
generateHighQualityLinkPreview: true,
|
||||
// ignore all broadcast messages -- to receive the same
|
||||
// comment the line below out
|
||||
shouldIgnoreJid: jid => isJidBroadcast(jid),
|
||||
// shouldIgnoreJid: jid => isJidBroadcast(jid),
|
||||
// implement to handle retries
|
||||
getMessage: async key => {
|
||||
if(store) {
|
||||
|
||||
@@ -38,6 +38,7 @@ export const makeSocket = ({
|
||||
agent
|
||||
})
|
||||
ws.setMaxListeners(0)
|
||||
|
||||
const ev = makeEventBuffer(logger)
|
||||
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
||||
const ephemeralKeyPair = Curve.generateKeyPair()
|
||||
@@ -65,7 +66,17 @@ export const makeSocket = ({
|
||||
}
|
||||
|
||||
const bytes = noise.encodeFrame(data)
|
||||
await sendPromise.call(ws, bytes) as Promise<void>
|
||||
await promiseTimeout<void>(
|
||||
connectTimeoutMs,
|
||||
async(resolve, reject) => {
|
||||
try {
|
||||
await sendPromise.call(ws, bytes)
|
||||
resolve()
|
||||
} catch(error) {
|
||||
reject(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/** send a binary node */
|
||||
|
||||
@@ -138,13 +138,13 @@ export const delayCancellable = (ms: number) => {
|
||||
|
||||
export async function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v?: T)=>void, reject: (error) => void) => void) {
|
||||
if(!ms) {
|
||||
return new Promise (promise)
|
||||
return new Promise(promise)
|
||||
}
|
||||
|
||||
const stack = new Error().stack
|
||||
// Create a promise that rejects in <ms> milliseconds
|
||||
const { delay, cancel } = delayCancellable (ms)
|
||||
const p = new Promise ((resolve, reject) => {
|
||||
const p = new Promise((resolve, reject) => {
|
||||
delay
|
||||
.then(() => reject(
|
||||
new Boom('Timed Out', {
|
||||
|
||||
Reference in New Issue
Block a user