Browse Source

[RN] Refactor getting the default URL

Move it away from AbstractApp into an auxiliary function. In addition, introduce
a new `getServerURL` function which gets the configured server URL and defaults
to meet.jit.si as before.
master
Saúl Ibarra Corretgé 7 years ago
parent
commit
3bfab7718f

+ 2
- 2
react/features/app/actions.js View File

16
 import { setFatalError } from '../overlay';
16
 import { setFatalError } from '../overlay';
17
 
17
 
18
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
18
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
19
+import { getDefaultURL } from './functions';
19
 
20
 
20
 const logger = require('jitsi-meet-logger').getLogger(__filename);
21
 const logger = require('jitsi-meet-logger').getLogger(__filename);
21
 
22
 
116
     // If the specified location (URI) does not identify a host, use the app's
117
     // If the specified location (URI) does not identify a host, use the app's
117
     // default.
118
     // default.
118
     if (!location || !location.host) {
119
     if (!location || !location.host) {
119
-        const defaultLocation
120
-            = parseURIString(getState()['features/app'].app._getDefaultURL());
120
+        const defaultLocation = parseURIString(getDefaultURL(getState));
121
 
121
 
122
         if (location) {
122
         if (location) {
123
             location.host = defaultLocation.host;
123
             location.host = defaultLocation.host;

+ 2
- 27
react/features/app/components/AbstractApp.js View File

20
 import { OverlayContainer } from '../../overlay';
20
 import { OverlayContainer } from '../../overlay';
21
 
21
 
22
 import { appNavigate, appWillMount, appWillUnmount } from '../actions';
22
 import { appNavigate, appWillMount, appWillUnmount } from '../actions';
23
-
24
-/**
25
- * The default URL to open if no other was specified to {@code AbstractApp} via
26
- * props.
27
- *
28
- * FIXME: This is not at the best place here. This should be either in the
29
- * base/settings feature or a default in base/config.
30
- */
31
-const DEFAULT_URL = 'https://meet.jit.si';
23
+import { getDefaultURL } from '../functions';
32
 
24
 
33
 /**
25
 /**
34
  * Base (abstract) class for main App component.
26
  * Base (abstract) class for main App component.
322
      * mounts.
314
      * mounts.
323
      */
315
      */
324
     _getDefaultURL() {
316
     _getDefaultURL() {
325
-        // If the execution environment provides a Location abstraction, then
326
-        // this App at already at that location but it must be made aware of the
327
-        // fact.
328
-        const windowLocation = this.getWindowLocation();
329
-
330
-        if (windowLocation) {
331
-            const href = windowLocation.toString();
332
-
333
-            if (href) {
334
-                return href;
335
-            }
336
-        }
337
-
338
-        return (
339
-            this.props.defaultURL
340
-                || this.state.store.getState()['features/base/settings']
341
-                    .serverURL
342
-                || DEFAULT_URL);
317
+        return getDefaultURL(this.state.store);
343
     }
318
     }
344
 
319
 
345
     /**
320
     /**

+ 28
- 0
react/features/app/functions.any.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { toState } from '../base/redux';
3
 import { toState } from '../base/redux';
4
+import { getServerURL } from '../base/settings';
4
 
5
 
5
 /**
6
 /**
6
  * Gets the value of a specific React {@code Component} prop of the currently
7
  * Gets the value of a specific React {@code Component} prop of the currently
26
 
27
 
27
     return undefined;
28
     return undefined;
28
 }
29
 }
30
+
31
+/**
32
+ * Retrieves the default URL for the app. This can either come from a prop to
33
+ * the root App component or be configured in the settings.
34
+ *
35
+ * @param {Function|Object} stateful - The redux store or {@code getState}
36
+ * function.
37
+ * @returns {string} - Default URL for the app.
38
+ */
39
+export function getDefaultURL(stateful: Function | Object) {
40
+    const state = toState(stateful);
41
+    const { app } = state['features/app'];
42
+
43
+    // If the execution environment provides a Location abstraction (e.g. a Web
44
+    // browser), then we'll presume it's the one and only base URL it can be on.
45
+    const windowLocation = app.getWindowLocation();
46
+
47
+    if (windowLocation) {
48
+        const href = windowLocation.toString();
49
+
50
+        if (href) {
51
+            return href;
52
+        }
53
+    }
54
+
55
+    return getAppProp(state, 'defaultURL') || getServerURL(state);
56
+}

+ 3
- 3
react/features/base/known-domains/middleware.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { APP_WILL_MOUNT } from '../../app';
3
+import { APP_WILL_MOUNT, getDefaultURL } from '../../app';
4
+
4
 import { SET_ROOM } from '../conference';
5
 import { SET_ROOM } from '../conference';
5
 import { MiddlewareRegistry } from '../redux';
6
 import { MiddlewareRegistry } from '../redux';
6
 import { parseURIString } from '../util';
7
 import { parseURIString } from '../util';
32
  * @returns {Promise}
33
  * @returns {Promise}
33
  */
34
  */
34
 function _appWillMount({ dispatch, getState }) {
35
 function _appWillMount({ dispatch, getState }) {
35
-    const defaultURL
36
-        = parseURIString(getState()['features/app'].app._getDefaultURL());
36
+    const defaultURL = parseURIString(getDefaultURL(getState));
37
 
37
 
38
     dispatch(addKnownDomains(defaultURL.host));
38
     dispatch(addKnownDomains(defaultURL.host));
39
 }
39
 }

+ 6
- 0
react/features/base/settings/constants.js View File

1
+// @flow
2
+
3
+/**
4
+ * The default server URL to open if no other was specified.
5
+ */
6
+export const DEFAULT_SERVER_URL = 'https://meet.jit.si';

+ 14
- 0
react/features/base/settings/functions.js View File

3
 import { parseURLParams } from '../config';
3
 import { parseURLParams } from '../config';
4
 import { toState } from '../redux';
4
 import { toState } from '../redux';
5
 
5
 
6
+import { DEFAULT_SERVER_URL } from './constants';
6
 
7
 
7
 /**
8
 /**
8
  * Returns the effective value of a configuration/preference/setting by applying
9
  * Returns the effective value of a configuration/preference/setting by applying
83
 
84
 
84
     return undefined;
85
     return undefined;
85
 }
86
 }
87
+
88
+/**
89
+ * Gets the currently configured server URL.
90
+ *
91
+ * @param {Object|Function} stateful - The redux state object or
92
+ * {@code getState} function.
93
+ * @returns {string} - The currently configured server URL.
94
+ */
95
+export function getServerURL(stateful: Object | Function) {
96
+    const state = toState(stateful);
97
+
98
+    return state['features/base/settings'].serverURL || DEFAULT_SERVER_URL;
99
+}

+ 1
- 0
react/features/base/settings/index.js View File

1
 export * from './actions';
1
 export * from './actions';
2
+export * from './constants';
2
 export * from './functions';
3
 export * from './functions';
3
 
4
 
4
 import './middleware';
5
 import './middleware';

+ 2
- 2
react/features/recent-list/components/RecentList.native.js View File

2
 import React, { Component } from 'react';
2
 import React, { Component } from 'react';
3
 import { connect } from 'react-redux';
3
 import { connect } from 'react-redux';
4
 
4
 
5
-import { appNavigate } from '../../app';
5
+import { appNavigate, getDefaultURL } from '../../app';
6
 import {
6
 import {
7
     getLocalizedDateFormatter,
7
     getLocalizedDateFormatter,
8
     getLocalizedDurationFormatter,
8
     getLocalizedDurationFormatter,
226
  */
226
  */
227
 export function _mapStateToProps(state: Object) {
227
 export function _mapStateToProps(state: Object) {
228
     return {
228
     return {
229
-        _defaultServerURL: state['features/app'].app._getDefaultURL(),
229
+        _defaultServerURL: getDefaultURL(state),
230
         _recentList: state['features/recent-list']
230
         _recentList: state['features/recent-list']
231
     };
231
     };
232
 }
232
 }

+ 2
- 1
react/features/settings/components/AbstractSettingsView.js View File

2
 
2
 
3
 import { Component } from 'react';
3
 import { Component } from 'react';
4
 
4
 
5
+import { getDefaultURL } from '../../app';
5
 import { updateSettings } from '../../base/settings';
6
 import { updateSettings } from '../../base/settings';
6
 
7
 
7
 /**
8
 /**
173
  */
174
  */
174
 export function _mapStateToProps(state: Object) {
175
 export function _mapStateToProps(state: Object) {
175
     return {
176
     return {
176
-        _serverURL: state['features/app'].app._getDefaultURL(),
177
+        _serverURL: getDefaultURL(state),
177
         _settings: state['features/base/settings'],
178
         _settings: state['features/base/settings'],
178
         _visible: state['features/settings'].visible
179
         _visible: state['features/settings'].visible
179
     };
180
     };

Loading…
Cancel
Save