Return early if already subscribed.
* 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
@@ -429,6 +429,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
// ignore already subscribed error
return err
}
+ if err == nil && subTrack != nil { // subTrack could be nil if already subscribed
subTrack.OnClose(func(willBeResumed bool) {
m.handleSubscribedTrackClose(s, willBeResumed)
})
@@ -442,6 +443,9 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
m.params.Participant.Negotiate(false)
}
+ go m.params.OnTrackSubscribed(subTrack)
+ }
+
// add mark the participant as someone we've subscribed to
firstSubscribe := false
publisherID := s.getPublisherID()
@@ -456,8 +460,6 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
pTracks[s.trackID] = struct{}{}
m.lock.Unlock()
- go m.params.OnTrackSubscribed(subTrack)
-
if changedCB != nil && firstSubscribe {
go changedCB(publisherID, true)
}
