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

RoomLockPrompt.native.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // @flow
  2. import React, { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { InputDialog } from '../../base/dialog';
  5. import { connect } from '../../base/redux';
  6. import { endRoomLockRequest } from '../actions';
  7. /**
  8. * The style of the {@link TextInput} rendered by {@code RoomLockPrompt}. As it
  9. * requests the entry of a password, {@code TextInput} automatically correcting
  10. * the entry of the password is a pain to deal with as a user.
  11. */
  12. const _TEXT_INPUT_PROPS = {
  13. autoCapitalize: 'none',
  14. autoCorrect: false
  15. };
  16. /**
  17. * The type of the React {@code Component} props of {@link RoomLockPrompt}.
  18. */
  19. type Props = {
  20. /**
  21. * The JitsiConference which requires a password.
  22. */
  23. conference: Object,
  24. /**
  25. * The number of digits to be used in the password.
  26. */
  27. passwordNumberOfDigits: ?number,
  28. /**
  29. * Redux store dispatch function.
  30. */
  31. dispatch: Dispatch<any>
  32. };
  33. /**
  34. * Implements a React Component which prompts the user for a password to lock a
  35. * conference/room.
  36. */
  37. class RoomLockPrompt extends Component<Props> {
  38. /**
  39. * Initializes a new RoomLockPrompt instance.
  40. *
  41. * @param {Props} props - The read-only properties with which the new
  42. * instance is to be initialized.
  43. */
  44. constructor(props: Props) {
  45. super(props);
  46. // Bind event handlers so they are only bound once per instance.
  47. this._onCancel = this._onCancel.bind(this);
  48. this._onSubmit = this._onSubmit.bind(this);
  49. this._validateInput = this._validateInput.bind(this);
  50. }
  51. /**
  52. * Implements React's {@link Component#render()}.
  53. *
  54. * @inheritdoc
  55. * @returns {ReactElement}
  56. */
  57. render() {
  58. let textInputProps = _TEXT_INPUT_PROPS;
  59. if (this.props.passwordNumberOfDigits) {
  60. textInputProps = {
  61. ...textInputProps,
  62. keyboardType: 'number-pad',
  63. maxLength: this.props.passwordNumberOfDigits
  64. };
  65. }
  66. return (
  67. <InputDialog
  68. contentKey = 'security.about'
  69. onCancel = { this._onCancel }
  70. onSubmit = { this._onSubmit }
  71. textInputProps = { textInputProps }
  72. validateInput = { this._validateInput } />
  73. );
  74. }
  75. _onCancel: () => boolean;
  76. /**
  77. * Notifies this prompt that it has been dismissed by cancel.
  78. *
  79. * @private
  80. * @returns {boolean} True to hide this dialog/prompt; otherwise, false.
  81. */
  82. _onCancel() {
  83. // An undefined password is understood to cancel the request to lock the
  84. // conference/room.
  85. return this._onSubmit(undefined);
  86. }
  87. _onSubmit: (?string) => boolean;
  88. /**
  89. * Notifies this prompt that it has been dismissed by submitting a specific
  90. * value.
  91. *
  92. * @param {string|undefined} value - The submitted value.
  93. * @private
  94. * @returns {boolean} False because we do not want to hide this
  95. * dialog/prompt as the hiding will be handled inside endRoomLockRequest
  96. * after setting the password is resolved.
  97. */
  98. _onSubmit(value: ?string) {
  99. this.props.dispatch(endRoomLockRequest(this.props.conference, value));
  100. return false; // Do not hide.
  101. }
  102. _validateInput: (string) => boolean;
  103. /**
  104. * Verifies input in case only digits are required.
  105. *
  106. * @param {string|undefined} value - The submitted value.
  107. * @private
  108. * @returns {boolean} False when the value is not valid and True otherwise.
  109. */
  110. _validateInput(value: string) {
  111. // we want only digits, but both number-pad and numeric add ',' and '.' as symbols
  112. if (this.props.passwordNumberOfDigits
  113. && value.length > 0
  114. && !/^\d+$/.test(value)) {
  115. return false;
  116. }
  117. return true;
  118. }
  119. }
  120. export default connect()(RoomLockPrompt);