2022-07-12 11:41:26 +00:00
|
|
|
import { SET_ROOM } from '../conference/actionTypes';
|
2018-05-01 19:58:46 +00:00
|
|
|
import { JitsiConnectionErrors } from '../lib-jitsi-meet';
|
2022-07-12 11:41:26 +00:00
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
2022-09-05 09:05:07 +00:00
|
|
|
import { assign, set } from '../redux/functions';
|
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,
|
2021-06-30 16:12:12 +00:00
|
|
|
SET_LOCATION_URL,
|
|
|
|
SHOW_CONNECTION_INFO
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './actionTypes';
|
2022-07-12 11:41:26 +00:00
|
|
|
import { ConnectionFailedError } from './actions.native';
|
|
|
|
|
|
|
|
export interface IConnectionState {
|
2022-10-11 10:47:54 +00:00
|
|
|
connecting?: any;
|
2022-09-05 11:24:13 +00:00
|
|
|
connection?: {
|
2022-10-11 10:47:54 +00:00
|
|
|
disconnect: Function;
|
2022-09-05 11:24:13 +00:00
|
|
|
getJid: () => string;
|
2022-09-27 07:42:30 +00:00
|
|
|
getLogs: () => Object;
|
2022-10-17 11:28:01 +00:00
|
|
|
initJitsiConference: Function;
|
2022-09-05 11:24:13 +00:00
|
|
|
};
|
2022-07-12 11:41:26 +00:00
|
|
|
error?: ConnectionFailedError;
|
|
|
|
locationURL?: URL;
|
2022-07-20 08:47:01 +00:00
|
|
|
passwordRequired?: Object;
|
2022-07-12 11:41:26 +00:00
|
|
|
showConnectionInfo?: boolean;
|
2022-07-20 08:47:01 +00:00
|
|
|
timeEstablished?: number;
|
2022-07-12 11:41:26 +00:00
|
|
|
}
|
2018-05-02 18:27:50 +00:00
|
|
|
|
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
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IConnectionState>(
|
2017-02-03 18:51:12 +00:00
|
|
|
'features/base/connection',
|
2022-09-05 09:05:07 +00:00
|
|
|
(state = {}, action): IConnectionState => {
|
2017-02-03 18:51:12 +00:00
|
|
|
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);
|
2021-06-30 16:12:12 +00:00
|
|
|
|
|
|
|
case SHOW_CONNECTION_INFO:
|
|
|
|
return _setShowConnectionInfo(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.
|
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} state - The Redux state of the feature base/connection.
|
2016-12-05 15:14:50 +00:00
|
|
|
* @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(
|
2022-07-12 11:41:26 +00:00
|
|
|
state: IConnectionState,
|
2022-09-08 09:52:36 +00:00
|
|
|
{ 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.
|
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} state - The Redux state of the feature base/connection.
|
2016-12-05 15:14:50 +00:00
|
|
|
* @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(
|
2022-07-12 11:41:26 +00:00
|
|
|
state: IConnectionState,
|
2018-07-02 21:22:51 +00:00
|
|
|
{ connection, timeEstablished }: {
|
2022-09-08 09:52:36 +00:00
|
|
|
connection: any;
|
|
|
|
timeEstablished: number;
|
2018-07-02 21:22:51 +00:00
|
|
|
}) {
|
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.
|
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} state - The Redux state of the feature base/connection.
|
2017-07-06 11:51:35 +00:00
|
|
|
* @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(
|
2022-07-12 11:41:26 +00:00
|
|
|
state: IConnectionState,
|
2017-09-24 21:51:43 +00:00
|
|
|
{ connection, error }: {
|
2022-09-08 09:52:36 +00:00
|
|
|
connection: Object;
|
|
|
|
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.
|
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} state - The Redux state of the feature base/connection.
|
2017-07-06 11:51:35 +00:00
|
|
|
* @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(
|
2022-07-12 11:41:26 +00:00
|
|
|
state: IConnectionState,
|
2022-09-08 09:52:36 +00:00
|
|
|
{ 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
|
|
|
/**
|
2022-03-17 14:13:58 +00:00
|
|
|
* The current (similar to getCurrentConference in base/conference/functions.any.js)
|
2018-06-06 14:31:08 +00:00
|
|
|
* connection which is {@code connection} or {@code connecting}.
|
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} baseConnectionState - The current state of the
|
2018-06-06 14:31:08 +00:00
|
|
|
* {@code 'base/connection'} feature.
|
|
|
|
* @returns {JitsiConnection} - The current {@code JitsiConnection} if any.
|
|
|
|
* @private
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
function _getCurrentConnection(baseConnectionState: IConnectionState): IConnectionState | undefined {
|
2018-06-06 14:31:08 +00:00
|
|
|
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
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} state - The redux state of the feature base/connection.
|
2017-05-09 05:15:43 +00:00
|
|
|
* @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(
|
2022-07-12 11:41:26 +00:00
|
|
|
state: IConnectionState,
|
2022-09-08 09:52:36 +00:00
|
|
|
{ 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.
|
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} state - The redux state of the feature base/connection.
|
2017-11-24 15:23:40 +00:00
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2022-07-12 11:41:26 +00:00
|
|
|
function _setRoom(state: IConnectionState) {
|
2018-05-01 19:58:46 +00:00
|
|
|
return assign(state, {
|
|
|
|
error: undefined,
|
|
|
|
passwordRequired: undefined
|
|
|
|
});
|
2017-11-24 15:23:40 +00:00
|
|
|
}
|
2021-06-30 16:12:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific redux action {@link SHOW_CONNECTION_INFO} of the feature
|
|
|
|
* base/connection.
|
|
|
|
*
|
2022-07-12 11:41:26 +00:00
|
|
|
* @param {IConnectionState} state - The redux state of the feature base/connection.
|
2021-06-30 16:12:12 +00:00
|
|
|
* @param {Action} action - The redux action {@code SHOW_CONNECTION_INFO} to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/connection after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
|
|
|
function _setShowConnectionInfo(
|
2022-07-12 11:41:26 +00:00
|
|
|
state: IConnectionState,
|
2022-09-08 09:52:36 +00:00
|
|
|
{ showConnectionInfo }: { showConnectionInfo: boolean; }) {
|
2021-06-30 16:12:12 +00:00
|
|
|
return set(state, 'showConnectionInfo', showConnectionInfo);
|
|
|
|
}
|