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:

Example

final recoveryHandler = ConnectionRecoveryHandler(
  client: client,
  networkStateProvider: NetworkStateProvider(),
  appLifecycleStateProvider: AppLifecycleStateProvider(),
);
Inheritance

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 true if 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