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.web.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // @flow
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import { connect } from 'react-redux';
  5. import UIEvents from '../../../../../service/UI/UIEvents';
  6. import {
  7. ACTION_SHORTCUT_TRIGGERED,
  8. VIDEO_MUTE,
  9. createShortcutEvent,
  10. sendAnalytics
  11. } from '../../../analytics';
  12. import { translate } from '../../../base/i18n';
  13. import { MEDIA_TYPE } from '../../../base/media';
  14. import { isLocalTrackMuted } from '../../../base/tracks';
  15. import AbstractVideoMuteButton from './AbstractVideoMuteButton';
  16. import ToolbarButton from '../ToolbarButton';
  17. declare var APP: Object;
  18. /**
  19. * Component that renders a toolbar button for toggling video mute.
  20. *
  21. * @extends AbstractVideoMuteButton
  22. */
  23. export class VideoMuteButton extends AbstractVideoMuteButton {
  24. /**
  25. * Default values for {@code VideoMuteButton} component's properties.
  26. *
  27. * @static
  28. */
  29. static defaultProps = {
  30. tooltipPosition: 'top'
  31. };
  32. /**
  33. * {@code VideoMuteButton} component's property types.
  34. *
  35. * @static
  36. */
  37. static propTypes = {
  38. ...AbstractVideoMuteButton.propTypes,
  39. /**
  40. * The {@code JitsiConference} for the current conference.
  41. */
  42. _conference: PropTypes.object,
  43. /**
  44. * Invoked to obtain translated strings.
  45. */
  46. t: PropTypes.func,
  47. /**
  48. * Where the tooltip should display, relative to the button.
  49. */
  50. tooltipPosition: PropTypes.string
  51. };
  52. /**
  53. * Initializes a new {@code VideoMuteButton} instance.
  54. *
  55. * @param {Props} props - The read-only React {@code Component} props with
  56. * which the new instance is to be initialized.
  57. */
  58. constructor(props: Object) {
  59. super(props);
  60. // Bind event handlers so they are only bound once per instance.
  61. this._onShortcutToggleVideo = this._onShortcutToggleVideo.bind(this);
  62. }
  63. /**
  64. * Sets a keyboard shortcuts for toggling video mute.
  65. *
  66. * @inheritdoc
  67. * @returns {void}
  68. */
  69. componentDidMount() {
  70. APP.keyboardshortcut.registerShortcut(
  71. 'V',
  72. null,
  73. this._onShortcutToggleVideo,
  74. 'keyboardShortcuts.videoMute');
  75. }
  76. /**
  77. * Removes the registered keyboard shortcut handler.
  78. *
  79. * @inheritdoc
  80. * @returns {void}
  81. */
  82. componentWillUnmount() {
  83. APP.keyboardshortcut.unregisterShortcut('V');
  84. }
  85. /**
  86. * Implements React's {@link Component#render()}.
  87. *
  88. * @inheritdoc
  89. * @returns {ReactElement}
  90. */
  91. render() {
  92. const { _conference, _videoMuted, t, tooltipPosition } = this.props;
  93. return (
  94. <ToolbarButton
  95. accessibilityLabel = 'Video mute'
  96. iconName = { _videoMuted && _conference
  97. ? 'icon-camera-disabled toggled'
  98. : 'icon-camera' }
  99. onClick = { this._onToolbarToggleVideo }
  100. tooltip = { t('toolbar.videomute') }
  101. tooltipPosition = { tooltipPosition } />
  102. );
  103. }
  104. _doToggleVideo: () => void;
  105. /**
  106. * Emits an event to signal video mute should be toggled.
  107. *
  108. * @private
  109. * @returns {void}
  110. */
  111. _doToggleVideo() {
  112. APP.UI.emitEvent(UIEvents.VIDEO_MUTED, !this.props._videoMuted);
  113. }
  114. _onShortcutToggleVideo: () => void;
  115. /**
  116. * Creates an analytics keyboard shortcut event for and dispatches an action
  117. * for toggling video mute.
  118. *
  119. * @private
  120. * @returns {void}
  121. */
  122. _onShortcutToggleVideo() {
  123. sendAnalytics(createShortcutEvent(
  124. VIDEO_MUTE,
  125. ACTION_SHORTCUT_TRIGGERED,
  126. { enable: !this.props._videoMuted }));
  127. this._doToggleVideo();
  128. }
  129. _onToolbarToggleVideo: () => void;
  130. }
  131. /**
  132. * Maps (parts of) the Redux state to the associated props for the
  133. * {@code AudioMuteButton} component.
  134. *
  135. * @param {Object} state - The Redux state.
  136. * @private
  137. * @returns {{
  138. * _conference: Object,
  139. * _videoMuted: boolean,
  140. * }}
  141. */
  142. function _mapStateToProps(state) {
  143. const tracks = state['features/base/tracks'];
  144. return {
  145. _conference: state['features/base/conference'].conference,
  146. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO)
  147. };
  148. }
  149. export default translate(connect(_mapStateToProps)(VideoMuteButton));