SocketService class
SocketService: Singleton-per-URL socket handler.
Constructors
-
SocketService.new(String url, {Map<
String, dynamic> ? queryParams, void onConnect()?, void onError(dynamic error)?, void onDisconnect(dynamic reason)?, void onReconnectAttempt(int attempt)?}) -
Factory: Return existing or create new instance per URL
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isConnected → bool
-
Check connection state
no setter
- onConnectCallback → void Function()?
-
Optional callbacks
final
- onDisconnectCallback → void Function(dynamic reason)?
-
final
- onErrorCallback → void Function(dynamic error)?
-
final
- onReconnectAttemptCallback → void Function(int attempt)?
-
final
- raw → Socket
-
Get the underlying socket
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- url → String
-
final
Methods
-
connect(
) → void - Connect the socket
-
disconnect(
{bool removeListeners = false}) → void - Disconnect the socket (but keep instance)
-
dispose(
) → void - Completely dispose socket and remove instance
-
emit(
String event, dynamic data) → void - Emit an event with data
-
hasListeners(
String event) → bool - Check if the socket has listeners for an event
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
off(
String event) → void - Remove a listener
-
offAll(
) → void - Remove all listeners for the socket
-
on(
String event, dynamic callback(dynamic)) → void - Listen to an event
-
once(
String event, dynamic callback(dynamic)) → void - Listen to an event only once
-
reconnect(
) → void - Reconnect manually
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
allInstances
→ Map<
String, SocketService> -
Get all existing instances (for debugging or cleanup)
no setter
Static Methods
-
disposeAll(
) → void - Dispose all sockets