diff --git a/src/Defaults/index.ts b/src/Defaults/index.ts index 564581f0cd7..6e55e7db0d9 100644 --- a/src/Defaults/index.ts +++ b/src/Defaults/index.ts @@ -129,3 +129,5 @@ export const DEFAULT_CACHE_TTLS = { CALL_OFFER: 5 * 60, // 5 minutes USER_DEVICES: 5 * 60, // 5 minutes } + +export const DEFAULT_DELAY_PAIRINGCODE = 2000 // 2 seconds \ No newline at end of file diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index bca4e19f23a..98ab97ef771 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -6,6 +6,7 @@ import { proto } from '../../WAProto' import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, + DEFAULT_DELAY_PAIRINGCODE, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, MOBILE_ENDPOINT, @@ -21,6 +22,7 @@ import { bytesToCrockford, configureSuccessfulPairing, Curve, + delay, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, @@ -488,7 +490,14 @@ export const makeSocket = (config: SocketConfig) => { end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut })) } - const requestPairingCode = async(phoneNumber: string): Promise => { + const requestPairingCode = async( + phoneNumber: string, + delayMs: number | null = DEFAULT_DELAY_PAIRINGCODE + ): Promise => { + if(delayMs) { + await delay(delayMs) + } + authState.creds.pairingCode = bytesToCrockford(randomBytes(5)) authState.creds.me = { id: jidEncode(phoneNumber, 's.whatsapp.net'),