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

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