jiti-meet/react/features/authentication/components/WaitForOwnerDialog.native.js

177 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-09-18 07:09:43 +00:00
import PropTypes from 'prop-types';
2017-09-08 13:36:42 +00:00
import React, { Component } from 'react';
2017-09-18 07:09:43 +00:00
import { Text } from 'react-native';
2017-09-08 13:36:42 +00:00
import { connect } from 'react-redux';
2017-09-18 07:09:43 +00:00
import { Dialog } from '../../base/dialog';
2017-09-08 13:36:42 +00:00
import { translate } from '../../base/i18n';
2017-09-18 07:09:43 +00:00
import { cancelWaitForOwner, _openLoginDialog } from '../actions';
2017-09-08 13:36:42 +00:00
import styles from './styles';
/**
* The dialog is display in XMPP password + guest access configuration, after
* user connects from anonymous domain and the conference does not exist yet.
*
* See {@link LoginDialog} description for more details.
*/
class WaitForOwnerDialog extends Component {
/**
* WaitForOwnerDialog component's property types.
*
* @static
*/
static propTypes = {
/**
2017-09-18 07:09:43 +00:00
* The name of the conference room (without the domain part).
2017-09-08 13:36:42 +00:00
*/
2017-09-18 07:09:43 +00:00
_room: PropTypes.string,
2017-09-08 13:36:42 +00:00
/**
2017-09-18 07:09:43 +00:00
* Redux store dispatch function.
2017-09-08 13:36:42 +00:00
*/
2017-09-18 07:09:43 +00:00
dispatch: PropTypes.func,
2017-09-08 13:36:42 +00:00
/**
* Invoked to obtain translated strings.
*/
2017-09-18 07:09:43 +00:00
t: PropTypes.func
2017-09-08 13:36:42 +00:00
};
/**
* Initializes a new WaitForWonderDialog instance.
*
* @param {Object} props - The read-only properties with which the new
* instance is to be initialized.
*/
constructor(props) {
super(props);
2017-09-18 07:09:43 +00:00
// Bind event handlers so they are only bound once per instance.
2017-09-08 13:36:42 +00:00
this._onCancel = this._onCancel.bind(this);
2017-09-18 07:09:43 +00:00
this._onLogin = this._onLogin.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
_room: room,
2017-09-08 13:36:42 +00:00
t
} = this.props;
return (
2017-09-18 07:09:43 +00:00
<Dialog
okTitleKey = { 'dialog.IamHost' }
onCancel = { this._onCancel }
onSubmit = { this._onLogin }
titleKey = 'dialog.WaitingForHost'>
<Text style = { styles.waitForOwnerDialog }>
{
this._renderHTML(t('dialog.WaitForHostMsg', { room }))
2017-09-18 07:09:43 +00:00
}
</Text>
</Dialog>
2017-09-08 13:36:42 +00:00
);
}
/**
2017-09-18 07:09:43 +00:00
* Called when the cancel button is clicked.
2017-09-08 13:36:42 +00:00
*
* @private
* @returns {void}
*/
2017-09-18 07:09:43 +00:00
_onCancel() {
this.props.dispatch(cancelWaitForOwner());
2017-09-08 13:36:42 +00:00
}
/**
2017-09-18 07:09:43 +00:00
* Called when the OK button is clicked.
2017-09-08 13:36:42 +00:00
*
* @private
* @returns {void}
*/
2017-09-18 07:09:43 +00:00
_onLogin() {
this.props.dispatch(_openLoginDialog());
}
/**
* Renders a specific {@code string} which may contain HTML.
2017-09-18 07:09:43 +00:00
*
* @param {string} html - The {@code string} which may contain HTML to
2017-09-18 07:09:43 +00:00
* render.
* @returns {ReactElement[]|string}
2017-09-18 07:09:43 +00:00
*/
_renderHTML(html) {
if (typeof html === 'string') {
// At the time of this writing, the specified HTML contains a couple
// of spaces one after the other. They do not cause a visible
// problem on Web, because the specified HTML is rendered as, well,
// HTML. However, we're not rendering HTML here.
// eslint-disable-next-line no-param-reassign
html = html.replace(/\s{2,}/gi, ' ');
// Render text in <b>text</b> in bold.
const opening = /<\s*b\s*>/gi;
const closing = /<\s*\/\s*b\s*>/gi;
let o;
let c;
let prevClosingLastIndex = 0;
const r = [];
// eslint-disable-next-line no-cond-assign
while (o = opening.exec(html)) {
closing.lastIndex = opening.lastIndex;
// eslint-disable-next-line no-cond-assign
if (c = closing.exec(html)) {
r.push(html.substring(prevClosingLastIndex, o.index));
r.push(
<Text style = { styles.boldDialogText }>
{ html.substring(opening.lastIndex, c.index) }
</Text>);
opening.lastIndex
= prevClosingLastIndex
= closing.lastIndex;
} else {
break;
}
}
if (prevClosingLastIndex < html.length) {
r.push(html.substring(prevClosingLastIndex));
}
return r;
2017-09-18 07:09:43 +00:00
}
return html;
2017-09-08 13:36:42 +00:00
}
}
/**
* Maps (parts of) the Redux state to the associated props for the
* {@code WaitForOwnerDialog} component.
*
* @param {Object} state - The Redux state.
* @private
* @returns {{
2017-09-18 07:09:43 +00:00
* _room: string
2017-09-08 13:36:42 +00:00
* }}
*/
function _mapStateToProps(state) {
const {
authRequired
} = state['features/base/conference'];
return {
2017-09-18 07:09:43 +00:00
_room: authRequired && authRequired.getName()
2017-09-08 13:36:42 +00:00
};
}
export default translate(connect(_mapStateToProps)(WaitForOwnerDialog));