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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 { isVideoSettingsButtonDisabled } from '../../functions';
  11. import VideoMuteButton from '../VideoMuteButton';
  12. type Props = {
  13. /**
  14. * Click handler for the small icon. Opens video options.
  15. */
  16. onVideoOptionsClick: Function,
  17. /**
  18. * Indicates whether video permissions have been granted or denied.
  19. */
  20. hasPermissions: boolean,
  21. /**
  22. * Whether there is a video track or not.
  23. */
  24. hasVideoTrack: boolean,
  25. /**
  26. * If the button should be disabled
  27. */
  28. isDisabled: boolean,
  29. /**
  30. * Flag controlling the visibility of the button.
  31. * VideoSettings popup is currently disabled on mobile browsers
  32. * as mobile devices do not support capture of more than one
  33. * camera at a time.
  34. */
  35. visible: boolean,
  36. /**
  37. * Used for translation
  38. */
  39. t: Function
  40. };
  41. /**
  42. * Button used for video & video settings.
  43. *
  44. * @returns {ReactElement}
  45. */
  46. class VideoSettingsButton extends Component<Props> {
  47. /**
  48. * Returns true if the settings icon is disabled.
  49. *
  50. * @returns {boolean}
  51. */
  52. _isIconDisabled() {
  53. const { hasPermissions, hasVideoTrack, isDisabled } = this.props;
  54. return (!hasPermissions || isDisabled) && !hasVideoTrack;
  55. }
  56. /**
  57. * Implements React's {@link Component#render}.
  58. *
  59. * @inheritdoc
  60. */
  61. render() {
  62. const { onVideoOptionsClick, t, visible } = this.props;
  63. return visible ? (
  64. <VideoSettingsPopup>
  65. <ToolboxButtonWithIcon
  66. icon = { IconArrowUp }
  67. iconDisabled = { this._isIconDisabled() }
  68. iconTooltip = { t('toolbar.videoSettings') }
  69. onIconClick = { onVideoOptionsClick }>
  70. <VideoMuteButton />
  71. </ToolboxButtonWithIcon>
  72. </VideoSettingsPopup>
  73. ) : <VideoMuteButton />;
  74. }
  75. }
  76. /**
  77. * Function that maps parts of Redux state tree into component props.
  78. *
  79. * @param {Object} state - Redux state.
  80. * @returns {Object}
  81. */
  82. function mapStateToProps(state) {
  83. const { permissions = {} } = state['features/base/devices'];
  84. return {
  85. hasPermissions: permissions.video,
  86. hasVideoTrack: Boolean(getLocalJitsiVideoTrack(state)),
  87. isDisabled: isVideoSettingsButtonDisabled(state),
  88. visible: !isMobileBrowser()
  89. };
  90. }
  91. const mapDispatchToProps = {
  92. onVideoOptionsClick: toggleVideoSettings
  93. };
  94. export default translate(connect(
  95. mapStateToProps,
  96. mapDispatchToProps,
  97. )(VideoSettingsButton));