You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AudioMuteButton.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import {
  4. AUDIO_MUTE,
  5. createToolbarEvent,
  6. sendAnalytics
  7. } from '../../analytics';
  8. import { translate } from '../../base/i18n';
  9. import { MEDIA_TYPE, setAudioMuted } from '../../base/media';
  10. import { AbstractAudioMuteButton } from '../../base/toolbox';
  11. import type { AbstractButtonProps } from '../../base/toolbox';
  12. import { isLocalTrackMuted } from '../../base/tracks';
  13. type Props = AbstractButtonProps & {
  14. /**
  15. * Whether audio is currently muted or not.
  16. */
  17. _audioMuted: boolean,
  18. /**
  19. * The redux {@code dispatch} function.
  20. */
  21. dispatch: Function
  22. }
  23. /**
  24. * Component that renders a toolbar button for toggling audio mute.
  25. *
  26. * @extends AbstractAudioMuteButton
  27. */
  28. class AudioMuteButton extends AbstractAudioMuteButton<Props, *> {
  29. label = 'toolbar.mute';
  30. tooltip = 'toolbar.mute';
  31. /**
  32. * Indicates if audio is currently muted ot nor.
  33. *
  34. * @override
  35. * @private
  36. * @returns {boolean}
  37. */
  38. _isAudioMuted() {
  39. return this.props._audioMuted;
  40. }
  41. /**
  42. * Changes the muted state.
  43. *
  44. * @param {boolean} audioMuted - Whether audio should be muted or not.
  45. * @private
  46. * @returns {void}
  47. */
  48. _setAudioMuted(audioMuted: boolean) {
  49. sendAnalytics(createToolbarEvent(AUDIO_MUTE, { enable: audioMuted }));
  50. this.props.dispatch(setAudioMuted(audioMuted));
  51. }
  52. }
  53. /**
  54. * Maps (parts of) the redux state to the associated props for the
  55. * {@code AudioMuteButton} component.
  56. *
  57. * @param {Object} state - The Redux state.
  58. * @private
  59. * @returns {{
  60. * _audioMuted: boolean
  61. * }}
  62. */
  63. function _mapStateToProps(state): Object {
  64. const tracks = state['features/base/tracks'];
  65. return {
  66. _audioMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.AUDIO)
  67. };
  68. }
  69. export default translate(connect(_mapStateToProps)(AudioMuteButton));