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 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import {
  5. createShortcutEvent,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import { getToolbarButtons } from '../../../base/config';
  10. import { translate } from '../../../base/i18n';
  11. import { Icon, IconMenuDown, IconMenuUp } from '../../../base/icons';
  12. import { connect } from '../../../base/redux';
  13. import { isButtonEnabled } from '../../../toolbox/functions.web';
  14. import { LAYOUTS, getCurrentLayout } from '../../../video-layout';
  15. import { setFilmstripVisible } from '../../actions';
  16. import { shouldRemoteVideosBeVisible } from '../../functions';
  17. declare var APP: Object;
  18. declare var interfaceConfig: Object;
  19. /**
  20. * The type of the React {@code Component} props of {@link Filmstrip}.
  21. */
  22. type Props = {
  23. /**
  24. * Additional CSS class names top add to the root.
  25. */
  26. _className: string,
  27. /**
  28. * The current layout of the filmstrip.
  29. */
  30. _currentLayout: string,
  31. /**
  32. * The number of columns in tile view.
  33. */
  34. _columns: number,
  35. /**
  36. * The width of the filmstrip.
  37. */
  38. _filmstripWidth: number,
  39. /**
  40. * Whether the filmstrip scrollbar should be hidden or not.
  41. */
  42. _hideScrollbar: boolean,
  43. /**
  44. * Whether the filmstrip toolbar should be hidden or not.
  45. */
  46. _hideToolbar: boolean,
  47. /**
  48. * Whether the filmstrip button is enabled.
  49. */
  50. _isFilmstripButtonEnabled: boolean,
  51. /**
  52. * The number of rows in tile view.
  53. */
  54. _rows: number,
  55. /**
  56. * Additional CSS class names to add to the container of all the thumbnails.
  57. */
  58. _videosClassName: string,
  59. /**
  60. * Whether or not the filmstrip videos should currently be displayed.
  61. */
  62. _visible: boolean,
  63. /**
  64. * The redux {@code dispatch} function.
  65. */
  66. dispatch: Dispatch<any>,
  67. /**
  68. * Invoked to obtain translated strings.
  69. */
  70. t: Function
  71. };
  72. /**
  73. * Implements a React {@link Component} which represents the filmstrip on
  74. * Web/React.
  75. *
  76. * @extends Component
  77. */
  78. class Filmstrip extends Component <Props> {
  79. /**
  80. * Initializes a new {@code Filmstrip} instance.
  81. *
  82. * @param {Object} props - The read-only properties with which the new
  83. * instance is to be initialized.
  84. */
  85. constructor(props: Props) {
  86. super(props);
  87. // Bind event handlers so they are only bound once for every instance.
  88. this._onShortcutToggleFilmstrip = this._onShortcutToggleFilmstrip.bind(this);
  89. this._onToolbarToggleFilmstrip = this._onToolbarToggleFilmstrip.bind(this);
  90. }
  91. /**
  92. * Implements React's {@link Component#componentDidMount}.
  93. *
  94. * @inheritdoc
  95. */
  96. componentDidMount() {
  97. APP.keyboardshortcut.registerShortcut(
  98. 'F',
  99. 'filmstripPopover',
  100. this._onShortcutToggleFilmstrip,
  101. 'keyboardShortcuts.toggleFilmstrip'
  102. );
  103. }
  104. /**
  105. * Implements React's {@link Component#componentDidUpdate}.
  106. *
  107. * @inheritdoc
  108. */
  109. componentWillUnmount() {
  110. APP.keyboardshortcut.unregisterShortcut('F');
  111. }
  112. /**
  113. * Implements React's {@link Component#render()}.
  114. *
  115. * @inheritdoc
  116. * @returns {ReactElement}
  117. */
  118. render() {
  119. // Note: Appending of {@code RemoteVideo} views is handled through
  120. // VideoLayout. The views do not get blown away on render() because
  121. // ReactDOMComponent is only aware of the given JSX and not new appended
  122. // DOM. As such, when updateDOMProperties gets called, only attributes
  123. // will get updated without replacing the DOM. If the known DOM gets
  124. // modified, then the views will get blown away.
  125. const filmstripStyle = { };
  126. const filmstripRemoteVideosContainerStyle = {};
  127. let remoteVideoContainerClassName = 'remote-videos-container';
  128. switch (this.props._currentLayout) {
  129. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  130. // Adding 18px for the 2px margins, 2px borders on the left and right and 5px padding on the left and right.
  131. // Also adding 7px for the scrollbar.
  132. filmstripStyle.maxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 25;
  133. break;
  134. case LAYOUTS.TILE_VIEW: {
  135. // The size of the side margins for each tile as set in CSS.
  136. const { _columns, _rows, _filmstripWidth } = this.props;
  137. if (_rows > _columns) {
  138. remoteVideoContainerClassName += ' has-overflow';
  139. }
  140. filmstripRemoteVideosContainerStyle.width = _filmstripWidth;
  141. break;
  142. }
  143. }
  144. let remoteVideosWrapperClassName = 'filmstrip__videos';
  145. if (this.props._hideScrollbar) {
  146. remoteVideosWrapperClassName += ' hide-scrollbar';
  147. }
  148. let toolbar = null;
  149. if (!this.props._hideToolbar && this.props._isFilmstripButtonEnabled) {
  150. toolbar = this._renderToggleButton();
  151. }
  152. return (
  153. <div
  154. className = { `filmstrip ${this.props._className}` }
  155. style = { filmstripStyle }>
  156. { toolbar }
  157. <div
  158. className = { this.props._videosClassName }
  159. id = 'remoteVideos'>
  160. <div
  161. className = 'filmstrip__videos'
  162. id = 'filmstripLocalVideo'>
  163. <div id = 'filmstripLocalVideoThumbnail' />
  164. </div>
  165. <div
  166. className = { remoteVideosWrapperClassName }
  167. id = 'filmstripRemoteVideos'>
  168. {/*
  169. * XXX This extra video container is needed for
  170. * scrolling thumbnails in Firefox; otherwise, the flex
  171. * thumbnails resize instead of causing overflow.
  172. */}
  173. <div
  174. className = { remoteVideoContainerClassName }
  175. id = 'filmstripRemoteVideosContainer'
  176. style = { filmstripRemoteVideosContainerStyle }>
  177. <div id = 'localVideoTileViewContainer' />
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. );
  183. }
  184. /**
  185. * Dispatches an action to change the visibility of the filmstrip.
  186. *
  187. * @private
  188. * @returns {void}
  189. */
  190. _doToggleFilmstrip() {
  191. this.props.dispatch(setFilmstripVisible(!this.props._visible));
  192. }
  193. _onShortcutToggleFilmstrip: () => void;
  194. /**
  195. * Creates an analytics keyboard shortcut event and dispatches an action for
  196. * toggling filmstrip visibility.
  197. *
  198. * @private
  199. * @returns {void}
  200. */
  201. _onShortcutToggleFilmstrip() {
  202. sendAnalytics(createShortcutEvent(
  203. 'toggle.filmstrip',
  204. {
  205. enable: this.props._visible
  206. }));
  207. this._doToggleFilmstrip();
  208. }
  209. _onToolbarToggleFilmstrip: () => void;
  210. /**
  211. * Creates an analytics toolbar event and dispatches an action for opening
  212. * the speaker stats modal.
  213. *
  214. * @private
  215. * @returns {void}
  216. */
  217. _onToolbarToggleFilmstrip() {
  218. sendAnalytics(createToolbarEvent(
  219. 'toggle.filmstrip.button',
  220. {
  221. enable: this.props._visible
  222. }));
  223. this._doToggleFilmstrip();
  224. }
  225. /**
  226. * Creates a React Element for changing the visibility of the filmstrip when
  227. * clicked.
  228. *
  229. * @private
  230. * @returns {ReactElement}
  231. */
  232. _renderToggleButton() {
  233. const icon = this.props._visible ? IconMenuDown : IconMenuUp;
  234. const { t } = this.props;
  235. return (
  236. <div className = 'filmstrip__toolbar'>
  237. <button
  238. aria-label = { t('toolbar.accessibilityLabel.toggleFilmstrip') }
  239. id = 'toggleFilmstripButton'
  240. onClick = { this._onToolbarToggleFilmstrip }>
  241. <Icon src = { icon } />
  242. </button>
  243. </div>
  244. );
  245. }
  246. }
  247. /**
  248. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  249. *
  250. * @param {Object} state - The Redux state.
  251. * @private
  252. * @returns {Props}
  253. */
  254. function _mapStateToProps(state) {
  255. const { iAmSipGateway } = state['features/base/config'];
  256. const toolbarButtons = getToolbarButtons(state);
  257. const { visible } = state['features/filmstrip'];
  258. const reduceHeight
  259. = state['features/toolbox'].visible && toolbarButtons.length;
  260. const remoteVideosVisible = shouldRemoteVideosBeVisible(state);
  261. const { isOpen: shiftRight } = state['features/chat'];
  262. const className = `${remoteVideosVisible ? '' : 'hide-videos'} ${
  263. reduceHeight ? 'reduce-height' : ''
  264. } ${shiftRight ? 'shift-right' : ''}`.trim();
  265. const videosClassName = `filmstrip__videos${visible ? '' : ' hidden'}`;
  266. const { gridDimensions = {}, filmstripWidth } = state['features/filmstrip'].tileViewDimensions;
  267. return {
  268. _className: className,
  269. _columns: gridDimensions.columns,
  270. _currentLayout: getCurrentLayout(state),
  271. _filmstripWidth: filmstripWidth,
  272. _hideScrollbar: Boolean(iAmSipGateway),
  273. _hideToolbar: Boolean(iAmSipGateway),
  274. _isFilmstripButtonEnabled: isButtonEnabled('filmstrip', state),
  275. _rows: gridDimensions.rows,
  276. _videosClassName: videosClassName,
  277. _visible: visible
  278. };
  279. }
  280. export default translate(connect(_mapStateToProps)(Filmstrip));