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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.unmute';
  43. label = 'toolbar.mute';
  44. tooltip = 'toolbar.mute';
  45. toggledTooltip = 'toolbar.unmute';
  46. /**
  47. * Initializes a new {@code AudioMuteButton} instance.
  48. *
  49. * @param {Props} props - The read-only React {@code Component} props with
  50. * which the new instance is to be initialized.
  51. */
  52. constructor(props: Props) {
  53. super(props);
  54. // Bind event handlers so they are only bound once per instance.
  55. this._onKeyboardShortcut = this._onKeyboardShortcut.bind(this);
  56. }
  57. /**
  58. * Registers the keyboard shortcut that toggles the audio muting.
  59. *
  60. * @inheritdoc
  61. * @returns {void}
  62. */
  63. componentDidMount() {
  64. typeof APP === 'undefined'
  65. || APP.keyboardshortcut.registerShortcut(
  66. 'M',
  67. null,
  68. this._onKeyboardShortcut,
  69. 'keyboardShortcuts.mute');
  70. }
  71. /**
  72. * Unregisters the keyboard shortcut that toggles the audio muting.
  73. *
  74. * @inheritdoc
  75. * @returns {void}
  76. */
  77. componentWillUnmount() {
  78. typeof APP === 'undefined'
  79. || APP.keyboardshortcut.unregisterShortcut('M');
  80. }
  81. /**
  82. * Indicates if audio is currently muted or not.
  83. *
  84. * @override
  85. * @protected
  86. * @returns {boolean}
  87. */
  88. _isAudioMuted() {
  89. return this.props._audioMuted;
  90. }
  91. _onKeyboardShortcut: () => void;
  92. /**
  93. * Creates an analytics keyboard shortcut event and dispatches an action to
  94. * toggle the audio muting.
  95. *
  96. * @private
  97. * @returns {void}
  98. */
  99. _onKeyboardShortcut() {
  100. // Ignore keyboard shortcuts if the audio button is disabled.
  101. if (this._isDisabled()) {
  102. return;
  103. }
  104. sendAnalytics(
  105. createShortcutEvent(
  106. AUDIO_MUTE,
  107. ACTION_SHORTCUT_TRIGGERED,
  108. { enable: !this._isAudioMuted() }));
  109. AbstractButton.prototype._onClick.call(this);
  110. }
  111. /**
  112. * Changes the muted state.
  113. *
  114. * @param {boolean} audioMuted - Whether audio should be muted or not.
  115. * @protected
  116. * @returns {void}
  117. */
  118. _setAudioMuted(audioMuted: boolean) {
  119. this.props.dispatch(muteLocal(audioMuted, MEDIA_TYPE.AUDIO));
  120. }
  121. /**
  122. * Return a boolean value indicating if this button is disabled or not.
  123. *
  124. * @returns {boolean}
  125. */
  126. _isDisabled() {
  127. return this.props._disabled;
  128. }
  129. }
  130. /**
  131. * Maps (parts of) the redux state to the associated props for the
  132. * {@code AudioMuteButton} component.
  133. *
  134. * @param {Object} state - The Redux state.
  135. * @private
  136. * @returns {{
  137. * _audioMuted: boolean,
  138. * _disabled: boolean
  139. * }}
  140. */
  141. function _mapStateToProps(state): Object {
  142. const _audioMuted = isLocalTrackMuted(state['features/base/tracks'], MEDIA_TYPE.AUDIO);
  143. const _disabled = isAudioMuteButtonDisabled(state);
  144. const enabledFlag = getFeatureFlag(state, AUDIO_MUTE_BUTTON_ENABLED, true);
  145. return {
  146. _audioMuted,
  147. _disabled,
  148. visible: enabledFlag
  149. };
  150. }
  151. export default translate(connect(_mapStateToProps)(AudioMuteButton));