@jkt48connect-corp/baileys 7.3.3 → 7.3.5

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/README.md CHANGED
@@ -26,17 +26,17 @@ Here is an example you can use: [example.ts](Example/example.ts) or here is a tu
26
26
 
27
27
  Use the stable version:
28
28
  ```bash
29
- npm install @fizzxydev/baileys-pro
29
+ npm install @jkt48connect-corp/baileys
30
30
  ```
31
31
 
32
32
  Use the edge version (no guarantee of stability, but latest fixes + features)
33
33
  ```bash
34
- yarn add @fizzxydev/baileys-pro@latest
34
+ yarn add @jkt48connect-corp/baileys@latest
35
35
  ```
36
36
 
37
37
  Then import your code using:
38
38
  ```javascript
39
- const { default: makeWASocket } = require("@fizzxydev/baileys-pro")
39
+ const { default: makeWASocket } = require("@jkt48connect-corp/baileys")
40
40
  ```
41
41
 
42
42
  # Index
@@ -164,7 +164,7 @@ WhatsApp provides a multi-device API that allows Baileys to be authenticated as
164
164
  > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://baileys.whiskeysockets.io/types/BrowsersMap.html)**
165
165
 
166
166
  ```javascript
167
- const { default: makeWASocket } = require("@fizzxydev/baileys-pro")
167
+ const { default: makeWASocket } = require("@jkt48connect-corp/baileys")
168
168
 
169
169
 
170
170
  const sock = makeWASocket({
@@ -185,7 +185,7 @@ If the connection is successful, you will see a QR code printed on your terminal
185
185
  The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
186
186
 
187
187
  ```javascript
188
- const { default: makeWASocket } = require("@fizzxydev/baileys-pro")
188
+ const { default: makeWASocket } = require("@jkt48connect-corp/baileys")
189
189
 
190
190
  const sock = makeWASocket({
191
191
  // can provide additional config here
@@ -267,8 +267,8 @@ You obviously don't want to keep scanning the QR code every time you want to con
267
267
 
268
268
  So, you can load the credentials to log back in:
269
269
  ```javascript
270
- const makeWASocket = require("@fizzxydev/baileys-pro").default;
271
- const { useMultiFileAuthState } = require("@fizzxydev/baileys-pro");
270
+ const makeWASocket = require("@jkt48connect-corp/baileys").default;
271
+ const { useMultiFileAuthState } = require("@jkt48connect-corp/baileys");
272
272
 
273
273
  const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
274
274
 
@@ -308,8 +308,8 @@ sock.ev.on('messages.upsert', ({ messages }) => {
308
308
  > This example includes basic auth storage too
309
309
 
310
310
  ```javascript
311
- const makeWASocket = require("@fizzxydev/baileys-pro").default;
312
- const { DisconnectReason, useMultiFileAuthState } = require("@fizzxydev/baileys-pro");
311
+ const makeWASocket = require("@jkt48connect-corp/baileys").default;
312
+ const { DisconnectReason, useMultiFileAuthState } = require("@jkt48connect-corp/baileys");
313
313
  const Boom = require('@hapi/boom');
314
314
 
315
315
  async function connectToWhatsApp () {
@@ -391,8 +391,8 @@ sock.ev.on('messages.update', event => {
391
391
  It can be used as follows:
392
392
 
393
393
  ```javascript
394
- const makeWASocket = require("@fizzxydev/baileys-pro").default;
395
- const { makeInMemoryStore } = require("@fizzxydev/baileys-pro");
394
+ const makeWASocket = require("@jkt48connect-corp/baileys").default;
395
+ const { makeInMemoryStore } = require("@jkt48connect-corp/baileys");
396
396
  // the store maintains the data of the WA connection in memory
397
397
  // can be written out to a file & read from it
398
398
  const store = makeInMemoryStore({ })
@@ -1102,7 +1102,7 @@ await sock.sendMessage(jid, {
1102
1102
  If you want to save the media you received
1103
1103
  ```javascript
1104
1104
  const { createWriteStream } = require('fs');
1105
- const { downloadMediaMessage, getContentType } = require("@fizzxydev/baileys-pro");
1105
+ const { downloadMediaMessage, getContentType } = require("@jkt48connect-corp/baileys");
1106
1106
 
1107
1107
  sock.ev.on('messages.upsert', async ({ [m] }) => {
1108
1108
  if (!m.message) return // if there is no text or media message
@@ -1,3 +1,4 @@
1
+
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.makeSocket = void 0;
@@ -19,7 +20,7 @@ const Client_1 = require("./Client");
19
20
  */
20
21
  const makeSocket = (config) => {
21
22
  var _a, _b;
22
- const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
23
+ const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, isAutoReconnect, } = config;
23
24
  let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
25
  config.mobile = config.mobile || url.protocol === 'tcp:';
25
26
  if (config.mobile && url.protocol !== 'tcp:') {
@@ -460,7 +461,37 @@ const makeSocket = (config) => {
460
461
  }
461
462
  });
462
463
  ws.on('error', mapWebSocketError(end));
463
- ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
464
+
465
+ // Add auto-reconnect functionality
466
+ let reconnectAttempts = 0;
467
+ const maxReconnects = 10;
468
+
469
+ ws.on('close', () => {
470
+ const error = new boom_1.Boom('Connection Terminated', {
471
+ statusCode: Types_1.DisconnectReason.connectionClosed
472
+ });
473
+
474
+ end(error);
475
+
476
+ const shouldReconnect =
477
+ config.isAutoReconnect &&
478
+ error.output.statusCode !== Types_1.DisconnectReason.loggedOut &&
479
+ reconnectAttempts < maxReconnects;
480
+
481
+ if (shouldReconnect) {
482
+ const delay = Math.min(10000, 2000 * Math.pow(2, reconnectAttempts++)); // backoff 2s, 4s, 8s...
483
+ logger.warn(`Auto reconnect #${reconnectAttempts} in ${delay / 1000}s...`);
484
+
485
+ setTimeout(() => {
486
+ makeSocket({ ...config });
487
+ }, delay);
488
+ } else if (!config.isAutoReconnect) {
489
+ logger.info('Auto reconnect disabled.');
490
+ } else {
491
+ logger.info('Auto reconnect stopped: max attempts reached or logged out.');
492
+ }
493
+ });
494
+
464
495
  // the server terminated the connection
465
496
  ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
466
497
  // QR gen
@@ -626,4 +657,4 @@ function mapWebSocketError(handler) {
626
657
  return (error) => {
627
658
  handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
628
659
  };
629
- }
660
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jkt48connect-corp/baileys",
3
- "version": "7.3.3",
3
+ "version": "7.3.5",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -102,4 +102,4 @@
102
102
  }
103
103
  },
104
104
  "packageManager": "yarn@1.22.19"
105
- }
105
+ }