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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 { translate } from '../../../base/i18n';
  11. import { Icon, IconMenuDown, IconMenuUp } from '../../../base/icons';
  12. import { connect } from '../../../base/redux';
  13. import { dockToolbox } from '../../../toolbox/actions.web';
  14. import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
  15. import { setFilmstripHovered, setFilmstripVisible } from '../../actions';
  16. import { shouldRemoteVideosBeVisible } from '../../functions';
  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. * The width of the filmstrip.
  37. */
  38. _filmstripWidth: number,
  39. /**
  40. * Whether the filmstrip scrollbar should be hidden or not.
  41. */
  42. _hideScrollbar: boolean,
  43. /**
  44. * Whether the filmstrip toolbar should be hidden or not.
  45. */
  46. _hideToolbar: 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. * Invoked to obtain translated strings.
  70. */
  71. t: Function
  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. APP.keyboardshortcut.registerShortcut(
  114. 'F',
  115. 'filmstripPopover',
  116. this._onShortcutToggleFilmstrip,
  117. 'keyboardShortcuts.toggleFilmstrip'
  118. );
  119. }
  120. /**
  121. * Implements React's {@link Component#componentDidUpdate}.
  122. *
  123. * @inheritdoc
  124. */
  125. componentWillUnmount() {
  126. APP.keyboardshortcut.unregisterShortcut('F');
  127. }
  128. /**
  129. * Implements React's {@link Component#render()}.
  130. *
  131. * @inheritdoc
  132. * @returns {ReactElement}
  133. */
  134. render() {
  135. // Note: Appending of {@code RemoteVideo} views is handled through
  136. // VideoLayout. The views do not get blown away on render() because
  137. // ReactDOMComponent is only aware of the given JSX and not new appended
  138. // DOM. As such, when updateDOMProperties gets called, only attributes
  139. // will get updated without replacing the DOM. If the known DOM gets
  140. // modified, then the views will get blown away.
  141. const filmstripStyle = { };
  142. const filmstripRemoteVideosContainerStyle = {};
  143. let remoteVideoContainerClassName = 'remote-videos-container';
  144. switch (this.props._currentLayout) {
  145. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  146. // Adding 18px for the 2px margins, 2px borders on the left and right and 5px padding on the left and right.
  147. // Also adding 7px for the scrollbar.
  148. filmstripStyle.maxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 25;
  149. break;
  150. case LAYOUTS.TILE_VIEW: {
  151. // The size of the side margins for each tile as set in CSS.
  152. const { _columns, _rows, _filmstripWidth } = this.props;
  153. if (_rows > _columns) {
  154. remoteVideoContainerClassName += ' has-overflow';
  155. }
  156. filmstripRemoteVideosContainerStyle.width = _filmstripWidth;
  157. break;
  158. }
  159. }
  160. let remoteVideosWrapperClassName = 'filmstrip__videos';
  161. if (this.props._hideScrollbar) {
  162. remoteVideosWrapperClassName += ' hide-scrollbar';
  163. }
  164. let toolbar = null;
  165. if (!this.props._hideToolbar) {
  166. toolbar = this._renderToggleButton();
  167. }
  168. return (
  169. <div
  170. className = { `filmstrip ${this.props._className}` }
  171. style = { filmstripStyle }>
  172. { toolbar }
  173. <div
  174. className = { this.props._videosClassName }
  175. id = 'remoteVideos'>
  176. <div
  177. className = 'filmstrip__videos'
  178. id = 'filmstripLocalVideo'
  179. onMouseOut = { this._onMouseOut }
  180. onMouseOver = { this._onMouseOver }>
  181. <div id = 'filmstripLocalVideoThumbnail' />
  182. </div>
  183. <div
  184. className = { remoteVideosWrapperClassName }
  185. id = 'filmstripRemoteVideos'>
  186. {/*
  187. * XXX This extra video container is needed for
  188. * scrolling thumbnails in Firefox; otherwise, the flex
  189. * thumbnails resize instead of causing overflow.
  190. */}
  191. <div
  192. className = { remoteVideoContainerClassName }
  193. id = 'filmstripRemoteVideosContainer'
  194. onMouseOut = { this._onMouseOut }
  195. onMouseOver = { this._onMouseOver }
  196. style = { filmstripRemoteVideosContainerStyle }>
  197. <div id = 'localVideoTileViewContainer' />
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. );
  203. }
  204. /**
  205. * Dispatches an action to change the visibility of the filmstrip.
  206. *
  207. * @private
  208. * @returns {void}
  209. */
  210. _doToggleFilmstrip() {
  211. this.props.dispatch(setFilmstripVisible(!this.props._visible));
  212. }
  213. /**
  214. * If the current hover state does not match the known hover state in redux,
  215. * dispatch an action to update the known hover state in redux.
  216. *
  217. * @private
  218. * @returns {void}
  219. */
  220. _notifyOfHoveredStateUpdate() {
  221. if (this.props._hovered !== this._isHovered) {
  222. this.props.dispatch(dockToolbox(this._isHovered));
  223. this.props.dispatch(setFilmstripHovered(this._isHovered));
  224. }
  225. }
  226. /**
  227. * Updates the currently known mouseover state and attempt to dispatch an
  228. * update of the known hover state in redux.
  229. *
  230. * @private
  231. * @returns {void}
  232. */
  233. _onMouseOut() {
  234. this._isHovered = false;
  235. this._notifyOfHoveredStateUpdate();
  236. }
  237. /**
  238. * Updates the currently known mouseover state and attempt to dispatch an
  239. * update of the known hover state in redux.
  240. *
  241. * @private
  242. * @returns {void}
  243. */
  244. _onMouseOver() {
  245. this._isHovered = true;
  246. this._notifyOfHoveredStateUpdate();
  247. }
  248. _onShortcutToggleFilmstrip: () => void;
  249. /**
  250. * Creates an analytics keyboard shortcut event and dispatches an action for
  251. * toggling filmstrip visibility.
  252. *
  253. * @private
  254. * @returns {void}
  255. */
  256. _onShortcutToggleFilmstrip() {
  257. sendAnalytics(createShortcutEvent(
  258. 'toggle.filmstrip',
  259. {
  260. enable: this.props._visible
  261. }));
  262. this._doToggleFilmstrip();
  263. }
  264. _onToolbarToggleFilmstrip: () => void;
  265. /**
  266. * Creates an analytics toolbar event and dispatches an action for opening
  267. * the speaker stats modal.
  268. *
  269. * @private
  270. * @returns {void}
  271. */
  272. _onToolbarToggleFilmstrip() {
  273. sendAnalytics(createToolbarEvent(
  274. 'toggle.filmstrip.button',
  275. {
  276. enable: this.props._visible
  277. }));
  278. this._doToggleFilmstrip();
  279. }
  280. /**
  281. * Creates a React Element for changing the visibility of the filmstrip when
  282. * clicked.
  283. *
  284. * @private
  285. * @returns {ReactElement}
  286. */
  287. _renderToggleButton() {
  288. const icon = this.props._visible ? IconMenuDown : IconMenuUp;
  289. const { t } = this.props;
  290. return (
  291. <div className = 'filmstrip__toolbar'>
  292. <button
  293. aria-label = { t('toolbar.accessibilityLabel.toggleFilmstrip') }
  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 reduceHeight
  313. = state['features/toolbox'].visible && interfaceConfig.TOOLBAR_BUTTONS.length;
  314. const remoteVideosVisible = shouldRemoteVideosBeVisible(state);
  315. const { isOpen: shiftRight } = state['features/chat'];
  316. const className = `${remoteVideosVisible ? '' : 'hide-videos'} ${
  317. reduceHeight ? 'reduce-height' : ''
  318. } ${shiftRight ? 'shift-right' : ''}`.trim();
  319. const videosClassName = `filmstrip__videos${visible ? '' : ' hidden'}`;
  320. const { gridDimensions = {}, filmstripWidth } = state['features/filmstrip'].tileViewDimensions;
  321. return {
  322. _className: className,
  323. _columns: gridDimensions.columns,
  324. _currentLayout: getCurrentLayout(state),
  325. _filmstripWidth: filmstripWidth,
  326. _hideScrollbar: Boolean(iAmSipGateway),
  327. _hideToolbar: Boolean(iAmSipGateway),
  328. _hovered: hovered,
  329. _rows: gridDimensions.rows,
  330. _videosClassName: videosClassName,
  331. _visible: visible
  332. };
  333. }
  334. export default translate(connect(_mapStateToProps)(Filmstrip));