Clear disconnect timer on ICERestart
* 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
@@ -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.disconnectTimer = time.AfterFunc(disconnectCleanupDuration, func() {
- p.lock.Lock()
- 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.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() {
