Skip to content

Commit

Permalink
fix: Active speaker highlighting [WPB-11040] (#3045)
Browse files Browse the repository at this point in the history
* fix: Active speaker highlighting

* Added tests
  • Loading branch information
borichellow authored and MohamadJaara committed Oct 18, 2024
1 parent 372e0b0 commit 43076b7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data class CallMetadata(
) {
fun getFullParticipants(): List<Participant> = participants.map { participant ->
val user = users.firstOrNull { it.id == participant.userId }
val isSpeaking = (activeSpeakers[participant.id]?.contains(participant.clientId) ?: false) && !participant.isMuted
val isSpeaking = (activeSpeakers[participant.userId]?.contains(participant.clientId) ?: false) && !participant.isMuted
Participant(
id = participant.id,
clientId = participant.clientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.yield
import kotlinx.datetime.Clock
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
Expand Down Expand Up @@ -1474,6 +1475,56 @@ class CallRepositoryTest {
assertEquals(activeSpeakers, callRepository.getCallMetadataProfile().data[Arrangement.conversationId]?.activeSpeakers)
}

@Test
fun givenCallWithActiveSpeakers_whenGetFullParticipants_thenOnlySpeakingUsers() = runTest {
val (_, callRepository) = Arrangement().arrange()
val mutedParticipant = ParticipantMinimized(
id = QualifiedID("participantId", ""),
userId = QualifiedID("participantId", "participantDomain"),
clientId = "abcd0",
isMuted = true,
isCameraOn = false,
isSharingScreen = false,
hasEstablishedAudio = true
)
val unMutedParticipant = mutedParticipant.copy(
id = QualifiedID("anotherParticipantId", ""),
userId = QualifiedID("anotherParticipantId", "participantDomain"),
clientId = "abcd1",
isMuted = false
)
val activeSpeakers = mapOf(
mutedParticipant.userId to listOf(mutedParticipant.clientId),
unMutedParticipant.userId to listOf(unMutedParticipant.clientId),
)

callRepository.updateCallMetadataProfileFlow(
callMetadataProfile = CallMetadataProfile(
data = mapOf(
Arrangement.conversationId to createCallMetadata().copy(
participants = listOf(mutedParticipant, unMutedParticipant),
maxParticipants = 0
)
)
)
)

// when
callRepository.updateParticipantsActiveSpeaker(Arrangement.conversationId, activeSpeakers)

// then
val fullParticipants = callRepository.getCallMetadataProfile().data[Arrangement.conversationId]?.getFullParticipants()

assertEquals(
false,
fullParticipants?.first { it.id == mutedParticipant.id && it.clientId == mutedParticipant.clientId }?.isSpeaking
)
assertEquals(
true,
fullParticipants?.first { it.id == unMutedParticipant.id && it.clientId == unMutedParticipant.clientId }?.isSpeaking
)
}

private fun provideCall(id: ConversationId, status: CallStatus) = Call(
conversationId = id,
status = status,
Expand Down

0 comments on commit 43076b7

Please sign in to comment.