Przeglądaj źródła

Move interceptComponent.js out of features/base/util

I don't like the file/function name, I'm not excited about the
complexity of the logic it implements, and it's definitely a reusable
piece worthy of being called a utility.
j8
Lyubo Marinov 8 lat temu
rodzic
commit
8e6f043586

+ 100
- 6
react/features/app/functions.web.js Wyświetl plik

@@ -1,10 +1,17 @@
1
-/* global APP, loggingConfig */
1
+/* @flow */
2
+
3
+import Logger from 'jitsi-meet-logger';
2 4
 
3 5
 import { isRoomValid } from '../base/conference';
4 6
 import JitsiMeetJS from '../base/lib-jitsi-meet';
5
-import { RouteRegistry } from '../base/react';
6
-import { interceptComponent } from '../base/util';
7
+import { Platform, RouteRegistry } from '../base/react';
7 8
 import { Conference } from '../conference';
9
+import {
10
+    NoMobileApp,
11
+    PluginRequiredBrowser,
12
+    UnsupportedDesktopBrowser,
13
+    UnsupportedMobileBrowser
14
+} from '../unsupported-browser';
8 15
 import { WelcomePage } from '../welcome';
9 16
 
10 17
 import URLProcessor from '../../../modules/config/URLProcessor';
@@ -13,7 +20,65 @@ import KeyboardShortcut
13 20
 import getTokenData from '../../../modules/tokendata/TokenData';
14 21
 import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
15 22
 
16
-const Logger = require('jitsi-meet-logger');
23
+declare var APP: Object;
24
+declare var interfaceConfig: Object;
25
+declare var loggingConfig: Object;
26
+
27
+/**
28
+ * Array of rules defining whether we should {@link _interceptComponent} to
29
+ * render.
30
+ *
31
+ * @private
32
+ * @param {Object} state - Object containing current Redux state.
33
+ * @returns {ReactElement|void}
34
+ * @type {Function[]}
35
+ */
36
+const _INTERCEPT_COMPONENT_RULES = [
37
+
38
+    /**
39
+     * This rule describes case when user opens application using mobile
40
+     * browser. In order to promote the app, we choose to suggest the mobile
41
+     * app even if the browser supports the app (e.g. Google Chrome with
42
+     * WebRTC support on Android).
43
+     *
44
+     * @param {Object} state - Redux state of the app.
45
+     * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
46
+     * we should intercept existing component by UnsupportedMobileBrowser.
47
+     */
48
+    () => {
49
+        const OS = Platform.OS;
50
+
51
+        if (OS === 'android' || OS === 'ios') {
52
+            const mobileAppPromo
53
+                = typeof interfaceConfig === 'object'
54
+                    && interfaceConfig.MOBILE_APP_PROMO;
55
+
56
+            return (
57
+                typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
58
+                    ? UnsupportedMobileBrowser
59
+                    : NoMobileApp);
60
+        }
61
+    },
62
+    state => {
63
+        const { webRTCReady } = state['features/base/lib-jitsi-meet'];
64
+
65
+        switch (typeof webRTCReady) {
66
+        case 'boolean':
67
+            if (webRTCReady === false) {
68
+                return UnsupportedDesktopBrowser;
69
+            }
70
+            break;
71
+
72
+        case 'undefined':
73
+            // If webRTCReady is not set, then we cannot use it to take a
74
+            // decision.
75
+            break;
76
+
77
+        default:
78
+            return PluginRequiredBrowser;
79
+        }
80
+    }
81
+];
17 82
 
18 83
 export { _parseURIString } from './functions.native';
19 84
 
@@ -25,7 +90,7 @@ export { _parseURIString } from './functions.native';
25 90
  * method.
26 91
  * @returns {Route}
27 92
  */
28
-export function _getRouteToRender(stateOrGetState) {
93
+export function _getRouteToRender(stateOrGetState: Object | Function) {
29 94
     const state
30 95
         = typeof stateOrGetState === 'function'
31 96
             ? stateOrGetState()
@@ -38,7 +103,7 @@ export function _getRouteToRender(stateOrGetState) {
38 103
 
39 104
     // Intercepts route components if any of component interceptor rules
40 105
     // is satisfied.
41
-    route.component = interceptComponent(state, component);
106
+    route.component = _interceptComponent(state, component);
42 107
 
43 108
     return route;
44 109
 }
@@ -118,3 +183,32 @@ function _initLogging() {
118 183
         JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
119 184
     }
120 185
 }
186
+
187
+/**
188
+ * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
189
+ *
190
+ * @param {Object|Function} stateOrGetState - Either Redux state object or
191
+ * getState() function.
192
+ * @param {ReactElement} component - Current route component to render.
193
+ * @private
194
+ * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
195
+ * intercepted component.
196
+ */
197
+function _interceptComponent(
198
+        stateOrGetState: Object,
199
+        component: ReactElement<*>) {
200
+    let result;
201
+    const state
202
+        = typeof stateOrGetState === 'function'
203
+            ? stateOrGetState()
204
+            : stateOrGetState;
205
+
206
+    for (const rule of _INTERCEPT_COMPONENT_RULES) {
207
+        result = rule(state);
208
+        if (result) {
209
+            break;
210
+        }
211
+    }
212
+
213
+    return result || component;
214
+}

+ 0
- 1
react/features/base/util/index.js Wyświetl plik

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

+ 0
- 98
react/features/base/util/interceptComponent.js Wyświetl plik

@@ -1,98 +0,0 @@
1
-/* @flow */
2
-
3
-import { Platform } from '../react';
4
-import {
5
-    NoMobileApp,
6
-    PluginRequiredBrowser,
7
-    UnsupportedDesktopBrowser,
8
-    UnsupportedMobileBrowser
9
-} from '../../unsupported-browser';
10
-
11
-declare var APP: Object;
12
-declare var interfaceConfig: Object;
13
-declare var JitsiMeetJS: Object;
14
-
15
-/**
16
- * Array of rules defining whether we should intercept component to render
17
- * or not.
18
- *
19
- * @private
20
- * @param {Object} state - Object containing current Redux state.
21
- * @returns {ReactElement|void}
22
- * @type {Function[]}
23
- */
24
-const _RULES = [
25
-
26
-    /**
27
-     * This rule describes case when user opens application using mobile
28
-     * browser. In order to promote the app, we choose to suggest the mobile
29
-     * app even if the browser supports the app (e.g. Google Chrome with
30
-     * WebRTC support on Android).
31
-     *
32
-     * @param {Object} state - Redux state of the app.
33
-     * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
34
-     * we should intercept existing component by UnsupportedMobileBrowser.
35
-     */
36
-    () => {
37
-        const OS = Platform.OS;
38
-
39
-        if (OS === 'android' || OS === 'ios') {
40
-            const mobileAppPromo
41
-                = typeof interfaceConfig === 'object'
42
-                    && interfaceConfig.MOBILE_APP_PROMO;
43
-
44
-            return (
45
-                typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
46
-                    ? UnsupportedMobileBrowser
47
-                    : NoMobileApp);
48
-        }
49
-    },
50
-    state => {
51
-        const { webRTCReady } = state['features/base/lib-jitsi-meet'];
52
-
53
-        switch (typeof webRTCReady) {
54
-        case 'boolean':
55
-            if (webRTCReady === false) {
56
-                return UnsupportedDesktopBrowser;
57
-            }
58
-            break;
59
-
60
-        case 'undefined':
61
-            // If webRTCReady is not set, then we cannot use it to take a
62
-            // decision.
63
-            break;
64
-
65
-        default:
66
-            return PluginRequiredBrowser;
67
-        }
68
-    }
69
-];
70
-
71
-/**
72
- * Utility method that responsible for intercepting of route components based on
73
- * the set of defined rules.
74
- *
75
- * @param {Object|Function} stateOrGetState - Either Redux state object or
76
- * getState() function.
77
- * @param {ReactElement} component - Current route component to render.
78
- * @returns {ReactElement} If any of rules is satisfied returns intercepted
79
- * component.
80
- */
81
-export function interceptComponent(
82
-        stateOrGetState: Object,
83
-        component: ReactElement<*>) {
84
-    let result;
85
-    const state
86
-        = typeof stateOrGetState === 'function'
87
-            ? stateOrGetState()
88
-            : stateOrGetState;
89
-
90
-    for (const rule of _RULES) {
91
-        result = rule(state);
92
-        if (result) {
93
-            break;
94
-        }
95
-    }
96
-
97
-    return result || component;
98
-}

Ładowanie…
Anuluj
Zapisz