2020-10-29 22:23:30 +01:00
|
|
|
package room
|
2020-10-30 18:16:21 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2021-02-14 14:40:17 +01:00
|
|
|
"strconv"
|
2020-10-30 18:16:21 +01:00
|
|
|
|
2022-07-14 00:58:22 +02:00
|
|
|
"github.com/demodesk/neko/pkg/auth"
|
|
|
|
"github.com/demodesk/neko/pkg/types"
|
|
|
|
"github.com/demodesk/neko/pkg/types/event"
|
|
|
|
"github.com/demodesk/neko/pkg/types/message"
|
|
|
|
"github.com/demodesk/neko/pkg/utils"
|
2020-10-30 19:56:22 +01:00
|
|
|
)
|
2020-10-30 18:16:21 +01:00
|
|
|
|
2020-11-18 21:56:42 +01:00
|
|
|
type ScreenConfigurationPayload struct {
|
2021-01-15 17:30:19 +01:00
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Rate int16 `json:"rate"`
|
2020-10-30 18:16:21 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request) error {
|
2020-11-01 16:54:06 +01:00
|
|
|
size := h.desktop.GetScreenSize()
|
2020-10-30 18:16:21 +01:00
|
|
|
|
2023-02-14 21:18:47 +01:00
|
|
|
return utils.HttpSuccess(w, ScreenConfigurationPayload{
|
|
|
|
Width: size.Width,
|
|
|
|
Height: size.Height,
|
|
|
|
Rate: size.Rate,
|
|
|
|
})
|
2020-10-30 18:16:21 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.Request) error {
|
2020-11-18 21:56:42 +01:00
|
|
|
data := &ScreenConfigurationPayload{}
|
2021-09-17 00:58:50 +02:00
|
|
|
if err := utils.HttpJsonRequest(w, r, data); err != nil {
|
|
|
|
return err
|
2020-10-30 19:56:22 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 21:18:47 +01:00
|
|
|
size, err := h.desktop.SetScreenSize(types.ScreenSize{
|
|
|
|
Width: data.Width,
|
|
|
|
Height: data.Height,
|
|
|
|
Rate: data.Rate,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpUnprocessableEntity("cannot set screen size").WithInternalErr(err)
|
2020-10-30 19:56:22 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 21:18:47 +01:00
|
|
|
h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSize{
|
|
|
|
Width: size.Width,
|
|
|
|
Height: size.Height,
|
|
|
|
Rate: size.Rate,
|
|
|
|
})
|
2020-10-30 19:56:22 +01:00
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpSuccess(w, data)
|
2020-10-30 18:16:21 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 21:18:47 +01:00
|
|
|
// TODO: remove.
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) screenConfigurationsList(w http.ResponseWriter, r *http.Request) error {
|
2023-02-14 21:18:47 +01:00
|
|
|
configurations := h.desktop.ScreenConfigurations()
|
|
|
|
|
|
|
|
list := make([]ScreenConfigurationPayload, 0, len(configurations))
|
|
|
|
for _, conf := range configurations {
|
|
|
|
list = append(list, ScreenConfigurationPayload{
|
|
|
|
Width: conf.Width,
|
|
|
|
Height: conf.Height,
|
|
|
|
Rate: conf.Rate,
|
|
|
|
})
|
2020-10-30 22:20:23 +01:00
|
|
|
}
|
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpSuccess(w, list)
|
2020-10-30 18:16:21 +01:00
|
|
|
}
|
2021-01-21 20:44:09 +01:00
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) screenShotGet(w http.ResponseWriter, r *http.Request) error {
|
2021-01-25 17:31:24 +01:00
|
|
|
quality, err := strconv.Atoi(r.URL.Query().Get("quality"))
|
|
|
|
if err != nil {
|
|
|
|
quality = 90
|
2021-01-21 20:44:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
img := h.desktop.GetScreenshotImage()
|
2021-02-25 14:15:18 +01:00
|
|
|
bytes, err := utils.CreateJPGImage(img, quality)
|
|
|
|
if err != nil {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpInternalServerError().WithInternalErr(err)
|
2021-01-21 20:44:09 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 15:23:10 +01:00
|
|
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
2021-01-21 20:44:09 +01:00
|
|
|
w.Header().Set("Content-Type", "image/jpeg")
|
2021-09-17 00:58:50 +02:00
|
|
|
|
|
|
|
_, err = w.Write(bytes)
|
|
|
|
return err
|
2021-01-21 20:44:09 +01:00
|
|
|
}
|
2021-01-22 18:13:32 +01:00
|
|
|
|
2021-09-17 00:58:50 +02:00
|
|
|
func (h *RoomHandler) screenCastGet(w http.ResponseWriter, r *http.Request) error {
|
2022-03-26 23:20:38 +01:00
|
|
|
// display fallback image when private mode is enabled even if screencast is not
|
|
|
|
if session, ok := auth.GetSession(r); ok && session.PrivateModeEnabled() {
|
|
|
|
if h.privateModeImage != nil {
|
|
|
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
w.Header().Set("Content-Type", "image/jpeg")
|
|
|
|
|
|
|
|
_, err := w.Write(h.privateModeImage)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return utils.HttpBadRequest("private mode is enabled but no fallback image available")
|
|
|
|
}
|
|
|
|
|
2021-01-22 18:13:32 +01:00
|
|
|
screencast := h.capture.Screencast()
|
|
|
|
if !screencast.Enabled() {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpBadRequest("screencast pipeline is not enabled")
|
2021-01-22 18:13:32 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 15:17:52 +01:00
|
|
|
bytes, err := screencast.Image()
|
|
|
|
if err != nil {
|
2021-09-17 00:58:50 +02:00
|
|
|
return utils.HttpInternalServerError().WithInternalErr(err)
|
2021-01-23 15:17:52 +01:00
|
|
|
}
|
|
|
|
|
2021-01-22 18:13:32 +01:00
|
|
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
w.Header().Set("Content-Type", "image/jpeg")
|
2021-09-17 00:58:50 +02:00
|
|
|
|
|
|
|
_, err = w.Write(bytes)
|
|
|
|
return err
|
2021-01-22 18:13:32 +01:00
|
|
|
}
|