2017-11-03 20:14:38 +00:00
|
|
|
// @flow
|
2017-05-24 17:01:46 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
import React, { Component } from 'react';
|
2016-10-31 17:33:32 +00:00
|
|
|
import { ScrollView } from 'react-native';
|
2017-02-16 23:02:40 +00:00
|
|
|
import { connect } from 'react-redux';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-02-06 18:14:05 +00:00
|
|
|
import { Container } from '../../base/react';
|
2017-11-03 20:14:38 +00:00
|
|
|
import {
|
|
|
|
isNarrowAspectRatio,
|
|
|
|
makeAspectRatioAware
|
2018-02-06 18:14:05 +00:00
|
|
|
} from '../../base/responsive-ui';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-02-12 17:42:38 +00:00
|
|
|
import styles from './styles';
|
2018-02-06 18:14:05 +00:00
|
|
|
import Thumbnail from './Thumbnail';
|
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 = {
|
|
|
|
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
2018-02-06 09:40:16 +00:00
|
|
|
* The indicator which determines whether the filmstrip is enabled.
|
2016-12-01 01:52:39 +00:00
|
|
|
*
|
2018-02-06 09:40:16 +00:00
|
|
|
* @private
|
2016-12-01 01:52:39 +00:00
|
|
|
*/
|
2018-02-06 09:40:16 +00:00
|
|
|
_enabled: boolean,
|
2017-03-31 17:54:58 +00:00
|
|
|
|
2018-02-06 09:40:16 +00:00
|
|
|
/**
|
|
|
|
* The participants in the conference.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_participants: Array<any>,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The indicator which determines whether the filmstrip is visible.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_visible: boolean
|
|
|
|
};
|
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.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class Filmstrip extends Component<Props> {
|
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() {
|
2018-02-06 09:40:16 +00:00
|
|
|
if (!this.props._enabled) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-11-07 14:28:08 +00:00
|
|
|
const isNarrowAspectRatio_ = isNarrowAspectRatio(this);
|
2017-10-13 16:13:46 +00:00
|
|
|
const filmstripStyle
|
2017-11-07 14:28:08 +00:00
|
|
|
= isNarrowAspectRatio_
|
|
|
|
? styles.filmstripNarrow
|
|
|
|
: styles.filmstripWide;
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
return (
|
|
|
|
<Container
|
2017-10-13 16:13:46 +00:00
|
|
|
style = { filmstripStyle }
|
2018-02-12 17:42:38 +00:00
|
|
|
visible = { this.props._visible }>
|
2016-10-31 17:33:32 +00:00
|
|
|
<ScrollView
|
2017-11-07 14:28:08 +00:00
|
|
|
horizontal = { isNarrowAspectRatio_ }
|
2016-10-31 17:33:32 +00:00
|
|
|
showsHorizontalScrollIndicator = { false }
|
|
|
|
showsVerticalScrollIndicator = { false }>
|
|
|
|
{
|
2017-10-02 23:08:07 +00:00
|
|
|
/* eslint-disable react/jsx-wrap-multilines */
|
|
|
|
|
2018-02-12 17:42:38 +00:00
|
|
|
this._sort(
|
|
|
|
this.props._participants,
|
|
|
|
isNarrowAspectRatio_)
|
2016-10-31 17:33:32 +00:00
|
|
|
.map(p =>
|
|
|
|
<Thumbnail
|
|
|
|
key = { p.id }
|
|
|
|
participant = { p } />)
|
2017-10-02 23:08:07 +00:00
|
|
|
|
|
|
|
/* eslint-enable react/jsx-wrap-multilines */
|
2016-10-31 17:33:32 +00:00
|
|
|
}
|
|
|
|
</ScrollView>
|
2016-10-05 14:36:59 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
2016-11-04 18:13:26 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* Sorts a specific array of {@code Participant}s in display order.
|
2016-11-04 18:13:26 +00:00
|
|
|
*
|
2017-10-01 06:35:19 +00:00
|
|
|
* @param {Participant[]} participants - The array of {@code Participant}s
|
2016-11-04 18:13:26 +00:00
|
|
|
* to sort in display order.
|
2017-12-14 10:38:27 +00:00
|
|
|
* @param {boolean} isNarrowAspectRatio_ - Indicates if the aspect ratio is
|
|
|
|
* wide or narrow.
|
2016-11-04 18:13:26 +00:00
|
|
|
* @private
|
|
|
|
* @returns {Participant[]} A new array containing the elements of the
|
2017-10-01 06:35:19 +00:00
|
|
|
* specified {@code participants} array sorted in display order.
|
2016-11-04 18:13:26 +00:00
|
|
|
*/
|
2017-12-14 10:38:27 +00:00
|
|
|
_sort(participants, isNarrowAspectRatio_) {
|
2016-11-04 18:13:26 +00:00
|
|
|
// XXX Array.prototype.sort() is not appropriate because (1) it operates
|
|
|
|
// in place and (2) it is not necessarily stable.
|
|
|
|
|
2017-12-14 10:38:27 +00:00
|
|
|
const sortedParticipants = [
|
2016-11-04 18:13:26 +00:00
|
|
|
|
2017-12-14 10:38:27 +00:00
|
|
|
// First put the local participant.
|
|
|
|
...participants.filter(p => p.local),
|
2016-11-04 18:13:26 +00:00
|
|
|
|
2017-12-14 10:38:27 +00:00
|
|
|
// Then the remote participants, which are sorted by join order.
|
|
|
|
...participants.filter(p => !p.local)
|
|
|
|
];
|
2016-11-04 18:13:26 +00:00
|
|
|
|
2017-12-14 10:38:27 +00:00
|
|
|
if (isNarrowAspectRatio_) {
|
|
|
|
// When the narrow aspect ratio is used, we want to have the remote
|
|
|
|
// participants from right to left with the newest added/joined to
|
|
|
|
// the leftmost side. The local participant is the leftmost item.
|
|
|
|
sortedParticipants.reverse();
|
2016-11-04 18:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sortedParticipants;
|
|
|
|
}
|
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
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {{
|
2017-03-31 17:54:58 +00:00
|
|
|
* _participants: Participant[],
|
2017-02-16 23:02:40 +00:00
|
|
|
* _visible: boolean
|
2017-04-01 05:52:40 +00:00
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-01-28 23:34:57 +00:00
|
|
|
function _mapStateToProps(state) {
|
2017-10-13 16:13:46 +00:00
|
|
|
const participants = state['features/base/participants'];
|
2018-02-06 09:40:16 +00:00
|
|
|
const { enabled, visible } = state['features/filmstrip'];
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
2018-02-06 09:40:16 +00:00
|
|
|
/**
|
|
|
|
* The indicator which determines whether the filmstrip is enabled.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
_enabled: enabled,
|
|
|
|
|
2017-01-28 03:36:20 +00:00
|
|
|
/**
|
|
|
|
* The participants in the conference.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {Participant[]}
|
|
|
|
*/
|
2017-10-13 16:13:46 +00:00
|
|
|
_participants: participants,
|
2017-02-16 23:02:40 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-07 14:28:08 +00:00
|
|
|
* The indicator which determines whether the filmstrip is visible. The
|
|
|
|
* mobile/react-native Filmstrip is visible when there are at least 2
|
|
|
|
* participants in the conference (including the local one).
|
2017-02-16 23:02:40 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2018-02-01 15:47:54 +00:00
|
|
|
_visible: visible && participants.length > 1
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-03 20:14:38 +00:00
|
|
|
export default connect(_mapStateToProps)(makeAspectRatioAware(Filmstrip));
|