[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(
dispatch: Dispatch<*>, getState: Function,
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)
.then(
config => configLoaded(/* err */ undefined, config),
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
@ -83,27 +72,9 @@ function _appNavigateToMandatoryLocation(
}
return (
dispatchSetLocationURL()
dispatch(setLocationURL(new URL(newLocation.toString())))
.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
* @returns {Promise<Object>}
*/
function _loadConfig(location: Object) {
let protocol = location.protocol.toLowerCase();
function _loadConfig({ contextRoot, host, protocol, room }) {
/* eslint-disable no-param-reassign */
protocol = protocol.toLowerCase();
// The React Native app supports an app-specific scheme which is sure to not
// be supported by fetch (or whatever loadConfig utilizes).
@ -205,7 +178,12 @@ function _loadConfig(location: Object) {
// TDOO userinfo
return (
loadConfig(
`${protocol}//${location.host}${location.contextRoot || '/'}`));
let url = `${protocol}//${host}${contextRoot || '/'}config.js`;
// 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.
*
* @param {string} host - Host where config.js is hosted.
* @param {string} path='config.js' - Relative pah to config.js file.
* @param {string} url - The URL to load.
* @returns {Promise<Object>}
*/
export function loadConfig(host: string, path: string = 'config.js') {
export function loadConfig(url: string) {
let promise;
if (typeof APP === 'undefined') {
promise
= loadScript(new URL(path, host).toString())
= loadScript(url)
.then(() => {
const { config } = window;
@ -77,7 +76,7 @@ export function loadConfig(host: string, path: string = 'config.js') {
return config;
})
.catch(err => {
console.error(`Failed to load ${path} from ${host}`, err);
console.error(`Failed to load config from ${url}`, err);
throw err;
});