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

VideoMuteButton.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import {
  4. ACTION_SHORTCUT_TRIGGERED,
  5. VIDEO_MUTE,
  6. createShortcutEvent,
  7. createToolbarEvent,
  8. sendAnalytics
  9. } from '../../analytics';
  10. import { translate } from '../../base/i18n';
  11. import {
  12. MEDIA_TYPE,
  13. VIDEO_MUTISM_AUTHORITY,
  14. setVideoMuted
  15. } from '../../base/media';
  16. import { AbstractVideoMuteButton } from '../../base/toolbox';
  17. import type { AbstractButtonProps } from '../../base/toolbox';
  18. import { isLocalTrackMuted } from '../../base/tracks';
  19. import UIEvents from '../../../../service/UI/UIEvents';
  20. declare var APP: Object;
  21. /**
  22. * The type of the React {@code Component} props of {@link VideoMuteButton}.
  23. */
  24. type Props = AbstractButtonProps & {
  25. /**
  26. * Whether the current conference is in audio only mode or not.
  27. */
  28. _audioOnly: boolean,
  29. /**
  30. * Whether video is currently muted or not.
  31. */
  32. _videoMuted: boolean,
  33. /**
  34. * The redux {@code dispatch} function.
  35. */
  36. dispatch: Function
  37. }
  38. /**
  39. * Component that renders a toolbar button for toggling video mute.
  40. *
  41. * @extends AbstractVideoMuteButton
  42. */
  43. class VideoMuteButton extends AbstractVideoMuteButton<Props, *> {
  44. accessibilityLabel = 'toolbar.accessibilityLabel.videomute';
  45. label = 'toolbar.videomute';
  46. tooltip = 'toolbar.videomute';
  47. /**
  48. * Initializes a new {@code VideoMuteButton} instance.
  49. *
  50. * @param {Props} props - The read-only React {@code Component} props with
  51. * which the new instance is to be initialized.
  52. */
  53. constructor(props: Props) {
  54. super(props);
  55. // Bind event handlers so they are only bound once per instance.
  56. this._onKeyboardShortcut = this._onKeyboardShortcut.bind(this);
  57. }
  58. /**
  59. * Registers the keyboard shortcut that toggles the video muting.
  60. *
  61. * @inheritdoc
  62. * @returns {void}
  63. */
  64. componentDidMount() {
  65. typeof APP === 'undefined'
  66. || APP.keyboardshortcut.registerShortcut(
  67. 'V',
  68. null,
  69. this._onKeyboardShortcut,
  70. 'keyboardShortcuts.videoMute');
  71. }
  72. /**
  73. * Unregisters the keyboard shortcut that toggles the video muting.
  74. *
  75. * @inheritdoc
  76. * @returns {void}
  77. */
  78. componentWillUnmount() {
  79. typeof APP === 'undefined'
  80. || APP.keyboardshortcut.unregisterShortcut('V');
  81. }
  82. /**
  83. * Indicates if this button should be disabled or not.
  84. *
  85. * @override
  86. * @protected
  87. * @returns {boolean}
  88. */
  89. _isDisabled() {
  90. return this.props._audioOnly;
  91. }
  92. /**
  93. * Indicates if video is currently muted ot nor.
  94. *
  95. * @override
  96. * @protected
  97. * @returns {boolean}
  98. */
  99. _isVideoMuted() {
  100. return this.props._videoMuted;
  101. }
  102. _onKeyboardShortcut: () => void;
  103. /**
  104. * Creates an analytics keyboard shortcut event and dispatches an action to
  105. * toggle the video muting.
  106. *
  107. * @private
  108. * @returns {void}
  109. */
  110. _onKeyboardShortcut() {
  111. sendAnalytics(
  112. createShortcutEvent(
  113. VIDEO_MUTE,
  114. ACTION_SHORTCUT_TRIGGERED,
  115. { enable: !this._isVideoMuted() }));
  116. super._handleClick();
  117. }
  118. /**
  119. * Changes the muted state.
  120. *
  121. * @override
  122. * @param {boolean} videoMuted - Whether video should be muted or not.
  123. * @protected
  124. * @returns {void}
  125. */
  126. _setVideoMuted(videoMuted: boolean) {
  127. sendAnalytics(createToolbarEvent(VIDEO_MUTE, { enable: videoMuted }));
  128. this.props.dispatch(
  129. setVideoMuted(
  130. videoMuted,
  131. VIDEO_MUTISM_AUTHORITY.USER,
  132. /* ensureTrack */ true));
  133. // FIXME: The old conference logic still relies on this event being
  134. // emitted.
  135. typeof APP === 'undefined'
  136. || APP.UI.emitEvent(UIEvents.VIDEO_MUTED, videoMuted, true);
  137. }
  138. }
  139. /**
  140. * Maps (parts of) the redux state to the associated props for the
  141. * {@code VideoMuteButton} component.
  142. *
  143. * @param {Object} state - The Redux state.
  144. * @private
  145. * @returns {{
  146. * _audioOnly: boolean,
  147. * _videoMuted: boolean
  148. * }}
  149. */
  150. function _mapStateToProps(state): Object {
  151. const { audioOnly } = state['features/base/conference'];
  152. const tracks = state['features/base/tracks'];
  153. return {
  154. _audioOnly: Boolean(audioOnly),
  155. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO)
  156. };
  157. }
  158. export default translate(connect(_mapStateToProps)(VideoMuteButton));