mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-31 18:07:05 +02:00
broadcast cursor position via WebSockets.
This commit is contained in:
parent
e8286dec96
commit
f22922191a
5 changed files with 61 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue