[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.
This commit is contained in:
Saúl Ibarra Corretgé 2018-08-17 06:03:15 +02:00 committed by Любомир Маринов
parent 99d285519d
commit a896d8f076
2 changed files with 25 additions and 69 deletions

View File

@ -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,
// Deep clone the options to make sure we don't modify the object in the
// redux store.
const options = _.cloneDeep(state['features/base/config']);
// Lib-jitsi-meet wants the config passed in multiple places and here is
// the latest one I have discovered.
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;
}

View File

@ -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);
}
/**