fix: timeout send call

This commit is contained in:
Adhiraj Singh
2023-02-01 14:33:14 +05:30
parent 41851d9e34
commit b2c1cfbf9c
3 changed files with 15 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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 */