mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
unlock room if no admins online
This commit is contained in:
parent
82ca6e13ca
commit
414b5a8015
@ -88,6 +88,21 @@ func (manager *SessionManager) Get(id string) (types.Session, bool) {
|
|||||||
return session, ok
|
return session, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *SessionManager) Admins() []*types.Member {
|
||||||
|
members := []*types.Member{}
|
||||||
|
for _, session := range manager.members {
|
||||||
|
if !session.connected || !session.admin {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
member := session.Member()
|
||||||
|
if member != nil {
|
||||||
|
members = append(members, member)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
func (manager *SessionManager) Members() []*types.Member {
|
func (manager *SessionManager) Members() []*types.Member {
|
||||||
members := []*types.Member{}
|
members := []*types.Member{}
|
||||||
for _, session := range manager.members {
|
for _, session := range manager.members {
|
||||||
@ -113,7 +128,7 @@ func (manager *SessionManager) Destroy(id string) error {
|
|||||||
manager.remote.StopStream()
|
manager.remote.StopStream()
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.emmiter.Emit("destroyed", id)
|
manager.emmiter.Emit("destroyed", id, session)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,9 +170,9 @@ func (manager *SessionManager) OnHostCleared(listener func(id string)) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManager) OnDestroy(listener func(id string)) {
|
func (manager *SessionManager) OnDestroy(listener func(id string, session types.Session)) {
|
||||||
manager.emmiter.On("destroyed", func(payload ...interface{}) {
|
manager.emmiter.On("destroyed", func(payload ...interface{}) {
|
||||||
listener(payload[0].(string))
|
listener(payload[0].(string), payload[1].(*Session))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,12 +36,13 @@ type SessionManager interface {
|
|||||||
Has(id string) bool
|
Has(id string) bool
|
||||||
Get(id string) (Session, bool)
|
Get(id string) (Session, bool)
|
||||||
Members() []*Member
|
Members() []*Member
|
||||||
|
Admins() []*Member
|
||||||
Destroy(id string) error
|
Destroy(id string) error
|
||||||
Clear() error
|
Clear() error
|
||||||
Broadcast(v interface{}, exclude interface{}) error
|
Broadcast(v interface{}, exclude interface{}) error
|
||||||
OnHost(listener func(id string))
|
OnHost(listener func(id string))
|
||||||
OnHostCleared(listener func(id string))
|
OnHostCleared(listener func(id string))
|
||||||
OnDestroy(listener func(id string))
|
OnDestroy(listener func(id string, session Session))
|
||||||
OnCreated(listener func(id string, session Session))
|
OnCreated(listener func(id string, session Session))
|
||||||
OnConnected(listener func(id string, session Session))
|
OnConnected(listener func(id string, session Session))
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,10 @@ func (h *MessageHandler) Connected(id string, socket *WebSocket) (bool, string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) Disconnected(id string) error {
|
func (h *MessageHandler) Disconnected(id string) error {
|
||||||
|
if h.locked && len(h.sessions.Admins()) == 0 {
|
||||||
|
h.locked = false
|
||||||
|
}
|
||||||
|
|
||||||
return h.sessions.Destroy(id)
|
return h.sessions.Destroy(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user