inactive cursors access control.

This commit is contained in:
Miroslav Šedivý 2021-11-03 21:59:38 +01:00
parent 6b417131f2
commit 437eb44003
8 changed files with 62 additions and 36 deletions

View File

@ -63,6 +63,8 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) e
CanWatch: true, CanWatch: true,
CanHost: true, CanHost: true,
CanAccessClipboard: true, CanAccessClipboard: true,
SendsInactiveCursor: true,
CanSeeInactiveCursors: true,
}, },
} }

View File

@ -15,6 +15,8 @@ func New() types.MemberProvider {
CanWatch: true, CanWatch: true,
CanHost: true, CanHost: true,
CanAccessClipboard: true, CanAccessClipboard: true,
SendsInactiveCursor: true,
CanSeeInactiveCursors: true,
}, },
} }
} }

View File

@ -29,6 +29,8 @@ func (provider *MemberProviderCtx) Connect() error {
CanWatch: true, CanWatch: true,
CanHost: true, CanHost: true,
CanAccessClipboard: true, CanAccessClipboard: true,
SendsInactiveCursor: true,
CanSeeInactiveCursors: true,
}) })
} }
@ -42,6 +44,8 @@ func (provider *MemberProviderCtx) Connect() error {
CanWatch: true, CanWatch: true,
CanHost: true, CanHost: true,
CanAccessClipboard: true, CanAccessClipboard: true,
SendsInactiveCursor: true,
CanSeeInactiveCursors: false,
}) })
} }

View File

@ -254,6 +254,22 @@ func (manager *SessionManagerCtx) AdminBroadcast(event string, payload interface
} }
} }
func (manager *SessionManagerCtx) InactiveCursorsBroadcast(event string, payload interface{}, exclude interface{}) {
for _, session := range manager.List() {
if !session.State().IsConnected || !session.Profile().CanSeeInactiveCursors {
continue
}
if exclude != nil {
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
continue
}
}
session.Send(event, payload)
}
}
// --- // ---
// events // events
// --- // ---

View File

@ -54,7 +54,7 @@ func (session *SessionCtx) IsHost() bool {
} }
func (session *SessionCtx) SetCursor(cursor types.Cursor) { func (session *SessionCtx) SetCursor(cursor types.Cursor) {
if session.manager.InactiveCursors() { if session.manager.InactiveCursors() && session.profile.SendsInactiveCursor {
session.manager.SetCursor(cursor, session) session.manager.SetCursor(cursor, session)
} }
} }

View File

@ -16,6 +16,8 @@ type MemberProfile struct {
CanWatch bool `json:"can_watch"` CanWatch bool `json:"can_watch"`
CanHost bool `json:"can_host"` CanHost bool `json:"can_host"`
CanAccessClipboard bool `json:"can_access_clipboard"` CanAccessClipboard bool `json:"can_access_clipboard"`
SendsInactiveCursor bool `json:"sends_inactive_cursor"`
CanSeeInactiveCursors bool `json:"can_see_inactive_cursors"`
} }
type MemberProvider interface { type MemberProvider interface {

View File

@ -60,6 +60,7 @@ type SessionManager interface {
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{})
InactiveCursorsBroadcast(event string, payload interface{}, exclude interface{})
OnCreated(listener func(session Session)) OnCreated(listener func(session Session))
OnDeleted(listener func(session Session)) OnDeleted(listener func(session Session))

View File

@ -173,8 +173,7 @@ func (manager *WebSocketManagerCtx) Start() {
) )
} }
// TODO: Send to subscribers only. manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, cursors, nil)
manager.sessions.AdminBroadcast(event.SESSION_CURSORS, cursors, nil)
} }
} }
}() }()