Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app not leaving call when Jitsi widget is removed #5914

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions Riot/Managers/Call/CallPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1575.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jitsi: fix app not leaving call when widget is removed