update clipboard WS.

This commit is contained in:
Miroslav Šedivý 2020-11-30 17:40:38 +01:00
parent 2c210f3cf1
commit e93d167be6
6 changed files with 27 additions and 27 deletions

View File

@ -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 (

View File

@ -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"`

View File

@ -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
}

View File

@ -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")

View File

@ -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)

View File

@ -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")