2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { LOCKED_LOCALLY } from '../../../room-lock';
|
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link PasswordForm}.
|
2018-02-13 19:46:47 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* Whether or not to show the password editing field.
|
2018-02-13 19:46:47 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
editEnabled: boolean,
|
2018-02-13 19:46:47 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The value for how the conference is locked (or undefined if not locked)
|
|
|
|
* as defined by room-lock constants.
|
2018-02-13 19:46:47 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
locked: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to invoke when the local participant is submitting a password
|
|
|
|
* set request.
|
|
|
|
*/
|
|
|
|
onSubmit: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current known password for the JitsiConference.
|
|
|
|
*/
|
|
|
|
password: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of {@link PasswordForm}.
|
|
|
|
*/
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The value of the password being entered by the local participant.
|
|
|
|
*/
|
|
|
|
enteredPassword: string
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React {@code Component} for displaying and editing the conference password.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class PasswordForm extends Component<Props, State> {
|
2018-10-29 02:11:03 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#getDerivedStateFromProps()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
static getDerivedStateFromProps(props, state) {
|
|
|
|
return {
|
|
|
|
enteredPassword: props.editEnabled ? state.enteredPassword : ''
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
state = {
|
|
|
|
enteredPassword: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code PasswordForm} instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
|
|
|
* the new {@code PasswordForm} instance with.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2018-02-13 19:46:47 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onEnteredPasswordChange
|
|
|
|
= this._onEnteredPasswordChange.bind(this);
|
|
|
|
this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
|
2019-03-05 14:26:45 +00:00
|
|
|
this._onKeyDown = this._onKeyDown.bind(this);
|
2018-02-13 19:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { t } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = 'info-password'>
|
2018-04-04 15:58:54 +00:00
|
|
|
<span className = 'info-label'>
|
|
|
|
{ t('info.password') }
|
|
|
|
</span>
|
|
|
|
<span className = 'spacer'> </span>
|
|
|
|
<span className = 'info-password-field info-value'>
|
2018-02-13 19:46:47 +00:00
|
|
|
{ this._renderPasswordField() }
|
2018-04-04 15:58:54 +00:00
|
|
|
</span>
|
2018-02-13 19:46:47 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a ReactElement for showing the current state of the password or
|
|
|
|
* for editing the current password.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderPasswordField() {
|
|
|
|
if (this.props.editEnabled) {
|
|
|
|
return (
|
|
|
|
<form
|
|
|
|
className = 'info-password-form'
|
2019-03-05 14:26:45 +00:00
|
|
|
onKeyDown = { this._onKeyDown }
|
2018-02-13 19:46:47 +00:00
|
|
|
onSubmit = { this._onPasswordSubmit }>
|
|
|
|
<input
|
|
|
|
autoFocus = { true }
|
|
|
|
className = 'info-password-input'
|
|
|
|
onChange = { this._onEnteredPasswordChange }
|
|
|
|
spellCheck = { 'false' }
|
|
|
|
type = 'text'
|
|
|
|
value = { this.state.enteredPassword } />
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
} else if (this.props.locked === LOCKED_LOCALLY) {
|
|
|
|
return (
|
|
|
|
<div className = 'info-password-local'>
|
|
|
|
{ this.props.password }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (this.props.locked) {
|
|
|
|
return (
|
|
|
|
<div className = 'info-password-remote'>
|
|
|
|
{ this.props.t('passwordSetRemotely') }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = 'info-password-none'>
|
|
|
|
{ this.props.t('info.noPassword') }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onEnteredPasswordChange: (Object) => void;
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
/**
|
|
|
|
* Updates the internal state of entered password.
|
|
|
|
*
|
|
|
|
* @param {Object} event - DOM Event for value change.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onEnteredPasswordChange(event) {
|
|
|
|
this.setState({ enteredPassword: event.target.value });
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onPasswordSubmit: (Object) => void;
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
/**
|
|
|
|
* Invokes the passed in onSubmit callback to notify the parent that a
|
|
|
|
* password submission has been attempted.
|
|
|
|
*
|
|
|
|
* @param {Object} event - DOM Event for form submission.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onPasswordSubmit(event) {
|
|
|
|
event.preventDefault();
|
2019-03-05 14:26:45 +00:00
|
|
|
event.stopPropagation();
|
2018-02-13 19:46:47 +00:00
|
|
|
|
|
|
|
this.props.onSubmit(this.state.enteredPassword);
|
|
|
|
}
|
2019-03-05 14:26:45 +00:00
|
|
|
|
|
|
|
_onKeyDown: (Object) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the the EnterKey for propagation in order to prevent the dialog
|
|
|
|
* to close.
|
|
|
|
*
|
|
|
|
* @param {Object} event - The key event.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onKeyDown(event) {
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
}
|
2018-02-13 19:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(PasswordForm);
|