mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add sessions cursors.
This commit is contained in:
@ -15,14 +15,12 @@ import (
|
||||
|
||||
func New(config *config.Session) *SessionManagerCtx {
|
||||
manager := &SessionManagerCtx{
|
||||
logger: log.With().Str("module", "session").Logger(),
|
||||
config: config,
|
||||
host: nil,
|
||||
hostMu: sync.Mutex{},
|
||||
tokens: make(map[string]string),
|
||||
sessions: make(map[string]*SessionCtx),
|
||||
sessionsMu: sync.Mutex{},
|
||||
emmiter: events.New(),
|
||||
logger: log.With().Str("module", "session").Logger(),
|
||||
config: config,
|
||||
tokens: make(map[string]string),
|
||||
sessions: make(map[string]*SessionCtx),
|
||||
cursors: make(map[types.Session]types.Cursor),
|
||||
emmiter: events.New(),
|
||||
}
|
||||
|
||||
// create API session
|
||||
@ -48,13 +46,19 @@ func New(config *config.Session) *SessionManagerCtx {
|
||||
}
|
||||
|
||||
type SessionManagerCtx struct {
|
||||
logger zerolog.Logger
|
||||
config *config.Session
|
||||
host types.Session
|
||||
hostMu sync.Mutex
|
||||
logger zerolog.Logger
|
||||
config *config.Session
|
||||
|
||||
tokens map[string]string
|
||||
sessions map[string]*SessionCtx
|
||||
sessionsMu sync.Mutex
|
||||
|
||||
host types.Session
|
||||
hostMu sync.Mutex
|
||||
|
||||
cursors map[types.Session]types.Cursor
|
||||
cursorsMu sync.Mutex
|
||||
|
||||
emmiter events.EventEmmiter
|
||||
apiSession *SessionCtx
|
||||
}
|
||||
@ -193,6 +197,32 @@ func (manager *SessionManagerCtx) ClearHost() {
|
||||
manager.SetHost(nil)
|
||||
}
|
||||
|
||||
// ---
|
||||
// cursors
|
||||
// ---
|
||||
|
||||
func (manager *SessionManagerCtx) SetCursor(x, y int, 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}
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SessionManagerCtx) PopCursors() map[types.Session]types.Cursor {
|
||||
manager.cursorsMu.Lock()
|
||||
defer manager.cursorsMu.Unlock()
|
||||
|
||||
cursors := manager.cursors
|
||||
manager.cursors = make(map[types.Session]types.Cursor)
|
||||
|
||||
return cursors
|
||||
}
|
||||
|
||||
// ---
|
||||
// broadcasts
|
||||
// ---
|
||||
|
@ -16,10 +16,6 @@ type SessionCtx struct {
|
||||
profile types.MemberProfile
|
||||
state types.SessionState
|
||||
|
||||
positionX int
|
||||
positionY int
|
||||
positionMu sync.Mutex
|
||||
|
||||
websocketPeer types.WebSocketPeer
|
||||
websocketMu sync.Mutex
|
||||
|
||||
@ -57,16 +53,8 @@ func (session *SessionCtx) IsHost() bool {
|
||||
return session.manager.GetHost() == session
|
||||
}
|
||||
|
||||
// ---
|
||||
// cursor position
|
||||
// ---
|
||||
|
||||
func (session *SessionCtx) SetPosition(x, y int) {
|
||||
session.positionMu.Lock()
|
||||
defer session.positionMu.Unlock()
|
||||
|
||||
session.positionX = x
|
||||
session.positionY = y
|
||||
func (session *SessionCtx) SetCursor(x, y int) {
|
||||
session.manager.SetCursor(x, y, session)
|
||||
}
|
||||
|
||||
// ---
|
||||
|
Reference in New Issue
Block a user