您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AudioSettingsButton.js 4.3KB

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