Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Filmstrip.js 15KB

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