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.

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