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(everyoneIsModerator): Optimize.

Hristo Terezov4d04ea325e06
diff --git a/react/features/base/participants/functions.ts b/react/features/base/participants/functions.ts
index e693b074a8..62b062f330 100644
--- a/react/features/base/participants/functions.ts
+++ b/react/features/base/participants/functions.ts
@@ -601,7 +601,7 @@ export function getDominantSpeakerParticipant(stateful: IStateful) {
export function isEveryoneModerator(stateful: IStateful) {
const state = toState(stateful)['features/base/participants'];
- return state.everyoneIsModerator === true;
+ return state.numberOfNonModeratorParticipants === 0;
}
/**
diff --git a/react/features/base/participants/reducer.ts b/react/features/base/participants/reducer.ts
index 4be9e09db7..402f7b6339 100644
--- a/react/features/base/participants/reducer.ts
+++ b/react/features/base/participants/reducer.ts
@@ -63,10 +63,10 @@ const PARTICIPANT_PROPS_TO_OMIT_WHEN_UPDATE = [
const DEFAULT_STATE = {
dominantSpeaker: undefined,
- everyoneIsModerator: false,
fakeParticipants: new Map(),
local: undefined,
localScreenShare: undefined,
+ numberOfNonModeratorParticipants: 0,
numberOfParticipantsDisabledE2EE: 0,
numberOfParticipantsNotSupportingE2EE: 0,
overwrittenNameList: {},
@@ -81,10 +81,10 @@ const DEFAULT_STATE = {
export interface IParticipantsState {
dominantSpeaker?: string;
- everyoneIsModerator: boolean;
fakeParticipants: Map<string, IParticipant>;
local?: ILocalParticipant;
localScreenShare?: IParticipant;
+ numberOfNonModeratorParticipants: number;
numberOfParticipantsDisabledE2EE: number;
numberOfParticipantsNotSupportingE2EE: number;
overwrittenNameList: { [id: string]: string; };
@@ -204,28 +204,22 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',
}
let newParticipant: IParticipant | null = null;
+ const oldParticipant = local ? state.local : state.remote.get(id);
if (state.remote.has(id)) {
- newParticipant = _participant(state.remote.get(id), action);
+ newParticipant = _participant(oldParticipant, action);
state.remote.set(id, newParticipant);
} else if (id === state.local?.id) {
newParticipant = state.local = _participant(state.local, action);
}
- const oldParticipant = local ? state.local : state.remote.get(id);
-
- if (newParticipant) {
- // everyoneIsModerator calculation:
+ if (oldParticipant && newParticipant && !newParticipant.fakeParticipant) {
const isModerator = isParticipantModerator(newParticipant);
- if (state.everyoneIsModerator && !isModerator) {
- state.everyoneIsModerator = false;
- } else if (!state.everyoneIsModerator && isModerator) {
- state.everyoneIsModerator = _isEveryoneModerator(state);
+ if (isParticipantModerator(oldParticipant) !== isModerator) {
+ state.numberOfNonModeratorParticipants += isModerator ? -1 : 1;
}
- }
- if (oldParticipant && newParticipant && !newParticipant.fakeParticipant) {
if (oldParticipant.e2eeEnabled !== newParticipant.e2eeEnabled) {
state.numberOfParticipantsDisabledE2EE += newParticipant.e2eeEnabled ? -1 : 1;
}
@@ -281,16 +275,13 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',
state.dominantSpeaker = id;
}
- const isModerator = isParticipantModerator(participant);
- const { local, remote } = state;
+ if (!fakeParticipant) {
+ const isModerator = isParticipantModerator(participant);
- if (state.everyoneIsModerator && !isModerator) {
- state.everyoneIsModerator = false;
- } else if (!local && remote.size === 0 && isModerator) {
- state.everyoneIsModerator = true;
- }
+ if (!isModerator) {
+ state.numberOfNonModeratorParticipants += 1;
+ }
- if (!fakeParticipant) {
const { e2eeEnabled, e2eeSupported } = participant as IParticipant;
if (!e2eeEnabled) {
@@ -409,10 +400,6 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',
state.sortedRemoteParticipants.delete(id);
state.raisedHandsQueue = state.raisedHandsQueue.filter(pid => pid.id !== id);
- if (!state.everyoneIsModerator && !isParticipantModerator(oldParticipant)) {
- state.everyoneIsModerator = _isEveryoneModerator(state);
- }
-
if (dominantSpeaker === id) {
state.dominantSpeaker = undefined;
}
@@ -436,6 +423,10 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',
if (oldParticipant && !oldParticipant.fakeParticipant) {
const { e2eeEnabled, e2eeSupported } = oldParticipant;
+ if (!isParticipantModerator(oldParticipant)) {
+ state.numberOfNonModeratorParticipants -= 1;
+ }
+
if (!e2eeEnabled) {
state.numberOfParticipantsDisabledE2EE -= 1;
}
@@ -503,27 +494,6 @@ function _getDisplayName(state: Object, name?: string): string {
return name ?? (config?.defaultRemoteDisplayName || 'Fellow Jitster');
}
-/**
- * Loops through the participants in the state in order to check if all participants are moderators.
- *
- * @param {Object} state - The local participant redux state.
- * @returns {boolean}
- */
-function _isEveryoneModerator(state: IParticipantsState) {
- if (isParticipantModerator(state.local)) {
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- for (const [ k, p ] of state.remote) {
- if (!isParticipantModerator(p)) {
- return false;
- }
- }
-
- return true;
- }
-
- return false;
-}
-
/**
* Reducer function for a single participant.
*