您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PasswordRequiredPrompt.web.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* global APP */
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import AKFieldText from '@atlaskit/field-text';
  5. import UIEvents from '../../../../service/UI/UIEvents';
  6. import { setPassword } from '../../base/conference';
  7. import { Dialog } from '../../base/dialog';
  8. import { translate } from '../../base/i18n';
  9. /**
  10. * Implements a React Component which prompts the user when a password is
  11. * required to join a conference.
  12. */
  13. class PasswordRequiredPrompt extends Component {
  14. /**
  15. * PasswordRequiredPrompt component's property types.
  16. *
  17. * @static
  18. */
  19. static propTypes = {
  20. /**
  21. * The JitsiConference which requires a password.
  22. *
  23. * @type {JitsiConference}
  24. */
  25. conference: React.PropTypes.object,
  26. dispatch: React.PropTypes.func,
  27. t: React.PropTypes.func
  28. }
  29. /**
  30. * Initializes a new PasswordRequiredPrompt instance.
  31. *
  32. * @param {Object} props - The read-only properties with which the new
  33. * instance is to be initialized.
  34. */
  35. constructor(props) {
  36. super(props);
  37. this.state = { password: '' };
  38. this._onPasswordChanged = this._onPasswordChanged.bind(this);
  39. this._onSubmit = this._onSubmit.bind(this);
  40. }
  41. /**
  42. * Implements React's {@link Component#render()}.
  43. *
  44. * @inheritdoc
  45. * @returns {ReactElement}
  46. */
  47. render() {
  48. return (
  49. <Dialog
  50. isModal = { true }
  51. onSubmit = { this._onSubmit }
  52. titleKey = 'dialog.passwordRequired'
  53. width = 'small'>
  54. { this._renderBody() }
  55. </Dialog>);
  56. }
  57. /**
  58. * Display component in dialog body.
  59. *
  60. * @returns {ReactElement}
  61. * @protected
  62. */
  63. _renderBody() {
  64. const { t } = this.props;
  65. return (
  66. <div>
  67. <AKFieldText
  68. compact = { true }
  69. label = { t('dialog.passwordLabel') }
  70. name = 'lockKey'
  71. onChange = { this._onPasswordChanged }
  72. shouldFitContainer = { true }
  73. type = 'text'
  74. value = { this.state.password } />
  75. </div>);
  76. }
  77. /**
  78. * Notifies this dialog that password has changed.
  79. *
  80. * @param {Object} event - The details of the notification/event.
  81. * @private
  82. * @returns {void}
  83. */
  84. _onPasswordChanged(event) {
  85. this.setState({ password: event.target.value });
  86. }
  87. /**
  88. * Dispatches action to submit value from thus dialog.
  89. *
  90. * @private
  91. * @returns {void}
  92. */
  93. _onSubmit() {
  94. const conference = this.props.conference;
  95. // we received that password is required, but user is trying
  96. // anyway to login without a password, mark room as not
  97. // locked in case he succeeds (maybe someone removed the
  98. // password meanwhile), if it is still locked another
  99. // password required will be received and the room again
  100. // will be marked as locked.
  101. if (!this.state.password || this.state.password === '') {
  102. // XXX temporary solution while some components are not listening
  103. // for lock state updates in redux
  104. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, false);
  105. }
  106. this.props.dispatch(setPassword(
  107. conference, conference.join, this.state.password));
  108. // we have used the password lets clean it
  109. this.setState({ password: undefined });
  110. return true;
  111. }
  112. }
  113. export default translate(connect()(PasswordRequiredPrompt));