From ec2be349df367ce9ce63a0a286be4d60ef176aeb Mon Sep 17 00:00:00 2001 From: isymchych Date: Tue, 15 Dec 2015 14:09:44 +0200 Subject: [PATCH] refactor authentication module --- app.js | 5 +- modules/UI/UI.js | 15 -- modules/UI/authentication/Authentication.js | 156 -------------------- modules/UI/authentication/LoginDialog.js | 156 ++++---------------- modules/UI/videolayout/SmallVideo.js | 1 - 5 files changed, 33 insertions(+), 300 deletions(-) delete mode 100644 modules/UI/authentication/Authentication.js diff --git a/app.js b/app.js index 50c1552fa..4b6327650 100644 --- a/app.js +++ b/app.js @@ -460,6 +460,10 @@ function initConference(localTracks, connection) { // APP.xmpp.eject(self.id); }); + APP.UI.addListener(UIEvents.AUTH_CLICKED, function () { + // FIXME handle + }); + APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, function (id) { room.selectParticipant(id); }); @@ -484,7 +488,6 @@ function initConference(localTracks, connection) { // FIXME handle errors here - APP.UI.closeAuthenticationDialog(); room.join(); }).catch(function (err) { // FIXME notify that we cannot conenct to the room diff --git a/modules/UI/UI.js b/modules/UI/UI.js index a63bc6f2a..603a19729 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -22,7 +22,6 @@ var EventEmitter = require("events"); var Settings = require("./../settings/Settings"); UI.messageHandler = require("./util/MessageHandler"); var messageHandler = UI.messageHandler; -var Authentication = require("./authentication/Authentication"); var JitsiPopover = require("./util/JitsiPopover"); var CQEvents = require("../../service/connectionquality/CQEvents"); var DesktopSharingEventTypes @@ -208,10 +207,6 @@ function registerListeners() { UI.addListener(UIEvents.FULLSCREEN_TOGGLE, toggleFullScreen); - UI.addListener(UIEvents.AUTH_CLICKED, function () { - Authentication.authenticate(); - }); - UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat); UI.addListener(UIEvents.TOGGLE_SETTINGS, function () { @@ -407,7 +402,6 @@ UI.updateLocalRole = function (isModerator) { SettingsMenu.onRoleChanged(); if (isModerator) { - Authentication.closeAuthenticationWindow(); messageHandler.notify(null, "notify.me", 'connected', "notify.moderator"); Toolbar.checkAutoRecord(); @@ -437,10 +431,6 @@ UI.updateUserRole = function (user) { } }; -UI.notifyAuthRequired = function (intervalCallback) { - Authentication.openAuthenticationDialog(APP.conference.roomName, intervalCallback); -}; - UI.toggleSmileys = function () { Chat.toggleSmileys(); @@ -506,11 +496,6 @@ UI.showLoginPopup = function(callback) { ); }; -UI.closeAuthenticationDialog = function () { - Authentication.closeAuthenticationDialog(); - Authentication.stopInterval(); -}; - UI.askForNickname = function () { return window.prompt('Your nickname (optional)'); }; diff --git a/modules/UI/authentication/Authentication.js b/modules/UI/authentication/Authentication.js deleted file mode 100644 index a43e2fd8a..000000000 --- a/modules/UI/authentication/Authentication.js +++ /dev/null @@ -1,156 +0,0 @@ -/* global $, APP*/ -/* jshint -W101 */ - -import messageHandler from '../util/MessageHandler'; - -var LoginDialog = require('./LoginDialog'); -var Moderator = require('../../xmpp/moderator'); - -/* Initial "authentication required" dialog */ -var authDialog = null; -/* Loop retry ID that wits for other user to create the room */ -var authRetryId = null; -var authenticationWindow = null; - -var Authentication = { - authenticate () { - Authentication.focusAuthenticationWindow(); - if (!APP.xmpp.isExternalAuthEnabled()) { - Authentication.xmppAuthenticate(); - return; - } - // Get authentication URL - if (!APP.xmpp.isMUCJoined()) { - APP.xmpp.getLoginUrl(APP.conference.roomName, function (url) { - // If conference has not been started yet - redirect to login page - window.location.href = url; - }); - } else { - APP.xmpp.getPopupLoginUrl(APP.conference.roomName, function (url) { - // Otherwise - open popup with authentication URL - var authenticationWindow = Authentication.createAuthenticationWindow( - function () { - // On popup closed - retry room allocation - APP.xmpp.allocateConferenceFocus( - APP.conference.roomName, - function () { console.info("AUTH DONE"); } - ); - }, url); - if (!authenticationWindow) { - messageHandler.openMessageDialog(null, "dialog.popupError"); - } - }); - } - }, - - openAuthenticationDialog (roomName, intervalCallback) { - // This is the loop that will wait for the room to be created by - // someone else. 'auth_required.moderator' will bring us back here. - authRetryId = window.setTimeout(intervalCallback, 5000); - // Show prompt only if it's not open - if (authDialog !== null) { - return; - } - // extract room name from 'room@muc.server.net' - var room = roomName.substr(0, roomName.indexOf('@')); - - var title - = APP.translation.generateTranslationHTML("dialog.WaitingForHost"); - var msg - = APP.translation.generateTranslationHTML( - "dialog.WaitForHostMsg", {room: room}); - - var buttonTxt - = APP.translation.generateTranslationHTML("dialog.IamHost"); - var buttons = []; - buttons.push({title: buttonTxt, value: "authNow"}); - - authDialog = messageHandler.openDialog( - title, - msg, - true, - buttons, - function (onSubmitEvent, submitValue) { - - // Do not close the dialog yet - onSubmitEvent.preventDefault(); - - // Open login popup - if (submitValue === 'authNow') { - Authentication.authenticate(); - } - } - ); - }, - closeAuthenticationWindow () { - if (authenticationWindow) { - authenticationWindow.close(); - authenticationWindow = null; - } - }, - xmppAuthenticate () { - var loginDialog = LoginDialog.show( - function (connection, state) { - if (!state) { - // User cancelled - loginDialog.close(); - return; - } else if (state == APP.xmpp.Status.CONNECTED) { - - loginDialog.close(); - - Authentication.stopInterval(); - Authentication.closeAuthenticationDialog(); - - // Close the connection as anonymous one will be used - // to create the conference. Session-id will authorize - // the request. - connection.disconnect(); - - var roomName = APP.conference.roomName; - Moderator.allocateConferenceFocus(roomName, function () { - // If it's not "on the fly" authentication now join - // the conference room - if (!APP.xmpp.isMUCJoined()) { - APP.UI.checkForNicknameAndJoin(); - } - }); - } - }, true); - }, - focusAuthenticationWindow () { - // If auth window exists just bring it to the front - if (authenticationWindow) { - authenticationWindow.focus(); - return; - } - }, - closeAuthenticationDialog () { - // Close authentication dialog if opened - if (authDialog) { - authDialog.close(); - authDialog = null; - } - }, - createAuthenticationWindow (callback, url) { - authenticationWindow = messageHandler.openCenteredPopup( - url, 910, 660, - // On closed - function () { - // Close authentication dialog if opened - Authentication.closeAuthenticationDialog(); - callback(); - authenticationWindow = null; - }); - return authenticationWindow; - }, - stopInterval () { - // Clear retry interval, so that we don't call 'doJoinAfterFocus' twice - if (authRetryId) { - window.clearTimeout(authRetryId); - authRetryId = null; - } - } -}; - -module.exports = Authentication; \ No newline at end of file diff --git a/modules/UI/authentication/LoginDialog.js b/modules/UI/authentication/LoginDialog.js index cf39bfe31..a6b39a3b6 100644 --- a/modules/UI/authentication/LoginDialog.js +++ b/modules/UI/authentication/LoginDialog.js @@ -1,35 +1,19 @@ /* global $, APP, config*/ -var XMPP = require('../../xmpp/xmpp'); -var Moderator = require('../../xmpp/moderator'); +var messageHandler = require('../util/MessageHandler'); //FIXME: use LoginDialog to add retries to XMPP.connect method used when // anonymous domain is not enabled -/** - * Creates new Dialog instance. - * @param callback function(Strophe.Connection, Strophe.Status) called - * when we either fail to connect or succeed(check Strophe.Status). - * @param obtainSession true if we want to send ConferenceIQ to Jicofo - * in order to create session-id after the connection is established. - * @constructor - */ -function Dialog(callback, obtainSession) { - - var self = this; - - var stop = false; - - var connection = APP.xmpp.createConnection(); - +function Dialog(successCallback, cancelCallback) { var message = '

'; message += APP.translation.translateString("dialog.passwordRequired"); message += '

' + 'error').attr('code'); - - self.displayError(errorMsg); - - connection.disconnect(); - }); - - break; - case XMPP.Status.AUTHFAIL: - case XMPP.Status.CONNFAIL: - case XMPP.Status.DISCONNECTED: - - stop = true; - - callback(connection, status); - - var errorMessage = statusStr; - - if (message) - { - errorMessage += ': ' + message; - } - self.displayError(errorMessage); - - break; - default: - break; - } - }; + var connDialog = messageHandler.openDialogWithStates( + states, { persistent: true, closeText: '' }, null + ); /** * Displays error message in 'finished' state which allows either to cancel @@ -211,7 +100,6 @@ function Dialog(callback, obtainSession) { * Closes LoginDialog. */ this.close = function () { - stop = true; connDialog.close(); }; } @@ -232,8 +120,22 @@ var LoginDialog = { * established. * @returns {Dialog} */ - show: function (callback, obtainSession) { - return new Dialog(callback, obtainSession); + show: function (successCallback, cancelCallback) { + return new Dialog(successCallback, cancelCallback); + }, + + showExternalAuthDialog: function (url, callback) { + var dialog = messageHandler.openCenteredPopup( + url, 910, 660, + // On closed + callback + ); + + if (!dialog) { + messageHandler.openMessageDialog(null, "dialog.popupError"); + } + + return dialog; } }; diff --git a/modules/UI/videolayout/SmallVideo.js b/modules/UI/videolayout/SmallVideo.js index 83173dc85..37cf502c8 100644 --- a/modules/UI/videolayout/SmallVideo.js +++ b/modules/UI/videolayout/SmallVideo.js @@ -5,7 +5,6 @@ import UIUtil from "../util/UIUtil"; import LargeVideo from "./LargeVideo"; var RTCBrowserType = require("../../RTC/RTCBrowserType"); -var MediaStreamType = require("../../../service/RTC/MediaStreamTypes"); function SmallVideo() { this.isMuted = false;