Преглед изворни кода

Introduce interceptComponent function

master
Ilya Daynatovich пре 8 година
родитељ
комит
6a0b92638c

+ 4
- 7
react/features/app/functions.web.js Прегледај датотеку

@@ -2,10 +2,9 @@
2 2
 
3 3
 import { isRoomValid } from '../base/conference';
4 4
 import { RouteRegistry } from '../base/navigator';
5
-import { Platform } from '../base/react';
6 5
 import { Conference } from '../conference';
7
-import { MobileBrowserPage } from '../unsupported-browser';
8 6
 import { WelcomePage } from '../welcome';
7
+import { interceptComponent } from '../base/util';
9 8
 
10 9
 import URLProcessor from '../../../modules/config/URLProcessor';
11 10
 import KeyboardShortcut
@@ -27,21 +26,19 @@ export { _getRoomAndDomainFromUrlString } from './functions.native';
27 26
  * @returns {Route}
28 27
  */
29 28
 export function _getRouteToRender(stateOrGetState) {
30
-    const OS = Platform.OS;
31 29
     const state
32 30
         = typeof stateOrGetState === 'function'
33 31
             ? stateOrGetState()
34 32
             : stateOrGetState;
35 33
 
36 34
     // If mobile browser page was shown, there is no need to show it again.
37
-    const { mobileBrowserPageIsShown } = state['features/unsupported-browser'];
38 35
     const { room } = state['features/base/conference'];
39 36
     const component = isRoomValid(room) ? Conference : WelcomePage;
40 37
     const route = RouteRegistry.getRouteByComponent(component);
41 38
 
42
-    if ((OS === 'android' || OS === 'ios') && !mobileBrowserPageIsShown) {
43
-        route.component = MobileBrowserPage;
44
-    }
39
+    // Intercepts route components if any of component interceptor rules
40
+    // is satisfied.
41
+    route.component = interceptComponent(state, component);
45 42
 
46 43
     return route;
47 44
 }

+ 78
- 0
react/features/base/util/componentInterceptor.js Прегледај датотеку

@@ -0,0 +1,78 @@
1
+import { Platform } from '../react';
2
+
3
+import {
4
+    MobileBrowserPage,
5
+    UnsupportedBrowserPage
6
+} from '../../unsupported-browser';
7
+
8
+/**
9
+ * Array of rules defining whether we should intercept component to render
10
+ * or not.
11
+ *
12
+ * @type {Array<Function>}
13
+ * @param {Object} state - Redux state object.
14
+ * @returns {ReactElement|void}
15
+ */
16
+const RULES = [
17
+
18
+    /**
19
+     * This rule describes case when user opens application using mobile
20
+     * browser. In order to promote the app, we choose to suggest the mobile
21
+     * app even if the browser supports the app (e.g. Google Chrome with
22
+     * WebRTC support on Android).
23
+     *
24
+     * @param {Object} state - Object containing Redux state.
25
+     * @returns {MobileBrowserPage|void} If the rule is satisfied then
26
+     * we should intercept existing component by MobileBrowserPage.
27
+     */
28
+    state => {
29
+        const OS = Platform.OS;
30
+        const { mobileBrowserPageIsShown }
31
+        = state['features/unsupported-browser'];
32
+
33
+        if ((OS === 'android' || OS === 'ios') && !mobileBrowserPageIsShown) {
34
+            return MobileBrowserPage;
35
+        }
36
+    },
37
+
38
+    /**
39
+     * This rule describes case when user opens application using web browser
40
+     * that doesn't support WebRTC or Temasys plugin should be installed.
41
+     *
42
+     * @returns {UnsupportedBrowserPage|void} If the rule is satisfied
43
+     * then we should intercept existing component by UnsupportedBrowserPage.
44
+     */
45
+    () => {
46
+        if (true) {
47
+            return UnsupportedBrowserPage;
48
+        }
49
+    }
50
+];
51
+
52
+/**
53
+ * Utility method that responsible for intercepting of route components based on
54
+ * the set of defined rules.
55
+ *
56
+ * @param {Object|Function} stateOrGetState - Either Redux state object or
57
+ * getState() function.
58
+ * @param {ReactElement} currentComponent - Current route component to render.
59
+ * @returns {ReactElement} If any of rules is satisfied returns intercepted
60
+ * component.
61
+ */
62
+export function interceptComponent(stateOrGetState, currentComponent) {
63
+    let result;
64
+    const state
65
+        = typeof stateOrGetState === 'function'
66
+        ? stateOrGetState()
67
+        : stateOrGetState;
68
+
69
+    for (const rule of RULES) {
70
+        result = rule(state);
71
+
72
+        if (result) {
73
+            break;
74
+        }
75
+    }
76
+
77
+    return result || currentComponent;
78
+}

+ 1
- 0
react/features/base/util/index.js Прегледај датотеку

@@ -1,2 +1,3 @@
1 1
 export * from './loadScript';
2 2
 export * from './roomnameGenerator';
3
+export * from './componentInterceptor';

+ 1
- 1
react/features/unsupported-browser/components/MobileBrowserPage.js Прегледај датотеку

@@ -100,7 +100,7 @@ class MobileBrowserPage extends Component {
100 100
         const textClasses = `${blockPrefix}__text ${blockPrefix}__text_small`;
101 101
         let primaryButtonClasses = `${blockPrefix}__button`;
102 102
 
103
-        primaryButtonClasses += `${blockPrefix}__button_primary`;
103
+        primaryButtonClasses += ` ${blockPrefix}__button_primary`;
104 104
 
105 105
         return (
106 106
             <div className = { blockPrefix }>

+ 3
- 1
react/features/unsupported-browser/components/UnsupportedBrowserPage.js Прегледај датотеку

@@ -98,7 +98,9 @@ export default class UnsupportedBrowserPage extends Component {
98 98
         }
99 99
 
100 100
         return (
101
-            <div className = 'browser'>
101
+            <div
102
+                className = 'browser'
103
+                key = { browser.name }>
102 104
                 <div className = 'browser__text'>
103 105
                     { browser.title }
104 106
                     { pluginHtml }

Loading…
Откажи
Сачувај