bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/audio/audio-modal/component.jsx

641 lines
16 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
2019-04-19 02:48:39 +08:00
import { Session } from 'meteor/session';
2019-03-29 05:53:42 +08:00
import {
defineMessages, injectIntl, FormattedMessage,
2019-03-29 05:53:42 +08:00
} from 'react-intl';
2021-11-09 21:22:59 +08:00
import Styled from './styles';
2017-11-09 02:41:15 +08:00
import PermissionsOverlay from '../permissions-overlay/component';
import AudioSettings from '../audio-settings/component';
2017-10-04 04:42:10 +08:00
import EchoTest from '../echo-test/component';
2017-11-17 19:52:48 +08:00
import Help from '../help/component';
import AudioDial from '../audio-dial/component';
import AudioAutoplayPrompt from '../autoplay/component';
2021-11-09 21:22:59 +08:00
import Settings from '/imports/ui/services/settings';
import CaptionsSelectContainer from '/imports/ui/components/audio/captions/select/container';
const propTypes = {
2021-08-09 22:24:02 +08:00
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
closeModal: PropTypes.func.isRequired,
joinMicrophone: PropTypes.func.isRequired,
joinListenOnly: PropTypes.func.isRequired,
joinEchoTest: PropTypes.func.isRequired,
exitAudio: PropTypes.func.isRequired,
leaveEchoTest: PropTypes.func.isRequired,
changeInputDevice: PropTypes.func.isRequired,
changeOutputDevice: PropTypes.func.isRequired,
isEchoTest: PropTypes.bool.isRequired,
isConnecting: PropTypes.bool.isRequired,
isConnected: PropTypes.bool.isRequired,
isUsingAudio: PropTypes.bool.isRequired,
2017-10-23 20:41:09 +08:00
inputDeviceId: PropTypes.string,
outputDeviceId: PropTypes.string,
2019-04-16 00:39:36 +08:00
formattedDialNum: PropTypes.string.isRequired,
showPermissionsOvelay: PropTypes.bool.isRequired,
listenOnlyMode: PropTypes.bool.isRequired,
joinFullAudioImmediately: PropTypes.bool,
2018-03-06 04:00:52 +08:00
forceListenOnlyAttendee: PropTypes.bool.isRequired,
audioLocked: PropTypes.bool.isRequired,
resolve: PropTypes.func,
isMobileNative: PropTypes.bool.isRequired,
isIE: PropTypes.bool.isRequired,
formattedTelVoice: PropTypes.string.isRequired,
autoplayBlocked: PropTypes.bool.isRequired,
handleAllowAutoplay: PropTypes.func.isRequired,
changeInputStream: PropTypes.func.isRequired,
localEchoEnabled: PropTypes.bool.isRequired,
showVolumeMeter: PropTypes.bool.isRequired,
notify: PropTypes.func.isRequired,
2017-10-23 20:41:09 +08:00
};
const defaultProps = {
inputDeviceId: null,
outputDeviceId: null,
resolve: null,
joinFullAudioImmediately: false,
};
const intlMessages = defineMessages({
microphoneLabel: {
id: 'app.audioModal.microphoneLabel',
description: 'Join mic audio button label',
},
listenOnlyLabel: {
id: 'app.audioModal.listenOnlyLabel',
description: 'Join listen only audio button label',
},
listenOnlyDesc: {
id: 'app.audioModal.listenOnlyDesc',
description: 'Join listen only audio button description',
},
microphoneDesc: {
id: 'app.audioModal.microphoneDesc',
description: 'Join mic audio button description',
},
closeLabel: {
id: 'app.audioModal.closeLabel',
description: 'close audio modal button label',
},
audioChoiceLabel: {
id: 'app.audioModal.audioChoiceLabel',
description: 'Join audio modal title',
},
iOSError: {
id: 'app.audioModal.iOSBrowser',
description: 'Audio/Video Not supported warning',
},
iOSErrorDescription: {
id: 'app.audioModal.iOSErrorDescription',
description: 'Audio/Video not supported description',
},
iOSErrorRecommendation: {
id: 'app.audioModal.iOSErrorRecommendation',
description: 'Audio/Video recommended action',
},
echoTestTitle: {
id: 'app.audioModal.echoTestTitle',
description: 'Title for the echo test',
},
settingsTitle: {
id: 'app.audioModal.settingsTitle',
description: 'Title for the audio modal',
},
2017-11-17 19:52:48 +08:00
helpTitle: {
id: 'app.audioModal.helpTitle',
description: 'Title for the audio help',
},
audioDialTitle: {
id: 'app.audioModal.audioDialTitle',
description: 'Title for the audio dial',
},
connecting: {
id: 'app.audioModal.connecting',
description: 'Message for audio connecting',
},
2019-05-08 21:16:00 +08:00
ariaModalTitle: {
id: 'app.audioModal.ariaTitle',
description: 'aria label for modal title',
},
autoplayPromptTitle: {
id: 'app.audioModal.autoplayBlockedDesc',
description: 'Message for autoplay audio block',
},
});
class AudioModal extends Component {
constructor(props) {
super(props);
this.state = {
content: null,
2018-03-20 20:09:45 +08:00
hasError: false,
errCode: null,
};
2017-10-04 04:42:10 +08:00
this.handleGoToAudioOptions = this.handleGoToAudioOptions.bind(this);
2017-09-29 21:38:10 +08:00
this.handleGoToAudioSettings = this.handleGoToAudioSettings.bind(this);
this.handleRetryGoToEchoTest = this.handleRetryGoToEchoTest.bind(this);
2017-10-04 04:42:10 +08:00
this.handleGoToEchoTest = this.handleGoToEchoTest.bind(this);
this.handleJoinMicrophone = this.handleJoinMicrophone.bind(this);
this.handleJoinLocalEcho = this.handleJoinLocalEcho.bind(this);
2017-11-17 19:52:48 +08:00
this.handleJoinListenOnly = this.handleJoinListenOnly.bind(this);
2018-03-20 20:09:45 +08:00
this.skipAudioOptions = this.skipAudioOptions.bind(this);
2017-10-04 04:42:10 +08:00
this.contents = {
echoTest: {
title: intlMessages.echoTestTitle,
component: () => this.renderEchoTest(),
},
settings: {
title: intlMessages.settingsTitle,
component: () => this.renderAudioSettings(),
},
2017-11-17 19:52:48 +08:00
help: {
title: intlMessages.helpTitle,
2017-11-17 19:52:48 +08:00
component: () => this.renderHelp(),
},
audioDial: {
title: intlMessages.audioDialTitle,
component: () => this.renderAudioDial(),
},
autoplayBlocked: {
title: intlMessages.autoplayPromptTitle,
component: () => this.renderAutoplayOverlay(),
},
2017-10-04 04:42:10 +08:00
};
this.failedMediaElements = [];
}
2019-04-19 02:48:39 +08:00
componentDidMount() {
2018-03-06 04:00:52 +08:00
const {
forceListenOnlyAttendee,
joinFullAudioImmediately,
listenOnlyMode,
audioLocked,
isUsingAudio,
2018-03-06 04:00:52 +08:00
} = this.props;
if (!isUsingAudio) {
2021-06-10 20:14:51 +08:00
if (forceListenOnlyAttendee || audioLocked) return this.handleJoinListenOnly();
2021-06-10 20:14:51 +08:00
if (joinFullAudioImmediately && !listenOnlyMode) return this.handleJoinMicrophone();
if (!listenOnlyMode) return this.handleGoToEchoTest();
}
2021-08-09 22:24:02 +08:00
return false;
}
componentDidUpdate(prevProps) {
const { autoplayBlocked, closeModal } = this.props;
if (autoplayBlocked !== prevProps.autoplayBlocked) {
2021-08-09 22:24:02 +08:00
if (autoplayBlocked) {
this.setContent({ content: 'autoplayBlocked' });
2021-08-09 22:24:02 +08:00
} else {
closeModal();
}
}
}
componentWillUnmount() {
const {
isEchoTest,
2019-01-18 00:33:43 +08:00
exitAudio,
2019-05-08 03:49:32 +08:00
resolve,
} = this.props;
if (isEchoTest) {
2019-01-18 00:33:43 +08:00
exitAudio();
}
2019-05-08 03:49:32 +08:00
if (resolve) resolve();
2019-04-19 02:48:39 +08:00
Session.set('audioModalIsOpen', false);
}
2017-10-04 04:42:10 +08:00
handleGoToAudioOptions() {
this.setState({
2017-10-04 04:42:10 +08:00
content: null,
2018-03-20 20:09:45 +08:00
hasError: true,
disableActions: false,
});
}
2017-09-29 21:38:10 +08:00
handleGoToAudioSettings() {
2019-01-18 00:33:43 +08:00
const { leaveEchoTest } = this.props;
leaveEchoTest().then(() => {
2017-10-05 04:49:11 +08:00
this.setState({
content: 'settings',
});
});
2017-10-04 04:42:10 +08:00
}
handleRetryGoToEchoTest() {
this.setState({
hasError: false,
content: null,
});
return this.handleGoToEchoTest();
}
handleGoToLocalEcho() {
// Simplified echo test: this will return the AudioSettings with:
// - withEcho: true
// Echo test will be local and done in the AudioSettings view instead of the
// old E2E -> yes/no -> join view
this.setState({
content: 'settings',
});
}
2017-10-04 04:42:10 +08:00
handleGoToEchoTest() {
const { AudioError } = this.props;
const { MIC_ERROR } = AudioError;
const noSSL = !window.location.protocol.includes('https');
if (noSSL) {
return this.setState({
content: 'help',
errCode: MIC_ERROR.NO_SSL,
});
}
2017-11-17 19:52:48 +08:00
const {
2019-01-18 00:33:43 +08:00
joinEchoTest,
isConnecting,
localEchoEnabled,
2017-11-17 19:52:48 +08:00
} = this.props;
const {
disableActions,
} = this.state;
2021-08-09 22:24:02 +08:00
if (disableActions && isConnecting) return null;
if (localEchoEnabled) return this.handleGoToLocalEcho();
this.setState({
2018-03-20 20:09:45 +08:00
hasError: false,
disableActions: true,
});
2018-03-06 04:00:52 +08:00
2019-01-18 00:33:43 +08:00
return joinEchoTest().then(() => {
2017-10-05 04:49:11 +08:00
this.setState({
content: 'echoTest',
disableActions: false,
2017-10-05 04:49:11 +08:00
});
}).catch((err) => {
this.handleJoinMicrophoneError(err);
2017-11-17 19:52:48 +08:00
});
}
handleJoinListenOnly() {
const {
joinListenOnly,
isConnecting,
2017-11-17 19:52:48 +08:00
} = this.props;
const {
disableActions,
} = this.state;
2021-08-09 22:24:02 +08:00
if (disableActions && isConnecting) return null;
this.setState({
disableActions: true,
});
return joinListenOnly().then(() => {
this.setState({
disableActions: false,
});
}).catch((err) => {
2017-11-17 19:52:48 +08:00
if (err.type === 'MEDIA_ERROR') {
this.setState({
content: 'help',
});
}
});
}
handleJoinLocalEcho(inputStream) {
const { changeInputStream } = this.props;
// Reset the modal to a connecting state - this kind of sucks?
// prlanzarin Apr 04 2022
this.setState({
content: null,
});
if (inputStream) changeInputStream(inputStream);
this.handleJoinMicrophone();
}
handleJoinMicrophone() {
const {
joinMicrophone,
isConnecting,
} = this.props;
const {
disableActions,
} = this.state;
if (disableActions && isConnecting) return;
this.setState({
2018-03-20 20:09:45 +08:00
hasError: false,
disableActions: true,
});
2020-03-03 21:59:01 +08:00
joinMicrophone().then(() => {
this.setState({
disableActions: false,
});
}).catch((err) => {
this.handleJoinMicrophoneError(err);
});
}
handleJoinMicrophoneError(err) {
const { type } = err;
switch (type) {
case 'MEDIA_ERROR':
this.setState({
content: 'help',
errCode: 0,
disableActions: false,
});
break;
case 'CONNECTION_ERROR':
default:
this.setState({
errCode: 0,
disableActions: false,
});
break;
}
}
2021-08-09 22:24:02 +08:00
setContent(content) {
this.setState(content);
}
2018-03-20 20:09:45 +08:00
skipAudioOptions() {
const {
isConnecting,
} = this.props;
const {
content,
hasError,
} = this.state;
2021-02-23 02:09:14 +08:00
return isConnecting && !content && !hasError;
2018-03-20 20:09:45 +08:00
}
renderAudioOptions() {
const {
intl,
listenOnlyMode,
2018-03-06 04:00:52 +08:00
forceListenOnlyAttendee,
2021-02-23 02:09:14 +08:00
joinFullAudioImmediately,
2018-07-10 03:23:16 +08:00
audioLocked,
isMobileNative,
2019-04-17 01:04:23 +08:00
formattedDialNum,
2019-08-27 04:47:54 +08:00
isRTL,
} = this.props;
const showMicrophone = forceListenOnlyAttendee || audioLocked;
const arrow = isRTL ? '←' : '→';
2019-08-29 22:26:51 +08:00
const dialAudioLabel = `${intl.formatMessage(intlMessages.audioDialTitle)} ${arrow}`;
2019-08-27 04:47:54 +08:00
return (
2019-03-29 05:53:42 +08:00
<div>
<Styled.AudioOptions data-test="audioModalOptions">
2019-03-29 05:53:42 +08:00
{!showMicrophone && !isMobileNative
&& (
<>
2021-11-09 21:22:59 +08:00
<Styled.AudioModalButton
label={intl.formatMessage(intlMessages.microphoneLabel)}
2022-01-20 21:03:18 +08:00
data-test="microphoneBtn"
aria-describedby="mic-description"
icon="unmute"
circle
size="jumbo"
disabled={audioLocked}
onClick={
joinFullAudioImmediately
? this.handleJoinMicrophone
: this.handleGoToEchoTest
}
/>
2021-08-11 12:10:41 +08:00
<span className="sr-only" id="mic-description">
{intl.formatMessage(intlMessages.microphoneDesc)}
</span>
</>
)}
2019-03-29 05:53:42 +08:00
{listenOnlyMode
&& (
<>
2021-11-09 21:22:59 +08:00
<Styled.AudioModalButton
label={intl.formatMessage(intlMessages.listenOnlyLabel)}
2022-01-20 21:03:18 +08:00
data-test="listenOnlyBtn"
aria-describedby="listenOnly-description"
icon="listen"
circle
size="jumbo"
onClick={this.handleJoinListenOnly}
/>
2021-08-11 12:10:41 +08:00
<span className="sr-only" id="listenOnly-description">
{intl.formatMessage(intlMessages.listenOnlyDesc)}
</span>
</>
)}
2021-11-09 21:22:59 +08:00
</Styled.AudioOptions>
2019-04-17 01:04:23 +08:00
{formattedDialNum ? (
2021-11-09 21:22:59 +08:00
<Styled.AudioDial
2019-08-27 04:47:54 +08:00
label={dialAudioLabel}
size="md"
2022-08-05 01:17:45 +08:00
color="secondary"
onClick={() => {
this.setState({
content: 'audioDial',
});
}}
/>
2019-08-29 22:26:51 +08:00
) : null}
<CaptionsSelectContainer />
2019-03-29 05:53:42 +08:00
</div>
);
}
2017-10-05 04:49:11 +08:00
renderContent() {
const {
isEchoTest,
intl,
2017-10-05 04:49:11 +08:00
} = this.props;
2018-03-20 20:09:45 +08:00
const { content } = this.state;
2021-11-09 21:22:59 +08:00
const { animations } = Settings.application;
2018-03-20 20:09:45 +08:00
if (this.skipAudioOptions()) {
2017-10-05 04:49:11 +08:00
return (
2021-11-09 21:22:59 +08:00
<Styled.Connecting role="alert">
<span data-test={!isEchoTest ? 'establishingAudioLabel' : 'connectingToEchoTest'}>
{intl.formatMessage(intlMessages.connecting)}
</span>
2021-11-09 21:22:59 +08:00
<Styled.ConnectingAnimation animations={animations} />
</Styled.Connecting>
);
2017-10-05 04:49:11 +08:00
}
return content ? this.contents[content].component() : this.renderAudioOptions();
2017-10-05 04:49:11 +08:00
}
renderEchoTest() {
return (
2017-10-05 04:49:11 +08:00
<EchoTest
handleNo={this.handleGoToAudioSettings}
handleYes={this.handleJoinMicrophone}
/>
);
}
2017-10-05 04:49:11 +08:00
renderAudioSettings() {
2017-10-05 04:49:11 +08:00
const {
isConnecting,
isConnected,
isEchoTest,
inputDeviceId,
outputDeviceId,
2019-01-18 00:33:43 +08:00
joinEchoTest,
changeInputDevice,
changeOutputDevice,
localEchoEnabled,
showVolumeMeter,
notify,
2017-10-05 04:49:11 +08:00
} = this.props;
const confirmationCallback = !localEchoEnabled
? this.handleRetryGoToEchoTest
: this.handleJoinLocalEcho;
const handleGUMFailure = () => {
this.setState({
content: 'help',
errCode: 0,
disableActions: false,
});
};
2017-10-05 04:49:11 +08:00
return (
<AudioSettings
handleBack={this.handleGoToAudioOptions}
handleConfirmation={confirmationCallback}
handleGUMFailure={handleGUMFailure}
2019-01-18 00:33:43 +08:00
joinEchoTest={joinEchoTest}
changeInputDevice={changeInputDevice}
changeOutputDevice={changeOutputDevice}
2017-10-05 04:49:11 +08:00
isConnecting={isConnecting}
isConnected={isConnected}
isEchoTest={isEchoTest}
inputDeviceId={inputDeviceId}
outputDeviceId={outputDeviceId}
withVolumeMeter={showVolumeMeter}
withEcho={localEchoEnabled}
produceStreams={localEchoEnabled || showVolumeMeter}
notify={notify}
2017-10-05 04:49:11 +08:00
/>
);
}
2017-11-17 19:52:48 +08:00
renderHelp() {
const { errCode } = this.state;
2019-09-30 22:54:34 +08:00
const { AudioError } = this.props;
const audioErr = {
...AudioError,
code: errCode,
};
2017-11-17 19:52:48 +08:00
return (
<Help
handleBack={this.handleGoToAudioOptions}
2019-09-30 22:54:34 +08:00
audioErr={audioErr}
2017-11-17 19:52:48 +08:00
/>
);
}
renderAudioDial() {
2019-04-17 01:04:23 +08:00
const { formattedDialNum, formattedTelVoice } = this.props;
return (
<AudioDial
2019-04-16 00:39:36 +08:00
formattedDialNum={formattedDialNum}
2019-04-17 01:04:23 +08:00
telVoice={formattedTelVoice}
handleBack={this.handleGoToAudioOptions}
/>
);
}
renderAutoplayOverlay() {
const { handleAllowAutoplay } = this.props;
return (
<AudioAutoplayPrompt
handleAllowAutoplay={handleAllowAutoplay}
/>
);
}
render() {
const {
intl,
2017-11-09 02:41:15 +08:00
showPermissionsOvelay,
2019-01-18 00:33:43 +08:00
closeModal,
isIE,
} = this.props;
2018-03-20 20:09:45 +08:00
const { content } = this.state;
return (
2017-11-09 02:41:15 +08:00
<span>
{showPermissionsOvelay ? <PermissionsOverlay closeModal={closeModal} /> : null}
2021-11-09 21:22:59 +08:00
<Styled.AudioModal
2019-01-18 00:33:43 +08:00
onRequestClose={closeModal}
2022-01-20 21:03:18 +08:00
data-test="audioModal"
2019-05-08 21:16:00 +08:00
contentLabel={intl.formatMessage(intlMessages.ariaModalTitle)}
title={
!this.skipAudioOptions()
? (
content
? intl.formatMessage(this.contents[content].title)
: intl.formatMessage(intlMessages.audioChoiceLabel)
)
: null
}
>
{isIE ? (
2021-11-09 21:22:59 +08:00
<Styled.BrowserWarning>
<FormattedMessage
id="app.audioModal.unsupportedBrowserLabel"
description="Warning when someone joins with a browser that isnt supported"
values={{
0: <a href="https://www.google.com/chrome/">Chrome</a>,
1: <a href="https://getfirefox.com">Firefox</a>,
}}
/>
2021-11-09 21:22:59 +08:00
</Styled.BrowserWarning>
) : null}
2021-11-09 21:22:59 +08:00
<Styled.Content>
{this.renderContent()}
2021-11-09 21:22:59 +08:00
</Styled.Content>
</Styled.AudioModal>
2017-11-09 02:41:15 +08:00
</span>
);
2017-10-05 04:49:11 +08:00
}
2017-06-03 03:25:02 +08:00
}
AudioModal.propTypes = propTypes;
2017-10-23 20:41:09 +08:00
AudioModal.defaultProps = defaultProps;
export default injectIntl(AudioModal);