2021-03-24 14:09:40 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-08-10 06:25:31 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2021-03-24 14:09:40 +00:00
|
|
|
|
2022-10-19 08:42:54 +00:00
|
|
|
// @ts-expect-error
|
2021-03-24 14:09:40 +00:00
|
|
|
import { connect } from '../../../../../connection';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState, IStore } from '../../../app/types';
|
2022-10-17 11:28:01 +00:00
|
|
|
import { IJitsiConference } from '../../../base/conference/reducer';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { IConfig } from '../../../base/config/configType';
|
2021-03-24 14:09:40 +00:00
|
|
|
import { toJid } from '../../../base/connection/functions';
|
2022-08-10 06:25:31 +00:00
|
|
|
import { translate, translateToHTML } from '../../../base/i18n/functions';
|
2021-03-24 14:09:40 +00:00
|
|
|
import { JitsiConnectionErrors } from '../../../base/lib-jitsi-meet';
|
2022-08-10 06:25:31 +00:00
|
|
|
import { connect as reduxConnect } from '../../../base/redux/functions';
|
2022-10-17 11:27:48 +00:00
|
|
|
import Dialog from '../../../base/ui/components/web/Dialog';
|
2022-08-10 06:25:31 +00:00
|
|
|
import Input from '../../../base/ui/components/web/Input';
|
2021-05-26 16:15:35 +00:00
|
|
|
import {
|
|
|
|
authenticateAndUpgradeRole,
|
|
|
|
cancelLogin
|
|
|
|
} from '../../actions.web';
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link LoginDialog}.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* {@link JitsiConference} That needs authentication - will hold a valid
|
2021-03-24 14:09:40 +00:00
|
|
|
* value in XMPP login + guest access mode.
|
|
|
|
*/
|
2022-10-17 11:28:01 +00:00
|
|
|
_conference: IJitsiConference;
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The server hosts specified in the global config.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_configHosts: IConfig['hosts'];
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the dialog should display "connecting" status message.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_connecting: boolean;
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The error which occurred during login/authentication.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_error: any;
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The progress in the floating range between 0 and 1 of the authenticating
|
|
|
|
* and upgrading the role of the local participant/user.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_progress: number;
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redux store dispatch method.
|
|
|
|
*/
|
2022-10-11 10:47:54 +00:00
|
|
|
dispatch: IStore['dispatch'];
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when username and password are submitted.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onSuccess: Function;
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Conference room name.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
roomName: string;
|
2021-03-24 14:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of {@link LoginDialog}.
|
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
interface IState {
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-10 06:25:31 +00:00
|
|
|
* Authentication process starts before joining the conference room.
|
2021-03-24 14:09:40 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
loginStarted: boolean;
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-10 06:25:31 +00:00
|
|
|
* The user entered password for the conference.
|
2021-03-24 14:09:40 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
password: string;
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-10 06:25:31 +00:00
|
|
|
* The user entered local participant name.
|
2021-03-24 14:09:40 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
username: string;
|
2022-11-03 08:35:51 +00:00
|
|
|
}
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that renders the login in conference dialog.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
class LoginDialog extends Component<IProps, IState> {
|
2021-03-24 14:09:40 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code LoginDialog} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
constructor(props: IProps) {
|
2021-03-24 14:09:40 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
username: '',
|
|
|
|
password: '',
|
|
|
|
loginStarted: false
|
|
|
|
};
|
|
|
|
|
|
|
|
this._onCancelLogin = this._onCancelLogin.bind(this);
|
|
|
|
this._onLogin = this._onLogin.bind(this);
|
2022-08-10 06:25:31 +00:00
|
|
|
this._onUsernameChange = this._onUsernameChange.bind(this);
|
|
|
|
this._onPasswordChange = this._onPasswordChange.bind(this);
|
2021-03-24 14:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the cancel button is clicked.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onCancelLogin() {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
2021-08-23 16:59:17 +00:00
|
|
|
dispatch(cancelLogin());
|
2021-03-24 14:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies this LoginDialog that the login button (OK) has been pressed by
|
|
|
|
* the user.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onLogin() {
|
|
|
|
const {
|
|
|
|
_conference: conference,
|
|
|
|
_configHosts: configHosts,
|
|
|
|
roomName,
|
|
|
|
onSuccess,
|
|
|
|
dispatch
|
|
|
|
} = this.props;
|
|
|
|
const { password, username } = this.state;
|
2022-09-14 07:54:56 +00:00
|
|
|
const jid = toJid(username, configHosts ?? {
|
|
|
|
authdomain: '',
|
|
|
|
domain: ''
|
|
|
|
});
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
if (conference) {
|
|
|
|
dispatch(authenticateAndUpgradeRole(jid, password, conference));
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
loginStarted: true
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(jid, password, roomName)
|
2022-08-10 06:25:31 +00:00
|
|
|
.then((connection: any) => {
|
2022-09-08 09:52:36 +00:00
|
|
|
onSuccess?.(connection);
|
2021-03-24 14:09:40 +00:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.setState({
|
|
|
|
loginStarted: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for the onChange event of the field.
|
|
|
|
*
|
2022-08-10 06:25:31 +00:00
|
|
|
* @param {string} value - The static event.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onPasswordChange(value: string) {
|
|
|
|
this.setState({
|
|
|
|
password: value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for the onChange event of the username input.
|
|
|
|
*
|
|
|
|
* @param {string} value - The new value.
|
2021-03-24 14:09:40 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-10 06:25:31 +00:00
|
|
|
_onUsernameChange(value: string) {
|
2021-03-24 14:09:40 +00:00
|
|
|
this.setState({
|
2022-08-10 06:25:31 +00:00
|
|
|
username: value
|
2021-03-24 14:09:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders an optional message, if applicable.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
renderMessage() {
|
|
|
|
const {
|
|
|
|
_configHosts: configHosts,
|
|
|
|
_connecting: connecting,
|
|
|
|
_error: error,
|
|
|
|
_progress: progress,
|
|
|
|
t
|
|
|
|
} = this.props;
|
|
|
|
const { username, password } = this.state;
|
2022-08-10 06:25:31 +00:00
|
|
|
const messageOptions: any = {};
|
2021-03-24 14:09:40 +00:00
|
|
|
let messageKey;
|
|
|
|
|
2021-04-22 15:05:14 +00:00
|
|
|
if (progress && progress < 1) {
|
2023-02-23 12:47:34 +00:00
|
|
|
messageKey = 'connection.FETCH_SESSION_ID';
|
2021-03-24 14:09:40 +00:00
|
|
|
} else if (error) {
|
|
|
|
const { name } = error;
|
|
|
|
|
|
|
|
if (name === JitsiConnectionErrors.PASSWORD_REQUIRED) {
|
|
|
|
const { credentials } = error;
|
|
|
|
|
|
|
|
if (credentials
|
2022-09-14 07:54:56 +00:00
|
|
|
&& credentials.jid === toJid(username, configHosts ?? { authdomain: '',
|
|
|
|
domain: '' })
|
2021-03-24 14:09:40 +00:00
|
|
|
&& credentials.password === password) {
|
2023-02-23 12:47:34 +00:00
|
|
|
messageKey = 'dialog.incorrectPassword';
|
2021-03-24 14:09:40 +00:00
|
|
|
}
|
|
|
|
} else if (name) {
|
2023-02-23 12:47:34 +00:00
|
|
|
messageKey = 'dialog.connectErrorWithMsg';
|
2021-03-24 14:09:40 +00:00
|
|
|
messageOptions.msg = `${name} ${error.message}`;
|
|
|
|
}
|
|
|
|
} else if (connecting) {
|
2023-02-23 12:47:34 +00:00
|
|
|
messageKey = 'connection.CONNECTING';
|
2021-03-24 14:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (messageKey) {
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{ translateToHTML(t, messageKey, messageOptions) }
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements {@Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
_connecting: connecting,
|
|
|
|
t
|
|
|
|
} = this.props;
|
|
|
|
const { password, loginStarted, username } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
2023-01-24 13:41:37 +00:00
|
|
|
disableAutoHideOnSubmit = { true }
|
2022-10-17 11:27:48 +00:00
|
|
|
disableBackdropClose = { true }
|
|
|
|
hideCloseButton = { true }
|
|
|
|
ok = {{
|
|
|
|
disabled: connecting
|
|
|
|
|| loginStarted
|
|
|
|
|| !password
|
|
|
|
|| !username,
|
|
|
|
translationKey: 'dialog.login'
|
|
|
|
}}
|
2021-03-24 14:09:40 +00:00
|
|
|
onCancel = { this._onCancelLogin }
|
|
|
|
onSubmit = { this._onLogin }
|
2022-10-17 11:27:48 +00:00
|
|
|
titleKey = { t('dialog.authenticationRequired') }>
|
2022-08-10 06:25:31 +00:00
|
|
|
<Input
|
2021-03-24 14:09:40 +00:00
|
|
|
autoFocus = { true }
|
|
|
|
label = { t('dialog.user') }
|
|
|
|
name = 'username'
|
2022-08-10 06:25:31 +00:00
|
|
|
onChange = { this._onUsernameChange }
|
2021-03-24 14:09:40 +00:00
|
|
|
placeholder = { t('dialog.userIdentifier') }
|
|
|
|
type = 'text'
|
|
|
|
value = { username } />
|
2022-08-10 06:25:31 +00:00
|
|
|
<br />
|
|
|
|
<Input
|
2022-10-17 11:27:48 +00:00
|
|
|
className = 'dialog-bottom-margin'
|
2021-03-24 14:09:40 +00:00
|
|
|
label = { t('dialog.userPassword') }
|
|
|
|
name = 'password'
|
2022-08-10 06:25:31 +00:00
|
|
|
onChange = { this._onPasswordChange }
|
2021-04-22 15:05:14 +00:00
|
|
|
placeholder = { t('dialog.password') }
|
2021-03-24 14:09:40 +00:00
|
|
|
type = 'password'
|
|
|
|
value = { password } />
|
|
|
|
{ this.renderMessage() }
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code LoginDialog} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {IProps}
|
2021-03-24 14:09:40 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function mapStateToProps(state: IReduxState) {
|
2021-03-24 14:09:40 +00:00
|
|
|
const {
|
|
|
|
error: authenticateAndUpgradeRoleError,
|
|
|
|
progress,
|
|
|
|
thenableWithCancel
|
|
|
|
} = state['features/authentication'];
|
2022-01-28 14:14:54 +00:00
|
|
|
const { authRequired, conference } = state['features/base/conference'];
|
2021-03-24 14:09:40 +00:00
|
|
|
const { hosts: configHosts } = state['features/base/config'];
|
|
|
|
const {
|
|
|
|
connecting,
|
|
|
|
error: connectionError
|
|
|
|
} = state['features/base/connection'];
|
|
|
|
|
|
|
|
return {
|
2022-01-28 14:14:54 +00:00
|
|
|
_conference: authRequired || conference,
|
2021-03-24 14:09:40 +00:00
|
|
|
_configHosts: configHosts,
|
|
|
|
_connecting: connecting || thenableWithCancel,
|
|
|
|
_error: connectionError || authenticateAndUpgradeRoleError,
|
|
|
|
_progress: progress
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(reduxConnect(mapStateToProps)(LoginDialog));
|