neko/internal/websocket/handler/session.go

100 lines
2.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) SessionCreated(session types.Session) error {
// send sdp and id over to client
if err := h.signalProvide(session); err != nil {
return err
}
if session.Admin() {
// send screen configurations if admin
if err := h.screenConfigurations(session); err != nil {
return err
}
// send broadcast status if admin
if err := h.boradcastStatus(session); err != nil {
return err
}
}
return nil
}
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
2020-11-02 06:12:16 +13:00
// create member list
2020-11-02 04:09:48 +13:00
members := []*message.MembersListEntry{}
for _, session := range h.sessions.Members() {
members = append(members, &message.MembersListEntry{
ID: session.ID(),
Name: session.Name(),
Admin: session.Admin(),
})
}
// send list of members to session
2020-11-19 08:30:33 +13:00
if err := session.Send(
message.MembersList{
Event: event.MEMBER_LIST,
Memebers: members,
}); err != nil {
return err
}
2020-11-17 10:04:50 +13:00
// send current screen size
if err := h.screenSize(session); err != nil {
return err
}
// tell session there is a host
host := h.sessions.GetHost()
if host != nil {
2020-11-19 08:30:33 +13:00
if err := session.Send(
message.Control{
Event: event.CONTROL_LOCKED,
ID: host.ID(),
}); err != nil {
return err
}
}
// let everyone know there is a new session
2020-11-19 08:30:33 +13:00
h.sessions.Broadcast(
message.Member{
Event: event.MEMBER_CONNECTED,
2020-11-02 04:37:00 +13:00
ID: session.ID(),
Name: session.Name(),
Admin: 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-11-17 05:48:10 +13:00
message.Control{
Event: event.CONTROL_RELEASE,
ID: session.ID(),
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(
message.MemberDisconnected{
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
}