|
@@ -276,6 +276,7 @@
|
|
|
keepalive: false,
|
|
|
message_carbons: false,
|
|
|
no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width)
|
|
|
+ ping_interval: 180, //in seconds
|
|
|
play_sounds: false,
|
|
|
sounds_path: '/sounds/',
|
|
|
password: undefined,
|
|
@@ -663,10 +664,57 @@
|
|
|
},this), 200));
|
|
|
};
|
|
|
|
|
|
+ this.ping = function (jid, success, error, timeout){
|
|
|
+ //var feature = converse.features.findWhere({'var': Strophe.NS.PING});
|
|
|
+ //if (feature) {
|
|
|
+ converse.lastMessage=new Date();
|
|
|
+ if (typeof jid === 'undefined' || jid == null) { jid = converse.bare_jid; }
|
|
|
+ if (typeof timeout === 'undefined' ) { timeout = null; }
|
|
|
+ if (typeof success === 'undefined' ) { success = null; }
|
|
|
+ if (typeof error === 'undefined' ) { error = null; }
|
|
|
+ if (converse.connection) {
|
|
|
+ converse.connection.ping.ping( jid, success, error, timeout );
|
|
|
+ return true
|
|
|
+ };
|
|
|
+ //}
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+
|
|
|
+ this.pong = function (ping){
|
|
|
+ converse.lastMessage=new Date();
|
|
|
+ converse.connection.ping.pong(ping);
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+
|
|
|
+ this.registerPongHandler = function (){
|
|
|
+ var feature = converse.features.findWhere({'var': Strophe.NS.PING});
|
|
|
+ if (feature) {
|
|
|
+ converse.connection.disco.addFeature(Strophe.NS.PING);
|
|
|
+ converse.connection.ping.addPingHandler( this.pong );
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ this.registerPingHandler = function (){
|
|
|
+ if (this.ping_interval>0){
|
|
|
+ //handler on each message : save last message date in order to ping only when needed
|
|
|
+ converse.connection.addHandler(function(){ converse.lastMessage=new Date();});
|
|
|
+ converse.connection.addTimedHandler(1000,function() {
|
|
|
+ now = new Date();
|
|
|
+ if (!converse.lastMessage) converse.lastMessage=now;
|
|
|
+ if ((now - converse.lastMessage)/1000 > converse.ping_interval){
|
|
|
+ return converse.ping();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
this.onReconnected = function () {
|
|
|
// We need to re-register all the event handlers on the newly
|
|
|
// created connection.
|
|
|
this.initStatus($.proxy(function () {
|
|
|
+ this.registerPongHandler();
|
|
|
+ this.registerPingHandler();
|
|
|
this.rosterview.registerRosterXHandler();
|
|
|
this.rosterview.registerPresenceHandler();
|
|
|
this.chatboxes.registerMessageHandler();
|
|
@@ -713,6 +761,8 @@
|
|
|
this.enableCarbons();
|
|
|
this.initStatus($.proxy(function () {
|
|
|
|
|
|
+ this.registerPingHandler();
|
|
|
+ this.registerPongHandler();
|
|
|
this.chatboxes.onConnected();
|
|
|
this.giveFeedback(__('Contacts'));
|
|
|
if (this.callback) {
|
|
@@ -5828,6 +5878,9 @@
|
|
|
'send': function (stanza) {
|
|
|
converse.connection.send(stanza);
|
|
|
},
|
|
|
+ 'ping': function (jid) {
|
|
|
+ converse.ping(jid);
|
|
|
+ },
|
|
|
'plugins': {
|
|
|
'add': function (name, callback) {
|
|
|
converse.plugins[name] = callback;
|