neko/internal/websocket/handler/session.go

53 lines
1.0 KiB
Go
Raw Normal View History

2020-11-02 04:09:48 +13:00
package handler
import (
2020-10-29 07:15:48 +13:00
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
2020-12-01 08:07:19 +13:00
if err := h.systemInit(session); err != nil {
return err
}
2020-12-01 08:07:19 +13:00
if session.Admin() {
if err := h.systemAdmin(session); err != nil {
return err
}
}
// let everyone know there is a new session
2020-11-19 08:30:33 +13:00
h.sessions.Broadcast(
2020-12-02 07:47:50 +13:00
message.MemberData{
Event: event.MEMBER_CONNECTED,
ID: session.ID(),
Name: session.Name(),
IsAdmin: session.Admin(),
2020-11-17 06:12:25 +13:00
}, nil)
2020-11-19 08:30:33 +13:00
return nil
}
2020-11-02 08:53:25 +13:00
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
// clear host if exists
2020-11-02 08:53:25 +13:00
if session.IsHost() {
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)
}
// let everyone know session disconnected
2020-11-19 08:30:33 +13:00
h.sessions.Broadcast(
2020-12-02 07:47:50 +13:00
message.MemberID{
Event: event.MEMBER_DISCONNECTED,
2020-11-02 08:53:25 +13:00
ID: session.ID(),
2020-11-17 06:12:25 +13:00
}, nil);
2020-11-19 08:30:33 +13:00
return nil
}