Skip to content

Commit

Permalink
Improve UX when answering EL-Call through the notification (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 authored Jun 24, 2024
1 parent 3465ea4 commit fa22b98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
18 changes: 10 additions & 8 deletions ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg

registerBackgroundAppRefresh()

elementCallService.actions.sink { [weak self] action in
switch action {
case .answerCall(let roomID):
self?.handleAppRoute(.call(roomID: roomID))
case .declineCall:
break
elementCallService.actions
.receive(on: DispatchQueue.main)
.sink { [weak self] action in
switch action {
case .answerCall(let roomID):
self?.handleAppRoute(.call(roomID: roomID))
case .declineCall:
break
}
}
}
.store(in: &cancellables)
.store(in: &cancellables)
}

func start() {
Expand Down
13 changes: 11 additions & 2 deletions ElementX/Sources/Services/ElementCall/ElementCallService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe

private var incomingCallRoomID: String?

private var endUnansweredCallTask: Task<Void, Never>?

private let actionsSubject: PassthroughSubject<ElementCallServiceAction, Never> = .init()
var actions: AnyPublisher<ElementCallServiceAction, Never> {
actionsSubject.eraseToAnyPublisher()
Expand All @@ -48,7 +50,7 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
guard ongoingCallID == nil else {
return
}

let callID = UUID()
ongoingCallID = callID

Expand Down Expand Up @@ -103,6 +105,8 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
let configuration = CXProviderConfiguration()
configuration.supportsVideo = true
configuration.includesCallsInRecents = true
// Provide image icon if available
configuration.iconTemplateImageData = nil

// https://stackoverflow.com/a/46077628/730924
configuration.supportedHandleTypes = [.generic]
Expand All @@ -125,8 +129,12 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
completion()
}

Task { [weak self, callProvider, callID] in
endUnansweredCallTask = Task { [weak self, callProvider, callID] in
try? await Task.sleep(for: .seconds(15))
guard !Task.isCancelled else {
return
}

if let ongoingCallID = self?.ongoingCallID, ongoingCallID == callID {
callProvider.reportCall(with: callID, endedAt: .now, reason: .unanswered)
}
Expand All @@ -146,6 +154,7 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
actionsSubject.send(.answerCall(roomID: incomingCallRoomID))
}
self.incomingCallRoomID = nil
endUnansweredCallTask?.cancel()
} else {
MXLog.error("Failed answering incoming call, missing room ID")
}
Expand Down

0 comments on commit fa22b98

Please sign in to comment.