您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VideoQualityLabel.web.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 { VideoQualityDialog } from './';
  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. } = this.props;
  116. // FIXME The _conferenceStarted check is used to be defensive against
  117. // toggling audio only mode while there is no conference and hides the
  118. // need for error handling around audio only mode toggling.
  119. if (!_conferenceStarted) {
  120. return null;
  121. }
  122. // Determine which classes should be set on the component. These classes
  123. // will used to help with animations and setting position.
  124. const baseClasses = 'video-state-indicator moveToCorner';
  125. const filmstrip
  126. = _filmstripVisible ? 'with-filmstrip' : 'without-filmstrip';
  127. const remoteVideosVisible = _remoteVideosVisible
  128. ? 'with-remote-videos'
  129. : 'without-remote-videos';
  130. const opening = this.state.togglingToVisible ? 'opening' : '';
  131. const classNames
  132. = `${baseClasses} ${filmstrip} ${remoteVideosVisible} ${opening}`;
  133. return (
  134. <Popover
  135. className = { classNames }
  136. content = { <VideoQualityDialog /> }
  137. id = 'videoResolutionLabel'
  138. position = { 'left top' }>
  139. <div
  140. className = 'video-quality-label-status'>
  141. { _audioOnly
  142. ? <i className = 'icon-visibility-off' />
  143. : this._mapResolutionToTranslation(_resolution) }
  144. </div>
  145. </Popover>
  146. );
  147. }
  148. /**
  149. * Matches the passed in resolution with a translation key for describing
  150. * the resolution. The passed in resolution will be matched with a known
  151. * resolution that it is at least greater than or equal to.
  152. *
  153. * @param {number} resolution - The video height to match with a
  154. * translation.
  155. * @private
  156. * @returns {string}
  157. */
  158. _mapResolutionToTranslation(resolution) {
  159. // Set the default matching resolution of the lowest just in case a
  160. // match is not found.
  161. let highestMatchingResolution = RESOLUTIONS[0];
  162. for (let i = 0; i < RESOLUTIONS.length; i++) {
  163. const knownResolution = RESOLUTIONS[i];
  164. if (resolution >= knownResolution) {
  165. highestMatchingResolution = knownResolution;
  166. } else {
  167. break;
  168. }
  169. }
  170. return this.props.t(
  171. RESOLUTION_TO_TRANSLATION_KEY[highestMatchingResolution]);
  172. }
  173. }
  174. /**
  175. * Maps (parts of) the Redux state to the associated {@code VideoQualityLabel}'s
  176. * props.
  177. *
  178. * @param {Object} state - The Redux state.
  179. * @private
  180. * @returns {{
  181. * _audioOnly: boolean,
  182. * _conferenceStarted: boolean,
  183. * _filmstripVisible: true,
  184. * _remoteVideosVisible: boolean,
  185. * _resolution: number
  186. * }}
  187. */
  188. function _mapStateToProps(state) {
  189. const {
  190. audioOnly,
  191. conference
  192. } = state['features/base/conference'];
  193. const { disable1On1Mode } = state['features/base/config'];
  194. const {
  195. remoteVideosVisible,
  196. visible
  197. } = state['features/filmstrip'];
  198. const {
  199. resolution
  200. } = state['features/large-video'];
  201. return {
  202. _audioOnly: audioOnly,
  203. _conferenceStarted: Boolean(conference),
  204. _filmstripVisible: visible,
  205. _remoteVideosVisible: Boolean(remoteVideosVisible || disable1On1Mode),
  206. _resolution: resolution
  207. };
  208. }
  209. export default translate(connect(_mapStateToProps)(VideoQualityLabel));