diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index f2b7892d..50c4f3bc 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -793,7 +793,7 @@ func (p *ParticipantImpl) ICERestart(iceConfig *livekit.ICEConfig, reason liveki t.(types.LocalMediaTrack).Restart() } - p.TransportManager.ICERestart(iceConfig, reason == livekit.ReconnectReason_RR_PUBLISHER_FAILED || reason == livekit.ReconnectReason_RR_SUBSCRIBER_FAILED) + p.TransportManager.ICERestart(iceConfig, reason) } func (p *ParticipantImpl) OnICEConfigChanged(f func(participant types.LocalParticipant, iceConfig *livekit.ICEConfig)) { diff --git a/pkg/rtc/transport.go b/pkg/rtc/transport.go index cbc70ba2..c4afdd55 100644 --- a/pkg/rtc/transport.go +++ b/pkg/rtc/transport.go @@ -495,7 +495,7 @@ func (t *PCTransport) resetShortConn() { t.lock.Unlock() } -func (t *PCTransport) isShortConnection(at time.Time) (bool, time.Duration) { +func (t *PCTransport) IsShortConnection(at time.Time) (bool, time.Duration) { t.lock.RLock() defer t.lock.RUnlock() @@ -568,7 +568,7 @@ func (t *PCTransport) handleConnectionFailed(forceShortConn bool) { isShort := forceShortConn if !isShort { var duration time.Duration - isShort, duration = t.isShortConnection(time.Now()) + isShort, duration = t.IsShortConnection(time.Now()) if isShort { pair, err := t.getSelectedPair() if err != nil { diff --git a/pkg/rtc/transportmanager.go b/pkg/rtc/transportmanager.go index d4d347ba..b3002212 100644 --- a/pkg/rtc/transportmanager.go +++ b/pkg/rtc/transportmanager.go @@ -456,11 +456,31 @@ func (t *TransportManager) NegotiateSubscriber(force bool) { t.subscriber.Negotiate(force) } -func (t *TransportManager) ICERestart(iceConfig *livekit.ICEConfig, resetShortConnection bool) { +func (t *TransportManager) ICERestart(iceConfig *livekit.ICEConfig, reason livekit.ReconnectReason) { if iceConfig != nil { t.SetICEConfig(iceConfig) } + var ( + isShort bool + duration time.Duration + resetShortConnection bool + ) + switch reason { + case livekit.ReconnectReason_RR_PUBLISHER_FAILED: + resetShortConnection = true + isShort, duration = t.publisher.IsShortConnection(time.Now()) + + case livekit.ReconnectReason_RR_SUBSCRIBER_FAILED: + resetShortConnection = true + isShort, duration = t.subscriber.IsShortConnection(time.Now()) + } + + if isShort { + t.params.Logger.Infow("short connection by client ice restart", "duration", duration, "reason", reason) + t.handleConnectionFailed(isShort) + } + if resetShortConnection { t.publisher.ResetShortConnOnICERestart() t.subscriber.ResetShortConnOnICERestart()