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.web.js 6.4KB

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