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

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 { 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 invite button rendering should be skipped,
  29. * by default it is. false
  30. */
  31. _hideInviteButton: 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. * 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. /**
  80. * Note: Appending of {@code RemoteVideo} views is handled through
  81. * VideoLayout. The views do not get blown away on render() because
  82. * ReactDOMComponent is only aware of the given JSX and not new appended
  83. * DOM. As such, when updateDOMProperties gets called, only attributes
  84. * will get updated without replacing the DOM. If the known DOM gets
  85. * modified, then the views will get blown away.
  86. */
  87. const filmstripClassNames = `filmstrip ${this.props._remoteVideosVisible
  88. ? '' : 'hide-videos'}`;
  89. return (
  90. <div className = { filmstripClassNames }>
  91. { this.props.filmstripOnly ? <Toolbox /> : null }
  92. <div
  93. className = 'filmstrip__videos'
  94. id = 'remoteVideos'>
  95. <div
  96. className = 'filmstrip__videos'
  97. id = 'filmstripLocalVideo'
  98. onMouseOut = { this._onMouseOut }
  99. onMouseOver = { this._onMouseOver }>
  100. { this.props.filmstripOnly
  101. || this.props._hideInviteButton
  102. ? null : <InviteButton /> }
  103. <div id = 'filmstripLocalVideoThumbnail' />
  104. </div>
  105. <div
  106. className = 'filmstrip__videos'
  107. id = 'filmstripRemoteVideos'>
  108. {/**
  109. * This extra video container is needed for scrolling
  110. * thumbnails in Firefox; otherwise, the flex
  111. * thumbnails resize instead of causing overflow.
  112. */}
  113. <div
  114. className = 'remote-videos-container'
  115. id = 'filmstripRemoteVideosContainer'
  116. onMouseOut = { this._onMouseOut }
  117. onMouseOver = { this._onMouseOver } />
  118. </div>
  119. <audio
  120. id = 'userJoined'
  121. preload = 'auto'
  122. src = 'sounds/joined.wav' />
  123. <audio
  124. id = 'userLeft'
  125. preload = 'auto'
  126. src = 'sounds/left.wav' />
  127. </div>
  128. </div>
  129. );
  130. }
  131. /**
  132. * If the current hover state does not match the known hover state in redux,
  133. * dispatch an action to update the known hover state in redux.
  134. *
  135. * @private
  136. * @returns {void}
  137. */
  138. _notifyOfHoveredStateUpdate() {
  139. if (this.props._hovered !== this._isHovered) {
  140. this.props.dispatch(setFilmstripHovered(this._isHovered));
  141. }
  142. }
  143. /**
  144. * Updates the currently known mouseover state and attempt to dispatch an
  145. * update of the known hover state in redux.
  146. *
  147. * @private
  148. * @returns {void}
  149. */
  150. _onMouseOut() {
  151. this._isHovered = false;
  152. this._notifyOfHoveredStateUpdate();
  153. }
  154. /**
  155. * Updates the currently known mouseover state and attempt to dispatch an
  156. * update of the known hover state in redux.
  157. *
  158. * @private
  159. * @returns {void}
  160. */
  161. _onMouseOver() {
  162. this._isHovered = true;
  163. this._notifyOfHoveredStateUpdate();
  164. }
  165. }
  166. /**
  167. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  168. *
  169. * @param {Object} state - The Redux state.
  170. * @private
  171. * @returns {{
  172. * _hovered: boolean,
  173. * _hideInviteButton: boolean,
  174. * _remoteVideosVisible: boolean
  175. * }}
  176. */
  177. function _mapStateToProps(state) {
  178. return {
  179. _hovered: state['features/filmstrip'].hovered,
  180. _hideInviteButton: state['features/base/config'].iAmRecorder,
  181. _remoteVideosVisible: shouldRemoteVideosBeVisible(state)
  182. };
  183. }
  184. export default connect(_mapStateToProps)(Filmstrip);