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

496 lines
12 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
2019-03-29 05:53:42 +08:00
import cx from 'classnames';
import Modal from '/imports/ui/components/modal/simple/component';
import Button from '/imports/ui/components/button/component';
2019-03-29 05:53:42 +08:00
import {
defineMessages, injectIntl, intlShape, FormattedMessage,
} from 'react-intl';
2018-01-08 14:17:18 +08:00
import { styles } 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';
const propTypes = {
intl: intlShape.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,
2017-10-23 20:41:09 +08:00
inputDeviceId: PropTypes.string,
outputDeviceId: PropTypes.string,
dialNumber: PropTypes.string.isRequired,
telVoice: PropTypes.string.isRequired,
showPermissionsOvelay: PropTypes.bool.isRequired,
listenOnlyMode: PropTypes.bool.isRequired,
skipCheck: PropTypes.bool.isRequired,
2018-03-06 04:00:52 +08:00
joinFullAudioImmediately: PropTypes.bool.isRequired,
joinFullAudioEchoTest: PropTypes.bool.isRequired,
forceListenOnlyAttendee: PropTypes.bool.isRequired,
2017-10-23 20:41:09 +08:00
};
const defaultProps = {
inputDeviceId: null,
outputDeviceId: null,
};
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',
},
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',
},
audioDialLabel: {
id: 'app.audioModal.audioDialLabel',
description: 'Label for the audio dial',
},
connecting: {
id: 'app.audioModal.connecting',
description: 'Message for audio connecting',
},
connectingEchoTest: {
id: 'app.audioModal.connectingEchoTest',
description: 'Message for echo test connecting',
},
});
class AudioModal extends Component {
constructor(props) {
super(props);
this.state = {
content: null,
2018-03-20 20:09:45 +08:00
hasError: false,
};
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);
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(),
},
2017-10-04 04:42:10 +08:00
};
}
componentWillMount() {
2018-03-06 04:00:52 +08:00
const {
joinFullAudioImmediately,
joinFullAudioEchoTest,
forceListenOnlyAttendee,
audioLocked,
2018-03-06 04:00:52 +08:00
} = this.props;
if (joinFullAudioImmediately) {
this.handleJoinMicrophone();
}
2018-03-06 04:00:52 +08:00
if (joinFullAudioEchoTest) {
this.handleGoToEchoTest();
}
if (forceListenOnlyAttendee || audioLocked) {
2018-03-06 04:00:52 +08:00
this.handleJoinListenOnly();
}
}
componentWillUnmount() {
const {
isEchoTest,
2019-01-18 00:33:43 +08:00
exitAudio,
} = this.props;
if (isEchoTest) {
2019-01-18 00:33:43 +08:00
exitAudio();
}
}
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,
});
}
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() {
const { joinFullAudioImmediately } = this.props;
this.setState({
hasError: false,
content: null,
});
if (joinFullAudioImmediately) return this.joinMicrophone();
return this.handleGoToEchoTest();
}
2017-10-04 04:42:10 +08:00
handleGoToEchoTest() {
2017-11-17 19:52:48 +08:00
const {
inputDeviceId,
outputDeviceId,
2019-01-18 00:33:43 +08:00
joinEchoTest,
2017-11-17 19:52:48 +08:00
} = this.props;
this.setState({
2018-03-20 20:09:45 +08:00
hasError: false,
});
2018-03-06 04:00:52 +08:00
2019-01-18 00:33:43 +08:00
return joinEchoTest().then(() => {
2017-11-17 19:52:48 +08:00
console.log(inputDeviceId, outputDeviceId);
2017-10-05 04:49:11 +08:00
this.setState({
content: 'echoTest',
});
}).catch((err) => {
2017-11-17 19:52:48 +08:00
if (err.type === 'MEDIA_ERROR') {
this.setState({
content: 'help',
});
}
});
}
handleJoinListenOnly() {
const {
joinListenOnly,
} = this.props;
return joinListenOnly().catch((err) => {
2017-11-17 19:52:48 +08:00
if (err.type === 'MEDIA_ERROR') {
this.setState({
content: 'help',
});
}
});
}
handleJoinMicrophone() {
const {
joinMicrophone,
} = this.props;
this.setState({
2018-03-20 20:09:45 +08:00
hasError: false,
});
joinMicrophone().catch(this.handleGoToAudioOptions);
}
2018-03-20 20:09:45 +08:00
skipAudioOptions() {
const {
isConnecting,
joinFullAudioImmediately,
joinFullAudioEchoTest,
forceListenOnlyAttendee,
} = this.props;
const {
content,
hasError,
} = this.state;
return (
2019-01-18 00:33:43 +08:00
isConnecting
|| forceListenOnlyAttendee
|| joinFullAudioImmediately
|| joinFullAudioEchoTest
2018-03-20 20:09:45 +08:00
) && !content && !hasError;
}
renderAudioOptions() {
const {
intl,
listenOnlyMode,
2018-03-06 04:00:52 +08:00
forceListenOnlyAttendee,
skipCheck,
2018-07-10 03:23:16 +08:00
audioLocked,
isMobileNative,
2019-03-29 05:53:42 +08:00
isIEOrEdge,
dialNumber,
} = this.props;
const showMicrophone = forceListenOnlyAttendee || audioLocked;
const showAudioDial = dialNumber !== '613-555-1212' && Number(dialNumber) !== 0;
return (
2019-03-29 05:53:42 +08:00
<div>
<span className={styles.audioOptions}>
{!showMicrophone && !isMobileNative
? (
<Button
className={styles.audioBtn}
label={intl.formatMessage(intlMessages.microphoneLabel)}
icon="unmute"
circle
size="jumbo"
disabled={audioLocked}
onClick={skipCheck ? this.handleJoinMicrophone : this.handleGoToEchoTest}
/>
)
: null}
{listenOnlyMode
? (
<Button
className={styles.audioBtn}
label={intl.formatMessage(intlMessages.listenOnlyLabel)}
icon="listen"
circle
size="jumbo"
onClick={this.handleJoinListenOnly}
/>
)
: null}
</span>
{isIEOrEdge ? (
<p className={cx(styles.text, styles.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>,
}}
2019-01-18 00:33:43 +08:00
/>
2019-03-29 05:53:42 +08:00
</p>
) : null}
{showAudioDial ? (
<Button
className={styles.audioDial}
label={intl.formatMessage(intlMessages.audioDialLabel)}
size="md"
color="primary"
onClick={() => {
this.setState({
content: 'audioDial',
});
}}
ghost
/>
) : null}
2019-03-29 05:53:42 +08:00
</div>
);
}
2017-10-05 04:49:11 +08:00
renderContent() {
const {
isEchoTest,
intl,
isIOSChrome,
2017-10-05 04:49:11 +08:00
} = this.props;
2018-03-20 20:09:45 +08:00
const { content } = this.state;
if (isIOSChrome) {
return (
<div>
<div className={styles.warning}>!</div>
<h4 className={styles.main}>{intl.formatMessage(intlMessages.iOSError)}</h4>
<div className={styles.text}>{intl.formatMessage(intlMessages.iOSErrorDescription)}</div>
2019-01-18 00:33:43 +08:00
<div className={styles.text}>
{intl.formatMessage(intlMessages.iOSErrorRecommendation)}
</div>
</div>);
}
2018-03-20 20:09:45 +08:00
if (this.skipAudioOptions()) {
2017-10-05 04:49:11 +08:00
return (
<div className={styles.connecting} role="alert">
<span>
2019-01-18 00:33:43 +08:00
{!isEchoTest
? intl.formatMessage(intlMessages.connecting)
: intl.formatMessage(intlMessages.connectingEchoTest)
}
</span>
<span className={styles.connectingAnimation} />
</div>
);
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,
2017-10-05 04:49:11 +08:00
} = this.props;
return (
<AudioSettings
handleBack={this.handleGoToAudioOptions}
handleRetry={this.handleRetryGoToEchoTest}
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}
2017-10-05 04:49:11 +08:00
/>
);
}
2017-11-17 19:52:48 +08:00
renderHelp() {
return (
<Help
handleBack={this.handleGoToAudioOptions}
/>
);
}
renderAudioDial() {
const { dialNumber, telVoice } = this.props;
return (
<AudioDial
dialNumber={dialNumber}
telVoice={telVoice}
handleBack={this.handleGoToAudioOptions}
/>
);
}
render() {
const {
intl,
2017-11-09 02:41:15 +08:00
showPermissionsOvelay,
isIOSChrome,
2019-01-18 00:33:43 +08:00
closeModal,
} = 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 /> : null}
<Modal
2017-11-09 02:41:15 +08:00
overlayClassName={styles.overlay}
className={styles.modal}
2019-01-18 00:33:43 +08:00
onRequestClose={closeModal}
hideBorder
>
2019-01-18 00:33:43 +08:00
{!this.skipAudioOptions()
? (
<header
data-test="audioModalHeader"
className={styles.header}
>
{
isIOSChrome ? null
: (
<h3 className={styles.title}>
{content
? intl.formatMessage(this.contents[content].title)
: intl.formatMessage(intlMessages.audioChoiceLabel)}
</h3>
)
}
2019-01-18 00:33:43 +08:00
</header>
)
2018-03-21 01:18:36 +08:00
: null
2017-11-09 02:41:15 +08:00
}
<div className={styles.content}>
{this.renderContent()}
2017-11-09 02:41:15 +08:00
</div>
</Modal>
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);