From 59ad94ff59c874a6f3792216aa95185064317219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Mon, 8 Jan 2024 17:57:55 +0100 Subject: [PATCH 01/22] add simulcast confit to added track event --- .idea/gradle.xml | 5 ++--- .idea/inspectionProfiles/Project_Default.xml | 4 ++++ .../org/membraneframework/rtc/InternalMembraneRTC.kt | 11 ++++++----- .../membraneframework/rtc/RTCEngineCommunication.kt | 4 ++-- .../org/membraneframework/rtc/RTCEngineListener.kt | 3 ++- .../java/org/membraneframework/rtc/events/Event.kt | 5 ++++- .../java/org/membraneframework/rtc/models/Endpoint.kt | 4 +++- .../org/membraneframework/rtc/models/TrackContext.kt | 6 +++++- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 0b1f53f..c6e9676 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,10 +4,8 @@ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 7f41d7c..44ca2d9 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -7,6 +7,7 @@ \ No newline at end of file diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 7c2f8e5..b6ee372 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.membraneframework.rtc.events.OfferData +import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.media.* import org.membraneframework.rtc.models.EncodingReason import org.membraneframework.rtc.models.Endpoint @@ -48,7 +49,7 @@ constructor( ) private var localEndpoint: Endpoint = - Endpoint(id = "", type = "webrtc", metadata = mapOf(), trackIdToMetadata = mapOf()) + Endpoint(id = "", type = "webrtc", metadata = mapOf(), trackIdToMetadata = mapOf(), tracks = mapOf()) // mapping from endpoint's id to the endpoint himself private val remoteEndpoints = HashMap() @@ -230,7 +231,7 @@ constructor( this.remoteEndpoints[it.id] = it for ((trackId, metadata) in it.trackIdToMetadata) { - val context = TrackContext(track = null, endpoint = it, trackId = trackId, metadata = metadata) + val context = TrackContext(track = null, endpoint = it, trackId = trackId, metadata = metadata, simulcastConfig = it.tracks[trackId]?.simulcastConfig) this.trackContexts[trackId] = context @@ -337,7 +338,7 @@ constructor( } } - override fun onTracksAdded(endpointId: String, trackIdToMetadata: Map) { + override fun onTracksAdded(endpointId: String, trackIdToMetadata: Map, tracks: Map) { if (localEndpoint.id == endpointId) return val endpoint = remoteEndpoints.remove(endpointId) ?: run { @@ -345,12 +346,12 @@ constructor( return } - val updatedEndpoint = endpoint.copy(trackIdToMetadata = trackIdToMetadata) + val updatedEndpoint = endpoint.copy(trackIdToMetadata = trackIdToMetadata, tracks = tracks) remoteEndpoints[updatedEndpoint.id] = updatedEndpoint for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { - val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata) + val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata, simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig) this.trackContexts[trackId] = context diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt index 10f18d7..0a179ca 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt @@ -100,7 +100,7 @@ constructor( is OfferData -> engineListener.onOfferData(event.data.integratedTurnServers, event.data.tracksTypes) is EndpointRemoved -> engineListener.onEndpointRemoved(event.data.id) is EndpointAdded -> engineListener.onEndpointAdded( - Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf()) + Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf(), mapOf()) ) is EndpointUpdated -> engineListener.onEndpointUpdated(event.data.id, event.data.metadata) is RemoteCandidate -> engineListener.onRemoteCandidate( @@ -114,7 +114,7 @@ constructor( event.data.trackId, event.data.metadata ) - is TracksAdded -> engineListener.onTracksAdded(event.data.endpointId, event.data.trackIdToMetadata) + is TracksAdded -> engineListener.onTracksAdded(event.data.endpointId, event.data.trackIdToMetadata, event.data.tracks) is TracksRemoved -> engineListener.onTracksRemoved(event.data.endpointId, event.data.trackIds) is EncodingSwitched -> engineListener.onTrackEncodingChanged( event.data.endpointId, diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt index b51f9ab..6af47c2 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt @@ -1,6 +1,7 @@ package org.membraneframework.rtc import org.membraneframework.rtc.events.OfferData +import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.models.Endpoint import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.SerializedMediaEvent @@ -14,7 +15,7 @@ internal interface RTCEngineListener { fun onOfferData(integratedTurnServers: List, tracksTypes: Map) fun onSdpAnswer(type: String, sdp: String, midToTrackId: Map) fun onRemoteCandidate(candidate: String, sdpMLineIndex: Int, sdpMid: String?) - fun onTracksAdded(endpointId: String, trackIdToMetadata: Map) + fun onTracksAdded(endpointId: String, trackIdToMetadata: Map, tracks: Map) fun onTracksRemoved(endpointId: String, trackIds: List) fun onTrackUpdated(endpointId: String, trackId: String, metadata: Metadata) fun onTrackEncodingChanged(endpointId: String, trackId: String, encoding: String, encodingReason: String) 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 7d1baa3..887c7f6 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -4,6 +4,7 @@ import com.google.gson.Gson import com.google.gson.JsonParseException import com.google.gson.annotations.SerializedName import com.google.gson.reflect.TypeToken +import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.models.Endpoint import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.Payload @@ -255,7 +256,9 @@ data class OfferData(val type: ReceivableEventType, val data: Data) : Receivable } data class TracksAdded(val type: ReceivableEventType, val data: Data) : ReceivableEvent() { - data class Data(val endpointId: String, val trackIdToMetadata: Map) + data class Data(val endpointId: String, val trackIdToMetadata: Map, val tracks: Map){ + data class TrackData(val metadata: Metadata, val simulcastConfig: SimulcastConfig) + } } data class TracksRemoved(val type: ReceivableEventType, val data: Data) : ReceivableEvent() { diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt index 7b9702f..bbc31b2 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt @@ -1,12 +1,14 @@ package org.membraneframework.rtc.models +import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.utils.Metadata data class Endpoint( val id: String, val type: String, val metadata: Metadata = mapOf(), - val trackIdToMetadata: Map = mapOf() + val trackIdToMetadata: Map = mapOf(), + val tracks: Map, ) { fun withTrack(trackId: String, metadata: Metadata?): Endpoint { val newTrackIdToMetadata = this.trackIdToMetadata.toMutableMap() diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt index 0cad3bb..6171bfa 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt @@ -1,5 +1,6 @@ package org.membraneframework.rtc.models +import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.TrackEncoding import org.membraneframework.rtc.media.RemoteTrack import org.membraneframework.rtc.utils.Metadata @@ -19,7 +20,7 @@ fun interface OnVoiceActivityChangedListener { * @property trackId Track id. It is generated by RTC engine and takes form `endpoint_id:`. * @property metadata Any info that was passed in MembraneWebRTC.createVideoTrack/MembraneWebRTC.createAudioTrack */ -class TrackContext(track: RemoteTrack?, val endpoint: Endpoint, val trackId: String, metadata: Metadata) { +class TrackContext(track: RemoteTrack?, val endpoint: Endpoint, val trackId: String, metadata: Metadata, simulcastConfig: SimulcastConfig?) { private var onTrackEncodingChangeListener: (OnEncodingChangedListener)? = null private var onVadNotificationListener: (OnVoiceActivityChangedListener)? = null @@ -28,6 +29,9 @@ class TrackContext(track: RemoteTrack?, val endpoint: Endpoint, val trackId: Str var metadata: Metadata = metadata internal set + var simulcastConfig: SimulcastConfig? = simulcastConfig + internal set + var vadStatus: VadStatus = VadStatus.SILENCE internal set(value) { field = value From d536baa9bdb3a0cdbb85e16ecf77b466b58b4d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Tue, 9 Jan 2024 14:41:02 +0100 Subject: [PATCH 02/22] add temp logging --- .../java/org/membraneframework/rtc/InternalMembraneRTC.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index b6ee372..cecf559 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -2,6 +2,7 @@ package org.membraneframework.rtc import android.content.Context import android.content.Intent +import android.util.Log import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject @@ -229,6 +230,7 @@ constructor( otherEndpoints.forEach { this.remoteEndpoints[it.id] = it + Timber.tag("AAA").d(it.toString()) for ((trackId, metadata) in it.trackIdToMetadata) { val context = TrackContext(track = null, endpoint = it, trackId = trackId, metadata = metadata, simulcastConfig = it.tracks[trackId]?.simulcastConfig) @@ -351,8 +353,10 @@ constructor( remoteEndpoints[updatedEndpoint.id] = updatedEndpoint for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { - val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata, simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig) + + val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata, simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig) + Timber.tag("AAA").d(context.toString()) this.trackContexts[trackId] = context this.listener.onTrackAdded(context) From f4297bd983a3a15262b719e85825be6aa4b40774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 10 Jan 2024 18:24:38 +0100 Subject: [PATCH 03/22] make simulcastConfig nulable in TracksAdded --- .../java/org/membraneframework/rtc/InternalMembraneRTC.kt | 5 +---- .../src/main/java/org/membraneframework/rtc/events/Event.kt | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index cecf559..212464f 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -230,7 +230,6 @@ constructor( otherEndpoints.forEach { this.remoteEndpoints[it.id] = it - Timber.tag("AAA").d(it.toString()) for ((trackId, metadata) in it.trackIdToMetadata) { val context = TrackContext(track = null, endpoint = it, trackId = trackId, metadata = metadata, simulcastConfig = it.tracks[trackId]?.simulcastConfig) @@ -353,10 +352,8 @@ constructor( remoteEndpoints[updatedEndpoint.id] = updatedEndpoint for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { - - val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata, simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig) - Timber.tag("AAA").d(context.toString()) + this.trackContexts[trackId] = context this.listener.onTrackAdded(context) 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 887c7f6..25ff52a 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -257,7 +257,7 @@ data class OfferData(val type: ReceivableEventType, val data: Data) : Receivable data class TracksAdded(val type: ReceivableEventType, val data: Data) : ReceivableEvent() { data class Data(val endpointId: String, val trackIdToMetadata: Map, val tracks: Map){ - data class TrackData(val metadata: Metadata, val simulcastConfig: SimulcastConfig) + data class TrackData(val metadata: Metadata, val simulcastConfig: SimulcastConfig?) } } From 1dfa549f4fef1d90a527c9638bc9395241c28e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 10 Jan 2024 19:27:06 +0100 Subject: [PATCH 04/22] make simulcastConfig nulable in TracksAdded v1 --- .../main/java/org/membraneframework/rtc/InternalMembraneRTC.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 212464f..6568a23 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -352,6 +352,7 @@ constructor( remoteEndpoints[updatedEndpoint.id] = updatedEndpoint for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { + Log.d("AAA", "${updatedEndpoint.tracks[trackId]?.simulcastConfig?.enabled} ${updatedEndpoint.tracks[trackId]?.simulcastConfig?.activeEncodings}") val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata, simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig) this.trackContexts[trackId] = context From d4920c7aaedbc56136bef7167b01d3cba7a94471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 10 Jan 2024 19:55:28 +0100 Subject: [PATCH 05/22] make simulcastConfig nulable in TracksAdded v2 --- .../org/membraneframework/rtc/RTCEngineCommunication.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt index 0a179ca..9d69de1 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt @@ -1,5 +1,6 @@ package org.membraneframework.rtc +import android.util.Log import com.google.gson.reflect.TypeToken import dagger.assisted.Assisted import dagger.assisted.AssistedFactory @@ -95,7 +96,12 @@ constructor( } fun onEvent(serializedEvent: SerializedMediaEvent) { - when (val event = decodeEvent(serializedEvent)) { + Log.d("AAA","Before serialization" + serializedEvent) + val event = decodeEvent(serializedEvent) + Log.d("AAA", event?.javaClass?.toString() ?: "not possible to obtain class") + Log.d("AAA", event?.toString()?: "not possible to string") + + when (event) { is Connected -> engineListener.onConnected(event.data.id, event.data.otherEndpoints) is OfferData -> engineListener.onOfferData(event.data.integratedTurnServers, event.data.tracksTypes) is EndpointRemoved -> engineListener.onEndpointRemoved(event.data.id) From d9e820dfbdc7c9250faf4995db29cfcec7d8b381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 10 Jan 2024 20:12:10 +0100 Subject: [PATCH 06/22] make simulcastConfig nulable in TracksAdded v3 --- .../java/org/membraneframework/rtc/SimulcastConfig.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt index 2a33dd0..ab73d77 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt @@ -1,5 +1,7 @@ package org.membraneframework.rtc +import com.google.gson.annotations.SerializedName + /** * Enum describing possible track encodings. * `"h"` - original encoding @@ -7,7 +9,12 @@ package org.membraneframework.rtc * `"l"` - original encoding scaled down by 4 */ enum class TrackEncoding(val rid: String) { - L("l"), M("m"), H("h"); + @SerializedName("l") + L("l"), + @SerializedName("m") + M("m"), + @SerializedName("h") + H("h"); companion object { fun fromString(s: String): TrackEncoding? { From 38248a6ffa4a4f378d8eddb75c05ce5326625306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Thu, 11 Jan 2024 16:16:45 +0100 Subject: [PATCH 07/22] remove logs --- .../java/org/membraneframework/rtc/InternalMembraneRTC.kt | 1 - .../org/membraneframework/rtc/RTCEngineCommunication.kt | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 6568a23..212464f 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -352,7 +352,6 @@ constructor( remoteEndpoints[updatedEndpoint.id] = updatedEndpoint for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { - Log.d("AAA", "${updatedEndpoint.tracks[trackId]?.simulcastConfig?.enabled} ${updatedEndpoint.tracks[trackId]?.simulcastConfig?.activeEncodings}") val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata, simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig) this.trackContexts[trackId] = context diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt index 9d69de1..9134701 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt @@ -96,12 +96,7 @@ constructor( } fun onEvent(serializedEvent: SerializedMediaEvent) { - Log.d("AAA","Before serialization" + serializedEvent) - val event = decodeEvent(serializedEvent) - Log.d("AAA", event?.javaClass?.toString() ?: "not possible to obtain class") - Log.d("AAA", event?.toString()?: "not possible to string") - - when (event) { + when (val event = decodeEvent(serializedEvent)) { is Connected -> engineListener.onConnected(event.data.id, event.data.otherEndpoints) is OfferData -> engineListener.onOfferData(event.data.integratedTurnServers, event.data.tracksTypes) is EndpointRemoved -> engineListener.onEndpointRemoved(event.data.id) From 41988a5bb72f08c67465780917fcba9f07c27706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Thu, 11 Jan 2024 16:27:46 +0100 Subject: [PATCH 08/22] merge master --- .../main/java/org/membraneframework/rtc/RTCEngineListener.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt index b51f9ab..6af47c2 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt @@ -1,6 +1,7 @@ package org.membraneframework.rtc import org.membraneframework.rtc.events.OfferData +import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.models.Endpoint import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.SerializedMediaEvent @@ -14,7 +15,7 @@ internal interface RTCEngineListener { fun onOfferData(integratedTurnServers: List, tracksTypes: Map) fun onSdpAnswer(type: String, sdp: String, midToTrackId: Map) fun onRemoteCandidate(candidate: String, sdpMLineIndex: Int, sdpMid: String?) - fun onTracksAdded(endpointId: String, trackIdToMetadata: Map) + fun onTracksAdded(endpointId: String, trackIdToMetadata: Map, tracks: Map) fun onTracksRemoved(endpointId: String, trackIds: List) fun onTrackUpdated(endpointId: String, trackId: String, metadata: Metadata) fun onTrackEncodingChanged(endpointId: String, trackId: String, encoding: String, encodingReason: String) From e0ec3e0258bcf5f2fc384c00246c1eb4ecab2d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Tue, 16 Jan 2024 14:20:46 +0100 Subject: [PATCH 09/22] run ktlint --- .../rtc/InternalMembraneRTC.kt | 21 ++++++++++++++++--- .../rtc/RTCEngineCommunication.kt | 7 ++++++- .../rtc/RTCEngineListener.kt | 8 ++++++- .../membraneframework/rtc/SimulcastConfig.kt | 2 ++ .../org/membraneframework/rtc/events/Event.kt | 6 +++++- .../membraneframework/rtc/models/Endpoint.kt | 2 +- .../rtc/models/TrackContext.kt | 8 ++++++- 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 52d58a1..44a90ef 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -249,7 +249,14 @@ internal class InternalMembraneRTC this.remoteEndpoints[it.id] = it for ((trackId, metadata) in it.trackIdToMetadata) { - val context = TrackContext(track = null, endpoint = it, trackId = trackId, metadata = metadata ?: mapOf(), simulcastConfig = it.tracks[trackId]?.simulcastConfig) + val context = + TrackContext( + track = null, + endpoint = it, + trackId = trackId, + metadata = metadata ?: mapOf(), + simulcastConfig = it.tracks[trackId]?.simulcastConfig + ) this.trackContexts[trackId] = context @@ -376,7 +383,8 @@ internal class InternalMembraneRTC override fun onTracksAdded( endpointId: String, trackIdToMetadata: Map, - tracks: Map) { + tracks: Map + ) { if (localEndpoint.id == endpointId) return val endpoint = @@ -390,7 +398,14 @@ internal class InternalMembraneRTC remoteEndpoints[updatedEndpoint.id] = updatedEndpoint for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { - val context = TrackContext(track = null, endpoint = endpoint, trackId = trackId, metadata = metadata ?: mapOf(), simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig) + val context = + TrackContext( + track = null, + endpoint = endpoint, + trackId = trackId, + metadata = metadata ?: mapOf(), + simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig + ) this.trackContexts[trackId] = context diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt index 670436a..c92624f 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt @@ -124,7 +124,12 @@ internal class RTCEngineCommunication event.data.trackId, event.data.metadata ) - is TracksAdded -> engineListener.onTracksAdded(event.data.endpointId, event.data.trackIdToMetadata, event.data.tracks) + is TracksAdded -> + engineListener.onTracksAdded( + event.data.endpointId, + event.data.trackIdToMetadata, + event.data.tracks + ) is TracksRemoved -> engineListener.onTracksRemoved(event.data.endpointId, event.data.trackIds) is EncodingSwitched -> engineListener.onTrackEncodingChanged( diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt index 4a84bed..e780d7b 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt @@ -7,9 +7,15 @@ import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.SerializedMediaEvent internal interface RTCEngineListener { - fun onConnected(endpointID: String, otherEndpoints: List) + fun onConnected( + endpointID: String, + otherEndpoints: List + ) + fun onSendMediaEvent(event: SerializedMediaEvent) + fun onEndpointAdded(endpoint: Endpoint) + fun onEndpointRemoved(endpointId: String) fun onEndpointUpdated( diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt index ab73d77..32defaa 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/SimulcastConfig.kt @@ -11,8 +11,10 @@ import com.google.gson.annotations.SerializedName enum class TrackEncoding(val rid: String) { @SerializedName("l") L("l"), + @SerializedName("m") M("m"), + @SerializedName("h") H("h"); 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 c7d99d7..3acc145 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -261,7 +261,11 @@ data class OfferData(val type: ReceivableEventType, val data: Data) : Receivable } data class TracksAdded(val type: ReceivableEventType, val data: Data) : ReceivableEvent() { - data class Data(val endpointId: String, val trackIdToMetadata: Map, val tracks: Map){ + data class Data( + val endpointId: String, + val trackIdToMetadata: Map, + val tracks: Map + ) { data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) } } diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt index 5a9ea3c..432f119 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt @@ -8,7 +8,7 @@ data class Endpoint( val type: String, val metadata: Metadata? = mapOf(), val trackIdToMetadata: Map = mapOf(), - val tracks: Map, + val tracks: Map ) { fun withTrack( trackId: String, diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt index 03591c7..9c368eb 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt @@ -20,7 +20,13 @@ fun interface OnVoiceActivityChangedListener { * @property trackId Track id. It is generated by RTC engine and takes form `endpoint_id:`. * @property metadata Any info that was passed in MembraneWebRTC.createVideoTrack/MembraneWebRTC.createAudioTrack */ -class TrackContext(track: RemoteTrack?, val endpoint: Endpoint, val trackId: String, metadata: Metadata = mapOf(), simulcastConfig: SimulcastConfig?) { +class TrackContext( + track: RemoteTrack?, + val endpoint: Endpoint, + val trackId: String, + metadata: Metadata = mapOf(), + simulcastConfig: SimulcastConfig? +) { private var onTrackEncodingChangeListener: (OnEncodingChangedListener)? = null private var onVadNotificationListener: (OnVoiceActivityChangedListener)? = null From cd9d5d8f024f7a9fad2540f1a4da08098c80046c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 17:00:43 +0100 Subject: [PATCH 10/22] add .idea folder to git ignore --- .gitignore | 10 +- .idea/.gitignore | 3 - .idea/.name | 1 - .idea/codeStyles/Project.xml | 122 ------------------- .idea/codeStyles/codeStyleConfig.xml | 5 - .idea/compiler.xml | 9 -- .idea/gradle.xml | 20 --- .idea/inspectionProfiles/Project_Default.xml | 41 ------- .idea/jarRepositories.xml | 35 ------ .idea/kotlinc.xml | 6 - .idea/vcs.xml | 6 - 11 files changed, 2 insertions(+), 256 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.name delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/kotlinc.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 30366ac..7245430 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,10 @@ *.iml .gradle /local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml -/.idea/deploymentTargetDropDown.xml -/.idea/misc.xml + .DS_Store /build /captures .externalNativeBuild .cxx +/.idea/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 5126f86..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Membrane Videoroom Demo \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 88ea3aa..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - - - - -
- - - - xmlns:android - - ^$ - - - -
-
- - - - xmlns:.* - - ^$ - - - BY_NAME - -
-
- - - - .*:id - - http://schemas.android.com/apk/res/android - - - -
-
- - - - .*:name - - http://schemas.android.com/apk/res/android - - - -
-
- - - - name - - ^$ - - - -
-
- - - - style - - ^$ - - - -
-
- - - - .* - - ^$ - - - BY_NAME - -
-
- - - - .* - - http://schemas.android.com/apk/res/android - - - ANDROID_ATTRIBUTE_ORDER - -
-
- - - - .* - - .* - - - BY_NAME - -
-
-
-
- - -
-
\ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 79ee123..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index e33b607..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index c6e9676..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 44ca2d9..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 4dcbce1..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 4515aa3..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 0b93cc1fddca81301a9dc9b989febf06248e7a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 17:27:45 +0100 Subject: [PATCH 11/22] add documentation about simulcast config in track context --- .../java/org/membraneframework/rtc/models/TrackContext.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt index 9c368eb..72de21c 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackContext.kt @@ -17,8 +17,10 @@ fun interface OnVoiceActivityChangedListener { * Track's context i.e. all data that can be useful when operating on track. * * @property endpoint Endpoint this track comes from. - * @property trackId Track id. It is generated by RTC engine and takes form `endpoint_id:`. + * @property trackId Track id. It is generated by RTC engine and takes form `endpoint_id:`. * @property metadata Any info that was passed in MembraneWebRTC.createVideoTrack/MembraneWebRTC.createAudioTrack + * @property simulcastConfig Information about simulcast for given track + * */ class TrackContext( track: RemoteTrack?, From df2d63f6b6ca26deaa27c1139739295cdc48b5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:06:30 +0100 Subject: [PATCH 12/22] remove unnecesary track id to metadata property and export TrackData to separate file --- .../rtc/InternalMembraneRTC.kt | 24 +++++++++---------- .../rtc/RTCEngineCommunication.kt | 3 +-- .../rtc/RTCEngineListener.kt | 4 ++-- .../org/membraneframework/rtc/events/Event.kt | 8 +++---- .../membraneframework/rtc/models/Endpoint.kt | 17 +++++++------ .../membraneframework/rtc/models/TrackData.kt | 8 +++++++ 6 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 44a90ef..063e569 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -15,6 +15,7 @@ import org.membraneframework.rtc.models.EncodingReason import org.membraneframework.rtc.models.Endpoint import org.membraneframework.rtc.models.RTCStats import org.membraneframework.rtc.models.TrackContext +import org.membraneframework.rtc.models.TrackData import org.membraneframework.rtc.models.VadStatus import org.membraneframework.rtc.utils.ClosableCoroutineScope import org.membraneframework.rtc.utils.Metadata @@ -50,7 +51,7 @@ internal class InternalMembraneRTC ) private var localEndpoint: Endpoint = - Endpoint(id = "", type = "webrtc", metadata = mapOf(), trackIdToMetadata = mapOf(), tracks = mapOf()) + Endpoint(id = "", type = "webrtc", metadata = mapOf(), tracks = mapOf()) // mapping from endpoint's id to the endpoint himself private val remoteEndpoints = HashMap() @@ -248,14 +249,14 @@ internal class InternalMembraneRTC otherEndpoints.forEach { this.remoteEndpoints[it.id] = it - for ((trackId, metadata) in it.trackIdToMetadata) { + for ((trackId, trackData) in it.tracks) { val context = TrackContext( track = null, endpoint = it, trackId = trackId, - metadata = metadata ?: mapOf(), - simulcastConfig = it.tracks[trackId]?.simulcastConfig + metadata = trackData.metadata ?: mapOf(), + simulcastConfig = trackData.simulcastConfig ) this.trackContexts[trackId] = context @@ -290,7 +291,7 @@ internal class InternalMembraneRTC return } - val trackIds: List = endpoint.trackIdToMetadata.keys.toList() + val trackIds: List = endpoint.tracks.keys.toList() trackIds.forEach { trackContexts.remove(it)?.let { ctx -> @@ -326,7 +327,7 @@ internal class InternalMembraneRTC } rtcEngineCommunication.sdpOffer( offer.description, - localEndpoint.trackIdToMetadata, + localEndpoint.tracks.mapValues { it.value.metadata }, offer.midToTrackIdMapping ) } catch (e: Exception) { @@ -382,8 +383,7 @@ internal class InternalMembraneRTC override fun onTracksAdded( endpointId: String, - trackIdToMetadata: Map, - tracks: Map + tracks: Map ) { if (localEndpoint.id == endpointId) return @@ -393,18 +393,18 @@ internal class InternalMembraneRTC return } - val updatedEndpoint = endpoint.copy(trackIdToMetadata = trackIdToMetadata, tracks = tracks) + val updatedEndpoint = endpoint.copy(tracks = tracks) remoteEndpoints[updatedEndpoint.id] = updatedEndpoint - for ((trackId, metadata) in updatedEndpoint.trackIdToMetadata) { + for ((trackId, trackData) in updatedEndpoint.tracks) { val context = TrackContext( track = null, endpoint = endpoint, trackId = trackId, - metadata = metadata ?: mapOf(), - simulcastConfig = updatedEndpoint.tracks[trackId]?.simulcastConfig + metadata = trackData.metadata ?: mapOf(), + simulcastConfig = trackData.simulcastConfig ) this.trackContexts[trackId] = context diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt index c92624f..3ffd7d8 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineCommunication.kt @@ -108,7 +108,7 @@ internal class RTCEngineCommunication is EndpointRemoved -> engineListener.onEndpointRemoved(event.data.id) is EndpointAdded -> engineListener.onEndpointAdded( - Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf(), mapOf()) + Endpoint(event.data.id, event.data.type, event.data.metadata, mapOf()) ) is EndpointUpdated -> engineListener.onEndpointUpdated(event.data.id, event.data.metadata) is RemoteCandidate -> @@ -127,7 +127,6 @@ internal class RTCEngineCommunication is TracksAdded -> engineListener.onTracksAdded( event.data.endpointId, - event.data.trackIdToMetadata, event.data.tracks ) is TracksRemoved -> engineListener.onTracksRemoved(event.data.endpointId, event.data.trackIds) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt index e780d7b..f634b61 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt @@ -3,6 +3,7 @@ package org.membraneframework.rtc import org.membraneframework.rtc.events.OfferData import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.models.Endpoint +import org.membraneframework.rtc.models.TrackData import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.SerializedMediaEvent @@ -42,8 +43,7 @@ internal interface RTCEngineListener { fun onTracksAdded( endpointId: String, - trackIdToMetadata: Map, - tracks: Map + tracks: Map ) fun onTracksRemoved( 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 3acc145..6137f57 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -6,6 +6,7 @@ import com.google.gson.annotations.SerializedName import com.google.gson.reflect.TypeToken import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.models.Endpoint +import org.membraneframework.rtc.models.TrackData import org.membraneframework.rtc.utils.Metadata import org.membraneframework.rtc.utils.Payload import timber.log.Timber @@ -236,7 +237,7 @@ data class EndpointAdded(val type: ReceivableEventType, val data: Data) : Receiv val id: String, val type: String, val metadata: Metadata?, - val trackIdToMetadata: Map + val tracks: Map ) } @@ -263,11 +264,8 @@ data class OfferData(val type: ReceivableEventType, val data: Data) : Receivable data class TracksAdded(val type: ReceivableEventType, val data: Data) : ReceivableEvent() { data class Data( val endpointId: String, - val trackIdToMetadata: Map, val tracks: Map - ) { - data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) - } + ) } data class TracksRemoved(val type: ReceivableEventType, val data: Data) : ReceivableEvent() { diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt index 432f119..90fd812 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt @@ -1,27 +1,26 @@ package org.membraneframework.rtc.models -import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.utils.Metadata data class Endpoint( val id: String, val type: String, val metadata: Metadata? = mapOf(), - val trackIdToMetadata: Map = mapOf(), - val tracks: Map + val tracks: Map = mapOf(), ) { fun withTrack( trackId: String, metadata: Metadata? ): Endpoint { - val newTrackIdToMetadata = this.trackIdToMetadata.toMutableMap() - newTrackIdToMetadata[trackId] = metadata ?: mapOf() - return this.copy(trackIdToMetadata = newTrackIdToMetadata) + val tracks = this.tracks.toMutableMap() + val trackData = tracks[trackId] + tracks[trackId] = TrackData(metadata = metadata, simulcastConfig = trackData?.simulcastConfig); + return this.copy(tracks = tracks) } fun withoutTrack(trackId: String): Endpoint { - val newTrackIdToMetadata = this.trackIdToMetadata.toMutableMap() - newTrackIdToMetadata.remove(trackId) - return this.copy(trackIdToMetadata = newTrackIdToMetadata) + val tracks = this.tracks.toMutableMap() + tracks.remove(trackId) + return this.copy(tracks = tracks) } } diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt new file mode 100644 index 0000000..55c283f --- /dev/null +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -0,0 +1,8 @@ +package org.membraneframework.rtc.models + +import org.membraneframework.rtc.SimulcastConfig +import org.membraneframework.rtc.utils.Metadata + +data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?){ + +} From cbf1f6b0fedb0d493ac838a773c1edc8067bbb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:07:50 +0100 Subject: [PATCH 13/22] reformat code --- .../java/org/membraneframework/rtc/InternalMembraneRTC.kt | 1 - .../main/java/org/membraneframework/rtc/RTCEngineListener.kt | 1 - .../src/main/java/org/membraneframework/rtc/events/Event.kt | 1 - .../main/java/org/membraneframework/rtc/models/Endpoint.kt | 4 ++-- .../main/java/org/membraneframework/rtc/models/TrackData.kt | 3 +-- 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt index 063e569..4652da9 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/InternalMembraneRTC.kt @@ -9,7 +9,6 @@ import kotlinx.coroutines.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.membraneframework.rtc.events.OfferData -import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.media.* import org.membraneframework.rtc.models.EncodingReason import org.membraneframework.rtc.models.Endpoint diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt index f634b61..a5b2734 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/RTCEngineListener.kt @@ -1,7 +1,6 @@ package org.membraneframework.rtc import org.membraneframework.rtc.events.OfferData -import org.membraneframework.rtc.events.TracksAdded import org.membraneframework.rtc.models.Endpoint import org.membraneframework.rtc.models.TrackData import org.membraneframework.rtc.utils.Metadata 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 6137f57..cd1881d 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt @@ -4,7 +4,6 @@ import com.google.gson.Gson import com.google.gson.JsonParseException import com.google.gson.annotations.SerializedName import com.google.gson.reflect.TypeToken -import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.models.Endpoint import org.membraneframework.rtc.models.TrackData import org.membraneframework.rtc.utils.Metadata diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt index 90fd812..0fbd4fa 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/Endpoint.kt @@ -6,7 +6,7 @@ data class Endpoint( val id: String, val type: String, val metadata: Metadata? = mapOf(), - val tracks: Map = mapOf(), + val tracks: Map = mapOf() ) { fun withTrack( trackId: String, @@ -14,7 +14,7 @@ data class Endpoint( ): Endpoint { val tracks = this.tracks.toMutableMap() val trackData = tracks[trackId] - tracks[trackId] = TrackData(metadata = metadata, simulcastConfig = trackData?.simulcastConfig); + tracks[trackId] = TrackData(metadata = metadata, simulcastConfig = trackData?.simulcastConfig) return this.copy(tracks = tracks) } diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index 55c283f..a1b15b3 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -3,6 +3,5 @@ package org.membraneframework.rtc.models import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.utils.Metadata -data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?){ - +data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) { } From 9e343873c6ceaed5a368eece9a85b2751fb253a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:09:24 +0100 Subject: [PATCH 14/22] reformat code --- .../main/java/org/membraneframework/rtc/models/TrackData.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index a1b15b3..354d0d4 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -3,5 +3,4 @@ package org.membraneframework.rtc.models import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.utils.Metadata -data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) { -} +data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) From 32ca45d8a1b77b53a346ccbbf1283dd27ae3555d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:18:46 +0100 Subject: [PATCH 15/22] test1 --- .githooks/pre-commit | 14 +++++++++----- .../org/membraneframework/rtc/models/TrackData.kt | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 1dcab99..292811c 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,7 +1,11 @@ #!/bin/bash # https://github.com/pinterest/ktlint pre-commit hook -# On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists -[ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty -git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative --format -if [ $? -ne 0 ]; then exit 1; fi -git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty git add +echo "Running ktlint" +git diff --name-only --cached --relative --diff-filter=ACMT "*.kt" "*.kts" | xargs -0 ./ktlint --relative --format +if [ $? -ne 0 ]; then + echo "ktlint check failed" + exit 1 +else + echo "ktlint check passed" + git diff --name-only --cached --relative --diff-filter=ACMT "*.kt" "*.kts" | xargs -0 git add +fi \ No newline at end of file diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index 354d0d4..55c283f 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -3,4 +3,6 @@ package org.membraneframework.rtc.models import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.utils.Metadata -data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) +data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?){ + +} From 93a528468ab8ace9270980228138370d5a404ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:23:58 +0100 Subject: [PATCH 16/22] test2 --- .githooks/pre-commit | 14 +++++--------- .../org/membraneframework/rtc/models/TrackData.kt | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 292811c..eb6929c 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,11 +1,7 @@ #!/bin/bash # https://github.com/pinterest/ktlint pre-commit hook -echo "Running ktlint" -git diff --name-only --cached --relative --diff-filter=ACMT "*.kt" "*.kts" | xargs -0 ./ktlint --relative --format -if [ $? -ne 0 ]; then - echo "ktlint check failed" - exit 1 -else - echo "ktlint check passed" - git diff --name-only --cached --relative --diff-filter=ACMT "*.kt" "*.kts" | xargs -0 git add -fi \ No newline at end of file +# On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists +[ "$(uname -s)" == "Darwin" ] && no_run_if_empty=--no-run-if-empty +git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative --format +if [ $? -ne 0 ]; then exit 1; fi +git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty git add diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index 55c283f..a98bd50 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -6,3 +6,4 @@ import org.membraneframework.rtc.utils.Metadata data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?){ } + From 513303e3a7cc677037290fe5018e4de5ceead1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:26:05 +0100 Subject: [PATCH 17/22] test2 --- .githooks/pre-commit | 2 +- .../src/main/java/org/membraneframework/rtc/models/TrackData.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit old mode 100644 new mode 100755 index eb6929c..1dcab99 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,7 +1,7 @@ #!/bin/bash # https://github.com/pinterest/ktlint pre-commit hook # On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists -[ "$(uname -s)" == "Darwin" ] && no_run_if_empty=--no-run-if-empty +[ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative --format if [ $? -ne 0 ]; then exit 1; fi git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty git add diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index a98bd50..c112470 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -7,3 +7,4 @@ data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConf } + From 3b84427118cdafc2c6ea008c57c47d5159639025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:28:55 +0100 Subject: [PATCH 18/22] test3 --- .githooks/pre-commit | 7 ++++++- .../java/org/membraneframework/rtc/models/TrackData.kt | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 1dcab99..b8fa65f 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,7 +1,12 @@ #!/bin/bash # https://github.com/pinterest/ktlint pre-commit hook # On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists +echo "dupa1" [ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty -git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative --format +echo "dupa2" +git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative --format && echo "dupa3" +echo "dupa4" if [ $? -ne 0 ]; then exit 1; fi +echo "dupa5" git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty git add +echo "dupa6" diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index c112470..7210945 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -5,6 +5,7 @@ import org.membraneframework.rtc.utils.Metadata data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?){ -} + +} From 0231704db6158c3d3c89b1ddc3f7d9d1ef74904a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:33:12 +0100 Subject: [PATCH 19/22] test4 --- .../main/java/org/membraneframework/rtc/models/TrackData.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index 7210945..a1b15b3 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -3,9 +3,5 @@ package org.membraneframework.rtc.models import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.utils.Metadata -data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?){ - - - - +data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) { } From 527dd74c514cf5b9f76fc509827e359407434b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Wed, 17 Jan 2024 20:33:54 +0100 Subject: [PATCH 20/22] test4 --- .../main/java/org/membraneframework/rtc/models/TrackData.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index a1b15b3..354d0d4 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -3,5 +3,4 @@ package org.membraneframework.rtc.models import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.utils.Metadata -data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) { -} +data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?) From a66946c7028da8ead2d3b8125cb8c70667fbcc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Thu, 18 Jan 2024 14:08:25 +0100 Subject: [PATCH 21/22] remove unnecesary echo --- .githooks/pre-commit | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index b8fa65f..1dcab99 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,12 +1,7 @@ #!/bin/bash # https://github.com/pinterest/ktlint pre-commit hook # On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists -echo "dupa1" [ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty -echo "dupa2" -git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative --format && echo "dupa3" -echo "dupa4" +git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative --format if [ $? -ne 0 ]; then exit 1; fi -echo "dupa5" git diff --name-only --cached --relative --diff-filter=ACMT | grep '\.kt[s"]\?$' | xargs $no_run_if_empty git add -echo "dupa6" From 7e5e35a6019f879b5354615bb6772a1aac084393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20K=C4=85kol?= Date: Mon, 22 Jan 2024 13:20:28 +0100 Subject: [PATCH 22/22] add documentation about TrackData --- .../java/org/membraneframework/rtc/models/TrackData.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt index 354d0d4..95357b4 100644 --- a/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt +++ b/MembraneRTC/src/main/java/org/membraneframework/rtc/models/TrackData.kt @@ -3,4 +3,12 @@ package org.membraneframework.rtc.models import org.membraneframework.rtc.SimulcastConfig import org.membraneframework.rtc.utils.Metadata +/** + * Class containing information about track + * + * @property metadata metadata of given track + * @property simulcastConfig contains information regarding simulcast, including whether it is enabled and data on its supported encodings. + * + */ + data class TrackData(val metadata: Metadata?, val simulcastConfig: SimulcastConfig?)