2017-11-27 22:08:12 +00:00
|
|
|
// @flow
|
2017-05-31 05:24:34 +00:00
|
|
|
|
2020-07-09 07:17:23 +00:00
|
|
|
import { randomInt } from '@jitsi/js-utils/random';
|
2017-03-09 00:16:53 +00:00
|
|
|
import React, { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2017-03-09 00:16:53 +00:00
|
|
|
|
2018-01-03 21:24:07 +00:00
|
|
|
import {
|
|
|
|
createPageReloadScheduledEvent,
|
|
|
|
sendAnalytics
|
|
|
|
} from '../../analytics';
|
2020-06-04 14:09:13 +00:00
|
|
|
import { reloadNow } from '../../app/actions';
|
2017-11-09 13:34:42 +00:00
|
|
|
import {
|
|
|
|
isFatalJitsiConferenceError,
|
|
|
|
isFatalJitsiConnectionError
|
|
|
|
} from '../../base/lib-jitsi-meet';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from '../logger';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2019-04-09 11:05:20 +00:00
|
|
|
import ReloadButton from './web/ReloadButton';
|
2017-03-09 00:16:53 +00:00
|
|
|
|
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link AbstractPageReloadOverlay}.
|
2017-03-09 00:16:53 +00:00
|
|
|
*/
|
2019-03-06 16:28:59 +00:00
|
|
|
export type Props = {
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2017-03-09 00:16:53 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The details is an object containing more information about the connection
|
|
|
|
* failed (shard changes, was the computer suspended, etc.)
|
2017-03-09 00:16:53 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
details: Object,
|
2018-02-06 22:54:21 +00:00
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2017-05-31 05:31:00 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The indicator which determines whether the reload was caused by network
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
isNetworkFailure: boolean,
|
2017-03-09 00:16:53 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The reason for the error that will cause the reload.
|
|
|
|
* NOTE: Used by PageReloadOverlay only.
|
|
|
|
*/
|
|
|
|
reason: string,
|
2017-05-31 05:24:34 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The function to translate human-readable text.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of
|
|
|
|
* {@link AbstractPageReloadOverlay}.
|
|
|
|
*/
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation key for the title of the overlay.
|
|
|
|
*/
|
|
|
|
message: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current value(time) of the timer.
|
|
|
|
*/
|
|
|
|
timeLeft: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How long the overlay dialog will be displayed before the conference will
|
|
|
|
* be reloaded.
|
|
|
|
*/
|
|
|
|
timeoutSeconds: number,
|
2017-03-09 00:16:53 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The translation key for the title of the overlay.
|
|
|
|
*/
|
|
|
|
title: string
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements an abstract React {@link Component} for the page reload overlays.
|
2019-04-09 11:05:20 +00:00
|
|
|
*
|
|
|
|
* FIXME: This is not really an abstract class as some components and functions are very web specific.
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2019-03-06 16:28:59 +00:00
|
|
|
export default class AbstractPageReloadOverlay<P: Props>
|
|
|
|
extends Component<P, State> {
|
2017-11-27 22:08:12 +00:00
|
|
|
/**
|
|
|
|
* Determines whether this overlay needs to be rendered (according to a
|
|
|
|
* specific redux state). Called by {@link OverlayContainer}.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {boolean} - If this overlay needs to be rendered, {@code true};
|
|
|
|
* {@code false}, otherwise.
|
|
|
|
*/
|
2018-05-22 14:23:03 +00:00
|
|
|
static needsRender(state: Object) {
|
2018-06-26 12:18:29 +00:00
|
|
|
// FIXME web does not rely on the 'recoverable' flag set on an error
|
|
|
|
// action, but on a predefined list of fatal errors. Because of that
|
|
|
|
// the value of 'fatalError' which relies on the flag should not be used
|
|
|
|
// on web yet (until conference/connection and their errors handling is
|
|
|
|
// not unified).
|
|
|
|
return typeof APP === 'undefined'
|
|
|
|
? Boolean(state['features/overlay'].fatalError)
|
|
|
|
: this.needsRenderWeb(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether this overlay needs to be rendered (according to a
|
|
|
|
* specific redux state). Called by {@link OverlayContainer}.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {boolean} - If this overlay needs to be rendered, {@code true};
|
|
|
|
* {@code false}, otherwise.
|
|
|
|
*/
|
|
|
|
static needsRenderWeb(state: Object) {
|
2017-11-27 22:08:12 +00:00
|
|
|
const conferenceError = state['features/base/conference'].error;
|
2017-11-29 14:15:57 +00:00
|
|
|
const configError = state['features/base/config'].error;
|
2017-11-27 22:08:12 +00:00
|
|
|
const connectionError = state['features/base/connection'].error;
|
|
|
|
|
|
|
|
return (
|
|
|
|
(connectionError && isFatalJitsiConnectionError(connectionError))
|
|
|
|
|| (conferenceError
|
|
|
|
&& isFatalJitsiConferenceError(conferenceError))
|
2018-03-05 01:27:15 +00:00
|
|
|
|| configError);
|
2017-11-27 22:08:12 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 19:54:29 +00:00
|
|
|
_interval: ?IntervalID;
|
2017-05-31 05:24:34 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2019-03-06 16:28:59 +00:00
|
|
|
constructor(props: P) {
|
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.
|
2017-11-24 15:23:40 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
2018-01-04 00:07:39 +00:00
|
|
|
if (APP.conference && APP.conference._room) {
|
2018-03-05 01:27:15 +00:00
|
|
|
APP.conference._room.sendApplicationLog(JSON.stringify({
|
|
|
|
name: 'page.reload',
|
|
|
|
label: this.props.reason
|
|
|
|
}));
|
2018-01-03 21:24:07 +00:00
|
|
|
}
|
2017-11-24 15:23:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 21:24:07 +00:00
|
|
|
sendAnalytics(createPageReloadScheduledEvent(
|
2018-03-05 01:27:15 +00:00
|
|
|
this.props.reason,
|
|
|
|
this.state.timeoutSeconds,
|
|
|
|
this.props.details));
|
2018-01-03 21:24:07 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2018-07-02 21:22:51 +00:00
|
|
|
this.props.dispatch(reloadNow());
|
2017-06-15 00:40:51 +00:00
|
|
|
} else {
|
|
|
|
this.setState(prevState => {
|
|
|
|
return {
|
|
|
|
timeLeft: prevState.timeLeft - 1
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
1000);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-22 14:23:03 +00:00
|
|
|
* Renders the button for reloading the page if necessary.
|
2017-05-31 05:24:34 +00:00
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {ReactElement|null}
|
|
|
|
*/
|
|
|
|
_renderButton() {
|
|
|
|
if (this.props.isNetworkFailure) {
|
|
|
|
return (
|
|
|
|
<ReloadButton textKey = 'dialog.rejoinNow' />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the progress bar.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderProgressBar() {
|
2017-11-27 22:08:12 +00:00
|
|
|
const { timeLeft, timeoutSeconds } = this.state;
|
2017-11-21 22:45:40 +00:00
|
|
|
const timeRemaining = timeoutSeconds - timeLeft;
|
2017-11-27 22:08:12 +00:00
|
|
|
const percentageComplete
|
|
|
|
= Math.floor((timeRemaining / timeoutSeconds) * 100);
|
2017-11-21 22:45:40 +00:00
|
|
|
|
2017-05-31 05:24:34 +00:00
|
|
|
return (
|
|
|
|
<div
|
2017-11-21 22:45:40 +00:00
|
|
|
className = 'progress-indicator'
|
2017-05-31 05:24:34 +00:00
|
|
|
id = 'reloadProgressBar'>
|
2017-11-21 22:45:40 +00:00
|
|
|
<div
|
|
|
|
className = 'progress-indicator-fill'
|
2017-11-27 22:08:12 +00:00
|
|
|
style = {{ width: `${percentageComplete}%` }} />
|
2017-05-31 05:24:34 +00:00
|
|
|
</div>
|
|
|
|
);
|
2017-03-09 00:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-09 13:34:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated component's props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
2017-11-27 22:08:12 +00:00
|
|
|
* @protected
|
2017-11-09 13:34:42 +00:00
|
|
|
* @returns {{
|
2018-03-05 01:27:15 +00:00
|
|
|
* details: Object,
|
2017-11-27 22:08:12 +00:00
|
|
|
* isNetworkFailure: boolean,
|
2018-03-05 01:27:15 +00:00
|
|
|
* reason: string
|
2017-11-09 13:34:42 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function abstractMapStateToProps(state: Object) {
|
2018-03-05 01:27:15 +00:00
|
|
|
const { error: configError } = state['features/base/config'];
|
|
|
|
const { error: connectionError } = state['features/base/connection'];
|
2018-06-26 12:18:29 +00:00
|
|
|
const { fatalError } = state['features/overlay'];
|
2017-11-09 13:34:42 +00:00
|
|
|
|
|
|
|
return {
|
2018-06-26 12:18:29 +00:00
|
|
|
details: fatalError && fatalError.details,
|
|
|
|
isNetworkFailure:
|
|
|
|
fatalError === configError || fatalError === connectionError,
|
2020-05-07 11:59:37 +00:00
|
|
|
reason: fatalError && (fatalError.message || fatalError.name)
|
2017-11-09 13:34:42 +00:00
|
|
|
};
|
|
|
|
}
|