2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-09-18 07:09:43 +00:00
|
|
|
import { Text, TextInput, View } from 'react-native';
|
2017-09-08 13:36:42 +00:00
|
|
|
import { connect as reduxConnect } from 'react-redux';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2019-11-29 11:33:35 +00:00
|
|
|
import { ColorSchemeRegistry } from '../../base/color-scheme';
|
2019-04-08 13:10:31 +00:00
|
|
|
import { toJid } from '../../base/connection';
|
|
|
|
import { connect } from '../../base/connection/actions.native';
|
2018-10-18 08:30:25 +00:00
|
|
|
import {
|
|
|
|
CustomSubmitDialog,
|
|
|
|
FIELD_UNDERLINE,
|
|
|
|
PLACEHOLDER_COLOR,
|
2019-01-22 10:35:28 +00:00
|
|
|
_abstractMapStateToProps,
|
2018-10-18 08:30:25 +00:00
|
|
|
inputDialog as inputDialogStyle
|
|
|
|
} from '../../base/dialog';
|
2017-09-08 13:36:42 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
import { JitsiConnectionErrors } from '../../base/lib-jitsi-meet';
|
2019-10-16 11:51:41 +00:00
|
|
|
import type { StyleType } from '../../base/styles';
|
2017-09-18 07:09:43 +00:00
|
|
|
import { authenticateAndUpgradeRole, cancelLogin } from '../actions';
|
2019-11-29 11:33:35 +00:00
|
|
|
|
|
|
|
// Register styles.
|
|
|
|
import './styles';
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@link Component} props of {@link LoginDialog}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@link JitsiConference} that needs authentication - will hold a valid
|
|
|
|
* value in XMPP login + guest access mode.
|
|
|
|
*/
|
|
|
|
_conference: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server hosts specified in the global config.
|
|
|
|
*/
|
|
|
|
_configHosts: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the dialog should display "connecting" status message.
|
|
|
|
*/
|
|
|
|
_connecting: boolean,
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
/**
|
|
|
|
* The color-schemed stylesheet of the base/dialog feature.
|
|
|
|
*/
|
|
|
|
_dialogStyles: StyleType,
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The error which occurred during login/authentication.
|
|
|
|
*/
|
|
|
|
_error: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The progress in the floating range between 0 and 1 of the authenticating
|
|
|
|
* and upgrading the role of the local participant/user.
|
|
|
|
*/
|
|
|
|
_progress: number,
|
|
|
|
|
2019-11-29 11:33:35 +00:00
|
|
|
/**
|
|
|
|
* The color-schemed stylesheet of this feature.
|
|
|
|
*/
|
|
|
|
_styles: StyleType,
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Redux store dispatch method.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@link Component} state of {@link LoginDialog}.
|
|
|
|
*/
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The user entered password for the conference.
|
|
|
|
*/
|
|
|
|
password: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The user entered local participant name.
|
|
|
|
*/
|
|
|
|
username: string
|
|
|
|
};
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
|
|
|
* Dialog asks user for username and password.
|
|
|
|
*
|
|
|
|
* First authentication configuration that it will deal with is the main XMPP
|
|
|
|
* domain (config.hosts.domain) with password authentication. A LoginDialog
|
|
|
|
* will be opened after 'CONNECTION_FAILED' action with
|
|
|
|
* 'JitsiConnectionErrors.PASSWORD_REQUIRED' error. After username and password
|
|
|
|
* are entered a new 'connect' action from 'features/base/connection' will be
|
|
|
|
* triggered which will result in new XMPP connection. The conference will start
|
|
|
|
* if the credentials are correct.
|
|
|
|
*
|
|
|
|
* The second setup is the main XMPP domain with password plus guest domain with
|
|
|
|
* anonymous access configured under 'config.hosts.anonymousdomain'. In such
|
|
|
|
* case user connects from the anonymous domain, but if the room does not exist
|
|
|
|
* yet, Jicofo will not allow to start new conference. This will trigger
|
|
|
|
* 'CONFERENCE_FAILED' action with JitsiConferenceErrors.AUTHENTICATION_REQUIRED
|
|
|
|
* error and 'authRequired' value of 'features/base/conference' will hold
|
2017-09-18 07:09:43 +00:00
|
|
|
* the {@link JitsiConference} instance. If user decides to authenticate, a
|
|
|
|
* new/separate XMPP connection is established and authentication is performed.
|
|
|
|
* In case it succeeds, Jicofo will assign new session ID which then can be used
|
|
|
|
* from the anonymous domain connection to create and join the room. This part
|
|
|
|
* is done by {@link JitsiConference#authenticateAndUpgradeRole} in
|
|
|
|
* lib-jitsi-meet.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
2017-09-18 07:09:43 +00:00
|
|
|
* See {@link https://github.com/jitsi/jicofo#secure-domain} for a description
|
|
|
|
* of the configuration parameters.
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
class LoginDialog extends Component<Props, State> {
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new LoginDialog instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2017-09-08 13:36:42 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
username: '',
|
|
|
|
password: ''
|
|
|
|
};
|
2017-09-18 07:09:43 +00:00
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onCancel = this._onCancel.bind(this);
|
|
|
|
this._onLogin = this._onLogin.bind(this);
|
|
|
|
this._onPasswordChange = this._onPasswordChange.bind(this);
|
|
|
|
this._onUsernameChange = this._onUsernameChange.bind(this);
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
2017-09-18 07:09:43 +00:00
|
|
|
_connecting: connecting,
|
2019-01-22 10:35:28 +00:00
|
|
|
_dialogStyles,
|
2019-11-29 11:33:35 +00:00
|
|
|
_styles: styles,
|
|
|
|
t
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomSubmitDialog
|
|
|
|
okDisabled = { connecting }
|
|
|
|
onCancel = { this._onCancel }
|
|
|
|
onSubmit = { this._onLogin }>
|
|
|
|
<View style = { styles.loginDialog }>
|
|
|
|
<TextInput
|
|
|
|
autoCapitalize = { 'none' }
|
|
|
|
autoCorrect = { false }
|
|
|
|
onChangeText = { this._onUsernameChange }
|
|
|
|
placeholder = { 'user@domain.com' }
|
|
|
|
placeholderTextColor = { PLACEHOLDER_COLOR }
|
|
|
|
style = { _dialogStyles.field }
|
|
|
|
underlineColorAndroid = { FIELD_UNDERLINE }
|
|
|
|
value = { this.state.username } />
|
|
|
|
<TextInput
|
|
|
|
onChangeText = { this._onPasswordChange }
|
|
|
|
placeholder = { t('dialog.userPassword') }
|
|
|
|
placeholderTextColor = { PLACEHOLDER_COLOR }
|
|
|
|
secureTextEntry = { true }
|
|
|
|
style = { [
|
|
|
|
_dialogStyles.field,
|
|
|
|
inputDialogStyle.bottomField
|
|
|
|
] }
|
|
|
|
underlineColorAndroid = { FIELD_UNDERLINE }
|
|
|
|
value = { this.state.password } />
|
|
|
|
{ this._renderMessage() }
|
|
|
|
</View>
|
|
|
|
</CustomSubmitDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders an optional message, if applicable.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_renderMessage() {
|
|
|
|
const {
|
|
|
|
_connecting: connecting,
|
2017-09-18 07:09:43 +00:00
|
|
|
_error: error,
|
2017-09-24 23:41:20 +00:00
|
|
|
_progress: progress,
|
2019-11-29 11:33:35 +00:00
|
|
|
_styles: styles,
|
2017-09-08 13:36:42 +00:00
|
|
|
t
|
|
|
|
} = this.props;
|
|
|
|
|
2017-09-24 21:51:43 +00:00
|
|
|
let messageKey;
|
2019-11-29 11:33:35 +00:00
|
|
|
let messageIsError = false;
|
2018-10-30 05:02:23 +00:00
|
|
|
const messageOptions = {};
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-09-24 23:41:20 +00:00
|
|
|
if (progress && progress < 1) {
|
2017-09-22 19:06:16 +00:00
|
|
|
messageKey = 'connection.FETCH_SESSION_ID';
|
|
|
|
} else if (error) {
|
2017-09-24 21:51:43 +00:00
|
|
|
const { name } = error;
|
|
|
|
|
|
|
|
if (name === JitsiConnectionErrors.PASSWORD_REQUIRED) {
|
|
|
|
// Show a message that the credentials are incorrect only if the
|
|
|
|
// credentials which have caused the connection to fail are the
|
|
|
|
// ones which the user sees.
|
|
|
|
const { credentials } = error;
|
|
|
|
|
|
|
|
if (credentials
|
|
|
|
&& credentials.jid
|
|
|
|
=== toJid(
|
|
|
|
this.state.username,
|
|
|
|
this.props._configHosts)
|
|
|
|
&& credentials.password === this.state.password) {
|
|
|
|
messageKey = 'dialog.incorrectPassword';
|
2019-11-29 11:33:35 +00:00
|
|
|
messageIsError = true;
|
2017-09-24 21:51:43 +00:00
|
|
|
}
|
|
|
|
} else if (name) {
|
|
|
|
messageKey = 'dialog.connectErrorWithMsg';
|
|
|
|
messageOptions.msg = `${name} ${error.message}`;
|
2019-11-29 11:33:35 +00:00
|
|
|
messageIsError = true;
|
2017-09-24 21:51:43 +00:00
|
|
|
}
|
2019-11-29 11:33:35 +00:00
|
|
|
} else if (connecting) {
|
|
|
|
messageKey = 'connection.CONNECTING';
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 11:33:35 +00:00
|
|
|
if (messageKey) {
|
|
|
|
const message = t(messageKey, messageOptions);
|
|
|
|
const messageStyles = [
|
|
|
|
styles.dialogText,
|
|
|
|
messageIsError ? styles.errorMessage : styles.progressMessage
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Text style = { messageStyles }>
|
|
|
|
{ message }
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
2018-10-18 08:30:25 +00:00
|
|
|
|
2019-11-29 11:33:35 +00:00
|
|
|
return null;
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onUsernameChange: (string) => void;
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
|
|
|
* Called when user edits the username.
|
|
|
|
*
|
|
|
|
* @param {string} text - A new username value entered by user.
|
|
|
|
* @returns {void}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_onUsernameChange(text) {
|
|
|
|
this.setState({
|
|
|
|
username: text
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onPasswordChange: (string) => void;
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
|
|
|
* Called when user edits the password.
|
|
|
|
*
|
|
|
|
* @param {string} text - A new password value entered by user.
|
|
|
|
* @returns {void}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_onPasswordChange(text) {
|
|
|
|
this.setState({
|
|
|
|
password: text
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onCancel: () => void;
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
|
|
|
* Notifies this LoginDialog that it has been dismissed by cancel.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onCancel() {
|
|
|
|
this.props.dispatch(cancelLogin());
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onLogin: () => void;
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
|
|
|
* Notifies this LoginDialog that the login button (OK) has been pressed by
|
|
|
|
* the user.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onLogin() {
|
2017-09-22 20:15:06 +00:00
|
|
|
const { _conference: conference, dispatch } = this.props;
|
2017-11-17 19:06:47 +00:00
|
|
|
const { password, username } = this.state;
|
2017-09-18 07:09:43 +00:00
|
|
|
const jid = toJid(username, this.props._configHosts);
|
2017-09-22 20:15:06 +00:00
|
|
|
let r;
|
2017-09-08 13:36:42 +00:00
|
|
|
|
|
|
|
// If there's a conference it means that the connection has succeeded,
|
|
|
|
// but authentication is required in order to join the room.
|
|
|
|
if (conference) {
|
2017-09-22 20:15:06 +00:00
|
|
|
r = dispatch(authenticateAndUpgradeRole(jid, password, conference));
|
2017-09-08 13:36:42 +00:00
|
|
|
} else {
|
2017-09-22 20:15:06 +00:00
|
|
|
r = dispatch(connect(jid, password));
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
2017-09-22 20:15:06 +00:00
|
|
|
|
|
|
|
return r;
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code LoginDialog} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
2019-11-29 11:33:35 +00:00
|
|
|
* @returns {Props}
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
2017-09-18 07:09:43 +00:00
|
|
|
const {
|
2017-09-24 23:41:20 +00:00
|
|
|
error: authenticateAndUpgradeRoleError,
|
|
|
|
progress,
|
|
|
|
thenableWithCancel
|
2017-09-18 07:09:43 +00:00
|
|
|
} = state['features/authentication'];
|
|
|
|
const { authRequired } = state['features/base/conference'];
|
2017-09-08 13:36:42 +00:00
|
|
|
const { hosts: configHosts } = state['features/base/config'];
|
|
|
|
const {
|
|
|
|
connecting,
|
2017-09-24 21:51:43 +00:00
|
|
|
error: connectionError
|
2017-09-08 13:36:42 +00:00
|
|
|
} = state['features/base/connection'];
|
|
|
|
|
|
|
|
return {
|
2019-01-22 10:35:28 +00:00
|
|
|
..._abstractMapStateToProps(state),
|
2017-09-18 07:09:43 +00:00
|
|
|
_conference: authRequired,
|
|
|
|
_configHosts: configHosts,
|
2017-09-24 23:41:20 +00:00
|
|
|
_connecting: Boolean(connecting) || Boolean(thenableWithCancel),
|
|
|
|
_error: connectionError || authenticateAndUpgradeRoleError,
|
2019-11-29 11:33:35 +00:00
|
|
|
_progress: progress,
|
|
|
|
_styles: ColorSchemeRegistry.get(state, 'LoginDialog')
|
2017-09-08 13:36:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(reduxConnect(_mapStateToProps)(LoginDialog));
|