2021-06-23 11:23:44 +00:00
|
|
|
// @flow
|
2021-06-02 16:49:44 +00:00
|
|
|
|
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';
|
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';
|
2021-06-02 16:49:44 +00:00
|
|
|
import { toState } from '../base/redux';
|
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.
|
|
|
|
*
|
|
|
|
* @param {Element} target - Element to look up.
|
2021-10-22 13:23:52 +00:00
|
|
|
* @param {string} cssClass - Styled component reference.
|
2021-04-21 13:48:05 +00:00
|
|
|
* @returns {Element|null} Ancestor.
|
|
|
|
*/
|
2021-10-22 13:23:52 +00:00
|
|
|
export const findAncestorByClass = (target: Object, cssClass: string) => {
|
|
|
|
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
|
|
|
*
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {Object} participant - The participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* @param {MediaType} mediaType - The media type.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {MediaState}
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2021-07-09 12:36:19 +00:00
|
|
|
export function isForceMuted(participant: Object, mediaType: MediaType, state: Object) {
|
2021-08-20 16:51:38 +00:00
|
|
|
if (isEnabledFromState(mediaType, state)) {
|
2021-06-23 11:23:44 +00:00
|
|
|
if (participant.local) {
|
|
|
|
return !isLocalParticipantApprovedFromState(mediaType, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// moderators cannot be force muted
|
|
|
|
if (isParticipantModerator(participant)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !isParticipantApproved(participant.id, mediaType)(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant.
|
|
|
|
* @param {boolean} muted - The mute state of the participant.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {MediaState}
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2021-07-09 12:36:19 +00:00
|
|
|
export function getParticipantAudioMediaState(participant: Object, muted: Boolean, state: Object) {
|
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.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant.
|
|
|
|
* @param {boolean} muted - The mute state of the participant.
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {MediaState}
|
|
|
|
*/
|
|
|
|
export function getParticipantVideoMediaState(participant: Object, muted: Boolean, state: Object) {
|
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.
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export const getFloatStyleProperty = (styles: Object, 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.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Global state.
|
|
|
|
* @returns {Object} Feature state.
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
const getState = (state: Object) => state[REDUCER_KEY];
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2022-05-19 08:48:54 +00:00
|
|
|
/**
|
|
|
|
* Returns the participants pane config.
|
|
|
|
*
|
|
|
|
* @param {Function|Object} stateful - The redux store, the redux
|
|
|
|
* {@code getState} function, or the redux state itself.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export const getParticipantsPaneConfig = (stateful: Function | Object) => {
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Global state.
|
|
|
|
* @returns {boolean} Is the participants pane open.
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export const getParticipantsPaneOpen = (state: Object) => Boolean(getState(state)?.isOpen);
|
|
|
|
|
|
|
|
/**
|
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.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant.
|
|
|
|
* @param {boolean} isAudioMuted - If audio is muted for the participant.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {string} - The type of the quick action button.
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2021-07-09 12:36:19 +00:00
|
|
|
export function getQuickActionButtonType(participant: Object, isAudioMuted: Boolean, state: Object) {
|
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.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Global state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export const shouldRenderInviteButton = (state: Object) => {
|
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.
|
|
|
|
*
|
|
|
|
* @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 {Array<string>}
|
|
|
|
*/
|
|
|
|
export function getSortedParticipantIds(stateful: Object | Function): Array<string> {
|
|
|
|
const { id } = getLocalParticipant(stateful);
|
|
|
|
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;
|
2021-10-21 09:40:57 +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}
|
|
|
|
*/
|
|
|
|
export function participantMatchesSearch(participant: Object, searchString: string) {
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Global state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export const isMoreActionsVisible = (state: Object) => {
|
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.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Global state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export const isMuteAllVisible = (state: Object) => {
|
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
|
|
|
};
|