Configurer des notifications d’appel un-à-un et push dans la bibliothèque d’interface utilisateur
La bibliothèque d’interface utilisateur fournit une prise en charge prête à l’emploi pour effectuer des appels un-à-un à l’aide d’identificateurs de participants Azure Communication Services. Pour prendre en charge les appels un-à-un, la bibliothèque d’interface utilisateur fournit des notifications d’appel entrantes. Vous pouvez également utiliser Azure Communication Services comme source d’événements Azure Event Grid pour les appels.
Dans cet article, vous allez apprendre à effectuer des appels un-à-un correctement à l’aide de la bibliothèque d’interface utilisateur dans votre application.
Important
Cette fonctionnalité d’Azure Communication Services est actuellement en préversion.
Ces interfaces de programmation d’applications et kits de développement logiciel (SDK) en préversion sont fournis sans contrat au niveau du service. Nous vous recommandons de ne pas les utiliser pour les charges de travail de production. Certaines fonctionnalités peuvent être limitées ou non prises en charge.
Pour plus d’informations, consultez Conditions d’utilisation supplémentaires relatives aux préversions de Microsoft Azure.
Prérequis
- Compte Azure avec un abonnement actif. Créez un compte gratuitement.
- Une ressource Communication Services déployée. Créez une ressource Communication Services.
- Un jeton d’accès utilisateur pour activer le client d’appel. Obtenez un jeton d’accès utilisateur.
- Facultatif : fin du guide de démarrage rapide pour la prise en main des composites de la bibliothèque d’interface utilisateur.
Configurer les fonctionnalités
Pour plus d’informations, consultez la bibliothèque d’interface utilisateur Android open source et l’exemple de code d’application.
Configurer des autorisations pour les notifications Push
Pour configurer des notifications Push, vous avez besoin d’un compte Firebase avec Firebase Cloud Messaging (FCM) activé. Votre service FCM doit être connecté à une instance Azure Notification Hubs. Pour plus d’informations, consultez notifications Communication Services. Vous devez également utiliser Android Studio version 3.6 ou ultérieure pour générer votre application.
Pour que l’application Android reçoive des messages de notification de FCM, elle a besoin d’un ensemble d’autorisations. Dans votre AndroidManifest.xml
fichier, ajoutez le jeu d’autorisations suivant après l’étiquette ou </application>
la <manifest ...>
balise.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
Inscription aux notifications Push
Pour vous inscrire aux notifications Push, l’application doit appeler registerPushNotification()
sur une instance de CallComposite
avec un jeton d’inscription d’appareil.
Pour obtenir le jeton d’inscription de l’appareil, ajoutez le Kit de développement logiciel (SDK) Firebase à l’instance de votre module d’application build.gradle
. Pour recevoir des notifications de Firebase, intégrez Azure Notification Hubs en suivant les instructions des notifications Communication Services.
Pour éviter les limitations actuelles, vous pouvez ignorer registerPushNotification
à l’aide d’Azure Event Grid pour les notifications Push. Pour plus d’informations, consultez Connecter appeler des notifications Push natives avec Azure Event Grid.
val deviceRegistrationToken = "" // From Firebase
callComposite.registerPushNotification(
applicationContext,
CallCompositePushNotificationOptions(
CommunicationTokenCredential...,
deviceRegistrationToken,
displayName
)
)
Gérer les notifications Push
Pour recevoir des notifications Push pour les appels entrants, appelez handlePushNotification
une CallComposite
instance avec une charge utile.
Pour obtenir la charge utile à partir de FCM, commencez par créer un service (service>de nouveau>> service de fichiers) qui étend la FirebaseMessagingService
classe du Kit de développement logiciel (SDK) Firebase et remplace la onMessageReceived
méthode. Cette méthode est le gestionnaire d’événements appelé lorsque FCM remet la notification Push à l’application.
// On Firebase onMessageReceived
val pushNotificationInfo = CallCompositePushNotificationInfo(remoteMessage.data)
// If pushNotificationInfo.eventType is an incoming call
val remoteOptions = CallCompositeRemoteOptions(
pushNotificationInfo,
communicationTokenCredential,
displayName
)
callComposite.handlePushNotification(
applicationContext,
remoteOptions
)
S’inscrire aux notifications d’appel entrantes
Pour recevoir des notifications d’appel entrantes après handlePushNotification
, abonnez-vous à IncomingCallEvent
et IncomingCallEndEvent
.
private var incomingCallEvent: IncomingCallEvent? = null
private var incomingCallEndEvent: IncomingCallEndEvent? = null
class IncomingCallEndEvent : CallCompositeEventHandler<CallCompositeIncomingCallEndEvent> {
override fun handle(eventArgs: CallCompositeIncomingCallEndEvent?) {
// Display incoming call UI to accept/decline a call
}
}
class IncomingCallEndEvent : CallCompositeEventHandler<CallCompositeIncomingCallEndEvent> {
override fun handle(eventArgs: CallCompositeIncomingCallEndEvent?) {
// Call-ended event when a call is declined or not accepted
}
}
// Event subscription
incomingCallEvent = IncomingCallEvent()
callComposite.addOnIncomingCallEventHandler(incomingCallEvent)
incomingCallEndEvent = IncomingCallEndEvent()
callComposite.addOnIncomingCallEndEventHandler(incomingCallEndEvent)
// Event unsubscribe
callComposite.removeOnIncomingCallEventHandler(incomingCallEvent)
callComposite.removeOnIncomingCallEndEventHandler(incomingCallEndEvent)
Gérer les appels
Pour accepter les appels, passez un appel à acceptIncomingCall
. Pour refuser les appels, effectuez un appel à declineIncomingCall
.
// Accept call
callComposite.acceptIncomingCall(applicationContext, localOptions)
// Decline call
callComposite.declineIncomingCall()
Composer d’autres participants
Pour commencer les appels avec d’autres participants, créez CallCompositeStartCallOptions
avec les ID bruts des participants depuis CommunicationIdentity
et launch
.
val participant = [] // Participant raw IDs
val startCallOption = CallCompositeStartCallOptions(participant)
val remoteOptions = CallCompositeRemoteOptions(startCallOption, communicationTokenCredential, displayName)
callComposite.launch(context, remoteOptions, localOptions)
Intégrer des exemples TelecomManager
Pour intégrer TelecomManager, utilisez les exemples fournis dans la bibliothèque open source. Utiliser CallComposite
des API pour hold
, , mute
resume
et unmute
. Créez CallComposite
avec CallCompositeTelecomIntegration.APPLICATION_IMPLEMENTED_TELECOM_MANAGER
pour pouvoir l’utiliser TelecomManager
dans une application.
Pour plus d’informations, consultez la bibliothèque d’interface utilisateur iOS open source et l’exemple de code d’application.
Configurer des notifications Push
Une notification Push mobile est la notification contextuelle que vous recevez sur un appareil mobile. Pour les appels, cet article se concentre sur les notifications Push voIP (Voice over Internet Protocol).
Les sections suivantes expliquent comment s’inscrire à des notifications Push, les gérer et annuler cette inscription. Avant de démarrer ces tâches, effectuez les prérequis suivants :
- Dans Xcode, accédez à Signing & Capabilities (Signature et fonctionnalités). Ajoutez une fonctionnalité en sélectionnant + Capability (Fonctionnalité), puis Push Notifications (Notifications Push).
- Ajoutez une autre fonctionnalité en sélectionnant + Capability, puis Background Modes (Modes d’arrière-plan).
- Sous Background Modes, cochez les cases Voice over IP (Voix sur IP) et Remote notifications (Notifications distantes).
Inscription aux notifications Push
Pour vous inscrire aux notifications Push, l’application doit appeler registerPushNotification()
sur une instance de CallComposite
avec un jeton d’inscription d’appareil.
Pour éviter les limitations actuelles, vous pouvez ignorer registerPushNotification
à l’aide d’Azure Event Grid pour les notifications Push. Pour plus d’informations, consultez Connecter appeler des notifications Push natives avec Azure Event Grid.
let deviceToken: Data = pushRegistry?.pushToken(for: PKPushType.voIP)
let displayName = "DISPLAY_NAME"
let notificationOptions = CallCompositePushNotificationOptions(
deviceToken: deviceToken,
credential: credential,
displayName: displayName,
callKitOptions: callKitOptions) // CallKit options
try await callComposite.registerPushNotification(notificationOptions: notificationOptions)
Gérer les notifications Push
Pour recevoir les notifications Push relatives aux appels entrants, appelez handlePushNotification()
sur une instance CallComposite
avec une charge utile de dictionnaire.
Lorsque vous utilisez handlePushNotification()
, vous recevez une notification CallKit pour accepter ou refuser des appels.
// App is in the background
let pushNotificationInfo = CallCompositePushNotificationInfo(pushNotificationInfo: dictionaryPayload)
let cxHandle = CXHandle(type: .generic, value: "\(pushNotificationInfo.callId)")
let cxProvider = CallCompositeCallKitOption.getDefaultCXProviderConfiguration()
let remoteInfo = CallCompositeCallKitRemoteInfo(displayName: pushNotificationInfo.fromDisplayName,
cxHandle: cxHandle)
let callKitOptions = CallCompositeCallKitOption(cxProvideConfig: cxProvider,
isCallHoldSupported: true,
remoteInfo: remoteInfo)
CallComposite.reportIncomingCall(callKitOptions: callKitOptions,
callNotification: pushNotificationInfo) { result in
if case .success() = result {
DispatchQueue.global().async {
// Handle push notification
// You don't need to wait for a Communication Services token to handle the push because
// Communication Services commonly receives a callback function to get the token
}
}
}
// App is in the foreground
let pushNotificationInfo = CallCompositePushNotificationInfo(pushNotificationInfo: dictionaryPayload)
let displayName = "display name"
let remoteOptions = RemoteOptions(for: pushNotificationInfo,
credential: credential,
displayName: displayName,
callKitOptions: callKitOptions)
try await callComposite.handlePushNotification(remoteOptions: remoteOptions)
S’inscrire aux notifications d’appel entrantes
Pour recevoir des notifications d’appel entrantes après handlePushNotification
, abonnez-vous à IncomingCallEvent
et IncomingCallEndEvent
.
let onIncomingCall: (CallCompositeIncomingCallInfo) -> Void = { [] _ in
// Incoming call
}
let onIncomingCallEnded: (CallCompositeIncomingCallEndedInfo) -> Void = { [] _ in
// Incoming call ended
}
callComposite.events.onIncomingCall = onIncomingCall
callComposite.events.onIncomingCallEnded = onIncomingCallEnded
Composer d’autres participants
Pour commencer les appels avec d’autres participants, créez CallCompositeStartCallOptions
avec les ID bruts des participants depuis CommunicationIdentity
et launch
.
let startCallOptions = CallCompositeStartCallOptions(participants: <list of participant IDs>)
let remoteOptions = RemoteOptions(for: startCallOptions,
credential: credential,
displayName: "DISPLAY_NAME",
callKitOptions: callKitOptions)
callComposite.launch(remoteOptions: remoteOptions,
localOptions: localOptions)