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

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