bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/audio/container.jsx

277 lines
8.9 KiB
React
Raw Normal View History

import React, { useEffect } from 'react';
import { useSubscription } from '@apollo/client';
import PropTypes from 'prop-types';
import Session from '/imports/ui/services/storage/in-memory';
import { injectIntl, defineMessages } from 'react-intl';
import { range } from '/imports/utils/array-utils';
import { useMeetingIsBreakout } from '/imports/ui/components/app/service';
2018-07-10 03:23:16 +08:00
import { notify } from '/imports/ui/services/notification';
import getFromUserSettings from '/imports/ui/services/users-settings';
import VideoPreviewContainer from '/imports/ui/components/video-preview/container';
2019-05-24 00:47:56 +08:00
import lockContextContainer from '/imports/ui/components/lock-viewers/context/container';
import {
joinMicrophone,
joinListenOnly,
} from '/imports/ui/components/audio/audio-modal/service';
2017-05-02 03:52:57 +08:00
import Service from './service';
2017-09-29 21:38:10 +08:00
import AudioModalContainer from './audio-modal/container';
2024-01-29 20:49:40 +08:00
import useToggleVoice from './audio-graphql/hooks/useToggleVoice';
import usePreviousValue from '/imports/ui/hooks/usePreviousValue';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import { toggleMuteMicrophone } from '/imports/ui/components/audio/audio-graphql/audio-controls/input-stream-live-selector/service';
import useSettings from '../../services/settings/hooks/useSettings';
import { SETTINGS } from '../../services/settings/enums';
import { useStorageKey } from '../../services/storage/hooks';
import { BREAKOUT_COUNT } from './queries';
2024-06-14 21:30:48 +08:00
import useMeeting from '../../core/hooks/useMeeting';
import useWhoIsUnmuted from '../../core/hooks/useWhoIsUnmuted';
import AudioService from '/imports/ui/components/audio/service';
2017-03-28 04:40:44 +08:00
const intlMessages = defineMessages({
joinedAudio: {
id: 'app.audioManager.joinedAudio',
description: 'Joined audio toast message',
},
2017-10-23 20:41:09 +08:00
joinedEcho: {
id: 'app.audioManager.joinedEcho',
description: 'Joined echo test toast message',
},
leftAudio: {
id: 'app.audioManager.leftAudio',
description: 'Left audio toast message',
},
reconnectingAudio: {
id: 'app.audioManager.reconnectingAudio',
description: 'Reconnecting audio toast message',
},
genericError: {
id: 'app.audioManager.genericError',
description: 'Generic error message',
},
connectionError: {
id: 'app.audioManager.connectionError',
description: 'Connection error message',
},
requestTimeout: {
id: 'app.audioManager.requestTimeout',
description: 'Request timeout error message',
},
invalidTarget: {
id: 'app.audioManager.invalidTarget',
description: 'Invalid target error message',
},
2017-10-27 01:14:56 +08:00
mediaError: {
id: 'app.audioManager.mediaError',
description: 'Media error message',
2017-10-27 01:14:56 +08:00
},
2018-06-27 21:56:03 +08:00
BrowserNotSupported: {
id: 'app.audioNotification.audioFailedError1003',
description: 'browser not supported error message',
2018-06-27 21:56:03 +08:00
},
2018-07-10 03:23:16 +08:00
reconectingAsListener: {
id: 'app.audioNotificaion.reconnectingAsListenOnly',
description: 'ice negotiation error message',
2018-07-10 03:23:16 +08:00
},
});
let didMountAutoJoin = false;
const webRtcError = range(1001, 1011)
.reduce((acc, value) => ({
...acc,
[value]: { id: `app.audioNotification.audioFailedError${value}` },
}), {});
const messages = {
info: {
JOINED_AUDIO: intlMessages.joinedAudio,
JOINED_ECHO: intlMessages.joinedEcho,
LEFT_AUDIO: intlMessages.leftAudio,
RECONNECTING_AUDIO: intlMessages.reconnectingAudio,
},
error: {
GENERIC_ERROR: intlMessages.genericError,
CONNECTION_ERROR: intlMessages.connectionError,
REQUEST_TIMEOUT: intlMessages.requestTimeout,
INVALID_TARGET: intlMessages.invalidTarget,
MEDIA_ERROR: intlMessages.mediaError,
WEBRTC_NOT_SUPPORTED: intlMessages.BrowserNotSupported,
...webRtcError,
},
};
const AudioContainer = (props) => {
const {
isAudioModalOpen,
setAudioModalIsOpen,
setVideoPreviewModalIsOpen,
isVideoPreviewModalOpen,
intl,
userLocks,
} = props;
const APP_CONFIG = window.meetingClientSettings.public.app;
const KURENTO_CONFIG = window.meetingClientSettings.public.kurento;
const autoJoin = getFromUserSettings('bbb_auto_join_audio', APP_CONFIG.autoJoin);
const enableVideo = getFromUserSettings('bbb_enable_video', KURENTO_CONFIG.enableVideo);
const autoShareWebcam = getFromUserSettings('bbb_auto_share_webcam', KURENTO_CONFIG.autoShareWebcam);
const { userWebcam } = userLocks;
const prevProps = usePreviousValue(props);
const toggleVoice = useToggleVoice();
const userSelectedMicrophone = !!useStorageKey('clientUserSelectedMicrophone', 'session');
const userSelectedListenOnly = !!useStorageKey('clientUserSelectedListenOnly', 'session');
const { microphoneConstraints } = useSettings(SETTINGS.APPLICATION);
const { data: breakoutCountData } = useSubscription(BREAKOUT_COUNT);
const hasBreakoutRooms = (breakoutCountData?.breakoutRoom_aggregate?.aggregate?.count ?? 0) > 0;
const meetingIsBreakout = useMeetingIsBreakout();
2024-06-14 21:30:48 +08:00
const { data: meeting } = useMeeting((m) => ({
voiceSettings: {
voiceConf: m?.voiceSettings?.voiceConf,
},
}));
2024-06-14 22:35:53 +08:00
const { data: currentUserName } = useCurrentUser((u) => u.name);
const { data: speechLocale } = useCurrentUser((u) => u.speechLocale);
const openAudioModal = () => setAudioModalIsOpen(true);
const openVideoPreviewModal = () => {
if (userWebcam) return;
setVideoPreviewModalIsOpen(true);
};
const init = async () => {
2024-06-14 21:30:48 +08:00
await Service.init(
messages,
intl,
toggleVoice,
speechLocale,
meeting?.voiceSettings?.voiceConf,
2024-06-14 22:35:53 +08:00
currentUserName,
2024-06-14 21:30:48 +08:00
);
if ((!autoJoin || didMountAutoJoin)) {
if (enableVideo && autoShareWebcam) {
openVideoPreviewModal();
}
return Promise.resolve(false);
}
Session.setItem('audioModalIsOpen', true);
if (enableVideo && autoShareWebcam) {
openAudioModal();
openVideoPreviewModal();
didMountAutoJoin = true;
} else if (!(
userSelectedMicrophone
&& userSelectedListenOnly
&& meetingIsBreakout)) {
openAudioModal();
didMountAutoJoin = true;
}
return Promise.resolve(true);
};
const { hasBreakoutRooms: hadBreakoutRooms } = prevProps || {};
const userIsReturningFromBreakoutRoom = hadBreakoutRooms && !hasBreakoutRooms;
const { data: currentUser } = useCurrentUser((u) => ({ userId: u.userId }));
const { data: unmutedUsers } = useWhoIsUnmuted();
const currentUserMuted = currentUser?.userId && !unmutedUsers[currentUser.userId];
const joinAudio = () => {
if (Service.isConnected()) return;
if (userSelectedMicrophone) {
feat(audio): rework audio join without listen only This is a rework of the audio join procedure whithout the explict listen only separation in mind. It's supposed to be used in conjunction with the transparent listen only feature so that the distinction between modes is seamless with minimal server-side impact. An abridged list of changes: - Let the user pick no input device when joining microphone while allowing them to set an input device on the fly later on - Give the user the option to join audio with no input device whenever we fail to obtain input devices, with the option to try re-enabling them on the fly later on - Add the option to open the audio settings modal (echo test et al) via the in-call device selection chevron - Rework the SFU audio bridge and its services to support adding/removing tracks on the fly without renegotiation - Rework the SFU audio bridge and its services to support a new peer role called "passive-sendrecv". That role is used by dupled peers that have no active input source on start, but might have one later on. - Remove stale PermissionsOverlay component from the audio modal - Rework how permission errors are detected using the Permissions API - Rework the local echo test so that it uses a separate media tag rather than the remote - Add new, separate dialplans that mute/hold FreeSWITCH channels on hold based on UA strings. This is orchestrated server-side via webrtc-sfu and akka-apps. The basic difference here is that channels now join in their desired state rather than waiting for client side observers to sync the state up. It also mitigates transparent listen only performance edge cases on multiple audio channels joining at the same time. The old, decoupled listen only mode is still present in code while we validate this new approach. To test this, transparentListenOnly must be enabled and listen only mode must be disable on audio join so that the user skips straight through microphone join.
2024-06-05 19:26:27 +08:00
joinMicrophone({ skipEchoTest: true });
return;
}
if (userSelectedListenOnly) joinListenOnly();
};
useEffect(() => {
2024-06-13 23:00:30 +08:00
// Data is not loaded yet.
2024-06-13 23:01:34 +08:00
// We don't know whether the meeting is a breakout or not.
2024-06-13 23:00:30 +08:00
// So, postpone the decision.
if (meetingIsBreakout === undefined) return;
init().then(() => {
if (meetingIsBreakout && !Service.isUsingAudio()) {
joinAudio();
}
});
2024-06-13 23:00:30 +08:00
}, [meetingIsBreakout]);
useEffect(() => {
if (userIsReturningFromBreakoutRoom) {
joinAudio();
}
}, [userIsReturningFromBreakoutRoom]);
useEffect(() => {
const CONFIRMATION_ON_LEAVE = window.meetingClientSettings.public.app.askForConfirmationOnLeave;
if (CONFIRMATION_ON_LEAVE) {
window.onbeforeunload = (event) => {
if (AudioService.isUsingAudio() && !AudioService.isMuted()) {
toggleVoice(currentUser?.userId, true);
}
event.stopImmediatePropagation();
event.preventDefault();
// eslint-disable-next-line no-param-reassign
event.returnValue = '';
};
}
}, [currentUser?.userId, toggleVoice]);
if (Service.isConnected() && !Service.isListenOnly()) {
Service.updateAudioConstraints(microphoneConstraints);
if (userLocks.userMic && !currentUserMuted) {
toggleMuteMicrophone(!currentUserMuted, toggleVoice);
notify(intl.formatMessage(intlMessages.reconectingAsListener), 'info', 'volume_level_2');
}
}
return (
<>
{isAudioModalOpen ? (
<AudioModalContainer
{...{
priority: 'low',
setIsOpen: setAudioModalIsOpen,
isOpen: isAudioModalOpen,
}}
/>
) : null}
{isVideoPreviewModalOpen ? (
<VideoPreviewContainer
{...{
callbackToClose: () => {
setVideoPreviewModalIsOpen(false);
},
priority: 'low',
setIsOpen: setVideoPreviewModalIsOpen,
isOpen: isVideoPreviewModalOpen,
}}
/>
) : null}
</>
);
};
export default lockContextContainer(injectIntl(AudioContainer));
AudioContainer.propTypes = {
isAudioModalOpen: PropTypes.bool.isRequired,
setAudioModalIsOpen: PropTypes.func.isRequired,
setVideoPreviewModalIsOpen: PropTypes.func.isRequired,
isVideoPreviewModalOpen: PropTypes.bool.isRequired,
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
userLocks: PropTypes.shape({
userMic: PropTypes.bool.isRequired,
}).isRequired,
};