fix repeated AddSubscriber of MediaTrackSubscription (#723)
This commit is contained in:
@@ -29,9 +29,10 @@ const (
|
|||||||
type MediaTrackSubscriptions struct {
|
type MediaTrackSubscriptions struct {
|
||||||
params MediaTrackSubscriptionsParams
|
params MediaTrackSubscriptionsParams
|
||||||
|
|
||||||
subscribedTracksMu sync.RWMutex
|
subscribedTracksMu sync.RWMutex
|
||||||
subscribedTracks map[livekit.ParticipantID]types.SubscribedTrack
|
subscribedTracks map[livekit.ParticipantID]types.SubscribedTrack
|
||||||
pendingClose map[livekit.ParticipantID]types.SubscribedTrack
|
pendingSubscribeTracks sync.Map // livekit.ParticipantID -> bool
|
||||||
|
pendingClose map[livekit.ParticipantID]types.SubscribedTrack
|
||||||
|
|
||||||
onNoSubscribers func()
|
onNoSubscribers func()
|
||||||
|
|
||||||
@@ -108,6 +109,12 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, code
|
|||||||
trackID := t.params.MediaTrack.ID()
|
trackID := t.params.MediaTrack.ID()
|
||||||
subscriberID := sub.ID()
|
subscriberID := sub.ID()
|
||||||
|
|
||||||
|
if _, pending := t.pendingSubscribeTracks.LoadOrStore(subscriberID, true); pending {
|
||||||
|
return nil, nil
|
||||||
|
} else {
|
||||||
|
defer t.pendingSubscribeTracks.Delete(subscriberID)
|
||||||
|
}
|
||||||
|
|
||||||
// don't subscribe to the same track multiple times
|
// don't subscribe to the same track multiple times
|
||||||
t.subscribedTracksMu.Lock()
|
t.subscribedTracksMu.Lock()
|
||||||
if _, ok := t.subscribedTracks[subscriberID]; ok {
|
if _, ok := t.subscribedTracks[subscriberID]; ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user