fix: refresh on-demand media status (#54)

This commit is contained in:
ila
2026-08-13 15:08:25 +08:00
parent 676586711e
commit e2c2a8686f
+34
View File
@@ -125,6 +125,40 @@ func (s *Service) Reconcile(ctx context.Context, actor identity.Principal, id st
identity.RecordAudit(ctx, actor.UserID, "media.reconcile", id, "success", map[string]any{"actual": route.Actual})
return route, nil
}
// Refresh reads the MediaMTX runtime state without reapplying configuration or
// exposing the source URI. It is safe to call while a playback session polls.
func (s *Service) Refresh(ctx context.Context, id string) (Route, error) {
route, err := s.store.Get(ctx, id)
if err != nil {
return Route{}, err
}
if route.Desired != "running" {
return route, nil
}
status, err := s.controller.Status(ctx, route.Path)
if err != nil {
return route, nil
}
actual := "waiting"
detail := "等待播放器连接并按需拉流"
if status.Ready {
actual = "ready"
detail = "上游拉流正常"
}
if route.Actual == actual && route.Detail == detail && route.Readers == status.Readers {
return route, nil
}
route.Actual = actual
route.Detail = detail
route.Readers = status.Readers
route.Version++
route.UpdatedAt = s.now().UTC()
if err := s.store.Save(ctx, route); err != nil {
return Route{}, err
}
return route, nil
}
func (s *Service) Stop(ctx context.Context, actor identity.Principal, id string) (Route, error) {
route, err := s.store.Get(ctx, id)
if err != nil {