2020-06-23 03:11:56 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2020-10-05 19:07:09 +02:00
|
|
|
"github.com/owncast/owncast/core"
|
|
|
|
"github.com/owncast/owncast/router/middleware"
|
2021-03-01 08:30:46 +01:00
|
|
|
"github.com/owncast/owncast/utils"
|
2020-06-23 03:11:56 +02:00
|
|
|
)
|
|
|
|
|
2020-11-13 00:14:59 +01:00
|
|
|
// GetStatus gets the status of the server.
|
2020-06-23 03:11:56 +02:00
|
|
|
func GetStatus(w http.ResponseWriter, r *http.Request) {
|
|
|
|
status := core.GetStatus()
|
2021-03-01 08:30:46 +01:00
|
|
|
response := webStatusResponse{
|
2021-07-09 20:16:44 +02:00
|
|
|
Online: status.Online,
|
|
|
|
ViewerCount: status.ViewerCount,
|
|
|
|
LastConnectTime: status.LastConnectTime,
|
2021-03-01 08:30:46 +01:00
|
|
|
LastDisconnectTime: status.LastDisconnectTime,
|
2021-07-09 20:16:44 +02:00
|
|
|
VersionNumber: status.VersionNumber,
|
|
|
|
StreamTitle: status.StreamTitle,
|
2021-03-01 08:30:46 +01:00
|
|
|
}
|
2020-06-23 03:11:56 +02:00
|
|
|
|
2021-03-01 08:30:46 +01:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
2021-11-17 05:58:03 +01:00
|
|
|
middleware.DisableCache(w)
|
|
|
|
|
2021-03-01 08:30:46 +01:00
|
|
|
if err := json.NewEncoder(w).Encode(response); err != nil {
|
2021-02-19 08:05:52 +01:00
|
|
|
InternalErrorHandler(w, err)
|
2020-11-15 03:39:53 +01:00
|
|
|
}
|
2020-06-23 03:11:56 +02:00
|
|
|
}
|
2021-03-01 08:30:46 +01:00
|
|
|
|
|
|
|
type webStatusResponse struct {
|
2021-07-09 20:16:44 +02:00
|
|
|
Online bool `json:"online"`
|
|
|
|
ViewerCount int `json:"viewerCount"`
|
2021-03-01 08:30:46 +01:00
|
|
|
|
2021-08-04 02:47:16 +02:00
|
|
|
LastConnectTime *utils.NullTime `json:"lastConnectTime"`
|
|
|
|
LastDisconnectTime *utils.NullTime `json:"lastDisconnectTime"`
|
2021-03-01 08:30:46 +01:00
|
|
|
|
|
|
|
VersionNumber string `json:"versionNumber"`
|
|
|
|
StreamTitle string `json:"streamTitle"`
|
2021-07-09 20:16:44 +02:00
|
|
|
}
|