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