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,
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<typeof makeSocket>
export type Socket = ReturnType<typeof makeSocket>