From 7bcd2a620605683a7bbd0af8e3f61567c75a5a30 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Wed, 22 May 2024 15:37:41 +0700 Subject: [PATCH] [core] WEBJS videofix --- .pre-commit-config.yaml | 1 + docker-compose.yaml | 2 + nest-cli.json | 2 +- src/core/abc/session.abc.ts | 4 + .../engines/webjs/2.2412.54-videofix.html | 316 ------------------ src/core/engines/webjs/session.webjs.core.ts | 19 +- 6 files changed, 24 insertions(+), 320 deletions(-) delete mode 100644 src/core/engines/webjs/2.2412.54-videofix.html diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81832171..e4714a08 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,6 +2,7 @@ exclude: | (?x)^( ^src/dashboard/.*| ^src/core/engines/webjs/.*html + ^src/plus/engines/webjs/.*html )$ repos: diff --git a/docker-compose.yaml b/docker-compose.yaml index 40986183..0e0c1983 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -39,6 +39,8 @@ services: # Default - waha / waha - WAHA_DASHBOARD_USERNAME=waha - WAHA_DASHBOARD_PASSWORD=waha + # Engine specific environment variables + # - WAHA_WEBJS_WEB_VERSION=2.2412.54-videofix restart: always whatsapp-http-api-plus--mongodb: diff --git a/nest-cli.json b/nest-cli.json index bcd99f9d..6a76019a 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -3,7 +3,7 @@ "sourceRoot": "src", "compilerOptions": { "plugins": ["@nestjs/swagger"], - "assets": ["dashboard/**", "core/engines/webjs/*"], + "assets": ["dashboard/**", "core/engines/webjs/*", "plus/engines/webjs/*"], "watchAssets": true } } diff --git a/src/core/abc/session.abc.ts b/src/core/abc/session.abc.ts index a6caf053..4dcdfb8d 100644 --- a/src/core/abc/session.abc.ts +++ b/src/core/abc/session.abc.ts @@ -81,6 +81,7 @@ export interface SessionParams { sessionStore: DataStore; proxyConfig?: ProxyConfig; sessionConfig?: SessionConfig; + engineConfig?: any; } export abstract class WhatsappSession { @@ -93,6 +94,7 @@ export abstract class WhatsappSession { protected sessionStore: DataStore; protected proxyConfig?: ProxyConfig; public sessionConfig?: SessionConfig; + protected engineConfig?: any; private _status: WAHASessionStatus; @@ -103,6 +105,7 @@ export abstract class WhatsappSession { proxyConfig, mediaManager, sessionConfig, + engineConfig, }: SessionParams) { this.events = new EventEmitter(); this.name = name; @@ -111,6 +114,7 @@ export abstract class WhatsappSession { this.sessionStore = sessionStore; this.mediaManager = mediaManager; this.sessionConfig = sessionConfig; + this.engineConfig = engineConfig; } protected set status(value: WAHASessionStatus) { diff --git a/src/core/engines/webjs/2.2412.54-videofix.html b/src/core/engines/webjs/2.2412.54-videofix.html deleted file mode 100644 index aa5fdcf5..00000000 --- a/src/core/engines/webjs/2.2412.54-videofix.html +++ /dev/null @@ -1,316 +0,0 @@ -WhatsApp Web
WhatsApp
 End-to-end encrypted
\ No newline at end of file diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 7a19ac48..3b6e3906 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -62,8 +62,13 @@ const QRCode = require('qrcode'); // eslint-disable-next-line @typescript-eslint/no-var-requires const qrcode = require('qrcode-terminal'); +export interface WebJSConfig { + webVersion?: string; +} + export class WhatsappSessionWebJSCore extends WhatsappSession { engine = WAHAEngine.WEBJS; + protected engineConfig?: WebJSConfig; whatsapp: Client; protected qr: QR; @@ -73,16 +78,24 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { this.qr = new QR(); } + /** + * Folder with the current class + */ + protected getClassDirName() { + return __dirname; + } + protected getClientOptions(): ClientOptions { - // Folder with current file - const path = __dirname; + const path = this.getClassDirName(); + const webVersion = this.engineConfig?.webVersion || '2.2412.54'; + this.log.debug(`Using web version: '${webVersion}'`); return { puppeteer: { headless: true, executablePath: this.getBrowserExecutablePath(), args: this.getBrowserArgsForPuppeteer(), }, - webVersion: '2.2412.54', + webVersion: webVersion, webVersionCache: { type: 'local', path: path,