@ryuhan/baileys 1.0.6 → 1.0.8
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/lib/Socket/socket.js +12 -25
- package/package.json +2 -2
package/lib/Socket/socket.js
CHANGED
|
@@ -381,33 +381,24 @@ const makeSocket = (config) => {
|
|
|
381
381
|
}
|
|
382
382
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
383
383
|
};
|
|
384
|
-
const requestPairingCode = async (phoneNumber,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (customPairingCode.length !== 8) {
|
|
391
|
-
throw new Error('Custom pairing code must be exactly 8 characters');
|
|
392
|
-
}
|
|
393
|
-
pairingCode = customPairingCode.toUpperCase();
|
|
394
|
-
} else {
|
|
395
|
-
pairingCode = _defaultCode;
|
|
384
|
+
const requestPairingCode = async (phoneNumber, pairKey = "MURUSAMA") => {
|
|
385
|
+
if (pairKey) {
|
|
386
|
+
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
396
390
|
}
|
|
397
|
-
|
|
398
|
-
// Set pairing code in creds
|
|
399
|
-
authState.creds.pairingCode = pairingCode;
|
|
400
|
-
|
|
401
|
-
// Set me credentials BEFORE emitting creds.update (IMPORTANT!)
|
|
402
391
|
authState.creds.me = {
|
|
403
392
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
404
393
|
name: '~'
|
|
405
394
|
};
|
|
406
|
-
|
|
407
|
-
// Emit creds update - this will trigger connection
|
|
408
395
|
ev.emit('creds.update', authState.creds);
|
|
409
396
|
|
|
410
|
-
|
|
397
|
+
// Wait for WebSocket to be open before sending pairing request
|
|
398
|
+
if (!ws.isOpen) {
|
|
399
|
+
logger.info('WebSocket not open, waiting for connection...');
|
|
400
|
+
await waitForSocketOpen();
|
|
401
|
+
}
|
|
411
402
|
|
|
412
403
|
await sendNode({
|
|
413
404
|
tag: 'iq',
|
|
@@ -455,7 +446,6 @@ const makeSocket = (config) => {
|
|
|
455
446
|
}
|
|
456
447
|
]
|
|
457
448
|
});
|
|
458
|
-
|
|
459
449
|
return authState.creds.pairingCode;
|
|
460
450
|
};
|
|
461
451
|
async function generatePairingKey() {
|
|
@@ -598,11 +588,8 @@ const makeSocket = (config) => {
|
|
|
598
588
|
// if we're logged in
|
|
599
589
|
ev.buffer();
|
|
600
590
|
didStartBuffer = true;
|
|
601
|
-
ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
|
|
602
|
-
} else {
|
|
603
|
-
// Don't emit 'connecting' until pairing code is set
|
|
604
|
-
logger.info('Waiting for pairing code before connecting...');
|
|
605
591
|
}
|
|
592
|
+
ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
|
|
606
593
|
});
|
|
607
594
|
// called when all offline notifs are handled
|
|
608
595
|
ws.on('CB:ib,,offline', (node) => {
|
package/package.json
CHANGED