mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
update screen WS.
This commit is contained in:
parent
83be51ea0f
commit
4bbf3bb039
@ -6,7 +6,6 @@ import (
|
|||||||
"demodesk/neko/internal/types/event"
|
"demodesk/neko/internal/types/event"
|
||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
"demodesk/neko/internal/utils"
|
"demodesk/neko/internal/utils"
|
||||||
"demodesk/neko/internal/http/auth"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScreenConfigurationPayload struct {
|
type ScreenConfigurationPayload struct {
|
||||||
@ -41,12 +40,9 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session := auth.GetSession(r)
|
|
||||||
|
|
||||||
h.sessions.Broadcast(
|
h.sessions.Broadcast(
|
||||||
message.ScreenResolution{
|
message.ScreenSize{
|
||||||
Event: event.SCREEN_RESOLUTION,
|
Event: event.SCREEN_UPDATED,
|
||||||
ID: session.ID(),
|
|
||||||
Width: data.Width,
|
Width: data.Width,
|
||||||
Height: data.Height,
|
Height: data.Height,
|
||||||
Rate: data.Rate,
|
Rate: data.Rate,
|
||||||
|
@ -32,10 +32,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SCREEN_CONFIGURATIONS = "screen/configurations" // TODO: Remove.
|
SCREEN_UPDATED = "screen/updated"
|
||||||
SCREEN_RESOLUTION = "screen/resolution" // TODO: Remove.
|
|
||||||
|
|
||||||
SCREEN_UPDATED = "screen/updated" // TODO: New.
|
|
||||||
SCREEN_SET = "screen/set"
|
SCREEN_SET = "screen/set"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package message
|
package message
|
||||||
|
|
||||||
import (
|
|
||||||
"demodesk/neko/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
Payload interface{} `json:"payload"` // TODO: New.
|
Payload interface{} `json:"payload"` // TODO: New.
|
||||||
@ -84,7 +80,6 @@ type ControlKey struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Screen
|
// Screen
|
||||||
// TODO: New.
|
|
||||||
type ScreenSize struct {
|
type ScreenSize struct {
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
@ -162,18 +157,3 @@ type ControlTarget struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Target string `json:"target"`
|
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"`
|
|
||||||
}
|
|
||||||
|
@ -64,6 +64,13 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
|||||||
return h.controlGive(session, payload)
|
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
|
// Clipboard Events
|
||||||
case event.CLIPBOARD_SET:
|
case event.CLIPBOARD_SET:
|
||||||
payload := &message.ClipboardData{}
|
payload := &message.ClipboardData{}
|
||||||
@ -82,17 +89,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
|||||||
err = utils.Unmarshal(payload, raw, func() error {
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.keyboardModifiers(session, payload)
|
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:
|
default:
|
||||||
return errors.Errorf("unknown message event %s", header.Event)
|
return errors.Errorf("unknown message event %s", header.Event)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"demodesk/neko/internal/types/message"
|
"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() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -17,9 +17,8 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.sessions.Broadcast(
|
h.sessions.Broadcast(
|
||||||
message.ScreenResolution{
|
message.ScreenSize{
|
||||||
Event: event.SCREEN_RESOLUTION,
|
Event: event.SCREEN_UPDATED,
|
||||||
ID: session.ID(),
|
|
||||||
Width: payload.Width,
|
Width: payload.Width,
|
||||||
Height: payload.Height,
|
Height: payload.Height,
|
||||||
Rate: payload.Rate,
|
Rate: payload.Rate,
|
||||||
@ -27,32 +26,3 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes
|
|||||||
|
|
||||||
return nil
|
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(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -12,13 +12,6 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.Admin() {
|
|
||||||
// send screen configurations if admin
|
|
||||||
if err := h.screenConfigurations(session); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,11 +35,6 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// send current screen size
|
|
||||||
if err := h.screenSize(session); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// tell session there is a host
|
// tell session there is a host
|
||||||
host := h.sessions.GetHost()
|
host := h.sessions.GetHost()
|
||||||
if host != nil {
|
if host != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user