generate screenshot using Xlib.

This commit is contained in:
Miroslav Šedivý
2021-01-21 20:44:09 +01:00
parent 7ff6ada205
commit afd3dd2f56
8 changed files with 110 additions and 1 deletions

View File

@ -61,7 +61,8 @@ func (h *RoomHandler) Route(r chi.Router) {
})
r.Route("/screen", func(r chi.Router) {
r.Get("/", h.screenConfiguration)
r.With(auth.CanWatchOnly).Get("/", h.screenConfiguration)
r.With(auth.CanWatchOnly).Get("/image", h.screenImageGet)
r.With(auth.AdminsOnly).Post("/", h.screenConfigurationChange)
r.With(auth.AdminsOnly).Get("/configurations", h.screenConfigurationsList)

View File

@ -1,6 +1,9 @@
package room
import (
"bytes"
"image/jpeg"
"strconv"
"net/http"
"demodesk/neko/internal/types"
@ -72,3 +75,23 @@ func (h *RoomHandler) screenConfigurationsList(w http.ResponseWriter, r *http.Re
utils.HttpSuccess(w, list)
}
func (h *RoomHandler) screenImageGet(w http.ResponseWriter, r *http.Request) {
var options *jpeg.Options
if quality, err := strconv.Atoi(r.URL.Query().Get("quality")); err == nil {
options = &jpeg.Options{ quality }
} else {
options = &jpeg.Options{ 90 }
}
img := h.desktop.GetScreenshotImage()
out := new(bytes.Buffer)
err := jpeg.Encode(out, img, options)
if err != nil {
utils.HttpInternalServerError(w, err)
return
}
w.Header().Set("Content-Type", "image/jpeg")
w.Write(out.Bytes())
}