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.

SecurityDialogButton.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  4. import {
  5. getFeatureFlag,
  6. LOBBY_MODE_ENABLED,
  7. MEETING_PASSWORD_ENABLED,
  8. SECURITY_OPTIONS_ENABLED
  9. } from '../../../base/flags';
  10. import { translate } from '../../../base/i18n';
  11. import { IconSecurityOff, IconSecurityOn } from '../../../base/icons';
  12. import { isLocalParticipantModerator } from '../../../base/participants';
  13. import { connect } from '../../../base/redux';
  14. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  15. import { toggleSecurityDialog } from '../../actions';
  16. type Props = AbstractButtonProps & {
  17. /**
  18. * Whether the shared document is being edited or not.
  19. */
  20. _locked: boolean,
  21. /**
  22. * The redux {@code dispatch} function.
  23. */
  24. dispatch: Dispatch<any>
  25. };
  26. /**
  27. * Implements an {@link AbstractButton} to open the security dialog.
  28. */
  29. class SecurityDialogButton extends AbstractButton<Props, *> {
  30. accessibilityLabel = 'toolbar.accessibilityLabel.security';
  31. icon = IconSecurityOff;
  32. label = 'toolbar.security';
  33. toggledIcon = IconSecurityOn;
  34. tooltip = 'toolbar.security';
  35. /**
  36. * Handles clicking / pressing the button, and opens / closes the appropriate dialog.
  37. *
  38. * @private
  39. * @returns {void}
  40. */
  41. _handleClick() {
  42. const { _locked, dispatch, handleClick } = this.props;
  43. if (handleClick) {
  44. handleClick();
  45. return;
  46. }
  47. sendAnalytics(createToolbarEvent('toggle.security', { enable: !_locked }));
  48. dispatch(toggleSecurityDialog());
  49. }
  50. /**
  51. * Indicates whether this button is in toggled state or not.
  52. *
  53. * @override
  54. * @returns {boolean}
  55. */
  56. _isToggled() {
  57. return this.props._locked;
  58. }
  59. }
  60. /**
  61. * Maps part of the redux state to the component's props.
  62. *
  63. * @param {Object} state - The redux store/state.
  64. * @returns {Props}
  65. */
  66. function mapStateToProps(state: Object) {
  67. const { conference } = state['features/base/conference'];
  68. const { hideLobbyButton } = state['features/base/config'];
  69. const { locked } = state['features/base/conference'];
  70. const { lobbyEnabled } = state['features/lobby'];
  71. const lobbySupported = conference && conference.isLobbySupported();
  72. const lobby = lobbySupported && isLocalParticipantModerator(state) && !hideLobbyButton;
  73. const enabledFlag = getFeatureFlag(state, SECURITY_OPTIONS_ENABLED, true);
  74. const enabledLobbyModeFlag = getFeatureFlag(state, LOBBY_MODE_ENABLED, true) && lobby;
  75. const enabledMeetingPassFlag = getFeatureFlag(state, MEETING_PASSWORD_ENABLED, true);
  76. return {
  77. _locked: locked || lobbyEnabled,
  78. visible: enabledFlag || (enabledLobbyModeFlag || enabledMeetingPassFlag)
  79. };
  80. }
  81. export default translate(connect(mapStateToProps)(SecurityDialogButton));