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

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