Socket class

Facade for the Socket system.

Provides static helpers to interact with the framework's socket manager (broadcasts, room management, client lookup). Useful in jobs, controllers and background tasks where dependency injection isn't available.

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static 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.
getSubscriptions(SocketClient client) Set<String>
Get all events a client is subscribed to.
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.
joinRoom(String room, SocketClient client) → void
Add a client to a room.
leaveRoom(String room, SocketClient client) → void
Remove a client from a room.
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.
unsubscribe(String event, SocketClient client) → void
Unsubscribe a client from an event.