Skip to content

bodhi-realtime-agent / MultiClientTransport

Class: MultiClientTransport

Defined in: transport/multi-client-transport.ts:46

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

Constructors

Constructor

new MultiClientTransport(port, callbacks, host?): MultiClientTransport

Defined in: transport/multi-client-transport.ts:51

Parameters

port

number

callbacks

MultiClientTransportCallbacks

host?

string = '0.0.0.0'

Returns

MultiClientTransport

Methods

associateSession()

associateSession(ws, sessionId): void

Defined in: transport/multi-client-transport.ts:153

Associate a session with a WebSocket connection.

Parameters

ws

WebSocket

sessionId

string

Returns

void


associateUser()

associateUser(ws, userId): void

Defined in: transport/multi-client-transport.ts:164

Associate a user with a WebSocket connection.

Parameters

ws

WebSocket

userId

string

Returns

void


attachToHttpServer()

attachToHttpServer(httpServer, wsPaths?): void

Defined in: transport/multi-client-transport.ts:91

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: transport/multi-client-transport.ts:195

Broadcast a message to all connected clients.

Parameters

message

Record<string, unknown>

Returns

void


getConnectionContext()

getConnectionContext(ws): ConnectionContext | null

Defined in: transport/multi-client-transport.ts:146

Get connection context for a WebSocket.

Parameters

ws

WebSocket

Returns

ConnectionContext | null


getStats()

getStats(): object

Defined in: transport/multi-client-transport.ts:207

Get statistics about active connections.

Returns

object

connectionsByUser

connectionsByUser: Record<string, number>

totalConnections

totalConnections: number


sendAudioToClient()

sendAudioToClient(ws, data): void

Defined in: transport/multi-client-transport.ts:175

Send audio data to a specific WebSocket connection.

Parameters

ws

WebSocket

data

Buffer

Returns

void


sendJsonToClient()

sendJsonToClient(ws, message): void

Defined in: transport/multi-client-transport.ts:185

Send a JSON message to a specific WebSocket connection.

Parameters

ws

WebSocket

message

Record<string, unknown>

Returns

void


start()

start(): Promise<void>

Defined in: transport/multi-client-transport.ts:60

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

Returns

Promise<void>


stop()

stop(): Promise<void>

Defined in: transport/multi-client-transport.ts:121

Stop the WebSocket server and close all connections.

Returns

Promise<void>

Built with VitePress