neko/internal/websocket/handler/control.go
2021-03-14 00:45:51 +01:00

53 lines
1.1 KiB
Go

package handler
import (
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
if !session.Profile().CanHost {
h.logger.Debug().Str("session_id", session.ID()).Msg("is not allowed to host")
return nil
}
if !session.IsHost() {
h.logger.Debug().Str("session_id", session.ID()).Msg("is not the host")
return nil
}
h.desktop.ResetKeys()
h.sessions.ClearHost()
return nil
}
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
if !session.Profile().CanHost {
h.logger.Debug().Str("session_id", session.ID()).Msg("is not allowed to host")
return nil
}
if session.IsHost() {
h.logger.Debug().Str("session_id", session.ID()).Msg("is already the host")
return nil
}
if !h.sessions.ImplicitHosting() {
// tell session if there is a host
if host := h.sessions.GetHost(); host != nil {
return session.Send(
message.ControlHost{
Event: event.CONTROL_HOST,
HasHost: true,
HostID: host.ID(),
})
}
}
h.sessions.SetHost(session)
return nil
}