From 9c4b9f4433bef335e3d2ac006dca9e5ff263f31b Mon Sep 17 00:00:00 2001 From: devlikepro Date: Wed, 26 Mar 2025 10:21:42 +0700 Subject: [PATCH] [core] NOWEB - fix scan qr issue --- src/core/engines/noweb/session.noweb.core.ts | 29 +++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index dfb316c5..ba930fea 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -457,7 +457,16 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { return; } else if (connection === 'close') { this.qr.save(''); + const statusCode = lastDisconnect.error?.output?.statusCode; + // Restart required from the server + const restartRequired = statusCode === DisconnectReason.restartRequired; + if (restartRequired) { + this.restartClient(); + return; + } + + // Stuck in STARTING status if (this.statusTracker.isStuckInStarting()) { this.logger.error( 'Session stuck in STARTING status, force stopping the session.', @@ -466,6 +475,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { return; } + // Do not reconnect if the QR code has not been scanned yet if (this.status == WAHASessionStatus.SCAN_QR_CODE) { this.logger.warn( 'QR code has not been scanned yet, force stopping the session.', @@ -474,11 +484,8 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { return; } - // reconnect if not logged out - const shouldReconnect = - // @ts-ignore: Property output does not exist on type 'Error' - lastDisconnect.error?.output?.statusCode !== - DisconnectReason.loggedOut; + // Reconnect if not logged out + const shouldReconnect = statusCode !== DisconnectReason.loggedOut; if (shouldReconnect) { if (lastDisconnect.error) { this.logger.info( @@ -486,12 +493,14 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { ); } this.restartClient(); - } else { - this.logger.error( - `Connection closed due to '${lastDisconnect.error}', do not reconnect the session.`, - ); - await this.failed(); + return; } + + // Unknown error or logged out + this.logger.error( + `Connection closed due to '${lastDisconnect.error}', do not reconnect the session.`, + ); + await this.failed(); } // Save QR