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.

RoomLockButton.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import { translate } from '../../base/i18n';
  4. import { isLocalParticipantModerator } from '../../base/participants';
  5. import { AbstractButton } from '../../base/toolbox';
  6. import type { AbstractButtonProps } from '../../base/toolbox';
  7. import { beginRoomLockRequest, unlockRoom } from '../actions';
  8. type Props = AbstractButtonProps & {
  9. /**
  10. * Whether the current local participant is a moderator, therefore is
  11. * allowed to lock or unlock the conference.
  12. */
  13. _localParticipantModerator: boolean,
  14. /**
  15. * Whether the current conference is locked or not.
  16. */
  17. _locked: boolean,
  18. /**
  19. * The redux {@code dispatch} function.
  20. */
  21. dispatch: Function
  22. };
  23. /**
  24. * An implementation of a button for locking / unlocking a room.
  25. */
  26. class RoomLockButton extends AbstractButton<Props, *> {
  27. accessibilityLabel = 'toolbar.accessibilityLabel.lockRoom';
  28. iconName = 'security';
  29. label = 'dialog.lockRoom';
  30. toggledIconName = 'security-locked';
  31. toggledLabel = 'dialog.unlockRoom';
  32. /**
  33. * Handles clicking / pressing the button.
  34. *
  35. * @override
  36. * @protected
  37. * @returns {void}
  38. */
  39. _handleClick() {
  40. const { dispatch, _locked } = this.props;
  41. if (_locked) {
  42. dispatch(unlockRoom());
  43. } else {
  44. dispatch(beginRoomLockRequest());
  45. }
  46. }
  47. /**
  48. * Indicates whether this button is disabled or not.
  49. *
  50. * @override
  51. * @protected
  52. * @returns {boolean}
  53. */
  54. _isDisabled() {
  55. return !this.props._localParticipantModerator;
  56. }
  57. /**
  58. * Indicates whether this button is in toggled state or not.
  59. *
  60. * @override
  61. * @protected
  62. * @returns {boolean}
  63. */
  64. _isToggled() {
  65. return this.props._locked;
  66. }
  67. }
  68. /**
  69. * Maps (parts of) the redux state to the associated props for the
  70. * {@code RoomLockButton} component.
  71. *
  72. * @param {Object} state - The Redux state.
  73. * @private
  74. * @returns {{
  75. * _localParticipantModerator: boolean,
  76. * _locked: boolean
  77. * }}
  78. */
  79. function _mapStateToProps(state): Object {
  80. const { conference, locked } = state['features/base/conference'];
  81. return {
  82. _localParticipantModerator:
  83. Boolean(conference && isLocalParticipantModerator(state)),
  84. _locked: Boolean(conference && locked)
  85. };
  86. }
  87. export default translate(connect(_mapStateToProps)(RoomLockButton));