2017-10-04 22:36:09 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import { appNavigate } from '../app/actions';
|
2017-09-18 07:09:43 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
CONFERENCE_JOINED,
|
|
|
|
CONFERENCE_LEFT
|
|
|
|
} from '../base/conference';
|
|
|
|
import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../base/connection';
|
|
|
|
import { hideDialog, isDialogOpen } from '../base/dialog';
|
|
|
|
import {
|
|
|
|
JitsiConferenceErrors,
|
|
|
|
JitsiConnectionErrors
|
|
|
|
} from '../base/lib-jitsi-meet';
|
2017-09-08 13:36:42 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2022-06-17 11:29:16 +00:00
|
|
|
import { setPrejoinPageVisibility } from '../prejoin';
|
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
|
|
|
openLoginDialog,
|
|
|
|
openWaitForOwnerDialog,
|
2017-09-18 07:09:43 +00:00
|
|
|
stopWaitForOwner,
|
2021-04-22 15:05:14 +00:00
|
|
|
waitForOwner } from './actions.native';
|
2017-09-18 07:09:43 +00:00
|
|
|
import { LoginDialog, WaitForOwnerDialog } from './components';
|
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
|
|
|
case CANCEL_LOGIN: {
|
2017-10-06 20:15:51 +00:00
|
|
|
const { dispatch, getState } = store;
|
|
|
|
const { thenableWithCancel } = getState()['features/authentication'];
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2017-09-24 23:41:20 +00:00
|
|
|
thenableWithCancel && thenableWithCancel.cancel();
|
2017-09-18 07:09:43 +00:00
|
|
|
|
|
|
|
// The LoginDialog can be opened on top of "wait for owner". The app
|
|
|
|
// should navigate only if LoginDialog was open without the
|
|
|
|
// WaitForOwnerDialog.
|
|
|
|
if (!isDialogOpen(store, WaitForOwnerDialog)) {
|
|
|
|
if (_isWaitingForOwner(store)) {
|
|
|
|
// Instead of hiding show the new one.
|
|
|
|
const result = next(action);
|
|
|
|
|
2021-04-22 15:05:14 +00:00
|
|
|
dispatch(openWaitForOwnerDialog());
|
2017-09-18 07:09:43 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go back to the app's entry point.
|
|
|
|
_hideLoginDialog(store);
|
2017-11-17 19:06:47 +00:00
|
|
|
|
2022-03-04 11:59:43 +00:00
|
|
|
const state = getState();
|
|
|
|
const { authRequired, conference } = state['features/base/conference'];
|
|
|
|
const { passwordRequired } = state['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-03-04 11:59:43 +00:00
|
|
|
// NOTE: Despite it's confusing name, `passwordRequired` implies an XMPP
|
|
|
|
// connection auth error.
|
|
|
|
if ((passwordRequired || authRequired) && !conference) {
|
2022-01-28 14:14:54 +00:00
|
|
|
dispatch(appNavigate(undefined));
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
// XXX The feature authentication affords recovery from
|
|
|
|
// CONFERENCE_FAILED caused by
|
|
|
|
// JitsiConferenceErrors.AUTHENTICATION_REQUIRED.
|
|
|
|
let recoverable;
|
|
|
|
|
|
|
|
if (error.name === JitsiConferenceErrors.AUTHENTICATION_REQUIRED) {
|
|
|
|
if (typeof error.recoverable === 'undefined') {
|
|
|
|
error.recoverable = true;
|
|
|
|
}
|
|
|
|
recoverable = error.recoverable;
|
|
|
|
}
|
|
|
|
if (recoverable) {
|
2017-09-08 13:36:42 +00:00
|
|
|
store.dispatch(waitForOwner());
|
|
|
|
} 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:
|
|
|
|
if (_isWaitingForOwner(store)) {
|
|
|
|
store.dispatch(stopWaitForOwner());
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
2017-09-18 07:09:43 +00:00
|
|
|
_hideLoginDialog(store);
|
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:
|
|
|
|
_hideLoginDialog(store);
|
2017-09-08 13:36:42 +00:00
|
|
|
break;
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2017-09-24 21:51:43 +00:00
|
|
|
case CONNECTION_FAILED: {
|
|
|
|
const { error } = action;
|
|
|
|
|
2018-05-01 19:58:46 +00:00
|
|
|
if (error
|
|
|
|
&& error.name === JitsiConnectionErrors.PASSWORD_REQUIRED
|
|
|
|
&& typeof error.recoverable === 'undefined') {
|
|
|
|
error.recoverable = true;
|
2022-06-17 11:29:16 +00:00
|
|
|
store.dispatch(setPrejoinPageVisibility(false));
|
2021-04-22 15:05:14 +00:00
|
|
|
store.dispatch(openLoginDialog());
|
2018-05-01 19:58:46 +00:00
|
|
|
}
|
2017-09-08 13:36:42 +00:00
|
|
|
break;
|
2017-09-24 21:51:43 +00:00
|
|
|
}
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
case STOP_WAIT_FOR_OWNER:
|
|
|
|
_clearExistingWaitForOwnerTimeout(store);
|
|
|
|
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) {
|
|
|
|
_hideLoginDialog(store);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
case WAIT_FOR_OWNER: {
|
|
|
|
_clearExistingWaitForOwnerTimeout(store);
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
const { handler, timeoutMs } = 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
|
|
|
// The WAIT_FOR_OWNER action is cyclic and we don't want to hide the
|
2017-09-24 23:41:20 +00:00
|
|
|
// login dialog every few seconds.
|
2017-09-18 07:09:43 +00:00
|
|
|
isDialogOpen(store, LoginDialog)
|
2021-04-22 15:05:14 +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}
|
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
function _clearExistingWaitForOwnerTimeout(
|
|
|
|
{ getState }: { getState: Function }) {
|
2017-09-18 07:09:43 +00:00
|
|
|
const { waitForOwnerTimeoutID } = getState()['features/authentication'];
|
|
|
|
|
|
|
|
waitForOwnerTimeoutID && clearTimeout(waitForOwnerTimeoutID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides {@link LoginDialog} if it's currently displayed.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
function _hideLoginDialog({ dispatch }: { dispatch: Dispatch<any> }) {
|
2017-09-18 07:09:43 +00:00
|
|
|
dispatch(hideDialog(LoginDialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the cyclic "wait for conference owner" task is currently scheduled.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The redux store.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
function _isWaitingForOwner({ getState }: { getState: Function }) {
|
2017-09-18 07:09:43 +00:00
|
|
|
return Boolean(getState()['features/authentication'].waitForOwnerTimeoutID);
|
|
|
|
}
|