2022-08-25 11:35:19 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2021-03-24 16:32:45 +00:00
|
|
|
import Spinner from '@atlaskit/spinner';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-06-02 19:21:39 +00:00
|
|
|
import Bourne from '@hapi/bourne';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-03-24 16:32:45 +00:00
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils/jitsi-local-storage';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
2022-09-27 07:10:28 +00:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../app/types';
|
2022-10-11 08:24:11 +00:00
|
|
|
import { getMultipleVideoSendingSupportFeatureFlag } from '../../base/config/functions.any';
|
|
|
|
import { hideDialog } from '../../base/dialog/actions';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { translate } from '../../base/i18n/functions';
|
|
|
|
import Icon from '../../base/icons/components/Icon';
|
2022-10-07 20:51:43 +00:00
|
|
|
import { IconCloseSmall } from '../../base/icons/svg';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { connect } from '../../base/redux/functions';
|
2022-10-11 08:24:11 +00:00
|
|
|
import { updateSettings } from '../../base/settings/actions';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-06-10 12:48:44 +00:00
|
|
|
import { Tooltip } from '../../base/tooltip';
|
2022-10-11 08:24:11 +00:00
|
|
|
import { getLocalVideoTrack } from '../../base/tracks/functions';
|
|
|
|
import Dialog from '../../base/ui/components/web/Dialog';
|
2022-10-07 21:15:48 +00:00
|
|
|
import { toggleBackgroundEffect } from '../actions';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { BACKGROUNDS_LIMIT, IMAGES, type Image, VIRTUAL_BACKGROUND_TYPE } from '../constants';
|
2021-09-10 07:00:54 +00:00
|
|
|
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';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-05-06 06:54:23 +00:00
|
|
|
import VirtualBackgroundPreview from './VirtualBackgroundPreview';
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2021-09-10 07:00:54 +00:00
|
|
|
/**
|
|
|
|
* The list of Images to choose from.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_images: Array<Image>;
|
2021-09-10 07:00:54 +00:00
|
|
|
|
2022-07-06 19:47:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the jitsi track that will have backgraund effect applied.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_jitsiTrack: Object;
|
2022-07-06 19:47:06 +00:00
|
|
|
|
2021-06-24 15:21:34 +00:00
|
|
|
/**
|
|
|
|
* The current local flip x status.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_localFlipX: boolean;
|
2021-06-24 15:21:34 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_multiStreamModeEnabled: boolean;
|
2021-05-06 06:54:23 +00:00
|
|
|
|
2021-04-09 14:25:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the selected thumbnail identifier.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_selectedThumbnail: string;
|
2021-04-09 14:25:26 +00:00
|
|
|
|
2021-09-10 07:00:54 +00:00
|
|
|
/**
|
|
|
|
* If the upload button should be displayed or not.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_showUploadButton: boolean;
|
2021-09-10 07:00:54 +00:00
|
|
|
|
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
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_virtualBackground: any;
|
2021-05-19 09:57:11 +00:00
|
|
|
|
2021-02-18 15:52:47 +00:00
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
dispatch: Function;
|
2021-02-18 15:52:47 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
initialOptions: Object;
|
2022-08-25 11:35:19 +00:00
|
|
|
}
|
2021-02-18 15:52:47 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
const onError = (event: any) => {
|
2021-06-10 12:48:44 +00:00
|
|
|
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}}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function _mapStateToProps(state: IReduxState): 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-09-13 07:36:00 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
2022-03-29 09:07:55 +00:00
|
|
|
return {
|
2022-10-11 08:24:11 +00:00
|
|
|
dialogContainer: {
|
|
|
|
width: 'auto'
|
|
|
|
},
|
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
|
|
|
position: 'relative',
|
|
|
|
maxHeight: '300px',
|
|
|
|
color: 'white',
|
|
|
|
display: 'inline-grid',
|
|
|
|
gridTemplateColumns: 'auto auto auto auto auto',
|
|
|
|
columnGap: '9px',
|
|
|
|
cursor: 'pointer',
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-03-29 09:07:55 +00:00
|
|
|
[[ '& .desktop-share:hover',
|
|
|
|
'& .thumbnail:hover',
|
|
|
|
'& .blur:hover',
|
|
|
|
'& .slight-blur:hover',
|
|
|
|
'& .virtual-background-none:hover' ]]: {
|
|
|
|
opacity: 0.5,
|
|
|
|
border: '2px solid #99bbf3'
|
|
|
|
},
|
|
|
|
'& .background-option': {
|
2022-09-13 07:36:00 +00:00
|
|
|
marginTop: theme.spacing(2),
|
2022-03-29 09:07:55 +00:00
|
|
|
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',
|
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-03-29 09:07:55 +00:00
|
|
|
[[ '& .desktop-share:hover',
|
|
|
|
'& .thumbnail:hover',
|
|
|
|
'& .blur:hover',
|
|
|
|
'& .slight-blur:hover',
|
|
|
|
'& .virtual-background-none:hover' ]]: {
|
|
|
|
height: '60px',
|
|
|
|
width: '60px'
|
|
|
|
},
|
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-03-29 09:07:55 +00:00
|
|
|
[[ '& .desktop-share',
|
|
|
|
'& .virtual-background-none,',
|
|
|
|
'& .thumbnail,',
|
|
|
|
'& .blur,',
|
|
|
|
'& .slight-blur' ]]: {
|
|
|
|
height: '60px',
|
|
|
|
width: '60px'
|
|
|
|
},
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-03-29 09:07:55 +00:00
|
|
|
[[ '& .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,
|
|
|
|
dispatch,
|
|
|
|
initialOptions,
|
|
|
|
t
|
2022-10-20 09:11:27 +00:00
|
|
|
}: IProps) {
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes, cx } = useStyles();
|
2021-08-26 13:33:43 +00:00
|
|
|
const [ previewIsLoaded, setPreviewIsLoaded ] = useState(false);
|
2022-08-25 11:35:19 +00:00
|
|
|
const [ options, setOptions ] = useState<any>({ ...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);
|
2021-06-18 14:18:05 +00:00
|
|
|
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 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 () => {
|
|
|
|
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);
|
2022-10-07 20:51:43 +00:00
|
|
|
|
|
|
|
// Set x scale to default value.
|
|
|
|
dispatch(updateSettings({
|
|
|
|
localFlipX: true
|
|
|
|
}));
|
|
|
|
|
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-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());
|
2022-08-25 11:35:19 +00:00
|
|
|
}, []);
|
2021-06-18 14:18:05 +00:00
|
|
|
|
2021-08-26 13:33:43 +00:00
|
|
|
const loadedPreviewState = useCallback(async loaded => {
|
|
|
|
await setPreviewIsLoaded(loaded);
|
2022-08-25 11:35:19 +00:00
|
|
|
}, []);
|
2021-08-26 13:33:43 +00:00
|
|
|
|
2021-02-18 15:52:47 +00:00
|
|
|
return (
|
|
|
|
<Dialog
|
2022-10-11 08:24:11 +00:00
|
|
|
className = { classes.dialogContainer }
|
|
|
|
ok = {{
|
|
|
|
disabled: !options || loading || !previewIsLoaded,
|
|
|
|
translationKey: 'virtualBackground.apply'
|
|
|
|
}}
|
2021-06-18 14:18:05 +00:00
|
|
|
onCancel = { cancelVirtualBackground }
|
2021-05-06 06:54:23 +00:00
|
|
|
onSubmit = { applyVirtualBackground }
|
2022-10-11 08:24:11 +00:00
|
|
|
size = 'large'
|
|
|
|
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
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-03-24 16:32:45 +00:00
|
|
|
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-09-13 07:36:00 +00:00
|
|
|
className = { cx(classes.dialog, { [classes.dialogMarginTop]: previewIsLoaded }) }
|
2021-06-10 12:48:44 +00:00
|
|
|
role = 'radiogroup'
|
2022-08-25 11:35:19 +00:00
|
|
|
tabIndex = { -1 }>
|
2021-06-10 12:48:44 +00:00
|
|
|
<Tooltip
|
|
|
|
content = { t('virtualBackground.removeBackground') }
|
|
|
|
position = { 'top' }>
|
|
|
|
<div
|
|
|
|
aria-checked = { _selectedThumbnail === 'none' }
|
|
|
|
aria-label = { t('virtualBackground.removeBackground') }
|
2022-09-13 07:36:00 +00:00
|
|
|
className = { cx('background-option', 'virtual-background-none', {
|
2022-03-29 09:07:55 +00:00
|
|
|
'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-09-13 07:36:00 +00:00
|
|
|
className = { cx('background-option', 'slight-blur', {
|
2022-03-29 09:07:55 +00:00
|
|
|
'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-09-13 07:36:00 +00:00
|
|
|
className = { cx('background-option', 'blur', {
|
2022-03-29 09:07:55 +00:00
|
|
|
'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-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-09-13 07:36:00 +00:00
|
|
|
className = { cx('background-option', {
|
2022-03-29 09:07:55 +00:00
|
|
|
'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;
|