Make a Call
Overview
This guide covers the functionalities in your Vonage Client application, in order to start in-app or server-managed voice calls.
Before you begin, make sure you added the SDK to your app.
Start an In-App Call
The quickest way to start an in-app call is by conducting an in-app to in-app call, meaning between two users.
val callListener = object: NexmoRequestListener<NexmoCall> {
override fun onSuccess(nexmoCall: NexmoCall?) {
Log.d("TAG", "Call started: ${nexmoCall.toString()}")
}
override fun onError(apiError: NexmoApiError) {
Log.d("TAG", "Error: Unable to start a call ${apiError.message}")
}
}
client.inAppCall("123456", callListener);
The possible voice capabilities are very limited, as this doesn't utilize the Voice API. This method is recommended mostly for onboarding. Later, it is recommended to use a server managed call.
Start a Server Managed Call
This method allows you to conduct in-app calls as well as phone calls while taking advantage of the rich Voice API features.
When your client app calls this method, the answer_url webhook that is configured for your Vonage Application will execute. That defines the logic and capabilities of the call.
On the client side, start the call as such:
val callListener = object: NexmoRequestListener<NexmoCall> {
override fun onSuccess(nexmoCall: NexmoCall?) {
Log.d("TAG", "Call started: ${nexmoCall.toString()}")
}
override fun onError(apiError: NexmoApiError) {
Log.d("TAG", "Error: Unable to start a call ${apiError.message}")
}
}
client.serverCall("123456", null, callListener);
Custom Data
The server call method has a parameter for custom data. This allows you to pass additional context, in a key-value format, to your answer_url webhook server.
val callListener = object: NexmoRequestListener<NexmoCall> {
override fun onSuccess(nexmoCall: NexmoCall?) {
Log.d("TAG", "Call started: ${nexmoCall.toString()}")
}
override fun onError(apiError: NexmoApiError) {
Log.d("TAG", "Error: Unable to start a call ${apiError.message}")
}
}
val customData:HashMap<String, Any> = HashMap<String, Any>()
customData.put("device_name", "Alice app")
client.serverCall("123456", customData, callListener);
The data will be available on the request's query made to your answer_url webhook server:
Listen For Call Events
To see updates on the state of a call, for example, to know if the other member answered or hung up the call, you should listen to call events.
To see updates on the state of the call and its members:
val callEventListener = object : NexmoCallEventListener {
override fun onDTMF(digit: String?, nexmoMember: NexmoMember?) {
Log.d("TAG", "onDTMF(): digit: $digit, nexmoMember: $nexmoMember")
}
override fun onMemberStatusUpdated(memberStatus: NexmoCallMemberStatus?, nexmoMember: NexmoMember?) {
Log.d("TAG", "onMemberStatusUpdated(): status: $memberStatus, nexmoMember: $nexmoMember")
}
override fun onMuteChanged(muteState: NexmoMediaActionState?, nexmoMember: NexmoMember?) {
Log.d("TAG", ":NexmoMediaActionState(): muteState: $muteState, nexmoMember: $nexmoMember")
}
override fun onEarmuffChanged(earmuffState: NexmoMediaActionState?, nexmoMember: NexmoMember?) {
Log.d("TAG", "onEarmuffChanged(): earmuffState: $earmuffState, nexmoMember: $nexmoMember")
}
}
nexmoCall?.addCallEventListener(callEventListener)
Remove the listener when needed:
nexmoCall?.removeCallEventListener(callEventListener)
Remove the listener when needed:
Add the current ViewController, or similar, as a delegate for the call object returned when making a call:
ViewController will now have to conform to NXMCallDelegate:
Add the current ViewController, or similar, as a delegate for the call object returned when making a call:
ViewController will now have to conform to NXMCallDelegate: