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.web.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // @flow
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import { connect } from 'react-redux';
  5. import {
  6. ACTION_SHORTCUT_TRIGGERED,
  7. AUDIO_MUTE,
  8. createShortcutEvent,
  9. sendAnalytics
  10. } from '../../../analytics';
  11. import { translate } from '../../../base/i18n';
  12. import { MEDIA_TYPE } from '../../../base/media';
  13. import { isLocalTrackMuted } from '../../../base/tracks';
  14. import AbstractAudioMuteButton from './AbstractAudioMuteButton';
  15. import ToolbarButtonV2 from '../ToolbarButtonV2';
  16. declare var APP: Object;
  17. /**
  18. * Component that renders a toolbar button for toggling audio mute.
  19. *
  20. * @extends Component
  21. */
  22. export class AudioMuteButton extends AbstractAudioMuteButton {
  23. /**
  24. * Default values for {@code AudioMuteButton} component's properties.
  25. *
  26. * @static
  27. */
  28. static defaultProps = {
  29. tooltipPosition: 'top'
  30. };
  31. /**
  32. * {@code AudioMuteButton} component's property types.
  33. *
  34. * @static
  35. */
  36. static propTypes = {
  37. ...AbstractAudioMuteButton.propTypes,
  38. /**
  39. * The {@code JitsiConference} for the current conference.
  40. */
  41. _conference: PropTypes.object,
  42. /**
  43. * Invoked to update the audio mute status.
  44. */
  45. dispatch: PropTypes.func,
  46. /**
  47. * Invoked to obtain translated strings.
  48. */
  49. t: PropTypes.func,
  50. /**
  51. * Where the tooltip should display, relative to the button.
  52. */
  53. tooltipPosition: PropTypes.string
  54. };
  55. /**
  56. * Initializes a new {@code AudioMuteButton} instance.
  57. *
  58. * @param {Props} props - The read-only React {@code Component} props with
  59. * which the new instance is to be initialized.
  60. */
  61. constructor(props: Object) {
  62. super(props);
  63. // Bind event handlers so it is only bound once per instance.
  64. this._onShortcutToggleAudio = this._onShortcutToggleAudio.bind(this);
  65. }
  66. /**
  67. * Sets a keyboard shortcuts for toggling audio mute.
  68. *
  69. * @inheritdoc
  70. * @returns {void}
  71. */
  72. componentDidMount() {
  73. APP.keyboardshortcut.registerShortcut(
  74. 'M',
  75. null,
  76. this._onShortcutToggleAudio,
  77. 'keyboardShortcuts.mute');
  78. }
  79. /**
  80. * Removes the registered keyboard shortcut handler.
  81. *
  82. * @inheritdoc
  83. * @returns {void}
  84. */
  85. componentWillUnmount() {
  86. APP.keyboardshortcut.unregisterShortcut('M');
  87. }
  88. /**
  89. * Implements React's {@link Component#render()}.
  90. *
  91. * @inheritdoc
  92. * @returns {ReactElement}
  93. */
  94. render() {
  95. const { _audioMuted, _conference, t, tooltipPosition } = this.props;
  96. return (
  97. <ToolbarButtonV2
  98. iconName = { _audioMuted && _conference
  99. ? 'icon-mic-disabled toggled'
  100. : 'icon-microphone' }
  101. onClick = { this._onToolbarToggleAudio }
  102. tooltip = { t('toolbar.mute') }
  103. tooltipPosition = { tooltipPosition } />
  104. );
  105. }
  106. _doToggleAudio: () => void;
  107. _onShortcutToggleAudio: () => void;
  108. /**
  109. * Creates an analytics keyboard shortcut event and dispatches an action for
  110. * toggling audio mute.
  111. *
  112. * @private
  113. * @returns {void}
  114. */
  115. _onShortcutToggleAudio() {
  116. sendAnalytics(createShortcutEvent(
  117. AUDIO_MUTE,
  118. ACTION_SHORTCUT_TRIGGERED,
  119. { enable: !this.props._audioMuted }));
  120. this._doToggleAudio();
  121. }
  122. _onToolbarToggleAudio: () => void;
  123. }
  124. /**
  125. * Maps (parts of) the Redux state to the associated props for the
  126. * {@code AudioMuteButton} component.
  127. *
  128. * @param {Object} state - The Redux state.
  129. * @private
  130. * @returns {{
  131. * _audioMuted: boolean,
  132. * _conference: Object,
  133. * }}
  134. */
  135. function _mapStateToProps(state) {
  136. const tracks = state['features/base/tracks'];
  137. return {
  138. _audioMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.AUDIO),
  139. _conference: state['features/base/conference'].conference
  140. };
  141. }
  142. export default translate(connect(_mapStateToProps)(AudioMuteButton));