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

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