diff --git a/MEGAUnitTests/Meeting/CallControlsViewModelTests.swift b/MEGAUnitTests/Meeting/CallControlsViewModelTests.swift index 049a268eb7..262d25ae57 100644 --- a/MEGAUnitTests/Meeting/CallControlsViewModelTests.swift +++ b/MEGAUnitTests/Meeting/CallControlsViewModelTests.swift @@ -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, @@ -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, @@ -518,9 +520,7 @@ final class CallControlsViewModelTests: XCTestCase { } func localAudioFlagUpdated(enabled: Bool) { - callUseCase - .callUpdateSubject - .send(.localCameraEnabled(enabled)) + callUpdateUseCase.sendCallUpdate(.localCameraEnabled(enabled)) } } } diff --git a/iMEGA/CallScene/FloatingPanel/MeetingFloatingPanelRouter.swift b/iMEGA/CallScene/FloatingPanel/MeetingFloatingPanelRouter.swift index 5663397fb4..ecbe7071aa 100644 --- a/iMEGA/CallScene/FloatingPanel/MeetingFloatingPanelRouter.swift +++ b/iMEGA/CallScene/FloatingPanel/MeetingFloatingPanelRouter.swift @@ -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), diff --git a/iMEGA/CallScene/FloatingPanel/Views/CallControls/ViewModel/CallControlsViewModel.swift b/iMEGA/CallScene/FloatingPanel/Views/CallControls/ViewModel/CallControlsViewModel.swift index 4e06cfacc3..fb4289cf49 100644 --- a/iMEGA/CallScene/FloatingPanel/Views/CallControls/ViewModel/CallControlsViewModel.swift +++ b/iMEGA/CallScene/FloatingPanel/Views/CallControls/ViewModel/CallControlsViewModel.swift @@ -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? @@ -29,8 +30,6 @@ final class CallControlsViewModel: CallControlsViewModelProtocol { private let raiseHandBadgeStoring: any RaiseHandBadgeStoring private let tracker: any AnalyticsTracking - private var subscriptions = Set() - @Published var micEnabled: Bool = false @Published var cameraEnabled: Bool = false @Published var speakerEnabled: Bool = false @@ -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, @@ -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 @@ -85,7 +86,7 @@ final class CallControlsViewModel: CallControlsViewModelProtocol { registerForAudioRouteChanges() checkRouteViewAvailability() - listenToCallUpdates() + monitorOnCallUpdate() updateSpeakerIcon() } @@ -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) {