Skip to content

Commit

Permalink
fix(jwt): Use isJwtFeatureEnabled the same way in all places.
Browse files Browse the repository at this point in the history
Fixes an issue where we were showing cc button for visitors that does not have features in the token.
  • Loading branch information
damencho committed Sep 30, 2024
1 parent 2413b89 commit d1d77c8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
18 changes: 9 additions & 9 deletions react/features/base/jwt/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function getJwtName(state: IReduxState) {
* @param {boolean} ifNotInFeatures - Default value if features prop exists but does not have the {@code feature}.
* @returns {boolean}
*/
export function isJwtFeatureEnabled(state: IReduxState, feature: string, ifNoToken = false, ifNotInFeatures = false) {
export function isJwtFeatureEnabled(state: IReduxState, feature: string, ifNoToken: boolean, ifNotInFeatures: boolean) {
const { jwt } = state['features/base/jwt'];
const { features } = getLocalParticipant(state) || {};

Expand All @@ -63,8 +63,8 @@ export function isJwtFeatureEnabled(state: IReduxState, feature: string, ifNoTok

interface IIsJwtFeatureEnabledStatelessParams {
feature: string;
ifNoToken?: boolean;
ifNotInFeatures?: boolean;
ifNoToken: boolean;
ifNotInFeatures: boolean;
jwt?: string;
localParticipantFeatures?: IParticipantFeatures;
}
Expand All @@ -76,23 +76,23 @@ interface IIsJwtFeatureEnabledStatelessParams {
* @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}
* @param {boolean} ifNotInFeatures - Default value if features is missing
* or prop exists but does not have the {@code feature}.
* @returns {boolean}
*/
export function isJwtFeatureEnabledStateless({
jwt,
localParticipantFeatures: features,
feature,
ifNoToken = false,
ifNotInFeatures = false
ifNoToken,
ifNotInFeatures
}: IIsJwtFeatureEnabledStatelessParams) {
if (!jwt) {
return ifNoToken;
}

// If `features` is undefined, act as if everything is enabled.
if (typeof features === 'undefined') {
return true;
return ifNotInFeatures;
}

if (typeof features[feature as keyof typeof features] === 'undefined') {
Expand Down
5 changes: 2 additions & 3 deletions react/features/recording/actions.any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,8 @@ export function showStartRecordingNotificationWithCallback(openRecordingDialog:
state = getState();
const isModerator = isLocalParticipantModerator(state);
const { recordingService } = state['features/base/config'];
const canBypassDialog = isModerator
&& recordingService?.enabled
&& isJwtFeatureEnabled(state, 'recording', true);
const canBypassDialog = recordingService?.enabled
&& isJwtFeatureEnabled(state, 'recording', isModerator, isModerator);

if (canBypassDialog) {
const options = {
Expand Down
4 changes: 3 additions & 1 deletion react/features/recording/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ export function canStopRecording(state: IReduxState) {
}

if (isCloudRecordingRunning(state) || isRecorderTranscriptionsRunning(state)) {
return isLocalParticipantModerator(state) && isJwtFeatureEnabled(state, 'recording', true);
const isModerator = isLocalParticipantModerator(state);

return isJwtFeatureEnabled(state, 'recording', isModerator, isModerator);
}

return false;
Expand Down
6 changes: 4 additions & 2 deletions react/features/toolbox/functions.any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function getJwtDisabledButtons(
jwt,
localParticipantFeatures,
feature: 'livestreaming',
ifNoToken: true
ifNoToken: true,
ifNotInFeatures: true
})) {
acc.push('livestreaming');
}
Expand All @@ -44,7 +45,8 @@ export function getJwtDisabledButtons(
jwt,
localParticipantFeatures,
feature: 'transcription',
ifNoToken: true
ifNoToken: true,
ifNotInFeatures: true
})) {
acc.push('closedcaptions');
}
Expand Down

0 comments on commit d1d77c8

Please sign in to comment.