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

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