2021-03-26 20:23:05 +00:00
|
|
|
import React, { Component } from 'react';
|
2023-02-02 11:12:31 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-03-26 20:23:05 +00:00
|
|
|
import { shouldComponentUpdate } from 'react-window';
|
|
|
|
|
2023-02-02 11:12:31 +00:00
|
|
|
import { IReduxState } from '../../../app/types';
|
|
|
|
import { getLocalParticipant } from '../../../base/participants/functions';
|
2023-01-27 14:30:47 +00:00
|
|
|
import { getHideSelfView } from '../../../base/settings/functions.any';
|
2023-02-02 11:12:31 +00:00
|
|
|
import { LAYOUTS } from '../../../video-layout/constants';
|
|
|
|
import { getCurrentLayout } from '../../../video-layout/functions.web';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { FILMSTRIP_TYPE, TILE_ASPECT_RATIO, TILE_HORIZONTAL_MARGIN } from '../../constants';
|
2023-02-02 11:12:31 +00:00
|
|
|
import { getActiveParticipantsIds, showGridInVerticalView } from '../../functions.web';
|
2021-03-26 20:23:05 +00:00
|
|
|
|
|
|
|
import Thumbnail from './Thumbnail';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link ThumbnailWrapper}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
2021-12-07 08:24:00 +00:00
|
|
|
/**
|
|
|
|
* Whether or not to hide the self view.
|
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
_disableSelfView?: boolean;
|
2021-12-07 08:24:00 +00:00
|
|
|
|
2022-06-29 13:59:49 +00:00
|
|
|
/**
|
|
|
|
* The type of filmstrip this thumbnail is displayed in.
|
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
_filmstripType?: string;
|
2022-06-29 13:59:49 +00:00
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
/**
|
2021-05-19 23:23:40 +00:00
|
|
|
* The horizontal offset in px for the thumbnail. Used to center the thumbnails in the last row in tile view.
|
2021-03-26 20:23:05 +00:00
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
_horizontalOffset?: number;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
2021-12-15 13:18:41 +00:00
|
|
|
/**
|
2023-02-02 11:12:31 +00:00
|
|
|
* Whether or not the thumbnail is a local screen share.
|
2021-12-15 13:18:41 +00:00
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
_isLocalScreenShare?: boolean;
|
2021-12-15 13:18:41 +00:00
|
|
|
|
2022-04-04 18:57:58 +00:00
|
|
|
/**
|
2023-02-02 11:12:31 +00:00
|
|
|
* The ID of the participant associated with the Thumbnail.
|
2022-04-04 18:57:58 +00:00
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
_participantID?: string;
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2022-05-03 21:55:33 +00:00
|
|
|
/**
|
|
|
|
* The width of the thumbnail. Used for expanding the width of the thumbnails on last row in case
|
|
|
|
* there is empty space.
|
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
_thumbnailWidth?: number;
|
2022-05-03 21:55:33 +00:00
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
/**
|
|
|
|
* The index of the column in tile view.
|
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
columnIndex?: number;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The index of the ThumbnailWrapper in stage view.
|
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
index?: number;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The index of the row in tile view.
|
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
rowIndex?: number;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-14 07:10:08 +00:00
|
|
|
* The styles coming from react-window.
|
2021-03-26 20:23:05 +00:00
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
style: Object;
|
2021-03-26 20:23:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper Component for the Thumbnail that translates the react-window specific props
|
|
|
|
* to the Thumbnail Component's props.
|
|
|
|
*/
|
|
|
|
class ThumbnailWrapper extends Component<Props> {
|
2023-02-02 11:12:31 +00:00
|
|
|
shouldComponentUpdate: (p: any, s: any) => boolean;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates new ThumbnailWrapper instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The props of the component.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.shouldComponentUpdate = shouldComponentUpdate.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2022-03-29 08:45:09 +00:00
|
|
|
const {
|
|
|
|
_disableSelfView,
|
2022-06-29 13:59:49 +00:00
|
|
|
_filmstripType = FILMSTRIP_TYPE.MAIN,
|
2022-04-04 18:57:58 +00:00
|
|
|
_isLocalScreenShare = false,
|
2022-03-29 08:45:09 +00:00
|
|
|
_horizontalOffset = 0,
|
|
|
|
_participantID,
|
2022-05-03 21:55:33 +00:00
|
|
|
_thumbnailWidth,
|
2022-03-29 08:45:09 +00:00
|
|
|
style
|
|
|
|
} = this.props;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
|
|
|
if (typeof _participantID !== 'string') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_participantID === 'local') {
|
2021-12-07 08:24:00 +00:00
|
|
|
return _disableSelfView ? null : (
|
2021-03-26 20:23:05 +00:00
|
|
|
<Thumbnail
|
2022-06-29 13:59:49 +00:00
|
|
|
filmstripType = { _filmstripType }
|
2021-03-26 20:23:05 +00:00
|
|
|
horizontalOffset = { _horizontalOffset }
|
|
|
|
key = 'local'
|
2022-05-03 21:55:33 +00:00
|
|
|
style = { style }
|
|
|
|
width = { _thumbnailWidth } />);
|
2021-03-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 18:57:58 +00:00
|
|
|
if (_isLocalScreenShare) {
|
|
|
|
return _disableSelfView ? null : (
|
|
|
|
<Thumbnail
|
2022-06-29 13:59:49 +00:00
|
|
|
filmstripType = { _filmstripType }
|
2022-04-04 18:57:58 +00:00
|
|
|
horizontalOffset = { _horizontalOffset }
|
|
|
|
key = 'localScreenShare'
|
|
|
|
participantID = { _participantID }
|
2022-05-03 21:55:33 +00:00
|
|
|
style = { style }
|
|
|
|
width = { _thumbnailWidth } />);
|
2022-04-04 18:57:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
return (
|
|
|
|
<Thumbnail
|
2022-06-29 13:59:49 +00:00
|
|
|
filmstripType = { _filmstripType }
|
2021-03-26 20:23:05 +00:00
|
|
|
horizontalOffset = { _horizontalOffset }
|
|
|
|
key = { `remote_${_participantID}` }
|
|
|
|
participantID = { _participantID }
|
2022-05-03 21:55:33 +00:00
|
|
|
style = { style }
|
|
|
|
width = { _thumbnailWidth } />);
|
2021-03-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated {@code ThumbnailWrapper}'s props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @param {Object} ownProps - The props passed to the component.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
2023-02-02 11:12:31 +00:00
|
|
|
function _mapStateToProps(state: IReduxState, ownProps: { columnIndex: number;
|
|
|
|
data: { filmstripType: string; }; index?: number; rowIndex: number; }) {
|
2021-03-26 20:23:05 +00:00
|
|
|
const _currentLayout = getCurrentLayout(state);
|
2022-03-29 08:45:09 +00:00
|
|
|
const { remoteParticipants: remote } = state['features/filmstrip'];
|
|
|
|
const activeParticipants = getActiveParticipantsIds(state);
|
2023-01-27 14:30:47 +00:00
|
|
|
const disableSelfView = getHideSelfView(state);
|
2022-02-24 12:20:37 +00:00
|
|
|
const _verticalViewGrid = showGridInVerticalView(state);
|
2022-06-29 13:59:49 +00:00
|
|
|
const filmstripType = ownProps.data?.filmstripType;
|
|
|
|
const stageFilmstrip = filmstripType === FILMSTRIP_TYPE.STAGE;
|
2022-04-12 06:57:01 +00:00
|
|
|
const sortedActiveParticipants = activeParticipants.sort();
|
|
|
|
const remoteParticipants = stageFilmstrip ? sortedActiveParticipants : remote;
|
2022-03-29 08:45:09 +00:00
|
|
|
const remoteParticipantsLength = remoteParticipants.length;
|
2023-02-02 11:12:31 +00:00
|
|
|
const localId = getLocalParticipant(state)?.id;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
2022-03-29 08:45:09 +00:00
|
|
|
if (_currentLayout === LAYOUTS.TILE_VIEW || _verticalViewGrid || stageFilmstrip) {
|
2021-03-26 20:23:05 +00:00
|
|
|
const { columnIndex, rowIndex } = ownProps;
|
2022-03-29 08:45:09 +00:00
|
|
|
const { tileViewDimensions, stageFilmstripDimensions, verticalViewDimensions } = state['features/filmstrip'];
|
|
|
|
const { gridView } = verticalViewDimensions;
|
2023-02-02 11:12:31 +00:00
|
|
|
let gridDimensions = tileViewDimensions?.gridDimensions,
|
|
|
|
thumbnailSize = tileViewDimensions?.thumbnailSize;
|
2022-03-29 08:45:09 +00:00
|
|
|
|
|
|
|
if (stageFilmstrip) {
|
|
|
|
gridDimensions = stageFilmstripDimensions.gridDimensions;
|
|
|
|
thumbnailSize = stageFilmstripDimensions.thumbnailSize;
|
|
|
|
} else if (_verticalViewGrid) {
|
2023-02-02 11:12:31 +00:00
|
|
|
gridDimensions = gridView?.gridDimensions;
|
|
|
|
thumbnailSize = gridView?.thumbnailSize;
|
2022-03-29 08:45:09 +00:00
|
|
|
}
|
2023-02-02 11:12:31 +00:00
|
|
|
const { columns = 1, rows = 1 } = gridDimensions ?? {};
|
2021-03-26 20:23:05 +00:00
|
|
|
const index = (rowIndex * columns) + columnIndex;
|
2022-05-03 21:55:33 +00:00
|
|
|
let horizontalOffset, thumbnailWidth;
|
|
|
|
const { iAmRecorder, disableTileEnlargement } = state['features/base/config'];
|
2022-04-04 18:57:58 +00:00
|
|
|
const { localScreenShare } = state['features/base/participants'];
|
|
|
|
const localParticipantsLength = localScreenShare ? 2 : 1;
|
|
|
|
|
2022-04-05 15:17:25 +00:00
|
|
|
let participantsLength;
|
|
|
|
|
|
|
|
if (stageFilmstrip) {
|
|
|
|
// We use the length of activeParticipants in stage filmstrip which includes local participants.
|
|
|
|
participantsLength = remoteParticipantsLength;
|
2022-11-08 19:15:49 +00:00
|
|
|
} else {
|
2022-04-05 15:17:25 +00:00
|
|
|
// We need to include the local screenshare participant in tile view.
|
2022-04-04 18:57:58 +00:00
|
|
|
participantsLength = remoteParticipantsLength
|
|
|
|
|
|
|
|
// Add local camera and screen share to total participant count when self view is not disabled.
|
|
|
|
+ (disableSelfView ? 0 : localParticipantsLength)
|
|
|
|
|
|
|
|
// Removes iAmRecorder from the total participants count.
|
|
|
|
- (iAmRecorder ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
if (rowIndex === rows - 1) { // center the last row
|
2022-03-29 08:45:09 +00:00
|
|
|
const partialLastRowParticipantsNumber = participantsLength % columns;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
2021-05-19 23:23:40 +00:00
|
|
|
if (partialLastRowParticipantsNumber > 0) {
|
2023-02-02 11:12:31 +00:00
|
|
|
const { width = 1, height = 1 } = thumbnailSize ?? {};
|
2022-05-03 21:55:33 +00:00
|
|
|
const availableWidth = columns * (width + TILE_HORIZONTAL_MARGIN);
|
|
|
|
let widthDifference = 0;
|
|
|
|
let widthToUse = width;
|
|
|
|
|
|
|
|
if (!disableTileEnlargement) {
|
|
|
|
thumbnailWidth = Math.min(
|
|
|
|
(availableWidth / partialLastRowParticipantsNumber) - TILE_HORIZONTAL_MARGIN,
|
|
|
|
height * TILE_ASPECT_RATIO);
|
|
|
|
widthDifference = thumbnailWidth - width;
|
|
|
|
widthToUse = thumbnailWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
horizontalOffset
|
|
|
|
= Math.floor((availableWidth
|
|
|
|
- (partialLastRowParticipantsNumber * (widthToUse + TILE_HORIZONTAL_MARGIN))) / 2
|
|
|
|
)
|
|
|
|
+ (columnIndex * widthDifference);
|
2021-03-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-29 08:45:09 +00:00
|
|
|
if (index > participantsLength - 1) {
|
2021-03-26 20:23:05 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-03-29 08:45:09 +00:00
|
|
|
if (stageFilmstrip) {
|
|
|
|
return {
|
|
|
|
_disableSelfView: disableSelfView,
|
2022-06-29 13:59:49 +00:00
|
|
|
_filmstripType: filmstripType,
|
2022-03-29 08:45:09 +00:00
|
|
|
_participantID: remoteParticipants[index] === localId ? 'local' : remoteParticipants[index],
|
|
|
|
_horizontalOffset: horizontalOffset,
|
2022-05-03 21:55:33 +00:00
|
|
|
_thumbnailWidth: thumbnailWidth
|
2022-03-29 08:45:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-19 21:56:45 +00:00
|
|
|
// When the thumbnails are reordered, local participant is inserted at index 0.
|
2022-10-20 23:01:08 +00:00
|
|
|
const localIndex = disableSelfView ? remoteParticipantsLength : 0;
|
2022-04-04 18:57:58 +00:00
|
|
|
|
|
|
|
// Local screen share is inserted at index 1 after the local camera.
|
2022-10-20 23:01:08 +00:00
|
|
|
const localScreenShareIndex = disableSelfView ? remoteParticipantsLength : 1;
|
2022-11-08 19:15:49 +00:00
|
|
|
const remoteIndex = !iAmRecorder && !disableSelfView
|
|
|
|
? index - localParticipantsLength
|
|
|
|
: index;
|
2021-08-19 21:56:45 +00:00
|
|
|
|
2021-09-17 22:50:57 +00:00
|
|
|
if (!iAmRecorder && index === localIndex) {
|
2021-03-26 20:23:05 +00:00
|
|
|
return {
|
2021-12-07 08:24:00 +00:00
|
|
|
_disableSelfView: disableSelfView,
|
2022-06-29 13:59:49 +00:00
|
|
|
_filmstripType: filmstripType,
|
2021-03-26 20:23:05 +00:00
|
|
|
_participantID: 'local',
|
2022-05-03 21:55:33 +00:00
|
|
|
_horizontalOffset: horizontalOffset,
|
|
|
|
_thumbnailWidth: thumbnailWidth
|
2021-03-26 20:23:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
if (!iAmRecorder && localScreenShare && index === localScreenShareIndex) {
|
2022-04-04 18:57:58 +00:00
|
|
|
return {
|
|
|
|
_disableSelfView: disableSelfView,
|
2022-06-29 13:59:49 +00:00
|
|
|
_filmstripType: filmstripType,
|
2022-04-04 18:57:58 +00:00
|
|
|
_isLocalScreenShare: true,
|
|
|
|
_participantID: localScreenShare?.id,
|
2022-05-03 21:55:33 +00:00
|
|
|
_horizontalOffset: horizontalOffset,
|
|
|
|
_thumbnailWidth: thumbnailWidth
|
2022-04-04 18:57:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
return {
|
2022-06-29 13:59:49 +00:00
|
|
|
_filmstripType: filmstripType,
|
2021-08-19 21:56:45 +00:00
|
|
|
_participantID: remoteParticipants[remoteIndex],
|
2022-05-03 21:55:33 +00:00
|
|
|
_horizontalOffset: horizontalOffset,
|
|
|
|
_thumbnailWidth: thumbnailWidth
|
2021-03-26 20:23:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-29 13:59:49 +00:00
|
|
|
if (_currentLayout === LAYOUTS.STAGE_FILMSTRIP_VIEW && filmstripType === FILMSTRIP_TYPE.SCREENSHARE) {
|
2022-07-29 11:13:02 +00:00
|
|
|
const { screenshareFilmstripParticipantId } = state['features/filmstrip'];
|
|
|
|
const screenshares = state['features/video-layout'].remoteScreenShares;
|
|
|
|
let id = screenshares.find(sId => sId === screenshareFilmstripParticipantId);
|
|
|
|
|
|
|
|
if (!id && screenshares.length) {
|
|
|
|
id = screenshares[screenshares.length - 1];
|
|
|
|
}
|
2022-06-29 13:59:49 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
_filmstripType: filmstripType,
|
2022-07-29 11:13:02 +00:00
|
|
|
_participantID: id
|
2022-06-29 13:59:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
const { index } = ownProps;
|
|
|
|
|
|
|
|
if (typeof index !== 'number' || remoteParticipantsLength <= index) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2022-03-29 08:45:09 +00:00
|
|
|
_participantID: remoteParticipants[index]
|
2021-03-26 20:23:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(ThumbnailWrapper);
|