2020-10-29 22:23:30 +01:00
|
|
|
package room
|
2020-11-18 21:34:39 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-03-20 11:43:00 +01:00
|
|
|
"gitlab.com/demodesk/neko/server/pkg/types/event"
|
|
|
|
"gitlab.com/demodesk/neko/server/pkg/types/message"
|
|
|
|
"gitlab.com/demodesk/neko/server/pkg/utils"
|
2020-11-18 21:34:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type BroadcastStatusPayload struct {
|
2021-02-14 14:40:17 +01:00
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
IsActive bool `json:"is_active"`
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) broadcastStatus(w http.ResponseWriter, r *http.Request) error {
|
2021-01-22 14:09:47 +01:00
|
|
|
broadcast := h.capture.Broadcast()
|
2021-09-17 00:58:50 +02:00
|
|
|
|
|
|
|
return utils.HttpSuccess(w, BroadcastStatusPayload{
|
2021-02-05 14:03:53 +01:00
|
|
|
IsActive: broadcast.Started(),
|
2021-01-22 14:09:47 +01:00
|
|
|
URL: broadcast.Url(),
|
2020-11-18 21:34:39 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) error {
|
2020-11-18 21:34:39 +01:00
|
|
|
data := &BroadcastStatusPayload{}
|
2021-09-17 00:58:50 +02:00
|
|
|
if err := utils.HttpJsonRequest(w, r, data); err != nil {
|
|
|
|
return err
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.URL == "" {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpBadRequest("missing broadcast URL")
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|
|
|
|
|
2021-01-22 14:09:47 +01:00
|
|
|
broadcast := h.capture.Broadcast()
|
2021-02-05 14:03:53 +01:00
|
|
|
if broadcast.Started() {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpUnprocessableEntity("server is already broadcasting")
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|
|
|
|
|
2021-01-22 14:09:47 +01:00
|
|
|
if err := broadcast.Start(data.URL); err != nil {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpInternalServerError().WithInternalErr(err)
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
h.sessions.AdminBroadcast(
|
2021-09-01 21:58:39 +02:00
|
|
|
event.BORADCAST_STATUS,
|
2020-11-18 21:34:39 +01:00
|
|
|
message.BroadcastStatus{
|
2021-02-05 14:03:53 +01:00
|
|
|
IsActive: broadcast.Started(),
|
2021-01-22 14:09:47 +01:00
|
|
|
URL: broadcast.Url(),
|
2020-11-18 21:34:39 +01:00
|
|
|
}, nil)
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpSuccess(w)
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) error {
|
2021-01-22 14:09:47 +01:00
|
|
|
broadcast := h.capture.Broadcast()
|
2021-02-05 14:03:53 +01:00
|
|
|
if !broadcast.Started() {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpUnprocessableEntity("server is not broadcasting")
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|
2021-02-02 18:28:32 +01:00
|
|
|
|
2021-01-22 14:09:47 +01:00
|
|
|
broadcast.Stop()
|
2020-11-18 21:34:39 +01:00
|
|
|
|
|
|
|
h.sessions.AdminBroadcast(
|
2021-09-01 21:58:39 +02:00
|
|
|
event.BORADCAST_STATUS,
|
2020-11-18 21:34:39 +01:00
|
|
|
message.BroadcastStatus{
|
2021-02-05 14:03:53 +01:00
|
|
|
IsActive: broadcast.Started(),
|
2021-01-22 14:09:47 +01:00
|
|
|
URL: broadcast.Url(),
|
2020-11-18 21:34:39 +01:00
|
|
|
}, nil)
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpSuccess(w)
|
2020-11-18 21:34:39 +01:00
|
|
|
}
|