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