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

PasswordForm.web.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { LOCKED_LOCALLY } from '../../../room-lock';
  5. /**
  6. * The type of the React {@code Component} props of {@link PasswordForm}.
  7. */
  8. type Props = {
  9. /**
  10. * Whether or not to show the password editing field.
  11. */
  12. editEnabled: boolean,
  13. /**
  14. * The value for how the conference is locked (or undefined if not locked)
  15. * as defined by room-lock constants.
  16. */
  17. locked: string,
  18. /**
  19. * Callback to invoke when the local participant is submitting a password
  20. * set request.
  21. */
  22. onSubmit: Function,
  23. /**
  24. * The current known password for the JitsiConference.
  25. */
  26. password: string,
  27. /**
  28. * Invoked to obtain translated strings.
  29. */
  30. t: Function
  31. };
  32. /**
  33. * The type of the React {@code Component} state of {@link PasswordForm}.
  34. */
  35. type State = {
  36. /**
  37. * The value of the password being entered by the local participant.
  38. */
  39. enteredPassword: string
  40. };
  41. /**
  42. * React {@code Component} for displaying and editing the conference password.
  43. *
  44. * @extends Component
  45. */
  46. class PasswordForm extends Component<Props, State> {
  47. /**
  48. * Implements React's {@link Component#getDerivedStateFromProps()}.
  49. *
  50. * @inheritdoc
  51. */
  52. static getDerivedStateFromProps(props, state) {
  53. return {
  54. enteredPassword: props.editEnabled ? state.enteredPassword : ''
  55. };
  56. }
  57. state = {
  58. enteredPassword: ''
  59. };
  60. /**
  61. * Initializes a new {@code PasswordForm} instance.
  62. *
  63. * @param {Props} props - The React {@code Component} props to initialize
  64. * the new {@code PasswordForm} instance with.
  65. */
  66. constructor(props: Props) {
  67. super(props);
  68. // Bind event handlers so they are only bound once per instance.
  69. this._onEnteredPasswordChange
  70. = this._onEnteredPasswordChange.bind(this);
  71. this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
  72. this._onKeyDown = this._onKeyDown.bind(this);
  73. }
  74. /**
  75. * Implements React's {@link Component#render()}.
  76. *
  77. * @inheritdoc
  78. * @returns {ReactElement}
  79. */
  80. render() {
  81. const { t } = this.props;
  82. return (
  83. <div className = 'info-password'>
  84. <span className = 'info-label'>
  85. { t('info.password') }
  86. </span>
  87. <span className = 'spacer'>&nbsp;</span>
  88. <span className = 'info-password-field info-value'>
  89. { this._renderPasswordField() }
  90. </span>
  91. </div>
  92. );
  93. }
  94. /**
  95. * Returns a ReactElement for showing the current state of the password or
  96. * for editing the current password.
  97. *
  98. * @private
  99. * @returns {ReactElement}
  100. */
  101. _renderPasswordField() {
  102. if (this.props.editEnabled) {
  103. return (
  104. <form
  105. className = 'info-password-form'
  106. onKeyDown = { this._onKeyDown }
  107. onSubmit = { this._onPasswordSubmit }>
  108. <input
  109. autoFocus = { true }
  110. className = 'info-password-input'
  111. onChange = { this._onEnteredPasswordChange }
  112. spellCheck = { 'false' }
  113. type = 'text'
  114. value = { this.state.enteredPassword } />
  115. </form>
  116. );
  117. } else if (this.props.locked === LOCKED_LOCALLY) {
  118. return (
  119. <div className = 'info-password-local'>
  120. { this.props.password }
  121. </div>
  122. );
  123. } else if (this.props.locked) {
  124. return (
  125. <div className = 'info-password-remote'>
  126. { this.props.t('passwordSetRemotely') }
  127. </div>
  128. );
  129. }
  130. return (
  131. <div className = 'info-password-none'>
  132. { this.props.t('info.noPassword') }
  133. </div>
  134. );
  135. }
  136. _onEnteredPasswordChange: (Object) => void;
  137. /**
  138. * Updates the internal state of entered password.
  139. *
  140. * @param {Object} event - DOM Event for value change.
  141. * @private
  142. * @returns {void}
  143. */
  144. _onEnteredPasswordChange(event) {
  145. this.setState({ enteredPassword: event.target.value });
  146. }
  147. _onPasswordSubmit: (Object) => void;
  148. /**
  149. * Invokes the passed in onSubmit callback to notify the parent that a
  150. * password submission has been attempted.
  151. *
  152. * @param {Object} event - DOM Event for form submission.
  153. * @private
  154. * @returns {void}
  155. */
  156. _onPasswordSubmit(event) {
  157. event.preventDefault();
  158. event.stopPropagation();
  159. this.props.onSubmit(this.state.enteredPassword);
  160. }
  161. _onKeyDown: (Object) => void;
  162. /**
  163. * Stops the the EnterKey for propagation in order to prevent the dialog
  164. * to close.
  165. *
  166. * @param {Object} event - The key event.
  167. * @private
  168. * @returns {void}
  169. */
  170. _onKeyDown(event) {
  171. if (event.key === 'Enter') {
  172. event.stopPropagation();
  173. }
  174. }
  175. }
  176. export default translate(PasswordForm);