Clear incoming-call state on every path that ends a ringing call

Four end paths each cleaned up partially.

Signed-off-by: Daniel Anderson <daniel.anderson@toptal.com>
This commit is contained in:
Daniel Anderson
2026-05-27 10:36:48 -06:00
committed by Stefan Ceriu
parent 9bfc97ad59
commit 4c8becc99e
2 changed files with 87 additions and 3 deletions
@@ -115,7 +115,7 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
CallID(callKitID: UUID(), roomID: roomID, rtcNotificationID: nil, isVoiceCall: false)
}
incomingCallID = nil
clearIncomingCallState()
ongoingCallID = callID
// Don't bother starting another CallKit session as it won't work properly
@@ -230,6 +230,7 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
if let incomingCallID, incomingCallID.callKitID == callID.callKitID {
callProvider.reportCall(with: incomingCallID.callKitID, endedAt: nil, reason: .unanswered)
clearIncomingCallState()
}
}
}
@@ -308,6 +309,10 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
}
}
if incomingCallID?.callKitID == action.callUUID {
clearIncomingCallState()
}
tearDownCallSession(sendEndCallAction: false)
action.fulfill()
@@ -419,9 +424,20 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
}
private func reportEndedCall(incomingCallID: CallID, reason: CXCallEndedReason) {
callProvider.reportCall(with: incomingCallID.callKitID, endedAt: nil, reason: reason)
clearIncomingCallState()
}
/// Cancels every subscription and task tied to a ringing incoming call and nils `incomingCallID`.
/// Call this on every path that ends the incoming-call state (answered, declined, timed out,
/// cancelled by remote, answered/declined elsewhere) so that follow-up calls to the same room
/// start from a clean slate and the SDK decline-listener subscription doesn't leak.
private func clearIncomingCallState() {
endUnansweredCallTask?.cancel()
endUnansweredCallTask = nil
declineListenerHandle?.cancel()
declineListenerHandle = nil
endUnansweredCallTask?.cancel()
callProvider.reportCall(with: incomingCallID.callKitID, endedAt: nil, reason: reason)
incomingCallRoomInfoCancellable = nil
incomingCallID = nil
}
}