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.

VideoBlurButton.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @flow
  2. import { createVideoBlurEvent, sendAnalytics } from '../../analytics';
  3. import { translate } from '../../base/i18n';
  4. import { connect } from '../../base/redux';
  5. import { AbstractButton } from '../../base/toolbox';
  6. import type { AbstractButtonProps } from '../../base/toolbox';
  7. import {
  8. getJitsiMeetGlobalNS,
  9. loadScript
  10. } from '../../base/util';
  11. import { toggleBlurEffect } from '../actions';
  12. const logger = require('jitsi-meet-logger').getLogger(__filename);
  13. /**
  14. * The type of the React {@code Component} props of {@link VideoBlurButton}.
  15. */
  16. type Props = AbstractButtonProps & {
  17. /**
  18. * True if the video background is blurred or false if it is not.
  19. */
  20. _isVideoBlurred: boolean,
  21. /**
  22. * The redux {@code dispatch} function.
  23. */
  24. dispatch: Function
  25. };
  26. /**
  27. * An abstract implementation of a button that toggles the video blur effect.
  28. */
  29. class VideoBlurButton extends AbstractButton<Props, *> {
  30. accessibilityLabel = 'toolbar.accessibilityLabel.videoblur';
  31. iconName = 'icon-blur-background';
  32. label = 'toolbar.startvideoblur';
  33. tooltip = '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 {
  44. _isVideoBlurred,
  45. dispatch
  46. } = this.props;
  47. if (!getJitsiMeetGlobalNS().effects
  48. || !getJitsiMeetGlobalNS().effects.createBlurEffect) {
  49. loadScript('libs/video-blur-effect.min.js')
  50. .then(() => {
  51. this._handleClick();
  52. })
  53. .catch(error => {
  54. logger.error('Failed to load script with error: ', error);
  55. });
  56. } else {
  57. sendAnalytics(createVideoBlurEvent(_isVideoBlurred ? 'started' : 'stopped'));
  58. dispatch(toggleBlurEffect(!_isVideoBlurred));
  59. }
  60. }
  61. /**
  62. * Returns {@code boolean} value indicating if the blur effect is
  63. * enabled or not.
  64. *
  65. * @protected
  66. * @returns {boolean}
  67. */
  68. _isToggled() {
  69. const {
  70. _isVideoBlurred
  71. } = this.props;
  72. if (!getJitsiMeetGlobalNS().effects
  73. || !getJitsiMeetGlobalNS().effects.createBlurEffect) {
  74. return false;
  75. }
  76. return _isVideoBlurred;
  77. }
  78. }
  79. /**
  80. * Maps (parts of) the redux state to the associated props for the
  81. * {@code VideoBlurButton} component.
  82. *
  83. * @param {Object} state - The Redux state.
  84. * @private
  85. * @returns {{
  86. * _isVideoBlurred: boolean
  87. * }}
  88. */
  89. function _mapStateToProps(state): Object {
  90. return {
  91. _isVideoBlurred: Boolean(state['features/blur'].blurEnabled)
  92. };
  93. }
  94. export default translate(connect(_mapStateToProps)(VideoBlurButton));