Kaynağa Gözat

Invite URL w/o (hash & query/search) params

j8
Lyubo Marinov 8 yıl önce
ebeveyn
işleme
a4a13bed84

+ 1
- 0
react/features/app/index.js Dosyayı Görüntüle

@@ -3,4 +3,5 @@ export * from './actionTypes';
3 3
 export * from './components';
4 4
 export * from './functions';
5 5
 
6
+import './middleware';
6 7
 import './reducer';

+ 55
- 0
react/features/app/middleware.js Dosyayı Görüntüle

@@ -0,0 +1,55 @@
1
+import {
2
+    CONNECTION_ESTABLISHED,
3
+    getURLWithoutParams
4
+} from '../base/connection';
5
+import { MiddlewareRegistry } from '../base/redux';
6
+
7
+MiddlewareRegistry.register(store => next => action => {
8
+    switch (action.type) {
9
+    case CONNECTION_ESTABLISHED:
10
+        return _connectionEstablished(store, next, action);
11
+    }
12
+
13
+    return next(action);
14
+});
15
+
16
+/**
17
+ * Notifies the feature app that the action {@link CONNECTION_ESTABLISHED} is
18
+ * being dispatched within a specific Redux {@code store}.
19
+ *
20
+ * @param {Store} store - The Redux store in which the specified {@code action}
21
+ * is being dispatched.
22
+ * @param {Dispatch} next - The Redux {@code dispatch} function to dispatch the
23
+ * specified {@code action} to the specified {@code store}.
24
+ * @param {Action} action - The Redux action {@code CONNECTION_ESTABLISHED}
25
+ * which is being dispatched in the specified {@code store}.
26
+ * @private
27
+ * @returns {Object} The new state that is the result of the reduction of the
28
+ * specified {@code action}.
29
+ */
30
+function _connectionEstablished(store, next, action) {
31
+    const result = next(action);
32
+
33
+    // In the Web app we explicitly do not want to display the hash and
34
+    // query/search URL params. Unfortunately, window.location and, more
35
+    // importantly, its params are used not only in jitsi-meet but also in
36
+    // lib-jitsi-meet. Consequenlty, the time to remove the params is
37
+    // determined by when no one needs them anymore.
38
+    const { history, location } = window;
39
+
40
+    if (history
41
+            && location
42
+            && history.length
43
+            && typeof history.replaceState === 'function') {
44
+        const replacement = getURLWithoutParams(location);
45
+
46
+        if (location !== replacement) {
47
+            history.replaceState(
48
+                history.state,
49
+                (document && document.title) || '',
50
+                replacement);
51
+        }
52
+    }
53
+
54
+    return result;
55
+}

+ 22
- 3
react/features/base/connection/functions.js Dosyayı Görüntüle

@@ -17,10 +17,29 @@ export function getInviteURL(stateOrGetState: Function | Object): ?string {
17 17
     let inviteURL;
18 18
 
19 19
     if (locationURL) {
20
-        const { host, pathname, protocol } = locationURL;
21
-
22
-        inviteURL = `${protocol}//${host}${pathname}`;
20
+        inviteURL = getURLWithoutParams(locationURL).href;
23 21
     }
24 22
 
25 23
     return inviteURL;
26 24
 }
25
+
26
+/**
27
+ * Gets a {@link URL} without hash and query/search params from a specific
28
+ * {@code URL}.
29
+ *
30
+ * @param {URL} url - The {@code URL} which may have hash and query/search
31
+ * params.
32
+ * @returns {URL}
33
+ */
34
+export function getURLWithoutParams(url: URL): URL {
35
+    const { hash, search } = url;
36
+
37
+    if ((hash && hash.length > 1) || (search && search.length > 1)) {
38
+        // eslint-disable-next-line no-param-reassign
39
+        url = new URL(url.href);
40
+        url.hash = '';
41
+        url.search = '';
42
+    }
43
+
44
+    return url;
45
+}

Loading…
İptal
Kaydet