Bladeren bron

[RN] Fix normalizing BOSH URLs (#3376)

If a relative BOSH URL is found (as docker-jitsi-meet does) construct a full URL
based on the location URL and context root.

Also remove some default options since we need the config file anyway, so I see
no point in doing the extra work.
master
Saúl Ibarra Corretgé 6 jaren geleden
bovenliggende
commit
a896d8f076
2 gewijzigde bestanden met toevoegingen van 26 en 70 verwijderingen
  1. 24
    20
      react/features/base/connection/actions.native.js
  2. 2
    50
      react/features/base/connection/reducer.js

+ 24
- 20
react/features/base/connection/actions.native.js Bestand weergeven

@@ -9,7 +9,7 @@ import {
9 9
     getCurrentConference
10 10
 } from '../conference';
11 11
 import JitsiMeetJS, { JitsiConnectionEvents } from '../lib-jitsi-meet';
12
-import { parseStandardURIString } from '../util';
12
+import { parseURIString } from '../util';
13 13
 
14 14
 import {
15 15
     CONNECTION_DISCONNECTED,
@@ -276,18 +276,32 @@ function _connectionWillConnect(connection) {
276 276
  * {@code JitsiConnection}.
277 277
  */
278 278
 function _constructOptions(state) {
279
-    const defaultOptions = state['features/base/connection'].options;
280
-    const options = _.merge(
281
-        {},
282
-        defaultOptions,
283
-
284
-        // Lib-jitsi-meet wants the config passed in multiple places and here is
285
-        // the latest one I have discovered.
286
-        state['features/base/config'],
287
-    );
279
+    // Deep clone the options to make sure we don't modify the object in the
280
+    // redux store.
281
+    const options = _.cloneDeep(state['features/base/config']);
282
+
283
+    // Normalize the BOSH URL.
288 284
     let { bosh } = options;
289 285
 
290 286
     if (bosh) {
287
+        if (bosh.startsWith('//')) {
288
+            // By default our config.js doesn't include the protocol.
289
+            const { locationURL } = state['features/base/connection'];
290
+
291
+            bosh = `${locationURL.protocol}${bosh}`;
292
+        } else if (bosh.startsWith('/')) {
293
+            // Handle relative URLs, which won't work on mobile.
294
+            const { locationURL } = state['features/base/connection'];
295
+            const {
296
+                protocol,
297
+                hostname,
298
+                contextRoot
299
+            } = parseURIString(locationURL.href);
300
+
301
+            // eslint-disable-next-line max-len
302
+            bosh = `${protocol}//${hostname}${contextRoot || '/'}${bosh.substr(1)}`;
303
+        }
304
+
291 305
         // Append room to the URL's search.
292 306
         const { room } = state['features/base/conference'];
293 307
 
@@ -296,16 +310,6 @@ function _constructOptions(state) {
296 310
         // not ignore case themselves.
297 311
         room && (bosh += `?room=${room.toLowerCase()}`);
298 312
 
299
-        // XXX By default, config.js does not add a protocol to the BOSH URL.
300
-        // Which trips React Native. Make sure there is a protocol in order to
301
-        // satisfy React Native.
302
-        if (bosh !== defaultOptions.bosh
303
-                && !parseStandardURIString(bosh).protocol) {
304
-            const { protocol } = parseStandardURIString(defaultOptions.bosh);
305
-
306
-            protocol && (bosh = protocol + bosh);
307
-        }
308
-
309 313
         options.bosh = bosh;
310 314
     }
311 315
 

+ 2
- 50
react/features/base/connection/reducer.js Bestand weergeven

@@ -2,8 +2,7 @@
2 2
 
3 3
 import { SET_ROOM } from '../conference';
4 4
 import { JitsiConnectionErrors } from '../lib-jitsi-meet';
5
-import { assign, ReducerRegistry } from '../redux';
6
-import { parseURIString } from '../util';
5
+import { assign, set, ReducerRegistry } from '../redux';
7 6
 
8 7
 import {
9 8
     CONNECTION_DISCONNECTED,
@@ -153,50 +152,6 @@ function _connectionWillConnect(
153 152
     });
154 153
 }
155 154
 
156
-/**
157
- * Constructs options to be passed to the constructor of {@code JitsiConnection}
158
- * based on a specific location URL.
159
- *
160
- * @param {string} locationURL - The location URL with which the returned
161
- * options are to be constructed.
162
- * @private
163
- * @returns {Object} The options to be passed to the constructor of
164
- * {@code JitsiConnection} based on the location URL.
165
- */
166
-function _constructOptions(locationURL: URL) {
167
-    const locationURI = parseURIString(locationURL.href);
168
-
169
-    // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
170
-    // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
171
-    // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
172
-    // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
173
-    let { protocol } = locationURI;
174
-    const domain = locationURI.hostname;
175
-
176
-    if (!protocol && domain === 'beta.meet.jit.si') {
177
-        const windowLocation = window.location;
178
-
179
-        windowLocation && (protocol = windowLocation.protocol);
180
-        protocol || (protocol = 'http:');
181
-    }
182
-
183
-    // Default to the HTTPS scheme for the BOSH URL.
184
-    protocol || (protocol = 'https:');
185
-
186
-    return {
187
-        bosh:
188
-            `${String(protocol)}//${domain}${
189
-                locationURI.contextRoot || '/'}http-bind`,
190
-        hosts: {
191
-            domain,
192
-
193
-            // Required by:
194
-            // - lib-jitsi-meet/modules/xmpp/xmpp.js
195
-            muc: `conference.${domain}`
196
-        }
197
-    };
198
-}
199
-
200 155
 /**
201 156
  * The current (similar to getCurrentConference in base/conference/functions.js)
202 157
  * connection which is {@code connection} or {@code connecting}.
@@ -223,10 +178,7 @@ function _getCurrentConnection(baseConnectionState: Object): ?Object {
223 178
 function _setLocationURL(
224 179
         state: Object,
225 180
         { locationURL }: { locationURL: ?URL }) {
226
-    return assign(state, {
227
-        locationURL,
228
-        options: locationURL ? _constructOptions(locationURL) : undefined
229
-    });
181
+    return set(state, 'locationURL', locationURL);
230 182
 }
231 183
 
232 184
 /**

Laden…
Annuleren
Opslaan