|
|
@ -186,49 +186,53 @@ function _loadConfig({ contextRoot, host, protocol, room }) { |
|
|
|
|
|
|
|
|
|
|
|
// TDOO userinfo
|
|
|
|
// TDOO userinfo
|
|
|
|
|
|
|
|
|
|
|
|
const rootUrl = `${protocol}//${host}${contextRoot || '/'}`; |
|
|
|
const baseURL = `${protocol}//${host}${contextRoot || '/'}`; |
|
|
|
let url = `${rootUrl}config.js`; |
|
|
|
let url = `${baseURL}config.js`; |
|
|
|
|
|
|
|
|
|
|
|
// XXX In order to support multiple shards, tell the room to the deployment.
|
|
|
|
// XXX In order to support multiple shards, tell the room to the deployment.
|
|
|
|
room && (url += `?room=${room.toLowerCase()}`); |
|
|
|
room && (url += `?room=${room.toLowerCase()}`); |
|
|
|
|
|
|
|
|
|
|
|
/* eslint-enable no-param-reassign */ |
|
|
|
/* eslint-enable no-param-reassign */ |
|
|
|
|
|
|
|
|
|
|
|
const key = `config/${rootUrl}`; |
|
|
|
const key = `config.js/${baseURL}`; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return loadConfig(url).then( |
|
|
|
loadConfig(url) |
|
|
|
/* onFulfilled */ config => { |
|
|
|
.then(config => { |
|
|
|
// Try to store the configuration in localStorage. If the deployment
|
|
|
|
// Try to store the configuration in localStorage. If the
|
|
|
|
// specified 'getroom' as a function, for example, it does not make
|
|
|
|
// deployment specified the 'getroom' option as a function, for
|
|
|
|
// sense to and it will not be stored.
|
|
|
|
// example, we cannot store it, so don't.
|
|
|
|
try { |
|
|
|
try { |
|
|
|
if (typeof window.config === 'undefined' |
|
|
|
|
|
|
|
|| window.config !== config) { |
|
|
|
window.localStorage.setItem(key, JSON.stringify(config)); |
|
|
|
window.localStorage.setItem(key, JSON.stringify(config)); |
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ignore the error, we won't cache this config.
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
// Ignore the error because the caching is optional.
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return config; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/* onRejected */ error => { |
|
|
|
|
|
|
|
// XXX The (down)loading of config failed. Try to use the last
|
|
|
|
|
|
|
|
// successfully fetched for that deployment. It may not match the
|
|
|
|
|
|
|
|
// shard.
|
|
|
|
|
|
|
|
let storage; |
|
|
|
|
|
|
|
|
|
|
|
return config; |
|
|
|
try { |
|
|
|
}) |
|
|
|
// XXX Even reading the property localStorage of window may
|
|
|
|
.catch(error => { |
|
|
|
// throw an error (which is user agent-specific behavior).
|
|
|
|
// We failed to load the requested config, try to use the last
|
|
|
|
storage = window.localStorage; |
|
|
|
// one which was fetched for that deployment. It may not match
|
|
|
|
|
|
|
|
// the shard, but it's probably better than nothing.
|
|
|
|
const config = storage.getItem(key); |
|
|
|
const config = window.localStorage.getItem(key); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (config) { |
|
|
|
if (config) { |
|
|
|
try { |
|
|
|
return JSON.parse(config); |
|
|
|
return JSON.parse(config); |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Somehow incorrect data ended up in the storage. Clean
|
|
|
|
|
|
|
|
// up.
|
|
|
|
|
|
|
|
window.localStorage.removeItem(key); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
// Somehow incorrect data ended up in the storage. Clean it up.
|
|
|
|
|
|
|
|
storage && storage.removeItem(key); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw error; |
|
|
|
throw error; |
|
|
|
}) |
|
|
|
}); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|