WebSocketManager class
WebSocketManager is a singleton class that manages a single WebSocket connection and allows multiple subscriptions to the incoming message stream.
Usage:
- Call initWebSocket once to establish a connection.
- Use sendRequestData to send messages.
- Use subscribe to listen for messages and handle events.
- Use unsubscribe to remove a subscription.
- Use closeWebSocket to close the connection and clean up.
Constructors
- WebSocketManager()
-
Factory constructor returns the singleton instance
factory
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
-
clearAllSubscription(
) → Future - Cancels all active subscriptions.
-
closeWebSocket(
) → void - Closes the WebSocket connection and all subscriptions.
-
debugPrint(
String message) → void - Prints debug messages only in debug mode (not in production).
-
initWebSocket(
String? sokcketApi, String? socketCookie) → Future< void> - Initializes the WebSocket connection.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
sendRequestData(
String requestData) → void - Sends a message to the WebSocket server.
-
subscribe(
String subscriptionName, int? timeout, {required dynamic onMessage(String? response), required dynamic onError(String? error), required dynamic onDone(), required dynamic onTimeOut(), required dynamic onSessionTimeOut()}) → void - Subscribes to the WebSocket message stream with custom event handlers.
-
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribe(
String subscriptionName) → void - Unsubscribes from a specific subscription by name.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited