Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Filmstrip.web.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. <audio
  140. id = 'userJoined'
  141. preload = 'auto'
  142. src = 'sounds/joined.wav' />
  143. <audio
  144. id = 'userLeft'
  145. preload = 'auto'
  146. src = 'sounds/left.wav' />
  147. </div>
  148. </div>
  149. );
  150. }
  151. /**
  152. * If the current hover state does not match the known hover state in redux,
  153. * dispatch an action to update the known hover state in redux.
  154. *
  155. * @private
  156. * @returns {void}
  157. */
  158. _notifyOfHoveredStateUpdate() {
  159. if (this.props._hovered !== this._isHovered) {
  160. this.props.dispatch(setFilmstripHovered(this._isHovered));
  161. }
  162. }
  163. /**
  164. * Updates the currently known mouseover state and attempt to dispatch an
  165. * update of the known hover state in redux.
  166. *
  167. * @private
  168. * @returns {void}
  169. */
  170. _onMouseOut() {
  171. this._isHovered = false;
  172. this._notifyOfHoveredStateUpdate();
  173. }
  174. /**
  175. * Updates the currently known mouseover state and attempt to dispatch an
  176. * update of the known hover state in redux.
  177. *
  178. * @private
  179. * @returns {void}
  180. */
  181. _onMouseOver() {
  182. this._isHovered = true;
  183. this._notifyOfHoveredStateUpdate();
  184. }
  185. }
  186. /**
  187. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  188. *
  189. * @param {Object} state - The Redux state.
  190. * @private
  191. * @returns {{
  192. * _hideInviteButton: boolean,
  193. * _hovered: boolean,
  194. * _isAddToCallAvailable: boolean,
  195. * _isDialOutAvailable: boolean,
  196. * _remoteVideosVisible: boolean
  197. * }}
  198. */
  199. function _mapStateToProps(state) {
  200. const { conference } = state['features/base/conference'];
  201. const {
  202. enableUserRolesBasedOnToken,
  203. iAmRecorder
  204. } = state['features/base/config'];
  205. const { isGuest } = state['features/base/jwt'];
  206. const { hovered } = state['features/filmstrip'];
  207. const isAddToCallAvailable = !isGuest;
  208. const isDialOutAvailable
  209. = getLocalParticipant(state).role === PARTICIPANT_ROLE.MODERATOR
  210. && conference && conference.isSIPCallingSupported()
  211. && (!enableUserRolesBasedOnToken || !isGuest);
  212. return {
  213. _hideInviteButton: iAmRecorder
  214. || (!isAddToCallAvailable && !isDialOutAvailable),
  215. _hovered: hovered,
  216. _isAddToCallAvailable: isAddToCallAvailable,
  217. _isDialOutAvailable: isDialOutAvailable,
  218. _remoteVideosVisible: shouldRemoteVideosBeVisible(state)
  219. };
  220. }
  221. export default connect(_mapStateToProps)(Filmstrip);