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:
+23
-3
@@ -997,7 +997,10 @@ func (p *ParticipantImpl) onTrackSubscribed(subTrack types.SubscribedTrack) {
|
||||
subTrack.DownTrack().SetActivePaddingOnMuteUpTrack()
|
||||
}
|
||||
|
||||
subTrack.AddOnBind(func() {
|
||||
subTrack.AddOnBind(func(err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if p.TransportManager.HasSubscriberEverConnected() {
|
||||
subTrack.DownTrack().SetConnected()
|
||||
}
|
||||
@@ -2083,8 +2086,25 @@ func (p *ParticipantImpl) onPublicationError(trackID livekit.TrackID) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) onSubscriptionError(trackID livekit.TrackID) {
|
||||
if p.params.ReconnectOnSubscriptionError {
|
||||
func (p *ParticipantImpl) onSubscriptionError(trackID livekit.TrackID, fatal bool, err error) {
|
||||
signalErr := livekit.SubscriptionError_SE_UNKOWN
|
||||
switch {
|
||||
case errors.Is(err, webrtc.ErrUnsupportedCodec):
|
||||
signalErr = livekit.SubscriptionError_SE_CODEC_UNSUPPORTED
|
||||
case errors.Is(err, ErrTrackNotFound):
|
||||
signalErr = livekit.SubscriptionError_SE_TRACK_NOTFOUND
|
||||
}
|
||||
|
||||
_ = p.writeMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_SubscriptionResponse{
|
||||
SubscriptionResponse: &livekit.SubscriptionResponse{
|
||||
TrackSid: string(trackID),
|
||||
Err: signalErr,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if p.params.ReconnectOnSubscriptionError && fatal {
|
||||
p.params.Logger.Infow("issuing full reconnect on subscription error", "trackID", trackID)
|
||||
p.IssueFullReconnect(types.ParticipantCloseReasonPublicationError)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user