瀏覽代碼

feat(base/connection): throw error and add isInviteURLReady

master
paweldomas 6 年之前
父節點
當前提交
e4af5ddbe9
共有 1 個檔案被更改,包括 29 行新增5 行删除
  1. 29
    5
      react/features/base/connection/functions.js

+ 29
- 5
react/features/base/connection/functions.js 查看文件

3
 import { toState } from '../redux';
3
 import { toState } from '../redux';
4
 
4
 
5
 /**
5
 /**
6
- * Retrieves a simplified version of the conference/location URL stripped of URL
7
- * params (i.e. Query/search and hash) which should be used for sending invites.
6
+ * Retrieves a simplified version of the conference/location URL stripped of URL params (i.e. Query/search and hash)
7
+ * which should be used for sending invites.
8
+ * NOTE that the method will throw an error if called too early. That is before the conference is joined or before
9
+ * the process of joining one has started. This limitation does not apply to the case when called with the URL object
10
+ * instance. Use {@link isInviteURLReady} to check if it's safe to call the method already.
8
  *
11
  *
9
- * @param {Function|Object} stateOrGetState - The redux state or redux's
10
- * {@code getState} function.
12
+ * @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function or the URL object
13
+ * to be stripped.
11
  * @returns {string}
14
  * @returns {string}
12
  */
15
  */
13
 export function getInviteURL(stateOrGetState: Function | Object): string {
16
 export function getInviteURL(stateOrGetState: Function | Object): string {
14
     const state = toState(stateOrGetState);
17
     const state = toState(stateOrGetState);
15
-    const locationURL
18
+    let locationURL
16
         = state instanceof URL
19
         = state instanceof URL
17
             ? state
20
             ? state
18
             : state['features/base/connection'].locationURL;
21
             : state['features/base/connection'].locationURL;
19
 
22
 
23
+    // If there's no locationURL on the base/connection feature try the base/config where it's set earlier.
24
+    if (!locationURL) {
25
+        locationURL = state['features/base/config'].locationURL;
26
+    }
27
+
28
+    if (!locationURL) {
29
+        throw new Error('Can not get invite URL - the app is not ready');
30
+    }
31
+
20
     return getURLWithoutParams(locationURL).href;
32
     return getURLWithoutParams(locationURL).href;
21
 }
33
 }
22
 
34
 
35
+/**
36
+ * Checks whether or not is safe to call the {@link getInviteURL} method already.
37
+ *
38
+ * @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function.
39
+ * @returns {boolean}
40
+ */
41
+export function isInviteURLReady(stateOrGetState: Function | Object): boolean {
42
+    const state = toState(stateOrGetState);
43
+
44
+    return Boolean(state['features/base/connection'].locationURL || state['features/base/config'].locationURL);
45
+}
46
+
23
 /**
47
 /**
24
  * Gets a {@link URL} without hash and query/search params from a specific
48
  * Gets a {@link URL} without hash and query/search params from a specific
25
  * {@code URL}.
49
  * {@code URL}.

Loading…
取消
儲存