refactor authentication module
This commit is contained in:
parent
fbe5ef7ee6
commit
ec2be349df
5
app.js
5
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
|
||||
|
|
|
@ -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)');
|
||||
};
|
||||
|
|
|
@ -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;
|
|
@ -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 <tt>Dialog</tt> instance.
|
||||
* @param callback <tt>function(Strophe.Connection, Strophe.Status)</tt> called
|
||||
* when we either fail to connect or succeed(check Strophe.Status).
|
||||
* @param obtainSession <tt>true</tt> 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 = '<h2 data-i18n="dialog.passwordRequired">';
|
||||
message += APP.translation.translateString("dialog.passwordRequired");
|
||||
message += '</h2>' +
|
||||
'<input name="username" type="text" ';
|
||||
if (config.hosts.authdomain) {
|
||||
message += 'placeholder="user identity" autofocus>';
|
||||
message += 'placeholder="user identity" autofocus>';
|
||||
} else {
|
||||
message += 'placeholder="user@domain.net" autofocus>';
|
||||
message += 'placeholder="user@domain.net" autofocus>';
|
||||
}
|
||||
message += '<input name="password" ' +
|
||||
'type="password" data-i18n="[placeholder]dialog.userPassword"' +
|
||||
|
@ -53,23 +37,12 @@ function Dialog(callback, obtainSession) {
|
|||
var jid = f.username;
|
||||
var password = f.password;
|
||||
if (jid && password) {
|
||||
stop = false;
|
||||
if (jid.indexOf("@") < 0) {
|
||||
jid = jid.concat('@');
|
||||
if (config.hosts.authdomain) {
|
||||
jid += config.hosts.authdomain;
|
||||
} else {
|
||||
jid += config.hosts.domain;
|
||||
}
|
||||
}
|
||||
connection.reset();
|
||||
connDialog.goToState('connecting');
|
||||
connection.connect(jid, password, stateHandler);
|
||||
successCallback(jid, password);
|
||||
}
|
||||
} else {
|
||||
// User cancelled
|
||||
stop = true;
|
||||
callback();
|
||||
cancelCallback();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -95,102 +68,18 @@ function Dialog(callback, obtainSession) {
|
|||
defaultButton: 0,
|
||||
submit: function (e, v, m, f) {
|
||||
e.preventDefault();
|
||||
if (v === 'retry')
|
||||
if (v === 'retry') {
|
||||
connDialog.goToState('login');
|
||||
else
|
||||
callback();
|
||||
} else {
|
||||
cancelCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var connDialog
|
||||
= APP.UI.messageHandler.openDialogWithStates(states,
|
||||
{ persistent: true, closeText: '' }, null);
|
||||
|
||||
var stateHandler = function (status, message) {
|
||||
if (stop) {
|
||||
return;
|
||||
}
|
||||
|
||||
var translateKey = "connection." + XMPP.getStatusString(status);
|
||||
var statusStr = APP.translation.translateString(translateKey);
|
||||
|
||||
// Display current state
|
||||
var connectionStatus =
|
||||
connDialog.getState('connecting').find('#connectionStatus');
|
||||
|
||||
connectionStatus.text(statusStr);
|
||||
|
||||
switch (status) {
|
||||
case XMPP.Status.CONNECTED:
|
||||
|
||||
stop = true;
|
||||
if (!obtainSession) {
|
||||
callback(connection, status);
|
||||
return;
|
||||
}
|
||||
// Obtaining session-id status
|
||||
connectionStatus.text(
|
||||
APP.translation.translateString(
|
||||
'connection.FETCH_SESSION_ID'));
|
||||
|
||||
// Authenticate with Jicofo and obtain session-id
|
||||
var roomName = APP.conference.roomName;
|
||||
|
||||
// Jicofo will return new session-id when connected
|
||||
// from authenticated domain
|
||||
connection.sendIQ(
|
||||
Moderator.createConferenceIq(roomName),
|
||||
function (result) {
|
||||
|
||||
connectionStatus.text(
|
||||
APP.translation.translateString(
|
||||
'connection.GOT_SESSION_ID'));
|
||||
|
||||
stop = true;
|
||||
|
||||
// Parse session-id
|
||||
Moderator.parseSessionId(result);
|
||||
|
||||
callback(connection, status);
|
||||
},
|
||||
function (error) {
|
||||
console.error("Auth on the fly failed", error);
|
||||
|
||||
stop = true;
|
||||
|
||||
var errorMsg =
|
||||
APP.translation.translateString(
|
||||
'connection.GET_SESSION_ID_ERROR') +
|
||||
$(error).find('>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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue