mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-31 09:57:08 +02:00
move server to server directory.
This commit is contained in:
parent
da45f62ca8
commit
cfb423b13d
211 changed files with 18 additions and 10 deletions
70
server/internal/api/room/broadcast.go
Normal file
70
server/internal/api/room/broadcast.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package room
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/demodesk/neko/pkg/types/event"
|
||||
"github.com/demodesk/neko/pkg/types/message"
|
||||
"github.com/demodesk/neko/pkg/utils"
|
||||
)
|
||||
|
||||
type BroadcastStatusPayload struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) broadcastStatus(w http.ResponseWriter, r *http.Request) error {
|
||||
broadcast := h.capture.Broadcast()
|
||||
|
||||
return utils.HttpSuccess(w, BroadcastStatusPayload{
|
||||
IsActive: broadcast.Started(),
|
||||
URL: broadcast.Url(),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) error {
|
||||
data := &BroadcastStatusPayload{}
|
||||
if err := utils.HttpJsonRequest(w, r, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if data.URL == "" {
|
||||
return utils.HttpBadRequest("missing broadcast URL")
|
||||
}
|
||||
|
||||
broadcast := h.capture.Broadcast()
|
||||
if broadcast.Started() {
|
||||
return utils.HttpUnprocessableEntity("server is already broadcasting")
|
||||
}
|
||||
|
||||
if err := broadcast.Start(data.URL); err != nil {
|
||||
return utils.HttpInternalServerError().WithInternalErr(err)
|
||||
}
|
||||
|
||||
h.sessions.AdminBroadcast(
|
||||
event.BORADCAST_STATUS,
|
||||
message.BroadcastStatus{
|
||||
IsActive: broadcast.Started(),
|
||||
URL: broadcast.Url(),
|
||||
})
|
||||
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) error {
|
||||
broadcast := h.capture.Broadcast()
|
||||
if !broadcast.Started() {
|
||||
return utils.HttpUnprocessableEntity("server is not broadcasting")
|
||||
}
|
||||
|
||||
broadcast.Stop()
|
||||
|
||||
h.sessions.AdminBroadcast(
|
||||
event.BORADCAST_STATUS,
|
||||
message.BroadcastStatus{
|
||||
IsActive: broadcast.Started(),
|
||||
URL: broadcast.Url(),
|
||||
})
|
||||
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue