Skip to content

Commit

Permalink
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 e2ee5e6 commit 3b18dad
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 34 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
4 changes: 4 additions & 0 deletions GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public final class CallVisualizer {
by: .embedded(container, onEngagementAccepted: onEngagementAccepted)
)
}

public func resume() {
coordinator.resume()
}
}

// MARK: - Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ extension CallVisualizer {
self.bubbleView = environment.viewFactory.makeBubbleView()

bubbleView.tap = { [weak self] in
guard let self = self else { return }
if self.videoCallCoordinator == nil {
self.showEndScreenSharingViewController()
} else {
self.resumeVideoCallViewController()
}
environment.eventHandler(.maximized)
self?.resume()
}
bubbleView.pan = { [weak self] translation in
self?.updateBubblePosition(translation: translation)
}
}

func resume() {
if self.videoCallCoordinator == nil {
self.showEndScreenSharingViewController()
} else {
self.resumeVideoCallViewController()
}
environment.eventHandler(.maximized)
}

func showVisitorCodeViewController(by presentation: Presentation) {
let coordinator = VisitorCodeCoordinator(
theme: environment.viewFactory.theme,
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:
break
}
} 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])
}
}
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ target 'TestingApp' do
end

target 'GliaWidgets' do
pod 'GliaCoreSDK', '1.5.8'
pod 'GliaCoreSDK', '2.0.4'
swiftlint
end

Expand Down

0 comments on commit 3b18dad

Please sign in to comment.