From 5cf069f86b49425ba15f57d5e1b8d8d8f68e7d1b Mon Sep 17 00:00:00 2001 From: Vilsonei Machado Date: Wed, 28 Aug 2024 17:42:23 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Tratativa=20para=20resolver=20o=20problema?= =?UTF-8?q?=20de=20reconex=C3=A3o=20quando=20h=C3=A1=20perdas=20de=20conex?= =?UTF-8?q?=C3=A3o=20com=20o=20WebSocket.=20Antes=20ficavam=20v=C3=A1rios?= =?UTF-8?q?=20listeners=20escutando=20um=20client=20inexistente.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/whatsapp/services/whatsapp.service.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cdaf30521..7ec25413f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "tsc", "start": "ts-node --files --transpile-only ./src/main.ts", "start:prod": "bash start.sh", - "start:dev": "cls && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts", + "start:dev": "tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts", "test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts" }, "repository": { diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 4f4566ea2..18d41a819 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -178,6 +178,7 @@ export class WAStartupService { this.configService.get('DATABASE'); private endSession = false; + private inReconnection = false; public client: WASocket; private authState: Partial = {}; private authStateProvider: AuthStateProvider; @@ -424,7 +425,7 @@ export class WAStartupService { if (connection === 'close') { const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut; - if (shouldReconnect) { + if (shouldReconnect && !this.inReconnection) { await this.connectToWhatsapp(); } else { this.sendDataWebhook('statusInstance', { @@ -552,12 +553,22 @@ export class WAStartupService { public async connectToWhatsapp(): Promise { try { this.instanceQr.count = 0; - await this.loadWebhook(); - this.client = await this.setSocket(); - this.eventHandler(); + const timeout = this.client ? 3000 : 0; + + if (!this.inReconnection) { + this.inReconnection = true; + setTimeout(async () => { + await this.loadWebhook(); + this.client = await this.setSocket(); + this.eventHandler(); + + this.inReconnection = false; + }, timeout); + } return this.client; } catch (error) { + this.inReconnection = false; this.logger.error(error); throw new InternalServerErrorException(error?.toString()); } From 32342fd18dfe3918af4e1349cc68983cb8ec60b5 Mon Sep 17 00:00:00 2001 From: Vilsonei Machado Date: Wed, 28 May 2025 08:26:49 -0300 Subject: [PATCH 2/2] =?UTF-8?q?Corre=C3=A7=C3=A3o=20da=20nova=20vers=C3=A3?= =?UTF-8?q?o=20do=20WhatsApp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.dev b/.env.dev index 4f8f11175..3a1ec0f6f 100644 --- a/.env.dev +++ b/.env.dev @@ -65,7 +65,7 @@ INSTANCE_EXPIRATION_TIME=false CONFIG_SESSION_PHONE_CLIENT=CodeChat_V1 CONFIG_SESSION_PHONE_NAME=Edge -WA_VERSION=[ 2, 3000, 1015901307 ] +WA_VERSION=[ 2, 3000, 1023047013 ] # Set qrcode display limit QRCODE_LIMIT=5