2020-11-02 04:09:48 +13:00
|
|
|
package handler
|
2020-10-23 03:54:50 +13:00
|
|
|
|
|
|
|
import (
|
2020-10-29 07:15:48 +13:00
|
|
|
"demodesk/neko/internal/types"
|
|
|
|
"demodesk/neko/internal/types/event"
|
|
|
|
"demodesk/neko/internal/types/message"
|
2020-10-23 03:54:50 +13:00
|
|
|
)
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.ScreenResolution) error {
|
2020-10-23 03:54:50 +13:00
|
|
|
if !session.Admin() {
|
|
|
|
h.logger.Debug().Msg("user not admin")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
if err := h.capture.ChangeResolution(payload.Width, payload.Height, payload.Rate); err != nil {
|
2020-10-23 03:54:50 +13:00
|
|
|
h.logger.Warn().Err(err).Msgf("unable to change screen size")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
if err := h.sessions.Broadcast(message.ScreenResolution{
|
|
|
|
Event: event.SCREEN_RESOLUTION,
|
|
|
|
ID: session.ID(),
|
|
|
|
Width: payload.Width,
|
|
|
|
Height: payload.Height,
|
|
|
|
Rate: payload.Rate,
|
|
|
|
}, nil); err != nil {
|
|
|
|
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_RESOLUTION)
|
2020-10-23 03:54:50 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) screenResolution(session types.Session) error {
|
2020-11-02 06:12:16 +13:00
|
|
|
size := h.desktop.GetScreenSize()
|
|
|
|
if size == nil {
|
|
|
|
h.logger.Debug().Msg("could not get screen size")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) screenConfigurations(session types.Session) error {
|
2020-10-23 03:54:50 +13:00
|
|
|
if !session.Admin() {
|
|
|
|
h.logger.Debug().Msg("user not admin")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := session.Send(message.ScreenConfigurations{
|
|
|
|
Event: event.SCREEN_CONFIGURATIONS,
|
2020-11-02 04:09:48 +13:00
|
|
|
Configurations: h.desktop.ScreenConfigurations(),
|
2020-10-23 03:54:50 +13:00
|
|
|
}); err != nil {
|
|
|
|
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_CONFIGURATIONS)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|