Files
jitsi-meet/react/features/screenshot-capture/actions.js
robertpin 001ae54a7c feat(screenshot-capture) Updated screensharing screenshot capture
Changed screen capture to non effect. Effects are used to alter the stream, this feature does not need to alter the stream, it just needs access to it

Changed image diff library. Previous library diff’ed the whole image, the new one has en early return threshold

Use ImageCaptureAPI to take the screenshot. Added polyfill for it and polyfill for createImageBitmap

Added analytics
2021-10-05 10:25:27 +02:00

67 lines
1.9 KiB
JavaScript

// @flow
import { getLocalVideoTrack } from '../../features/base/tracks';
import { SET_SCREENSHOT_CAPTURE } from './actionTypes';
import { createScreenshotCaptureSummary } from './functions';
import logger from './logger';
let screenshotSummary;
/**
* Marks the on-off state of screenshot captures.
*
* @param {boolean} enabled - Whether to turn screen captures on or off.
* @returns {{
* type: START_SCREENSHOT_CAPTURE,
* payload: enabled
* }}
*/
function setScreenshotCapture(enabled) {
return {
type: SET_SCREENSHOT_CAPTURE,
payload: enabled
};
}
/**
* Action that toggles the screenshot captures.
*
* @param {boolean} enabled - Bool that represents the intention to start/stop screenshot captures.
* @returns {Promise}
*/
export function toggleScreenshotCaptureSummary(enabled: boolean) {
return async function(dispatch: (Object) => Object, getState: () => any) {
const state = getState();
if (state['features/screenshot-capture'].capturesEnabled !== enabled) {
const { jitsiTrack } = getLocalVideoTrack(state['features/base/tracks']);
if (!screenshotSummary) {
try {
screenshotSummary = await createScreenshotCaptureSummary(state);
} catch (err) {
logger.error('Cannot create screenshotCaptureSummary', err);
}
}
if (enabled) {
try {
await screenshotSummary.start(jitsiTrack);
dispatch(setScreenshotCapture(enabled));
} catch {
// Handle promise rejection from {@code start} due to stream type not being desktop.
logger.error('Unsupported stream type.');
}
} else {
screenshotSummary.stop();
dispatch(setScreenshotCapture(enabled));
}
}
return Promise.resolve();
};
}