Reconnect a Call or Conversation's Media
Overview
This guide covers how to reconnect to a call or a conversation's media in your Android and iOS Vonage Client application.
Automatically Reconnect
The Client SDK can attempt to automatically reconnect to a call or a conversation's media if you set the client's autoReoffer configuration property. This is useful for when there is a short drop in internet connectivity or the user switches between cellular and WiFi.
let config = NXMClientConfig()
config.autoMediaReoffer = true
NXMClient.setConfiguration(config)
Listening for Call Status Changes
To know when the status of a call or conversation's media has changed, you can listen for media status events with the Android and iOS SDK. Note the disconnected state. A disconnected state means that there has been a temporary network issue and the client will attempt a reconnection providing the autoReoffer configuration property was set. If you did not set autoReoffer to true then you can manually reconnect here.
To get MediaConnectionState updates you need to add a NexmoMediaStatusListener. You can do this by setting it on a call's conversation object.
To get MediaConnectionState updates, you need to add a NexmoMediaStatusListener. You can do this by setting it on a call's conversation object.
To get NXMMediaConnectionStatus updates you need to conform to the NXMConversationDelegate. You can do this by setting it on a call's conversation object.
call.conversation.delegate = self
Then you can implement the onMediaConnectionStateChange delegate function
extension ViewController: NXMConversationDelegate {
func conversation(_ conversation: NXMConversation, didReceive error: Error) {}
func conversation(_ conversation: NXMConversation, onMediaConnectionStateChange state: NXMMediaConnectionStatus, legId: String) {
// Update UI and/or reconnect
}
}
To get NXMMediaConnectionStatus updates you need to conform to the NXMConversationDelegate. You can do this by setting it on a call's conversation object.
Then you can implement the onMediaConnectionStateChange delegate function
Manually Reconnect
The Client SDK has functions for explicitly reconnecting a call or conversation's media. 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 if the application dies.
Call:
Conversation media:
Call:
Conversation media:
Call:
NXMClient.shared.reconnectCall(withConversationId: "", andLegId: "") { error, call in
if error != nil {
// handle error
return
}
// handle call
}
Conversation media:
conversation.reconnectMedia()
Call:
Conversation media: