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.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. * The button's key.
  16. */
  17. buttonKey?: string,
  18. /**
  19. * External handler for click action.
  20. */
  21. handleClick: Function,
  22. /**
  23. * Indicates whether audio permissions have been granted or denied.
  24. */
  25. hasPermissions: boolean,
  26. /**
  27. * Click handler for the small icon. Opens audio options.
  28. */
  29. onAudioOptionsClick: Function,
  30. /**
  31. * If the button should be disabled.
  32. */
  33. isDisabled: boolean,
  34. /**
  35. * Notify mode for `toolbarButtonClicked` event -
  36. * whether to only notify or to also prevent button click routine.
  37. */
  38. notifyMode?: string,
  39. /**
  40. * Used for translation.
  41. */
  42. t: Function,
  43. /**
  44. * Flag controlling the visibility of the button.
  45. * AudioSettings popup is disabled on mobile browsers.
  46. */
  47. visible: boolean,
  48. /**
  49. * Defines is popup is open.
  50. */
  51. isOpen: boolean,
  52. };
  53. /**
  54. * Button used for audio & audio settings.
  55. *
  56. * @returns {ReactElement}
  57. */
  58. class AudioSettingsButton extends Component<Props> {
  59. /**
  60. * Initializes a new {@code AudioSettingsButton} instance.
  61. *
  62. * @inheritdoc
  63. */
  64. constructor(props: Props) {
  65. super(props);
  66. this._onEscClick = this._onEscClick.bind(this);
  67. this._onClick = this._onClick.bind(this);
  68. }
  69. _onEscClick: (KeyboardEvent) => void;
  70. /**
  71. * Click handler for the more actions entries.
  72. *
  73. * @param {KeyboardEvent} event - Esc key click to close the popup.
  74. * @returns {void}
  75. */
  76. _onEscClick(event) {
  77. if (event.key === 'Escape' && this.props.isOpen) {
  78. event.preventDefault();
  79. event.stopPropagation();
  80. this._onClick();
  81. }
  82. }
  83. _onClick: () => void;
  84. /**
  85. * Click handler for the more actions entries.
  86. *
  87. * @returns {void}
  88. */
  89. _onClick() {
  90. const { onAudioOptionsClick } = this.props;
  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) {
  135. const { permissions = {} } = state['features/base/devices'];
  136. const { isNarrowLayout } = state['features/base/responsive-ui'];
  137. return {
  138. hasPermissions: permissions.audio,
  139. isDisabled: isAudioSettingsButtonDisabled(state),
  140. isOpen: 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));