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.

MuteButton.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import {
  4. createRemoteVideoMenuButtonEvent,
  5. sendAnalytics
  6. } from '../../../analytics';
  7. import { openDialog } from '../../../base/dialog';
  8. import { translate } from '../../../base/i18n';
  9. import { MEDIA_TYPE } from '../../../base/media';
  10. import {
  11. AbstractButton,
  12. type AbstractButtonProps
  13. } from '../../../base/toolbox';
  14. import { getTrackByMediaTypeAndParticipant } from '../../../base/tracks';
  15. import MuteRemoteParticipantDialog from './MuteRemoteParticipantDialog';
  16. type Props = AbstractButtonProps & {
  17. /**
  18. * The audio track of the participant.
  19. */
  20. _audioTrack: ?Object,
  21. /**
  22. * The redux {@code dispatch} function.
  23. */
  24. dispatch: Function,
  25. /**
  26. * The participant object that this button is supposed to mute/unmute.
  27. */
  28. participant: Object
  29. };
  30. /**
  31. * A remote video menu button which mutes the remote participant.
  32. */
  33. class MuteButton extends AbstractButton<Props, *> {
  34. accessibilityLabel = 'toolbar.accessibilityLabel.audioRoute';
  35. iconName = 'icon-mic-disabled';
  36. label = 'videothumbnail.domute';
  37. toggledLabel = 'videothumbnail.muted';
  38. /**
  39. * Handles clicking / pressing the button, and mutes the participant.
  40. *
  41. * @private
  42. * @returns {void}
  43. */
  44. _handleClick() {
  45. const { dispatch, participant } = this.props;
  46. sendAnalytics(createRemoteVideoMenuButtonEvent(
  47. 'mute.button',
  48. {
  49. 'participant_id': participant.id
  50. }));
  51. dispatch(openDialog(MuteRemoteParticipantDialog, { participant }));
  52. }
  53. /**
  54. * Renders the item disabled if the participant is muted.
  55. *
  56. * @inheritdoc
  57. */
  58. _isDisabled() {
  59. return this._isMuted();
  60. }
  61. /**
  62. * Returns true if the participant is muted, false otherwise.
  63. *
  64. * @returns {boolean}
  65. */
  66. _isMuted() {
  67. const { _audioTrack } = this.props;
  68. return !_audioTrack || _audioTrack.muted;
  69. }
  70. /**
  71. * Renders the item toggled if the participant is muted.
  72. *
  73. * @inheritdoc
  74. */
  75. _isToggled() {
  76. return this._isMuted();
  77. }
  78. }
  79. /**
  80. * Function that maps parts of Redux state tree into component props.
  81. *
  82. * @param {Object} state - Redux state.
  83. * @param {Object} ownProps - Properties of component.
  84. * @private
  85. * @returns {{
  86. * _audioTrack: Track
  87. * }}
  88. */
  89. function _mapStateToProps(state, ownProps) {
  90. const tracks = state['features/base/tracks'];
  91. const audioTrack
  92. = getTrackByMediaTypeAndParticipant(
  93. tracks, MEDIA_TYPE.AUDIO, ownProps.participant.id);
  94. return {
  95. _audioTrack: audioTrack
  96. };
  97. }
  98. export default translate(connect(_mapStateToProps)(MuteButton));