Skip to content

Commit

Permalink
Fix a bug where call observation wasn't set up if the call comes when…
Browse files Browse the repository at this point in the history
… the app has been killed.
  • Loading branch information
pixlwave committed Nov 5, 2024
1 parent e0c8abf commit 6dac0a2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ElementX/Sources/Services/ElementCall/ElementCallService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
return CXProvider(configuration: configuration)
}()

private weak var clientProxy: ClientProxyProtocol?
private weak var clientProxy: ClientProxyProtocol? {
didSet {
// There's a race condition where a call starts when the app has been killed and the
// observation set in `incomingCallID` occurs *before* the user session is restored.
// So observe when the client proxy is set to fix this (the method guards for the call).
Task { await observeIncomingCallRoomInfo() }
}
}

private var incomingCallRoomInfoCancellable: AnyCancellable?
private var incomingCallID: CallID? {
didSet {
Task {
await observeIncomingCallRoomInfo()
}
Task { await observeIncomingCallRoomInfo() }
}
}

Expand Down Expand Up @@ -276,11 +281,18 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
private func observeIncomingCallRoomInfo() async {
incomingCallRoomInfoCancellable = nil

guard let clientProxy, let incomingCallID else {
guard let incomingCallID else {
MXLog.info("No incoming call to observe for.")
return
}

guard let clientProxy else {
MXLog.warning("A ClientProxy is needed to fetch the room.")
return
}

guard case let .joined(roomProxy) = await clientProxy.roomForIdentifier(incomingCallID.roomID) else {
MXLog.warning("Failed to fetch a joined room for the incoming call.")
return
}

Expand Down

0 comments on commit 6dac0a2

Please sign in to comment.