feat: native-mobile-api

This commit is contained in:
SamuelScheit
2023-04-20 13:01:11 +02:00
parent 28be45a9b4
commit ef673f62ca
17 changed files with 940 additions and 74 deletions

31
src/Socket/web-socket.ts Normal file
View File

@@ -0,0 +1,31 @@
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
}
}