diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 63afd88..6b208c2 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -682,11 +682,10 @@ constructor( return mapping } - fun selectTrackEncoding(peerId: String, trackId: String, encoding: TrackEncoding) { + fun setTargetTrackEncoding(trackId: String, encoding: TrackEncoding) { coroutineScope.launch { transport.send( SelectEncoding( - peerId, trackId, encoding.rid ) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/MembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/MembraneRTC.kt index 7182cea..863e6cf 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/MembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/MembraneRTC.kt @@ -105,14 +105,17 @@ private constructor( } /** - * Selects track encoding that server should send to the client library. + * Sets track encoding that server should send to the client library. + * + * The encoding will be sent whenever it is available. + * If chosen encoding is temporarily unavailable, some other encoding + * will be sent until chosen encoding becomes active again. * - * @param peerId: an id of a peer that owns the track * @param trackId: an id of a remote track * @param encoding: an encoding to receive */ - public fun selectTrackEncoding(peerId: String, trackId: String, encoding: TrackEncoding) { - client.selectTrackEncoding(peerId, trackId, encoding) + public fun setTargetTrackEncoding(trackId: String, encoding: TrackEncoding) { + client.setTargetTrackEncoding(trackId, encoding) } /** diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt index de33c86..70d06e0 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -70,11 +70,15 @@ data class RenegotiateTracks(val type: String, val data: Payload): SendableEvent ) } -data class SelectEncoding(val type: String, val data: Data): SendableEvent() { - data class Data(val peerId: String, val trackId: String, val encoding: String) - - constructor(peerId: String, trackId: String, encoding: String): - this("selectEncoding", Data(peerId, trackId, encoding)) +data class SelectEncoding(val type: String, val data: Payload): SendableEvent() { + constructor(trackId: String, encoding: String): + this("custom", mapOf( + "type" to "setTargetTrackVariant", + "data" to mapOf( + "trackId" to trackId, + "variant" to encoding + ) + )) } data class UpdatePeerMetadata(val type: String, val data: Data): SendableEvent() { diff --git a/app/src/main/java/com/dscout/membranevideoroomdemo/viewmodels/RoomViewModel.kt b/app/src/main/java/com/dscout/membranevideoroomdemo/viewmodels/RoomViewModel.kt index 994f2fa..9335d09 100644 --- a/app/src/main/java/com/dscout/membranevideoroomdemo/viewmodels/RoomViewModel.kt +++ b/app/src/main/java/com/dscout/membranevideoroomdemo/viewmodels/RoomViewModel.kt @@ -95,13 +95,13 @@ public class RoomViewModel( val primaryParticipantTrackId = primaryParticipant.value?.videoTrack?.id() if(localVideoTrack?.id() != primaryParticipantTrackId && localScreencastTrack?.id() != primaryParticipantTrackId) { val globalId = globalToLocalTrackId.filterValues { it1 -> it1 == primaryParticipantTrackId }.keys.first() - primaryParticipant.value?.id?.let { it1 -> room.value?.selectTrackEncoding(it1, globalId, TrackEncoding.L) } + room.value?.setTargetTrackEncoding(globalId, TrackEncoding.L) } primaryParticipant.value = it val videoTrackId = it.videoTrack?.id() if(localVideoTrack?.id() != it.videoTrack?.id() && localScreencastTrack?.id() != videoTrackId) { val globalId = globalToLocalTrackId.filterValues { it1 -> it1 == it.videoTrack?.id() }.keys.first() - room.value?.selectTrackEncoding(participantId, globalId, TrackEncoding.H) + room.value?.setTargetTrackEncoding(globalId, TrackEncoding.H) } participants.value = candidates.filter { candidate ->