2020-06-23 04:11:56 +03:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2022-05-24 01:15:32 +03:00
|
|
|
"time"
|
2020-06-23 04:11:56 +03:00
|
|
|
|
2020-10-05 20:07:09 +03:00
|
|
|
"github.com/owncast/owncast/core"
|
2022-06-26 10:46:55 +03:00
|
|
|
"github.com/owncast/owncast/core/data"
|
2020-10-05 20:07:09 +03:00
|
|
|
"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) {
|
2022-09-11 01:37:07 +03:00
|
|
|
response := getStatusResponse()
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
middleware.DisableCache(w)
|
|
|
|
|
|
|
|
if err := json.NewEncoder(w).Encode(response); err != nil {
|
|
|
|
InternalErrorHandler(w, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStatusResponse() webStatusResponse {
|
2020-06-23 04:11:56 +03:00
|
|
|
status := core.GetStatus()
|
2021-03-01 10:30:46 +03:00
|
|
|
response := webStatusResponse{
|
2021-07-09 21:16:44 +03:00
|
|
|
Online: status.Online,
|
2022-05-24 01:15:32 +03:00
|
|
|
ServerTime: time.Now(),
|
2021-07-09 21:16:44 +03:00
|
|
|
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
|
|
|
}
|
2022-06-26 10:46:55 +03:00
|
|
|
if !data.GetHideViewerCount() {
|
|
|
|
response.ViewerCount = status.ViewerCount
|
|
|
|
}
|
2022-09-11 01:37:07 +03:00
|
|
|
return response
|
2020-06-23 04:11:56 +03:00
|
|
|
}
|
2021-03-01 10:30:46 +03:00
|
|
|
|
|
|
|
type webStatusResponse struct {
|
2022-05-24 01:15:32 +03:00
|
|
|
Online bool `json:"online"`
|
2022-06-26 10:46:55 +03:00
|
|
|
ViewerCount int `json:"viewerCount,omitempty"`
|
2022-05-24 01:15:32 +03:00
|
|
|
ServerTime time.Time `json:"serverTime"`
|
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
|
|
|
}
|