2020-03-30 14:17:18 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2020-06-29 20:59:28 +00:00
|
|
|
import { isMobileBrowser } from '../../../base/environment/utils';
|
2021-02-23 11:09:22 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2021-03-11 09:25:49 +00:00
|
|
|
import { IconArrowUp } from '../../../base/icons';
|
2020-03-30 14:17:18 +00:00
|
|
|
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';
|
2020-03-30 14:17:18 +00:00
|
|
|
import { AudioSettingsPopup, toggleAudioSettings } from '../../../settings';
|
2021-06-10 12:48:44 +00:00
|
|
|
import { getAudioSettingsVisibility } from '../../../settings/functions';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { isAudioSettingsButtonDisabled } from '../../functions';
|
|
|
|
import AudioMuteButton from '../AudioMuteButton';
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
2022-01-04 11:21:00 +00:00
|
|
|
/**
|
|
|
|
* The button's key.
|
|
|
|
*/
|
|
|
|
buttonKey?: string,
|
|
|
|
|
2021-09-14 07:07:20 +00:00
|
|
|
/**
|
|
|
|
* External handler for click action.
|
|
|
|
*/
|
|
|
|
handleClick: Function,
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
2021-02-02 00:20:39 +00:00
|
|
|
* Indicates whether audio permissions have been granted or denied.
|
2020-03-30 14:17:18 +00:00
|
|
|
*/
|
2021-02-02 00:20:39 +00:00
|
|
|
hasPermissions: boolean,
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2020-04-07 07:14:23 +00:00
|
|
|
/**
|
2021-02-02 00:20:39 +00:00
|
|
|
* Click handler for the small icon. Opens audio options.
|
2020-04-07 07:14:23 +00:00
|
|
|
*/
|
2021-02-02 00:20:39 +00:00
|
|
|
onAudioOptionsClick: Function,
|
2020-04-07 07:14:23 +00:00
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
2020-04-16 10:47:10 +00:00
|
|
|
* If the button should be disabled.
|
2020-03-30 14:17:18 +00:00
|
|
|
*/
|
2020-04-16 10:47:10 +00:00
|
|
|
isDisabled: boolean,
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2022-01-04 11:21:00 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
|
|
|
* Flag controlling the visibility of the button.
|
2020-06-29 20:59:28 +00:00
|
|
|
* AudioSettings popup is disabled on mobile browsers.
|
2020-03-30 14:17:18 +00:00
|
|
|
*/
|
2021-06-10 12:48:44 +00:00
|
|
|
visible: boolean,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Defines is popup is open.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
|
|
|
isOpen: boolean,
|
2020-03-30 14:17:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Button used for audio & audio settings.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
2021-02-02 00:20:39 +00:00
|
|
|
class AudioSettingsButton extends Component<Props> {
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code AudioSettingsButton} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._onEscClick = this._onEscClick.bind(this);
|
2021-09-14 07:07:20 +00:00
|
|
|
this._onClick = this._onClick.bind(this);
|
2021-06-10 12:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_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();
|
2021-09-14 07:07:20 +00:00
|
|
|
this._onClick();
|
2021-06-10 12:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-16 10:47:10 +00:00
|
|
|
|
2021-09-14 07:07:20 +00:00
|
|
|
_onClick: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler for the more actions entries.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onClick() {
|
2022-01-04 11:21:00 +00:00
|
|
|
const { onAudioOptionsClick } = this.props;
|
2021-09-14 07:07:20 +00:00
|
|
|
|
|
|
|
onAudioOptionsClick();
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
2022-01-04 11:21:00 +00:00
|
|
|
const { hasPermissions, isDisabled, visible, isOpen, buttonKey, notifyMode, t } = this.props;
|
2021-02-02 00:20:39 +00:00
|
|
|
const settingsDisabled = !hasPermissions
|
2020-06-04 17:43:32 +00:00
|
|
|
|| isDisabled
|
|
|
|
|| !JitsiMeetJS.mediaDevices.isMultipleAudioInputSupported();
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
return visible ? (
|
|
|
|
<AudioSettingsPopup>
|
|
|
|
<ToolboxButtonWithIcon
|
2021-06-10 12:48:44 +00:00
|
|
|
ariaControls = 'audio-settings-dialog'
|
|
|
|
ariaExpanded = { isOpen }
|
|
|
|
ariaHasPopup = { true }
|
|
|
|
ariaLabel = { t('toolbar.audioSettings') }
|
2022-01-04 11:21:00 +00:00
|
|
|
buttonKey = { buttonKey }
|
2021-03-11 09:25:49 +00:00
|
|
|
icon = { IconArrowUp }
|
2020-03-30 14:17:18 +00:00
|
|
|
iconDisabled = { settingsDisabled }
|
2021-06-10 12:48:44 +00:00
|
|
|
iconId = 'audio-settings-button'
|
2021-02-23 11:09:22 +00:00
|
|
|
iconTooltip = { t('toolbar.audioSettings') }
|
2022-01-04 11:21:00 +00:00
|
|
|
notifyMode = { notifyMode }
|
2021-09-14 07:07:20 +00:00
|
|
|
onIconClick = { this._onClick }
|
2021-06-10 12:48:44 +00:00
|
|
|
onIconKeyDown = { this._onEscClick }>
|
2022-01-04 11:21:00 +00:00
|
|
|
<AudioMuteButton
|
|
|
|
buttonKey = { buttonKey }
|
|
|
|
notifyMode = { notifyMode } />
|
2020-03-30 14:17:18 +00:00
|
|
|
</ToolboxButtonWithIcon>
|
|
|
|
</AudioSettingsPopup>
|
2022-01-04 11:21:00 +00:00
|
|
|
) : <AudioMuteButton
|
|
|
|
buttonKey = { buttonKey }
|
|
|
|
notifyMode = { notifyMode } />;
|
2020-03-30 14:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function mapStateToProps(state) {
|
2021-02-02 00:20:39 +00:00
|
|
|
const { permissions = {} } = state['features/base/devices'];
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
return {
|
2021-02-02 00:20:39 +00:00
|
|
|
hasPermissions: permissions.audio,
|
2020-04-16 10:47:10 +00:00
|
|
|
isDisabled: isAudioSettingsButtonDisabled(state),
|
2021-06-10 12:48:44 +00:00
|
|
|
isOpen: getAudioSettingsVisibility(state),
|
2020-06-29 20:59:28 +00:00
|
|
|
visible: !isMobileBrowser()
|
2020-03-30 14:17:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
onAudioOptionsClick: toggleAudioSettings
|
|
|
|
};
|
|
|
|
|
2021-02-23 11:09:22 +00:00
|
|
|
export default translate(connect(
|
2020-03-30 14:17:18 +00:00
|
|
|
mapStateToProps,
|
2021-11-04 21:10:43 +00:00
|
|
|
mapDispatchToProps
|
2021-02-23 11:09:22 +00:00
|
|
|
)(AudioSettingsButton));
|