Browse Source

Clean up Conference component

j8
Ilya Daynatovich 8 years ago
parent
commit
a99bbe67ab

+ 67
- 0
react/features/conference/actions.js View File

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
+}

+ 3
- 88
react/features/conference/components/Conference.web.js View File

1
-/* global APP, $, interfaceConfig, config */
1
+/* global APP, $, interfaceConfig */
2
 
2
 
3
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
4
 import { connect as reactReduxConnect } from 'react-redux';
4
 import { connect as reactReduxConnect } from 'react-redux';
7
     connect,
7
     connect,
8
     disconnect
8
     disconnect
9
 } from '../../base/connection';
9
 } from '../../base/connection';
10
-import ConferenceUrl from '../../../../modules/URL/ConferenceUrl';
11
-import HttpConfigFetch from '../../../../modules/config/HttpConfigFetch';
12
-import BoshAddressChoice from '../../../../modules/config/BoshAddressChoice';
13
-
14
-const logger = require('jitsi-meet-logger').getLogger(__filename);
10
+import { obtainConfigAndInit } from '../actions';
15
 
11
 
16
 /**
12
 /**
17
  * For legacy reasons, inline style for display none.
13
  * For legacy reasons, inline style for display none.
33
      * @inheritdoc
29
      * @inheritdoc
34
      */
30
      */
35
     componentDidMount() {
31
     componentDidMount() {
36
-
37
-        /**
38
-         * If JWT token data it will be used for local user settings.
39
-         *
40
-         * @returns {void}
41
-         */
42
-        function setTokenData() {
43
-            const localUser = APP.tokenData.caller;
44
-
45
-            if (localUser) {
46
-                const email = localUser.getEmail();
47
-                const avatarUrl = localUser.getAvatarUrl();
48
-                const name = localUser.getName();
49
-
50
-                APP.settings.setEmail((email || '').trim(), true);
51
-                APP.settings.setAvatarUrl((avatarUrl || '').trim());
52
-                APP.settings.setDisplayName((name || '').trim(), true);
53
-            }
54
-        }
55
-
56
-        /**
57
-         *  Initialization of the app.
58
-         *
59
-         *  @returns {void}
60
-         */
61
-        function init() {
62
-            setTokenData();
63
-
64
-            // Initialize the conference URL handler
65
-            APP.ConferenceUrl = new ConferenceUrl(window.location);
66
-        }
67
-
68
-        /**
69
-         * If we have an HTTP endpoint for getting config.json configured
70
-         * we're going to read it and override properties from config.js and
71
-         * interfaceConfig.js. If there is no endpoint we'll just
72
-         * continue with initialization.
73
-         * Keep in mind that if the endpoint has been configured and we fail
74
-         * to obtain the config for any reason then the conference won't
75
-         * start and error message will be displayed to the user.
76
-         *
77
-         * @returns {void}
78
-         */
79
-        function obtainConfigAndInit() {
80
-            const room = APP.conference.roomName;
81
-
82
-            if (config.configLocation) {
83
-                const configFetch = HttpConfigFetch;
84
-                const location = config.configLocation;
85
-
86
-                configFetch.obtainConfig(location, room, obtainConfigHandler);
87
-            } else {
88
-                BoshAddressChoice.chooseAddress(config, room);
89
-                init();
90
-            }
91
-        }
92
-
93
-        /**
94
-         * Obtain config handler.
95
-         *
96
-         * @param {boolean} success - Equals to true if
97
-         * config has been obtained w/o errors.
98
-         * @param {Object} error - Error object if there is error occured
99
-         * while fetching config.
100
-         * @returns {void}
101
-         */
102
-        function obtainConfigHandler(success, error) {
103
-            if (success) {
104
-                const now = window.performance.now();
105
-
106
-                APP.connectionTimes['configuration.fetched'] = now;
107
-                logger.log('(TIME) configuration fetched:\t', now);
108
-                init();
109
-            } else {
110
-                // Show obtain config error,
111
-                // pass the error object for report
112
-                APP.UI.messageHandler.openReportDialog(
113
-                    null, 'dialog.connectError', error);
114
-            }
115
-        }
116
-
117
-        obtainConfigAndInit();
32
+        this.props.dispatch(obtainConfigAndInit());
118
         APP.UI.start();
33
         APP.UI.start();
119
 
34
 
120
         // XXX Temporary solution until we add React translation.
35
         // XXX Temporary solution until we add React translation.

+ 42
- 0
react/features/conference/functions.js View File

1
+/* global APP */
2
+import HttpConfigFetch from '../../../modules/config/HttpConfigFetch';
3
+
4
+/**
5
+ * Promise wrapper on obtain config method.
6
+ * When HttpConfigFetch will be moved to React app
7
+ * it's better to use load config instead.
8
+ *
9
+ * @param {string} location - URL of the domain.
10
+ * @param {string} room - Room name.
11
+ * @returns {Promise}
12
+ */
13
+export function obtainConfig(location, room) {
14
+    return new Promise((resolve, reject) => {
15
+        HttpConfigFetch.obtainConfig(location, room, (success, error) => {
16
+            if (success) {
17
+                resolve();
18
+            } else {
19
+                reject(error);
20
+            }
21
+        });
22
+    });
23
+}
24
+
25
+/**
26
+ * If JWT token data it will be used for local user settings.
27
+ *
28
+ * @returns {void}
29
+ */
30
+export function setTokenData() {
31
+    const localUser = APP.tokenData.caller;
32
+
33
+    if (localUser) {
34
+        const email = localUser.getEmail();
35
+        const avatarUrl = localUser.getAvatarUrl();
36
+        const name = localUser.getName();
37
+
38
+        APP.settings.setEmail((email || '').trim(), true);
39
+        APP.settings.setAvatarUrl((avatarUrl || '').trim());
40
+        APP.settings.setDisplayName((name || '').trim(), true);
41
+    }
42
+}

Loading…
Cancel
Save