# AtloriaWebSocketClient

**Kind:** Class

**Source:** [`atloria-monorepo/apps/web/src/lib/websocket-client.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/web/src/lib/websocket-client.ts#L30)

AtloriaWebSocketClient

Manages WebSocket connections for real-time updates.
Supports multiple namespaces (comments, documents) and channel subscriptions.

**Implements:** `WebSocketClient`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `setToken` | `setToken(token: string | null)` | `void` |
| `joinDocument` | `joinDocument(documentId: string, namespace: NamespaceType)` | `void` |
| `leaveDocument` | `leaveDocument(documentId: string, namespace: NamespaceType)` | `void` |
| `subscribe` | `subscribe(channel: string, handler: SubscriptionHandler)` | `() => void` |
| `on` | `on(event: string, handler: SubscriptionHandler)` | `void` |
| `off` | `off(event: string, handler: SubscriptionHandler)` | `void` |
| `emit` | `emit(event: string, data: any)` | `void` |
| `disconnect` | `disconnect()` | `void` |
| `isConnected` | `isConnected()` | `boolean` |

## Where it refuses work

- `AtloriaWebSocketClient` stops the work with an early return when `existingSocket?.connected`.
- `AtloriaWebSocketClient` stops the work with an early return when `this.reconnecting`.

## When something fails

- `AtloriaWebSocketClient` handles failure in 1 place: it logs it and continues in all 1.
