Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.ts 2.6KB

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