2020-11-02 04:09:48 +13:00
|
|
|
package handler
|
2020-10-23 03:54:50 +13:00
|
|
|
|
|
|
|
import (
|
2020-10-29 07:15:48 +13:00
|
|
|
"demodesk/neko/internal/types"
|
|
|
|
"demodesk/neko/internal/types/event"
|
|
|
|
"demodesk/neko/internal/types/message"
|
2020-10-23 03:54:50 +13:00
|
|
|
)
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
|
2020-11-01 11:03:37 +13:00
|
|
|
if !session.IsHost() {
|
2020-11-01 10:43:47 +13:00
|
|
|
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
2020-10-23 03:54:50 +13:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-02 22:46:00 +13:00
|
|
|
h.desktop.ResetKeys()
|
2020-10-23 03:54:50 +13:00
|
|
|
h.sessions.ClearHost()
|
2020-12-02 22:46:00 +13:00
|
|
|
|
2020-11-19 08:30:33 +13:00
|
|
|
h.sessions.Broadcast(
|
2020-12-01 06:24:38 +13:00
|
|
|
message.ControlHost{
|
|
|
|
Event: event.CONTROL_HOST,
|
|
|
|
HasHost: false,
|
2020-11-17 06:12:25 +13:00
|
|
|
}, nil)
|
2020-11-19 08:30:33 +13:00
|
|
|
|
|
|
|
return nil
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
2020-12-01 06:24:38 +13:00
|
|
|
// TODO: Allow implicit requests.
|
2020-11-01 11:53:19 +13:00
|
|
|
host := h.sessions.GetHost()
|
2020-12-01 06:24:38 +13:00
|
|
|
if host != nil {
|
2020-11-19 08:30:33 +13:00
|
|
|
// tell session there is a host
|
2020-12-01 06:24:38 +13:00
|
|
|
return session.Send(
|
|
|
|
message.ControlHost{
|
|
|
|
Event: event.CONTROL_HOST,
|
|
|
|
HasHost: true,
|
|
|
|
HostID: host.ID(),
|
2020-11-19 08:30:33 +13:00
|
|
|
})
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-12-01 06:24:38 +13:00
|
|
|
h.sessions.SetHost(session)
|
2020-11-19 08:30:33 +13:00
|
|
|
h.sessions.Broadcast(
|
2020-12-01 06:24:38 +13:00
|
|
|
message.ControlHost{
|
|
|
|
Event: event.CONTROL_HOST,
|
|
|
|
HasHost: true,
|
|
|
|
HostID: session.ID(),
|
2020-11-17 06:12:25 +13:00
|
|
|
}, nil)
|
2020-11-19 08:30:33 +13:00
|
|
|
|
|
|
|
return nil
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|