2017-02-03 18:51:12 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-11-24 15:23:40 +00:00
|
|
|
import { SET_ROOM } from '../conference';
|
2018-05-01 19:58:46 +00:00
|
|
|
import { JitsiConnectionErrors } from '../lib-jitsi-meet';
|
2018-08-17 04:03:15 +00:00
|
|
|
import { assign, set, ReducerRegistry } from '../redux';
|
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';
|
2018-05-02 18:27:50 +00:00
|
|
|
import type { ConnectionFailedError } from './actions.native';
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
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-11-24 15:23:40 +00:00
|
|
|
|
|
|
|
case SET_ROOM:
|
|
|
|
return _setRoom(state);
|
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 }) {
|
2018-06-06 14:31:08 +00:00
|
|
|
const connection_ = _getCurrentConnection(state);
|
|
|
|
|
|
|
|
if (connection_ !== connection) {
|
2017-07-07 17:21:08 +00:00
|
|
|
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,
|
2018-07-02 21:22:51 +00:00
|
|
|
connection: undefined,
|
|
|
|
timeEstablished: undefined
|
2017-07-07 17:21:08 +00:00
|
|
|
});
|
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,
|
2018-07-02 21:22:51 +00:00
|
|
|
{ connection, timeEstablished }: {
|
|
|
|
connection: Object,
|
|
|
|
timeEstablished: number
|
|
|
|
}) {
|
2017-07-06 11:51:35 +00:00
|
|
|
return assign(state, {
|
|
|
|
connecting: undefined,
|
2017-09-19 19:14:17 +00:00
|
|
|
connection,
|
2018-05-01 19:58:46 +00:00
|
|
|
error: undefined,
|
2018-07-02 21:22:51 +00:00
|
|
|
passwordRequired: undefined,
|
|
|
|
timeEstablished
|
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,
|
2018-05-02 18:27:50 +00:00
|
|
|
error: ConnectionFailedError
|
2017-09-19 19:14:17 +00:00
|
|
|
}) {
|
2018-06-06 14:31:08 +00:00
|
|
|
const connection_ = _getCurrentConnection(state);
|
2017-11-28 14:03:38 +00:00
|
|
|
|
|
|
|
if (connection_ && connection_ !== connection) {
|
2017-07-07 17:21:08 +00:00
|
|
|
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,
|
2018-05-01 19:58:46 +00:00
|
|
|
error,
|
|
|
|
passwordRequired:
|
|
|
|
error.name === JitsiConnectionErrors.PASSWORD_REQUIRED
|
|
|
|
? connection : undefined
|
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,
|
2018-06-06 14:31:08 +00:00
|
|
|
|
|
|
|
// We don't care if the previous connection has been closed already,
|
|
|
|
// because it's an async process and there's no guarantee if it'll be
|
|
|
|
// done before the new one is established.
|
|
|
|
connection: undefined,
|
2018-05-01 19:58:46 +00:00
|
|
|
error: undefined,
|
2018-07-02 21:22:51 +00:00
|
|
|
passwordRequired: undefined,
|
|
|
|
timeEstablished: 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
|
|
|
|
2018-06-06 14:31:08 +00:00
|
|
|
/**
|
|
|
|
* The current (similar to getCurrentConference in base/conference/functions.js)
|
|
|
|
* connection which is {@code connection} or {@code connecting}.
|
|
|
|
*
|
|
|
|
* @param {Object} baseConnectionState - The current state of the
|
|
|
|
* {@code 'base/connection'} feature.
|
|
|
|
* @returns {JitsiConnection} - The current {@code JitsiConnection} if any.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function _getCurrentConnection(baseConnectionState: Object): ?Object {
|
|
|
|
return baseConnectionState.connection || baseConnectionState.connecting;
|
|
|
|
}
|
|
|
|
|
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 }) {
|
2018-08-17 04:03:15 +00:00
|
|
|
return set(state, 'locationURL', locationURL);
|
2016-12-05 15:14:50 +00:00
|
|
|
}
|
2017-11-24 15:23:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific redux action {@link SET_ROOM} of the feature
|
|
|
|
* base/connection.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state of the feature base/connection.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
|
|
|
function _setRoom(state: Object) {
|
2018-05-01 19:58:46 +00:00
|
|
|
return assign(state, {
|
|
|
|
error: undefined,
|
|
|
|
passwordRequired: undefined
|
|
|
|
});
|
2017-11-24 15:23:40 +00:00
|
|
|
}
|