update screen WS.

This commit is contained in:
Miroslav Šedivý 2020-11-30 17:53:05 +01:00
parent 83be51ea0f
commit 4bbf3bb039
6 changed files with 13 additions and 86 deletions

View File

@ -6,7 +6,6 @@ import (
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
"demodesk/neko/internal/utils"
"demodesk/neko/internal/http/auth"
)
type ScreenConfigurationPayload struct {
@ -41,12 +40,9 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
return
}
session := auth.GetSession(r)
h.sessions.Broadcast(
message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
ID: session.ID(),
message.ScreenSize{
Event: event.SCREEN_UPDATED,
Width: data.Width,
Height: data.Height,
Rate: data.Rate,

View File

@ -32,10 +32,7 @@ const (
)
const (
SCREEN_CONFIGURATIONS = "screen/configurations" // TODO: Remove.
SCREEN_RESOLUTION = "screen/resolution" // TODO: Remove.
SCREEN_UPDATED = "screen/updated" // TODO: New.
SCREEN_UPDATED = "screen/updated"
SCREEN_SET = "screen/set"
)

View File

@ -1,9 +1,5 @@
package message
import (
"demodesk/neko/internal/types"
)
type Message struct {
Event string `json:"event"`
Payload interface{} `json:"payload"` // TODO: New.
@ -84,7 +80,6 @@ type ControlKey struct {
}
// Screen
// TODO: New.
type ScreenSize struct {
Event string `json:"event,omitempty"`
Width int `json:"width"`
@ -162,18 +157,3 @@ type ControlTarget struct {
ID string `json:"id"`
Target string `json:"target"`
}
// TODO: Remove.
type ScreenResolution struct {
Event string `json:"event"`
ID string `json:"id,omitempty"`
Width int `json:"width"`
Height int `json:"height"`
Rate int `json:"rate"`
}
// TODO: Remove.
type ScreenConfigurations struct {
Event string `json:"event"`
Configurations map[int]types.ScreenConfiguration `json:"configurations"`
}

View File

@ -64,6 +64,13 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
return h.controlGive(session, payload)
})
// Screen Events
case event.SCREEN_SET:
payload := &message.ScreenSize{}
err = utils.Unmarshal(payload, raw, func() error {
return h.screenSet(session, payload)
})
// Clipboard Events
case event.CLIPBOARD_SET:
payload := &message.ClipboardData{}
@ -82,17 +89,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
err = utils.Unmarshal(payload, raw, func() error {
return h.keyboardModifiers(session, payload)
})
// Screen Events
case event.SCREEN_RESOLUTION:
err = h.screenSize(session)
case event.SCREEN_CONFIGURATIONS:
err = h.screenConfigurations(session)
case event.SCREEN_SET:
payload := &message.ScreenResolution{}
err = utils.Unmarshal(payload, raw, func() error {
return h.screenSizeChange(session, payload)
})
default:
return errors.Errorf("unknown message event %s", header.Event)
}

View File

@ -6,7 +6,7 @@ import (
"demodesk/neko/internal/types/message"
)
func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *message.ScreenResolution) error {
func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.ScreenSize) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
@ -17,9 +17,8 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes
}
h.sessions.Broadcast(
message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
ID: session.ID(),
message.ScreenSize{
Event: event.SCREEN_UPDATED,
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
@ -27,32 +26,3 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes
return nil
}
func (h *MessageHandlerCtx) screenSize(session types.Session) error {
size := h.desktop.GetScreenSize()
if size == nil {
h.logger.Debug().Msg("could not get screen size")
return nil
}
return session.Send(
message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
Width: size.Width,
Height: size.Height,
Rate: int(size.Rate),
})
}
func (h *MessageHandlerCtx) screenConfigurations(session types.Session) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
return session.Send(
message.ScreenConfigurations{
Event: event.SCREEN_CONFIGURATIONS,
Configurations: h.desktop.ScreenConfigurations(),
})
}

View File

@ -12,13 +12,6 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
return err
}
if session.Admin() {
// send screen configurations if admin
if err := h.screenConfigurations(session); err != nil {
return err
}
}
return nil
}
@ -42,11 +35,6 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
return err
}
// send current screen size
if err := h.screenSize(session); err != nil {
return err
}
// tell session there is a host
host := h.sessions.GetHost()
if host != nil {