ConnectionRecoveryHandler class
A connection recovery handler with intelligent reconnection management.
Provides intelligent reconnection management with multiple policies and retry strategies for StreamWebSocketClient instances. Automatically handles reconnection based on various conditions like network state, app lifecycle, and connection errors.
The handler monitors connection state changes and applies configurable policies to determine when reconnection should occur, implementing exponential backoff with jitter for optimal retry behavior.
Built-in Policies
The handler automatically includes several reconnection policies:
- WebSocketAutomaticReconnectionPolicy: Checks whether reconnection is enabled based on disconnection source
- InternetAvailabilityReconnectionPolicy: Only allows reconnection when network is available
- BackgroundStateReconnectionPolicy: Prevents reconnection when app is in background
Example
final recoveryHandler = ConnectionRecoveryHandler(
client: client,
networkStateProvider: NetworkStateProvider(),
appLifecycleStateProvider: AppLifecycleStateProvider(),
);
- Inheritance
-
- Object
- Disposable
- ConnectionRecoveryHandler
Constructors
-
ConnectionRecoveryHandler({required StreamWebSocketClient client, NetworkStateProvider? networkStateProvider, LifecycleStateProvider? lifecycleStateProvider, bool keepConnectionAliveInBackground = false, List<
AutomaticReconnectionPolicy> ? policies, RetryStrategy? retryStrategy}) - Creates a new instance of ConnectionRecoveryHandler.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Returns
trueif this object has been disposed.no setterinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
disconnectIfNeeded(
) → void - Disconnects the client if policies require it.
-
dispose(
) → Future< void> -
Disposes of this object.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reconnectIfNeeded(
) → void - Attempts reconnection if policies allow it.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited