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

@ -8,6 +8,7 @@ import (
type Session struct {
Password string
AdminPassword string
ImplicitHosting bool
}
func (Session) Init(cmd *cobra.Command) error {
@ -21,10 +22,16 @@ func (Session) Init(cmd *cobra.Command) error {
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
}
func (s *Session) Set() {
s.Password = viper.GetString("password")
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))
})
}
func (manager *SessionManagerCtx) ImplicitHosting() bool {
return manager.config.ImplicitHosting
}

View File

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

View File

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

View File

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

View File

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