Archived
2
0

Implicit control gain (#108)

* add client side implicit hosting.

* add server side implicit hosting.

* update changelog.

* allow clipboard & keybaord access.
This commit is contained in:
Miroslav Šedivý
2021-12-11 14:34:28 +01:00
committed by GitHub
parent f08ed0fc28
commit 7d1fa28d88
21 changed files with 125 additions and 38 deletions

View File

@ -25,6 +25,11 @@ func (h *MessageHandler) adminLock(id string, session types.Session, payload *me
return nil
}
// TODO: Handle locks in sessions as flags.
if payload.Resource == "control" {
h.sessions.SetControlLocked(true)
}
h.locked[payload.Resource] = id
if err := h.sessions.Broadcast(
@ -52,6 +57,11 @@ func (h *MessageHandler) adminUnlock(id string, session types.Session, payload *
return nil
}
// TODO: Handle locks in sessions as flags.
if payload.Resource == "control" {
h.sessions.SetControlLocked(false)
}
delete(h.locked, payload.Resource)
if err := h.sessions.Broadcast(

View File

@ -125,9 +125,9 @@ func (h *MessageHandler) controlGive(id string, session types.Session, payload *
}
func (h *MessageHandler) controlClipboard(id string, session types.Session, payload *message.Clipboard) error {
// check if session is host
if !h.sessions.IsHost(id) {
h.logger.Debug().Str("id", id).Msg("is not the host")
// check if session can access clipboard
if (!h.webrtc.ImplicitControl() && !h.sessions.IsHost(id)) || (h.webrtc.ImplicitControl() && !h.sessions.CanControl(id)) {
h.logger.Debug().Str("id", id).Msg("cannot access clipboard")
return nil
}
@ -136,9 +136,9 @@ func (h *MessageHandler) controlClipboard(id string, session types.Session, payl
}
func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error {
// check if session is host
if !h.sessions.IsHost(id) {
h.logger.Debug().Str("id", id).Msg("is not the host")
// check if session can control keyboard
if (!h.webrtc.ImplicitControl() && !h.sessions.IsHost(id)) || (h.webrtc.ImplicitControl() && !h.sessions.CanControl(id)) {
h.logger.Debug().Str("id", id).Msg("cannot control keyboard")
return nil
}

View File

@ -15,7 +15,7 @@ func (h *MessageHandler) SessionCreated(id string, session types.Session) error
// send initialization information
if err := session.Send(message.SystemInit{
Event: event.SYSTEM_INIT,
ImplicitHosting: true,
ImplicitHosting: h.webrtc.ImplicitControl(),
Locks: h.locked,
}); err != nil {
h.logger.Warn().Str("id", id).Err(err).Msgf("sending event %s has failed", event.SYSTEM_INIT)

View File

@ -105,6 +105,7 @@ func (ws *WebSocketHandler) Start() {
sess, ok := ws.handler.locked["control"]
if ok && ws.conf.ControlProtection && sess == CONTROL_PROTECTION_SESSION && len(ws.sessions.Admins()) > 0 {
delete(ws.handler.locked, "control")
ws.sessions.SetControlLocked(false) // TODO: Handle locks in sessions as flags.
ws.logger.Info().Msgf("control unlocked on behalf of control protection")
if err := ws.sessions.Broadcast(
@ -140,6 +141,7 @@ func (ws *WebSocketHandler) Start() {
_, ok := ws.handler.locked["control"]
if !ok && ws.conf.ControlProtection && adminCount == 0 {
ws.handler.locked["control"] = CONTROL_PROTECTION_SESSION
ws.sessions.SetControlLocked(true) // TODO: Handle locks in sessions as flags.
ws.logger.Info().Msgf("control locked and released on behalf of control protection")
ws.handler.adminRelease(id, session)