You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Filmstrip.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { ScrollView } from 'react-native';
  4. import { Container, Platform } from '../../../base/react';
  5. import { connect } from '../../../base/redux';
  6. import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
  7. import { isFilmstripVisible } from '../../functions';
  8. import LocalThumbnail from './LocalThumbnail';
  9. import Thumbnail from './Thumbnail';
  10. import styles from './styles';
  11. /**
  12. * Filmstrip component's property types.
  13. */
  14. type Props = {
  15. /**
  16. * Application's aspect ratio.
  17. */
  18. _aspectRatio: Symbol,
  19. /**
  20. * The indicator which determines whether the filmstrip is enabled.
  21. */
  22. _enabled: boolean,
  23. /**
  24. * The participants in the conference.
  25. */
  26. _participants: Array<any>,
  27. /**
  28. * The indicator which determines whether the filmstrip is visible.
  29. */
  30. _visible: boolean
  31. };
  32. /**
  33. * Implements a React {@link Component} which represents the filmstrip on
  34. * mobile/React Native.
  35. *
  36. * @extends Component
  37. */
  38. class Filmstrip extends Component<Props> {
  39. /**
  40. * Whether the local participant should be rendered separately from the
  41. * remote participants i.e. outside of their {@link ScrollView}.
  42. */
  43. _separateLocalThumbnail: boolean;
  44. /**
  45. * Constructor of the component.
  46. *
  47. * @inheritdoc
  48. */
  49. constructor(props) {
  50. super(props);
  51. // XXX Our current design is to have the local participant separate from
  52. // the remote participants. Unfortunately, Android's Video
  53. // implementation cannot accommodate that because remote participants'
  54. // videos appear on top of the local participant's video at times.
  55. // That's because Android's Video utilizes EGL and EGL gives us only two
  56. // practical layers in which we can place our participants' videos:
  57. // layer #0 sits behind the window, creates a hole in the window, and
  58. // there we render the LargeVideo; layer #1 is known as media overlay in
  59. // EGL terms, renders on top of layer #0, and, consequently, is for the
  60. // Filmstrip. With the separate LocalThumnail, we should have left the
  61. // remote participants' Thumbnails in layer #1 and utilized layer #2 for
  62. // LocalThumbnail. Unfortunately, layer #2 is not practical (that's why
  63. // I said we had two practical layers only) because it renders on top of
  64. // everything which in our case means on top of participant-related
  65. // indicators such as moderator, audio and video muted, etc. For now we
  66. // do not have much of a choice but to continue rendering LocalThumbnail
  67. // as any other remote Thumbnail on Android.
  68. this._separateLocalThumbnail = Platform.OS !== 'android';
  69. }
  70. /**
  71. * Implements React's {@link Component#render()}.
  72. *
  73. * @inheritdoc
  74. * @returns {ReactElement}
  75. */
  76. render() {
  77. const { _aspectRatio, _enabled, _participants, _visible } = this.props;
  78. if (!_enabled) {
  79. return null;
  80. }
  81. const isNarrowAspectRatio = _aspectRatio === ASPECT_RATIO_NARROW;
  82. const filmstripStyle = isNarrowAspectRatio ? styles.filmstripNarrow : styles.filmstripWide;
  83. return (
  84. <Container
  85. style = { filmstripStyle }
  86. visible = { _visible }>
  87. {
  88. this._separateLocalThumbnail
  89. && !isNarrowAspectRatio
  90. && <LocalThumbnail />
  91. }
  92. <ScrollView
  93. horizontal = { isNarrowAspectRatio }
  94. showsHorizontalScrollIndicator = { false }
  95. showsVerticalScrollIndicator = { false }
  96. style = { styles.scrollView } >
  97. {
  98. !this._separateLocalThumbnail && !isNarrowAspectRatio
  99. && <LocalThumbnail />
  100. }
  101. {
  102. this._sort(_participants, isNarrowAspectRatio)
  103. .map(p => (
  104. <Thumbnail
  105. key = { p.id }
  106. participant = { p } />))
  107. }
  108. {
  109. !this._separateLocalThumbnail && isNarrowAspectRatio
  110. && <LocalThumbnail />
  111. }
  112. </ScrollView>
  113. {
  114. this._separateLocalThumbnail && isNarrowAspectRatio
  115. && <LocalThumbnail />
  116. }
  117. </Container>
  118. );
  119. }
  120. /**
  121. * Sorts a specific array of {@code Participant}s in display order.
  122. *
  123. * @param {Participant[]} participants - The array of {@code Participant}s
  124. * to sort in display order.
  125. * @param {boolean} isNarrowAspectRatio - Indicates if the aspect ratio is
  126. * wide or narrow.
  127. * @private
  128. * @returns {Participant[]} A new array containing the elements of the
  129. * specified {@code participants} array sorted in display order.
  130. */
  131. _sort(participants, isNarrowAspectRatio) {
  132. // XXX Array.prototype.sort() is not appropriate because (1) it operates
  133. // in place and (2) it is not necessarily stable.
  134. const sortedParticipants = [
  135. ...participants
  136. ];
  137. if (isNarrowAspectRatio) {
  138. // When the narrow aspect ratio is used, we want to have the remote
  139. // participants from right to left with the newest added/joined to
  140. // the leftmost side. The local participant is the leftmost item.
  141. sortedParticipants.reverse();
  142. }
  143. return sortedParticipants;
  144. }
  145. }
  146. /**
  147. * Maps (parts of) the redux state to the associated {@code Filmstrip}'s props.
  148. *
  149. * @param {Object} state - The redux state.
  150. * @private
  151. * @returns {Props}
  152. */
  153. function _mapStateToProps(state) {
  154. const participants = state['features/base/participants'];
  155. const { enabled } = state['features/filmstrip'];
  156. return {
  157. _aspectRatio: state['features/base/responsive-ui'].aspectRatio,
  158. _enabled: enabled,
  159. _participants: participants.filter(p => !p.local),
  160. _visible: isFilmstripVisible(state)
  161. };
  162. }
  163. export default connect(_mapStateToProps)(Filmstrip);