2020-11-05 18:29:16 -08:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/owncast/owncast/core"
|
2022-03-24 23:06:47 -07:00
|
|
|
"github.com/owncast/owncast/metrics"
|
2020-11-05 18:29:16 -08:00
|
|
|
"github.com/owncast/owncast/models"
|
2024-11-15 19:20:58 -08:00
|
|
|
"github.com/owncast/owncast/persistence/configrepository"
|
2024-07-01 20:12:08 -07:00
|
|
|
"github.com/owncast/owncast/webserver/router/middleware"
|
2020-11-14 18:39:53 -08:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-11-05 18:29:16 -08:00
|
|
|
)
|
|
|
|
|
2020-11-13 00:14:59 +01:00
|
|
|
// Status gets the details of the inbound broadcaster.
|
2020-11-05 18:29:16 -08:00
|
|
|
func Status(w http.ResponseWriter, r *http.Request) {
|
2024-11-15 19:20:58 -08:00
|
|
|
configRepository := configrepository.Get()
|
|
|
|
|
2020-11-05 18:29:16 -08:00
|
|
|
broadcaster := core.GetBroadcaster()
|
|
|
|
status := core.GetStatus()
|
2021-02-18 23:05:52 -08:00
|
|
|
currentBroadcast := core.GetCurrentBroadcast()
|
2022-03-24 23:06:47 -07:00
|
|
|
health := metrics.GetStreamHealthOverview()
|
2020-11-05 18:29:16 -08:00
|
|
|
response := adminStatusResponse{
|
|
|
|
Broadcaster: broadcaster,
|
2021-02-18 23:05:52 -08:00
|
|
|
CurrentBroadcast: currentBroadcast,
|
2020-11-05 18:29:16 -08:00
|
|
|
Online: status.Online,
|
2022-03-24 23:06:47 -07:00
|
|
|
Health: health,
|
2020-11-05 18:29:16 -08:00
|
|
|
ViewerCount: status.ViewerCount,
|
|
|
|
OverallPeakViewerCount: status.OverallMaxViewerCount,
|
|
|
|
SessionPeakViewerCount: status.SessionMaxViewerCount,
|
|
|
|
VersionNumber: status.VersionNumber,
|
2024-11-15 19:20:58 -08:00
|
|
|
StreamTitle: configRepository.GetStreamTitle(),
|
2020-11-05 18:29:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
2021-11-16 20:58:03 -08:00
|
|
|
middleware.DisableCache(w)
|
|
|
|
|
2020-11-14 18:39:53 -08:00
|
|
|
err := json.NewEncoder(w).Encode(response)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
2020-11-05 18:29:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type adminStatusResponse struct {
|
2022-03-24 23:06:47 -07:00
|
|
|
Broadcaster *models.Broadcaster `json:"broadcaster"`
|
|
|
|
CurrentBroadcast *models.CurrentBroadcast `json:"currentBroadcast"`
|
2023-05-30 10:31:43 -07:00
|
|
|
Health *models.StreamHealthOverview `json:"health"`
|
|
|
|
StreamTitle string `json:"streamTitle"`
|
|
|
|
VersionNumber string `json:"versionNumber"`
|
2022-03-24 23:06:47 -07:00
|
|
|
ViewerCount int `json:"viewerCount"`
|
|
|
|
OverallPeakViewerCount int `json:"overallPeakViewerCount"`
|
|
|
|
SessionPeakViewerCount int `json:"sessionPeakViewerCount"`
|
2023-05-30 10:31:43 -07:00
|
|
|
Online bool `json:"online"`
|
2020-11-05 18:29:16 -08:00
|
|
|
}
|