introduced ImplicitHosting.

This commit is contained in:
Miroslav Šedivý 2020-12-02 11:24:20 +01:00
parent 26c0fea840
commit 1677e38935
6 changed files with 31 additions and 17 deletions

View File

@ -6,8 +6,9 @@ import (
) )
type Session struct { type Session struct {
Password string Password string
AdminPassword string AdminPassword string
ImplicitHosting bool
} }
func (Session) Init(cmd *cobra.Command) error { func (Session) Init(cmd *cobra.Command) error {
@ -21,10 +22,16 @@ func (Session) Init(cmd *cobra.Command) error {
return err return err
} }
cmd.PersistentFlags().Bool("implicit_hosting", true, "allow implicit control switching")
if err := viper.BindPFlag("implicit_hosting", cmd.PersistentFlags().Lookup("implicit_hosting")); err != nil {
return err
}
return nil return nil
} }
func (s *Session) Set() { func (s *Session) Set() {
s.Password = viper.GetString("password") s.Password = viper.GetString("password")
s.AdminPassword = viper.GetString("password_admin") s.AdminPassword = viper.GetString("password_admin")
s.ImplicitHosting = viper.GetBool("implicit_hosting")
} }

View File

@ -241,3 +241,7 @@ func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Ses
listener(payload[0].(*SessionCtx)) listener(payload[0].(*SessionCtx))
}) })
} }
func (manager *SessionManagerCtx) ImplicitHosting() bool {
return manager.config.ImplicitHosting
}

View File

@ -15,6 +15,7 @@ type SystemInit struct {
ControlHost ControlHost `json:"control_host"` ControlHost ControlHost `json:"control_host"`
ScreenSize ScreenSize `json:"screen_size"` ScreenSize ScreenSize `json:"screen_size"`
Members map[string]MemberData `json:"members"` Members map[string]MemberData `json:"members"`
ImplicitHosting bool `json:"implicit_hosting"`
} }
type SystemAdmin struct { type SystemAdmin struct {

View File

@ -48,6 +48,7 @@ type SessionManager interface {
OnHostCleared(listener func(session Session)) OnHostCleared(listener func(session Session))
OnConnected(listener func(session Session)) OnConnected(listener func(session Session))
OnDisconnected(listener func(session Session)) OnDisconnected(listener func(session Session))
ImplicitHosting() bool
// auth // auth
Authenticate(r *http.Request) (Session, error) Authenticate(r *http.Request) (Session, error)

View File

@ -30,16 +30,16 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
return nil return nil
} }
// TODO: Allow implicit requests. if !h.sessions.ImplicitHosting() {
host := h.sessions.GetHost() // tell session if there is a host
if host != nil { if host := h.sessions.GetHost(); host != nil {
// tell session there is a host return session.Send(
return session.Send( message.ControlHost{
message.ControlHost{ Event: event.CONTROL_HOST,
Event: event.CONTROL_HOST, HasHost: true,
HasHost: true, HostID: host.ID(),
HostID: host.ID(), })
}) }
} }
h.sessions.SetHost(session) h.sessions.SetHost(session)

View File

@ -34,15 +34,16 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
return session.Send( return session.Send(
message.SystemInit{ message.SystemInit{
Event: event.SYSTEM_INIT, Event: event.SYSTEM_INIT,
MemberId: session.ID(), MemberId: session.ID(),
ControlHost: controlHost, ControlHost: controlHost,
Members: members, ScreenSize: message.ScreenSize{
ScreenSize: message.ScreenSize{
Width: size.Width, Width: size.Width,
Height: size.Height, Height: size.Height,
Rate: int(size.Rate), Rate: int(size.Rate),
}, },
Members: members,
ImplicitHosting: h.sessions.ImplicitHosting(),
}) })
} }