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

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