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() {