websocket move cursor & scroll.

This commit is contained in:
Miroslav Šedivý 2022-07-21 18:28:32 +02:00
parent babddacbf3
commit 81531d74c1
4 changed files with 33 additions and 12 deletions

View File

@ -59,6 +59,24 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
return nil
}
func (h *MessageHandlerCtx) controlMove(session types.Session, payload *message.ControlPos) error {
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
return err
}
h.desktop.Move(payload.X, payload.Y)
return nil
}
func (h *MessageHandlerCtx) controlScroll(session types.Session, payload *message.ControlPos) error {
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
return err
}
h.desktop.Scroll(payload.X, payload.Y)
return nil
}
func (h *MessageHandlerCtx) controlKeyPress(session types.Session, payload *message.ControlKey) error {
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
return err

View File

@ -77,6 +77,16 @@ 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_MOVE:
payload := &message.ControlPos{}
err = utils.Unmarshal(payload, data.Payload, func() error {
return h.controlMove(session, payload)
})
case event.CONTROL_SCROLL:
payload := &message.ControlPos{}
err = utils.Unmarshal(payload, data.Payload, func() error {
return h.controlScroll(session, payload)
})
case event.CONTROL_KEYPRESS:
payload := &message.ControlKey{}
err = utils.Unmarshal(payload, data.Payload, func() error {

View File

@ -32,8 +32,8 @@ const (
CONTROL_RELEASE = "control/release"
CONTROL_REQUEST = "control/request"
// mouse
CONTROL_MOVE = "control/move" // TODO: New. (fallback)
CONTROL_SCROLL = "control/scroll" // TODO: New. (fallback)
CONTROL_MOVE = "control/move"
CONTROL_SCROLL = "control/scroll"
// keyboard
CONTROL_KEYPRESS = "control/keypress"
CONTROL_KEYDOWN = "control/keydown"

View File

@ -101,16 +101,9 @@ type ControlHost struct {
HostID string `json:"host_id,omitempty"`
}
// TODO: New.
type ControlMove struct {
X uint16 `json:"x"`
Y uint16 `json:"y"`
}
// TODO: New.
type ControlScroll struct {
X int16 `json:"x"`
Y int16 `json:"y"`
type ControlPos struct {
X int `json:"x"`
Y int `json:"y"`
}
type ControlKey struct {