Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PasswordRequiredPrompt.web.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // @flow
  2. import React, { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { setPassword } from '../../base/conference';
  5. import { Dialog } from '../../base/dialog';
  6. import { translate } from '../../base/i18n';
  7. import { connect } from '../../base/redux';
  8. import Input from '../../base/ui/components/web/Input';
  9. import { _cancelPasswordRequiredPrompt } from '../actions';
  10. /**
  11. * The type of the React {@code Component} props of
  12. * {@link PasswordRequiredPrompt}.
  13. */
  14. type Props = {
  15. /**
  16. * The JitsiConference which requires a password.
  17. */
  18. conference: Object,
  19. /**
  20. * The redux store's {@code dispatch} function.
  21. */
  22. dispatch: Dispatch<any>,
  23. /**
  24. * The translate function.
  25. */
  26. t: Function
  27. };
  28. /**
  29. * The type of the React {@code Component} state of
  30. * {@link PasswordRequiredPrompt}.
  31. */
  32. type State = {
  33. /**
  34. * The password entered by the local participant.
  35. */
  36. password: string
  37. }
  38. /**
  39. * Implements a React Component which prompts the user when a password is
  40. * required to join a conference.
  41. */
  42. class PasswordRequiredPrompt extends Component<Props, State> {
  43. state = {
  44. password: ''
  45. };
  46. /**
  47. * Initializes a new PasswordRequiredPrompt instance.
  48. *
  49. * @param {Object} props - The read-only properties with which the new
  50. * instance is to be initialized.
  51. */
  52. constructor(props: Props) {
  53. super(props);
  54. // Bind event handlers so they are only bound once per instance.
  55. this._onPasswordChanged = this._onPasswordChanged.bind(this);
  56. this._onCancel = this._onCancel.bind(this);
  57. this._onSubmit = this._onSubmit.bind(this);
  58. }
  59. /**
  60. * Implements React's {@link Component#render()}.
  61. *
  62. * @inheritdoc
  63. * @returns {ReactElement}
  64. */
  65. render() {
  66. return (
  67. <Dialog
  68. disableBlanketClickDismiss = { true }
  69. isModal = { false }
  70. onCancel = { this._onCancel }
  71. onSubmit = { this._onSubmit }
  72. titleKey = 'dialog.passwordRequired'
  73. width = 'small'>
  74. { this._renderBody() }
  75. </Dialog>
  76. );
  77. }
  78. /**
  79. * Display component in dialog body.
  80. *
  81. * @returns {ReactElement}
  82. * @protected
  83. */
  84. _renderBody() {
  85. return (
  86. <div>
  87. <Input
  88. autoFocus = { true }
  89. label = { this.props.t('dialog.passwordLabel') }
  90. name = 'lockKey'
  91. onChange = { this._onPasswordChanged }
  92. type = 'password'
  93. value = { this.state.password } />
  94. </div>
  95. );
  96. }
  97. _onPasswordChanged: ({ target: { value: * }}) => void;
  98. /**
  99. * Notifies this dialog that password has changed.
  100. *
  101. * @param {string} value - The details of the notification/event.
  102. * @private
  103. * @returns {void}
  104. */
  105. _onPasswordChanged(value: string) {
  106. this.setState({
  107. password: value
  108. });
  109. }
  110. _onCancel: () => boolean;
  111. /**
  112. * Dispatches action to cancel and dismiss this dialog.
  113. *
  114. * @private
  115. * @returns {boolean}
  116. */
  117. _onCancel() {
  118. this.props.dispatch(
  119. _cancelPasswordRequiredPrompt(this.props.conference));
  120. return true;
  121. }
  122. _onSubmit: () => boolean;
  123. /**
  124. * Dispatches action to submit value from this dialog.
  125. *
  126. * @private
  127. * @returns {boolean}
  128. */
  129. _onSubmit() {
  130. const { conference } = this.props;
  131. // We received that password is required, but user is trying anyway to
  132. // login without a password. Mark the room as not locked in case she
  133. // succeeds (maybe someone removed the password meanwhile). If it is
  134. // still locked, another password required will be received and the room
  135. // again will be marked as locked.
  136. this.props.dispatch(
  137. setPassword(conference, conference.join, this.state.password));
  138. // We have used the password so let's clean it.
  139. this.setState({
  140. password: undefined
  141. });
  142. return true;
  143. }
  144. }
  145. export default translate(connect()(PasswordRequiredPrompt));