diff --git a/internal/api/room/screen.go b/internal/api/room/screen.go index d3e9d54e..3c6ed3eb 100644 --- a/internal/api/room/screen.go +++ b/internal/api/room/screen.go @@ -6,6 +6,7 @@ import ( "github.com/go-chi/render" "demodesk/neko/internal/api/utils" + "demodesk/neko/internal/websocket/broadcast" ) type ScreenConfiguration struct { @@ -45,7 +46,10 @@ func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.R return } - // TODO: WebSocket notify. + if err := broadcast.ScreenConfiguration(h.sessions, "-todo-session-id-", data.Width, data.Height, data.Rate); err != nil { + render.Render(w, r, utils.ErrInvalidRequest(err)) + return + } render.JSON(w, r, data) } diff --git a/internal/websocket/broadcast/screen.go b/internal/websocket/broadcast/screen.go new file mode 100644 index 00000000..ead004e3 --- /dev/null +++ b/internal/websocket/broadcast/screen.go @@ -0,0 +1,17 @@ +package broadcast + +import ( + "demodesk/neko/internal/types" + "demodesk/neko/internal/types/event" + "demodesk/neko/internal/types/message" +) + +func ScreenConfiguration(session types.SessionManager, id string, width int, height int, rate int) error { + return session.Broadcast(message.ScreenResolution{ + Event: event.SCREEN_RESOLUTION, + ID: id, + Width: width, + Height: height, + Rate: rate, + }, nil) +} diff --git a/internal/websocket/screen.go b/internal/websocket/screen.go index ddb35167..26a6fa71 100644 --- a/internal/websocket/screen.go +++ b/internal/websocket/screen.go @@ -4,6 +4,7 @@ import ( "demodesk/neko/internal/types" "demodesk/neko/internal/types/event" "demodesk/neko/internal/types/message" + "demodesk/neko/internal/websocket/broadcast" ) func (h *MessageHandler) screenSet(id string, session types.Session, payload *message.ScreenResolution) error { @@ -17,14 +18,7 @@ func (h *MessageHandler) screenSet(id string, session types.Session, payload *me return err } - if err := h.sessions.Broadcast( - message.ScreenResolution{ - Event: event.SCREEN_RESOLUTION, - ID: id, - Width: payload.Width, - Height: payload.Height, - Rate: payload.Rate, - }, nil); err != nil { + if err := broadcast.ScreenConfiguration(h.sessions, id, payload.Width, payload.Height, payload.Rate); err != nil { h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.SCREEN_RESOLUTION) return err }