Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AudioSettingsButton.tsx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { IReduxState } from '../../../app/types';
  5. import { isMobileBrowser } from '../../../base/environment/utils';
  6. import { translate } from '../../../base/i18n/functions';
  7. import { IconArrowUp } from '../../../base/icons/svg';
  8. import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
  9. import ToolboxButtonWithIcon from '../../../base/toolbox/components/web/ToolboxButtonWithIcon';
  10. import { toggleAudioSettings } from '../../../settings/actions';
  11. import AudioSettingsPopup from '../../../settings/components/web/audio/AudioSettingsPopup';
  12. import { getAudioSettingsVisibility } from '../../../settings/functions';
  13. import { isAudioSettingsButtonDisabled } from '../../functions';
  14. import AudioMuteButton from '../AudioMuteButton';
  15. interface IProps extends WithTranslation {
  16. /**
  17. * The button's key.
  18. */
  19. buttonKey?: string;
  20. /**
  21. * External handler for click action.
  22. */
  23. handleClick: Function;
  24. /**
  25. * Indicates whether audio permissions have been granted or denied.
  26. */
  27. hasPermissions: boolean;
  28. /**
  29. * If the button should be disabled.
  30. */
  31. isDisabled: boolean;
  32. /**
  33. * Defines is popup is open.
  34. */
  35. isOpen: boolean;
  36. /**
  37. * Notify mode for `toolbarButtonClicked` event -
  38. * whether to only notify or to also prevent button click routine.
  39. */
  40. notifyMode?: string;
  41. /**
  42. * Click handler for the small icon. Opens audio options.
  43. */
  44. onAudioOptionsClick: Function;
  45. /**
  46. * Flag controlling the visibility of the button.
  47. * AudioSettings popup is disabled on mobile browsers.
  48. */
  49. visible: boolean;
  50. }
  51. /**
  52. * Button used for audio & audio settings.
  53. *
  54. * @returns {ReactElement}
  55. */
  56. class AudioSettingsButton extends Component<IProps> {
  57. /**
  58. * Initializes a new {@code AudioSettingsButton} instance.
  59. *
  60. * @inheritdoc
  61. */
  62. constructor(props: IProps) {
  63. super(props);
  64. this._onEscClick = this._onEscClick.bind(this);
  65. this._onClick = this._onClick.bind(this);
  66. }
  67. /**
  68. * Click handler for the more actions entries.
  69. *
  70. * @param {KeyboardEvent} event - Esc key click to close the popup.
  71. * @returns {void}
  72. */
  73. _onEscClick(event: React.KeyboardEvent) {
  74. if (event.key === 'Escape' && this.props.isOpen) {
  75. event.preventDefault();
  76. event.stopPropagation();
  77. this._onClick();
  78. }
  79. }
  80. /**
  81. * Click handler for the more actions entries.
  82. *
  83. * @param {MouseEvent} e - Mouse event.
  84. * @returns {void}
  85. */
  86. _onClick(e?: React.MouseEvent) {
  87. const { onAudioOptionsClick, isOpen } = this.props;
  88. if (isOpen) {
  89. e?.stopPropagation();
  90. }
  91. onAudioOptionsClick();
  92. }
  93. /**
  94. * Implements React's {@link Component#render}.
  95. *
  96. * @inheritdoc
  97. */
  98. render() {
  99. const { hasPermissions, isDisabled, visible, isOpen, buttonKey, notifyMode, t } = this.props;
  100. const settingsDisabled = !hasPermissions
  101. || isDisabled
  102. || !JitsiMeetJS.mediaDevices.isMultipleAudioInputSupported();
  103. return visible ? (
  104. <AudioSettingsPopup>
  105. <ToolboxButtonWithIcon
  106. ariaControls = 'audio-settings-dialog'
  107. ariaExpanded = { isOpen }
  108. ariaHasPopup = { true }
  109. ariaLabel = { t('toolbar.audioSettings') }
  110. buttonKey = { buttonKey }
  111. icon = { IconArrowUp }
  112. iconDisabled = { settingsDisabled }
  113. iconId = 'audio-settings-button'
  114. iconTooltip = { t('toolbar.audioSettings') }
  115. notifyMode = { notifyMode }
  116. onIconClick = { this._onClick }
  117. onIconKeyDown = { this._onEscClick }>
  118. <AudioMuteButton
  119. buttonKey = { buttonKey }
  120. notifyMode = { notifyMode } />
  121. </ToolboxButtonWithIcon>
  122. </AudioSettingsPopup>
  123. ) : <AudioMuteButton
  124. buttonKey = { buttonKey }
  125. notifyMode = { notifyMode } />;
  126. }
  127. }
  128. /**
  129. * Function that maps parts of Redux state tree into component props.
  130. *
  131. * @param {Object} state - Redux state.
  132. * @returns {Object}
  133. */
  134. function mapStateToProps(state: IReduxState) {
  135. const { permissions = { audio: false } } = state['features/base/devices'];
  136. const { isNarrowLayout } = state['features/base/responsive-ui'];
  137. return {
  138. hasPermissions: permissions.audio,
  139. isDisabled: Boolean(isAudioSettingsButtonDisabled(state)),
  140. isOpen: Boolean(getAudioSettingsVisibility(state)),
  141. visible: !isMobileBrowser() && !isNarrowLayout
  142. };
  143. }
  144. const mapDispatchToProps = {
  145. onAudioOptionsClick: toggleAudioSettings
  146. };
  147. export default translate(connect(
  148. mapStateToProps,
  149. mapDispatchToProps
  150. )(AudioSettingsButton));