Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

[RN] Add a timeout for loading the configuration

Saúl Ibarra Corretgé38b645bc27df
diff --git a/react/features/app/actions.js b/react/features/app/actions.js
index edc03d0795..10be99372b 100644
--- a/react/features/app/actions.js
+++ b/react/features/app/actions.js
@@ -10,6 +10,11 @@ import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
declare var APP: Object;
+/**
+ * Timeout for loading the configuration.
+ */
+const LOAD_CONFIG_TIMEOUT = 8000;
+
/**
* Triggers an in-app navigation to a specific route. Allows navigation to be
* abstracted between the mobile/React Native and Web/React applications.
@@ -206,7 +211,7 @@ function _loadConfig({ contextRoot, host, protocol, room }) {
const key = `config.js/${baseURL}`;
- return loadConfig(url).then(
+ return loadConfig(url, LOAD_CONFIG_TIMEOUT).then(
/* onFulfilled */ config => {
// Try to store the configuration in localStorage. If the deployment
// specified 'getroom' as a function, for example, it does not make
diff --git a/react/features/base/lib-jitsi-meet/functions.js b/react/features/base/lib-jitsi-meet/functions.js
index 38ce6c0e5b..0707b29465 100644
--- a/react/features/base/lib-jitsi-meet/functions.js
+++ b/react/features/base/lib-jitsi-meet/functions.js
@@ -2,7 +2,7 @@
import { setConfigFromURLParams } from '../config';
import { toState } from '../redux';
-import { loadScript } from '../util';
+import { loadScript, timeoutPromise } from '../util';
import JitsiMeetJS from './_';
@@ -107,9 +107,11 @@ export function isFatalJitsiConnectionError(error: Object | string) {
* Loads config.js from a specific remote server.
*
* @param {string} url - The URL to load.
+ * @param {number} timeoutMs - The timeout for the configuration to be loaded,
+ * in milliseconds.
* @returns {Promise<Object>}
*/
-export function loadConfig(url: string): Promise<Object> {
+export function loadConfig(url: string, timeoutMs: number): Promise<Object> {
let promise;
if (typeof APP === 'undefined') {
@@ -148,5 +150,5 @@ export function loadConfig(url: string): Promise<Object> {
return value;
});
- return promise;
+ return timeoutPromise(promise, timeoutMs);
}
diff --git a/react/features/base/util/helpers.js b/react/features/base/util/helpers.js
index 2391e30f93..e151ef2b70 100644
--- a/react/features/base/util/helpers.js
+++ b/react/features/base/util/helpers.js
@@ -16,3 +16,31 @@ export function getJitsiMeetGlobalNS() {
return window.JitsiMeetJS.app;
}
+
+/**
+ * Makes the given promise fail with a timeout error if it wasn't fulfilled in
+ * the given timeout.
+ *
+ * @param {Promise} promise - The promise which will be wrapped for timeout.
+ * @param {number} ms - The amount of milliseconds to wait for a response before
+ * failing with a timeout error.
+ * @returns {Promise} - The wrapped promise.
+ */
+export function timeoutPromise(promise, ms) {
+ return new Promise((resolve, reject) => {
+ const timeoutId = setTimeout(() => {
+ reject(new Error('timeout'));
+ }, ms);
+
+ promise.then(
+ res => {
+ clearTimeout(timeoutId);
+ resolve(res);
+ },
+ err => {
+ clearTimeout(timeoutId);
+ reject(err);
+ }
+ );
+ });
+}