您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VideoMuteButton.js 2.5KB

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