add control status.

This commit is contained in:
Miroslav Šedivý 2020-11-18 23:14:28 +01:00
parent 628abe06fd
commit fb6dabf4e0
2 changed files with 21 additions and 0 deletions

View File

@ -9,10 +9,30 @@ import (
"demodesk/neko/internal/http/auth"
)
type ControlStatusPayload struct {
HasHost bool `json:"has_host"`
HostId string `json:"host_id,omitempty"`
}
type ControlTargetPayload struct {
ID string `json:"id"`
}
func (h *RoomHandler) controlStatus(w http.ResponseWriter, r *http.Request) {
host := h.sessions.GetHost()
if host == nil {
utils.HttpSuccess(w, ControlStatusPayload{
HasHost: false,
})
} else {
utils.HttpSuccess(w, ControlStatusPayload{
HasHost: true,
HostId: host.ID(),
})
}
}
func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) {
host := h.sessions.GetHost()
if host != nil {

View File

@ -52,6 +52,7 @@ func (h *RoomHandler) Route(r chi.Router) {
})
r.Route("/control", func(r chi.Router) {
r.Get("/", h.controlStatus)
r.Post("/request", h.controlRequest)
r.Post("/release", h.controlRelease)