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.

VideoStatusLabel.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { toggleAudioOnly } from '../../base/conference';
  4. import { translate } from '../../base/i18n';
  5. /**
  6. * React {@code Component} responsible for displaying a label that indicates
  7. * the displayed video state of the current conference. {@code AudioOnlyLabel}
  8. * will display when the conference is in audio only mode. {@code HDVideoLabel}
  9. * will display if not in audio only mode and a high-definition large video is
  10. * being displayed.
  11. */
  12. export class VideoStatusLabel extends Component {
  13. /**
  14. * {@code VideoStatusLabel}'s property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * Whether or not the conference is in audio only mode.
  21. */
  22. _audioOnly: React.PropTypes.bool,
  23. /**
  24. * Whether or not a connection to a conference has been established.
  25. */
  26. _conferenceStarted: React.PropTypes.bool,
  27. /**
  28. * Whether or not the filmstrip is displayed with remote videos. Used to
  29. * determine display classes to set.
  30. */
  31. _filmstripVisible: React.PropTypes.bool,
  32. /**
  33. * Whether or not a high-definition large video is displayed.
  34. */
  35. _largeVideoHD: React.PropTypes.bool,
  36. /**
  37. * Whether or note remote videos are visible in the filmstrip,
  38. * regardless of count. Used to determine display classes to set.
  39. */
  40. _remoteVideosVisible: React.PropTypes.bool,
  41. /**
  42. * Invoked to request toggling of audio only mode.
  43. */
  44. dispatch: React.PropTypes.func,
  45. /**
  46. * Invoked to obtain translated strings.
  47. */
  48. t: React.PropTypes.func
  49. };
  50. /**
  51. * Initializes a new {@code VideoStatusLabel} instance.
  52. *
  53. * @param {Object} props - The read-only React Component props with which
  54. * the new instance is to be initialized.
  55. */
  56. constructor(props) {
  57. super(props);
  58. this.state = {
  59. // Whether or not the filmstrip is transitioning from not visible
  60. // to visible. Used to set a transition class for animation.
  61. togglingToVisible: false
  62. };
  63. // Bind event handler so it is only bound once for every instance.
  64. this._toggleAudioOnly = this._toggleAudioOnly.bind(this);
  65. }
  66. /**
  67. * Updates the state for whether or not the filmstrip is being toggled to
  68. * display after having being hidden.
  69. *
  70. * @inheritdoc
  71. * @param {Object} nextProps - The read-only props which this Component will
  72. * receive.
  73. * @returns {void}
  74. */
  75. componentWillReceiveProps(nextProps) {
  76. this.setState({
  77. togglingToVisible: nextProps._filmstripVisible
  78. && !this.props._filmstripVisible
  79. });
  80. }
  81. /**
  82. * Implements React's {@link Component#render()}.
  83. *
  84. * @inheritdoc
  85. * @returns {ReactElement}
  86. */
  87. render() {
  88. const {
  89. _audioOnly,
  90. _conferenceStarted,
  91. _filmstripVisible,
  92. _remoteVideosVisible,
  93. _largeVideoHD,
  94. t
  95. } = this.props;
  96. // FIXME The _conferenceStarted check is used to be defensive against
  97. // toggling audio only mode while there is no conference and hides the
  98. // need for error handling around audio only mode toggling.
  99. if (!_conferenceStarted) {
  100. return null;
  101. }
  102. let displayedLabel;
  103. if (_audioOnly) {
  104. displayedLabel = <i className = 'icon-visibility-off' />;
  105. } else {
  106. displayedLabel = _largeVideoHD
  107. ? t('videoStatus.hd') : t('videoStatus.sd');
  108. }
  109. // Determine which classes should be set on the component. These classes
  110. // will used to help with animations and setting position.
  111. const baseClasses = 'video-state-indicator moveToCorner';
  112. const filmstrip
  113. = _filmstripVisible ? 'with-filmstrip' : 'without-filmstrip';
  114. const remoteVideosVisible = _remoteVideosVisible
  115. ? 'with-remote-videos'
  116. : 'without-remote-videos';
  117. const opening = this.state.togglingToVisible ? 'opening' : '';
  118. const classNames
  119. = `${baseClasses} ${filmstrip} ${remoteVideosVisible} ${opening}`;
  120. return (
  121. <div
  122. className = { classNames }
  123. id = 'videoResolutionLabel' >
  124. { displayedLabel }
  125. { this._renderVideonMenu() }
  126. </div>
  127. );
  128. }
  129. /**
  130. * Renders a dropdown menu for changing video modes.
  131. *
  132. * @private
  133. * @returns {ReactElement}
  134. */
  135. _renderVideonMenu() {
  136. const { _audioOnly, t } = this.props;
  137. const audioOnlyAttributes = _audioOnly ? { className: 'active' }
  138. : { onClick: this._toggleAudioOnly };
  139. const videoAttributes = _audioOnly ? { onClick: this._toggleAudioOnly }
  140. : { className: 'active' };
  141. return (
  142. <div className = 'video-state-indicator-menu'>
  143. <div className = 'video-state-indicator-menu-options'>
  144. <div { ...audioOnlyAttributes }>
  145. <i className = 'icon-visibility' />
  146. { t('audioOnly.audioOnly') }
  147. </div>
  148. <div { ...videoAttributes }>
  149. <i className = 'icon-camera' />
  150. { this.props._largeVideoHD
  151. ? t('videoStatus.hdVideo')
  152. : t('videoStatus.sdVideo') }
  153. </div>
  154. </div>
  155. </div>
  156. );
  157. }
  158. /**
  159. * Dispatches an action to toggle the state of audio only mode.
  160. *
  161. * @private
  162. * @returns {void}
  163. */
  164. _toggleAudioOnly() {
  165. this.props.dispatch(toggleAudioOnly());
  166. }
  167. }
  168. /**
  169. * Maps (parts of) the Redux state to the associated {@code VideoStatusLabel}'s
  170. * props.
  171. *
  172. * @param {Object} state - The Redux state.
  173. * @private
  174. * @returns {{
  175. * _audioOnly: boolean,
  176. * _conferenceStarted: boolean,
  177. * _filmstripVisible: true,
  178. * _largeVideoHD: (boolean|undefined),
  179. * _remoteVideosVisible: boolean
  180. * }}
  181. */
  182. function _mapStateToProps(state) {
  183. const {
  184. audioOnly,
  185. conference,
  186. isLargeVideoHD
  187. } = state['features/base/conference'];
  188. const {
  189. remoteVideosVisible,
  190. visible
  191. } = state['features/filmstrip'];
  192. return {
  193. _audioOnly: audioOnly,
  194. _conferenceStarted: Boolean(conference),
  195. _filmstripVisible: visible,
  196. _largeVideoHD: isLargeVideoHD,
  197. _remoteVideosVisible: remoteVideosVisible
  198. };
  199. }
  200. export default translate(connect(_mapStateToProps)(VideoStatusLabel));