Skip to content

Commit

Permalink
fixup! Create interface for resuming call visualizer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rasmustautsglia committed Dec 18, 2024
1 parent 4ccf477 commit 478149b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 26 deletions.
4 changes: 4 additions & 0 deletions GliaWidgets/Public/Glia/Glia+EntryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension EntryWidget {
var isAuthenticated: () -> Bool
var hasPendingInteraction: () -> Bool
var currentInteractor: () -> Interactor?
var onCallVisualizerResume: () -> Void
}
}

Expand All @@ -27,7 +28,8 @@ extension EntryWidget.Environment {
log: .mock,
isAuthenticated: { true },
hasPendingInteraction: { false },
currentInteractor: { .mock() }
currentInteractor: { .mock() },
onCallVisualizerResume: {}
)
}
}
Expand Down
50 changes: 25 additions & 25 deletions GliaWidgets/Sources/EntryWidget/EntryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions GliaWidgetsTests/Sources/EntryWidget/EntryWidgetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 478149b

Please sign in to comment.