您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.ts 2.5KB

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