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

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