|
@@ -186,12 +186,49 @@ function _loadConfig({ contextRoot, host, protocol, room }) {
|
186
|
186
|
|
187
|
187
|
// TDOO userinfo
|
188
|
188
|
|
189
|
|
- let url = `${protocol}//${host}${contextRoot || '/'}config.js`;
|
|
189
|
+ const rootUrl = `${protocol}//${host}${contextRoot || '/'}`;
|
|
190
|
+ let url = `${rootUrl}config.js`;
|
190
|
191
|
|
191
|
192
|
// XXX In order to support multiple shards, tell the room to the deployment.
|
192
|
193
|
room && (url += `?room=${room.toLowerCase()}`);
|
193
|
194
|
|
194
|
195
|
/* eslint-enable no-param-reassign */
|
195
|
196
|
|
196
|
|
- return loadConfig(url);
|
|
197
|
+ const key = `config/${rootUrl}`;
|
|
198
|
+
|
|
199
|
+ return (
|
|
200
|
+ loadConfig(url)
|
|
201
|
+ .then(config => {
|
|
202
|
+ // Try to store the configuration in localStorage. If the
|
|
203
|
+ // deployment specified the 'getroom' option as a function, for
|
|
204
|
+ // example, we cannot store it, so don't.
|
|
205
|
+ try {
|
|
206
|
+ window.localStorage.setItem(key, JSON.stringify(config));
|
|
207
|
+ } catch (e) {
|
|
208
|
+
|
|
209
|
+ // Ignore the error, we won't cache this config.
|
|
210
|
+ }
|
|
211
|
+
|
|
212
|
+ return config;
|
|
213
|
+ })
|
|
214
|
+ .catch(error => {
|
|
215
|
+ // We failed to load the requested config, try to use the last
|
|
216
|
+ // one which was fetched for that deployment. It may not match
|
|
217
|
+ // the shard, but it's probably better than nothing.
|
|
218
|
+ const config = window.localStorage.getItem(key);
|
|
219
|
+
|
|
220
|
+ if (config) {
|
|
221
|
+ try {
|
|
222
|
+ return JSON.parse(config);
|
|
223
|
+ } catch (e) {
|
|
224
|
+
|
|
225
|
+ // Somehow incorrect data ended up in the storage. Clean
|
|
226
|
+ // up.
|
|
227
|
+ window.localStorage.removeItem(key);
|
|
228
|
+ }
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ throw error;
|
|
232
|
+ })
|
|
233
|
+ );
|
197
|
234
|
}
|