Receive a Call
This guide covers how to receive a call with the Vonage Client SDK. Before you begin, make sure you added the SDK to your app and (Android, iOS, JS).
NOTE: On iOS it is expected that you use CallKit for incoming and outgoing calls. Please follow the push notification guide.
Receive a Call Invite
In order to receive an incoming in-app call, you should listen for incoming call invites:
To receive an incoming in-app call, listen for the callInvite event:
client.setCallInviteListener { callId, from, channelType ->
// Handling incoming call invite
}
Add the current ViewController, or similar, as a delegate for the voice client:
client.delegate = self
ViewController will now have to conform to VGVoiceClientDelegate, the didReceiveInviteForCall function will be called when there is an incoming call invite. Keep reference to the callId as this will be needed to perform further operations:
extension ViewController: VGVoiceClientDelegate {
func voiceClient(_ client: VGVoiceClient, didReceiveInviteForCall callId: String, from caller: String, withChannelType type: VGVoiceChannelType) {
// Handling incoming callId
}
...
}
Then, you’ll be able to answer or reject the invite.
Answer
client.answer(callID) {
err ->
when {
err != null -> {
// Handle invite answer error
}
else -> {
// Handle active call
}
}
}
client.answer(callID) { error in
if error == nil {
self.callID = callID
} else {
// Handle answer error
}
}
Reject
client.reject(callID) {
err ->
when {
err != null -> {
// Handle inviate reject error
}
}
}
client.reject(callID) { error in
if error != nil {
// Handle invite reject error
}
}
Hang Up
For an on-going call:
client.hangup(callID) {
err ->
when {
err != null -> {
// Handle hang up error
}
}
}
client.hangup(callID) { error in
if error != nil {
// Handle hang up error
}
}
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 leg status events.
To see updates on the state of the call and its members:
client.setOnLegStatusUpdate { callId, legId, status ->
// Call leg updates
}
The didReceiveLegStatusUpdateForCall function will update you on changes to call legs for the active call:
extension ViewController: VGVoiceClientDelegate {
func voiceClient(_ client: VGVoiceClient, didReceiveLegStatusUpdateForCall callId: String, withLegId legId: String, andStatus status: String) {
// Call leg updates
}
...
}