neko/internal/websocket/handler/control.go
Miroslav Šedivý 5edd9dc97a + CanHost.
2020-12-06 18:50:41 +01:00

65 lines
1.3 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.CanHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not allowed to host")
return nil
}
if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil
}
h.desktop.ResetKeys()
h.sessions.ClearHost()
h.sessions.Broadcast(
message.ControlHost{
Event: event.CONTROL_HOST,
HasHost: false,
}, nil)
return nil
}
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
if !session.CanHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not allowed to host")
return nil
}
if session.IsHost() {
h.logger.Debug().Str("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)
h.sessions.Broadcast(
message.ControlHost{
Event: event.CONTROL_HOST,
HasHost: true,
HostID: session.ID(),
}, nil)
return nil
}