Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SetVideoSendStateUseCase (WPB-7114) #2670

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CallManagerImpl : CallManager {
TODO("Not yet implemented")
}

override suspend fun updateVideoState(conversationId: ConversationId, videoState: VideoState) {
override suspend fun setVideoSendState(conversationId: ConversationId, videoState: VideoState) {
TODO("Not yet implemented")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class CallManagerImpl internal constructor(
/**
* This method should NOT be called while the call is still incoming or outgoing and not established yet.
*/
override suspend fun updateVideoState(conversationId: ConversationId, videoState: VideoState) {
override suspend fun setVideoSendState(conversationId: ConversationId, videoState: VideoState) {
withCalling {
callingLogger.d("$TAG -> changing video state to ${videoState.name}..")
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface CallManager {
suspend fun endCall(conversationId: ConversationId)
suspend fun rejectCall(conversationId: ConversationId)
suspend fun muteCall(shouldMute: Boolean)
suspend fun updateVideoState(conversationId: ConversationId, videoState: VideoState)
suspend fun setVideoSendState(conversationId: ConversationId, videoState: VideoState)
suspend fun requestVideoStreams(conversationId: ConversationId, callClients: CallClientList)
suspend fun updateEpochInfo(conversationId: ConversationId, epochInfo: EpochInfo)
suspend fun updateConversationClients(conversationId: ConversationId, clients: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ import com.wire.kalium.logic.feature.call.usecase.UnMuteCallUseCase
import com.wire.kalium.logic.feature.call.usecase.UnMuteCallUseCaseImpl
import com.wire.kalium.logic.feature.call.usecase.UpdateConversationClientsForCurrentCallUseCase
import com.wire.kalium.logic.feature.call.usecase.UpdateConversationClientsForCurrentCallUseCaseImpl
import com.wire.kalium.logic.feature.call.usecase.UpdateVideoStateUseCase
import com.wire.kalium.logic.feature.call.usecase.video.SetVideoSendStateUseCase
import com.wire.kalium.logic.feature.call.usecase.video.UpdateVideoStateUseCase
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.logic.sync.SyncManager
import com.wire.kalium.util.KaliumDispatcher
Expand Down Expand Up @@ -157,7 +158,8 @@ class CallsScope internal constructor(

val unMuteCall: UnMuteCallUseCase get() = UnMuteCallUseCaseImpl(callManager, callRepository)

val updateVideoState: UpdateVideoStateUseCase get() = UpdateVideoStateUseCase(callManager, callRepository)
val updateVideoState: UpdateVideoStateUseCase get() = UpdateVideoStateUseCase(callRepository)
val setVideoSendState: SetVideoSendStateUseCase get() = SetVideoSendStateUseCase(callManager)

val setVideoPreview: SetVideoPreviewUseCase get() = SetVideoPreviewUseCase(flowManagerService)
val flipToFrontCamera: FlipToFrontCameraUseCase get() = FlipToFrontCameraUseCase(flowManagerService)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.feature.call.usecase.video

import com.wire.kalium.logic.data.call.VideoState
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.feature.call.CallManager

/**
* This usecase is responsible for setting the video send state of a call.
*/
class SetVideoSendStateUseCase(
private val callManager: Lazy<CallManager>,
) {
suspend operator fun invoke(
conversationId: ConversationId,
videoState: VideoState
) {
callManager.value.setVideoSendState(conversationId, videoState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

package com.wire.kalium.logic.feature.call.usecase
package com.wire.kalium.logic.feature.call.usecase.video

import com.wire.kalium.logic.data.call.CallRepository
import com.wire.kalium.logic.data.call.VideoState
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.feature.call.CallManager
import kotlinx.coroutines.flow.first

/**
* This use case is responsible for updating the video state of a call.
* This use case is responsible for updating and caching the video state of a call.
* @see [VideoState]
*/
class UpdateVideoStateUseCase(
private val callManager: Lazy<CallManager>,
private val callRepository: CallRepository
) {
/**
Expand All @@ -42,12 +39,5 @@ class UpdateVideoStateUseCase(
) {
if (videoState != VideoState.PAUSED)
callRepository.updateIsCameraOnById(conversationId, videoState == VideoState.STARTED)

// updateVideoState should be called only when the call is established
callRepository.establishedCallsFlow().first().find { call ->
call.conversationId == conversationId
}?.let {
callManager.value.updateVideoState(conversationId, videoState)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.feature.call.usecase.video

import com.wire.kalium.logic.data.call.VideoState
import com.wire.kalium.logic.feature.call.CallManager
import com.wire.kalium.logic.framework.TestConversation
import io.mockative.Mock
import io.mockative.any
import io.mockative.classOf
import io.mockative.eq
import io.mockative.mock
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

class SetVideoSendStateUseCaseTest {

@Test
fun givenVideoState_whenRunningUsecase_thenInvokeSetVideoSendStateOnce() = runTest {
val (arrangement, setVideoSendState) = Arrangement()
.arrange()

setVideoSendState.invoke(TestConversation.ID, VideoState.STARTED)

verify(arrangement.callManager)
.suspendFunction(arrangement.callManager::setVideoSendState)
.with(any(), eq(VideoState.STARTED))
.wasInvoked(once)
}

private class Arrangement {

@Mock
val callManager = mock(classOf<CallManager>())

val setVideoSendState = SetVideoSendStateUseCase(lazy { callManager })

fun arrange() = this to setVideoSendState
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

package com.wire.kalium.logic.feature.call.usecase
package com.wire.kalium.logic.feature.call.usecase.video

import com.wire.kalium.logic.data.call.CallRepository
import com.wire.kalium.logic.data.call.VideoState
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.call.Call
import com.wire.kalium.logic.feature.call.CallManager
import com.wire.kalium.logic.data.call.CallStatus
import io.mockative.Mock
import io.mockative.any
import io.mockative.classOf
import io.mockative.eq
import io.mockative.given
Expand All @@ -41,26 +39,18 @@ import kotlin.test.Test

class UpdateVideoStateUseCaseTest {

@Mock
private val callManager = mock(classOf<CallManager>())

@Mock
private val callRepository = mock(classOf<CallRepository>())

private lateinit var updateVideoStateUseCase: UpdateVideoStateUseCase

@BeforeTest
fun setup() {
updateVideoStateUseCase = UpdateVideoStateUseCase(lazy { callManager }, callRepository)
updateVideoStateUseCase = UpdateVideoStateUseCase(callRepository)
given(callRepository)
.function(callRepository::updateIsCameraOnById)
.whenInvokedWith(eq(conversationId.toString()), eq(isCameraOn))
.thenDoNothing()

given(callManager)
.suspendFunction(callManager::updateVideoState)
.whenInvokedWith(any(), any())
.thenReturn(Unit)
}

@Test
Expand All @@ -77,10 +67,6 @@ class UpdateVideoStateUseCaseTest {
null,
null
)
given(callManager)
.suspendFunction(callManager::updateVideoState)
.whenInvokedWith(eq(conversationId), eq(videoState))
.thenDoNothing()

given(callRepository)
.suspendFunction(callRepository::establishedCallsFlow)
Expand All @@ -98,11 +84,6 @@ class UpdateVideoStateUseCaseTest {
.function(callRepository::updateIsCameraOnById)
.with(eq(conversationId), eq(isCameraOn))
.wasInvoked(once)

verify(callManager)
.suspendFunction(callManager::updateVideoState)
.with(any(), any())
.wasInvoked(once)
}

@Test
Expand All @@ -124,11 +105,6 @@ class UpdateVideoStateUseCaseTest {
.function(callRepository::updateIsCameraOnById)
.with(eq(conversationId), eq(isCameraOn))
.wasInvoked(once)

verify(callManager)
.suspendFunction(callManager::updateVideoState)
.with(any(), any())
.wasNotInvoked()
}

companion object {
Expand Down
Loading