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.

OverflowMenuVideoQualityItem.web.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { translate } from '../../base/i18n';
  4. import {
  5. Icon,
  6. IconVideoQualityAudioOnly,
  7. IconVideoQualityHD,
  8. IconVideoQualityLD,
  9. IconVideoQualitySD
  10. } from '../../base/icons';
  11. import { connect } from '../../base/redux';
  12. import { VIDEO_QUALITY_LEVELS } from '../constants';
  13. import { findNearestQualityLevel } from '../functions';
  14. /**
  15. * A map of of selectable receive resolutions to corresponding icons.
  16. *
  17. * @private
  18. * @type {Object}
  19. */
  20. const VIDEO_QUALITY_TO_ICON = {
  21. [VIDEO_QUALITY_LEVELS.ULTRA]: IconVideoQualityHD,
  22. [VIDEO_QUALITY_LEVELS.HIGH]: IconVideoQualityHD,
  23. [VIDEO_QUALITY_LEVELS.STANDARD]: IconVideoQualitySD,
  24. [VIDEO_QUALITY_LEVELS.LOW]: IconVideoQualityLD
  25. };
  26. /**
  27. * The type of the React {@code Component} props of
  28. * {@link OverflowMenuVideoQualityItem}.
  29. */
  30. type Props = {
  31. /**
  32. * Whether or not audio only mode is currently enabled.
  33. */
  34. _audioOnly: boolean,
  35. /**
  36. * The currently configured maximum quality resolution to be received from
  37. * and sent to remote participants.
  38. */
  39. _videoQuality: number,
  40. /**
  41. * Callback to invoke when {@link OverflowMenuVideoQualityItem} is clicked.
  42. */
  43. onClick: Function,
  44. /**
  45. * Invoked to obtain translated strings.
  46. */
  47. t: Function
  48. };
  49. /**
  50. * React {@code Component} responsible for displaying a button in the overflow
  51. * menu of the toolbar, including an icon showing the currently selected
  52. * max receive quality.
  53. *
  54. * @extends Component
  55. */
  56. class OverflowMenuVideoQualityItem extends Component<Props> {
  57. /**
  58. * Initializes a new {@code OverflowMenuVideoQualityItem} instance.
  59. *
  60. * @param {*} props - The read-only properties with which the new instance
  61. * is to be initialized.
  62. */
  63. constructor(props) {
  64. super(props);
  65. // Bind event handler so it is only bound once for every instance.
  66. this._onKeyPress = this._onKeyPress.bind(this);
  67. }
  68. _onKeyPress: (Object) => void;
  69. /**
  70. * KeyPress handler for accessibility.
  71. *
  72. * @param {Object} e - The key event to handle.
  73. *
  74. * @returns {void}
  75. */
  76. _onKeyPress(e) {
  77. if (this.props.onClick && (e.key === ' ' || e.key === 'Enter')) {
  78. e.preventDefault();
  79. this.props.onClick();
  80. }
  81. }
  82. /**
  83. * Implements React's {@link Component#render()}.
  84. *
  85. * @inheritdoc
  86. * @returns {ReactElement}
  87. */
  88. render() {
  89. const { _audioOnly, _videoQuality } = this.props;
  90. const videoQualityLevel = findNearestQualityLevel(_videoQuality);
  91. const icon = _audioOnly || !videoQualityLevel
  92. ? IconVideoQualityAudioOnly
  93. : VIDEO_QUALITY_TO_ICON[videoQualityLevel];
  94. return (
  95. <li
  96. aria-label = { this.props.t('toolbar.accessibilityLabel.callQuality') }
  97. className = 'overflow-menu-item'
  98. onClick = { this.props.onClick }
  99. onKeyPress = { this._onKeyPress }
  100. role = 'menuitem'
  101. tabIndex = { 0 }>
  102. <span className = 'overflow-menu-item-icon'>
  103. <Icon src = { icon } />
  104. </span>
  105. <span className = 'profile-text'>
  106. { this.props.t('toolbar.callQuality') }
  107. </span>
  108. </li>
  109. );
  110. }
  111. }
  112. /**
  113. * Maps (parts of) the Redux state to the associated props for the
  114. * {@code OverflowMenuVideoQualityItem} component.
  115. *
  116. * @param {Object} state - The Redux state.
  117. * @private
  118. * @returns {{
  119. * _audioOnly: boolean,
  120. * _videoQuality: number
  121. * }}
  122. */
  123. function _mapStateToProps(state) {
  124. return {
  125. _audioOnly: state['features/base/audio-only'].enabled,
  126. _videoQuality: state['features/video-quality'].preferredVideoQuality
  127. };
  128. }
  129. export default translate(
  130. connect(_mapStateToProps)(OverflowMenuVideoQualityItem));