jitsi-meet/react/features/overlay/components/PageReloadOverlay.native.js
virtuacoplenny 84b589719f fix(connection): reload immediately on possible split-brain (#3162)
* fix(connection): reload immediately on possible split-brain

There isn't an explicit way to know when a split brain
scenario has happened. It is assumed it arises when an
"item-not-found" connection error is encountered early
on in the conference. So, store when a connection has
happened so it be calculated how much time has
elapsed and if the threshold has not been exceeded
then do an immediate reload of the app instead of
showing the overlay with a reload timer.

* squash: rename isItemNotFoundError -> isShardChangedError
2018-07-02 16:22:51 -05:00

102 lines
3.1 KiB
JavaScript

import React from 'react';
import { Text, View } from 'react-native';
import { connect } from 'react-redux';
import { appNavigate, reloadNow } from '../../app';
import { translate } from '../../base/i18n';
import { LoadingIndicator } from '../../base/react';
import AbstractPageReloadOverlay, { abstractMapStateToProps }
from './AbstractPageReloadOverlay';
import { setFatalError } from '../actions';
import OverlayFrame from './OverlayFrame';
import { pageReloadOverlay as styles } from './styles';
/**
* Implements a React Component for page reload overlay. Shown before the
* conference is reloaded. Shows a warning message and counts down towards the
* reload.
*/
class PageReloadOverlay extends AbstractPageReloadOverlay {
/**
* Initializes a new PageReloadOverlay instance.
*
* @param {Object} props - The read-only properties with which the new
* instance is to be initialized.
* @public
*/
constructor(props) {
super(props);
this._onCancel = this._onCancel.bind(this);
this._onReloadNow = this._onReloadNow.bind(this);
}
/**
* Handle clicking of the "Cancel" button. It will navigate back to the
* welcome page.
*
* @private
* @returns {void}
*/
_onCancel() {
clearInterval(this._interval);
this.props.dispatch(setFatalError(undefined));
this.props.dispatch(appNavigate(undefined));
}
/**
* Handle clicking on the "Reload Now" button. It will navigate to the same
* conference URL as before immediately, without waiting for the timer to
* kick in.
*
* @private
* @returns {void}
*/
_onReloadNow() {
clearInterval(this._interval);
this.props.dispatch(reloadNow());
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const { t } = this.props;
const { message, timeLeft, title } = this.state;
return (
<OverlayFrame>
<View style = { styles.container }>
<View style = { styles.loadingIndicator }>
<LoadingIndicator />
</View>
<Text style = { styles.title }>
{ t(title) }
</Text>
<Text style = { styles.message }>
{ t(message, { seconds: timeLeft }) }
</Text>
<View style = { styles.buttonBox }>
<Text
onPress = { this._onReloadNow }
style = { styles.button } >
{ t('dialog.rejoinNow') }
</Text>
<Text
onPress = { this._onCancel }
style = { styles.button } >
{ t('dialog.Cancel') }
</Text>
</View>
</View>
</OverlayFrame>
);
}
}
export default translate(connect(abstractMapStateToProps)(PageReloadOverlay));