Files
Baileys/src/Socket/web-socket.ts
2023-04-20 13:01:11 +02:00

32 lines
703 B
TypeScript

import { WebSocket as WS } from 'ws'
import { DEFAULT_ORIGIN } from '../Defaults'
import { SocketConfig } from '../Types'
export class WebSocket extends WS {
constructor(public config: SocketConfig) {
super(config.waWebSocketUrl, undefined, {
origin: DEFAULT_ORIGIN,
headers: config.options.headers as Record<string, string>,
handshakeTimeout: config.connectTimeoutMs,
timeout: config.connectTimeoutMs,
agent: config.agent,
})
}
get isOpen() {
return this.readyState === WS.OPEN
}
get isClosed() {
return this.readyState === WS.CLOSED
}
get isClosing() {
return this.readyState === WS.CLOSING
}
get isConnecting() {
return this.readyState === WS.CONNECTING
}
}