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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * Callback to invoke when {@link VideoQualityButton} is clicked.
  41. */
  42. handleClick: Function,
  43. /**
  44. * Invoked to obtain translated strings.
  45. */
  46. t: Function
  47. };
  48. /**
  49. * React {@code Component} responsible for displaying a button in the overflow
  50. * menu of the toolbar, including an icon showing the currently selected
  51. * max receive quality.
  52. *
  53. * @extends Component
  54. */
  55. class VideoQualityButton extends AbstractButton<Props, *> {
  56. accessibilityLabel = 'toolbar.accessibilityLabel.callQuality';
  57. label = 'toolbar.callQuality';
  58. tooltip = 'toolbar.callQuality';
  59. /**
  60. * Dynamically retrieves the icon.
  61. */
  62. get icon() {
  63. const { _audioOnly, _videoQuality } = this.props;
  64. const videoQualityLevel = findNearestQualityLevel(_videoQuality);
  65. const icon = _audioOnly || !videoQualityLevel
  66. ? IconVideoQualityAudioOnly
  67. : VIDEO_QUALITY_TO_ICON[videoQualityLevel];
  68. return icon;
  69. }
  70. /**
  71. * Required by linter due to AbstractButton overwritten prop being writable.
  72. *
  73. * @param {string} value - The icon value.
  74. */
  75. set icon(value) {
  76. return value;
  77. }
  78. /**
  79. * Handles clicking / pressing the button.
  80. *
  81. * @override
  82. * @protected
  83. * @returns {void}
  84. */
  85. _handleClick() {
  86. this.props.handleClick();
  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));