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.0KB

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