jiti-meet/react/features/virtual-background/components/VideoBackgroundButton.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-06-28 17:18:47 +00:00
// @flow
import { openDialog } from '../../base/dialog';
2019-06-28 17:18:47 +00:00
import { translate } from '../../base/i18n';
import { IconVirtualBackground } from '../../base/icons';
2019-06-28 17:18:47 +00:00
import { connect } from '../../base/redux';
import { AbstractButton } from '../../base/toolbox/components';
2020-07-24 12:14:33 +00:00
import type { AbstractButtonProps } from '../../base/toolbox/components';
import { checkBlurSupport } from '../functions';
import { VirtualBackgroundDialog } from './index';
2019-06-28 17:18:47 +00:00
/**
* The type of the React {@code Component} props of {@link VideoBackgroundButton}.
2019-06-28 17:18:47 +00:00
*/
type Props = AbstractButtonProps & {
/**
* True if the video background is blurred or false if it is not.
*/
_isBackgroundEnabled: boolean,
2019-06-28 17:18:47 +00:00
/**
* The redux {@code dispatch} function.
*/
dispatch: Function
};
/**
* An abstract implementation of a button that toggles the video background dialog.
2019-06-28 17:18:47 +00:00
*/
class VideoBackgroundButton extends AbstractButton<Props, *> {
accessibilityLabel = 'toolbar.accessibilityLabel.selectBackground';
icon = IconVirtualBackground;
label = 'toolbar.selectBackground';
tooltip = 'toolbar.selectBackground';
2019-06-28 17:18:47 +00:00
/**
* Handles clicking / pressing the button, and toggles the virtual background dialog
2019-06-28 17:18:47 +00:00
* state accordingly.
*
* @protected
* @returns {void}
*/
_handleClick() {
const { dispatch, handleClick } = this.props;
if (handleClick) {
handleClick();
return;
}
2019-06-28 17:18:47 +00:00
dispatch(openDialog(VirtualBackgroundDialog));
2019-06-28 17:18:47 +00:00
}
/**
* Returns {@code boolean} value indicating if the background effect is
2019-06-28 17:18:47 +00:00
* enabled or not.
*
* @protected
* @returns {boolean}
*/
_isToggled() {
return this.props._isBackgroundEnabled;
2019-06-28 17:18:47 +00:00
}
}
/**
* Maps (parts of) the redux state to the associated props for the
* {@code VideoBackgroundButton} component.
2019-06-28 17:18:47 +00:00
*
* @param {Object} state - The Redux state.
* @private
* @returns {{
* _isBackgroundEnabled: boolean
2019-06-28 17:18:47 +00:00
* }}
*/
function _mapStateToProps(state): Object {
2019-06-28 17:18:47 +00:00
return {
_isBackgroundEnabled: Boolean(state['features/virtual-background'].backgroundEffectEnabled),
visible: checkBlurSupport()
2019-06-28 17:18:47 +00:00
};
}
export default translate(connect(_mapStateToProps)(VideoBackgroundButton));