2019-09-19 13:28:57 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { getLocalVideoTrack } from '../../features/base/tracks';
|
2021-07-26 11:38:56 +00:00
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2019-09-19 13:28:57 +00:00
|
|
|
import { SET_SCREENSHOT_CAPTURE } from './actionTypes';
|
2021-07-26 11:38:56 +00:00
|
|
|
import { createScreenshotCaptureSummary } from './functions';
|
2020-05-20 10:57:03 +00:00
|
|
|
import logger from './logger';
|
2019-09-19 13:28:57 +00:00
|
|
|
|
2021-07-26 11:38:56 +00:00
|
|
|
let screenshotSummary;
|
2020-02-26 15:50:54 +00:00
|
|
|
|
2019-09-19 13:28:57 +00:00
|
|
|
/**
|
|
|
|
* 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}
|
|
|
|
*/
|
2021-07-26 11:38:56 +00:00
|
|
|
export function toggleScreenshotCaptureSummary(enabled: boolean) {
|
2020-02-26 15:50:54 +00:00
|
|
|
return async function(dispatch: (Object) => Object, getState: () => any) {
|
2019-09-19 13:28:57 +00:00
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
if (state['features/screenshot-capture'].capturesEnabled !== enabled) {
|
2021-07-26 11:38:56 +00:00
|
|
|
if (!screenshotSummary) {
|
|
|
|
try {
|
|
|
|
screenshotSummary = await createScreenshotCaptureSummary(state);
|
|
|
|
} catch (err) {
|
|
|
|
logger.error('Cannot create screenshotCaptureSummary', err);
|
|
|
|
}
|
2020-02-26 15:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
try {
|
2022-01-28 09:11:35 +00:00
|
|
|
const { jitsiTrack } = getLocalVideoTrack(state['features/base/tracks']);
|
|
|
|
|
2021-07-26 11:38:56 +00:00
|
|
|
await screenshotSummary.start(jitsiTrack);
|
2020-02-25 15:22:10 +00:00
|
|
|
dispatch(setScreenshotCapture(enabled));
|
2020-02-26 15:50:54 +00:00
|
|
|
} catch {
|
|
|
|
|
2021-07-26 11:38:56 +00:00
|
|
|
// Handle promise rejection from {@code start} due to stream type not being desktop.
|
2020-02-26 15:50:54 +00:00
|
|
|
logger.error('Unsupported stream type.');
|
|
|
|
}
|
|
|
|
} else {
|
2021-07-26 11:38:56 +00:00
|
|
|
screenshotSummary.stop();
|
2020-02-26 15:50:54 +00:00
|
|
|
dispatch(setScreenshotCapture(enabled));
|
|
|
|
}
|
2019-09-19 13:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
};
|
|
|
|
}
|