2015-12-29 14:41:24 +00:00
|
|
|
/* global JitsiMeetJS, APP */
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2016-01-06 22:39:13 +00:00
|
|
|
import LoginDialog from './LoginDialog';
|
|
|
|
import UIEvents from '../../../service/UI/UIEvents';
|
|
|
|
import UIUtil from '../util/UIUtil';
|
|
|
|
import {openConnection} from '../../../connection';
|
2015-12-17 15:31:11 +00:00
|
|
|
|
|
|
|
const ConferenceEvents = JitsiMeetJS.events.conference;
|
|
|
|
|
|
|
|
let externalAuthWindow;
|
|
|
|
let authRequiredDialog;
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Authenticate using external service or just focus
|
|
|
|
* external auth window if there is one already.
|
|
|
|
*
|
|
|
|
* @param {JitsiConference} room
|
|
|
|
* @param {string} [lockPassword] password to use if the conference is locked
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function doExternalAuth (room, lockPassword) {
|
|
|
|
if (externalAuthWindow) {
|
|
|
|
externalAuthWindow.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (room.isJoined()) {
|
|
|
|
room.getExternalAuthUrl(true).then(function (url) {
|
|
|
|
externalAuthWindow = LoginDialog.showExternalAuthDialog(
|
|
|
|
url,
|
|
|
|
function () {
|
|
|
|
externalAuthWindow = null;
|
|
|
|
room.join(lockPassword);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// If conference has not been started yet
|
|
|
|
// then redirect to login page
|
|
|
|
room.getExternalAuthUrl().then(UIUtil.redirect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Authenticate on the server.
|
|
|
|
* @param {JitsiConference} room
|
|
|
|
* @param {string} [lockPassword] password to use if the conference is locked
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function doXmppAuth (room, lockPassword) {
|
|
|
|
let loginDialog = LoginDialog.showAuthDialog(function (id, password) {
|
|
|
|
// auth "on the fly":
|
|
|
|
// 1. open new connection with proper id and password
|
|
|
|
// 2. connect to the room
|
|
|
|
// (this will store sessionId in the localStorage)
|
|
|
|
// 3. close new connection
|
|
|
|
// 4. reallocate focus in current room
|
|
|
|
openConnection({id, password}).then(function (connection) {
|
|
|
|
// open room
|
2016-02-16 15:42:28 +00:00
|
|
|
let newRoom = connection.initJitsiConference(
|
|
|
|
room.getName(), APP.conference._getConferenceOptions()
|
|
|
|
);
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2015-12-29 14:41:24 +00:00
|
|
|
loginDialog.displayConnectionStatus(
|
|
|
|
APP.translation.translateString('connection.FETCH_SESSION_ID')
|
|
|
|
);
|
2015-12-21 13:02:07 +00:00
|
|
|
|
2015-12-29 14:41:24 +00:00
|
|
|
newRoom.room.moderator.authenticate().then(function () {
|
2015-12-17 15:31:11 +00:00
|
|
|
connection.disconnect();
|
2015-12-29 14:41:24 +00:00
|
|
|
|
|
|
|
loginDialog.displayConnectionStatus(
|
|
|
|
APP.translation.translateString('connection.GOT_SESSION_ID')
|
|
|
|
);
|
2015-12-21 13:02:07 +00:00
|
|
|
|
|
|
|
if (room.isJoined()) {
|
|
|
|
// just reallocate focus if already joined
|
|
|
|
room.room.moderator.allocateConferenceFocus();
|
|
|
|
} else {
|
|
|
|
// or join
|
|
|
|
room.join(lockPassword);
|
|
|
|
}
|
2015-12-17 15:31:11 +00:00
|
|
|
|
2015-12-29 14:41:24 +00:00
|
|
|
loginDialog.close();
|
|
|
|
}).catch(function (error, code) {
|
|
|
|
connection.disconnect();
|
|
|
|
|
|
|
|
console.error('Auth on the fly failed', error);
|
|
|
|
|
|
|
|
let errorMsg = APP.translation.translateString(
|
|
|
|
'connection.GET_SESSION_ID_ERROR'
|
|
|
|
);
|
|
|
|
|
|
|
|
loginDialog.displayError(errorMsg + code);
|
|
|
|
});
|
2015-12-17 15:31:11 +00:00
|
|
|
}, function (err) {
|
|
|
|
loginDialog.displayError(err);
|
|
|
|
});
|
|
|
|
}, function () { // user canceled
|
|
|
|
loginDialog.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Authenticate for the conference.
|
|
|
|
* Uses external service for auth if conference supports that.
|
|
|
|
* @param {JitsiConference} room
|
|
|
|
* @param {string} [lockPassword] password to use if the conference is locked
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function authenticate (room, lockPassword) {
|
|
|
|
if (room.isExternalAuthEnabled()) {
|
|
|
|
doExternalAuth(room, lockPassword);
|
|
|
|
} else {
|
2016-02-16 15:42:28 +00:00
|
|
|
doXmppAuth(room, lockPassword);
|
2015-12-17 15:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Notify user that authentication is required to create the conference.
|
2016-02-16 15:42:28 +00:00
|
|
|
* @param {JitsiConference} room
|
|
|
|
* @param {string} [lockPassword] password to use if the conference is locked
|
2016-01-15 14:59:35 +00:00
|
|
|
*/
|
2016-02-16 15:42:28 +00:00
|
|
|
function requireAuth(room, lockPassword) {
|
2015-12-17 15:31:11 +00:00
|
|
|
if (authRequiredDialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
authRequiredDialog = LoginDialog.showAuthRequiredDialog(
|
2016-02-16 15:42:28 +00:00
|
|
|
room.getName(), authenticate.bind(null, room, lockPassword)
|
2015-12-17 15:31:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Close auth-related dialogs if there are any.
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function closeAuth() {
|
|
|
|
if (externalAuthWindow) {
|
|
|
|
externalAuthWindow.close();
|
|
|
|
externalAuthWindow = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (authRequiredDialog) {
|
|
|
|
authRequiredDialog.close();
|
|
|
|
authRequiredDialog = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
authenticate,
|
|
|
|
requireAuth,
|
|
|
|
closeAuth
|
|
|
|
};
|