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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 this button should be disabled or not.
  33. *
  34. * @override
  35. * @private
  36. * @returns {boolean}
  37. */
  38. _isDisabled() {
  39. return false;
  40. }
  41. /**
  42. * Indicates if audio is currently muted ot nor.
  43. *
  44. * @override
  45. * @private
  46. * @returns {boolean}
  47. */
  48. _isAudioMuted() {
  49. return this.props._audioMuted;
  50. }
  51. /**
  52. * Changes the muted state.
  53. *
  54. * @param {boolean} audioMuted - Whether audio should be muted or not.
  55. * @private
  56. * @returns {void}
  57. */
  58. _setAudioMuted(audioMuted: boolean) {
  59. sendAnalytics(createToolbarEvent(AUDIO_MUTE, { enable: audioMuted }));
  60. this.props.dispatch(setAudioMuted(audioMuted));
  61. }
  62. }
  63. /**
  64. * Maps (parts of) the redux state to the associated props for the
  65. * {@code AudioMuteButton} component.
  66. *
  67. * @param {Object} state - The Redux state.
  68. * @private
  69. * @returns {{
  70. * _audioMuted: boolean
  71. * }}
  72. */
  73. function _mapStateToProps(state): Object {
  74. const tracks = state['features/base/tracks'];
  75. return {
  76. _audioMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.AUDIO)
  77. };
  78. }
  79. export default translate(connect(_mapStateToProps)(AudioMuteButton));