unify types.ScreenSize and add ID to screen size update.

This commit is contained in:
Miroslav Šedivý 2024-05-03 22:40:56 +02:00
parent 0f45aa3f19
commit b90eb87c22
5 changed files with 28 additions and 56 deletions

View File

@ -11,24 +11,16 @@ import (
"github.com/demodesk/neko/pkg/utils" "github.com/demodesk/neko/pkg/utils"
) )
type ScreenConfigurationPayload struct {
Width int `json:"width"`
Height int `json:"height"`
Rate int16 `json:"rate"`
}
func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request) error { func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request) error {
size := h.desktop.GetScreenSize() screenSize := h.desktop.GetScreenSize()
return utils.HttpSuccess(w, ScreenConfigurationPayload{ return utils.HttpSuccess(w, screenSize)
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
})
} }
func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.Request) error { func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.Request) error {
data := &ScreenConfigurationPayload{} auth, _ := auth.GetSession(r)
data := &types.ScreenSize{}
if err := utils.HttpJsonRequest(w, r, data); err != nil { if err := utils.HttpJsonRequest(w, r, data); err != nil {
return err return err
} }
@ -43,10 +35,9 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
return utils.HttpUnprocessableEntity("cannot set screen size").WithInternalErr(err) return utils.HttpUnprocessableEntity("cannot set screen size").WithInternalErr(err)
} }
h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSize{ h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSizeUpdate{
Width: size.Width, ID: auth.ID(),
Height: size.Height, ScreenSize: size,
Rate: size.Rate,
}) })
return utils.HttpSuccess(w, data) return utils.HttpSuccess(w, data)
@ -56,16 +47,7 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
func (h *RoomHandler) screenConfigurationsList(w http.ResponseWriter, r *http.Request) error { func (h *RoomHandler) screenConfigurationsList(w http.ResponseWriter, r *http.Request) error {
configurations := h.desktop.ScreenConfigurations() configurations := h.desktop.ScreenConfigurations()
list := make([]ScreenConfigurationPayload, 0, len(configurations)) return utils.HttpSuccess(w, configurations)
for _, conf := range configurations {
list = append(list, ScreenConfigurationPayload{
Width: conf.Width,
Height: conf.Height,
Rate: conf.Rate,
})
}
return utils.HttpSuccess(w, list)
} }
func (h *RoomHandler) screenShotGet(w http.ResponseWriter, r *http.Request) error { func (h *RoomHandler) screenShotGet(w http.ResponseWriter, r *http.Request) error {

View File

@ -13,20 +13,14 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
return errors.New("is not the admin") return errors.New("is not the admin")
} }
size, err := h.desktop.SetScreenSize(types.ScreenSize{ size, err := h.desktop.SetScreenSize(payload.ScreenSize)
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
})
if err != nil { if err != nil {
return err return err
} }
h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSize{ h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSizeUpdate{
Width: size.Width, ID: session.ID(),
Height: size.Height, ScreenSize: size,
Rate: size.Rate,
}) })
return nil return nil
} }

View File

@ -22,13 +22,6 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
HostID: hostID, HostID: hostID,
} }
size := h.desktop.GetScreenSize()
screenSize := message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
}
sessions := map[string]message.SessionData{} sessions := map[string]message.SessionData{}
for _, session := range h.sessions.List() { for _, session := range h.sessions.List() {
sessionId := session.ID() sessionId := session.ID()
@ -44,7 +37,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
message.SystemInit{ message.SystemInit{
SessionId: session.ID(), SessionId: session.ID(),
ControlHost: controlHost, ControlHost: controlHost,
ScreenSize: screenSize, ScreenSize: h.desktop.GetScreenSize(),
Sessions: sessions, Sessions: sessions,
Settings: h.sessions.Settings(), Settings: h.sessions.Settings(),
TouchEvents: h.desktop.HasTouchSupport(), TouchEvents: h.desktop.HasTouchSupport(),
@ -60,9 +53,9 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
func (h *MessageHandlerCtx) systemAdmin(session types.Session) error { func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
configurations := h.desktop.ScreenConfigurations() configurations := h.desktop.ScreenConfigurations()
list := make([]message.ScreenSize, 0, len(configurations)) list := make([]types.ScreenSize, 0, len(configurations))
for _, conf := range configurations { for _, conf := range configurations {
list = append(list, message.ScreenSize{ list = append(list, types.ScreenSize{
Width: conf.Width, Width: conf.Width,
Height: conf.Height, Height: conf.Height,
Rate: conf.Rate, Rate: conf.Rate,

View File

@ -15,9 +15,9 @@ type CursorImage struct {
} }
type ScreenSize struct { type ScreenSize struct {
Width int Width int `json:"width"`
Height int Height int `json:"height"`
Rate int16 Rate int16 `json:"rate"`
} }
func (s ScreenSize) String() string { func (s ScreenSize) String() string {

View File

@ -17,7 +17,7 @@ type SystemWebRTC struct {
type SystemInit struct { type SystemInit struct {
SessionId string `json:"session_id"` SessionId string `json:"session_id"`
ControlHost ControlHost `json:"control_host"` ControlHost ControlHost `json:"control_host"`
ScreenSize ScreenSize `json:"screen_size"` ScreenSize types.ScreenSize `json:"screen_size"`
Sessions map[string]SessionData `json:"sessions"` Sessions map[string]SessionData `json:"sessions"`
Settings types.Settings `json:"settings"` Settings types.Settings `json:"settings"`
TouchEvents bool `json:"touch_events"` TouchEvents bool `json:"touch_events"`
@ -26,8 +26,8 @@ type SystemInit struct {
} }
type SystemAdmin struct { type SystemAdmin struct {
ScreenSizesList []ScreenSize `json:"screen_sizes_list"` ScreenSizesList []types.ScreenSize `json:"screen_sizes_list"`
BroadcastStatus BroadcastStatus `json:"broadcast_status"` BroadcastStatus BroadcastStatus `json:"broadcast_status"`
} }
type SystemLogs = []SystemLog type SystemLogs = []SystemLog
@ -151,9 +151,12 @@ type ControlTouch struct {
///////////////////////////// /////////////////////////////
type ScreenSize struct { type ScreenSize struct {
Width int `json:"width"` types.ScreenSize
Height int `json:"height"` }
Rate int16 `json:"rate"`
type ScreenSizeUpdate struct {
ID string `json:"id"`
types.ScreenSize
} }
///////////////////////////// /////////////////////////////