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.4KB

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