mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
API screen change websocket broadcast.
This commit is contained in:
parent
9343e85b8f
commit
b6d5df6d04
@ -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)
|
||||
}
|
||||
|
17
internal/websocket/broadcast/screen.go
Normal file
17
internal/websocket/broadcast/screen.go
Normal 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)
|
||||
}
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user