Only send single "incall" message with "all: true" in clustered setup.

Previously each instance would send one message to all users in the cluster.
This commit is contained in:
Joachim Bauch
2022-07-04 15:26:12 +02:00
parent b2da4002a4
commit ad1dea2780
2 changed files with 268 additions and 3 deletions
+18 -3
View File
@@ -692,11 +692,13 @@ func (r *Room) PublishUsersInCallChangedAll(inCall int) {
r.mu.Lock()
defer r.mu.Unlock()
var notify []*ClientSession
if inCall&FlagInCall != 0 {
// All connected sessions join the call.
var joined []string
for _, session := range r.sessions {
if _, ok := session.(*ClientSession); !ok {
clientSession, ok := session.(*ClientSession)
if !ok {
continue
}
@@ -708,6 +710,7 @@ func (r *Room) PublishUsersInCallChangedAll(inCall int) {
r.inCallSessions[session] = true
joined = append(joined, session.PublicId())
}
notify = append(notify, clientSession)
}
if len(joined) == 0 {
@@ -729,6 +732,15 @@ func (r *Room) PublishUsersInCallChangedAll(inCall int) {
}
}()
for _, session := range r.sessions {
clientSession, ok := session.(*ClientSession)
if !ok {
continue
}
notify = append(notify, clientSession)
}
for session := range r.inCallSessions {
if clientSession, ok := session.(*ClientSession); ok {
ch <- clientSession
@@ -755,8 +767,11 @@ func (r *Room) PublishUsersInCallChangedAll(inCall int) {
},
},
}
if err := r.publish(message); err != nil {
log.Printf("Could not publish incall message in room %s: %s", r.Id(), err)
for _, session := range notify {
if !session.SendMessage(message) {
log.Printf("Could not send incall message from room %s to %s", r.Id(), session.PublicId())
}
}
}