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.

AudioSettingsButton.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { isMobileBrowser } from '../../../base/environment/utils';
  4. import { translate } from '../../../base/i18n';
  5. import { IconArrowUp } from '../../../base/icons';
  6. import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
  7. import { connect } from '../../../base/redux';
  8. import { ToolboxButtonWithIcon } from '../../../base/toolbox/components';
  9. import { AudioSettingsPopup, toggleAudioSettings } from '../../../settings';
  10. import { getAudioSettingsVisibility } from '../../../settings/functions';
  11. import { isAudioSettingsButtonDisabled } from '../../functions';
  12. import AudioMuteButton from '../AudioMuteButton';
  13. type Props = {
  14. /**
  15. * Indicates whether audio permissions have been granted or denied.
  16. */
  17. hasPermissions: boolean,
  18. /**
  19. * Click handler for the small icon. Opens audio options.
  20. */
  21. onAudioOptionsClick: Function,
  22. /**
  23. * If the button should be disabled.
  24. */
  25. isDisabled: boolean,
  26. /**
  27. * Used for translation.
  28. */
  29. t: Function,
  30. /**
  31. * Flag controlling the visibility of the button.
  32. * AudioSettings popup is disabled on mobile browsers.
  33. */
  34. visible: boolean,
  35. /**
  36. * Defines is popup is open
  37. */
  38. isOpen: boolean,
  39. };
  40. /**
  41. * Button used for audio & audio settings.
  42. *
  43. * @returns {ReactElement}
  44. */
  45. class AudioSettingsButton extends Component<Props> {
  46. /**
  47. * Initializes a new {@code AudioSettingsButton} instance.
  48. *
  49. * @inheritdoc
  50. */
  51. constructor(props: Props) {
  52. super(props);
  53. this._onEscClick = this._onEscClick.bind(this);
  54. }
  55. _onEscClick: (KeyboardEvent) => void;
  56. /**
  57. * Click handler for the more actions entries.
  58. *
  59. * @param {KeyboardEvent} event - Esc key click to close the popup.
  60. * @returns {void}
  61. */
  62. _onEscClick(event) {
  63. if (event.key === 'Escape' && this.props.isOpen) {
  64. event.preventDefault();
  65. event.stopPropagation();
  66. this.props.onAudioOptionsClick();
  67. }
  68. }
  69. /**
  70. * Implements React's {@link Component#render}.
  71. *
  72. * @inheritdoc
  73. */
  74. render() {
  75. const { hasPermissions, isDisabled, onAudioOptionsClick, visible, isOpen, t } = this.props;
  76. const settingsDisabled = !hasPermissions
  77. || isDisabled
  78. || !JitsiMeetJS.mediaDevices.isMultipleAudioInputSupported();
  79. return visible ? (
  80. <AudioSettingsPopup>
  81. <ToolboxButtonWithIcon
  82. ariaControls = 'audio-settings-dialog'
  83. ariaExpanded = { isOpen }
  84. ariaHasPopup = { true }
  85. ariaLabel = { t('toolbar.audioSettings') }
  86. icon = { IconArrowUp }
  87. iconDisabled = { settingsDisabled }
  88. iconId = 'audio-settings-button'
  89. iconTooltip = { t('toolbar.audioSettings') }
  90. onIconClick = { onAudioOptionsClick }
  91. onIconKeyDown = { this._onEscClick }>
  92. <AudioMuteButton />
  93. </ToolboxButtonWithIcon>
  94. </AudioSettingsPopup>
  95. ) : <AudioMuteButton />;
  96. }
  97. }
  98. /**
  99. * Function that maps parts of Redux state tree into component props.
  100. *
  101. * @param {Object} state - Redux state.
  102. * @returns {Object}
  103. */
  104. function mapStateToProps(state) {
  105. const { permissions = {} } = state['features/base/devices'];
  106. return {
  107. hasPermissions: permissions.audio,
  108. isDisabled: isAudioSettingsButtonDisabled(state),
  109. isOpen: getAudioSettingsVisibility(state),
  110. visible: !isMobileBrowser()
  111. };
  112. }
  113. const mapDispatchToProps = {
  114. onAudioOptionsClick: toggleAudioSettings
  115. };
  116. export default translate(connect(
  117. mapStateToProps,
  118. mapDispatchToProps,
  119. )(AudioSettingsButton));