2022-11-10 08:45:56 +00:00
|
|
|
import { maybeRedirectToWelcomePage } from '../app/actions.web';
|
|
|
|
import { IStore } from '../app/types';
|
2017-09-18 07:09:43 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
CONFERENCE_JOINED,
|
|
|
|
CONFERENCE_LEFT
|
2022-11-10 08:45:56 +00:00
|
|
|
} from '../base/conference/actionTypes';
|
|
|
|
import { CONNECTION_ESTABLISHED } from '../base/connection/actionTypes';
|
|
|
|
import { hideDialog } from '../base/dialog/actions';
|
|
|
|
import { isDialogOpen } from '../base/dialog/functions';
|
2017-09-18 07:09:43 +00:00
|
|
|
import {
|
2021-03-24 14:09:40 +00:00
|
|
|
JitsiConferenceErrors
|
2017-09-18 07:09:43 +00:00
|
|
|
} from '../base/lib-jitsi-meet';
|
2022-11-10 08:45:56 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import {
|
|
|
|
CANCEL_LOGIN,
|
|
|
|
STOP_WAIT_FOR_OWNER,
|
2022-01-28 14:14:54 +00:00
|
|
|
UPGRADE_ROLE_FINISHED,
|
2020-05-20 10:57:03 +00:00
|
|
|
WAIT_FOR_OWNER
|
|
|
|
} from './actionTypes';
|
2017-09-08 13:36:42 +00:00
|
|
|
import {
|
2021-04-22 15:05:14 +00:00
|
|
|
hideLoginDialog,
|
|
|
|
openWaitForOwnerDialog,
|
2022-04-06 02:13:39 +00:00
|
|
|
stopWaitForOwner
|
2021-03-24 14:09:40 +00:00
|
|
|
} from './actions.web';
|
2023-02-02 11:12:31 +00:00
|
|
|
import LoginDialog from './components/web/LoginDialog';
|
|
|
|
import WaitForOwnerDialog from './components/web/WaitForOwnerDialog';
|
2017-09-08 13:36:42 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Middleware that captures connection or conference failed errors and controls
|
2017-09-08 13:36:42 +00:00
|
|
|
* {@link WaitForOwnerDialog} and {@link LoginDialog}.
|
|
|
|
*
|
|
|
|
* FIXME Some of the complexity was introduced by the lack of dialog stacking.
|
|
|
|
*
|
|
|
|
* @param {Store} store - Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2021-03-24 14:09:40 +00:00
|
|
|
case CANCEL_LOGIN: {
|
2022-01-28 14:14:54 +00:00
|
|
|
const { dispatch, getState } = store;
|
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
if (!isDialogOpen(store, WaitForOwnerDialog)) {
|
2021-04-22 15:05:14 +00:00
|
|
|
if (_isWaitingForOwner(store)) {
|
2022-01-28 14:14:54 +00:00
|
|
|
dispatch(openWaitForOwnerDialog());
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2021-03-24 14:09:40 +00:00
|
|
|
return next(action);
|
2017-09-18 07:09:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 14:14:54 +00:00
|
|
|
dispatch(hideLoginDialog());
|
|
|
|
|
|
|
|
const { authRequired, conference } = getState()['features/base/conference'];
|
2022-06-17 11:30:31 +00:00
|
|
|
const { passwordRequired } = getState()['features/base/connection'];
|
2017-11-17 19:06:47 +00:00
|
|
|
|
2022-01-28 14:14:54 +00:00
|
|
|
// Only end the meeting if we are not already inside and trying to upgrade.
|
2022-06-17 11:30:31 +00:00
|
|
|
if ((authRequired && !conference) || passwordRequired) {
|
2022-01-28 14:14:54 +00:00
|
|
|
dispatch(maybeRedirectToWelcomePage());
|
|
|
|
}
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2017-10-19 18:25:44 +00:00
|
|
|
case CONFERENCE_FAILED: {
|
|
|
|
const { error } = action;
|
|
|
|
let recoverable;
|
|
|
|
|
|
|
|
if (error.name === JitsiConferenceErrors.AUTHENTICATION_REQUIRED) {
|
|
|
|
if (typeof error.recoverable === 'undefined') {
|
|
|
|
error.recoverable = true;
|
|
|
|
}
|
|
|
|
recoverable = error.recoverable;
|
|
|
|
}
|
|
|
|
if (recoverable) {
|
2022-04-06 02:13:39 +00:00
|
|
|
// we haven't migrated all the code from AuthHandler, and we need for now conference.js to trigger
|
|
|
|
// the dialog to pass all required parameters to WaitForOwnerDialog
|
|
|
|
// keep it commented, so we do not trigger sending iqs to jicofo twice
|
|
|
|
// and showing the broken dialog with no handler
|
|
|
|
// store.dispatch(waitForOwner());
|
2017-09-08 13:36:42 +00:00
|
|
|
} else {
|
2017-09-18 07:09:43 +00:00
|
|
|
store.dispatch(stopWaitForOwner());
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-10-19 18:25:44 +00:00
|
|
|
}
|
2017-09-18 07:09:43 +00:00
|
|
|
|
|
|
|
case CONFERENCE_JOINED:
|
2022-04-29 11:22:18 +00:00
|
|
|
store.dispatch(stopWaitForOwner());
|
2021-04-22 15:05:14 +00:00
|
|
|
store.dispatch(hideLoginDialog());
|
2017-09-08 13:36:42 +00:00
|
|
|
break;
|
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
case CONFERENCE_LEFT:
|
|
|
|
store.dispatch(stopWaitForOwner());
|
|
|
|
break;
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
case CONNECTION_ESTABLISHED:
|
2021-04-22 15:05:14 +00:00
|
|
|
store.dispatch(hideLoginDialog());
|
2017-09-08 13:36:42 +00:00
|
|
|
break;
|
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
case STOP_WAIT_FOR_OWNER:
|
2021-04-22 15:05:14 +00:00
|
|
|
_clearExistingWaitForOwnerTimeout(store);
|
2017-09-18 07:09:43 +00:00
|
|
|
store.dispatch(hideDialog(WaitForOwnerDialog));
|
|
|
|
break;
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2022-01-28 14:14:54 +00:00
|
|
|
case UPGRADE_ROLE_FINISHED: {
|
|
|
|
const { error, progress } = action;
|
|
|
|
|
|
|
|
if (!error && progress === 1) {
|
|
|
|
store.dispatch(hideLoginDialog());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
case WAIT_FOR_OWNER: {
|
2021-04-22 15:05:14 +00:00
|
|
|
_clearExistingWaitForOwnerTimeout(store);
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2022-11-10 08:45:56 +00:00
|
|
|
const { handler, timeoutMs }: { handler: () => void; timeoutMs: number; } = action;
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
action.waitForOwnerTimeoutID = setTimeout(handler, timeoutMs);
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
isDialogOpen(store, LoginDialog)
|
2021-03-24 14:09:40 +00:00
|
|
|
|| store.dispatch(openWaitForOwnerDialog());
|
2017-09-08 13:36:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
2017-09-18 07:09:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Will clear the wait for conference owner timeout handler if any is currently
|
|
|
|
* set.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-04-22 15:05:14 +00:00
|
|
|
function _clearExistingWaitForOwnerTimeout(
|
2022-11-10 08:45:56 +00:00
|
|
|
{ getState }: IStore) {
|
2017-09-18 07:09:43 +00:00
|
|
|
const { waitForOwnerTimeoutID } = getState()['features/authentication'];
|
|
|
|
|
|
|
|
waitForOwnerTimeoutID && clearTimeout(waitForOwnerTimeoutID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the cyclic "wait for conference owner" task is currently scheduled.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The redux store.
|
2021-03-24 14:09:40 +00:00
|
|
|
* @returns {void}
|
2017-09-18 07:09:43 +00:00
|
|
|
*/
|
2022-11-10 08:45:56 +00:00
|
|
|
function _isWaitingForOwner({ getState }: IStore) {
|
2021-03-24 14:09:40 +00:00
|
|
|
return getState()['features/authentication'].waitForOwnerTimeoutID;
|
2017-09-18 07:09:43 +00:00
|
|
|
}
|