Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
better error handling while establishing connection
isymchych3a00837107fe
diff --git a/app.js b/app.jsindex 678ee2b4c2..2b4e61de3c 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.jsindex be998a197a..363d05f478 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.jsindex c24bb77360..a15968ed1d 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.jsindex 489579681b..efd2bd8a8e 100644--- a/modules/UI/authentication/LoginDialog.js+++ b/modules/UI/authentication/LoginDialog.js@@ -13,22 +13,53 @@ function getPasswordInputHtml() {<h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2><input name="username" type="text" placeholder=${placeholder} autofocus><input name="password" type="password"- data-i18n="[placeholder]dialog.userPassword"- placeholder="user password">- `;+ 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: '<div id="errorMessage"></div>',- 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.jsindex 24b00a2263..8da0a29d96 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);+ connection.connect({id, password});+ });+}- if (!retry) {- handleConnectionFailed(err);- return;+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);+ }+ });}+ );+ });+}- // retry only if auth failed- if (err !== ConnectionErrors.PASSWORD_REQUIRED) {- handleConnectionFailed(err);- return;- }+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 validif (config.token) {- handleConnectionFailed(err);- return;- }-- // ask for password and try again-- if (authDialog) {- authDialog.displayError(err);- return;+ throw err;+ } else {+ return requestAuth();}-- authDialog = LoginDialog.showAuthDialog(- function (id, password) {- connection.connect({id, password});- }- );+ } else {+ throw err;}-- connection.connect(id, password);});}diff --git a/modules/desktopsharing/desktopsharing.js b/modules/desktopsharing/desktopsharing.jsindex 4c91180cd3..b4ed1a049a 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.jsindex 9f63b07867..578970f5e0 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,