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.6KB

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