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/types/event"
"demodesk/neko/internal/types/message"
2021-02-15 02:40:17 +13:00
"demodesk/neko/internal/utils"
)
type BroadcastStatusPayload struct {
2021-02-15 02:40:17 +13:00
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{
2021-02-06 02:03:53 +13:00
IsActive: broadcast.Started(),
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 == "" {
2021-04-25 07:37:43 +12:00
utils.HttpBadRequest(w, "missing broadcast URL")
return
}
broadcast := h.capture.Broadcast()
2021-02-06 02:03:53 +13:00
if broadcast.Started() {
2021-04-25 07:37:43 +12:00
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,
2021-02-06 02:03:53 +13:00
IsActive: broadcast.Started(),
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()
2021-02-06 02:03:53 +13:00
if !broadcast.Started() {
2021-04-25 07:37:43 +12:00
utils.HttpUnprocessableEntity(w, "server is not broadcasting")
return
}
2021-02-03 06:28:32 +13:00
broadcast.Stop()
h.sessions.AdminBroadcast(
message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
2021-02-06 02:03:53 +13:00
IsActive: broadcast.Started(),
URL: broadcast.Url(),
}, nil)
utils.HttpSuccess(w)
}