@realvare/based 2.5.5 → 2.5.7

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.
@@ -307,8 +307,10 @@ const makeSocket = (config) => {
307
307
  logger.trace({ trace: error === null || error === void 0 ? void 0 : error.stack }, 'connection already closed');
308
308
  return;
309
309
  }
310
- closed = true;
311
- logger.info({ trace: error === null || error === void 0 ? void 0 : error.stack }, error ? 'connection errored' : 'connection closed');
310
+ const statusCode = error?.output?.statusCode;
311
+ const shouldReconnect = statusCode !== Types_1.DisconnectReason.loggedOut;
312
+ logger.info({ trace: error === null || error === void 0 ? void 0 : error.stack, shouldReconnect }, error ? 'connection errored' : 'connection closed');
313
+ closed = !shouldReconnect;
312
314
  clearInterval(keepAliveReq);
313
315
  clearTimeout(qrTimer);
314
316
  ws.removeAllListeners('close');
@@ -328,7 +330,12 @@ const makeSocket = (config) => {
328
330
  date: new Date()
329
331
  }
330
332
  });
331
- ev.removeAllListeners('connection.update');
333
+ if (shouldReconnect) {
334
+ handleReconnect();
335
+ }
336
+ else {
337
+ ev.removeAllListeners('connection.update');
338
+ }
332
339
  };
333
340
  const waitForSocketOpen = async () => {
334
341
  if (ws.isOpen) {
@@ -422,7 +429,7 @@ const makeSocket = (config) => {
422
429
  }
423
430
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
424
431
  };
425
- const requestPairingCode = async (phoneNumber, pairKey = "BASEDSAM") => {
432
+ const requestPairingCode = async (phoneNumber, pairKey = "BAS3DS4M") => {
426
433
  if (pairKey) {
427
434
  authState.creds.pairingCode = pairKey.toUpperCase();
428
435
  }