neko/internal/websocket/handler/system.go
Miroslav Šedivý ea5517b270
Xorg input driver (#53)
* add xf86 input driver.

* cleanup.

* rewrite to unix socket PoC.

* add input rebuild.

* lint & docs.

* add input driver struct.

* comments, lint, socket name from config.

* add touch events to webrtc.

* switch to uint32.

* misc update logging & linting,

* fix screen size

* set touchscreen as core pointer.

* add touch to ws control.

* SendCoreEvents.

* extract to own xinput folder.

* add debounce.

* switch pressure to uint8.

* check buffer size.

* send touch events with system init.
2023-08-17 16:14:59 +02:00

104 lines
2.3 KiB
Go

package handler
import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/demodesk/neko/pkg/types"
"github.com/demodesk/neko/pkg/types/event"
"github.com/demodesk/neko/pkg/types/message"
)
func (h *MessageHandlerCtx) systemInit(session types.Session) error {
host, hasHost := h.sessions.GetHost()
var hostID string
if hasHost {
hostID = host.ID()
}
controlHost := message.ControlHost{
HasHost: hasHost,
HostID: hostID,
}
size := h.desktop.GetScreenSize()
screenSize := message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
}
sessions := map[string]message.SessionData{}
for _, session := range h.sessions.List() {
sessionId := session.ID()
sessions[sessionId] = message.SessionData{
ID: sessionId,
Profile: session.Profile(),
State: session.State(),
}
}
session.Send(
event.SYSTEM_INIT,
message.SystemInit{
SessionId: session.ID(),
ControlHost: controlHost,
ScreenSize: screenSize,
Sessions: sessions,
Settings: h.sessions.Settings(),
TouchEvents: h.desktop.HasTouchSupport(),
ScreencastEnabled: h.capture.Screencast().Enabled(),
WebRTC: message.SystemWebRTC{
Videos: h.capture.Video().IDs(),
},
})
return nil
}
func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
configurations := h.desktop.ScreenConfigurations()
list := make([]message.ScreenSize, 0, len(configurations))
for _, conf := range configurations {
list = append(list, message.ScreenSize{
Width: conf.Width,
Height: conf.Height,
Rate: conf.Rate,
})
}
broadcast := h.capture.Broadcast()
session.Send(
event.SYSTEM_ADMIN,
message.SystemAdmin{
ScreenSizesList: list, // TODO: remove
BroadcastStatus: message.BroadcastStatus{
IsActive: broadcast.Started(),
URL: broadcast.Url(),
},
})
return nil
}
func (h *MessageHandlerCtx) systemLogs(session types.Session, payload *message.SystemLogs) error {
for _, msg := range *payload {
level, _ := zerolog.ParseLevel(msg.Level)
if level < zerolog.DebugLevel || level > zerolog.ErrorLevel {
level = zerolog.NoLevel
}
// do not use handler logger context
log.WithLevel(level).
Fields(msg.Fields).
Str("module", "client").
Str("session_id", session.ID()).
Msg(msg.Message)
}
return nil
}