2017-05-31 05:24:34 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-03-09 00:16:53 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { randomInt } from '../../base/util';
|
|
|
|
|
2017-05-31 05:31:00 +00:00
|
|
|
import { _reloadNow } from '../actions';
|
2017-03-09 00:16:53 +00:00
|
|
|
import ReloadButton from './ReloadButton';
|
|
|
|
|
|
|
|
declare var AJS: Object;
|
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements abstract React Component for the page reload overlays.
|
|
|
|
*/
|
|
|
|
export default class AbstractPageReloadOverlay extends Component {
|
|
|
|
/**
|
|
|
|
* AbstractPageReloadOverlay component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
2017-05-31 05:31:00 +00:00
|
|
|
dispatch: React.PropTypes.func,
|
|
|
|
|
2017-03-09 00:16:53 +00:00
|
|
|
/**
|
|
|
|
* The indicator which determines whether the reload was caused by
|
|
|
|
* network failure.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
isNetworkFailure: React.PropTypes.bool,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The reason for the error that will cause the reload.
|
|
|
|
* NOTE: Used by PageReloadOverlay only.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2017-05-31 05:24:34 +00:00
|
|
|
reason: React.PropTypes.string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The function to translate human-readable text.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
t: React.PropTypes.func
|
2017-06-02 02:01:50 +00:00
|
|
|
};
|
2017-03-09 00:16:53 +00:00
|
|
|
|
2017-05-31 05:24:34 +00:00
|
|
|
_interval: ?number
|
|
|
|
|
|
|
|
state: {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation key for the title of the overlay.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
message: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current value(time) of the timer.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
timeLeft: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How long the overlay dialog will be displayed before the
|
|
|
|
* conference will be reloaded.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
timeoutSeconds: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation key for the title of the overlay.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
title: string
|
|
|
|
}
|
|
|
|
|
2017-03-09 00:16:53 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new AbstractPageReloadOverlay instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
* @public
|
|
|
|
*/
|
2017-05-31 05:24:34 +00:00
|
|
|
constructor(props: Object) {
|
2017-03-09 00:16:53 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How long the overlay dialog will be displayed, before the conference
|
|
|
|
* will be reloaded.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
const timeoutSeconds = 10 + randomInt(0, 20);
|
|
|
|
|
|
|
|
let message, title;
|
|
|
|
|
|
|
|
if (this.props.isNetworkFailure) {
|
|
|
|
title = 'dialog.conferenceDisconnectTitle';
|
|
|
|
message = 'dialog.conferenceDisconnectMsg';
|
|
|
|
} else {
|
|
|
|
title = 'dialog.conferenceReloadTitle';
|
|
|
|
message = 'dialog.conferenceReloadMsg';
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
message,
|
|
|
|
timeLeft: timeoutSeconds,
|
|
|
|
timeoutSeconds,
|
|
|
|
title
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React Component method that executes once component is mounted.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
// FIXME (CallStats - issue) This event will not make it to CallStats
|
|
|
|
// because the log queue is not flushed before "fabric terminated" is
|
|
|
|
// sent to the backed.
|
|
|
|
// FIXME: We should dispatch action for this.
|
|
|
|
APP.conference.logEvent(
|
2017-06-15 00:40:51 +00:00
|
|
|
'page.reload',
|
|
|
|
/* value */ undefined,
|
|
|
|
/* label */ this.props.reason);
|
2017-03-09 00:16:53 +00:00
|
|
|
logger.info(
|
2017-06-15 00:40:51 +00:00
|
|
|
`The conference will be reloaded after ${
|
|
|
|
this.state.timeoutSeconds} seconds.`);
|
2017-03-09 00:16:53 +00:00
|
|
|
|
|
|
|
AJS.progressBars.update('#reloadProgressBar', 0);
|
|
|
|
|
2017-05-31 05:24:34 +00:00
|
|
|
this._interval
|
|
|
|
= setInterval(
|
2017-06-15 00:40:51 +00:00
|
|
|
() => {
|
|
|
|
if (this.state.timeLeft === 0) {
|
|
|
|
if (this._interval) {
|
|
|
|
clearInterval(this._interval);
|
|
|
|
this._interval = undefined;
|
2017-05-31 05:24:34 +00:00
|
|
|
}
|
2017-06-15 00:40:51 +00:00
|
|
|
|
|
|
|
this.props.dispatch(_reloadNow());
|
|
|
|
} else {
|
|
|
|
this.setState(prevState => {
|
|
|
|
return {
|
|
|
|
timeLeft: prevState.timeLeft - 1
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
1000);
|
2017-03-09 00:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React Component method that executes once component is updated.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
componentDidUpdate() {
|
2017-05-31 05:24:34 +00:00
|
|
|
const { timeLeft, timeoutSeconds } = this.state;
|
|
|
|
|
|
|
|
AJS.progressBars.update(
|
|
|
|
'#reloadProgressBar',
|
|
|
|
(timeoutSeconds - timeLeft) / timeoutSeconds);
|
2017-03-09 00:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the timer interval.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
2017-05-31 05:24:34 +00:00
|
|
|
if (this._interval) {
|
|
|
|
clearInterval(this._interval);
|
|
|
|
this._interval = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the button for relaod the page if necessary.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {ReactElement|null}
|
|
|
|
*/
|
|
|
|
_renderButton() {
|
|
|
|
if (this.props.isNetworkFailure) {
|
|
|
|
return (
|
|
|
|
<ReloadButton textKey = 'dialog.rejoinNow' />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the progress bar.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderProgressBar() {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = 'aui-progress-indicator'
|
|
|
|
id = 'reloadProgressBar'>
|
|
|
|
<span className = 'aui-progress-indicator-value' />
|
|
|
|
</div>
|
|
|
|
);
|
2017-03-09 00:16:53 +00:00
|
|
|
}
|
|
|
|
}
|