neko/internal/api/room/broadcast.go

74 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) {
broadcast := h.capture.Broadcast()
utils.HttpSuccess(w, BroadcastStatusPayload{
IsActive: broadcast.Enabled(),
URL: broadcast.Url(),
})
}
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
}
broadcast := h.capture.Broadcast()
if broadcast.Enabled() {
utils.HttpUnprocessableEntity(w, "Server is already broadcasting.")
return
}
if err := broadcast.Start(data.URL); err != nil {
2020-11-29 03:00:21 +13:00
utils.HttpInternalServerError(w, err)
return
}
h.sessions.AdminBroadcast(
message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
IsActive: broadcast.Enabled(),
URL: broadcast.Url(),
}, nil)
utils.HttpSuccess(w)
}
2020-11-19 10:35:50 +13:00
func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) {
broadcast := h.capture.Broadcast()
if !broadcast.Enabled() {
utils.HttpUnprocessableEntity(w, "Server is not broadcasting.")
return
}
broadcast.Stop()
h.sessions.AdminBroadcast(
message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
IsActive: broadcast.Enabled(),
URL: broadcast.Url(),
}, nil)
utils.HttpSuccess(w)
}