From 1394984be7fde9b4bc913cf32aa1ae4a071679c2 Mon Sep 17 00:00:00 2001
From: Maxim Khlobystov <maxim.khlobystov@gmail.com>
Date: Mon, 15 Jan 2018 16:01:57 -0500
Subject: [PATCH] Made the mute/unmute observer work.

---
 .../ui/services/audio-manager/index.js        | 28 ++++++++-----------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/bigbluebutton-html5/imports/ui/services/audio-manager/index.js b/bigbluebutton-html5/imports/ui/services/audio-manager/index.js
index 4b09c335d4..2944f40b0c 100644
--- a/bigbluebutton-html5/imports/ui/services/audio-manager/index.js
+++ b/bigbluebutton-html5/imports/ui/services/audio-manager/index.js
@@ -33,15 +33,6 @@ class AudioManager {
       error: null,
       outputDeviceId: null,
     });
-
-    const query = VoiceUsers.find({ intId: Auth.userID });
-
-    query.observeChanges({ // keep track of mute/unmute in case of Flash changing it
-      changed: (id, fields) => {
-        if (fields.muted === this.isMuted) return;
-        this.isMuted = fields.muted;
-      },
-    });
   }
 
   init(userData, messages) {
@@ -128,15 +119,24 @@ class AudioManager {
   }
 
   toggleMuteMicrophone() {
-    makeCall('toggleSelfVoice').then(() => {
-      this.onToggleMicrophoneMute();
-    });
+    makeCall('toggleSelfVoice');
   }
 
   onAudioJoin() {
     this.isConnecting = false;
     this.isConnected = true;
 
+    // listen to the VoiceUsers changes and update the flag
+    if(!this.muteHandle) {
+      const query = VoiceUsers.find({ intId: Auth.userID });
+      this.muteHandle = query.observeChanges({ // keep track of mute/unmute in case of Flash changing it
+        changed: (id, fields) => {
+          if (fields.muted === this.isMuted) return;
+          this.isMuted = fields.muted;
+        },
+      });
+    }
+
     if (!this.isEchoTest) {
       this.notify(this.messages.info.JOINED_AUDIO);
     }
@@ -147,10 +147,6 @@ class AudioManager {
     this.isConnecting = true;
   }
 
-  onToggleMicrophoneMute() {
-    this.isMuted = !this.isMuted;
-  }
-
   onAudioExit() {
     this.isConnected = false;
     this.isConnecting = false;
-- 
GitLab