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(breakout-rooms): let moderators restrict joining breakout rooms to the rooms they assign (#17985)
moataz hjaijibcad5613c3d5
diff --git a/config.js b/config.jsindex 7ba09fd87b..019a3f37a5 100644--- a/config.js+++ b/config.js@@ -165,6 +165,12 @@ var config = {// thus enable this only when that module is loaded.// showSharedVideoPermissionsModeratorSetting: false,+ // Shows/hides the moderator setting that restricts joining a breakout room to the room a moderator+ // assigns. The restriction is enforced by the mod_muc_breakout_rooms prosody module, thus enable this+ // only when the server runs a version of that module that supports it. Older clients still show Join while+ // the restriction is on: the server refuses that join and lib-jitsi-meet moves them back to the main room.+ // showBreakoutRoomJoinPermissionsModeratorSetting: false,+// screenshotCapture : {// Enables the screensharing capture feature.// enabled: false,diff --git a/lang/main.json b/lang/main.jsonindex c8f8b6d648..4cfb6576e6 100644--- a/lang/main.json+++ b/lang/main.json@@ -1299,6 +1299,7 @@"settings": {"audio": "Audio","audioTranslation": "Enable audio translation",+ "breakoutRoomJoinWithPermissions": "Disable choosing a breakout room for non-moderators","buttonLabel": "Settings","calendar": {"about": "The {{appName}} calendar integration is used to securely access your calendar so it can read upcoming events.",diff --git a/modules/API/API.js b/modules/API/API.jsindex 4c9b225170..fdc8a7077e 100755--- a/modules/API/API.js+++ b/modules/API/API.js@@ -67,7 +67,12 @@ import {removeBreakoutRoom,sendParticipantToRoom} from '../../react/features/breakout-rooms/actions';-import { getBreakoutRooms, getRoomsInfo } from '../../react/features/breakout-rooms/functions';+import {+ getBreakoutRooms,+ getMainRoom,+ getRoomsInfo,+ isBreakoutRoomJoinAllowed+} from '../../react/features/breakout-rooms/functions';import {sendMessage,setPrivateMessageRecipient,@@ -973,6 +978,16 @@ function initCommands() {APP.store.dispatch(closeBreakoutRoom(roomId));},'join-breakout-room': roomId => {+ const state = APP.store.getState();+ const room = roomId ? getBreakoutRooms(state)[roomId.split('@')[0]] : getMainRoom(state);++ // The server rejects a join that is not allowed as well.+ if (!isBreakoutRoomJoinAllowed(state, room)) {+ logger.error('Joining breakout rooms is restricted to the rooms that a moderator assigns');++ return;+ }+APP.store.dispatch(moveToRoom(roomId));},'send-participant-to-room': (participantId, roomId) => {diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.tsindex d7286ff697..10d64b234c 100644--- a/react/features/base/config/configType.ts+++ b/react/features/base/config/configType.ts@@ -713,6 +713,7 @@ export interface IConfig {};serviceUrl?: string;sharedVideoAllowedURLDomains?: Array<string>;+ showBreakoutRoomJoinPermissionsModeratorSetting?: boolean;showChatPermissionsModeratorSetting?: boolean;showSharedVideoPermissionsModeratorSetting?: boolean;sipInviteUrl?: string;diff --git a/react/features/base/config/configWhitelist.ts b/react/features/base/config/configWhitelist.tsindex ef489b0b1a..ce756e81bd 100644--- a/react/features/base/config/configWhitelist.ts+++ b/react/features/base/config/configWhitelist.ts@@ -227,6 +227,7 @@ export default ['screenshotCapture','secondScreen','securityUi',+ 'showBreakoutRoomJoinPermissionsModeratorSetting','showChatPermissionsModeratorSetting','showSharedVideoPermissionsModeratorSetting','speakerStats',diff --git a/react/features/breakout-rooms/components/native/BreakoutRoom.tsx b/react/features/breakout-rooms/components/native/BreakoutRoom.tsxindex 498e7b6df1..1cd98cd55b 100644--- a/react/features/breakout-rooms/components/native/BreakoutRoom.tsx+++ b/react/features/breakout-rooms/components/native/BreakoutRoom.tsx@@ -1,11 +1,13 @@import React, { useCallback, useState } from 'react';import { useTranslation } from 'react-i18next';import { FlatList, Text, TextStyle, TouchableOpacity, View, ViewStyle } from 'react-native';-import { useDispatch } from 'react-redux';+import { useDispatch, useSelector } from 'react-redux';+import { IReduxState } from '../../../app/types';import { openSheet } from '../../../base/dialog/actions';import Icon from '../../../base/icons/components/Icon';import { IconArrowDown, IconArrowUp } from '../../../base/icons/svg';+import { isBreakoutRoomJoinAllowed } from '../../functions';import { IRoom } from '../../types';import BreakoutRoomContextMenu from './BreakoutRoomContextMenu';@@ -39,6 +41,7 @@ export const BreakoutRoom = ({ room }: IProps) => {const dispatch = useDispatch();const { t } = useTranslation();const [ collapsed, setCollapsed ] = useState(false);+ const joinAllowed = useSelector((state: IReduxState) => isBreakoutRoomJoinAllowed(state, room));const roomParticipantsNr = Object.values(room.participants || {}).length;const title = `${room.name || t('breakoutRooms.mainRoom')} (${roomParticipantsNr})`;@@ -47,8 +50,12 @@ export const BreakoutRoom = ({ room }: IProps) => {}, []);const _openContextMenu = useCallback(() => {- dispatch(openSheet(BreakoutRoomContextMenu, { room }));- }, [ dispatch, room ]);+ // Joining is the only action of a participant who is not a moderator, thus with the join restriction the menu+ // of a breakout room would be empty.+ if (joinAllowed) {+ dispatch(openSheet(BreakoutRoomContextMenu, { room }));+ }+ }, [ dispatch, joinAllowed, room ]);const renderItem = useCallback(({ item: participant }: { item: any; }) => (<BreakoutRoomParticipantItemdiff --git a/react/features/breakout-rooms/components/native/BreakoutRoomContextMenu.tsx b/react/features/breakout-rooms/components/native/BreakoutRoomContextMenu.tsxindex 6214e4aecc..e6bdf5d7db 100644--- a/react/features/breakout-rooms/components/native/BreakoutRoomContextMenu.tsx+++ b/react/features/breakout-rooms/components/native/BreakoutRoomContextMenu.tsx@@ -6,6 +6,7 @@ import { useDispatch, useSelector } from 'react-redux';import { createBreakoutRoomsEvent } from '../../../analytics/AnalyticsEvents';import { sendAnalytics } from '../../../analytics/functions';+import { IReduxState } from '../../../app/types';import { hideSheet, openDialog } from '../../../base/dialog/actions';import BottomSheet from '../../../base/dialog/components/native/BottomSheet';import Icon from '../../../base/icons/components/Icon';@@ -15,7 +16,7 @@ import styles from '../../../participants-pane/components/native/styles';import { isBreakoutRoomRenameAllowed } from '../../../participants-pane/functions';import { BREAKOUT_CONTEXT_MENU_ACTIONS as ACTIONS } from '../../../participants-pane/types';import { closeBreakoutRoom, moveToRoom, removeBreakoutRoom } from '../../actions';-import { getBreakoutRoomsConfig } from '../../functions';+import { getBreakoutRoomsConfig, isBreakoutRoomJoinAllowed } from '../../functions';import { IRoom } from '../../types';import BreakoutRoomNamePrompt from './BreakoutRoomNamePrompt';@@ -43,6 +44,7 @@ const BreakoutRoomContextMenu = ({ room, actions = ALL_ACTIONS }: IProps) => {const dispatch = useDispatch();const isLocalModerator = useSelector(isLocalParticipantModerator);const { hideJoinRoomButton } = useSelector(getBreakoutRoomsConfig);+ const joinAllowed = useSelector((state: IReduxState) => isBreakoutRoomJoinAllowed(state, room));const _isBreakoutRoomRenameAllowed = useSelector(isBreakoutRoomRenameAllowed);const { t } = useTranslation();@@ -75,7 +77,7 @@ const BreakoutRoomContextMenu = ({ room, actions = ALL_ACTIONS }: IProps) => {addScrollViewPadding = { false }showSlidingView = { true }>{- !hideJoinRoomButton && actions.includes(ACTIONS.JOIN) && (+ !hideJoinRoomButton && joinAllowed && actions.includes(ACTIONS.JOIN) && (<TouchableOpacityaccessibilityLabel = { t('breakoutRooms.actions.join') }accessibilityRole = 'button'diff --git a/react/features/breakout-rooms/functions.ts b/react/features/breakout-rooms/functions.tsindex aa7c87a36a..d8d8a14ff8 100644--- a/react/features/breakout-rooms/functions.ts+++ b/react/features/breakout-rooms/functions.ts@@ -238,3 +238,18 @@ export const isAutoAssignParticipantsVisible = (stateful: IStateful) => {&& Object.keys(rooms).length > 1&& !hideAutoAssignButton;};++/**+ * Returns whether the local participant may join the given room by themselves. Returning to the main room is always+ * allowed. When the main room restricts joining breakout rooms, only a moderator can join one, and another participant+ * joins the room that a moderator moves them to.+ *+ * @param {IStateful} stateful - Global state.+ * @param {IRoom} room - The room to join.+ * @returns {boolean}+ */+export const isBreakoutRoomJoinAllowed = (stateful: IStateful, room?: IRoom) => {+ const state = toState(stateful);++ return Boolean(room?.isMainRoom) || !state[FEATURE_KEY].joinRestricted || isLocalParticipantModerator(state);+};diff --git a/react/features/breakout-rooms/middleware.ts b/react/features/breakout-rooms/middleware.tsindex b4d5827a04..9656b24a71 100644--- a/react/features/breakout-rooms/middleware.ts+++ b/react/features/breakout-rooms/middleware.ts@@ -23,8 +23,8 @@ StateListenerRegistry.register(dispatch(moveToRoom(roomId));});- conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED, ({ rooms, roomCounter }: {- roomCounter: number; rooms: IRooms;+ conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED, ({ joinRestricted, rooms, roomCounter }: {+ joinRestricted?: boolean; roomCounter: number; rooms: IRooms;}) => {logger.debug('Room list updated');if (typeof APP !== 'undefined') {@@ -32,6 +32,7 @@ StateListenerRegistry.register(}dispatch({type: UPDATE_BREAKOUT_ROOMS,+ joinRestricted,rooms,roomCounter});diff --git a/react/features/breakout-rooms/reducer.ts b/react/features/breakout-rooms/reducer.tsindex 9223ca9206..5779560723 100644--- a/react/features/breakout-rooms/reducer.ts+++ b/react/features/breakout-rooms/reducer.ts@@ -15,6 +15,11 @@ const DEFAULT_STATE = {};export interface IBreakoutRoomsState {++ /**+ * Whether the main room lets only moderators, and the participants they move, join breakout rooms.+ */+ joinRestricted?: boolean;roomCounter: number;rooms: IRooms;userContextCache: {@@ -37,10 +42,14 @@ ReducerRegistry.register<IBreakoutRoomsState>(FEATURE_KEY, (state = DEFAULT_STATroomCounter: action.roomCounter};case UPDATE_BREAKOUT_ROOMS: {- const { roomCounter, rooms, userContextCache } = action;+ const { joinRestricted, roomCounter, rooms, updatedNames, userContextCache } = action;return {...state,++ // The update that the client sends to itself for a changed display name does not carry it. Any update+ // from the server does, an older server that does not send it does not restrict joining.+ joinRestricted: updatedNames ? state.joinRestricted : Boolean(joinRestricted),roomCounter,rooms,userContextCache: userContextCache || state.userContextCachediff --git a/react/features/participants-pane/components/breakout-rooms/components/web/JoinQuickActionButton.tsx b/react/features/participants-pane/components/breakout-rooms/components/web/JoinQuickActionButton.tsxindex d4dad40282..dd55bb3e65 100644--- a/react/features/participants-pane/components/breakout-rooms/components/web/JoinQuickActionButton.tsx+++ b/react/features/participants-pane/components/breakout-rooms/components/web/JoinQuickActionButton.tsx@@ -1,22 +1,22 @@import React, { useCallback } from 'react';import { useTranslation } from 'react-i18next';-import { useDispatch } from 'react-redux';+import { useDispatch, useSelector } from 'react-redux';import { makeStyles } from 'tss-react/mui';import { createBreakoutRoomsEvent } from '../../../../../analytics/AnalyticsEvents';import { sendAnalytics } from '../../../../../analytics/functions';+import { IReduxState } from '../../../../../app/types';import Button from '../../../../../base/ui/components/web/Button';import { moveToRoom } from '../../../../../breakout-rooms/actions';+import { isBreakoutRoomJoinAllowed } from '../../../../../breakout-rooms/functions';+import { IRoom } from '../../../../../breakout-rooms/types';interface IProps {/*** The room to join.*/- room: {- id: string;- jid: string;- };+ room: IRoom;}const useStyles = makeStyles()(theme => {@@ -31,6 +31,7 @@ const JoinActionButton = ({ room }: IProps) => {const { classes: styles } = useStyles();const { t } = useTranslation();const dispatch = useDispatch();+ const joinAllowed = useSelector((state: IReduxState) => isBreakoutRoomJoinAllowed(state, room));const onJoinRoom = useCallback(e => {e.stopPropagation();@@ -38,6 +39,10 @@ const JoinActionButton = ({ room }: IProps) => {dispatch(moveToRoom(room.jid));}, [ dispatch, room ]);+ if (!joinAllowed) {+ return null;+ }+return (<ButtonaccessibilityLabel = { t('breakoutRooms.actions.join') }diff --git a/react/features/participants-pane/components/breakout-rooms/components/web/RoomContextMenu.tsx b/react/features/participants-pane/components/breakout-rooms/components/web/RoomContextMenu.tsxindex bc5dcfc463..a2c076f613 100644--- a/react/features/participants-pane/components/breakout-rooms/components/web/RoomContextMenu.tsx+++ b/react/features/participants-pane/components/breakout-rooms/components/web/RoomContextMenu.tsx@@ -4,12 +4,14 @@ import { useDispatch, useSelector } from 'react-redux';import { createBreakoutRoomsEvent } from '../../../../../analytics/AnalyticsEvents';import { sendAnalytics } from '../../../../../analytics/functions';+import { IReduxState } from '../../../../../app/types';import { openDialog } from '../../../../../base/dialog/actions';import { IconCloseLarge, IconEdit, IconRingGroup } from '../../../../../base/icons/svg';import { isLocalParticipantModerator } from '../../../../../base/participants/functions';import ContextMenu from '../../../../../base/ui/components/web/ContextMenu';import ContextMenuItemGroup from '../../../../../base/ui/components/web/ContextMenuItemGroup';import { closeBreakoutRoom, moveToRoom, removeBreakoutRoom } from '../../../../../breakout-rooms/actions';+import { isBreakoutRoomJoinAllowed } from '../../../../../breakout-rooms/functions';import { IRoom } from '../../../../../breakout-rooms/types';import { showOverflowDrawer } from '../../../../../toolbox/functions.web';import { isBreakoutRoomRenameAllowed } from '../../../../functions';@@ -57,6 +59,7 @@ export const RoomContextMenu = ({const isLocalModerator = useSelector(isLocalParticipantModerator);const _isBreakoutRoomRenameAllowed = useSelector(isBreakoutRoomRenameAllowed);const _overflowDrawer = useSelector(showOverflowDrawer);+ const joinAllowed = useSelector((state: IReduxState) => isBreakoutRoomJoinAllowed(state, room));const onJoinRoom = useCallback(() => {sendAnalytics(createBreakoutRoomsEvent('join'));@@ -81,7 +84,7 @@ export const RoomContextMenu = ({const isRoomEmpty = !(room?.participants && Object.keys(room.participants).length > 0);const actions = [- _overflowDrawer ? {+ _overflowDrawer && joinAllowed ? {accessibilityLabel: t('breakoutRooms.actions.join'),icon: IconRingGroup,onClick: onJoinRoom,diff --git a/react/features/participants-pane/components/breakout-rooms/components/web/RoomList.tsx b/react/features/participants-pane/components/breakout-rooms/components/web/RoomList.tsxindex e5119831b8..b4520310af 100644--- a/react/features/participants-pane/components/breakout-rooms/components/web/RoomList.tsx+++ b/react/features/participants-pane/components/breakout-rooms/components/web/RoomList.tsx@@ -1,6 +1,6 @@import React, { useCallback, useEffect } from 'react';import { useTranslation } from 'react-i18next';-import { useSelector } from 'react-redux';+import { useSelector, useStore } from 'react-redux';import { makeStyles } from 'tss-react/mui';import { isMobileBrowser } from '../../../../../base/environment/utils';@@ -12,6 +12,7 @@ import {getBreakoutRoomsConfig,getCurrentRoomId,isAutoAssignParticipantsVisible,+ isBreakoutRoomJoinAllowed,isInBreakoutRoom} from '../../../../../breakout-rooms/functions';import { IRoom } from '../../../../../breakout-rooms/types';@@ -51,6 +52,7 @@ export const RoomList = ({ searchString }: IProps) => {const isLocalModerator = useSelector(isLocalParticipantModerator);const showAutoAssign = useSelector(isAutoAssignParticipantsVisible);const { hideJoinRoomButton } = useSelector(getBreakoutRoomsConfig);+ const store = useStore();const [ lowerMenu, raiseMenu, toggleMenu, menuEnter, menuLeave, raiseContext ] = useContextMenu<IRoom>();const [ lowerParticipantMenu, raiseParticipantMenu, toggleParticipantMenu,participantMenuEnter, participantMenuLeave, raiseParticipantContext ] = useContextMenu<{@@ -58,7 +60,13 @@ export const RoomList = ({ searchString }: IProps) => {participantName: string;room: IRoom;}>();- const onRaiseMenu = useCallback(room => (target: HTMLElement) => raiseMenu(room, target), [ raiseMenu ]);+ const onRaiseMenu = useCallback(room => (target: HTMLElement) => {+ // Joining is the only action of a participant who is not a moderator, thus with the join restriction the menu+ // of a breakout room would be empty.+ if (isBreakoutRoomJoinAllowed(store.getState(), room)) {+ raiseMenu(room, target);+ }+ }, [ raiseMenu, store ]);// close the menu when the room vanishesuseEffect(() => {diff --git a/react/features/settings/actions.web.ts b/react/features/settings/actions.web.tsindex 500a6579af..eabcac2a69 100644--- a/react/features/settings/actions.web.ts+++ b/react/features/settings/actions.web.ts@@ -242,7 +242,9 @@ export function submitModeratorTab(newState: any) {if (newState.chatWithPermissionsEnabled !== currentState.chatWithPermissionsEnabled|| newState.privateChatWithPermissionsEnabled !== currentState.privateChatWithPermissionsEnabled- || newState.sharedVideoWithPermissionsEnabled !== currentState.sharedVideoWithPermissionsEnabled) {+ || newState.sharedVideoWithPermissionsEnabled !== currentState.sharedVideoWithPermissionsEnabled+ || newState.breakoutRoomJoinWithPermissionsEnabled+ !== currentState.breakoutRoomJoinWithPermissionsEnabled) {const { conference } = getState()['features/base/conference'];const currentPermissions = conference?.getMetadataHandler().getMetadata().permissions || {};@@ -251,6 +253,7 @@ export function submitModeratorTab(newState: any) {// confirms it, thus a second update here would not see the first one.conference?.getMetadataHandler().setMetadata('permissions', {...currentPermissions,+ breakoutRoomJoinRestricted: newState.breakoutRoomJoinWithPermissionsEnabled,groupChatRestricted: newState.chatWithPermissionsEnabled,privateChatRestricted: newState.privateChatWithPermissionsEnabled,sharedVideoRestricted: newState.sharedVideoWithPermissionsEnableddiff --git a/react/features/settings/components/native/ModeratorSection.tsx b/react/features/settings/components/native/ModeratorSection.tsxindex 01cefa0175..463df88fa3 100644--- a/react/features/settings/components/native/ModeratorSection.tsx+++ b/react/features/settings/components/native/ModeratorSection.tsx@@ -18,10 +18,12 @@ const ModeratorSection = () => {const dispatch = useDispatch();const {audioModerationEnabled,+ breakoutRoomJoinWithPermissionsEnabled,chatWithPermissionsEnabled,privateChatWithPermissionsEnabled,sharedVideoWithPermissionsEnabled,showSharedVideoWithPermissions,+ showBreakoutRoomJoinWithPermissions,followMeActive,followMeEnabled,followMeRecorderActive,@@ -76,7 +78,8 @@ const ModeratorSection = () => {delete pendingPermissions.current[key];}}- }, [ conference, chatWithPermissionsEnabled, privateChatWithPermissionsEnabled, sharedVideoWithPermissionsEnabled ]);+ }, [ conference, chatWithPermissionsEnabled, privateChatWithPermissionsEnabled, sharedVideoWithPermissionsEnabled,+ breakoutRoomJoinWithPermissionsEnabled ]);const setPermission = useCallback((key: string, enabled?: boolean) => {pendingPermissions.current[key] = enabled;@@ -99,6 +102,10 @@ const ModeratorSection = () => {setPermission('sharedVideoRestricted', enabled);}, [ setPermission ]);+ const onBreakoutRoomJoinWithPermissionsToggled = useCallback((enabled?: boolean) => {+ setPermission('breakoutRoomJoinRestricted', enabled);+ }, [ setPermission ]);+const followMeRecorderChecked = followMeRecorderEnabled && !followMeRecorderActive;const moderationSettings = useMemo(() => {@@ -148,6 +155,11 @@ const ModeratorSection = () => {state: sharedVideoWithPermissionsEnabled,onChange: onSharedVideoWithPermissionsToggled},+ {+ label: 'settings.breakoutRoomJoinWithPermissions',+ state: breakoutRoomJoinWithPermissionsEnabled,+ onChange: onBreakoutRoomJoinWithPermissionsToggled+ },];return moderation.filter(({ label }) => {@@ -161,6 +173,10 @@ const ModeratorSection = () => {return showSharedVideoWithPermissions;}+ if (label === 'settings.breakoutRoomJoinWithPermissions') {+ return showBreakoutRoomJoinWithPermissions;+ }+return true;});}, [ startAudioMuted,@@ -180,6 +196,9 @@ const ModeratorSection = () => {privateChatWithPermissionsEnabled,sharedVideoWithPermissionsEnabled,showSharedVideoWithPermissions,+ onBreakoutRoomJoinWithPermissionsToggled,+ breakoutRoomJoinWithPermissionsEnabled,+ showBreakoutRoomJoinWithPermissions,startReactionsMuted ]);return (diff --git a/react/features/settings/components/web/ModeratorTab.tsx b/react/features/settings/components/web/ModeratorTab.tsxindex 963596e5b8..e6bce28d63 100644--- a/react/features/settings/components/web/ModeratorTab.tsx+++ b/react/features/settings/components/web/ModeratorTab.tsx@@ -22,6 +22,11 @@ export interface IProps extends AbstractDialogTabProps, WithTranslation {*/audioTranslationEnabled: boolean;+ /**+ * Whether the user has selected that only moderators, and the participants they move, can join breakout rooms.+ */+ breakoutRoomJoinWithPermissionsEnabled: boolean;+/*** Whether the user has selected the chat with permissions feature to be enabled.*/@@ -77,6 +82,12 @@ export interface IProps extends AbstractDialogTabProps, WithTranslation {*/showAudioTranslation: boolean;+ /**+ * Whether the breakout room join restriction setting should be shown (i.e. it is enabled in the config and+ * breakout rooms are supported).+ */+ showBreakoutRoomJoinWithPermissions: boolean;+/*** Whether the shared video restriction setting should be shown (i.e. it is enabled in the config,* video sharing is enabled and the room does not make every participant a moderator).@@ -150,6 +161,7 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {this._onChatWithPermissionsChanged = this._onChatWithPermissionsChanged.bind(this);this._onPrivateChatWithPermissionsChanged = this._onPrivateChatWithPermissionsChanged.bind(this);this._onSharedVideoWithPermissionsChanged = this._onSharedVideoWithPermissionsChanged.bind(this);+ this._onBreakoutRoomJoinWithPermissionsChanged = this._onBreakoutRoomJoinWithPermissionsChanged.bind(this);this._onAudioTranslationEnabledChanged = this._onAudioTranslationEnabledChanged.bind(this);}@@ -262,6 +274,17 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {super._onChange({ sharedVideoWithPermissionsEnabled: checked });}+ /**+ * Callback invoked to select if joining breakout rooms with permissions should be activated.+ *+ * @param {Object} e - The key event to handle.+ *+ * @returns {void}+ */+ _onBreakoutRoomJoinWithPermissionsChanged({ target: { checked } }: React.ChangeEvent<HTMLInputElement>) {+ super._onChange({ breakoutRoomJoinWithPermissionsEnabled: checked });+ }+/*** Implements React's {@link Component#render()}.*@@ -272,6 +295,7 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {const {audioModerationEnabled,audioTranslationEnabled,+ breakoutRoomJoinWithPermissionsEnabled,chatWithPermissionsEnabled,disableReactionsModeration,followMeActive,@@ -283,6 +307,7 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {sharedVideoWithPermissionsEnabled,showAudioTranslation,showSharedVideoWithPermissions,+ showBreakoutRoomJoinWithPermissions,startAudioMuted,startVideoMuted,startReactionsMuted,@@ -354,6 +379,13 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {label = { t('settings.sharedVideoWithPermissions') }name = 'shared-video-with-permissions'onChange = { this._onSharedVideoWithPermissionsChanged } /> }+ { showBreakoutRoomJoinWithPermissions+ && <Checkbox+ checked = { breakoutRoomJoinWithPermissionsEnabled }+ className = { classes.checkbox }+ label = { t('settings.breakoutRoomJoinWithPermissions') }+ name = 'breakout-room-join-with-permissions'+ onChange = { this._onBreakoutRoomJoinWithPermissionsChanged } /> }{ showAudioTranslation&& <Checkboxchecked = { audioTranslationEnabled }diff --git a/react/features/settings/components/web/SettingsDialog.tsx b/react/features/settings/components/web/SettingsDialog.tsxindex 0e9a524c30..c39faf4f0b 100644--- a/react/features/settings/components/web/SettingsDialog.tsx+++ b/react/features/settings/components/web/SettingsDialog.tsx@@ -264,6 +264,7 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {return {...newProps,audioTranslationEnabled: tabState?.audioTranslationEnabled,+ breakoutRoomJoinWithPermissionsEnabled: tabState?.breakoutRoomJoinWithPermissionsEnabled,chatWithPermissionsEnabled: tabState?.chatWithPermissionsEnabled,privateChatWithPermissionsEnabled: tabState?.privateChatWithPermissionsEnabled,sharedVideoWithPermissionsEnabled: tabState?.sharedVideoWithPermissionsEnabled,diff --git a/react/features/settings/functions.any.ts b/react/features/settings/functions.any.tsindex db02983cd7..f92a1a12cf 100644--- a/react/features/settings/functions.any.ts+++ b/react/features/settings/functions.any.ts@@ -10,6 +10,7 @@ import { getLocalParticipant } from '../base/participants/functions';import { toState } from '../base/redux/functions';import { getHideSelfView } from '../base/settings/functions.any';import { parseStandardURIString } from '../base/util/uri';+import { getBreakoutRoomsConfig, isInBreakoutRoom } from '../breakout-rooms/functions';import { isStageFilmstripEnabled } from '../filmstrip/functions';import { isFollowMeActive, isFollowMeRecorderActive } from '../follow-me/functions';import { isReactionsEnabled } from '../reactions/functions.any';@@ -166,6 +167,7 @@ export function getModeratorTabProps(stateful: IStateful) {const { sharedVideoRestricted } = state['features/shared-video'];const {audioTranslation,+ showBreakoutRoomJoinPermissionsModeratorSetting,showChatPermissionsModeratorSetting,showSharedVideoPermissionsModeratorSetting,disableReactionsModeration@@ -175,6 +177,14 @@ export function getModeratorTabProps(stateful: IStateful) {const showModeratorSettings = shouldShowModeratorSettings(state);const conferenceMetadata = conference?.getMetadataHandler()?.getMetadata();const hideChatWithPermissions = !showChatPermissionsModeratorSetting || conferenceMetadata?.allownersEnabled;+ const { hideJoinRoomButton } = getBreakoutRoomsConfig(state);+ // The restriction is a setting of the main room, a breakout room has its own metadata that the server ignores+ // for it. When everyone is an owner (allowners), nobody is restricted.+ const showBreakoutRoomJoinWithPermissions = Boolean(showBreakoutRoomJoinPermissionsModeratorSetting)+ && Boolean(conference?.getBreakoutRooms()?.isSupported())+ && !hideJoinRoomButton+ && !isInBreakoutRoom(state)+ && !conferenceMetadata?.allownersEnabled;const isAudioModerationEnabled = isEnabledFromState(MEDIA_TYPE.AUDIO, state);const isVideoModerationEnabled = isEnabledFromState(MEDIA_TYPE.VIDEO, state);@@ -184,12 +194,14 @@ export function getModeratorTabProps(stateful: IStateful) {audioTranslationEnabled: Boolean(conference) && conferenceMetadata?.audioTranslation?.enabled !== false,showAudioTranslation: Boolean(audioTranslation?.enabled),videoModerationEnabled: isVideoModerationEnabled,+ breakoutRoomJoinWithPermissionsEnabled: Boolean(conferenceMetadata?.permissions?.breakoutRoomJoinRestricted),chatWithPermissionsEnabled: Boolean(groupChatWithPermissions),privateChatWithPermissionsEnabled: Boolean(privateChatWithPermissions),sharedVideoWithPermissionsEnabled: Boolean(sharedVideoRestricted),showSharedVideoWithPermissions: Boolean(showSharedVideoPermissionsModeratorSetting)&& !conferenceMetadata?.allownersEnabled&& isSharedVideoEnabled(state),+ showBreakoutRoomJoinWithPermissions,showModeratorSettings: Boolean(conference && showModeratorSettings),disableReactionsModeration: Boolean(disableReactionsModeration),followMeActive: Boolean(conference && followMeActive),diff --git a/resources/prosody-plugins/mod_muc_breakout_rooms.lua b/resources/prosody-plugins/mod_muc_breakout_rooms.luaindex 2f6debc83b..e0eb7a7395 100644--- a/resources/prosody-plugins/mod_muc_breakout_rooms.lua+++ b/resources/prosody-plugins/mod_muc_breakout_rooms.lua@@ -73,6 +73,9 @@ local main_rooms_map = {};local cache = require 'util.cache';local switching_room_cache = cache.new(1000);+-- How long, in seconds, a move that a moderator requested lets the participant join the target room.+local MOVE_REQUEST_TTL = 30;+-- Utility functionsfunction get_main_room_jid(room_jid)@@ -99,6 +102,39 @@ function get_room_from_jid(room_jid)or breakout_rooms_muc_service.get_room_from_jid(room_jid);end+-- The moves that moderators requested are kept on the main room object (main_room.move_requests, not in _data so they+-- are not saved), keyed by the real full JID of the participant. When the main room restricts joining breakout rooms+-- (permissions.breakoutRoomJoinRestricted in the room metadata), a participant who is not a moderator can join a+-- breakout room only through such a move. They go away with the main room.++-- Remembers that a moderator moved a participant to a breakout room. Drops the moves of the room that expired.+-- @param main_room - The main room+-- @param participant_jid - The real full JID of the participant+-- @param room_jid - The breakout room the participant is moved to+function add_move_request(main_room, participant_jid, room_jid)+ local now = os.time();+ local move_requests = main_room.move_requests or {};++ for jid, move_request in pairs(move_requests) do+ if move_request.expires < now then+ move_requests[jid] = nil;+ end+ end++ move_requests[participant_jid] = {+ room_jid = room_jid,+ expires = now + MOVE_REQUEST_TTL+ };+ main_room.move_requests = move_requests;+end++-- Returns the move a moderator requested for a participant in the main room, if any.+-- @param main_room - The main room+-- @param participant_jid - The real full JID of the participant+function get_move_request(main_room, participant_jid)+ return main_room.move_requests and main_room.move_requests[participant_jid];+end+function send_json_msg(to_jid, json_msg)local stanza = st.message({ from = breakout_rooms_muc_component_config; to = to_jid; }):tag('json-message', { xmlns = 'http://jitsi.org/jitmeet' }):text(json_msg):up();@@ -176,6 +212,7 @@ function broadcast_breakout_rooms(room_jid)local json_msg, error = json.encode({type = BREAKOUT_ROOMS_IDENTITY_TYPE,event = JSON_TYPE_UPDATE_BREAKOUT_ROOMS,+ joinRestricted = is_breakout_room_join_restricted(main_room),roomCounter = main_room._data.breakout_rooms_counter,rooms = rooms});@@ -363,6 +400,11 @@ function on_message(event)return falseend+ -- Returning to the main room is always allowed, only a move to a breakout room needs to be remembered.+ if room._data.breakout_rooms[target_room_jid] then+ add_move_request(room, participant_jid, target_room_jid);+ end+send_json_msg(participant_jid, json_msg)return true;end@@ -406,6 +448,14 @@ function on_occupant_joined(event)local main_room, main_room_jid = get_main_room(room.jid);local isFocus = is_admin(occupant.bare_jid);+ -- The occupant is in the room a moderator moved them to, the move is used up.+ local real_jid = event.stanza and event.stanza.attr.from;+ local move_request = main_room and real_jid and get_move_request(main_room, real_jid);++ if move_request and move_request.room_jid == room.jid then+ main_room.move_requests[real_jid] = nil;+ end+if main_room and main_room._data.breakout_rooms_active thenif not isFocus thenbroadcast_breakout_rooms(main_room_jid);@@ -537,6 +587,8 @@ function on_main_room_destroyed(event)for breakout_room_jid in pairs(main_room._data.breakout_rooms or {}) dodestroy_breakout_room(main_room, breakout_room_jid, event.reason)end++ main_room.move_requests = nil;end-- Checks for a conflict with a JID in the switching_room_cache. In case of a conflict sends an error and returns true (the join is not allowed).@@ -631,6 +683,57 @@ function on_occupant_pre_join_or_change(e)endend+-- Returns true when the main room restricts joining breakout rooms to moderators and the moves they request.+-- @param main_room - The main room+function is_breakout_room_join_restricted(main_room)+ local permissions = main_room.jitsiMetadata and main_room.jitsiMetadata.permissions;++ return permissions and permissions.breakoutRoomJoinRestricted == true or false;+end++-- Returns true when the main room restricts joining breakout rooms and the occupant may not join the breakout room+-- by themselves. A moderator of the main room can always join. Another occupant can join only a room that a moderator+-- moved them to. Returning to the main room is not checked here, it is always allowed. The move is used up in+-- on_occupant_joined, once the join succeeded, thus a join that another handler rejects can be retried.+-- @param main_room - The main room+-- @param room - The breakout room being joined+-- @param from_jid - The real full JID of the occupant trying to join+function is_breakout_room_join_blocked(main_room, room, from_jid)+ if not is_breakout_room_join_restricted(main_room) then+ return false;+ end++ if main_room:get_affiliation(jid_bare(from_jid)) == 'owner' then+ return false;+ end++ local move_request = get_move_request(main_room, from_jid);++ if move_request and move_request.room_jid == room.jid and move_request.expires >= os.time() then+ return false;+ end++ return true;+end++-- This is a request to join a breakout room. When the main room restricts joining breakout rooms, a participant who+-- is not a moderator needs a move from a moderator.+function on_breakout_room_pre_join(e)+ local room, stanza, origin = e.room, e.stanza, e.origin;+ local occupant = e.dest_occupant or e.occupant;++ if is_admin(occupant.bare_jid) then+ return;+ end++ local main_room = get_main_room(room.jid);++ if main_room and is_breakout_room_join_blocked(main_room, room, stanza.attr.from) then+ origin.send(st.error_reply(stanza, 'cancel', 'not-allowed', 'Joining breakout rooms not allowed'));+ return true;+ end+end+-- Module operations-- operates on already loaded breakout rooms muc module@@ -658,6 +761,7 @@ function process_breakout_rooms_muc_loaded(breakout_rooms_muc, host_module)host_module:hook('muc-occupant-pre-leave', on_occupant_pre_leave);host_module:hook('muc-occupant-pre-join', on_occupant_pre_join_or_change);host_module:hook('muc-occupant-pre-change', on_occupant_pre_join_or_change);+ host_module:hook('muc-occupant-pre-join', on_breakout_room_pre_join);host_module:hook('muc-disco#info', function (event)local room = event.room;@@ -794,6 +898,16 @@ function process_main_muc_loaded(main_muc, host_module)host_module:hook('muc-occupant-pre-join', on_occupant_pre_join_or_change);host_module:hook('muc-occupant-pre-change', on_occupant_pre_join_or_change);++ -- The occupants of the breakout rooms do not receive the metadata of the main room, thus send them the+ -- breakout room join restriction with the breakout rooms update when a moderator changes it.+ host_module:hook('jitsi-metadata-updated', function(event)+ local room = event.room;++ if event.key == 'permissions' and room and room._data.breakout_rooms_active then+ broadcast_breakout_rooms(room.jid);+ end+ end);end-- process or waits to process the main muc componentdiff --git a/tests/prosody/mod_muc_breakout_rooms_spec.js b/tests/prosody/mod_muc_breakout_rooms_spec.jsindex 32e04bfa13..75a765bc88 100644--- a/tests/prosody/mod_muc_breakout_rooms_spec.js+++ b/tests/prosody/mod_muc_breakout_rooms_spec.js@@ -1,16 +1,19 @@import assert from 'assert';import { mintAsapToken } from './helpers/jwt.js';+import { prosodyShell } from './helpers/prosody_shell.js';import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';const CONFERENCE = 'conference.localhost';const BREAKOUT_MUC = 'breakout.conference.localhost';+const METADATA_COMPONENT = 'metadata.localhost';const JITMEET_NS = 'http://jitsi.org/jitmeet';// JSON message type constants (must match mod_muc_breakout_rooms.lua)const BREAKOUT_ROOMS_TYPE = 'breakout_rooms';const EVENT_UPDATE = 'features/breakout-rooms/update';const OP_ADD = 'features/breakout-rooms/add';+const OP_MOVE = 'features/breakout-rooms/move-to-room';const OP_REMOVE = 'features/breakout-rooms/remove';const OP_RENAME = 'features/breakout-rooms/rename';@@ -60,6 +63,25 @@ async function waitForBreakoutUpdate(client, timeout = 6000) {return parseJsonMessage(stanza);}+/**+ * Waits for a breakout_rooms update broadcast that satisfies the predicate.+ * Earlier updates that do not match are left in the queue.+ *+ * @param {object} client+ * @param {Function} predicate Receives the parsed payload.+ * @param {number} [timeout=6000]+ * @returns {Promise<object>}+ */+async function waitForBreakoutUpdateWhere(client, predicate, timeout = 6000) {+ const stanza = await client.waitForMessage(s => {+ const p = parseJsonMessage(s);++ return p?.type === BREAKOUT_ROOMS_TYPE && p?.event === EVENT_UPDATE && predicate(p);+ }, timeout);++ return parseJsonMessage(stanza);+}+/*** Creates a conference room with focus and an authenticated moderator.*@@ -370,4 +392,239 @@ describe('mod_muc_breakout_rooms', () => {});+ // -------------------------------------------------------------------------+ // joining breakout rooms restricted to moderators and the moves they request+ // -------------------------------------------------------------------------+ describe('breakoutRoomJoinRestricted', () => {++ /**+ * Creates a room with a moderator, two physically created breakout rooms and an+ * anonymous participant in the main room. Restricts joining breakout rooms when asked.+ *+ * @param {boolean} restricted Whether to set permissions.breakoutRoomJoinRestricted.+ */+ async function setup(restricted) {+ const name = nextRoomName();+ const { focus, moderator } = await createRoom(name);++ clients.push(focus, moderator);++ await moderator.sendBreakoutRoomsMessage(BREAKOUT_MUC, OP_ADD, { subject: 'Group 1' });+ await moderator.sendBreakoutRoomsMessage(BREAKOUT_MUC, OP_ADD, { subject: 'Group 2' });++ const created = await waitForBreakoutUpdateWhere(moderator,+ p => Object.values(p.rooms).filter(r => !r.isMainRoom).length === 2);+ const [ room1, room2 ] = Object.values(created.rooms).filter(r => !r.isMainRoom)+ .map(r => r.jid);++ // Focus creates the breakout rooms, the component restricts room creation.+ await focus.joinRoom(room1, 'focus');+ await focus.joinRoom(room2, 'focus');++ const participant = await createXmppClient({ params: { room: name } });++ clients.push(participant);+ await participant.joinRoom(roomJid(name));++ if (restricted) {+ moderator.sendMetadataUpdate(METADATA_COMPONENT, roomJid(name), 'permissions',+ { breakoutRoomJoinRestricted: true });++ // The module sends the restriction with the breakout rooms update.+ await waitForBreakoutUpdateWhere(participant, p => p.joinRestricted === true);+ }++ return { moderator,+ name,+ participant,+ room1,+ room2 };+ }++ /**+ * Returns the Lua expression for the main room object of the given room name.+ *+ * @param {string} name bare room name+ * @returns {string}+ */+ const mainRoomLua = name => `prosody.hosts["${CONFERENCE}"].modules.muc.get_room_from_jid("${roomJid(name)}")`;++ /**+ * Asks the moderator to move the participant to the breakout room and waits until the participant gets the+ * request.+ *+ * @param {object} moderator+ * @param {object} participant+ * @param {string} breakoutRoomJid+ * @returns {Promise<void>}+ */+ async function move(moderator, participant, breakoutRoomJid) {+ await moderator.sendBreakoutRoomsMessage(BREAKOUT_MUC, OP_MOVE, {+ participantJid: participant.jid,+ roomJid: breakoutRoomJid+ });+ await participant.waitForMessage(s => parseJsonMessage(s)?.event === OP_MOVE);+ }++ it('participant can join a breakout room when breakoutRoomJoinRestricted is not set', async () => {+ const { participant, room1 } = await setup(false);++ const presence = await participant.joinRoom(room1);++ assert.notEqual(presence.attrs.type, 'error', 'join must be allowed when not restricted');+ });++ it('breakout rooms update carries joinRestricted', async () => {+ const { moderator } = await setup(true);++ const update = await waitForBreakoutUpdateWhere(moderator, p => p.joinRestricted === true);++ assert.strictEqual(update.joinRestricted, true);+ });++ it('participant cannot join a breakout room by themselves when breakoutRoomJoinRestricted is true',+ async () => {+ const { participant, room1 } = await setup(true);++ const presence = await participant.joinRoom(room1);++ assert.strictEqual(presence.attrs.type, 'error', 'self join must be rejected');+ assert.ok(presence.getChild('error')?.getChild('not-allowed'), 'expected <not-allowed/>');+ });++ it('participant can join the room a moderator moved them to when breakoutRoomJoinRestricted is true',+ async () => {+ const { moderator, participant, room1 } = await setup(true);++ await moderator.sendBreakoutRoomsMessage(BREAKOUT_MUC, OP_MOVE, {+ participantJid: participant.jid,+ roomJid: room1+ });+ await participant.waitForMessage(s => parseJsonMessage(s)?.event === OP_MOVE);++ const presence = await participant.joinRoom(room1);++ assert.notEqual(presence.attrs.type, 'error', 'join after a move must be allowed');+ });++ it('a move to one breakout room does not allow joining another one', async () => {+ const { moderator, participant, room1, room2 } = await setup(true);++ await moderator.sendBreakoutRoomsMessage(BREAKOUT_MUC, OP_MOVE, {+ participantJid: participant.jid,+ roomJid: room1+ });+ await participant.waitForMessage(s => parseJsonMessage(s)?.event === OP_MOVE);++ const presence = await participant.joinRoom(room2);++ assert.strictEqual(presence.attrs.type, 'error', 'join to another room must be rejected');+ });++ it('a move is used up once the participant joined the room', async () => {+ const { moderator, participant, room1 } = await setup(true);++ await moderator.sendBreakoutRoomsMessage(BREAKOUT_MUC, OP_MOVE, {+ participantJid: participant.jid,+ roomJid: room1+ });+ await participant.waitForMessage(s => parseJsonMessage(s)?.event === OP_MOVE);++ const joined = await participant.joinRoom(room1);++ assert.notEqual(joined.attrs.type, 'error', 'join after a move must be allowed');++ await participant.leaveRoom(room1);++ const rejoined = await participant.joinRoom(room1);++ assert.strictEqual(rejoined.attrs.type, 'error', 'a second join with the same move must be rejected');+ });++ it('a move is kept when another handler rejects the join', async () => {+ const { moderator, participant, room1 } = await setup(true);++ // Rejects the first join of the participant after this module allowed it, e.g. as a members-only or+ // max-occupants check would.+ await prosodyShell([+ '>local st = require "util.stanza";',+ 'local rejected = false;',+ `prosody.hosts["${BREAKOUT_MUC}"].events.add_handler("muc-occupant-pre-join", function(e)`,+ `if not rejected and e.stanza.attr.from == "${participant.jid}" then`,+ 'rejected = true;',+ 'e.origin.send(st.error_reply(e.stanza, "cancel", "service-unavailable"));',+ 'return true;',+ 'end end, -100)'+ ].join(' '));++ await moderator.sendBreakoutRoomsMessage(BREAKOUT_MUC, OP_MOVE, {+ participantJid: participant.jid,+ roomJid: room1+ });+ await participant.waitForMessage(s => parseJsonMessage(s)?.event === OP_MOVE);++ const rejected = await participant.joinRoom(room1);++ assert.ok(rejected.getChild('error')?.getChild('service-unavailable'),+ 'the first join must be rejected by the other handler');++ const retried = await participant.joinRoom(room1);++ assert.notEqual(retried.attrs.type, 'error', 'the move must still allow the retried join');+ });++ it('a move in one conference does not allow joining a breakout room of another conference', async () => {+ const other = await setup(true);+ const { moderator, room1 } = await setup(true);++ // The moderator of this conference moves the participant of the other conference to its own room.+ await move(moderator, other.participant, room1);++ const presence = await other.participant.joinRoom(other.room1);++ assert.strictEqual(presence.attrs.type, 'error', 'a move in another conference must not allow the join');+ assert.ok(presence.getChild('error')?.getChild('not-allowed'), 'expected <not-allowed/>');+ });++ it('an expired move does not allow joining the room', async () => {+ const { moderator, name, participant, room1 } = await setup(true);++ await move(moderator, participant, room1);++ // Expire the move instead of waiting for it to time out.+ await prosodyShell(`>${mainRoomLua(name)}.move_requests["${participant.jid}"].expires = 0`);++ const presence = await participant.joinRoom(room1);++ assert.strictEqual(presence.attrs.type, 'error', 'an expired move must not allow the join');+ assert.ok(presence.getChild('error')?.getChild('not-allowed'), 'expected <not-allowed/>');+ });++ it('pending moves are cleared when the main room is destroyed', async () => {+ const { moderator, name, participant, room1 } = await setup(true);++ await move(moderator, participant, room1);++ // Keep a reference to the room object, a new room with the same name is another object.+ const pending = '>print("pending:" .. tostring(prosody.br_test_room.move_requests ~= nil))';++ await prosodyShell(`>prosody.br_test_room = ${mainRoomLua(name)}`);+ assert.match(await prosodyShell(pending), /pending:true/, 'the move must be pending before the destroy');++ await prosodyShell('>prosody.br_test_room:destroy()');++ const after = await prosodyShell(pending);++ await prosodyShell('>prosody.br_test_room = nil');+ assert.match(after, /pending:false/, 'the moves must be cleared with the main room');+ });++ it('moderator can join a breakout room when breakoutRoomJoinRestricted is true', async () => {+ const { moderator, room1 } = await setup(true);++ const presence = await moderator.joinRoom(room1);++ assert.notEqual(presence.attrs.type, 'error', 'a moderator must keep joining breakout rooms');+ });+ });});