@raevon/n8n-nodes-whatsapp 2.0.9 → 2.0.11

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.
@@ -345,20 +345,34 @@ async function startServer(cfg) {
345
345
  }
346
346
  async function ensureServerRunning(cfg) {
347
347
  const port = getPort(cfg);
348
- // Port is free start server
348
+ // Check if server is already running and healthy
349
+ try {
350
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
351
+ if (res.ok)
352
+ return; // Server alive
353
+ }
354
+ catch { }
355
+ // Port is in use but server not responding — stale from another worker, can't kill it
356
+ // Just try to use it anyway (might have recovered)
357
+ try {
358
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(5000) });
359
+ if (res.ok)
360
+ return;
361
+ }
362
+ catch { }
363
+ // Port truly free — start server
349
364
  if (await isPortOpen(port)) {
350
365
  await startServer(cfg);
351
366
  return;
352
367
  }
353
- // Port is in usecheck if server responds
368
+ // Port occupied, can't starttry to use existing anyway
354
369
  try {
355
- const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
370
+ const res = await fetch(`http://127.0.0.1:${port}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
356
371
  if (res.ok)
357
- return; // Server alive, use it
372
+ return; // It worked
358
373
  }
359
374
  catch { }
360
- // Port in use but not responding — stale process, needs container restart
361
- throw new Error(`Port ${port} occupied. Use "Stop Server" first, or restart n8n container.`);
375
+ throw new Error(`Port ${port} occupied. Restart n8n container, then try again.`);
362
376
  }
363
377
  async function stopServer(cfg) {
364
378
  const port = getPort(cfg);
@@ -61,11 +61,20 @@ class WhatsAppConnect {
61
61
  });
62
62
  }
63
63
  else if (operation === 'stopServer') {
64
- await (0, WhatsAppApiHelper_1.stopServer)(cfg);
65
- returnData.push({
66
- json: { success: true, message: 'Server stopped', sessionPath: cfg.sessionPath },
67
- pairedItem: { item: i },
68
- });
64
+ // Try graceful shutdown via /signout
65
+ try {
66
+ await fetch(`${(0, WhatsAppApiHelper_1.getServerUrl)(cfg)}/signout`, { method: 'POST', signal: AbortSignal.timeout(3000) });
67
+ returnData.push({
68
+ json: { success: true, message: 'Server stopped', sessionPath: cfg.sessionPath },
69
+ pairedItem: { item: i },
70
+ });
71
+ }
72
+ catch {
73
+ returnData.push({
74
+ json: { success: false, message: 'Server may be in another worker. Restart n8n container to fully stop.', sessionPath: cfg.sessionPath },
75
+ pairedItem: { item: i },
76
+ });
77
+ }
69
78
  }
70
79
  else if (operation === 'connect') {
71
80
  try {
@@ -79,13 +88,14 @@ class WhatsAppConnect {
79
88
  continue;
80
89
  }
81
90
  try {
82
- const response = await fetch(`${(0, WhatsAppApiHelper_1.getServerUrl)(cfg)}/connect`, { method: 'POST' });
91
+ const serverUrl = (0, WhatsAppApiHelper_1.getServerUrl)(cfg);
92
+ const response = await fetch(`${serverUrl}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
83
93
  const result = await response.json();
84
94
  returnData.push({ json: { ...result, sessionPath: cfg.sessionPath }, pairedItem: { item: i } });
85
95
  }
86
96
  catch (err) {
87
97
  returnData.push({
88
- json: { connected: false, error: `Server unreachable: ${err.message}`, sessionPath: cfg.sessionPath },
98
+ json: { connected: false, error: `Connect failed: ${err.message}`, sessionPath: cfg.sessionPath },
89
99
  pairedItem: { item: i },
90
100
  });
91
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raevon/n8n-nodes-whatsapp",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "description": "n8n community node for WhatsApp — send and receive messages with anti-ban protection via the Baileys library",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",