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 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // @flow
  2. import { getLocalVideoTrack } from '../base/tracks';
  3. import { createVirtualBackgroundEffect } from '../stream-effects/virtual-background';
  4. import { BACKGROUND_ENABLED, SET_VIRTUAL_BACKGROUND } from './actionTypes';
  5. import logger from './logger';
  6. /**
  7. * Signals the local participant activate the virtual background video or not.
  8. *
  9. * @param {Object} options - Represents the virtual background setted options.
  10. * @returns {Promise}
  11. */
  12. export function toggleBackgroundEffect(options: Object) {
  13. return async function(dispatch: Object => Object, getState: () => any) {
  14. await dispatch(backgroundEnabled(options.enabled));
  15. await dispatch(setVirtualBackground(options));
  16. const state = getState();
  17. const { jitsiTrack } = getLocalVideoTrack(state['features/base/tracks']);
  18. const virtualBackground = state['features/virtual-background'];
  19. try {
  20. if (options.enabled) {
  21. await jitsiTrack.setEffect(await createVirtualBackgroundEffect(virtualBackground));
  22. } else {
  23. await jitsiTrack.setEffect(undefined);
  24. dispatch(backgroundEnabled(false));
  25. }
  26. } catch (error) {
  27. dispatch(backgroundEnabled(false));
  28. logger.error('Error on apply backgroun effect:', error);
  29. }
  30. };
  31. }
  32. /**
  33. * Sets the selected virtual background image object.
  34. *
  35. * @param {Object} options - Represents the virtual background setted options.
  36. * @returns {{
  37. * type: SET_VIRTUAL_BACKGROUND,
  38. * virtualSource: string,
  39. * blurValue: number,
  40. * type: string,
  41. * }}
  42. */
  43. export function setVirtualBackground(options: Object) {
  44. return {
  45. type: SET_VIRTUAL_BACKGROUND,
  46. virtualSource: options?.url,
  47. blurValue: options?.blurValue,
  48. backgroundType: options?.backgroundType
  49. };
  50. }
  51. /**
  52. * Signals the local participant that the background effect has been enabled.
  53. *
  54. * @param {boolean} backgroundEffectEnabled - Indicate if virtual background effect is activated.
  55. * @returns {{
  56. * type: BACKGROUND_ENABLED,
  57. * backgroundEffectEnabled: boolean
  58. * }}
  59. */
  60. export function backgroundEnabled(backgroundEffectEnabled: boolean) {
  61. return {
  62. type: BACKGROUND_ENABLED,
  63. backgroundEffectEnabled
  64. };
  65. }