您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VideoBlurButton.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // @flow
  2. import { createVideoBlurEvent, sendAnalytics } from '../../analytics';
  3. import { translate } from '../../base/i18n';
  4. import { IconBlurBackground } 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 { toggleBlurEffect } from '../actions';
  10. /**
  11. * The type of the React {@code Component} props of {@link VideoBlurButton}.
  12. */
  13. type Props = AbstractButtonProps & {
  14. /**
  15. * True if the video background is blurred or false if it is not.
  16. */
  17. _isVideoBlurred: 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 blur effect.
  29. */
  30. class VideoBlurButton extends AbstractButton<Props, *> {
  31. accessibilityLabel = 'toolbar.accessibilityLabel.videoblur';
  32. icon = IconBlurBackground;
  33. label = 'toolbar.startvideoblur';
  34. toggledLabel = 'toolbar.stopvideoblur';
  35. /**
  36. * Handles clicking / pressing the button, and toggles the blur effect
  37. * state accordingly.
  38. *
  39. * @protected
  40. * @returns {void}
  41. */
  42. _handleClick() {
  43. const { _isVideoBlurred, dispatch } = this.props;
  44. const value = !_isVideoBlurred;
  45. sendAnalytics(createVideoBlurEvent(value ? 'started' : 'stopped'));
  46. dispatch(toggleBlurEffect(value));
  47. }
  48. /**
  49. * Returns {@code boolean} value indicating if the blur effect is
  50. * enabled or not.
  51. *
  52. * @protected
  53. * @returns {boolean}
  54. */
  55. _isToggled() {
  56. return this.props._isVideoBlurred;
  57. }
  58. /**
  59. * Returns {@code boolean} value indicating if disabled state is
  60. * enabled or not.
  61. *
  62. * @protected
  63. * @returns {boolean}
  64. */
  65. _isDisabled() {
  66. return this.props._videoMuted;
  67. }
  68. }
  69. /**
  70. * Maps (parts of) the redux state to the associated props for the
  71. * {@code VideoBlurButton} component.
  72. *
  73. * @param {Object} state - The Redux state.
  74. * @private
  75. * @returns {{
  76. * _isVideoBlurred: boolean
  77. * }}
  78. */
  79. function _mapStateToProps(state): Object {
  80. const tracks = state['features/base/tracks'];
  81. return {
  82. _isVideoBlurred: Boolean(state['features/blur'].blurEnabled),
  83. _videoMuted: isLocalCameraTrackMuted(tracks)
  84. };
  85. }
  86. export default translate(connect(_mapStateToProps)(VideoBlurButton));