diff --git a/index.d.ts b/index.d.ts index 268d8c3..631d8bc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -197,6 +197,9 @@ declare namespace WAWebJS { intervalMs?: number, ): Promise; + /** Cancels an active pairing code session and returns to QR code mode */ + cancelPairingCode(): Promise + /** Force reset of connection state for the client */ resetState(): Promise; diff --git a/src/Client.js b/src/Client.js index deb4f7e..ed2392d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -255,8 +255,6 @@ class Client extends EventEmitter { window.AuthStore.Base64Tools.encodeB64( registrationInfo.identityKeyPair.pubKey, ); - const advSecretKey = - await window.AuthStore.RegistrationUtils.getADVSecretKey(); const platform = window.AuthStore.RegistrationUtils.DEVICE_PLATFORM; const getQR = (ref) => @@ -266,10 +264,11 @@ class Client extends EventEmitter { ',' + identityKeyB64 + ',' + - advSecretKey + + window + .require('WAWebUserPrefsMultiDevice') + .getADVSecretKey() + ',' + platform; - window.onQRChangedEvent(getQR(window.AuthStore.Conn.ref)); // initial qr window.AuthStore.Conn.on('change:ref', (_, ref) => { window.onQRChangedEvent(getQR(ref)); @@ -516,6 +515,14 @@ class Client extends EventEmitter { showNotification = true, intervalMs = 180000, ) { + await exposeFunctionIfAbsent( + this.pupPage, + 'onCodeReceivedEvent', + async (code) => { + this.emit(Events.CODE_RECEIVED, code); + return code; + }, + ); return await this.pupPage.evaluate( async (phoneNumber, showNotification, intervalMs) => { const getCode = async () => { @@ -553,6 +560,22 @@ class Client extends EventEmitter { ); } + /** + * Cancels an active pairing code session and returns to QR code mode + */ + async cancelPairingCode() { + await this.pupPage.evaluate(async () => { + if (window.codeInterval) { + clearInterval(window.codeInterval); + window.codeInterval = undefined; + } + window.require('WAWebLaunchSocketUtils').refreshQR(); + await window + .require('WAWebAltDeviceLinkingApi') + .initializeQRLinking(); + }); + } + /** * Attach event listeners to WA Web * Private function