2019-06-03 22:28:05 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-09-26 04:28:36 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2018-06-19 23:38:09 +08:00
|
|
|
import cx from 'classnames';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-09-20 01:47:57 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
2018-11-01 23:03:16 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2018-11-01 02:51:56 +08:00
|
|
|
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
|
2020-06-16 21:41:51 +08:00
|
|
|
import MutedAlert from '/imports/ui/components/muted-alert/component';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles';
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2017-12-11 21:47:50 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
joinAudio: {
|
|
|
|
id: 'app.audio.joinAudio',
|
|
|
|
description: 'Join audio button label',
|
|
|
|
},
|
|
|
|
leaveAudio: {
|
|
|
|
id: 'app.audio.leaveAudio',
|
|
|
|
description: 'Leave audio button label',
|
|
|
|
},
|
|
|
|
muteAudio: {
|
|
|
|
id: 'app.actionsBar.muteLabel',
|
|
|
|
description: 'Mute audio button label',
|
|
|
|
},
|
|
|
|
unmuteAudio: {
|
|
|
|
id: 'app.actionsBar.unmuteLabel',
|
|
|
|
description: 'Unmute audio button label',
|
|
|
|
},
|
|
|
|
});
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2017-09-26 04:28:36 +08:00
|
|
|
const propTypes = {
|
2018-11-14 01:14:30 +08:00
|
|
|
processToggleMuteFromOutside: PropTypes.func.isRequired,
|
2017-09-26 04:28:36 +08:00
|
|
|
handleToggleMuteMicrophone: PropTypes.func.isRequired,
|
|
|
|
handleJoinAudio: PropTypes.func.isRequired,
|
|
|
|
handleLeaveAudio: PropTypes.func.isRequired,
|
2017-10-23 20:41:09 +08:00
|
|
|
disable: PropTypes.bool.isRequired,
|
2019-03-22 06:16:56 +08:00
|
|
|
muted: PropTypes.bool.isRequired,
|
|
|
|
showMute: PropTypes.bool.isRequired,
|
|
|
|
inAudio: PropTypes.bool.isRequired,
|
|
|
|
listenOnly: PropTypes.bool.isRequired,
|
2020-05-26 04:00:13 +08:00
|
|
|
intl: PropTypes.object.isRequired,
|
2019-03-22 06:16:56 +08:00
|
|
|
talking: PropTypes.bool.isRequired,
|
2017-09-26 04:28:36 +08:00
|
|
|
};
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2019-06-03 22:28:05 +08:00
|
|
|
class AudioControls extends PureComponent {
|
2018-11-01 23:03:16 +08:00
|
|
|
componentDidMount() {
|
2018-11-14 01:14:30 +08:00
|
|
|
const { processToggleMuteFromOutside } = this.props;
|
2019-03-20 01:11:48 +08:00
|
|
|
if (Meteor.settings.public.allowOutsideCommands.toggleSelfVoice
|
2019-07-22 22:28:13 +08:00
|
|
|
|| getFromUserSettings('bbb_outside_toggle_self_voice', false)) {
|
2018-11-14 01:14:30 +08:00
|
|
|
window.addEventListener('message', processToggleMuteFromOutside);
|
2018-11-01 23:03:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
handleToggleMuteMicrophone,
|
|
|
|
handleJoinAudio,
|
|
|
|
handleLeaveAudio,
|
2019-03-22 06:16:56 +08:00
|
|
|
showMute,
|
|
|
|
muted,
|
2018-11-01 23:03:16 +08:00
|
|
|
disable,
|
2019-03-22 06:16:56 +08:00
|
|
|
talking,
|
|
|
|
inAudio,
|
|
|
|
listenOnly,
|
2018-11-01 23:03:16 +08:00
|
|
|
intl,
|
2018-11-09 03:34:57 +08:00
|
|
|
shortcuts,
|
2019-08-22 20:05:06 +08:00
|
|
|
isVoiceUser,
|
2020-06-16 23:03:45 +08:00
|
|
|
inputStream,
|
2020-06-23 21:38:59 +08:00
|
|
|
isViewer,
|
|
|
|
isPresenter,
|
2018-11-01 23:03:16 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-03-22 06:16:56 +08:00
|
|
|
let joinIcon = 'audio_off';
|
|
|
|
if (inAudio) {
|
|
|
|
if (listenOnly) {
|
|
|
|
joinIcon = 'listen';
|
|
|
|
} else {
|
|
|
|
joinIcon = 'audio_on';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:41:51 +08:00
|
|
|
const label = muted ? intl.formatMessage(intlMessages.unmuteAudio)
|
|
|
|
: intl.formatMessage(intlMessages.muteAudio);
|
|
|
|
|
|
|
|
const toggleMuteBtn = (
|
|
|
|
<Button
|
|
|
|
className={cx(styles.muteToggle, !talking || styles.glow, !muted || styles.btn)}
|
|
|
|
onClick={handleToggleMuteMicrophone}
|
|
|
|
disabled={disable}
|
|
|
|
hideLabel
|
|
|
|
label={label}
|
|
|
|
aria-label={label}
|
|
|
|
color={!muted ? 'primary' : 'default'}
|
|
|
|
ghost={muted}
|
|
|
|
icon={muted ? 'mute' : 'unmute'}
|
|
|
|
size="lg"
|
|
|
|
circle
|
|
|
|
accessKey={shortcuts.togglemute}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-10-27 05:07:15 +08:00
|
|
|
const MUTE_ALERT_CONFIG = Meteor.settings.public.app.mutedAlert;
|
|
|
|
const { enabled: muteAlertEnabled } = MUTE_ALERT_CONFIG;
|
2021-01-31 01:04:07 +08:00
|
|
|
|
2018-11-01 23:03:16 +08:00
|
|
|
return (
|
|
|
|
<span className={styles.container}>
|
2021-01-31 01:04:07 +08:00
|
|
|
{inputStream && muteAlertEnabled ? (
|
|
|
|
<MutedAlert {...{
|
|
|
|
muted, inputStream, isViewer, isPresenter,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-06-16 21:41:51 +08:00
|
|
|
{showMute && isVoiceUser ? toggleMuteBtn : null}
|
2018-11-01 23:03:16 +08:00
|
|
|
<Button
|
2020-06-16 21:41:51 +08:00
|
|
|
className={cx(inAudio || styles.btn)}
|
2019-03-22 06:16:56 +08:00
|
|
|
onClick={inAudio ? handleLeaveAudio : handleJoinAudio}
|
2018-11-01 23:03:16 +08:00
|
|
|
disabled={disable}
|
2021-02-17 04:57:10 +08:00
|
|
|
data-test={inAudio ? 'leaveAudio' : 'joinAudio'}
|
2018-11-01 23:03:16 +08:00
|
|
|
hideLabel
|
2019-03-22 06:16:56 +08:00
|
|
|
aria-label={inAudio ? intl.formatMessage(intlMessages.leaveAudio)
|
2019-03-20 01:11:48 +08:00
|
|
|
: intl.formatMessage(intlMessages.joinAudio)}
|
2019-03-22 06:16:56 +08:00
|
|
|
label={inAudio ? intl.formatMessage(intlMessages.leaveAudio)
|
2019-03-20 01:11:48 +08:00
|
|
|
: intl.formatMessage(intlMessages.joinAudio)}
|
2019-03-22 06:16:56 +08:00
|
|
|
color={inAudio ? 'primary' : 'default'}
|
|
|
|
ghost={!inAudio}
|
|
|
|
icon={joinIcon}
|
2018-11-01 23:03:16 +08:00
|
|
|
size="lg"
|
|
|
|
circle
|
2020-05-22 02:43:34 +08:00
|
|
|
accessKey={inAudio ? shortcuts.leaveaudio : shortcuts.joinaudio}
|
2018-11-01 23:03:16 +08:00
|
|
|
/>
|
2020-06-16 21:41:51 +08:00
|
|
|
</span>
|
|
|
|
);
|
2018-11-01 23:03:16 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 04:28:36 +08:00
|
|
|
|
|
|
|
AudioControls.propTypes = propTypes;
|
|
|
|
|
2018-11-01 02:51:56 +08:00
|
|
|
export default withShortcutHelper(injectIntl(AudioControls), ['joinAudio', 'leaveAudio', 'toggleMute']);
|