次の方法で共有


UI ライブラリで 1 対 1 の呼び出しとプッシュ通知を設定する

UI ライブラリでは、Azure Communication Services 参加要素識別子を使用して 1 対 1 の呼び出しを行うために、すぐに使用できるサポートが提供されます。 一対一の呼び出しをサポートするために、UI ライブラリは着信呼び出し通知を提供します。 呼び出しの Azure Event Grid イベント ソースとして Azure Communication Services を使用することもできます。

この記事では、アプリケーションで UI ライブラリを使用して、1 対 1 の呼び出しを正しく行う方法について説明します。

重要

Azure Communication Services のこの機能は、現在プレビュー段階にあります。

プレビューの API と SDK は、サービス レベル アグリーメントなしに提供されます。 運用環境のワークロードには使用しないことをお勧めします。 一部の機能はサポート対象ではなく、機能が制限されることがあります。

詳細については、「Microsoft Azure プレビューの追加利用規約」を確認してください。

前提条件

機能を設定する

詳細については、オープンソースの Android UI ライブラリとサンプル アプリケーション コード参照してください。

プッシュ通知のアクセス許可を設定する

プッシュ通知を設定するには、Firebase Cloud Messaging (FCM) が有効になっている Firebase アカウントが必要です。 FCM サービスは、Azure Notification Hubs インスタンスに接続されている必要があります。 詳細については、「Communication Services の通知」を参照してください。 また、Android Studio バージョン 3.6 以降を使用してアプリケーションをビルドする必要があります。

Android アプリケーションが FCM から通知メッセージを受信するには、一連のアクセス許可が必要です。 ファイルでAndroidManifest.xml、または</application>タグの後に次のアクセス許可のセットを<manifest ...>追加します。

<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" />

プッシュ通知に登録する

プッシュ通知を登録するには、アプリケーションは、デバイス登録トークンを使用して CallComposite インスタンスの registerPushNotification() を呼び出す必要があります。

デバイス登録トークンを取得するには、Firebase SDK をアプリケーション モジュールの build.gradle インスタンスに追加します。 Firebase から通知を受信するには、Communication Services 通知の手順 に従って Azure Notification Hubs を統合します

現在の制限を回避するために、プッシュ通知に Azure Event Grid を使用してスキップ registerPushNotification できます。 詳細については、「Azure Event Grid を使用してネイティブ プッシュ通知を呼び出す接続」を参照してください

    val deviceRegistrationToken = "" // From Firebase
    callComposite.registerPushNotification(
        applicationContext,
        CallCompositePushNotificationOptions(
            CommunicationTokenCredential...,
            deviceRegistrationToken,
            displayName
        )
    )

プッシュ通知を処理する

着信呼び出しのプッシュ通知を受信するには、ペイロードを持つインスタンスをCallComposite呼び出handlePushNotificationします。

FCM からペイロードを取得するには、まず、Firebase SDK クラスを拡張してメソッドをオーバーライドonMessageReceivedする新しいサービス (File>New>Service>Service) を作成します。FirebaseMessagingService このメソッドは、FCM がアプリケーションにプッシュ通知を配信するときに呼び出されるイベント ハンドラーです。

    // 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
        )

着信通話通知に登録する

handlePushNotificationに着信通話通知を受信するには、サブスクライブしてIncomingCallEndEventIncomingCallEvent.

    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)

呼び出しを処理する

呼び出しを受け入れるには、次の呼び出しを行 acceptIncomingCallいます。 通話を拒否するには、次の呼び出し declineIncomingCallを行います。

// Accept call
callComposite.acceptIncomingCall(applicationContext, localOptions)

// Decline call
callComposite.declineIncomingCall()

他の参加者にダイヤルする

他の参加者との通話を開始するには、参加者の生 ID CommunicationIdentity を使用して作成CallCompositeStartCallOptionsしますlaunch

    val participant = [] // Participant raw IDs
    val startCallOption = CallCompositeStartCallOptions(participant)
    val remoteOptions = CallCompositeRemoteOptions(startCallOption, communicationTokenCredential, displayName)
    callComposite.launch(context, remoteOptions, localOptions)

TelecomManager のサンプルを統合する

TelecomManager を統合するには、オープンソース ライブラリで提供されているサンプルを使用します。 、および < a0/resume& unmutemuteの API をhold使用CallCompositeします。 アプリケーションでCallCompositeTelecomIntegration.APPLICATION_IMPLEMENTED_TELECOM_MANAGER使用TelecomManagerする with を作成CallCompositeします。

callComposite.hold()
callComposite.resume()
callComposite.mute()
callComposite.unmute()

詳細については、オープンソースの iOS UI ライブラリとサンプル アプリケーション コード参照してください。

プッシュ通知の設定

モバイル プッシュ通知は、モバイル デバイスで受け取るポップアップ通知です。 この記事では、通話について、ボイス オーバー インターネット プロトコル (VoIP) プッシュ通知に焦点を当てています。

以下のセクションでは、プッシュ通知の登録、処理、および登録解除を行う方法について説明します。 これらの作業を開始する前に、次の前提条件を満たす必要があります。

  1. Xcode で、[Signing & Capabilities]\(署名と機能\) に移動します。 [+ Capability]\(+ 機能\) を選択して機能を追加してから、[プッシュ通知] を選択します。
  2. [+ Capability]\(+ 機能\) を選択して別の機能を追加してから、[バックグラウンド モード] を選びます。
  3. [バックグラウンド モード] で、[ボイス オーバー IP][リモート通知] のチェックボックスをオンにします。

プッシュ通知に登録する

プッシュ通知を登録するには、アプリケーションは、デバイス登録トークンを使用して CallComposite インスタンスの registerPushNotification() を呼び出す必要があります。

現在の制限を回避するために、プッシュ通知に Azure Event Grid を使用してスキップ registerPushNotification できます。 詳細については、「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)

プッシュ通知を処理する

着信通話のプッシュ通知を受信するには、ディクショナリ ペイロードを設定して CallComposite インスタンスで handlePushNotification() を呼び出します。

使用 handlePushNotification()すると、通話を承諾または拒否するための CallKit 通知が表示されます。

    // 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)

着信通話通知に登録する

handlePushNotificationに着信通話通知を受信するには、サブスクライブしてIncomingCallEndEventIncomingCallEvent.

    let onIncomingCall: (CallCompositeIncomingCallInfo) -> Void = { [] _ in
        // Incoming call
    }
    let onIncomingCallEnded: (CallCompositeIncomingCallEndedInfo) -> Void = { [] _ in
        // Incoming call ended
    }

    callComposite.events.onIncomingCall = onIncomingCall
    callComposite.events.onIncomingCallEnded = onIncomingCallEnded

他の参加者にダイヤルする

他の参加者との通話を開始するには、参加者の生 ID CommunicationIdentity を使用して作成CallCompositeStartCallOptionsします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)

次のステップ