2022-08-08 08:12:22 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
|
|
|
// @ts-ignore
|
2020-07-09 07:17:23 +00:00
|
|
|
import { getGravatarURL } from '@jitsi/js-utils/avatar';
|
2017-09-01 21:25:48 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState, IStore } from '../../app/types';
|
2022-08-08 08:12:22 +00:00
|
|
|
// @ts-ignore
|
2022-04-12 13:19:10 +00:00
|
|
|
import { isStageFilmstripAvailable } from '../../filmstrip/functions';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { IStateful } from '../app/types';
|
2022-08-08 08:12:22 +00:00
|
|
|
import { GRAVATAR_BASE_URL } from '../avatar/constants';
|
|
|
|
import { isCORSAvatarURL } from '../avatar/functions';
|
2022-10-07 12:18:49 +00:00
|
|
|
import { getMultipleVideoSupportFeatureFlag } from '../config/functions.any';
|
2022-08-08 08:12:22 +00:00
|
|
|
import i18next from '../i18n/i18next';
|
2022-10-07 14:32:07 +00:00
|
|
|
import { VIDEO_TYPE } from '../media/constants';
|
2022-08-08 08:12:22 +00:00
|
|
|
import { toState } from '../redux/functions';
|
2022-10-07 12:18:49 +00:00
|
|
|
import { getScreenShareTrack } from '../tracks/functions';
|
2022-08-08 08:12:22 +00:00
|
|
|
import { createDeferred } from '../util/helpers';
|
2019-01-25 10:17:58 +00:00
|
|
|
|
2022-09-30 14:50:45 +00:00
|
|
|
import {
|
|
|
|
JIGASI_PARTICIPANT_ICON,
|
|
|
|
MAX_DISPLAY_NAME_LENGTH,
|
|
|
|
PARTICIPANT_ROLE,
|
|
|
|
WHITEBOARD_PARTICIPANT_ICON
|
|
|
|
} from './constants';
|
2022-08-08 08:12:22 +00:00
|
|
|
// @ts-ignore
|
2019-06-26 14:08:23 +00:00
|
|
|
import { preloadImage } from './preloadImage';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { FakeParticipant, IParticipant } from './types';
|
2017-08-16 21:28:39 +00:00
|
|
|
|
2019-06-26 14:08:23 +00:00
|
|
|
/**
|
|
|
|
* Temp structures for avatar urls to be checked/preloaded.
|
|
|
|
*/
|
2022-08-08 08:12:22 +00:00
|
|
|
const AVATAR_QUEUE: Object[] = [];
|
2019-06-26 14:08:23 +00:00
|
|
|
const AVATAR_CHECKED_URLS = new Map();
|
2020-11-15 21:33:55 +00:00
|
|
|
/* eslint-disable arrow-body-style, no-unused-vars */
|
2019-06-26 14:08:23 +00:00
|
|
|
const AVATAR_CHECKER_FUNCTIONS = [
|
2022-10-20 09:11:27 +00:00
|
|
|
(participant: IParticipant) => {
|
2022-10-06 11:12:57 +00:00
|
|
|
return isJigasiParticipant(participant) ? JIGASI_PARTICIPANT_ICON : null;
|
2019-07-16 10:23:01 +00:00
|
|
|
},
|
2022-10-20 09:11:27 +00:00
|
|
|
(participant: IParticipant) => {
|
2022-10-06 11:12:57 +00:00
|
|
|
return isWhiteboardParticipant(participant) ? WHITEBOARD_PARTICIPANT_ICON : null;
|
2022-09-30 14:50:45 +00:00
|
|
|
},
|
2022-10-20 09:11:27 +00:00
|
|
|
(participant: IParticipant) => {
|
2022-09-08 09:52:36 +00:00
|
|
|
return participant?.avatarURL ? participant.avatarURL : null;
|
2019-06-26 14:08:23 +00:00
|
|
|
},
|
2022-10-20 09:11:27 +00:00
|
|
|
(participant: IParticipant, store: IStore) => {
|
2022-05-09 05:36:39 +00:00
|
|
|
const config = store.getState()['features/base/config'];
|
|
|
|
const isGravatarDisabled = config.gravatar?.disabled;
|
|
|
|
|
2022-09-08 09:52:36 +00:00
|
|
|
if (participant?.email && !isGravatarDisabled) {
|
2022-05-09 05:36:39 +00:00
|
|
|
const gravatarBaseURL = config.gravatar?.baseUrl
|
|
|
|
|| config.gravatarBaseURL
|
|
|
|
|| GRAVATAR_BASE_URL;
|
2020-11-24 10:19:08 +00:00
|
|
|
|
|
|
|
return getGravatarURL(participant.email, gravatarBaseURL);
|
2020-11-15 21:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2019-06-26 14:08:23 +00:00
|
|
|
}
|
|
|
|
];
|
2020-11-15 21:33:55 +00:00
|
|
|
/* eslint-enable arrow-body-style, no-unused-vars */
|
2019-06-26 14:08:23 +00:00
|
|
|
|
2022-07-20 19:51:47 +00:00
|
|
|
/**
|
|
|
|
* 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>}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getActiveSpeakersToBeDisplayed(stateful: IStateful) {
|
2022-07-20 19:51:47 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const {
|
2022-08-12 17:44:09 +00:00
|
|
|
dominantSpeaker,
|
2022-07-20 19:51:47 +00:00
|
|
|
fakeParticipants,
|
|
|
|
sortedRemoteScreenshares,
|
|
|
|
sortedRemoteVirtualScreenshareParticipants,
|
|
|
|
speakersList
|
|
|
|
} = state['features/base/participants'];
|
|
|
|
const { visibleRemoteParticipants } = state['features/filmstrip'];
|
2022-08-16 17:20:29 +00:00
|
|
|
let activeSpeakers = new Map(speakersList);
|
2022-07-20 19:51:47 +00:00
|
|
|
|
2022-08-12 17:44:09 +00:00
|
|
|
// Do not re-sort the active speakers if dominant speaker is currently visible.
|
|
|
|
if (dominantSpeaker && visibleRemoteParticipants.has(dominantSpeaker)) {
|
2022-07-21 15:53:35 +00:00
|
|
|
return activeSpeakers;
|
2022-07-20 19:51:47 +00:00
|
|
|
}
|
|
|
|
let availableSlotsForActiveSpeakers = visibleRemoteParticipants.size;
|
|
|
|
|
2022-09-14 07:54:56 +00:00
|
|
|
if (activeSpeakers.has(dominantSpeaker ?? '')) {
|
|
|
|
activeSpeakers.delete(dominantSpeaker ?? '');
|
2022-08-16 17:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add dominant speaker to the beginning of the list (not including self) since the active speaker list is always
|
|
|
|
// alphabetically sorted.
|
2022-09-14 07:54:56 +00:00
|
|
|
if (dominantSpeaker && dominantSpeaker !== getLocalParticipant(state)?.id) {
|
2022-08-16 17:20:29 +00:00
|
|
|
const updatedSpeakers = Array.from(activeSpeakers);
|
|
|
|
|
2022-09-14 07:54:56 +00:00
|
|
|
updatedSpeakers.splice(0, 0, [ dominantSpeaker, getParticipantById(state, dominantSpeaker)?.name ?? '' ]);
|
2022-08-16 17:20:29 +00:00
|
|
|
activeSpeakers = new Map(updatedSpeakers);
|
|
|
|
}
|
|
|
|
|
2022-07-20 19:51:47 +00:00
|
|
|
// Remove screenshares from the count.
|
|
|
|
if (getMultipleVideoSupportFeatureFlag(state)) {
|
|
|
|
if (sortedRemoteVirtualScreenshareParticipants) {
|
|
|
|
availableSlotsForActiveSpeakers -= sortedRemoteVirtualScreenshareParticipants.size * 2;
|
|
|
|
for (const screenshare of Array.from(sortedRemoteVirtualScreenshareParticipants.keys())) {
|
2022-08-08 08:12:22 +00:00
|
|
|
const ownerId = getVirtualScreenshareParticipantOwnerId(screenshare as string);
|
2022-07-20 19:51:47 +00:00
|
|
|
|
|
|
|
activeSpeakers.delete(ownerId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (sortedRemoteScreenshares) {
|
|
|
|
availableSlotsForActiveSpeakers -= sortedRemoteScreenshares.size;
|
|
|
|
for (const id of Array.from(sortedRemoteScreenshares.keys())) {
|
|
|
|
activeSpeakers.delete(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
// Remove fake participants from the count.
|
2022-07-20 19:51:47 +00:00
|
|
|
if (fakeParticipants) {
|
|
|
|
availableSlotsForActiveSpeakers -= fakeParticipants.size;
|
|
|
|
}
|
|
|
|
const truncatedSpeakersList = Array.from(activeSpeakers).slice(0, availableSlotsForActiveSpeakers);
|
|
|
|
|
2022-08-08 08:12:22 +00:00
|
|
|
truncatedSpeakersList.sort((a: any, b: any) => a[1].localeCompare(b[1]));
|
2022-07-20 19:51:47 +00:00
|
|
|
|
|
|
|
return new Map(truncatedSpeakersList);
|
|
|
|
}
|
|
|
|
|
2019-06-26 14:08:23 +00:00
|
|
|
/**
|
|
|
|
* Resolves the first loadable avatar URL for a participant.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant to resolve avatars for.
|
2020-11-15 21:33:55 +00:00
|
|
|
* @param {Store} store - Redux store.
|
2019-06-26 14:08:23 +00:00
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getFirstLoadableAvatarUrl(participant: IParticipant, store: IStore) {
|
2022-08-08 08:12:22 +00:00
|
|
|
const deferred: any = createDeferred();
|
2019-06-26 14:08:23 +00:00
|
|
|
const fullPromise = deferred.promise
|
2020-11-15 21:33:55 +00:00
|
|
|
.then(() => _getFirstLoadableAvatarUrl(participant, store))
|
2022-08-08 08:12:22 +00:00
|
|
|
.then((result: any) => {
|
2019-06-26 14:08:23 +00:00
|
|
|
|
|
|
|
if (AVATAR_QUEUE.length) {
|
2022-08-08 08:12:22 +00:00
|
|
|
const next: any = AVATAR_QUEUE.shift();
|
2019-06-26 14:08:23 +00:00
|
|
|
|
|
|
|
next.resolve();
|
|
|
|
}
|
|
|
|
|
2021-12-17 00:16:24 +00:00
|
|
|
return result;
|
2019-06-26 14:08:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (AVATAR_QUEUE.length) {
|
|
|
|
AVATAR_QUEUE.push(deferred);
|
|
|
|
} else {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
return fullPromise;
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns local participant from Redux state.
|
|
|
|
*
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {(IParticipant|undefined)}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getLocalParticipant(stateful: IStateful) {
|
2021-07-09 12:36:19 +00:00
|
|
|
const state = toState(stateful)['features/base/participants'];
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return state.local;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 15:17:25 +00:00
|
|
|
/**
|
|
|
|
* Returns local screen share participant from Redux state.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state features/base/participants.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {(IParticipant|undefined)}
|
2022-04-05 15:17:25 +00:00
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getLocalScreenShareParticipant(stateful: IStateful) {
|
2022-04-05 15:17:25 +00:00
|
|
|
const state = toState(stateful)['features/base/participants'];
|
|
|
|
|
|
|
|
return state.localScreenShare;
|
|
|
|
}
|
|
|
|
|
2022-04-14 17:07:17 +00:00
|
|
|
/**
|
|
|
|
* Returns screenshare participant.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's {@code getState} function to be used to
|
|
|
|
* retrieve the state features/base/participants.
|
|
|
|
* @param {string} id - The owner ID of the screenshare participant to retrieve.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {(IParticipant|undefined)}
|
2022-04-14 17:07:17 +00:00
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getVirtualScreenshareParticipantByOwnerId(stateful: IStateful, id: string) {
|
2022-04-29 14:32:16 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
|
|
|
|
if (getMultipleVideoSupportFeatureFlag(state)) {
|
|
|
|
const track = getScreenShareTrack(state['features/base/tracks'], id);
|
|
|
|
|
|
|
|
return getParticipantById(stateful, track?.jitsiTrack.getSourceName());
|
|
|
|
}
|
2022-04-14 17:07:17 +00:00
|
|
|
|
2022-04-29 14:32:16 +00:00
|
|
|
return;
|
2022-04-14 17:07:17 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 11:28:07 +00:00
|
|
|
/**
|
|
|
|
* Normalizes a display name so then no invalid values (padding, length...etc)
|
|
|
|
* can be set.
|
|
|
|
*
|
|
|
|
* @param {string} name - The display name to set.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getNormalizedDisplayName(name: string) {
|
|
|
|
if (!name || !name.trim()) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name.trim().substring(0, MAX_DISPLAY_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns participant by ID from Redux state.
|
|
|
|
*
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @param {string} id - The ID of the participant to retrieve.
|
|
|
|
* @private
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {(IParticipant|undefined)}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getParticipantById(stateful: IStateful, id: string): IParticipant | undefined {
|
2021-07-09 12:36:19 +00:00
|
|
|
const state = toState(stateful)['features/base/participants'];
|
2022-04-04 18:57:58 +00:00
|
|
|
const { local, localScreenShare, remote } = state;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2022-04-04 18:57:58 +00:00
|
|
|
return remote.get(id)
|
|
|
|
|| (local?.id === id ? local : undefined)
|
|
|
|
|| (localScreenShare?.id === id ? localScreenShare : undefined);
|
2021-07-09 12:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the participant with the ID matching the passed ID or the local participant if the ID is
|
|
|
|
* undefined.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
|
|
|
* @param {string|undefined} [participantID] - An optional partipantID argument.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {IParticipant|undefined}
|
2021-07-09 12:36:19 +00:00
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getParticipantByIdOrUndefined(stateful: IStateful, participantID?: string) {
|
2021-07-09 12:36:19 +00:00
|
|
|
return participantID ? getParticipantById(stateful, participantID) : getLocalParticipant(stateful);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 22:56:55 +00:00
|
|
|
/**
|
|
|
|
* Returns a count of the known participants in the passed in redux state,
|
|
|
|
* excluding any fake participants.
|
|
|
|
*
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2017-06-27 22:56:55 +00:00
|
|
|
* @returns {number}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getParticipantCount(stateful: IStateful) {
|
2022-04-04 18:57:58 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const {
|
|
|
|
local,
|
|
|
|
remote,
|
|
|
|
fakeParticipants,
|
2022-04-29 14:32:16 +00:00
|
|
|
sortedRemoteVirtualScreenshareParticipants
|
2022-04-04 18:57:58 +00:00
|
|
|
} = state['features/base/participants'];
|
|
|
|
|
2022-08-01 15:31:38 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state)) {
|
2022-04-29 14:32:16 +00:00
|
|
|
return remote.size - fakeParticipants.size - sortedRemoteVirtualScreenshareParticipants.size + (local ? 1 : 0);
|
2022-04-04 18:57:58 +00:00
|
|
|
}
|
2021-07-09 12:36:19 +00:00
|
|
|
|
|
|
|
return remote.size - fakeParticipants.size + (local ? 1 : 0);
|
2022-04-04 18:57:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-29 14:32:16 +00:00
|
|
|
* Returns participant ID of the owner of a virtual screenshare participant.
|
2022-04-04 18:57:58 +00:00
|
|
|
*
|
2022-04-29 14:32:16 +00:00
|
|
|
* @param {string} id - The ID of the virtual screenshare participant.
|
2022-04-04 18:57:58 +00:00
|
|
|
* @private
|
|
|
|
* @returns {(string|undefined)}
|
|
|
|
*/
|
2022-04-29 14:32:16 +00:00
|
|
|
export function getVirtualScreenshareParticipantOwnerId(id: string) {
|
2022-04-04 18:57:58 +00:00
|
|
|
return id.split('-')[0];
|
2021-07-09 12:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Map with fake participants.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {Map<string, IParticipant>} - The Map with fake participants.
|
2021-07-09 12:36:19 +00:00
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getFakeParticipants(stateful: IStateful) {
|
2021-07-09 12:36:19 +00:00
|
|
|
return toState(stateful)['features/base/participants'].fakeParticipants;
|
|
|
|
}
|
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the fake participant is Jigasi.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant|undefined} participant - The participant entity.
|
2022-10-06 11:12:57 +00:00
|
|
|
* @returns {boolean} - True if it's a Jigasi participant.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function isJigasiParticipant(participant?: IParticipant): boolean {
|
2022-10-06 11:12:57 +00:00
|
|
|
return participant?.fakeParticipant === FakeParticipant.Jigasi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the fake participant is a local screenshare.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant|undefined} participant - The participant entity.
|
2022-10-06 11:12:57 +00:00
|
|
|
* @returns {boolean} - True if it's a local screenshare participant.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isLocalScreenshareParticipant(participant?: IParticipant): boolean {
|
2022-10-06 11:12:57 +00:00
|
|
|
return participant?.fakeParticipant === FakeParticipant.LocalScreenShare;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the fake participant is a remote screenshare.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant|undefined} participant - The participant entity.
|
2022-10-06 11:12:57 +00:00
|
|
|
* @returns {boolean} - True if it's a remote screenshare participant.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isRemoteScreenshareParticipant(participant?: IParticipant): boolean {
|
2022-10-06 11:12:57 +00:00
|
|
|
return participant?.fakeParticipant === FakeParticipant.RemoteScreenShare;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the fake participant is of local or virtual screenshare type.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The (whole) redux state, or redux's.
|
2022-10-06 11:12:57 +00:00
|
|
|
* @param {string|undefined} participantId - The participant id.
|
|
|
|
* @returns {boolean} - True if it's one of the two.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isScreenShareParticipantById(state: IReduxState, participantId?: string): boolean {
|
2022-10-06 11:12:57 +00:00
|
|
|
const participant = getParticipantByIdOrUndefined(state, participantId);
|
|
|
|
|
|
|
|
return isScreenShareParticipant(participant);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the fake participant is of local or virtual screenshare type.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant|undefined} participant - The participant entity.
|
2022-10-06 11:12:57 +00:00
|
|
|
* @returns {boolean} - True if it's one of the two.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isScreenShareParticipant(participant?: IParticipant): boolean {
|
2022-10-06 11:12:57 +00:00
|
|
|
return isLocalScreenshareParticipant(participant) || isRemoteScreenshareParticipant(participant);
|
|
|
|
}
|
|
|
|
|
2022-10-07 11:36:22 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the (fake) participant is a shared video.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant|undefined} participant - The participant entity.
|
2022-10-07 11:36:22 +00:00
|
|
|
* @returns {boolean} - True if it's a shared video participant.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isSharedVideoParticipant(participant?: IParticipant): boolean {
|
2022-10-07 11:36:22 +00:00
|
|
|
return participant?.fakeParticipant === FakeParticipant.SharedVideo;
|
|
|
|
}
|
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the fake participant is a whiteboard.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant|undefined} participant - The participant entity.
|
2022-10-06 11:12:57 +00:00
|
|
|
* @returns {boolean} - True if it's a whiteboard participant.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isWhiteboardParticipant(participant?: IParticipant): boolean {
|
2022-10-06 11:12:57 +00:00
|
|
|
return participant?.fakeParticipant === FakeParticipant.Whiteboard;
|
|
|
|
}
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
/**
|
|
|
|
* Returns a count of the known remote participants in the passed in redux state.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getRemoteParticipantCount(stateful: IStateful) {
|
2022-09-30 09:08:03 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const participantsState = state['features/base/participants'];
|
2021-07-09 12:36:19 +00:00
|
|
|
|
2022-08-01 15:31:38 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state)) {
|
2022-09-30 09:08:03 +00:00
|
|
|
return participantsState.remote.size - participantsState.sortedRemoteVirtualScreenshareParticipants.size;
|
2022-04-04 18:57:58 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 09:08:03 +00:00
|
|
|
return participantsState.remote.size;
|
2017-08-30 23:17:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 20:22:25 +00:00
|
|
|
/**
|
|
|
|
* Returns a count of the known participants in the passed in redux state,
|
|
|
|
* including fake participants.
|
|
|
|
*
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
2018-11-27 20:22:25 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getParticipantCountWithFake(stateful: IStateful) {
|
2022-04-04 18:57:58 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const { local, localScreenShare, remote } = state['features/base/participants'];
|
|
|
|
|
2022-08-01 15:31:38 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state)) {
|
2022-04-04 18:57:58 +00:00
|
|
|
return remote.size + (local ? 1 : 0) + (localScreenShare ? 1 : 0);
|
|
|
|
}
|
2021-07-09 12:36:19 +00:00
|
|
|
|
|
|
|
return remote.size + (local ? 1 : 0);
|
2018-11-27 20:22:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 15:30:23 +00:00
|
|
|
/**
|
|
|
|
* Returns participant's display name.
|
2018-11-08 12:25:02 +00:00
|
|
|
*
|
2022-04-14 17:07:17 +00:00
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's {@code getState} function to be used to
|
|
|
|
* retrieve the state.
|
2017-12-12 15:30:23 +00:00
|
|
|
* @param {string} id - The ID of the participant's display name to retrieve.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getParticipantDisplayName(stateful: IStateful, id: string): string {
|
2022-10-06 11:12:57 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const participant = getParticipantById(state, id);
|
2021-11-26 15:39:34 +00:00
|
|
|
const {
|
|
|
|
defaultLocalDisplayName,
|
|
|
|
defaultRemoteDisplayName
|
2022-10-06 11:12:57 +00:00
|
|
|
} = state['features/base/config'];
|
2017-12-12 15:30:23 +00:00
|
|
|
|
|
|
|
if (participant) {
|
2022-10-06 11:12:57 +00:00
|
|
|
if (isScreenShareParticipant(participant)) {
|
|
|
|
return getScreenshareParticipantDisplayName(state, id);
|
2022-04-14 17:07:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 15:30:23 +00:00
|
|
|
if (participant.name) {
|
|
|
|
return participant.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (participant.local) {
|
2022-09-14 07:54:56 +00:00
|
|
|
return defaultLocalDisplayName ?? '';
|
2017-12-12 15:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 07:54:56 +00:00
|
|
|
return defaultRemoteDisplayName ?? '';
|
2017-12-12 15:30:23 +00:00
|
|
|
}
|
2017-06-27 22:56:55 +00:00
|
|
|
|
2022-04-14 17:07:17 +00:00
|
|
|
/**
|
|
|
|
* Returns screenshare participant's display name.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's {@code getState} function to be used to
|
|
|
|
* retrieve the state.
|
|
|
|
* @param {string} id - The ID of the screenshare participant's display name to retrieve.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getScreenshareParticipantDisplayName(stateful: IStateful, id: string) {
|
2022-05-03 14:25:19 +00:00
|
|
|
const ownerDisplayName = getParticipantDisplayName(stateful, getVirtualScreenshareParticipantOwnerId(id));
|
2022-04-14 17:07:17 +00:00
|
|
|
|
2022-05-03 14:25:19 +00:00
|
|
|
return i18next.t('screenshareDisplayName', { name: ownerDisplayName });
|
2022-04-14 17:07:17 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 14:32:07 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of IDs of the participants that are currently screensharing.
|
|
|
|
*
|
|
|
|
* @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 getScreenshareParticipantIds(stateful: IStateful): Array<string> {
|
|
|
|
return toState(stateful)['features/base/tracks']
|
|
|
|
.filter(track => track.videoType === VIDEO_TYPE.DESKTOP && !track.muted)
|
|
|
|
.map(t => t.participantId);
|
|
|
|
}
|
|
|
|
|
2018-05-21 20:52:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the presence status of a participant associated with the passed id.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state.
|
|
|
|
* @param {string} id - The id of the participant.
|
|
|
|
* @returns {string} - The presence status.
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getParticipantPresenceStatus(stateful: IStateful, id: string) {
|
2018-05-21 20:52:30 +00:00
|
|
|
if (!id) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
const participantById = getParticipantById(stateful, id);
|
|
|
|
|
|
|
|
if (!participantById) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return participantById.presence;
|
|
|
|
}
|
|
|
|
|
2017-06-27 22:56:55 +00:00
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Selectors for getting all remote participants.
|
2017-06-27 22:56:55 +00:00
|
|
|
*
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {Map<string, Object>}
|
2017-06-27 22:56:55 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getRemoteParticipants(stateful: IStateful): Map<string, IParticipant> {
|
2021-07-09 12:36:19 +00:00
|
|
|
return toState(stateful)['features/base/participants'].remote;
|
2017-06-27 22:56:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 17:37:05 +00:00
|
|
|
/**
|
|
|
|
* Selectors for the getting the remote participants in the order that they are displayed in the filmstrip.
|
|
|
|
*
|
|
|
|
@param {(Function|Object)} stateful - The (whole) redux state, or redux's {@code getState} function to be used to
|
|
|
|
* retrieve the state features/filmstrip.
|
|
|
|
* @returns {Array<string>}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getRemoteParticipantsSorted(stateful: IStateful) {
|
2021-09-10 17:37:05 +00:00
|
|
|
return toState(stateful)['features/filmstrip'].remoteParticipants;
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Returns the participant which has its pinned state set to truthy.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {(IParticipant|undefined)}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getPinnedParticipant(stateful: IStateful) {
|
2022-03-29 08:45:09 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const { pinnedParticipant } = state['features/base/participants'];
|
2022-04-12 13:19:10 +00:00
|
|
|
const stageFilmstrip = isStageFilmstripAvailable(state);
|
2022-03-29 08:45:09 +00:00
|
|
|
|
|
|
|
if (stageFilmstrip) {
|
|
|
|
const { activeParticipants } = state['features/filmstrip'];
|
2022-09-14 07:54:56 +00:00
|
|
|
const id = activeParticipants.find(p => p.pinned)?.participantId;
|
2022-03-29 08:45:09 +00:00
|
|
|
|
|
|
|
return id ? getParticipantById(stateful, id) : undefined;
|
|
|
|
}
|
2018-05-17 15:45:51 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
if (!pinnedParticipant) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-06-12 10:15:16 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return getParticipantById(stateful, pinnedParticipant);
|
2020-06-12 10:15:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 10:13:28 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the participant is a moderator.
|
|
|
|
*
|
|
|
|
* @param {string} participant - Participant object.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isParticipantModerator(participant?: IParticipant) {
|
2020-07-15 10:13:28 +00:00
|
|
|
return participant?.role === PARTICIPANT_ROLE.MODERATOR;
|
|
|
|
}
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
/**
|
|
|
|
* Returns the dominant speaker participant.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state features/base/participants.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {IParticipant} - The participant from the redux store.
|
2021-07-09 12:36:19 +00:00
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function getDominantSpeakerParticipant(stateful: IStateful) {
|
2021-07-09 12:36:19 +00:00
|
|
|
const state = toState(stateful)['features/base/participants'];
|
|
|
|
const { dominantSpeaker } = state;
|
|
|
|
|
|
|
|
if (!dominantSpeaker) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getParticipantById(stateful, dominantSpeaker);
|
|
|
|
}
|
|
|
|
|
2019-05-22 10:00:17 +00:00
|
|
|
/**
|
|
|
|
* Returns true if all of the meeting participants are moderators.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful -Object or function that can be resolved
|
|
|
|
* to the Redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function isEveryoneModerator(stateful: IStateful) {
|
2021-07-09 12:36:19 +00:00
|
|
|
const state = toState(stateful)['features/base/participants'];
|
2019-05-22 10:00:17 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return state.everyoneIsModerator === true;
|
2019-05-22 10:00:17 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 10:23:01 +00:00
|
|
|
/**
|
2019-08-30 16:39:06 +00:00
|
|
|
* Checks a value and returns true if it's a preloaded icon object.
|
2019-07-16 10:23:01 +00:00
|
|
|
*
|
2019-08-30 16:39:06 +00:00
|
|
|
* @param {?string | ?Object} icon - The icon to check.
|
2019-07-16 10:23:01 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-08-08 08:12:22 +00:00
|
|
|
export function isIconUrl(icon?: string | Object) {
|
2021-01-05 19:02:11 +00:00
|
|
|
return Boolean(icon) && (typeof icon === 'object' || typeof icon === 'function');
|
2019-07-16 10:23:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 15:45:51 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the current local participant is a moderator in the
|
|
|
|
* conference.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - Object or function that can be resolved
|
|
|
|
* to the Redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
export function isLocalParticipantModerator(stateful: IStateful) {
|
2021-07-09 12:36:19 +00:00
|
|
|
const state = toState(stateful)['features/base/participants'];
|
|
|
|
|
|
|
|
const { local } = state;
|
2018-05-17 15:45:51 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
if (!local) {
|
2018-05-17 15:45:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return isParticipantModerator(local);
|
2018-05-17 15:45:51 +00:00
|
|
|
}
|
2019-01-25 10:17:58 +00:00
|
|
|
|
2019-06-26 14:08:23 +00:00
|
|
|
/**
|
|
|
|
* Resolves the first loadable avatar URL for a participant.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant to resolve avatars for.
|
2020-11-15 21:33:55 +00:00
|
|
|
* @param {Store} store - Redux store.
|
2019-06-26 14:08:23 +00:00
|
|
|
* @returns {?string}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
async function _getFirstLoadableAvatarUrl(participant: IParticipant, store: IStore) {
|
2019-06-26 14:08:23 +00:00
|
|
|
for (let i = 0; i < AVATAR_CHECKER_FUNCTIONS.length; i++) {
|
2020-11-15 21:33:55 +00:00
|
|
|
const url = AVATAR_CHECKER_FUNCTIONS[i](participant, store);
|
2019-06-26 14:08:23 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
if (url !== null) {
|
2019-06-26 14:08:23 +00:00
|
|
|
if (AVATAR_CHECKED_URLS.has(url)) {
|
2021-12-17 00:16:24 +00:00
|
|
|
const { isLoadable, isUsingCORS } = AVATAR_CHECKED_URLS.get(url) || {};
|
|
|
|
|
|
|
|
if (isLoadable) {
|
|
|
|
return {
|
|
|
|
isUsingCORS,
|
|
|
|
src: url
|
|
|
|
};
|
2019-06-26 14:08:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
2021-12-17 00:16:24 +00:00
|
|
|
const { corsAvatarURLs } = store.getState()['features/base/config'];
|
2022-09-30 14:51:16 +00:00
|
|
|
const useCORS = isIconUrl(url) ? false : isCORSAvatarURL(url, corsAvatarURLs);
|
|
|
|
const { isUsingCORS, src } = await preloadImage(url, useCORS);
|
2021-12-17 00:16:24 +00:00
|
|
|
|
|
|
|
AVATAR_CHECKED_URLS.set(src, {
|
|
|
|
isLoadable: true,
|
|
|
|
isUsingCORS
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
isUsingCORS,
|
|
|
|
src
|
|
|
|
};
|
2019-06-26 14:08:23 +00:00
|
|
|
} catch (e) {
|
2021-12-17 00:16:24 +00:00
|
|
|
AVATAR_CHECKED_URLS.set(url, {
|
|
|
|
isLoadable: false,
|
|
|
|
isUsingCORS: false
|
|
|
|
});
|
2019-06-26 14:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-08-18 11:29:41 +00:00
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
/**
|
|
|
|
* Get the participants queue with raised hands.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2021-10-21 09:40:57 +00:00
|
|
|
* @returns {Array<Object>}
|
2021-09-10 11:05:16 +00:00
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export function getRaiseHandsQueue(stateful: IStateful): Array<{ id: string; raisedHandTimestamp: number; }> {
|
2021-09-10 11:05:16 +00:00
|
|
|
const { raisedHandsQueue } = toState(stateful)['features/base/participants'];
|
|
|
|
|
|
|
|
return raisedHandsQueue;
|
|
|
|
}
|
2021-10-21 09:40:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the given participant has his hand raised or not.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant.
|
|
|
|
* @returns {boolean} - Whether participant has raise hand or not.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function hasRaisedHand(participant?: IParticipant): boolean {
|
2022-08-26 09:54:03 +00:00
|
|
|
return Boolean(participant?.raisedHandTimestamp);
|
2021-10-21 09:40:57 +00:00
|
|
|
}
|