|
@@ -3,23 +3,134 @@ import { RouteRegistry } from '../base/react';
|
3
|
3
|
import { Conference } from '../conference';
|
4
|
4
|
import { WelcomePage } from '../welcome';
|
5
|
5
|
|
|
6
|
+/**
|
|
7
|
+ * The RegExp pattern of the authority of a URI.
|
|
8
|
+ *
|
|
9
|
+ * @private
|
|
10
|
+ * @type {string}
|
|
11
|
+ */
|
|
12
|
+const _URI_AUTHORITY_PATTERN = '(//[^/?#]+)';
|
|
13
|
+
|
|
14
|
+/**
|
|
15
|
+ * The RegExp pattern of the path of a URI.
|
|
16
|
+ *
|
|
17
|
+ * @private
|
|
18
|
+ * @type {string}
|
|
19
|
+ */
|
|
20
|
+const _URI_PATH_PATTERN = '([^?#]*)';
|
|
21
|
+
|
|
22
|
+/**
|
|
23
|
+ * The RegExp patther of the protocol of a URI.
|
|
24
|
+ *
|
|
25
|
+ * @private
|
|
26
|
+ * @type {string}
|
|
27
|
+ */
|
|
28
|
+const _URI_PROTOCOL_PATTERN = '([a-z][a-z0-9\\.\\+-]*:)';
|
|
29
|
+
|
|
30
|
+/**
|
|
31
|
+ * Fixes the hier-part of a specific URI (string) so that the URI is well-known.
|
|
32
|
+ * For example, certain Jitsi Meet deployments are not conventional but it is
|
|
33
|
+ * possible to translate their URLs into conventional.
|
|
34
|
+ *
|
|
35
|
+ * @param {string} uri - The URI (string) to fix the hier-part of.
|
|
36
|
+ * @private
|
|
37
|
+ * @returns {string}
|
|
38
|
+ */
|
|
39
|
+function _fixURIStringHierPart(uri) {
|
|
40
|
+ // Rewrite the specified URL in order to handle special cases such as
|
|
41
|
+ // hipchat.com and enso.me which do not follow the common pattern of most
|
|
42
|
+ // Jitsi Meet deployments.
|
|
43
|
+
|
|
44
|
+ // hipchat.com
|
|
45
|
+ let regex
|
|
46
|
+ = new RegExp(
|
|
47
|
+ `^${_URI_PROTOCOL_PATTERN}//hipchat\\.com/video/call/`,
|
|
48
|
+ 'gi');
|
|
49
|
+ let match = regex.exec(uri);
|
|
50
|
+
|
|
51
|
+ if (!match) {
|
|
52
|
+ // enso.me
|
|
53
|
+ regex
|
|
54
|
+ = new RegExp(
|
|
55
|
+ `^${_URI_PROTOCOL_PATTERN}//enso\\.me/(?:call|meeting)/`,
|
|
56
|
+ 'gi');
|
|
57
|
+ match = regex.exec(uri);
|
|
58
|
+ }
|
|
59
|
+ if (match) {
|
|
60
|
+ /* eslint-disable no-param-reassign, prefer-template */
|
|
61
|
+
|
|
62
|
+ uri
|
|
63
|
+ = match[1] /* protocol */
|
|
64
|
+ + '//enso.hipchat.me/'
|
|
65
|
+ + uri.substring(regex.lastIndex); /* room (name) */
|
|
66
|
+
|
|
67
|
+ /* eslint-enable no-param-reassign, prefer-template */
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ return uri;
|
|
71
|
+}
|
|
72
|
+
|
|
73
|
+/**
|
|
74
|
+ * Fixes the scheme part of a specific URI (string) so that it contains a
|
|
75
|
+ * well-known scheme such as HTTP(S). For example, the mobile app implements an
|
|
76
|
+ * app-specific URI scheme in addition to Universal Links. The app-specific
|
|
77
|
+ * scheme may precede or replace the well-known scheme. In such a case, dealing
|
|
78
|
+ * with the app-specific scheme only complicates the logic and it is simpler to
|
|
79
|
+ * get rid of it (by translating the app-specific scheme into a well-known
|
|
80
|
+ * scheme).
|
|
81
|
+ *
|
|
82
|
+ * @param {string} uri - The URI (string) to fix the scheme of.
|
|
83
|
+ * @private
|
|
84
|
+ * @returns {string}
|
|
85
|
+ */
|
|
86
|
+function _fixURIStringScheme(uri) {
|
|
87
|
+ const regex = new RegExp(`^${_URI_PROTOCOL_PATTERN}+`, 'gi');
|
|
88
|
+ const match = regex.exec(uri);
|
|
89
|
+
|
|
90
|
+ if (match) {
|
|
91
|
+ // As an implementation convenience, pick up the last scheme and make
|
|
92
|
+ // sure that it is a well-known one.
|
|
93
|
+ let protocol = match[match.length - 1].toLowerCase();
|
|
94
|
+
|
|
95
|
+ if (protocol !== 'http:' && protocol !== 'https:') {
|
|
96
|
+ protocol = 'https:';
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ /* eslint-disable no-param-reassign */
|
|
100
|
+
|
|
101
|
+ uri = uri.substring(regex.lastIndex);
|
|
102
|
+ if (uri.startsWith('//')) {
|
|
103
|
+ // The specified URL was not a room name only, it contained an
|
|
104
|
+ // authority.
|
|
105
|
+ uri = protocol + uri;
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ /* eslint-enable no-param-reassign */
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ return uri;
|
|
112
|
+}
|
|
113
|
+
|
6
|
114
|
/**
|
7
|
115
|
* Gets room name and domain from URL object.
|
8
|
116
|
*
|
9
|
117
|
* @param {URL} url - URL object.
|
10
|
118
|
* @private
|
11
|
119
|
* @returns {{
|
12
|
|
- * domain: (string|undefined),
|
13
|
|
- * room: (string|undefined)
|
14
|
|
- * }}
|
|
120
|
+ * domain: (string|undefined),
|
|
121
|
+ * room: (string|undefined)
|
|
122
|
+ * }}
|
15
|
123
|
*/
|
16
|
|
-function _getRoomAndDomainFromUrlObject(url) {
|
|
124
|
+function _getRoomAndDomainFromURLObject(url) {
|
17
|
125
|
let domain;
|
18
|
126
|
let room;
|
19
|
127
|
|
20
|
128
|
if (url) {
|
21
|
129
|
domain = url.hostname;
|
22
|
|
- room = url.pathname.substr(1);
|
|
130
|
+
|
|
131
|
+ // The room (name) is the last component of pathname.
|
|
132
|
+ room = url.pathname;
|
|
133
|
+ room = room.substring(room.lastIndexOf('/') + 1);
|
23
|
134
|
|
24
|
135
|
// Convert empty string to undefined to simplify checks.
|
25
|
136
|
if (room === '') {
|
|
@@ -36,44 +147,6 @@ function _getRoomAndDomainFromUrlObject(url) {
|
36
|
147
|
};
|
37
|
148
|
}
|
38
|
149
|
|
39
|
|
-/**
|
40
|
|
- * Gets conference room name and connection domain from URL.
|
41
|
|
- *
|
42
|
|
- * @param {(string|undefined)} url - URL.
|
43
|
|
- * @returns {{
|
44
|
|
- * domain: (string|undefined),
|
45
|
|
- * room: (string|undefined)
|
46
|
|
- * }}
|
47
|
|
- */
|
48
|
|
-export function _getRoomAndDomainFromUrlString(url) {
|
49
|
|
- // Rewrite the specified URL in order to handle special cases such as
|
50
|
|
- // hipchat.com and enso.me which do not follow the common pattern of most
|
51
|
|
- // Jitsi Meet deployments.
|
52
|
|
- if (typeof url === 'string') {
|
53
|
|
- // hipchat.com
|
54
|
|
- let regex = /^(https?):\/\/hipchat.com\/video\/call\//gi;
|
55
|
|
- let match = regex.exec(url);
|
56
|
|
-
|
57
|
|
- if (!match) {
|
58
|
|
- // enso.me
|
59
|
|
- regex = /^(https?):\/\/enso\.me\/(?:call|meeting)\//gi;
|
60
|
|
- match = regex.exec(url);
|
61
|
|
- }
|
62
|
|
- if (match && match.length > 1) {
|
63
|
|
- /* eslint-disable no-param-reassign, prefer-template */
|
64
|
|
-
|
65
|
|
- url
|
66
|
|
- = match[1] /* URL protocol */
|
67
|
|
- + '://enso.hipchat.me/'
|
68
|
|
- + url.substring(regex.lastIndex);
|
69
|
|
-
|
70
|
|
- /* eslint-enable no-param-reassign, prefer-template */
|
71
|
|
- }
|
72
|
|
- }
|
73
|
|
-
|
74
|
|
- return _getRoomAndDomainFromUrlObject(_urlStringToObject(url));
|
75
|
|
-}
|
76
|
|
-
|
77
|
150
|
/**
|
78
|
151
|
* Determines which route is to be rendered in order to depict a specific Redux
|
79
|
152
|
* store.
|
|
@@ -94,24 +167,74 @@ export function _getRouteToRender(stateOrGetState) {
|
94
|
167
|
}
|
95
|
168
|
|
96
|
169
|
/**
|
97
|
|
- * Parses a string into a URL (object).
|
|
170
|
+ * Parses a specific URI which (supposedly) references a Jitsi Meet resource
|
|
171
|
+ * (location).
|
98
|
172
|
*
|
99
|
|
- * @param {(string|undefined)} url - The URL to parse.
|
100
|
|
- * @private
|
101
|
|
- * @returns {URL}
|
|
173
|
+ * @param {(string|undefined)} uri - The URI to parse which (supposedly)
|
|
174
|
+ * references a Jitsi Meet resource (location).
|
|
175
|
+ * @returns {{
|
|
176
|
+ * domain: (string|undefined),
|
|
177
|
+ * room: (string|undefined)
|
|
178
|
+ * }}
|
102
|
179
|
*/
|
103
|
|
-function _urlStringToObject(url) {
|
104
|
|
- let urlObj;
|
|
180
|
+export function _parseURIString(uri) {
|
|
181
|
+ let obj;
|
105
|
182
|
|
106
|
|
- if (url) {
|
107
|
|
- try {
|
108
|
|
- urlObj = new URL(url);
|
109
|
|
- } catch (ex) {
|
110
|
|
- // The return value will signal the failure & the logged exception
|
111
|
|
- // will provide the details to the developers.
|
112
|
|
- console.log(`${url} seems to be not a valid URL, but it's OK`, ex);
|
|
183
|
+ if (typeof uri === 'string') {
|
|
184
|
+ let str = uri;
|
|
185
|
+
|
|
186
|
+ str = _fixURIStringScheme(str);
|
|
187
|
+ str = _fixURIStringHierPart(str);
|
|
188
|
+
|
|
189
|
+ obj = {};
|
|
190
|
+
|
|
191
|
+ let regex;
|
|
192
|
+ let match;
|
|
193
|
+
|
|
194
|
+ // protocol
|
|
195
|
+ regex = new RegExp(`^${_URI_PROTOCOL_PATTERN}`, 'gi');
|
|
196
|
+ match = regex.exec(str);
|
|
197
|
+ if (match) {
|
|
198
|
+ obj.protocol = match[1].toLowerCase();
|
|
199
|
+ str = str.substring(regex.lastIndex);
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ // authority
|
|
203
|
+ regex = new RegExp(`^${_URI_AUTHORITY_PATTERN}`, 'gi');
|
|
204
|
+ match = regex.exec(str);
|
|
205
|
+ if (match) {
|
|
206
|
+ let authority = match[1];
|
|
207
|
+
|
|
208
|
+ str = str.substring(regex.lastIndex);
|
|
209
|
+
|
|
210
|
+ // userinfo
|
|
211
|
+ const userinfoEndIndex = authority.indexOf('@');
|
|
212
|
+
|
|
213
|
+ if (userinfoEndIndex !== -1) {
|
|
214
|
+ authority = authority.substring(userinfoEndIndex + 1);
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ obj.host = authority;
|
|
218
|
+
|
|
219
|
+ // port
|
|
220
|
+ const portBeginIndex = authority.lastIndexOf(':');
|
|
221
|
+
|
|
222
|
+ if (portBeginIndex !== -1) {
|
|
223
|
+ obj.port = authority.substring(portBeginIndex + 1);
|
|
224
|
+ authority = authority.substring(0, portBeginIndex);
|
|
225
|
+ }
|
|
226
|
+
|
|
227
|
+ obj.hostname = authority;
|
|
228
|
+ }
|
|
229
|
+
|
|
230
|
+ // pathname
|
|
231
|
+ regex = new RegExp(`^${_URI_PATH_PATTERN}`, 'gi');
|
|
232
|
+ match = regex.exec(str);
|
|
233
|
+ if (match) {
|
|
234
|
+ obj.pathname = match[1] || '/';
|
|
235
|
+ str = str.substring(regex.lastIndex);
|
113
|
236
|
}
|
114
|
237
|
}
|
115
|
238
|
|
116
|
|
- return urlObj;
|
|
239
|
+ return _getRoomAndDomainFromURLObject(obj);
|
117
|
240
|
}
|