Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // @flow
  2. import { getLocalVideoTrack } from '../../features/base/tracks';
  3. import { createScreenshotCaptureEffect } from '../stream-effects/screenshot-capture';
  4. import { SET_SCREENSHOT_CAPTURE } from './actionTypes';
  5. import logger from './logger';
  6. let ongoingEffect;
  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 toggleScreenshotCaptureEffect(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 (!ongoingEffect) {
  34. ongoingEffect = await createScreenshotCaptureEffect(state);
  35. }
  36. // Screenshot capture effect doesn't return a modified stream. Therefore, we don't have to
  37. // switch the stream at the conference level, starting/stopping the effect will suffice here.
  38. if (enabled) {
  39. try {
  40. await ongoingEffect.startEffect(
  41. jitsiTrack.getOriginalStream(),
  42. jitsiTrack.videoType
  43. );
  44. dispatch(setScreenshotCapture(enabled));
  45. } catch {
  46. // Handle promise rejection from {@code startEffect} due to stream type not being desktop.
  47. logger.error('Unsupported stream type.');
  48. }
  49. } else {
  50. ongoingEffect.stopEffect();
  51. dispatch(setScreenshotCapture(enabled));
  52. }
  53. }
  54. return Promise.resolve();
  55. };
  56. }