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.0KB

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