mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Inactive cursors - multiple positions.
This commit is contained in:
parent
8dbe0d1d2d
commit
097e8d2a87
@ -19,7 +19,7 @@ func New(config *config.Session) *SessionManagerCtx {
|
|||||||
config: config,
|
config: config,
|
||||||
tokens: make(map[string]string),
|
tokens: make(map[string]string),
|
||||||
sessions: make(map[string]*SessionCtx),
|
sessions: make(map[string]*SessionCtx),
|
||||||
cursors: make(map[types.Session]types.Cursor),
|
cursors: make(map[types.Session][]types.Cursor),
|
||||||
emmiter: events.New(),
|
emmiter: events.New(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ type SessionManagerCtx struct {
|
|||||||
host types.Session
|
host types.Session
|
||||||
hostMu sync.Mutex
|
hostMu sync.Mutex
|
||||||
|
|
||||||
cursors map[types.Session]types.Cursor
|
cursors map[types.Session][]types.Cursor
|
||||||
cursorsMu sync.Mutex
|
cursorsMu sync.Mutex
|
||||||
|
|
||||||
emmiter events.EventEmmiter
|
emmiter events.EventEmmiter
|
||||||
@ -205,15 +205,21 @@ func (manager *SessionManagerCtx) SetCursor(cursor types.Cursor, session types.S
|
|||||||
manager.cursorsMu.Lock()
|
manager.cursorsMu.Lock()
|
||||||
defer manager.cursorsMu.Unlock()
|
defer manager.cursorsMu.Unlock()
|
||||||
|
|
||||||
manager.cursors[session] = cursor
|
list, ok := manager.cursors[session]
|
||||||
|
if !ok {
|
||||||
|
list = []types.Cursor{}
|
||||||
|
}
|
||||||
|
|
||||||
|
list = append(list, cursor)
|
||||||
|
manager.cursors[session] = list
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) PopCursors() map[types.Session]types.Cursor {
|
func (manager *SessionManagerCtx) PopCursors() map[types.Session][]types.Cursor {
|
||||||
manager.cursorsMu.Lock()
|
manager.cursorsMu.Lock()
|
||||||
defer manager.cursorsMu.Unlock()
|
defer manager.cursorsMu.Unlock()
|
||||||
|
|
||||||
cursors := manager.cursors
|
cursors := manager.cursors
|
||||||
manager.cursors = make(map[types.Session]types.Cursor)
|
manager.cursors = make(map[types.Session][]types.Cursor)
|
||||||
|
|
||||||
return cursors
|
return cursors
|
||||||
}
|
}
|
||||||
|
@ -88,10 +88,9 @@ type SessionData struct {
|
|||||||
State types.SessionState `json:"state"`
|
State types.SessionState `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionCursor struct {
|
type SessionCursors struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
X uint16 `json:"x"`
|
Cursors []types.Cursor `json:"cursors"`
|
||||||
Y uint16 `json:"y"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -13,8 +13,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Cursor struct {
|
type Cursor struct {
|
||||||
X int
|
X int `json:"x"`
|
||||||
Y int
|
Y int `json:"y"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionState struct {
|
type SessionState struct {
|
||||||
@ -56,7 +56,7 @@ type SessionManager interface {
|
|||||||
ClearHost()
|
ClearHost()
|
||||||
|
|
||||||
SetCursor(cursor Cursor, session Session)
|
SetCursor(cursor Cursor, session Session)
|
||||||
PopCursors() map[Session]Cursor
|
PopCursors() map[Session][]Cursor
|
||||||
|
|
||||||
Broadcast(event string, payload interface{}, exclude interface{})
|
Broadcast(event string, payload interface{}, exclude interface{})
|
||||||
AdminBroadcast(event string, payload interface{}, exclude interface{})
|
AdminBroadcast(event string, payload interface{}, exclude interface{})
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
const pingPeriod = 10 * time.Second
|
const pingPeriod = 10 * time.Second
|
||||||
|
|
||||||
// period for sending inactive cursor messages
|
// period for sending inactive cursor messages
|
||||||
const inactiveCursorsPeriod = 500 * time.Millisecond
|
const inactiveCursorsPeriod = 750 * time.Millisecond
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
sessions types.SessionManager,
|
sessions types.SessionManager,
|
||||||
@ -326,19 +326,18 @@ func (manager *WebSocketManagerCtx) inactiveCursors() {
|
|||||||
}
|
}
|
||||||
lastEmpty = currentEmpty
|
lastEmpty = currentEmpty
|
||||||
|
|
||||||
cursors := []message.SessionCursor{}
|
sessionCursors := []message.SessionCursors{}
|
||||||
for session, cursor := range cursorsMap {
|
for session, cursors := range cursorsMap {
|
||||||
cursors = append(
|
sessionCursors = append(
|
||||||
cursors,
|
sessionCursors,
|
||||||
message.SessionCursor{
|
message.SessionCursors{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
X: uint16(cursor.X),
|
Cursors: cursors,
|
||||||
Y: uint16(cursor.Y),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, cursors, nil)
|
manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, sessionCursors, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user