Return early if already subscribed. (#1377)

* Return early if already subscribed.

When already subscribed, returned `subTrack` is nil.
Return early, but do not return an error.

* check for nil subTrack

* check for nil as well
This commit is contained in:
Raja Subramanian
2023-02-04 13:47:35 +05:30
committed by GitHub
parent add9962655
commit d67cdb6141
+4 -2
View File
@@ -429,6 +429,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
// ignore already subscribed error // ignore already subscribed error
return err return err
} }
if err == nil && subTrack != nil { // subTrack could be nil if already subscribed
subTrack.OnClose(func(willBeResumed bool) { subTrack.OnClose(func(willBeResumed bool) {
m.handleSubscribedTrackClose(s, willBeResumed) m.handleSubscribedTrackClose(s, willBeResumed)
}) })
@@ -442,6 +443,9 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
m.params.Participant.Negotiate(false) m.params.Participant.Negotiate(false)
} }
go m.params.OnTrackSubscribed(subTrack)
}
// add mark the participant as someone we've subscribed to // add mark the participant as someone we've subscribed to
firstSubscribe := false firstSubscribe := false
publisherID := s.getPublisherID() publisherID := s.getPublisherID()
@@ -456,8 +460,6 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
pTracks[s.trackID] = struct{}{} pTracks[s.trackID] = struct{}{}
m.lock.Unlock() m.lock.Unlock()
go m.params.OnTrackSubscribed(subTrack)
if changedCB != nil && firstSubscribe { if changedCB != nil && firstSubscribe {
go changedCB(publisherID, true) go changedCB(publisherID, true)
} }