feat: add option to set timeout between each qr generation

This commit is contained in:
fadiinho
2022-07-29 22:36:50 -03:00
committed by Adhiraj Singh
parent 34f2095263
commit f2917f0a6d
2 changed files with 7 additions and 4 deletions

View File

@@ -26,7 +26,8 @@ export const makeSocket = ({
printQRInTerminal, printQRInTerminal,
defaultQueryTimeoutMs, defaultQueryTimeoutMs,
syncFullHistory, syncFullHistory,
transactionOpts transactionOpts,
qrTimeout
}: SocketConfig) => { }: SocketConfig) => {
const ws = new WebSocket(waWebSocketUrl, undefined, { const ws = new WebSocket(waWebSocketUrl, undefined, {
origin: DEFAULT_ORIGIN, origin: DEFAULT_ORIGIN,
@@ -450,7 +451,7 @@ export const makeSocket = ({
const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64') const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64')
const advB64 = creds.advSecretKey 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 = () => { const genPairQR = () => {
if(ws.readyState !== ws.OPEN) { if(ws.readyState !== ws.OPEN) {
return return
@@ -468,7 +469,7 @@ export const makeSocket = ({
ev.emit('connection.update', { qr }) ev.emit('connection.update', { qr })
qrTimer = setTimeout(genPairQR, qrMs) qrTimer = setTimeout(genPairQR, qrMs)
qrMs = 20_000 // shorter subsequent qrs qrMs = qrTimeout || 20_000 // shorter subsequent qrs
} }
genPairQR() genPairQR()

View File

@@ -37,4 +37,6 @@ export type CommonSocketConfig = {
customUploadHosts: MediaConnInfo['hosts'] customUploadHosts: MediaConnInfo['hosts']
/** time to wait between sending new retry requests */ /** time to wait between sending new retry requests */
retryRequestDelayMs: number retryRequestDelayMs: number
/** time to wait for the generation of the next QR in ms */
qrTimeout?: number;
} }