mirror of
https://github.com/owncast/owncast.git
synced 2024-10-10 19:16:02 +00:00
Admin API to change in-memory streaming key. Closes #212
This commit is contained in:
parent
7b64fc7c30
commit
48c8cf5ed2
35
controllers/admin/changeStreamKey.go
Normal file
35
controllers/admin/changeStreamKey.go
Normal file
@ -0,0 +1,35 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gabek/owncast/config"
|
||||
"github.com/gabek/owncast/controllers"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// ChangeStreamKey will change the stream key (in memory)
|
||||
func ChangeStreamKey(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" {
|
||||
controllers.WriteSimpleResponse(w, false, r.Method+" not supported")
|
||||
return
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
var request changeStreamKeyRequest
|
||||
err := decoder.Decode(&request)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
controllers.WriteSimpleResponse(w, false, "")
|
||||
return
|
||||
}
|
||||
|
||||
config.Config.VideoSettings.StreamingKey = request.Key
|
||||
controllers.WriteSimpleResponse(w, true, "changed")
|
||||
}
|
||||
|
||||
type changeStreamKeyRequest struct {
|
||||
Key string `json:"key"`
|
||||
}
|
@ -1,19 +1,21 @@
|
||||
package controllers
|
||||
package admin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gabek/owncast/controllers"
|
||||
"github.com/gabek/owncast/core"
|
||||
|
||||
"github.com/gabek/owncast/core/rtmp"
|
||||
)
|
||||
|
||||
// DisconnectInboundConnection will force-disconnect an inbound stream
|
||||
func DisconnectInboundConnection(w http.ResponseWriter, r *http.Request) {
|
||||
if !core.GetStatus().Online {
|
||||
writeSimpleResponse(w, false, "no inbound stream connected")
|
||||
controllers.WriteSimpleResponse(w, false, "no inbound stream connected")
|
||||
return
|
||||
}
|
||||
|
||||
rtmp.Disconnect()
|
||||
writeSimpleResponse(w, true, "inbound stream disconnected")
|
||||
controllers.WriteSimpleResponse(w, true, "inbound stream disconnected")
|
||||
}
|
@ -27,7 +27,7 @@ func badRequestHandler(w http.ResponseWriter, err error) {
|
||||
json.NewEncoder(w).Encode(j{"error": err.Error()})
|
||||
}
|
||||
|
||||
func writeSimpleResponse(w http.ResponseWriter, success bool, message string) {
|
||||
func WriteSimpleResponse(w http.ResponseWriter, success bool, message string) {
|
||||
response := models.BaseAPIResponse{
|
||||
Success: success,
|
||||
Message: message,
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
|
||||
"github.com/gabek/owncast/config"
|
||||
"github.com/gabek/owncast/controllers"
|
||||
"github.com/gabek/owncast/controllers/admin"
|
||||
|
||||
"github.com/gabek/owncast/core/chat"
|
||||
"github.com/gabek/owncast/core/rtmp"
|
||||
"github.com/gabek/owncast/router/middleware"
|
||||
@ -47,7 +49,10 @@ func Start() error {
|
||||
// Authenticated admin requests
|
||||
|
||||
// Disconnect inbound stream
|
||||
http.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(controllers.DisconnectInboundConnection))
|
||||
http.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(admin.DisconnectInboundConnection))
|
||||
|
||||
// Change the current streaming key in memory
|
||||
http.HandleFunc("/api/admin/changekey", middleware.RequireAdminAuth(admin.ChangeStreamKey))
|
||||
|
||||
port := config.Config.GetPublicWebServerPort()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user