app-manager-edge-worker 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-manager-edge-worker",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Distributed Scraper Edge Worker for Apps Manager. Run on any local machine, VPS, or Termux Android device to serve browser and HTTP scraping jobs.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -112,7 +112,7 @@ export class WhatsAppWorkerHandler {
112
112
  * Can be invoked for pairing (requestQr=true) or on-demand send.
113
113
  */
114
114
  async initialize(requestQr = false) {
115
- if (this.sock && this.status === "CONNECTED") {
115
+ if (this.sock && this.status === "CONNECTED" && !requestQr) {
116
116
  this._resetIdleTimer();
117
117
  return this.sock;
118
118
  }
@@ -126,19 +126,31 @@ export class WhatsAppWorkerHandler {
126
126
  }
127
127
  }
128
128
 
129
+ if (requestQr) {
130
+ // Clean slate for fresh pairing request
131
+ if (this.sock) {
132
+ try {
133
+ this.sock.end(undefined);
134
+ } catch (_) {}
135
+ this.sock = null;
136
+ }
137
+ this.clearAuth();
138
+ }
139
+
129
140
  this.isInitializing = true;
130
141
  this.status = requestQr ? "PAIRING" : "STANDBY";
131
142
 
132
143
  try {
133
144
  const { state, saveCreds } = await useMultiFileAuthState(this.authDir);
134
- const { version } = await fetchLatestBaileysVersion().catch(() => ({
135
- version: [2, 3000, 1015901307],
136
- }));
145
+ let version = undefined;
146
+ try {
147
+ const fetched = await fetchLatestBaileysVersion();
148
+ if (fetched?.version) version = fetched.version;
149
+ } catch (_) {}
137
150
 
138
151
  const logger = pino({ level: "silent" });
139
152
 
140
- this.sock = makeWASocket({
141
- version,
153
+ const socketConfig = {
142
154
  auth: state,
143
155
  logger,
144
156
  printQRInTerminal: false,
@@ -146,7 +158,10 @@ export class WhatsAppWorkerHandler {
146
158
  syncFullHistory: false,
147
159
  markOnlineOnConnect: false, // Stealth Presence: Does NOT broadcast green online dot
148
160
  generateHighQualityLinkPreview: true,
149
- });
161
+ };
162
+ if (version) socketConfig.version = version;
163
+
164
+ this.sock = makeWASocket(socketConfig);
150
165
 
151
166
  this.sock.ev.on("creds.update", saveCreds);
152
167
 
@@ -173,6 +188,10 @@ export class WhatsAppWorkerHandler {
173
188
  try {
174
189
  this.currentQrDataUrl = await qrcode.toDataURL(qr);
175
190
  this.onQrGenerated({ qrDataUrl: this.currentQrDataUrl });
191
+ this.onStatusChange({
192
+ status: "PAIRING",
193
+ qrCodeDataUrl: this.currentQrDataUrl,
194
+ });
176
195
  } catch (err) {
177
196
  console.error("[WhatsApp Worker] Failed to render QR Data URL:", err);
178
197
  }