Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(shared-video): let moderators restrict video sharing to participants with permission (#17981)

moataz hjaijic1c5cc0388e6
diff --git a/config.js b/config.js
index 6ff0266aa0..0008eb8dd3 100644
--- a/config.js
+++ b/config.js
@@ -160,6 +160,11 @@ var config = {
// Shows/hides the moderator setting for chat permissions.
// showChatPermissionsModeratorSetting: false,
+ // Shows/hides the moderator setting that restricts video sharing to the participants with the
+ // `share-video` permission. The restriction is enforced by the mod_filter_messages prosody module,
+ // thus enable this only when that module is loaded.
+ // showSharedVideoPermissionsModeratorSetting: false,
+
// screenshotCapture : {
// Enables the screensharing capture feature.
// enabled: false,
diff --git a/lang/main.json b/lang/main.json
index 4081bb0e35..42619a1045 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -993,6 +993,7 @@
"selfViewTitle": "You can always un-hide the self-view from settings",
"settingsIncompleteDescription": "Some meeting settings could not be loaded and default values were used instead.",
"settingsIncompleteTitle": "Meeting settings may be incomplete",
+ "sharedVideoRestricted": "A moderator turned off video sharing for non-moderators",
"somebody": "Somebody",
"startSilentDescription": "Rejoin the meeting to enable audio",
"startSilentTitle": "You joined with no audio output!",
@@ -1341,6 +1342,7 @@
"selectCamera": "Camera",
"selectMic": "Microphone",
"selfView": "Self view",
+ "sharedVideoWithPermissions": "Disable video sharing for non-moderators",
"shortcuts": "Shortcuts",
"showSubtitlesOnStage": "Show subtitles on stage",
"speakers": "Speakers",
diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.ts
index c1d25b2052..3f1aa01805 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>;
showChatPermissionsModeratorSetting?: boolean;
+ showSharedVideoPermissionsModeratorSetting?: boolean;
sipInviteUrl?: string;
speakerStats?: {
disableSearch?: boolean;
diff --git a/react/features/base/config/configWhitelist.ts b/react/features/base/config/configWhitelist.ts
index a806760cd5..25a351db92 100644
--- a/react/features/base/config/configWhitelist.ts
+++ b/react/features/base/config/configWhitelist.ts
@@ -227,6 +227,7 @@ export default [
'secondScreen',
'securityUi',
'showChatPermissionsModeratorSetting',
+ 'showSharedVideoPermissionsModeratorSetting',
'speakerStats',
'startAudioMuted',
'startLowBandwidthMode',
diff --git a/react/features/base/jwt/constants.ts b/react/features/base/jwt/constants.ts
index edefa2af15..b0140975b1 100644
--- a/react/features/base/jwt/constants.ts
+++ b/react/features/base/jwt/constants.ts
@@ -20,6 +20,7 @@ export const MEET_FEATURES: Record<string, ParticipantFeaturesKey> = {
SCREEN_SHARING: 'screen-sharing',
SEND_GROUPCHAT: 'send-groupchat',
SEND_PRIVATE_MESSAGE: 'send-private-message',
+ SHARE_VIDEO: 'share-video',
LIST_VISITORS: 'list-visitors',
SIP_INBOUND_CALL: 'sip-inbound-call',
SIP_OUTBOUND_CALL: 'sip-outbound-call',
diff --git a/react/features/base/participants/types.ts b/react/features/base/participants/types.ts
index b2a8bda369..a57646cc59 100644
--- a/react/features/base/participants/types.ts
+++ b/react/features/base/participants/types.ts
@@ -79,6 +79,7 @@ export interface IParticipantFeatures {
'screen-sharing'?: boolean | string;
'send-groupchat'?: boolean | string;
'send-private-message'?: boolean | string;
+ 'share-video'?: boolean | string;
'sip-inbound-call'?: boolean | string;
'sip-outbound-call'?: boolean | string;
'transcription'?: boolean | string;
diff --git a/react/features/settings/actions.web.ts b/react/features/settings/actions.web.ts
index 018b4c3d82..50679ce442 100644
--- a/react/features/settings/actions.web.ts
+++ b/react/features/settings/actions.web.ts
@@ -204,15 +204,19 @@ export function submitModeratorTab(newState: any) {
}
if (newState.chatWithPermissionsEnabled !== currentState.chatWithPermissionsEnabled
- || newState.privateChatWithPermissionsEnabled !== currentState.privateChatWithPermissionsEnabled) {
+ || newState.privateChatWithPermissionsEnabled !== currentState.privateChatWithPermissionsEnabled
+ || newState.sharedVideoWithPermissionsEnabled !== currentState.sharedVideoWithPermissionsEnabled) {
const { conference } = getState()['features/base/conference'];
const currentPermissions = conference?.getMetadataHandler().getMetadata().permissions || {};
+ // One update for all the restrictions. The metadata changes only when the server
+ // confirms it, thus a second update here would not see the first one.
conference?.getMetadataHandler().setMetadata('permissions', {
...currentPermissions,
groupChatRestricted: newState.chatWithPermissionsEnabled,
- privateChatRestricted: newState.privateChatWithPermissionsEnabled
+ privateChatRestricted: newState.privateChatWithPermissionsEnabled,
+ sharedVideoRestricted: newState.sharedVideoWithPermissionsEnabled
});
}
diff --git a/react/features/settings/components/native/ModeratorSection.tsx b/react/features/settings/components/native/ModeratorSection.tsx
index d66c825472..01cefa0175 100644
--- a/react/features/settings/components/native/ModeratorSection.tsx
+++ b/react/features/settings/components/native/ModeratorSection.tsx
@@ -1,4 +1,4 @@
-import React, { useCallback, useMemo } from 'react';
+import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { IReduxState } from '../../../app/types';
@@ -20,6 +20,8 @@ const ModeratorSection = () => {
audioModerationEnabled,
chatWithPermissionsEnabled,
privateChatWithPermissionsEnabled,
+ sharedVideoWithPermissionsEnabled,
+ showSharedVideoWithPermissions,
followMeActive,
followMeEnabled,
followMeRecorderActive,
@@ -56,23 +58,46 @@ const ModeratorSection = () => {
}, [ dispatch, updateSettings, setStartReactionsMuted ]);
const { conference } = useSelector((state: IReduxState) => state['features/base/conference']);
- const onChatWithPermissionsToggled = useCallback((enabled?: boolean) => {
- const currentPermissions = conference?.getMetadataHandler().getMetadata().permissions || {};
+
+ // The permissions that were set but that the server has not confirmed yet. The metadata changes only
+ // when the server confirms it, thus a second toggle before that would put back the old value of the first.
+ const pendingPermissions = useRef<Record<string, boolean | undefined>>({});
+
+ // The values that were not confirmed belong to the previous room, e.g. when moving to a breakout room.
+ useEffect(() => {
+ pendingPermissions.current = {};
+ }, [ conference ]);
+
+ useEffect(() => {
+ const confirmed = conference?.getMetadataHandler().getMetadata().permissions || {};
+
+ for (const key of Object.keys(pendingPermissions.current)) {
+ if (Boolean(confirmed[key]) === Boolean(pendingPermissions.current[key])) {
+ delete pendingPermissions.current[key];
+ }
+ }
+ }, [ conference, chatWithPermissionsEnabled, privateChatWithPermissionsEnabled, sharedVideoWithPermissionsEnabled ]);
+
+ const setPermission = useCallback((key: string, enabled?: boolean) => {
+ pendingPermissions.current[key] = enabled;
conference?.getMetadataHandler().setMetadata('permissions', {
- ...currentPermissions,
- groupChatRestricted: enabled
+ ...conference?.getMetadataHandler().getMetadata().permissions,
+ ...pendingPermissions.current
});
- }, [ dispatch, conference ]);
+ }, [ conference ]);
+
+ const onChatWithPermissionsToggled = useCallback((enabled?: boolean) => {
+ setPermission('groupChatRestricted', enabled);
+ }, [ setPermission ]);
const onPrivateChatWithPermissionsToggled = useCallback((enabled?: boolean) => {
- const currentPermissions = conference?.getMetadataHandler().getMetadata().permissions || {};
+ setPermission('privateChatRestricted', enabled);
+ }, [ setPermission ]);
- conference?.getMetadataHandler().setMetadata('permissions', {
- ...currentPermissions,
- privateChatRestricted: enabled
- });
- }, [ dispatch, conference ]);
+ const onSharedVideoWithPermissionsToggled = useCallback((enabled?: boolean) => {
+ setPermission('sharedVideoRestricted', enabled);
+ }, [ setPermission ]);
const followMeRecorderChecked = followMeRecorderEnabled && !followMeRecorderActive;
@@ -118,15 +143,26 @@ const ModeratorSection = () => {
state: privateChatWithPermissionsEnabled,
onChange: onPrivateChatWithPermissionsToggled
},
+ {
+ label: 'settings.sharedVideoWithPermissions',
+ state: sharedVideoWithPermissionsEnabled,
+ onChange: onSharedVideoWithPermissionsToggled
+ },
];
- if (disableReactionsModeration) {
- // Remove the reactions entry by name. A pop() here took out whichever
+ return moderation.filter(({ label }) => {
+ // Remove the entries by name. A pop() here took out whichever
// entry came last, which is not the reactions one.
- return moderation.filter(({ label }) => label !== 'settings.startReactionsMuted');
- }
+ if (label === 'settings.startReactionsMuted') {
+ return !disableReactionsModeration;
+ }
+
+ if (label === 'settings.sharedVideoWithPermissions') {
+ return showSharedVideoWithPermissions;
+ }
- return moderation;
+ return true;
+ });
}, [ startAudioMuted,
startVideoMuted,
followMeEnabled,
@@ -139,8 +175,11 @@ const ModeratorSection = () => {
onStartReactionsMutedToggled,
onChatWithPermissionsToggled,
onPrivateChatWithPermissionsToggled,
+ onSharedVideoWithPermissionsToggled,
chatWithPermissionsEnabled,
privateChatWithPermissionsEnabled,
+ sharedVideoWithPermissionsEnabled,
+ showSharedVideoWithPermissions,
startReactionsMuted ]);
return (
diff --git a/react/features/settings/components/web/ModeratorTab.tsx b/react/features/settings/components/web/ModeratorTab.tsx
index c17094df7f..963596e5b8 100644
--- a/react/features/settings/components/web/ModeratorTab.tsx
+++ b/react/features/settings/components/web/ModeratorTab.tsx
@@ -67,11 +67,22 @@ export interface IProps extends AbstractDialogTabProps, WithTranslation {
*/
privateChatWithPermissionsEnabled: boolean;
+ /**
+ * Whether the user has selected to restrict video sharing to the participants that have the permission for it.
+ */
+ sharedVideoWithPermissionsEnabled: boolean;
+
/**
* Whether the audio-translation room toggle should be shown (i.e. the feature is deployed).
*/
showAudioTranslation: 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).
+ */
+ showSharedVideoWithPermissions: boolean;
+
/**
* Whether or not the user has selected the Start Audio Muted feature to be
* enabled.
@@ -138,6 +149,7 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {
this._onFollowMeRecorderEnabledChanged = this._onFollowMeRecorderEnabledChanged.bind(this);
this._onChatWithPermissionsChanged = this._onChatWithPermissionsChanged.bind(this);
this._onPrivateChatWithPermissionsChanged = this._onPrivateChatWithPermissionsChanged.bind(this);
+ this._onSharedVideoWithPermissionsChanged = this._onSharedVideoWithPermissionsChanged.bind(this);
this._onAudioTranslationEnabledChanged = this._onAudioTranslationEnabledChanged.bind(this);
}
@@ -239,6 +251,17 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {
super._onChange({ privateChatWithPermissionsEnabled: checked });
}
+ /**
+ * Callback invoked to select if video sharing with permissions should be activated.
+ *
+ * @param {Object} e - The key event to handle.
+ *
+ * @returns {void}
+ */
+ _onSharedVideoWithPermissionsChanged({ target: { checked } }: React.ChangeEvent<HTMLInputElement>) {
+ super._onChange({ sharedVideoWithPermissionsEnabled: checked });
+ }
+
/**
* Implements React's {@link Component#render()}.
*
@@ -257,7 +280,9 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {
followMeRecorderEnabled,
hideChatWithPermissions,
privateChatWithPermissionsEnabled,
+ sharedVideoWithPermissionsEnabled,
showAudioTranslation,
+ showSharedVideoWithPermissions,
startAudioMuted,
startVideoMuted,
startReactionsMuted,
@@ -322,6 +347,13 @@ class ModeratorTab extends AbstractDialogTab<IProps, any> {
label = { t('settings.privateChatWithPermissions') }
name = 'private-chat-with-permissions'
onChange = { this._onPrivateChatWithPermissionsChanged } /> }
+ { showSharedVideoWithPermissions
+ && <Checkbox
+ checked = { sharedVideoWithPermissionsEnabled }
+ className = { classes.checkbox }
+ label = { t('settings.sharedVideoWithPermissions') }
+ name = 'shared-video-with-permissions'
+ onChange = { this._onSharedVideoWithPermissionsChanged } /> }
{ showAudioTranslation
&& <Checkbox
checked = { audioTranslationEnabled }
diff --git a/react/features/settings/components/web/SettingsDialog.tsx b/react/features/settings/components/web/SettingsDialog.tsx
index 4b3daa6a0d..e106546287 100644
--- a/react/features/settings/components/web/SettingsDialog.tsx
+++ b/react/features/settings/components/web/SettingsDialog.tsx
@@ -257,6 +257,7 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
audioTranslationEnabled: tabState?.audioTranslationEnabled,
chatWithPermissionsEnabled: tabState?.chatWithPermissionsEnabled,
privateChatWithPermissionsEnabled: tabState?.privateChatWithPermissionsEnabled,
+ sharedVideoWithPermissionsEnabled: tabState?.sharedVideoWithPermissionsEnabled,
followMeEnabled: tabState?.followMeEnabled,
followMeRecorderEnabled: tabState?.followMeRecorderEnabled,
startAudioMuted: tabState?.startAudioMuted,
diff --git a/react/features/settings/functions.any.ts b/react/features/settings/functions.any.ts
index 89edcf60e1..db02983cd7 100644
--- a/react/features/settings/functions.any.ts
+++ b/react/features/settings/functions.any.ts
@@ -13,6 +13,7 @@ import { parseStandardURIString } from '../base/util/uri';
import { isStageFilmstripEnabled } from '../filmstrip/functions';
import { isFollowMeActive, isFollowMeRecorderActive } from '../follow-me/functions';
import { isReactionsEnabled } from '../reactions/functions.any';
+import { isSharedVideoEnabled } from '../shared-video/functions';
import { areClosedCaptionsEnabled } from '../subtitles/functions.any';
import { iAmVisitor } from '../visitors/functions';
@@ -162,9 +163,11 @@ export function getModeratorTabProps(stateful: IStateful) {
} = state['features/base/conference'];
const { followMeEnabled, followMeRecorderEnabled } = state['features/follow-me'];
const { groupChatWithPermissions, privateChatWithPermissions } = state['features/chat'];
+ const { sharedVideoRestricted } = state['features/shared-video'];
const {
audioTranslation,
showChatPermissionsModeratorSetting,
+ showSharedVideoPermissionsModeratorSetting,
disableReactionsModeration
} = state['features/base/config'];
const followMeActive = isFollowMeActive(state);
@@ -183,6 +186,10 @@ export function getModeratorTabProps(stateful: IStateful) {
videoModerationEnabled: isVideoModerationEnabled,
chatWithPermissionsEnabled: Boolean(groupChatWithPermissions),
privateChatWithPermissionsEnabled: Boolean(privateChatWithPermissions),
+ sharedVideoWithPermissionsEnabled: Boolean(sharedVideoRestricted),
+ showSharedVideoWithPermissions: Boolean(showSharedVideoPermissionsModeratorSetting)
+ && !conferenceMetadata?.allownersEnabled
+ && isSharedVideoEnabled(state),
showModeratorSettings: Boolean(conference && showModeratorSettings),
disableReactionsModeration: Boolean(disableReactionsModeration),
followMeActive: Boolean(conference && followMeActive),
diff --git a/react/features/shared-video/actions.ts b/react/features/shared-video/actions.ts
index 119e22d3e8..ea3f2472ed 100644
--- a/react/features/shared-video/actions.ts
+++ b/react/features/shared-video/actions.ts
@@ -11,7 +11,7 @@ import {
} from './actionTypes';
import { ShareVideoConfirmDialog, SharedVideoDialog } from './components';
import { PLAYBACK_START, PLAYBACK_STATUSES } from './constants';
-import { isSharedVideoEnabled, sendShareVideoCommand } from './functions';
+import { canShareVideo, sendShareVideoCommand } from './functions';
/**
@@ -112,7 +112,7 @@ export function stopSharedVideo() {
*/
export function playSharedVideo(videoUrl: string) {
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
- if (!isSharedVideoEnabled(getState())) {
+ if (!canShareVideo(getState())) {
return;
}
const conference = getCurrentConference(getState());
diff --git a/react/features/shared-video/functions.ts b/react/features/shared-video/functions.ts
index b96c7ec1f8..a012932ea0 100644
--- a/react/features/shared-video/functions.ts
+++ b/react/features/shared-video/functions.ts
@@ -1,6 +1,8 @@
import { IStateful } from '../base/app/types';
import { IJitsiConference } from '../base/conference/reducer';
-import { getFakeParticipants } from '../base/participants/functions';
+import { MEET_FEATURES } from '../base/jwt/constants';
+import { isJwtFeatureEnabled } from '../base/jwt/functions';
+import { getFakeParticipants, getLocalParticipant } from '../base/participants/functions';
import { toState } from '../base/redux/functions';
import {
@@ -111,6 +113,58 @@ export function isSharedVideoEnabled(stateful: IStateful) {
return !disableThirdPartyRequests;
}
+/**
+ * Returns true if the room restricts video sharing and the local participant
+ * does not have the permission for it.
+ *
+ * The restriction is read from the room metadata, which a moderator toggles at
+ * runtime. The server applies the same check in mod_filter_messages: a
+ * participant without the share-video permission is blocked, the same as for
+ * the chat restrictions. The server pushes the default permissions of a
+ * participant that it promotes to moderator, so this selector follows a promotion.
+ *
+ * @param {IStateful} stateful - The redux store or {@code getState} function.
+ * @returns {boolean}
+ */
+export function isShareVideoDisabled(stateful: IStateful) {
+ const state = toState(stateful);
+
+ if (!state['features/shared-video'].sharedVideoRestricted) {
+ return false;
+ }
+
+ return !isJwtFeatureEnabled(state, MEET_FEATURES.SHARE_VIDEO, false);
+}
+
+/**
+ * Returns true if the local participant may share a video: video sharing is
+ * enabled and the room does not restrict it for the local participant.
+ *
+ * @param {IStateful} stateful - The redux store or {@code getState} function.
+ * @returns {boolean}
+ */
+export function canShareVideo(stateful: IStateful) {
+ const state = toState(stateful);
+
+ return isSharedVideoEnabled(state) && !isShareVideoDisabled(state);
+}
+
+/**
+ * Returns true if the shared video button should be shown. The owner of a
+ * video stops it with the same button, thus it stays visible while the local
+ * participant shares a video, also when the room restricts video sharing for them.
+ *
+ * @param {IStateful} stateful - The redux store or {@code getState} function.
+ * @returns {boolean}
+ */
+export function isSharedVideoButtonVisible(stateful: IStateful) {
+ const state = toState(stateful);
+ const { ownerId, status } = state['features/shared-video'];
+ const isLocalOwner = Boolean(ownerId) && ownerId === getLocalParticipant(state)?.id;
+
+ return canShareVideo(state) || (isSharedVideoEnabled(state) && isLocalOwner && isSharingStatus(status ?? ''));
+}
+
/**
* Returns true if the passed url is allowed to be used for shared video or not.
*
diff --git a/react/features/shared-video/hooks.ts b/react/features/shared-video/hooks.ts
index 7ba3bd6f39..5c05835356 100644
--- a/react/features/shared-video/hooks.ts
+++ b/react/features/shared-video/hooks.ts
@@ -1,7 +1,7 @@
import { useSelector } from 'react-redux';
import { SharedVideoButton } from './components';
-import { isSharedVideoEnabled } from './functions';
+import { isSharedVideoButtonVisible } from './functions';
const shareVideo = {
key: 'sharedvideo',
@@ -10,14 +10,15 @@ const shareVideo = {
};
/**
- * A hook that returns the shared video button if it is enabled and undefined otherwise.
+ * A hook that returns the shared video button if the local participant may share a video or shares one,
+ * and undefined otherwise.
*
* @returns {Object | undefined}
*/
export function useSharedVideoButton() {
- const sharedVideoEnabled = useSelector(isSharedVideoEnabled);
+ const sharedVideoButtonVisible = useSelector(isSharedVideoButtonVisible);
- if (sharedVideoEnabled) {
+ if (sharedVideoButtonVisible) {
return shareVideo;
}
}
diff --git a/react/features/shared-video/middleware.ts b/react/features/shared-video/middleware.ts
index 7958602b3f..2bc4887849 100644
--- a/react/features/shared-video/middleware.ts
+++ b/react/features/shared-video/middleware.ts
@@ -1,7 +1,11 @@
import { batch } from 'react-redux';
import { IStore } from '../app/types';
-import { CONFERENCE_JOIN_IN_PROGRESS, CONFERENCE_LEFT } from '../base/conference/actionTypes';
+import {
+ CONFERENCE_JOIN_IN_PROGRESS,
+ CONFERENCE_LEFT,
+ UPDATE_CONFERENCE_METADATA
+} from '../base/conference/actionTypes';
import { getCurrentConference } from '../base/conference/functions';
import { IJitsiConference } from '../base/conference/reducer';
import { SET_CONFIG } from '../base/config/actionTypes';
@@ -21,7 +25,8 @@ import {
resetSharedVideoStatus,
setAllowedUrlDomians,
setSharedVideoStatus,
- showConfirmPlayingDialog
+ showConfirmPlayingDialog,
+ stopSharedVideo
} from './actions';
import {
DEFAULT_ALLOWED_URL_DOMAINS,
@@ -30,7 +35,13 @@ import {
SHARED_VIDEO,
VIDEO_PLAYER_PARTICIPANT_NAME
} from './constants';
-import { isSharedVideoEnabled, isSharingStatus, isURLAllowedForSharedVideo, sendShareVideoCommand } from './functions';
+import {
+ isShareVideoDisabled,
+ isSharedVideoEnabled,
+ isSharingStatus,
+ isURLAllowedForSharedVideo,
+ sendShareVideoCommand
+} from './functions';
import logger from './logger';
@@ -144,6 +155,24 @@ MiddlewareRegistry.register(store => next => action => {
}
break;
}
+ case UPDATE_CONFERENCE_METADATA: {
+ const result = next(action);
+ const state = getState();
+ const { ownerId, status } = state['features/shared-video'];
+
+ // A moderator restricted video sharing while the local participant shares a video,
+ // and the local participant does not have the permission for it.
+ if (isShareVideoDisabled(state)
+ && ownerId === getLocalParticipant(state)?.id
+ && isSharingStatus(status ?? '')) {
+ dispatch(stopSharedVideo());
+ dispatch(showWarningNotification({
+ titleKey: 'notify.sharedVideoRestricted'
+ }, NOTIFICATION_TIMEOUT_TYPE.LONG));
+ }
+
+ return result;
+ }
case SET_CONFIG:
case SET_DYNAMIC_BRANDING_DATA: {
const result = next(action);
diff --git a/react/features/shared-video/reducer.ts b/react/features/shared-video/reducer.ts
index ca1ebebd0c..890cf84eb1 100644
--- a/react/features/shared-video/reducer.ts
+++ b/react/features/shared-video/reducer.ts
@@ -1,3 +1,4 @@
+import { CONFERENCE_LEFT, UPDATE_CONFERENCE_METADATA } from '../base/conference/actionTypes';
import ReducerRegistry from '../base/redux/ReducerRegistry';
import {
@@ -17,6 +18,7 @@ export interface ISharedVideoState {
confirmShowVideo?: boolean;
muted?: boolean;
ownerId?: string;
+ sharedVideoRestricted?: boolean;
status?: string;
time?: number;
videoUrl?: string;
@@ -32,9 +34,18 @@ ReducerRegistry.register<ISharedVideoState>('features/shared-video',
switch (action.type) {
case RESET_SHARED_VIDEO_STATUS:
+ // A video stopping does not change the restriction of the room.
return {
...initialState,
- allowedUrlDomains: state.allowedUrlDomains
+ allowedUrlDomains: state.allowedUrlDomains,
+ sharedVideoRestricted: state.sharedVideoRestricted
+ };
+
+ case CONFERENCE_LEFT:
+ // The restriction belongs to the room, the next one (e.g. a breakout room) sends its own.
+ return {
+ ...state,
+ sharedVideoRestricted: false
};
case SET_CONFIRM_SHOW_VIDEO: {
return {
@@ -60,6 +71,16 @@ ReducerRegistry.register<ISharedVideoState>('features/shared-video',
};
}
+ case UPDATE_CONFERENCE_METADATA: {
+ const { metadata } = action;
+
+ // Metadata without permissions means that the room does not restrict anything.
+ return {
+ ...state,
+ sharedVideoRestricted: Boolean(metadata?.permissions?.sharedVideoRestricted)
+ };
+ }
+
default:
return state;
}
diff --git a/react/features/toolbox/components/native/OverflowMenu.tsx b/react/features/toolbox/components/native/OverflowMenu.tsx
index 8c91154b26..e0900266d2 100644
--- a/react/features/toolbox/components/native/OverflowMenu.tsx
+++ b/react/features/toolbox/components/native/OverflowMenu.tsx
@@ -20,7 +20,7 @@ import RecordButton from '../../../recording/components/Recording/native/RecordB
import SecurityDialogButton
from '../../../security/components/security-dialog/native/SecurityDialogButton';
import SharedVideoButton from '../../../shared-video/components/native/SharedVideoButton';
-import { isSharedVideoEnabled } from '../../../shared-video/functions';
+import { isSharedVideoButtonVisible } from '../../../shared-video/functions';
import SpeakerStatsButton from '../../../speaker-stats/components/native/SpeakerStatsButton';
import { isSpeakerStatsDisabled } from '../../../speaker-stats/functions';
import ClosedCaptionButton from '../../../subtitles/components/native/ClosedCaptionButton';
@@ -53,11 +53,6 @@ interface IProps {
*/
_isOpen: boolean;
- /**
- * Whether the shared video is enabled or not.
- */
- _isSharedVideoEnabled: boolean;
-
/**
* Whether or not speaker stats is disable.
*/
@@ -83,6 +78,11 @@ interface IProps {
*/
_shouldDisplayReactionsButtons: boolean;
+ /**
+ * Whether the shared video button is shown, i.e. the local participant may share a video or shares one.
+ */
+ _showSharedVideoButton: boolean;
+
/**
* Used for hiding the dialog when the selection was completed.
*/
@@ -129,7 +129,7 @@ class OverflowMenu extends PureComponent<IProps, IState> {
const {
_isBreakoutRoomsSupported,
_isSpeakerStatsDisabled,
- _isSharedVideoEnabled,
+ _showSharedVideoButton,
dispatch
} = this.props;
@@ -169,7 +169,7 @@ class OverflowMenu extends PureComponent<IProps, IState> {
<CustomPanelButton { ...buttonProps } />
{/* @ts-ignore */}
<Divider style = { styles.divider as ViewStyle } />
- {_isSharedVideoEnabled && <SharedVideoButton { ...buttonProps } />}
+ {_showSharedVideoButton && <SharedVideoButton { ...buttonProps } />}
{ this._renderOverflowMenuButtons(topButtonProps) }
{!_isSpeakerStatsDisabled && <SpeakerStatsButton { ...buttonProps } />}
{_isBreakoutRoomsSupported && <BreakoutRoomsButton { ...buttonProps } />}
@@ -284,7 +284,7 @@ function _mapStateToProps(state: IReduxState) {
return {
_isBreakoutRoomsSupported: conference?.getBreakoutRooms()?.isSupported(),
- _isSharedVideoEnabled: isSharedVideoEnabled(state),
+ _showSharedVideoButton: isSharedVideoButtonVisible(state),
_isSpeakerStatsDisabled: isSpeakerStatsDisabled(state),
_shouldDisplayReactionsButtons: shouldDisplayReactionsButtons(state)
};
diff --git a/resources/prosody-plugins/mod_filter_messages.lua b/resources/prosody-plugins/mod_filter_messages.lua
index 60de0b771a..f1ad036a96 100644
--- a/resources/prosody-plugins/mod_filter_messages.lua
+++ b/resources/prosody-plugins/mod_filter_messages.lua
@@ -1,11 +1,13 @@
-- Filters MUC messages when the room operator has restricted chat.
--
--- Two independent restrictions live in the room metadata:
+-- Three independent restrictions live in the room metadata:
--
-- permissions.groupChatRestricted — group-chat messages, addressed to the
-- bare room JID
-- permissions.privateChatRestricted — private messages, addressed to an
-- occupant JID (room@muc/nick)
+-- permissions.sharedVideoRestricted — the shared-video command, which a
+-- client sends in its presence
--
-- When a restriction is on, a sender must have the matching feature set to true
-- in their JWT context (session.jitsi_meet_context_features) to send a message.
@@ -14,6 +16,7 @@
--
-- groupChatRestricted → send-groupchat
-- privateChatRestricted → send-private-message
+-- sharedVideoRestricted → share-video
--
-- Feature evaluation via is_feature_allowed:
-- feature = true in token features → allowed
@@ -24,6 +27,12 @@
-- Messages without a <body> (polls, lobby notifications, etc.) are always
-- passed through regardless of the restriction flags.
--
+-- A presence is not rejected. The module removes the <shared-video> element
+-- from it and lets the rest of the presence through, thus the occupant stays
+-- in the room and no other participant starts the video. A <shared-video>
+-- element with state="stop" stays, so a participant can still stop a video
+-- that they shared before the restriction was set.
+--
-- Hooks:
-- message/bare — ordinary MUC group-chat messages
-- jitsi-visitor-groupchat-pre-route — visitor group-chat messages, routed
@@ -31,6 +40,8 @@
-- muc-private-message — MUC private messages
-- jitsi-visitor-private-message-pre-route — visitor private messages, routed
-- via the visitors component
+-- muc-occupant-pre-join — the presence of a joining occupant
+-- muc-occupant-pre-change — a presence update of an occupant
--
-- A message that is addressed to the real JID of a participant
-- (user@domain/resource) does not go to the MUC component, thus no hook here
@@ -137,7 +148,45 @@ local function on_private_message(event)
end
end
+-- Whether the element is a shared-video command other than stop. The client
+-- handles presence children by name and ignores their namespace, thus so does this.
+local function is_shared_video_share(tag)
+ return tag.name == 'shared-video' and tag.attr.state ~= 'stop';
+end
+
+-- Removes the shared-video commands that the occupant may not send. The MUC stores
+-- the presence after these events, thus a participant that joins later does not
+-- receive them either. A stop command always passes, so the owner can stop a video.
+local function on_occupant_presence(event)
+ local stanza, session, room = event.stanza, event.origin, event.room;
+
+ if not session or not room then
+ return;
+ end
+
+ local has_share = false;
+
+ for _, tag in ipairs(stanza.tags) do
+ if is_shared_video_share(tag) then
+ has_share = true;
+ break;
+ end
+ end
+
+ if has_share and is_blocked(room, session, 'sharedVideoRestricted', 'share-video') then
+ stanza:maptags(function (tag)
+ if is_shared_video_share(tag) then
+ return nil;
+ end
+
+ return tag;
+ end);
+ end
+end
+
module:hook('message/bare', on_message); -- room messages
module:hook('jitsi-visitor-groupchat-pre-route', on_message); -- visitors messages
module:hook('muc-private-message', on_private_message); -- private messages
module:hook('jitsi-visitor-private-message-pre-route', on_visitor_private_message); -- visitors private messages
+module:hook('muc-occupant-pre-join', on_occupant_presence); -- shared video on join
+module:hook('muc-occupant-pre-change', on_occupant_presence); -- shared video on presence update
diff --git a/resources/prosody-plugins/mod_jitsi_permissions.lua b/resources/prosody-plugins/mod_jitsi_permissions.lua
index a4743829db..42d02cfec1 100644
--- a/resources/prosody-plugins/mod_jitsi_permissions.lua
+++ b/resources/prosody-plugins/mod_jitsi_permissions.lua
@@ -73,6 +73,7 @@ local function load_config()
['create-polls'] = true;
['send-groupchat'] = true;
['send-private-message'] = true;
+ ['share-video'] = true;
flip = true;
['live-translation'] = true;
['live-translation-subscribe'] = true;
diff --git a/tests/prosody/mod_filter_messages_spec.js b/tests/prosody/mod_filter_messages_spec.js
index 1775dcdf0e..bf7e8db50b 100644
--- a/tests/prosody/mod_filter_messages_spec.js
+++ b/tests/prosody/mod_filter_messages_spec.js
@@ -1,3 +1,4 @@
+import { xml } from '@xmpp/client';
import assert from 'assert';
import { mintAsapToken } from './helpers/jwt.js';
@@ -46,8 +47,8 @@ const connectModerator = roomJid => connect(roomJid, { contextUser: { moderator:
*
* @param {object} mod Moderator XMPP client (occupant of the room).
* @param {string} roomJid Full room JID.
- * @param {string} [key] Permission to set: 'groupChatRestricted' (default)
- * or 'privateChatRestricted'.
+ * @param {string} [key] Permission to set: 'groupChatRestricted' (default),
+ * 'privateChatRestricted' or 'sharedVideoRestricted'.
*/
async function restrictChat(mod, roomJid, key = 'groupChatRestricted') {
mod.sendMetadataUpdate(METADATA_COMPONENT, roomJid, 'permissions', { [key]: true });
@@ -67,6 +68,32 @@ async function restrictChat(mod, roomJid, key = 'groupChatRestricted') {
}, 3000);
}
+/**
+ * Builds the shared-video element that the client sends in its presence.
+ *
+ * @param {string} state Playback state, e.g. 'start' or 'stop'.
+ */
+const sharedVideoEl = (state = 'start') => xml('shared-video', { from: 'abc',
+ state,
+ time: '0' }, 'https://example.com/video.mp4');
+
+/**
+ * Sends a presence update with a shared-video element from `sender` and
+ * resolves with the copy of it that `observer` receives.
+ *
+ * @param {object} sender Occupant that shares the video.
+ * @param {object} observer Another occupant of the room.
+ * @param {string} roomJid Full room JID.
+ * @param {string} [state] Playback state of the shared video.
+ */
+async function sendSharedVideo(sender, observer, roomJid, state) {
+ const from = `${roomJid}/${sender.nick}`;
+
+ await sender.sendPresence(from, [ sharedVideoEl(state) ]);
+
+ return observer.waitForPresenceFrom(from);
+}
+
// ─── Tests ────────────────────────────────────────────────────────────────────
describe('mod_filter_messages', () => {
@@ -488,3 +515,178 @@ describe('mod_filter_messages private messages', () => {
'body-less message must pass through even when private chat is restricted');
});
});
+
+describe('mod_filter_messages shared video', () => {
+
+ const clients = [];
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ clients.length = 0;
+ });
+
+ describe('sharedVideoRestricted', () => {
+
+ /**
+ * Joins a moderator and an occupant to a fresh room and drains the
+ * join presence of the occupant on the moderator.
+ *
+ * @param {object} [opts] Options for the occupant connection.
+ */
+ async function setup(opts) {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ const sender = opts ? await connect(r, opts) : await createXmppClient();
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ // Drain the presence that each of them received for the other on join.
+ await mod.waitForPresenceFrom(`${r}/${sender.nick}`);
+ await sender.waitForPresenceFrom(`${r}/${mod.nick}`);
+
+ return { r,
+ mod,
+ sender };
+ }
+
+ it('shared video passes when sharedVideoRestricted is not set', async () => {
+ const { r, mod, sender } = await setup();
+
+ const received = await sendSharedVideo(sender, mod, r);
+
+ assert.ok(received.getChild('shared-video'), 'shared-video must pass when not restricted');
+ });
+
+ it('shared video of an anonymous occupant is removed when sharedVideoRestricted is true', async () => {
+ const { r, mod, sender } = await setup();
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const received = await sendSharedVideo(sender, mod, r);
+
+ assert.ok(!received.getChild('shared-video'), 'shared-video must be removed');
+ assert.notEqual(received.attrs.type, 'error', 'the rest of the presence must pass');
+ });
+
+ it('stop command of an anonymous occupant passes when sharedVideoRestricted is true', async () => {
+ const { r, mod, sender } = await setup();
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const received = await sendSharedVideo(sender, mod, r, 'stop');
+
+ assert.strictEqual(received.getChild('shared-video')?.attrs.state, 'stop',
+ 'a stop command must pass, so a video shared before the restriction can be stopped');
+ });
+
+ it('a share after a stop in the same presence is removed when sharedVideoRestricted is true', async () => {
+ const { r, mod, sender } = await setup();
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const from = `${r}/${sender.nick}`;
+
+ await sender.sendPresence(from, [ sharedVideoEl('stop'), sharedVideoEl('start') ]);
+
+ const received = await mod.waitForPresenceFrom(from);
+ const states = received.getChildren('shared-video').map(el => el.attrs.state);
+
+ assert.deepStrictEqual(states, [ 'stop' ], 'only the stop command must pass');
+ });
+
+ it('a shared video in another namespace is removed when sharedVideoRestricted is true', async () => {
+ const { r, mod, sender } = await setup();
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const from = `${r}/${sender.nick}`;
+
+ await sender.sendPresence(from, [
+ xml('shared-video', { from: 'abc',
+ state: 'start',
+ xmlns: 'urn:example:other' }, 'https://example.com/video.mp4')
+ ]);
+
+ const received = await mod.waitForPresenceFrom(from);
+
+ assert.strictEqual(received.getChildren('shared-video').length, 0,
+ 'shared-video must be removed whatever its namespace');
+ });
+
+ it('occupant with share-video=true passes when sharedVideoRestricted is true', async () => {
+ const { r, mod, sender } = await setup({ features: { 'share-video': true } });
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const received = await sendSharedVideo(sender, mod, r);
+
+ assert.ok(received.getChild('shared-video'), 'shared-video must pass with share-video=true');
+ });
+
+ it('occupant with share-video=false is blocked when sharedVideoRestricted is true', async () => {
+ const { r, mod, sender } = await setup({ features: { 'share-video': false } });
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const received = await sendSharedVideo(sender, mod, r);
+
+ assert.ok(!received.getChild('shared-video'), 'shared-video must be removed with share-video=false');
+ });
+
+ it('shared video in the join presence of an anonymous occupant is removed', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const sender = await createXmppClient();
+
+ clients.push(sender);
+ await sender.joinRoom(r, undefined, { extensions: [ sharedVideoEl() ] });
+
+ const received = await mod.waitForPresenceFrom(`${r}/${sender.nick}`);
+
+ assert.ok(!received.getChild('shared-video'), 'shared-video must be removed from the join presence');
+ });
+
+ it('a participant that joins later does not get a removed shared video', async () => {
+ const { r, mod, sender } = await setup();
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const received = await sendSharedVideo(sender, mod, r);
+
+ assert.ok(!received.getChild('shared-video'), 'shared-video must be removed');
+
+ // The MUC sends the stored presence of each occupant to a participant that joins.
+ // The whitelisted domain bypasses the occupant limit of the test MUC.
+ const late = await createXmppClient({ domain: 'whitelist.localhost' });
+
+ clients.push(late);
+ await late.joinRoom(r);
+
+ const stored = await late.waitForPresenceFrom(`${r}/${sender.nick}`);
+
+ assert.ok(!stored.getChild('shared-video'), 'the stored presence must not carry the shared video');
+ });
+
+ it('moderator with no features in token passes when sharedVideoRestricted is true', async () => {
+ const { r, mod, sender } = await setup();
+
+ await restrictChat(mod, r, 'sharedVideoRestricted');
+
+ const received = await sendSharedVideo(mod, sender, r);
+
+ assert.ok(received.getChild('shared-video'), 'a moderator must keep sharing a video');
+ });
+ });
+});
diff --git a/tests/prosody/mod_jitsi_permissions_spec.js b/tests/prosody/mod_jitsi_permissions_spec.js
index 6d835a7fb3..6579844ddf 100644
--- a/tests/prosody/mod_jitsi_permissions_spec.js
+++ b/tests/prosody/mod_jitsi_permissions_spec.js
@@ -13,7 +13,7 @@ const nextRoom = () => `permissions-${++_roomCounter}@${CONFERENCE}`;
// Keys present in the default_permissions table in mod_jitsi_permissions.lua.
const DEFAULT_PERMISSION_KEYS = [
'livestreaming', 'recording', 'transcription',
- 'outbound-call', 'create-polls', 'send-groupchat', 'flip'
+ 'outbound-call', 'create-polls', 'send-groupchat', 'share-video', 'flip'
];
/**