2017-09-26 04:28:36 +08:00
|
|
|
import React from 'react';
|
|
|
|
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-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 = {
|
|
|
|
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-05-01 05:09:56 +08:00
|
|
|
const SHORTCUTS_CONFIG = Meteor.settings.public.app.shortcuts;
|
2018-05-02 08:02:45 +08:00
|
|
|
const JOIN_AUDIO_AK = SHORTCUTS_CONFIG.joinAudio.accesskey;
|
|
|
|
const LEAVE_AUDIO_AK = SHORTCUTS_CONFIG.leaveAudio.accesskey;
|
|
|
|
const MUTE_UNMUTE_AK = SHORTCUTS_CONFIG.toggleMute.accesskey;
|
2018-05-01 05:09:56 +08:00
|
|
|
|
2017-09-26 04:28:36 +08:00
|
|
|
const AudioControls = ({
|
2017-09-20 01:47:57 +08:00
|
|
|
handleToggleMuteMicrophone,
|
|
|
|
handleJoinAudio,
|
|
|
|
handleLeaveAudio,
|
|
|
|
mute,
|
|
|
|
unmute,
|
2017-10-20 18:11:51 +08:00
|
|
|
disable,
|
2017-11-17 19:52:48 +08:00
|
|
|
glow,
|
2017-09-20 01:47:57 +08:00
|
|
|
join,
|
2017-12-11 21:47:50 +08:00
|
|
|
intl,
|
2017-09-26 04:28:36 +08:00
|
|
|
}) => (
|
2017-09-20 01:47:57 +08:00
|
|
|
<span className={styles.container}>
|
|
|
|
{mute ?
|
|
|
|
<Button
|
2017-11-17 19:52:48 +08:00
|
|
|
className={glow ? cx(styles.button, styles.glow) : styles.button}
|
2017-09-20 01:47:57 +08:00
|
|
|
onClick={handleToggleMuteMicrophone}
|
2017-10-23 20:41:09 +08:00
|
|
|
disabled={disable}
|
2017-12-11 21:47:50 +08:00
|
|
|
hideLabel
|
|
|
|
label={unmute ? intl.formatMessage(intlMessages.unmuteAudio) : intl.formatMessage(intlMessages.muteAudio)}
|
|
|
|
aria-label={unmute ? intl.formatMessage(intlMessages.unmuteAudio) : intl.formatMessage(intlMessages.muteAudio)}
|
2017-12-14 03:03:14 +08:00
|
|
|
color="primary"
|
2017-09-20 01:47:57 +08:00
|
|
|
icon={unmute ? 'mute' : 'unmute'}
|
2017-12-14 03:03:14 +08:00
|
|
|
size="lg"
|
2017-09-20 01:47:57 +08:00
|
|
|
circle
|
2018-05-02 08:02:45 +08:00
|
|
|
accessKey={MUTE_UNMUTE_AK}
|
2017-09-20 01:47:57 +08:00
|
|
|
/> : null}
|
|
|
|
<Button
|
2017-10-12 22:49:50 +08:00
|
|
|
className={styles.button}
|
2017-09-26 04:28:36 +08:00
|
|
|
onClick={join ? handleLeaveAudio : handleJoinAudio}
|
2017-10-23 20:41:09 +08:00
|
|
|
disabled={disable}
|
2017-12-11 21:47:50 +08:00
|
|
|
hideLabel
|
|
|
|
aria-label={join ? intl.formatMessage(intlMessages.leaveAudio) : intl.formatMessage(intlMessages.joinAudio)}
|
|
|
|
label={join ? intl.formatMessage(intlMessages.leaveAudio) : intl.formatMessage(intlMessages.joinAudio)}
|
2017-09-26 04:28:36 +08:00
|
|
|
color={join ? 'danger' : 'primary'}
|
|
|
|
icon={join ? 'audio_off' : 'audio_on'}
|
2017-12-14 03:03:14 +08:00
|
|
|
size="lg"
|
2017-09-20 01:47:57 +08:00
|
|
|
circle
|
2018-05-02 08:02:45 +08:00
|
|
|
accessKey={join ? LEAVE_AUDIO_AK : JOIN_AUDIO_AK}
|
2017-09-20 01:47:57 +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
|
|
|
|
2017-12-11 21:47:50 +08:00
|
|
|
export default injectIntl(AudioControls);
|