Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AbstractAudioMuteButton.tsx 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { IReduxState } from '../../app/types';
  2. import { AUDIO_MUTE_BUTTON_ENABLED } from '../../base/flags/constants';
  3. import { getFeatureFlag } from '../../base/flags/functions';
  4. import { MEDIA_TYPE } from '../../base/media/constants';
  5. import { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
  6. import BaseAudioMuteButton from '../../base/toolbox/components/BaseAudioMuteButton';
  7. import { isLocalTrackMuted } from '../../base/tracks/functions';
  8. import { muteLocal } from '../../video-menu/actions';
  9. import { isAudioMuteButtonDisabled } from '../functions';
  10. /**
  11. * The type of the React {@code Component} props of {@link AbstractAudioMuteButton}.
  12. */
  13. export interface IProps extends AbstractButtonProps {
  14. /**
  15. * Whether audio is currently muted or not.
  16. */
  17. _audioMuted: boolean;
  18. /**
  19. * Whether the button is disabled.
  20. */
  21. _disabled: boolean;
  22. }
  23. /**
  24. * Component that renders a toolbar button for toggling audio mute.
  25. *
  26. * @augments BaseAudioMuteButton
  27. */
  28. export default class AbstractAudioMuteButton<P extends IProps> extends BaseAudioMuteButton<P> {
  29. accessibilityLabel = 'toolbar.accessibilityLabel.mute';
  30. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.unmute';
  31. label = 'toolbar.mute';
  32. tooltip = 'toolbar.mute';
  33. toggledTooltip = 'toolbar.unmute';
  34. /**
  35. * Indicates if audio is currently muted or not.
  36. *
  37. * @override
  38. * @protected
  39. * @returns {boolean}
  40. */
  41. _isAudioMuted() {
  42. return this.props._audioMuted;
  43. }
  44. /**
  45. * Changes the muted state.
  46. *
  47. * @param {boolean} audioMuted - Whether audio should be muted or not.
  48. * @protected
  49. * @returns {void}
  50. */
  51. _setAudioMuted(audioMuted: boolean) {
  52. this.props.dispatch(muteLocal(audioMuted, MEDIA_TYPE.AUDIO));
  53. }
  54. /**
  55. * Return a boolean value indicating if this button is disabled or not.
  56. *
  57. * @returns {boolean}
  58. */
  59. _isDisabled() {
  60. return this.props._disabled;
  61. }
  62. }
  63. /**
  64. * Maps (parts of) the redux state to the associated props for the
  65. * {@code AbstractAudioMuteButton} component.
  66. *
  67. * @param {Object} state - The Redux state.
  68. * @private
  69. * @returns {{
  70. * _audioMuted: boolean,
  71. * _disabled: boolean
  72. * }}
  73. */
  74. export function mapStateToProps(state: IReduxState) {
  75. const _audioMuted = isLocalTrackMuted(state['features/base/tracks'], MEDIA_TYPE.AUDIO);
  76. const _disabled = isAudioMuteButtonDisabled(state);
  77. const enabledFlag = getFeatureFlag(state, AUDIO_MUTE_BUTTON_ENABLED, true);
  78. return {
  79. _audioMuted,
  80. _disabled,
  81. visible: enabledFlag
  82. };
  83. }