SocketManager class

Manages the state of WebSocket clients, rooms, and event subscriptions.

This class delegates the actual state management to a SocketAdapter, allowing for different implementations (e.g., in-memory, Redis).

Constructors

SocketManager({SocketAdapter? adapter})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addClient(SocketClient client) → void
Add a new client to the manager.
broadcast(String event, dynamic data, {String? namespace}) → void
Broadcast an event to all clients who have subscribed to it.
broadcastToRoom(String room, String event, dynamic data, {String? namespace}) → void
Broadcast an event to all clients in a room.
broadcastToRoomExcept(String room, String event, dynamic data, Set<String> excludedClientIds, {String? namespace}) → void
Broadcast an event to all clients in a room except specific ones.
getClient(String id) SocketClient?
Get a client instance by ID.
hasRoom(String room) bool
Check if a room exists (has active clients).
hasSubscribers(String event) bool
Check if an event has any subscribers.
isSubscribed(String event, SocketClient client) bool
Check if a client is subscribed to an event.
join(String room, SocketClient client) → void
Add a client to a room.
leave(String room, SocketClient client) → void
Remove a client from a room.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeClient(SocketClient client) → void
Remove a client from the manager.
sendTo(String id, String event, dynamic data) → void
Send a message to a specific client by ID.
sendToUser(dynamic userId, String event, dynamic data) → void
Send a message to a specific user by User ID.
sendToUsers(List userIds, String event, dynamic data) → void
Send a message to multiple specific users by User IDs.
subscribe(String event, SocketClient client) → void
Subscribe a client to an event for future broadcasts.
subscriberCount(String event) int
Get the number of subscribers for an event.
subscriptions(SocketClient client) Set<String>
Get all events a client is subscribed to.
toString() String
A string representation of this object.
inherited
unsubscribe(String event, SocketClient client) → void
Unsubscribe a client from an event.

Operators

operator ==(Object other) bool
The equality operator.
inherited