From 478149b78108faab8c81a1748697e8301b278675 Mon Sep 17 00:00:00 2001 From: Rasmus Tauts Date: Wed, 18 Dec 2024 14:28:34 +0200 Subject: [PATCH] fixup! Create interface for resuming call visualizer Up until now Call Visualizer screen sharing or video call screen could only be opened through bubble tap. Entry Widget requires to open Call Visualizer by a tap on call visualizer media type, if CV session is ongoing. This PR allows to do just that, by providing an interface to resume the view. MOB-3887 --- .../Public/Glia/Glia+EntryWidget.swift | 4 ++ .../EntryWidget/EntryWidget.Environment.swift | 4 +- .../Sources/EntryWidget/EntryWidget.swift | 50 +++++++++---------- .../EntryWidget/EntryWidgetTests.swift | 35 +++++++++++++ 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/GliaWidgets/Public/Glia/Glia+EntryWidget.swift b/GliaWidgets/Public/Glia/Glia+EntryWidget.swift index a1eac8654..b7cf6f450 100644 --- a/GliaWidgets/Public/Glia/Glia+EntryWidget.swift +++ b/GliaWidgets/Public/Glia/Glia+EntryWidget.swift @@ -31,6 +31,10 @@ extension Glia { currentInteractor: { [weak self] in guard let self else { return nil } return interactor + }, + onCallVisualizerResume: { [weak self] in + guard let self else { return } + callVisualizer.resume() } ) ) diff --git a/GliaWidgets/Sources/EntryWidget/EntryWidget.Environment.swift b/GliaWidgets/Sources/EntryWidget/EntryWidget.Environment.swift index e35f85a55..f4dbb7acb 100644 --- a/GliaWidgets/Sources/EntryWidget/EntryWidget.Environment.swift +++ b/GliaWidgets/Sources/EntryWidget/EntryWidget.Environment.swift @@ -11,6 +11,7 @@ extension EntryWidget { var isAuthenticated: () -> Bool var hasPendingInteraction: () -> Bool var currentInteractor: () -> Interactor? + var onCallVisualizerResume: () -> Void } } @@ -27,7 +28,8 @@ extension EntryWidget.Environment { log: .mock, isAuthenticated: { true }, hasPendingInteraction: { false }, - currentInteractor: { .mock() } + currentInteractor: { .mock() }, + onCallVisualizerResume: {} ) } } diff --git a/GliaWidgets/Sources/EntryWidget/EntryWidget.swift b/GliaWidgets/Sources/EntryWidget/EntryWidget.swift index 8262ed918..40f14e9e8 100644 --- a/GliaWidgets/Sources/EntryWidget/EntryWidget.swift +++ b/GliaWidgets/Sources/EntryWidget/EntryWidget.swift @@ -114,6 +114,31 @@ extension EntryWidget { return appliedHeight } + + func mediaTypeSelected(_ mediaTypeItem: MediaTypeItem) { + if let configurationAction = configuration.mediaTypeSelected { + configurationAction(mediaTypeItem) + return + } + hideViewIfNecessary { + do { + switch mediaTypeItem.type { + case .chat: + try self.environment.engagementLauncher.startChat() + case .audio: + try self.environment.engagementLauncher.startAudioCall() + case .video: + try self.environment.engagementLauncher.startVideoCall() + case .secureMessaging: + try self.environment.engagementLauncher.startSecureMessaging() + case .callVisualizer: + self.environment.onCallVisualizerResume() + } + } catch { + self.viewState = .error + } + } + } } // MARK: - Private methods @@ -189,31 +214,6 @@ private extension EntryWidget { return Array(availableMediaTypes).sorted(by: { $0.rawValue < $1.rawValue }) } - func mediaTypeSelected(_ mediaTypeItem: MediaTypeItem) { - if let configurationAction = configuration.mediaTypeSelected { - configurationAction(mediaTypeItem) - return - } - hideViewIfNecessary { - do { - switch mediaTypeItem.type { - case .chat: - try self.environment.engagementLauncher.startChat() - case .audio: - try self.environment.engagementLauncher.startAudioCall() - case .video: - try self.environment.engagementLauncher.startVideoCall() - case .secureMessaging: - try self.environment.engagementLauncher.startSecureMessaging() - case .callVisualizer: - Glia.sharedInstance.callVisualizer.resume() - } - } catch { - self.viewState = .error - } - } - } - func hideViewIfNecessary(completion: @escaping () -> Void) { guard hostedViewController != nil else { completion() diff --git a/GliaWidgetsTests/Sources/EntryWidget/EntryWidgetTests.swift b/GliaWidgetsTests/Sources/EntryWidget/EntryWidgetTests.swift index 78c3a013d..c751bc3e3 100644 --- a/GliaWidgetsTests/Sources/EntryWidget/EntryWidgetTests.swift +++ b/GliaWidgetsTests/Sources/EntryWidget/EntryWidgetTests.swift @@ -351,4 +351,39 @@ class EntryWidgetTests: XCTestCase { XCTAssertEqual(entryWidget.viewState, .ongoingEngagement(.callVisualizer)) } + + func test_callVisualizerResumeCallbackBeingCalled() { + enum Call { + case onCallVisualizerResume + } + var calls: [Call] = [] + let mockQueueId = "mockQueueId" + let mockQueue = Queue.mock(id: mockQueueId, media: [.messaging, .audio]) + + var queueMonitorEnvironment: QueuesMonitor.Environment = .mock + queueMonitorEnvironment.listQueues = { completion in + completion([mockQueue], nil) + } + queueMonitorEnvironment.subscribeForQueuesUpdates = { _, completion in + completion(.success(mockQueue)) + return UUID.mock.uuidString + } + var environment = EntryWidget.Environment.mock() + environment.queuesMonitor = QueuesMonitor(environment: queueMonitorEnvironment) + let interactor: Interactor = .mock() + interactor.currentEngagement = .mock(source: .callVisualizer) + environment.currentInteractor = { interactor } + environment.onCallVisualizerResume = { + calls.append(.onCallVisualizerResume) + } + let entryWidget = EntryWidget( + queueIds: [mockQueueId], + configuration: .default, + environment: environment + ) + + entryWidget.mediaTypeSelected(.init(type: .callVisualizer)) + + XCTAssertEqual(calls, [.onCallVisualizerResume]) + } }