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:
val client = StreamVideoBuilder(
context = context,
apiKey = apiKey,
user = user,
token = token,
leaveAfterDisconnectSeconds = 60, // Leave call after 60 seconds of disconnection
).build()By default, leaveAfterDisconnectSeconds is set to 30 seconds. A value of 0 does not disable automatic leaving: the SDK leaves the call as soon as the network drops.
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.Disconnected
If the SDK exhausts its reconnection attempts before the timeout expires, the connection state transitions to RealtimeConnection.ReconnectingFailed. RealtimeConnection.Failed is only used when joining the call fails.
The leaveAfterDisconnectSeconds parameter is client-level and applies to all calls. There is no per-call setting; set the timeout when creating the client.
Detecting Connection Failure
For advanced scenarios where you need to detect permanent connection failure, observe the call.state.connection flow. When reconnection fails, the connection state transitions to RealtimeConnection.ReconnectingFailed, and when the disconnection timeout expires, the SDK leaves the call and the state transitions to RealtimeConnection.Disconnected:
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.getstream.video.android.compose.ui.components.call.activecall.CallContent
import io.getstream.video.android.core.Call
import io.getstream.video.android.core.RealtimeConnection
@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.ReconnectingFailed,
is RealtimeConnection.Disconnected -> {
// Reconnection failed, or the SDK left the call after the timeout
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.