2021-02-18 15:52:47 +00:00
|
|
|
// @flow
|
2021-06-10 12:48:44 +00:00
|
|
|
|
2021-03-24 16:32:45 +00:00
|
|
|
import Spinner from '@atlaskit/spinner';
|
2021-06-02 19:21:39 +00:00
|
|
|
import Bourne from '@hapi/bourne';
|
2021-03-24 16:32:45 +00:00
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils/jitsi-local-storage';
|
2022-03-29 09:07:55 +00:00
|
|
|
import { makeStyles } from '@material-ui/styles';
|
|
|
|
import clsx from 'clsx';
|
2021-09-10 07:00:54 +00:00
|
|
|
import React, { useState, useEffect, useCallback } from 'react';
|
2021-10-28 07:17:46 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2022-07-06 19:47:06 +00:00
|
|
|
import { getMultipleVideoSendingSupportFeatureFlag } from '../../base/config';
|
2021-06-20 02:17:52 +00:00
|
|
|
import { Dialog, hideDialog, openDialog } from '../../base/dialog';
|
2021-02-18 15:52:47 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2021-09-10 07:00:54 +00:00
|
|
|
import { Icon, IconCloseSmall, IconShareDesktop } from '../../base/icons';
|
2021-06-20 02:17:52 +00:00
|
|
|
import { browser, JitsiTrackErrors } from '../../base/lib-jitsi-meet';
|
2021-05-14 14:53:11 +00:00
|
|
|
import { createLocalTrack } from '../../base/lib-jitsi-meet/functions';
|
2021-05-26 11:53:14 +00:00
|
|
|
import { VIDEO_TYPE } from '../../base/media';
|
2021-02-18 15:52:47 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2021-06-24 15:21:34 +00:00
|
|
|
import { updateSettings } from '../../base/settings';
|
2021-06-10 12:48:44 +00:00
|
|
|
import { Tooltip } from '../../base/tooltip';
|
2021-05-06 06:54:23 +00:00
|
|
|
import { getLocalVideoTrack } from '../../base/tracks';
|
2021-11-24 11:05:27 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE, showErrorNotification } from '../../notifications';
|
2021-11-17 14:33:03 +00:00
|
|
|
import { toggleBackgroundEffect, virtualBackgroundTrackChanged } from '../actions';
|
2021-09-10 07:00:54 +00:00
|
|
|
import { IMAGES, BACKGROUNDS_LIMIT, VIRTUAL_BACKGROUND_TYPE, type Image } from '../constants';
|
|
|
|
import { toDataURL } from '../functions';
|
2021-03-24 16:32:45 +00:00
|
|
|
import logger from '../logger';
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2021-09-10 07:00:54 +00:00
|
|
|
import UploadImageButton from './UploadImageButton';
|
2021-05-06 06:54:23 +00:00
|
|
|
import VirtualBackgroundPreview from './VirtualBackgroundPreview';
|
|
|
|
|
2021-02-18 15:52:47 +00:00
|
|
|
type Props = {
|
|
|
|
|
2021-09-10 07:00:54 +00:00
|
|
|
/**
|
|
|
|
* The list of Images to choose from.
|
|
|
|
*/
|
|
|
|
_images: Array<Image>,
|
|
|
|
|
2022-07-06 19:47:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the jitsi track that will have backgraund effect applied.
|
|
|
|
*/
|
|
|
|
_jitsiTrack: Object,
|
|
|
|
|
2021-06-24 15:21:34 +00:00
|
|
|
/**
|
|
|
|
* The current local flip x status.
|
|
|
|
*/
|
|
|
|
_localFlipX: boolean,
|
|
|
|
|
2021-05-06 06:54:23 +00:00
|
|
|
/**
|
2022-07-06 19:47:06 +00:00
|
|
|
* Whether or not multi-stream send support is enabled.
|
|
|
|
*/
|
|
|
|
_multiStreamModeEnabled: boolean,
|
2021-05-06 06:54:23 +00:00
|
|
|
|
2021-04-09 14:25:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the selected thumbnail identifier.
|
|
|
|
*/
|
|
|
|
_selectedThumbnail: string,
|
|
|
|
|
2021-09-10 07:00:54 +00:00
|
|
|
/**
|
|
|
|
* If the upload button should be displayed or not.
|
|
|
|
*/
|
|
|
|
_showUploadButton: boolean,
|
|
|
|
|
2021-05-19 09:57:11 +00:00
|
|
|
/**
|
2021-06-18 14:18:05 +00:00
|
|
|
* Returns the selected virtual background object.
|
2021-05-19 09:57:11 +00:00
|
|
|
*/
|
2021-06-18 14:18:05 +00:00
|
|
|
_virtualBackground: Object,
|
2021-05-19 09:57:11 +00:00
|
|
|
|
2021-02-18 15:52:47 +00:00
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
2021-06-20 02:17:52 +00:00
|
|
|
/**
|
|
|
|
* The initial options copied in the state for the {@code VirtualBackground} component.
|
|
|
|
*
|
|
|
|
* NOTE: currently used only for electron in order to open the dialog in the correct state after desktop sharing
|
|
|
|
* selection.
|
|
|
|
*/
|
|
|
|
initialOptions: Object,
|
|
|
|
|
2021-02-18 15:52:47 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const onError = event => {
|
|
|
|
event.target.style.display = 'none';
|
|
|
|
};
|
|
|
|
|
2021-06-20 02:17:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated props for the
|
|
|
|
* {@code VirtualBackground} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{Props}}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state): Object {
|
2021-06-24 15:21:34 +00:00
|
|
|
const { localFlipX } = state['features/base/settings'];
|
2021-09-10 07:00:54 +00:00
|
|
|
const dynamicBrandingImages = state['features/dynamic-branding'].virtualBackgrounds;
|
|
|
|
const hasBrandingImages = Boolean(dynamicBrandingImages.length);
|
2021-06-24 15:21:34 +00:00
|
|
|
|
2021-06-20 02:17:52 +00:00
|
|
|
return {
|
2021-06-24 15:21:34 +00:00
|
|
|
_localFlipX: Boolean(localFlipX),
|
2021-09-10 07:00:54 +00:00
|
|
|
_images: (hasBrandingImages && dynamicBrandingImages) || IMAGES,
|
2021-06-20 02:17:52 +00:00
|
|
|
_virtualBackground: state['features/virtual-background'],
|
|
|
|
_selectedThumbnail: state['features/virtual-background'].selectedThumbnail,
|
2021-09-10 07:00:54 +00:00
|
|
|
_showUploadButton: !(hasBrandingImages || state['features/base/config'].disableAddingBackgroundImages),
|
2022-07-06 19:47:06 +00:00
|
|
|
_jitsiTrack: getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack,
|
|
|
|
_multiStreamModeEnabled: getMultipleVideoSendingSupportFeatureFlag(state)
|
2021-06-20 02:17:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const VirtualBackgroundDialog = translate(connect(_mapStateToProps)(VirtualBackground));
|
|
|
|
|
2022-03-29 09:07:55 +00:00
|
|
|
const useStyles = makeStyles(theme => {
|
|
|
|
return {
|
2022-07-12 13:18:07 +00:00
|
|
|
container: {
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column'
|
|
|
|
},
|
2022-03-29 09:07:55 +00:00
|
|
|
dialog: {
|
2022-07-12 13:18:07 +00:00
|
|
|
alignSelf: 'flex-start',
|
2022-03-29 09:07:55 +00:00
|
|
|
marginLeft: '-10px',
|
|
|
|
position: 'relative',
|
|
|
|
maxHeight: '300px',
|
|
|
|
color: 'white',
|
|
|
|
display: 'inline-grid',
|
|
|
|
gridTemplateColumns: 'auto auto auto auto auto',
|
|
|
|
columnGap: '9px',
|
|
|
|
cursor: 'pointer',
|
|
|
|
[[ '& .desktop-share:hover',
|
|
|
|
'& .thumbnail:hover',
|
|
|
|
'& .blur:hover',
|
|
|
|
'& .slight-blur:hover',
|
|
|
|
'& .virtual-background-none:hover' ]]: {
|
|
|
|
opacity: 0.5,
|
|
|
|
border: '2px solid #99bbf3'
|
|
|
|
},
|
|
|
|
'& .background-option': {
|
|
|
|
marginTop: `${theme.spacing(2)}px`,
|
|
|
|
borderRadius: `${theme.shape.borderRadius}px`,
|
|
|
|
height: '60px',
|
|
|
|
width: '107px',
|
|
|
|
textAlign: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
'& thumbnail-container': {
|
|
|
|
position: 'relative',
|
|
|
|
'&:focus-within .thumbnail ~ .delete-image-icon': {
|
|
|
|
display: 'block'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'& .thumbnail': {
|
|
|
|
objectFit: 'cover'
|
|
|
|
},
|
|
|
|
'& .thumbnail:hover ~ .delete-image-icon': {
|
|
|
|
display: 'block'
|
|
|
|
},
|
|
|
|
'& .thumbnail-selected': {
|
|
|
|
objectFit: 'cover',
|
|
|
|
border: '2px solid #246fe5'
|
|
|
|
},
|
|
|
|
'& .blur': {
|
|
|
|
boxShadow: 'inset 0 0 12px #000000',
|
|
|
|
background: '#7e8287',
|
|
|
|
padding: '0 10px'
|
|
|
|
},
|
|
|
|
'& .blur-selected': {
|
|
|
|
border: '2px solid #246fe5'
|
|
|
|
},
|
|
|
|
'& .slight-blur': {
|
|
|
|
boxShadow: 'inset 0 0 12px #000000',
|
|
|
|
background: '#a4a4a4',
|
|
|
|
padding: '0 10px'
|
|
|
|
},
|
|
|
|
'& .slight-blur-selected': {
|
|
|
|
border: '2px solid #246fe5'
|
|
|
|
},
|
|
|
|
'& .virtual-background-none': {
|
|
|
|
background: '#525252',
|
|
|
|
padding: '0 10px'
|
|
|
|
},
|
|
|
|
'& .none-selected': {
|
|
|
|
border: '2px solid #246fe5'
|
|
|
|
},
|
|
|
|
'& .desktop-share': {
|
|
|
|
background: '#525252'
|
|
|
|
},
|
|
|
|
'& .desktop-share-selected': {
|
|
|
|
border: '2px solid #246fe5',
|
|
|
|
padding: '0 10px'
|
|
|
|
},
|
|
|
|
'& delete-image-icon': {
|
|
|
|
background: '#3d3d3d',
|
|
|
|
position: 'absolute',
|
|
|
|
display: 'none',
|
|
|
|
left: '96px',
|
|
|
|
bottom: '51px',
|
|
|
|
'&:hover': {
|
|
|
|
display: 'block'
|
|
|
|
},
|
|
|
|
'@media (max-width: 632px)': {
|
|
|
|
left: '51px'
|
|
|
|
}
|
|
|
|
},
|
2022-07-12 13:18:07 +00:00
|
|
|
'@media (max-width: 720px)': {
|
|
|
|
gridTemplateColumns: 'auto auto auto auto'
|
2022-03-29 09:07:55 +00:00
|
|
|
},
|
|
|
|
'@media (max-width: 632px)': {
|
2022-07-12 13:18:07 +00:00
|
|
|
gridTemplateColumns: 'auto auto auto auto auto',
|
2022-03-29 09:07:55 +00:00
|
|
|
fontSize: '1.5vw',
|
|
|
|
|
|
|
|
[[ '& .desktop-share:hover',
|
|
|
|
'& .thumbnail:hover',
|
|
|
|
'& .blur:hover',
|
|
|
|
'& .slight-blur:hover',
|
|
|
|
'& .virtual-background-none:hover' ]]: {
|
|
|
|
height: '60px',
|
|
|
|
width: '60px'
|
|
|
|
},
|
|
|
|
|
|
|
|
[[ '& .desktop-share',
|
|
|
|
'& .virtual-background-none,',
|
|
|
|
'& .thumbnail,',
|
|
|
|
'& .blur,',
|
|
|
|
'& .slight-blur' ]]: {
|
|
|
|
height: '60px',
|
|
|
|
width: '60px'
|
|
|
|
},
|
|
|
|
[[ '& .desktop-share-selected',
|
|
|
|
'& .thumbnail-selected',
|
|
|
|
'& .none-selected',
|
|
|
|
'& .blur-selected',
|
|
|
|
'& .slight-blur-selected' ]]: {
|
|
|
|
height: '60px',
|
|
|
|
width: '60px'
|
|
|
|
}
|
2022-07-12 13:18:07 +00:00
|
|
|
},
|
|
|
|
'@media (max-width: 360px)': {
|
|
|
|
gridTemplateColumns: 'auto auto auto auto'
|
|
|
|
},
|
|
|
|
'@media (max-width: 319px)': {
|
|
|
|
gridTemplateColumns: 'auto auto'
|
2022-03-29 09:07:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
dialogMarginTop: {
|
|
|
|
marginTop: '44px'
|
|
|
|
},
|
|
|
|
virtualBackgroundLoading: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
position: 'fixed',
|
|
|
|
left: '50%',
|
|
|
|
marginTop: '10px',
|
|
|
|
transform: 'translateX(-50%)'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-02-18 15:52:47 +00:00
|
|
|
/**
|
|
|
|
* Renders virtual background dialog.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
2021-06-20 02:17:52 +00:00
|
|
|
function VirtualBackground({
|
2021-09-10 07:00:54 +00:00
|
|
|
_images,
|
2021-06-20 02:17:52 +00:00
|
|
|
_jitsiTrack,
|
2021-09-10 07:00:54 +00:00
|
|
|
_localFlipX,
|
2021-06-20 02:17:52 +00:00
|
|
|
_selectedThumbnail,
|
2021-09-10 07:00:54 +00:00
|
|
|
_showUploadButton,
|
2021-06-20 02:17:52 +00:00
|
|
|
_virtualBackground,
|
2022-07-06 19:47:06 +00:00
|
|
|
_multiStreamModeEnabled,
|
2021-06-20 02:17:52 +00:00
|
|
|
dispatch,
|
|
|
|
initialOptions,
|
|
|
|
t
|
|
|
|
}: Props) {
|
2022-03-29 09:07:55 +00:00
|
|
|
const classes = useStyles();
|
2021-08-26 13:33:43 +00:00
|
|
|
const [ previewIsLoaded, setPreviewIsLoaded ] = useState(false);
|
2021-06-20 02:17:52 +00:00
|
|
|
const [ options, setOptions ] = useState({ ...initialOptions });
|
2021-03-24 16:32:45 +00:00
|
|
|
const localImages = jitsiLocalStorage.getItem('virtualBackgrounds');
|
2021-06-10 12:48:44 +00:00
|
|
|
const [ storedImages, setStoredImages ] = useState<Array<Image>>((localImages && Bourne.parse(localImages)) || []);
|
|
|
|
const [ loading, setLoading ] = useState(false);
|
2022-07-06 19:47:06 +00:00
|
|
|
let { disableScreensharingVirtualBackground } = useSelector(state => state['features/base/config']);
|
|
|
|
|
|
|
|
// Disable screenshare as virtual background in multi-stream mode.
|
|
|
|
disableScreensharingVirtualBackground = disableScreensharingVirtualBackground || _multiStreamModeEnabled;
|
2021-09-10 07:00:54 +00:00
|
|
|
|
2021-06-18 14:18:05 +00:00
|
|
|
const [ activeDesktopVideo ] = useState(_virtualBackground?.virtualSource?.videoType === VIDEO_TYPE.DESKTOP
|
|
|
|
? _virtualBackground.virtualSource
|
|
|
|
: null);
|
|
|
|
const [ initialVirtualBackground ] = useState(_virtualBackground);
|
2021-06-10 12:48:44 +00:00
|
|
|
const deleteStoredImage = useCallback(e => {
|
|
|
|
const imageId = e.currentTarget.getAttribute('data-imageid');
|
|
|
|
|
|
|
|
setStoredImages(storedImages.filter(item => item.id !== imageId));
|
|
|
|
}, [ storedImages ]);
|
|
|
|
|
|
|
|
const deleteStoredImageKeyPress = useCallback(e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
deleteStoredImage(e);
|
|
|
|
}
|
|
|
|
}, [ deleteStoredImage ]);
|
2021-03-24 16:32:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates stored images on local storage.
|
|
|
|
*/
|
|
|
|
useEffect(() => {
|
2021-04-09 12:17:06 +00:00
|
|
|
try {
|
|
|
|
jitsiLocalStorage.setItem('virtualBackgrounds', JSON.stringify(storedImages));
|
|
|
|
} catch (err) {
|
|
|
|
// Preventing localStorage QUOTA_EXCEEDED_ERR
|
2021-06-10 12:48:44 +00:00
|
|
|
err && setStoredImages(storedImages.slice(1));
|
2021-04-09 12:17:06 +00:00
|
|
|
}
|
2021-09-10 07:00:54 +00:00
|
|
|
if (storedImages.length === BACKGROUNDS_LIMIT) {
|
2021-06-10 12:48:44 +00:00
|
|
|
setStoredImages(storedImages.slice(1));
|
2021-03-24 16:32:45 +00:00
|
|
|
}
|
2021-07-08 17:20:12 +00:00
|
|
|
}, [ storedImages ]);
|
2021-03-24 16:32:45 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const enableBlur = useCallback(async () => {
|
2021-05-06 06:54:23 +00:00
|
|
|
setOptions({
|
2021-05-26 11:53:14 +00:00
|
|
|
backgroundType: VIRTUAL_BACKGROUND_TYPE.BLUR,
|
2021-05-06 06:54:23 +00:00
|
|
|
enabled: true,
|
2021-06-10 12:48:44 +00:00
|
|
|
blurValue: 25,
|
|
|
|
selectedThumbnail: 'blur'
|
2021-05-06 06:54:23 +00:00
|
|
|
});
|
2022-07-14 07:10:08 +00:00
|
|
|
logger.info('"Blur" option set for virtual background preview!');
|
2021-07-14 15:23:40 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
}, []);
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const enableBlurKeyPress = useCallback(e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
enableBlur();
|
|
|
|
}
|
|
|
|
}, [ enableBlur ]);
|
|
|
|
|
|
|
|
const enableSlideBlur = useCallback(async () => {
|
2021-05-06 06:54:23 +00:00
|
|
|
setOptions({
|
2021-06-10 12:48:44 +00:00
|
|
|
backgroundType: VIRTUAL_BACKGROUND_TYPE.BLUR,
|
|
|
|
enabled: true,
|
|
|
|
blurValue: 8,
|
|
|
|
selectedThumbnail: 'slight-blur'
|
2021-05-06 06:54:23 +00:00
|
|
|
});
|
2022-07-14 07:10:08 +00:00
|
|
|
logger.info('"Slight-blur" option set for virtual background preview!');
|
2021-07-14 15:23:40 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const enableSlideBlurKeyPress = useCallback(e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
enableSlideBlur();
|
|
|
|
}
|
|
|
|
}, [ enableSlideBlur ]);
|
2021-03-24 16:32:45 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
const shareDesktop = useCallback(async () => {
|
2021-10-28 07:17:46 +00:00
|
|
|
if (disableScreensharingVirtualBackground) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-20 02:17:52 +00:00
|
|
|
let isCancelled = false, url;
|
|
|
|
|
|
|
|
try {
|
|
|
|
url = await createLocalTrack('desktop', '');
|
|
|
|
} catch (e) {
|
|
|
|
if (e.name === JitsiTrackErrors.SCREENSHARING_USER_CANCELED) {
|
|
|
|
isCancelled = true;
|
|
|
|
} else {
|
|
|
|
logger.error(e);
|
|
|
|
}
|
|
|
|
}
|
2021-05-14 14:53:11 +00:00
|
|
|
|
2021-05-26 11:53:14 +00:00
|
|
|
if (!url) {
|
2021-06-20 02:17:52 +00:00
|
|
|
if (!isCancelled) {
|
|
|
|
dispatch(showErrorNotification({
|
|
|
|
titleKey: 'virtualBackground.desktopShareError'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
|
2021-06-20 02:17:52 +00:00
|
|
|
logger.error('Could not create desktop share as a virtual background!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For electron createLocalTrack will open the {@code DesktopPicker} dialog and hide the
|
|
|
|
* {@code VirtualBackgroundDialog}. That's why we need to reopen the {@code VirtualBackgroundDialog}
|
|
|
|
* and restore the current state through {@code initialOptions} prop.
|
|
|
|
*/
|
|
|
|
if (browser.isElectron()) {
|
|
|
|
dispatch(openDialog(VirtualBackgroundDialog, { initialOptions: options }));
|
|
|
|
}
|
2021-05-26 16:01:00 +00:00
|
|
|
|
|
|
|
return;
|
2021-05-26 11:53:14 +00:00
|
|
|
}
|
2021-06-20 02:17:52 +00:00
|
|
|
|
|
|
|
const newOptions = {
|
2021-05-26 11:53:14 +00:00
|
|
|
backgroundType: VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE,
|
2021-05-13 14:38:23 +00:00
|
|
|
enabled: true,
|
2021-06-10 12:48:44 +00:00
|
|
|
selectedThumbnail: 'desktop-share',
|
2021-05-14 14:53:11 +00:00
|
|
|
url
|
2021-06-20 02:17:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For electron createLocalTrack will open the {@code DesktopPicker} dialog and hide the
|
|
|
|
* {@code VirtualBackgroundDialog}. That's why we need to reopen the {@code VirtualBackgroundDialog}
|
|
|
|
* and force it to show desktop share virtual background through {@code initialOptions} prop.
|
|
|
|
*/
|
|
|
|
if (browser.isElectron()) {
|
|
|
|
dispatch(openDialog(VirtualBackgroundDialog, { initialOptions: newOptions }));
|
|
|
|
} else {
|
|
|
|
setOptions(newOptions);
|
2022-07-14 07:10:08 +00:00
|
|
|
logger.info('"Desktop-share" option set for virtual background preview!');
|
2021-06-20 02:17:52 +00:00
|
|
|
}
|
|
|
|
}, [ dispatch, options ]);
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
const shareDesktopKeyPress = useCallback(e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
shareDesktop();
|
|
|
|
}
|
|
|
|
}, [ shareDesktop ]);
|
2021-05-13 14:38:23 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const removeBackground = useCallback(async () => {
|
2021-05-06 06:54:23 +00:00
|
|
|
setOptions({
|
2021-06-10 12:48:44 +00:00
|
|
|
enabled: false,
|
|
|
|
selectedThumbnail: 'none'
|
2021-05-06 06:54:23 +00:00
|
|
|
});
|
2022-07-14 07:10:08 +00:00
|
|
|
logger.info('"None" option set for virtual background preview!');
|
2021-07-14 15:23:40 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
}, []);
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const removeBackgroundKeyPress = useCallback(e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
removeBackground();
|
|
|
|
}
|
|
|
|
}, [ removeBackground ]);
|
2021-04-09 12:17:06 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const setUploadedImageBackground = useCallback(async e => {
|
|
|
|
const imageId = e.currentTarget.getAttribute('data-imageid');
|
|
|
|
const image = storedImages.find(img => img.id === imageId);
|
|
|
|
|
|
|
|
if (image) {
|
|
|
|
setOptions({
|
|
|
|
backgroundType: 'image',
|
|
|
|
enabled: true,
|
|
|
|
url: image.src,
|
|
|
|
selectedThumbnail: image.id
|
|
|
|
});
|
2022-07-14 07:10:08 +00:00
|
|
|
logger.info('Uploaded image set for virtual background preview!');
|
2021-06-10 12:48:44 +00:00
|
|
|
}
|
|
|
|
}, [ storedImages ]);
|
|
|
|
|
|
|
|
const setImageBackground = useCallback(async e => {
|
|
|
|
const imageId = e.currentTarget.getAttribute('data-imageid');
|
2021-09-10 07:00:54 +00:00
|
|
|
const image = _images.find(img => img.id === imageId);
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
if (image) {
|
2021-09-10 07:00:54 +00:00
|
|
|
try {
|
|
|
|
const url = await toDataURL(image.src);
|
|
|
|
|
|
|
|
setOptions({
|
|
|
|
backgroundType: 'image',
|
|
|
|
enabled: true,
|
|
|
|
url,
|
|
|
|
selectedThumbnail: image.id
|
|
|
|
});
|
|
|
|
logger.info('Image set for virtual background preview!');
|
|
|
|
} catch (err) {
|
|
|
|
logger.error('Could not fetch virtual background image:', err);
|
|
|
|
}
|
2021-07-14 15:23:40 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
setLoading(false);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const setImageBackgroundKeyPress = useCallback(e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
setImageBackground(e);
|
|
|
|
}
|
|
|
|
}, [ setImageBackground ]);
|
|
|
|
|
|
|
|
const setUploadedImageBackgroundKeyPress = useCallback(e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
setUploadedImageBackground(e);
|
|
|
|
}
|
|
|
|
}, [ setUploadedImageBackground ]);
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const applyVirtualBackground = useCallback(async () => {
|
2021-05-19 09:57:11 +00:00
|
|
|
if (activeDesktopVideo) {
|
|
|
|
await activeDesktopVideo.dispose();
|
|
|
|
}
|
2021-06-10 12:48:44 +00:00
|
|
|
setLoading(true);
|
2021-05-06 06:54:23 +00:00
|
|
|
await dispatch(toggleBackgroundEffect(options, _jitsiTrack));
|
2021-06-10 12:48:44 +00:00
|
|
|
await setLoading(false);
|
2021-07-08 17:20:12 +00:00
|
|
|
if (_localFlipX && options.backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
|
|
|
|
dispatch(updateSettings({
|
|
|
|
localFlipX: !_localFlipX
|
|
|
|
}));
|
2021-07-12 11:28:11 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Set x scale to default value.
|
|
|
|
dispatch(updateSettings({
|
|
|
|
localFlipX: true
|
|
|
|
}));
|
2021-07-08 17:20:12 +00:00
|
|
|
}
|
2021-05-06 06:54:23 +00:00
|
|
|
dispatch(hideDialog());
|
2021-07-14 15:23:40 +00:00
|
|
|
logger.info(`Virtual background type: '${typeof options.backgroundType === 'undefined'
|
|
|
|
? 'none' : options.backgroundType}' applied!`);
|
2021-11-17 14:33:03 +00:00
|
|
|
dispatch(virtualBackgroundTrackChanged());
|
2021-07-08 17:20:12 +00:00
|
|
|
}, [ dispatch, options, _localFlipX ]);
|
2021-05-06 06:54:23 +00:00
|
|
|
|
2021-06-18 14:18:05 +00:00
|
|
|
// Prevent the selection of a new virtual background if it has not been applied by default
|
|
|
|
const cancelVirtualBackground = useCallback(async () => {
|
|
|
|
await setOptions({
|
|
|
|
backgroundType: initialVirtualBackground.backgroundType,
|
|
|
|
enabled: initialVirtualBackground.backgroundEffectEnabled,
|
|
|
|
url: initialVirtualBackground.virtualSource,
|
|
|
|
selectedThumbnail: initialVirtualBackground.selectedThumbnail,
|
|
|
|
blurValue: initialVirtualBackground.blurValue
|
|
|
|
});
|
|
|
|
dispatch(hideDialog());
|
|
|
|
});
|
|
|
|
|
2021-08-26 13:33:43 +00:00
|
|
|
const loadedPreviewState = useCallback(async loaded => {
|
|
|
|
await setPreviewIsLoaded(loaded);
|
|
|
|
});
|
|
|
|
|
2021-02-18 15:52:47 +00:00
|
|
|
return (
|
|
|
|
<Dialog
|
2021-05-06 06:54:23 +00:00
|
|
|
hideCancelButton = { false }
|
|
|
|
okKey = { 'virtualBackground.apply' }
|
2021-06-18 14:18:05 +00:00
|
|
|
onCancel = { cancelVirtualBackground }
|
2021-05-06 06:54:23 +00:00
|
|
|
onSubmit = { applyVirtualBackground }
|
2021-08-26 13:33:43 +00:00
|
|
|
submitDisabled = { !options || loading || !previewIsLoaded }
|
2021-05-20 15:12:39 +00:00
|
|
|
titleKey = { 'virtualBackground.title' } >
|
2021-08-26 13:33:43 +00:00
|
|
|
<VirtualBackgroundPreview
|
|
|
|
loadedPreview = { loadedPreviewState }
|
|
|
|
options = { options } />
|
2021-03-24 16:32:45 +00:00
|
|
|
{loading ? (
|
2022-03-29 09:07:55 +00:00
|
|
|
<div className = { classes.virtualBackgroundLoading }>
|
2021-03-24 16:32:45 +00:00
|
|
|
<Spinner
|
|
|
|
isCompleting = { false }
|
|
|
|
size = 'medium' />
|
|
|
|
</div>
|
|
|
|
) : (
|
2022-07-12 13:18:07 +00:00
|
|
|
<div className = { classes.container }>
|
2021-09-10 07:00:54 +00:00
|
|
|
{_showUploadButton
|
|
|
|
&& <UploadImageButton
|
|
|
|
setLoading = { setLoading }
|
|
|
|
setOptions = { setOptions }
|
|
|
|
setStoredImages = { setStoredImages }
|
|
|
|
showLabel = { previewIsLoaded }
|
|
|
|
storedImages = { storedImages } />}
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
2022-03-29 09:07:55 +00:00
|
|
|
className = { clsx(classes.dialog, { [classes.dialogMarginTop]: previewIsLoaded }) }
|
2021-06-10 12:48:44 +00:00
|
|
|
role = 'radiogroup'
|
|
|
|
tabIndex = '-1'>
|
|
|
|
<Tooltip
|
|
|
|
content = { t('virtualBackground.removeBackground') }
|
|
|
|
position = { 'top' }>
|
|
|
|
<div
|
|
|
|
aria-checked = { _selectedThumbnail === 'none' }
|
|
|
|
aria-label = { t('virtualBackground.removeBackground') }
|
2022-03-29 09:07:55 +00:00
|
|
|
className = { clsx('background-option', 'virtual-background-none', {
|
|
|
|
'none-selected': _selectedThumbnail === 'none'
|
|
|
|
}) }
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { removeBackground }
|
|
|
|
onKeyPress = { removeBackgroundKeyPress }
|
|
|
|
role = 'radio'
|
|
|
|
tabIndex = { 0 } >
|
|
|
|
{t('virtualBackground.none')}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip
|
|
|
|
content = { t('virtualBackground.slightBlur') }
|
|
|
|
position = { 'top' }>
|
|
|
|
<div
|
|
|
|
aria-checked = { _selectedThumbnail === 'slight-blur' }
|
|
|
|
aria-label = { t('virtualBackground.slightBlur') }
|
2022-03-29 09:07:55 +00:00
|
|
|
className = { clsx('background-option', 'slight-blur', {
|
|
|
|
'slight-blur-selected': _selectedThumbnail === 'slight-blur'
|
|
|
|
}) }
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { enableSlideBlur }
|
|
|
|
onKeyPress = { enableSlideBlurKeyPress }
|
|
|
|
role = 'radio'
|
|
|
|
tabIndex = { 0 }>
|
|
|
|
{t('virtualBackground.slightBlur')}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip
|
|
|
|
content = { t('virtualBackground.blur') }
|
|
|
|
position = { 'top' }>
|
|
|
|
<div
|
|
|
|
aria-checked = { _selectedThumbnail === 'blur' }
|
|
|
|
aria-label = { t('virtualBackground.blur') }
|
2022-03-29 09:07:55 +00:00
|
|
|
className = { clsx('background-option', 'blur', {
|
|
|
|
'blur-selected': _selectedThumbnail === 'blur'
|
|
|
|
}) }
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { enableBlur }
|
|
|
|
onKeyPress = { enableBlurKeyPress }
|
|
|
|
role = 'radio'
|
|
|
|
tabIndex = { 0 }>
|
|
|
|
{t('virtualBackground.blur')}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2021-10-28 07:17:46 +00:00
|
|
|
{!disableScreensharingVirtualBackground && (
|
|
|
|
<Tooltip
|
|
|
|
content = { t('virtualBackground.desktopShare') }
|
|
|
|
position = { 'top' }>
|
|
|
|
<div
|
|
|
|
aria-checked = { _selectedThumbnail === 'desktop-share' }
|
|
|
|
aria-label = { t('virtualBackground.desktopShare') }
|
2022-03-29 09:07:55 +00:00
|
|
|
className = { clsx('background-option', 'desktop-share', {
|
|
|
|
'desktop-share-selected': _selectedThumbnail === 'desktop-share'
|
|
|
|
}) }
|
2021-10-28 07:17:46 +00:00
|
|
|
onClick = { shareDesktop }
|
|
|
|
onKeyPress = { shareDesktopKeyPress }
|
|
|
|
role = 'radio'
|
|
|
|
tabIndex = { 0 }>
|
|
|
|
<Icon
|
|
|
|
className = 'share-desktop-icon'
|
|
|
|
size = { 30 }
|
|
|
|
src = { IconShareDesktop } />
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2021-09-10 07:00:54 +00:00
|
|
|
{_images.map(image => (
|
2021-06-10 12:48:44 +00:00
|
|
|
<Tooltip
|
|
|
|
content = { image.tooltip && t(`virtualBackground.${image.tooltip}`) }
|
|
|
|
key = { image.id }
|
|
|
|
position = { 'top' }>
|
|
|
|
<img
|
|
|
|
alt = { image.tooltip && t(`virtualBackground.${image.tooltip}`) }
|
|
|
|
aria-checked = { options.selectedThumbnail === image.id
|
|
|
|
|| _selectedThumbnail === image.id }
|
|
|
|
className = {
|
|
|
|
options.selectedThumbnail === image.id || _selectedThumbnail === image.id
|
|
|
|
? 'background-option thumbnail-selected' : 'background-option thumbnail' }
|
|
|
|
data-imageid = { image.id }
|
|
|
|
onClick = { setImageBackground }
|
|
|
|
onError = { onError }
|
|
|
|
onKeyPress = { setImageBackgroundKeyPress }
|
|
|
|
role = 'radio'
|
|
|
|
src = { image.src }
|
|
|
|
tabIndex = { 0 } />
|
|
|
|
</Tooltip>
|
2021-03-24 16:32:45 +00:00
|
|
|
))}
|
|
|
|
{storedImages.map((image, index) => (
|
|
|
|
<div
|
|
|
|
className = { 'thumbnail-container' }
|
2021-06-10 12:48:44 +00:00
|
|
|
key = { image.id }>
|
2021-03-24 16:32:45 +00:00
|
|
|
<img
|
2021-06-10 12:48:44 +00:00
|
|
|
alt = { t('virtualBackground.uploadedImage', { index: index + 1 }) }
|
|
|
|
aria-checked = { _selectedThumbnail === image.id }
|
2022-03-29 09:07:55 +00:00
|
|
|
className = { clsx('background-option', {
|
|
|
|
'thumbnail-selected': _selectedThumbnail === image.id,
|
|
|
|
'thumbnail': _selectedThumbnail !== image.id
|
|
|
|
}) }
|
2021-06-10 12:48:44 +00:00
|
|
|
data-imageid = { image.id }
|
|
|
|
onClick = { setUploadedImageBackground }
|
|
|
|
onError = { onError }
|
|
|
|
onKeyPress = { setUploadedImageBackgroundKeyPress }
|
|
|
|
role = 'radio'
|
|
|
|
src = { image.src }
|
|
|
|
tabIndex = { 0 } />
|
|
|
|
|
2021-03-24 16:32:45 +00:00
|
|
|
<Icon
|
2021-06-10 12:48:44 +00:00
|
|
|
ariaLabel = { t('virtualBackground.deleteImage') }
|
2021-03-24 16:32:45 +00:00
|
|
|
className = { 'delete-image-icon' }
|
2021-06-10 12:48:44 +00:00
|
|
|
data-imageid = { image.id }
|
|
|
|
onClick = { deleteStoredImage }
|
|
|
|
onKeyPress = { deleteStoredImageKeyPress }
|
|
|
|
role = 'button'
|
2021-03-24 16:32:45 +00:00
|
|
|
size = { 15 }
|
2021-06-10 12:48:44 +00:00
|
|
|
src = { IconCloseSmall }
|
|
|
|
tabIndex = { 0 } />
|
2021-03-24 16:32:45 +00:00
|
|
|
</div>
|
|
|
|
))}
|
2021-02-18 15:52:47 +00:00
|
|
|
</div>
|
2021-03-24 16:32:45 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2021-02-18 15:52:47 +00:00
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-20 02:17:52 +00:00
|
|
|
export default VirtualBackgroundDialog;
|