34 lines
795 B
Go
34 lines
795 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// HandleStatus returns the current stream status as JSON.
|
|
// GET /api/status
|
|
func (a *App) HandleStatus(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
a.mu.RLock()
|
|
status := a.Status
|
|
a.mu.RUnlock()
|
|
|
|
// Attach live stream health metrics when FFmpeg is running
|
|
status.Health = a.FFmpeg.Health()
|
|
|
|
// Auto-clear transitioning once FFmpeg is producing health data
|
|
if status.Transitioning && status.Health != nil && status.Health.Speed != "" {
|
|
a.mu.Lock()
|
|
a.Status.Transitioning = false
|
|
a.mu.Unlock()
|
|
status.Transitioning = false
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(status)
|
|
}
|