final preferences = DefaultCallPreferences(
reconnectTimeout: const Duration(minutes: 2),
networkAvailabilityTimeout: const Duration(minutes: 3),
connectTimeout: const Duration(seconds: 30),
);
final streamVideo = StreamVideo(
'api_key',
user: user,
userToken: token,
options: StreamVideoOptions(
defaultCallPreferences: preferences,
),
);
Network Disruptions
Connection problems can occur during a call, for example when switching networks or if the signal is poor. In this case the SDK will try to reconnect automatically.
Automatic Reconnection
The Stream Video Flutter SDK provides a reliable reconnection system that automatically handles network disruptions. When connection issues occur, the SDK will:
- Detect network changes and connection failures
- Automatically attempt to reconnect using the most appropriate strategy
- Maintain call quality with minimal disruption to users
- Provide status updates throughout the reconnection process
Configuration Options
You can customize the reconnection behavior using CallPreferences
:
reconnectTimeout
Controls how long the SDK will attempt to reconnect before giving up. By default, this is set to Duration.zero
(unlimited - will retry indefinitely). When this timeout is exceeded, reconnection stops and call status becomes CallStatusReconnectionFailed
.
networkAvailabilityTimeout
How long to wait for network connectivity to be restored during a reconnection attempt. This defaults to Duration(minutes: 5)
and prevents waiting indefinitely for network in poor coverage areas.
connectTimeout
Maximum time to wait when establishing the initial connection to a call. The default is Duration(seconds: 60)
which provides faster feedback in poor network conditions.
Monitoring Reconnection Status
Monitor the reconnection process by observing call status changes using partialState
:
call.partialState((state) => state.status).listen((status) {
switch (status) {
case CallStatusConnecting():
// Initial connection
break;
case CallStatusReconnecting():
// Reconnection in progress
break;
case CallStatusReconnectionFailed():
// Reconnection failed - handle accordingly
break;
case CallStatusConnected():
// Successfully connected
break;
}
});