neko/internal/websocket/handler/control.go

123 lines
2.8 KiB
Go
Raw Normal View History

2020-11-02 04:09:48 +13:00
package handler
import (
2021-09-02 09:10:18 +12:00
"errors"
2022-01-30 13:25:04 +13:00
"demodesk/neko/internal/desktop/xorg"
2020-10-29 07:15:48 +13:00
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
2021-08-30 04:23:58 +12:00
logger := h.logger.With().Str("session_id", session.ID()).Logger()
2021-03-14 12:45:51 +13:00
if !session.Profile().CanHost {
2021-08-30 04:23:58 +12:00
logger.Debug().Msg("is not allowed to host")
2020-12-07 06:50:41 +13:00
return nil
}
2020-11-01 11:03:37 +13:00
if !session.IsHost() {
2021-08-30 04:23:58 +12:00
logger.Debug().Msg("is not the host")
return nil
}
2020-12-02 22:46:00 +13:00
h.desktop.ResetKeys()
h.sessions.ClearHost()
2020-12-02 22:46:00 +13:00
2020-11-19 08:30:33 +13:00
return nil
}
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
2021-03-14 12:45:51 +13:00
if !session.Profile().CanHost {
2021-09-02 09:10:18 +12:00
return errors.New("is not allowed to host")
2020-12-07 06:50:41 +13:00
}
2020-12-02 22:47:20 +13:00
if session.IsHost() {
2021-09-02 09:10:18 +12:00
return errors.New("is already the host")
2020-12-02 22:47:20 +13:00
}
2020-12-02 23:24:20 +13:00
if !h.sessions.ImplicitHosting() {
// tell session if there is a host
if host := h.sessions.GetHost(); host != nil {
2021-09-02 07:58:39 +12:00
session.Send(
event.CONTROL_HOST,
2020-12-02 23:24:20 +13:00
message.ControlHost{
HasHost: true,
HostID: host.ID(),
})
2021-09-02 07:58:39 +12:00
return nil
2020-12-02 23:24:20 +13:00
}
}
2020-12-01 06:24:38 +13:00
h.sessions.SetHost(session)
2020-11-19 08:30:33 +13:00
return nil
}
2022-01-30 13:25:04 +13:00
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)
}