bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/audio/audio-modal/service.js
Mario Jr bf17b385b6 fix: breakout autojoin audio with wrong behavior
When joining/returning breakouts, audio would always connect
with full audio. This can lead to a performance problem, once
all listenonly users would join full audio, increasing the
number of streams in FreeSWITCH.

We now have a consistent behavior, which is:
1 - The choice made by the user in the main room is predominant:
    if mic is active in main room, user will automatically
    join mic in breakout room. When returning from breakout
    room, user will also join with mic again.
2 - Changes made in breakout room won't have effect when
    returning to the main room. This means if user, for example,
    change from listenonly to mic in breakout room, the returning
    will consider the option choosen previously (listenonly) and
    listenonly will be active again in the main room.
3 - If user didn't join audio in the main room, the audio modal
    will be prompted when joining the breakout room (this is
    a special case of (1))


The following is some technicall information:
InputStreamLiveSelector (component.jsx) now calls
'handleLeaveAudio' function, which is the default
function when user leaves audio (also used when
dynamic devices are inactive).

We now store information about user's choice (mic or listenonly)
using local storage, instead of the previous cookie method (this
was triggering some warnings in browser's console).

Also did a small refactoring to match eslint rules.
Fixes #11662.
2021-04-20 14:38:11 -03:00

84 lines
2.3 KiB
JavaScript

import { showModal } from '/imports/ui/components/modal/service';
import Service from '../service';
import Storage from '/imports/ui/services/storage/session';
const CLIENT_DID_USER_SELECTED_MICROPHONE_KEY = 'clientUserSelectedMicrophone';
const CLIENT_DID_USER_SELECTED_LISTEN_ONLY_KEY = 'clientUserSelectedListenOnly';
export const setUserSelectedMicrophone = (value) => (
Storage.setItem(CLIENT_DID_USER_SELECTED_MICROPHONE_KEY, !!value)
);
export const setUserSelectedListenOnly = (value) => (
Storage.setItem(CLIENT_DID_USER_SELECTED_LISTEN_ONLY_KEY, !!value)
);
export const didUserSelectedMicrophone = () => (
!!Storage.getItem(CLIENT_DID_USER_SELECTED_MICROPHONE_KEY)
);
export const didUserSelectedListenOnly = () => (
!!Storage.getItem(CLIENT_DID_USER_SELECTED_LISTEN_ONLY_KEY)
);
export const joinMicrophone = (skipEchoTest = false) => {
Storage.setItem(CLIENT_DID_USER_SELECTED_MICROPHONE_KEY, true);
Storage.setItem(CLIENT_DID_USER_SELECTED_LISTEN_ONLY_KEY, false);
const call = new Promise((resolve, reject) => {
if (skipEchoTest) {
resolve(Service.joinMicrophone());
} else {
resolve(Service.transferCall());
}
reject(Service.exitAudio);
});
return call.then(() => {
showModal(null);
}).catch((error) => {
throw error;
});
};
export const joinListenOnly = () => {
Storage.setItem(CLIENT_DID_USER_SELECTED_MICROPHONE_KEY, false);
Storage.setItem(CLIENT_DID_USER_SELECTED_LISTEN_ONLY_KEY, true);
const call = new Promise((resolve) => {
Service.joinListenOnly().then(() => {
// Autoplay block wasn't triggered. Close the modal. If autoplay was
// blocked, that'll be handled in the modal component when then
// prop transitions to a state where it was handled OR the user opts
// to close the modal.
if (!Service.autoplayBlocked()) {
showModal(null);
}
resolve();
});
});
return call.catch((error) => {
throw error;
});
};
export const leaveEchoTest = () => {
if (!Service.isEchoTest()) {
return Promise.resolve();
}
return Service.exitAudio();
};
export const closeModal = () => {
if (!Service.isConnecting()) showModal(null);
};
export default {
joinMicrophone,
closeModal,
joinListenOnly,
leaveEchoTest,
didUserSelectedMicrophone,
didUserSelectedListenOnly,
};