瀏覽代碼

Introduce interceptComponent function

master
Ilya Daynatovich 8 年之前
父節點
當前提交
6a0b92638c

+ 4
- 7
react/features/app/functions.web.js 查看文件

2
 
2
 
3
 import { isRoomValid } from '../base/conference';
3
 import { isRoomValid } from '../base/conference';
4
 import { RouteRegistry } from '../base/navigator';
4
 import { RouteRegistry } from '../base/navigator';
5
-import { Platform } from '../base/react';
6
 import { Conference } from '../conference';
5
 import { Conference } from '../conference';
7
-import { MobileBrowserPage } from '../unsupported-browser';
8
 import { WelcomePage } from '../welcome';
6
 import { WelcomePage } from '../welcome';
7
+import { interceptComponent } from '../base/util';
9
 
8
 
10
 import URLProcessor from '../../../modules/config/URLProcessor';
9
 import URLProcessor from '../../../modules/config/URLProcessor';
11
 import KeyboardShortcut
10
 import KeyboardShortcut
27
  * @returns {Route}
26
  * @returns {Route}
28
  */
27
  */
29
 export function _getRouteToRender(stateOrGetState) {
28
 export function _getRouteToRender(stateOrGetState) {
30
-    const OS = Platform.OS;
31
     const state
29
     const state
32
         = typeof stateOrGetState === 'function'
30
         = typeof stateOrGetState === 'function'
33
             ? stateOrGetState()
31
             ? stateOrGetState()
34
             : stateOrGetState;
32
             : stateOrGetState;
35
 
33
 
36
     // If mobile browser page was shown, there is no need to show it again.
34
     // If mobile browser page was shown, there is no need to show it again.
37
-    const { mobileBrowserPageIsShown } = state['features/unsupported-browser'];
38
     const { room } = state['features/base/conference'];
35
     const { room } = state['features/base/conference'];
39
     const component = isRoomValid(room) ? Conference : WelcomePage;
36
     const component = isRoomValid(room) ? Conference : WelcomePage;
40
     const route = RouteRegistry.getRouteByComponent(component);
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
     return route;
43
     return route;
47
 }
44
 }

+ 78
- 0
react/features/base/util/componentInterceptor.js 查看文件

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
 export * from './loadScript';
1
 export * from './loadScript';
2
 export * from './roomnameGenerator';
2
 export * from './roomnameGenerator';
3
+export * from './componentInterceptor';

+ 1
- 1
react/features/unsupported-browser/components/MobileBrowserPage.js 查看文件

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

+ 3
- 1
react/features/unsupported-browser/components/UnsupportedBrowserPage.js 查看文件

98
         }
98
         }
99
 
99
 
100
         return (
100
         return (
101
-            <div className = 'browser'>
101
+            <div
102
+                className = 'browser'
103
+                key = { browser.name }>
102
                 <div className = 'browser__text'>
104
                 <div className = 'browser__text'>
103
                     { browser.title }
105
                     { browser.title }
104
                     { pluginHtml }
106
                     { pluginHtml }

Loading…
取消
儲存