From 38fc1c01d4c56a95d2fe6215e01e0127fdf8eb34 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Mon, 11 Jul 2016 13:44:49 +0200 Subject: [PATCH] Move XMPP login prompt handling to AuthHandler --- connection.js | 32 ++----------------- modules/UI/authentication/AuthHandler.js | 39 ++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/connection.js b/connection.js index 5add17e48..94f73e5e4 100644 --- a/connection.js +++ b/connection.js @@ -1,6 +1,5 @@ /* global APP, JitsiMeetJS, config */ -//FIXME: -import LoginDialog from './modules/UI/authentication/LoginDialog'; +import AuthHandler from './modules/UI/authentication/AuthHandler'; const ConnectionEvents = JitsiMeetJS.events.connection; const ConnectionErrors = JitsiMeetJS.errors.connection; @@ -92,33 +91,6 @@ function connect(id, password, roomName) { }); } -/** - * 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] - * @returns {Promise} - */ -function requestAuth(roomName) { - return new Promise(function (resolve, reject) { - let authDialog = LoginDialog.showAuthDialog( - function (id, password) { - connect(id, password, roomName).then(function (connection) { - authDialog.close(); - resolve(connection); - }, function (err) { - if (err === ConnectionErrors.PASSWORD_REQUIRED) { - authDialog.displayError(err); - } else { - authDialog.close(); - reject(err); - } - }); - } - ); - }); -} - /** * Open JitsiConnection using provided credentials. * If retry option is true it will show auth dialog on PASSWORD_REQUIRED error. @@ -157,7 +129,7 @@ export function openConnection({id, password, retry, roomName}) { if (config.token) { throw err; } else { - return requestAuth(roomName); + return AuthHandler.requestAuth(roomName, connect); } } else { throw err; diff --git a/modules/UI/authentication/AuthHandler.js b/modules/UI/authentication/AuthHandler.js index fc321af3a..98586d13c 100644 --- a/modules/UI/authentication/AuthHandler.js +++ b/modules/UI/authentication/AuthHandler.js @@ -1,11 +1,11 @@ -/* global JitsiMeetJS, APP */ +/* global APP, config, JitsiMeetJS, Promise */ import LoginDialog from './LoginDialog'; -import UIEvents from '../../../service/UI/UIEvents'; import UIUtil from '../util/UIUtil'; import {openConnection} from '../../../connection'; const ConferenceEvents = JitsiMeetJS.events.conference; +const ConnectionErrors = JitsiMeetJS.errors.connection; let externalAuthWindow; let authRequiredDialog; @@ -157,10 +157,45 @@ function closeAuth() { } } +function showXmppPasswordPrompt(roomName, connect) { + return new Promise(function (resolve, reject) { + let authDialog = LoginDialog.showAuthDialog( + function (id, password) { + connect(id, password, roomName).then(function (connection) { + authDialog.close(); + resolve(connection); + }, function (err) { + if (err === ConnectionErrors.PASSWORD_REQUIRED) { + authDialog.displayError(err); + } else { + authDialog.close(); + reject(err); + } + }); + } + ); + }); +} + +/** + * 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 + * @param {function(id, password, roomName)} [connect] function that returns + * a Promise which resolves with JitsiConnection or fails with one of + * ConnectionErrors. + * @returns {Promise} + */ +function requestAuth(roomName, connect) { + return showXmppPasswordPrompt(roomName, connect); +} + export default { authenticate, requireAuth, + requestAuth, closeAuth, logout };