Skip to content

Commit

Permalink
exposeFunctionIfAbsent - onQRChangedEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
devlikepro committed Sep 24, 2024
1 parent c9a6167 commit 4c4cc98
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,21 @@ class Client extends EventEmitter {

// Register qr events
let qrRetries = 0;
const injected = await this.pupPage.evaluate(() => {
return typeof window.onQRChangedEvent !== 'undefined';
});
if (!injected) {
await exposeFunctionIfAbsent(this.pupPage, 'onQRChangedEvent', async (qr) => {
/**
* Emitted when a QR code is received
* @event Client#qr
* @param {string} qr QR Code
*/
this.emit(Events.QR_RECEIVED, qr);
if (this.options.qrMaxRetries > 0) {
qrRetries++;
if (qrRetries > this.options.qrMaxRetries) {
this.emit(Events.DISCONNECTED, 'Max qrcode retries reached');
await this.destroy();
}
await exposeFunctionIfAbsent(this.pupPage, 'onQRChangedEvent', async (qr) => {
/**
* Emitted when a QR code is received
* @event Client#qr
* @param {string} qr QR Code
*/
this.emit(Events.QR_RECEIVED, qr);
if (this.options.qrMaxRetries > 0) {
qrRetries++;
if (qrRetries > this.options.qrMaxRetries) {
this.emit(Events.DISCONNECTED, 'Max qrcode retries reached');
await this.destroy();
}
});
}
}
});


await this.pupPage.evaluate(async () => {
Expand Down

0 comments on commit 4c4cc98

Please sign in to comment.