Committed by
GitHub
Add test for TrackSubscribed (#476)
* Add test for TrackSubscribed * spotless
正在显示
1 个修改的文件
包含
40 行增加
和
0 行删除
| @@ -18,6 +18,7 @@ package io.livekit.android.room | @@ -18,6 +18,7 @@ package io.livekit.android.room | ||
| 18 | 18 | ||
| 19 | import android.net.Network | 19 | import android.net.Network |
| 20 | import io.livekit.android.events.DisconnectReason | 20 | import io.livekit.android.events.DisconnectReason |
| 21 | +import io.livekit.android.events.ParticipantEvent | ||
| 21 | import io.livekit.android.events.RoomEvent | 22 | import io.livekit.android.events.RoomEvent |
| 22 | import io.livekit.android.events.convert | 23 | import io.livekit.android.events.convert |
| 23 | import io.livekit.android.room.participant.ConnectionQuality | 24 | import io.livekit.android.room.participant.ConnectionQuality |
| @@ -37,6 +38,7 @@ import io.livekit.android.test.mock.createMediaStreamId | @@ -37,6 +38,7 @@ import io.livekit.android.test.mock.createMediaStreamId | ||
| 37 | import io.livekit.android.util.flow | 38 | import io.livekit.android.util.flow |
| 38 | import io.livekit.android.util.toOkioByteString | 39 | import io.livekit.android.util.toOkioByteString |
| 39 | import junit.framework.Assert.assertEquals | 40 | import junit.framework.Assert.assertEquals |
| 41 | +import junit.framework.Assert.assertNotNull | ||
| 40 | import kotlinx.coroutines.CoroutineScope | 42 | import kotlinx.coroutines.CoroutineScope |
| 41 | import kotlinx.coroutines.Dispatchers | 43 | import kotlinx.coroutines.Dispatchers |
| 42 | import kotlinx.coroutines.ExperimentalCoroutinesApi | 44 | import kotlinx.coroutines.ExperimentalCoroutinesApi |
| @@ -179,6 +181,44 @@ class RoomMockE2ETest : MockE2ETest() { | @@ -179,6 +181,44 @@ class RoomMockE2ETest : MockE2ETest() { | ||
| 179 | } | 181 | } |
| 180 | 182 | ||
| 181 | @Test | 183 | @Test |
| 184 | + fun participantSubscribesRemoteTrack() = runTest { | ||
| 185 | + connect() | ||
| 186 | + | ||
| 187 | + simulateMessageFromServer(TestData.PARTICIPANT_JOIN) | ||
| 188 | + val remoteParticipant = room.getParticipantBySid(TestData.REMOTE_PARTICIPANT.sid)!! | ||
| 189 | + val eventCollector = EventCollector(room.events, coroutineRule.scope) | ||
| 190 | + val participantEventsCollector = EventCollector(remoteParticipant.events, coroutineRule.scope) | ||
| 191 | + room.onAddTrack( | ||
| 192 | + MockRtpReceiver.create(), | ||
| 193 | + MockAudioStreamTrack(), | ||
| 194 | + arrayOf( | ||
| 195 | + MockMediaStream( | ||
| 196 | + id = createMediaStreamId( | ||
| 197 | + TestData.REMOTE_PARTICIPANT.sid, | ||
| 198 | + TestData.REMOTE_AUDIO_TRACK.sid, | ||
| 199 | + ), | ||
| 200 | + ), | ||
| 201 | + ), | ||
| 202 | + ) | ||
| 203 | + val events = eventCollector.stopCollecting() | ||
| 204 | + val participantEvents = participantEventsCollector.stopCollecting() | ||
| 205 | + | ||
| 206 | + assertIsClassList( | ||
| 207 | + listOf(RoomEvent.TrackSubscribed::class.java), | ||
| 208 | + events, | ||
| 209 | + ) | ||
| 210 | + | ||
| 211 | + assertIsClassList( | ||
| 212 | + listOf(ParticipantEvent.TrackSubscribed::class.java), | ||
| 213 | + participantEvents, | ||
| 214 | + ) | ||
| 215 | + | ||
| 216 | + val micPub = remoteParticipant.getTrackPublication(Track.Source.MICROPHONE) | ||
| 217 | + assertNotNull(micPub) | ||
| 218 | + assertNotNull(micPub?.track) | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + @Test | ||
| 182 | fun participantDisconnected() = runTest { | 222 | fun participantDisconnected() = runTest { |
| 183 | connect() | 223 | connect() |
| 184 | wsFactory.listener.onMessage( | 224 | wsFactory.listener.onMessage( |
-
请 注册 或 登录 后发表评论