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

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