From f2917f0a6d6ac3cfef7a7f11d42043e8a024015d Mon Sep 17 00:00:00 2001 From: fadiinho Date: Fri, 29 Jul 2022 22:36:50 -0300 Subject: [PATCH] feat: add option to set timeout between each qr generation --- src/Socket/socket.ts | 9 +++++---- src/Types/Socket.ts | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index e65ad2d..dcc8ef2 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -26,7 +26,8 @@ export const makeSocket = ({ printQRInTerminal, defaultQueryTimeoutMs, syncFullHistory, - transactionOpts + transactionOpts, + qrTimeout }: SocketConfig) => { const ws = new WebSocket(waWebSocketUrl, undefined, { origin: DEFAULT_ORIGIN, @@ -450,7 +451,7 @@ export const makeSocket = ({ const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64') const advB64 = creds.advSecretKey - let qrMs = 60_000 // time to let a QR live + let qrMs = qrTimeout || 60_000 // time to let a QR live const genPairQR = () => { if(ws.readyState !== ws.OPEN) { return @@ -468,7 +469,7 @@ export const makeSocket = ({ ev.emit('connection.update', { qr }) qrTimer = setTimeout(genPairQR, qrMs) - qrMs = 20_000 // shorter subsequent qrs + qrMs = qrTimeout || 20_000 // shorter subsequent qrs } genPairQR() @@ -572,4 +573,4 @@ export const makeSocket = ({ } } -export type Socket = ReturnType \ No newline at end of file +export type Socket = ReturnType diff --git a/src/Types/Socket.ts b/src/Types/Socket.ts index 95e178b..f328b5e 100644 --- a/src/Types/Socket.ts +++ b/src/Types/Socket.ts @@ -37,4 +37,6 @@ export type CommonSocketConfig = { customUploadHosts: MediaConnInfo['hosts'] /** time to wait between sending new retry requests */ retryRequestDelayMs: number + /** time to wait for the generation of the next QR in ms */ + qrTimeout?: number; }