選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Filmstrip.js 9.4KB

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