|
@@ -1,7 +1,13 @@
|
1
|
1
|
/* @flow */
|
2
|
2
|
|
3
|
3
|
import { setRoom } from '../base/conference';
|
4
|
|
-import { configWillLoad, loadConfigError, setConfig } from '../base/config';
|
|
4
|
+import {
|
|
5
|
+ configWillLoad,
|
|
6
|
+ loadConfigError,
|
|
7
|
+ restoreConfig,
|
|
8
|
+ setConfig,
|
|
9
|
+ storeConfig
|
|
10
|
+} from '../base/config';
|
5
|
11
|
import { setLocationURL } from '../base/connection';
|
6
|
12
|
import { loadConfig } from '../base/lib-jitsi-meet';
|
7
|
13
|
import { parseURIString } from '../base/util';
|
|
@@ -24,48 +30,6 @@ export function appNavigate(uri: ?string) {
|
24
|
30
|
_appNavigateToOptionalLocation(dispatch, getState, parseURIString(uri));
|
25
|
31
|
}
|
26
|
32
|
|
27
|
|
-/**
|
28
|
|
- * Redirects to another page generated by replacing the path in the original URL
|
29
|
|
- * with the given path.
|
30
|
|
- *
|
31
|
|
- * @param {(string)} pathname - The path to navigate to.
|
32
|
|
- * @returns {Function}
|
33
|
|
- */
|
34
|
|
-export function redirectWithStoredParams(pathname: string) {
|
35
|
|
- return (dispatch: Dispatch<*>, getState: Function) => {
|
36
|
|
- const { locationURL } = getState()['features/base/connection'];
|
37
|
|
- const newLocationURL = new URL(locationURL.href);
|
38
|
|
-
|
39
|
|
- newLocationURL.pathname = pathname;
|
40
|
|
- window.location.assign(newLocationURL.toString());
|
41
|
|
- };
|
42
|
|
-}
|
43
|
|
-
|
44
|
|
-/**
|
45
|
|
- * Reloads the page by restoring the original URL.
|
46
|
|
- *
|
47
|
|
- * @returns {Function}
|
48
|
|
- */
|
49
|
|
-export function reloadWithStoredParams() {
|
50
|
|
- return (dispatch: Dispatch<*>, getState: Function) => {
|
51
|
|
- const { locationURL } = getState()['features/base/connection'];
|
52
|
|
- const windowLocation = window.location;
|
53
|
|
- const oldSearchString = windowLocation.search;
|
54
|
|
-
|
55
|
|
- windowLocation.replace(locationURL.toString());
|
56
|
|
-
|
57
|
|
- if (window.self !== window.top
|
58
|
|
- && locationURL.search === oldSearchString) {
|
59
|
|
- // NOTE: Assuming that only the hash or search part of the URL will
|
60
|
|
- // be changed!
|
61
|
|
- // location.reload will not trigger redirect/reload for iframe when
|
62
|
|
- // only the hash params are changed. That's why we need to call
|
63
|
|
- // reload in addition to replace.
|
64
|
|
- windowLocation.reload();
|
65
|
|
- }
|
66
|
|
- };
|
67
|
|
-}
|
68
|
|
-
|
69
|
33
|
/**
|
70
|
34
|
* Triggers an in-app navigation to a specific location URI.
|
71
|
35
|
*
|
|
@@ -89,7 +53,7 @@ function _appNavigateToMandatoryLocation(
|
89
|
53
|
dispatch(configWillLoad(newLocation));
|
90
|
54
|
|
91
|
55
|
return (
|
92
|
|
- _loadConfig(newLocation)
|
|
56
|
+ _loadConfig(dispatch, getState, newLocation)
|
93
|
57
|
.then(
|
94
|
58
|
config => loadConfigSettled(/* error */ undefined, config),
|
95
|
59
|
error => loadConfigSettled(error, /* config */ undefined))
|
|
@@ -214,12 +178,17 @@ export function appWillUnmount(app: Object) {
|
214
|
178
|
/**
|
215
|
179
|
* Loads config.js from a specific host.
|
216
|
180
|
*
|
|
181
|
+ * @param {Dispatch} dispatch - The redux {@code dispatch} function.
|
|
182
|
+ * @param {Function} getState - The redux {@code getState} function.
|
217
|
183
|
* @param {Object} location - The location URI which specifies the host to load
|
218
|
184
|
* the config.js from.
|
219
|
185
|
* @private
|
220
|
186
|
* @returns {Promise<Object>}
|
221
|
187
|
*/
|
222
|
|
-function _loadConfig({ contextRoot, host, protocol, room }) {
|
|
188
|
+function _loadConfig(
|
|
189
|
+ dispatch: Dispatch<*>,
|
|
190
|
+ getState: Function,
|
|
191
|
+ { contextRoot, host, protocol, room }) {
|
223
|
192
|
// XXX As the mobile/React Native app does not employ config on the
|
224
|
193
|
// WelcomePage, do not download config.js from the deployment when
|
225
|
194
|
// navigating to the WelcomePage - the perceived/visible navigation will be
|
|
@@ -246,21 +215,9 @@ function _loadConfig({ contextRoot, host, protocol, room }) {
|
246
|
215
|
|
247
|
216
|
/* eslint-enable no-param-reassign */
|
248
|
217
|
|
249
|
|
- const key = `config.js/${baseURL}`;
|
250
|
|
-
|
251
|
218
|
return loadConfig(url).then(
|
252
|
219
|
/* onFulfilled */ config => {
|
253
|
|
- // Try to store the configuration in localStorage. If the deployment
|
254
|
|
- // specified 'getroom' as a function, for example, it does not make
|
255
|
|
- // sense to and it will not be stored.
|
256
|
|
- try {
|
257
|
|
- if (typeof window.config === 'undefined'
|
258
|
|
- || window.config !== config) {
|
259
|
|
- window.localStorage.setItem(key, JSON.stringify(config));
|
260
|
|
- }
|
261
|
|
- } catch (e) {
|
262
|
|
- // Ignore the error because the caching is optional.
|
263
|
|
- }
|
|
220
|
+ dispatch(storeConfig(baseURL, config));
|
264
|
221
|
|
265
|
222
|
return config;
|
266
|
223
|
},
|
|
@@ -268,23 +225,54 @@ function _loadConfig({ contextRoot, host, protocol, room }) {
|
268
|
225
|
// XXX The (down)loading of config failed. Try to use the last
|
269
|
226
|
// successfully fetched for that deployment. It may not match the
|
270
|
227
|
// shard.
|
271
|
|
- let storage;
|
|
228
|
+ const config = restoreConfig(baseURL);
|
272
|
229
|
|
273
|
|
- try {
|
274
|
|
- // XXX Even reading the property localStorage of window may
|
275
|
|
- // throw an error (which is user agent-specific behavior).
|
276
|
|
- storage = window.localStorage;
|
277
|
|
-
|
278
|
|
- const config = storage.getItem(key);
|
279
|
|
-
|
280
|
|
- if (config) {
|
281
|
|
- return JSON.parse(config);
|
282
|
|
- }
|
283
|
|
- } catch (e) {
|
284
|
|
- // Somehow incorrect data ended up in the storage. Clean it up.
|
285
|
|
- storage && storage.removeItem(key);
|
|
230
|
+ if (config) {
|
|
231
|
+ return config;
|
286
|
232
|
}
|
287
|
233
|
|
288
|
234
|
throw error;
|
289
|
235
|
});
|
290
|
236
|
}
|
|
237
|
+
|
|
238
|
+/**
|
|
239
|
+ * Redirects to another page generated by replacing the path in the original URL
|
|
240
|
+ * with the given path.
|
|
241
|
+ *
|
|
242
|
+ * @param {(string)} pathname - The path to navigate to.
|
|
243
|
+ * @returns {Function}
|
|
244
|
+ */
|
|
245
|
+export function redirectWithStoredParams(pathname: string) {
|
|
246
|
+ return (dispatch: Dispatch<*>, getState: Function) => {
|
|
247
|
+ const { locationURL } = getState()['features/base/connection'];
|
|
248
|
+ const newLocationURL = new URL(locationURL.href);
|
|
249
|
+
|
|
250
|
+ newLocationURL.pathname = pathname;
|
|
251
|
+ window.location.assign(newLocationURL.toString());
|
|
252
|
+ };
|
|
253
|
+}
|
|
254
|
+
|
|
255
|
+/**
|
|
256
|
+ * Reloads the page by restoring the original URL.
|
|
257
|
+ *
|
|
258
|
+ * @returns {Function}
|
|
259
|
+ */
|
|
260
|
+export function reloadWithStoredParams() {
|
|
261
|
+ return (dispatch: Dispatch<*>, getState: Function) => {
|
|
262
|
+ const { locationURL } = getState()['features/base/connection'];
|
|
263
|
+ const windowLocation = window.location;
|
|
264
|
+ const oldSearchString = windowLocation.search;
|
|
265
|
+
|
|
266
|
+ windowLocation.replace(locationURL.toString());
|
|
267
|
+
|
|
268
|
+ if (window.self !== window.top
|
|
269
|
+ && locationURL.search === oldSearchString) {
|
|
270
|
+ // NOTE: Assuming that only the hash or search part of the URL will
|
|
271
|
+ // be changed!
|
|
272
|
+ // location.reload will not trigger redirect/reload for iframe when
|
|
273
|
+ // only the hash params are changed. That's why we need to call
|
|
274
|
+ // reload in addition to replace.
|
|
275
|
+ windowLocation.reload();
|
|
276
|
+ }
|
|
277
|
+ };
|
|
278
|
+}
|