2018-11-01 23:03:16 +08:00
|
|
|
import React, { Component } 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';
|
2017-12-11 21:47:50 +08:00
|
|
|
import { defineMessages, intlShape, 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';
|
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,
|
2018-06-19 23:38:09 +08:00
|
|
|
unmute: PropTypes.bool,
|
2017-09-26 04:28:36 +08:00
|
|
|
mute: PropTypes.bool.isRequired,
|
|
|
|
join: PropTypes.bool.isRequired,
|
2017-12-11 21:47:50 +08:00
|
|
|
intl: intlShape.isRequired,
|
2017-12-14 03:03:14 +08:00
|
|
|
glow: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
2017-12-14 03:19:26 +08:00
|
|
|
glow: false,
|
2018-06-19 23:38:09 +08:00
|
|
|
unmute: false,
|
2017-09-26 04:28:36 +08:00
|
|
|
};
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2018-11-01 23:03:16 +08:00
|
|
|
class AudioControls extends Component {
|
|
|
|
componentDidMount() {
|
2018-11-14 01:14:30 +08:00
|
|
|
const { processToggleMuteFromOutside } = this.props;
|
2018-11-01 23:03:16 +08:00
|
|
|
if (Meteor.settings.public.allowOutsideCommands.toggleSelfVoice ||
|
|
|
|
getFromUserSettings('outsideToggleSelfVoice', 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,
|
|
|
|
mute,
|
|
|
|
unmute,
|
|
|
|
disable,
|
|
|
|
glow,
|
|
|
|
join,
|
|
|
|
intl,
|
2018-11-09 03:34:57 +08:00
|
|
|
shortcuts,
|
2018-11-01 23:03:16 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className={styles.container}>
|
|
|
|
{mute ?
|
|
|
|
<Button
|
2018-11-28 20:59:03 +08:00
|
|
|
className={glow ? cx(styles.button, styles.glow) : cx(styles.button, !unmute || styles.ghostButton)}
|
2018-11-01 23:03:16 +08:00
|
|
|
onClick={handleToggleMuteMicrophone}
|
|
|
|
disabled={disable}
|
|
|
|
hideLabel
|
|
|
|
label={unmute ? intl.formatMessage(intlMessages.unmuteAudio) :
|
|
|
|
intl.formatMessage(intlMessages.muteAudio)}
|
|
|
|
aria-label={unmute ? intl.formatMessage(intlMessages.unmuteAudio) :
|
|
|
|
intl.formatMessage(intlMessages.muteAudio)}
|
2018-11-30 00:58:39 +08:00
|
|
|
color={!unmute ? 'primary' : 'default'}
|
2018-11-28 20:59:03 +08:00
|
|
|
ghost={unmute}
|
2018-11-01 23:03:16 +08:00
|
|
|
icon={unmute ? 'mute' : 'unmute'}
|
|
|
|
size="lg"
|
|
|
|
circle
|
2018-11-09 03:34:57 +08:00
|
|
|
accessKey={shortcuts.toggleMute}
|
2018-11-01 23:03:16 +08:00
|
|
|
/> : null}
|
|
|
|
<Button
|
2018-11-28 20:59:03 +08:00
|
|
|
className={cx(styles.button, join || styles.ghostButton)}
|
2018-11-01 23:03:16 +08:00
|
|
|
onClick={join ? handleLeaveAudio : handleJoinAudio}
|
|
|
|
disabled={disable}
|
|
|
|
hideLabel
|
|
|
|
aria-label={join ? intl.formatMessage(intlMessages.leaveAudio) :
|
|
|
|
intl.formatMessage(intlMessages.joinAudio)}
|
|
|
|
label={join ? intl.formatMessage(intlMessages.leaveAudio) :
|
|
|
|
intl.formatMessage(intlMessages.joinAudio)}
|
2018-11-30 00:58:39 +08:00
|
|
|
color={join ? 'primary' : 'default'}
|
2018-11-28 20:59:03 +08:00
|
|
|
icon={join ? 'audio_on' : 'audio_off'}
|
2018-11-01 23:03:16 +08:00
|
|
|
size="lg"
|
|
|
|
circle
|
2018-11-09 03:34:57 +08:00
|
|
|
accessKey={join ? shortcuts.leaveAudio : shortcuts.joinAudio}
|
2018-11-01 23:03:16 +08:00
|
|
|
/>
|
|
|
|
</span>);
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 04:28:36 +08:00
|
|
|
|
|
|
|
AudioControls.propTypes = propTypes;
|
2017-12-14 03:03:14 +08:00
|
|
|
AudioControls.defaultProps = defaultProps;
|
2017-09-26 04:28:36 +08:00
|
|
|
|
2018-11-01 02:51:56 +08:00
|
|
|
export default withShortcutHelper(injectIntl(AudioControls), ['joinAudio', 'leaveAudio', 'toggleMute']);
|