2017-10-13 19:31:05 +00:00
|
|
|
// @flow
|
2019-07-04 07:45:15 +00:00
|
|
|
import { getGravatarURL } from 'js-utils/avatar';
|
2017-09-01 21:25:48 +00:00
|
|
|
|
2019-01-25 10:17:58 +00:00
|
|
|
import { JitsiParticipantConnectionStatus } from '../lib-jitsi-meet';
|
|
|
|
import { MEDIA_TYPE, shouldRenderVideoTrack } from '../media';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { toState } from '../redux';
|
2019-01-25 10:17:58 +00:00
|
|
|
import { getTrackByMediaTypeAndParticipant } from '../tracks';
|
2019-06-26 14:08:23 +00:00
|
|
|
import { createDeferred } from '../util';
|
2019-01-25 10:17:58 +00:00
|
|
|
|
2017-12-19 23:11:54 +00:00
|
|
|
import {
|
2019-07-16 10:23:01 +00:00
|
|
|
JIGASI_PARTICIPANT_ICON,
|
2019-01-15 11:28:07 +00:00
|
|
|
MAX_DISPLAY_NAME_LENGTH,
|
2018-05-17 15:45:51 +00:00
|
|
|
PARTICIPANT_ROLE
|
2017-12-19 23:11:54 +00:00
|
|
|
} from './constants';
|
2019-06-26 14:08:23 +00:00
|
|
|
import { preloadImage } from './preloadImage';
|
2017-08-16 21:28:39 +00:00
|
|
|
|
2017-02-27 21:42:28 +00:00
|
|
|
declare var config: Object;
|
|
|
|
declare var interfaceConfig: Object;
|
2017-03-07 16:50:17 +00:00
|
|
|
|
2019-06-26 14:08:23 +00:00
|
|
|
/**
|
|
|
|
* Temp structures for avatar urls to be checked/preloaded.
|
|
|
|
*/
|
|
|
|
const AVATAR_QUEUE = [];
|
|
|
|
const AVATAR_CHECKED_URLS = new Map();
|
|
|
|
/* eslint-disable arrow-body-style */
|
|
|
|
const AVATAR_CHECKER_FUNCTIONS = [
|
2019-07-16 10:23:01 +00:00
|
|
|
participant => {
|
|
|
|
return participant && participant.isJigasi ? JIGASI_PARTICIPANT_ICON : null;
|
|
|
|
},
|
2019-06-26 14:08:23 +00:00
|
|
|
participant => {
|
|
|
|
return participant && participant.avatarURL ? participant.avatarURL : null;
|
|
|
|
},
|
|
|
|
participant => {
|
|
|
|
return participant && participant.email ? getGravatarURL(participant.email) : null;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
/* eslint-enable arrow-body-style */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves the first loadable avatar URL for a participant.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant to resolve avatars for.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
export function getFirstLoadableAvatarUrl(participant: Object) {
|
|
|
|
const deferred = createDeferred();
|
|
|
|
const fullPromise = deferred.promise
|
|
|
|
.then(() => _getFirstLoadableAvatarUrl(participant))
|
|
|
|
.then(src => {
|
|
|
|
|
|
|
|
if (AVATAR_QUEUE.length) {
|
|
|
|
const next = AVATAR_QUEUE.shift();
|
|
|
|
|
|
|
|
next.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
return src;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (AVATAR_QUEUE.length) {
|
|
|
|
AVATAR_QUEUE.push(deferred);
|
|
|
|
} else {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
return fullPromise;
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns local participant from Redux state.
|
|
|
|
*
|
2017-10-13 19:31:05 +00:00
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
2017-05-31 05:32:13 +00:00
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {(Participant|undefined)}
|
|
|
|
*/
|
2017-10-13 19:31:05 +00:00
|
|
|
export function getLocalParticipant(stateful: Object | Function) {
|
|
|
|
const participants = _getAllParticipants(stateful);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
return participants.find(p => p.local);
|
|
|
|
}
|
|
|
|
|
2019-01-15 11:28:07 +00:00
|
|
|
/**
|
|
|
|
* Normalizes a display name so then no invalid values (padding, length...etc)
|
|
|
|
* can be set.
|
|
|
|
*
|
|
|
|
* @param {string} name - The display name to set.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getNormalizedDisplayName(name: string) {
|
|
|
|
if (!name || !name.trim()) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name.trim().substring(0, MAX_DISPLAY_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns participant by ID from Redux state.
|
|
|
|
*
|
2017-10-13 19:31:05 +00:00
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
2017-05-31 05:32:13 +00:00
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @param {string} id - The ID of the participant to retrieve.
|
|
|
|
* @private
|
|
|
|
* @returns {(Participant|undefined)}
|
|
|
|
*/
|
2019-01-25 10:17:58 +00:00
|
|
|
export function getParticipantById(
|
|
|
|
stateful: Object | Function, id: string): ?Object {
|
2017-10-13 19:31:05 +00:00
|
|
|
const participants = _getAllParticipants(stateful);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
return participants.find(p => p.id === id);
|
|
|
|
}
|
|
|
|
|
2017-06-27 22:56:55 +00:00
|
|
|
/**
|
|
|
|
* Returns a count of the known participants in the passed in redux state,
|
|
|
|
* excluding any fake participants.
|
|
|
|
*
|
2017-10-13 19:31:05 +00:00
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
2017-06-27 22:56:55 +00:00
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2017-06-27 22:56:55 +00:00
|
|
|
* @returns {number}
|
|
|
|
*/
|
2017-10-13 19:31:05 +00:00
|
|
|
export function getParticipantCount(stateful: Object | Function) {
|
|
|
|
return getParticipants(stateful).length;
|
2017-08-30 23:17:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 20:22:25 +00:00
|
|
|
/**
|
|
|
|
* Returns a count of the known participants in the passed in redux state,
|
|
|
|
* including fake participants.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
export function getParticipantCountWithFake(stateful: Object | Function) {
|
|
|
|
return _getAllParticipants(stateful).length;
|
|
|
|
}
|
|
|
|
|
2017-12-12 15:30:23 +00:00
|
|
|
/**
|
|
|
|
* Returns participant's display name.
|
2018-11-08 12:25:02 +00:00
|
|
|
*
|
|
|
|
* FIXME: Remove the hardcoded strings once interfaceConfig is stored in redux
|
|
|
|
* and merge with a similarly named method in {@code conference.js}.
|
2017-12-12 15:30:23 +00:00
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state.
|
|
|
|
* @param {string} id - The ID of the participant's display name to retrieve.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getParticipantDisplayName(
|
2018-02-13 15:55:18 +00:00
|
|
|
stateful: Object | Function,
|
|
|
|
id: string) {
|
2017-12-12 15:30:23 +00:00
|
|
|
const participant = getParticipantById(stateful, id);
|
|
|
|
|
|
|
|
if (participant) {
|
|
|
|
if (participant.name) {
|
|
|
|
return participant.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (participant.local) {
|
|
|
|
return typeof interfaceConfig === 'object'
|
|
|
|
? interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME
|
|
|
|
: 'me';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return typeof interfaceConfig === 'object'
|
|
|
|
? interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME
|
|
|
|
: 'Fellow Jitster';
|
|
|
|
}
|
2017-06-27 22:56:55 +00:00
|
|
|
|
2018-05-21 20:52:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the presence status of a participant associated with the passed id.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state.
|
|
|
|
* @param {string} id - The id of the participant.
|
|
|
|
* @returns {string} - The presence status.
|
|
|
|
*/
|
|
|
|
export function getParticipantPresenceStatus(
|
|
|
|
stateful: Object | Function, id: string) {
|
|
|
|
if (!id) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
const participantById = getParticipantById(stateful, id);
|
|
|
|
|
|
|
|
if (!participantById) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return participantById.presence;
|
|
|
|
}
|
|
|
|
|
2017-08-30 23:17:55 +00:00
|
|
|
/**
|
|
|
|
* Selectors for getting all known participants with fake participants filtered
|
|
|
|
* out.
|
|
|
|
*
|
2017-10-13 19:31:05 +00:00
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
2017-08-30 23:17:55 +00:00
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2017-08-30 23:17:55 +00:00
|
|
|
* @returns {Participant[]}
|
|
|
|
*/
|
2017-10-13 19:31:05 +00:00
|
|
|
export function getParticipants(stateful: Object | Function) {
|
2018-06-22 18:59:54 +00:00
|
|
|
return _getAllParticipants(stateful).filter(p => !p.isFakeParticipant);
|
2017-06-27 22:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the participant which has its pinned state set to truthy.
|
|
|
|
*
|
2017-10-13 19:31:05 +00:00
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
2017-06-27 22:56:55 +00:00
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2017-06-27 22:56:55 +00:00
|
|
|
* @returns {(Participant|undefined)}
|
|
|
|
*/
|
2017-10-13 19:31:05 +00:00
|
|
|
export function getPinnedParticipant(stateful: Object | Function) {
|
|
|
|
return _getAllParticipants(stateful).find(p => p.pinned);
|
2017-06-27 22:56:55 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns array of participants from Redux state.
|
|
|
|
*
|
2017-10-13 19:31:05 +00:00
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
2017-05-31 05:32:13 +00:00
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
2017-10-13 19:31:05 +00:00
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @private
|
|
|
|
* @returns {Participant[]}
|
|
|
|
*/
|
2017-10-13 19:31:05 +00:00
|
|
|
function _getAllParticipants(stateful) {
|
2017-09-01 21:25:48 +00:00
|
|
|
return (
|
2017-10-13 19:31:05 +00:00
|
|
|
Array.isArray(stateful)
|
|
|
|
? stateful
|
|
|
|
: toState(stateful)['features/base/participants'] || []);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
2018-05-17 15:45:51 +00:00
|
|
|
|
2020-06-12 10:15:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the youtube fake participant.
|
|
|
|
* At the moment it is considered the youtube participant the only fake participant in the list.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object|Participant[])} stateful - The redux state
|
|
|
|
* features/base/participants, the (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state
|
|
|
|
* features/base/participants.
|
|
|
|
* @private
|
|
|
|
* @returns {Participant}
|
|
|
|
*/
|
|
|
|
export function getYoutubeParticipant(stateful: Object | Function) {
|
|
|
|
const participants = _getAllParticipants(stateful);
|
|
|
|
|
|
|
|
return participants.filter(p => p.isFakeParticipant)[0];
|
|
|
|
}
|
|
|
|
|
2019-05-22 10:00:17 +00:00
|
|
|
/**
|
|
|
|
* Returns true if all of the meeting participants are moderators.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful -Object or function that can be resolved
|
|
|
|
* to the Redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function isEveryoneModerator(stateful: Object | Function) {
|
|
|
|
const participants = _getAllParticipants(stateful);
|
|
|
|
|
|
|
|
for (const participant of participants) {
|
|
|
|
if (participant.role !== PARTICIPANT_ROLE.MODERATOR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-16 10:23:01 +00:00
|
|
|
/**
|
2019-08-30 16:39:06 +00:00
|
|
|
* Checks a value and returns true if it's a preloaded icon object.
|
2019-07-16 10:23:01 +00:00
|
|
|
*
|
2019-08-30 16:39:06 +00:00
|
|
|
* @param {?string | ?Object} icon - The icon to check.
|
2019-07-16 10:23:01 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2019-08-30 16:39:06 +00:00
|
|
|
export function isIconUrl(icon: ?string | ?Object) {
|
|
|
|
return Boolean(icon) && typeof icon === 'object';
|
2019-07-16 10:23:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 15:45:51 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the current local participant is a moderator in the
|
|
|
|
* conference.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - Object or function that can be resolved
|
|
|
|
* to the Redux state.
|
2019-05-09 11:30:38 +00:00
|
|
|
* @param {?boolean} ignoreToken - When true we ignore the token check.
|
2018-05-17 15:45:51 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2019-05-09 11:30:38 +00:00
|
|
|
export function isLocalParticipantModerator(
|
|
|
|
stateful: Object | Function,
|
|
|
|
ignoreToken: ?boolean = false) {
|
2018-05-17 15:45:51 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
if (!localParticipant) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-22 22:41:53 +00:00
|
|
|
return (
|
|
|
|
localParticipant.role === PARTICIPANT_ROLE.MODERATOR
|
2019-05-09 11:30:38 +00:00
|
|
|
&& (ignoreToken
|
|
|
|
|| !state['features/base/config'].enableUserRolesBasedOnToken
|
2018-05-22 22:41:53 +00:00
|
|
|
|| !state['features/base/jwt'].isGuest));
|
2018-05-17 15:45:51 +00:00
|
|
|
}
|
2019-01-25 10:17:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the video of the participant should be rendered.
|
2019-08-02 17:22:19 +00:00
|
|
|
* NOTE: This is currently only used on mobile.
|
2019-01-25 10:17:58 +00:00
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - Object or function that can be resolved
|
|
|
|
* to the Redux state.
|
|
|
|
* @param {string} id - The ID of the participant.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2019-08-02 17:22:19 +00:00
|
|
|
export function shouldRenderParticipantVideo(stateful: Object | Function, id: string) {
|
2019-01-25 10:17:58 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const participant = getParticipantById(state, id);
|
|
|
|
|
|
|
|
if (!participant) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:22:19 +00:00
|
|
|
/* First check if we have an unmuted video track. */
|
|
|
|
const videoTrack
|
|
|
|
= getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id);
|
|
|
|
|
|
|
|
if (!shouldRenderVideoTrack(videoTrack, /* waitForVideoStarted */ false)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then check if the participant connection is active. */
|
|
|
|
const connectionStatus = participant.connectionStatus || JitsiParticipantConnectionStatus.ACTIVE;
|
|
|
|
|
|
|
|
if (connectionStatus !== JitsiParticipantConnectionStatus.ACTIVE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then check if audio-only mode is not active. */
|
2019-07-31 12:47:52 +00:00
|
|
|
const audioOnly = state['features/base/audio-only'].enabled;
|
2019-01-25 10:17:58 +00:00
|
|
|
|
2019-08-02 17:22:19 +00:00
|
|
|
if (!audioOnly) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Last, check if the participant is sharing their screen and they are on stage. */
|
|
|
|
const screenShares = state['features/video-layout'].screenShares || [];
|
|
|
|
const largeVideoParticipantId = state['features/large-video'].participantId;
|
|
|
|
const participantIsInLargeVideoWithScreen
|
|
|
|
= participant.id === largeVideoParticipantId && screenShares.includes(participant.id);
|
|
|
|
|
|
|
|
return participantIsInLargeVideoWithScreen;
|
2019-01-25 10:17:58 +00:00
|
|
|
}
|
2019-06-26 14:08:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves the first loadable avatar URL for a participant.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant to resolve avatars for.
|
|
|
|
* @returns {?string}
|
|
|
|
*/
|
|
|
|
async function _getFirstLoadableAvatarUrl(participant) {
|
|
|
|
for (let i = 0; i < AVATAR_CHECKER_FUNCTIONS.length; i++) {
|
|
|
|
const url = AVATAR_CHECKER_FUNCTIONS[i](participant);
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
if (AVATAR_CHECKED_URLS.has(url)) {
|
|
|
|
if (AVATAR_CHECKED_URLS.get(url)) {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const finalUrl = await preloadImage(url);
|
|
|
|
|
|
|
|
AVATAR_CHECKED_URLS.set(finalUrl, true);
|
|
|
|
|
|
|
|
return finalUrl;
|
|
|
|
} catch (e) {
|
|
|
|
AVATAR_CHECKED_URLS.set(url, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|