Merge pull request #5914 from vector-im/aringenbach/1575_jitsi_leave_call_on_remove_widget

Fix app not leaving call when Jitsi widget is removed
This commit is contained in:
aringenbach 2022-03-24 16:40:01 +01:00 committed by GitHub
commit 4bda8da4fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 9 deletions

View file

@ -263,24 +263,25 @@ class CallPresenter: NSObject {
func processWidgetEvent(_ event: MXEvent, inSession session: MXSession) {
MXLog.debug("[CallPresenter] processWidgetEvent")
guard JMCallKitProxy.isProviderConfigured() else {
// CallKit proxy is not configured, no benefit in parsing the event
MXLog.debug("[CallPresenter] processWidgetEvent: JMCallKitProxy not configured")
return
}
guard let widget = Widget(widgetEvent: event, inMatrixSession: session) else {
MXLog.debug("[CallPresenter] processWidgetEvent: widget couldn't be created")
return
}
if let uuid = self.jitsiCalls.first(where: { $0.value.widgetId == widget.widgetId })?.key {
// this Jitsi call is already managed by this class, no need to report the call again
MXLog.debug("[CallPresenter] processWidgetEvent: Jitsi call already managed with id: \(uuid.uuidString)")
guard JMCallKitProxy.isProviderConfigured() else {
// CallKit proxy is not configured, no benefit in parsing the event
MXLog.debug("[CallPresenter] processWidgetEvent: JMCallKitProxy not configured")
hangupUnhandledCallIfNeeded(widget)
return
}
if widget.isActive {
if let uuid = self.jitsiCalls.first(where: { $0.value.widgetId == widget.widgetId })?.key {
// this Jitsi call is already managed by this class, no need to report the call again
MXLog.debug("[CallPresenter] processWidgetEvent: Jitsi call already managed with id: \(uuid.uuidString)")
return
}
guard widget.type == kWidgetTypeJitsiV1 || widget.type == kWidgetTypeJitsiV2 else {
// not a Jitsi widget, ignore
MXLog.debug("[CallPresenter] processWidgetEvent: not a Jitsi widget")
@ -337,6 +338,7 @@ class CallPresenter: NSObject {
guard let uuid = self.jitsiCalls.first(where: { $0.value.widgetId == widget.widgetId })?.key else {
// this Jitsi call is not managed by this class
MXLog.debug("[CallPresenter] processWidgetEvent: not managed Jitsi call: \(widget.widgetId)")
hangupUnhandledCallIfNeeded(widget)
return
}
MXLog.debug("[CallPresenter] processWidgetEvent: ended call with id: \(uuid.uuidString)")
@ -722,6 +724,15 @@ class CallPresenter: NSObject {
uiOperationQueue.addOperation(operation)
}
/// Hangs up current Jitsi call, if it is inactive and associated with given widget.
/// Should be used for calls that are not handled through JMCallKitProxy,
/// as these should be removed regardless.
private func hangupUnhandledCallIfNeeded(_ widget: Widget) {
guard !widget.isActive, widget.widgetId == jitsiVC?.widget.widgetId else { return }
MXLog.debug("[CallPresenter] hangupUnhandledCallIfNeeded: ending call with Widget id: %@", widget.widgetId)
endActiveJitsiCall()
}
}
// MARK: - MXKCallViewControllerDelegate

1
changelog.d/1575.bugfix Normal file
View file

@ -0,0 +1 @@
Jitsi: fix app not leaving call when widget is removed