HasConnectedMembers and Members returns not connected.

This commit is contained in:
Miroslav Šedivý 2020-12-02 17:12:00 +01:00
parent 5541675f57
commit 82d37b15e4
2 changed files with 5 additions and 13 deletions

View File

@ -131,20 +131,17 @@ func (manager *SessionManagerCtx) ClearHost() {
// --- // ---
// members list // members list
// --- // ---
func (manager *SessionManagerCtx) Admins() []types.Session { func (manager *SessionManagerCtx) HasConnectedMembers() bool {
manager.membersMu.Lock() manager.membersMu.Lock()
defer manager.membersMu.Unlock() defer manager.membersMu.Unlock()
var sessions []types.Session
for _, session := range manager.members { for _, session := range manager.members {
if !session.IsConnected() || !session.IsAdmin() { if session.IsConnected() {
continue return true
} }
sessions = append(sessions, session)
} }
return sessions return false
} }
func (manager *SessionManagerCtx) Members() []types.Session { func (manager *SessionManagerCtx) Members() []types.Session {
@ -153,10 +150,6 @@ func (manager *SessionManagerCtx) Members() []types.Session {
var sessions []types.Session var sessions []types.Session
for _, session := range manager.members { for _, session := range manager.members {
if !session.IsConnected() {
continue
}
sessions = append(sessions, session) sessions = append(sessions, session)
} }
@ -234,7 +227,7 @@ func (manager *SessionManagerCtx) OnConnected(listener func(session types.Sessio
func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Session)) { func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Session)) {
manager.emmiter.On("disconnected", func(payload ...interface{}) { manager.emmiter.On("disconnected", func(payload ...interface{}) {
// Stop streaming, if everyone left // Stop streaming, if everyone left
if manager.capture.Streaming() && len(manager.Members()) == 0 { if manager.capture.Streaming() && !manager.HasConnectedMembers() {
manager.capture.StopStream() manager.capture.StopStream()
} }

View File

@ -39,7 +39,6 @@ type SessionManager interface {
GetHost() Session GetHost() Session
ClearHost() ClearHost()
Admins() []Session
Members() []Session Members() []Session
Broadcast(v interface{}, exclude interface{}) Broadcast(v interface{}, exclude interface{})
AdminBroadcast(v interface{}, exclude interface{}) AdminBroadcast(v interface{}, exclude interface{})