Browse Source

fix(reload): Preserve URL params on reload/redirect.

j8
hristoterezov 7 years ago
parent
commit
df754f4f41

+ 10
- 6
conference.js View File

@@ -7,7 +7,7 @@ import Recorder from './modules/recorder/Recorder';
7 7
 
8 8
 import mediaDeviceHelper from './modules/devices/mediaDeviceHelper';
9 9
 
10
-import { reload, reportError } from './modules/util/helpers';
10
+import { reportError } from './modules/util/helpers';
11 11
 
12 12
 import * as RemoteControlEvents
13 13
     from './service/remotecontrol/RemoteControlEvents';
@@ -24,6 +24,10 @@ import {
24 24
     initAnalytics,
25 25
     sendAnalytics
26 26
 } from './react/features/analytics';
27
+import {
28
+    redirectWithStoredParams,
29
+    reloadWithStoredParams
30
+} from './react/features/app';
27 31
 
28 32
 import EventEmitter from 'events';
29 33
 
@@ -216,7 +220,7 @@ function maybeRedirectToWelcomePage(options) {
216 220
         // save whether current user is guest or not, before navigating
217 221
         // to close page
218 222
         window.sessionStorage.setItem('guest', isGuest);
219
-        assignWindowLocationPathname(`static/${
223
+        redirectToStaticPage(`static/${
220 224
             options.feedbackSubmitted ? 'close.html' : 'close2.html'}`);
221 225
 
222 226
         return;
@@ -234,7 +238,7 @@ function maybeRedirectToWelcomePage(options) {
234 238
     if (config.enableWelcomePage) {
235 239
         setTimeout(
236 240
             () => {
237
-                assignWindowLocationPathname('./');
241
+                APP.store.dispatch(redirectWithStoredParams('/'));
238 242
             },
239 243
             3000);
240 244
     }
@@ -250,7 +254,7 @@ function maybeRedirectToWelcomePage(options) {
250 254
  * assigning it to window.location.pathname.
251 255
  * @return {void}
252 256
  */
253
-function assignWindowLocationPathname(pathname) {
257
+function redirectToStaticPage(pathname) {
254 258
     const windowLocation = window.location;
255 259
     let newPathname = pathname;
256 260
 
@@ -310,7 +314,7 @@ class ConferenceConnector {
310 314
 
311 315
         case JitsiConferenceErrors.NOT_ALLOWED_ERROR: {
312 316
             // let's show some auth not allowed page
313
-            assignWindowLocationPathname('static/authError.html');
317
+            redirectToStaticPage('static/authError.html');
314 318
             break;
315 319
         }
316 320
 
@@ -378,7 +382,7 @@ class ConferenceConnector {
378 382
             break;
379 383
 
380 384
         case JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS:
381
-            reload();
385
+            APP.store.dispatch(reloadWithStoredParams());
382 386
             break;
383 387
 
384 388
         default:

+ 2
- 0
modules/UI/authentication/AuthHandler.js View File

@@ -66,6 +66,8 @@ function doExternalAuth(room, lockPassword) {
66 66
  * @param {string} [roomName] the name of the conference room.
67 67
  */
68 68
 function redirectToTokenAuthService(roomName) {
69
+    // FIXME: This method will not preserve the other URL params that were
70
+    // originally passed.
69 71
     UIUtil.redirect(getTokenAuthUrl(roomName, false));
70 72
 }
71 73
 

+ 8
- 0
modules/UI/util/UIUtil.js View File

@@ -217,6 +217,14 @@ const UIUtil = {
217 217
         }
218 218
     },
219 219
 
220
+    /**
221
+     * Redirects to a given URL.
222
+     *
223
+     * @param {string} url - The redirect URL.
224
+     * NOTE: Currently used to redirect to 3rd party location for
225
+     * authentication. In most cases redirectWithStoredParams action must be
226
+     * used instead of this method in order to preserve curent URL params.
227
+     */
220 228
     redirect(url) {
221 229
         window.location.href = url;
222 230
     },

+ 0
- 18
modules/util/helpers.js View File

@@ -16,24 +16,6 @@ export function createDeferred() {
16 16
     return deferred;
17 17
 }
18 18
 
19
-/**
20
- * Reload page.
21
- */
22
-export function reload() {
23
-    window.location.reload();
24
-}
25
-
26
-/**
27
- * Redirects to a specific new URL by replacing the current location (in the
28
- * history).
29
- *
30
- * @param {string} url the URL pointing to the location where the user should
31
- * be redirected to.
32
- */
33
-export function replace(url) {
34
-    window.location.replace(url);
35
-}
36
-
37 19
 /**
38 20
  * Prints the error and reports it to the global error handler.
39 21
  *

+ 42
- 0
react/features/app/actions.js View File

@@ -24,6 +24,48 @@ export function appNavigate(uri: ?string) {
24 24
         _appNavigateToOptionalLocation(dispatch, getState, parseURIString(uri));
25 25
 }
26 26
 
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
+
27 69
 /**
28 70
  * Triggers an in-app navigation to a specific location URI.
29 71
  *

+ 2
- 7
react/features/overlay/actions.js View File

@@ -1,6 +1,5 @@
1
-import { appNavigate } from '../app';
1
+import { appNavigate, reloadWithStoredParams } from '../app';
2 2
 import { toURLString } from '../base/util';
3
-import { reload, replace } from '../../../modules/util/helpers';
4 3
 
5 4
 import {
6 5
     MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
@@ -44,12 +43,8 @@ export function _reloadNow() {
44 43
 
45 44
         if (navigator.product === 'ReactNative') {
46 45
             dispatch(appNavigate(toURLString(locationURL)));
47
-        } else if (window.self === window.top) {
48
-            replace(locationURL);
49 46
         } else {
50
-            // In an iframe reload with the reload() utility because the
51
-            // replace() utility does not work on an iframe.
52
-            reload();
47
+            dispatch(reloadWithStoredParams());
53 48
         }
54 49
     };
55 50
 }

Loading…
Cancel
Save