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