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 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /**
  14. * The type of the React {@code Component} props of {@link AudioMuteButton}.
  15. */
  16. type Props = AbstractButtonProps & {
  17. /**
  18. * Whether audio is currently muted or not.
  19. */
  20. _audioMuted: boolean,
  21. /**
  22. * The redux {@code dispatch} function.
  23. */
  24. dispatch: Function
  25. }
  26. /**
  27. * Component that renders a toolbar button for toggling audio mute.
  28. *
  29. * @extends AbstractAudioMuteButton
  30. */
  31. class AudioMuteButton extends AbstractAudioMuteButton<Props, *> {
  32. label = 'toolbar.mute';
  33. tooltip = 'toolbar.mute';
  34. /**
  35. * Indicates if audio is currently muted ot nor.
  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. sendAnalytics(createToolbarEvent(AUDIO_MUTE, { enable: audioMuted }));
  53. this.props.dispatch(setAudioMuted(audioMuted));
  54. }
  55. }
  56. /**
  57. * Maps (parts of) the redux state to the associated props for the
  58. * {@code AudioMuteButton} component.
  59. *
  60. * @param {Object} state - The Redux state.
  61. * @private
  62. * @returns {{
  63. * _audioMuted: boolean
  64. * }}
  65. */
  66. function _mapStateToProps(state): Object {
  67. const tracks = state['features/base/tracks'];
  68. return {
  69. _audioMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.AUDIO)
  70. };
  71. }
  72. export default translate(connect(_mapStateToProps)(AudioMuteButton));