Commit 47e00ae0 authored by JC Brand's avatar JC Brand

Various bugfixes.

- HAS_CSI might be called before features have been received. Instead, set a
  flag whenever a feature is received and check for that flag.
- Converse.ping was sending stanzas to the bare jid instead of to the domain.
- The handler that updates the date the last stanza was received must return
  true so that it gets called again.
- Only register the Pong handler if Ping is enabled.
- Rename lastMessage to lastStanzaDate to make it more clear.
parent e0a58efc
...@@ -386,7 +386,7 @@ ...@@ -386,7 +386,7 @@
// ---------------------- // ----------------------
this.sendCSI = function (stat) { this.sendCSI = function (stat) {
if (converse.HAS_CSI) { if (converse.features[Strophe.NS.CSI]) {
converse.connection.send($build(stat, {xmlns: Strophe.NS.CSI})); converse.connection.send($build(stat, {xmlns: Strophe.NS.CSI}));
} }
}; };
...@@ -403,7 +403,6 @@ ...@@ -403,7 +403,6 @@
this.registerAutoAwayHandler = function () { this.registerAutoAwayHandler = function () {
// TODO: we should probably come up with a way to decouple CSI and auto-away // TODO: we should probably come up with a way to decouple CSI and auto-away
if (this.auto_away > 0 || this.auto_xa > 0) { if (this.auto_away > 0 || this.auto_xa > 0) {
this.HAS_CSI = this.features.findWhere({'var': Strophe.NS.CSI}) ? true : false;
if (this.auto_xa > 0 && this.auto_xa < this.auto_away) { if (this.auto_xa > 0 && this.auto_xa < this.auto_away) {
this.auto_xa = this.auto_away; this.auto_xa = this.auto_away;
} }
...@@ -725,8 +724,10 @@ ...@@ -725,8 +724,10 @@
// connection option due to pings. // connection option due to pings.
// //
// var feature = converse.features.findWhere({'var': Strophe.NS.PING}); // var feature = converse.features.findWhere({'var': Strophe.NS.PING});
converse.lastMessage = new Date(); converse.lastStanzaDate = new Date();
if (typeof jid === 'undefined' || jid === null) { jid = converse.bare_jid; } if (typeof jid === 'undefined' || jid === null) {
jid = Strophe.getDomainFromJid(converse.bare_jid);
}
if (typeof timeout === 'undefined' ) { timeout = null; } if (typeof timeout === 'undefined' ) { timeout = null; }
if (typeof success === 'undefined' ) { success = null; } if (typeof success === 'undefined' ) { success = null; }
if (typeof error === 'undefined' ) { error = null; } if (typeof error === 'undefined' ) { error = null; }
...@@ -738,29 +739,33 @@ ...@@ -738,29 +739,33 @@
}; };
this.pong = function (ping) { this.pong = function (ping) {
converse.lastMessage=new Date(); converse.lastStanzaDate = new Date();
converse.connection.ping.pong(ping); converse.connection.ping.pong(ping);
return true; return true;
}; };
this.registerPongHandler = function () { this.registerPongHandler = function () {
if (converse.features.findWhere({'var': Strophe.NS.PING})) { converse.connection.disco.addFeature(Strophe.NS.PING);
converse.connection.disco.addFeature(Strophe.NS.PING); converse.connection.ping.addPingHandler(this.pong);
converse.connection.ping.addPingHandler(this.pong);
}
}; };
this.registerPingHandler = function () { this.registerPingHandler = function () {
if (this.ping_interval > 0) { if (this.ping_interval > 0) {
//handler on each message : save last message date in order to ping only when needed this.registerPongHandler();
converse.connection.addHandler(function () { converse.lastMessage = new Date();}); this.connection.addHandler(function () {
converse.connection.addTimedHandler(1000,function () { /* Handler on each stanza, saves the received date
* in order to ping only when needed.
*/
this.lastStanzaDate = new Date();
return true;
}.bind(converse));
this.connection.addTimedHandler(1000, function () {
now = new Date(); now = new Date();
if (!converse.lastMessage) { if (!this.lastStanzaDate) {
converse.lastMessage = now; this.lastStanzaDate = now;
} }
if ((now - converse.lastMessage)/1000 > converse.ping_interval) { if ((now - this.lastStanzaDate)/1000 > this.ping_interval) {
return converse.ping(); return this.ping();
} }
return true; return true;
}); });
...@@ -771,7 +776,6 @@ ...@@ -771,7 +776,6 @@
// We need to re-register all the event handlers on the newly // We need to re-register all the event handlers on the newly
// created connection. // created connection.
this.initStatus($.proxy(function () { this.initStatus($.proxy(function () {
this.registerPongHandler();
this.registerPingHandler(); this.registerPingHandler();
this.rosterview.registerRosterXHandler(); this.rosterview.registerRosterXHandler();
this.rosterview.registerPresenceHandler(); this.rosterview.registerPresenceHandler();
...@@ -819,7 +823,6 @@ ...@@ -819,7 +823,6 @@
this.enableCarbons(); this.enableCarbons();
this.initStatus($.proxy(function () { this.initStatus($.proxy(function () {
this.registerPingHandler(); this.registerPingHandler();
this.registerPongHandler();
this.registerAutoAwayHandler(); this.registerAutoAwayHandler();
this.chatboxes.onConnected(); this.chatboxes.onConnected();
this.giveFeedback(__('Contacts')); this.giveFeedback(__('Contacts'));
...@@ -5020,8 +5023,10 @@ ...@@ -5020,8 +5023,10 @@
return; return;
} }
$stanza.find('feature').each($.proxy(function (idx, feature) { $stanza.find('feature').each($.proxy(function (idx, feature) {
var namespace = $(feature).attr('var');
this[namespace] = true;
this.create({ this.create({
'var': $(feature).attr('var'), 'var': namespace,
'from': $stanza.attr('from') 'from': $stanza.attr('from')
}); });
}, this)); }, this));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment