From e93d167be63dc1b6f3dbdd63a4656bfa25144745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 30 Nov 2020 17:40:38 +0100 Subject: [PATCH] update clipboard WS. --- internal/types/event/events.go | 5 ++--- internal/types/message/messages.go | 7 ------- internal/websocket/handler/clipboard.go | 16 ++++++++++++++++ internal/websocket/handler/control.go | 10 ---------- internal/websocket/handler/handler.go | 12 +++++++----- internal/websocket/manager.go | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 internal/websocket/handler/clipboard.go diff --git a/internal/types/event/events.go b/internal/types/event/events.go index 4b56299e..0ba2b473 100644 --- a/internal/types/event/events.go +++ b/internal/types/event/events.go @@ -22,7 +22,6 @@ const ( CONTROL_LOCKED = "control/locked" // TODO: Remove. CONTROL_REQUESTING = "control/requesting" // TODO: Remove. CONTROL_GIVE = "control/give" // TODO: Remove. - CONTROL_CLIPBOARD = "control/clipboard" // TODO: Remove. CONTROL_KEYBOARD = "control/keyboard" // TODO: Remove. CONTROL_HOST = "control/host" // TODO: New. CONTROL_RELEASE = "control/release" @@ -42,8 +41,8 @@ const ( ) const ( - CLIPBOARD_UPDATED = "clipboard/updated" // TODO: New. - CLIPBOARD_SET = "clipboard/set" // TODO: New. + CLIPBOARD_UPDATED = "clipboard/updated" + CLIPBOARD_SET = "clipboard/set" ) const ( diff --git a/internal/types/message/messages.go b/internal/types/message/messages.go index 4ec92cf7..4158b336 100644 --- a/internal/types/message/messages.go +++ b/internal/types/message/messages.go @@ -93,7 +93,6 @@ type ScreenSize struct { } // Clipboard -// TODO: New. type ClipboardData struct { Event string `json:"event,omitempty"` Text string `json:"text"` @@ -153,12 +152,6 @@ type MemberDisconnected struct { ID string `json:"id"` } -// TODO: Remove. -type Clipboard struct { - Event string `json:"event"` - Text string `json:"text"` -} - // TODO: Remove. type Keyboard struct { Event string `json:"event"` diff --git a/internal/websocket/handler/clipboard.go b/internal/websocket/handler/clipboard.go new file mode 100644 index 00000000..ee0e0f25 --- /dev/null +++ b/internal/websocket/handler/clipboard.go @@ -0,0 +1,16 @@ +package handler + +import ( + "demodesk/neko/internal/types" + "demodesk/neko/internal/types/message" +) + +func (h *MessageHandlerCtx) clipboardSet(session types.Session, payload *message.ClipboardData) error { + if !session.IsHost() { + h.logger.Debug().Str("id", session.ID()).Msg("is not the host") + return nil + } + + h.desktop.WriteClipboard(payload.Text) + return nil +} diff --git a/internal/websocket/handler/control.go b/internal/websocket/handler/control.go index b575323c..1051dae5 100644 --- a/internal/websocket/handler/control.go +++ b/internal/websocket/handler/control.go @@ -82,16 +82,6 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message. return nil } -func (h *MessageHandlerCtx) controlClipboard(session types.Session, payload *message.Clipboard) error { - if !session.IsHost() { - h.logger.Debug().Str("id", session.ID()).Msg("is not the host") - return nil - } - - h.desktop.WriteClipboard(payload.Text) - return nil -} - func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *message.Keyboard) error { if !session.IsHost() { h.logger.Debug().Str("id", session.ID()).Msg("is not the host") diff --git a/internal/websocket/handler/handler.go b/internal/websocket/handler/handler.go index 6e0a5d4d..b3068461 100644 --- a/internal/websocket/handler/handler.go +++ b/internal/websocket/handler/handler.go @@ -63,17 +63,19 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error { err = utils.Unmarshal(payload, raw, func() error { return h.controlGive(session, payload) }) - case event.CONTROL_CLIPBOARD: - payload := &message.Clipboard{} - err = utils.Unmarshal(payload, raw, func() error { - return h.controlClipboard(session, payload) - }) case event.CONTROL_KEYBOARD: payload := &message.Keyboard{} err = utils.Unmarshal(payload, raw, func() error { return h.controlKeyboard(session, payload) }) + // Clipboard Events + case event.CLIPBOARD_SET: + payload := &message.ClipboardData{} + err = utils.Unmarshal(payload, raw, func() error { + return h.clipboardSet(session, payload) + }) + // Screen Events case event.SCREEN_RESOLUTION: err = h.screenSize(session) diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index ff4c5588..027fe3e0 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -98,8 +98,8 @@ func (ws *WebSocketManagerCtx) Start() { } if err := session.Send( - message.Clipboard{ - Event: event.CONTROL_CLIPBOARD, + message.ClipboardData{ + Event: event.CLIPBOARD_UPDATED, Text: text, }); err != nil { ws.logger.Warn().Err(err).Msg("could not sync clipboard")