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-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
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a class attribute value.
|
|
|
|
*
|
|
|
|
* @param {Iterable<string>} args - String iterable.
|
|
|
|
* @returns {string} Class attribute value.
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export const classList = (...args: Array<string | boolean>) => args.filter(Boolean).join(' ');
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the first styled ancestor component of an element.
|
|
|
|
*
|
|
|
|
* @param {Element} target - Element to look up.
|
|
|
|
* @param {StyledComponentClass} component - Styled component reference.
|
|
|
|
* @returns {Element|null} Ancestor.
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export const findStyledAncestor = (target: Object, component: any) => {
|
2021-04-21 13:48:05 +00:00
|
|
|
if (!target || target.matches(`.${component.styledComponentId}`)) {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
return findStyledAncestor(target.parentElement, component);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
return flagEnabled && !disableInviteFunctions;
|
|
|
|
};
|
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);
|
|
|
|
const raisedHandParticipants = getRaiseHandsQueue(stateful);
|
|
|
|
const remoteRaisedHandParticipants = new Set(raisedHandParticipants || []);
|
|
|
|
const dominantSpeaker = getDominantSpeakerParticipant(stateful);
|
|
|
|
|
|
|
|
for (const participant of remoteRaisedHandParticipants.keys()) {
|
|
|
|
// Avoid duplicates.
|
|
|
|
if (reorderedParticipants.has(participant)) {
|
|
|
|
reorderedParticipants.delete(participant);
|
|
|
|
} else {
|
|
|
|
remoteRaisedHandParticipants.delete(participant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove self.
|
|
|
|
remoteRaisedHandParticipants.delete(id);
|
|
|
|
|
|
|
|
const dominant = [];
|
|
|
|
|
|
|
|
// Remove dominant speaker.
|
|
|
|
if (dominantSpeaker && dominantSpeaker.id !== id) {
|
|
|
|
remoteRaisedHandParticipants.delete(dominantSpeaker.id);
|
|
|
|
reorderedParticipants.delete(dominantSpeaker.id);
|
|
|
|
dominant.push(dominantSpeaker.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move self and participants with raised hand to the top of the list.
|
|
|
|
return [
|
|
|
|
...dominant,
|
|
|
|
id,
|
|
|
|
...Array.from(remoteRaisedHandParticipants.keys()),
|
|
|
|
...Array.from(reorderedParticipants.keys())
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|