|
@@ -0,0 +1,214 @@
|
|
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
|
+
|
|
10
|
+import URLProcessor from '../../../modules/config/URLProcessor';
|
|
11
|
+import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
|
|
12
|
+
|
|
13
|
+// eslint-disable-next-line max-len
|
|
14
|
+import KeyboardShortcut from '../../../modules/keyboardshortcut/keyboardshortcut';
|
|
15
|
+
|
|
16
|
+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
|
+
|
|
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
|
+}
|
|
132
|
+
|
|
133
|
+/**
|
|
134
|
+ * Temporary solution. Later we'll get rid of global APP
|
|
135
|
+ * and set its properties in redux store.
|
|
136
|
+ *
|
|
137
|
+ * @returns {void}
|
|
138
|
+ */
|
|
139
|
+export function init() {
|
|
140
|
+ _setConfigParametersFromUrl();
|
|
141
|
+ _initLogging();
|
|
142
|
+
|
|
143
|
+ APP.keyboardshortcut = KeyboardShortcut;
|
|
144
|
+ APP.tokenData = getTokenData();
|
|
145
|
+ APP.API.init(APP.tokenData.externalAPISettings);
|
|
146
|
+
|
|
147
|
+ APP.translation.init(settings.getLanguage());
|
|
148
|
+}
|
|
149
|
+
|
|
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
|
+/**
|
|
172
|
+ * Adjusts the logging levels.
|
|
173
|
+ *
|
|
174
|
+ * @private
|
|
175
|
+ * @returns {void}
|
|
176
|
+ */
|
|
177
|
+function configureLoggingLevels() {
|
|
178
|
+ // NOTE The library Logger is separated from
|
|
179
|
+ // the app loggers, so the levels
|
|
180
|
+ // have to be set in two places
|
|
181
|
+
|
|
182
|
+ // Set default logging level
|
|
183
|
+ const defaultLogLevel
|
|
184
|
+ = loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE;
|
|
185
|
+
|
|
186
|
+ Logger.setLogLevel(defaultLogLevel);
|
|
187
|
+ JitsiMeetJS.setLogLevel(defaultLogLevel);
|
|
188
|
+
|
|
189
|
+ // NOTE console was used on purpose here to go around the logging
|
|
190
|
+ // and always print the default logging level to the console
|
|
191
|
+ console.info(`Default logging level set to: ${defaultLogLevel}`);
|
|
192
|
+
|
|
193
|
+ // Set log level for each logger
|
|
194
|
+ if (loggingConfig) {
|
|
195
|
+ Object.keys(loggingConfig).forEach(loggerName => {
|
|
196
|
+ if (loggerName !== 'defaultLogLevel') {
|
|
197
|
+ const level = loggingConfig[loggerName];
|
|
198
|
+
|
|
199
|
+ Logger.setLogLevelById(level, loggerName);
|
|
200
|
+ JitsiMeetJS.setLogLevelById(level, loggerName);
|
|
201
|
+ }
|
|
202
|
+ });
|
|
203
|
+ }
|
|
204
|
+}
|
|
205
|
+
|
|
206
|
+/**
|
|
207
|
+ * Sets config parameters from query string.
|
|
208
|
+ *
|
|
209
|
+ * @private
|
|
210
|
+ * @returns {void}
|
|
211
|
+ */
|
|
212
|
+function _setConfigParametersFromUrl() {
|
|
213
|
+ URLProcessor.setConfigParametersFromUrl();
|
|
214
|
+}
|