2017-10-06 20:15:51 +00:00
|
|
|
// @flow
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2017-10-06 20:15:51 +00:00
|
|
|
import { appNavigate } from '../app';
|
2017-10-20 17:53:10 +00:00
|
|
|
import { checkIfCanJoin, conferenceLeft } from '../base/conference';
|
2018-05-01 19:58:46 +00:00
|
|
|
import { connectionFailed } from '../base/connection';
|
2017-09-18 07:09:43 +00:00
|
|
|
import { openDialog } from '../base/dialog';
|
2018-05-02 18:27:50 +00:00
|
|
|
import { set } from '../base/redux';
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
import {
|
|
|
|
CANCEL_LOGIN,
|
|
|
|
STOP_WAIT_FOR_OWNER,
|
2017-09-18 07:09:43 +00:00
|
|
|
UPGRADE_ROLE_FINISHED,
|
2017-09-08 13:36:42 +00:00
|
|
|
UPGRADE_ROLE_STARTED,
|
|
|
|
WAIT_FOR_OWNER
|
|
|
|
} from './actionTypes';
|
|
|
|
import { LoginDialog, WaitForOwnerDialog } from './components';
|
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Initiates authenticating and upgrading the role of the local participant to
|
|
|
|
* moderator which will allow to create and join a new conference on an XMPP
|
|
|
|
* password + guest access configuration. Refer to {@link LoginDialog} for more
|
|
|
|
* info.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
2018-11-08 12:25:02 +00:00
|
|
|
* @param {string} id - The XMPP user's ID (e.g. {@code user@domain.com}).
|
2017-09-18 07:09:43 +00:00
|
|
|
* @param {string} password - The XMPP user's password.
|
|
|
|
* @param {JitsiConference} conference - The conference for which the local
|
|
|
|
* participant's role will be upgraded.
|
2017-10-06 20:15:51 +00:00
|
|
|
* @returns {Function}
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
2017-09-18 07:09:43 +00:00
|
|
|
export function authenticateAndUpgradeRole(
|
|
|
|
id: string,
|
|
|
|
password: string,
|
|
|
|
conference: Object) {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2017-09-08 13:36:42 +00:00
|
|
|
const { password: roomPassword }
|
|
|
|
= getState()['features/base/conference'];
|
2017-09-18 07:09:43 +00:00
|
|
|
const process
|
|
|
|
= conference.authenticateAndUpgradeRole({
|
|
|
|
id,
|
|
|
|
password,
|
2017-09-22 19:06:16 +00:00
|
|
|
roomPassword,
|
|
|
|
|
|
|
|
onLoginSuccessful() {
|
2017-09-24 23:41:20 +00:00
|
|
|
// When the login succeeds, the process has completed half
|
|
|
|
// of its job (i.e. 0.5).
|
|
|
|
return dispatch(_upgradeRoleFinished(process, 0.5));
|
2017-09-22 19:06:16 +00:00
|
|
|
}
|
2017-09-18 07:09:43 +00:00
|
|
|
});
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
dispatch(_upgradeRoleStarted(process));
|
|
|
|
process.then(
|
2017-09-24 23:41:20 +00:00
|
|
|
/* onFulfilled */ () => dispatch(_upgradeRoleFinished(process, 1)),
|
2017-09-18 07:09:43 +00:00
|
|
|
/* onRejected */ error => {
|
|
|
|
// The lack of an error signals a cancellation.
|
|
|
|
if (error.authenticationError || error.connectionError) {
|
|
|
|
logger.error('authenticateAndUpgradeRole failed', error);
|
|
|
|
}
|
|
|
|
|
2017-09-24 23:41:20 +00:00
|
|
|
dispatch(_upgradeRoleFinished(process, error));
|
2017-09-18 07:09:43 +00:00
|
|
|
});
|
2017-09-22 20:15:06 +00:00
|
|
|
|
|
|
|
return process;
|
2017-09-08 13:36:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels {@ink LoginDialog}.
|
|
|
|
*
|
|
|
|
* @returns {{
|
2017-09-18 07:09:43 +00:00
|
|
|
* type: CANCEL_LOGIN
|
2017-09-08 13:36:42 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function cancelLogin() {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2018-05-01 19:58:46 +00:00
|
|
|
dispatch({ type: CANCEL_LOGIN });
|
|
|
|
|
|
|
|
// XXX The error associated with CONNECTION_FAILED was marked as
|
|
|
|
// recoverable by the authentication feature and, consequently,
|
|
|
|
// recoverable-aware features such as mobile's external-api did not
|
|
|
|
// deliver the CONFERENCE_FAILED to the SDK clients/consumers (as
|
|
|
|
// a reaction to CONNECTION_FAILED). Since the
|
|
|
|
// app/user is going to navigate to WelcomePage, the SDK
|
|
|
|
// clients/consumers need an event.
|
|
|
|
const { error, passwordRequired }
|
|
|
|
= getState()['features/base/connection'];
|
2017-11-17 19:06:47 +00:00
|
|
|
|
2018-05-01 19:58:46 +00:00
|
|
|
passwordRequired
|
|
|
|
&& dispatch(
|
|
|
|
connectionFailed(
|
|
|
|
passwordRequired,
|
2018-05-02 18:27:50 +00:00
|
|
|
set(error, 'recoverable', false)));
|
2017-09-08 13:36:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels {@link WaitForOwnerDialog}. Will navigate back to the welcome page.
|
|
|
|
*
|
2017-10-06 20:15:51 +00:00
|
|
|
* @returns {Function}
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
|
|
|
export function cancelWaitForOwner() {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2017-10-06 20:15:51 +00:00
|
|
|
dispatch(stopWaitForOwner());
|
2017-10-24 18:58:08 +00:00
|
|
|
|
|
|
|
// XXX The error associated with CONFERENCE_FAILED was marked as
|
|
|
|
// recoverable by the feature room-lock and, consequently,
|
|
|
|
// recoverable-aware features such as mobile's external-api did not
|
|
|
|
// deliver the CONFERENCE_FAILED to the SDK clients/consumers. Since the
|
|
|
|
// app/user is going to nativate to WelcomePage, the SDK
|
|
|
|
// clients/consumers need an event.
|
2017-10-20 17:53:10 +00:00
|
|
|
const { authRequired } = getState()['features/base/conference'];
|
|
|
|
|
2017-10-24 18:58:08 +00:00
|
|
|
authRequired && dispatch(conferenceLeft(authRequired));
|
2017-10-20 17:53:10 +00:00
|
|
|
|
2017-10-06 20:15:51 +00:00
|
|
|
dispatch(appNavigate(undefined));
|
2017-09-08 13:36:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Opens {@link LoginDialog} which will ask to enter username and password
|
2017-09-08 13:36:42 +00:00
|
|
|
* for the current conference.
|
|
|
|
*
|
|
|
|
* @protected
|
2017-09-18 07:09:43 +00:00
|
|
|
* @returns {Action}
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
2017-09-18 07:09:43 +00:00
|
|
|
export function _openLoginDialog() {
|
|
|
|
return openDialog(LoginDialog);
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Opens {@link WaitForOnwerDialog}.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2017-09-18 07:09:43 +00:00
|
|
|
* @returns {Action}
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
2017-09-18 07:09:43 +00:00
|
|
|
export function _openWaitForOwnerDialog() {
|
|
|
|
return openDialog(WaitForOwnerDialog);
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Stops waiting for the conference owner.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
|
|
|
* @returns {{
|
2017-09-18 07:09:43 +00:00
|
|
|
* type: STOP_WAIT_FOR_OWNER
|
2017-09-08 13:36:42 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2017-09-18 07:09:43 +00:00
|
|
|
export function stopWaitForOwner() {
|
2017-09-08 13:36:42 +00:00
|
|
|
return {
|
2017-09-18 07:09:43 +00:00
|
|
|
type: STOP_WAIT_FOR_OWNER
|
2017-09-08 13:36:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Signals that the process of authenticating and upgrading the local
|
|
|
|
* participant's role has finished either with success or with a specific error.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
2017-09-24 23:41:20 +00:00
|
|
|
* @param {Object} thenableWithCancel - The process of authenticating and
|
|
|
|
* upgrading the local participant's role.
|
2017-10-01 06:35:19 +00:00
|
|
|
* @param {Object} progressOrError - If the value is a {@code number}, then the
|
2017-09-24 23:41:20 +00:00
|
|
|
* process of authenticating and upgrading the local participant's role has
|
|
|
|
* succeeded in one of its two/multiple steps; otherwise, it has failed with the
|
|
|
|
* specified error. Refer to {@link JitsiConference#authenticateAndUpgradeRole}
|
|
|
|
* in lib-jitsi-meet for the error details.
|
2017-09-08 13:36:42 +00:00
|
|
|
* @private
|
|
|
|
* @returns {{
|
2017-09-18 07:09:43 +00:00
|
|
|
* type: UPGRADE_ROLE_FINISHED,
|
2017-09-24 23:41:20 +00:00
|
|
|
* error: ?Object,
|
|
|
|
* progress: number
|
2017-09-08 13:36:42 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2017-09-24 23:41:20 +00:00
|
|
|
function _upgradeRoleFinished(
|
|
|
|
thenableWithCancel,
|
|
|
|
progressOrError: number | Object) {
|
|
|
|
let error;
|
|
|
|
let progress;
|
|
|
|
|
|
|
|
if (typeof progressOrError === 'number') {
|
|
|
|
progress = progressOrError;
|
|
|
|
} else {
|
2017-09-24 21:51:43 +00:00
|
|
|
// Make the specified error object resemble an Error instance (to the
|
|
|
|
// extent that jitsi-meet needs it).
|
|
|
|
const {
|
|
|
|
authenticationError,
|
|
|
|
connectionError,
|
|
|
|
...other
|
2017-09-24 23:41:20 +00:00
|
|
|
} = progressOrError;
|
2017-09-24 21:51:43 +00:00
|
|
|
|
2017-09-24 23:41:20 +00:00
|
|
|
error = {
|
2017-09-24 21:51:43 +00:00
|
|
|
name: authenticationError || connectionError,
|
|
|
|
...other
|
|
|
|
};
|
2017-09-24 23:41:20 +00:00
|
|
|
progress = authenticationError ? 0.5 : 0;
|
2017-09-24 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
return {
|
2017-09-18 07:09:43 +00:00
|
|
|
type: UPGRADE_ROLE_FINISHED,
|
2017-09-24 23:41:20 +00:00
|
|
|
error,
|
|
|
|
progress,
|
|
|
|
thenableWithCancel
|
2017-09-08 13:36:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Signals that a process of authenticating and upgrading the local
|
|
|
|
* participant's role has started.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
2017-09-18 07:09:43 +00:00
|
|
|
* @param {Object} thenableWithCancel - The process of authenticating and
|
|
|
|
* upgrading the local participant's role.
|
2017-09-08 13:36:42 +00:00
|
|
|
* @private
|
|
|
|
* @returns {{
|
2017-09-18 07:09:43 +00:00
|
|
|
* type: UPGRADE_ROLE_STARTED,
|
|
|
|
* thenableWithCancel: Object
|
2017-09-08 13:36:42 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2017-09-18 07:09:43 +00:00
|
|
|
function _upgradeRoleStarted(thenableWithCancel) {
|
2017-09-08 13:36:42 +00:00
|
|
|
return {
|
2017-09-18 07:09:43 +00:00
|
|
|
type: UPGRADE_ROLE_STARTED,
|
|
|
|
thenableWithCancel
|
2017-09-08 13:36:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when Jicofo rejects to create the room for anonymous user. Will
|
|
|
|
* start the process of "waiting for the owner" by periodically trying to join
|
|
|
|
* the room every five seconds.
|
|
|
|
*
|
2017-10-06 20:15:51 +00:00
|
|
|
* @returns {Function}
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
|
|
|
export function waitForOwner() {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>) =>
|
2017-09-18 07:09:43 +00:00
|
|
|
dispatch({
|
|
|
|
type: WAIT_FOR_OWNER,
|
|
|
|
handler: () => dispatch(checkIfCanJoin()),
|
|
|
|
timeoutMs: 5000
|
|
|
|
});
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|