2017-10-13 19:31:05 +00:00
|
|
|
// @flow
|
2017-10-02 23:08:07 +00:00
|
|
|
|
2020-11-09 20:59:13 +00:00
|
|
|
import { JitsiParticipantConnectionStatus } from '../base/lib-jitsi-meet';
|
|
|
|
import { MEDIA_TYPE } from '../base/media';
|
2018-05-22 22:41:53 +00:00
|
|
|
import {
|
2020-11-09 20:59:13 +00:00
|
|
|
getLocalParticipant,
|
|
|
|
getParticipantById,
|
2018-11-27 20:22:25 +00:00
|
|
|
getParticipantCountWithFake,
|
2018-05-22 22:41:53 +00:00
|
|
|
getPinnedParticipant
|
|
|
|
} from '../base/participants';
|
2018-06-14 09:14:32 +00:00
|
|
|
import { toState } from '../base/redux';
|
2020-11-09 20:59:13 +00:00
|
|
|
import {
|
|
|
|
getLocalVideoTrack,
|
|
|
|
getTrackByMediaTypeAndParticipant,
|
|
|
|
isLocalTrackMuted,
|
|
|
|
isRemoteTrackMuted
|
2021-01-07 20:39:21 +00:00
|
|
|
} from '../base/tracks/functions';
|
2021-12-15 13:18:41 +00:00
|
|
|
import { LAYOUTS } from '../video-layout';
|
2017-08-29 15:08:16 +00:00
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
import {
|
|
|
|
ASPECT_RATIO_BREAKPOINT,
|
|
|
|
DISPLAY_AVATAR,
|
|
|
|
DISPLAY_VIDEO,
|
2021-12-15 13:18:41 +00:00
|
|
|
INDICATORS_TOOLTIP_POSITION,
|
2021-03-26 20:23:05 +00:00
|
|
|
SCROLL_SIZE,
|
2021-01-21 20:46:47 +00:00
|
|
|
SQUARE_TILE_ASPECT_RATIO,
|
2021-03-26 20:23:05 +00:00
|
|
|
STAGE_VIEW_THUMBNAIL_HORIZONTAL_BORDER,
|
|
|
|
TILE_ASPECT_RATIO,
|
|
|
|
TILE_HORIZONTAL_MARGIN,
|
|
|
|
TILE_VERTICAL_MARGIN,
|
2021-12-15 13:18:41 +00:00
|
|
|
TILE_VIEW_GRID_HORIZONTAL_MARGIN,
|
|
|
|
TILE_VIEW_GRID_VERTICAL_MARGIN,
|
2021-03-26 20:23:05 +00:00
|
|
|
VERTICAL_FILMSTRIP_MIN_HORIZONTAL_MARGIN
|
2021-01-21 20:46:47 +00:00
|
|
|
} from './constants';
|
2020-01-24 16:28:47 +00:00
|
|
|
|
2021-08-23 23:02:41 +00:00
|
|
|
export * from './functions.any';
|
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
declare var interfaceConfig: Object;
|
2017-08-29 15:08:16 +00:00
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the filmstrip on mobile is visible, false otherwise.
|
|
|
|
*
|
|
|
|
* NOTE: Filmstrip on web behaves differently to mobile, much simpler, but so
|
|
|
|
* function lies here only for the sake of consistency and to avoid flow errors
|
|
|
|
* on import.
|
|
|
|
*
|
|
|
|
* @param {Object | Function} stateful - The Object or Function that can be
|
|
|
|
* resolved to a Redux state object with the toState function.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function isFilmstripVisible(stateful: Object | Function) {
|
|
|
|
return toState(stateful)['features/filmstrip'].visible;
|
|
|
|
}
|
|
|
|
|
2017-08-29 15:08:16 +00:00
|
|
|
/**
|
2017-10-13 19:31:05 +00:00
|
|
|
* Determines whether the remote video thumbnails should be displayed/visible in
|
|
|
|
* the filmstrip.
|
2017-08-29 15:08:16 +00:00
|
|
|
*
|
|
|
|
* @param {Object} state - The full redux state.
|
2017-10-13 19:31:05 +00:00
|
|
|
* @returns {boolean} - If remote video thumbnails should be displayed/visible
|
|
|
|
* in the filmstrip, then {@code true}; otherwise, {@code false}.
|
2017-08-29 15:08:16 +00:00
|
|
|
*/
|
2017-10-02 23:08:07 +00:00
|
|
|
export function shouldRemoteVideosBeVisible(state: Object) {
|
2018-06-26 22:56:22 +00:00
|
|
|
if (state['features/invite'].calleeInfoVisible) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-27 20:22:25 +00:00
|
|
|
// Include fake participants to derive how many thumbnails are dispalyed,
|
|
|
|
// as it is assumed all participants, including fake, will be displayed
|
|
|
|
// in the filmstrip.
|
|
|
|
const participantCount = getParticipantCountWithFake(state);
|
2017-10-13 19:31:05 +00:00
|
|
|
let pinnedParticipant;
|
2021-06-10 11:51:51 +00:00
|
|
|
const { disable1On1Mode } = state['features/base/config'];
|
2021-09-14 07:43:52 +00:00
|
|
|
const { contextMenuOpened } = state['features/base/responsive-ui'];
|
2017-08-29 15:08:16 +00:00
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
return Boolean(
|
2021-09-14 07:43:52 +00:00
|
|
|
contextMenuOpened
|
|
|
|
|| participantCount > 2
|
2017-08-29 15:08:16 +00:00
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
// Always show the filmstrip when there is another participant to
|
2021-01-29 13:34:37 +00:00
|
|
|
// show and the local video is pinned, or the toolbar is displayed.
|
2017-10-13 19:31:05 +00:00
|
|
|
|| (participantCount > 1
|
2021-06-10 11:51:51 +00:00
|
|
|
&& disable1On1Mode !== null
|
2021-01-29 13:34:37 +00:00
|
|
|
&& (state['features/toolbox'].visible
|
2018-05-22 22:41:53 +00:00
|
|
|
|| ((pinnedParticipant = getPinnedParticipant(state))
|
2017-10-13 19:31:05 +00:00
|
|
|
&& pinnedParticipant.local)))
|
2017-08-29 15:08:16 +00:00
|
|
|
|
2021-06-10 11:51:51 +00:00
|
|
|
|| disable1On1Mode);
|
2017-08-29 15:08:16 +00:00
|
|
|
}
|
2020-01-24 16:28:47 +00:00
|
|
|
|
2020-11-09 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Checks whether there is a playable video stream available for the user associated with the passed ID.
|
|
|
|
*
|
|
|
|
* @param {Object | Function} stateful - The Object or Function that can be
|
|
|
|
* resolved to a Redux state object with the toState function.
|
|
|
|
* @param {string} id - The id of the participant.
|
|
|
|
* @returns {boolean} <tt>true</tt> if there is a playable video stream available
|
|
|
|
* or <tt>false</tt> otherwise.
|
|
|
|
*/
|
|
|
|
export function isVideoPlayable(stateful: Object | Function, id: String) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
const participant = id ? getParticipantById(state, id) : getLocalParticipant(state);
|
|
|
|
const isLocal = participant?.local ?? true;
|
|
|
|
const { connectionStatus } = participant || {};
|
|
|
|
const videoTrack
|
|
|
|
= isLocal ? getLocalVideoTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
|
|
|
|
const isAudioOnly = Boolean(state['features/base/audio-only'].enabled);
|
|
|
|
let isPlayable = false;
|
|
|
|
|
2021-01-06 23:50:28 +00:00
|
|
|
if (isLocal) {
|
|
|
|
const isVideoMuted = isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO);
|
|
|
|
|
2020-11-09 20:59:13 +00:00
|
|
|
isPlayable = Boolean(videoTrack) && !isVideoMuted && !isAudioOnly;
|
|
|
|
} else if (!participant?.isFakeParticipant) { // remote participants excluding shared video
|
2021-01-06 23:50:28 +00:00
|
|
|
const isVideoMuted = isRemoteTrackMuted(tracks, MEDIA_TYPE.VIDEO, id);
|
|
|
|
|
2020-11-09 20:59:13 +00:00
|
|
|
isPlayable = Boolean(videoTrack) && !isVideoMuted && !isAudioOnly
|
|
|
|
&& connectionStatus === JitsiParticipantConnectionStatus.ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isPlayable;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
/**
|
|
|
|
* Calculates the size for thumbnails when in horizontal view layout.
|
|
|
|
*
|
|
|
|
* @param {number} clientHeight - The height of the app window.
|
|
|
|
* @returns {{local: {height, width}, remote: {height, width}}}
|
|
|
|
*/
|
|
|
|
export function calculateThumbnailSizeForHorizontalView(clientHeight: number = 0) {
|
|
|
|
const topBottomMargin = 15;
|
|
|
|
const availableHeight = Math.min(clientHeight, (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + topBottomMargin);
|
|
|
|
const height = availableHeight - topBottomMargin;
|
|
|
|
|
|
|
|
return {
|
|
|
|
local: {
|
|
|
|
height,
|
|
|
|
width: Math.floor(interfaceConfig.LOCAL_THUMBNAIL_RATIO * height)
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
height,
|
|
|
|
width: Math.floor(interfaceConfig.REMOTE_THUMBNAIL_RATIO * height)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
/**
|
|
|
|
* Calculates the size for thumbnails when in vertical view layout.
|
|
|
|
*
|
|
|
|
* @param {number} clientWidth - The height of the app window.
|
|
|
|
* @returns {{local: {height, width}, remote: {height, width}}}
|
|
|
|
*/
|
|
|
|
export function calculateThumbnailSizeForVerticalView(clientWidth: number = 0) {
|
|
|
|
const horizontalMargin
|
|
|
|
= VERTICAL_FILMSTRIP_MIN_HORIZONTAL_MARGIN + SCROLL_SIZE
|
|
|
|
+ TILE_HORIZONTAL_MARGIN + STAGE_VIEW_THUMBNAIL_HORIZONTAL_BORDER;
|
|
|
|
const availableWidth = Math.min(
|
|
|
|
Math.max(clientWidth - horizontalMargin, 0),
|
|
|
|
interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120);
|
|
|
|
|
|
|
|
return {
|
|
|
|
local: {
|
|
|
|
height: Math.floor(availableWidth / interfaceConfig.LOCAL_THUMBNAIL_RATIO),
|
|
|
|
width: availableWidth
|
|
|
|
},
|
|
|
|
remote: {
|
|
|
|
height: Math.floor(availableWidth / interfaceConfig.REMOTE_THUMBNAIL_RATIO),
|
|
|
|
width: availableWidth
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
/**
|
|
|
|
* Calculates the size for thumbnails when in tile view layout.
|
|
|
|
*
|
|
|
|
* @param {Object} dimensions - The desired dimensions of the tile view grid.
|
2021-03-26 20:23:05 +00:00
|
|
|
* @returns {{hasScroll, height, width}}
|
2020-01-24 16:28:47 +00:00
|
|
|
*/
|
|
|
|
export function calculateThumbnailSizeForTileView({
|
|
|
|
columns,
|
2021-03-26 20:23:05 +00:00
|
|
|
minVisibleRows,
|
|
|
|
rows,
|
2020-01-24 16:28:47 +00:00
|
|
|
clientWidth,
|
2021-01-26 08:33:31 +00:00
|
|
|
clientHeight,
|
|
|
|
disableResponsiveTiles
|
2020-01-24 16:28:47 +00:00
|
|
|
}: Object) {
|
2021-01-26 08:33:31 +00:00
|
|
|
let aspectRatio = TILE_ASPECT_RATIO;
|
|
|
|
|
|
|
|
if (!disableResponsiveTiles && clientWidth < ASPECT_RATIO_BREAKPOINT) {
|
|
|
|
aspectRatio = SQUARE_TILE_ASPECT_RATIO;
|
|
|
|
}
|
|
|
|
|
2021-12-15 13:18:41 +00:00
|
|
|
const viewWidth = clientWidth - (columns * TILE_HORIZONTAL_MARGIN) - TILE_VIEW_GRID_HORIZONTAL_MARGIN;
|
|
|
|
const viewHeight = clientHeight - (minVisibleRows * TILE_VERTICAL_MARGIN) - TILE_VIEW_GRID_VERTICAL_MARGIN;
|
2020-01-24 16:28:47 +00:00
|
|
|
const initialWidth = viewWidth / columns;
|
2021-03-26 20:23:05 +00:00
|
|
|
const initialHeight = viewHeight / minVisibleRows;
|
2021-01-18 10:17:23 +00:00
|
|
|
const aspectRatioHeight = initialWidth / aspectRatio;
|
2021-03-26 20:23:05 +00:00
|
|
|
const noScrollHeight = (clientHeight / rows) - TILE_VERTICAL_MARGIN;
|
|
|
|
const scrollInitialWidth = (viewWidth - SCROLL_SIZE) / columns;
|
|
|
|
let height = Math.floor(Math.min(aspectRatioHeight, initialHeight));
|
|
|
|
let width = Math.floor(aspectRatio * height);
|
|
|
|
|
|
|
|
if (height > noScrollHeight && width > scrollInitialWidth) { // we will have scroll and we need more space for it.
|
|
|
|
const scrollAspectRatioHeight = scrollInitialWidth / aspectRatio;
|
|
|
|
|
|
|
|
// Recalculating width/height to fit the available space when a scroll is displayed.
|
|
|
|
// NOTE: Math.min(scrollAspectRatioHeight, initialHeight) would be enough to recalculate but since the new
|
|
|
|
// height value can theoretically be dramatically smaller and the scroll may not be neccessary anymore we need
|
|
|
|
// to compare it with noScrollHeight( the optimal height to fit all thumbnails without scroll) and get the
|
|
|
|
// bigger one. This way we ensure that we always strech the thumbnails as close as we can to the edges of the
|
|
|
|
// window.
|
|
|
|
height = Math.floor(Math.max(Math.min(scrollAspectRatioHeight, initialHeight), noScrollHeight));
|
|
|
|
width = Math.floor(aspectRatio * height);
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
|
|
|
|
return {
|
2021-10-26 08:46:01 +00:00
|
|
|
height: initialHeight,
|
|
|
|
width: initialWidth
|
2020-01-24 16:28:47 +00:00
|
|
|
};
|
|
|
|
}
|
2020-02-10 15:27:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the width of the visible area (doesn't include the left margin/padding) of the the vertical filmstrip.
|
|
|
|
*
|
|
|
|
* @returns {number} - The width of the vertical filmstrip.
|
|
|
|
*/
|
|
|
|
export function getVerticalFilmstripVisibleAreaWidth() {
|
|
|
|
// Adding 11px for the 2px right margin, 2px borders on the left and right and 5px right padding.
|
|
|
|
// Also adding 7px for the scrollbar. Note that we are not counting the left margins and paddings because this
|
|
|
|
// function is used for calculating the available space and they are invisible.
|
|
|
|
// TODO: Check if we can remove the left margins and paddings from the CSS.
|
|
|
|
// FIXME: This function is used to calculate the size of the large video, etherpad or shared video. Once everything
|
|
|
|
// is reactified this calculation will need to move to the corresponding components.
|
|
|
|
const filmstripMaxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 18;
|
|
|
|
|
|
|
|
return Math.min(filmstripMaxWidth, window.innerWidth);
|
|
|
|
}
|
2021-01-21 20:46:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes information that determine the display mode.
|
|
|
|
*
|
2021-12-15 13:18:41 +00:00
|
|
|
* @param {Object} input - Object containing all necessary information for determining the display mode for
|
2021-01-21 20:46:47 +00:00
|
|
|
* the thumbnail.
|
2021-12-15 13:18:41 +00:00
|
|
|
* @returns {number} - One of <tt>DISPLAY_VIDEO</tt> or <tt>DISPLAY_AVATAR</tt>.
|
2021-01-21 20:46:47 +00:00
|
|
|
*/
|
2021-12-15 13:18:41 +00:00
|
|
|
export function computeDisplayModeFromInput(input: Object) {
|
2021-01-21 20:46:47 +00:00
|
|
|
const {
|
|
|
|
isAudioOnly,
|
|
|
|
isCurrentlyOnLargeVideo,
|
|
|
|
isScreenSharing,
|
|
|
|
canPlayEventReceived,
|
|
|
|
isRemoteParticipant,
|
|
|
|
tileViewActive
|
|
|
|
} = input;
|
|
|
|
const adjustedIsVideoPlayable = input.isVideoPlayable && (!isRemoteParticipant || canPlayEventReceived);
|
|
|
|
|
|
|
|
if (!tileViewActive && isScreenSharing && isRemoteParticipant) {
|
2021-12-15 13:18:41 +00:00
|
|
|
return DISPLAY_AVATAR;
|
2021-01-21 20:46:47 +00:00
|
|
|
} else if (isCurrentlyOnLargeVideo && !tileViewActive) {
|
|
|
|
// Display name is always and only displayed when user is on the stage
|
2021-12-15 13:18:41 +00:00
|
|
|
return adjustedIsVideoPlayable && !isAudioOnly ? DISPLAY_VIDEO : DISPLAY_AVATAR;
|
2021-01-21 20:46:47 +00:00
|
|
|
} else if (adjustedIsVideoPlayable && !isAudioOnly) {
|
|
|
|
// check hovering and change state to video with name
|
2021-12-15 13:18:41 +00:00
|
|
|
return DISPLAY_VIDEO;
|
2021-01-21 20:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check hovering and change state to avatar with name
|
2021-12-15 13:18:41 +00:00
|
|
|
return DISPLAY_AVATAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts information for props and state needed to compute the display mode.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The Thumbnail component's props.
|
|
|
|
* @param {Object} state - The Thumbnail component's state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function getDisplayModeInput(props: Object, state: Object) {
|
|
|
|
const {
|
|
|
|
_currentLayout,
|
|
|
|
_isAudioOnly,
|
|
|
|
_isCurrentlyOnLargeVideo,
|
|
|
|
_isScreenSharing,
|
|
|
|
_isVideoPlayable,
|
|
|
|
_participant,
|
|
|
|
_videoTrack
|
|
|
|
} = props;
|
|
|
|
const tileViewActive = _currentLayout === LAYOUTS.TILE_VIEW;
|
|
|
|
const { canPlayEventReceived } = state;
|
|
|
|
|
|
|
|
return {
|
|
|
|
isCurrentlyOnLargeVideo: _isCurrentlyOnLargeVideo,
|
|
|
|
isAudioOnly: _isAudioOnly,
|
|
|
|
tileViewActive,
|
|
|
|
isVideoPlayable: _isVideoPlayable,
|
|
|
|
connectionStatus: _participant?.connectionStatus,
|
|
|
|
canPlayEventReceived,
|
|
|
|
videoStream: Boolean(_videoTrack),
|
|
|
|
isRemoteParticipant: !_participant?.isFakeParticipant && !_participant?.local,
|
|
|
|
isScreenSharing: _isScreenSharing,
|
|
|
|
videoStreamMuted: _videoTrack ? _videoTrack.muted : 'no stream'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the tooltip position for the thumbnail indicators.
|
|
|
|
*
|
|
|
|
* @param {string} currentLayout - The current layout of the app.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getIndicatorsTooltipPosition(currentLayout: string) {
|
|
|
|
return INDICATORS_TOOLTIP_POSITION[currentLayout] || 'top';
|
2021-01-21 20:46:47 +00:00
|
|
|
}
|