Recevoir un appel
Ce guide explique comment recevoir un appel avec le Vonage Client SDK. Avant de commencer, assurez-vous d'avoir ajouté le SDK à votre application et (Android, iOS, JS).
NOTE : Sur iOS, il est prévu que vous utilisiez CallKit pour les appels entrants et sortants. Veuillez suivre les instructions de guide de la notification push.
Recevoir une invitation à téléphoner
Pour recevoir un appel entrant in-app, vous devez écouter les invitations à recevoir des appels :
Pour recevoir un appel entrant in-app, écoutez la tonalité callInvite événement :
// After creating a session
client.on("callInvite", (callId, from, channelType) => {
// Answer / Reject Call
console.log( { callId, from, channelType } );
});
client.setCallInviteListener { callId, from, channelType ->
// Handling incoming call invite
}
Ajouter le ViewControllerou similaire, en tant que délégué du client vocal :
client.delegate = self
ViewController devront désormais se conformer à la VGVoiceClientDelegate, le didReceiveInviteForCall sera appelée en cas d'appel entrant. Gardez une référence à la fonction callId car elle sera nécessaire pour effectuer d'autres opérations :
extension ViewController: VGVoiceClientDelegate {
func voiceClient(_ client: VGVoiceClient, didReceiveInviteForCall callId: String, from caller: String, withChannelType type: VGVoiceChannelType) {
// Handling incoming callId
}
...
}
Vous pourrez alors répondre à l'invitation ou la rejeter.
Réponse
// After creating a session
client.answer(callId)
.then(() => {
console.log("Success answering call.");
})
.catch(error => {
console.error("Error answering call: ", error);
});
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
}
}
Rejeter
// After creating a session
client.reject(callId)
.then(() => {
console.log("Success rejecting call.");
})
.catch(error => {
console.error("Error rejecting call: ", error);
});
client.reject(callID) {
err ->
when {
err != null -> {
// Handle inviate reject error
}
}
}
client.reject(callID) { error in
if error != nil {
// Handle invite reject error
}
}
Raccrocher
Pour un call:
// After creating a session
client.hangup(callId)
.then(() => {
console.log("Success hanging up call.");
})
.catch(error => {
console.error("Error hanging up call: ", error);
});
client.hangup(callID) {
err ->
when {
err != null -> {
// Handle hang up error
}
}
}
client.hangup(callID) { error in
if error != nil {
// Handle hang up error
}
}
Écouter les événements de l'appel
Pour connaître l'état d'un appel, par exemple pour savoir si l'autre membre a répondu ou raccroché, vous devez écouter les événements relatifs à l'état des segments.
Pour voir les mises à jour sur l'état de l'appel et de ses membres :
// After creating a session
client.on("legStatusUpdate", (callId, legId, status) => {
console.log({callId, legId, status});
});
client.setOnLegStatusUpdate { callId, legId, status ->
// Call leg updates
}
Les didReceiveLegStatusUpdateForCall vous informera des modifications apportées aux segments d'appel de l'appel actif :
extension ViewController: VGVoiceClientDelegate {
func voiceClient(_ client: VGVoiceClient, didReceiveLegStatusUpdateForCall callId: String, withLegId legId: String, andStatus status: String) {
// Call leg updates
}
...
}