Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

AudioMuteButton.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // @flow
  2. import {
  3. ACTION_SHORTCUT_TRIGGERED,
  4. AUDIO_MUTE,
  5. createShortcutEvent,
  6. sendAnalytics
  7. } from '../../analytics';
  8. import { AUDIO_MUTE_BUTTON_ENABLED, getFeatureFlag } from '../../base/flags';
  9. import { translate } from '../../base/i18n';
  10. import { MEDIA_TYPE } from '../../base/media';
  11. import { connect } from '../../base/redux';
  12. import { AbstractAudioMuteButton, AbstractButton } from '../../base/toolbox/components';
  13. import type { AbstractButtonProps } from '../../base/toolbox/components';
  14. import { isLocalTrackMuted } from '../../base/tracks';
  15. import { muteLocal } from '../../video-menu/actions';
  16. import { isAudioMuteButtonDisabled } from '../functions';
  17. declare var APP: Object;
  18. /**
  19. * The type of the React {@code Component} props of {@link AudioMuteButton}.
  20. */
  21. type Props = AbstractButtonProps & {
  22. /**
  23. * Whether audio is currently muted or not.
  24. */
  25. _audioMuted: boolean,
  26. /**
  27. * Whether the button is disabled.
  28. */
  29. _disabled: boolean,
  30. /**
  31. * The redux {@code dispatch} function.
  32. */
  33. dispatch: Function
  34. }
  35. /**
  36. * Component that renders a toolbar button for toggling audio mute.
  37. *
  38. * @augments AbstractAudioMuteButton
  39. */
  40. class AudioMuteButton extends AbstractAudioMuteButton<Props, *> {
  41. accessibilityLabel = 'toolbar.accessibilityLabel.mute';
  42. label = 'toolbar.mute';
  43. tooltip = 'toolbar.mute';
  44. /**
  45. * Initializes a new {@code AudioMuteButton} instance.
  46. *
  47. * @param {Props} props - The read-only React {@code Component} props with
  48. * which the new instance is to be initialized.
  49. */
  50. constructor(props: Props) {
  51. super(props);
  52. // Bind event handlers so they are only bound once per instance.
  53. this._onKeyboardShortcut = this._onKeyboardShortcut.bind(this);
  54. }
  55. /**
  56. * Registers the keyboard shortcut that toggles the audio muting.
  57. *
  58. * @inheritdoc
  59. * @returns {void}
  60. */
  61. componentDidMount() {
  62. typeof APP === 'undefined'
  63. || APP.keyboardshortcut.registerShortcut(
  64. 'M',
  65. null,
  66. this._onKeyboardShortcut,
  67. 'keyboardShortcuts.mute');
  68. }
  69. /**
  70. * Unregisters the keyboard shortcut that toggles the audio muting.
  71. *
  72. * @inheritdoc
  73. * @returns {void}
  74. */
  75. componentWillUnmount() {
  76. typeof APP === 'undefined'
  77. || APP.keyboardshortcut.unregisterShortcut('M');
  78. }
  79. /**
  80. * Indicates if audio is currently muted or not.
  81. *
  82. * @override
  83. * @protected
  84. * @returns {boolean}
  85. */
  86. _isAudioMuted() {
  87. return this.props._audioMuted;
  88. }
  89. _onKeyboardShortcut: () => void;
  90. /**
  91. * Creates an analytics keyboard shortcut event and dispatches an action to
  92. * toggle the audio muting.
  93. *
  94. * @private
  95. * @returns {void}
  96. */
  97. _onKeyboardShortcut() {
  98. // Ignore keyboard shortcuts if the audio button is disabled.
  99. if (this._isDisabled()) {
  100. return;
  101. }
  102. sendAnalytics(
  103. createShortcutEvent(
  104. AUDIO_MUTE,
  105. ACTION_SHORTCUT_TRIGGERED,
  106. { enable: !this._isAudioMuted() }));
  107. AbstractButton.prototype._onClick.call(this);
  108. }
  109. /**
  110. * Changes the muted state.
  111. *
  112. * @param {boolean} audioMuted - Whether audio should be muted or not.
  113. * @protected
  114. * @returns {void}
  115. */
  116. _setAudioMuted(audioMuted: boolean) {
  117. this.props.dispatch(muteLocal(audioMuted, MEDIA_TYPE.AUDIO));
  118. }
  119. /**
  120. * Return a boolean value indicating if this button is disabled or not.
  121. *
  122. * @returns {boolean}
  123. */
  124. _isDisabled() {
  125. return this.props._disabled;
  126. }
  127. }
  128. /**
  129. * Maps (parts of) the redux state to the associated props for the
  130. * {@code AudioMuteButton} component.
  131. *
  132. * @param {Object} state - The Redux state.
  133. * @private
  134. * @returns {{
  135. * _audioMuted: boolean,
  136. * _disabled: boolean
  137. * }}
  138. */
  139. function _mapStateToProps(state): Object {
  140. const _audioMuted = isLocalTrackMuted(state['features/base/tracks'], MEDIA_TYPE.AUDIO);
  141. const _disabled = isAudioMuteButtonDisabled(state);
  142. const enabledFlag = getFeatureFlag(state, AUDIO_MUTE_BUTTON_ENABLED, true);
  143. return {
  144. _audioMuted,
  145. _disabled,
  146. visible: enabledFlag
  147. };
  148. }
  149. export default translate(connect(_mapStateToProps)(AudioMuteButton));