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(settings): add an Experimental tab with a Picture-in-Picture switch
Hristo Terezovd0e34a154390
diff --git a/config.js b/config.jsindex acd42a9cd8..ee8ab750ad 100644--- a/config.js+++ b/config.js@@ -852,7 +852,10 @@ var config = {// Picture-in-Picture configuration.// pip: {- // // Enable Picture-in-Picture for browser meetings. Opt-in, defaults to false.+ // // Enable Picture-in-Picture for browser meetings. Opt-in, defaults to false. Leave it unset to let+ // // users turn browser PiP on or off for themselves from the Experimental tab of the settings dialog;+ // // their browser remembers the choice. A value set here, through URL parameters or the iframe API is+ // // final and hides that setting.// enableBrowserPiP: false,// // Disable Picture-in-Picture entirely. Defaults to false.// disabled: false,diff --git a/lang/main.json b/lang/main.jsonindex 65e370d506..9dff62b3d9 100644--- a/lang/main.json+++ b/lang/main.json@@ -1318,6 +1318,7 @@"desktopShareWarning": "You need to restart the screen share for the new settings to take effect.","devices": "Devices","enableCtrlAltReactionShortcuts": "Enable Ctrl+Alt alternatives for reaction shortcuts",+ "experimental": "Experimental","followMe": "Everyone follows me","followMeRecorder": "Recorder follows me","framesPerSecond": "frames-per-second",@@ -1335,6 +1336,8 @@"participantJoined": "Participant Joined","participantKnocking": "Participant entered lobby","participantLeft": "Participant Left",+ "pictureInPicture": "Picture-in-Picture",+ "pictureInPictureDescription": "Keep the meeting visible in a small floating window when you switch to another tab or app.","playSounds": "Play sound on","privateChatWithPermissions": "Disable private chat for non-moderators","reactions": "Meeting reactions",diff --git a/react/features/base/icons/svg/constants.ts b/react/features/base/icons/svg/constants.tsindex 3a56a4f771..bd8240b415 100644--- a/react/features/base/icons/svg/constants.ts+++ b/react/features/base/icons/svg/constants.ts@@ -85,6 +85,7 @@ import { default as IconShare } from './share.svg';import { default as IconShortcuts } from './shortcuts.svg';import { default as IconSip } from './sip.svg';import { default as IconSites } from './sites.svg';+import { default as IconSliders } from './sliders.svg';import { default as IconRemoteControlStart } from './start-remote-control.svg';import { default as IconRemoteControlStop } from './stop-remote-control.svg';import { default as IconStop } from './stop.svg';@@ -210,6 +211,7 @@ export const DEFAULT_ICON: Record<string, any> = {IconShortcuts,IconSip,IconSites,+ IconSliders,IconStop,IconSubtitles,IconTileView,diff --git a/react/features/base/icons/svg/index.ts b/react/features/base/icons/svg/index.tsindex a9c73a5cca..d0e15e4533 100644--- a/react/features/base/icons/svg/index.ts+++ b/react/features/base/icons/svg/index.ts@@ -97,6 +97,7 @@ const {IconShortcuts,IconSip,IconSites,+ IconSliders,IconStop,IconSubtitles,IconTileView,@@ -221,6 +222,7 @@ export {IconShortcuts,IconSip,IconSites,+ IconSliders,IconStop,IconSubtitles,IconTileView,diff --git a/react/features/base/icons/svg/sliders.svg b/react/features/base/icons/svg/sliders.svgnew file mode 100644index 0000000000..22a2593e9f--- /dev/null+++ b/react/features/base/icons/svg/sliders.svg@@ -0,0 +1,5 @@+<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">+ <path fill-rule="evenodd" clip-rule="evenodd" d="M3 5.25H12.095C12.4459 3.96862 13.6187 3 15 3C16.3813 3 17.5541 3.96862 17.905 5.25H21V6.75H17.905C17.5541 8.03138 16.3813 9 15 9C13.6187 9 12.4459 8.03138 12.095 6.75H3V5.25ZM15 4.5C14.1716 4.5 13.5 5.17157 13.5 6C13.5 6.82843 14.1716 7.5 15 7.5C15.8284 7.5 16.5 6.82843 16.5 6C16.5 5.17157 15.8284 4.5 15 4.5Z" />+ <path fill-rule="evenodd" clip-rule="evenodd" d="M3 11.25H5.095C5.44588 9.96862 6.61866 9 8 9C9.38134 9 10.5541 9.96862 10.905 11.25H21V12.75H10.905C10.5541 14.0314 9.38134 15 8 15C6.61866 15 5.44588 14.0314 5.095 12.75H3V11.25ZM8 10.5C7.17157 10.5 6.5 11.1716 6.5 12C6.5 12.8284 7.17157 13.5 8 13.5C8.82843 13.5 9.5 12.8284 9.5 12C9.5 11.1716 8.82843 10.5 8 10.5Z" />+ <path fill-rule="evenodd" clip-rule="evenodd" d="M3 17.25H11.095C11.4459 15.9686 12.6187 15 14 15C15.3813 15 16.5541 15.9686 16.905 17.25H21V18.75H16.905C16.5541 20.0314 15.3813 21 14 21C12.6187 21 11.4459 20.0314 11.095 18.75H3V17.25ZM14 16.5C13.1716 16.5 12.5 17.1716 12.5 18C12.5 18.8284 13.1716 19.5 14 19.5C14.8284 19.5 15.5 18.8284 15.5 18C15.5 17.1716 14.8284 16.5 14 16.5Z" />+</svg>diff --git a/react/features/pip/external-api.shared.ts b/react/features/pip/external-api.shared.tsindex f29cbc853b..636f312f53 100644--- a/react/features/pip/external-api.shared.ts+++ b/react/features/pip/external-api.shared.ts@@ -43,6 +43,15 @@ export function isPiPEnabled(pipConfig?: { disabled?: boolean; enableBrowserPiP?return false;}+ return isPiPSupportedByBrowser();+}++/**+ * Checks if the browser offers a Picture-in-Picture API at all, either Document PiP or video element PiP.+ *+ * @returns {boolean} - True if the browser supports Picture-in-Picture.+ */+export function isPiPSupportedByBrowser(): boolean {return 'documentPictureInPicture' in window|| Boolean(document.pictureInPictureEnabled);}diff --git a/react/features/pip/functions.ts b/react/features/pip/functions.tsindex af1acead81..c5d40f6729 100644--- a/react/features/pip/functions.ts+++ b/react/features/pip/functions.ts@@ -13,7 +13,7 @@ import { isPrejoinPageVisible } from '../prejoin/functions.any';import { toggleAudioFromPiP, toggleVideoFromPiP } from './actions';import { BROWSER_PIP_OPTION_ID } from './constants';-import { isPiPEnabled } from './external-api.shared';+import { isPiPEnabled, isPiPSupportedByBrowser } from './external-api.shared';import logger from './logger';import {ExtendedMediaSessionAction,@@ -135,6 +135,24 @@ export function shouldShowPiP(state: IReduxState): boolean {return true;}+/**+ * Determines if the local user may choose whether browser Picture-in-Picture is on or off. That is the case outside+ * Electron, which has its own always-on PiP flow, when the browser supports PiP, the deployment has not disabled the+ * feature altogether with `pip.disabled` and the config leaves `pip.enableBrowserPiP` unset: a value set there, by+ * config.js, URL parameters or the iframe API, is the deployment's or the embedder's decision and is final.+ *+ * @param {IReduxState} state - Redux state.+ * @returns {boolean} Whether the browser PiP setting applies.+ */+export function isBrowserPiPConfigurable(state: IReduxState): boolean {+ const pipConfig = state['features/base/config'].pip;++ return !browser.isElectron()+ && !pipConfig?.disabled+ && pipConfig?.enableBrowserPiP === undefined+ && isPiPSupportedByBrowser();+}+/*** Draws an image-based avatar as a circular clipped image on canvas.*diff --git a/react/features/settings/actions.web.ts b/react/features/settings/actions.web.tsindex 50679ce442..3b46cae884 100644--- a/react/features/settings/actions.web.ts+++ b/react/features/settings/actions.web.ts@@ -36,6 +36,7 @@ import {import LogoutDialog from './components/web/LogoutDialog';import SettingsDialog from './components/web/SettingsDialog';import {+ getExperimentalTabProps,getModeratorTabProps,getMoreTabProps,getNotificationsTabProps,@@ -43,6 +44,7 @@ import {getShortcutsTabProps} from './functions.web';import logger from './logger';+import { IConfigOptionValues, IExperimentalTabState } from './types';/*** Opens {@code LogoutDialog}.@@ -171,6 +173,39 @@ export function submitMoreTab(newState: any) {};}+/**+ * Submits the settings from the "Experimental" tab of the settings dialog. Only the options whose value the user+ * changed are stored, so an option they leave alone keeps following the config.+ *+ * @param {IExperimentalTabState} newState - The new settings.+ * @returns {Function}+ */+export function submitExperimentalTab(newState: IExperimentalTabState) {+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {+ const state = getState();+ const { values: currentValues } = getExperimentalTabProps(state);+ const newValues = newState.values ?? {};+ const changedValues: IConfigOptionValues = {};++ for (const optionId of Object.keys(newValues)) {+ if (newValues[optionId] !== currentValues[optionId]) {+ changedValues[optionId] = newValues[optionId];+ }+ }++ if (Object.keys(changedValues).length === 0) {+ return;+ }++ dispatch(updateSettings({+ userSelectedConfig: {+ ...state['features/base/settings'].userSelectedConfig,+ ...changedValues+ }+ }));+ };+}+/*** Submits the settings from the "Moderator" tab of the settings dialog.*diff --git a/react/features/settings/components/web/ExperimentalTab.tsx b/react/features/settings/components/web/ExperimentalTab.tsxnew file mode 100644index 0000000000..3a9097d1ce--- /dev/null+++ b/react/features/settings/components/web/ExperimentalTab.tsx@@ -0,0 +1,193 @@+import { Theme } from '@mui/material';+import clsx from 'clsx';+import React from 'react';+import { WithTranslation } from 'react-i18next';+import { withStyles } from 'tss-react/mui';++import AbstractDialogTab, {+ IProps as AbstractDialogTabProps+} from '../../../base/dialog/components/web/AbstractDialogTab';+import { translate } from '../../../base/i18n/functions';+import Switch from '../../../base/ui/components/web/Switch';+import { ConfigOption, ConfigOptionValue, IConfigOptionValues, IExperimentalTabState } from '../../types';++/**+ * The type of the React {@code Component} props of {@link ExperimentalTab}.+ */+export interface IProps extends AbstractDialogTabProps, WithTranslation {++ /**+ * CSS classes object.+ */+ classes?: Partial<Record<keyof ReturnType<typeof styles>, string>>;++ /**+ * The config options to display.+ */+ options: ConfigOption[];++ /**+ * The current value of every displayed option, keyed by option id.+ */+ values: IConfigOptionValues;+}++const styles = (theme: Theme) => {+ return {+ container: {+ display: 'flex',+ flexDirection: 'column' as const,+ padding: '0 2px'+ },++ option: {+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'space-between',+ gap: theme.spacing(3),+ padding: `${theme.spacing(3)} 0`,++ '&:not(:last-child)': {+ borderBottom: `1px solid ${theme.palette.settingsSectionBackground}`+ }+ },++ text: {+ display: 'flex',+ flexDirection: 'column' as const,+ gap: theme.spacing(1)+ },++ title: {+ ...theme.typography.bodyShortBold,+ color: theme.palette.settingsTabText+ },++ // Smaller than the title, so that the two read as a title and its explanation.+ description: {+ ...theme.typography.labelRegular,+ color: theme.palette.text02,+ fontSize: '0.6875rem',+ paddingTop: theme.spacing(1)+ },++ // Without it the switch, which has no content of its own, is squeezed by a long description.+ switch: {+ flexShrink: 0+ }+ };+};++/**+ * React {@code Component} for changing the experimental config options a user may decide for themselves.+ *+ * @augments Component+ */+class ExperimentalTab extends AbstractDialogTab<IProps, IExperimentalTabState> {+ /**+ * Initializes a new {@code ExperimentalTab} 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._onValueChange = this._onValueChange.bind(this);+ }++ /**+ * Implements React's {@link Component#render()}.+ *+ * @inheritdoc+ * @returns {ReactElement}+ */+ override render() {+ const { options, values } = this.props;+ const classes = withStyles.getClasses(this.props);++ return (+ <div+ className = { clsx('experimental-tab', classes.container) }+ key = 'experimental'>+ {options.map(option => this._renderOption(option, values[option.id]))}+ </div>+ );+ }++ /**+ * Records the new value of an option in the tab state; it is persisted when the dialog is submitted.+ *+ * @param {string} optionId - The id of the changed option.+ * @param {ConfigOptionValue} value - The new value of the option.+ * @returns {void}+ */+ _onValueChange(optionId: string, value: ConfigOptionValue) {+ super._onChange({+ values: {+ ...this.props.values,+ [optionId]: value+ }+ });+ }++ /**+ * Returns the React Element for a single config option: its title, description and control.+ *+ * @param {ConfigOption} option - The option to render.+ * @param {ConfigOptionValue} value - The current value of the option.+ * @returns {ReactElement}+ */+ _renderOption(option: ConfigOption, value: ConfigOptionValue) {+ const { descriptionKey, id, labelKey } = option;+ const { t } = this.props;+ const classes = withStyles.getClasses(this.props);+ const controlId = `config-option-${id}`;++ return (+ <div+ className = { classes.option }+ key = { id }>+ <div className = { classes.text }>+ <label+ className = { classes.title }+ htmlFor = { controlId }>+ {t(labelKey)}+ </label>+ <span className = { classes.description }>{t(descriptionKey)}</span>+ </div>+ {this._renderControl(option, value, controlId)}+ </div>+ );+ }++ /**+ * Returns the React Element that edits the value of a config option, which depends on the kind of value the+ * option holds.+ *+ * @param {ConfigOption} option - The option whose control to render.+ * @param {ConfigOptionValue} value - The current value of the option.+ * @param {string} controlId - The id of the control, which the option's title is the label of.+ * @returns {ReactElement}+ */+ _renderControl(option: ConfigOption, value: ConfigOptionValue, controlId: string) {+ const classes = withStyles.getClasses(this.props);++ // Only on/off options exist for now. The switch is deliberate: a new kind of value adds its own case here+ // with a control suited to it, e.g. a Select for a list of choices.+ switch (option.type) {+ case 'boolean':+ return (+ <Switch+ checked = { Boolean(value) }+ className = { classes.switch }+ id = { controlId }+ /* eslint-disable-next-line react/jsx-no-bind */+ onChange = { on => this._onValueChange(option.id, Boolean(on)) } />+ );+ }+ }+}++export default withStyles(translate(ExperimentalTab), styles);diff --git a/react/features/settings/components/web/SettingsDialog.tsx b/react/features/settings/components/web/SettingsDialog.tsxindex e106546287..0e9a524c30 100644--- a/react/features/settings/components/web/SettingsDialog.tsx+++ b/react/features/settings/components/web/SettingsDialog.tsx@@ -10,6 +10,7 @@ import {IconImage,IconModerator,IconShortcuts,+ IconSliders,IconUser,IconVideo,IconVolumeUp@@ -26,6 +27,7 @@ import {import { checkBlurSupport, checkVirtualBackgroundEnabled } from '../../../virtual-background/functions';import { iAmVisitor } from '../../../visitors/functions';import {+ submitExperimentalTab,submitModeratorTab,submitMoreTab,submitNotificationsTab,@@ -35,6 +37,7 @@ import {} from '../../actions';import { SETTINGS_TABS } from '../../constants';import {+ getExperimentalTabProps,getModeratorTabProps,getMoreTabProps,getNotificationsMap,@@ -43,8 +46,10 @@ import {getShortcutsTabProps,getVirtualBackgroundTabProps} from '../../functions';+import { IExperimentalTabState } from '../../types';import CalendarTab from './CalendarTab';+import ExperimentalTab from './ExperimentalTab';import ModeratorTab from './ModeratorTab';import MoreTab from './MoreTab';import NotificationsTab from './NotificationsTab';@@ -143,6 +148,10 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {const showNotificationsSettings = Object.keys(enabledNotifications).length > 0;const virtualBackgroundSupported = checkBlurSupport();const enableVirtualBackground = checkVirtualBackgroundEnabled(state);+ const experimentalTabProps = getExperimentalTabProps(state);++ // The tab only lists config options the user may change here; without any (e.g. in Electron) it has no purpose.+ const showExperimentalSettings = experimentalTabProps.options.length > 0;const tabs: IDialogTab<any>[] = [];const _iAmVisitor = iAmVisitor(state);@@ -339,6 +348,25 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {});}+ if (showExperimentalSettings) {+ tabs.push({+ name: SETTINGS_TABS.EXPERIMENTAL,+ component: ExperimentalTab,+ labelKey: 'settings.experimental',+ props: experimentalTabProps,+ propsUpdateFunction: (tabState: IExperimentalTabState, newProps: typeof experimentalTabProps) => {+ // Updates tab props, keeping users selection++ return {+ ...newProps,+ values: tabState?.values ?? newProps.values+ };+ },+ submit: submitExperimentalTab,+ icon: IconSliders+ });+ }+return { _tabs: tabs };}diff --git a/react/features/settings/configOptions.web.ts b/react/features/settings/configOptions.web.tsnew file mode 100644index 0000000000..85d52cc678--- /dev/null+++ b/react/features/settings/configOptions.web.ts@@ -0,0 +1,20 @@+import { BROWSER_PIP_OPTION_ID } from '../pip/constants';+import { isBrowserPiPConfigurable, isBrowserPiPTurnedOn } from '../pip/functions';++import { ConfigOption } from './types';++/**+ * The config options the user can change from the Experimental tab of the settings dialog. The tab and the+ * persistence of the choice are generic, so exposing a config option takes an entry here plus a feature that reads+ * the choice (see {@code isBrowserPiPTurnedOn}). The tab is hidden when no entry applies.+ */+export const CONFIG_OPTIONS: ConfigOption[] = [+ {+ descriptionKey: 'settings.pictureInPictureDescription',+ getValue: isBrowserPiPTurnedOn,+ id: BROWSER_PIP_OPTION_ID,+ isAvailable: isBrowserPiPConfigurable,+ labelKey: 'settings.pictureInPicture',+ type: 'boolean'+ }+];diff --git a/react/features/settings/constants.ts b/react/features/settings/constants.tsindex d71c27e00c..a1c399daf6 100644--- a/react/features/settings/constants.ts+++ b/react/features/settings/constants.ts@@ -1,6 +1,7 @@export const SETTINGS_TABS = {AUDIO: 'audio_tab',CALENDAR: 'calendar_tab',+ EXPERIMENTAL: 'experimental_tab',MORE: 'more_tab',MODERATOR: 'moderator-tab',NOTIFICATIONS: 'notifications_tab',diff --git a/react/features/settings/functions.web.ts b/react/features/settings/functions.web.tsindex a4c0134ffa..6cac2c65c5 100644--- a/react/features/settings/functions.web.ts+++ b/react/features/settings/functions.web.ts@@ -12,6 +12,9 @@ import {import { getParticipantsPaneConfig } from '../participants-pane/functions';import { isPrejoinPageVisible } from '../prejoin/functions';+import { CONFIG_OPTIONS } from './configOptions';+import { ConfigOption, IConfigOptionValues } from './types';+export * from './functions.any';/**@@ -125,6 +128,43 @@ export function getVirtualBackgroundTabProps(stateful: IStateful, isDisplayedOnW};}+/**+ * Returns the config options the user may decide here: those that apply to the current environment and whose value+ * no config source has set.+ *+ * @param {(Function|Object)} stateful - The (whole) redux state, or redux's+ * {@code getState} function to be used to retrieve the state.+ * @returns {ConfigOption[]} - The config options to display.+ */+export function getAvailableConfigOptions(stateful: IStateful): ConfigOption[] {+ const state = toState(stateful);++ return CONFIG_OPTIONS.filter(option => option.isAvailable(state));+}++/**+ * Returns the properties for the "Experimental" 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 "Experimental" tab from settings dialog.+ */+export function getExperimentalTabProps(stateful: IStateful) {+ const state = toState(stateful);+ const options = getAvailableConfigOptions(state);+ const values: IConfigOptionValues = {};++ for (const option of options) {+ values[option.id] = option.getValue(state);+ }++ return {+ options,+ values+ };+}+/*** Used for web. Indicates if the setting section is enabled.*diff --git a/react/features/settings/types.ts b/react/features/settings/types.tsnew file mode 100644index 0000000000..e1e6a4e5a7--- /dev/null+++ b/react/features/settings/types.ts@@ -0,0 +1,77 @@+import { IReduxState } from '../app/types';++/**+ * The properties shared by every config option the user can choose a value for, whatever the kind of value it holds.+ *+ * @template T - The type of the option's value.+ */+interface IConfigOptionBase<T> {++ /**+ * The translation key of the text explaining what the option does.+ */+ descriptionKey: string;++ /**+ * Returns the effective value of the option: the value the config sets when there is one, else the user's choice,+ * else the option's default. The feature owning the option provides it, since it decides how its config and the+ * user's choice combine.+ */+ getValue: (state: IReduxState) => T;++ /**+ * The key under which the user's choice is persisted. It is deliberately not the path of the config option, so+ * that a rename of the config option does not lose the choices users have already made.+ */+ id: string;++ /**+ * Returns whether the user may decide the option here: the feature applies to the current environment, e.g. the+ * browser supports it, and no config source has set the option's value. A value set by config.js, URL parameters+ * or the iframe API is the deployment's or the embedder's decision and is final, so the option is not displayed.+ */+ isAvailable: (state: IReduxState) => boolean;++ /**+ * The translation key of the option's title.+ */+ labelKey: string;+}++/**+ * A config option that is either on or off, displayed as a switch.+ */+export interface IBooleanConfigOption extends IConfigOptionBase<boolean> {++ /**+ * The kind of value the option holds.+ */+ type: 'boolean';+}++/**+ * Any config option the user can choose a value for. To support a new kind of value, add its interface to this+ * union, widen {@code userSelectedConfig} in the settings reducer and the check in {@code getUserSelectedConfigValue},+ * and add a case rendering its control to {@code ExperimentalTab}.+ */+export type ConfigOption = IBooleanConfigOption;++/**+ * Any value a config option can hold.+ */+export type ConfigOptionValue = ReturnType<ConfigOption['getValue']>;++/**+ * The values of config options, keyed by option id.+ */+export interface IConfigOptionValues {+ [optionId: string]: ConfigOptionValue;+}++/**+ * The state of the Experimental tab of the settings dialog: the values the user has set in the tab, persisted when+ * the dialog is submitted.+ */+export interface IExperimentalTabState {+ values?: IConfigOptionValues;+}