unify types.ScreenSize and add ID to screen size update.

This commit is contained in:
Miroslav Šedivý
2024-05-03 22:40:56 +02:00
parent 0f45aa3f19
commit b90eb87c22
5 changed files with 28 additions and 56 deletions

View File

@ -11,24 +11,16 @@ import (
"github.com/demodesk/neko/pkg/utils"
)
type ScreenConfigurationPayload struct {
Width int `json:"width"`
Height int `json:"height"`
Rate int16 `json:"rate"`
}
func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request) error {
size := h.desktop.GetScreenSize()
screenSize := h.desktop.GetScreenSize()
return utils.HttpSuccess(w, ScreenConfigurationPayload{
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
})
return utils.HttpSuccess(w, screenSize)
}
func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.Request) error {
data := &ScreenConfigurationPayload{}
auth, _ := auth.GetSession(r)
data := &types.ScreenSize{}
if err := utils.HttpJsonRequest(w, r, data); err != nil {
return err
}
@ -43,10 +35,9 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
return utils.HttpUnprocessableEntity("cannot set screen size").WithInternalErr(err)
}
h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSizeUpdate{
ID: auth.ID(),
ScreenSize: size,
})
return utils.HttpSuccess(w, data)
@ -56,16 +47,7 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
func (h *RoomHandler) screenConfigurationsList(w http.ResponseWriter, r *http.Request) error {
configurations := h.desktop.ScreenConfigurations()
list := make([]ScreenConfigurationPayload, 0, len(configurations))
for _, conf := range configurations {
list = append(list, ScreenConfigurationPayload{
Width: conf.Width,
Height: conf.Height,
Rate: conf.Rate,
})
}
return utils.HttpSuccess(w, list)
return utils.HttpSuccess(w, configurations)
}
func (h *RoomHandler) screenShotGet(w http.ResponseWriter, r *http.Request) error {

View File

@ -13,20 +13,14 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
return errors.New("is not the admin")
}
size, err := h.desktop.SetScreenSize(types.ScreenSize{
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
})
size, err := h.desktop.SetScreenSize(payload.ScreenSize)
if err != nil {
return err
}
h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
h.sessions.Broadcast(event.SCREEN_UPDATED, message.ScreenSizeUpdate{
ID: session.ID(),
ScreenSize: size,
})
return nil
}

View File

@ -22,13 +22,6 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
HostID: hostID,
}
size := h.desktop.GetScreenSize()
screenSize := message.ScreenSize{
Width: size.Width,
Height: size.Height,
Rate: size.Rate,
}
sessions := map[string]message.SessionData{}
for _, session := range h.sessions.List() {
sessionId := session.ID()
@ -44,7 +37,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
message.SystemInit{
SessionId: session.ID(),
ControlHost: controlHost,
ScreenSize: screenSize,
ScreenSize: h.desktop.GetScreenSize(),
Sessions: sessions,
Settings: h.sessions.Settings(),
TouchEvents: h.desktop.HasTouchSupport(),
@ -60,9 +53,9 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
configurations := h.desktop.ScreenConfigurations()
list := make([]message.ScreenSize, 0, len(configurations))
list := make([]types.ScreenSize, 0, len(configurations))
for _, conf := range configurations {
list = append(list, message.ScreenSize{
list = append(list, types.ScreenSize{
Width: conf.Width,
Height: conf.Height,
Rate: conf.Rate,