feat: add legacy connection

This commit is contained in:
Adhiraj Singh
2021-12-17 19:27:04 +05:30
parent 13b49e658d
commit 19a9980492
23 changed files with 2402 additions and 103 deletions

View File

@@ -1,5 +1,5 @@
import P from "pino"
import type { MediaType, SocketConfig } from "../Types"
import type { MediaType, SocketConfig, LegacySocketConfig, CommonSocketConfig } from "../Types"
import { Browsers } from "../Utils"
export const UNAUTHORIZED_CODES = [401, 403, 419]
@@ -17,7 +17,26 @@ export const NOISE_WA_HEADER = new Uint8Array([87, 65, 5, 2]) // last is "DICT_V
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
export const URL_REGEX = /[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)?/gi
const BASE_CONNECTION_CONFIG: CommonSocketConfig<any> = {
version: [2, 2146, 9],
browser: Browsers.baileys('Chrome'),
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
connectTimeoutMs: 20_000,
keepAliveIntervalMs: 25_000,
logger: P().child({ class: 'baileys' }),
printQRInTerminal: false,
emitOwnEvents: true,
defaultQueryTimeoutMs: 60_000,
customUploadHosts: [],
}
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
...BASE_CONNECTION_CONFIG,
getMessage: async() => undefined
}
export const DEFAULT_LEGACY_CONNECTION_CONFIG: LegacySocketConfig = {
version: [2, 2146, 9],
browser: Browsers.baileys('Chrome'),
@@ -29,7 +48,9 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
emitOwnEvents: true,
defaultQueryTimeoutMs: 60_000,
customUploadHosts: [],
getMessage: async() => undefined
phoneResponseTimeMs: 20_000,
expectResponseTimeout: 60_000,
pendingRequestTimeoutMs: 60_000
}
export const MEDIA_PATH_MAP: { [T in MediaType]: string } = {