SocketRegistry

A registry for managing WebSocket sessions.

This object maintains a collection of active WebSocket sessions and provides methods for sending messages, broadcasting to all sessions, or targeting specific sessions by user ID or room.

Functions

Link copied to clipboard
fun add(session: SocketSession)

Adds a new WebSocket session to the registry.

Link copied to clipboard

Returns all active WebSocket sessions in the registry.

Link copied to clipboard
fun broadcast(message: String)

Broadcasts a message to all active WebSocket sessions.

Link copied to clipboard
fun broadcastExcept(sender: SocketSession, message: String, room: String? = sender.room)

Broadcasts a message to all sessions in a room, excluding the sender's session.

Link copied to clipboard
fun broadcastRoom(message: String, room: String = "global")

Broadcasts a message to all sessions in a specific room.

Link copied to clipboard
fun emitToId(id: UUID, event: String, data: Any, acknowledgment: Boolean = false)

Emits an event to a specific session identified by the session ID.

Link copied to clipboard
fun emitToUsername(name: String, event: String, data: Any, acknowledgment: Boolean = false)

Emits an event to a session identified by the username.

Link copied to clipboard
fun remove(session: SocketSession)

Removes a WebSocket session from the registry.