diff --git a/app.js b/app.js index 678ee2b4c..2b4e61de3 100644 --- a/app.js +++ b/app.js @@ -17,8 +17,6 @@ import URLProcessor from "./modules/config/URLProcessor"; import RoomnameGenerator from './modules/util/RoomnameGenerator'; import CQEvents from './service/connectionquality/CQEvents'; import UIEvents from './service/UI/UIEvents'; -import LoginDialog from './modules/UI/authentication/LoginDialog'; -import UIUtil from './modules/UI/util/UIUtil'; import {openConnection} from './modules/connection'; import AuthHandler from './modules/AuthHandler'; @@ -149,6 +147,8 @@ function initConference(localTracks, connection) { room.addTrack(track); APP.UI.addLocalStream(track); }); + + APP.UI.updateAuthInfo(room.isAuthEnabled(), room.getAuthLogin()); }); @@ -534,6 +534,8 @@ function init() { APP.statistics.start(); APP.connectionquality.init(); APP.keyboardshortcut.init(); + }).catch(function (err) { + console.error(err); }); } diff --git a/lib-jitsi-meet.js b/lib-jitsi-meet.js index be998a197..363d05f47 100644 --- a/lib-jitsi-meet.js +++ b/lib-jitsi-meet.js @@ -34,7 +34,7 @@ function JitsiConference(options) { this.connection = this.options.connection; this.xmpp = this.connection.xmpp; this.eventEmitter = new EventEmitter(); - this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config); + this.room = this.xmpp.createRoom(this.options.name, this.options.config); this.room.updateDeviceAvailability(RTC.getDeviceAvailability()); this.rtc = new RTC(this.room, options); if(!RTC.options.disableAudioLevels) @@ -44,6 +44,8 @@ function JitsiConference(options) { this.lastActiveSpeaker = null; this.dtmfManager = null; this.somebodySupportsDTMF = false; + this.authEnabled = false; + this.authIdentity; } /** @@ -78,6 +80,27 @@ JitsiConference.prototype.getName = function () { return this.options.name; }; +/** + * Check if authentication is enabled for this conference. + */ +JitsiConference.prototype.isAuthEnabled = function () { + return this.authEnabled; +}; + +/** + * Check if user is logged in. + */ +JitsiConference.prototype.isLoggedIn = function () { + return !!this.authIdentity; +}; + +/** + * Get authorized login. + */ +JitsiConference.prototype.getAuthLogin = function () { + return this.authIdentity; +}; + /** * Check if external authentication is enabled for this conference. */ @@ -385,6 +408,9 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) { JitsiConference.prototype.onMemberLeft = function (jid) { var id = Strophe.getResourceFromJid(jid); + if (id === 'focus') { + return; + } var participant = this.participants[id]; delete this.participants[id]; this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant); @@ -564,7 +590,8 @@ function setupListeners(conference) { }); conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) { - console.error(authEnabled, authIdentity); + conference.authEnabled = authEnabled; + conference.authIdentity = authIdentity; }); conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) { @@ -11522,12 +11549,12 @@ XMPP.prototype.connect = function (jid, password) { return this._connect(jid, password); }; -XMPP.prototype.createRoom = function (roomName, options, useNicks, nick) { +XMPP.prototype.createRoom = function (roomName, options) { var roomjid = roomName + '@' + this.options.hosts.muc; - if (useNicks) { - if (nick) { - roomjid += '/' + nick; + if (options.useNicks) { + if (options.nick) { + roomjid += '/' + options.nick; } else { roomjid += '/' + Strophe.getNodeFromJid(this.connection.jid); } diff --git a/modules/UI/UI.js b/modules/UI/UI.js index c24bb7736..a15968ed1 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -612,10 +612,6 @@ UI.updateRemoteStats = function (jid, percent, stats) { VideoLayout.updateConnectionStats(jid, percent, stats); }; -UI.showAuthenticateButton = function (show) { - Toolbar.showAuthenticateButton(show); -}; - UI.markVideoInterrupted = function (interrupted) { if (interrupted) { VideoLayout.onVideoInterrupted(); @@ -740,4 +736,15 @@ UI.notifyTokenAuthFailed = function () { messageHandler.showError("dialog.error", "dialog.tokenAuthFailed"); }; +UI.updateAuthInfo = function (isAuthEnabled, login) { + let loggedIn = !!login; + + if (isAuthEnabled) { + Toolbar.setAuthenticatedIdentity(login); + + Toolbar.showLoginButton(!loggedIn); + Toolbar.showLogoutButton(loggedIn); + } +}; + module.exports = UI; diff --git a/modules/UI/authentication/LoginDialog.js b/modules/UI/authentication/LoginDialog.js index 489579681..efd2bd8a8 100644 --- a/modules/UI/authentication/LoginDialog.js +++ b/modules/UI/authentication/LoginDialog.js @@ -13,22 +13,53 @@ function getPasswordInputHtml() {

${passRequiredMsg}

- `; + data-i18n="[placeholder]dialog.userPassword" + placeholder="user password"> + `; +} + +function toJid(id) { + if (id.indexOf("@") >= 0) { + return id; + } + + let jid = id.concat('@'); + if (config.hosts.authdomain) { + jid += config.hosts.authdomain; + } else { + jid += config.hosts.domain; + } + + return jid; +} + +function cancelButton() { + return { + title: APP.translation.generateTranslationHTML("dialog.Cancel"), + value: false + }; } function Dialog(successCallback, cancelCallback) { + let loginButtons = [{ + title: APP.translation.generateTranslationHTML("dialog.Ok"), + value: true + }]; + let finishedButtons = [{ + title: APP.translation.translateString('dialog.retry'), + value: 'retry' + }]; + + // show "cancel" button only if cancelCallback provided + if (cancelCallback) { + loginButtons.push(cancelButton()); + finishedButtons.push(cancelButton()); + } + const states = { login: { html: getPasswordInputHtml(), - buttons: [{ - title: APP.translation.generateTranslationHTML("dialog.Ok"), - value: true - }, { - title: APP.translation.generateTranslationHTML("dialog.Cancel"), - value: false - }], + buttons: loginButtons, focus: ':input:first', submit: function (e, v, m, f) { e.preventDefault(); @@ -37,7 +68,7 @@ function Dialog(successCallback, cancelCallback) { let password = f.password; if (jid && password) { connDialog.goToState('connecting'); - successCallback(jid, password); + successCallback(toJid(jid), password); } } else { // User cancelled @@ -54,13 +85,7 @@ function Dialog(successCallback, cancelCallback) { finished: { title: APP.translation.translateString('dialog.error'), html: '
', - buttons: [{ - title: APP.translation.translateString('dialog.retry'), - value: 'retry' - }, { - title: APP.translation.generateTranslationHTML("dialog.Cancel"), - value: false - }], + buttons: finishedButtons, defaultButton: 0, submit: function (e, v, m, f) { e.preventDefault(); diff --git a/modules/connection.js b/modules/connection.js index 24b00a226..8da0a29d9 100644 --- a/modules/connection.js +++ b/modules/connection.js @@ -5,7 +5,7 @@ import LoginDialog from './UI/authentication/LoginDialog'; const ConnectionEvents = JitsiMeetJS.events.connection; const ConnectionErrors = JitsiMeetJS.errors.connection; -export function openConnection({retry, id, password}) { +function connect(id, password) { let connection = new JitsiMeetJS.JitsiConnection(null, null, { hosts: config.hosts, bosh: config.bosh, @@ -17,9 +17,8 @@ export function openConnection({retry, id, password}) { ConnectionEvents.CONNECTION_ESTABLISHED, handleConnectionEstablished ); connection.addEventListener( - ConnectionEvents.CONNECTION_FAILED, onConnectionFailed + ConnectionEvents.CONNECTION_FAILED, handleConnectionFailed ); - let authDialog; function unsubscribe() { connection.removeEventListener( @@ -27,11 +26,9 @@ export function openConnection({retry, id, password}) { handleConnectionEstablished ); connection.removeEventListener( - ConnectionEvents.CONNECTION_FAILED, onConnectionFailed + ConnectionEvents.CONNECTION_FAILED, + handleConnectionFailed ); - if (authDialog) { - authDialog.close(); - } } function handleConnectionEstablished() { @@ -41,43 +38,49 @@ export function openConnection({retry, id, password}) { function handleConnectionFailed(err) { unsubscribe(); + console.error("CONNECTION FAILED:", err); reject(err); } - function onConnectionFailed (err) { - console.error("CONNECTION FAILED:", err); - - if (!retry) { - handleConnectionFailed(err); - return; - } - - // retry only if auth failed - if (err !== ConnectionErrors.PASSWORD_REQUIRED) { - handleConnectionFailed(err); - return; - } - - // do not retry if token is not valid - if (config.token) { - handleConnectionFailed(err); - return; - } - - // ask for password and try again - - if (authDialog) { - authDialog.displayError(err); - return; - } - - authDialog = LoginDialog.showAuthDialog( - function (id, password) { - connection.connect({id, password}); - } - ); - } - - connection.connect(id, password); + connection.connect({id, password}); + }); +} + +function requestAuth() { + return new Promise(function (resolve, reject) { + let authDialog = LoginDialog.showAuthDialog( + function (id, password) { + connect(id, password).then(function (connection) { + authDialog.close(); + resolve(connection); + }, function (err) { + if (err === ConnectionErrors.PASSWORD_REQUIRED) { + authDialog.displayError(err); + } else { + authDialog.close(); + reject(err); + } + }); + } + ); + }); +} + +export function openConnection({id, password, retry}) { + return connect(id, password).catch(function (err) { + if (!retry) { + throw err; + } + + if (err === ConnectionErrors.PASSWORD_REQUIRED) { + // do not retry if token is not valid + if (config.token) { + throw err; + } else { + return requestAuth(); + } + } else { + throw err; + } }); } diff --git a/modules/desktopsharing/desktopsharing.js b/modules/desktopsharing/desktopsharing.js index 4c91180cd..b4ed1a049 100644 --- a/modules/desktopsharing/desktopsharing.js +++ b/modules/desktopsharing/desktopsharing.js @@ -73,6 +73,7 @@ module.exports = { init: function () { // Called when RTC finishes initialization + return; APP.RTC.addListener(RTCEvents.RTC_READY, function() { screenObtainer.init(eventEmitter); diff --git a/modules/statistics/statistics.js b/modules/statistics/statistics.js index 9f63b0786..578970f5e 100644 --- a/modules/statistics/statistics.js +++ b/modules/statistics/statistics.js @@ -86,6 +86,7 @@ var statistics = { stopRemote(); }, start: function () { + return; APP.RTC.addStreamListener(onStreamCreated, StreamEventTypes.EVENT_TYPE_LOCAL_CREATED); APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,