neko/internal/api/room/screen.go

60 lines
1.4 KiB
Go
Raw Normal View History

2020-10-30 10:23:30 +13:00
package room
2020-10-31 06:16:21 +13:00
import (
"net/http"
"github.com/go-chi/render"
2020-10-31 07:56:22 +13:00
"demodesk/neko/internal/api/utils"
2020-10-31 09:29:51 +13:00
"demodesk/neko/internal/websocket/broadcast"
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 (a *ScreenConfiguration) Bind(r *http.Request) error {
2020-10-31 07:56:22 +13:00
return nil
}
2020-10-31 09:28:07 +13:00
func (h *RoomHandler) ScreenConfiguration(w http.ResponseWriter, r *http.Request) {
2020-10-31 06:16:21 +13:00
size := h.remote.GetScreenSize()
if size == nil {
2020-10-31 07:56:22 +13:00
render.Render(w, r, utils.ErrMessage(500, "Not implmented."))
2020-10-31 06:16:21 +13:00
return
}
2020-10-31 09:28:07 +13:00
render.JSON(w, r, 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-10-31 07:56:22 +13:00
if err := render.Bind(r, data); err != nil {
render.Render(w, r, utils.ErrInvalidRequest(err))
return
}
if err := h.remote.ChangeResolution(data.Width, data.Height, data.Rate); err != nil {
render.Render(w, r, utils.ErrInvalidRequest(err))
return
}
2020-10-31 09:29:51 +13:00
if err := broadcast.ScreenConfiguration(h.sessions, "-todo-session-id-", data.Width, data.Height, data.Rate); err != nil {
render.Render(w, r, utils.ErrInvalidRequest(err))
return
}
2020-10-31 07:56:22 +13:00
render.JSON(w, r, 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-10-31 07:56:22 +13:00
render.Render(w, r, utils.ErrMessage(500, "Not implmented."))
2020-10-31 06:16:21 +13:00
}