diff --git a/internal/api/room/screen.go b/internal/api/room/screen.go index 174f3477..12124bdc 100644 --- a/internal/api/room/screen.go +++ b/internal/api/room/screen.go @@ -11,24 +11,16 @@ import ( "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 { - size := h.desktop.GetScreenSize() + screenSize := h.desktop.GetScreenSize() - return utils.HttpSuccess(w, ScreenConfigurationPayload{ - Width: size.Width, - Height: size.Height, - Rate: size.Rate, - }) + return utils.HttpSuccess(w, screenSize) } 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 { 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) } - h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSize{ - Width: size.Width, - Height: size.Height, - Rate: size.Rate, + h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSizeUpdate{ + ID: auth.ID(), + ScreenSize: size, }) 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 { 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, - }) - } - - return utils.HttpSuccess(w, list) + return utils.HttpSuccess(w, configurations) } func (h *RoomHandler) screenShotGet(w http.ResponseWriter, r *http.Request) error { diff --git a/internal/websocket/handler/screen.go b/internal/websocket/handler/screen.go index 8d88ac9d..4419cd92 100644 --- a/internal/websocket/handler/screen.go +++ b/internal/websocket/handler/screen.go @@ -13,20 +13,14 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc return errors.New("is not the admin") } - size, err := h.desktop.SetScreenSize(types.ScreenSize{ - Width: payload.Width, - Height: payload.Height, - Rate: payload.Rate, - }) - + size, err := h.desktop.SetScreenSize(payload.ScreenSize) if err != nil { return err } - h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSize{ - Width: size.Width, - Height: size.Height, - Rate: size.Rate, + h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSizeUpdate{ + ID: session.ID(), + ScreenSize: size, }) return nil } diff --git a/internal/websocket/handler/system.go b/internal/websocket/handler/system.go index adf375d2..3ec60489 100644 --- a/internal/websocket/handler/system.go +++ b/internal/websocket/handler/system.go @@ -22,13 +22,6 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error { HostID: hostID, } - size := h.desktop.GetScreenSize() - screenSize := message.ScreenSize{ - Width: size.Width, - Height: size.Height, - Rate: size.Rate, - } - sessions := map[string]message.SessionData{} for _, session := range h.sessions.List() { sessionId := session.ID() @@ -44,7 +37,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error { message.SystemInit{ SessionId: session.ID(), ControlHost: controlHost, - ScreenSize: screenSize, + ScreenSize: h.desktop.GetScreenSize(), Sessions: sessions, Settings: h.sessions.Settings(), TouchEvents: h.desktop.HasTouchSupport(), @@ -60,9 +53,9 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error { func (h *MessageHandlerCtx) systemAdmin(session types.Session) error { configurations := h.desktop.ScreenConfigurations() - list := make([]message.ScreenSize, 0, len(configurations)) + list := make([]types.ScreenSize, 0, len(configurations)) for _, conf := range configurations { - list = append(list, message.ScreenSize{ + list = append(list, types.ScreenSize{ Width: conf.Width, Height: conf.Height, Rate: conf.Rate, diff --git a/pkg/types/desktop.go b/pkg/types/desktop.go index b7699096..0cc4cae9 100644 --- a/pkg/types/desktop.go +++ b/pkg/types/desktop.go @@ -15,9 +15,9 @@ type CursorImage struct { } type ScreenSize struct { - Width int - Height int - Rate int16 + Width int `json:"width"` + Height int `json:"height"` + Rate int16 `json:"rate"` } func (s ScreenSize) String() string { diff --git a/pkg/types/message/messages.go b/pkg/types/message/messages.go index c2121dee..3ba1ab19 100644 --- a/pkg/types/message/messages.go +++ b/pkg/types/message/messages.go @@ -17,7 +17,7 @@ type SystemWebRTC struct { type SystemInit struct { SessionId string `json:"session_id"` ControlHost ControlHost `json:"control_host"` - ScreenSize ScreenSize `json:"screen_size"` + ScreenSize types.ScreenSize `json:"screen_size"` Sessions map[string]SessionData `json:"sessions"` Settings types.Settings `json:"settings"` TouchEvents bool `json:"touch_events"` @@ -26,8 +26,8 @@ type SystemInit struct { } type SystemAdmin struct { - ScreenSizesList []ScreenSize `json:"screen_sizes_list"` - BroadcastStatus BroadcastStatus `json:"broadcast_status"` + ScreenSizesList []types.ScreenSize `json:"screen_sizes_list"` + BroadcastStatus BroadcastStatus `json:"broadcast_status"` } type SystemLogs = []SystemLog @@ -151,9 +151,12 @@ type ControlTouch struct { ///////////////////////////// type ScreenSize struct { - Width int `json:"width"` - Height int `json:"height"` - Rate int16 `json:"rate"` + types.ScreenSize +} + +type ScreenSizeUpdate struct { + ID string `json:"id"` + types.ScreenSize } /////////////////////////////