다음을 통해 공유


UI 라이브러리에서 일대일 통화 및 푸시 알림 설정

UI 라이브러리는 Azure Communication Services 참가자 식별자를 사용하여 일대일 통화를 수행하기 위한 기본 지원을 제공합니다. 일대일 통화를 지원하기 위해 UI 라이브러리는 수신 전화 알림을 제공합니다. 통화용 Azure Event Grid 이벤트 원본으로 Azure Communication Services를 사용할 수도 있습니다.

이 문서에서는 애플리케이션에서 UI 라이브러리를 사용하여 일대일 통화를 올바르게 수행하는 방법을 알아봅니다.

필수 조건

기능 설정

자세한 내용은 오픈 소스 Android UI 라이브러리샘플 애플리케이션 코드를 참조하세요.

푸시 알림에 대한 권한 설정

푸시 알림을 설정하려면 FCM(Firebase 클라우드 메시지)을 사용하도록 설정된 Firebase 계정이 필요합니다. FCM 서비스는 Azure Notification Hubs 인스턴스에 연결되어야 합니다. 자세한 내용은 Communication Services 알림을 참조하세요. 또한 Android Studio 버전 3.6 이상을 사용하여 애플리케이션을 빌드해야 합니다.

Android 애플리케이션이 FCM에서 알림 메시지를 받으려면 사용 권한 집합이 필요합니다. AndroidManifest.xml 파일에서 <manifest ...> 또는 </application> 태그 뒤에 다음 권한 세트를 추가합니다.

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

모바일 앱에 수신 알림 추가

Azure Communication Services는 Azure Event GridAzure Notification Hubs와 통합되므로 Azure의 앱에 푸시 알림을 추가할 수 있습니다.

알림 허브 푸시 알림 등록/등록 취소

푸시 알림을 등록하려면 애플리케이션이 디바이스 등록 토큰을 사용하여 CallComposite 인스턴스에서 registerPushNotification()을 호출해야 합니다.

디바이스 등록 토큰을 가져오려면 애플리케이션 모듈의 build.gradle 인스턴스에 Firebase SDK를 추가합니다. Firebase에서 알림을 받으려면 Communication Services 알림의 지침에 따라 Azure Notification Hubs를 통합합니다.

    val deviceRegistrationToken = "" // From Firebase
    callComposite.registerPushNotification(deviceRegistrationToken).whenComplete { _, throwable ->
        if (throwable != null) {
            // Handle error
        }
    }

Event Grid 또는 알림 허브에서 받은 푸시 알림 처리

수신 전화에 대한 푸시 알림을 받으려면 페이로드를 사용하여 CallComposite 인스턴스에서 handlePushNotification을 호출합니다.

FCM에서 페이로드를 얻으려면, 우선 FirebaseMessagingService Firebase SDK 클래스를 확장하고 onMessageReceived 메서드를 재정의하는 새 서비스(파일>새로 만들기>서비스>서비스)부터 만듭니다. 이 메서드는 FCM이 애플리케이션에 푸시 알림을 전달할 때 호출되는 이벤트 처리기입니다.

    // On Firebase onMessageReceived
    val pushNotification = CallCompositePushNotification(remoteMessage.data)
    callComposite.handlePushNotification(pushNotification).whenComplete { _, throwable ->
        if (throwable != null) {
            // Handle error
        }
    }

수신 통화 알림 등록

handlePushNotification 후에 들어오는 통화 알림을 수신하려면 CallCompositeIncomingCallEventCallCompositeIncomingCallCancelledEvent를 구독합니다. CallCompositeIncomingCallEvent에는 수신 callId 및 발신자 정보가 포함되어 있습니다. CallCompositeIncomingCallCancelledEvent에는 callId 및 통화 취소 코드 Azure Communication Services 문제 해결이 포함되어 있습니다.

    private var incomingCallEvent: IncomingCallEvent? = null
    private var incomingCallCancelledEvent: IncomingCallCancelledEvent? = null

    class IncomingCallEvent : CallCompositeEventHandler<CallCompositeIncomingCallEvent> {
        override fun handle(eventArgs: CallCompositeIncomingCallEvent?) {
            // Display incoming call UI to accept/decline a call
            // CallCompositeIncomingCallEvent contains call id and caller information
        }
    }

    class IncomingCallCancelledEvent : CallCompositeEventHandler<CallCompositeIncomingCallCancelledEvent> {
        override fun handle(eventArgs: CallCompositeIncomingCallCancelledEvent?) {
            // Call-ended event when a call is declined or not accepted
        }
    }

    // Event subscription
    incomingCallEvent = IncomingCallEvent()
    callComposite.addOnIncomingCallEventHandler(incomingCallEvent)

    incomingCallCancelledEvent = IncomingCallCancelledEvent()
    callComposite.addOnIncomingCallCancelledEventHandler(incomingCallEndEvent)

    // Event unsubscribe
    callComposite.removeOnIncomingCallEventHandler(incomingCallEvent)
    callComposite.removeOnIncomingCallCancelledEventHandler(incomingCallEndEvent)

통화 처리

통화를 수락하려면 accept을 호출합니다. 통화를 거절하려면 reject을 호출합니다.

// Accept call
callComposite.accept(applicationContext, incomingCallId, localOptions)

// Decline call
callComposite.reject(incomingCallId)

다른 참가자에게 전화 걸기

다른 참가자와 통화를 시작하려면, CommunicationIdentitylaunch에서 참가자의 원시 ID를 이용해 CallCompositeStartCallOptions를 만듭니다.

    val participants: List<CommunicationIdentifier> // participants to dial
    callComposite.launch(context, participants, localOptions)

자세한 내용은 오픈 소스 iOS UI 라이브러리샘플 애플리케이션 코드를 참조하세요.

푸시 알림 설정

모바일 푸시 알림은 모바일 디바이스에 표시되는 팝업 알림입니다. 이 문서에서는 VoIP(Voice over Internet Protocol) 푸시 알림에 중점을 둡니다.

다음 섹션에서는 푸시 알림을 등록, 처리 및 등록 취소하는 방법을 설명합니다. 이러한 작업을 시작하기 전에 다음 필수 조건을 완료해야 합니다.

  1. Xcode에서 서명 및 기능으로 이동합니다. + 기능을 선택하여 기능을 추가한 다음, 푸시 알림을 선택합니다.
  2. + 기능을 선택하여 다른 기능을 추가한 다음, 백그라운드 모드를 선택합니다.
  3. 백그라운드 모드에서 Voice over IP원격 알림 확인란을 선택합니다.

모바일 앱에 수신 알림 추가

Azure Communication Services는 Azure Event GridAzure Notification Hubs와 통합되므로 Azure의 앱에 푸시 알림을 추가할 수 있습니다.

알림 허브 푸시 알림 등록/등록 취소

푸시 알림을 등록하려면 애플리케이션이 디바이스 등록 토큰을 사용하여 CallComposite 인스턴스에서 registerPushNotifications()을 호출해야 합니다.

    // to register
    let deviceToken: Data = pushRegistry?.pushToken(for: PKPushType.voIP)
    callComposite.registerPushNotifications(
        deviceRegistrationToken: deviceToken) { result in
        switch result {
            case .success:
                // success
            case .failure(let error):
                // failure
        }
    }

    // to unregister
    callComposite.unregisterPushNotification()

Event Grid 또는 알림 허브에서 받은 푸시 알림 처리

수신 전화에 대한 푸시 알림을 받으려면 사전 페이로드를 사용하여 CallComposite 인스턴스에서 handlePushNotification()을 호출합니다.

handlePushNotification()을 사용하고 CallKit 옵션이 설정되면 통화를 수락하거나 거부하라는 CallKit 알림을 받게 됩니다.

    // App is in the background
    // push notification contains from/to communication identifiers and event type
    let pushNotification = PushNotification(data: payload.dictionaryPayload)
    let callKitOptions = CallKitOptions(...//CallKit options)
    CallComposite.reportIncomingCall(pushNotification: pushNotification,
                                    callKitOptions: callKitOptions) { result in
        if case .success() = result {
            DispatchQueue.global().async {
                // You don't need to wait for a Communication Services token to handle the push because 
                // Communication Services common receives a callback function to get the token with refresh options
                // create call composite and handle push notification
                callComposite.handlePushNotification(pushNotification: pushNotification)
            }
        }
    }

    // App is in the foreground
    let pushNotification = PushNotification(data: dictionaryPayload)
    callComposite.handlePushNotification(pushNotification: pushNotification) { result in
        switch result {
            case .success:
                // success
            case .failure(let error):
                // failure
        }
    }

핸들 푸시 시 수신 전화 알림 등록

handlePushNotification 후에 들어오는 통화 알림을 수신하려면 onIncomingCallonIncomingCallCancelled를 구독합니다. IncomingCall에는 수신 callId 및 발신자 정보가 포함되어 있습니다. IncomingCallCancelled에는 callId 및 통화 취소 코드 Azure Communication Services 문제 해결이 포함되어 있습니다.

    let onIncomingCall: (IncomingCall) -> Void = { [] incomingCall in
        // Incoming call id and caller info
    }
    let onIncomingCallEnded: (IncomingCallCancelled) -> Void = { [] incomingCallCancelled in
        // Incoming call cancelled code with callId
    }
    callComposite.events.onIncomingCall = onIncomingCall
    callComposite.events.onIncomingCallEnded = onIncomingCallEnded

수신 전화에 대한 내부 푸시 사용 안 함

EventGridAPNS에서만 푸시 알림을 받으려면 CallCompositeOptions에서 disableInternalPushForIncomingCall을 true로 설정합니다. disableInternalPushForIncomingCall이 true인 경우 handlePushNotification이 호출될 때만 UI 라이브러리의 푸시 알림 이벤트가 수신됩니다. disableInternalPushForIncomingCall 옵션은 포그라운드 모드에서 CallComposite의 알림 수신을 중지하는 데 도움이 됩니다. 이 설정은 EventGridNotificationHub 설정을 제어하지 않습니다.

    let options = CallCompositeOptions(disableInternalPushForIncomingCall: true)

SDK CallKit 호출에서 수락된 수신 전화에 대해 복합 시작

Azure Communication Services 통화 iOS SDK는 CallKit 통합을 지원합니다. CallCompositeCallKitOption 인스턴스를 구성하여 UI 라이브러리에서 이 통합을 사용하도록 설정할 수 있습니다. 자세한 내용은 CallKit과 통합을 참조하세요.

SDK 호출의 CallKit이 사용하도록 설정된 경우 onIncomingCallAcceptedFromCallKit를 구독합니다. 통화가 수락되면 통화 ID로 callComposite를 시작합니다.

    let onIncomingCallAcceptedFromCallKit: (callId) -> Void = { [] callId in
        // Incoming call accepted call id
    }
    
    callComposite.events.onIncomingCallAcceptedFromCallKit = onIncomingCallAcceptedFromCallKit

    // launch composite with/without local options
    // Note: as call is already accepted, setup screen will not be displayed
    callComposite.launch(callIdAcceptedFromCallKit: callId)

CallComposite로 통화 처리

통화를 수락하려면 accept을 호출합니다. 통화를 거절하려면 reject을 호출합니다.

// Accept call
callComposite.accept(incomingCallId, 
                     ... // CallKit and local options
                     )

// Decline call
callComposite.reject(incomingCallId)

다른 참가자에게 전화 걸기

다른 참가자와 통화를 시작하려면 참가자의 CommunicationIdentifier 목록으로 callComposite를 시작합니다.

    // [CommunicationIdentifier]
    // use createCommunicationIdentifier(fromRawId: "raw id")
    callComposite.launch(participants: <list of CommunicationIdentifier>,
                         localOptions: localOptions)

다음 단계