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.

VideoSettingsButton.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { isMobileBrowser } from '../../../base/environment/utils';
  4. import { translate } from '../../../base/i18n';
  5. import { IconArrowUp } from '../../../base/icons';
  6. import { connect } from '../../../base/redux';
  7. import { ToolboxButtonWithIcon } from '../../../base/toolbox/components';
  8. import { getLocalJitsiVideoTrack } from '../../../base/tracks';
  9. import { toggleVideoSettings, VideoSettingsPopup } from '../../../settings';
  10. import { getVideoSettingsVisibility } from '../../../settings/functions';
  11. import { isVideoSettingsButtonDisabled } from '../../functions';
  12. import VideoMuteButton from '../VideoMuteButton';
  13. type Props = {
  14. /**
  15. * External handler for click action.
  16. */
  17. handleClick: Function,
  18. /**
  19. * Click handler for the small icon. Opens video options.
  20. */
  21. onVideoOptionsClick: Function,
  22. /**
  23. * Indicates whether video permissions have been granted or denied.
  24. */
  25. hasPermissions: boolean,
  26. /**
  27. * Whether there is a video track or not.
  28. */
  29. hasVideoTrack: boolean,
  30. /**
  31. * If the button should be disabled
  32. */
  33. isDisabled: boolean,
  34. /**
  35. * Flag controlling the visibility of the button.
  36. * VideoSettings popup is currently disabled on mobile browsers
  37. * as mobile devices do not support capture of more than one
  38. * camera at a time.
  39. */
  40. visible: boolean,
  41. /**
  42. * Used for translation
  43. */
  44. t: Function,
  45. /**
  46. * Defines is popup is open
  47. */
  48. isOpen: boolean
  49. };
  50. /**
  51. * Button used for video & video settings.
  52. *
  53. * @returns {ReactElement}
  54. */
  55. class VideoSettingsButton extends Component<Props> {
  56. /**
  57. * Initializes a new {@code VideoSettingsButton} instance.
  58. *
  59. * @inheritdoc
  60. */
  61. constructor(props: Props) {
  62. super(props);
  63. this._onEscClick = this._onEscClick.bind(this);
  64. this._onClick = this._onClick.bind(this);
  65. }
  66. /**
  67. * Returns true if the settings icon is disabled.
  68. *
  69. * @returns {boolean}
  70. */
  71. _isIconDisabled() {
  72. const { hasPermissions, hasVideoTrack, isDisabled } = this.props;
  73. return (!hasPermissions || isDisabled) && !hasVideoTrack;
  74. }
  75. _onEscClick: (KeyboardEvent) => void;
  76. /**
  77. * Click handler for the more actions entries.
  78. *
  79. * @param {KeyboardEvent} event - Esc key click to close the popup.
  80. * @returns {void}
  81. */
  82. _onEscClick(event) {
  83. if (event.key === 'Escape' && this.props.isOpen) {
  84. event.preventDefault();
  85. event.stopPropagation();
  86. this._onClick();
  87. }
  88. }
  89. _onClick: () => void;
  90. /**
  91. * Click handler for the more actions entries.
  92. *
  93. * @returns {void}
  94. */
  95. _onClick() {
  96. const { handleClick, onVideoOptionsClick } = this.props;
  97. if (handleClick) {
  98. handleClick();
  99. return;
  100. }
  101. onVideoOptionsClick();
  102. }
  103. /**
  104. * Implements React's {@link Component#render}.
  105. *
  106. * @inheritdoc
  107. */
  108. render() {
  109. const { handleClick, t, visible, isOpen } = this.props;
  110. return visible ? (
  111. <VideoSettingsPopup>
  112. <ToolboxButtonWithIcon
  113. ariaControls = 'video-settings-dialog'
  114. ariaExpanded = { isOpen }
  115. ariaHasPopup = { true }
  116. ariaLabel = { this.props.t('toolbar.videoSettings') }
  117. icon = { IconArrowUp }
  118. iconDisabled = { this._isIconDisabled() }
  119. iconId = 'video-settings-button'
  120. iconTooltip = { t('toolbar.videoSettings') }
  121. onIconClick = { this._onClick }
  122. onIconKeyDown = { this._onEscClick }>
  123. <VideoMuteButton handleClick = { handleClick } />
  124. </ToolboxButtonWithIcon>
  125. </VideoSettingsPopup>
  126. ) : <VideoMuteButton handleClick = { handleClick } />;
  127. }
  128. }
  129. /**
  130. * Function that maps parts of Redux state tree into component props.
  131. *
  132. * @param {Object} state - Redux state.
  133. * @returns {Object}
  134. */
  135. function mapStateToProps(state) {
  136. const { permissions = {} } = state['features/base/devices'];
  137. return {
  138. hasPermissions: permissions.video,
  139. hasVideoTrack: Boolean(getLocalJitsiVideoTrack(state)),
  140. isDisabled: isVideoSettingsButtonDisabled(state),
  141. isOpen: getVideoSettingsVisibility(state),
  142. visible: !isMobileBrowser()
  143. };
  144. }
  145. const mapDispatchToProps = {
  146. onVideoOptionsClick: toggleVideoSettings
  147. };
  148. export default translate(connect(
  149. mapStateToProps,
  150. mapDispatchToProps,
  151. )(VideoSettingsButton));