jiti-meet/react/features/toolbox/components/web/AudioSettingsButton.js

176 lines
4.7 KiB
JavaScript
Raw Permalink Normal View History

// @flow
import React, { Component } from 'react';
import { isMobileBrowser } from '../../../base/environment/utils';
2021-02-23 11:09:22 +00:00
import { translate } from '../../../base/i18n';
import { IconArrowUp } from '../../../base/icons';
import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
import { connect } from '../../../base/redux';
2020-07-24 12:14:33 +00:00
import { ToolboxButtonWithIcon } from '../../../base/toolbox/components';
import { AudioSettingsPopup, toggleAudioSettings } from '../../../settings';
import { getAudioSettingsVisibility } from '../../../settings/functions';
2020-05-20 10:57:03 +00:00
import { isAudioSettingsButtonDisabled } from '../../functions';
import AudioMuteButton from '../AudioMuteButton';
type Props = {
/**
* The button's key.
*/
buttonKey?: string,
/**
* External handler for click action.
*/
handleClick: Function,
/**
* Indicates whether audio permissions have been granted or denied.
*/
hasPermissions: boolean,
/**
* Click handler for the small icon. Opens audio options.
*/
onAudioOptionsClick: Function,
/**
2020-04-16 10:47:10 +00:00
* If the button should be disabled.
*/
2020-04-16 10:47:10 +00:00
isDisabled: boolean,
/**
* Notify mode for `toolbarButtonClicked` event -
* whether to only notify or to also prevent button click routine.
*/
notifyMode?: string,
2021-02-23 11:09:22 +00:00
/**
* Used for translation.
*/
t: Function,
/**
* Flag controlling the visibility of the button.
* AudioSettings popup is disabled on mobile browsers.
*/
visible: boolean,
/**
2021-11-04 21:10:43 +00:00
* Defines is popup is open.
*/
isOpen: boolean,
};
/**
* Button used for audio & audio settings.
*
* @returns {ReactElement}
*/
class AudioSettingsButton extends Component<Props> {
/**
* Initializes a new {@code AudioSettingsButton} instance.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
this._onEscClick = this._onEscClick.bind(this);
this._onClick = this._onClick.bind(this);
}
_onEscClick: (KeyboardEvent) => void;
/**
* Click handler for the more actions entries.
*
* @param {KeyboardEvent} event - Esc key click to close the popup.
* @returns {void}
*/
_onEscClick(event) {
if (event.key === 'Escape' && this.props.isOpen) {
event.preventDefault();
event.stopPropagation();
this._onClick();
}
}
2020-04-16 10:47:10 +00:00
_onClick: () => void;
/**
* Click handler for the more actions entries.
*
* @returns {void}
*/
_onClick() {
const { onAudioOptionsClick } = this.props;
onAudioOptionsClick();
}
/**
* Implements React's {@link Component#render}.
*
* @inheritdoc
*/
render() {
const { hasPermissions, isDisabled, visible, isOpen, buttonKey, notifyMode, t } = this.props;
const settingsDisabled = !hasPermissions
|| isDisabled
|| !JitsiMeetJS.mediaDevices.isMultipleAudioInputSupported();
return visible ? (
<AudioSettingsPopup>
<ToolboxButtonWithIcon
ariaControls = 'audio-settings-dialog'
ariaExpanded = { isOpen }
ariaHasPopup = { true }
ariaLabel = { t('toolbar.audioSettings') }
buttonKey = { buttonKey }
icon = { IconArrowUp }
iconDisabled = { settingsDisabled }
iconId = 'audio-settings-button'
2021-02-23 11:09:22 +00:00
iconTooltip = { t('toolbar.audioSettings') }
notifyMode = { notifyMode }
onIconClick = { this._onClick }
onIconKeyDown = { this._onEscClick }>
<AudioMuteButton
buttonKey = { buttonKey }
notifyMode = { notifyMode } />
</ToolboxButtonWithIcon>
</AudioSettingsPopup>
) : <AudioMuteButton
buttonKey = { buttonKey }
notifyMode = { notifyMode } />;
}
}
/**
* Function that maps parts of Redux state tree into component props.
*
* @param {Object} state - Redux state.
* @returns {Object}
*/
function mapStateToProps(state) {
const { permissions = {} } = state['features/base/devices'];
const { isNarrowLayout } = state['features/base/responsive-ui'];
return {
hasPermissions: permissions.audio,
2020-04-16 10:47:10 +00:00
isDisabled: isAudioSettingsButtonDisabled(state),
isOpen: getAudioSettingsVisibility(state),
visible: !isMobileBrowser() && !isNarrowLayout
};
}
const mapDispatchToProps = {
onAudioOptionsClick: toggleAudioSettings
};
2021-02-23 11:09:22 +00:00
export default translate(connect(
mapStateToProps,
2021-11-04 21:10:43 +00:00
mapDispatchToProps
2021-02-23 11:09:22 +00:00
)(AudioSettingsButton));