feat: add delay between retry requests

This commit is contained in:
Adhiraj Singh
2022-03-23 12:40:01 +05:30
parent b933970d51
commit 8d7fde1bf4
3 changed files with 18 additions and 4 deletions

View File

@@ -30,7 +30,8 @@ const BASE_CONNECTION_CONFIG: CommonSocketConfig<any> = {
emitOwnEvents: true, emitOwnEvents: true,
defaultQueryTimeoutMs: 60_000, defaultQueryTimeoutMs: 60_000,
customUploadHosts: [], customUploadHosts: [],
treatCiphertextMessagesAsReal: true treatCiphertextMessagesAsReal: true,
retryRequestDelayMs: 250
} }
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = { export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {

View File

@@ -2,14 +2,18 @@
import { proto } from '../../WAProto' import { proto } from '../../WAProto'
import { KEY_BUNDLE_TYPE } from '../Defaults' import { KEY_BUNDLE_TYPE } from '../Defaults'
import { BaileysEventMap, Chat, GroupMetadata, MessageUserReceipt, ParticipantAction, SocketConfig, WAMessageStubType } from '../Types' import { BaileysEventMap, Chat, GroupMetadata, MessageUserReceipt, ParticipantAction, SocketConfig, WAMessageStubType } from '../Types'
import { decodeMessageStanza, downloadAndProcessHistorySyncNotification, encodeBigEndian, generateSignalPubKey, normalizeMessageContent, toNumber, xmppPreKey, xmppSignedPreKey } from '../Utils' import { decodeMessageStanza, delay, downloadAndProcessHistorySyncNotification, encodeBigEndian, generateSignalPubKey, normalizeMessageContent, toNumber, xmppPreKey, xmppSignedPreKey } from '../Utils'
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex' import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex'
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getAllBinaryNodeChildren, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary' import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getAllBinaryNodeChildren, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary'
import { makeChatsSocket } from './chats' import { makeChatsSocket } from './chats'
import { extractGroupMetadata } from './groups' import { extractGroupMetadata } from './groups'
export const makeMessagesRecvSocket = (config: SocketConfig) => { export const makeMessagesRecvSocket = (config: SocketConfig) => {
const { logger, treatCiphertextMessagesAsReal } = config const {
logger,
treatCiphertextMessagesAsReal,
retryRequestDelayMs
} = config
const sock = makeChatsSocket(config) const sock = makeChatsSocket(config)
const { const {
ev, ev,
@@ -360,7 +364,14 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
'failure in decrypting message' 'failure in decrypting message'
) )
retryMutex.mutex( retryMutex.mutex(
async() => await sendRetryRequest(stanza) async() => {
if(ws.readyState === ws.OPEN) {
await sendRetryRequest(stanza)
if(retryRequestDelayMs) {
await delay(retryRequestDelayMs)
}
}
}
) )
} else { } else {
await sendMessageAck(stanza, { class: 'receipt' }) await sendMessageAck(stanza, { class: 'receipt' })

View File

@@ -39,4 +39,6 @@ export type CommonSocketConfig<T> = {
customUploadHosts: MediaConnInfo['hosts'] customUploadHosts: MediaConnInfo['hosts']
/** fires a conversationTimestamp & read count update on CIPHERTEXT messages */ /** fires a conversationTimestamp & read count update on CIPHERTEXT messages */
treatCiphertextMessagesAsReal: boolean treatCiphertextMessagesAsReal: boolean
/** time to wait between sending new retry requests */
retryRequestDelayMs: number
} }