broadcast cursor position via WebSockets.

This commit is contained in:
Miroslav Šedivý 2021-02-11 18:36:27 +01:00
parent e8286dec96
commit f22922191a
5 changed files with 61 additions and 1 deletions

View file

@ -41,6 +41,7 @@ type WebSocketManagerCtx struct {
desktop types.DesktopManager
handler *handler.MessageHandlerCtx
handlers []types.HandlerFunction
shutdown chan bool
}
func (ws *WebSocketManagerCtx) Start() {
@ -133,9 +134,51 @@ func (ws *WebSocketManagerCtx) Start() {
})
ws.fileChooserDialogEvents()
go func() {
ws.logger.Debug().Msg("cursor position broadcast start")
defer func() {
ws.logger.Debug().Msg("cursor position broadcast shutdown")
}()
var posX int
var posY int
for {
select {
case <-ws.shutdown:
return
default:
time.Sleep(40 * time.Millisecond)
session := ws.sessions.GetHost()
if session == nil {
continue
}
x, y := ws.desktop.GetMousePositon()
if posX == x && posY == y {
continue
}
memberId := session.ID()
posX = x
posY = y
ws.sessions.Broadcast(message.CursorPosition{
Event: event.CURSOR_POSITION,
MemberId: memberId,
X: uint16(x),
Y: uint16(y),
}, []string{ memberId })
}
}
}()
}
func (ws *WebSocketManagerCtx) Shutdown() error {
ws.shutdown <- true
return nil
}