API screen change websocket broadcast.

This commit is contained in:
Miroslav Šedivý 2020-10-30 21:29:51 +01:00
parent 9343e85b8f
commit b6d5df6d04
3 changed files with 24 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/go-chi/render"
"demodesk/neko/internal/api/utils"
"demodesk/neko/internal/websocket/broadcast"
)
type ScreenConfiguration struct {
@ -45,7 +46,10 @@ func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.R
return
}
// TODO: WebSocket notify.
if err := broadcast.ScreenConfiguration(h.sessions, "-todo-session-id-", data.Width, data.Height, data.Rate); err != nil {
render.Render(w, r, utils.ErrInvalidRequest(err))
return
}
render.JSON(w, r, data)
}

View File

@ -0,0 +1,17 @@
package broadcast
import (
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
func ScreenConfiguration(session types.SessionManager, id string, width int, height int, rate int) error {
return session.Broadcast(message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
ID: id,
Width: width,
Height: height,
Rate: rate,
}, nil)
}

View File

@ -4,6 +4,7 @@ import (
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
"demodesk/neko/internal/websocket/broadcast"
)
func (h *MessageHandler) screenSet(id string, session types.Session, payload *message.ScreenResolution) error {
@ -17,14 +18,7 @@ func (h *MessageHandler) screenSet(id string, session types.Session, payload *me
return err
}
if err := h.sessions.Broadcast(
message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
ID: id,
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
}, nil); err != nil {
if err := broadcast.ScreenConfiguration(h.sessions, id, payload.Width, payload.Height, payload.Rate); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.SCREEN_RESOLUTION)
return err
}