Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(virtual-background) Move dialog to SettingsDialog tab (#13005)
Robert Pintilii8982f17ce1d4
diff --git a/lang/main.json b/lang/main.jsonindex dce7185c28..72d8533f7a 100644--- a/lang/main.json+++ b/lang/main.json@@ -1350,7 +1350,7 @@"none": "None","pleaseWait": "Please wait...","removeBackground": "Remove background",- "slightBlur": "Slight Blur",+ "slightBlur": "Half Blur","title": "Virtual backgrounds","uploadedImage": "Uploaded image {{index}}","webAssemblyWarning": "WebAssembly not supported",diff --git a/modules/API/API.js b/modules/API/API.jsindex c86df333ec..27525ec4f6 100644--- a/modules/API/API.js+++ b/modules/API/API.js@@ -106,6 +106,8 @@ import { startAudioScreenShareFlow, startScreenShareFlow } from '../../react/feaimport { isScreenAudioSupported } from '../../react/features/screen-share/functions';import { toggleScreenshotCaptureSummary } from '../../react/features/screenshot-capture';import { isScreenshotCaptureEnabled } from '../../react/features/screenshot-capture/functions';+import SettingsDialog from '../../react/features/settings/components/web/SettingsDialog';+import { SETTINGS_TABS } from '../../react/features/settings/constants';import { playSharedVideo, stopSharedVideo } from '../../react/features/shared-video/actions.any';import { extractYoutubeIdOrURL } from '../../react/features/shared-video/functions';import { setRequestingSubtitles, toggleRequestingSubtitles } from '../../react/features/subtitles/actions';@@ -113,7 +115,6 @@ import { isAudioMuteButtonDisabled } from '../../react/features/toolbox/functionimport { setTileView, toggleTileView } from '../../react/features/video-layout';import { muteAllParticipants } from '../../react/features/video-menu/actions';import { setVideoQuality } from '../../react/features/video-quality';-import VirtualBackgroundDialog from '../../react/features/virtual-background/components/VirtualBackgroundDialog';import { getJitsiMeetTransport } from '../transport';import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';@@ -798,7 +799,8 @@ function initCommands() {APP.store.dispatch(overwriteConfig(whitelistedConfig));},'toggle-virtual-background': () => {- APP.store.dispatch(toggleDialog(VirtualBackgroundDialog));+ APP.store.dispatch(toggleDialog(SettingsDialog, {+ defaultTab: SETTINGS_TABS.VIRTUAL_BACKGROUND }));},'end-conference': () => {APP.store.dispatch(endConference());diff --git a/react/features/base/ui/components/web/DialogWithTabs.tsx b/react/features/base/ui/components/web/DialogWithTabs.tsxindex 1f50425850..eed895f3c1 100644--- a/react/features/base/ui/components/web/DialogWithTabs.tsx+++ b/react/features/base/ui/components/web/DialogWithTabs.tsx@@ -146,6 +146,7 @@ interface IObject {}export interface IDialogTab<P> {+ cancel?: Function;className?: string;component: ComponentType<any>;icon: Function;@@ -214,7 +215,12 @@ const DialogWithTabs = ({}}, [ isMobile, userSelected, selectedTab ]);- const onClose = useCallback(() => {+ const onClose = useCallback((isCancel = true) => {+ if (isCancel) {+ tabs.forEach(({ cancel }) => {+ cancel && dispatch(cancel());+ });+ }dispatch(hideDialog());}, []);@@ -268,7 +274,7 @@ const DialogWithTabs = ({tabs.forEach(({ submit }, idx) => {submit?.(tabStates[idx]);});- onClose();+ onClose(false);}, [ tabs, tabStates ]);const selectedTabIndex = useMemo(() => {diff --git a/react/features/settings/actions.ts b/react/features/settings/actions.tsindex bc07044562..80a6a127e1 100644--- a/react/features/settings/actions.ts+++ b/react/features/settings/actions.ts@@ -11,6 +11,8 @@ import {import { openDialog } from '../base/dialog/actions';import i18next from '../base/i18n/i18next';import { updateSettings } from '../base/settings/actions';+import { toggleBackgroundEffect } from '../virtual-background/actions';+import virtualBackgroundLogger from '../virtual-background/logger';import {SET_AUDIO_SETTINGS_VISIBILITY,@@ -24,7 +26,8 @@ import {getMoreTabProps,getNotificationsTabProps,getProfileTabProps,- getShortcutsTabProps+ getShortcutsTabProps,+ getVirtualBackgroundTabProps} from './functions';/**@@ -249,3 +252,31 @@ export function submitShortcutsTab(newState: any) {}};}++/**+ * Submits the settings from the "Virtual Background" tab of the settings dialog.+ *+ * @param {Object} newState - The new settings.+ * @param {boolean} isCancel - Whether the change represents a cancel.+ * @returns {Function}+ */+export function submitVirtualBackgroundTab(newState: any, isCancel = false) {+ return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {+ const currentState = getVirtualBackgroundTabProps(getState());++ if (newState.options?.selectedThumbnail) {+ await dispatch(toggleBackgroundEffect(newState.options, currentState._jitsiTrack));++ if (!isCancel) {+ // Set x scale to default value.+ dispatch(updateSettings({+ localFlipX: true+ }));++ virtualBackgroundLogger.info(`Virtual background type: '${+ typeof newState.options.backgroundType === 'undefined'+ ? 'none' : newState.options.backgroundType}' applied!`);+ }+ }+ };+}diff --git a/react/features/settings/components/web/SettingsDialog.tsx b/react/features/settings/components/web/SettingsDialog.tsxindex 76e73f4c94..26cd9be3a8 100644--- a/react/features/settings/components/web/SettingsDialog.tsx+++ b/react/features/settings/components/web/SettingsDialog.tsx@@ -8,6 +8,7 @@ import {IconCalendar,IconGear,IconHost,+ IconImage,IconShortcuts,IconUser,IconVideo,@@ -24,12 +25,14 @@ import {getAudioDeviceSelectionDialogProps,getVideoDeviceSelectionDialogProps} from '../../../device-selection/functions.web';+import { checkBlurSupport } from '../../../virtual-background/functions';import {submitModeratorTab,submitMoreTab,submitNotificationsTab,submitProfileTab,- submitShortcutsTab+ submitShortcutsTab,+ submitVirtualBackgroundTab} from '../../actions';import { SETTINGS_TABS } from '../../constants';import {@@ -38,7 +41,8 @@ import {getNotificationsMap,getNotificationsTabProps,getProfileTabProps,- getShortcutsTabProps+ getShortcutsTabProps,+ getVirtualBackgroundTabProps} from '../../functions';// @ts-ignore@@ -48,6 +52,7 @@ import MoreTab from './MoreTab';import NotificationsTab from './NotificationsTab';import ProfileTab from './ProfileTab';import ShortcutsTab from './ShortcutsTab';+import VirtualBackgroundTab from './VirtualBackgroundTab';/*** The type of the React {@code Component} props of@@ -254,6 +259,7 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {const showSoundsSettings = configuredTabs.includes('sounds');const enabledNotifications = getNotificationsMap(state);const showNotificationsSettings = Object.keys(enabledNotifications).length > 0;+ const virtualBackgroundSupported = checkBlurSupport();const tabs: IDialogTab<any>[] = [];if (showDeviceSettings) {@@ -305,12 +311,37 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {});}+ if (virtualBackgroundSupported) {+ tabs.push({+ name: SETTINGS_TABS.VIRTUAL_BACKGROUND,+ component: VirtualBackgroundTab,+ labelKey: 'virtualBackground.title',+ props: getVirtualBackgroundTabProps(state),+ className: `settings-pane ${classes.settingsDialog}`,+ submit: (newState: any) => submitVirtualBackgroundTab(newState),+ cancel: () => {+ const { _virtualBackground } = getVirtualBackgroundTabProps(state);++ return submitVirtualBackgroundTab({+ options: {+ backgroundType: _virtualBackground.backgroundType,+ enabled: _virtualBackground.backgroundEffectEnabled,+ url: _virtualBackground.virtualSource,+ selectedThumbnail: _virtualBackground.selectedThumbnail,+ blurValue: _virtualBackground.blurValue+ }+ }, true);+ },+ icon: IconImage+ });+ }+if (showSoundsSettings || showNotificationsSettings) {tabs.push({name: SETTINGS_TABS.NOTIFICATIONS,component: NotificationsTab,labelKey: 'settings.notifications',- propsUpdateFunction: (tabState: any, newProps: any) => {+ propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getNotificationsTabProps>) => {return {...newProps,enabledNotifications: tabState?.enabledNotifications || {}@@ -373,7 +404,7 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {component: ShortcutsTab,labelKey: 'settings.shortcuts',props: getShortcutsTabProps(state, isDisplayedOnWelcomePage),- propsUpdateFunction: (tabState: any, newProps: any) => {+ propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getShortcutsTabProps>) => {// Updates tab props, keeping users selectionreturn {diff --git a/react/features/settings/components/web/VirtualBackgroundTab.tsx b/react/features/settings/components/web/VirtualBackgroundTab.tsxnew file mode 100644index 0000000000..83c6d7d5c0--- /dev/null+++ b/react/features/settings/components/web/VirtualBackgroundTab.tsx@@ -0,0 +1,107 @@+import { withStyles } from '@mui/styles';+import React from 'react';+import { WithTranslation } from 'react-i18next';++import AbstractDialogTab, {+ IProps as AbstractDialogTabProps+} from '../../../base/dialog/components/web/AbstractDialogTab';+import { translate } from '../../../base/i18n/functions';+import VirtualBackgrounds from '../../../virtual-background/components/VirtualBackgrounds';++/**+ * The type of the React {@code Component} props of {@link VirtualBackgroundTab}.+ */+export interface IProps extends AbstractDialogTabProps, WithTranslation {++ /**+ * Returns the jitsi track that will have background effect applied.+ */+ _jitsiTrack: Object;++ /**+ * CSS classes object.+ */+ classes: any;++ /**+ * Virtual background options.+ */+ options: any;++ /**+ * The selected thumbnail identifier.+ */+ selectedThumbnail: string;+}++const styles = () => {+ return {+ container: {+ width: '100%',+ display: 'flex',+ flexDirection: 'column' as const+ }+ };+};++/**+ * React {@code Component} for modifying language and moderator settings.+ *+ * @augments Component+ */+class VirtualBackgroundTab extends AbstractDialogTab<IProps, any> {+ /**+ * Initializes a new {@code ModeratorTab} instance.+ *+ * @param {Object} props - The read-only properties with which the new+ * instance is to be initialized.+ */+ constructor(props: IProps) {+ super(props);++ // Bind event handler so it is only bound once for every instance.+ this._onOptionsChanged = this._onOptionsChanged.bind(this);+ }++ /**+ * Callback invoked to select if follow-me mode+ * should be activated.+ *+ * @param {Object} options - The new background options.+ *+ * @returns {void}+ */+ _onOptionsChanged(options: any) {+ super._onChange({ options });+ }++ /**+ * Implements React's {@link Component#render()}.+ *+ * @inheritdoc+ * @returns {ReactElement}+ */+ render() {+ const {+ classes,+ options,+ selectedThumbnail,+ _jitsiTrack+ } = this.props;++ return (+ <div+ className = { classes.container }+ id = 'virtual-background-dialog'+ key = 'virtual-background'>+ <VirtualBackgrounds+ _jitsiTrack = { _jitsiTrack }+ onOptionsChange = { this._onOptionsChanged }+ options = { options }+ selectedThumbnail = { selectedThumbnail } />+ </div>+ );+ }+}++export default withStyles(styles)(translate(VirtualBackgroundTab));diff --git a/react/features/settings/components/web/video/VideoSettingsContent.tsx b/react/features/settings/components/web/video/VideoSettingsContent.tsxindex 3837835900..4378f26084 100644--- a/react/features/settings/components/web/video/VideoSettingsContent.tsx+++ b/react/features/settings/components/web/video/VideoSettingsContent.tsx@@ -3,7 +3,6 @@ import { WithTranslation } from 'react-i18next';import { connect } from 'react-redux';import { IReduxState, IStore } from '../../../../app/types';-import { openDialog } from '../../../../base/dialog/actions';import { translate } from '../../../../base/i18n/functions';import { IconImage } from '../../../../base/icons/svg';import Video from '../../../../base/media/components/Video.web';@@ -13,7 +12,8 @@ import Checkbox from '../../../../base/ui/components/web/Checkbox';import ContextMenu from '../../../../base/ui/components/web/ContextMenu';import ContextMenuItem from '../../../../base/ui/components/web/ContextMenuItem';import ContextMenuItemGroup from '../../../../base/ui/components/web/ContextMenuItemGroup';-import VirtualBackgroundDialog from '../../../../virtual-background/components/VirtualBackgroundDialog';+import { openSettingsDialog } from '../../../actions';+import { SETTINGS_TABS } from '../../../constants';import { createLocalVideoTracks } from '../../../functions.web';const videoClassName = 'video-preview-video flipVideoX';@@ -297,7 +297,7 @@ const mapStateToProps = (state: IReduxState) => {const mapDispatchToProps = (dispatch: IStore['dispatch']) => {return {- selectBackground: () => dispatch(openDialog(VirtualBackgroundDialog)),+ selectBackground: () => dispatch(openSettingsDialog(SETTINGS_TABS.VIRTUAL_BACKGROUND)),changeFlip: (flip: boolean) => {dispatch(updateSettings({localFlipX: flipdiff --git a/react/features/settings/constants.ts b/react/features/settings/constants.tsindex 69911a5e25..d71c27e00c 100644--- a/react/features/settings/constants.ts+++ b/react/features/settings/constants.ts@@ -6,7 +6,8 @@ export const SETTINGS_TABS = {NOTIFICATIONS: 'notifications_tab',PROFILE: 'profile_tab',SHORTCUTS: 'shortcuts_tab',- VIDEO: 'video_tab'+ VIDEO: 'video_tab',+ VIRTUAL_BACKGROUND: 'virtual-background_tab'};/**diff --git a/react/features/settings/functions.any.ts b/react/features/settings/functions.any.tsindex 4e0276da3e..33445ad9a6 100644--- a/react/features/settings/functions.any.ts+++ b/react/features/settings/functions.any.ts@@ -12,6 +12,7 @@ import {} from '../base/participants/functions';import { toState } from '../base/redux/functions';import { getHideSelfView } from '../base/settings/functions';+import { getLocalVideoTrack } from '../base/tracks/functions.any';import { parseStandardURIString } from '../base/util/uri';import { isStageFilmstripEnabled } from '../filmstrip/functions';import { isFollowMeActive } from '../follow-me/functions';@@ -293,3 +294,22 @@ export function getShortcutsTabProps(stateful: IStateful, isDisplayedOnWelcomePakeyboardShortcutsEnabled: keyboardShortcut.getEnabled()};}++/**+ * Returns the properties for the "Virtual Background" tab from settings dialog from Redux+ * state.+ *+ * @param {(Function|Object)} stateful -The (whole) redux state, or redux's+ * {@code getState} function to be used to retrieve the state.+ * @returns {Object} - The properties for the "Shortcuts" tab from settings+ * dialog.+ */+export function getVirtualBackgroundTabProps(stateful: IStateful) {+ const state = toState(stateful);++ return {+ _virtualBackground: state['features/virtual-background'],+ selectedThumbnail: state['features/virtual-background'].selectedThumbnail,+ _jitsiTrack: getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack+ };+}diff --git a/react/features/virtual-background/components/UploadImageButton.tsx b/react/features/virtual-background/components/UploadImageButton.tsxindex e4310ded64..98c323ef1b 100644--- a/react/features/virtual-background/components/UploadImageButton.tsx+++ b/react/features/virtual-background/components/UploadImageButton.tsx@@ -6,6 +6,7 @@ import { v4 as uuidv4 } from 'uuid';import { translate } from '../../base/i18n/functions';import Icon from '../../base/icons/components/Icon';import { IconPlus } from '../../base/icons/svg';+import { withPixelLineHeight } from '../../base/styles/functions.web';import { type Image, VIRTUAL_BACKGROUND_TYPE } from '../constants';import { resizeImage } from '../functions';import logger from '../logger';@@ -40,24 +41,25 @@ interface IProps extends WithTranslation {const useStyles = makeStyles()(theme => {return {+ label: {+ ...withPixelLineHeight(theme.typography.bodyShortBold),+ color: theme.palette.link01,+ marginBottom: theme.spacing(3),+ cursor: 'pointer',+ display: 'flex',+ alignItems: 'center'+ },+addBackground: {- marginRight: theme.spacing(2),+ marginRight: theme.spacing(3),+'& svg': {- fill: '#669aec !important'+ fill: `${theme.palette.link01} !important`}},- button: {++ input: {display: 'none'- },- label: {- fontSize: '14px',- fontWeight: 600,- lineHeight: '20px',- marginTop: theme.spacing(3),- marginBottom: theme.spacing(2),- color: '#669aec',- display: 'inline-flex',- cursor: 'pointer'}};});@@ -127,14 +129,14 @@ function UploadImageButton({tabIndex = { 0 } ><IconclassName = { classes.addBackground }- size = { 20 }+ size = { 24 }src = { IconPlus } />{t('virtualBackground.addBackground')}</label>}<inputaccept = 'image/*'- className = { classes.button }+ className = { classes.input }id = 'file-upload'onChange = { uploadImage }ref = { uploadImageButton }diff --git a/react/features/virtual-background/components/VideoBackgroundButton.js b/react/features/virtual-background/components/VideoBackgroundButton.jsindex ff174dd892..16729a5cb9 100644--- a/react/features/virtual-background/components/VideoBackgroundButton.js+++ b/react/features/virtual-background/components/VideoBackgroundButton.js@@ -1,15 +1,14 @@// @flow-import { openDialog } from '../../base/dialog';import { translate } from '../../base/i18n';import { IconImage } from '../../base/icons';import { connect } from '../../base/redux';import { AbstractButton } from '../../base/toolbox/components';import type { AbstractButtonProps } from '../../base/toolbox/components';+import { openSettingsDialog } from '../../settings/actions';+import { SETTINGS_TABS } from '../../settings/constants';import { checkBlurSupport } from '../functions';-import { VirtualBackgroundDialog } from './index';-/*** The type of the React {@code Component} props of {@link VideoBackgroundButton}.*/@@ -45,7 +44,7 @@ class VideoBackgroundButton extends AbstractButton<Props, *> {_handleClick() {const { dispatch } = this.props;- dispatch(openDialog(VirtualBackgroundDialog));+ dispatch(openSettingsDialog(SETTINGS_TABS.VIRTUAL_BACKGROUND));}/**diff --git a/react/features/virtual-background/components/VirtualBackgroundPreview.tsx b/react/features/virtual-background/components/VirtualBackgroundPreview.tsxindex 9dffea444f..deb77632d3 100644--- a/react/features/virtual-background/components/VirtualBackgroundPreview.tsx+++ b/react/features/virtual-background/components/VirtualBackgroundPreview.tsx@@ -8,8 +8,6 @@ import { connect } from 'react-redux';import { IReduxState } from '../../app/types';import { hideDialog } from '../../base/dialog/actions';import { translate } from '../../base/i18n/functions';-// eslint-disable-next-line lines-around-comment-// @ts-ignoreimport Video from '../../base/media/components/Video';import { equals } from '../../base/redux/functions';import { getCurrentCameraDeviceId } from '../../base/settings/functions.web';@@ -83,39 +81,28 @@ interface IState {const styles = (theme: Theme) => {return {virtualBackgroundPreview: {- '& .video-preview': {- height: '250px'- },-- '& .video-background-preview-entry': {- height: '250px',- width: '570px',- marginBottom: theme.spacing(2),- zIndex: 2,-- '@media (max-width: 632px)': {- maxWidth: '336px'- }- },+ height: 'auto',+ width: '100%',+ overflow: 'hidden',+ marginBottom: theme.spacing(3),+ zIndex: 2,+ borderRadius: '3px',+ backgroundColor: theme.palette.uiBackground,+ position: 'relative' as const,'& .video-preview-loader': {- borderRadius: '6px',- backgroundColor: 'transparent',- height: '250px',- marginBottom: theme.spacing(2),- width: '572px',- position: 'fixed',- zIndex: 2,+ height: '220px','& svg': {- position: 'absolute',+ position: 'absolute' as const,top: '40%',left: '45%'- },-- '@media (min-width: 432px) and (max-width: 632px)': {- width: '340px'}+ },++ '& .video-preview-error': {+ height: '220px',+ position: 'relative'}}};@@ -238,31 +225,21 @@ class VirtualBackgroundPreview extends PureComponent<IProps, IState> {*/_renderPreviewEntry(data: Object) {const { t } = this.props;- const className = 'video-background-preview-entry';if (this.state.loading) {return this._loadVideoPreview();}if (!data) {return (- <div- className = { className }- video-preview-container = { true }>- <div className = 'video-preview-error'>{t('deviceSelection.previewUnavailable')}</div>- </div>+ <div className = 'video-preview-error'>{t('deviceSelection.previewUnavailable')}</div>);}- const props: Object = {- className- };return (- <div { ...props }>- <Video- className = { videoClassName }- playsinline = { true }- videoTrack = {{ jitsiTrack: data }} />- </div>+ <Video+ className = { videoClassName }+ playsinline = { true }+ videoTrack = {{ jitsiTrack: data }} />);}@@ -310,8 +287,8 @@ class VirtualBackgroundPreview extends PureComponent<IProps, IState> {return (<div className = { classes.virtualBackgroundPreview }>{jitsiTrack- ? <div className = 'video-preview'>{this._renderPreviewEntry(jitsiTrack)}</div>- : <div className = 'video-preview-loader'>{this._loadVideoPreview()}</div>+ ? this._renderPreviewEntry(jitsiTrack)+ : this._loadVideoPreview()}</div>);}}diff --git a/react/features/virtual-background/components/VirtualBackgroundDialog.tsx b/react/features/virtual-background/components/VirtualBackgrounds.tsxsimilarity index 58%rename from react/features/virtual-background/components/VirtualBackgroundDialog.tsxrename to react/features/virtual-background/components/VirtualBackgrounds.tsxindex d3b9a35444..dc412f8413 100644--- a/react/features/virtual-background/components/VirtualBackgroundDialog.tsx+++ b/react/features/virtual-background/components/VirtualBackgrounds.tsx@@ -6,27 +6,22 @@ import Bourne from '@hapi/bourne';import { jitsiLocalStorage } from '@jitsi/js-utils/jitsi-local-storage';import React, { useCallback, useEffect, useState } from 'react';import { WithTranslation } from 'react-i18next';+import { connect } from 'react-redux';import { makeStyles } from 'tss-react/mui';import { IReduxState } from '../../app/types';import { getMultipleVideoSendingSupportFeatureFlag } from '../../base/config/functions.any';-import { hideDialog } from '../../base/dialog/actions';import { translate } from '../../base/i18n/functions';import Icon from '../../base/icons/components/Icon';import { IconCloseLarge } from '../../base/icons/svg';-import { connect } from '../../base/redux/functions';-import { updateSettings } from '../../base/settings/actions';+import { withPixelLineHeight } from '../../base/styles/functions.web';// @ts-ignoreimport { Tooltip } from '../../base/tooltip';-import { getLocalVideoTrack } from '../../base/tracks/functions';-import Dialog from '../../base/ui/components/web/Dialog';-import { toggleBackgroundEffect } from '../actions';import { BACKGROUNDS_LIMIT, IMAGES, type Image, VIRTUAL_BACKGROUND_TYPE } from '../constants';import { toDataURL } from '../functions';import logger from '../logger';import UploadImageButton from './UploadImageButton';-// @ts-ignoreimport VirtualBackgroundPreview from './VirtualBackgroundPreview';/* eslint-enable lines-around-comment */@@ -38,7 +33,7 @@ interface IProps extends WithTranslation {_images: Array<Image>;/**- * Returns the jitsi track that will have backgraund effect applied.+ * Returns the jitsi track that will have background effect applied.*/_jitsiTrack: Object;@@ -52,11 +47,6 @@ interface IProps extends WithTranslation {*/_multiStreamModeEnabled: boolean;- /**- * Returns the selected thumbnail identifier.- */- _selectedThumbnail: string;-/*** If the upload button should be displayed or not.*/@@ -78,192 +68,131 @@ interface IProps extends WithTranslation {* NOTE: currently used only for electron in order to open the dialog in the correct state after desktop sharing* selection.*/- initialOptions: Object;-}--const onError = (event: any) => {- event.target.style.display = 'none';-};+ initialOptions?: Object;+ /**+ * Options change handler.+ */+ onOptionsChange: Function;-/**- * 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: IReduxState): Object {- const { localFlipX } = state['features/base/settings'];- const dynamicBrandingImages = state['features/dynamic-branding'].virtualBackgrounds;- const hasBrandingImages = Boolean(dynamicBrandingImages.length);+ /**+ * Virtual background options.+ */+ options: any;- return {- _localFlipX: Boolean(localFlipX),- _images: (hasBrandingImages && dynamicBrandingImages) || IMAGES,- _virtualBackground: state['features/virtual-background'],- _selectedThumbnail: state['features/virtual-background'].selectedThumbnail,- _showUploadButton: state['features/base/config'].disableAddingBackgroundImages,- _jitsiTrack: getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack,- _multiStreamModeEnabled: getMultipleVideoSendingSupportFeatureFlag(state)- };+ /**+ * Returns the selected thumbnail identifier.+ */+ selectedThumbnail: string;}-const VirtualBackgroundDialog = translate(connect(_mapStateToProps)(VirtualBackground));+const onError = (event: any) => {+ event.target.style.display = 'none';+};const useStyles = makeStyles()(theme => {return {- dialogContainer: {- width: 'auto'+ virtualBackgroundLoading: {+ width: '100%',+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ height: '50px'},+container: {+ width: '100%',display: 'flex',flexDirection: 'column'},- dialog: {- alignSelf: 'flex-start',- position: 'relative',- maxHeight: '300px',- color: 'white',++ thumbnailContainer: {+ width: '100%',display: 'inline-grid',- gridTemplateColumns: 'auto auto auto auto auto',- columnGap: '9px',- cursor: 'pointer',+ gridTemplateColumns: '1fr 1fr 1fr 1fr 1fr',+ gap: theme.spacing(1),- // @ts-ignore- [[ '& .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),- 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'+ '@media (min-width: 608px) and (max-width: 712px)': {+ gridTemplateColumns: '1fr 1fr 1fr 1fr'},- '& .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': {++ '@media (max-width: 607px)': {+ gridTemplateColumns: '1fr 1fr 1fr',+ gap: theme.spacing(2)+ }+ },++ thumbnail: {+ height: '54px',+ width: '100%',+ borderRadius: '4px',+ boxSizing: 'border-box',+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ ...withPixelLineHeight(theme.typography.labelBold),+ color: theme.palette.text01,+ objectFit: 'cover',++ [[ '&:hover', '&:focus' ] as any]: {+ opacity: 0.5,+ cursor: 'pointer',++ '& ~ .delete-image-icon': {display: 'block'- },- '@media (max-width: 632px)': {- left: '51px'- }- },- '@media (max-width: 720px)': {- gridTemplateColumns: 'auto auto auto auto'- },- '@media (max-width: 632px)': {- gridTemplateColumns: 'auto auto auto auto auto',- fontSize: '1.5vw',-- // @ts-ignore- [[ '& .desktop-share:hover',- '& .thumbnail:hover',- '& .blur:hover',- '& .slight-blur:hover',- '& .virtual-background-none:hover' ]]: {- height: '60px',- width: '60px'- },-- // @ts-ignore- [[ '& .desktop-share',- '& .virtual-background-none,',- '& .thumbnail,',- '& .blur,',- '& .slight-blur' ]]: {- height: '60px',- width: '60px'- },-- // @ts-ignore- [[ '& .desktop-share-selected',- '& .thumbnail-selected',- '& .none-selected',- '& .blur-selected',- '& .slight-blur-selected' ]]: {- height: '60px',- width: '60px'}},- '@media (max-width: 360px)': {- gridTemplateColumns: 'auto auto auto auto'- },- '@media (max-width: 319px)': {- gridTemplateColumns: 'auto auto'++ '@media (max-width: 607px)': {+ height: '70px'}},- dialogMarginTop: {- marginTop: '8px'++ selectedThumbnail: {+ border: `2px solid ${theme.palette.action01Hover}`},- virtualBackgroundLoading: {- overflow: 'hidden',- position: 'fixed',- left: '50%',- marginTop: '10px',- transform: 'translateX(-50%)'++ noneThumbnail: {+ backgroundColor: theme.palette.ui04+ },++ slightBlur: {+ boxShadow: 'inset 0 0 12px #000000',+ background: '#a4a4a4'+ },++ blur: {+ boxShadow: 'inset 0 0 12px #000000',+ background: '#7e8287'+ },++ storedImageContainer: {+ position: 'relative',+ display: 'flex',+ flexDirection: 'column',++ '&:focus-within .delete-image-container': {+ display: 'block'+ }+ },++ deleteImageIcon: {+ position: 'absolute',+ top: '3px',+ right: '3px',+ background: theme.palette.ui03,+ borderRadius: '3px',+ cursor: 'pointer',+ display: 'none',++ '@media (max-width: 607px)': {+ display: 'block',+ padding: '3px'+ },++ [[ '&:hover', '&:focus' ] as any]: {+ display: 'block'+ }}};});@@ -273,24 +202,28 @@ const useStyles = makeStyles()(theme => {** @returns {ReactElement}*/-function VirtualBackground({+function VirtualBackgrounds({_images,_jitsiTrack,_localFlipX,- _selectedThumbnail,+ selectedThumbnail,_showUploadButton,_virtualBackground,- dispatch,+ onOptionsChange,+ options,initialOptions,t}: IProps) {const { classes, cx } = useStyles();const [ previewIsLoaded, setPreviewIsLoaded ] = useState(false);- const [ options, setOptions ] = useState<any>({ ...initialOptions });const localImages = jitsiLocalStorage.getItem('virtualBackgrounds');const [ storedImages, setStoredImages ] = useState<Array<Image>>((localImages && Bourne.parse(localImages)) || []);const [ loading, setLoading ] = useState(false);- const [ initialVirtualBackground ] = useState(_virtualBackground);++ useEffect(() => {+ onOptionsChange({ ...initialOptions });+ }, []);+const deleteStoredImage = useCallback(e => {const imageId = e.currentTarget.getAttribute('data-imageid');@@ -320,7 +253,7 @@ function VirtualBackground({}, [ storedImages ]);const enableBlur = useCallback(async () => {- setOptions({+ onOptionsChange({backgroundType: VIRTUAL_BACKGROUND_TYPE.BLUR,enabled: true,blurValue: 25,@@ -338,7 +271,7 @@ function VirtualBackground({}, [ enableBlur ]);const enableSlideBlur = useCallback(async () => {- setOptions({+ onOptionsChange({backgroundType: VIRTUAL_BACKGROUND_TYPE.BLUR,enabled: true,blurValue: 8,@@ -356,7 +289,7 @@ function VirtualBackground({}, [ enableSlideBlur ]);const removeBackground = useCallback(async () => {- setOptions({+ onOptionsChange({enabled: false,selectedThumbnail: 'none'});@@ -376,7 +309,7 @@ function VirtualBackground({const image = storedImages.find(img => img.id === imageId);if (image) {- setOptions({+ onOptionsChange({backgroundType: 'image',enabled: true,url: image.src,@@ -394,7 +327,7 @@ function VirtualBackground({try {const url = await toDataURL(image.src);- setOptions({+ onOptionsChange({backgroundType: 'image',enabled: true,url,@@ -423,48 +356,12 @@ function VirtualBackground({}}, [ setUploadedImageBackground ]);- const applyVirtualBackground = useCallback(async () => {- setLoading(true);- await dispatch(toggleBackgroundEffect(options, _jitsiTrack));- await setLoading(false);-- // Set x scale to default value.- dispatch(updateSettings({- localFlipX: true- }));-- dispatch(hideDialog());- logger.info(`Virtual background type: '${typeof options.backgroundType === 'undefined'- ? 'none' : options.backgroundType}' applied!`);- }, [ dispatch, options, _localFlipX ]);-- // 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());- }, []);-const loadedPreviewState = useCallback(async loaded => {await setPreviewIsLoaded(loaded);}, []);return (- <Dialog- className = { classes.dialogContainer }- ok = {{- disabled: !options || loading || !previewIsLoaded,- translationKey: 'virtualBackground.apply'- }}- onCancel = { cancelVirtualBackground }- onSubmit = { applyVirtualBackground }- size = 'large'- titleKey = 'virtualBackground.title' >+ <><VirtualBackgroundPreviewloadedPreview = { loadedPreviewState }options = { options } />@@ -481,23 +378,22 @@ function VirtualBackground({{_showUploadButton&& <UploadImageButtonsetLoading = { setLoading }- setOptions = { setOptions }+ setOptions = { onOptionsChange }setStoredImages = { setStoredImages }showLabel = { previewIsLoaded }storedImages = { storedImages } />}<div- className = { cx(classes.dialog, { [classes.dialogMarginTop]: previewIsLoaded }) }+ className = { classes.thumbnailContainer }role = 'radiogroup'tabIndex = { -1 }><Tooltipcontent = { t('virtualBackground.removeBackground') }position = { 'top' }><div- aria-checked = { _selectedThumbnail === 'none' }+ aria-checked = { selectedThumbnail === 'none' }aria-label = { t('virtualBackground.removeBackground') }- className = { cx('background-option', 'virtual-background-none', {- 'none-selected': _selectedThumbnail === 'none'- }) }+ className = { cx(classes.thumbnail, classes.noneThumbnail,+ selectedThumbnail === 'none' && classes.selectedThumbnail) }onClick = { removeBackground }onKeyPress = { removeBackgroundKeyPress }role = 'radio'@@ -509,11 +405,10 @@ function VirtualBackground({content = { t('virtualBackground.slightBlur') }position = { 'top' }><div- aria-checked = { _selectedThumbnail === 'slight-blur' }+ aria-checked = { selectedThumbnail === 'slight-blur' }aria-label = { t('virtualBackground.slightBlur') }- className = { cx('background-option', 'slight-blur', {- 'slight-blur-selected': _selectedThumbnail === 'slight-blur'- }) }+ className = { cx(classes.thumbnail, classes.slightBlur,+ selectedThumbnail === 'slight-blur' && classes.selectedThumbnail) }onClick = { enableSlideBlur }onKeyPress = { enableSlideBlurKeyPress }role = 'radio'@@ -525,11 +420,10 @@ function VirtualBackground({content = { t('virtualBackground.blur') }position = { 'top' }><div- aria-checked = { _selectedThumbnail === 'blur' }+ aria-checked = { selectedThumbnail === 'blur' }aria-label = { t('virtualBackground.blur') }- className = { cx('background-option', 'blur', {- 'blur-selected': _selectedThumbnail === 'blur'- }) }+ className = { cx(classes.thumbnail, classes.blur,+ selectedThumbnail === 'blur' && classes.selectedThumbnail) }onClick = { enableBlur }onKeyPress = { enableBlurKeyPress }role = 'radio'@@ -544,11 +438,11 @@ function VirtualBackground({position = { 'top' }><imgalt = { 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' }+ aria-checked = { options?.selectedThumbnail === image.id+ || selectedThumbnail === image.id }+ className = { cx(classes.thumbnail,+ (options?.selectedThumbnail === image.id+ || selectedThumbnail === image.id) && classes.selectedThumbnail) }data-imageid = { image.id }onClick = { setImageBackground }onError = { onError }@@ -560,15 +454,13 @@ function VirtualBackground({))}{storedImages.map((image, index) => (<div- className = { 'thumbnail-container' }+ className = { classes.storedImageContainer }key = { image.id }><imgalt = { t('virtualBackground.uploadedImage', { index: index + 1 }) }- aria-checked = { _selectedThumbnail === image.id }- className = { cx('background-option', {- 'thumbnail-selected': _selectedThumbnail === image.id,- 'thumbnail': _selectedThumbnail !== image.id- }) }+ aria-checked = { selectedThumbnail === image.id }+ className = { cx(classes.thumbnail,+ selectedThumbnail === image.id && classes.selectedThumbnail) }data-imageid = { image.id }onClick = { setUploadedImageBackground }onError = { onError }@@ -579,12 +471,12 @@ function VirtualBackground({<IconariaLabel = { t('virtualBackground.deleteImage') }- className = { 'delete-image-icon' }+ className = { cx(classes.deleteImageIcon, 'delete-image-icon') }data-imageid = { image.id }onClick = { deleteStoredImage }onKeyPress = { deleteStoredImageKeyPress }role = 'button'- size = { 15 }+ size = { 16 }src = { IconCloseLarge }tabIndex = { 0 } /></div>@@ -592,8 +484,30 @@ function VirtualBackground({</div></div>)}- </Dialog>+ </>);}-export default VirtualBackgroundDialog;+/**+ * 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: IReduxState) {+ const { localFlipX } = state['features/base/settings'];+ const dynamicBrandingImages = state['features/dynamic-branding'].virtualBackgrounds;+ const hasBrandingImages = Boolean(dynamicBrandingImages.length);++ return {+ _localFlipX: Boolean(localFlipX),+ _images: (hasBrandingImages && dynamicBrandingImages) || IMAGES,+ _virtualBackground: state['features/virtual-background'],+ _showUploadButton: !state['features/base/config'].disableAddingBackgroundImages,+ _multiStreamModeEnabled: getMultipleVideoSendingSupportFeatureFlag(state)+ };+}++export default connect(_mapStateToProps)(translate(VirtualBackgrounds));diff --git a/react/features/virtual-background/components/index.js b/react/features/virtual-background/components/index.jsindex 2a31b4ab94..a6cb1e2b57 100644--- a/react/features/virtual-background/components/index.js+++ b/react/features/virtual-background/components/index.js@@ -1,2 +1 @@export { default as VideoBackgroundButton } from './VideoBackgroundButton';-export { default as VirtualBackgroundDialog } from './VirtualBackgroundDialog';