Prevent subscribing to track that's closing (#1454)

Due to the order of events in MediaTrackReceiver and friends, SubscribedTrack
will be closed before the track is removed from RoomTrackManager.

Because of this, when a track is unpublished, it's possible to be subscribed
to the track as it's closing.

By introducing a closing state, we'd prevent accidental subscription to
closing tracks.
This commit is contained in:
David Zhao
2023-02-22 01:14:49 -08:00
committed by GitHub
parent 1b3d6fad54
commit e855620379
6 changed files with 159 additions and 1 deletions
+9 -1
View File
@@ -82,7 +82,15 @@ func (r *RoomTrackManager) GetTrackInfo(trackID livekit.TrackID) *TrackInfo {
r.lock.RLock()
defer r.lock.RUnlock()
return r.tracks[trackID]
info := r.tracks[trackID]
if info == nil {
return nil
}
// when track is about to close, do not resolve
if info.Track != nil && !info.Track.IsOpen() {
return nil
}
return info
}
func (r *RoomTrackManager) NotifyTrackChanged(trackID livekit.TrackID) {