mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
system init WS.
This commit is contained in:
parent
745ef00cd2
commit
d00015ee91
@ -1,7 +1,8 @@
|
|||||||
package event
|
package event
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SYSTEM_CONNECT = "system/connect" // TODO: New.
|
SYSTEM_INIT = "system/init"
|
||||||
|
SYSTEM_ADMIN = "system/admin"
|
||||||
SYSTEM_DISCONNECT = "system/disconnect"
|
SYSTEM_DISCONNECT = "system/disconnect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,14 +6,17 @@ type Message struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// System
|
// System
|
||||||
// TODO: New.
|
type SystemInit struct {
|
||||||
type SystemConnect struct {
|
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
ControlHost ControlHost `json:"control_host"`
|
ControlHost ControlHost `json:"control_host"`
|
||||||
ScreenSize ScreenSize `json:"screen_size"`
|
ScreenSize ScreenSize `json:"screen_size"`
|
||||||
Members []MemberData `json:"members"`
|
Members []MemberData `json:"members"`
|
||||||
ScreenSizesList *[]ScreenSize `json:"screen_sizes_list,omitempty"`
|
}
|
||||||
BroadcastStatus BroadcastStatus `json:"members,omitempty"`
|
|
||||||
|
type SystemAdmin struct {
|
||||||
|
Event string `json:"event,omitempty"`
|
||||||
|
ScreenSizesList []ScreenSize `json:"screen_sizes_list"`
|
||||||
|
BroadcastStatus BroadcastStatus `json:"broadcast_status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: New.
|
// TODO: New.
|
||||||
@ -106,9 +109,9 @@ type KeyboardLayout struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BroadcastStatus struct {
|
type BroadcastStatus struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event,omitempty"`
|
||||||
URL string `json:"url"`
|
|
||||||
IsActive bool `json:"is_active"`
|
IsActive bool `json:"is_active"`
|
||||||
|
URL string `json:"url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove.
|
// TODO: Remove.
|
||||||
|
@ -7,34 +7,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||||
// create member list
|
if err := h.systemInit(session); err != nil {
|
||||||
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
|
|
||||||
if err := session.Send(
|
|
||||||
message.MembersList{
|
|
||||||
Event: event.MEMBER_LIST,
|
|
||||||
Memebers: members,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell session there is a host
|
if session.Admin() {
|
||||||
host := h.sessions.GetHost()
|
if err := h.systemAdmin(session); err != nil {
|
||||||
if host != nil {
|
|
||||||
if err := session.Send(
|
|
||||||
message.ControlHost{
|
|
||||||
Event: event.CONTROL_HOST,
|
|
||||||
HasHost: true,
|
|
||||||
HostID: host.ID(),
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
69
internal/websocket/handler/system.go
Normal file
69
internal/websocket/handler/system.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"demodesk/neko/internal/types"
|
||||||
|
"demodesk/neko/internal/types/event"
|
||||||
|
"demodesk/neko/internal/types/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
||||||
|
host := h.sessions.GetHost()
|
||||||
|
|
||||||
|
controlHost := message.ControlHost{
|
||||||
|
HasHost: host != nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if controlHost.HasHost {
|
||||||
|
controlHost.HostID = host.ID()
|
||||||
|
}
|
||||||
|
|
||||||
|
size := h.desktop.GetScreenSize()
|
||||||
|
if size == nil {
|
||||||
|
h.logger.Debug().Msg("could not get screen size")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
members := []message.MemberData{}
|
||||||
|
for _, session := range h.sessions.Members() {
|
||||||
|
members = append(members, message.MemberData{
|
||||||
|
ID: session.ID(),
|
||||||
|
Name: session.Name(),
|
||||||
|
IsAdmin: session.Admin(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Send(
|
||||||
|
message.SystemInit{
|
||||||
|
Event: event.SYSTEM_INIT,
|
||||||
|
ControlHost: controlHost,
|
||||||
|
Members: members,
|
||||||
|
ScreenSize: message.ScreenSize{
|
||||||
|
Width: size.Width,
|
||||||
|
Height: size.Height,
|
||||||
|
Rate: int(size.Rate),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
|
||||||
|
screenSizesList := []message.ScreenSize{}
|
||||||
|
for _, size := range h.desktop.ScreenConfigurations() {
|
||||||
|
for _, fps := range size.Rates {
|
||||||
|
screenSizesList = append(screenSizesList, message.ScreenSize{
|
||||||
|
Width: size.Width,
|
||||||
|
Height: size.Height,
|
||||||
|
Rate: int(fps),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.Send(
|
||||||
|
message.SystemAdmin{
|
||||||
|
Event: event.SYSTEM_ADMIN,
|
||||||
|
ScreenSizesList: screenSizesList,
|
||||||
|
BroadcastStatus: message.BroadcastStatus{
|
||||||
|
IsActive: h.capture.BroadcastEnabled(),
|
||||||
|
URL: h.capture.BroadcastUrl(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user