From e4e2e4189b7aa90297ff24690791e648a11f396f Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Fri, 19 Aug 2022 16:24:41 +0530 Subject: [PATCH] Clear disconnect timer on ICERestart (#932) * Clear disconnect timer on ICERestart Disconnect timer is set up when a transport fails. But, it is possible that the connection is resumed. So, clear disconnect timer on resume. * clean up --- pkg/rtc/participant.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 46f06b263..acdaf5bc0 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -672,6 +672,8 @@ func (p *ParticipantImpl) MigrateState() types.MigrateState { // ICERestart restarts subscriber ICE connections func (p *ParticipantImpl) ICERestart(iceConfig *types.IceConfig) error { + p.clearDisconnectTimer() + for _, t := range p.GetPublishedTracks() { t.(types.LocalMediaTrack).Restart() } @@ -1178,21 +1180,21 @@ func (p *ParticipantImpl) onPrimaryTransportFullyEstablished() { p.updateState(livekit.ParticipantInfo_ACTIVE) } -func (p *ParticipantImpl) onAnyTransportFailed() { - // clients support resuming of connections when websocket becomes disconnected - p.closeSignalConnection() - - // detect when participant has actually left. +func (p *ParticipantImpl) clearDisconnectTimer() { p.lock.Lock() if p.disconnectTimer != nil { p.disconnectTimer.Stop() p.disconnectTimer = nil } + p.lock.Unlock() +} + +func (p *ParticipantImpl) setupDisconnectTimer() { + p.clearDisconnectTimer() + + p.lock.Lock() p.disconnectTimer = time.AfterFunc(disconnectCleanupDuration, func() { - p.lock.Lock() - p.disconnectTimer.Stop() - p.disconnectTimer = nil - p.lock.Unlock() + p.clearDisconnectTimer() if p.isClosed.Load() || p.State() == livekit.ParticipantInfo_DISCONNECTED { return @@ -1203,6 +1205,14 @@ func (p *ParticipantImpl) onAnyTransportFailed() { p.lock.Unlock() } +func (p *ParticipantImpl) onAnyTransportFailed() { + // clients support resuming of connections when websocket becomes disconnected + p.closeSignalConnection() + + // detect when participant has actually left. + p.setupDisconnectTimer() +} + // subscriberRTCPWorker sends SenderReports periodically when the participant is subscribed to // other publishedTracks in the room. func (p *ParticipantImpl) subscriberRTCPWorker() {