neko/server/internal/websocket/screen.go

67 lines
1.7 KiB
Go
Raw Normal View History

2020-02-11 18:15:59 +13:00
package websocket
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
}
2020-04-06 10:34:51 +12:00
if err := h.remote.ChangeResolution(payload.Width, payload.Height, 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 {
2020-04-06 10:34:51 +12:00
if size := h.remote.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,
Rate: int(size.Rate),
}); 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,
2020-04-06 10:34:51 +12:00
Configurations: h.remote.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
}