2022-03-22 09:34:14 +00:00
|
|
|
import debounce from 'lodash/debounce';
|
|
|
|
|
2022-04-26 10:15:31 +00:00
|
|
|
import { CONFERENCE_FAILED, SET_ROOM } from '../../base/conference/actionTypes';
|
|
|
|
import { JitsiConferenceErrors } from '../../base/lib-jitsi-meet';
|
2022-01-25 12:55:57 +00:00
|
|
|
import { MiddlewareRegistry } from '../../base/redux';
|
2022-03-22 09:34:14 +00:00
|
|
|
import { readyToClose } from '../external-api/actions';
|
|
|
|
|
2022-01-25 12:55:57 +00:00
|
|
|
|
2022-03-17 14:13:58 +00:00
|
|
|
import { isWelcomePageAppEnabled } from './components/welcome/functions';
|
2022-01-25 12:55:57 +00:00
|
|
|
import { navigateRoot } from './rootNavigationContainerRef';
|
|
|
|
import { screen } from './routes';
|
|
|
|
|
|
|
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case SET_ROOM:
|
|
|
|
return _setRoom(store, next, action);
|
2022-04-26 10:15:31 +00:00
|
|
|
|
|
|
|
case CONFERENCE_FAILED:
|
|
|
|
return _conferenceFailed(store, next, action);
|
2022-01-25 12:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
2022-03-22 09:34:14 +00:00
|
|
|
/**
|
|
|
|
* Debounced sending of `readyToClose`.
|
|
|
|
*/
|
|
|
|
const _sendReadyToClose = debounce(dispatch => {
|
|
|
|
dispatch(readyToClose());
|
|
|
|
}, 2500, { leading: true });
|
2022-01-25 12:55:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the feature base/conference that the action
|
|
|
|
* {@code SET_ROOM} is being dispatched within a specific
|
|
|
|
* redux store.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} to the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action {@code SET_ROOM}
|
|
|
|
* which is being dispatched in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The value returned by {@code next(action)}.
|
|
|
|
*/
|
2022-03-22 09:34:14 +00:00
|
|
|
function _setRoom({ dispatch, getState }, next, action) {
|
|
|
|
const { room: oldRoom } = getState()['features/base/conference'];
|
2022-01-25 12:55:57 +00:00
|
|
|
const result = next(action);
|
2022-03-22 09:34:14 +00:00
|
|
|
const { room: newRoom } = getState()['features/base/conference'];
|
|
|
|
const isWelcomePageEnabled = isWelcomePageAppEnabled(getState());
|
2022-01-25 12:55:57 +00:00
|
|
|
|
|
|
|
if (!oldRoom && newRoom) {
|
|
|
|
navigateRoot(screen.conference.root);
|
2022-01-25 15:08:53 +00:00
|
|
|
} else if (!newRoom) {
|
2022-03-17 14:13:58 +00:00
|
|
|
if (isWelcomePageEnabled) {
|
|
|
|
navigateRoot(screen.root);
|
|
|
|
} else {
|
|
|
|
// For JitsiSDK, WelcomePage is not available
|
2022-03-22 09:34:14 +00:00
|
|
|
_sendReadyToClose(dispatch);
|
2022-03-17 14:13:58 +00:00
|
|
|
}
|
2022-01-25 12:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2022-04-26 10:15:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to handle the conference failed event and navigate the user to the lobby screen
|
|
|
|
* based on the failure reason.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The Redux store.
|
|
|
|
* @param {Function} next - The Redux next function.
|
|
|
|
* @param {Object} action - The Redux action.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function _conferenceFailed({ dispatch, getState }, next, action) {
|
|
|
|
const state = getState();
|
|
|
|
const isWelcomePageEnabled = isWelcomePageAppEnabled(state);
|
|
|
|
const { error } = action;
|
|
|
|
|
|
|
|
// We need to cover the case where knocking participant
|
|
|
|
// is rejected from entering the conference
|
|
|
|
if (error.name === JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED) {
|
|
|
|
if (isWelcomePageEnabled) {
|
|
|
|
navigateRoot(screen.root);
|
|
|
|
} else {
|
|
|
|
// For JitsiSDK, WelcomePage is not available
|
|
|
|
_sendReadyToClose(dispatch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|