Skip to content

Commit

Permalink
IOS-9343 Convert CallControlsViewModel callUseCase.onCallUpdate() int…
Browse files Browse the repository at this point in the history
…o async stream
  • Loading branch information
jcmartinac committed Nov 26, 2024
1 parent 86c9c2f commit 824153a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions MEGAUnitTests/Meeting/CallControlsViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ final class CallControlsViewModelTests: XCTestCase {
let cameraSwitcher = MockCameraSwitcher()
let raiseHandBadgeStore = MockRaiseHandBadgeStore()
let mockTracker = MockTracker()

let callUpdateUseCase = MockCallUpdateUseCase()

init(
chatType: ChatRoomEntity.ChatType = .meeting,
isModerator: Bool = true,
Expand Down Expand Up @@ -390,6 +391,7 @@ final class CallControlsViewModelTests: XCTestCase {
menuPresenter: { actions in menuPresenter(actions) },
chatRoom: chatRoom,
callUseCase: callUseCase,
callUpdateUseCase: callUpdateUseCase,
localVideoUseCase: localVideoUseCase,
containerViewModel: containerViewModel,
audioSessionUseCase: audioSessionUseCase,
Expand Down Expand Up @@ -518,9 +520,7 @@ final class CallControlsViewModelTests: XCTestCase {
}

func localAudioFlagUpdated(enabled: Bool) {
callUseCase
.callUpdateSubject
.send(.localCameraEnabled(enabled))
callUpdateUseCase.sendCallUpdate(.localCameraEnabled(enabled))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ final class MeetingFloatingPanelRouter: MeetingFloatingPanelRouting {
menuPresenter: presentMenu,
chatRoom: chatRoom,
callUseCase: CallUseCase(repository: CallRepository.newRepo),
callUpdateUseCase: CallUpdateUseCase(repository: CallUpdateRepository.newRepo),
localVideoUseCase: CallLocalVideoUseCase(repository: CallLocalVideoRepository(chatSdk: .shared)),
containerViewModel: containerViewModel,
audioSessionUseCase: AudioSessionUseCase(audioSessionRepository: audioSessionRepository),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class CallControlsViewModel: CallControlsViewModelProtocol {
private var chatRoom: ChatRoomEntity

private let callUseCase: any CallUseCaseProtocol
private let callUpdateUseCase: any CallUpdateUseCaseProtocol
private let localVideoUseCase: any CallLocalVideoUseCaseProtocol
private let audioSessionUseCase: any AudioSessionUseCaseProtocol
private weak var containerViewModel: MeetingContainerViewModel?
Expand All @@ -29,8 +30,6 @@ final class CallControlsViewModel: CallControlsViewModelProtocol {
private let raiseHandBadgeStoring: any RaiseHandBadgeStoring
private let tracker: any AnalyticsTracking

private var subscriptions = Set<AnyCancellable>()

@Published var micEnabled: Bool = false
@Published var cameraEnabled: Bool = false
@Published var speakerEnabled: Bool = false
Expand All @@ -44,6 +43,7 @@ final class CallControlsViewModel: CallControlsViewModelProtocol {
menuPresenter: @escaping ([ActionSheetAction]) -> Void,
chatRoom: ChatRoomEntity,
callUseCase: some CallUseCaseProtocol,
callUpdateUseCase: some CallUpdateUseCaseProtocol,
localVideoUseCase: some CallLocalVideoUseCaseProtocol,
containerViewModel: MeetingContainerViewModel? = nil,
audioSessionUseCase: some AudioSessionUseCaseProtocol,
Expand All @@ -62,6 +62,7 @@ final class CallControlsViewModel: CallControlsViewModelProtocol {
self.menuPresenter = menuPresenter
self.chatRoom = chatRoom
self.callUseCase = callUseCase
self.callUpdateUseCase = callUpdateUseCase
self.localVideoUseCase = localVideoUseCase
self.containerViewModel = containerViewModel
self.permissionHandler = permissionHandler
Expand All @@ -85,7 +86,7 @@ final class CallControlsViewModel: CallControlsViewModelProtocol {

registerForAudioRouteChanges()
checkRouteViewAvailability()
listenToCallUpdates()
monitorOnCallUpdate()
updateSpeakerIcon()
}

Expand Down Expand Up @@ -304,16 +305,13 @@ final class CallControlsViewModel: CallControlsViewModelProtocol {
routeViewVisible = audioSessionUseCase.isBluetoothAudioRouteAvailable
}

private func listenToCallUpdates() {
callUseCase.onCallUpdate()
.receive(on: scheduler)
.sink { @Sendable [weak self] call in
guard let self else { return }
Task {
await self.onCallUpdate(call)
}
private func monitorOnCallUpdate() {
let callUpdates = callUpdateUseCase.monitorOnCallUpdate()
Task { [weak self] in
for await call in callUpdates {
self?.onCallUpdate(call)
}
.store(in: &subscriptions)
}
}

private func onCallUpdate(_ call: CallEntity) {
Expand Down

0 comments on commit 824153a

Please sign in to comment.