You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoBackgroundButton.ts 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { connect } from 'react-redux';
  2. import { IReduxState } from '../../app/types';
  3. import { translate } from '../../base/i18n/functions';
  4. import { IconImage } from '../../base/icons/svg';
  5. import AbstractButton, { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
  6. import { isScreenVideoShared } from '../../screen-share/functions';
  7. import { openSettingsDialog } from '../../settings/actions';
  8. import { SETTINGS_TABS } from '../../settings/constants';
  9. import { checkBlurSupport, checkVirtualBackgroundEnabled } from '../functions';
  10. /**
  11. * The type of the React {@code Component} props of {@link VideoBackgroundButton}.
  12. */
  13. interface IProps extends AbstractButtonProps {
  14. /**
  15. * True if the video background is blurred or false if it is not.
  16. */
  17. _isBackgroundEnabled: boolean;
  18. }
  19. /**
  20. * An abstract implementation of a button that toggles the video background dialog.
  21. */
  22. class VideoBackgroundButton extends AbstractButton<IProps> {
  23. accessibilityLabel = 'toolbar.accessibilityLabel.selectBackground';
  24. icon = IconImage;
  25. label = 'toolbar.selectBackground';
  26. tooltip = 'toolbar.selectBackground';
  27. /**
  28. * Handles clicking / pressing the button, and toggles the virtual background dialog
  29. * state accordingly.
  30. *
  31. * @protected
  32. * @returns {void}
  33. */
  34. _handleClick() {
  35. const { dispatch } = this.props;
  36. dispatch(openSettingsDialog(SETTINGS_TABS.VIRTUAL_BACKGROUND));
  37. }
  38. /**
  39. * Returns {@code boolean} value indicating if the background effect is
  40. * enabled or not.
  41. *
  42. * @protected
  43. * @returns {boolean}
  44. */
  45. _isToggled() {
  46. return this.props._isBackgroundEnabled;
  47. }
  48. }
  49. /**
  50. * Maps (parts of) the redux state to the associated props for the
  51. * {@code VideoBackgroundButton} component.
  52. *
  53. * @param {Object} state - The Redux state.
  54. * @private
  55. * @returns {{
  56. * _isBackgroundEnabled: boolean
  57. * }}
  58. */
  59. function _mapStateToProps(state: IReduxState) {
  60. return {
  61. _isBackgroundEnabled: Boolean(state['features/virtual-background'].backgroundEffectEnabled),
  62. visible: checkBlurSupport()
  63. && !isScreenVideoShared(state)
  64. && checkVirtualBackgroundEnabled(state)
  65. };
  66. }
  67. export default translate(connect(_mapStateToProps)(VideoBackgroundButton));