func subscribeToEvents()

in AzureCommunicationUI/AzureCommunicationUIDemoApp/Sources/Views/CallingDemoViewController.swift [332:414]


    func subscribeToEvents(callComposite: CallComposite) {
        let onRemoteParticipantJoinedHandler: ([CommunicationIdentifier]) -> Void = { [weak callComposite] ids in
            guard let composite = callComposite else {
                return
            }
            self.onRemoteParticipantJoined(to: composite,
                                           identifiers: ids)
        }
        let onErrorHandler: (CallCompositeError) -> Void = { [weak callComposite] error in
            guard let composite = callComposite else {
                return
            }
            self.onError(error,
                    callComposite: composite)
        }

        let onPipChangedHandler: (Bool) -> Void = { isPictureInPicture in
            print("::::CallingDemoView:onPipChangedHandler: ", isPictureInPicture)
        }

        let onUserReportedIssueHandler: (CallCompositeUserReportedIssue) -> Void = { issue in
            print("::::UIKitDemoView::getEventsHandler::onUserReportedIssue \(issue)")
        }

        let onCallStateChangedHandler: (CallState) -> Void = { [weak callComposite] callStateEvent in
            guard let composite = callComposite else {
                return
            }
            self.onCallStateChanged(callStateEvent,
                    callComposite: composite)
        }
        let onDismissedHandler: (CallCompositeDismissed) -> Void = { [] _ in
            if self.envConfigSubject.useRelaunchOnDismissedToggle && self.exitCompositeExecuted {
                            DispatchQueue.main.async {
                                Task { @MainActor in
                                    self.onStartExperienceBtnPressed()
                                }
                            }
                        }
        }

        exitCompositeExecuted = false
        if !envConfigSubject.exitCompositeAfterDuration.isEmpty {
            DispatchQueue.main.asyncAfter(deadline: .now() +
                                          Float64(envConfigSubject.exitCompositeAfterDuration)!
            ) { [weak callComposite] in
                self.exitCompositeExecuted = true
                callComposite?.dismiss()
            }
        }

        let callKitCallAccepted: (String) -> Void = { [weak callComposite] callId in
            self.acceptCallButton.isHidden = true
            self.declineCallButton.isHidden = true
            guard let callComposite = callComposite else {
                return
            }
            callComposite.launch(callIdAcceptedFromCallKit: callId, localOptions: self.getLocalOptions(callComposite))
        }

        let onIncomingCall: (IncomingCall) -> Void = { [] incomingCall in
            self.incomingCallId = incomingCall.callId
            self.isIncomingCall = true
            self.acceptCallButton.isHidden = false
            self.declineCallButton.isHidden = false
        }

        let onIncomingCallCancelled: (IncomingCallCancelled) -> Void = { [] _ in
            self.isIncomingCall = false
            self.acceptCallButton.isHidden = true
            self.declineCallButton.isHidden = true
        }

        callComposite.events.onRemoteParticipantJoined = onRemoteParticipantJoinedHandler
        callComposite.events.onError = onErrorHandler
        callComposite.events.onCallStateChanged = onCallStateChangedHandler
        callComposite.events.onDismissed = onDismissedHandler
        callComposite.events.onPictureInPictureChanged = onPipChangedHandler
        callComposite.events.onUserReportedIssue = onUserReportedIssueHandler
        callComposite.events.onIncomingCallAcceptedFromCallKit = callKitCallAccepted
        callComposite.events.onIncomingCall = onIncomingCall
        callComposite.events.onIncomingCallCancelled = onIncomingCallCancelled
    }