mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Implements QR Code refresh
This commit is contained in:
@@ -74,6 +74,11 @@ export default class WAConnectionValidator extends WAConnectionBase {
|
|||||||
return this.userMetaData
|
return this.userMetaData
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
/** Refresh QR Code */
|
||||||
|
protected refreshQRCode() {
|
||||||
|
const data = ['admin', 'Conn', 'reref']
|
||||||
|
return this.query(data)
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Once the QR code is scanned and we can validate our connection, or we resolved the challenge when logging back in
|
* Once the QR code is scanned and we can validate our connection, or we resolved the challenge when logging back in
|
||||||
* @private
|
* @private
|
||||||
@@ -153,13 +158,27 @@ export default class WAConnectionValidator extends WAConnectionBase {
|
|||||||
* When starting a new session, generate a QR code by generating a private/public key pair & the keys the server sends
|
* When starting a new session, generate a QR code by generating a private/public key pair & the keys the server sends
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
protected generateKeysForAuth(ref: string) {
|
protected async generateKeysForAuth(ref: string) {
|
||||||
this.curveKeys = Curve.generateKeyPair(Utils.randomBytes(32))
|
this.curveKeys = Curve.generateKeyPair(Utils.randomBytes(32))
|
||||||
this.onReadyForPhoneAuthentication([
|
|
||||||
ref,
|
let retries = 0
|
||||||
Buffer.from(this.curveKeys.public).toString('base64'),
|
let _ref = ref
|
||||||
this.authInfo.clientID,
|
|
||||||
])
|
while (retries < 5) {
|
||||||
return this.waitForMessage('s1', [])
|
retries++
|
||||||
|
|
||||||
|
this.onReadyForPhoneAuthentication([
|
||||||
|
_ref,
|
||||||
|
Buffer.from(this.curveKeys.public).toString('base64'),
|
||||||
|
this.authInfo.clientID,
|
||||||
|
])
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await this.waitForMessage('s1', [], 20 * 1000)
|
||||||
|
} catch (err) {
|
||||||
|
const json = await this.refreshQRCode()
|
||||||
|
_ref = json.ref
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user