From b71c65d49d3c0e33df3082ee038da781e2117eaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 21 May 2021 09:42:09 -0400
Subject: [PATCH] conference: do not bind audio for muted participants

Change-Id: I9185ae55bd507b2b9869545928ad8792c81e4172
GitLab: #552
---
 src/conference.cpp | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/conference.cpp b/src/conference.cpp
index c2b283a686..ae7b93e9a3 100644
--- a/src/conference.cpp
+++ b/src/conference.cpp
@@ -443,7 +443,14 @@ Conference::attach()
     if (getState() == State::ACTIVE_DETACHED) {
         auto& rbPool = Manager::instance().getRingBufferPool();
         for (const auto& participant : getParticipantList()) {
-            rbPool.bindCallID(participant, RingBufferPool::DEFAULT_ID);
+            if (auto call = Manager::instance().getCallFromCallID(participant)) {
+                if (isMuted(string_remove_suffix(call->getPeerNumber(), '@')))
+                    rbPool.bindHalfDuplexOut(participant, RingBufferPool::DEFAULT_ID);
+                else
+                    rbPool.bindCallID(participant, RingBufferPool::DEFAULT_ID);
+                rbPool.flush(participant);
+            }
+
             // Reset ringbuffer's readpointers
             rbPool.flush(participant);
         }
@@ -497,15 +504,25 @@ Conference::bindParticipant(const std::string& participant_id)
     auto& rbPool = Manager::instance().getRingBufferPool();
 
     for (const auto& item : participants_) {
-        if (participant_id != item)
-            rbPool.bindCallID(participant_id, item);
+        if (participant_id != item) {
+            // Do not attach muted participants
+            if (auto call = Manager::instance().getCallFromCallID(item)) {
+                if (isMuted(string_remove_suffix(call->getPeerNumber(), '@')))
+                    rbPool.bindHalfDuplexOut(item, participant_id);
+                else
+                    rbPool.bindCallID(participant_id, item);
+            }
+        }
         rbPool.flush(item);
     }
 
     // Bind local participant to other participants only if the
     // local is attached to the conference.
     if (getState() == State::ACTIVE_ATTACHED) {
-        rbPool.bindCallID(participant_id, RingBufferPool::DEFAULT_ID);
+        if (isMuted("host"sv))
+            rbPool.bindHalfDuplexOut(RingBufferPool::DEFAULT_ID, participant_id);
+        else
+            rbPool.bindCallID(participant_id, RingBufferPool::DEFAULT_ID);
         rbPool.flush(RingBufferPool::DEFAULT_ID);
     }
 }
-- 
GitLab