2022-09-21 08:32:50 +00:00
|
|
|
import { IStore } from '../../app/types';
|
2022-04-06 02:13:39 +00:00
|
|
|
import { CONFERENCE_JOIN_IN_PROGRESS } from '../conference/actionTypes';
|
2022-09-21 08:32:50 +00:00
|
|
|
import { IJitsiConference } from '../conference/reducer';
|
|
|
|
import { SET_CONFIG } from '../config/actionTypes';
|
2018-04-17 19:50:23 +00:00
|
|
|
import { JitsiConferenceEvents } from '../lib-jitsi-meet';
|
2022-09-21 08:32:50 +00:00
|
|
|
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
|
|
|
|
import { getJitsiMeetGlobalNS } from '../util/helpers';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2018-03-07 15:23:04 +00:00
|
|
|
import { setConnectionState } from './actions';
|
2020-12-08 14:01:16 +00:00
|
|
|
import {
|
|
|
|
getRemoteVideoType,
|
|
|
|
isLargeVideoReceived,
|
|
|
|
isRemoteVideoReceived,
|
|
|
|
isTestModeEnabled
|
|
|
|
} from './functions';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
2018-03-07 15:23:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux middleware of the feature testing.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
2022-04-06 02:13:39 +00:00
|
|
|
case CONFERENCE_JOIN_IN_PROGRESS:
|
2018-03-07 15:23:04 +00:00
|
|
|
_bindConferenceConnectionListener(action.conference, store);
|
|
|
|
break;
|
2020-12-08 14:01:16 +00:00
|
|
|
case SET_CONFIG: {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
_bindTortureHelpers(store);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-03-07 15:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds a handler which will listen for the connection related conference
|
|
|
|
* events (in the lib-jitsi-meet internals those are associated with the ICE
|
|
|
|
* connection state).
|
|
|
|
*
|
|
|
|
* @param {JitsiConference} conference - The {@link JitsiConference} for which
|
|
|
|
* the conference will join even is dispatched.
|
|
|
|
* @param {Store} store - The redux store in which the specified action is being
|
|
|
|
* dispatched.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
function _bindConferenceConnectionListener(conference: IJitsiConference, { dispatch }: IStore) {
|
2018-03-07 15:23:04 +00:00
|
|
|
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.CONNECTION_ESTABLISHED,
|
|
|
|
_onConnectionEvent.bind(
|
|
|
|
null, JitsiConferenceEvents.CONNECTION_ESTABLISHED, dispatch));
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.CONNECTION_RESTORED,
|
|
|
|
_onConnectionEvent.bind(
|
|
|
|
null, JitsiConferenceEvents.CONNECTION_RESTORED, dispatch));
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.CONNECTION_INTERRUPTED,
|
|
|
|
_onConnectionEvent.bind(
|
|
|
|
null, JitsiConferenceEvents.CONNECTION_INTERRUPTED, dispatch));
|
|
|
|
}
|
|
|
|
|
2020-12-08 14:01:16 +00:00
|
|
|
/**
|
|
|
|
* Binds all the helper functions needed by torture.
|
|
|
|
*
|
2022-09-21 08:32:50 +00:00
|
|
|
* @param {IStore} store - The redux store.
|
2020-12-08 14:01:16 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
function _bindTortureHelpers(store: IStore) {
|
2020-12-08 14:01:16 +00:00
|
|
|
const { getState } = store;
|
|
|
|
|
|
|
|
// We bind helpers only if testing mode is enabled
|
|
|
|
if (!isTestModeEnabled(getState())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All torture helper methods go in here
|
|
|
|
getJitsiMeetGlobalNS().testing = {
|
|
|
|
getRemoteVideoType: getRemoteVideoType.bind(null, store),
|
|
|
|
isLargeVideoReceived: isLargeVideoReceived.bind(null, store),
|
|
|
|
isRemoteVideoReceived: isRemoteVideoReceived.bind(null, store)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-07 15:23:04 +00:00
|
|
|
/**
|
2021-03-16 15:59:33 +00:00
|
|
|
* The handler function for conference connection events which will store the
|
2018-03-07 15:23:04 +00:00
|
|
|
* latest even name in the Redux store of feature testing.
|
|
|
|
*
|
|
|
|
* @param {string} event - One of the lib-jitsi-meet JitsiConferenceEvents.
|
|
|
|
* @param {Function} dispatch - The dispatch function of the current Redux
|
|
|
|
* store.
|
|
|
|
* @returns {void}
|
|
|
|
* @private
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
function _onConnectionEvent(event: string, dispatch: IStore['dispatch']) {
|
2018-03-07 15:23:04 +00:00
|
|
|
switch (event) {
|
|
|
|
case JitsiConferenceEvents.CONNECTION_ESTABLISHED:
|
|
|
|
case JitsiConferenceEvents.CONNECTION_INTERRUPTED:
|
|
|
|
case JitsiConferenceEvents.CONNECTION_RESTORED:
|
|
|
|
dispatch(setConnectionState(event));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
logger.error(`onConnectionEvent - unsupported event type: ${event}`);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|