瀏覽代碼

Remove duplication, simplify, comply with coding style

j8
Lyubomir Marinov 8 年之前
父節點
當前提交
0912dbf130

+ 1
- 0
modules/UI/UI.js 查看文件

1
 /* global APP, JitsiMeetJS, $, config, interfaceConfig, toastr */
1
 /* global APP, JitsiMeetJS, $, config, interfaceConfig, toastr */
2
+
2
 const logger = require("jitsi-meet-logger").getLogger(__filename);
3
 const logger = require("jitsi-meet-logger").getLogger(__filename);
3
 
4
 
4
 var UI = {};
5
 var UI = {};

+ 6
- 15
react/features/app/actions.js 查看文件

1
 import { setRoom } from '../base/conference';
1
 import { setRoom } from '../base/conference';
2
-import {
3
-    getDomain,
4
-    setDomain
5
-} from '../base/connection';
6
-import {
7
-    loadConfig,
8
-    setConfig
9
-} from '../base/lib-jitsi-meet';
2
+import { getDomain, setDomain } from '../base/connection';
3
+import { loadConfig, setConfig } from '../base/lib-jitsi-meet';
10
 
4
 
11
-import {
12
-    APP_WILL_MOUNT,
13
-    APP_WILL_UNMOUNT
14
-} from './actionTypes';
5
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
15
 import {
6
 import {
16
     _getRoomAndDomainFromUrlString,
7
     _getRoomAndDomainFromUrlString,
17
     _getRouteToRender,
8
     _getRouteToRender,
20
 import './reducer';
11
 import './reducer';
21
 
12
 
22
 /**
13
 /**
23
- * Temporary solution. Should dispatch actions related to
24
- * initial settings of the app like setting log levels,
25
- * reading the config parameters from query string etc.
14
+ * Temporary solution. Should dispatch actions related to initial settings of
15
+ * the app like setting log levels, reading the config parameters from query
16
+ * string etc.
26
  *
17
  *
27
  * @returns {Function}
18
  * @returns {Function}
28
  */
19
  */

+ 44
- 44
react/features/app/components/App.web.js 查看文件

1
-/* global $ */
2
 import React from 'react';
1
 import React from 'react';
3
 import { Provider } from 'react-redux';
2
 import { Provider } from 'react-redux';
4
-import {
5
-    browserHistory,
6
-    Route,
7
-    Router
8
-} from 'react-router';
3
+import { browserHistory, Route, Router } from 'react-router';
9
 import { push, syncHistoryWithStore } from 'react-router-redux';
4
 import { push, syncHistoryWithStore } from 'react-router-redux';
10
-import { compose } from 'redux';
11
 
5
 
12
 import { getDomain } from '../../base/connection';
6
 import { getDomain } from '../../base/connection';
13
 import { RouteRegistry } from '../../base/navigator';
7
 import { RouteRegistry } from '../../base/navigator';
45
         this.history = syncHistoryWithStore(browserHistory, props.store);
39
         this.history = syncHistoryWithStore(browserHistory, props.store);
46
 
40
 
47
         // Bind event handlers so they are only bound once for every instance.
41
         // Bind event handlers so they are only bound once for every instance.
48
-        this._getRoute = this._getRoute.bind(this);
49
-        this._getRoutes = this._getRoutes.bind(this);
50
-        this._onRouteEnter = this._onRouteEnter.bind(this);
51
         this._routerCreateElement = this._routerCreateElement.bind(this);
42
         this._routerCreateElement = this._routerCreateElement.bind(this);
52
     }
43
     }
53
 
44
 
74
                 <Router
65
                 <Router
75
                     createElement = { this._routerCreateElement }
66
                     createElement = { this._routerCreateElement }
76
                     history = { this.history }>
67
                     history = { this.history }>
77
-                    { this._getRoutes() }
68
+                    {
69
+                        this._renderRoutes()
70
+                    }
78
                 </Router>
71
                 </Router>
79
             </Provider>
72
             </Provider>
80
         );
73
         );
81
     }
74
     }
82
 
75
 
83
-    /**
84
-     * Method returns route for React Router.
85
-     *
86
-     * @param {Object} route - Object that describes route.
87
-     * @returns {ReactElement}
88
-     * @private
89
-     */
90
-    _getRoute(route) {
91
-        const onEnter = route.onEnter || $.noop;
92
-        const handler = compose(this._onRouteEnter, onEnter);
93
-
94
-        return (
95
-            <Route
96
-                component = { route.component }
97
-                key = { route.component }
98
-                onEnter = { handler }
99
-                path = { route.path } />
100
-        );
101
-    }
102
-
103
-    /**
104
-     * Returns routes for application.
105
-     *
106
-     * @returns {Array}
107
-     * @private
108
-     */
109
-    _getRoutes() {
110
-        const routes = RouteRegistry.getRoutes();
111
-
112
-        return routes.map(this._getRoute);
113
-    }
114
-
115
     /**
76
     /**
116
      * Navigates to a specific Route (via platform-specific means).
77
      * Navigates to a specific Route (via platform-specific means).
117
      *
78
      *
137
      * Invoked by react-router to notify this App that a Route is about to be
98
      * Invoked by react-router to notify this App that a Route is about to be
138
      * rendered.
99
      * rendered.
139
      *
100
      *
101
+     * @param {Route} route - The Route that is about to be rendered.
140
      * @private
102
      * @private
141
      * @returns {void}
103
      * @returns {void}
142
      */
104
      */
143
-    _onRouteEnter() {
105
+    _onRouteEnter(route, ...args) {
106
+        // Notify the route that it is about to be entered.
107
+        const onEnter = route.onEnter;
108
+
109
+        if (typeof onEnter === 'function') {
110
+            onEnter(...args);
111
+        }
112
+
144
         // XXX The following is mandatory. Otherwise, moving back & forward
113
         // XXX The following is mandatory. Otherwise, moving back & forward
145
         // through the browser's history could leave this App on the Conference
114
         // through the browser's history could leave this App on the Conference
146
         // page without a room name.
115
         // page without a room name.
159
         this._openURL(url);
128
         this._openURL(url);
160
     }
129
     }
161
 
130
 
131
+    /**
132
+     * Renders a specific Route (for the purposes of the Router of this App).
133
+     *
134
+     * @param {Object} route - The Route to render.
135
+     * @returns {ReactElement}
136
+     * @private
137
+     */
138
+    _renderRoute(route) {
139
+        const onEnter = (...args) => {
140
+            this._onRouteEnter(route, ...args);
141
+        };
142
+
143
+        return (
144
+            <Route
145
+                component = { route.component }
146
+                key = { route.component }
147
+                onEnter = { onEnter }
148
+                path = { route.path } />
149
+        );
150
+    }
151
+
152
+    /**
153
+     * Renders the Routes of the Router of this App.
154
+     *
155
+     * @returns {Array.<ReactElement>}
156
+     * @private
157
+     */
158
+    _renderRoutes() {
159
+        return RouteRegistry.getRoutes().map(this._renderRoute, this);
160
+    }
161
+
162
     /**
162
     /**
163
      * Create a ReactElement from the specified component and props on behalf of
163
      * Create a ReactElement from the specified component and props on behalf of
164
      * the associated Router.
164
      * the associated Router.

+ 2
- 2
react/features/app/functions.native.js 查看文件

64
 
64
 
65
             url
65
             url
66
                 = match[1] /* URL protocol */
66
                 = match[1] /* URL protocol */
67
-                   + '://enso.hipchat.me/'
68
-                   + url.substring(regex.lastIndex);
67
+                    + '://enso.hipchat.me/'
68
+                    + url.substring(regex.lastIndex);
69
 
69
 
70
             /* eslint-enable no-param-reassign, prefer-template */
70
             /* eslint-enable no-param-reassign, prefer-template */
71
         }
71
         }

+ 26
- 156
react/features/app/functions.web.js 查看文件

1
 /* global APP, JitsiMeetJS, loggingConfig */
1
 /* global APP, JitsiMeetJS, loggingConfig */
2
-import { isRoomValid } from '../base/conference';
3
-import { RouteRegistry } from '../base/navigator';
4
-import { Conference } from '../conference';
5
-import { WelcomePage } from '../welcome';
6
-
7
-import getTokenData from '../../../modules/tokendata/TokenData';
8
-import settings from '../../../modules/settings/Settings';
9
 
2
 
10
 import URLProcessor from '../../../modules/config/URLProcessor';
3
 import URLProcessor from '../../../modules/config/URLProcessor';
4
+import KeyboardShortcut
5
+    from '../../../modules/keyboardshortcut/keyboardshortcut';
6
+import settings from '../../../modules/settings/Settings';
7
+import getTokenData from '../../../modules/tokendata/TokenData';
11
 import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
8
 import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
12
 
9
 
13
-// eslint-disable-next-line max-len
14
-import KeyboardShortcut from '../../../modules/keyboardshortcut/keyboardshortcut';
15
-
16
 const Logger = require('jitsi-meet-logger');
10
 const Logger = require('jitsi-meet-logger');
17
-const LogCollector = Logger.LogCollector;
18
-
19
-
20
-/**
21
- * Gets room name and domain from URL object.
22
- *
23
- * @param {URL} url - URL object.
24
- * @private
25
- * @returns {{
26
- *      domain: (string|undefined),
27
- *      room: (string|undefined)
28
- *  }}
29
- */
30
-function _getRoomAndDomainFromUrlObject(url) {
31
-    let domain;
32
-    let room;
33
-
34
-    if (url) {
35
-        domain = url.hostname;
36
-        room = url.pathname.substr(1);
37
-
38
-        // Convert empty string to undefined to simplify checks.
39
-        if (room === '') {
40
-            room = undefined;
41
-        }
42
-        if (domain === '') {
43
-            domain = undefined;
44
-        }
45
-    }
46
-
47
-    return {
48
-        domain,
49
-        room
50
-    };
51
-}
52
-
53
-/**
54
- * Gets conference room name and connection domain from URL.
55
- *
56
- * @param {(string|undefined)} url - URL.
57
- * @returns {{
58
- *      domain: (string|undefined),
59
- *      room: (string|undefined)
60
- *  }}
61
- */
62
-export function _getRoomAndDomainFromUrlString(url) {
63
-    // Rewrite the specified URL in order to handle special cases such as
64
-    // hipchat.com and enso.me which do not follow the common pattern of most
65
-    // Jitsi Meet deployments.
66
-    if (typeof url === 'string') {
67
-        // hipchat.com
68
-        let regex = /^(https?):\/\/hipchat.com\/video\/call\//gi;
69
-        let match = regex.exec(url);
70
-
71
-        if (!match) {
72
-            // enso.me
73
-            regex = /^(https?):\/\/enso\.me\/(?:call|meeting)\//gi;
74
-            match = regex.exec(url);
75
-        }
76
-        if (match && match.length > 1) {
77
-            /* eslint-disable no-param-reassign, prefer-template */
78
-
79
-            url
80
-                = match[1] /* URL protocol */
81
-                + '://enso.hipchat.me/'
82
-                + url.substring(regex.lastIndex);
83
-
84
-            /* eslint-enable no-param-reassign, prefer-template */
85
-        }
86
-    }
87
-
88
-    return _getRoomAndDomainFromUrlObject(_urlStringToObject(url));
89
-}
90
-
91
-/**
92
- * Determines which route is to be rendered in order to depict a specific Redux
93
- * store.
94
- *
95
- * @param {(Object|Function)} stateOrGetState - Redux state or Regux getState()
96
- * method.
97
- * @returns {Route}
98
- */
99
-export function _getRouteToRender(stateOrGetState) {
100
-    const state
101
-        = typeof stateOrGetState === 'function'
102
-        ? stateOrGetState()
103
-        : stateOrGetState;
104
-    const room = state['features/base/conference'].room;
105
-    const component = isRoomValid(room) ? Conference : WelcomePage;
106
-
107
-    return RouteRegistry.getRouteByComponent(component);
108
-}
109
 
11
 
110
-/**
111
- * Parses a string into a URL (object).
112
- *
113
- * @param {(string|undefined)} url - The URL to parse.
114
- * @private
115
- * @returns {URL}
116
- */
117
-function _urlStringToObject(url) {
118
-    let urlObj;
119
-
120
-    if (url) {
121
-        try {
122
-            urlObj = new URL(url);
123
-        } catch (ex) {
124
-            // The return value will signal the failure & the logged
125
-            // exception will provide the details to the developers.
126
-            console.log(`${url} seems to be not a valid URL, but it's OK`, ex);
127
-        }
128
-    }
129
-
130
-    return urlObj;
131
-}
12
+export * from './functions.native';
132
 
13
 
133
 /**
14
 /**
134
- * Temporary solution. Later we'll get rid of global APP
135
- * and set its properties in redux store.
15
+ * Temporary solution. Later we'll get rid of global APP and set its properties
16
+ * in redux store.
136
  *
17
  *
137
  * @returns {void}
18
  * @returns {void}
138
  */
19
  */
139
 export function init() {
20
 export function init() {
140
-    _setConfigParametersFromUrl();
21
+    URLProcessor.setConfigParametersFromUrl();
141
     _initLogging();
22
     _initLogging();
142
 
23
 
143
     APP.keyboardshortcut = KeyboardShortcut;
24
     APP.keyboardshortcut = KeyboardShortcut;
147
     APP.translation.init(settings.getLanguage());
28
     APP.translation.init(settings.getLanguage());
148
 }
29
 }
149
 
30
 
150
-/**
151
- * Initializes logging in the app.
152
- *
153
- * @private
154
- * @returns {void}
155
- */
156
-function _initLogging() {
157
-    // Adjust logging level
158
-    configureLoggingLevels();
159
-
160
-    // Create the LogCollector and register it as the global log transport.
161
-    // It is done early to capture as much logs as possible. Captured logs
162
-    // will be cached, before the JitsiMeetLogStorage gets ready (statistics
163
-    // module is initialized).
164
-    if (!APP.logCollector && !loggingConfig.disableLogCollector) {
165
-        APP.logCollector = new LogCollector(new JitsiMeetLogStorage());
166
-        Logger.addGlobalTransport(APP.logCollector);
167
-        JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
168
-    }
169
-}
170
-
171
 /**
31
 /**
172
  * Adjusts the logging levels.
32
  * Adjusts the logging levels.
173
  *
33
  *
174
  * @private
34
  * @private
175
  * @returns {void}
35
  * @returns {void}
176
  */
36
  */
177
-function configureLoggingLevels() {
178
-    // NOTE The library Logger is separated from
179
-    // the app loggers, so the levels
37
+function _configureLoggingLevels() {
38
+    // NOTE The library Logger is separated from the app loggers, so the levels
180
     // have to be set in two places
39
     // have to be set in two places
181
 
40
 
182
     // Set default logging level
41
     // Set default logging level
186
     Logger.setLogLevel(defaultLogLevel);
45
     Logger.setLogLevel(defaultLogLevel);
187
     JitsiMeetJS.setLogLevel(defaultLogLevel);
46
     JitsiMeetJS.setLogLevel(defaultLogLevel);
188
 
47
 
189
-    // NOTE console was used on purpose here to go around the logging
190
-    // and always print the default logging level to the console
48
+    // NOTE console was used on purpose here to go around the logging and always
49
+    // print the default logging level to the console
191
     console.info(`Default logging level set to: ${defaultLogLevel}`);
50
     console.info(`Default logging level set to: ${defaultLogLevel}`);
192
 
51
 
193
     // Set log level for each logger
52
     // Set log level for each logger
204
 }
63
 }
205
 
64
 
206
 /**
65
 /**
207
- * Sets config parameters from query string.
66
+ * Initializes logging in the app.
208
  *
67
  *
209
  * @private
68
  * @private
210
  * @returns {void}
69
  * @returns {void}
211
  */
70
  */
212
-function _setConfigParametersFromUrl() {
213
-    URLProcessor.setConfigParametersFromUrl();
71
+function _initLogging() {
72
+    // Adjust logging level
73
+    _configureLoggingLevels();
74
+
75
+    // Create the LogCollector and register it as the global log transport. It
76
+    // is done early to capture as much logs as possible. Captured logs will be
77
+    // cached, before the JitsiMeetLogStorage gets ready (statistics module is
78
+    // initialized).
79
+    if (!APP.logCollector && !loggingConfig.disableLogCollector) {
80
+        APP.logCollector = new Logger.LogCollector(new JitsiMeetLogStorage());
81
+        Logger.addGlobalTransport(APP.logCollector);
82
+        JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
83
+    }
214
 }
84
 }

+ 7
- 9
react/features/base/connection/actions.web.js 查看文件

1
 /* global APP, JitsiMeetJS */
1
 /* global APP, JitsiMeetJS */
2
 
2
 
3
-import {
4
-    SET_DOMAIN
5
-} from './actionTypes';
6
-import './reducer';
7
 import UIEvents from '../../../../service/UI/UIEvents';
3
 import UIEvents from '../../../../service/UI/UIEvents';
8
 
4
 
9
-const logger = require('jitsi-meet-logger').getLogger(__filename);
10
-const ConferenceEvents = JitsiMeetJS.events.conference;
5
+import { SET_DOMAIN } from './actionTypes';
6
+import './reducer';
11
 
7
 
8
+const JitsiConferenceEvents = JitsiMeetJS.events.conference;
9
+const logger = require('jitsi-meet-logger').getLogger(__filename);
12
 
10
 
13
 /**
11
 /**
14
  * Opens new connection.
12
  * Opens new connection.
42
                 // room. It will then restart the media session when someone
40
                 // room. It will then restart the media session when someone
43
                 // eventually join the room which will start the stats again.
41
                 // eventually join the room which will start the stats again.
44
                 APP.conference.addConferenceListener(
42
                 APP.conference.addConferenceListener(
45
-                    ConferenceEvents.BEFORE_STATISTICS_DISPOSED,
43
+                    JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED,
46
                     () => {
44
                     () => {
47
                         if (APP.logCollector) {
45
                         if (APP.logCollector) {
48
                             APP.logCollector.flush();
46
                             APP.logCollector.flush();
74
  * @returns {Function}
72
  * @returns {Function}
75
  */
73
  */
76
 export function disconnect() {
74
 export function disconnect() {
77
-    // XXX For web based version we use conference
78
-    // hanging up logic from the old app.
75
+    // XXX For web based version we use conference hanging up logic from the old
76
+    // app.
79
     return () => APP.conference.hangup();
77
     return () => APP.conference.hangup();
80
 }
78
 }
81
 
79
 

+ 3
- 5
react/features/base/lib-jitsi-meet/actions.js 查看文件

1
-import React from 'react';
2
-
3
 import JitsiMeetJS from './';
1
 import JitsiMeetJS from './';
4
 import {
2
 import {
5
     LIB_DISPOSED,
3
     LIB_DISPOSED,
42
             throw new Error('Cannot initialize lib-jitsi-meet without config');
40
             throw new Error('Cannot initialize lib-jitsi-meet without config');
43
         }
41
         }
44
 
42
 
45
-        if (!React.View) {
46
-            // XXX Temporarily until conference.js is moved to the React app we
47
-            // shouldn't use JitsiMeetJS from the React app.
43
+        // XXX Temporarily until conference.js is moved to the React app we
44
+        // shouldn't use JitsiMeetJS from the React app.
45
+        if (typeof APP !== 'undefined') {
48
             return Promise.resolve();
46
             return Promise.resolve();
49
         }
47
         }
50
 
48
 

+ 4
- 6
react/features/base/lib-jitsi-meet/functions.js 查看文件

1
-import React from 'react';
2
-
3
 import { loadScript } from '../../base/util';
1
 import { loadScript } from '../../base/util';
4
 
2
 
5
 /**
3
 /**
10
  * @returns {Promise<Object>}
8
  * @returns {Promise<Object>}
11
  */
9
  */
12
 export function loadConfig(host, path = '/config.js') {
10
 export function loadConfig(host, path = '/config.js') {
13
-    if (!React.View) {
14
-        // Returns config.js file from global scope. We can't use the version
15
-        // that's being used for the React Native app because the old/current
16
-        // Web app uses config from the global scope.
11
+    // Returns config.js file from global scope. We can't use the version that's
12
+    // being used for the React Native app because the old/current Web app uses
13
+    // config from the global scope.
14
+    if (typeof APP !== 'undefined') {
17
         return Promise.resolve(window.config);
15
         return Promise.resolve(window.config);
18
     }
16
     }
19
 
17
 

+ 0
- 67
react/features/conference/actions.js 查看文件

1
-/* global APP, config */
2
-import ConferenceUrl from '../../../modules/URL/ConferenceUrl';
3
-import BoshAddressChoice from '../../../modules/config/BoshAddressChoice';
4
-import { obtainConfig, setTokenData } from './functions';
5
-const logger = require('jitsi-meet-logger').getLogger(__filename);
6
-
7
-/**
8
- * If we have an HTTP endpoint for getting config.json configured
9
- * we're going to read it and override properties from config.js and
10
- * interfaceConfig.js. If there is no endpoint we'll just
11
- * continue with initialization.
12
- * Keep in mind that if the endpoint has been configured and we fail
13
- * to obtain the config for any reason then the conference won't
14
- * start and error message will be displayed to the user.
15
- *
16
- * @returns {Function}
17
- */
18
-export function obtainConfigAndInit() {
19
-    return () => {
20
-        const room = APP.conference.roomName;
21
-
22
-        if (config.configLocation) {
23
-            const location = config.configLocation;
24
-
25
-            obtainConfig(location, room)
26
-                .then(_obtainConfigHandler)
27
-                .then(_initConference)
28
-                .catch(err => {
29
-                    // Show obtain config error,
30
-                    // pass the error object for report
31
-                    APP.UI.messageHandler.openReportDialog(
32
-                        null, 'dialog.connectError', err);
33
-                });
34
-        } else {
35
-            BoshAddressChoice.chooseAddress(config, room);
36
-            _initConference();
37
-        }
38
-    };
39
-}
40
-
41
-/**
42
- * Obtain config handler.
43
- *
44
- * @returns {Promise}
45
- * @private
46
- */
47
-function _obtainConfigHandler() {
48
-    const now = window.performance.now();
49
-
50
-    APP.connectionTimes['configuration.fetched'] = now;
51
-    logger.log('(TIME) configuration fetched:\t', now);
52
-
53
-    return Promise.resolve();
54
-}
55
-
56
-/**
57
- *  Initialization of the app.
58
- *
59
- *  @returns {void}
60
- *  @private
61
- */
62
-function _initConference() {
63
-    setTokenData();
64
-
65
-    // Initialize the conference URL handler
66
-    APP.ConferenceUrl = new ConferenceUrl(window.location);
67
-}

+ 12
- 13
react/features/conference/components/Conference.web.js 查看文件

1
 /* global $, APP, interfaceConfig */
1
 /* global $, APP, interfaceConfig */
2
+
2
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
3
 import { connect as reactReduxConnect } from 'react-redux';
4
 import { connect as reactReduxConnect } from 'react-redux';
4
 
5
 
5
-import {
6
-    connect,
7
-    disconnect
8
-} from '../../base/connection';
6
+import { connect, disconnect } from '../../base/connection';
9
 
7
 
10
 /**
8
 /**
11
  * For legacy reasons, inline style for display none.
9
  * For legacy reasons, inline style for display none.
19
  * Implements a React Component which renders initial conference layout
17
  * Implements a React Component which renders initial conference layout
20
  */
18
  */
21
 class Conference extends Component {
19
 class Conference extends Component {
20
+
21
+    /**
22
+     * Conference component's property types.
23
+     *
24
+     * @static
25
+     */
26
+    static propTypes = {
27
+        dispatch: React.PropTypes.func
28
+    }
29
+
22
     /**
30
     /**
23
      * Until we don't rewrite UI using react components
31
      * Until we don't rewrite UI using react components
24
      * we use UI.start from old app. Also method translates
32
      * we use UI.start from old app. Also method translates
45
         this.props.dispatch(disconnect());
53
         this.props.dispatch(disconnect());
46
     }
54
     }
47
 
55
 
48
-    /**
49
-     * Conference component's property types.
50
-     *
51
-     * @static
52
-     */
53
-    static propTypes = {
54
-        dispatch: React.PropTypes.func
55
-    };
56
-
57
     /**
56
     /**
58
      * Initializes Conference component instance.
57
      * Initializes Conference component instance.
59
      *
58
      *

+ 0
- 108
react/features/conference/functions.js 查看文件

1
-/* global APP, config */
2
-import HttpConfigFetch from '../../../modules/config/HttpConfigFetch';
3
-import ConferenceUrl from '../../../modules/URL/ConferenceUrl';
4
-import BoshAddressChoice from '../../../modules/config/BoshAddressChoice';
5
-const logger = require('jitsi-meet-logger').getLogger(__filename);
6
-
7
-/**
8
- * If we have an HTTP endpoint for getting config.json configured
9
- * we're going to read it and override properties from config.js and
10
- * interfaceConfig.js. If there is no endpoint we'll just
11
- * continue with initialization.
12
- * Keep in mind that if the endpoint has been configured and we fail
13
- * to obtain the config for any reason then the conference won't
14
- * start and error message will be displayed to the user.
15
- *
16
- * @returns {Function}
17
- */
18
-export function obtainConfigAndInit() {
19
-    // Skip initialization if conference is already initialized
20
-    if (!APP.ConferenceUrl) {
21
-        const room = APP.conference.roomName;
22
-
23
-        if (config.configLocation) {
24
-            const location = config.configLocation;
25
-
26
-            obtainConfig(location, room)
27
-                .then(_obtainConfigHandler)
28
-                .then(_initConference)
29
-                .catch(err => {
30
-                    // Show obtain config error,
31
-                    // pass the error object for report
32
-                    APP.UI.messageHandler.openReportDialog(
33
-                        null, 'dialog.connectError', err);
34
-                });
35
-        } else {
36
-            BoshAddressChoice.chooseAddress(config, room);
37
-            _initConference();
38
-        }
39
-    }
40
-}
41
-
42
-/**
43
- * Obtain config handler.
44
- *
45
- * @returns {Promise}
46
- * @private
47
- */
48
-function _obtainConfigHandler() {
49
-    const now = window.performance.now();
50
-
51
-    APP.connectionTimes['configuration.fetched'] = now;
52
-    logger.log('(TIME) configuration fetched:\t', now);
53
-
54
-    return Promise.resolve();
55
-}
56
-
57
-/**
58
- *  Initialization of the app.
59
- *
60
- *  @returns {void}
61
- *  @private
62
- */
63
-function _initConference() {
64
-    setTokenData();
65
-
66
-    // Initialize the conference URL handler
67
-    APP.ConferenceUrl = new ConferenceUrl(window.location);
68
-}
69
-
70
-/**
71
- * Promise wrapper on obtain config method.
72
- * When HttpConfigFetch will be moved to React app
73
- * it's better to use load config instead.
74
- *
75
- * @param {string} location - URL of the domain.
76
- * @param {string} room - Room name.
77
- * @returns {Promise}
78
- */
79
-export function obtainConfig(location, room) {
80
-    return new Promise((resolve, reject) => {
81
-        HttpConfigFetch.obtainConfig(location, room, (success, error) => {
82
-            if (success) {
83
-                resolve();
84
-            } else {
85
-                reject(error);
86
-            }
87
-        });
88
-    });
89
-}
90
-
91
-/**
92
- * If JWT token data it will be used for local user settings.
93
- *
94
- * @returns {void}
95
- */
96
-export function setTokenData() {
97
-    const localUser = APP.tokenData.caller;
98
-
99
-    if (localUser) {
100
-        const email = localUser.getEmail();
101
-        const avatarUrl = localUser.getAvatarUrl();
102
-        const name = localUser.getName();
103
-
104
-        APP.settings.setEmail((email || '').trim(), true);
105
-        APP.settings.setAvatarUrl((avatarUrl || '').trim());
106
-        APP.settings.setDisplayName((name || '').trim(), true);
107
-    }
108
-}

+ 112
- 3
react/features/conference/route.js 查看文件

1
+/* global APP, config */
2
+
3
+import BoshAddressChoice from '../../../modules/config/BoshAddressChoice';
4
+import HttpConfigFetch from '../../../modules/config/HttpConfigFetch';
5
+import ConferenceUrl from '../../../modules/URL/ConferenceUrl';
6
+
1
 import { RouteRegistry } from '../base/navigator';
7
 import { RouteRegistry } from '../base/navigator';
2
 
8
 
3
 import { Conference } from './components';
9
 import { Conference } from './components';
4
-import { obtainConfigAndInit } from './functions';
10
+
11
+const logger = require('jitsi-meet-logger').getLogger(__filename);
5
 
12
 
6
 /**
13
 /**
7
  * Register route for Conference (page).
14
  * Register route for Conference (page).
9
 RouteRegistry.register({
16
 RouteRegistry.register({
10
     component: Conference,
17
     component: Conference,
11
     onEnter: () => {
18
     onEnter: () => {
12
-        // XXX: If config or jwt are set by hash or query parameters
19
+        // XXX If config or jwt are set by hash or query parameters
13
         // Getting raw URL before stripping it.
20
         // Getting raw URL before stripping it.
14
-        obtainConfigAndInit();
21
+        _obtainConfigAndInit();
15
     },
22
     },
16
     path: '/:room'
23
     path: '/:room'
17
 });
24
 });
25
+
26
+/**
27
+ *  Initialization of the app.
28
+ *
29
+ *  @private
30
+ *  @returns {void}
31
+ */
32
+function _initConference() {
33
+    _setTokenData();
34
+
35
+    // Initialize the conference URL handler
36
+    APP.ConferenceUrl = new ConferenceUrl(window.location);
37
+}
38
+
39
+/**
40
+ * Promise wrapper on obtain config method. When HttpConfigFetch will be moved
41
+ * to React app it's better to use load config instead.
42
+ *
43
+ * @param {string} location - URL of the domain.
44
+ * @param {string} room - Room name.
45
+ * @private
46
+ * @returns {Promise}
47
+ */
48
+function _obtainConfig(location, room) {
49
+    return new Promise((resolve, reject) => {
50
+        HttpConfigFetch.obtainConfig(location, room, (success, error) => {
51
+            if (success) {
52
+                resolve();
53
+            } else {
54
+                reject(error);
55
+            }
56
+        });
57
+    });
58
+}
59
+
60
+/**
61
+ * If we have an HTTP endpoint for getting config.json configured we're going to
62
+ * read it and override properties from config.js and interfaceConfig.js. If
63
+ * there is no endpoint we'll just continue with initialization. Keep in mind
64
+ * that if the endpoint has been configured and we fail to obtain the config for
65
+ * any reason then the conference won't start and error message will be
66
+ * displayed to the user.
67
+ *
68
+ * @private
69
+ * @returns {void}
70
+ */
71
+function _obtainConfigAndInit() {
72
+    // Skip initialization if conference is initialized already.
73
+    if (typeof APP !== 'undefined' && !APP.ConferenceUrl) {
74
+        const location = config.configLocation;
75
+        const room = APP.conference.roomName;
76
+
77
+        if (location) {
78
+            _obtainConfig(location, room)
79
+                .then(() => {
80
+                    _obtainConfigHandler();
81
+                    _initConference();
82
+                })
83
+                .catch(err => {
84
+                    // Show obtain config error.
85
+                    APP.UI.messageHandler.openReportDialog(
86
+                        null, 'dialog.connectError', err);
87
+                });
88
+        } else {
89
+            BoshAddressChoice.chooseAddress(config, room);
90
+            _initConference();
91
+        }
92
+    }
93
+}
94
+
95
+/**
96
+ * Obtain config handler.
97
+ *
98
+ * @private
99
+ * @returns {Promise}
100
+ */
101
+function _obtainConfigHandler() {
102
+    const now = window.performance.now();
103
+
104
+    APP.connectionTimes['configuration.fetched'] = now;
105
+    logger.log('(TIME) configuration fetched:\t', now);
106
+}
107
+
108
+/**
109
+ * If JWT token data it will be used for local user settings.
110
+ *
111
+ * @private
112
+ * @returns {void}
113
+ */
114
+function _setTokenData() {
115
+    const localUser = APP.tokenData.caller;
116
+
117
+    if (localUser) {
118
+        const email = localUser.getEmail();
119
+        const avatarUrl = localUser.getAvatarUrl();
120
+        const name = localUser.getName();
121
+
122
+        APP.settings.setEmail((email || '').trim(), true);
123
+        APP.settings.setAvatarUrl((avatarUrl || '').trim());
124
+        APP.settings.setDisplayName((name || '').trim(), true);
125
+    }
126
+}

+ 18
- 17
react/features/welcome/route.js 查看文件

1
 /* global APP */
1
 /* global APP */
2
+
2
 import { RouteRegistry } from '../base/navigator';
3
 import { RouteRegistry } from '../base/navigator';
3
 import { generateRoomWithoutSeparator } from '../base/util';
4
 import { generateRoomWithoutSeparator } from '../base/util';
5
+
4
 import { WelcomePage } from './components';
6
 import { WelcomePage } from './components';
5
 
7
 
8
+/**
9
+ * Register route for WelcomePage.
10
+ */
11
+RouteRegistry.register({
12
+    component: WelcomePage,
13
+    onEnter,
14
+    path: '/'
15
+});
6
 
16
 
7
 /**
17
 /**
8
- * Function that checks if welcome page is enabled and if it isn't
9
- * redirects to randomly created conference.
18
+ * If the Welcome page/screen is disabled, generates a (random) room (name) so
19
+ * that the Welcome page/screen is skipped and the Conference page/screen is
20
+ * presented instead.
10
  *
21
  *
11
- * @param {Object} nextState - Next router state.
12
- * @param {Function} replace - Function to redirect to another path.
22
+ * @param {Object} nextState - The next Router state.
23
+ * @param {Function} replace - The function to redirect to another path.
13
  * @returns {void}
24
  * @returns {void}
14
  */
25
  */
15
 function onEnter(nextState, replace) {
26
 function onEnter(nextState, replace) {
16
-    if (!APP.settings.isWelcomePageEnabled()) {
17
-        const generatedRoomname = generateRoomWithoutSeparator();
18
-        const normalizedRoomname = generatedRoomname.toLowerCase();
27
+    if (typeof APP !== 'undefined' && !APP.settings.isWelcomePageEnabled()) {
28
+        const room = generateRoomWithoutSeparator();
19
 
29
 
20
-        replace(`/${normalizedRoomname}`);
30
+        replace(`/${room}`);
21
     }
31
     }
22
 }
32
 }
23
-
24
-/**
25
- * Register route for WelcomePage.
26
- */
27
-RouteRegistry.register({
28
-    component: WelcomePage,
29
-    onEnter,
30
-    path: '/'
31
-});

+ 3
- 1
react/index.native.js 查看文件

61
 
61
 
62
                 // XXX Start with an empty URL if getting the initial URL fails;
62
                 // XXX Start with an empty URL if getting the initial URL fails;
63
                 // otherwise, nothing will be rendered.
63
                 // otherwise, nothing will be rendered.
64
-                this.setState({ url: null });
64
+                if (this.state.url !== null) {
65
+                    this.setState({ url: null });
66
+                }
65
             });
67
             });
66
     }
68
     }
67
 
69
 

+ 6
- 11
react/index.web.js 查看文件

1
 /* global APP */
1
 /* global APP */
2
+
2
 import React from 'react';
3
 import React from 'react';
3
 import ReactDOM from 'react-dom';
4
 import ReactDOM from 'react-dom';
4
 import { browserHistory } from 'react-router';
5
 import { browserHistory } from 'react-router';
5
-import {
6
-    routerMiddleware,
7
-    routerReducer
8
-} from 'react-router-redux';
6
+import { routerMiddleware, routerReducer } from 'react-router-redux';
9
 import { compose, createStore } from 'redux';
7
 import { compose, createStore } from 'redux';
10
 import Thunk from 'redux-thunk';
8
 import Thunk from 'redux-thunk';
11
 
9
 
12
 import config from './config';
10
 import config from './config';
13
 import { App } from './features/app';
11
 import { App } from './features/app';
14
-import {
15
-    MiddlewareRegistry,
16
-    ReducerRegistry
17
-} from './features/base/redux';
12
+import { MiddlewareRegistry, ReducerRegistry } from './features/base/redux';
18
 
13
 
19
 const logger = require('jitsi-meet-logger').getLogger(__filename);
14
 const logger = require('jitsi-meet-logger').getLogger(__filename);
20
 
15
 
49
 const store = createStore(reducer, middleware);
44
 const store = createStore(reducer, middleware);
50
 
45
 
51
 /**
46
 /**
52
- * Render the app when DOM tree has been loaded.
47
+ * Renders the app when the DOM tree has been loaded.
53
  */
48
  */
54
 document.addEventListener('DOMContentLoaded', () => {
49
 document.addEventListener('DOMContentLoaded', () => {
55
     const now = window.performance.now();
50
     const now = window.performance.now();
67
 });
62
 });
68
 
63
 
69
 /**
64
 /**
70
- * Stop collecting the logs and disposing the API when
71
- * user closes the page.
65
+ * Stops collecting the logs and disposing the API when the user closes the
66
+ * page.
72
  */
67
  */
73
 window.addEventListener('beforeunload', () => {
68
 window.addEventListener('beforeunload', () => {
74
     // Stop the LogCollector
69
     // Stop the LogCollector

Loading…
取消
儲存