val client = StreamVideoBuilder(
context = context,
apiKey = apiKey,
user = user,
token = token,
leaveAfterDisconnectSeconds = 60, // Leave call after 60 seconds of disconnection
).build()Network Disruption
When a participant's network connection drops during a call, the SDK automatically attempts to reconnect. You can configure how long the SDK waits before automatically leaving the call, and detect when reconnection permanently fails.
Configuring the Disconnection Timeout
The disconnection timeout determines how long a user can remain disconnected before the SDK automatically calls leave() and removes them from the call. Configure this when initializing the StreamVideo client:
By default, leaveAfterDisconnectSeconds is set to 30 seconds. Setting it to 0 disables automatic leaving, allowing users to remain in the call indefinitely until they manually hang up or their connection restores.
How It Works
When a user's network connection drops:
- The SDK enters reconnecting state (
call.state.isReconnectingbecomestrue) - The SDK starts the disconnection timer
- The SDK attempts to reconnect automatically
- If reconnection succeeds before the timeout expires, the call continues normally
- If the timeout expires without successful reconnection, the SDK automatically calls
leave()and the connection state transitions toRealtimeConnection.Failed
Detecting Connection Failure
For advanced scenarios where you need to detect permanent connection failure, observe the call.state.connection flow. When the disconnection timeout expires, the connection state transitions to RealtimeConnection.Failed:
@Composable
fun CallWithDisconnectionHandling(call: Call) {
val connection by call.state.connection.collectAsStateWithLifecycle()
when (connection) {
is RealtimeConnection.Reconnecting -> {
// Show reconnecting UI (see Connection Unstable guide)
ReconnectingOverlay()
}
is RealtimeConnection.Failed -> {
// Connection permanently failed after timeout
val error = (connection as RealtimeConnection.Failed).error
ErrorDialog(
title = "Connection Failed",
message = "Unable to reconnect to the call",
onDismiss = { /* Navigate away */ }
)
}
is RealtimeConnection.Connected,
is RealtimeConnection.Joined -> {
// Normal call UI
CallContent(call = call)
}
else -> {
// Other connection states
}
}
}For basic reconnection UI without failure detection, see the Connection Unstable guide which covers the simpler call.state.isReconnecting pattern.