mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: enforce default timeout to prevent any hanging promises
This commit is contained in:
@@ -96,6 +96,8 @@ type SocketConfig = {
|
|||||||
waWebSocketUrl: string | URL
|
waWebSocketUrl: string | URL
|
||||||
/** Fails the connection if the connection times out in this time interval or no data is received */
|
/** Fails the connection if the connection times out in this time interval or no data is received */
|
||||||
connectTimeoutMs: number
|
connectTimeoutMs: number
|
||||||
|
/** Default timeout for queries, undefined for no timeout */
|
||||||
|
defaultQueryTimeoutMs: number | undefined
|
||||||
/** ping-pong interval for WS connection */
|
/** ping-pong interval for WS connection */
|
||||||
keepAliveIntervalMs: number
|
keepAliveIntervalMs: number
|
||||||
/** proxy agent */
|
/** proxy agent */
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
|
|||||||
logger: P().child({ class: 'baileys' }),
|
logger: P().child({ class: 'baileys' }),
|
||||||
printQRInTerminal: false,
|
printQRInTerminal: false,
|
||||||
emitOwnEvents: true,
|
emitOwnEvents: true,
|
||||||
|
defaultQueryTimeoutMs: 60_000
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MEDIA_PATH_MAP: { [T in MediaType]: string } = {
|
export const MEDIA_PATH_MAP: { [T in MediaType]: string } = {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export const makeSocket = ({
|
|||||||
browser,
|
browser,
|
||||||
auth: initialAuthState,
|
auth: initialAuthState,
|
||||||
printQRInTerminal,
|
printQRInTerminal,
|
||||||
|
defaultQueryTimeoutMs
|
||||||
}: SocketConfig) => {
|
}: SocketConfig) => {
|
||||||
const ws = new WebSocket(waWebSocketUrl, undefined, {
|
const ws = new WebSocket(waWebSocketUrl, undefined, {
|
||||||
origin: DEFAULT_ORIGIN,
|
origin: DEFAULT_ORIGIN,
|
||||||
@@ -110,7 +111,7 @@ export const makeSocket = ({
|
|||||||
* @param json query that was sent
|
* @param json query that was sent
|
||||||
* @param timeoutMs timeout after which the promise will reject
|
* @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 onRecv: (json) => void
|
||||||
let onErr: (err) => void
|
let onErr: (err) => void
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ export type SocketConfig = {
|
|||||||
waWebSocketUrl: string | URL
|
waWebSocketUrl: string | URL
|
||||||
/** Fails the connection if the socket times out in this interval */
|
/** Fails the connection if the socket times out in this interval */
|
||||||
connectTimeoutMs: number
|
connectTimeoutMs: number
|
||||||
|
/** Default timeout for queries, undefined for no timeout */
|
||||||
|
defaultQueryTimeoutMs: number | undefined
|
||||||
/** ping-pong interval for WS connection */
|
/** ping-pong interval for WS connection */
|
||||||
keepAliveIntervalMs: number
|
keepAliveIntervalMs: number
|
||||||
/** proxy agent */
|
/** proxy agent */
|
||||||
|
|||||||
Reference in New Issue
Block a user