Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Handle empty events metadata (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
incubo4u authored Jan 15, 2024
1 parent f117f5d commit 2e8be37
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ 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)
val context =
TrackContext(track = null, endpoint = it, trackId = trackId, metadata = metadata ?: mapOf())

this.trackContexts[trackId] = context

Expand Down Expand Up @@ -295,7 +296,7 @@ internal class InternalMembraneRTC

override fun onEndpointUpdated(
endpointId: String,
endpointMetadata: Metadata
endpointMetadata: Metadata?
) {
val endpoint =
remoteEndpoints.remove(endpointId) ?: run {
Expand Down Expand Up @@ -374,7 +375,7 @@ internal class InternalMembraneRTC

override fun onTracksAdded(
endpointId: String,
trackIdToMetadata: Map<String, Metadata>
trackIdToMetadata: Map<String, Metadata?>
) {
if (localEndpoint.id == endpointId) return

Expand All @@ -389,7 +390,8 @@ internal class InternalMembraneRTC
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 ?: mapOf())

this.trackContexts[trackId] = context

Expand Down Expand Up @@ -424,7 +426,7 @@ internal class InternalMembraneRTC
override fun onTrackUpdated(
endpointId: String,
trackId: String,
metadata: Metadata
metadata: Metadata?
) {
val endpoint =
remoteEndpoints[endpointId] ?: run {
Expand All @@ -438,7 +440,7 @@ internal class InternalMembraneRTC
return
}

context.metadata = metadata
context.metadata = metadata ?: mapOf()

val updatedEndpoint =
endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal class RTCEngineCommunication

fun sdpOffer(
sdp: String,
trackIdToTrackMetadata: Map<String, Metadata>,
trackIdToTrackMetadata: Map<String, Metadata?>,
midToTrackId: Map<String, String>
) {
sendEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal interface RTCEngineListener {

fun onEndpointUpdated(
endpointId: String,
endpointMetadata: Metadata
endpointMetadata: Metadata? = mapOf()
)

fun onOfferData(
Expand All @@ -41,7 +41,7 @@ internal interface RTCEngineListener {

fun onTracksAdded(
endpointId: String,
trackIdToMetadata: Map<String, Metadata>
trackIdToMetadata: Map<String, Metadata?>
)

fun onTracksRemoved(
Expand All @@ -52,7 +52,7 @@ internal interface RTCEngineListener {
fun onTrackUpdated(
endpointId: String,
trackId: String,
metadata: Metadata
metadata: Metadata? = mapOf()
)

fun onTrackEncodingChanged(
Expand Down
27 changes: 15 additions & 12 deletions MembraneRTC/src/main/java/org/membraneframework/rtc/events/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ internal inline fun <I, reified O> I.convert(): O {
sealed class SendableEvent

data class Connect(val type: String, val data: Data) : SendableEvent() {
data class Data(val metadata: Metadata)
data class Data(val metadata: Metadata?)

constructor(metadata: Metadata) : this("connect", Data(metadata))
constructor(metadata: Metadata? = mapOf()) : this("connect", Data(metadata))
}

data class SdpOffer(val type: String, val data: Payload) : SendableEvent() {
constructor(sdp: String, trackIdToTrackMetadata: Map<String, Metadata>, midToTrackId: Map<String, String>) :
constructor(sdp: String, trackIdToTrackMetadata: Map<String, Metadata?>, midToTrackId: Map<String, String>) :
this(
"custom",
mapOf(
Expand Down Expand Up @@ -96,15 +96,18 @@ data class SelectEncoding(val type: String, val data: Payload) : SendableEvent()
}

data class UpdateEndpointMetadata(val type: String, val data: Data) : SendableEvent() {
data class Data(val metadata: Metadata)
data class Data(val metadata: Metadata?)

constructor(metadata: Metadata) : this("updateEndpointMetadata", Data(metadata))
constructor(metadata: Metadata? = mapOf()) : this("updateEndpointMetadata", Data(metadata))
}

data class UpdateTrackMetadata(val type: String, val data: Data) : SendableEvent() {
data class Data(val trackId: String, val trackMetadata: Metadata)
data class Data(val trackId: String, val trackMetadata: Metadata?)

constructor(trackId: String, trackMetadata: Metadata) : this("updateTrackMetadata", Data(trackId, trackMetadata))
constructor(trackId: String, trackMetadata: Metadata = mapOf()) : this(
"updateTrackMetadata",
Data(trackId, trackMetadata)
)
}

data class Disconnect(val type: String) : SendableEvent() {
Expand Down Expand Up @@ -231,13 +234,13 @@ data class EndpointAdded(val type: ReceivableEventType, val data: Data) : Receiv
data class Data(
val id: String,
val type: String,
val metadata: Metadata,
val trackIdToMetadata: Map<String, Metadata>
val metadata: Metadata?,
val trackIdToMetadata: Map<String, Metadata?>
)
}

data class EndpointUpdated(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class Data(val id: String, val metadata: Metadata)
data class Data(val id: String, val metadata: Metadata?)
}

data class EndpointRemoved(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
Expand All @@ -257,15 +260,15 @@ 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<String, Metadata>)
data class Data(val endpointId: String, val trackIdToMetadata: Map<String, Metadata?>)
}

data class TracksRemoved(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class Data(val endpointId: String, val trackIds: List<String>)
}

data class TrackUpdated(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class Data(val endpointId: String, val trackId: String, val metadata: Metadata)
data class Data(val endpointId: String, val trackId: String, val metadata: Metadata?)
}

data class SdpAnswer(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class Endpoint(
val id: String,
val type: String,
val metadata: Metadata? = mapOf(),
val trackIdToMetadata: Map<String, Metadata> = mapOf()
val trackIdToMetadata: Map<String, Metadata?> = mapOf()
) {
fun withTrack(
trackId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun interface OnVoiceActivityChangedListener {
* @property trackId Track id. It is generated by RTC engine and takes form `endpoint_id:<random_uuidv4>`.
* @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 = mapOf()) {
private var onTrackEncodingChangeListener: (OnEncodingChangedListener)? = null
private var onVadNotificationListener: (OnVoiceActivityChangedListener)? = null

Expand Down

0 comments on commit 2e8be37

Please sign in to comment.