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

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