Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Filmstrip.js 9.4KB

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