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.
This commit is contained in:
Saúl Ibarra Corretgé 2019-09-13 16:51:58 +02:00 committed by Saúl Ibarra Corretgé
parent bcc1be675f
commit 3cc181a2e5
2 changed files with 32 additions and 2 deletions

View File

@ -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);
}
}
}

View File

@ -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.