feat: source timer

This commit is contained in:
Rob Watson 2025-03-04 20:44:57 +01:00
parent 7c34e374ce
commit 8b65a3573c
5 changed files with 13 additions and 3 deletions

View File

@ -75,7 +75,7 @@ func Run(ctx context.Context, params RunParams) error {
}) })
defer mp.Close() defer mp.Close()
const uiUpdateInterval = 2 * time.Second const uiUpdateInterval = time.Second
uiUpdateT := time.NewTicker(uiUpdateInterval) uiUpdateT := time.NewTicker(uiUpdateInterval)
defer uiUpdateT.Stop() defer uiUpdateT.Stop()

View File

@ -31,6 +31,7 @@ type BuildInfo struct {
type Source struct { type Source struct {
Container Container Container Container
Live bool Live bool
LiveChangedAt time.Time
Listeners int Listeners int
Tracks []string Tracks []string
RTMPURL string RTMPURL string

View File

@ -204,6 +204,7 @@ func (s *Actor) actorLoop(containerStateC <-chan domain.Container, errC <-chan e
} }
if ingressState.ready != s.state.Live || ingressState.listeners != s.state.Listeners { if ingressState.ready != s.state.Live || ingressState.listeners != s.state.Listeners {
s.state.Live = ingressState.ready s.state.Live = ingressState.ready
s.state.LiveChangedAt = time.Now()
s.state.Listeners = ingressState.listeners s.state.Listeners = ingressState.listeners
resetFetchTracksT(time.Second) resetFetchTracksT(time.Second)
sendState() sendState()

View File

@ -60,7 +60,9 @@ func TestIntegrationMediaServerStartStop(t *testing.T) {
t, t,
func() bool { func() bool {
currState := mediaServer.State() currState := mediaServer.State()
return currState.Live && currState.Container.HealthState == "healthy" return currState.Live &&
!currState.LiveChangedAt.IsZero() &&
currState.Container.HealthState == "healthy"
}, },
time.Second*5, time.Second*5,
time.Second, time.Second,

View File

@ -7,6 +7,7 @@ import (
"log/slog" "log/slog"
"strconv" "strconv"
"strings" "strings"
"time"
"git.netflux.io/rob/octoplex/domain" "git.netflux.io/rob/octoplex/domain"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
@ -319,7 +320,12 @@ func (ui *UI) redrawFromState(state domain.AppState) {
ui.sourceViews.tracks.SetText(tracks) ui.sourceViews.tracks.SetText(tracks)
if state.Source.Live { if state.Source.Live {
ui.sourceViews.status.SetText("[black:green]receiving") var durStr string
if !state.Source.LiveChangedAt.IsZero() {
durStr = fmt.Sprintf(" (%s)", time.Since(state.Source.LiveChangedAt).Round(time.Second))
}
ui.sourceViews.status.SetText("[black:green]receiving" + durStr)
} else if state.Source.Container.State == "running" && state.Source.Container.HealthState == "healthy" { } else if state.Source.Container.State == "running" && state.Source.Container.HealthState == "healthy" {
ui.sourceViews.status.SetText("[black:yellow]ready") ui.sourceViews.status.SetText("[black:yellow]ready")
} else { } else {