Add support for the BOSH bind URL as a setting parameter

This commit is contained in:
JC Brand 2013-04-25 00:21:54 +02:00
parent 9d4d651d1a
commit b36d2f18e5
2 changed files with 38 additions and 35 deletions

View File

@ -1864,27 +1864,35 @@
'<li><a class="current" href="#login">Sign in</a></li>'), '<li><a class="current" href="#login">Sign in</a></li>'),
template: _.template( template: _.template(
'<form id="converse-login">' + '<form id="converse-login">' +
'<label>XMPP ID:</label>' + '<label>XMPP/Jabber Username:</label>' +
'<input type="text" id="jid">' + '<input type="text" id="jid">' +
'<label>Password:</label>' + '<label>Password:</label>' +
'<input type="password" id="password">' + '<input type="password" id="password">' +
'<label>BOSH Service URL:</label>' +
'<input type="text" id="bosh_service_url">' +
'<input type="submit" name="submit"/>' + '<input type="submit" name="submit"/>' +
'</form">'), '</form">'),
authenticate: function (ev) { bosh_url_input: _.template(
'<label>BOSH Service URL:</label>' +
'<input type="text" id="bosh_service_url">'),
authenticate: $.proxy(function (ev) {
ev.preventDefault(); ev.preventDefault();
var $form = $(ev.target), var $form = $(ev.target),
$bsu_input = $form.find('input#bosh_service_url'),
bosh_service_url = $bsu_input.val(),
$jid_input = $form.find('input#jid'), $jid_input = $form.find('input#jid'),
jid = $jid_input.val(), jid = $jid_input.val(),
$pw_input = $form.find('input#password'), $pw_input = $form.find('input#password'),
password = $pw_input.val(), password = $pw_input.val(),
connection = new Strophe.Connection(bosh_service_url); $bsu_input = null,
errors = false;
var errors = false; if (! this.bosh_service_url) {
$bsu_input = $form.find('input#bosh_service_url');
this.bosh_service_url = $bsu_input.val();
if (! this.bosh_service_url) {
errors = true;
$bsu_input.addClass('error');
}
}
if (! jid) { if (! jid) {
errors = true; errors = true;
$jid_input.addClass('error'); $jid_input.addClass('error');
@ -1893,43 +1901,38 @@
errors = true; errors = true;
$pw_input.addClass('error'); $pw_input.addClass('error');
} }
if (! bosh_service_url) {
errors = true;
$bsu_input.addClass('error');
}
if (errors) { return; } if (errors) { return; }
// Clear the form's fields, so that it can't be submitted twice // Clear the form's fields, so that it can't be submitted twice
$bsu_input.val(''); if ($bsu_input) {
$bsu_input.val('');
}
$jid_input.val(''); $jid_input.val('');
$pw_input.val(''); $pw_input.val('');
var connection = new Strophe.Connection(this.bosh_service_url);
connection.connect(jid, password, $.proxy(function (status) { connection.connect(jid, password, $.proxy(function (status) {
if (status === Strophe.Status.CONNECTED) { if (status === Strophe.Status.CONNECTED) {
console.log('Connected'); console.log('Connected');
converse.onConnected(connection); this.onConnected(connection);
} else if (status === Strophe.Status.DISCONNECTED) { } else if (status === Strophe.Status.DISCONNECTED) {
console.log('Disconnected'); this.giveFeedback('Disconnected').css('background-image', "url(images/error_icon.png)");
this.$feedback.text('Unable to communicate with chat server').css('background-image', "url(images/error_icon.png)");
} else if (status === Strophe.Status.Error) { } else if (status === Strophe.Status.Error) {
console.log('Error'); this.giveFeedback('Error');
} else if (status === Strophe.Status.CONNECTING) { } else if (status === Strophe.Status.CONNECTING) {
console.log('Connecting'); this.giveFeedback('Connecting');
this.$feedback.text('Connecting to chat...');
} else if (status === Strophe.Status.CONNFAIL) { } else if (status === Strophe.Status.CONNFAIL) {
console.log('Connection Failed'); this.giveFeedback('Connection Failed');
} else if (status === Strophe.Status.AUTHENTICATING) { } else if (status === Strophe.Status.AUTHENTICATING) {
console.log('Authenticating'); this.giveFeedback('Authenticating');
converse.giveFeedback('Authenticating');
} else if (status === Strophe.Status.AUTHFAIL) { } else if (status === Strophe.Status.AUTHFAIL) {
console.log('Authenticating Failed'); this.giveFeedback('Authentication Failed');
converse.giveFeedback('Authentication failed');
} else if (status === Strophe.Status.DISCONNECTING) { } else if (status === Strophe.Status.DISCONNECTING) {
console.log('Disconnecting'); this.giveFeedback('Disconnecting');
} else if (status === Strophe.Status.ATTACHED) { } else if (status === Strophe.Status.ATTACHED) {
console.log('Attached'); console.log('Attached');
} }
}, this)); }, converse));
}, }, converse),
remove: function () { remove: function () {
this.$parent.find('#controlbox-tabs').empty(); this.$parent.find('#controlbox-tabs').empty();
@ -1938,7 +1941,11 @@
render: function () { render: function () {
this.$parent.find('#controlbox-tabs').append(this.tab_template()); this.$parent.find('#controlbox-tabs').append(this.tab_template());
this.$parent.find('#controlbox-panes').append(this.$el.html(this.template())); template = this.template();
if (! this.bosh_url_input) {
template.find('form').append(this.bosh_url_input);
}
this.$parent.find('#controlbox-panes').append(this.$el.html(template));
return this; return this;
} }
}); });
@ -1973,7 +1980,7 @@
}; };
converse.giveFeedback = function (message) { converse.giveFeedback = function (message) {
$('.conn-feedback').text(message); return $('.conn-feedback').text(message);
} }
converse.onConnected = function (connection) { converse.onConnected = function (connection) {
@ -2028,12 +2035,7 @@
}; };
converse.initialize = function (settings) { converse.initialize = function (settings) {
this.prebind = settings.prebind; _.extend(this, settings);
this.fullname = settings.fullname;
this.xhr_user_search = settings.xhr_user_search;
this.auto_subscribe = settings.auto_subscribe;
this.animate = settings.animate;
this.chatboxes = new this.ChatBoxes(); this.chatboxes = new this.ChatBoxes();
this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes}); this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes});
$('a.toggle-online-users').bind( $('a.toggle-online-users').bind(

View File

@ -1,5 +1,6 @@
require(["jquery", "converse"], function($, converse) { require(["jquery", "converse"], function($, converse) {
converse.initialize({ converse.initialize({
bosh_service_url: 'https://bind.opkode.im',
prebind: false, prebind: false,
xhr_user_search: false, xhr_user_search: false,
auto_subscribe: false auto_subscribe: false