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.

actions.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @flow
  2. import { getLocalVideoTrack } from '../../features/base/tracks';
  3. import { BLUR_DISABLED, BLUR_ENABLED } from './actionTypes';
  4. import { getBlurEffect } from './functions';
  5. import logger from './logger';
  6. /**
  7. * Signals the local participant is switching between blurred or non blurred video.
  8. *
  9. * @param {boolean} enabled - If true enables video blur, false otherwise.
  10. * @returns {Promise}
  11. */
  12. export function toggleBlurEffect(enabled: boolean) {
  13. return function(dispatch: (Object) => Object, getState: () => any) {
  14. const state = getState();
  15. if (state['features/blur'].blurEnabled !== enabled) {
  16. const { jitsiTrack } = getLocalVideoTrack(state['features/base/tracks']);
  17. return getBlurEffect()
  18. .then(blurEffectInstance =>
  19. jitsiTrack.setEffect(enabled ? blurEffectInstance : undefined)
  20. .then(() => {
  21. enabled ? dispatch(blurEnabled()) : dispatch(blurDisabled());
  22. })
  23. .catch(error => {
  24. enabled ? dispatch(blurDisabled()) : dispatch(blurEnabled());
  25. logger.error('setEffect failed with error:', error);
  26. })
  27. )
  28. .catch(error => {
  29. dispatch(blurDisabled());
  30. logger.error('getBlurEffect failed with error:', error);
  31. });
  32. }
  33. return Promise.resolve();
  34. };
  35. }
  36. /**
  37. * Signals the local participant that the blur has been enabled.
  38. *
  39. * @returns {{
  40. * type: BLUR_ENABLED
  41. * }}
  42. */
  43. export function blurEnabled() {
  44. return {
  45. type: BLUR_ENABLED
  46. };
  47. }
  48. /**
  49. * Signals the local participant that the blur has been disabled.
  50. *
  51. * @returns {{
  52. * type: BLUR_DISABLED
  53. * }}
  54. */
  55. export function blurDisabled() {
  56. return {
  57. type: BLUR_DISABLED
  58. };
  59. }