From bb8aea6446cd365c82c2cc27d01bc5863b50b617 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sun, 20 Jun 2021 17:26:35 -0700 Subject: [PATCH] Revert "Consolidate the ping and status request APIs" This reverts commit b96cd2e93ecd07e04797116a9ffd38665accd4a0. --- controllers/ping.go | 13 +++++++++++++ controllers/status.go | 20 ++++++++------------ router/router.go | 3 +++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 controllers/ping.go diff --git a/controllers/ping.go b/controllers/ping.go new file mode 100644 index 000000000..81b0ab6e1 --- /dev/null +++ b/controllers/ping.go @@ -0,0 +1,13 @@ +package controllers + +import ( + "net/http" + + "github.com/owncast/owncast/core" + "github.com/owncast/owncast/utils" +) + +func Ping(w http.ResponseWriter, r *http.Request) { + id := utils.GenerateClientIDFromRequest(r) + core.SetViewerIdActive(id) +} diff --git a/controllers/status.go b/controllers/status.go index 0d802e56d..95c58654f 100644 --- a/controllers/status.go +++ b/controllers/status.go @@ -15,31 +15,27 @@ func GetStatus(w http.ResponseWriter, r *http.Request) { status := core.GetStatus() response := webStatusResponse{ - Online: status.Online, - ViewerCount: status.ViewerCount, - LastConnectTime: status.LastConnectTime, + Online: status.Online, + ViewerCount: status.ViewerCount, + LastConnectTime: status.LastConnectTime, LastDisconnectTime: status.LastDisconnectTime, - VersionNumber: status.VersionNumber, - StreamTitle: status.StreamTitle, + VersionNumber: status.VersionNumber, + StreamTitle: status.StreamTitle, } w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(response); err != nil { InternalErrorHandler(w, err) } - - // Mark the user who requested this status as an active viewer - id := utils.GenerateClientIDFromRequest(r) - core.SetViewerIdActive(id) } type webStatusResponse struct { - Online bool `json:"online"` - ViewerCount int `json:"viewerCount"` + 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"` -} +} \ No newline at end of file diff --git a/router/router.go b/router/router.go index 3c0fe6712..e13052245 100644 --- a/router/router.go +++ b/router/router.go @@ -62,6 +62,9 @@ func Start() error { // return the list of video variants available http.HandleFunc("/api/video/variants", controllers.GetVideoStreamOutputVariants) + // tell the backend you're an active viewer + http.HandleFunc("/api/ping", controllers.Ping) + // Authenticated admin requests // Current inbound broadcaster