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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /* @flow */
  2. import _ from 'lodash';
  3. import React, { Component } from 'react';
  4. import type { Dispatch } from 'redux';
  5. import {
  6. createShortcutEvent,
  7. createToolbarEvent,
  8. sendAnalytics
  9. } from '../../../analytics';
  10. import { Icon, IconMenuDown, IconMenuUp } from '../../../base/icons';
  11. import { connect } from '../../../base/redux';
  12. import { dockToolbox } from '../../../toolbox';
  13. import { setFilmstripHovered, setFilmstripVisible } from '../../actions';
  14. import { shouldRemoteVideosBeVisible } from '../../functions';
  15. import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
  16. import Toolbar from './Toolbar';
  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. * Whether the UI/UX is filmstrip-only.
  37. */
  38. _filmstripOnly: boolean,
  39. /**
  40. * The width of the filmstrip.
  41. */
  42. _filmstripWidth: number,
  43. /**
  44. * Whether or not remote videos are currently being hovered over. Hover
  45. * handling is currently being handled detected outside of react.
  46. */
  47. _hovered: boolean,
  48. /**
  49. * The number of rows in tile view.
  50. */
  51. _rows: number,
  52. /**
  53. * Additional CSS class names to add to the container of all the thumbnails.
  54. */
  55. _videosClassName: string,
  56. /**
  57. * Whether or not the filmstrip videos should currently be displayed.
  58. */
  59. _visible: boolean,
  60. /**
  61. * The redux {@code dispatch} function.
  62. */
  63. dispatch: Dispatch<any>
  64. };
  65. /**
  66. * Implements a React {@link Component} which represents the filmstrip on
  67. * Web/React.
  68. *
  69. * @extends Component
  70. */
  71. class Filmstrip extends Component <Props> {
  72. _isHovered: boolean;
  73. _notifyOfHoveredStateUpdate: Function;
  74. _onMouseOut: Function;
  75. _onMouseOver: Function;
  76. /**
  77. * Initializes a new {@code Filmstrip} instance.
  78. *
  79. * @param {Object} props - The read-only properties with which the new
  80. * instance is to be initialized.
  81. */
  82. constructor(props: Props) {
  83. super(props);
  84. // Debounce the method for dispatching the new filmstrip handled state
  85. // so that it does not get called with each mouse movement event. This
  86. // also works around an issue where mouseout and then a mouseover event
  87. // is fired when hovering over remote thumbnails, which are not yet in
  88. // react.
  89. this._notifyOfHoveredStateUpdate = _.debounce(this._notifyOfHoveredStateUpdate, 100);
  90. // Cache the current hovered state for _updateHoveredState to always
  91. // send the last known hovered state.
  92. this._isHovered = false;
  93. // Bind event handlers so they are only bound once for every instance.
  94. this._onMouseOut = this._onMouseOut.bind(this);
  95. this._onMouseOver = this._onMouseOver.bind(this);
  96. this._onShortcutToggleFilmstrip = this._onShortcutToggleFilmstrip.bind(this);
  97. this._onToolbarToggleFilmstrip = this._onToolbarToggleFilmstrip.bind(this);
  98. }
  99. /**
  100. * Implements React's {@link Component#componentDidMount}.
  101. *
  102. * @inheritdoc
  103. */
  104. componentDidMount() {
  105. if (!this.props._filmstripOnly) {
  106. APP.keyboardshortcut.registerShortcut(
  107. 'F',
  108. 'filmstripPopover',
  109. this._onShortcutToggleFilmstrip,
  110. 'keyboardShortcuts.toggleFilmstrip'
  111. );
  112. }
  113. }
  114. /**
  115. * Implements React's {@link Component#componentDidUpdate}.
  116. *
  117. * @inheritdoc
  118. */
  119. componentWillUnmount() {
  120. APP.keyboardshortcut.unregisterShortcut('F');
  121. }
  122. /**
  123. * Implements React's {@link Component#render()}.
  124. *
  125. * @inheritdoc
  126. * @returns {ReactElement}
  127. */
  128. render() {
  129. // Note: Appending of {@code RemoteVideo} views is handled through
  130. // VideoLayout. The views do not get blown away on render() because
  131. // ReactDOMComponent is only aware of the given JSX and not new appended
  132. // DOM. As such, when updateDOMProperties gets called, only attributes
  133. // will get updated without replacing the DOM. If the known DOM gets
  134. // modified, then the views will get blown away.
  135. const remoteVideosStyle = { };
  136. const filmstripRemoteVideosContainerStyle = {};
  137. let remoteVideoContainerClassName = 'remote-videos-container';
  138. switch (this.props._currentLayout) {
  139. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  140. // Adding 8px for the 2px margins and 2px borders on the left and right. Also adding 7px for the scrollbar.
  141. remoteVideosStyle.maxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 15;
  142. break;
  143. case LAYOUTS.TILE_VIEW: {
  144. // The size of the side margins for each tile as set in CSS.
  145. const { _columns, _rows, _filmstripWidth } = this.props;
  146. if (_rows > _columns) {
  147. remoteVideoContainerClassName += ' has-overflow';
  148. }
  149. filmstripRemoteVideosContainerStyle.width = _filmstripWidth;
  150. break;
  151. }
  152. }
  153. return (
  154. <div className = { `filmstrip ${this.props._className}` }>
  155. { this.props._filmstripOnly
  156. ? <Toolbar /> : this._renderToggleButton() }
  157. <div
  158. className = { this.props._videosClassName }
  159. id = 'remoteVideos'
  160. style = { remoteVideosStyle }>
  161. <div
  162. className = 'filmstrip__videos'
  163. id = 'filmstripLocalVideo'
  164. onMouseOut = { this._onMouseOut }
  165. onMouseOver = { this._onMouseOver }>
  166. <div id = 'filmstripLocalVideoThumbnail' />
  167. </div>
  168. <div
  169. className = 'filmstrip__videos'
  170. id = 'filmstripRemoteVideos'>
  171. {/*
  172. * XXX This extra video container is needed for
  173. * scrolling thumbnails in Firefox; otherwise, the flex
  174. * thumbnails resize instead of causing overflow.
  175. */}
  176. <div
  177. className = { remoteVideoContainerClassName }
  178. id = 'filmstripRemoteVideosContainer'
  179. onMouseOut = { this._onMouseOut }
  180. onMouseOver = { this._onMouseOver }
  181. style = { filmstripRemoteVideosContainerStyle }>
  182. <div id = 'localVideoTileViewContainer' />
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. );
  188. }
  189. /**
  190. * Dispatches an action to change the visibility of the filmstrip.
  191. *
  192. * @private
  193. * @returns {void}
  194. */
  195. _doToggleFilmstrip() {
  196. this.props.dispatch(setFilmstripVisible(!this.props._visible));
  197. }
  198. /**
  199. * If the current hover state does not match the known hover state in redux,
  200. * dispatch an action to update the known hover state in redux.
  201. *
  202. * @private
  203. * @returns {void}
  204. */
  205. _notifyOfHoveredStateUpdate() {
  206. if (this.props._hovered !== this._isHovered) {
  207. this.props.dispatch(dockToolbox(this._isHovered));
  208. this.props.dispatch(setFilmstripHovered(this._isHovered));
  209. }
  210. }
  211. /**
  212. * Updates the currently known mouseover state and attempt to dispatch an
  213. * update of the known hover state in redux.
  214. *
  215. * @private
  216. * @returns {void}
  217. */
  218. _onMouseOut() {
  219. this._isHovered = false;
  220. this._notifyOfHoveredStateUpdate();
  221. }
  222. /**
  223. * Updates the currently known mouseover state and attempt to dispatch an
  224. * update of the known hover state in redux.
  225. *
  226. * @private
  227. * @returns {void}
  228. */
  229. _onMouseOver() {
  230. this._isHovered = true;
  231. this._notifyOfHoveredStateUpdate();
  232. }
  233. _onShortcutToggleFilmstrip: () => void;
  234. /**
  235. * Creates an analytics keyboard shortcut event and dispatches an action for
  236. * toggling filmstrip visibility.
  237. *
  238. * @private
  239. * @returns {void}
  240. */
  241. _onShortcutToggleFilmstrip() {
  242. sendAnalytics(createShortcutEvent(
  243. 'toggle.filmstrip',
  244. {
  245. enable: this.props._visible
  246. }));
  247. this._doToggleFilmstrip();
  248. }
  249. _onToolbarToggleFilmstrip: () => void;
  250. /**
  251. * Creates an analytics toolbar event and dispatches an action for opening
  252. * the speaker stats modal.
  253. *
  254. * @private
  255. * @returns {void}
  256. */
  257. _onToolbarToggleFilmstrip() {
  258. sendAnalytics(createToolbarEvent(
  259. 'toggle.filmstrip.button',
  260. {
  261. enable: this.props._visible
  262. }));
  263. this._doToggleFilmstrip();
  264. }
  265. /**
  266. * Creates a React Element for changing the visibility of the filmstrip when
  267. * clicked.
  268. *
  269. * @private
  270. * @returns {ReactElement}
  271. */
  272. _renderToggleButton() {
  273. const icon = this.props._visible ? IconMenuDown : IconMenuUp;
  274. return (
  275. <div className = 'filmstrip__toolbar'>
  276. <button
  277. id = 'toggleFilmstripButton'
  278. onClick = { this._onToolbarToggleFilmstrip }>
  279. <Icon src = { icon } />
  280. </button>
  281. </div>
  282. );
  283. }
  284. }
  285. /**
  286. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  287. *
  288. * @param {Object} state - The Redux state.
  289. * @private
  290. * @returns {{
  291. * _className: string,
  292. * _filmstripOnly: boolean,
  293. * _hovered: boolean,
  294. * _videosClassName: string,
  295. * _visible: boolean
  296. * }}
  297. */
  298. function _mapStateToProps(state) {
  299. const { hovered, visible } = state['features/filmstrip'];
  300. const isFilmstripOnly = Boolean(interfaceConfig.filmStripOnly);
  301. const reduceHeight
  302. = !isFilmstripOnly && state['features/toolbox'].visible && interfaceConfig.TOOLBAR_BUTTONS.length;
  303. const remoteVideosVisible = shouldRemoteVideosBeVisible(state);
  304. const className = `${remoteVideosVisible ? '' : 'hide-videos'} ${reduceHeight ? 'reduce-height' : ''}`.trim();
  305. const videosClassName = `filmstrip__videos${
  306. isFilmstripOnly ? ' filmstrip__videos-filmstripOnly' : ''}${
  307. visible ? '' : ' hidden'}`;
  308. const { gridDimensions = {}, filmstripWidth } = state['features/filmstrip'].tileViewDimensions;
  309. return {
  310. _className: className,
  311. _columns: gridDimensions.columns,
  312. _currentLayout: getCurrentLayout(state),
  313. _filmstripOnly: isFilmstripOnly,
  314. _filmstripWidth: filmstripWidth,
  315. _hovered: hovered,
  316. _rows: gridDimensions.rows,
  317. _videosClassName: videosClassName,
  318. _visible: visible
  319. };
  320. }
  321. export default connect(_mapStateToProps)(Filmstrip);