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,
|
|
|
|
isLocalParticipantApprovedFromState
|
|
|
|
} 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
|
|
|
getParticipantCount,
|
|
|
|
isLocalParticipantModerator,
|
|
|
|
isParticipantModerator
|
|
|
|
} 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-06-23 11:23:44 +00:00
|
|
|
if (getParticipantCount(state) > 2 && isEnabledFromState(mediaType, state)) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (participant === dominantSpeaker) {
|
|
|
|
return MEDIA_STATE.DOMINANT_SPEAKER;
|
|
|
|
}
|
|
|
|
|
2021-06-23 11:23:44 +00:00
|
|
|
if (muted) {
|
2021-07-09 12:36:19 +00:00
|
|
|
if (isForceMuted(participant, MEDIA_TYPE.AUDIO, 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)) {
|
2021-07-09 12:36:19 +00:00
|
|
|
if (isForceMuted(participant, MEDIA_TYPE.AUDIO, state)) {
|
2021-06-23 11:23:44 +00:00
|
|
|
return QUICK_ACTION_BUTTON.ASK_TO_UNMUTE;
|
|
|
|
}
|
|
|
|
if (!isAudioMuted) {
|
|
|
|
return QUICK_ACTION_BUTTON.MUTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|