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

Commit

Permalink
[MV-219] Add peerRemoved and encodingChanged events handling (#18)
Browse files Browse the repository at this point in the history
* [MV-219] Add `peerRemoved` and `encodingChanged` events handling

* Add default implementations
  • Loading branch information
graszka22 authored Nov 14, 2022
1 parent a8f0ee7 commit 3aafd92
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@ constructor(
remotePeers[peer.id] = peer.copy(metadata = event.data.metadata)
}

is PeerRemoved -> {
if (event.data.peerId != localPeer.id) {
Timber.e("Received onRemoved media event, but it does not refer to the local peer")
return
}
listener.onRemoved(event.data.reason)
}

is OfferData -> {
coroutineScope.launch {
onOfferData(event)
Expand Down Expand Up @@ -523,6 +531,10 @@ constructor(
this.listener.onTrackUpdated(updatedContext)
}

is EncodingSwitched -> {
this.listener.onTrackEncodingChanged(event.data.peerId, event.data.trackId, event.data.encoding)
}

else ->
Timber.e("Failed to process unknown event: $event")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.membraneframework.rtc

import org.membraneframework.rtc.models.Peer
import org.membraneframework.rtc.models.TrackContext
import timber.log.Timber

public interface MembraneRTCListener {
// / Callback invoked when client has successfully connected via transport layer.
Expand Down Expand Up @@ -34,6 +35,16 @@ public interface MembraneRTCListener {
// /Callback invoked when peer's metadata gets updated.
fun onPeerUpdated(peer: Peer)

// Callback invoked when received track encoding has changed
fun onTrackEncodingChanged(peerId: String, trackId: String, encoding: String) {
Timber.i(
"Track encoding changed $trackId -> $encoding"
)
}

// /Callback invoked when an errors happens.
fun onError(error: MembraneRTCError)

// Callback invoked every time a local peer is removed by the server
fun onRemoved(reason: String) { Timber.e("Peer removed") }
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ enum class ReceivableEventType() {
@SerializedName("peerUpdated")
PeerUpdated,

@SerializedName("peerRemoved")
PeerRemoved,

@SerializedName("custom")
Custom,

Expand All @@ -139,7 +142,10 @@ enum class ReceivableEventType() {
TrackUpdated,

@SerializedName("sdpAnswer")
SdpAnswer
SdpAnswer,

@SerializedName("encodingSwitched")
EncodingSwitched
}

internal data class BaseReceivableEvent(val type: ReceivableEventType)
Expand Down Expand Up @@ -167,6 +173,9 @@ sealed class ReceivableEvent {
ReceivableEventType.PeerUpdated ->
payload.toDataClass<PeerUpdated>()

ReceivableEventType.PeerRemoved ->
payload.toDataClass<PeerRemoved>()

ReceivableEventType.TracksAdded ->
payload.toDataClass<TracksAdded>()

Expand All @@ -189,6 +198,9 @@ sealed class ReceivableEvent {
ReceivableEventType.SdpAnswer ->
payload.toDataClass<CustomEvent<SdpAnswer>>().data

ReceivableEventType.EncodingSwitched ->
payload.toDataClass<CustomEvent<EncodingSwitched>>().data

else ->
null
}
Expand Down Expand Up @@ -223,6 +235,10 @@ data class PeerUpdated(val type: ReceivableEventType, val data: Data) : Receivab
data class Data(val peerId: String, val metadata: Metadata)
}

data class PeerRemoved(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class Data(val peerId: String, val reason: String)
}

data class OfferData(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class TurnServer(
val username: String,
Expand Down Expand Up @@ -255,6 +271,10 @@ data class RemoteCandidate(val type: ReceivableEventType, val data: Data) : Rece
data class Data(val candidate: String, val sdpMLineIndex: Int, val sdpMid: String?)
}

data class EncodingSwitched(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class Data(val peerId: String, val trackId: String, val encoding: String)
}

data class BaseCustomEvent(val type: ReceivableEventType, val data: Data) : ReceivableEvent() {
data class Data(val type: ReceivableEventType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,14 @@ class RoomViewModel(
val dimensions = videoParameters.dimensions.flip()
videoParameters = videoParameters.copy(
dimensions = dimensions,
simulcastConfig = screencastSimulcastConfig.value
simulcastConfig = screencastSimulcastConfig.value,
maxBitrate = TrackBandwidthLimit.SimulcastBandwidthLimit(
mapOf(
"l" to TrackBandwidthLimit.BandwidthLimit(150),
"m" to TrackBandwidthLimit.BandwidthLimit(500),
"h" to TrackBandwidthLimit.BandwidthLimit(1500)
)
)
)

localScreencastTrack = room.value?.createScreencastTrack(
Expand Down

0 comments on commit 3aafd92

Please sign in to comment.