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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 { getLocalParticipant, PARTICIPANT_ROLE } from '../../base/participants';
  7. import { InviteButton } from '../../invite';
  8. import { Toolbox } from '../../toolbox';
  9. import { setFilmstripHovered } from '../actions';
  10. import { shouldRemoteVideosBeVisible } from '../functions';
  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 invite button rendering should be skipped,
  30. * by default it is. false
  31. */
  32. _hideInviteButton: PropTypes.bool,
  33. /**
  34. * Whether or not remote videos are currently being hovered over.
  35. */
  36. _hovered: PropTypes.bool,
  37. /**
  38. * Whether or not the feature to directly invite people into the
  39. * conference is available.
  40. */
  41. _isAddToCallAvailable: PropTypes.bool,
  42. /**
  43. * Whether or not the feature to dial out to number to join the
  44. * conference is available.
  45. */
  46. _isDialOutAvailable: PropTypes.bool,
  47. /**
  48. * Whether or not the remote videos should be visible. Will toggle
  49. * a class for hiding the videos.
  50. */
  51. _remoteVideosVisible: PropTypes.bool,
  52. /**
  53. * Updates the redux store with filmstrip hover changes.
  54. */
  55. dispatch: PropTypes.func,
  56. /**
  57. * Whether or not the conference is in filmstripOnly mode.
  58. */
  59. filmstripOnly: PropTypes.bool
  60. };
  61. /**
  62. * Initializes a new {@code Filmstrip} instance.
  63. *
  64. * @param {Object} props - The read-only properties with which the new
  65. * instance is to be initialized.
  66. */
  67. constructor(props) {
  68. super(props);
  69. // Debounce the method for dispatching the new filmstrip handled state
  70. // so that it does not get called with each mouse movement event. This
  71. // also works around an issue where mouseout and then a mouseover event
  72. // is fired when hovering over remote thumbnails, which are not yet in
  73. // react.
  74. this._notifyOfHoveredStateUpdate
  75. = _.debounce(this._notifyOfHoveredStateUpdate, 100);
  76. // Cache the current hovered state for _updateHoveredState to always
  77. // send the last known hovered state.
  78. this._isHovered = false;
  79. // Bind event handlers so they are only bound once for every instance.
  80. this._onMouseOver = this._onMouseOver.bind(this);
  81. this._onMouseOut = this._onMouseOut.bind(this);
  82. }
  83. /**
  84. * Implements React's {@link Component#render()}.
  85. *
  86. * @inheritdoc
  87. * @returns {ReactElement}
  88. */
  89. render() {
  90. const {
  91. _hideInviteButton,
  92. _isAddToCallAvailable,
  93. _isDialOutAvailable,
  94. _remoteVideosVisible,
  95. filmstripOnly
  96. } = this.props;
  97. /**
  98. * Note: Appending of {@code RemoteVideo} views is handled through
  99. * VideoLayout. The views do not get blown away on render() because
  100. * ReactDOMComponent is only aware of the given JSX and not new appended
  101. * DOM. As such, when updateDOMProperties gets called, only attributes
  102. * will get updated without replacing the DOM. If the known DOM gets
  103. * modified, then the views will get blown away.
  104. */
  105. const filmstripClassNames = `filmstrip ${_remoteVideosVisible ? ''
  106. : 'hide-videos'}`;
  107. return (
  108. <div className = { filmstripClassNames }>
  109. { filmstripOnly ? <Toolbox /> : null }
  110. <div
  111. className = 'filmstrip__videos'
  112. id = 'remoteVideos'>
  113. <div
  114. className = 'filmstrip__videos'
  115. id = 'filmstripLocalVideo'
  116. onMouseOut = { this._onMouseOut }
  117. onMouseOver = { this._onMouseOver }>
  118. { filmstripOnly || _hideInviteButton
  119. ? null
  120. : <InviteButton
  121. enableAddPeople = { _isAddToCallAvailable }
  122. enableDialOut = { _isDialOutAvailable } /> }
  123. <div id = 'filmstripLocalVideoThumbnail' />
  124. </div>
  125. <div
  126. className = 'filmstrip__videos'
  127. id = 'filmstripRemoteVideos'>
  128. {/**
  129. * This extra video container is needed for scrolling
  130. * thumbnails in Firefox; otherwise, the flex
  131. * thumbnails resize instead of causing overflow.
  132. */}
  133. <div
  134. className = 'remote-videos-container'
  135. id = 'filmstripRemoteVideosContainer'
  136. onMouseOut = { this._onMouseOut }
  137. onMouseOver = { this._onMouseOver } />
  138. </div>
  139. </div>
  140. </div>
  141. );
  142. }
  143. /**
  144. * If the current hover state does not match the known hover state in redux,
  145. * dispatch an action to update the known hover state in redux.
  146. *
  147. * @private
  148. * @returns {void}
  149. */
  150. _notifyOfHoveredStateUpdate() {
  151. if (this.props._hovered !== this._isHovered) {
  152. this.props.dispatch(setFilmstripHovered(this._isHovered));
  153. }
  154. }
  155. /**
  156. * Updates the currently known mouseover state and attempt to dispatch an
  157. * update of the known hover state in redux.
  158. *
  159. * @private
  160. * @returns {void}
  161. */
  162. _onMouseOut() {
  163. this._isHovered = false;
  164. this._notifyOfHoveredStateUpdate();
  165. }
  166. /**
  167. * Updates the currently known mouseover state and attempt to dispatch an
  168. * update of the known hover state in redux.
  169. *
  170. * @private
  171. * @returns {void}
  172. */
  173. _onMouseOver() {
  174. this._isHovered = true;
  175. this._notifyOfHoveredStateUpdate();
  176. }
  177. }
  178. /**
  179. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  180. *
  181. * @param {Object} state - The Redux state.
  182. * @private
  183. * @returns {{
  184. * _hideInviteButton: boolean,
  185. * _hovered: boolean,
  186. * _isAddToCallAvailable: boolean,
  187. * _isDialOutAvailable: boolean,
  188. * _remoteVideosVisible: boolean
  189. * }}
  190. */
  191. function _mapStateToProps(state) {
  192. const { conference } = state['features/base/conference'];
  193. const {
  194. enableUserRolesBasedOnToken,
  195. iAmRecorder
  196. } = state['features/base/config'];
  197. const { isGuest } = state['features/base/jwt'];
  198. const { hovered } = state['features/filmstrip'];
  199. const isAddToCallAvailable = !isGuest;
  200. const isDialOutAvailable
  201. = getLocalParticipant(state).role === PARTICIPANT_ROLE.MODERATOR
  202. && conference && conference.isSIPCallingSupported()
  203. && (!enableUserRolesBasedOnToken || !isGuest);
  204. return {
  205. _hideInviteButton: iAmRecorder
  206. || (!isAddToCallAvailable && !isDialOutAvailable),
  207. _hovered: hovered,
  208. _isAddToCallAvailable: isAddToCallAvailable,
  209. _isDialOutAvailable: isDialOutAvailable,
  210. _remoteVideosVisible: shouldRemoteVideosBeVisible(state)
  211. };
  212. }
  213. export default connect(_mapStateToProps)(Filmstrip);