# WebSocketClient

**Kind:** Class

**Source:** [`atloria-monorepo/packages/api-client/src/clients/WebSocketClient.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/packages/api-client/src/clients/WebSocketClient.ts#L66)

WebSocket client for real-time updates

## Methods

| Method | Signature | Returns |
|---|---|---|
| `connect` | `connect(url: string, token: string)` | `void` |
| `disconnect` | `disconnect()` | `void` |
| `subscribe` | `subscribe(channel: string, callback: (data: unknown) => void)` | `() => void` |
| `unsubscribe` | `unsubscribe(channel: string, callback: (data: unknown) => void)` | `void` |
| `send` | `send(channel: string, data: unknown)` | `void` |
| `getState` | `getState()` | `WebSocketState` |
| `isConnected` | `isConnected()` | `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.
