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.

VideoQualityButton.web.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // @flow
  2. import { translate } from '../../base/i18n';
  3. import {
  4. IconVideoQualityAudioOnly,
  5. IconVideoQualityHD,
  6. IconVideoQualityLD,
  7. IconVideoQualitySD
  8. } from '../../base/icons';
  9. import { connect } from '../../base/redux';
  10. import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
  11. import { VIDEO_QUALITY_LEVELS } from '../constants';
  12. import { findNearestQualityLevel } from '../functions';
  13. /**
  14. * A map of of selectable receive resolutions to corresponding icons.
  15. *
  16. * @private
  17. * @type {Object}
  18. */
  19. const VIDEO_QUALITY_TO_ICON = {
  20. [VIDEO_QUALITY_LEVELS.ULTRA]: IconVideoQualityHD,
  21. [VIDEO_QUALITY_LEVELS.HIGH]: IconVideoQualityHD,
  22. [VIDEO_QUALITY_LEVELS.STANDARD]: IconVideoQualitySD,
  23. [VIDEO_QUALITY_LEVELS.LOW]: IconVideoQualityLD
  24. };
  25. /**
  26. * The type of the React {@code Component} props of
  27. * {@link VideoQualityButton}.
  28. */
  29. type Props = AbstractButtonProps & {
  30. /**
  31. * Whether or not audio only mode is currently enabled.
  32. */
  33. _audioOnly: boolean,
  34. /**
  35. * The currently configured maximum quality resolution to be received from
  36. * and sent to remote participants.
  37. */
  38. _videoQuality: number,
  39. /**
  40. * Invoked to obtain translated strings.
  41. */
  42. t: Function
  43. };
  44. /**
  45. * React {@code Component} responsible for displaying a button in the overflow
  46. * menu of the toolbar, including an icon showing the currently selected
  47. * max receive quality.
  48. *
  49. * @extends Component
  50. */
  51. class VideoQualityButton extends AbstractButton<Props, *> {
  52. accessibilityLabel = 'toolbar.accessibilityLabel.callQuality';
  53. label = 'toolbar.callQuality';
  54. tooltip = 'toolbar.callQuality';
  55. /**
  56. * Dynamically retrieves the icon.
  57. */
  58. get icon() {
  59. const { _audioOnly, _videoQuality } = this.props;
  60. const videoQualityLevel = findNearestQualityLevel(_videoQuality);
  61. const icon = _audioOnly || !videoQualityLevel
  62. ? IconVideoQualityAudioOnly
  63. : VIDEO_QUALITY_TO_ICON[videoQualityLevel];
  64. return icon;
  65. }
  66. /**
  67. * Required by linter due to AbstractButton overwritten prop being writable.
  68. *
  69. * @param {string} value - The icon value.
  70. */
  71. set icon(value) {
  72. return value;
  73. }
  74. /**
  75. * Handles clicking / pressing the button.
  76. *
  77. * @override
  78. * @protected
  79. * @returns {void}
  80. */
  81. _handleClick() {
  82. const { handleClick } = this.props;
  83. if (handleClick) {
  84. handleClick();
  85. return;
  86. }
  87. }
  88. }
  89. /**
  90. * Maps (parts of) the Redux state to the associated props for the
  91. * {@code VideoQualityButton} component.
  92. *
  93. * @param {Object} state - The Redux state.
  94. * @private
  95. * @returns {{
  96. * _audioOnly: boolean,
  97. * _videoQuality: number
  98. * }}
  99. */
  100. function _mapStateToProps(state) {
  101. return {
  102. _audioOnly: state['features/base/audio-only'].enabled,
  103. _videoQuality: state['features/video-quality'].preferredVideoQuality
  104. };
  105. }
  106. export default translate(
  107. connect(_mapStateToProps)(VideoQualityButton));