From 28c22a254bbdf1e729161dfedd86dc6aab09b2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 1 Nov 2021 17:31:00 +0100 Subject: [PATCH] use types.Cursor. --- internal/session/manager.go | 9 ++------- internal/session/session.go | 4 ++-- internal/types/session.go | 4 ++-- internal/webrtc/handler.go | 5 ++++- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/session/manager.go b/internal/session/manager.go index f5d39166..549e2a9b 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -201,16 +201,11 @@ func (manager *SessionManagerCtx) ClearHost() { // cursors // --- -func (manager *SessionManagerCtx) SetCursor(x, y int, session types.Session) { +func (manager *SessionManagerCtx) SetCursor(cursor types.Cursor, session types.Session) { manager.cursorsMu.Lock() defer manager.cursorsMu.Unlock() - pos, ok := manager.cursors[session] - if ok { - pos.X, pos.Y = x, y - } else { - manager.cursors[session] = types.Cursor{X: x, Y: y} - } + manager.cursors[session] = cursor } func (manager *SessionManagerCtx) PopCursors() map[types.Session]types.Cursor { diff --git a/internal/session/session.go b/internal/session/session.go index 85e16a30..d46458d5 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -53,8 +53,8 @@ func (session *SessionCtx) IsHost() bool { return session.manager.GetHost() == session } -func (session *SessionCtx) SetCursor(x, y int) { - session.manager.SetCursor(x, y, session) +func (session *SessionCtx) SetCursor(cursor types.Cursor) { + session.manager.SetCursor(cursor, session) } // --- diff --git a/internal/types/session.go b/internal/types/session.go index 95063766..82d28210 100644 --- a/internal/types/session.go +++ b/internal/types/session.go @@ -29,7 +29,7 @@ type Session interface { IsHost() bool // cursor - SetCursor(x, y int) + SetCursor(cursor Cursor) // websocket SetWebSocketPeer(websocketPeer WebSocketPeer) @@ -55,7 +55,7 @@ type SessionManager interface { GetHost() Session ClearHost() - SetCursor(x, y int, session Session) + SetCursor(cursor Cursor, session Session) PopCursors() map[Session]Cursor Broadcast(event string, payload interface{}, exclude interface{}) diff --git a/internal/webrtc/handler.go b/internal/webrtc/handler.go index 0732206b..7ff5f81c 100644 --- a/internal/webrtc/handler.go +++ b/internal/webrtc/handler.go @@ -52,7 +52,10 @@ func (manager *WebRTCManagerCtx) handle(data []byte, session types.Session) erro // handle inactive cursor movement if session.Profile().CanHost { - session.SetCursor(x, y) + session.SetCursor(types.Cursor{ + X: x, + Y: y, + }) } return nil