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

AudioMuteButton.js 4.2KB

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