Skip to content

WebSocketClient

reference
1 min readUpdated

Kind: Class

Source: atloria-monorepo/packages/api-client/src/clients/WebSocketClient.ts

WebSocket client for real-time updates

Methods

MethodSignatureReturns
connectconnect(url: string, token: string)void
disconnectdisconnect()void
subscribesubscribe(channel: string, callback: (data: unknown) => void)() => void
unsubscribeunsubscribe(channel: string, callback: (data: unknown) => void)void
sendsend(channel: string, data: unknown)void
getStategetState()WebSocketState
isConnectedisConnected()boolean

Where it refuses work

  • WebSocketClient stops the work with an early return when !channelSubscriptions.
  • WebSocketClient stops the work with an early return when message.type === 'pong'.
  • WebSocketClient stops the work with an early return when this.config.heartbeatInterval <= 0.

When something fails

  • WebSocketClient handles failure in 4 places: it logs it and continues in all 4.

Was this page helpful?

Download as PDF