Reconnect a Call
This guide covers how to reconnect to a call in your Vonage Client application. Before you begin, make sure you added the SDK to your app and (Android, iOS, JS) and you are able to make or receive calls.
Automatically Reconnect (Android & iOS)
On Android and iOS the Client SDK will by default automatically try to reconnect a call when the network conditions deteriorate. To turn off this behavior you can set autoReconnectMedia to false when initializing the Client SDK. During the automatic reconnection process you can get updates. The call will transition into a reconnecting state, which will either transition into a reconnected state or disconnected state. The Client SDK has listeners/delegate functions for the 3 states which you can use to update your UI.
Reconnecting
This is when the Client SDK is attempting to reconnect.
client.setOnCallMediaReconnectingListener {
}
// VGVoiceClientDelegate
func voiceClient(_ client: VGVoiceClient, didReceiveMediaReconnectingForCall callId: VGCallId) {
}
Reconnected
This is when the Client SDK has successfully reconnected.
client.setOnCallMediaReconnectionListener {
}
// VGVoiceClientDelegate
func voiceClient(_ client: VGVoiceClient, didReceiveMediaReconnectingForCall callId: VGCallId) {
}
Disconnected
This is when the Client SDK has failed to reconnect, you should treat the call as ended at this point.
client.setOnCallMediaDisconnectListener { callId, reason ->
}
// VGVoiceClientDelegate
func voiceClient(_ client: VGVoiceClient, didReceiveMediaDisconnectForCall callId: VGCallId, reason: VGCallDisconnectReason) {
}
Explicitly Reconnecting a Call
The Client SDK has a function for explicitly reconnecting a call. This is useful, for example, when you want to switch which device a user is speaking on without hanging up and starting a new call or if the application dies.
Once a session has been created, you can reconnect using the call ID of the initial call.
client.reconnectCall(existingCallId)
.then(reconnectedCallId => {
existingCallId = reconnectedCallId;
})
.catch(error=> {
console.error("Error reconnecting call: ", error);
})
Call:
client.reconnectCall(existingCallID) {
error, call ->
when {
error != null -> {
// Handle call reconnection error
}
else -> {
// Handle reconnected call
}
}
}
client.reconnectCall(existingCallID) { error, call in
if error == nil {
self.call = call
} else {
// Handle call reconnection error
}
}