davidliu
Committed by GitHub

Add lastSpokeAt and joinedAt fields to Participant (#226)

... ... @@ -14,6 +14,7 @@ import io.livekit.android.util.flowDelegate
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import livekit.LivekitModels
import java.util.Date
import javax.inject.Named
open class Participant(
... ... @@ -69,6 +70,9 @@ open class Participant(
listener?.onSpeakingChanged(this)
internalListener?.onSpeakingChanged(this)
eventBus.postEvent(ParticipantEvent.SpeakingChanged(this, newValue), scope)
if (newValue) {
lastSpokeAt = Date().time
}
}
}
internal set
... ... @@ -124,6 +128,20 @@ open class Participant(
internal set
/**
* Timestamp when participant joined room, in milliseconds
*/
val joinedAt
get() = participantInfo?.joinedAt?.times(1000)
/**
* Timestamp when the participant last started speaking, in milliseconds
*/
@FlowObservable
@get:FlowObservable
var lastSpokeAt by flowDelegate<Long?>(null)
internal set
/**
* Listener for when participant properties change
*/
@Deprecated("Use events instead")
... ...
... ... @@ -9,10 +9,14 @@ import kotlinx.coroutines.test.runTest
import livekit.LivekitModels
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.Date
import kotlin.math.abs
@ExperimentalCoroutinesApi
class ParticipantTest {
... ... @@ -125,15 +129,27 @@ class ParticipantTest {
participant.dispose()
assertEquals("", participant.sid)
Assert.assertNull(participant.name)
Assert.assertNull(participant.identity)
Assert.assertNull(participant.metadata)
Assert.assertNull(participant.permissions)
Assert.assertNull(participant.participantInfo)
assertNull(participant.name)
assertNull(participant.identity)
assertNull(participant.metadata)
assertNull(participant.permissions)
assertNull(participant.participantInfo)
Assert.assertFalse(participant.isSpeaking)
assertEquals(ConnectionQuality.UNKNOWN, participant.connectionQuality)
}
@Test
fun speakingUpdatesLastSpokeAt() = runTest {
assertNull(participant.lastSpokeAt)
participant.isSpeaking = true
val lastSpokeAt = participant.lastSpokeAt
val timestamp = Date().time
assertNotNull(lastSpokeAt)
assertTrue(abs(lastSpokeAt!! - timestamp) < 1000)
}
companion object {
val INFO = LivekitModels.ParticipantInfo.newBuilder()
.setSid("sid")
... ...
Subproject commit e78c5b18c0f3a18bae5d5cec44d30bb6358b9bc4
Subproject commit ac74d1e920384ac3972b6017d1514ca983450f0d
... ...