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{
|
2021-07-09 21:16:44 +03:00
|
|
|
Online: status.Online,
|
|
|
|
ViewerCount: status.ViewerCount,
|
|
|
|
LastConnectTime: status.LastConnectTime,
|
2021-03-01 10:30:46 +03:00
|
|
|
LastDisconnectTime: status.LastDisconnectTime,
|
2021-07-09 21:16:44 +03:00
|
|
|
VersionNumber: status.VersionNumber,
|
|
|
|
StreamTitle: status.StreamTitle,
|
2021-03-01 10:30:46 +03:00
|
|
|
}
|
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 {
|
2021-07-09 21:16:44 +03:00
|
|
|
Online bool `json:"online"`
|
|
|
|
ViewerCount int `json:"viewerCount"`
|
2021-03-01 10:30:46 +03:00
|
|
|
|
2021-08-04 03:47:16 +03:00
|
|
|
LastConnectTime *utils.NullTime `json:"lastConnectTime"`
|
|
|
|
LastDisconnectTime *utils.NullTime `json:"lastDisconnectTime"`
|
2021-03-01 10:30:46 +03:00
|
|
|
|
|
|
|
VersionNumber string `json:"versionNumber"`
|
|
|
|
StreamTitle string `json:"streamTitle"`
|
2021-07-09 21:16:44 +03:00
|
|
|
}
|