mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
websocket move cursor & scroll.
This commit is contained in:
parent
babddacbf3
commit
81531d74c1
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user