From cc91dae90bec637dd70aa20e5a4977be93da2ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Sun, 23 Sep 2018 10:49:17 +0200 Subject: [PATCH] Add a 10s join timeout --- .../conference/components/Conference.js | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/app/features/conference/components/Conference.js b/app/features/conference/components/Conference.js index 421f04c..a12a16b 100644 --- a/app/features/conference/components/Conference.js +++ b/app/features/conference/components/Conference.js @@ -77,11 +77,6 @@ type State = { * Conference component. */ class Conference extends Component { - /** - * Reference to the element of this component. - */ - _ref: Object; - /** * External API object. */ @@ -92,6 +87,16 @@ class Conference extends Component { */ _conference: Object; + /** + * Timer to cancel the joining if it takes too long. + */ + _loadTimer: ?TimeoutID; + + /** + * Reference to the element of this component. + */ + _ref: Object; + /** * Initializes a new {@code Conference} instance. * @@ -137,6 +142,19 @@ class Conference extends Component { script.src = getExternalApiURL(serverURL); this._ref.current.appendChild(script); + + // Set a timer for 10s, if we haven't joined by then, give up. + this._loadTimer = setTimeout(() => { + this._navigateToHome( + + // $FlowFixMe + { + error: 'Loading error', + type: 'error' + }, + room, + serverURL); + }, 10000); } /** @@ -165,6 +183,9 @@ class Conference extends Component { * @returns {void} */ componentWillUnmount() { + if (this._loadTimer) { + clearTimeout(this._loadTimer); + } if (this._api) { this._api.dispose(); } @@ -291,6 +312,11 @@ class Conference extends Component { * @returns {void} */ _onVideoConferenceJoined(conferenceInfo: Object) { + if (this._loadTimer) { + clearTimeout(this._loadTimer); + this._loadTimer = null; + } + this.setState({ isLoading: false });