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.

VideoMuteButton.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import {
  4. VIDEO_MUTE,
  5. createToolbarEvent,
  6. sendAnalytics
  7. } from '../../analytics';
  8. import { translate } from '../../base/i18n';
  9. import {
  10. MEDIA_TYPE,
  11. VIDEO_MUTISM_AUTHORITY,
  12. setVideoMuted
  13. } from '../../base/media';
  14. import { AbstractVideoMuteButton } from '../../base/toolbox';
  15. import type { AbstractButtonProps } from '../../base/toolbox';
  16. import { isLocalTrackMuted } from '../../base/tracks';
  17. /**
  18. * The type of the React {@code Component} props of {@link VideoMuteButton}.
  19. */
  20. type Props = AbstractButtonProps & {
  21. /**
  22. * Whether the current conference is in audio only mode or not.
  23. */
  24. _audioOnly: boolean,
  25. /**
  26. * Whether video is currently muted or not.
  27. */
  28. _videoMuted: boolean,
  29. /**
  30. * The redux {@code dispatch} function.
  31. */
  32. dispatch: Function
  33. }
  34. /**
  35. * Component that renders a toolbar button for toggling video mute.
  36. *
  37. * @extends AbstractVideoMuteButton
  38. */
  39. class VideoMuteButton extends AbstractVideoMuteButton<Props, *> {
  40. label = 'toolbar.videomute';
  41. tooltip = 'toolbar.videomute';
  42. /**
  43. * Indicates if this button should be disabled or not.
  44. *
  45. * @override
  46. * @protected
  47. * @returns {boolean}
  48. */
  49. _isDisabled() {
  50. return this.props._audioOnly;
  51. }
  52. /**
  53. * Indicates if video is currently muted ot nor.
  54. *
  55. * @override
  56. * @protected
  57. * @returns {boolean}
  58. */
  59. _isVideoMuted() {
  60. return this.props._videoMuted;
  61. }
  62. /**
  63. * Changes the muted state.
  64. *
  65. * @override
  66. * @param {boolean} videoMuted - Whether video should be muted or not.
  67. * @protected
  68. * @returns {void}
  69. */
  70. _setVideoMuted(videoMuted: boolean) {
  71. sendAnalytics(createToolbarEvent(VIDEO_MUTE, { enable: videoMuted }));
  72. this.props.dispatch(
  73. setVideoMuted(
  74. videoMuted,
  75. VIDEO_MUTISM_AUTHORITY.USER,
  76. /* ensureTrack */ true));
  77. }
  78. }
  79. /**
  80. * Maps (parts of) the redux state to the associated props for the
  81. * {@code VideoMuteButton} component.
  82. *
  83. * @param {Object} state - The Redux state.
  84. * @private
  85. * @returns {{
  86. * _audioOnly: boolean,
  87. * _videoMuted: boolean
  88. * }}
  89. */
  90. function _mapStateToProps(state): Object {
  91. const { audioOnly } = state['features/base/conference'];
  92. const tracks = state['features/base/tracks'];
  93. return {
  94. _audioOnly: Boolean(audioOnly),
  95. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO)
  96. };
  97. }
  98. export default translate(connect(_mapStateToProps)(VideoMuteButton));