fix: delayclosetimeout not work

This commit is contained in:
langhuihui
2024-08-29 19:51:03 +08:00
parent 005fb482f8
commit f231a0cd71

View File

@@ -295,6 +295,13 @@ func findOrCreateStream(streamPath string, waitTimeout time.Duration) (s *Stream
}
}
func (r *Stream) resetTimer(dur time.Duration) {
if r.timeout != nil {
r.Warn("reset timer", zap.Duration("timeout", dur))
r.timeout.Reset(dur)
}
}
func (r *Stream) action(action StreamAction) (ok bool) {
var event StateEvent
event.Target = r
@@ -327,7 +334,7 @@ func (r *Stream) action(action StreamAction) (ok bool) {
} else if waitTime == 0 {
waitTime = time.Millisecond * 10 //没有订阅者也没有配置发布者等待重连时间默认10ms后关闭流
}
r.timeout.Reset(waitTime)
r.resetTimer(waitTime)
r.Debug("wait publisher", zap.Duration("wait timeout", waitTime))
case STATE_WAITTRACK:
if len(r.SEHistory) > 1 {
@@ -335,7 +342,7 @@ func (r *Stream) action(action StreamAction) (ok bool) {
} else {
stateEvent = SEpublish{event}
}
r.timeout.Reset(time.Second * 5) // 5秒心跳检测track的存活度
r.resetTimer(time.Second * 5) // 5秒心跳检测track的存活度
case STATE_PUBLISHING:
stateEvent = SEtrackAvaliable{event}
r.Subscribers.SendInviteTrack(r)
@@ -343,13 +350,13 @@ func (r *Stream) action(action StreamAction) (ok bool) {
if puller, ok := r.Publisher.(IPuller); ok {
puller.OnConnected()
}
r.timeout.Reset(time.Second * 5) // 5秒心跳检测track的存活度
r.resetTimer(time.Second * 5) // 5秒心跳检测track的存活度
case STATE_WAITCLOSE:
stateEvent = SEwaitClose{event}
if r.IdleTimeout > 0 {
r.timeout.Reset(r.IdleTimeout)
r.resetTimer(r.IdleTimeout)
} else {
r.timeout.Reset(r.DelayCloseTimeout)
r.resetTimer(r.DelayCloseTimeout)
}
case STATE_CLOSED:
Streams.Delete(r.Path)
@@ -508,11 +515,14 @@ func (s *Stream) run() {
continue
}
}
if s.State == STATE_WAITTRACK {
switch s.State {
case STATE_WAITTRACK:
s.action(ACTION_TRACKAVAILABLE)
case STATE_WAITCLOSE:
continue
}
s.Subscribers.AbortWait()
s.timeout.Reset(time.Second * 5)
s.resetTimer(time.Second * 5)
} else {
s.Debug("timeout", timeOutInfo)
s.action(ACTION_TIMEOUT)