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.

VideoQualityLabel.web.js 6.8KB

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