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

Commit

Permalink
update RoomViewModel.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
karkakol committed May 21, 2024
1 parent 2a1e3af commit 4ba30df
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import com.fishjamdev.client.Config
import com.fishjamdev.client.FishjamClient
import com.fishjamdev.client.FishjamClientListener
import com.fishjamdev.client.Peer
import com.fishjamdev.client.TrackContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import org.membraneframework.rtc.SimulcastConfig
import org.membraneframework.rtc.media.LocalVideoTrack
import org.membraneframework.rtc.media.RemoteVideoTrack
import org.membraneframework.rtc.media.VideoParameters
import org.membraneframework.rtc.models.TrackContext

class RoomViewModel(application: Application) :
AndroidViewModel(application),
Expand Down Expand Up @@ -97,15 +97,15 @@ class RoomViewModel(application: Application) :

override fun onTrackReady(ctx: TrackContext) {
viewModelScope.launch {
val participant = mutableParticipants[ctx.peer.id] ?: return@launch
val participant = mutableParticipants[ctx.endpoint.id] ?: return@launch

val (id, newParticipant) =
when (ctx.track) {
is RemoteVideoTrack -> {
globalToLocalTrackId[ctx.trackId] = (ctx.track as RemoteVideoTrack).id()

val p = participant.copy(videoTrack = ctx.track as RemoteVideoTrack)
Pair(ctx.peer.id, p)
Pair(ctx.endpoint.id, p)
}

else ->
Expand All @@ -120,7 +120,7 @@ class RoomViewModel(application: Application) :

override fun onTrackRemoved(ctx: TrackContext) {
viewModelScope.launch {
val participant = mutableParticipants[ctx.peer.id] ?: return@launch
val participant = mutableParticipants[ctx.endpoint.id] ?: return@launch

val localTrackId = globalToLocalTrackId[ctx.trackId]
val videoTrackId = participant.videoTrack?.id()
Expand All @@ -134,7 +134,7 @@ class RoomViewModel(application: Application) :

globalToLocalTrackId.remove(ctx.trackId)

mutableParticipants[ctx.peer.id] = newParticipant
mutableParticipants[ctx.endpoint.id] = newParticipant

emitParticipants()
}
Expand Down

0 comments on commit 4ba30df

Please sign in to comment.