neko/internal/api/room/screen.go

62 lines
1.3 KiB
Go
Raw Normal View History

2020-10-29 22:23:30 +01:00
package room
2020-10-30 18:16:21 +01:00
import (
"net/http"
"demodesk/neko/internal/utils"
2020-10-30 19:56:22 +01:00
)
2020-10-30 18:16:21 +01:00
2020-10-30 21:28:07 +01:00
type ScreenConfiguration struct {
2020-10-30 18:16:21 +01:00
Width int `json:"width"`
Height int `json:"height"`
Rate int `json:"rate"`
}
2020-10-30 21:28:07 +01:00
func (h *RoomHandler) ScreenConfiguration(w http.ResponseWriter, r *http.Request) {
2020-11-01 16:54:06 +01:00
size := h.desktop.GetScreenSize()
2020-10-30 18:16:21 +01:00
if size == nil {
utils.HttpInternalServer(w, "Unable to get screen configuration.")
2020-10-30 18:16:21 +01:00
return
}
utils.HttpSuccess(w, ScreenConfiguration{
2020-10-30 18:16:21 +01:00
Width: size.Width,
Height: size.Height,
Rate: int(size.Rate),
})
}
2020-10-30 21:28:07 +01:00
func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.Request) {
data := &ScreenConfiguration{}
if !utils.HttpJsonRequest(w, r, data) {
2020-10-30 19:56:22 +01:00
return
}
2020-11-04 00:27:47 +01:00
if err := h.desktop.ChangeScreenSize(data.Width, data.Height, data.Rate); err != nil {
utils.HttpUnprocessableEntity(w, err)
2020-10-30 19:56:22 +01:00
return
}
2020-11-01 16:54:06 +01:00
// TODO: Broadcast change to all sessions.
2020-10-30 19:56:22 +01:00
utils.HttpSuccess(w, data)
2020-10-30 18:16:21 +01:00
}
2020-10-30 21:28:07 +01:00
func (h *RoomHandler) ScreenConfigurationsList(w http.ResponseWriter, r *http.Request) {
list := []ScreenConfiguration{}
2020-10-30 22:20:23 +01:00
2020-11-01 16:54:06 +01:00
ScreenConfigurations := h.desktop.ScreenConfigurations()
2020-10-30 22:20:23 +01:00
for _, size := range ScreenConfigurations {
for _, fps := range size.Rates {
list = append(list, ScreenConfiguration{
2020-10-30 22:20:23 +01:00
Width: size.Width,
Height: size.Height,
Rate: int(fps),
})
}
}
utils.HttpSuccess(w, list)
2020-10-30 18:16:21 +01:00
}