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.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // @flow
  2. import { openDialog } from '../../base/dialog';
  3. import { translate } from '../../base/i18n';
  4. import { IconVirtualBackground } from '../../base/icons';
  5. import { connect } from '../../base/redux';
  6. import { AbstractButton } from '../../base/toolbox/components';
  7. import type { AbstractButtonProps } from '../../base/toolbox/components';
  8. import { isLocalCameraTrackMuted } from '../../base/tracks';
  9. import { VirtualBackgroundDialog } from './index';
  10. /**
  11. * The type of the React {@code Component} props of {@link VideoBackgroundButton}.
  12. */
  13. type Props = AbstractButtonProps & {
  14. /**
  15. * True if the video background is blurred or false if it is not.
  16. */
  17. _isBackgroundEnabled: boolean,
  18. /**
  19. * Whether video is currently muted or not.
  20. */
  21. _videoMuted: boolean,
  22. /**
  23. * The redux {@code dispatch} function.
  24. */
  25. dispatch: Function
  26. };
  27. /**
  28. * An abstract implementation of a button that toggles the video background dialog.
  29. */
  30. class VideoBackgroundButton extends AbstractButton<Props, *> {
  31. accessibilityLabel = 'toolbar.accessibilityLabel.selectBackground';
  32. icon = IconVirtualBackground;
  33. label = 'toolbar.selectBackground';
  34. tooltip = 'toolbar.selectBackground';
  35. /**
  36. * Handles clicking / pressing the button, and toggles the virtual background dialog
  37. * state accordingly.
  38. *
  39. * @protected
  40. * @returns {void}
  41. */
  42. _handleClick() {
  43. const { dispatch } = this.props;
  44. dispatch(openDialog(VirtualBackgroundDialog));
  45. }
  46. /**
  47. * Returns {@code boolean} value indicating if the background effect is
  48. * enabled or not.
  49. *
  50. * @protected
  51. * @returns {boolean}
  52. */
  53. _isToggled() {
  54. return this.props._isBackgroundEnabled;
  55. }
  56. /**
  57. * Returns {@code boolean} value indicating if disabled state is
  58. * enabled or not.
  59. *
  60. * @protected
  61. * @returns {boolean}
  62. */
  63. _isDisabled() {
  64. return this.props._videoMuted;
  65. }
  66. }
  67. /**
  68. * Maps (parts of) the redux state to the associated props for the
  69. * {@code VideoBackgroundButton} component.
  70. *
  71. * @param {Object} state - The Redux state.
  72. * @private
  73. * @returns {{
  74. * _isBackgroundEnabled: boolean
  75. * }}
  76. */
  77. function _mapStateToProps(state): Object {
  78. const tracks = state['features/base/tracks'];
  79. return {
  80. _isBackgroundEnabled: Boolean(state['features/virtual-background'].backgroundEffectEnabled),
  81. _videoMuted: isLocalCameraTrackMuted(tracks)
  82. };
  83. }
  84. export default translate(connect(_mapStateToProps)(VideoBackgroundButton));