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

VideoMuteButton.js 5.3KB

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