Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

[RN] Fix normalizing BOSH URLs (#3376)

Saúl Ibarra Corretgéa896d8f076e7
diff --git a/react/features/base/connection/actions.native.js b/react/features/base/connection/actions.native.js
index 0ee82fbf5f..849e6dfb5e 100644
--- a/react/features/base/connection/actions.native.js
+++ b/react/features/base/connection/actions.native.js
@@ -9,7 +9,7 @@ import {
getCurrentConference
} from '../conference';
import JitsiMeetJS, { JitsiConnectionEvents } from '../lib-jitsi-meet';
-import { parseStandardURIString } from '../util';
+import { parseURIString } from '../util';
import {
CONNECTION_DISCONNECTED,
@@ -276,18 +276,32 @@ function _connectionWillConnect(connection) {
* {@code JitsiConnection}.
*/
function _constructOptions(state) {
- const defaultOptions = state['features/base/connection'].options;
- const options = _.merge(
- {},
- defaultOptions,
-
- // Lib-jitsi-meet wants the config passed in multiple places and here is
- // the latest one I have discovered.
- state['features/base/config'],
- );
+ // Deep clone the options to make sure we don't modify the object in the
+ // redux store.
+ const options = _.cloneDeep(state['features/base/config']);
+
+ // Normalize the BOSH URL.
let { bosh } = options;
if (bosh) {
+ if (bosh.startsWith('//')) {
+ // By default our config.js doesn't include the protocol.
+ const { locationURL } = state['features/base/connection'];
+
+ bosh = `${locationURL.protocol}${bosh}`;
+ } else if (bosh.startsWith('/')) {
+ // Handle relative URLs, which won't work on mobile.
+ const { locationURL } = state['features/base/connection'];
+ const {
+ protocol,
+ hostname,
+ contextRoot
+ } = parseURIString(locationURL.href);
+
+ // eslint-disable-next-line max-len
+ bosh = `${protocol}//${hostname}${contextRoot || '/'}${bosh.substr(1)}`;
+ }
+
// Append room to the URL's search.
const { room } = state['features/base/conference'];
@@ -296,16 +310,6 @@ function _constructOptions(state) {
// not ignore case themselves.
room && (bosh += `?room=${room.toLowerCase()}`);
- // XXX By default, config.js does not add a protocol to the BOSH URL.
- // Which trips React Native. Make sure there is a protocol in order to
- // satisfy React Native.
- if (bosh !== defaultOptions.bosh
- && !parseStandardURIString(bosh).protocol) {
- const { protocol } = parseStandardURIString(defaultOptions.bosh);
-
- protocol && (bosh = protocol + bosh);
- }
-
options.bosh = bosh;
}
diff --git a/react/features/base/connection/reducer.js b/react/features/base/connection/reducer.js
index 7bb8aed327..41d01da524 100644
--- a/react/features/base/connection/reducer.js
+++ b/react/features/base/connection/reducer.js
@@ -2,8 +2,7 @@
import { SET_ROOM } from '../conference';
import { JitsiConnectionErrors } from '../lib-jitsi-meet';
-import { assign, ReducerRegistry } from '../redux';
-import { parseURIString } from '../util';
+import { assign, set, ReducerRegistry } from '../redux';
import {
CONNECTION_DISCONNECTED,
@@ -153,50 +152,6 @@ function _connectionWillConnect(
});
}
-/**
- * Constructs options to be passed to the constructor of {@code JitsiConnection}
- * based on a specific location URL.
- *
- * @param {string} locationURL - The location URL with which the returned
- * options are to be constructed.
- * @private
- * @returns {Object} The options to be passed to the constructor of
- * {@code JitsiConnection} based on the location URL.
- */
-function _constructOptions(locationURL: URL) {
- const locationURI = parseURIString(locationURL.href);
-
- // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
- // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
- // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
- // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
- let { protocol } = locationURI;
- const domain = locationURI.hostname;
-
- if (!protocol && domain === 'beta.meet.jit.si') {
- const windowLocation = window.location;
-
- windowLocation && (protocol = windowLocation.protocol);
- protocol || (protocol = 'http:');
- }
-
- // Default to the HTTPS scheme for the BOSH URL.
- protocol || (protocol = 'https:');
-
- return {
- bosh:
- `${String(protocol)}//${domain}${
- locationURI.contextRoot || '/'}http-bind`,
- hosts: {
- domain,
-
- // Required by:
- // - lib-jitsi-meet/modules/xmpp/xmpp.js
- muc: `conference.${domain}`
- }
- };
-}
-
/**
* The current (similar to getCurrentConference in base/conference/functions.js)
* connection which is {@code connection} or {@code connecting}.
@@ -223,10 +178,7 @@ function _getCurrentConnection(baseConnectionState: Object): ?Object {
function _setLocationURL(
state: Object,
{ locationURL }: { locationURL: ?URL }) {
- return assign(state, {
- locationURL,
- options: locationURL ? _constructOptions(locationURL) : undefined
- });
+ return set(state, 'locationURL', locationURL);
}
/**