2020-03-30 17:17:18 +03:00
|
|
|
import React, { Component } from 'react';
|
2023-03-30 11:27:53 +03:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2023-03-21 09:47:52 +02:00
|
|
|
import { connect } from 'react-redux';
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2023-03-30 11:27:53 +03:00
|
|
|
import { IReduxState } from '../../../app/types';
|
2020-06-29 16:59:28 -04:00
|
|
|
import { isMobileBrowser } from '../../../base/environment/utils';
|
2023-03-30 11:27:53 +03:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
|
|
|
|
import { IconArrowUp } from '../../../base/icons/svg';
|
2020-03-30 17:17:18 +03:00
|
|
|
import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
|
2023-05-18 14:16:37 -05:00
|
|
|
import { IGUMPendingState } from '../../../base/media/types';
|
2023-03-30 11:27:53 +03:00
|
|
|
import ToolboxButtonWithIcon from '../../../base/toolbox/components/web/ToolboxButtonWithIcon';
|
2024-08-06 10:51:18 +03:00
|
|
|
import { toggleAudioSettings } from '../../../settings/actions.web';
|
2023-03-30 11:27:53 +03:00
|
|
|
import AudioSettingsPopup from '../../../settings/components/web/audio/AudioSettingsPopup';
|
2024-08-06 10:51:18 +03:00
|
|
|
import { getAudioSettingsVisibility } from '../../../settings/functions.web';
|
|
|
|
|
import { isAudioSettingsButtonDisabled } from '../../functions.web';
|
2023-06-09 15:02:00 -05:00
|
|
|
|
|
|
|
|
import AudioMuteButton from './AudioMuteButton';
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2023-03-30 11:27:53 +03:00
|
|
|
interface IProps extends WithTranslation {
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2022-01-04 13:21:00 +02:00
|
|
|
/**
|
|
|
|
|
* The button's key.
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
buttonKey?: string;
|
2022-01-04 13:21:00 +02:00
|
|
|
|
2023-05-18 14:16:37 -05:00
|
|
|
/**
|
|
|
|
|
* The gumPending state from redux.
|
|
|
|
|
*/
|
|
|
|
|
gumPending: IGUMPendingState;
|
|
|
|
|
|
2021-09-14 10:07:20 +03:00
|
|
|
/**
|
|
|
|
|
* External handler for click action.
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
handleClick: Function;
|
2021-09-14 10:07:20 +03:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
2021-02-01 18:20:39 -06:00
|
|
|
* Indicates whether audio permissions have been granted or denied.
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
hasPermissions: boolean;
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2020-04-07 10:14:23 +03:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* If the button should be disabled.
|
2020-04-07 10:14:23 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
isDisabled: boolean;
|
2020-04-07 10:14:23 +03:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Defines is popup is open.
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
isOpen: boolean;
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2022-01-04 13:21:00 +02:00
|
|
|
/**
|
|
|
|
|
* Notify mode for `toolbarButtonClicked` event -
|
|
|
|
|
* whether to only notify or to also prevent button click routine.
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
notifyMode?: string;
|
2022-01-04 13:21:00 +02:00
|
|
|
|
2021-02-23 13:09:22 +02:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Click handler for the small icon. Opens audio options.
|
2021-02-23 13:09:22 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
onAudioOptionsClick: Function;
|
2021-02-23 13:09:22 +02:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
|
|
|
|
* Flag controlling the visibility of the button.
|
2020-06-29 16:59:28 -04:00
|
|
|
* AudioSettings popup is disabled on mobile browsers.
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
visible: boolean;
|
|
|
|
|
}
|
2020-03-30 17:17:18 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Button used for audio & audio settings.
|
|
|
|
|
*
|
|
|
|
|
* @returns {ReactElement}
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
class AudioSettingsButton extends Component<IProps> {
|
2021-06-10 14:48:44 +02:00
|
|
|
/**
|
|
|
|
|
* Initializes a new {@code AudioSettingsButton} instance.
|
|
|
|
|
*
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
constructor(props: IProps) {
|
2021-06-10 14:48:44 +02:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this._onEscClick = this._onEscClick.bind(this);
|
2021-09-14 10:07:20 +03:00
|
|
|
this._onClick = this._onClick.bind(this);
|
2021-06-10 14:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Click handler for the more actions entries.
|
|
|
|
|
*
|
|
|
|
|
* @param {KeyboardEvent} event - Esc key click to close the popup.
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
_onEscClick(event: React.KeyboardEvent) {
|
2021-06-10 14:48:44 +02:00
|
|
|
if (event.key === 'Escape' && this.props.isOpen) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2021-09-14 10:07:20 +03:00
|
|
|
this._onClick();
|
2021-06-10 14:48:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-16 13:47:10 +03:00
|
|
|
|
2021-09-14 10:07:20 +03:00
|
|
|
/**
|
|
|
|
|
* Click handler for the more actions entries.
|
|
|
|
|
*
|
2023-04-07 12:26:56 +03:00
|
|
|
* @param {MouseEvent} e - Mouse event.
|
2021-09-14 10:07:20 +03:00
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2023-04-07 12:26:56 +03:00
|
|
|
_onClick(e?: React.MouseEvent) {
|
2023-04-10 12:52:22 +03:00
|
|
|
const { onAudioOptionsClick, isOpen } = this.props;
|
2021-09-14 10:07:20 +03:00
|
|
|
|
2023-04-10 12:52:22 +03:00
|
|
|
if (isOpen) {
|
|
|
|
|
e?.stopPropagation();
|
|
|
|
|
}
|
2021-09-14 10:07:20 +03:00
|
|
|
onAudioOptionsClick();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
|
|
|
|
* Implements React's {@link Component#render}.
|
|
|
|
|
*
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2025-03-12 10:19:11 -05:00
|
|
|
override render() {
|
2023-05-18 14:16:37 -05:00
|
|
|
const { gumPending, hasPermissions, isDisabled, visible, isOpen, buttonKey, notifyMode, t } = this.props;
|
2021-02-01 18:20:39 -06:00
|
|
|
const settingsDisabled = !hasPermissions
|
2020-06-04 13:43:32 -04:00
|
|
|
|| isDisabled
|
|
|
|
|
|| !JitsiMeetJS.mediaDevices.isMultipleAudioInputSupported();
|
2020-03-30 17:17:18 +03:00
|
|
|
|
|
|
|
|
return visible ? (
|
|
|
|
|
<AudioSettingsPopup>
|
|
|
|
|
<ToolboxButtonWithIcon
|
2021-06-10 14:48:44 +02:00
|
|
|
ariaControls = 'audio-settings-dialog'
|
|
|
|
|
ariaExpanded = { isOpen }
|
|
|
|
|
ariaHasPopup = { true }
|
|
|
|
|
ariaLabel = { t('toolbar.audioSettings') }
|
2022-01-04 13:21:00 +02:00
|
|
|
buttonKey = { buttonKey }
|
2021-03-11 11:25:49 +02:00
|
|
|
icon = { IconArrowUp }
|
2023-05-18 14:16:37 -05:00
|
|
|
iconDisabled = { settingsDisabled || gumPending !== IGUMPendingState.NONE }
|
2021-06-10 14:48:44 +02:00
|
|
|
iconId = 'audio-settings-button'
|
2021-02-23 13:09:22 +02:00
|
|
|
iconTooltip = { t('toolbar.audioSettings') }
|
2022-01-04 13:21:00 +02:00
|
|
|
notifyMode = { notifyMode }
|
2021-09-14 10:07:20 +03:00
|
|
|
onIconClick = { this._onClick }
|
2021-06-10 14:48:44 +02:00
|
|
|
onIconKeyDown = { this._onEscClick }>
|
2022-01-04 13:21:00 +02:00
|
|
|
<AudioMuteButton
|
|
|
|
|
buttonKey = { buttonKey }
|
|
|
|
|
notifyMode = { notifyMode } />
|
2020-03-30 17:17:18 +03:00
|
|
|
</ToolboxButtonWithIcon>
|
|
|
|
|
</AudioSettingsPopup>
|
2022-01-04 13:21:00 +02:00
|
|
|
) : <AudioMuteButton
|
|
|
|
|
buttonKey = { buttonKey }
|
|
|
|
|
notifyMode = { notifyMode } />;
|
2020-03-30 17:17:18 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
function mapStateToProps(state: IReduxState) {
|
|
|
|
|
const { permissions = { audio: false } } = state['features/base/devices'];
|
2023-01-25 17:02:26 +02:00
|
|
|
const { isNarrowLayout } = state['features/base/responsive-ui'];
|
2023-05-18 14:16:37 -05:00
|
|
|
const { gumPending } = state['features/base/media'].audio;
|
2021-02-01 18:20:39 -06:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
return {
|
2023-05-18 14:16:37 -05:00
|
|
|
gumPending,
|
2021-02-01 18:20:39 -06:00
|
|
|
hasPermissions: permissions.audio,
|
2023-03-30 11:27:53 +03:00
|
|
|
isDisabled: Boolean(isAudioSettingsButtonDisabled(state)),
|
|
|
|
|
isOpen: Boolean(getAudioSettingsVisibility(state)),
|
2023-01-25 17:02:26 +02:00
|
|
|
visible: !isMobileBrowser() && !isNarrowLayout
|
2020-03-30 17:17:18 +03:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
|
onAudioOptionsClick: toggleAudioSettings
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-23 13:09:22 +02:00
|
|
|
export default translate(connect(
|
2020-03-30 17:17:18 +03:00
|
|
|
mapStateToProps,
|
2021-11-04 22:10:43 +01:00
|
|
|
mapDispatchToProps
|
2021-02-23 13:09:22 +02:00
|
|
|
)(AudioSettingsButton));
|