Skip to content

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

fix(Toolbox): Stop rerendering on every action

Hristo Terezovd5dd5e4560b4
diff --git a/react/features/base/jwt/functions.ts b/react/features/base/jwt/functions.ts
index 5583b31cda..648bf53be7 100644
--- a/react/features/base/jwt/functions.ts
+++ b/react/features/base/jwt/functions.ts
@@ -3,6 +3,7 @@ import jwtDecode from 'jwt-decode';
import { IReduxState } from '../../app/types';
import { getLocalParticipant } from '../participants/functions';
+import { IParticipantFeatures } from '../participants/types';
import { parseURLParams } from '../util/parseURLParams';
import { JWT_VALIDATION_ERRORS, MEET_FEATURES } from './constants';
@@ -49,13 +50,46 @@ export function getJwtName(state: IReduxState) {
*/
export function isJwtFeatureEnabled(state: IReduxState, feature: string, ifNoToken = false, ifNotInFeatures = false) {
const { jwt } = state['features/base/jwt'];
+ const { features } = getLocalParticipant(state) || {};
+
+ return isJwtFeatureEnabledStateless({
+ jwt,
+ localParticipantFeatures: features,
+ feature,
+ ifNoToken,
+ ifNotInFeatures
+ });
+}
+
+interface IIsJwtFeatureEnabledStatelessParams {
+ feature: string;
+ ifNoToken?: boolean;
+ ifNotInFeatures?: boolean;
+ jwt?: string;
+ localParticipantFeatures?: IParticipantFeatures;
+}
+/**
+ * Check if the given JWT feature is enabled.
+ *
+ * @param {string | undefined} jwt - The jwt token.
+ * @param {ILocalParticipant} localParticipantFeatures - The features of the local participant.
+ * @param {string} feature - The feature we want to check.
+ * @param {boolean} ifNoToken - Default value if there is no token.
+ * @param {boolean} ifNotInFeatures - Default value if features prop exists but does not have the {@code feature}.
+ * @returns {bolean}
+ */
+export function isJwtFeatureEnabledStateless({
+ jwt,
+ localParticipantFeatures: features,
+ feature,
+ ifNoToken = false,
+ ifNotInFeatures = false
+}: IIsJwtFeatureEnabledStatelessParams) {
if (!jwt) {
return ifNoToken;
}
- const { features } = getLocalParticipant(state) || {};
-
// If `features` is undefined, act as if everything is enabled.
if (typeof features === 'undefined') {
return true;
diff --git a/react/features/base/participants/types.ts b/react/features/base/participants/types.ts
index 4b3b6e3bb3..1734f7928c 100644
--- a/react/features/base/participants/types.ts
+++ b/react/features/base/participants/types.ts
@@ -19,9 +19,7 @@ export interface IParticipant {
e2eeVerified?: boolean;
email?: string;
fakeParticipant?: FakeParticipant;
- features?: {
- 'screen-sharing'?: boolean | string;
- };
+ features?: IParticipantFeatures;
getId?: Function;
id: string;
isJigasi?: boolean;
@@ -54,6 +52,10 @@ export interface ILocalParticipant extends IParticipant {
userSelectedMicDeviceLabel?: string;
}
+export interface IParticipantFeatures {
+ 'screen-sharing'?: boolean | string;
+}
+
export interface ISourceInfo {
muted: boolean;
videoType: string;
diff --git a/react/features/toolbox/components/web/Toolbox.tsx b/react/features/toolbox/components/web/Toolbox.tsx
index af12962aed..02735bafb0 100644
--- a/react/features/toolbox/components/web/Toolbox.tsx
+++ b/react/features/toolbox/components/web/Toolbox.tsx
@@ -5,7 +5,7 @@ import { makeStyles } from 'tss-react/mui';
import { IReduxState } from '../../../app/types';
import { isMobileBrowser } from '../../../base/environment/utils';
-import { isLocalParticipantModerator } from '../../../base/participants/functions';
+import { getLocalParticipant, isLocalParticipantModerator } from '../../../base/participants/functions';
import ContextMenu from '../../../base/ui/components/web/ContextMenu';
import { isReactionsButtonEnabled, shouldDisplayReactionsButtons } from '../../../reactions/functions.web';
import {
@@ -97,7 +97,9 @@ export default function Toolbox({
const toolbarButtonsToUse = toolbarButtons || reduxToolbarButtons;
const chatOpen = useSelector((state: IReduxState) => state['features/chat'].isOpen);
const isDialogVisible = useSelector((state: IReduxState) => Boolean(state['features/base/dialog'].component));
- const jwtDisabledButtons = useSelector(getJwtDisabledButtons);
+ const jwt = useSelector((state: IReduxState) => state['features/base/jwt'].jwt);
+ const localParticipant = useSelector(getLocalParticipant);
+ const jwtDisabledButtons = getJwtDisabledButtons(jwt, localParticipant?.features);
const reactionsButtonEnabled = useSelector(isReactionsButtonEnabled);
const _shouldDisplayReactionsButtons = useSelector(shouldDisplayReactionsButtons);
const toolbarVisible = useSelector(isToolboxVisible);
diff --git a/react/features/toolbox/functions.any.ts b/react/features/toolbox/functions.any.ts
index 4fab6ba405..781958e39f 100644
--- a/react/features/toolbox/functions.any.ts
+++ b/react/features/toolbox/functions.any.ts
@@ -1,7 +1,8 @@
import { IReduxState } from '../app/types';
import { FEATURES_TO_BUTTONS_MAPPING } from '../base/jwt/constants';
-import { isJwtFeatureEnabled } from '../base/jwt/functions';
+import { isJwtFeatureEnabledStateless } from '../base/jwt/functions';
import { IGUMPendingState } from '../base/media/types';
+import { IParticipantFeatures } from '../base/participants/types';
/**
* Indicates if the audio mute button is disabled or not.
@@ -19,12 +20,18 @@ export function isAudioMuteButtonDisabled(state: IReduxState) {
/**
* Returns the buttons corresponding to features disabled through jwt.
*
- * @param {IReduxState} state - The state from the Redux store.
+ * @param {string | undefined} jwt - The jwt token.
+ * @param {ILocalParticipant} localParticipantFeatures - The features of the local participant.
* @returns {string[]} - The disabled by jwt buttons array.
*/
-export function getJwtDisabledButtons(state: IReduxState) {
+export function getJwtDisabledButtons(jwt: string | undefined, localParticipantFeatures?: IParticipantFeatures) {
return Object.keys(FEATURES_TO_BUTTONS_MAPPING).reduce((acc: string[], current: string) => {
- if (!isJwtFeatureEnabled(state, current, true)) {
+ if (!isJwtFeatureEnabledStateless({
+ jwt,
+ localParticipantFeatures,
+ feature: current,
+ ifNoToken: true
+ })) {
acc.push(FEATURES_TO_BUTTONS_MAPPING[current as keyof typeof FEATURES_TO_BUTTONS_MAPPING]);
}