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

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