正在显示
8 个修改的文件
包含
88 行增加
和
24 行删除
| @@ -5,8 +5,6 @@ apply plugin: 'kotlinx-serialization' | @@ -5,8 +5,6 @@ apply plugin: 'kotlinx-serialization' | ||
| 5 | apply plugin: 'com.google.protobuf' | 5 | apply plugin: 'com.google.protobuf' |
| 6 | apply plugin: 'org.jetbrains.dokka' | 6 | apply plugin: 'org.jetbrains.dokka' |
| 7 | 7 | ||
| 8 | -import java.net.URL | ||
| 9 | - | ||
| 10 | android { | 8 | android { |
| 11 | compileSdkVersion 29 | 9 | compileSdkVersion 29 |
| 12 | buildToolsVersion "29.0.3" | 10 | buildToolsVersion "29.0.3" |
| @@ -71,7 +69,7 @@ dokkaHtml { | @@ -71,7 +69,7 @@ dokkaHtml { | ||
| 71 | 69 | ||
| 72 | // URL showing where the source code can be accessed through the web browser | 70 | // URL showing where the source code can be accessed through the web browser |
| 73 | remoteUrl.set(new URL( | 71 | remoteUrl.set(new URL( |
| 74 | - "https://github.com/livekit/client-sdk-android/tree/master/livekit-android-sdk/src/main/java")) | 72 | + "https://github.com/livekit/client-sdk-android/tree/master/livekit-android-sdk/src/main/java")) |
| 75 | // Suffix which is used to append the line number to the URL. Use #L for GitHub | 73 | // Suffix which is used to append the line number to the URL. Use #L for GitHub |
| 76 | remoteLineSuffix.set("#L") | 74 | remoteLineSuffix.set("#L") |
| 77 | } | 75 | } |
| @@ -105,7 +103,9 @@ dependencies { | @@ -105,7 +103,9 @@ dependencies { | ||
| 105 | implementation 'com.github.ajalt:timberkt:1.5.1' | 103 | implementation 'com.github.ajalt:timberkt:1.5.1' |
| 106 | implementation 'com.vdurmont:semver4j:3.1.0' | 104 | implementation 'com.vdurmont:semver4j:3.1.0' |
| 107 | 105 | ||
| 108 | - testImplementation 'junit:junit:4.12' | 106 | + testImplementation 'junit:junit:4.13.2' |
| 107 | + testImplementation 'org.mockito:mockito-core:3.8.0' | ||
| 108 | + testImplementation "org.mockito.kotlin:mockito-kotlin:3.1.0" | ||
| 109 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' | 109 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' |
| 110 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | 110 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' |
| 111 | } | 111 | } |
| @@ -16,8 +16,8 @@ import org.webrtc.VideoTrack | @@ -16,8 +16,8 @@ import org.webrtc.VideoTrack | ||
| 16 | class RemoteParticipant( | 16 | class RemoteParticipant( |
| 17 | val rtcClient: RTCClient, | 17 | val rtcClient: RTCClient, |
| 18 | sid: String, | 18 | sid: String, |
| 19 | - name: String? = null, | ||
| 20 | -) : Participant(sid, name) { | 19 | + identity: String? = null, |
| 20 | +) : Participant(sid, identity) { | ||
| 21 | /** | 21 | /** |
| 22 | * @suppress | 22 | * @suppress |
| 23 | */ | 23 | */ |
| @@ -3,9 +3,11 @@ package io.livekit.android.room.track | @@ -3,9 +3,11 @@ package io.livekit.android.room.track | ||
| 3 | import io.livekit.android.room.participant.LocalParticipant | 3 | import io.livekit.android.room.participant.LocalParticipant |
| 4 | import livekit.LivekitModels | 4 | import livekit.LivekitModels |
| 5 | 5 | ||
| 6 | -class LocalTrackPublication(info: LivekitModels.TrackInfo, | ||
| 7 | - track: Track? = null, | ||
| 8 | - participant: LocalParticipant? = null) : TrackPublication(info, track, participant) { | 6 | +class LocalTrackPublication( |
| 7 | + info: LivekitModels.TrackInfo, | ||
| 8 | + track: Track? = null, | ||
| 9 | + participant: LocalParticipant | ||
| 10 | +) : TrackPublication(info, track, participant) { | ||
| 9 | 11 | ||
| 10 | /** | 12 | /** |
| 11 | * Mute or unmute the current track. Muting the track would stop audio or video from being | 13 | * Mute or unmute the current track. Muting the track would stop audio or video from being |
| @@ -22,7 +24,7 @@ class LocalTrackPublication(info: LivekitModels.TrackInfo, | @@ -22,7 +24,7 @@ class LocalTrackPublication(info: LivekitModels.TrackInfo, | ||
| 22 | this.muted = muted | 24 | this.muted = muted |
| 23 | 25 | ||
| 24 | // send updates to server | 26 | // send updates to server |
| 25 | - val participant = this.participant.get() as? LocalParticipant ?: return | 27 | + val participant = this.participant as? LocalParticipant ?: return |
| 26 | 28 | ||
| 27 | participant.engine.updateMuteStatus(sid, muted) | 29 | participant.engine.updateMuteStatus(sid, muted) |
| 28 | 30 |
| @@ -4,9 +4,11 @@ import io.livekit.android.room.participant.RemoteParticipant | @@ -4,9 +4,11 @@ import io.livekit.android.room.participant.RemoteParticipant | ||
| 4 | import livekit.LivekitModels | 4 | import livekit.LivekitModels |
| 5 | import livekit.LivekitRtc | 5 | import livekit.LivekitRtc |
| 6 | 6 | ||
| 7 | -class RemoteTrackPublication(info: LivekitModels.TrackInfo, | ||
| 8 | - track: Track? = null, participant: | ||
| 9 | - RemoteParticipant? = null): TrackPublication(info, track, participant) { | 7 | +class RemoteTrackPublication( |
| 8 | + info: LivekitModels.TrackInfo, | ||
| 9 | + track: Track? = null, | ||
| 10 | + participant: RemoteParticipant | ||
| 11 | +) : TrackPublication(info, track, participant) { | ||
| 10 | 12 | ||
| 11 | private var unsubscribed: Boolean = false | 13 | private var unsubscribed: Boolean = false |
| 12 | private var disabled: Boolean = false | 14 | private var disabled: Boolean = false |
| @@ -25,7 +27,7 @@ class RemoteTrackPublication(info: LivekitModels.TrackInfo, | @@ -25,7 +27,7 @@ class RemoteTrackPublication(info: LivekitModels.TrackInfo, | ||
| 25 | return | 27 | return |
| 26 | } | 28 | } |
| 27 | field = v | 29 | field = v |
| 28 | - val participant = this.participant.get() as? RemoteParticipant ?: return | 30 | + val participant = this.participant as? RemoteParticipant ?: return |
| 29 | if (v) { | 31 | if (v) { |
| 30 | participant.listener?.onTrackMuted(this, participant) | 32 | participant.listener?.onTrackMuted(this, participant) |
| 31 | participant.internalListener?.onTrackMuted(this, participant) | 33 | participant.internalListener?.onTrackMuted(this, participant) |
| @@ -40,7 +42,7 @@ class RemoteTrackPublication(info: LivekitModels.TrackInfo, | @@ -40,7 +42,7 @@ class RemoteTrackPublication(info: LivekitModels.TrackInfo, | ||
| 40 | */ | 42 | */ |
| 41 | fun setSubscribed(subscribed: Boolean) { | 43 | fun setSubscribed(subscribed: Boolean) { |
| 42 | unsubscribed = !subscribed | 44 | unsubscribed = !subscribed |
| 43 | - val participant = this.participant.get() as? RemoteParticipant ?: return | 45 | + val participant = this.participant as? RemoteParticipant ?: return |
| 44 | 46 | ||
| 45 | participant.rtcClient.sendUpdateSubscription(sid, !unsubscribed, videoQuality) | 47 | participant.rtcClient.sendUpdateSubscription(sid, !unsubscribed, videoQuality) |
| 46 | } | 48 | } |
| @@ -68,7 +70,7 @@ class RemoteTrackPublication(info: LivekitModels.TrackInfo, | @@ -68,7 +70,7 @@ class RemoteTrackPublication(info: LivekitModels.TrackInfo, | ||
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | private fun sendUpdateTrackSettings() { | 72 | private fun sendUpdateTrackSettings() { |
| 71 | - val participant = this.participant.get() as? RemoteParticipant ?: return | 73 | + val participant = this.participant as? RemoteParticipant ?: return |
| 72 | 74 | ||
| 73 | participant.rtcClient.sendUpdateTrackSettings(sid, disabled, videoQuality) | 75 | participant.rtcClient.sendUpdateTrackSettings(sid, disabled, videoQuality) |
| 74 | } | 76 | } |
| @@ -2,9 +2,12 @@ package io.livekit.android.room.track | @@ -2,9 +2,12 @@ package io.livekit.android.room.track | ||
| 2 | 2 | ||
| 3 | import io.livekit.android.room.participant.Participant | 3 | import io.livekit.android.room.participant.Participant |
| 4 | import livekit.LivekitModels | 4 | import livekit.LivekitModels |
| 5 | -import java.lang.ref.WeakReference | ||
| 6 | 5 | ||
| 7 | -open class TrackPublication(info: LivekitModels.TrackInfo, track: Track?, participant: Participant?) { | 6 | +open class TrackPublication( |
| 7 | + info: LivekitModels.TrackInfo, | ||
| 8 | + track: Track?, | ||
| 9 | + participant: Participant | ||
| 10 | +) { | ||
| 8 | var track: Track? = track | 11 | var track: Track? = track |
| 9 | internal set | 12 | internal set |
| 10 | var name: String | 13 | var name: String |
| @@ -20,14 +23,14 @@ open class TrackPublication(info: LivekitModels.TrackInfo, track: Track?, partic | @@ -20,14 +23,14 @@ open class TrackPublication(info: LivekitModels.TrackInfo, track: Track?, partic | ||
| 20 | return track != null | 23 | return track != null |
| 21 | } | 24 | } |
| 22 | 25 | ||
| 23 | - var participant: WeakReference<Participant>; | 26 | + var participant: Participant |
| 24 | 27 | ||
| 25 | init { | 28 | init { |
| 26 | sid = info.sid | 29 | sid = info.sid |
| 27 | name = info.name | 30 | name = info.name |
| 28 | kind = info.type | 31 | kind = info.type |
| 29 | muted = info.muted | 32 | muted = info.muted |
| 30 | - this.participant = WeakReference(participant) | 33 | + this.participant = participant |
| 31 | } | 34 | } |
| 32 | 35 | ||
| 33 | fun updateFromInfo(info: LivekitModels.TrackInfo) { | 36 | fun updateFromInfo(info: LivekitModels.TrackInfo) { |
| 1 | package io.livekit.android.room.participant | 1 | package io.livekit.android.room.participant |
| 2 | 2 | ||
| 3 | +import io.livekit.android.room.track.TrackPublication | ||
| 3 | import livekit.LivekitModels | 4 | import livekit.LivekitModels |
| 4 | import org.junit.Assert.assertEquals | 5 | import org.junit.Assert.assertEquals |
| 5 | import org.junit.Assert.assertTrue | 6 | import org.junit.Assert.assertTrue |
| @@ -23,6 +24,7 @@ class ParticipantTest { | @@ -23,6 +24,7 @@ class ParticipantTest { | ||
| 23 | assertEquals(INFO.sid, participant.sid) | 24 | assertEquals(INFO.sid, participant.sid) |
| 24 | assertEquals(INFO.identity, participant.identity) | 25 | assertEquals(INFO.identity, participant.identity) |
| 25 | assertEquals(INFO.metadata, participant.metadata) | 26 | assertEquals(INFO.metadata, participant.metadata) |
| 27 | + assertEquals(INFO, participant.participantInfo) | ||
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | @Test | 30 | @Test |
| @@ -59,11 +61,29 @@ class ParticipantTest { | @@ -59,11 +61,29 @@ class ParticipantTest { | ||
| 59 | 61 | ||
| 60 | } | 62 | } |
| 61 | 63 | ||
| 64 | + @Test | ||
| 65 | + fun addTrackPublication() { | ||
| 66 | + val audioPublication = TrackPublication(TRACK_INFO, null, participant) | ||
| 67 | + participant.addTrackPublication(audioPublication) | ||
| 68 | + | ||
| 69 | + assertEquals(1, participant.tracks.values.size) | ||
| 70 | + assertEquals(audioPublication, participant.tracks.values.first()) | ||
| 71 | + assertEquals(1, participant.audioTracks.values.size) | ||
| 72 | + assertEquals(audioPublication, participant.audioTracks.values.first()) | ||
| 73 | + } | ||
| 74 | + | ||
| 62 | companion object { | 75 | companion object { |
| 63 | val INFO = LivekitModels.ParticipantInfo.newBuilder() | 76 | val INFO = LivekitModels.ParticipantInfo.newBuilder() |
| 64 | .setSid("sid") | 77 | .setSid("sid") |
| 65 | .setIdentity("identity") | 78 | .setIdentity("identity") |
| 66 | .setMetadata("metadata") | 79 | .setMetadata("metadata") |
| 67 | .build() | 80 | .build() |
| 81 | + | ||
| 82 | + val TRACK_INFO = LivekitModels.TrackInfo.newBuilder() | ||
| 83 | + .setSid("sid") | ||
| 84 | + .setName("name") | ||
| 85 | + .setType(LivekitModels.TrackType.AUDIO) | ||
| 86 | + .setMuted(false) | ||
| 87 | + .build() | ||
| 68 | } | 88 | } |
| 69 | } | 89 | } |
| 1 | package io.livekit.android.room.participant | 1 | package io.livekit.android.room.participant |
| 2 | 2 | ||
| 3 | +import io.livekit.android.room.RTCClient | ||
| 4 | +import livekit.LivekitModels | ||
| 5 | +import org.junit.Assert.assertEquals | ||
| 6 | +import org.junit.Assert.assertNotNull | ||
| 7 | +import org.junit.Before | ||
| 3 | import org.junit.Test | 8 | import org.junit.Test |
| 4 | - | ||
| 5 | -import org.junit.Assert.* | 9 | +import org.mockito.Mockito |
| 6 | 10 | ||
| 7 | class RemoteParticipantTest { | 11 | class RemoteParticipantTest { |
| 12 | + | ||
| 13 | + lateinit var participant: RemoteParticipant | ||
| 14 | + | ||
| 15 | + @Before | ||
| 16 | + fun setup() { | ||
| 17 | + val rtcClient = Mockito.mock(RTCClient::class.java) | ||
| 18 | + participant = RemoteParticipant(rtcClient, "sid") | ||
| 19 | + } | ||
| 20 | + | ||
| 8 | @Test | 21 | @Test |
| 9 | - fun addition_isCorrect() { | ||
| 10 | - assertEquals(4, 2 + 2) | 22 | + fun updateFromInfoAddsTrack() { |
| 23 | + val newTrackInfo = LivekitModels.ParticipantInfo.newBuilder(INFO) | ||
| 24 | + .addTracks(TRACK_INFO) | ||
| 25 | + .build() | ||
| 26 | + | ||
| 27 | + participant.updateFromInfo(newTrackInfo) | ||
| 28 | + | ||
| 29 | + assertEquals(1, participant.tracks.values.size) | ||
| 30 | + assertNotNull(participant.getTrackPublication(TRACK_INFO.sid)) | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + companion object { | ||
| 35 | + val INFO = LivekitModels.ParticipantInfo.newBuilder() | ||
| 36 | + .setSid("sid") | ||
| 37 | + .setIdentity("identity") | ||
| 38 | + .setMetadata("metadata") | ||
| 39 | + .build() | ||
| 40 | + | ||
| 41 | + val TRACK_INFO = LivekitModels.TrackInfo.newBuilder() | ||
| 42 | + .setSid("sid") | ||
| 43 | + .setName("name") | ||
| 44 | + .setType(LivekitModels.TrackType.AUDIO) | ||
| 45 | + .setMuted(false) | ||
| 46 | + .build() | ||
| 11 | } | 47 | } |
| 12 | } | 48 | } |
| 1 | +mock-maker-inline |
-
请 注册 或 登录 后发表评论