in AzureCommunicationUI/AzureCommunicationUIDemoApp/Sources/Views/CallingDemoView.swift [518:625]
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
}
onError(error,
callComposite: composite)
}
let onPipChangedHandler: (Bool) -> Void = { isPictureInPicture in
print("::::CallingDemoView:onPipChangedHandler: ", isPictureInPicture)
}
let onUserReportedIssueHandler: (CallCompositeUserReportedIssue) -> Void = { issue in
DispatchQueue.main.schedule {
self.issue = issue
}
sendSupportEventToServer(event: issue) { success, result in
if success {
self.issueUrl = result
} else {
self.issueUrl = ""
}
}
}
let onCallStateChangedHandler: (CallState) -> Void = { [weak callComposite] callStateEvent in
guard let composite = callComposite else {
return
}
onCallStateChanged(callStateEvent,
callComposite: composite)
}
let onDismissedHandler: (CallCompositeDismissed) -> Void = { [] _ in
if envConfigSubject.useRelaunchOnDismissedToggle && exitCompositeExecuted {
relaunchComposite()
}
isCallActive = false // Re-enable button when call ends
print("::::CallingDemoView::onDismissedHandler")
}
exitCompositeExecuted = false
if !envConfigSubject.exitCompositeAfterDuration.isEmpty {
DispatchQueue.main.asyncAfter(deadline: .now() +
Float64(envConfigSubject.exitCompositeAfterDuration)!
) { [weak callComposite] in
exitCompositeExecuted = true
callComposite?.dismiss()
}
}
let callKitCallAccepted: (String) -> Void = { [weak callComposite] callId in
isIncomingCall = false
callComposite?.launch(callIdAcceptedFromCallKit: callId, localOptions: getLocalOptions())
}
let onIncomingCall: (IncomingCall) -> Void = { [] incomingCall in
incomingCallId = incomingCall.callId
isIncomingCall = true
print("::::CallingDemoView::onIncomingCall \(incomingCall.callId)")
}
let onIncomingCallCancelled: (IncomingCallCancelled) -> Void = { [] event in
isIncomingCall = false
print("::::CallingDemoView::onIncomingCallCancelled \(event.callId)")
showAlert(for: "\(event.callId) cancelled")
}
let onRemoteParticipantLeftHandler: ([CommunicationIdentifier]) -> Void = { [weak callComposite] ids in
guard let composite = callComposite else {
return
}
self.onRemoteParticipantLeft(to: composite,
identifiers: ids)
}
/* <CALL_START_TIME>
let onCallStartTimeUpdated: (Date) -> Void = { [] startTime in
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.timeZone = TimeZone.current
let systemTimeZoneDateString = dateFormatter.string(from: startTime)
print("::::CallingDemoView startTime event call start time \(systemTimeZoneDateString)")
}
</CALL_START_TIME> */
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
callComposite.events.onRemoteParticipantLeft = onRemoteParticipantLeftHandler
/* <CALL_START_TIME>
callComposite.events.onCallStartTimeUpdated = onCallStartTimeUpdated
</CALL_START_TIME> */
}