2015-12-17 15:31:11 +00:00
|
|
|
/* global APP, JitsiMeetJS, config */
|
2016-11-11 15:00:54 +00:00
|
|
|
|
2020-07-09 07:17:23 +00:00
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils';
|
2021-11-10 10:11:29 +00:00
|
|
|
import Logger from '@jitsi/logger';
|
2020-05-01 19:48:08 +00:00
|
|
|
|
2021-03-24 14:09:40 +00:00
|
|
|
import { redirectToTokenAuthService } from './modules/UI/authentication/AuthHandler';
|
|
|
|
import { LoginDialog } from './react/features/authentication/components';
|
|
|
|
import { isTokenAuthEnabled } from './react/features/authentication/functions';
|
2017-01-31 20:58:48 +00:00
|
|
|
import {
|
|
|
|
connectionEstablished,
|
2022-06-16 12:27:41 +00:00
|
|
|
connectionFailed,
|
|
|
|
constructOptions
|
2020-06-04 14:09:13 +00:00
|
|
|
} from './react/features/base/connection/actions';
|
2021-03-24 14:09:40 +00:00
|
|
|
import { openDialog } from './react/features/base/dialog/actions';
|
2021-07-09 06:30:49 +00:00
|
|
|
import { setJWT } from './react/features/base/jwt';
|
2017-02-19 00:42:11 +00:00
|
|
|
import {
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConnectionErrors,
|
|
|
|
JitsiConnectionEvents
|
2017-02-19 00:42:11 +00:00
|
|
|
} from './react/features/base/lib-jitsi-meet';
|
2022-04-08 12:24:58 +00:00
|
|
|
import { isFatalJitsiConnectionError } from './react/features/base/lib-jitsi-meet/functions';
|
2021-08-20 08:36:09 +00:00
|
|
|
import { getCustomerDetails } from './react/features/jaas/actions.any';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { getJaasJWT, isVpaasMeeting } from './react/features/jaas/functions';
|
2022-06-17 11:29:16 +00:00
|
|
|
import {
|
2022-07-04 19:47:59 +00:00
|
|
|
setPrejoinDisplayNameRequired
|
2022-06-17 11:29:16 +00:00
|
|
|
} from './react/features/prejoin/actions';
|
2020-05-20 10:57:03 +00:00
|
|
|
const logger = Logger.getLogger(__filename);
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2020-02-14 18:05:39 +00:00
|
|
|
/**
|
|
|
|
* The feature announced so we can distinguish jibri participants.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
export const DISCO_JIBRI_FEATURE = 'http://jitsi.org/protocol/jibri';
|
|
|
|
|
2016-03-28 21:19:32 +00:00
|
|
|
/**
|
|
|
|
* Checks if we have data to use attach instead of connect. If we have the data
|
|
|
|
* executes attach otherwise check if we have to wait for the data. If we have
|
|
|
|
* to wait for the attach data we are setting handler to APP.connect.handler
|
|
|
|
* which is going to be called when the attach data is received otherwise
|
|
|
|
* executes connect.
|
|
|
|
*
|
|
|
|
* @param {string} [id] user id
|
|
|
|
* @param {string} [password] password
|
|
|
|
* @param {string} [roomName] the name of the conference.
|
|
|
|
*/
|
|
|
|
function checkForAttachParametersAndConnect(id, password, connection) {
|
2017-10-12 23:02:29 +00:00
|
|
|
if (window.XMPPAttachInfo) {
|
|
|
|
APP.connect.status = 'connecting';
|
|
|
|
|
2016-03-28 22:42:20 +00:00
|
|
|
// When connection optimization is not deployed or enabled the default
|
|
|
|
// value will be window.XMPPAttachInfo.status = "error"
|
|
|
|
// If the connection optimization is deployed and enabled and there is
|
2016-04-20 19:02:16 +00:00
|
|
|
// a failure the value will be window.XMPPAttachInfo.status = "error"
|
2017-10-12 23:02:29 +00:00
|
|
|
if (window.XMPPAttachInfo.status === 'error') {
|
2017-10-16 20:37:13 +00:00
|
|
|
connection.connect({
|
|
|
|
id,
|
|
|
|
password
|
|
|
|
});
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-03-28 21:19:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const attachOptions = window.XMPPAttachInfo.data;
|
|
|
|
|
|
|
|
if (attachOptions) {
|
2016-03-28 21:19:32 +00:00
|
|
|
connection.attach(attachOptions);
|
2016-05-02 19:09:57 +00:00
|
|
|
delete window.XMPPAttachInfo.data;
|
2016-03-28 21:19:32 +00:00
|
|
|
} else {
|
2017-10-16 20:37:13 +00:00
|
|
|
connection.connect({
|
|
|
|
id,
|
|
|
|
password
|
|
|
|
});
|
2016-03-28 21:19:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-10-12 23:02:29 +00:00
|
|
|
APP.connect.status = 'ready';
|
2017-10-16 20:37:13 +00:00
|
|
|
APP.connect.handler
|
|
|
|
= checkForAttachParametersAndConnect.bind(
|
|
|
|
null,
|
|
|
|
id, password, connection);
|
2016-03-28 21:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Try to open connection using provided credentials.
|
|
|
|
* @param {string} [id]
|
|
|
|
* @param {string} [password]
|
|
|
|
* @returns {Promise<JitsiConnection>} connection if
|
|
|
|
* everything is ok, else error.
|
|
|
|
*/
|
2022-06-16 12:27:41 +00:00
|
|
|
export async function connect(id, password) {
|
2021-07-09 06:30:49 +00:00
|
|
|
const state = APP.store.getState();
|
|
|
|
let { jwt } = state['features/base/jwt'];
|
2021-07-21 05:52:04 +00:00
|
|
|
const { iAmRecorder, iAmSipGateway } = state['features/base/config'];
|
2021-07-09 06:30:49 +00:00
|
|
|
|
2021-08-20 08:36:09 +00:00
|
|
|
if (!iAmRecorder && !iAmSipGateway && isVpaasMeeting(state)) {
|
|
|
|
await APP.store.dispatch(getCustomerDetails());
|
|
|
|
|
|
|
|
if (!jwt) {
|
|
|
|
jwt = await getJaasJWT(state);
|
|
|
|
APP.store.dispatch(setJWT(jwt));
|
|
|
|
}
|
2021-07-09 06:30:49 +00:00
|
|
|
}
|
2016-02-09 23:44:41 +00:00
|
|
|
|
2022-06-16 12:27:41 +00:00
|
|
|
const connection = new JitsiMeetJS.JitsiConnection(null, jwt, constructOptions(state));
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2020-02-14 18:05:39 +00:00
|
|
|
if (config.iAmRecorder) {
|
|
|
|
connection.addFeature(DISCO_JIBRI_FEATURE);
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2015-12-17 15:31:11 +00:00
|
|
|
connection.addEventListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConnectionEvents.CONNECTION_ESTABLISHED,
|
2017-04-21 10:00:50 +00:00
|
|
|
handleConnectionEstablished);
|
2015-12-17 15:31:11 +00:00
|
|
|
connection.addEventListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConnectionEvents.CONNECTION_FAILED,
|
2017-04-21 10:00:50 +00:00
|
|
|
handleConnectionFailed);
|
2017-01-31 20:58:48 +00:00
|
|
|
connection.addEventListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConnectionEvents.CONNECTION_FAILED,
|
2017-04-21 10:00:50 +00:00
|
|
|
connectionFailedHandler);
|
2020-07-02 09:18:38 +00:00
|
|
|
connection.addEventListener(
|
|
|
|
JitsiConnectionEvents.DISPLAY_NAME_REQUIRED,
|
|
|
|
displayNameRequiredHandler
|
|
|
|
);
|
2017-01-31 20:58:48 +00:00
|
|
|
|
2018-02-06 22:54:21 +00:00
|
|
|
/* eslint-disable max-params */
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-02-06 22:54:21 +00:00
|
|
|
function connectionFailedHandler(error, message, credentials, details) {
|
|
|
|
/* eslint-enable max-params */
|
2017-09-24 21:51:43 +00:00
|
|
|
APP.store.dispatch(
|
2018-02-06 22:54:21 +00:00
|
|
|
connectionFailed(
|
2018-05-02 18:27:50 +00:00
|
|
|
connection, {
|
|
|
|
credentials,
|
|
|
|
details,
|
|
|
|
message,
|
|
|
|
name: error
|
|
|
|
}));
|
2017-01-31 20:58:48 +00:00
|
|
|
|
2017-02-19 00:42:11 +00:00
|
|
|
if (isFatalJitsiConnectionError(error)) {
|
2017-01-31 20:58:48 +00:00
|
|
|
connection.removeEventListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConnectionEvents.CONNECTION_FAILED,
|
2017-01-31 20:58:48 +00:00
|
|
|
connectionFailedHandler);
|
|
|
|
}
|
|
|
|
}
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function unsubscribe() {
|
|
|
|
connection.removeEventListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConnectionEvents.CONNECTION_ESTABLISHED,
|
2017-04-21 10:00:50 +00:00
|
|
|
handleConnectionEstablished);
|
2015-12-17 15:31:11 +00:00
|
|
|
connection.removeEventListener(
|
2017-10-10 23:31:40 +00:00
|
|
|
JitsiConnectionEvents.CONNECTION_FAILED,
|
2017-04-21 10:00:50 +00:00
|
|
|
handleConnectionFailed);
|
2015-12-17 15:31:11 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function handleConnectionEstablished() {
|
2018-07-02 21:22:51 +00:00
|
|
|
APP.store.dispatch(connectionEstablished(connection, Date.now()));
|
2015-12-17 15:31:11 +00:00
|
|
|
unsubscribe();
|
|
|
|
resolve(connection);
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function handleConnectionFailed(err) {
|
|
|
|
unsubscribe();
|
2017-10-12 23:02:29 +00:00
|
|
|
logger.error('CONNECTION FAILED:', err);
|
2015-12-17 15:31:11 +00:00
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
|
2020-07-02 09:18:38 +00:00
|
|
|
/**
|
|
|
|
* Marks the display name for the prejoin screen as required.
|
|
|
|
* This can happen if a user tries to join a room with lobby enabled.
|
|
|
|
*/
|
|
|
|
function displayNameRequiredHandler() {
|
|
|
|
APP.store.dispatch(setPrejoinDisplayNameRequired());
|
|
|
|
}
|
|
|
|
|
2016-03-28 21:19:32 +00:00
|
|
|
checkForAttachParametersAndConnect(id, password, connection);
|
2015-12-18 17:54:15 +00:00
|
|
|
});
|
|
|
|
}
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Open JitsiConnection using provided credentials.
|
|
|
|
* If retry option is true it will show auth dialog on PASSWORD_REQUIRED error.
|
|
|
|
*
|
|
|
|
* @param {object} options
|
|
|
|
* @param {string} [options.id]
|
|
|
|
* @param {string} [options.password]
|
2016-02-09 23:44:41 +00:00
|
|
|
* @param {string} [options.roomName]
|
2016-01-15 14:59:35 +00:00
|
|
|
* @param {boolean} [retry] if we should show auth dialog
|
|
|
|
* on PASSWORD_REQUIRED error.
|
|
|
|
*
|
|
|
|
* @returns {Promise<JitsiConnection>}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
export function openConnection({ id, password, retry, roomName }) {
|
|
|
|
const usernameOverride
|
|
|
|
= jitsiLocalStorage.getItem('xmpp_username_override');
|
|
|
|
const passwordOverride
|
|
|
|
= jitsiLocalStorage.getItem('xmpp_password_override');
|
2016-04-20 19:02:16 +00:00
|
|
|
|
2016-04-26 21:38:07 +00:00
|
|
|
if (usernameOverride && usernameOverride.length > 0) {
|
2017-10-12 23:02:29 +00:00
|
|
|
id = usernameOverride; // eslint-disable-line no-param-reassign
|
2016-04-20 19:02:16 +00:00
|
|
|
}
|
2016-04-26 21:38:07 +00:00
|
|
|
if (passwordOverride && passwordOverride.length > 0) {
|
2017-10-12 23:02:29 +00:00
|
|
|
password = passwordOverride; // eslint-disable-line no-param-reassign
|
2016-04-20 19:02:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 10:00:50 +00:00
|
|
|
return connect(id, password, roomName).catch(err => {
|
|
|
|
if (retry) {
|
2020-08-12 20:32:09 +00:00
|
|
|
const { jwt } = APP.store.getState()['features/base/jwt'];
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2020-08-12 20:32:09 +00:00
|
|
|
if (err === JitsiConnectionErrors.PASSWORD_REQUIRED && !jwt) {
|
2021-03-24 14:09:40 +00:00
|
|
|
return requestAuth(roomName);
|
2015-12-17 15:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-21 10:00:50 +00:00
|
|
|
|
|
|
|
throw err;
|
2015-12-17 15:31:11 +00:00
|
|
|
});
|
|
|
|
}
|
2021-03-24 14:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show Authentication Dialog and try to connect with new credentials.
|
|
|
|
* If failed to connect because of PASSWORD_REQUIRED error
|
|
|
|
* then ask for password again.
|
|
|
|
* @param {string} [roomName] name of the conference room
|
|
|
|
*
|
|
|
|
* @returns {Promise<JitsiConnection>}
|
|
|
|
*/
|
|
|
|
function requestAuth(roomName) {
|
|
|
|
const config = APP.store.getState()['features/base/config'];
|
|
|
|
|
|
|
|
if (isTokenAuthEnabled(config)) {
|
|
|
|
// This Promise never resolves as user gets redirected to another URL
|
|
|
|
return new Promise(() => redirectToTokenAuthService(roomName));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
const onSuccess = connection => {
|
|
|
|
resolve(connection);
|
|
|
|
};
|
|
|
|
|
|
|
|
APP.store.dispatch(
|
|
|
|
openDialog(LoginDialog, { onSuccess,
|
|
|
|
roomName })
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|