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

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