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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /* @flow */
  2. import React, { PureComponent } from 'react';
  3. import { FixedSizeList, FixedSizeGrid } from 'react-window';
  4. import type { Dispatch } from 'redux';
  5. import {
  6. createShortcutEvent,
  7. createToolbarEvent,
  8. sendAnalytics
  9. } from '../../../analytics';
  10. import { getToolbarButtons } from '../../../base/config';
  11. import { isMobileBrowser } from '../../../base/environment/utils';
  12. import { translate } from '../../../base/i18n';
  13. import { Icon, IconMenuDown, IconMenuUp } from '../../../base/icons';
  14. import { connect } from '../../../base/redux';
  15. import { showToolbox } from '../../../toolbox/actions.web';
  16. import { isButtonEnabled, isToolboxVisible } from '../../../toolbox/functions.web';
  17. import { LAYOUTS, getCurrentLayout } from '../../../video-layout';
  18. import { setFilmstripVisible, setVisibleRemoteParticipants } from '../../actions';
  19. import {
  20. ASPECT_RATIO_BREAKPOINT,
  21. TILE_HORIZONTAL_MARGIN,
  22. TILE_VERTICAL_MARGIN,
  23. TOOLBAR_HEIGHT,
  24. TOOLBAR_HEIGHT_MOBILE
  25. } from '../../constants';
  26. import { shouldRemoteVideosBeVisible } from '../../functions';
  27. import AudioTracksContainer from './AudioTracksContainer';
  28. import Thumbnail from './Thumbnail';
  29. import ThumbnailWrapper from './ThumbnailWrapper';
  30. declare var APP: Object;
  31. declare var interfaceConfig: Object;
  32. /**
  33. * The type of the React {@code Component} props of {@link Filmstrip}.
  34. */
  35. type Props = {
  36. /**
  37. * Additional CSS class names top add to the root.
  38. */
  39. _className: string,
  40. /**
  41. * The current layout of the filmstrip.
  42. */
  43. _currentLayout: string,
  44. /**
  45. * The number of columns in tile view.
  46. */
  47. _columns: number,
  48. /**
  49. * The width of the filmstrip.
  50. */
  51. _filmstripWidth: number,
  52. /**
  53. * The height of the filmstrip.
  54. */
  55. _filmstripHeight: number,
  56. /**
  57. * Whether the filmstrip button is enabled.
  58. */
  59. _isFilmstripButtonEnabled: boolean,
  60. /**
  61. * The participants in the call.
  62. */
  63. _remoteParticipants: Array<Object>,
  64. /**
  65. * The length of the remote participants array.
  66. */
  67. _remoteParticipantsLength: number,
  68. /**
  69. * The number of rows in tile view.
  70. */
  71. _rows: number,
  72. /**
  73. * The height of the thumbnail.
  74. */
  75. _thumbnailHeight: number,
  76. /**
  77. * The width of the thumbnail.
  78. */
  79. _thumbnailWidth: number,
  80. /**
  81. * Additional CSS class names to add to the container of all the thumbnails.
  82. */
  83. _videosClassName: string,
  84. /**
  85. * Whether or not the filmstrip videos should currently be displayed.
  86. */
  87. _visible: boolean,
  88. /**
  89. * Whether or not the toolbox is displayed.
  90. */
  91. _isToolboxVisible: Boolean,
  92. /**
  93. * The redux {@code dispatch} function.
  94. */
  95. dispatch: Dispatch<any>,
  96. /**
  97. * Invoked to obtain translated strings.
  98. */
  99. t: Function
  100. };
  101. /**
  102. * Implements a React {@link Component} which represents the filmstrip on
  103. * Web/React.
  104. *
  105. * @extends Component
  106. */
  107. class Filmstrip extends PureComponent <Props> {
  108. /**
  109. * Initializes a new {@code Filmstrip} instance.
  110. *
  111. * @param {Object} props - The read-only properties with which the new
  112. * instance is to be initialized.
  113. */
  114. constructor(props: Props) {
  115. super(props);
  116. // Bind event handlers so they are only bound once for every instance.
  117. this._onShortcutToggleFilmstrip = this._onShortcutToggleFilmstrip.bind(this);
  118. this._onToolbarToggleFilmstrip = this._onToolbarToggleFilmstrip.bind(this);
  119. this._onTabIn = this._onTabIn.bind(this);
  120. this._gridItemKey = this._gridItemKey.bind(this);
  121. this._listItemKey = this._listItemKey.bind(this);
  122. this._onGridItemsRendered = this._onGridItemsRendered.bind(this);
  123. this._onListItemsRendered = this._onListItemsRendered.bind(this);
  124. }
  125. /**
  126. * Implements React's {@link Component#componentDidMount}.
  127. *
  128. * @inheritdoc
  129. */
  130. componentDidMount() {
  131. APP.keyboardshortcut.registerShortcut(
  132. 'F',
  133. 'filmstripPopover',
  134. this._onShortcutToggleFilmstrip,
  135. 'keyboardShortcuts.toggleFilmstrip'
  136. );
  137. }
  138. /**
  139. * Implements React's {@link Component#componentDidUpdate}.
  140. *
  141. * @inheritdoc
  142. */
  143. componentWillUnmount() {
  144. APP.keyboardshortcut.unregisterShortcut('F');
  145. }
  146. /**
  147. * Implements React's {@link Component#render()}.
  148. *
  149. * @inheritdoc
  150. * @returns {ReactElement}
  151. */
  152. render() {
  153. const filmstripStyle = { };
  154. const { _currentLayout } = this.props;
  155. const tileViewActive = _currentLayout === LAYOUTS.TILE_VIEW;
  156. switch (_currentLayout) {
  157. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  158. // Adding 18px for the 2px margins, 2px borders on the left and right and 5px padding on the left and right.
  159. // Also adding 7px for the scrollbar.
  160. filmstripStyle.maxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 25;
  161. break;
  162. }
  163. let toolbar = null;
  164. if (this.props._isFilmstripButtonEnabled) {
  165. toolbar = this._renderToggleButton();
  166. }
  167. return (
  168. <div
  169. className = { `filmstrip ${this.props._className}` }
  170. style = { filmstripStyle }>
  171. { toolbar }
  172. <div
  173. className = { this.props._videosClassName }
  174. id = 'remoteVideos'>
  175. <div
  176. className = 'filmstrip__videos'
  177. id = 'filmstripLocalVideo'>
  178. <div id = 'filmstripLocalVideoThumbnail'>
  179. {
  180. !tileViewActive && <Thumbnail
  181. key = 'local' />
  182. }
  183. </div>
  184. </div>
  185. {
  186. this._renderRemoteParticipants()
  187. }
  188. </div>
  189. <AudioTracksContainer />
  190. </div>
  191. );
  192. }
  193. _onTabIn: () => void;
  194. /**
  195. * Toggle the toolbar visibility when tabbing into it.
  196. *
  197. * @returns {void}
  198. */
  199. _onTabIn() {
  200. if (!this.props._isToolboxVisible && this.props._visible) {
  201. this.props.dispatch(showToolbox());
  202. }
  203. }
  204. _listItemKey: number => string;
  205. /**
  206. * The key to be used for every ThumbnailWrapper element in stage view.
  207. *
  208. * @param {number} index - The index of the ThumbnailWrapper instance.
  209. * @returns {string} - The key.
  210. */
  211. _listItemKey(index) {
  212. const { _remoteParticipants, _remoteParticipantsLength } = this.props;
  213. if (typeof index !== 'number' || _remoteParticipantsLength <= index) {
  214. return `empty-${index}`;
  215. }
  216. return _remoteParticipants[index];
  217. }
  218. _gridItemKey: Object => string;
  219. /**
  220. * The key to be used for every ThumbnailWrapper element in tile views.
  221. *
  222. * @param {Object} data - An object with the indexes identifying the ThumbnailWrapper instance.
  223. * @returns {string} - The key.
  224. */
  225. _gridItemKey({ columnIndex, rowIndex }) {
  226. const { _columns, _remoteParticipants, _remoteParticipantsLength } = this.props;
  227. const index = (rowIndex * _columns) + columnIndex;
  228. if (index > _remoteParticipantsLength) {
  229. return `empty-${index}`;
  230. }
  231. if (index === 0) {
  232. return 'local';
  233. }
  234. return _remoteParticipants[index - 1];
  235. }
  236. _onListItemsRendered: Object => void;
  237. /**
  238. * Handles items rendered changes in stage view.
  239. *
  240. * @param {Object} data - Information about the rendered items.
  241. * @returns {void}
  242. */
  243. _onListItemsRendered({ visibleStartIndex, visibleStopIndex }) {
  244. const { dispatch } = this.props;
  245. dispatch(setVisibleRemoteParticipants(visibleStartIndex, visibleStopIndex + 1));
  246. }
  247. _onGridItemsRendered: Object => void;
  248. /**
  249. * Handles items rendered changes in tile view.
  250. *
  251. * @param {Object} data - Information about the rendered items.
  252. * @returns {void}
  253. */
  254. _onGridItemsRendered({
  255. visibleColumnStartIndex,
  256. visibleColumnStopIndex,
  257. visibleRowStartIndex,
  258. visibleRowStopIndex
  259. }) {
  260. const { _columns, dispatch } = this.props;
  261. let startIndex = (visibleRowStartIndex * _columns) + visibleColumnStartIndex;
  262. const endIndex = (visibleRowStopIndex * _columns) + visibleColumnStopIndex;
  263. // In tile view, the start index needs to be offset by 1 because the first participant is the local
  264. // participant.
  265. startIndex = startIndex > 0 ? startIndex - 1 : 0;
  266. dispatch(setVisibleRemoteParticipants(startIndex, endIndex));
  267. }
  268. /**
  269. * Renders the thumbnails for remote participants.
  270. *
  271. * @returns {ReactElement}
  272. */
  273. _renderRemoteParticipants() {
  274. const {
  275. _columns,
  276. _currentLayout,
  277. _filmstripHeight,
  278. _filmstripWidth,
  279. _remoteParticipantsLength,
  280. _rows,
  281. _thumbnailHeight,
  282. _thumbnailWidth
  283. } = this.props;
  284. if (!_thumbnailWidth || isNaN(_thumbnailWidth) || !_thumbnailHeight
  285. || isNaN(_thumbnailHeight) || !_filmstripHeight || isNaN(_filmstripHeight) || !_filmstripWidth
  286. || isNaN(_filmstripWidth)) {
  287. return null;
  288. }
  289. if (_currentLayout === LAYOUTS.TILE_VIEW) {
  290. return (
  291. <FixedSizeGrid
  292. className = 'filmstrip__videos remote-videos'
  293. columnCount = { _columns }
  294. columnWidth = { _thumbnailWidth + TILE_HORIZONTAL_MARGIN }
  295. height = { _filmstripHeight }
  296. initialScrollLeft = { 0 }
  297. initialScrollTop = { 0 }
  298. itemKey = { this._gridItemKey }
  299. onItemsRendered = { this._onGridItemsRendered }
  300. overscanRowCount = { 1 }
  301. rowCount = { _rows }
  302. rowHeight = { _thumbnailHeight + TILE_VERTICAL_MARGIN }
  303. width = { _filmstripWidth }>
  304. {
  305. ThumbnailWrapper
  306. }
  307. </FixedSizeGrid>
  308. );
  309. }
  310. const props = {
  311. itemCount: _remoteParticipantsLength,
  312. className: 'filmstrip__videos remote-videos',
  313. height: _filmstripHeight,
  314. itemKey: this._listItemKey,
  315. itemSize: 0,
  316. onItemsRendered: this._onListItemsRendered,
  317. overscanCount: 1,
  318. width: _filmstripWidth,
  319. style: {
  320. willChange: 'auto'
  321. }
  322. };
  323. if (_currentLayout === LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW) {
  324. const itemSize = _thumbnailWidth + TILE_HORIZONTAL_MARGIN;
  325. const isNotOverflowing = (_remoteParticipantsLength * itemSize) <= _filmstripWidth;
  326. props.itemSize = itemSize;
  327. // $FlowFixMe
  328. props.layout = 'horizontal';
  329. if (isNotOverflowing) {
  330. props.className += ' is-not-overflowing';
  331. }
  332. } else if (_currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  333. const itemSize = _thumbnailHeight + TILE_VERTICAL_MARGIN;
  334. const isNotOverflowing = (_remoteParticipantsLength * itemSize) <= _filmstripHeight;
  335. if (isNotOverflowing) {
  336. props.className += ' is-not-overflowing';
  337. }
  338. props.itemSize = itemSize;
  339. }
  340. return (
  341. <FixedSizeList { ...props }>
  342. {
  343. ThumbnailWrapper
  344. }
  345. </FixedSizeList>
  346. );
  347. }
  348. /**
  349. * Dispatches an action to change the visibility of the filmstrip.
  350. *
  351. * @private
  352. * @returns {void}
  353. */
  354. _doToggleFilmstrip() {
  355. this.props.dispatch(setFilmstripVisible(!this.props._visible));
  356. }
  357. _onShortcutToggleFilmstrip: () => void;
  358. /**
  359. * Creates an analytics keyboard shortcut event and dispatches an action for
  360. * toggling filmstrip visibility.
  361. *
  362. * @private
  363. * @returns {void}
  364. */
  365. _onShortcutToggleFilmstrip() {
  366. sendAnalytics(createShortcutEvent(
  367. 'toggle.filmstrip',
  368. {
  369. enable: this.props._visible
  370. }));
  371. this._doToggleFilmstrip();
  372. }
  373. _onToolbarToggleFilmstrip: () => void;
  374. /**
  375. * Creates an analytics toolbar event and dispatches an action for opening
  376. * the speaker stats modal.
  377. *
  378. * @private
  379. * @returns {void}
  380. */
  381. _onToolbarToggleFilmstrip() {
  382. sendAnalytics(createToolbarEvent(
  383. 'toggle.filmstrip.button',
  384. {
  385. enable: this.props._visible
  386. }));
  387. this._doToggleFilmstrip();
  388. }
  389. /**
  390. * Creates a React Element for changing the visibility of the filmstrip when
  391. * clicked.
  392. *
  393. * @private
  394. * @returns {ReactElement}
  395. */
  396. _renderToggleButton() {
  397. const icon = this.props._visible ? IconMenuDown : IconMenuUp;
  398. const { t } = this.props;
  399. return (
  400. <div
  401. className = 'filmstrip__toolbar'>
  402. <button
  403. aria-expanded = { this.props._visible }
  404. aria-label = { t('toolbar.accessibilityLabel.toggleFilmstrip') }
  405. id = 'toggleFilmstripButton'
  406. onClick = { this._onToolbarToggleFilmstrip }
  407. onFocus = { this._onTabIn }
  408. tabIndex = { 0 }>
  409. <Icon
  410. aria-label = { t('toolbar.accessibilityLabel.toggleFilmstrip') }
  411. src = { icon } />
  412. </button>
  413. </div>
  414. );
  415. }
  416. }
  417. /**
  418. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  419. *
  420. * @param {Object} state - The Redux state.
  421. * @private
  422. * @returns {Props}
  423. */
  424. function _mapStateToProps(state) {
  425. const toolbarButtons = getToolbarButtons(state);
  426. const { visible, remoteParticipants } = state['features/filmstrip'];
  427. const reduceHeight = state['features/toolbox'].visible && toolbarButtons.length;
  428. const remoteVideosVisible = shouldRemoteVideosBeVisible(state);
  429. const { isOpen: shiftRight } = state['features/chat'];
  430. const {
  431. gridDimensions = {},
  432. filmstripHeight,
  433. filmstripWidth,
  434. thumbnailSize: tileViewThumbnailSize
  435. } = state['features/filmstrip'].tileViewDimensions;
  436. const _currentLayout = getCurrentLayout(state);
  437. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  438. const availableSpace = clientHeight - filmstripHeight;
  439. let filmstripPadding = 0;
  440. if (availableSpace > 0) {
  441. const paddingValue = TOOLBAR_HEIGHT_MOBILE - availableSpace;
  442. if (paddingValue > 0) {
  443. filmstripPadding = paddingValue;
  444. }
  445. } else {
  446. filmstripPadding = TOOLBAR_HEIGHT_MOBILE;
  447. }
  448. const collapseTileView = reduceHeight
  449. && isMobileBrowser()
  450. && clientWidth <= ASPECT_RATIO_BREAKPOINT;
  451. const className = `${remoteVideosVisible ? '' : 'hide-videos'} ${
  452. reduceHeight ? 'reduce-height' : ''
  453. } ${shiftRight ? 'shift-right' : ''} ${collapseTileView ? 'collapse' : ''}`.trim();
  454. const videosClassName = `filmstrip__videos${visible ? '' : ' hidden'}`;
  455. let _thumbnailSize, remoteFilmstripHeight, remoteFilmstripWidth;
  456. switch (_currentLayout) {
  457. case LAYOUTS.TILE_VIEW:
  458. _thumbnailSize = tileViewThumbnailSize;
  459. remoteFilmstripHeight = filmstripHeight - (collapseTileView && filmstripPadding > 0 ? filmstripPadding : 0);
  460. remoteFilmstripWidth = filmstripWidth;
  461. break;
  462. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW: {
  463. const { remote, remoteVideosContainer } = state['features/filmstrip'].verticalViewDimensions;
  464. _thumbnailSize = remote;
  465. remoteFilmstripHeight = remoteVideosContainer?.height - (reduceHeight ? TOOLBAR_HEIGHT : 0);
  466. remoteFilmstripWidth = remoteVideosContainer?.width;
  467. break;
  468. }
  469. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW: {
  470. const { remote, remoteVideosContainer } = state['features/filmstrip'].horizontalViewDimensions;
  471. _thumbnailSize = remote;
  472. remoteFilmstripHeight = remoteVideosContainer?.height;
  473. remoteFilmstripWidth = remoteVideosContainer?.width;
  474. break;
  475. }
  476. }
  477. return {
  478. _className: className,
  479. _columns: gridDimensions.columns,
  480. _currentLayout,
  481. _filmstripHeight: remoteFilmstripHeight,
  482. _filmstripWidth: remoteFilmstripWidth,
  483. _isFilmstripButtonEnabled: isButtonEnabled('filmstrip', state),
  484. _remoteParticipantsLength: remoteParticipants.length,
  485. _remoteParticipants: remoteParticipants,
  486. _rows: gridDimensions.rows,
  487. _thumbnailWidth: _thumbnailSize?.width,
  488. _thumbnailHeight: _thumbnailSize?.height,
  489. _videosClassName: videosClassName,
  490. _visible: visible,
  491. _isToolboxVisible: isToolboxVisible(state)
  492. };
  493. }
  494. export default translate(connect(_mapStateToProps)(Filmstrip));