2020-03-30 14:17:18 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
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 { connect } from '../../../base/redux';
|
2020-07-24 12:14:33 +00:00
|
|
|
import { ToolboxButtonWithIcon } from '../../../base/toolbox/components';
|
2020-06-19 07:03:26 +00:00
|
|
|
import { getLocalJitsiVideoTrack } from '../../../base/tracks';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { VideoSettingsPopup, toggleVideoSettings } from '../../../settings';
|
2021-06-10 12:48:44 +00:00
|
|
|
import { getVideoSettingsVisibility } from '../../../settings/functions';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { isVideoSettingsButtonDisabled } from '../../functions';
|
|
|
|
import VideoMuteButton from '../VideoMuteButton';
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Click handler for the small icon. Opens video options.
|
|
|
|
*/
|
|
|
|
onVideoOptionsClick: Function,
|
|
|
|
|
2020-04-07 07:14:23 +00:00
|
|
|
/**
|
2021-02-02 00:20:39 +00:00
|
|
|
* Indicates whether video permissions have been granted or denied.
|
2020-04-07 07:14:23 +00:00
|
|
|
*/
|
2021-02-02 00:20:39 +00:00
|
|
|
hasPermissions: boolean,
|
2020-04-07 07:14:23 +00:00
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
/**
|
|
|
|
* Whether there is a video track or not.
|
|
|
|
*/
|
|
|
|
hasVideoTrack: boolean,
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +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,
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
|
|
|
* Flag controlling the visibility of the button.
|
2020-06-29 20:59:28 +00:00
|
|
|
* VideoSettings popup is currently disabled on mobile browsers
|
|
|
|
* as mobile devices do not support capture of more than one
|
|
|
|
* camera at a time.
|
2020-03-30 14:17:18 +00:00
|
|
|
*/
|
2021-02-23 11:09:22 +00:00
|
|
|
visible: boolean,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Used for translation.
|
2021-02-23 11:09:22 +00:00
|
|
|
*/
|
2021-06-10 12:48:44 +00:00
|
|
|
t: Function,
|
|
|
|
|
|
|
|
/**
|
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 video & video settings.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
2021-02-02 00:20:39 +00:00
|
|
|
class VideoSettingsButton extends Component<Props> {
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
2021-09-14 07:07:20 +00:00
|
|
|
* Initializes a new {@code VideoSettingsButton} instance.
|
2021-06-10 12:48:44 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
}
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the settings icon is disabled.
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isIconDisabled() {
|
2021-02-02 00:20:39 +00:00
|
|
|
const { hasPermissions, hasVideoTrack, isDisabled } = this.props;
|
2020-06-19 07:03:26 +00:00
|
|
|
|
2021-02-02 00:20:39 +00:00
|
|
|
return (!hasPermissions || isDisabled) && !hasVideoTrack;
|
2020-04-16 10:47:10 +00:00
|
|
|
}
|
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 { onVideoOptionsClick } = this.props;
|
2021-09-14 07:07:20 +00:00
|
|
|
|
|
|
|
onVideoOptionsClick();
|
|
|
|
}
|
|
|
|
|
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 { t, visible, isOpen, buttonKey, notifyMode } = this.props;
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
return visible ? (
|
|
|
|
<VideoSettingsPopup>
|
|
|
|
<ToolboxButtonWithIcon
|
2021-06-10 12:48:44 +00:00
|
|
|
ariaControls = 'video-settings-dialog'
|
|
|
|
ariaExpanded = { isOpen }
|
|
|
|
ariaHasPopup = { true }
|
|
|
|
ariaLabel = { this.props.t('toolbar.videoSettings') }
|
2022-01-04 11:21:00 +00:00
|
|
|
buttonKey = { buttonKey }
|
2021-03-11 09:25:49 +00:00
|
|
|
icon = { IconArrowUp }
|
2020-06-19 07:03:26 +00:00
|
|
|
iconDisabled = { this._isIconDisabled() }
|
2021-06-10 12:48:44 +00:00
|
|
|
iconId = 'video-settings-button'
|
2021-02-23 11:09:22 +00:00
|
|
|
iconTooltip = { t('toolbar.videoSettings') }
|
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
|
|
|
<VideoMuteButton
|
|
|
|
buttonKey = { buttonKey }
|
|
|
|
notifyMode = { notifyMode } />
|
2020-03-30 14:17:18 +00:00
|
|
|
</ToolboxButtonWithIcon>
|
|
|
|
</VideoSettingsPopup>
|
2022-01-04 11:21:00 +00:00
|
|
|
) : <VideoMuteButton
|
|
|
|
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.video,
|
2020-06-19 07:03:26 +00:00
|
|
|
hasVideoTrack: Boolean(getLocalJitsiVideoTrack(state)),
|
2020-04-16 10:47:10 +00:00
|
|
|
isDisabled: isVideoSettingsButtonDisabled(state),
|
2021-06-10 12:48:44 +00:00
|
|
|
isOpen: getVideoSettingsVisibility(state),
|
2020-06-29 20:59:28 +00:00
|
|
|
visible: !isMobileBrowser()
|
2020-03-30 14:17:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
onVideoOptionsClick: toggleVideoSettings
|
|
|
|
};
|
|
|
|
|
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
|
|
|
)(VideoSettingsButton));
|