|
|
@@ -3,23 +3,47 @@
|
|
3
|
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
|
14
|
* @returns {string}
|
|
12
|
15
|
*/
|
|
13
|
16
|
export function getInviteURL(stateOrGetState: Function | Object): string {
|
|
14
|
17
|
const state = toState(stateOrGetState);
|
|
15
|
|
- const locationURL
|
|
|
18
|
+ let locationURL
|
|
16
|
19
|
= state instanceof URL
|
|
17
|
20
|
? state
|
|
18
|
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
|
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
|
48
|
* Gets a {@link URL} without hash and query/search params from a specific
|
|
25
|
49
|
* {@code URL}.
|