Browse Source

[RN] Add known-domains feature

master
Zoltan Bettenbuk 7 years ago
parent
commit
ee94d79ee6

+ 1
- 0
react/features/app/components/App.native.js View File

@@ -6,6 +6,7 @@ import { Linking } from 'react-native';
6 6
 
7 7
 import '../../analytics';
8 8
 import '../../authentication';
9
+import '../../base/domains';
9 10
 import { Platform } from '../../base/react';
10 11
 import {
11 12
     AspectRatioDetector,

+ 12
- 0
react/features/base/domains/actionTypes.js View File

@@ -0,0 +1,12 @@
1
+// @flow
2
+
3
+/**
4
+ * Action to add new domains to the list of domains known to the feature
5
+ * base/domains.
6
+ *
7
+ * {
8
+ *     type: ADD_KNOWN_DOMAINS,
9
+ *     knownDomains: Array<string>
10
+ * }
11
+ */
12
+export const ADD_KNOWN_DOMAINS = Symbol('ADD_KNOWN_DOMAINS');

+ 21
- 0
react/features/base/domains/actions.js View File

@@ -0,0 +1,21 @@
1
+// @flow
2
+
3
+import { ADD_KNOWN_DOMAINS } from './actionTypes';
4
+
5
+/**
6
+ * Sends an action to add one or an array of known domains if not present yet.
7
+ *
8
+ * @param {string | Array<string>} knownDomains - The new domain as a string or
9
+ * an array of domains.
10
+ * @returns {{
11
+ *     type: ADD_KNOWN_DOMAINS,
12
+ *     knownDomains: Array<string>
13
+ * }}
14
+ */
15
+export function addKnownDomains(knownDomains: string | Array<string>) {
16
+    return {
17
+        type: ADD_KNOWN_DOMAINS,
18
+        knownDomains: typeof knownDomains === 'string'
19
+            ? [ knownDomains ] : knownDomains
20
+    };
21
+}

+ 15
- 0
react/features/base/domains/constants.js View File

@@ -0,0 +1,15 @@
1
+// @flow
2
+
3
+/**
4
+ * A list of domains we consider jitsi-enabled domains by default. This is in
5
+ * line with the app links on iOS and Android, but stands here as retreiving
6
+ * those programatically is not straightforward.
7
+ */
8
+export const JITSI_KNOWN_DOMAINS = [
9
+    'beta.meet.jit.si',
10
+    'beta.hipchat.me',
11
+    'chaos.hipchat.me',
12
+    'enso.me',
13
+    'hipchat.me',
14
+    'meet.jit.si'
15
+];

+ 5
- 0
react/features/base/domains/index.js View File

@@ -0,0 +1,5 @@
1
+export * from './actions';
2
+export * from './actionTypes';
3
+
4
+import './middleware';
5
+import './reducer';

+ 59
- 0
react/features/base/domains/middleware.js View File

@@ -0,0 +1,59 @@
1
+// @flow
2
+
3
+import { APP_WILL_MOUNT } from '../../app';
4
+import { SET_ROOM } from '../conference';
5
+import { MiddlewareRegistry } from '../redux';
6
+import { parseURIString } from '../util';
7
+
8
+import { addKnownDomains } from './actions';
9
+import { JITSI_KNOWN_DOMAINS } from './constants';
10
+
11
+MiddlewareRegistry.register(store => next => action => {
12
+    const result = next(action);
13
+
14
+    switch (action.type) {
15
+
16
+    case APP_WILL_MOUNT:
17
+        _ensureDefaultServer(store);
18
+        break;
19
+
20
+    case SET_ROOM:
21
+        _parseAndAddKnownDomain(store);
22
+        break;
23
+    }
24
+
25
+    return result;
26
+});
27
+
28
+/**
29
+ * Ensures presence of the default server in the known domains list.
30
+ *
31
+ * @param {Object} store - The redux store.
32
+ * @private
33
+ * @returns {Promise}
34
+ */
35
+function _ensureDefaultServer({ dispatch, getState }) {
36
+    const { app } = getState()['features/app'];
37
+    const defaultURL = parseURIString(app._getDefaultURL());
38
+
39
+    dispatch(addKnownDomains([
40
+        defaultURL.host,
41
+        ...JITSI_KNOWN_DOMAINS
42
+    ]));
43
+}
44
+
45
+/**
46
+ * Retrieves the domain name of a room upon join and stores it in the known
47
+ * domain list, if not present yet.
48
+ *
49
+ * @param {Object} store - The redux store.
50
+ * @private
51
+ * @returns {Promise}
52
+ */
53
+function _parseAndAddKnownDomain({ dispatch, getState }) {
54
+    const { locationURL } = getState()['features/base/connection'];
55
+
56
+    locationURL
57
+        && locationURL.host
58
+        && dispatch(addKnownDomains(locationURL.host));
59
+}

+ 49
- 0
react/features/base/domains/reducer.js View File

@@ -0,0 +1,49 @@
1
+// @flow
2
+
3
+import { ReducerRegistry } from '../redux';
4
+import { PersistenceRegistry } from '../storage';
5
+
6
+import { ADD_KNOWN_DOMAINS } from './actionTypes';
7
+
8
+const DEFAULT_STATE = [];
9
+
10
+const STORE_NAME = 'features/base/domains';
11
+
12
+PersistenceRegistry.register(STORE_NAME);
13
+
14
+ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
15
+    switch (action.type) {
16
+    case ADD_KNOWN_DOMAINS:
17
+        return _addKnownDomain(state, action);
18
+
19
+    default:
20
+        return state;
21
+    }
22
+});
23
+
24
+/**
25
+ * Adds an array of new domains to the known domain list if not present yet.
26
+ *
27
+ * @param {Object} state - The redux state.
28
+ * @param {Object} action - The redux action.
29
+ * @private
30
+ * @returns {Object}
31
+ */
32
+function _addKnownDomain(state, action) {
33
+    const { knownDomains: knownDomainsToAdd } = action;
34
+    const knownDomains = Array.from(state);
35
+
36
+    if (Array.isArray(knownDomainsToAdd)) {
37
+        for (let knownDomain of knownDomainsToAdd) {
38
+            knownDomain = knownDomain.toLowerCase();
39
+
40
+            if (knownDomains.indexOf(knownDomain) === -1) {
41
+                knownDomains.push(knownDomain);
42
+            }
43
+        }
44
+
45
+        return knownDomains;
46
+    }
47
+
48
+    return state;
49
+}

Loading…
Cancel
Save