[RN] Load config.js with ?room=

In order to load the configuration from the shard that will actually
host the conference, it's imperative that we add the room= query
parameter:

https://meet.jit.si/config.js?room=example

This implies a departure from our current model, where the config is
discarded if the domain for the next conference is different, but kept
otherwise.
This commit is contained in:
Lyubo Marinov 2017-08-31 16:38:35 -05:00
parent bf03e73876
commit ec9c05e401
2 changed files with 22 additions and 45 deletions

View File

@ -39,22 +39,11 @@ export function appNavigate(uri: ?string) {
function _appNavigateToMandatoryLocation( function _appNavigateToMandatoryLocation(
dispatch: Dispatch<*>, getState: Function, dispatch: Dispatch<*>, getState: Function,
newLocation: Object) { newLocation: Object) {
const oldLocationURL = getState()['features/base/connection'].locationURL;
const oldHost = oldLocationURL ? oldLocationURL.host : undefined;
const newHost = newLocation.host;
if (oldHost === newHost) {
dispatchSetLocationURL()
.then(dispatchSetRoom);
} else {
// If the host has changed, we need to load the config of the new host
// and set it, and only after that we can navigate to a different route.
_loadConfig(newLocation) _loadConfig(newLocation)
.then( .then(
config => configLoaded(/* err */ undefined, config), config => configLoaded(/* err */ undefined, config),
err => configLoaded(err, /* config */ undefined)) err => configLoaded(err, /* config */ undefined))
.then(dispatchSetRoom); .then(() => dispatch(setRoom(newLocation.room)));
}
/** /**
* Notifies that an attempt to load a config(uration) has completed. Due to * Notifies that an attempt to load a config(uration) has completed. Due to
@ -83,27 +72,9 @@ function _appNavigateToMandatoryLocation(
} }
return ( return (
dispatchSetLocationURL() dispatch(setLocationURL(new URL(newLocation.toString())))
.then(() => dispatch(setConfig(config)))); .then(() => dispatch(setConfig(config))));
} }
/**
* Dispatches {@link setLocationURL} in the redux store.
*
* @returns {void}
*/
function dispatchSetLocationURL() {
return dispatch(setLocationURL(new URL(newLocation.toString())));
}
/**
* Dispatches {@link _setRoomAndNavigate} in the redux store.
*
* @returns {void}
*/
function dispatchSetRoom() {
return dispatch(setRoom(newLocation.room));
}
} }
/** /**
@ -196,8 +167,10 @@ export function appWillUnmount(app) {
* @private * @private
* @returns {Promise<Object>} * @returns {Promise<Object>}
*/ */
function _loadConfig(location: Object) { function _loadConfig({ contextRoot, host, protocol, room }) {
let protocol = location.protocol.toLowerCase(); /* eslint-disable no-param-reassign */
protocol = protocol.toLowerCase();
// The React Native app supports an app-specific scheme which is sure to not // The React Native app supports an app-specific scheme which is sure to not
// be supported by fetch (or whatever loadConfig utilizes). // be supported by fetch (or whatever loadConfig utilizes).
@ -205,7 +178,12 @@ function _loadConfig(location: Object) {
// TDOO userinfo // TDOO userinfo
return ( let url = `${protocol}//${host}${contextRoot || '/'}config.js`;
loadConfig(
`${protocol}//${location.host}${location.contextRoot || '/'}`)); // XXX In order to support multiple shards, tell the room to the deployment.
room && (url += `?room=${room.toLowerCase()}`);
/* eslint-enable no-param-reassign */
return loadConfig(url);
} }

View File

@ -54,16 +54,15 @@ export function isFatalJitsiConnectionError(error: string) {
/** /**
* Loads config.js from a specific remote server. * Loads config.js from a specific remote server.
* *
* @param {string} host - Host where config.js is hosted. * @param {string} url - The URL to load.
* @param {string} path='config.js' - Relative pah to config.js file.
* @returns {Promise<Object>} * @returns {Promise<Object>}
*/ */
export function loadConfig(host: string, path: string = 'config.js') { export function loadConfig(url: string) {
let promise; let promise;
if (typeof APP === 'undefined') { if (typeof APP === 'undefined') {
promise promise
= loadScript(new URL(path, host).toString()) = loadScript(url)
.then(() => { .then(() => {
const { config } = window; const { config } = window;
@ -77,7 +76,7 @@ export function loadConfig(host: string, path: string = 'config.js') {
return config; return config;
}) })
.catch(err => { .catch(err => {
console.error(`Failed to load ${path} from ${host}`, err); console.error(`Failed to load config from ${url}`, err);
throw err; throw err;
}); });