2017-03-07 03:43:41 +00:00
|
|
|
import React, { Component } from 'react';
|
2023-02-13 13:47:42 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import { IStore } from '../../app/types';
|
|
|
|
import { setPassword } from '../../base/conference/actions';
|
|
|
|
import { IJitsiConference } from '../../base/conference/reducer';
|
|
|
|
import { translate } from '../../base/i18n/functions';
|
|
|
|
import Dialog from '../../base/ui/components/web/Dialog';
|
2022-08-05 12:07:28 +00:00
|
|
|
import Input from '../../base/ui/components/web/Input';
|
2019-07-01 12:02:25 +00:00
|
|
|
import { _cancelPasswordRequiredPrompt } from '../actions';
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link PasswordRequiredPrompt}.
|
2017-03-07 03:43:41 +00:00
|
|
|
*/
|
2023-02-13 13:47:42 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The JitsiConference which requires a password.
|
2017-03-07 03:43:41 +00:00
|
|
|
*/
|
2023-02-13 13:47:42 +00:00
|
|
|
conference: IJitsiConference;
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux store's {@code dispatch} function.
|
|
|
|
*/
|
2023-02-13 13:47:42 +00:00
|
|
|
dispatch: IStore['dispatch'];
|
|
|
|
}
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of
|
|
|
|
* {@link PasswordRequiredPrompt}.
|
|
|
|
*/
|
|
|
|
type State = {
|
2017-03-07 03:43:41 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The password entered by the local participant.
|
|
|
|
*/
|
2023-02-13 13:47:42 +00:00
|
|
|
password?: string;
|
|
|
|
};
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React Component which prompts the user when a password is
|
|
|
|
* required to join a conference.
|
|
|
|
*/
|
2023-02-13 13:47:42 +00:00
|
|
|
class PasswordRequiredPrompt extends Component<IProps, State> {
|
2017-10-04 22:36:09 +00:00
|
|
|
state = {
|
|
|
|
password: ''
|
|
|
|
};
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new PasswordRequiredPrompt instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2023-02-13 13:47:42 +00:00
|
|
|
constructor(props: IProps) {
|
2017-03-07 03:43:41 +00:00
|
|
|
super(props);
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2017-03-07 03:43:41 +00:00
|
|
|
this._onPasswordChanged = this._onPasswordChanged.bind(this);
|
2019-07-01 12:02:25 +00:00
|
|
|
this._onCancel = this._onCancel.bind(this);
|
2017-03-07 03:43:41 +00:00
|
|
|
this._onSubmit = this._onSubmit.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Dialog
|
2023-02-13 13:47:42 +00:00
|
|
|
disableBackdropClose = { true }
|
2019-07-01 12:02:25 +00:00
|
|
|
onCancel = { this._onCancel }
|
2017-03-07 03:43:41 +00:00
|
|
|
onSubmit = { this._onSubmit }
|
2023-02-13 13:47:42 +00:00
|
|
|
titleKey = 'dialog.passwordRequired'>
|
2017-03-07 03:43:41 +00:00
|
|
|
{ this._renderBody() }
|
2017-10-04 22:36:09 +00:00
|
|
|
</Dialog>
|
|
|
|
);
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display component in dialog body.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
_renderBody() {
|
|
|
|
return (
|
|
|
|
<div>
|
2022-08-05 12:07:28 +00:00
|
|
|
<Input
|
2017-06-06 20:34:21 +00:00
|
|
|
autoFocus = { true }
|
2023-02-13 13:47:42 +00:00
|
|
|
className = 'dialog-bottom-margin'
|
2017-04-18 21:49:52 +00:00
|
|
|
label = { this.props.t('dialog.passwordLabel') }
|
2017-03-07 03:43:41 +00:00
|
|
|
name = 'lockKey'
|
|
|
|
onChange = { this._onPasswordChanged }
|
2020-11-10 14:42:37 +00:00
|
|
|
type = 'password'
|
2017-03-07 03:43:41 +00:00
|
|
|
value = { this.state.password } />
|
2017-04-18 21:49:52 +00:00
|
|
|
</div>
|
|
|
|
);
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies this dialog that password has changed.
|
|
|
|
*
|
2022-08-05 12:07:28 +00:00
|
|
|
* @param {string} value - The details of the notification/event.
|
2017-03-07 03:43:41 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-05 12:07:28 +00:00
|
|
|
_onPasswordChanged(value: string) {
|
2017-04-18 21:49:52 +00:00
|
|
|
this.setState({
|
2017-10-04 22:36:09 +00:00
|
|
|
password: value
|
2017-04-18 21:49:52 +00:00
|
|
|
});
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 12:02:25 +00:00
|
|
|
/**
|
|
|
|
* Dispatches action to cancel and dismiss this dialog.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_onCancel() {
|
|
|
|
|
|
|
|
this.props.dispatch(
|
|
|
|
_cancelPasswordRequiredPrompt(this.props.conference));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
2017-10-04 22:36:09 +00:00
|
|
|
* Dispatches action to submit value from this dialog.
|
2017-03-07 03:43:41 +00:00
|
|
|
*
|
|
|
|
* @private
|
2017-10-04 22:36:09 +00:00
|
|
|
* @returns {boolean}
|
2017-03-07 03:43:41 +00:00
|
|
|
*/
|
|
|
|
_onSubmit() {
|
2017-04-18 21:49:52 +00:00
|
|
|
const { conference } = this.props;
|
|
|
|
|
|
|
|
// We received that password is required, but user is trying anyway to
|
|
|
|
// login without a password. Mark the room as not locked in case she
|
|
|
|
// succeeds (maybe someone removed the password meanwhile). If it is
|
|
|
|
// still locked, another password required will be received and the room
|
|
|
|
// again will be marked as locked.
|
|
|
|
this.props.dispatch(
|
|
|
|
setPassword(conference, conference.join, this.state.password));
|
2017-03-07 03:43:41 +00:00
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
// We have used the password so let's clean it.
|
|
|
|
this.setState({
|
|
|
|
password: undefined
|
|
|
|
});
|
2017-03-07 03:43:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect()(PasswordRequiredPrompt));
|