simple-xmpp / node-simple-xmpp

Simple High Level NodeJS XMPP Client
302 stars 90 forks source link

Cannot keep alive #57

Open xavieryao opened 9 years ago

xavieryao commented 9 years ago

After connected, it will automatically exit with code 0 after a little while (like 3 minutes)

Mo33n commented 9 years ago

Can you tell which XMPP server you are using ?

pavankumar9 commented 8 years ago

Any update on this issue. Even for me after some time chat messages are not sent.

cyberwolf commented 7 years ago

I'm using this library to connect to HipChat and also encountered that the connection gets closed by the server after a while.

I checked how the Hubot hipchat adapter (which also uses xmpp) tackles this, as I knew that one does not suffer from this issue, and that one seems to send a "r" Stanza in regular time intervals (each 30 seconds).

Based on the hubot example, I've implemented this in my own app, which seems to solve the connection drops by the server:

var keepAlive;

var ping = function () {
  xmpp.conn.send(new Client.Stanza('r'));
};

xmpp.on('online', function(data) {
  keepAlive = setInterval(ping, 30000);
});

xmpp.on('close', function() {
  if (keepAlive) {
    clearInterval(keepAlive);
  }
});