Skip to content

Commit

Permalink
fix: is user speaking mapper causes a flash briefly (#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Jun 14, 2024
1 parent 8901bc0 commit 94a64c4
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ActiveSpeakerMapperImpl : ActiveSpeakerMapper {
activeSpeaker.userId == participant.id.toString() && activeSpeaker.clientId == participant.clientId
}?.let {
this[indexOf(it)] = it.copy(
isSpeaking = activeSpeaker.audioLevel > 0 && activeSpeaker.audioLevelNow > 0
isSpeaking = activeSpeaker.audioLevel > 0 || activeSpeaker.audioLevelNow > 0
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ActiveSpeakerMapperTest {
private val activeSpeakerMapper = ActiveSpeakerMapperImpl()

@Test
fun givenCallActiveSpeakers_whenMappingToParticipantsActiveSpeaker_thenReturnParticipantsActiveSpeaker() = runTest {
fun givenUserAudioLevelNot0AndaudioLevelNowNot0_whenMapping_thenUserIsSpeaking() = runTest {
val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy(
clientId = "anotherClientId"
)
Expand All @@ -40,14 +40,111 @@ class ActiveSpeakerMapperTest {
dummyParticipantWithDifferentClientId
),
activeSpeakers = CallActiveSpeakers(
activeSpeakers = listOf(DUMMY_CALL_ACTIVE_SPEAKER, DUMMY_CALL_ACTIVE_SPEAKER1)
activeSpeakers = listOf(
DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 1, audioLevelNow = 1),
DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 1, audioLevelNow = 1)
)
)
)

val expectedParticipantsActiveSpeaker = listOf(
DUMMY_PARTICIPANT.copy(
isSpeaking = true
),
dummyParticipantWithDifferentClientId.copy(
isSpeaking = true
)
)

assertEquals(expectedParticipantsActiveSpeaker, callActiveSpeakerMap)
}


@Test
fun givenUserAudioLevelIs0AndaudioLevelNowNot0_whenMapping_thenUserIsSpeaking() = runTest {
val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy(
clientId = "anotherClientId"
)

val callActiveSpeakerMap = activeSpeakerMapper.mapParticipantsActiveSpeaker(
participants = listOf(
DUMMY_PARTICIPANT,
dummyParticipantWithDifferentClientId
),
activeSpeakers = CallActiveSpeakers(
activeSpeakers = listOf(
DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 0, audioLevelNow = 1),
DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 0, audioLevelNow = 1)
)
)
)

val expectedParticipantsActiveSpeaker = listOf(
DUMMY_PARTICIPANT.copy(
isSpeaking = true
),
dummyParticipantWithDifferentClientId.copy(
isSpeaking = true
)
)

assertEquals(expectedParticipantsActiveSpeaker, callActiveSpeakerMap)
}

@Test
fun givenUserAudioLevelNot0AndaudioLevelNowIs0_whenMapping_thenUserIsSpeaking() = runTest {
val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy(
clientId = "anotherClientId"
)

val callActiveSpeakerMap = activeSpeakerMapper.mapParticipantsActiveSpeaker(
participants = listOf(
DUMMY_PARTICIPANT,
dummyParticipantWithDifferentClientId
),
activeSpeakers = CallActiveSpeakers(
activeSpeakers = listOf(
DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 1, audioLevelNow = 0),
DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 1, audioLevelNow = 0)
)
)
)

val expectedParticipantsActiveSpeaker = listOf(
DUMMY_PARTICIPANT.copy(
isSpeaking = true
),
dummyParticipantWithDifferentClientId.copy(
isSpeaking = true
)
)

assertEquals(expectedParticipantsActiveSpeaker, callActiveSpeakerMap)
}

@Test
fun givenUserAudioLevelIs0AndaudioLevelNowIs0_whenMapping_thenUserIsNotSpeaking() = runTest {
val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy(
clientId = "anotherClientId"
)

val callActiveSpeakerMap = activeSpeakerMapper.mapParticipantsActiveSpeaker(
participants = listOf(
DUMMY_PARTICIPANT,
dummyParticipantWithDifferentClientId
),
activeSpeakers = CallActiveSpeakers(
activeSpeakers = listOf(
DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 0, audioLevelNow = 0),
DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 0, audioLevelNow = 0)
)
)
)

val expectedParticipantsActiveSpeaker = listOf(
DUMMY_PARTICIPANT.copy(
isSpeaking = false
),
dummyParticipantWithDifferentClientId.copy(
isSpeaking = false
)
Expand Down

0 comments on commit 94a64c4

Please sign in to comment.