103 lines
2.3 KiB
Go
Raw Normal View History

2020-11-30 20:07:19 +01:00
package handler
import (
2021-09-09 22:08:39 +02:00
"github.com/rs/zerolog"
2021-09-09 22:51:37 +02:00
"github.com/rs/zerolog/log"
2021-09-09 22:08:39 +02:00
"github.com/demodesk/neko/pkg/types"
"github.com/demodesk/neko/pkg/types/event"
"github.com/demodesk/neko/pkg/types/message"
2020-11-30 20:07:19 +01:00
)
func (h *MessageHandlerCtx) systemInit(session types.Session) error {
host, hasHost := h.sessions.GetHost()
2020-11-30 20:07:19 +01:00
var hostID string
if hasHost {
hostID = host.ID()
2020-11-30 20:07:19 +01:00
}
controlHost := message.ControlHost{
HasHost: hasHost,
HostID: hostID,
2020-11-30 20:07:19 +01:00
}
size := h.desktop.GetScreenSize()
screenSize := message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
2020-11-30 20:07:19 +01:00
}
2021-03-14 00:05:31 +01:00
sessions := map[string]message.SessionData{}
2021-03-13 21:11:48 +01:00
for _, session := range h.sessions.List() {
2021-03-13 23:32:10 +01:00
sessionId := session.ID()
2021-03-14 00:05:31 +01:00
sessions[sessionId] = message.SessionData{
2021-03-13 23:32:10 +01:00
ID: sessionId,
2021-03-14 00:45:51 +01:00
Profile: session.Profile(),
State: session.State(),
2020-12-01 22:56:08 +01:00
}
2020-11-30 20:07:19 +01:00
}
2021-09-01 21:58:39 +02:00
session.Send(
event.SYSTEM_INIT,
2020-11-30 20:07:19 +01:00
message.SystemInit{
2021-09-20 18:28:13 +02:00
SessionId: session.ID(),
ControlHost: controlHost,
ScreenSize: screenSize,
Sessions: sessions,
2022-03-27 00:08:06 +01:00
Settings: h.sessions.Settings(),
ScreencastEnabled: h.capture.Screencast().Enabled(),
2021-04-30 14:05:07 +00:00
WebRTC: message.SystemWebRTC{
Videos: h.capture.Video().IDs(),
2021-04-30 14:05:07 +00:00
},
2020-11-30 20:07:19 +01:00
})
2021-09-01 21:58:39 +02:00
return nil
2020-11-30 20:07:19 +01:00
}
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,
})
2020-11-30 20:07:19 +01:00
}
broadcast := h.capture.Broadcast()
2021-09-01 21:58:39 +02:00
session.Send(
event.SYSTEM_ADMIN,
2020-11-30 20:07:19 +01:00
message.SystemAdmin{
ScreenSizesList: list, // TODO: remove
2020-11-30 20:07:19 +01:00
BroadcastStatus: message.BroadcastStatus{
2021-02-05 14:03:53 +01:00
IsActive: broadcast.Started(),
URL: broadcast.Url(),
2020-11-30 20:07:19 +01:00
},
})
2021-09-01 21:58:39 +02:00
return nil
2020-11-30 20:07:19 +01:00
}
2021-09-09 22:08:39 +02:00
func (h *MessageHandlerCtx) systemLogs(session types.Session, payload *message.SystemLogs) error {
2021-09-09 22:51:37 +02:00
for _, msg := range *payload {
level, _ := zerolog.ParseLevel(msg.Level)
2021-09-09 22:08:39 +02:00
2021-09-09 22:51:37 +02:00
if level < zerolog.DebugLevel || level > zerolog.ErrorLevel {
level = zerolog.NoLevel
}
// do not use handler logger context
log.WithLevel(level).
Fields(msg.Fields).
2021-09-12 17:00:29 +02:00
Str("module", "client").
2021-09-09 22:08:39 +02:00
Str("session_id", session.ID()).
2021-09-09 22:51:37 +02:00
Msg(msg.Message)
2021-09-09 22:08:39 +02:00
}
return nil
}