2017-11-03 20:14:38 +00:00
|
|
|
// @flow
|
2017-05-24 17:01:46 +00:00
|
|
|
|
2021-08-20 23:32:38 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2022-03-01 15:41:45 +00:00
|
|
|
import { FlatList } from 'react-native';
|
2022-05-06 10:18:57 +00:00
|
|
|
import { SafeAreaView, withSafeAreaInsets } from 'react-native-safe-area-context';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2021-08-20 23:32:38 +00:00
|
|
|
import { getLocalParticipant } from '../../../base/participants';
|
2021-03-18 11:45:56 +00:00
|
|
|
import { Platform } from '../../../base/react';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2020-06-02 09:03:17 +00:00
|
|
|
import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
|
2021-12-16 16:55:45 +00:00
|
|
|
import { shouldHideSelfView } from '../../../base/settings/functions.any';
|
2022-03-01 15:41:45 +00:00
|
|
|
import { isToolboxVisible } from '../../../toolbox/functions';
|
2021-08-20 23:32:38 +00:00
|
|
|
import { setVisibleRemoteParticipants } from '../../actions';
|
2022-05-06 10:18:57 +00:00
|
|
|
import {
|
|
|
|
getFilmstripDimensions,
|
|
|
|
isFilmstripVisible,
|
|
|
|
shouldDisplayLocalThumbnailSeparately,
|
|
|
|
shouldRemoteVideosBeVisible
|
|
|
|
} from '../../functions';
|
2018-06-14 09:14:32 +00:00
|
|
|
|
2018-04-26 12:44:23 +00:00
|
|
|
import LocalThumbnail from './LocalThumbnail';
|
2018-02-06 18:14:05 +00:00
|
|
|
import Thumbnail from './Thumbnail';
|
2020-05-20 10:57:03 +00:00
|
|
|
import styles from './styles';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2021-08-06 08:59:17 +00:00
|
|
|
// Immutable reference to avoid re-renders.
|
|
|
|
const NO_REMOTE_VIDEOS = [];
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-02-06 09:40:16 +00:00
|
|
|
* Filmstrip component's property types.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-02-06 09:40:16 +00:00
|
|
|
type Props = {
|
|
|
|
|
2020-06-02 09:03:17 +00:00
|
|
|
/**
|
|
|
|
* Application's aspect ratio.
|
|
|
|
*/
|
|
|
|
_aspectRatio: Symbol,
|
|
|
|
|
2021-08-20 23:32:38 +00:00
|
|
|
_clientWidth: number,
|
|
|
|
|
|
|
|
_clientHeight: number,
|
|
|
|
|
2021-12-07 08:24:00 +00:00
|
|
|
/**
|
|
|
|
* Whether or not to hide the self view.
|
|
|
|
*/
|
|
|
|
_disableSelfView: boolean,
|
|
|
|
|
2022-03-01 15:41:45 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the toolbox is displayed.
|
|
|
|
*/
|
|
|
|
_toolboxVisible: Boolean,
|
|
|
|
|
2021-08-20 23:32:38 +00:00
|
|
|
_localParticipantId: string,
|
|
|
|
|
2018-02-06 09:40:16 +00:00
|
|
|
/**
|
|
|
|
* The participants in the conference.
|
|
|
|
*/
|
|
|
|
_participants: Array<any>,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The indicator which determines whether the filmstrip is visible.
|
|
|
|
*/
|
2021-08-20 23:32:38 +00:00
|
|
|
_visible: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to trigger state changes in Redux.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
2022-05-06 10:18:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Object containing the safe area insets.
|
|
|
|
*/
|
|
|
|
insets: Object,
|
2018-02-06 09:40:16 +00:00
|
|
|
};
|
2016-12-01 01:52:39 +00:00
|
|
|
|
2018-02-06 09:40:16 +00:00
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} which represents the filmstrip on
|
|
|
|
* mobile/React Native.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-02-06 09:40:16 +00:00
|
|
|
*/
|
2021-08-20 23:32:38 +00:00
|
|
|
class Filmstrip extends PureComponent<Props> {
|
2018-05-25 11:14:29 +00:00
|
|
|
/**
|
|
|
|
* Whether the local participant should be rendered separately from the
|
2021-11-04 21:10:43 +00:00
|
|
|
* remote participants ie outside of their {@link ScrollView}.
|
2018-05-25 11:14:29 +00:00
|
|
|
*/
|
|
|
|
_separateLocalThumbnail: boolean;
|
|
|
|
|
2021-08-20 23:32:38 +00:00
|
|
|
/**
|
|
|
|
* The FlatList's viewabilityConfig.
|
|
|
|
*/
|
|
|
|
_viewabilityConfig: Object;
|
|
|
|
|
2018-05-25 11:14:29 +00:00
|
|
|
/**
|
|
|
|
* Constructor of the component.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// XXX Our current design is to have the local participant separate from
|
|
|
|
// the remote participants. Unfortunately, Android's Video
|
|
|
|
// implementation cannot accommodate that because remote participants'
|
|
|
|
// videos appear on top of the local participant's video at times.
|
|
|
|
// That's because Android's Video utilizes EGL and EGL gives us only two
|
|
|
|
// practical layers in which we can place our participants' videos:
|
|
|
|
// layer #0 sits behind the window, creates a hole in the window, and
|
|
|
|
// there we render the LargeVideo; layer #1 is known as media overlay in
|
|
|
|
// EGL terms, renders on top of layer #0, and, consequently, is for the
|
2022-03-01 15:41:45 +00:00
|
|
|
// Filmstrip. With the separate LocalThumbnail, we should have left the
|
2018-05-25 11:14:29 +00:00
|
|
|
// remote participants' Thumbnails in layer #1 and utilized layer #2 for
|
|
|
|
// LocalThumbnail. Unfortunately, layer #2 is not practical (that's why
|
|
|
|
// I said we had two practical layers only) because it renders on top of
|
|
|
|
// everything which in our case means on top of participant-related
|
|
|
|
// indicators such as moderator, audio and video muted, etc. For now we
|
|
|
|
// do not have much of a choice but to continue rendering LocalThumbnail
|
|
|
|
// as any other remote Thumbnail on Android.
|
2022-05-06 10:18:57 +00:00
|
|
|
this._separateLocalThumbnail = shouldDisplayLocalThumbnailSeparately();
|
2021-08-20 23:32:38 +00:00
|
|
|
|
|
|
|
this._viewabilityConfig = {
|
2021-08-31 14:24:14 +00:00
|
|
|
itemVisiblePercentThreshold: 30,
|
|
|
|
minimumViewTime: 500
|
2021-08-20 23:32:38 +00:00
|
|
|
};
|
2021-08-31 14:24:14 +00:00
|
|
|
|
2021-08-20 23:32:38 +00:00
|
|
|
this._keyExtractor = this._keyExtractor.bind(this);
|
|
|
|
this._getItemLayout = this._getItemLayout.bind(this);
|
|
|
|
this._onViewableItemsChanged = this._onViewableItemsChanged.bind(this);
|
|
|
|
this._renderThumbnail = this._renderThumbnail.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_keyExtractor: string => string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a key for a passed item of the list.
|
|
|
|
*
|
|
|
|
* @param {string} item - The user ID.
|
|
|
|
* @returns {string} - The user ID.
|
|
|
|
*/
|
|
|
|
_keyExtractor(item) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the width and height of the filmstrip based on the screen size and aspect ratio.
|
|
|
|
*
|
|
|
|
* @returns {Object} - The width and the height.
|
|
|
|
*/
|
|
|
|
_getDimensions() {
|
2022-05-06 10:18:57 +00:00
|
|
|
const {
|
|
|
|
_aspectRatio,
|
|
|
|
_clientWidth,
|
|
|
|
_clientHeight,
|
|
|
|
_disableSelfView,
|
|
|
|
_localParticipantId,
|
|
|
|
insets
|
|
|
|
} = this.props;
|
|
|
|
const localParticipantVisible = Boolean(_localParticipantId) && !_disableSelfView;
|
|
|
|
|
|
|
|
return getFilmstripDimensions({
|
|
|
|
aspectRatio: _aspectRatio,
|
|
|
|
clientHeight: _clientHeight,
|
|
|
|
clientWidth: _clientWidth,
|
|
|
|
insets,
|
|
|
|
localParticipantVisible
|
|
|
|
});
|
2021-08-20 23:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_getItemLayout: (?Array<string>, number) => {length: number, offset: number, index: number};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optimization for FlatList. Returns the length, offset and index for an item.
|
|
|
|
*
|
|
|
|
* @param {Array<string>} data - The data array with user IDs.
|
|
|
|
* @param {number} index - The index number of the item.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
_getItemLayout(data, index) {
|
|
|
|
const { _aspectRatio } = this.props;
|
|
|
|
const isNarrowAspectRatio = _aspectRatio === ASPECT_RATIO_NARROW;
|
|
|
|
const length = isNarrowAspectRatio ? styles.thumbnail.width : styles.thumbnail.height;
|
|
|
|
|
|
|
|
return {
|
|
|
|
length,
|
|
|
|
offset: length * index,
|
|
|
|
index
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_onViewableItemsChanged: Object => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A handler for visible items changes.
|
|
|
|
*
|
|
|
|
* @param {Object} data - The visible items data.
|
|
|
|
* @param {Array<Object>} data.viewableItems - The visible items array.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onViewableItemsChanged({ viewableItems = [] }) {
|
2021-12-10 13:16:02 +00:00
|
|
|
const { _disableSelfView } = this.props;
|
|
|
|
|
|
|
|
if (!this._separateLocalThumbnail && !_disableSelfView && viewableItems[0]?.index === 0) {
|
2021-08-31 14:40:55 +00:00
|
|
|
// Skip the local thumbnail.
|
|
|
|
viewableItems.shift();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewableItems.length === 0) {
|
|
|
|
// User might be fast-scrolling, it will stabilize.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let startIndex = viewableItems[0].index;
|
|
|
|
let endIndex = viewableItems[viewableItems.length - 1].index;
|
|
|
|
|
2021-12-10 13:16:02 +00:00
|
|
|
if (!this._separateLocalThumbnail && !_disableSelfView) {
|
2021-08-31 14:40:55 +00:00
|
|
|
// We are off by one in the remote participants array.
|
|
|
|
startIndex -= 1;
|
|
|
|
endIndex -= 1;
|
|
|
|
}
|
2021-08-20 23:32:38 +00:00
|
|
|
|
|
|
|
this.props.dispatch(setVisibleRemoteParticipants(startIndex, endIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderThumbnail: Object => Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates React Element to display each participant in a thumbnail.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderThumbnail({ item /* , index , separators */ }) {
|
|
|
|
return (
|
|
|
|
<Thumbnail
|
|
|
|
key = { item }
|
|
|
|
participantID = { item } />)
|
|
|
|
;
|
2018-05-25 11:14:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
2017-05-24 17:01:46 +00:00
|
|
|
* @returns {ReactElement}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
render() {
|
2022-02-25 11:57:07 +00:00
|
|
|
const {
|
|
|
|
_aspectRatio,
|
|
|
|
_disableSelfView,
|
2022-03-01 15:41:45 +00:00
|
|
|
_toolboxVisible,
|
2022-02-25 11:57:07 +00:00
|
|
|
_localParticipantId,
|
|
|
|
_participants,
|
|
|
|
_visible
|
|
|
|
} = this.props;
|
2020-06-02 09:03:17 +00:00
|
|
|
|
2021-03-18 11:36:09 +00:00
|
|
|
if (!_visible) {
|
2018-02-06 09:40:16 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-01 15:41:45 +00:00
|
|
|
const bottomEdge = Platform.OS === 'ios' && !_toolboxVisible;
|
2020-06-02 09:03:17 +00:00
|
|
|
const isNarrowAspectRatio = _aspectRatio === ASPECT_RATIO_NARROW;
|
|
|
|
const filmstripStyle = isNarrowAspectRatio ? styles.filmstripNarrow : styles.filmstripWide;
|
2021-08-20 23:32:38 +00:00
|
|
|
const { height, width } = this._getDimensions();
|
|
|
|
const { height: thumbnailHeight, width: thumbnailWidth, margin } = styles.thumbnail;
|
|
|
|
const initialNumToRender = Math.ceil(isNarrowAspectRatio
|
|
|
|
? width / (thumbnailWidth + (2 * margin))
|
|
|
|
: height / (thumbnailHeight + (2 * margin))
|
|
|
|
);
|
2022-02-22 16:23:26 +00:00
|
|
|
let participants;
|
|
|
|
|
|
|
|
if (this._separateLocalThumbnail || _disableSelfView) {
|
|
|
|
participants = _participants;
|
|
|
|
} else if (isNarrowAspectRatio) {
|
|
|
|
participants = [ ..._participants, _localParticipantId ];
|
|
|
|
} else {
|
|
|
|
participants = [ _localParticipantId, ..._participants ];
|
|
|
|
}
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
return (
|
2022-03-01 15:41:45 +00:00
|
|
|
<SafeAreaView
|
|
|
|
edges = { [ bottomEdge && 'bottom', 'left', 'right' ].filter(Boolean) }
|
|
|
|
style = { filmstripStyle }>
|
2018-04-26 12:44:23 +00:00
|
|
|
{
|
2018-05-25 11:14:29 +00:00
|
|
|
this._separateLocalThumbnail
|
2020-06-02 09:03:17 +00:00
|
|
|
&& !isNarrowAspectRatio
|
2021-12-07 08:24:00 +00:00
|
|
|
&& !_disableSelfView
|
2018-05-25 11:14:29 +00:00
|
|
|
&& <LocalThumbnail />
|
2018-04-26 12:44:23 +00:00
|
|
|
}
|
2021-08-20 23:32:38 +00:00
|
|
|
<FlatList
|
2021-08-27 21:38:03 +00:00
|
|
|
bounces = { false }
|
2021-08-20 23:32:38 +00:00
|
|
|
data = { participants }
|
|
|
|
getItemLayout = { this._getItemLayout }
|
2020-06-02 09:03:17 +00:00
|
|
|
horizontal = { isNarrowAspectRatio }
|
2021-08-20 23:32:38 +00:00
|
|
|
initialNumToRender = { initialNumToRender }
|
|
|
|
key = { isNarrowAspectRatio ? 'narrow' : 'wide' }
|
|
|
|
keyExtractor = { this._keyExtractor }
|
|
|
|
onViewableItemsChanged = { this._onViewableItemsChanged }
|
|
|
|
renderItem = { this._renderThumbnail }
|
2016-10-31 17:33:32 +00:00
|
|
|
showsHorizontalScrollIndicator = { false }
|
2018-04-26 12:44:23 +00:00
|
|
|
showsVerticalScrollIndicator = { false }
|
2021-08-26 23:23:38 +00:00
|
|
|
style = { styles.flatListStageView }
|
2021-08-20 23:32:38 +00:00
|
|
|
viewabilityConfig = { this._viewabilityConfig }
|
|
|
|
windowSize = { 2 } />
|
2018-04-26 12:44:23 +00:00
|
|
|
{
|
2021-12-07 08:24:00 +00:00
|
|
|
this._separateLocalThumbnail
|
|
|
|
&& isNarrowAspectRatio
|
|
|
|
&& !_disableSelfView
|
2018-05-25 11:14:29 +00:00
|
|
|
&& <LocalThumbnail />
|
2018-04-26 12:44:23 +00:00
|
|
|
}
|
2021-03-18 11:45:56 +00:00
|
|
|
</SafeAreaView>
|
2016-10-05 14:36:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-12 17:42:38 +00:00
|
|
|
* Maps (parts of) the redux state to the associated {@code Filmstrip}'s props.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2018-02-12 17:42:38 +00:00
|
|
|
* @param {Object} state - The redux state.
|
2017-01-28 23:34:57 +00:00
|
|
|
* @private
|
2020-06-02 09:03:17 +00:00
|
|
|
* @returns {Props}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-01-28 23:34:57 +00:00
|
|
|
function _mapStateToProps(state) {
|
2021-07-09 12:36:19 +00:00
|
|
|
const { enabled, remoteParticipants } = state['features/filmstrip'];
|
2021-12-16 16:55:45 +00:00
|
|
|
const disableSelfView = shouldHideSelfView(state);
|
2021-08-06 08:59:17 +00:00
|
|
|
const showRemoteVideos = shouldRemoteVideosBeVisible(state);
|
2021-08-20 23:32:38 +00:00
|
|
|
const responsiveUI = state['features/base/responsive-ui'];
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
2022-05-06 10:18:57 +00:00
|
|
|
_aspectRatio: responsiveUI.aspectRatio,
|
2021-08-20 23:32:38 +00:00
|
|
|
_clientHeight: responsiveUI.clientHeight,
|
|
|
|
_clientWidth: responsiveUI.clientWidth,
|
2021-12-07 08:24:00 +00:00
|
|
|
_disableSelfView: disableSelfView,
|
2021-08-20 23:32:38 +00:00
|
|
|
_localParticipantId: getLocalParticipant(state)?.id,
|
2021-08-06 08:59:17 +00:00
|
|
|
_participants: showRemoteVideos ? remoteParticipants : NO_REMOTE_VIDEOS,
|
2022-03-01 15:41:45 +00:00
|
|
|
_toolboxVisible: isToolboxVisible(state),
|
2021-03-18 11:36:09 +00:00
|
|
|
_visible: enabled && isFilmstripVisible(state)
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-06 10:18:57 +00:00
|
|
|
export default withSafeAreaInsets(connect(_mapStateToProps)(Filmstrip));
|