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

VideoBlurButton.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. tooltip = 'toolbar.startvideoblur';
  35. toggledLabel = 'toolbar.stopvideoblur';
  36. /**
  37. * Handles clicking / pressing the button, and toggles the blur effect
  38. * state accordingly.
  39. *
  40. * @protected
  41. * @returns {void}
  42. */
  43. _handleClick() {
  44. const { _isVideoBlurred, dispatch } = this.props;
  45. const value = !_isVideoBlurred;
  46. sendAnalytics(createVideoBlurEvent(value ? 'started' : 'stopped'));
  47. dispatch(toggleBlurEffect(value));
  48. }
  49. /**
  50. * Returns {@code boolean} value indicating if the blur effect is
  51. * enabled or not.
  52. *
  53. * @protected
  54. * @returns {boolean}
  55. */
  56. _isToggled() {
  57. return this.props._isVideoBlurred;
  58. }
  59. /**
  60. * Returns {@code boolean} value indicating if disabled state is
  61. * enabled or not.
  62. *
  63. * @protected
  64. * @returns {boolean}
  65. */
  66. _isDisabled() {
  67. return this.props._videoMuted;
  68. }
  69. }
  70. /**
  71. * Maps (parts of) the redux state to the associated props for the
  72. * {@code VideoBlurButton} component.
  73. *
  74. * @param {Object} state - The Redux state.
  75. * @private
  76. * @returns {{
  77. * _isVideoBlurred: boolean
  78. * }}
  79. */
  80. function _mapStateToProps(state): Object {
  81. const tracks = state['features/base/tracks'];
  82. return {
  83. _isVideoBlurred: Boolean(state['features/blur'].blurEnabled),
  84. _videoMuted: isLocalCameraTrackMuted(tracks)
  85. };
  86. }
  87. export default translate(connect(_mapStateToProps)(VideoBlurButton));