diff --git a/app.js b/app.js index 60a306387..0ac25d0a7 100644 --- a/app.js +++ b/app.js @@ -66,6 +66,11 @@ function init() { return; } + var jid = document.getElementById('jid').value || config.hosts.domain || window.location.hostname; + connect(jid); +} + +function connect(jid, password) { connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind'); if (nickname) { @@ -82,9 +87,11 @@ function init() { connection.jingle.pc_constraints.optional.push({googIPv6: true}); } - var jid = document.getElementById('jid').value || config.hosts.domain || window.location.hostname; + if(!password) + password = document.getElementById('password').value; - connection.connect(jid, document.getElementById('password').value, function (status) { + var anonymousConnectionFailed = false; + connection.connect(jid, password, function (status, msg) { if (status === Strophe.Status.CONNECTED) { console.log('connected'); if (config.useStunTurn) { @@ -98,6 +105,20 @@ function init() { }); document.getElementById('connect').disabled = true; + } else if (status === Strophe.Status.CONNFAIL) { + if(msg === 'x-strophe-bad-non-anon-jid') { + anonymousConnectionFailed = true; + } + console.log('status', status); + } else if (status === Strophe.Status.DISCONNECTED) { + if(anonymousConnectionFailed) { + // prompt user for username and password + $(document).trigger('passwordrequired.main'); + } + } else if (status === Strophe.Status.AUTHFAIL) { + // wrong password or username, prompt user + $(document).trigger('passwordrequired.main'); + } else { console.log('status', status); } @@ -825,6 +846,31 @@ $(document).bind('passwordrequired.muc', function (event, jid) { }); }); +$(document).bind('passwordrequired.main', function (event) { + console.log('password is required'); + + $.prompt('