webrtc remote desktop from cursor pos.

This commit is contained in:
Miroslav Šedivý 2021-10-21 22:53:54 +02:00
parent d5c0c62675
commit 2068c0ee05
2 changed files with 3 additions and 11 deletions

View File

@ -6,21 +6,17 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"demodesk/neko/internal/types"
) )
func NewPosition(desktop types.DesktopManager) *PositionCtx { func NewPosition() *PositionCtx {
return &PositionCtx{ return &PositionCtx{
logger: log.With().Str("module", "webrtc").Str("submodule", "cursor-position").Logger(), logger: log.With().Str("module", "webrtc").Str("submodule", "cursor-position").Logger(),
desktop: desktop,
listeners: map[uintptr]*func(x, y int){}, listeners: map[uintptr]*func(x, y int){},
} }
} }
type PositionCtx struct { type PositionCtx struct {
logger zerolog.Logger logger zerolog.Logger
desktop types.DesktopManager
emitMu sync.Mutex emitMu sync.Mutex
listeners map[uintptr]*func(x, y int) listeners map[uintptr]*func(x, y int)
} }
@ -35,10 +31,6 @@ func (manager *PositionCtx) Shutdown() {
manager.emitMu.Unlock() manager.emitMu.Unlock()
} }
func (manager *PositionCtx) Get() (x, y int) {
return manager.desktop.GetCursorPosition()
}
func (manager *PositionCtx) Set(x, y int) { func (manager *PositionCtx) Set(x, y int) {
for _, emit := range manager.listeners { for _, emit := range manager.listeners {
(*emit)(x, y) (*emit)(x, y)

View File

@ -34,7 +34,7 @@ func New(desktop types.DesktopManager, capture types.CaptureManager, config *con
desktop: desktop, desktop: desktop,
capture: capture, capture: capture,
curImage: cursor.NewImage(desktop), curImage: cursor.NewImage(desktop),
curPosition: cursor.NewPosition(desktop), curPosition: cursor.NewPosition(),
} }
} }
@ -198,7 +198,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
} }
// send initial cursor position // send initial cursor position
x, y := manager.curPosition.Get() x, y := manager.desktop.GetCursorPosition()
cursorPosition(x, y) cursorPosition(x, y)
}) })