From ad23e9c0af2a308c2e7e56ab954d31cb21b19bf6 Mon Sep 17 00:00:00 2001
From: Mario Jr <mariogasparoni@gmail.com>
Date: Fri, 26 Feb 2021 15:05:17 -0300
Subject: [PATCH] Cleanup joinedAudioOnly state when user disconnects or
 reconnect microphone

Fixes #11490
---
 .../imports/ui/components/audio/service.js            |  1 +
 .../imports/ui/components/breakout-room/component.jsx | 11 +++++++++++
 .../imports/ui/components/breakout-room/container.jsx |  2 ++
 .../imports/ui/services/audio-manager/index.js        |  6 ++++++
 4 files changed, 20 insertions(+)

diff --git a/bigbluebutton-html5/imports/ui/components/audio/service.js b/bigbluebutton-html5/imports/ui/components/audio/service.js
index b5caac4531..f72b17c8c3 100755
--- a/bigbluebutton-html5/imports/ui/components/audio/service.js
+++ b/bigbluebutton-html5/imports/ui/components/audio/service.js
@@ -135,4 +135,5 @@ export default {
   },
   isReturningFromBreakoutAudioTransfer:
     () => AudioManager.returningFromBreakoutAudioTransfer,
+  isReconnecting: () => AudioManager.isReconnecting,
 };
diff --git a/bigbluebutton-html5/imports/ui/components/breakout-room/component.jsx b/bigbluebutton-html5/imports/ui/components/breakout-room/component.jsx
index 41b5b89864..25a0ffae7f 100644
--- a/bigbluebutton-html5/imports/ui/components/breakout-room/component.jsx
+++ b/bigbluebutton-html5/imports/ui/components/breakout-room/component.jsx
@@ -102,11 +102,14 @@ class BreakoutRoom extends PureComponent {
       breakoutRoomUser,
       breakoutRooms,
       closeBreakoutPanel,
+      isMicrophoneUser,
+      isReconnecting,
     } = this.props;
 
     const {
       waiting,
       requestedBreakoutId,
+      joinedAudioOnly,
     } = this.state;
 
     if (breakoutRooms.length <= 0) closeBreakoutPanel();
@@ -120,6 +123,10 @@ class BreakoutRoom extends PureComponent {
         _.delay(() => this.setState({ waiting: false }), 1000);
       }
     }
+
+    if (joinedAudioOnly && (!isMicrophoneUser || isReconnecting)) {
+      this.clearJoinedAudioOnly();
+    }
   }
 
   getBreakoutURL(breakoutId) {
@@ -144,6 +151,10 @@ class BreakoutRoom extends PureComponent {
     return null;
   }
 
+  clearJoinedAudioOnly() {
+    this.setState({ joinedAudioOnly: false });
+  }
+
   transferUserToBreakoutRoom(breakoutId) {
     const { transferToBreakout } = this.props;
     transferToBreakout(breakoutId);
diff --git a/bigbluebutton-html5/imports/ui/components/breakout-room/container.jsx b/bigbluebutton-html5/imports/ui/components/breakout-room/container.jsx
index a118057d34..f092a239a7 100644
--- a/bigbluebutton-html5/imports/ui/components/breakout-room/container.jsx
+++ b/bigbluebutton-html5/imports/ui/components/breakout-room/container.jsx
@@ -25,6 +25,7 @@ export default withTracker((props) => {
   const breakoutRooms = findBreakouts();
   const isMicrophoneUser = AudioService.isConnected() && !AudioService.isListenOnly();
   const isMeteorConnected = Meteor.status().connected;
+  const isReconnecting = AudioService.isReconnecting();
   const { setReturningFromBreakoutAudioTransfer } = AudioService;
 
   return {
@@ -43,5 +44,6 @@ export default withTracker((props) => {
     isUserInBreakoutRoom,
     exitAudio: () => AudioManager.exitAudio(),
     setReturningFromBreakoutAudioTransfer,
+    isReconnecting,
   };
 })(BreakoutContainer);
diff --git a/bigbluebutton-html5/imports/ui/services/audio-manager/index.js b/bigbluebutton-html5/imports/ui/services/audio-manager/index.js
index 000d427a09..f4d5d68a90 100755
--- a/bigbluebutton-html5/imports/ui/services/audio-manager/index.js
+++ b/bigbluebutton-html5/imports/ui/services/audio-manager/index.js
@@ -52,6 +52,7 @@ class AudioManager {
       outputDeviceId: null,
       muteHandle: null,
       autoplayBlocked: false,
+      isReconnecting: false,
     });
 
     this.useKurento = Meteor.settings.public.kurento.enableListenOnly;
@@ -392,12 +393,15 @@ class AudioManager {
       } = response;
 
       if (status === STARTED) {
+        this.isReconnecting = false;
         this.onAudioJoin();
         resolve(STARTED);
       } else if (status === ENDED) {
+        this.isReconnecting = false;
         logger.info({ logCode: 'audio_ended' }, 'Audio ended without issue');
         this.onAudioExit();
       } else if (status === FAILED) {
+        this.isReconnecting = false;
         const errorKey = this.messages.error[error] || this.messages.error.GENERIC_ERROR;
         const errorMsg = this.intl.formatMessage(errorKey, { 0: bridgeError });
         this.error = !!error;
@@ -415,10 +419,12 @@ class AudioManager {
           this.onAudioExit();
         }
       } else if (status === RECONNECTING) {
+        this.isReconnecting = true;
         logger.info({ logCode: 'audio_reconnecting' }, 'Attempting to reconnect audio');
         this.notify(this.intl.formatMessage(this.messages.info.RECONNECTING_AUDIO), true);
         this.playHangUpSound();
       } else if (status === AUTOPLAY_BLOCKED) {
+        this.isReconnecting = false;
         this.autoplayBlocked = true;
         this.onAudioJoin();
         resolve(AUTOPLAY_BLOCKED);
-- 
GitLab