Skip to content

bodhi-realtime-agent / MultiClientTransport

Class: MultiClientTransport<TAppContext> ​

Defined in: src/transport/multi-client-transport.ts:139

WebSocket server that manages multiple concurrent client connections. Each connection can be associated with a VoiceSession.

Type Parameters ​

TAppContext ​

TAppContext = unknown

Constructors ​

Constructor ​

new MultiClientTransport<TAppContext>(port, callbacks, host?, options?): MultiClientTransport<TAppContext>

Defined in: src/transport/multi-client-transport.ts:155

Parameters ​

port ​

number

callbacks ​

MultiClientTransportCallbacks<TAppContext>

host? ​

string = '0.0.0.0'

options? ​

MultiClientTransportOptions<TAppContext> = {}

Returns ​

MultiClientTransport<TAppContext>

Methods ​

associateSession() ​

associateSession(ws, sessionId): void

Defined in: src/transport/multi-client-transport.ts:285

Associate a session with a WebSocket connection.

Parameters ​

ws ​

WebSocket

sessionId ​

string

Returns ​

void


associateUser() ​

associateUser(ws, userId): void

Defined in: src/transport/multi-client-transport.ts:296

Associate a user with a WebSocket connection.

Parameters ​

ws ​

WebSocket

userId ​

string

Returns ​

void


attachToHttpServer() ​

attachToHttpServer(httpServer, wsPaths?): void

Defined in: src/transport/multi-client-transport.ts:201

Attach to an existing HTTP server; handle WebSocket upgrade on the given path(s). Call this instead of start() when you serve HTTP (e.g. /api) and WS on the same port. Accepts both '/' and '/ws' so client works with same-origin (/) and reverse-proxy (/ws) setups.

Parameters ​

httpServer ​

Server

wsPaths? ​

string | string[]

Returns ​

void


broadcast() ​

broadcast(message): void

Defined in: src/transport/multi-client-transport.ts:327

Broadcast a message to all connected clients.

Parameters ​

message ​

AnyServerToClientMessage

Returns ​

void


getConnectionContext() ​

getConnectionContext(ws): ConnectionContext<TAppContext> | null

Defined in: src/transport/multi-client-transport.ts:278

Get connection context for a WebSocket.

Parameters ​

ws ​

WebSocket

Returns ​

ConnectionContext<TAppContext> | null


getStats() ​

getStats(): object

Defined in: src/transport/multi-client-transport.ts:339

Get statistics about active connections.

Returns ​

object

connectionsByUser ​

connectionsByUser: Record<string, number>

totalConnections ​

totalConnections: number


sendAudioToClient() ​

sendAudioToClient(ws, data): void

Defined in: src/transport/multi-client-transport.ts:307

Send audio data to a specific WebSocket connection.

Parameters ​

ws ​

WebSocket

data ​

Buffer

Returns ​

void


sendJsonToClient() ​

sendJsonToClient(ws, message): void

Defined in: src/transport/multi-client-transport.ts:317

Send a JSON message to a specific WebSocket connection.

Parameters ​

ws ​

WebSocket

message ​

AnyServerToClientMessage

Returns ​

void


start() ​

start(): Promise<void>

Defined in: src/transport/multi-client-transport.ts:172

Start the WebSocket server on its own port (standalone).

Returns ​

Promise<void>


stop() ​

stop(): Promise<void>

Defined in: src/transport/multi-client-transport.ts:239

Stop the WebSocket server and close all connections. Awaits pending guarded validations, disposals, and teardowns so a graceful shutdown releases every app resource.

Returns ​

Promise<void>

Built with VitePress