diff --git a/README.md b/README.md index 2ab53bb..aa39163 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,8 @@ type SocketConfig = { waWebSocketUrl: string | URL /** Fails the connection if the connection times out in this time interval or no data is received */ connectTimeoutMs: number + /** Default timeout for queries, undefined for no timeout */ + defaultQueryTimeoutMs: number | undefined /** ping-pong interval for WS connection */ keepAliveIntervalMs: number /** proxy agent */ diff --git a/src/Defaults/index.ts b/src/Defaults/index.ts index 298d0aa..ab76ade 100644 --- a/src/Defaults/index.ts +++ b/src/Defaults/index.ts @@ -27,6 +27,7 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = { logger: P().child({ class: 'baileys' }), printQRInTerminal: false, emitOwnEvents: true, + defaultQueryTimeoutMs: 60_000 } export const MEDIA_PATH_MAP: { [T in MediaType]: string } = { diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index 522a873..3fb7657 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -25,6 +25,7 @@ export const makeSocket = ({ browser, auth: initialAuthState, printQRInTerminal, + defaultQueryTimeoutMs }: SocketConfig) => { const ws = new WebSocket(waWebSocketUrl, undefined, { origin: DEFAULT_ORIGIN, @@ -110,7 +111,7 @@ export const makeSocket = ({ * @param json query that was sent * @param timeoutMs timeout after which the promise will reject */ - const waitForMessage = async(msgId: string, timeoutMs?: number) => { + const waitForMessage = async(msgId: string, timeoutMs = defaultQueryTimeoutMs) => { let onRecv: (json) => void let onErr: (err) => void try { diff --git a/src/Types/index.ts b/src/Types/index.ts index 6eca814..d911a2d 100644 --- a/src/Types/index.ts +++ b/src/Types/index.ts @@ -30,6 +30,8 @@ export type SocketConfig = { waWebSocketUrl: string | URL /** Fails the connection if the socket times out in this interval */ connectTimeoutMs: number + /** Default timeout for queries, undefined for no timeout */ + defaultQueryTimeoutMs: number | undefined /** ping-pong interval for WS connection */ keepAliveIntervalMs: number /** proxy agent */