2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../app/types';
|
2021-06-23 11:23:44 +00:00
|
|
|
import {
|
|
|
|
isEnabledFromState,
|
2021-10-05 07:14:08 +00:00
|
|
|
isLocalParticipantApprovedFromState,
|
2022-09-27 07:10:28 +00:00
|
|
|
isParticipantApproved,
|
2021-10-05 07:14:08 +00:00
|
|
|
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';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { INVITE_ENABLED } from '../base/flags/constants';
|
|
|
|
import { getFeatureFlag } from '../base/flags/functions';
|
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-10-06 13:11:40 +00:00
|
|
|
getLocalParticipant,
|
2022-09-27 07:10:28 +00:00
|
|
|
getRaiseHandsQueue,
|
2021-10-06 13:11:40 +00:00
|
|
|
getRemoteParticipantsSorted,
|
2022-09-27 07:10:28 +00:00
|
|
|
isLocalParticipantModerator,
|
|
|
|
isParticipantModerator
|
2021-06-23 11:23:44 +00:00
|
|
|
} from '../base/participants/functions';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IParticipant } from '../base/participants/types';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { toState } from '../base/redux/functions';
|
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
|
|
|
|
2022-09-27 07:10:28 +00:00
|
|
|
import { MEDIA_STATE, QUICK_ACTION_BUTTON, REDUCER_KEY } from './constants';
|
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-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant|undefined} participant - The participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* @param {MediaType} mediaType - The media type.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {MediaState}
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isForceMuted(participant: IParticipant | undefined, mediaType: MediaType, state: IReduxState) {
|
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-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant} participant - The participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* @param {boolean} muted - The mute state of the participant.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {MediaState}
|
2021-06-23 11:23:44 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getParticipantAudioMediaState(participant: IParticipant, muted: Boolean, state: IReduxState) {
|
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-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant} participant - The participant.
|
2021-09-10 11:05:16 +00:00
|
|
|
* @param {boolean} muted - The mute state of the participant.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2021-09-10 11:05:16 +00:00
|
|
|
* @returns {MediaState}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getParticipantVideoMediaState(participant: IParticipant, muted: Boolean, state: IReduxState) {
|
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
|
|
|
/**
|
|
|
|
* Returns this feature's root state.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Global state.
|
2021-04-21 13:48:05 +00:00
|
|
|
* @returns {Object} Feature state.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
const getState = (state: IReduxState) => 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-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Global state.
|
2021-04-21 13:48:05 +00:00
|
|
|
* @returns {boolean} Is the participants pane open.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const getParticipantsPaneOpen = (state: IReduxState) => 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-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant} participant - The participant.
|
2021-06-23 11:23:44 +00:00
|
|
|
* @param {boolean} isAudioMuted - If audio is muted for the participant.
|
2023-03-06 17:05:26 +00:00
|
|
|
* @param {boolean} isVideoMuted - If audio is muted for the participant.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} 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
|
|
|
*/
|
2023-03-06 17:05:26 +00:00
|
|
|
export function getQuickActionButtonType(
|
|
|
|
participant: IParticipant,
|
|
|
|
isAudioMuted: Boolean,
|
|
|
|
isVideoMuted: Boolean,
|
|
|
|
state: IReduxState) {
|
2021-06-23 11:23:44 +00:00
|
|
|
// handled only by moderators
|
2023-03-06 17:05:26 +00:00
|
|
|
const isVideoForceMuted = isForceMuted(participant, MEDIA_TYPE.VIDEO, state);
|
|
|
|
|
2021-06-23 11:23:44 +00:00
|
|
|
if (isLocalParticipantModerator(state)) {
|
|
|
|
if (!isAudioMuted) {
|
|
|
|
return QUICK_ACTION_BUTTON.MUTE;
|
|
|
|
}
|
2023-03-06 17:05:26 +00:00
|
|
|
if (!isVideoMuted) {
|
|
|
|
return QUICK_ACTION_BUTTON.STOP_VIDEO;
|
|
|
|
}
|
|
|
|
if (isVideoForceMuted) {
|
|
|
|
return QUICK_ACTION_BUTTON.ALLOW_VIDEO;
|
|
|
|
}
|
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-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Global state.
|
2021-06-02 16:49:44 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const shouldRenderInviteButton = (state: IReduxState) => {
|
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-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Global state.
|
2022-04-29 09:30:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const isMoreActionsVisible = (state: IReduxState) => {
|
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-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Global state.
|
2022-04-29 09:30:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const isMuteAllVisible = (state: IReduxState) => {
|
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
|
|
|
};
|