Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AudioSettingsButton.tsx 5.0KB

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