Avoid reconnect loop for unsupported downtrack (#1754)
* Avoid reconnect loop for unsupported downtrack If the client subscribes to a track which codec is unsupported by the client, sfu will trigger negotiation failed and issue a full reconnect after received client answer. If the client try to subscribe that track then it will got full reconnect again. That will cause a infinite reconnect loop until the client don't subscribe that track. This PR will unsubscribe the error track for the client and send a SubscriptionResponse that contain the reason to indicates the track's codec is not supported to avoid the reconnect loop.
This commit is contained in:
@@ -40,7 +40,7 @@ type SubscribedTrack struct {
|
||||
needsNegotiation atomic.Bool
|
||||
|
||||
bindLock sync.Mutex
|
||||
onBindCallbacks []func()
|
||||
onBindCallbacks []func(error)
|
||||
onClose atomic.Value // func(bool)
|
||||
bound atomic.Bool
|
||||
|
||||
@@ -61,7 +61,7 @@ func NewSubscribedTrack(params SubscribedTrackParams) *SubscribedTrack {
|
||||
return s
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) AddOnBind(f func()) {
|
||||
func (t *SubscribedTrack) AddOnBind(f func(error)) {
|
||||
t.bindLock.Lock()
|
||||
bound := t.bound.Load()
|
||||
if !bound {
|
||||
@@ -71,19 +71,21 @@ func (t *SubscribedTrack) AddOnBind(f func()) {
|
||||
|
||||
if bound {
|
||||
// fire immediately, do not need to persist since bind is a one time event
|
||||
go f()
|
||||
go f(nil)
|
||||
}
|
||||
}
|
||||
|
||||
// for DownTrack callback to notify us that it's bound
|
||||
func (t *SubscribedTrack) Bound() {
|
||||
func (t *SubscribedTrack) Bound(err error) {
|
||||
t.bindLock.Lock()
|
||||
t.bound.Store(true)
|
||||
if err == nil {
|
||||
t.bound.Store(true)
|
||||
}
|
||||
callbacks := t.onBindCallbacks
|
||||
t.onBindCallbacks = nil
|
||||
t.bindLock.Unlock()
|
||||
|
||||
if t.MediaTrack().Kind() == livekit.TrackType_VIDEO {
|
||||
if err == nil && t.MediaTrack().Kind() == livekit.TrackType_VIDEO {
|
||||
// When AdaptiveStream is enabled, default the subscriber to LOW quality stream
|
||||
// we would want LOW instead of OFF for a couple of reasons
|
||||
// 1. when a subscriber unsubscribes from a track, we would forget their previously defined settings
|
||||
@@ -107,7 +109,7 @@ func (t *SubscribedTrack) Bound() {
|
||||
}
|
||||
|
||||
for _, cb := range callbacks {
|
||||
go cb()
|
||||
go cb(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user