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-12-03 06:59:54 +13:00
|
|
|
func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberData{
|
2020-12-04 04:10:52 +13:00
|
|
|
Event: event.MEMBER_CREATED,
|
|
|
|
ID: session.ID(),
|
2020-12-09 03:14:20 +13:00
|
|
|
// TODO: Get whole profile from session.
|
|
|
|
Profile: types.MemberProfile{
|
2020-12-03 06:59:54 +13:00
|
|
|
Name: session.Name(),
|
|
|
|
IsAdmin: session.IsAdmin(),
|
|
|
|
CanLogin: session.CanLogin(),
|
|
|
|
CanConnect: session.CanConnect(),
|
|
|
|
CanWatch: session.CanWatch(),
|
|
|
|
CanHost: session.CanHost(),
|
|
|
|
CanAccessClipboard: session.CanAccessClipboard(),
|
|
|
|
},
|
2020-12-09 03:14:20 +13:00
|
|
|
// TODO: Get whole state from session.
|
|
|
|
State: types.MemberState{
|
2020-12-04 04:10:52 +13:00
|
|
|
IsConnected: session.IsConnected(),
|
2020-12-07 07:02:33 +13:00
|
|
|
IsWatching: session.IsWatching(),
|
2020-12-04 04:10:52 +13:00
|
|
|
},
|
2020-12-03 06:59:54 +13:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MessageHandlerCtx) SessionDeleted(session types.Session) error {
|
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberID{
|
|
|
|
Event: event.MEMBER_DELETED,
|
|
|
|
ID: session.ID(),
|
|
|
|
}, nil);
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
2020-12-03 05:36:06 +13:00
|
|
|
// start streaming, when first member connects
|
|
|
|
if !h.capture.Streaming() {
|
|
|
|
h.capture.StartStream()
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:07:19 +13:00
|
|
|
if err := h.systemInit(session); err != nil {
|
2020-10-23 03:54:50 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-03 04:49:51 +13:00
|
|
|
if session.IsAdmin() {
|
2020-12-01 08:07:19 +13:00
|
|
|
if err := h.systemAdmin(session); err != nil {
|
2020-10-23 03:54:50 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 04:42:27 +13:00
|
|
|
return h.SessionStateChanged(session)
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 08:53:25 +13:00
|
|
|
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
2020-12-03 05:36:06 +13:00
|
|
|
// Stop streaming, if last member disonnects
|
|
|
|
if h.capture.Streaming() && !h.sessions.HasConnectedMembers() {
|
|
|
|
h.capture.StopStream()
|
|
|
|
}
|
|
|
|
|
2020-10-23 03:54:50 +13:00
|
|
|
// clear host if exists
|
2020-11-02 08:53:25 +13:00
|
|
|
if session.IsHost() {
|
2020-12-02 22:46:00 +13:00
|
|
|
h.desktop.ResetKeys()
|
2020-10-23 03:54:50 +13:00
|
|
|
h.sessions.ClearHost()
|
2020-11-17 06:12:25 +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-19 08:30:33 +13:00
|
|
|
}, nil)
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-12-04 04:42:27 +13:00
|
|
|
return h.SessionStateChanged(session)
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
2020-12-03 06:59:54 +13:00
|
|
|
|
2020-12-04 04:10:52 +13:00
|
|
|
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
|
2020-12-03 06:59:54 +13:00
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberProfile{
|
2020-12-09 03:14:20 +13:00
|
|
|
Event: event.MEMBER_PROFILE,
|
|
|
|
ID: session.ID(),
|
|
|
|
// TODO: Get whole profile from session.
|
|
|
|
MemberProfile: &types.MemberProfile{
|
|
|
|
Name: session.Name(),
|
|
|
|
IsAdmin: session.IsAdmin(),
|
|
|
|
CanLogin: session.CanLogin(),
|
|
|
|
CanConnect: session.CanConnect(),
|
|
|
|
CanWatch: session.CanWatch(),
|
|
|
|
CanHost: session.CanHost(),
|
|
|
|
CanAccessClipboard: session.CanAccessClipboard(),
|
|
|
|
},
|
2020-12-03 06:59:54 +13:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-04 04:10:52 +13:00
|
|
|
|
|
|
|
func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
|
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberState{
|
|
|
|
Event: event.MEMBER_STATE,
|
|
|
|
ID: session.ID(),
|
2020-12-09 03:14:20 +13:00
|
|
|
// TODO: Get whole state from session.
|
|
|
|
MemberState: &types.MemberState{
|
|
|
|
IsConnected: session.IsConnected(),
|
|
|
|
IsWatching: session.IsWatching(),
|
|
|
|
},
|
2020-12-04 04:10:52 +13:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|