mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add broadcast endpoint & broadcast pipeline return error.
This commit is contained in:
@ -1 +1,70 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/utils"
|
||||
"demodesk/neko/internal/types/event"
|
||||
"demodesk/neko/internal/types/message"
|
||||
)
|
||||
|
||||
type BroadcastStatusPayload struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) BroadcastStatus(w http.ResponseWriter, r *http.Request) {
|
||||
utils.HttpSuccess(w, BroadcastStatusPayload{
|
||||
IsActive: h.capture.BroadcastEnabled(),
|
||||
URL: h.capture.BroadcastUrl(),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *RoomHandler) BoradcastStart(w http.ResponseWriter, r *http.Request) {
|
||||
data := &BroadcastStatusPayload{}
|
||||
if !utils.HttpJsonRequest(w, r, data) {
|
||||
return
|
||||
}
|
||||
|
||||
if data.URL == "" {
|
||||
utils.HttpBadRequest(w, "Missing broadcast URL.")
|
||||
return
|
||||
}
|
||||
|
||||
if h.capture.BroadcastEnabled() {
|
||||
utils.HttpBadRequest(w, "Server is already broadcasting.")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.capture.StartBroadcast(data.URL); err != nil {
|
||||
utils.HttpInternalServer(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.sessions.AdminBroadcast(
|
||||
message.BroadcastStatus{
|
||||
Event: event.BORADCAST_STATUS,
|
||||
IsActive: h.capture.BroadcastEnabled(),
|
||||
URL: h.capture.BroadcastUrl(),
|
||||
}, nil)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) BoradcastStop(w http.ResponseWriter, r *http.Request) {
|
||||
if !h.capture.BroadcastEnabled() {
|
||||
utils.HttpBadRequest(w, "Server is not broadcasting.")
|
||||
return
|
||||
}
|
||||
|
||||
h.capture.StopBroadcast()
|
||||
|
||||
h.sessions.AdminBroadcast(
|
||||
message.BroadcastStatus{
|
||||
Event: event.BORADCAST_STATUS,
|
||||
IsActive: h.capture.BroadcastEnabled(),
|
||||
URL: h.capture.BroadcastUrl(),
|
||||
}, nil)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
@ -54,4 +54,10 @@ func (h *RoomHandler) Route(r chi.Router) {
|
||||
r.With(auth.AdminsOnly).Post("/take", h.ControlTake)
|
||||
r.With(auth.AdminsOnly).Post("/give", h.ControlGive)
|
||||
})
|
||||
|
||||
r.With(auth.AdminsOnly).Route("/broadcast", func(r chi.Router) {
|
||||
r.Get("/", h.BroadcastStatus)
|
||||
r.Post("/start", h.BoradcastStart)
|
||||
r.Post("/stop", h.BoradcastStop)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user