Detect client short ice connection (#1532)

This commit is contained in:
cnderrauber
2023-03-21 09:50:43 +08:00
committed by GitHub
parent e8c7506d60
commit 1a78dba3e0
3 changed files with 24 additions and 4 deletions
+1 -1
View File
@@ -793,7 +793,7 @@ func (p *ParticipantImpl) ICERestart(iceConfig *livekit.ICEConfig, reason liveki
t.(types.LocalMediaTrack).Restart() 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)) { func (p *ParticipantImpl) OnICEConfigChanged(f func(participant types.LocalParticipant, iceConfig *livekit.ICEConfig)) {
+2 -2
View File
@@ -495,7 +495,7 @@ func (t *PCTransport) resetShortConn() {
t.lock.Unlock() 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() t.lock.RLock()
defer t.lock.RUnlock() defer t.lock.RUnlock()
@@ -568,7 +568,7 @@ func (t *PCTransport) handleConnectionFailed(forceShortConn bool) {
isShort := forceShortConn isShort := forceShortConn
if !isShort { if !isShort {
var duration time.Duration var duration time.Duration
isShort, duration = t.isShortConnection(time.Now()) isShort, duration = t.IsShortConnection(time.Now())
if isShort { if isShort {
pair, err := t.getSelectedPair() pair, err := t.getSelectedPair()
if err != nil { if err != nil {
+21 -1
View File
@@ -456,11 +456,31 @@ func (t *TransportManager) NegotiateSubscriber(force bool) {
t.subscriber.Negotiate(force) 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 { if iceConfig != nil {
t.SetICEConfig(iceConfig) 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 { if resetShortConnection {
t.publisher.ResetShortConnOnICERestart() t.publisher.ResetShortConnOnICERestart()
t.subscriber.ResetShortConnOnICERestart() t.subscriber.ResetShortConnOnICERestart()