소스 검색

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

j8
hristoterezov 7 년 전
부모
커밋
df754f4f41
6개의 변경된 파일64개의 추가작업 그리고 31개의 파일을 삭제
  1. 10
    6
      conference.js
  2. 2
    0
      modules/UI/authentication/AuthHandler.js
  3. 8
    0
      modules/UI/util/UIUtil.js
  4. 0
    18
      modules/util/helpers.js
  5. 42
    0
      react/features/app/actions.js
  6. 2
    7
      react/features/overlay/actions.js

+ 10
- 6
conference.js 파일 보기

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

+ 2
- 0
modules/UI/authentication/AuthHandler.js 파일 보기

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

+ 8
- 0
modules/UI/util/UIUtil.js 파일 보기

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
     redirect(url) {
228
     redirect(url) {
221
         window.location.href = url;
229
         window.location.href = url;
222
     },
230
     },

+ 0
- 18
modules/util/helpers.js 파일 보기

16
     return deferred;
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
  * Prints the error and reports it to the global error handler.
20
  * Prints the error and reports it to the global error handler.
39
  *
21
  *

+ 42
- 0
react/features/app/actions.js 파일 보기

24
         _appNavigateToOptionalLocation(dispatch, getState, parseURIString(uri));
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
  * Triggers an in-app navigation to a specific location URI.
70
  * Triggers an in-app navigation to a specific location URI.
29
  *
71
  *

+ 2
- 7
react/features/overlay/actions.js 파일 보기

1
-import { appNavigate } from '../app';
1
+import { appNavigate, reloadWithStoredParams } from '../app';
2
 import { toURLString } from '../base/util';
2
 import { toURLString } from '../base/util';
3
-import { reload, replace } from '../../../modules/util/helpers';
4
 
3
 
5
 import {
4
 import {
6
     MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
5
     MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
44
 
43
 
45
         if (navigator.product === 'ReactNative') {
44
         if (navigator.product === 'ReactNative') {
46
             dispatch(appNavigate(toURLString(locationURL)));
45
             dispatch(appNavigate(toURLString(locationURL)));
47
-        } else if (window.self === window.top) {
48
-            replace(locationURL);
49
         } else {
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…
취소
저장