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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* @flow */
  2. import _ from 'lodash';
  3. import PropTypes from 'prop-types';
  4. import React, { Component } from 'react';
  5. import { connect } from 'react-redux';
  6. import { dockToolbox } from '../../../toolbox';
  7. import { setFilmstripHovered } from '../../actions';
  8. import { shouldRemoteVideosBeVisible } from '../../functions';
  9. import Toolbar from './Toolbar';
  10. declare var interfaceConfig: Object;
  11. /**
  12. * Implements a React {@link Component} which represents the filmstrip on
  13. * Web/React.
  14. *
  15. * @extends Component
  16. */
  17. class Filmstrip extends Component<*> {
  18. _isHovered: boolean;
  19. _notifyOfHoveredStateUpdate: Function;
  20. _onMouseOut: Function;
  21. _onMouseOver: Function;
  22. /**
  23. * {@code Filmstrip} component's property types.
  24. *
  25. * @static
  26. */
  27. static propTypes = {
  28. /**
  29. * Whether the UI/UX is filmstrip-only.
  30. */
  31. _filmstripOnly: PropTypes.bool,
  32. /**
  33. * Whether or not remote videos are currently being hovered over.
  34. */
  35. _hovered: PropTypes.bool,
  36. /**
  37. * Whether or not the remote videos should be visible. Will toggle
  38. * a class for hiding the videos.
  39. */
  40. _remoteVideosVisible: PropTypes.bool,
  41. /**
  42. * Whether or not the toolbox is visible. The height of the vertical
  43. * filmstrip needs to adjust to accommodate the horizontal toolbox.
  44. */
  45. _toolboxVisible: PropTypes.bool,
  46. /**
  47. * The redux {@code dispatch} function.
  48. */
  49. dispatch: PropTypes.func
  50. };
  51. /**
  52. * Initializes a new {@code Filmstrip} instance.
  53. *
  54. * @param {Object} props - The read-only properties with which the new
  55. * instance is to be initialized.
  56. */
  57. constructor(props) {
  58. super(props);
  59. // Debounce the method for dispatching the new filmstrip handled state
  60. // so that it does not get called with each mouse movement event. This
  61. // also works around an issue where mouseout and then a mouseover event
  62. // is fired when hovering over remote thumbnails, which are not yet in
  63. // react.
  64. this._notifyOfHoveredStateUpdate
  65. = _.debounce(this._notifyOfHoveredStateUpdate, 100);
  66. // Cache the current hovered state for _updateHoveredState to always
  67. // send the last known hovered state.
  68. this._isHovered = false;
  69. // Bind event handlers so they are only bound once for every instance.
  70. this._onMouseOut = this._onMouseOut.bind(this);
  71. this._onMouseOver = this._onMouseOver.bind(this);
  72. }
  73. /**
  74. * Implements React's {@link Component#render()}.
  75. *
  76. * @inheritdoc
  77. * @returns {ReactElement}
  78. */
  79. render() {
  80. const {
  81. _filmstripOnly,
  82. _remoteVideosVisible,
  83. _toolboxVisible
  84. } = this.props;
  85. // Note: Appending of {@code RemoteVideo} views is handled through
  86. // VideoLayout. The views do not get blown away on render() because
  87. // ReactDOMComponent is only aware of the given JSX and not new appended
  88. // DOM. As such, when updateDOMProperties gets called, only attributes
  89. // will get updated without replacing the DOM. If the known DOM gets
  90. // modified, then the views will get blown away.
  91. const reduceHeight
  92. = _toolboxVisible && interfaceConfig.TOOLBAR_BUTTONS.length;
  93. const classNames
  94. = `filmstrip ${
  95. _remoteVideosVisible ? '' : 'hide-videos'} ${
  96. reduceHeight ? 'reduce-height' : ''}`;
  97. return (
  98. <div className = { classNames }>
  99. { _filmstripOnly && <Toolbar /> }
  100. <div
  101. className = 'filmstrip__videos'
  102. id = 'remoteVideos'>
  103. <div
  104. className = 'filmstrip__videos'
  105. id = 'filmstripLocalVideo'
  106. onMouseOut = { this._onMouseOut }
  107. onMouseOver = { this._onMouseOver }>
  108. <div id = 'filmstripLocalVideoThumbnail' />
  109. </div>
  110. <div
  111. className = 'filmstrip__videos'
  112. id = 'filmstripRemoteVideos'>
  113. {/*
  114. * XXX This extra video container is needed for
  115. * scrolling thumbnails in Firefox; otherwise, the flex
  116. * thumbnails resize instead of causing overflow.
  117. */}
  118. <div
  119. className = 'remote-videos-container'
  120. id = 'filmstripRemoteVideosContainer'
  121. onMouseOut = { this._onMouseOut }
  122. onMouseOver = { this._onMouseOver } />
  123. </div>
  124. </div>
  125. </div>
  126. );
  127. }
  128. /**
  129. * If the current hover state does not match the known hover state in redux,
  130. * dispatch an action to update the known hover state in redux.
  131. *
  132. * @private
  133. * @returns {void}
  134. */
  135. _notifyOfHoveredStateUpdate() {
  136. if (this.props._hovered !== this._isHovered) {
  137. this.props.dispatch(dockToolbox(this._isHovered));
  138. this.props.dispatch(setFilmstripHovered(this._isHovered));
  139. }
  140. }
  141. /**
  142. * Updates the currently known mouseover state and attempt to dispatch an
  143. * update of the known hover state in redux.
  144. *
  145. * @private
  146. * @returns {void}
  147. */
  148. _onMouseOut() {
  149. this._isHovered = false;
  150. this._notifyOfHoveredStateUpdate();
  151. }
  152. /**
  153. * Updates the currently known mouseover state and attempt to dispatch an
  154. * update of the known hover state in redux.
  155. *
  156. * @private
  157. * @returns {void}
  158. */
  159. _onMouseOver() {
  160. this._isHovered = true;
  161. this._notifyOfHoveredStateUpdate();
  162. }
  163. }
  164. /**
  165. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  166. *
  167. * @param {Object} state - The Redux state.
  168. * @private
  169. * @returns {{
  170. * _filmstripOnly: boolean,
  171. * _hovered: boolean,
  172. * _remoteVideosVisible: boolean,
  173. * _toolboxVisible: boolean
  174. * }}
  175. */
  176. function _mapStateToProps(state) {
  177. const { hovered } = state['features/filmstrip'];
  178. return {
  179. _filmstripOnly: Boolean(interfaceConfig.filmStripOnly),
  180. _hovered: hovered,
  181. _remoteVideosVisible: shouldRemoteVideosBeVisible(state),
  182. _toolboxVisible: state['features/toolbox'].visible
  183. };
  184. }
  185. export default connect(_mapStateToProps)(Filmstrip);