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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. selectedThumbnail: options?.selectedThumbnail
  50. };
  51. }
  52. /**
  53. * Signals the local participant that the background effect has been enabled.
  54. *
  55. * @param {boolean} backgroundEffectEnabled - Indicate if virtual background effect is activated.
  56. * @returns {{
  57. * type: BACKGROUND_ENABLED,
  58. * backgroundEffectEnabled: boolean
  59. * }}
  60. */
  61. export function backgroundEnabled(backgroundEffectEnabled: boolean) {
  62. return {
  63. type: BACKGROUND_ENABLED,
  64. backgroundEffectEnabled
  65. };
  66. }