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
Revert "fix(large-video)pin prev speaker on stage when local user is dominant speaker. (#16511)"
Jaya Allamsetty81a7301a3e03
diff --git a/react/features/base/participants/functions.ts b/react/features/base/participants/functions.tsindex 03498c9d21..38e1d228b1 100644--- a/react/features/base/participants/functions.ts+++ b/react/features/base/participants/functions.ts@@ -62,6 +62,65 @@ const AVATAR_CHECKER_FUNCTIONS = [];/* eslint-enable arrow-body-style */+/**+ * Returns the list of active speakers that should be moved to the top of the sorted list of participants so that the+ * dominant speaker is visible always on the vertical filmstrip in stage layout.+ *+ * @param {Function | Object} stateful - The (whole) redux state, or redux's {@code getState} function to be used to+ * retrieve the state.+ * @returns {Array<string>}+ */+export function getActiveSpeakersToBeDisplayed(stateful: IStateful) {+ const state = toState(stateful);+ const {+ dominantSpeaker,+ fakeParticipants,+ sortedRemoteVirtualScreenshareParticipants,+ speakersList+ } = state['features/base/participants'];+ const { visibleRemoteParticipants } = state['features/filmstrip'];+ let activeSpeakers = new Map(speakersList);++ // Do not re-sort the active speakers if dominant speaker is currently visible.+ if (dominantSpeaker && visibleRemoteParticipants.has(dominantSpeaker)) {+ return activeSpeakers;+ }+ let availableSlotsForActiveSpeakers = visibleRemoteParticipants.size;++ if (activeSpeakers.has(dominantSpeaker ?? '')) {+ activeSpeakers.delete(dominantSpeaker ?? '');+ }++ // Add dominant speaker to the beginning of the list (not including self) since the active speaker list is always+ // alphabetically sorted.+ if (dominantSpeaker && dominantSpeaker !== getLocalParticipant(state)?.id) {+ const updatedSpeakers = Array.from(activeSpeakers);++ updatedSpeakers.splice(0, 0, [ dominantSpeaker, getParticipantById(state, dominantSpeaker)?.name ?? '' ]);+ activeSpeakers = new Map(updatedSpeakers);+ }++ // Remove screenshares from the count.+ if (sortedRemoteVirtualScreenshareParticipants) {+ availableSlotsForActiveSpeakers -= sortedRemoteVirtualScreenshareParticipants.size * 2;+ for (const screenshare of Array.from(sortedRemoteVirtualScreenshareParticipants.keys())) {+ const ownerId = getVirtualScreenshareParticipantOwnerId(screenshare as string);++ activeSpeakers.delete(ownerId);+ }+ }++ // Remove fake participants from the count.+ if (fakeParticipants) {+ availableSlotsForActiveSpeakers -= fakeParticipants.size;+ }+ const truncatedSpeakersList = Array.from(activeSpeakers).slice(0, availableSlotsForActiveSpeakers);++ truncatedSpeakersList.sort((a: any, b: any) => a[1].localeCompare(b[1]));++ return new Map(truncatedSpeakersList);+}+/*** Resolves the first loadable avatar URL for a participant.*diff --git a/react/features/base/participants/reducer.ts b/react/features/base/participants/reducer.tsindex 6ec34d5e94..3b14ad03bc 100644--- a/react/features/base/participants/reducer.ts+++ b/react/features/base/participants/reducer.ts@@ -77,12 +77,12 @@ const DEFAULT_STATE = {numberOfParticipantsNotSupportingE2EE: 0,overwrittenNameList: {},pinnedParticipant: undefined,- previousSpeakers: new Set<string>(),raisedHandsQueue: [],remote: new Map(),remoteVideoSources: new Set<string>(),sortedRemoteVirtualScreenshareParticipants: new Map(),- sortedRemoteParticipants: new Map()+ sortedRemoteParticipants: new Map(),+ speakersList: new Map()};export interface IParticipantsState {@@ -95,12 +95,12 @@ export interface IParticipantsState {numberOfParticipantsNotSupportingE2EE: number;overwrittenNameList: { [id: string]: string; };pinnedParticipant?: string;- previousSpeakers: Set<string>;raisedHandsQueue: Array<{ hasBeenNotified?: boolean; id: string; raisedHandTimestamp: number; }>;remote: Map<string, IParticipant>;remoteVideoSources: Set<string>;sortedRemoteParticipants: Map<string, string>;sortedRemoteVirtualScreenshareParticipants: Map<string, string>;+ speakersList: Map<string, string>;}/**@@ -157,10 +157,22 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',const { participant } = action;const { id, previousSpeakers = [] } = participant;const { dominantSpeaker, local } = state;+ const newSpeakers = [ id, ...previousSpeakers ];+ const sortedSpeakersList: Array<Array<string>> = [];- // Build chronologically ordered Set of remote speakers (excluding local)- const previousSpeakersSet: Set<string>- = new Set(previousSpeakers.filter((speaker: string) => speaker !== local?.id));+ for (const speaker of newSpeakers) {+ if (speaker !== local?.id) {+ const remoteParticipant = state.remote.get(speaker);++ remoteParticipant+ && sortedSpeakersList.push(+ [ speaker, _getDisplayName(state, remoteParticipant?.name) ]+ );+ }+ }++ // Keep the remote speaker list sorted alphabetically.+ sortedSpeakersList.sort((a, b) => a[1].localeCompare(b[1]));// Only one dominant speaker is allowed.if (dominantSpeaker) {@@ -170,8 +182,8 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',if (_updateParticipantProperty(state, id, 'dominantSpeaker', true)) {return {...state,- dominantSpeaker: id,- previousSpeakers: previousSpeakersSet+ dominantSpeaker: id, // @ts-ignore+ speakersList: new Map(sortedSpeakersList)};}@@ -426,7 +438,7 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',}// Remove the participant from the list of speakers.- state.previousSpeakers.delete(id);+ state.speakersList.has(id) && state.speakersList.delete(id);if (pinnedParticipant === id) {state.pinnedParticipant = undefined;diff --git a/react/features/filmstrip/functions.any.ts b/react/features/filmstrip/functions.any.tsindex b567df876f..9bd4a6e1f4 100644--- a/react/features/filmstrip/functions.any.ts+++ b/react/features/filmstrip/functions.any.ts@@ -1,28 +1,12 @@import { IReduxState, IStore } from '../app/types';-import { getParticipantById, getVirtualScreenshareParticipantOwnerId } from '../base/participants/functions';+import {+ getActiveSpeakersToBeDisplayed,+ getVirtualScreenshareParticipantOwnerId+} from '../base/participants/functions';import { setRemoteParticipants } from './actions';import { isFilmstripScrollVisible } from './functions';-/**- * Returns an array containing the first `count` items from a set.- *- * @param {Set<T>} set - The set from which to take items.- * @param {number} count - The number of items to take.- * @returns {T[]} An array containing the taken items.- * @private- */-function _takeFirstN<T>(set: Set<T>, count: number): T[] {- const result: T[] = [];-- for (const item of set) {- if (result.length >= count) break;- result.push(item);- }-- return result;-}-/*** Computes the reorderd list of the remote participants.*@@ -32,7 +16,7 @@ function _takeFirstN<T>(set: Set<T>, count: number): T[] {* @returns {void}* @private*/-export function updateRemoteParticipants(store: IStore, force?: boolean, participantId?: string): void {+export function updateRemoteParticipants(store: IStore, force?: boolean, participantId?: string) {const state = store.getState();let reorderedParticipants = [];const { sortedRemoteVirtualScreenshareParticipants } = state['features/base/participants'];@@ -49,26 +33,14 @@ export function updateRemoteParticipants(store: IStore, force?: boolean, partici}const {- dominantSpeaker,fakeParticipants,- previousSpeakers,sortedRemoteParticipants} = state['features/base/participants'];- const { visibleRemoteParticipants } = state['features/filmstrip'];const remoteParticipants = new Map(sortedRemoteParticipants);const screenShareParticipants = sortedRemoteVirtualScreenshareParticipants? [ ...sortedRemoteVirtualScreenshareParticipants.keys() ] : [];const sharedVideos = fakeParticipants ? Array.from(fakeParticipants.keys()) : [];- const speakers: Set<string> = new Set();- const dominant = dominantSpeaker ? getParticipantById(state, dominantSpeaker) : undefined;- const config = state['features/base/config'];- const defaultRemoteDisplayName = config?.defaultRemoteDisplayName ?? 'Fellow Jitster';-- // Generate the remote active speakers list.- if (dominant && !dominant.local) {- speakers.add(dominant.id);- }- previousSpeakers.forEach(id => speakers.add(id));+ const speakers = getActiveSpeakersToBeDisplayed(state);for (const screenshare of screenShareParticipants) {const ownerId = getVirtualScreenshareParticipantOwnerId(screenshare);@@ -85,16 +57,7 @@ export function updateRemoteParticipants(store: IStore, force?: boolean, particiremoteParticipants.delete(speaker);}- // Calculate the number of slots available for active speakers and then sort them alphabetically to ensure- // consistent order.- const numberOfActiveSpeakerSlots- = visibleRemoteParticipants.size - (screenShareParticipants.length * 2) - sharedVideos.length;- const activeSpeakersDisplayed = _takeFirstN(speakers, numberOfActiveSpeakerSlots)- .sort((a: string, b: string) => {- return (getParticipantById(state, a)?.name ?? defaultRemoteDisplayName)- .localeCompare(getParticipantById(state, b)?.name ?? defaultRemoteDisplayName);- });-+ // Always update the order of the thubmnails.const participantsWithScreenShare = screenShareParticipants.reduce<string[]>((acc, screenshare) => {const ownerId = getVirtualScreenshareParticipantOwnerId(screenshare);@@ -104,11 +67,10 @@ export function updateRemoteParticipants(store: IStore, force?: boolean, particireturn acc;}, []);- // Always update the order of the thumbnails.reorderedParticipants = [...participantsWithScreenShare,...sharedVideos,- ...activeSpeakersDisplayed,+ ...Array.from(speakers.keys()),...Array.from(remoteParticipants.keys())];diff --git a/react/features/large-video/actions.any.ts b/react/features/large-video/actions.any.tsindex 2a6b1d6980..9df86ad595 100644--- a/react/features/large-video/actions.any.ts+++ b/react/features/large-video/actions.any.ts@@ -161,26 +161,18 @@ function _electParticipantInLargeVideo(state: IReduxState) {}}- // Next, pick the dominant speaker or the last active speaker if the dominant speaker is local.+ // Next, pick the dominant speaker (other than self).participant = getDominantSpeakerParticipant(state);- let speakerId: string | undefined;+ if (participant && !participant.local) {+ // Return the screensharing participant id associated with this endpoint if multi-stream is enabled and+ // auto_pin_latest_screen_share setting is disabled.+ const screenshareParticipant = getVirtualScreenshareParticipantByOwnerId(state, participant.id);- if (participant?.local) {- const { previousSpeakers } = state['features/base/participants'];-- if (previousSpeakers?.size) {- speakerId = previousSpeakers.keys().next().value;- }- } else if (participant) {- speakerId = participant.id;+ return screenshareParticipant?.id ?? participant.id;}- // Return the screensharing participant id associated with this endpoint.- if (speakerId) {- const screenshareParticipant = getVirtualScreenshareParticipantByOwnerId(state, speakerId);-- return screenshareParticipant?.id ?? speakerId;- }+ // In case this is the local participant.+ participant = undefined;// Next, pick the most recent participant with video.const lastVisibleRemoteParticipant = _electLastVisibleRemoteParticipant(state);diff --git a/tests/helpers/Participant.ts b/tests/helpers/Participant.tsindex b74772ff9d..f09a7e0393 100644--- a/tests/helpers/Participant.ts+++ b/tests/helpers/Participant.ts@@ -579,50 +579,6 @@ export class Participant {return new LargeVideo(this);}- /**- * Waits for a specific participant to be displayed on large video.- *- * @param {string} expectedEndpointId - The endpoint ID of the participant expected on large video.- * @param {string} timeoutMsg - Optional custom timeout message.- * @param {number} timeout - Optional timeout in milliseconds (default: 30000).- * @returns {Promise<void>}- */- async waitForParticipantOnLargeVideo(- expectedEndpointId: string,- timeoutMsg?: string,- timeout: number = 30_000): Promise<void> {- await this.driver.waitUntil(- async () => await this.getLargeVideo().getResource() === expectedEndpointId,- {- timeout,- timeoutMsg: timeoutMsg || `Expected ${expectedEndpointId} on large video for ${this.name}`- });- }-- /**- * Waits for any one of the specified participants to be displayed on large video.- *- * @param {string[]} expectedEndpointIds - Array of endpoint IDs, any one of which is expected on large video.- * @param {string} timeoutMsg - Optional custom timeout message.- * @param {number} timeout - Optional timeout in milliseconds (default: 30000).- * @returns {Promise<void>}- */- async waitForAnyParticipantOnLargeVideo(- expectedEndpointIds: string[],- timeoutMsg?: string,- timeout: number = 30_000): Promise<void> {- await this.driver.waitUntil(- async () => {- const largeVideoResource = await this.getLargeVideo().getResource();-- return expectedEndpointIds.includes(largeVideoResource);- },- {- timeout,- timeoutMsg: timeoutMsg || `Expected one of [${expectedEndpointIds.join(', ')}] on large video for ${this.name}`- });- }-/*** Returns the videoQuality Dialog.*diff --git a/tests/specs/media/activeSpeaker.spec.ts b/tests/specs/media/activeSpeaker.spec.tsindex 92153e42af..2e544ab712 100644--- a/tests/specs/media/activeSpeaker.spec.ts+++ b/tests/specs/media/activeSpeaker.spec.ts@@ -13,16 +13,6 @@ describe('Active speaker', () => {const { p1, p2, p3 } = ctx;- // Exit tile view to enter stage view (default for 3 participants is tile view)- await p1.getToolbar().clickExitTileViewButton();- await p1.waitForTileViewDisplayed(true);-- await p2.getToolbar().clickExitTileViewButton();- await p2.waitForTileViewDisplayed(true);-- await p3.getToolbar().clickExitTileViewButton();- await p3.waitForTileViewDisplayed(true);-await muteAudioAndCheck(p1, p2);await muteAudioAndCheck(p2, p1);await muteAudioAndCheck(p3, p1);@@ -41,124 +31,6 @@ describe('Active speaker', () => {await assertOneDominantSpeaker(p2);await assertOneDominantSpeaker(p3);});-- it('testLocalDominantSpeakerShowsLastRemote', async () => {- await ensureThreeParticipants();-- const { p1, p2, p3 } = ctx;- const p2EndpointId = await p2.getEndpointId();- const p3EndpointId = await p3.getEndpointId();-- // p2 speaks first- await p2.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p2EndpointId, 'P2 not displayed as dominant speaker on P1');- await p2.getToolbar().clickAudioMuteButton();-- // p3 speaks second- await p3.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p3EndpointId, 'P3 not displayed as dominant speaker on P1');- await p3.getToolbar().clickAudioMuteButton();-- // Now p1 starts screenshare and becomes dominant speaker- await p1.getToolbar().clickDesktopSharingButton();-- // p1 should see p3 (last remote dominant speaker) on stage- await p1.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p3EndpointId, 'P1 should see P3 (last remote speaker) on stage when local is dominant');-- // Check that p2 and p3 tiles remain visible in filmstrip on p1- await p1.driver.$(`//span[@id='participant_${p2EndpointId}']`).waitForDisplayed({- timeout: 3_000,- timeoutMsg: 'P2 tile should remain visible in filmstrip during screenshare'- });- await p1.driver.$(`//span[@id='participant_${p3EndpointId}']`).waitForDisplayed({- timeout: 3_000,- timeoutMsg: 'P3 tile should remain visible in filmstrip during screenshare'- });-- // Check that there are no gaps in the filmstrip during local screenshare- await p2.getFilmstrip().assertNoGapsInFilmstrip();- await p3.getFilmstrip().assertNoGapsInFilmstrip();-- await p1.getToolbar().clickAudioMuteButton();- await p1.getToolbar().clickStopDesktopSharingButton();- });-- it('testAlternatingLocalAndRemoteDominantSpeaker', async () => {- await ensureThreeParticipants();-- const { p1, p2, p3 } = ctx;- const p2EndpointId = await p2.getEndpointId();- const p3EndpointId = await p3.getEndpointId();-- // Test alternating pattern: p2 -> p1 (local) -> p3 -> p1 (local) -> p2- // This tests that local dominant speaker consistently shows last remote speaker-- // p2 speaks- await p2.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p2EndpointId, 'P2 not shown on P1');- await p2.getToolbar().clickAudioMuteButton();-- // p1 (local) speaks - should still show p2- await p1.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p2EndpointId, 'P1 local dominant should show P2 (last remote)');- await p1.getToolbar().clickAudioMuteButton();-- // p3 speaks- await p3.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p3EndpointId, 'P3 not shown on P1');- await p3.getToolbar().clickAudioMuteButton();-- // p1 (local) speaks again - should now show p3- await p1.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p3EndpointId, 'P1 local dominant should show P3 (last remote)');- await p1.getToolbar().clickAudioMuteButton();-- // p2 speaks again- await p2.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p2EndpointId, 'P2 not shown on P1 after second speak');- await p2.getToolbar().clickAudioMuteButton();-- // p1 (local) speaks - should show p2 again- await p1.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(p2EndpointId, 'P1 local dominant should show P2 (last remote) again');- await p1.getToolbar().clickAudioMuteButton();- });-- it('testDominantSpeakerWithSimultaneousSpeakers', async () => {- await ensureThreeParticipants();-- const { p1, p2, p3 } = ctx;- const p2EndpointId = await p2.getEndpointId();- const p3EndpointId = await p3.getEndpointId();-- // Multiple participants unmute simultaneously (this is the scenario we're testing)- await p2.getToolbar().clickAudioUnmuteButton();- await p3.getToolbar().clickAudioUnmuteButton();-- // Wait for one to become dominant (bridge will pick one)- await p1.waitForAnyParticipantOnLargeVideo(- [ p2EndpointId, p3EndpointId ],- 'No dominant speaker detected when multiple speak simultaneously');-- // Get which one was selected as dominant- const firstDominant = await p1.getLargeVideo().getResource();-- // Mute both- await Promise.all([- p2.getToolbar().clickAudioMuteButton(),- p3.getToolbar().clickAudioMuteButton()- ]);-- // Now p1 becomes local dominant speaker- // Should show the last remote dominant speaker (firstDominant)- await p1.getToolbar().clickAudioUnmuteButton();- await p1.waitForParticipantOnLargeVideo(- firstDominant,- 'Local dominant should show last remote dominant after simultaneous speakers');-- await p1.getToolbar().clickAudioMuteButton();- });});/**@@ -191,12 +63,14 @@ async function testActiveSpeaker(await activeSpeaker.getFilmstrip().assertAudioMuteIconIsDisplayed(activeSpeaker, true);// Verify that the user is now an active speaker from otherParticipant1's perspective- await otherParticipant1.waitForParticipantOnLargeVideo(speakerEndpoint,- `Active speaker ${activeSpeaker.name} not displayed on large video.`,- 30_000); // 30 seconds- await otherParticipant2.waitForParticipantOnLargeVideo(speakerEndpoint,- `Active speaker ${activeSpeaker.name} not displayed on large video.`,- 30_000); // 30 seconds+ const otherParticipant1Driver = otherParticipant1.driver;++ await otherParticipant1Driver.waitUntil(+ async () => await otherParticipant1.getFilmstrip().isDominantSpeaker(speakerEndpoint),+ {+ timeout: 30_000, // 30 seconds+ timeoutMsg: `${activeSpeaker.name} is not selected as active speaker.`+ });// just a debug print to go in logsawait activeSpeaker.log('Muting in testActiveSpeaker');diff --git a/tests/specs/media/startMuted.spec.ts b/tests/specs/media/startMuted.spec.tsindex 7d58a0573b..b9bf5a8523 100644--- a/tests/specs/media/startMuted.spec.ts+++ b/tests/specs/media/startMuted.spec.ts@@ -175,6 +175,11 @@ describe('Start muted', () => {await p1.getParticipantsPane().assertVideoMuteIconIsDisplayed(p2);await p2.getParticipantsPane().assertVideoMuteIconIsDisplayed(p1);+ await Promise.all([+ p1.getLargeVideo().waitForSwitchTo(await p2.getEndpointId()),+ p2.getLargeVideo().waitForSwitchTo(await p1.getEndpointId())+ ]);+await unmuteVideoAndCheck(p2, p1);await p1.getLargeVideo().assertPlaying();});