2022-09-14 11:32:58 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
|
|
|
import { IState } from '../app/types';
|
2021-06-23 11:23:44 +00:00
|
|
|
import {
|
|
|
|
isParticipantApproved,
|
|
|
|
isEnabledFromState,
|
2021-10-05 07:14:08 +00:00
|
|
|
isLocalParticipantApprovedFromState,
|
|
|
|
isSupported
|
2021-06-23 11:23:44 +00:00
|
|
|
} from '../av-moderation/functions';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { IStateful } from '../base/app/types';
|
|
|
|
// @ts-ignore
|
2021-06-02 16:49:44 +00:00
|
|
|
import { getFeatureFlag, INVITE_ENABLED } from '../base/flags';
|
2021-06-23 11:23:44 +00:00
|
|
|
import { MEDIA_TYPE, type MediaType } from '../base/media/constants';
|
|
|
|
import {
|
2021-08-18 12:10:16 +00:00
|
|
|
getDominantSpeakerParticipant,
|
2021-06-23 11:23:44 +00:00
|
|
|
isLocalParticipantModerator,
|
2021-10-06 13:11:40 +00:00
|
|
|
isParticipantModerator,
|
|
|
|
getLocalParticipant,
|
|
|
|
getRemoteParticipantsSorted,
|
|
|
|
getRaiseHandsQueue
|
2021-06-23 11:23:44 +00:00
|
|
|
} from '../base/participants/functions';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { Participant } from '../base/participants/types';
|
|
|
|
import { toState } from '../base/redux/functions';
|
|
|
|
// @ts-ignore
|
2021-12-21 12:51:39 +00:00
|
|
|
import { normalizeAccents } from '../base/util/strings';
|
2022-05-19 08:48:54 +00:00
|
|
|
import { isInBreakoutRoom } from '../breakout-rooms/functions';
|
2021-06-02 16:49:44 +00:00
|
|
|
|
2021-06-23 11:23:44 +00:00
|
|
|
import { QUICK_ACTION_BUTTON, REDUCER_KEY, MEDIA_STATE } from './constants';
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the first styled ancestor component of an element.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {HTMLElement|null} target - Element to look up.
|
2021-10-22 13:23:52 +00:00
|
|
|
* @param {string} cssClass - Styled component reference.
|
2022-09-14 11:32:58 +00:00
|
|
|
* @returns {HTMLElement|null} Ancestor.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const findAncestorByClass = (target: HTMLElement | null, cssClass: string): HTMLElement | null => {
|
2021-10-22 13:23:52 +00:00
|
|
|
if (!target || target.classList.contains(cssClass)) {
|
2021-04-21 13:48:05 +00:00
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2021-10-22 13:23:52 +00:00
|
|
|
return findAncestorByClass(target.parentElement, cssClass);
|
2021-04-21 13:48:05 +00:00
|
|
|
};
|
|
|
|
|
2021-06-23 11:23:44 +00:00
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Checks if a participant is force muted.
|
2021-06-23 11:23:44 +00:00
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {Participant|undefined} participant - The participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* @param {MediaType} mediaType - The media type.
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - The redux state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {MediaState}
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export function isForceMuted(participant: Participant | undefined, mediaType: MediaType, state: IState) {
|
2021-08-20 16:51:38 +00:00
|
|
|
if (isEnabledFromState(mediaType, state)) {
|
2022-09-14 11:32:58 +00:00
|
|
|
if (participant?.local) {
|
2021-06-23 11:23:44 +00:00
|
|
|
return !isLocalParticipantApprovedFromState(mediaType, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// moderators cannot be force muted
|
|
|
|
if (isParticipantModerator(participant)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
return !isParticipantApproved(participant?.id ?? '', mediaType)(state);
|
2021-06-23 11:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-07-09 12:36:19 +00:00
|
|
|
}
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Determines the audio media state (the mic icon) for a participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {Participant} participant - The participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* @param {boolean} muted - The mute state of the participant.
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - The redux state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {MediaState}
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export function getParticipantAudioMediaState(participant: Participant, muted: Boolean, state: IState) {
|
2021-08-18 12:10:16 +00:00
|
|
|
const dominantSpeaker = getDominantSpeakerParticipant(state);
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
if (muted) {
|
|
|
|
if (isForceMuted(participant, MEDIA_TYPE.AUDIO, state)) {
|
|
|
|
return MEDIA_STATE.FORCE_MUTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MEDIA_STATE.MUTED;
|
|
|
|
}
|
|
|
|
|
2021-08-18 12:10:16 +00:00
|
|
|
if (participant === dominantSpeaker) {
|
|
|
|
return MEDIA_STATE.DOMINANT_SPEAKER;
|
|
|
|
}
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
return MEDIA_STATE.UNMUTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the video media state (the mic icon) for a participant.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {Participant} participant - The participant.
|
2021-09-10 11:05:16 +00:00
|
|
|
* @param {boolean} muted - The mute state of the participant.
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - The redux state.
|
2021-09-10 11:05:16 +00:00
|
|
|
* @returns {MediaState}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export function getParticipantVideoMediaState(participant: Participant, muted: Boolean, state: IState) {
|
2021-06-23 11:23:44 +00:00
|
|
|
if (muted) {
|
2021-09-10 11:05:16 +00:00
|
|
|
if (isForceMuted(participant, MEDIA_TYPE.VIDEO, state)) {
|
2021-06-23 11:23:44 +00:00
|
|
|
return MEDIA_STATE.FORCE_MUTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MEDIA_STATE.MUTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MEDIA_STATE.UNMUTED;
|
2021-07-09 12:36:19 +00:00
|
|
|
}
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
|
|
|
* Get a style property from a style declaration as a float.
|
|
|
|
*
|
|
|
|
* @param {CSSStyleDeclaration} styles - Style declaration.
|
|
|
|
* @param {string} name - Property name.
|
|
|
|
* @returns {number} Float value.
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getFloatStyleProperty = (styles: CSSStyleDeclaration, name: string) =>
|
2021-04-21 13:48:05 +00:00
|
|
|
parseFloat(styles.getPropertyValue(name));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the outer height of an element, including margins.
|
|
|
|
*
|
|
|
|
* @param {Element} element - Target element.
|
|
|
|
* @returns {number} Computed height.
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export const getComputedOuterHeight = (element: HTMLElement) => {
|
2021-04-21 13:48:05 +00:00
|
|
|
const computedStyle = getComputedStyle(element);
|
|
|
|
|
|
|
|
return element.offsetHeight
|
|
|
|
+ getFloatStyleProperty(computedStyle, 'margin-top')
|
|
|
|
+ getFloatStyleProperty(computedStyle, 'margin-bottom');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns this feature's root state.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - Global state.
|
2021-04-21 13:48:05 +00:00
|
|
|
* @returns {Object} Feature state.
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
const getState = (state: IState) => state[REDUCER_KEY];
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-05-19 08:48:54 +00:00
|
|
|
/**
|
|
|
|
* Returns the participants pane config.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, the redux
|
2022-05-19 08:48:54 +00:00
|
|
|
* {@code getState} function, or the redux state itself.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getParticipantsPaneConfig = (stateful: IStateful) => {
|
2022-05-19 08:48:54 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const { participantsPane = {} } = state['features/base/config'];
|
|
|
|
|
|
|
|
return participantsPane;
|
|
|
|
};
|
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
|
|
|
* Is the participants pane open.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - Global state.
|
2021-04-21 13:48:05 +00:00
|
|
|
* @returns {boolean} Is the participants pane open.
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getParticipantsPaneOpen = (state: IState) => Boolean(getState(state)?.isOpen);
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Returns the type of quick action button to be displayed for a participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* The button is displayed when hovering a participant from the participant list.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {Participant} participant - The participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* @param {boolean} isAudioMuted - If audio is muted for the participant.
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - The redux state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {string} - The type of the quick action button.
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export function getQuickActionButtonType(participant: Participant, isAudioMuted: Boolean, state: IState) {
|
2021-06-23 11:23:44 +00:00
|
|
|
// handled only by moderators
|
|
|
|
if (isLocalParticipantModerator(state)) {
|
|
|
|
if (!isAudioMuted) {
|
|
|
|
return QUICK_ACTION_BUTTON.MUTE;
|
|
|
|
}
|
2021-10-05 07:14:08 +00:00
|
|
|
if (isSupported()(state)) {
|
|
|
|
return QUICK_ACTION_BUTTON.ASK_TO_UNMUTE;
|
|
|
|
}
|
2021-06-23 11:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QUICK_ACTION_BUTTON.NONE;
|
2021-07-09 12:36:19 +00:00
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-06-02 16:49:44 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the invite button should be rendered.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - Global state.
|
2021-06-02 16:49:44 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const shouldRenderInviteButton = (state: IState) => {
|
2021-06-02 16:49:44 +00:00
|
|
|
const { disableInviteFunctions } = toState(state)['features/base/config'];
|
|
|
|
const flagEnabled = getFeatureFlag(state, INVITE_ENABLED, true);
|
2021-09-14 15:31:30 +00:00
|
|
|
const inBreakoutRoom = isInBreakoutRoom(state);
|
2021-06-02 16:49:44 +00:00
|
|
|
|
2021-09-14 15:31:30 +00:00
|
|
|
return flagEnabled && !disableInviteFunctions && !inBreakoutRoom;
|
2021-06-02 16:49:44 +00:00
|
|
|
};
|
2021-10-06 13:11:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Selector for retrieving ids of participants in the order that they are displayed in the filmstrip (with the
|
|
|
|
* exception of participants with raised hand). The participants are reordered as follows.
|
|
|
|
* 1. Dominant speaker.
|
|
|
|
* 2. Local participant.
|
|
|
|
* 3. Participants with raised hand.
|
|
|
|
* 4. Participants with screenshare sorted alphabetically by their display name.
|
|
|
|
* 5. Shared video participants.
|
|
|
|
* 6. Recent speakers sorted alphabetically by their display name.
|
|
|
|
* 7. Rest of the participants sorted alphabetically by their display name.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The (whole) redux state, or redux's
|
2021-10-06 13:11:40 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state features/base/participants.
|
|
|
|
* @returns {Array<string>}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export function getSortedParticipantIds(stateful: IStateful) {
|
|
|
|
const id = getLocalParticipant(stateful)?.id;
|
2021-10-06 13:11:40 +00:00
|
|
|
const remoteParticipants = getRemoteParticipantsSorted(stateful);
|
|
|
|
const reorderedParticipants = new Set(remoteParticipants);
|
2021-10-21 09:40:57 +00:00
|
|
|
const raisedHandParticipants = getRaiseHandsQueue(stateful).map(({ id: particId }) => particId);
|
2021-10-06 13:11:40 +00:00
|
|
|
const remoteRaisedHandParticipants = new Set(raisedHandParticipants || []);
|
|
|
|
const dominantSpeaker = getDominantSpeakerParticipant(stateful);
|
|
|
|
|
|
|
|
for (const participant of remoteRaisedHandParticipants.keys()) {
|
|
|
|
// Avoid duplicates.
|
|
|
|
if (reorderedParticipants.has(participant)) {
|
|
|
|
reorderedParticipants.delete(participant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const dominant = [];
|
2022-01-13 10:48:48 +00:00
|
|
|
const dominantId = dominantSpeaker?.id;
|
2022-09-14 11:32:58 +00:00
|
|
|
const local = remoteRaisedHandParticipants.has(id ?? '') ? [] : [ id ];
|
2021-10-06 13:11:40 +00:00
|
|
|
|
2022-01-13 10:48:48 +00:00
|
|
|
// In case dominat speaker has raised hand, keep the order in the raised hand queue.
|
|
|
|
// In case they don't have raised hand, goes first in the participants list.
|
|
|
|
if (dominantId && dominantId !== id && !remoteRaisedHandParticipants.has(dominantId)) {
|
|
|
|
reorderedParticipants.delete(dominantId);
|
|
|
|
dominant.push(dominantId);
|
2021-10-06 13:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Move self and participants with raised hand to the top of the list.
|
|
|
|
return [
|
|
|
|
...dominant,
|
2021-10-21 09:40:57 +00:00
|
|
|
...local,
|
2021-10-06 13:11:40 +00:00
|
|
|
...Array.from(remoteRaisedHandParticipants.keys()),
|
|
|
|
...Array.from(reorderedParticipants.keys())
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-12-21 12:51:39 +00:00
|
|
|
/**
|
|
|
|
* Checks if a participant matches the search string.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant to be checked.
|
|
|
|
* @param {string} searchString - The participants search string.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export function participantMatchesSearch(participant: { displayName: string; jid: string; name?: string; },
|
|
|
|
searchString: string) {
|
2021-12-21 12:51:39 +00:00
|
|
|
if (searchString === '') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const names = normalizeAccents(participant?.name || participant?.displayName || '')
|
|
|
|
.toLowerCase()
|
|
|
|
.split(' ');
|
|
|
|
const lowerCaseSearchString = searchString.toLowerCase();
|
|
|
|
|
|
|
|
for (const name of names) {
|
|
|
|
if (name.startsWith(lowerCaseSearchString)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-29 09:30:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the more actions button is visible.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - Global state.
|
2022-04-29 09:30:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const isMoreActionsVisible = (state: IState) => {
|
2022-05-19 08:48:54 +00:00
|
|
|
const isLocalModerator = isLocalParticipantModerator(state);
|
2022-04-29 09:30:49 +00:00
|
|
|
const inBreakoutRoom = isInBreakoutRoom(state);
|
2022-05-19 08:48:54 +00:00
|
|
|
const { hideMoreActionsButton } = getParticipantsPaneConfig(state);
|
2022-04-29 09:30:49 +00:00
|
|
|
|
2022-05-19 08:48:54 +00:00
|
|
|
return inBreakoutRoom ? false : !hideMoreActionsButton && isLocalModerator;
|
2022-04-29 09:30:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the mute all button is visible.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IState} state - Global state.
|
2022-04-29 09:30:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const isMuteAllVisible = (state: IState) => {
|
2022-05-19 08:48:54 +00:00
|
|
|
const isLocalModerator = isLocalParticipantModerator(state);
|
2022-04-29 09:30:49 +00:00
|
|
|
const inBreakoutRoom = isInBreakoutRoom(state);
|
2022-05-19 08:48:54 +00:00
|
|
|
const { hideMuteAllButton } = getParticipantsPaneConfig(state);
|
2022-04-29 09:30:49 +00:00
|
|
|
|
2022-05-19 08:48:54 +00:00
|
|
|
return inBreakoutRoom ? false : !hideMuteAllButton && isLocalModerator;
|
2022-04-29 09:30:49 +00:00
|
|
|
};
|