123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /* global JitsiMeetJS, APP */
-
- import LoginDialog from './LoginDialog';
- import UIEvents from '../../../service/UI/UIEvents';
- import UIUtil from '../util/UIUtil';
- import {openConnection} from '../../../connection';
-
- const ConferenceEvents = JitsiMeetJS.events.conference;
-
- let externalAuthWindow;
- let authRequiredDialog;
-
- /**
- * 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
- */
- 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);
- }
- }
-
- /**
- * Authenticate on the server.
- * @param {JitsiConference} room
- * @param {string} [lockPassword] password to use if the conference is locked
- */
- 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
- let newRoom = connection.initJitsiConference(
- room.getName(), APP.conference._getConferenceOptions()
- );
-
- loginDialog.displayConnectionStatus(
- APP.translation.translateString('connection.FETCH_SESSION_ID')
- );
-
- newRoom.room.moderator.authenticate().then(function () {
- connection.disconnect();
-
- loginDialog.displayConnectionStatus(
- APP.translation.translateString('connection.GOT_SESSION_ID')
- );
-
- if (room.isJoined()) {
- // just reallocate focus if already joined
- room.room.moderator.allocateConferenceFocus();
- } else {
- // or join
- room.join(lockPassword);
- }
-
- 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);
- });
- }, function (err) {
- loginDialog.displayError(err);
- });
- }, function () { // user canceled
- loginDialog.close();
- });
- }
-
- /**
- * 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
- */
- function authenticate (room, lockPassword) {
- if (room.isExternalAuthEnabled()) {
- doExternalAuth(room, lockPassword);
- } else {
- doXmppAuth(room, lockPassword);
- }
- }
-
- /**
- * Notify user that authentication is required to create the conference.
- * @param {JitsiConference} room
- * @param {string} [lockPassword] password to use if the conference is locked
- */
- function requireAuth(room, lockPassword) {
- if (authRequiredDialog) {
- return;
- }
-
- authRequiredDialog = LoginDialog.showAuthRequiredDialog(
- room.getName(), authenticate.bind(null, room, lockPassword)
- );
- }
-
- /**
- * Close auth-related dialogs if there are any.
- */
- function closeAuth() {
- if (externalAuthWindow) {
- externalAuthWindow.close();
- externalAuthWindow = null;
- }
-
- if (authRequiredDialog) {
- authRequiredDialog.close();
- authRequiredDialog = null;
- }
- }
-
-
- export default {
- authenticate,
- requireAuth,
- closeAuth
- };
|