func createCallComposite()

in AzureCommunicationUI/AzureCommunicationUIDemoApp/Sources/Views/CallingDemoViewController.swift [217:301]


    func createCallComposite() async -> CallComposite? {
        print("CallingDemoView:::: createCallComposite requesting")
        if GlobalCompositeManager.callComposite != nil {
            print("CallingDemoView:::: createCallComposite exist")
            return GlobalCompositeManager.callComposite!
        }
        print("CallingDemoView:::: createCallComposite creating")
        var localizationConfig: LocalizationOptions?
        let layoutDirection: LayoutDirection = envConfigSubject.isRightToLeft ? .rightToLeft : .leftToRight
        let barOptions = CallScreenControlBarOptions(leaveCallConfirmationMode:
                                                        envConfigSubject.displayLeaveCallConfirmation ?
            .alwaysEnabled : .alwaysDisabled)
        if !envConfigSubject.localeIdentifier.isEmpty {
            let locale = Locale(identifier: envConfigSubject.localeIdentifier)
            localizationConfig = LocalizationOptions(locale: locale,
                                                           layoutDirection: layoutDirection)
        } else if !envConfigSubject.locale.identifier.isEmpty {
            localizationConfig = LocalizationOptions(
                locale: envConfigSubject.locale,
                layoutDirection: layoutDirection)
        }
        var callScreenOptions = CallScreenOptions(controlBarOptions: barOptions
                                                  , headerViewData: CallScreenHeaderViewData(
                                                    title: "This is a custom header",
                                                    subtitle: "This is a custom subtitle")
                                                 )
        let setupViewOrientation = envConfigSubject.setupViewOrientation
        let setupScreenOptions = SetupScreenOptions(
            cameraButtonEnabled: envConfigSubject.setupScreenOptionsCameraButtonEnabled,
            microphoneButtonEnabled: envConfigSubject.setupScreenOptionsMicButtonEnabled)
        let callingViewOrientation = envConfigSubject.callingViewOrientation
        let callKitOptions = envConfigSubject.enableCallKit ? getCallKitOptions() : nil
        let userId = CommunicationUserIdentifier(envConfigSubject.userId)

        let callCompositeOptions = envConfigSubject.useDeprecatedLaunch ? CallCompositeOptions(
            theme: envConfigSubject.useCustomColors
            ? CustomColorTheming(envConfigSubject: envConfigSubject)
            : Theming(envConfigSubject: envConfigSubject),
            localization: localizationConfig,
            setupScreenOrientation: setupViewOrientation,
            callingScreenOrientation: callingViewOrientation,
            enableMultitasking: envConfigSubject.enableMultitasking,
            enableSystemPictureInPictureWhenMultitasking: envConfigSubject.enablePipWhenMultitasking,
            callScreenOptions: callScreenOptions,
            callKitOptions: callKitOptions,
            setupScreenOptions: setupScreenOptions) :
        CallCompositeOptions(
            theme: envConfigSubject.useCustomColors
            ? CustomColorTheming(envConfigSubject: envConfigSubject)
            : Theming(envConfigSubject: envConfigSubject),
            localization: localizationConfig,
            setupScreenOrientation: setupViewOrientation,
            callingScreenOrientation: callingViewOrientation,
            enableMultitasking: envConfigSubject.enableMultitasking,
            enableSystemPictureInPictureWhenMultitasking: envConfigSubject.enablePipWhenMultitasking,
            callScreenOptions: callScreenOptions,
            callKitOptions: callKitOptions,
            displayName: envConfigSubject.displayName,
            disableInternalPushForIncomingCall: envConfigSubject.disableInternalPushForIncomingCall,
            setupScreenOptions: setupScreenOptions)

        let useMockCallingSDKHandler = envConfigSubject.useMockCallingSDKHandler
        if let credential = try? await getTokenCredential() {
            #if DEBUG
            let callComposite = useMockCallingSDKHandler ?
                CallComposite(withOptions: callCompositeOptions,
                              callingSDKWrapperProtocol: callingSDKWrapperMock)
            : ( envConfigSubject.useDeprecatedLaunch ?
                CallComposite(withOptions: callCompositeOptions) :
                    CallComposite(credential: credential, withOptions: callCompositeOptions))

            callingSDKWrapperMock?.callComposite = callComposite

            #else
            let callComposite = envConfigSubject.useDeprecatedLaunch ?
            CallComposite(withOptions: callCompositeOptions) :
                CallComposite(credential: credential, withOptions: callCompositeOptions)
            #endif
            subscribeToEvents(callComposite: callComposite)
            GlobalCompositeManager.callComposite = callComposite
            self.envConfigSubject.saveFromState()
            return callComposite
        }
        return nil
    }