fun createCallAgent()

in azure-communication-ui/calling/src/main/java/com/azure/android/communication/ui/calling/service/sdk/CallingSDKInitializer.kt [102:141]


    fun createCallAgent(): CompletableFuture<CallAgent> {
        if (callAgentCompletableFuture == null || callAgentCompletableFuture!!.isCompletedExceptionally) {
            callAgentCompletableFuture = CompletableFuture<CallAgent>()
            val options = CallAgentOptions()
            callCompositeConfiguration.displayName?.let { options.displayName = it }
            callCompositeConfiguration.telecomManagerOptions?.let {
                if (it.telecomManagerIntegrationMode == CallCompositeTelecomManagerIntegrationMode.SDK_PROVIDED_TELECOM_MANAGER) {
                    options.telecomManagerOptions = TelecomManagerOptions(it.phoneAccountId)
                }
            }
            options.setDisableInternalPushForIncomingCall(callCompositeConfiguration.disableInternalPushForIncomingCall)

            try {
                setupCallClient()?.whenComplete { callClient, callAgentError ->
                    if (callAgentError != null) {
                        throw CallCompositeException("Failed to create call agent", callAgentError)
                    }
                    val createCallAgentFutureCompletableFuture = callClient.createCallAgent(
                        callCompositeConfiguration.applicationContext,
                        callCompositeConfiguration.credential,
                        options
                    )
                    logger.info("creating call agent")
                    createCallAgentFutureCompletableFuture.whenComplete { callAgent, error ->
                        if (error != null) {
                            callAgentCompletableFuture!!.completeExceptionally(error)
                        } else {
                            callAgentCompletableFuture!!.complete(callAgent)

                            callAgent.addOnIncomingCallListener(callCompositeIncomingCallListener)
                        }
                    }
                }
            } catch (error: Throwable) {
                callAgentCompletableFuture!!.completeExceptionally(error)
            }
        }

        return callAgentCompletableFuture!!
    }