2017-02-03 18:51:12 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-09-19 19:14:17 +00:00
|
|
|
import { assign, ReducerRegistry } from '../redux';
|
2017-07-21 21:12:02 +00:00
|
|
|
import { parseURIString } from '../util';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
CONNECTION_DISCONNECTED,
|
|
|
|
CONNECTION_ESTABLISHED,
|
2017-07-06 11:51:35 +00:00
|
|
|
CONNECTION_FAILED,
|
|
|
|
CONNECTION_WILL_CONNECT,
|
2017-05-09 05:15:43 +00:00
|
|
|
SET_LOCATION_URL
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
2016-12-05 15:14:50 +00:00
|
|
|
* Reduces the Redux actions of the feature base/connection.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-02-03 18:51:12 +00:00
|
|
|
ReducerRegistry.register(
|
|
|
|
'features/base/connection',
|
|
|
|
(state: Object = {}, action: Object) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case CONNECTION_DISCONNECTED:
|
|
|
|
return _connectionDisconnected(state, action);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-02-03 18:51:12 +00:00
|
|
|
case CONNECTION_ESTABLISHED:
|
|
|
|
return _connectionEstablished(state, action);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-07-06 11:51:35 +00:00
|
|
|
case CONNECTION_FAILED:
|
|
|
|
return _connectionFailed(state, action);
|
|
|
|
|
|
|
|
case CONNECTION_WILL_CONNECT:
|
|
|
|
return _connectionWillConnect(state, action);
|
|
|
|
|
2017-05-09 05:15:43 +00:00
|
|
|
case SET_LOCATION_URL:
|
|
|
|
return _setLocationURL(state, action);
|
2017-02-03 18:51:12 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-02-03 18:51:12 +00:00
|
|
|
return state;
|
|
|
|
});
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-05 15:14:50 +00:00
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action CONNECTION_DISCONNECTED of the feature
|
|
|
|
* base/connection.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/connection.
|
|
|
|
* @param {Action} action - The Redux action CONNECTION_DISCONNECTED to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2017-05-09 05:15:43 +00:00
|
|
|
function _connectionDisconnected(
|
|
|
|
state: Object,
|
|
|
|
{ connection }: { connection: Object }) {
|
2017-07-07 17:21:08 +00:00
|
|
|
if (state.connection !== connection) {
|
|
|
|
return state;
|
2016-12-05 15:14:50 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-07-07 17:21:08 +00:00
|
|
|
return assign(state, {
|
|
|
|
connecting: undefined,
|
|
|
|
connection: undefined
|
|
|
|
});
|
2016-12-05 15:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
|
|
|
|
* base/connection.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/connection.
|
|
|
|
* @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2017-05-09 05:15:43 +00:00
|
|
|
function _connectionEstablished(
|
|
|
|
state: Object,
|
|
|
|
{ connection }: { connection: Object }) {
|
2017-07-06 11:51:35 +00:00
|
|
|
return assign(state, {
|
|
|
|
connecting: undefined,
|
2017-09-19 19:14:17 +00:00
|
|
|
connection,
|
2017-09-24 21:51:43 +00:00
|
|
|
error: undefined
|
2017-07-06 11:51:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action CONNECTION_FAILED of the feature
|
|
|
|
* base/connection.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/connection.
|
|
|
|
* @param {Action} action - The Redux action CONNECTION_FAILED to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _connectionFailed(
|
|
|
|
state: Object,
|
2017-09-24 21:51:43 +00:00
|
|
|
{ connection, error }: {
|
2017-09-19 19:14:17 +00:00
|
|
|
connection: Object,
|
2017-09-24 21:51:43 +00:00
|
|
|
error: Object | string
|
2017-09-19 19:14:17 +00:00
|
|
|
}) {
|
2017-07-07 17:21:08 +00:00
|
|
|
if (state.connection && state.connection !== connection) {
|
|
|
|
return state;
|
|
|
|
}
|
2017-07-06 11:51:35 +00:00
|
|
|
|
2017-07-07 17:21:08 +00:00
|
|
|
return assign(state, {
|
|
|
|
connecting: undefined,
|
2017-09-19 19:14:17 +00:00
|
|
|
connection: undefined,
|
2017-09-24 21:51:43 +00:00
|
|
|
error
|
2017-07-07 17:21:08 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-06 11:51:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature
|
|
|
|
* base/connection.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/connection.
|
|
|
|
* @param {Action} action - The Redux action CONNECTION_WILL_CONNECT to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _connectionWillConnect(
|
|
|
|
state: Object,
|
|
|
|
{ connection }: { connection: Object }) {
|
2017-09-19 19:14:17 +00:00
|
|
|
return assign(state, {
|
|
|
|
connecting: connection,
|
2017-09-24 21:51:43 +00:00
|
|
|
error: undefined
|
2017-09-19 19:14:17 +00:00
|
|
|
});
|
2016-12-05 15:14:50 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
2017-05-09 05:15:43 +00:00
|
|
|
* Constructs options to be passed to the constructor of {@code JitsiConnection}
|
2017-07-21 21:12:02 +00:00
|
|
|
* based on a specific location URL.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-07-21 21:12:02 +00:00
|
|
|
* @param {string} locationURL - The location URL with which the returned
|
|
|
|
* options are to be constructed.
|
2017-01-28 18:11:24 +00:00
|
|
|
* @private
|
2017-07-21 21:12:02 +00:00
|
|
|
* @returns {Object} The options to be passed to the constructor of
|
|
|
|
* {@code JitsiConnection} based on the location URL.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-07-21 21:12:02 +00:00
|
|
|
function _constructOptions(locationURL: URL) {
|
|
|
|
const locationURI = parseURIString(locationURL.href);
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
// 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.
|
2017-07-21 21:12:02 +00:00
|
|
|
let { protocol } = locationURI;
|
|
|
|
const domain = locationURI.hostname;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-07-21 21:12:02 +00:00
|
|
|
if (!protocol && domain === 'beta.meet.jit.si') {
|
|
|
|
const windowLocation = window.location;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-07-21 21:12:02 +00:00
|
|
|
windowLocation && (protocol = windowLocation.protocol);
|
|
|
|
protocol || (protocol = 'http:');
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default to the HTTPS scheme for the BOSH URL.
|
2017-07-21 21:12:02 +00:00
|
|
|
protocol || (protocol = 'https:');
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
return {
|
2017-07-21 21:12:02 +00:00
|
|
|
bosh:
|
2017-10-02 23:08:07 +00:00
|
|
|
`${String(protocol)}//${domain}${
|
|
|
|
locationURI.contextRoot || '/'}http-bind`,
|
2016-10-05 14:36:59 +00:00
|
|
|
hosts: {
|
|
|
|
domain,
|
2017-02-23 23:12:50 +00:00
|
|
|
|
|
|
|
// Required by:
|
|
|
|
// - lib-jitsi-meet/modules/xmpp/xmpp.js
|
2016-10-05 14:36:59 +00:00
|
|
|
muc: `conference.${domain}`
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-12-05 15:14:50 +00:00
|
|
|
|
|
|
|
/**
|
2017-05-09 05:15:43 +00:00
|
|
|
* Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
|
|
|
|
* base/connection.
|
2016-12-05 15:14:50 +00:00
|
|
|
*
|
2017-05-09 05:15:43 +00:00
|
|
|
* @param {Object} state - The redux state of the feature base/connection.
|
|
|
|
* @param {Action} action - The redux action {@code SET_LOCATION_URL} to reduce.
|
2016-12-05 15:14:50 +00:00
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2017-05-09 05:15:43 +00:00
|
|
|
function _setLocationURL(
|
|
|
|
state: Object,
|
|
|
|
{ locationURL }: { locationURL: ?URL }) {
|
|
|
|
return assign(state, {
|
|
|
|
locationURL,
|
2017-07-21 21:12:02 +00:00
|
|
|
options: locationURL ? _constructOptions(locationURL) : undefined
|
2017-05-09 05:15:43 +00:00
|
|
|
});
|
2016-12-05 15:14:50 +00:00
|
|
|
}
|