Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/websocket/handler/screen.go

71 lines
1.7 KiB
Go
Raw Normal View History

2022-09-13 08:36:56 +12:00
package handler
2020-02-11 18:15:59 +13:00
import (
2021-10-06 09:38:24 +13:00
"m1k1o/neko/internal/types"
"m1k1o/neko/internal/types/event"
"m1k1o/neko/internal/types/message"
2020-02-11 18:15:59 +13:00
)
func (h *MessageHandler) screenSet(id string, session types.Session, payload *message.ScreenResolution) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
2022-09-17 22:43:17 +12:00
if err := h.desktop.SetScreenSize(types.ScreenSize{
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
}); err != nil {
2020-02-11 18:15:59 +13:00
h.logger.Warn().Err(err).Msgf("unable to change screen size")
return err
}
if err := h.sessions.Broadcast(
2020-02-11 18:15:59 +13:00
message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
ID: id,
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.SCREEN_RESOLUTION)
2020-02-11 18:15:59 +13:00
return err
}
return nil
}
func (h *MessageHandler) screenResolution(id string, session types.Session) error {
2022-09-13 08:12:47 +12:00
if size := h.desktop.GetScreenSize(); size != nil {
2020-02-11 18:15:59 +13:00
if err := session.Send(message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
Width: size.Width,
Height: size.Height,
2022-09-14 07:40:40 +12:00
Rate: size.Rate,
2020-02-11 18:15:59 +13:00
}); err != nil {
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_RESOLUTION)
return err
}
}
return nil
}
func (h *MessageHandler) screenConfigurations(id string, session types.Session) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
if err := session.Send(message.ScreenConfigurations{
Event: event.SCREEN_CONFIGURATIONS,
2022-09-13 08:12:47 +12:00
Configurations: h.desktop.ScreenConfigurations(),
2020-02-11 18:15:59 +13:00
}); err != nil {
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_CONFIGURATIONS)
return err
}
return nil
}