WebSocket Manager API Reference
The WebSocket Manager provides comprehensive WebSocket connection handling, pooling, and real-time communication features.WebSocketManager
Main WebSocket connection management class.Constructor
options
(object): WebSocket configuration options
maxConnections
(number): Maximum concurrent connectionsconnectionTimeout
(number): Connection timeoutheartbeatInterval
(number): Heartbeat intervalheartbeatTimeout
(number): Heartbeat timeoutauthentication
(object): Authentication configurationcompression
(object): Compression settingsprotocols
(array): Supported protocols
Methods
accept(request, options)
Accept a WebSocket connection.request
(Request): HTTP request with WebSocket upgradeoptions
(object, optional): Accept options
getActiveConnections()
Get number of active connections.getUserSockets(userId)
Get sockets for a specific user.userId
(string): User identifier
broadcast(message, filter)
Broadcast message to connections.message
(any): Message to broadcastfilter
(function, optional): Filter function for connections
close(code, reason)
Close all connections.code
(number, optional): Close codereason
(string, optional): Close reason
WebSocketPool
Connection pooling for WebSocket connections.Constructor
options
(object): Pool configuration options
maxConnections
(number): Maximum connections per poolminConnections
(number): Minimum connections to maintainacquireTimeout
(number): Timeout for acquiring connectionidleTimeout
(number): Close idle connections aftervalidateOnCheckout
(boolean): Validate connection before use
Methods
acquire()
Acquire connection from pool.release(connection)
Release connection back to pool.connection
(WebSocket): Connection to release
getActiveCount()
Get active connections count.getIdleCount()
Get idle connections count.getHealthStatus()
Get backend health status.Broadcaster
Message broadcasting utilities.Constructor
Methods
createChannel(name)
Create broadcast channel.name
(string): Channel name
subscribe(socket, channel)
Subscribe socket to channel.socket
(WebSocket): WebSocket connectionchannel
(string): Channel name
unsubscribe(socket, channel)
Unsubscribe socket from channel.socket
(WebSocket): WebSocket connectionchannel
(string): Channel name
broadcast(channel, message, options)
Broadcast to channel.channel
(string): Channel namemessage
(any): Message to broadcastoptions
(object, optional): Broadcast options