desktop control websocket.

This commit is contained in:
Miroslav Šedivý 2022-01-30 01:25:04 +01:00
parent 0d6335ebcd
commit fcc85aa9d6
4 changed files with 100 additions and 6 deletions

View File

@ -29,10 +29,17 @@ const (
CONTROL_HOST = "control/host"
CONTROL_RELEASE = "control/release"
CONTROL_REQUEST = "control/request"
// mouse
CONTROL_MOVE = "control/move" // TODO: New. (fallback)
CONTROL_SCROLL = "control/scroll" // TODO: New. (fallback)
CONTROL_KEYDOWN = "control/keydown" // TODO: New. (fallback)
CONTROL_KEYUP = "control/keyup" // TODO: New. (fallback)
// keyboard
CONTROL_KEYPRESS = "control/keypress"
CONTROL_KEYDOWN = "control/keydown"
CONTROL_KEYUP = "control/keyup"
// actions
CONTROL_COPY = "control/copy"
CONTROL_PASTE = "control/paste"
CONTROL_SELECT_ALL = "control/select_all"
)
const (

View File

@ -114,9 +114,8 @@ type ControlScroll struct {
Y int16 `json:"y"`
}
// TODO: New.
type ControlKey struct {
Key uint32 `json:"key"`
Keysym uint32 `json:"keysym"`
}
/////////////////////////////

View File

@ -3,6 +3,7 @@ package handler
import (
"errors"
"demodesk/neko/internal/desktop/xorg"
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
@ -53,3 +54,69 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
h.sessions.SetHost(session)
return nil
}
func (h *MessageHandlerCtx) controlKeyPress(session types.Session, payload *message.ControlKey) error {
logger := h.logger.With().Str("session_id", session.ID()).Logger()
if !session.IsHost() {
logger.Debug().Msg("is not the host")
return nil
}
return h.desktop.KeyPress(payload.Keysym)
}
func (h *MessageHandlerCtx) controlKeyDown(session types.Session, payload *message.ControlKey) error {
logger := h.logger.With().Str("session_id", session.ID()).Logger()
if !session.IsHost() {
logger.Debug().Msg("is not the host")
return nil
}
return h.desktop.KeyDown(payload.Keysym)
}
func (h *MessageHandlerCtx) controlKeyUp(session types.Session, payload *message.ControlKey) error {
logger := h.logger.With().Str("session_id", session.ID()).Logger()
if !session.IsHost() {
logger.Debug().Msg("is not the host")
return nil
}
return h.desktop.KeyUp(payload.Keysym)
}
func (h *MessageHandlerCtx) controlCopy(session types.Session) error {
logger := h.logger.With().Str("session_id", session.ID()).Logger()
if !session.IsHost() {
logger.Debug().Msg("is not the host")
return nil
}
return h.desktop.KeyPress(xorg.XK_Control_L, xorg.XK_c)
}
func (h *MessageHandlerCtx) controlPaste(session types.Session) error {
logger := h.logger.With().Str("session_id", session.ID()).Logger()
if !session.IsHost() {
logger.Debug().Msg("is not the host")
return nil
}
return h.desktop.KeyPress(xorg.XK_Control_L, xorg.XK_v)
}
func (h *MessageHandlerCtx) controlSelectAll(session types.Session) error {
logger := h.logger.With().Str("session_id", session.ID()).Logger()
if !session.IsHost() {
logger.Debug().Msg("is not the host")
return nil
}
return h.desktop.KeyPress(xorg.XK_Control_L, xorg.XK_a)
}

View File

@ -82,6 +82,27 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
err = h.controlRelease(session)
case event.CONTROL_REQUEST:
err = h.controlRequest(session)
case event.CONTROL_KEYPRESS:
payload := &message.ControlKey{}
err = utils.Unmarshal(payload, data.Payload, func() error {
return h.controlKeyPress(session, payload)
})
case event.CONTROL_KEYDOWN:
payload := &message.ControlKey{}
err = utils.Unmarshal(payload, data.Payload, func() error {
return h.controlKeyDown(session, payload)
})
case event.CONTROL_KEYUP:
payload := &message.ControlKey{}
err = utils.Unmarshal(payload, data.Payload, func() error {
return h.controlKeyUp(session, payload)
})
case event.CONTROL_COPY:
err = h.controlCopy(session)
case event.CONTROL_PASTE:
err = h.controlPaste(session)
case event.CONTROL_SELECT_ALL:
err = h.controlSelectAll(session)
// Screen Events
case event.SCREEN_SET: