The Vonage Client SDK allows you to build applications for iOS, Android, and the Web that feature voice and messaging communications backed by the Vonage Conversation API.
When building such apps, it is essential to consider how changes in connectivity can affect the app's experience. The typical scenario of being on a cellular connection, reaching home and connecting to WiFi could present challenges as the device switches between the connections. This post will cover how to mitigate such issues when using the Vonage Client SDK for Android and iOS.
Automatically Reconnecting Calls
The Client SDK will attempt to automatically reconnect a call when there is a change in internet connectivity. The Client SDK also provides listeners on Android and delegate functions on iOS to monitor connectivity changes. The call will initially transition into a reconnecting state, which will either transition into a reconnected or disconnected state. Monitoring when the SDK is experiencing changes in connection will allow you to update your app's UI to give feedback to your users.
Reconnecting State
This is when the Client SDK is attempting to reconnect.
client.setOnCallMediaReconnectingListener {
// Handle reconnecting state
}
// VGVoiceClientDelegate
func voiceClient(_ client: VGVoiceClient, didReceiveMediaReconnectingForCall callId: VGCallId) {
// Handle reconnecting state
}
Reconnected State
This is when the Client SDK has successfully reconnected.
client.setOnCallMediaReconnectionListener {
// Handle reconnection
}
// VGVoiceClientDelegate
func voiceClient(_ client: VGVoiceClient, didReceiveMediaReconnectionForCall callId: VGCallId) {
// Handle reconnection
}
Disconnected
This is when the Client SDK has failed to reconnect the call.
client.setOnCallMediaDisconnectListener { callId, reason ->
// Handle disconnection
}
// VGVoiceClientDelegate
func voiceClient(_ client: VGVoiceClient, didReceiveMediaDisconnectForCall callId: VGCallId, reason: VGCallDisconnectReason) {
// Handle disconnection
}
Recovering Calls or Moving Devices
The Client SDKs also have the flexibility to allow you to recover a call if your app dies or for you to move a call between devices. The reconnectCall
function takes a call ID and will attempt to reconnect your SDK to an existing call:
client.reconnectCall("existingCallID") {
error, call ->
when {
error != null -> {
// Handle call reconnection error
}
else -> {
// Handle reconnected call
}
}
}
client.reconnectCall("existingCallID") { error in
if error != nil {
// handle error
return
}
// handle call
}
To recover a call, you can store the ongoing call ID in some sort of local storage, and when your app reopens, you can attempt a reconnection. If you are trying to move calls between two devices, you can send the call ID to the new device and reconnect from there. Using reconnectCall
on the new device will join the call and close the connection on the old device. reconnectCall
is also available on the JavaScript Client SDK.
What Next?
You can read the guide on call reconnection. To learn more about the Client SDK, visit developer.vonage.com.