neko/internal/api/room/broadcast.go

71 lines
1.6 KiB
Go
Raw Normal View History

2020-10-30 10:23:30 +13:00
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"`
}
2020-11-19 10:35:50 +13:00
func (h *RoomHandler) broadcastStatus(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w, BroadcastStatusPayload{
IsActive: h.capture.BroadcastEnabled(),
URL: h.capture.BroadcastUrl(),
})
}
2020-11-19 10:35:50 +13:00
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.HttpUnprocessableEntity(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)
}
2020-11-19 10:35:50 +13:00
func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) {
if !h.capture.BroadcastEnabled() {
utils.HttpUnprocessableEntity(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)
}