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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { sendAnalyticsEvent } from '../../analytics';
  5. import { translate } from '../../base/i18n';
  6. import { openDialog } from '../../base/dialog';
  7. import RemoteVideoMenuButton from './RemoteVideoMenuButton';
  8. import MuteRemoteParticipantDialog from './MuteRemoteParticipantDialog';
  9. /**
  10. * Implements a React {@link Component} which displays a button for audio muting
  11. * a participant in the conference.
  12. *
  13. * @extends Component
  14. */
  15. class MuteButton extends Component {
  16. /**
  17. * {@code MuteButton} component's property types.
  18. *
  19. * @static
  20. */
  21. static propTypes = {
  22. /**
  23. * Invoked to send a request for muting the participant with the passed
  24. * in participantID.
  25. */
  26. dispatch: PropTypes.func,
  27. /**
  28. * Whether or not the participant is currently audio muted.
  29. */
  30. isAudioMuted: PropTypes.bool,
  31. /**
  32. * Callback to invoke when {@code MuteButton} is clicked.
  33. */
  34. onClick: PropTypes.func,
  35. /**
  36. * The ID of the participant linked to the onClick callback.
  37. */
  38. participantID: PropTypes.string,
  39. /**
  40. * Invoked to obtain translated strings.
  41. */
  42. t: PropTypes.func
  43. };
  44. /**
  45. * Initializes a new {@code MuteButton} instance.
  46. *
  47. * @param {Object} props - The read-only React Component props with which
  48. * the new instance is to be initialized.
  49. */
  50. constructor(props) {
  51. super(props);
  52. // Bind event handlers so they are only bound once for every instance.
  53. this._onClick = this._onClick.bind(this);
  54. }
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. * @returns {ReactElement}
  60. */
  61. render() {
  62. const { isAudioMuted, participantID, t } = this.props;
  63. const muteConfig = isAudioMuted ? {
  64. translationKey: 'videothumbnail.muted',
  65. muteClassName: 'mutelink disabled'
  66. } : {
  67. translationKey: 'videothumbnail.domute',
  68. muteClassName: 'mutelink'
  69. };
  70. return (
  71. <RemoteVideoMenuButton
  72. buttonText = { t(muteConfig.translationKey) }
  73. displayClass = { muteConfig.muteClassName }
  74. iconClass = 'icon-mic-disabled'
  75. id = { `mutelink_${participantID}` }
  76. onClick = { this._onClick } />
  77. );
  78. }
  79. /**
  80. * Dispatches a request to mute the participant with the passed in
  81. * participantID.
  82. *
  83. * @private
  84. * @returns {void}
  85. */
  86. _onClick() {
  87. const { dispatch, onClick, participantID } = this.props;
  88. sendAnalyticsEvent(
  89. 'remotevideomenu.mute.clicked',
  90. {
  91. value: 1,
  92. label: participantID
  93. }
  94. );
  95. dispatch(openDialog(MuteRemoteParticipantDialog, { participantID }));
  96. if (onClick) {
  97. onClick();
  98. }
  99. }
  100. }
  101. export default translate(connect()(MuteButton));