mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
introduced ImplicitHosting.
This commit is contained in:
parent
26c0fea840
commit
1677e38935
@ -6,8 +6,9 @@ import (
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
Password string
|
||||
AdminPassword string
|
||||
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")
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -30,16 +30,16 @@ 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
|
||||
return session.Send(
|
||||
message.ControlHost{
|
||||
Event: event.CONTROL_HOST,
|
||||
HasHost: true,
|
||||
HostID: host.ID(),
|
||||
})
|
||||
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,
|
||||
HasHost: true,
|
||||
HostID: host.ID(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
h.sessions.SetHost(session)
|
||||
|
@ -34,15 +34,16 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
||||
|
||||
return session.Send(
|
||||
message.SystemInit{
|
||||
Event: event.SYSTEM_INIT,
|
||||
MemberId: session.ID(),
|
||||
ControlHost: controlHost,
|
||||
Members: members,
|
||||
ScreenSize: message.ScreenSize{
|
||||
Event: event.SYSTEM_INIT,
|
||||
MemberId: session.ID(),
|
||||
ControlHost: controlHost,
|
||||
ScreenSize: message.ScreenSize{
|
||||
Width: size.Width,
|
||||
Height: size.Height,
|
||||
Rate: int(size.Rate),
|
||||
},
|
||||
Members: members,
|
||||
ImplicitHosting: h.sessions.ImplicitHosting(),
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user