@ryuhan/baileys 1.0.4 → 1.0.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.
@@ -167,6 +167,13 @@ const makeSocket = (config) => {
167
167
  };
168
168
  /** connection handshake */
169
169
  const validateConnection = async () => {
170
+ // Wait for pairing code if not registered yet
171
+ if (!creds.registered && !creds.me) {
172
+ logger.info('Waiting for pairing code registration...');
173
+ // Don't proceed with handshake until pairing code is set
174
+ return;
175
+ }
176
+
170
177
  let helloMsg = {
171
178
  clientHello: { ephemeral: ephemeralKeyPair.public }
172
179
  };
@@ -482,13 +489,32 @@ const makeSocket = (config) => {
482
489
  ws.on('message', onMessageReceived);
483
490
  ws.on('open', async () => {
484
491
  try {
485
- await validateConnection();
492
+ // Only validate connection if we have creds.me (pairing code already requested)
493
+ if (creds.me || creds.registered) {
494
+ await validateConnection();
495
+ } else {
496
+ logger.info('WebSocket connected, waiting for pairing code...');
497
+ }
486
498
  }
487
499
  catch (err) {
488
500
  logger.error({ err }, 'error in validating connection');
489
501
  end(err);
490
502
  }
491
503
  });
504
+
505
+ // Listen for creds.update to trigger connection after pairing code is set
506
+ ev.on('creds.update', async (update) => {
507
+ // If pairing code was just set and we have me.id, trigger connection
508
+ if (update.me?.id && ws.isOpen && !creds.registered) {
509
+ logger.info('Pairing code set, initiating connection...');
510
+ try {
511
+ await validateConnection();
512
+ }
513
+ catch (err) {
514
+ logger.error({ err }, 'error in validating connection after pairing');
515
+ }
516
+ }
517
+ });
492
518
  ws.on('error', mapWebSocketError(end));
493
519
  ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
494
520
  // the server terminated the connection
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ryuhan/baileys",
3
- "version": "1.0.4",
4
- "description": "Rimuru Baileys - Fixed & Enhanced Version",
3
+ "version": "1.0.5",
4
+ "description": "Rimuru Baileys - Fixed Pairing Code Flow",
5
5
  "keywords": [
6
6
  "baileys",
7
7
  "whatsapp",