diff --git a/internal/api/room/screen.go b/internal/api/room/screen.go index 7afc2117..06a3b729 100644 --- a/internal/api/room/screen.go +++ b/internal/api/room/screen.go @@ -6,7 +6,6 @@ import ( "demodesk/neko/internal/types/event" "demodesk/neko/internal/types/message" "demodesk/neko/internal/utils" - "demodesk/neko/internal/http/auth" ) type ScreenConfigurationPayload struct { @@ -41,12 +40,9 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R return } - session := auth.GetSession(r) - h.sessions.Broadcast( - message.ScreenResolution{ - Event: event.SCREEN_RESOLUTION, - ID: session.ID(), + message.ScreenSize{ + Event: event.SCREEN_UPDATED, Width: data.Width, Height: data.Height, Rate: data.Rate, diff --git a/internal/types/event/events.go b/internal/types/event/events.go index cfb5510f..e1bc0a8d 100644 --- a/internal/types/event/events.go +++ b/internal/types/event/events.go @@ -32,10 +32,7 @@ const ( ) const ( - SCREEN_CONFIGURATIONS = "screen/configurations" // TODO: Remove. - SCREEN_RESOLUTION = "screen/resolution" // TODO: Remove. - - SCREEN_UPDATED = "screen/updated" // TODO: New. + SCREEN_UPDATED = "screen/updated" SCREEN_SET = "screen/set" ) diff --git a/internal/types/message/messages.go b/internal/types/message/messages.go index 55f82828..f18a2153 100644 --- a/internal/types/message/messages.go +++ b/internal/types/message/messages.go @@ -1,9 +1,5 @@ package message -import ( - "demodesk/neko/internal/types" -) - type Message struct { Event string `json:"event"` Payload interface{} `json:"payload"` // TODO: New. @@ -84,7 +80,6 @@ type ControlKey struct { } // Screen -// TODO: New. type ScreenSize struct { Event string `json:"event,omitempty"` Width int `json:"width"` @@ -162,18 +157,3 @@ type ControlTarget struct { ID string `json:"id"` Target string `json:"target"` } - -// TODO: Remove. -type ScreenResolution struct { - Event string `json:"event"` - ID string `json:"id,omitempty"` - Width int `json:"width"` - Height int `json:"height"` - Rate int `json:"rate"` -} - -// TODO: Remove. -type ScreenConfigurations struct { - Event string `json:"event"` - Configurations map[int]types.ScreenConfiguration `json:"configurations"` -} diff --git a/internal/websocket/handler/handler.go b/internal/websocket/handler/handler.go index a78f19ee..4d1e1d0b 100644 --- a/internal/websocket/handler/handler.go +++ b/internal/websocket/handler/handler.go @@ -64,6 +64,13 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error { return h.controlGive(session, payload) }) + // Screen Events + case event.SCREEN_SET: + payload := &message.ScreenSize{} + err = utils.Unmarshal(payload, raw, func() error { + return h.screenSet(session, payload) + }) + // Clipboard Events case event.CLIPBOARD_SET: payload := &message.ClipboardData{} @@ -82,17 +89,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error { err = utils.Unmarshal(payload, raw, func() error { return h.keyboardModifiers(session, payload) }) - - // Screen Events - case event.SCREEN_RESOLUTION: - err = h.screenSize(session) - case event.SCREEN_CONFIGURATIONS: - err = h.screenConfigurations(session) - case event.SCREEN_SET: - payload := &message.ScreenResolution{} - err = utils.Unmarshal(payload, raw, func() error { - return h.screenSizeChange(session, payload) - }) default: return errors.Errorf("unknown message event %s", header.Event) } diff --git a/internal/websocket/handler/screen.go b/internal/websocket/handler/screen.go index acf00f52..0b9680cb 100644 --- a/internal/websocket/handler/screen.go +++ b/internal/websocket/handler/screen.go @@ -6,7 +6,7 @@ import ( "demodesk/neko/internal/types/message" ) -func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *message.ScreenResolution) error { +func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.ScreenSize) error { if !session.Admin() { h.logger.Debug().Msg("user not admin") return nil @@ -17,9 +17,8 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes } h.sessions.Broadcast( - message.ScreenResolution{ - Event: event.SCREEN_RESOLUTION, - ID: session.ID(), + message.ScreenSize{ + Event: event.SCREEN_UPDATED, Width: payload.Width, Height: payload.Height, Rate: payload.Rate, @@ -27,32 +26,3 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes return nil } - -func (h *MessageHandlerCtx) screenSize(session types.Session) error { - size := h.desktop.GetScreenSize() - if size == nil { - h.logger.Debug().Msg("could not get screen size") - return nil - } - - return session.Send( - message.ScreenResolution{ - Event: event.SCREEN_RESOLUTION, - Width: size.Width, - Height: size.Height, - Rate: int(size.Rate), - }) -} - -func (h *MessageHandlerCtx) screenConfigurations(session types.Session) error { - if !session.Admin() { - h.logger.Debug().Msg("user not admin") - return nil - } - - return session.Send( - message.ScreenConfigurations{ - Event: event.SCREEN_CONFIGURATIONS, - Configurations: h.desktop.ScreenConfigurations(), - }) -} diff --git a/internal/websocket/handler/session.go b/internal/websocket/handler/session.go index fb9a23b0..d8f13220 100644 --- a/internal/websocket/handler/session.go +++ b/internal/websocket/handler/session.go @@ -12,13 +12,6 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error { return err } - if session.Admin() { - // send screen configurations if admin - if err := h.screenConfigurations(session); err != nil { - return err - } - } - return nil } @@ -42,11 +35,6 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error { return err } - // send current screen size - if err := h.screenSize(session); err != nil { - return err - } - // tell session there is a host host := h.sessions.GetHost() if host != nil {