REST API keyboard.

This commit is contained in:
Miroslav Šedivý 2020-11-18 21:53:06 +01:00
parent db820806a4
commit ac2fc100b4
2 changed files with 64 additions and 0 deletions

View File

@ -60,4 +60,9 @@ func (h *RoomHandler) Route(r chi.Router) {
r.Post("/start", h.BoradcastStart) r.Post("/start", h.BoradcastStart)
r.Post("/stop", h.BoradcastStop) r.Post("/stop", h.BoradcastStop)
}) })
r.With(auth.HostsOnly).Route("/keyboard", func(r chi.Router) {
r.Post("/layout", h.KeyboardLayoutSet)
r.Post("/modifiers", h.KeyboardModifiersSet)
})
} }

View File

@ -1 +1,60 @@
package room package room
import (
"net/http"
"demodesk/neko/internal/utils"
)
type KeyboardLayoutData struct {
Layout string `json:"layout"`
}
type KeyboardModifiersData struct {
NumLock *bool `json:"numlock"`
CapsLock *bool `json:"capslock"`
ScrollLock *bool `json:"scrollock"`
}
func (h *RoomHandler) KeyboardLayoutSet(w http.ResponseWriter, r *http.Request) {
data := &KeyboardLayoutData{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
h.desktop.SetKeyboardLayout(data.Layout)
utils.HttpSuccess(w)
}
func (h *RoomHandler) KeyboardModifiersSet(w http.ResponseWriter, r *http.Request) {
data := &KeyboardModifiersData{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
var NumLock = 0
if data.NumLock == nil {
NumLock = -1
} else if *data.NumLock {
NumLock = 1
}
var CapsLock = 0
if data.CapsLock == nil {
CapsLock = -1
} else if *data.CapsLock {
CapsLock = 1
}
var ScrollLock = 0
if data.ScrollLock == nil {
ScrollLock = -1
} else if *data.ScrollLock {
ScrollLock = 1
}
h.desktop.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
utils.HttpSuccess(w)
}