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