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

180 lines
4.6 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl } from 'react-intl';
2021-04-01 01:13:36 +08:00
import deviceInfo from '/imports/utils/deviceInfo';
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
2020-07-28 03:49:26 +08:00
import InputStreamLiveSelectorContainer from './input-stream-live-selector/container';
import MutedAlert from '/imports/ui/components/muted-alert/component';
2021-11-09 20:45:31 +08:00
import Styled from './styles';
2022-06-17 03:59:01 +08:00
import Button from '/imports/ui/components/common/button/component';
import AudioModalContainer from '../audio-modal/container';
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',
},
});
const propTypes = {
shortcuts: PropTypes.objectOf(PropTypes.string).isRequired,
handleToggleMuteMicrophone: PropTypes.func.isRequired,
handleLeaveAudio: PropTypes.func.isRequired,
2017-10-23 20:41:09 +08:00
disable: PropTypes.bool.isRequired,
muted: PropTypes.bool.isRequired,
showMute: PropTypes.bool.isRequired,
inAudio: PropTypes.bool.isRequired,
listenOnly: PropTypes.bool.isRequired,
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
talking: PropTypes.bool.isRequired,
};
class AudioControls extends PureComponent {
2020-07-28 03:49:26 +08:00
constructor(props) {
super(props);
this.state = {
isAudioModalOpen: false,
};
this.renderButtonsAndStreamSelector = this.renderButtonsAndStreamSelector.bind(this);
this.renderJoinLeaveButton = this.renderJoinLeaveButton.bind(this);
this.setAudioModalIsOpen = this.setAudioModalIsOpen.bind(this);
2020-07-28 03:49:26 +08:00
}
renderJoinButton() {
const {
disable,
intl,
shortcuts,
joinListenOnly,
isConnected
} = this.props;
return (
2022-06-17 03:59:01 +08:00
<Button
onClick={() => this.handleJoinAudio(joinListenOnly, isConnected)}
disabled={disable}
hideLabel
aria-label={intl.formatMessage(intlMessages.joinAudio)}
label={intl.formatMessage(intlMessages.joinAudio)}
data-test="joinAudio"
color="default"
ghost
icon="no_audio"
size="lg"
circle
accessKey={shortcuts.joinaudio}
/>
);
}
renderButtonsAndStreamSelector(_enableDynamicDeviceSelection) {
const {
handleLeaveAudio, handleToggleMuteMicrophone, muted, disable, talking,
} = this.props;
2022-10-25 01:20:49 +08:00
const { isMobile } = deviceInfo;
return (
<InputStreamLiveSelectorContainer {...{
handleLeaveAudio,
handleToggleMuteMicrophone,
muted,
disable,
talking,
2022-10-25 01:20:49 +08:00
isMobile,
_enableDynamicDeviceSelection,
}}
/>
);
}
renderJoinLeaveButton() {
const {
inAudio,
} = this.props;
let { enableDynamicAudioDeviceSelection } = Meteor.settings.public.app;
if (typeof enableDynamicAudioDeviceSelection === 'undefined') {
enableDynamicAudioDeviceSelection = true;
}
if (inAudio) {
return this.renderButtonsAndStreamSelector(enableDynamicAudioDeviceSelection);
}
return this.renderJoinButton();
}
handleJoinAudio(joinListenOnly, isConnected) {
(isConnected()
? joinListenOnly()
: this.setAudioModalIsOpen(true)
)}
setAudioModalIsOpen(value) {
this.setState({ isAudioModalOpen: value })
}
render() {
const {
showMute,
muted,
isVoiceUser,
listenOnly,
inputStream,
isViewer,
isPresenter,
} = this.props;
const { isAudioModalOpen } = this.state;
const MUTE_ALERT_CONFIG = Meteor.settings.public.app.mutedAlert;
const { enabled: muteAlertEnabled } = MUTE_ALERT_CONFIG;
return (
2021-11-09 20:45:31 +08:00
<Styled.Container>
{isVoiceUser && inputStream && muteAlertEnabled && !listenOnly && muted && showMute ? (
<MutedAlert {...{
muted, inputStream, isViewer, isPresenter,
}}
/>
) : null}
2020-07-28 03:49:26 +08:00
{
this.renderJoinLeaveButton()
2020-07-28 03:49:26 +08:00
}
{
isAudioModalOpen ? <AudioModalContainer
{...{
priority: "low",
setIsOpen: this.setAudioModalIsOpen,
isOpen: isAudioModalOpen
}}
/> : null
}
2021-11-09 20:45:31 +08:00
</Styled.Container>
);
}
}
AudioControls.propTypes = propTypes;
export default withShortcutHelper(injectIntl(AudioControls), ['joinAudio',
'leaveAudio', 'toggleMute']);