2022-10-27 07:33:11 +00:00
|
|
|
import { IReduxState, IStore } from '../app/types';
|
|
|
|
import { TILE_VIEW_ENABLED } from '../base/flags/constants';
|
|
|
|
import { getFeatureFlag } from '../base/flags/functions';
|
|
|
|
import { pinParticipant } from '../base/participants/actions';
|
|
|
|
import { getParticipantCount, getPinnedParticipant } from '../base/participants/functions';
|
2022-10-17 20:26:52 +00:00
|
|
|
import { FakeParticipant } from '../base/participants/types';
|
2022-04-21 06:15:34 +00:00
|
|
|
import { isStageFilmstripAvailable } from '../filmstrip/functions';
|
2021-03-03 14:37:38 +00:00
|
|
|
import { isVideoPlaying } from '../shared-video/functions';
|
2022-03-16 14:57:30 +00:00
|
|
|
import { VIDEO_QUALITY_LEVELS } from '../video-quality/constants';
|
2022-08-16 11:56:47 +00:00
|
|
|
import { getReceiverVideoQualityLevel } from '../video-quality/functions';
|
|
|
|
import { getMinHeightForQualityLvlMap } from '../video-quality/selector';
|
2018-08-08 18:48:23 +00:00
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import { LAYOUTS } from './constants';
|
|
|
|
|
2021-06-04 21:11:18 +00:00
|
|
|
/**
|
|
|
|
* A selector for retrieving the current automatic pinning setting.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {string|undefined} The string "remote-only" is returned if only
|
|
|
|
* remote screen sharing should be automatically pinned, any other truthy value
|
|
|
|
* means automatically pin all screen shares. Falsy means do not automatically
|
|
|
|
* pin any screen shares.
|
|
|
|
*/
|
|
|
|
export function getAutoPinSetting() {
|
|
|
|
return typeof interfaceConfig === 'object'
|
|
|
|
? interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE
|
|
|
|
: 'remote-only';
|
|
|
|
}
|
|
|
|
|
2018-08-08 18:48:23 +00:00
|
|
|
/**
|
|
|
|
* Returns the {@code LAYOUTS} constant associated with the layout
|
|
|
|
* the application should currently be in.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
export function getCurrentLayout(state: IReduxState) {
|
2022-09-05 18:40:28 +00:00
|
|
|
if (navigator.product === 'ReactNative') {
|
|
|
|
// FIXME: what should this return?
|
|
|
|
return undefined;
|
|
|
|
} else if (shouldDisplayTileView(state)) {
|
2018-08-08 18:48:23 +00:00
|
|
|
return LAYOUTS.TILE_VIEW;
|
|
|
|
} else if (interfaceConfig.VERTICAL_FILMSTRIP) {
|
2022-04-21 06:15:34 +00:00
|
|
|
if (isStageFilmstripAvailable(state, 2)) {
|
2022-04-12 13:19:10 +00:00
|
|
|
return LAYOUTS.STAGE_FILMSTRIP_VIEW;
|
|
|
|
}
|
|
|
|
|
2018-08-08 18:48:23 +00:00
|
|
|
return LAYOUTS.VERTICAL_FILMSTRIP_VIEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selector for determining if the UI layout should be in tile view. Tile view
|
|
|
|
* is determined by more than just having the tile view setting enabled, as
|
|
|
|
* one-on-one calls should not be in tile view, as well as etherpad editing.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {boolean} True if tile view should be displayed.
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
export function shouldDisplayTileView(state: IReduxState) {
|
|
|
|
const { tileViewEnabled } = state['features/video-layout'] ?? {};
|
2020-07-23 13:12:25 +00:00
|
|
|
|
|
|
|
if (tileViewEnabled !== undefined) {
|
|
|
|
// If the user explicitly requested a view mode, we
|
|
|
|
// do that.
|
|
|
|
return tileViewEnabled;
|
|
|
|
}
|
|
|
|
|
2022-06-13 07:44:16 +00:00
|
|
|
const tileViewEnabledFeatureFlag = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
|
|
|
|
const { disableTileView } = state['features/base/config'];
|
|
|
|
|
|
|
|
if (disableTileView || !tileViewEnabledFeatureFlag) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const participantCount = getParticipantCount(state);
|
2020-11-13 18:11:30 +00:00
|
|
|
const { iAmRecorder } = state['features/base/config'];
|
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
// None tile view mode is easier to calculate (no need for many negations), so we do
|
|
|
|
// that and negate it only once.
|
|
|
|
const shouldDisplayNormalMode = Boolean(
|
|
|
|
|
|
|
|
// Reasons for normal mode:
|
|
|
|
|
|
|
|
// Editing etherpad
|
|
|
|
state['features/etherpad']?.editing
|
|
|
|
|
|
|
|
// We pinned a participant
|
|
|
|
|| getPinnedParticipant(state)
|
|
|
|
|
|
|
|
// It's a 1-on-1 meeting
|
|
|
|
|| participantCount < 3
|
|
|
|
|
|
|
|
// There is a shared YouTube video in the meeting
|
2021-03-03 14:37:38 +00:00
|
|
|
|| isVideoPlaying(state)
|
2020-11-13 18:11:30 +00:00
|
|
|
|
|
|
|
// We want jibri to use stage view by default
|
|
|
|
|| iAmRecorder
|
2018-08-08 18:48:23 +00:00
|
|
|
);
|
2020-07-23 13:12:25 +00:00
|
|
|
|
|
|
|
return !shouldDisplayNormalMode;
|
2018-08-08 18:48:23 +00:00
|
|
|
}
|
2021-06-04 21:11:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private helper to automatically pin the latest screen share stream or unpin
|
|
|
|
* if there are no more screen share streams.
|
|
|
|
*
|
|
|
|
* @param {Array<string>} screenShares - Array containing the list of all the screen sharing endpoints
|
|
|
|
* before the update was triggered (including the ones that have been removed from redux because of the update).
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
export function updateAutoPinnedParticipant(
|
2022-10-27 07:33:11 +00:00
|
|
|
screenShares: Array<string>, { dispatch, getState }: IStore) {
|
2021-06-04 21:11:18 +00:00
|
|
|
const state = getState();
|
|
|
|
const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
|
|
|
|
const pinned = getPinnedParticipant(getState);
|
|
|
|
|
|
|
|
// if the pinned participant is shared video or some other fake participant we want to skip auto-pinning
|
2022-10-17 20:26:52 +00:00
|
|
|
if (pinned?.fakeParticipant && pinned.fakeParticipant !== FakeParticipant.RemoteScreenShare) {
|
2021-06-04 21:11:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unpin the screen share when the screen sharing participant leaves. Switch to tile view if no other
|
|
|
|
// participant was pinned before screen share was auto-pinned, pin the previously pinned participant otherwise.
|
|
|
|
if (!remoteScreenShares?.length) {
|
|
|
|
let participantId = null;
|
|
|
|
|
|
|
|
if (pinned && !screenShares.find(share => share === pinned.id)) {
|
|
|
|
participantId = pinned.id;
|
|
|
|
}
|
|
|
|
dispatch(pinParticipant(participantId));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const latestScreenShareParticipantId = remoteScreenShares[remoteScreenShares.length - 1];
|
|
|
|
|
|
|
|
if (latestScreenShareParticipantId) {
|
|
|
|
dispatch(pinParticipant(latestScreenShareParticipantId));
|
|
|
|
}
|
|
|
|
}
|
2021-07-20 08:37:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Selector for whether we are currently in tile view.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
export function isLayoutTileView(state: IReduxState) {
|
2021-07-20 08:37:52 +00:00
|
|
|
return getCurrentLayout(state) === LAYOUTS.TILE_VIEW;
|
|
|
|
}
|
2022-03-16 14:57:30 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-16 11:56:47 +00:00
|
|
|
* Returns the video quality for the given height.
|
2022-03-16 14:57:30 +00:00
|
|
|
*
|
|
|
|
* @param {number|undefined} height - Height of the video container.
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
function getVideoQualityForHeight(height: number) {
|
|
|
|
if (!height) {
|
|
|
|
return VIDEO_QUALITY_LEVELS.LOW;
|
|
|
|
}
|
|
|
|
const levels = Object.values(VIDEO_QUALITY_LEVELS)
|
|
|
|
.map(Number)
|
|
|
|
.sort((a, b) => a - b);
|
|
|
|
|
|
|
|
for (const level of levels) {
|
|
|
|
if (height <= level) {
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VIDEO_QUALITY_LEVELS.ULTRA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-08-16 11:56:47 +00:00
|
|
|
* Returns the video quality level for the resizable filmstrip thumbnail height.
|
2022-03-16 14:57:30 +00:00
|
|
|
*
|
2022-08-16 11:56:47 +00:00
|
|
|
* @param {number} height - The height of the thumbnail.
|
2022-03-16 14:57:30 +00:00
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
export function getVideoQualityForResizableFilmstripThumbnails(height: number, state: IReduxState) {
|
2022-08-16 11:56:47 +00:00
|
|
|
if (!height) {
|
|
|
|
return VIDEO_QUALITY_LEVELS.LOW;
|
|
|
|
}
|
2022-03-16 14:57:30 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
return getReceiverVideoQualityLevel(height, getMinHeightForQualityLvlMap(state));
|
2022-03-16 14:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-08-16 11:56:47 +00:00
|
|
|
* Returns the video quality level for the screen sharing filmstrip thumbnail height.
|
2022-03-16 14:57:30 +00:00
|
|
|
*
|
2022-08-16 11:56:47 +00:00
|
|
|
* @param {number} height - The height of the thumbnail.
|
|
|
|
* @param {Object} state - Redux state.
|
2022-03-16 14:57:30 +00:00
|
|
|
* @returns {number}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
export function getVideoQualityForScreenSharingFilmstrip(height: number, state: IReduxState) {
|
2022-08-16 11:56:47 +00:00
|
|
|
if (!height) {
|
|
|
|
return VIDEO_QUALITY_LEVELS.LOW;
|
|
|
|
}
|
2022-03-16 14:57:30 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
return getReceiverVideoQualityLevel(height, getMinHeightForQualityLvlMap(state));
|
2022-03-16 14:57:30 +00:00
|
|
|
}
|
2022-03-29 08:45:09 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-16 11:56:47 +00:00
|
|
|
* Returns the video quality for the large video.
|
2022-03-29 08:45:09 +00:00
|
|
|
*
|
2022-08-16 11:56:47 +00:00
|
|
|
* @param {number} largeVideoHeight - The height of the large video.
|
|
|
|
* @returns {number} - The video quality for the large video.
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
export function getVideoQualityForLargeVideo(largeVideoHeight: number) {
|
2022-08-16 11:56:47 +00:00
|
|
|
return getVideoQualityForHeight(largeVideoHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the video quality level for the thumbnails in the stage filmstrip.
|
|
|
|
*
|
|
|
|
* @param {number} height - The height of the thumbnails.
|
2022-03-29 08:45:09 +00:00
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
export function getVideoQualityForStageThumbnails(height: number, state: IReduxState) {
|
2022-08-16 11:56:47 +00:00
|
|
|
if (!height) {
|
|
|
|
return VIDEO_QUALITY_LEVELS.LOW;
|
|
|
|
}
|
2022-03-29 08:45:09 +00:00
|
|
|
|
2022-08-16 11:56:47 +00:00
|
|
|
return getReceiverVideoQualityLevel(height, getMinHeightForQualityLvlMap(state));
|
2022-03-29 08:45:09 +00:00
|
|
|
}
|