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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../base/i18n';
  4. import { CircularLabel } from '../../base/label';
  5. import { MEDIA_TYPE } from '../../base/media';
  6. import { connect } from '../../base/redux';
  7. import { Tooltip } from '../../base/tooltip';
  8. import { getTrackByMediaTypeAndParticipant } from '../../base/tracks';
  9. import AbstractVideoQualityLabel, {
  10. _abstractMapStateToProps,
  11. type Props as AbstractProps
  12. } from './AbstractVideoQualityLabel';
  13. type Props = AbstractProps & {
  14. /**
  15. * The message to show within the label.
  16. */
  17. _labelKey: string,
  18. /**
  19. * The message to show within the label's tooltip.
  20. */
  21. _tooltipKey: string,
  22. /**
  23. * The redux representation of the JitsiTrack displayed on large video.
  24. */
  25. _videoTrack: Object
  26. };
  27. /**
  28. * A map of video resolution (number) to translation key.
  29. *
  30. * @type {Object}
  31. */
  32. const RESOLUTION_TO_TRANSLATION_KEY = {
  33. '720': 'videoStatus.hd',
  34. '360': 'videoStatus.sd',
  35. '180': 'videoStatus.ld'
  36. };
  37. /**
  38. * Expected video resolutions placed into an array, sorted from lowest to
  39. * highest resolution.
  40. *
  41. * @type {number[]}
  42. */
  43. const RESOLUTIONS
  44. = Object.keys(RESOLUTION_TO_TRANSLATION_KEY)
  45. .map(resolution => parseInt(resolution, 10))
  46. .sort((a, b) => a - b);
  47. /**
  48. * React {@code Component} responsible for displaying a label that indicates
  49. * the displayed video state of the current conference. {@code AudioOnlyLabel}
  50. * will display when the conference is in audio only mode. {@code HDVideoLabel}
  51. * will display if not in audio only mode and a high-definition large video is
  52. * being displayed.
  53. */
  54. export class VideoQualityLabel extends AbstractVideoQualityLabel<Props> {
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. * @returns {ReactElement}
  60. */
  61. render() {
  62. const {
  63. _audioOnly,
  64. _labelKey,
  65. _tooltipKey,
  66. _videoTrack,
  67. t
  68. } = this.props;
  69. let className, labelContent, tooltipKey;
  70. if (_audioOnly) {
  71. className = 'audio-only';
  72. labelContent = t('videoStatus.audioOnly');
  73. tooltipKey = 'videoStatus.labelTooltipAudioOnly';
  74. } else if (!_videoTrack || _videoTrack.muted) {
  75. className = 'no-video';
  76. labelContent = t('videoStatus.audioOnly');
  77. tooltipKey = 'videoStatus.labelTooiltipNoVideo';
  78. } else {
  79. className = 'current-video-quality';
  80. labelContent = t(_labelKey);
  81. tooltipKey = _tooltipKey;
  82. }
  83. return (
  84. <Tooltip
  85. content = { t(tooltipKey) }
  86. position = { 'left' }>
  87. <CircularLabel
  88. className = { className }
  89. id = 'videoResolutionLabel'
  90. label = { labelContent } />
  91. </Tooltip>
  92. );
  93. }
  94. }
  95. /**
  96. * Matches the passed in resolution with a translation keys for describing
  97. * the resolution. The passed in resolution will be matched with a known
  98. * resolution that it is at least greater than or equal to.
  99. *
  100. * @param {number} resolution - The video height to match with a
  101. * translation.
  102. * @private
  103. * @returns {Object}
  104. */
  105. function _mapResolutionToTranslationsKeys(resolution) {
  106. // Set the default matching resolution of the lowest just in case a match is
  107. // not found.
  108. let highestMatchingResolution = RESOLUTIONS[0];
  109. for (let i = 0; i < RESOLUTIONS.length; i++) {
  110. const knownResolution = RESOLUTIONS[i];
  111. if (resolution >= knownResolution) {
  112. highestMatchingResolution = knownResolution;
  113. } else {
  114. break;
  115. }
  116. }
  117. const labelKey
  118. = RESOLUTION_TO_TRANSLATION_KEY[highestMatchingResolution];
  119. return {
  120. labelKey,
  121. tooltipKey: `${labelKey}Tooltip`
  122. };
  123. }
  124. /**
  125. * Maps (parts of) the Redux state to the associated {@code VideoQualityLabel}'s
  126. * props.
  127. *
  128. * @param {Object} state - The Redux state.
  129. * @private
  130. * @returns {{
  131. * _labelKey: string,
  132. * _tooltipKey: string,
  133. * _videoTrack: Object
  134. * }}
  135. */
  136. function _mapStateToProps(state) {
  137. const { enabled: audioOnly } = state['features/base/audio-only'];
  138. const { resolution, participantId } = state['features/large-video'];
  139. const videoTrackOnLargeVideo = getTrackByMediaTypeAndParticipant(
  140. state['features/base/tracks'],
  141. MEDIA_TYPE.VIDEO,
  142. participantId
  143. );
  144. const translationKeys
  145. = audioOnly ? {} : _mapResolutionToTranslationsKeys(resolution);
  146. return {
  147. ..._abstractMapStateToProps(state),
  148. _labelKey: translationKeys.labelKey,
  149. _tooltipKey: translationKeys.tooltipKey,
  150. _videoTrack: videoTrackOnLargeVideo
  151. };
  152. }
  153. export default translate(connect(_mapStateToProps)(VideoQualityLabel));