2020-10-30 10:23:30 +13:00
|
|
|
package room
|
2020-11-19 09:34:39 +13:00
|
|
|
|
|
|
|
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"
|
2020-11-19 09:34:39 +13:00
|
|
|
)
|
|
|
|
|
|
|
|
type BroadcastStatusPayload struct {
|
2021-02-15 02:40:17 +13:00
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
IsActive bool `json:"is_active"`
|
2020-11-19 09:34:39 +13:00
|
|
|
}
|
|
|
|
|
2020-11-19 10:35:50 +13:00
|
|
|
func (h *RoomHandler) broadcastStatus(w http.ResponseWriter, r *http.Request) {
|
2021-01-23 02:09:47 +13:00
|
|
|
broadcast := h.capture.Broadcast()
|
2020-11-19 09:34:39 +13:00
|
|
|
utils.HttpSuccess(w, BroadcastStatusPayload{
|
2021-02-06 02:03:53 +13:00
|
|
|
IsActive: broadcast.Started(),
|
2021-01-23 02:09:47 +13:00
|
|
|
URL: broadcast.Url(),
|
2020-11-19 09:34:39 +13:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:35:50 +13:00
|
|
|
func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) {
|
2020-11-19 09:34:39 +13:00
|
|
|
data := &BroadcastStatusPayload{}
|
|
|
|
if !utils.HttpJsonRequest(w, r, data) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.URL == "" {
|
|
|
|
utils.HttpBadRequest(w, "Missing broadcast URL.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-23 02:09:47 +13:00
|
|
|
broadcast := h.capture.Broadcast()
|
2021-02-06 02:03:53 +13:00
|
|
|
if broadcast.Started() {
|
2020-11-19 11:05:26 +13:00
|
|
|
utils.HttpUnprocessableEntity(w, "Server is already broadcasting.")
|
2020-11-19 09:34:39 +13:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-23 02:09:47 +13:00
|
|
|
if err := broadcast.Start(data.URL); err != nil {
|
2020-11-29 03:00:21 +13:00
|
|
|
utils.HttpInternalServerError(w, err)
|
2020-11-19 09:34:39 +13:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
h.sessions.AdminBroadcast(
|
|
|
|
message.BroadcastStatus{
|
|
|
|
Event: event.BORADCAST_STATUS,
|
2021-02-06 02:03:53 +13:00
|
|
|
IsActive: broadcast.Started(),
|
2021-01-23 02:09:47 +13:00
|
|
|
URL: broadcast.Url(),
|
2020-11-19 09:34:39 +13:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
utils.HttpSuccess(w)
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:35:50 +13:00
|
|
|
func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) {
|
2021-01-23 02:09:47 +13:00
|
|
|
broadcast := h.capture.Broadcast()
|
2021-02-06 02:03:53 +13:00
|
|
|
if !broadcast.Started() {
|
2020-11-19 11:05:26 +13:00
|
|
|
utils.HttpUnprocessableEntity(w, "Server is not broadcasting.")
|
2020-11-19 09:34:39 +13:00
|
|
|
return
|
|
|
|
}
|
2021-02-03 06:28:32 +13:00
|
|
|
|
2021-01-23 02:09:47 +13:00
|
|
|
broadcast.Stop()
|
2020-11-19 09:34:39 +13:00
|
|
|
|
|
|
|
h.sessions.AdminBroadcast(
|
|
|
|
message.BroadcastStatus{
|
|
|
|
Event: event.BORADCAST_STATUS,
|
2021-02-06 02:03:53 +13:00
|
|
|
IsActive: broadcast.Started(),
|
2021-01-23 02:09:47 +13:00
|
|
|
URL: broadcast.Url(),
|
2020-11-19 09:34:39 +13:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
utils.HttpSuccess(w)
|
|
|
|
}
|