From 3cc181a2e5dae16c45838cd2585ce5038707bfba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 13 Sep 2019 16:51:58 +0200 Subject: [PATCH] rn,config: create a fake config if we cannot load one on the welcome page We try to load the configuration with every room change, even when there is no room. There is a bad (corner) case: when we have no config cached (first boot or wiped app data). In such case the user is trapped in an infinite loop because we require the config to show the welcome page, oh well. Pretend we have a configuration by creating the most minimal one to at least get to the welcome page. --- react/features/app/actions.js | 11 ++++++++-- react/features/base/config/functions.any.js | 23 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/react/features/app/actions.js b/react/features/app/actions.js index 3c0082d19..aca96b65f 100644 --- a/react/features/app/actions.js +++ b/react/features/app/actions.js @@ -5,6 +5,7 @@ import type { Dispatch } from 'redux'; import { setRoom } from '../base/conference'; import { configWillLoad, + createFakeConfig, loadConfigError, restoreConfig, setConfig, @@ -101,9 +102,15 @@ export function appNavigate(uri: ?string) { config = restoreConfig(baseURL); if (!config) { - dispatch(loadConfigError(error, locationURL)); + if (room) { + dispatch(loadConfigError(error, locationURL)); - return; + return; + } + + // If there is no room (we are on the welcome page), don't fail, just create a fake one. + logger.warn('Failed to load config but there is no room, applying a fake one'); + config = createFakeConfig(baseURL); } } } diff --git a/react/features/base/config/functions.any.js b/react/features/base/config/functions.any.js index be2bf038a..7b7643a50 100644 --- a/react/features/base/config/functions.any.js +++ b/react/features/base/config/functions.any.js @@ -155,6 +155,29 @@ const WHITELISTED_KEYS = [ export { default as getRoomName } from './getRoomName'; export { parseURLParams }; +/** + * Create a "fake" configuration object for the given base URL. This is used in case the config + * couldn't be loaded in the welcome page, so at least we have something to try with. + * + * @param {string} baseURL - URL of the deployment for which we want the fake config. + * @returns {Object} + */ +export function createFakeConfig(baseURL: string) { + const url = new URL(baseURL); + + return { + hosts: { + domain: url.hostname, + muc: `conference.${url.hostname}` + }, + bosh: `${baseURL}http-bind`, + clientNode: 'https://jitsi.org/jitsi-meet', + p2p: { + enabled: true + } + }; +} + /** * Promise wrapper on obtain config method. When HttpConfigFetch will be moved * to React app it's better to use load config instead.