Sfoglia il codice sorgente

Refactor config loading

j8
Bettenbuk Zoltan 6 anni fa
parent
commit
3987655f2a

+ 2
- 2
package-lock.json Vedi File

@@ -5519,8 +5519,8 @@
5519 5519
       }
5520 5520
     },
5521 5521
     "eslint-config-jitsi": {
5522
-      "version": "github:jitsi/eslint-config-jitsi#1f3fbcea8baa1ab95929a351be3977e00cb162ec",
5523
-      "from": "github:jitsi/eslint-config-jitsi#1.0.0",
5522
+      "version": "github:jitsi/eslint-config-jitsi#5f9fe4fd00be471ab6f5d06f77ffc90bba0853e8",
5523
+      "from": "github:jitsi/eslint-config-jitsi#1.0.1",
5524 5524
       "dev": true
5525 5525
     },
5526 5526
     "eslint-import-resolver-node": {

+ 1
- 1
package.json Vedi File

@@ -99,7 +99,7 @@
99 99
     "clean-css": "3.4.25",
100 100
     "css-loader": "0.28.7",
101 101
     "eslint": "5.6.1",
102
-    "eslint-config-jitsi": "github:jitsi/eslint-config-jitsi#1.0.0",
102
+    "eslint-config-jitsi": "github:jitsi/eslint-config-jitsi#1.0.1",
103 103
     "eslint-plugin-flowtype": "2.50.3",
104 104
     "eslint-plugin-import": "2.14.0",
105 105
     "eslint-plugin-jsdoc": "3.8.0",

+ 50
- 156
react/features/app/actions.js Vedi File

@@ -31,176 +31,70 @@ declare var APP: Object;
31 31
  * @returns {Function}
32 32
  */
33 33
 export function appNavigate(uri: ?string) {
34
-    return (dispatch: Dispatch<any>, getState: Function) =>
35
-        _appNavigateToOptionalLocation(dispatch, getState, parseURIString(uri));
36
-}
37
-
38
-/**
39
- * Triggers an in-app navigation to a specific location URI.
40
- *
41
- * @param {Dispatch} dispatch - The redux {@code dispatch} function.
42
- * @param {Function} getState - The redux function that gets/retrieves the redux
43
- * state.
44
- * @param {Object} newLocation - The location URI to navigate to. The value
45
- * cannot be undefined and is assumed to have all properties such as
46
- * {@code host}, {@code contextRoot}, and {@code room} defined. Depending on the
47
- * property, it may have a value equal to {@code undefined} and that may be
48
- * acceptable.
49
- * @private
50
- * @returns {Promise<void>}
51
- */
52
-function _appNavigateToMandatoryLocation(
53
-        dispatch: Dispatch<any>, getState: Function,
54
-        newLocation: Object
55
-): Promise<void> {
56
-    const { room } = newLocation;
57
-    const locationURL = new URL(newLocation.toString());
58
-
59
-    dispatch(configWillLoad(locationURL));
60
-
61
-    return (
62
-        _loadConfig(dispatch, getState, newLocation)
63
-            .then(
64
-                config => loadConfigSettled(/* error */ undefined, config),
65
-                error => loadConfigSettled(error, /* config */ undefined))
66
-            .then(() => dispatch(setRoom(room))));
67
-
68
-    /**
69
-     * Notifies that an attempt to load a configuration has completed. Due to
70
-     * the asynchronous nature of the loading, the specified {@code config} may
71
-     * or may not be required by the time the notification arrives.
72
-     *
73
-     * @param {string|undefined} error - If the loading has failed, the error
74
-     * detailing the cause of the failure.
75
-     * @param {Object|undefined} config - If the loading has succeeded, the
76
-     * loaded configuration.
77
-     * @returns {void}
78
-     */
79
-    function loadConfigSettled(error, config) {
80
-        // Due to the asynchronous nature of the loading, the specified config
81
-        // may or may not be required by the time the notification arrives. If
82
-        // we receive the config for a location we are no longer interested in,
83
-        // "ignore" it - deliver it to the external API, for example, but do not
84
-        // proceed with the appNavigate procedure/process.
85
-        if (getState()['features/base/config'].locationURL === locationURL) {
86
-            dispatch(setLocationURL(locationURL));
87
-            dispatch(setConfig(config));
88
-        } else {
89
-            // eslint-disable-next-line no-param-reassign
90
-            error || (error = new Error('Config no longer needed!'));
91
-
92
-            // XXX The failure could be, for example, because of a
93
-            // certificate-related error. In which case the connection will fail
94
-            // later in Strophe anyway.
95
-            dispatch(loadConfigError(error, locationURL));
96
-
97
-            throw error;
98
-        }
99
-    }
100
-}
101
-
102
-/**
103
- * Triggers an in-app navigation to a specific or undefined location (URI).
104
- *
105
- * @param {Dispatch} dispatch - The redux {@code dispatch} function.
106
- * @param {Function} getState - The redux function that gets/retrieves the redux
107
- * state.
108
- * @param {Object} location - The location (URI) to navigate to. The value may
109
- * be undefined.
110
- * @private
111
- * @returns {void}
112
- */
113
-function _appNavigateToOptionalLocation(
114
-        dispatch: Dispatch<any>, getState: Function,
115
-        location: Object) {
116
-    // If the specified location (URI) does not identify a host, use the app's
117
-    // default.
118
-    if (!location || !location.host) {
119
-        const defaultLocation = parseURIString(getDefaultURL(getState));
120
-
121
-        if (location) {
122
-            location.host = defaultLocation.host;
123
-
124
-            // FIXME Turn location's host, hostname, and port properties into
125
-            // setters in order to reduce the risks of inconsistent state.
126
-            location.hostname = defaultLocation.hostname;
127
-            location.pathname
128
-                = defaultLocation.pathname + location.pathname.substr(1);
129
-            location.port = defaultLocation.port;
130
-            location.protocol = defaultLocation.protocol;
131
-        } else {
132
-            // eslint-disable-next-line no-param-reassign
133
-            location = defaultLocation;
34
+    return async (dispatch: Dispatch<any>, getState: Function) => {
35
+        let location = parseURIString(uri);
36
+
37
+        // If the specified location (URI) does not identify a host, use the app's
38
+        // default.
39
+        if (!location || !location.host) {
40
+            const defaultLocation = parseURIString(getDefaultURL(getState));
41
+
42
+            if (location) {
43
+                location.host = defaultLocation.host;
44
+
45
+                // FIXME Turn location's host, hostname, and port properties into
46
+                // setters in order to reduce the risks of inconsistent state.
47
+                location.hostname = defaultLocation.hostname;
48
+                location.pathname
49
+                    = defaultLocation.pathname + location.pathname.substr(1);
50
+                location.port = defaultLocation.port;
51
+                location.protocol = defaultLocation.protocol;
52
+            } else {
53
+                location = defaultLocation;
54
+            }
134 55
         }
135
-    }
136 56
 
137
-    location.protocol || (location.protocol = 'https:');
57
+        location.protocol || (location.protocol = 'https:');
58
+        const locationURL = new URL(location.toString());
138 59
 
139
-    return _appNavigateToMandatoryLocation(dispatch, getState, location);
140
-}
141
-
142
-/**
143
- * Loads config.js from a specific host.
144
- *
145
- * @param {Dispatch} dispatch - The redux {@code dispatch} function.
146
- * @param {Function} getState - The redux {@code getState} function.
147
- * @param {Object} location - The location URI which specifies the host to load
148
- * the config.js from.
149
- * @private
150
- * @returns {Promise<Object>}
151
- */
152
-function _loadConfig(
153
-        dispatch: Dispatch<any>,
154
-        getState: Function,
155
-        { contextRoot, host, protocol, room }) {
156
-    // XXX As the mobile/React Native app does not employ config on the
157
-    // WelcomePage, do not download config.js from the deployment when
158
-    // navigating to the WelcomePage - the perceived/visible navigation will be
159
-    // faster.
160
-    if (!room && typeof APP === 'undefined') {
161
-        return Promise.resolve();
162
-    }
60
+        dispatch(configWillLoad(locationURL));
163 61
 
164
-    /* eslint-disable no-param-reassign */
62
+        let protocol = location.protocol.toLowerCase();
63
+        const { contextRoot, host, room } = location;
165 64
 
166
-    protocol = protocol.toLowerCase();
65
+        // The React Native app supports an app-specific scheme which is sure to not
66
+        // be supported by fetch.
67
+        protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
167 68
 
168
-    // The React Native app supports an app-specific scheme which is sure to not
169
-    // be supported by fetch (or whatever loadConfig utilizes).
170
-    protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
69
+        const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
70
+        let url = `${baseURL}config.js`;
171 71
 
172
-    // TDOO userinfo
72
+        // XXX In order to support multiple shards, tell the room to the deployment.
73
+        room && (url += `?room=${room.toLowerCase()}`);
173 74
 
174
-    const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
175
-    let url = `${baseURL}config.js`;
75
+        let config;
176 76
 
177
-    // XXX In order to support multiple shards, tell the room to the deployment.
178
-    room && (url += `?room=${room.toLowerCase()}`);
179
-
180
-    /* eslint-enable no-param-reassign */
181
-
182
-    return loadConfig(url).then(
183
-        /* onFulfilled */ config => {
184
-            // FIXME If the config is no longer needed (in the terms of
185
-            // _loadConfig) and that happened because of an intervening
186
-            // _loadConfig for the same baseURL, then the unneeded config may be
187
-            // stored after the needed config. Anyway.
77
+        try {
78
+            config = await loadConfig(url);
188 79
             dispatch(storeConfig(baseURL, config));
80
+        } catch (error) {
81
+            config = restoreConfig(baseURL);
189 82
 
190
-            return config;
191
-        },
192
-        /* onRejected */ error => {
193
-            // XXX The (down)loading of config failed. Try to use the last
194
-            // successfully fetched for that deployment. It may not match the
195
-            // shard.
196
-            const config = restoreConfig(baseURL);
83
+            if (!config) {
84
+                dispatch(loadConfigError(error, locationURL));
197 85
 
198
-            if (config) {
199
-                return config;
86
+                return;
200 87
             }
88
+        }
201 89
 
202
-            throw error;
203
-        });
90
+        if (getState()['features/base/config'].locationURL === locationURL) {
91
+            dispatch(setLocationURL(locationURL));
92
+            dispatch(setConfig(config));
93
+            dispatch(setRoom(room));
94
+        } else {
95
+            dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));
96
+        }
97
+    };
204 98
 }
205 99
 
206 100
 /**

+ 2
- 0
react/features/app/components/index.js Vedi File

@@ -1 +1,3 @@
1
+// @flow
2
+
1 3
 export * from './App';

+ 2
- 0
react/features/app/index.js Vedi File

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 export * from './actions';
2 4
 export * from './components';
3 5
 export * from './functions';

+ 2
- 8
react/features/base/lib-jitsi-meet/functions.js Vedi File

@@ -100,20 +100,14 @@ export function isFatalJitsiConnectionError(error: Object | string) {
100 100
  * Loads config.js from a specific remote server.
101 101
  *
102 102
  * @param {string} url - The URL to load.
103
- * @param {number} [timeout] - The timeout in milliseconds for the {@code url}
104
- * to load. If not specified, a default value deemed appropriate for the purpose
105
- * is used.
106 103
  * @returns {Promise<Object>}
107 104
  */
108
-export function loadConfig(
109
-        url: string,
110
-        timeout: ?number = 10 /* seconds */ * 1000 /* in milliseconds */
111
-): Promise<Object> {
105
+export function loadConfig(url: string): Promise<Object> {
112 106
     let promise;
113 107
 
114 108
     if (typeof APP === 'undefined') {
115 109
         promise
116
-            = loadScript(url, timeout)
110
+            = loadScript(url, 2.5 * 1000 /* Timeout in ms */)
117 111
                 .then(() => {
118 112
                     const { config } = window;
119 113
 

+ 14
- 1
webpack.config.js Vedi File

@@ -56,7 +56,20 @@ const config = {
56 56
 
57 57
                         // Tell babel to avoid compiling imports into CommonJS
58 58
                         // so that webpack may do tree shaking.
59
-                        { modules: false }
59
+                        {
60
+                            modules: false,
61
+
62
+                            // Specify our target browsers so no transpiling is
63
+                            // done unnecessarily. For browsers not specified
64
+                            // here, the ES2015+ profile will be used.
65
+                            targets: {
66
+                                chrome: 58,
67
+                                electron: 2,
68
+                                firefox: 54,
69
+                                safari: 11
70
+                            }
71
+
72
+                        }
60 73
                     ],
61 74
                     require.resolve('@babel/preset-flow'),
62 75
                     require.resolve('@babel/preset-react')

Loading…
Annulla
Salva