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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // @flow
  2. import { getLocalVideoTrack } from '../../features/base/tracks';
  3. import { SET_SCREENSHOT_CAPTURE } from './actionTypes';
  4. import { createScreenshotCaptureSummary } from './functions';
  5. import logger from './logger';
  6. let screenshotSummary;
  7. /**
  8. * Marks the on-off state of screenshot captures.
  9. *
  10. * @param {boolean} enabled - Whether to turn screen captures on or off.
  11. * @returns {{
  12. * type: START_SCREENSHOT_CAPTURE,
  13. * payload: enabled
  14. * }}
  15. */
  16. function setScreenshotCapture(enabled) {
  17. return {
  18. type: SET_SCREENSHOT_CAPTURE,
  19. payload: enabled
  20. };
  21. }
  22. /**
  23. * Action that toggles the screenshot captures.
  24. *
  25. * @param {boolean} enabled - Bool that represents the intention to start/stop screenshot captures.
  26. * @returns {Promise}
  27. */
  28. export function toggleScreenshotCaptureSummary(enabled: boolean) {
  29. return async function(dispatch: (Object) => Object, getState: () => any) {
  30. const state = getState();
  31. if (state['features/screenshot-capture'].capturesEnabled !== enabled) {
  32. const { jitsiTrack } = getLocalVideoTrack(state['features/base/tracks']);
  33. if (!screenshotSummary) {
  34. try {
  35. screenshotSummary = await createScreenshotCaptureSummary(state);
  36. } catch (err) {
  37. logger.error('Cannot create screenshotCaptureSummary', err);
  38. }
  39. }
  40. if (enabled) {
  41. try {
  42. await screenshotSummary.start(jitsiTrack);
  43. dispatch(setScreenshotCapture(enabled));
  44. } catch {
  45. // Handle promise rejection from {@code start} due to stream type not being desktop.
  46. logger.error('Unsupported stream type.');
  47. }
  48. } else {
  49. screenshotSummary.stop();
  50. dispatch(setScreenshotCapture(enabled));
  51. }
  52. }
  53. return Promise.resolve();
  54. };
  55. }