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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // @flow
  2. import { createScreenshotCaptureEffect } from '../stream-effects/screenshot-capture';
  3. import { getLocalVideoTrack } from '../../features/base/tracks';
  4. import { SET_SCREENSHOT_CAPTURE } from './actionTypes';
  5. /**
  6. * Marks the on-off state of screenshot captures.
  7. *
  8. * @param {boolean} enabled - Whether to turn screen captures on or off.
  9. * @returns {{
  10. * type: START_SCREENSHOT_CAPTURE,
  11. * payload: enabled
  12. * }}
  13. */
  14. function setScreenshotCapture(enabled) {
  15. return {
  16. type: SET_SCREENSHOT_CAPTURE,
  17. payload: enabled
  18. };
  19. }
  20. /**
  21. * Action that toggles the screenshot captures.
  22. *
  23. * @param {boolean} enabled - Bool that represents the intention to start/stop screenshot captures.
  24. * @returns {Promise}
  25. */
  26. export function toggleScreenshotCaptureEffect(enabled: boolean) {
  27. return function(dispatch: (Object) => Object, getState: () => any) {
  28. const state = getState();
  29. if (state['features/screenshot-capture'].capturesEnabled !== enabled) {
  30. const { jitsiTrack } = getLocalVideoTrack(state['features/base/tracks']);
  31. return createScreenshotCaptureEffect(state)
  32. .then(effect =>
  33. jitsiTrack.setEffect(enabled ? effect : undefined)
  34. .then(() => {
  35. dispatch(setScreenshotCapture(enabled));
  36. })
  37. .catch(() => {
  38. dispatch(setScreenshotCapture(!enabled));
  39. })
  40. )
  41. .catch(() => dispatch(setScreenshotCapture(false)));
  42. }
  43. return Promise.resolve();
  44. };
  45. }