Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Filmstrip.js 12KB

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