Browse Source

Replace admin broadcaster with status api

pull/328/head
Gabe Kangas 5 years ago
parent
commit
856961ad2d
  1. 2
      config-example.yaml
  2. 23
      config/config.go
  3. 35
      controllers/admin/inboundBroadcasterDetails.go
  4. 40
      controllers/admin/status.go
  5. 8
      controllers/status.go
  6. 5
      router/router.go

2
config-example.yaml

@ -26,3 +26,5 @@ videoSettings:
# Change this value and keep it secure. Treat it like a password to your live stream. # Change this value and keep it secure. Treat it like a password to your live stream.
streamingKey: abc123 streamingKey: abc123
# Set to true if you don't want the service checking for future releases.
disableUpgradeChecks: false

23
config/config.go

@ -14,17 +14,18 @@ var Config *config
var _default config var _default config
type config struct { type config struct {
DatabaseFilePath string `yaml:"databaseFile"` DatabaseFilePath string `yaml:"databaseFile"`
EnableDebugFeatures bool `yaml:"-"` EnableDebugFeatures bool `yaml:"-"`
FFMpegPath string `yaml:"ffmpegPath"` FFMpegPath string `yaml:"ffmpegPath"`
Files files `yaml:"files"` Files files `yaml:"files"`
InstanceDetails InstanceDetails `yaml:"instanceDetails"` InstanceDetails InstanceDetails `yaml:"instanceDetails"`
S3 S3 `yaml:"s3"` S3 S3 `yaml:"s3"`
VersionInfo string `yaml:"-"` // For storing the version/build number VersionInfo string `yaml:"-"` // For storing the version/build number
VersionNumber string `yaml:"-"` VersionNumber string `yaml:"-"`
VideoSettings videoSettings `yaml:"videoSettings"` VideoSettings videoSettings `yaml:"videoSettings"`
WebServerPort int `yaml:"webServerPort"` WebServerPort int `yaml:"webServerPort"`
YP YP `yaml:"yp"` DisableUpgradeChecks bool `yaml:"disableUpgradeChecks"`
YP YP `yaml:"yp"`
} }
// InstanceDetails defines the user-visible information about this particular instance. // InstanceDetails defines the user-visible information about this particular instance.

35
controllers/admin/inboundBroadcasterDetails.go

@ -1,35 +0,0 @@
package admin
import (
"encoding/json"
"net/http"
"github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/core"
"github.com/owncast/owncast/models"
)
// GetInboundBroadasterDetails gets the details of the inbound broadcaster
func GetInboundBroadasterDetails(w http.ResponseWriter, r *http.Request) {
broadcaster := core.GetBroadcaster()
if broadcaster == nil {
controllers.WriteSimpleResponse(w, false, "no broadcaster connected")
return
}
response := inboundBroadasterDetailsResponse{
models.BaseAPIResponse{
true,
"",
},
broadcaster,
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}
type inboundBroadasterDetailsResponse struct {
models.BaseAPIResponse
Broadcaster *models.Broadcaster `json:"broadcaster"`
}

40
controllers/admin/status.go

@ -0,0 +1,40 @@
package admin
import (
"encoding/json"
"net/http"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core"
"github.com/owncast/owncast/models"
)
// Status gets the details of the inbound broadcaster
func Status(w http.ResponseWriter, r *http.Request) {
broadcaster := core.GetBroadcaster()
status := core.GetStatus()
response := adminStatusResponse{
Broadcaster: broadcaster,
Online: status.Online,
ViewerCount: status.ViewerCount,
OverallPeakViewerCount: status.OverallMaxViewerCount,
SessionPeakViewerCount: status.SessionMaxViewerCount,
VersionNumber: status.VersionNumber,
DisableUpgradeChecks: config.Config.DisableUpgradeChecks,
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}
type adminStatusResponse struct {
Broadcaster *models.Broadcaster `json:"broadcaster"`
Online bool `json:"online"`
ViewerCount int `json:"viewerCount"`
OverallPeakViewerCount int `json:"overallPeakViewerCount"`
SessionPeakViewerCount int `json:"sessionPeakViewerCount"`
VersionNumber string `json:"versionNumber"`
DisableUpgradeChecks bool `json:"disableUpgradeChecks"`
}

8
controllers/status.go

@ -17,11 +17,3 @@ func GetStatus(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(status) json.NewEncoder(w).Encode(status)
} }
//GetStatus gets the status of the server
func GetAdminStatus(w http.ResponseWriter, r *http.Request) {
status := core.GetStatus()
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(status)
}

5
router/router.go

@ -44,11 +44,8 @@ func Start() error {
// Authenticated admin requests // Authenticated admin requests
// status of the system
http.HandleFunc("/api/admin/status", middleware.RequireAdminAuth(controllers.GetAdminStatus))
// Current inbound broadcaster // Current inbound broadcaster
http.HandleFunc("/api/admin/broadcaster", middleware.RequireAdminAuth(admin.GetInboundBroadasterDetails)) http.HandleFunc("/api/admin/status", middleware.RequireAdminAuth(admin.Status))
// Disconnect inbound stream // Disconnect inbound stream
http.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(admin.DisconnectInboundConnection)) http.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(admin.DisconnectInboundConnection))

Loading…
Cancel
Save