Open ekeren opened 11 years ago
Hi ekeren,
I ran into the same problem some days ago, and here is how it get solved: http://stackoverflow.com/questions/15175521/disconnect-node-xmpp-client. Also, don't forget to pass reconnect: 'false'
on xmpp.connect().
@mutil is correct. WIth the current underline node-xmpp module. It is not easy to end the connection. sending reconnect:false does work, but it is not ideal, since we need reconnecting.
For this to get work, I need to hack this file form node-xmpp.
adding it to not to reconnect after the .end() calls and do not accept messages after closed. So we need to fork node-xmpp and send him to get approved. In the meantime we can use the forked repo as the npm dependancy.
This week, I'm bit busy and I only can work on this in next week. If someone can patch node-xmpp. It would be great.
Thanks.
Thanks! I will not be able to patch this fix, I am at reserve duty ( http://en.m.wikipedia.org/wiki/Reserve_duty_(Israel) ) and dont have access to my computer....
Thanks again On Mar 13, 2013 3:39 AM, "Arunoda Susiripala" notifications@github.com wrote:
@mutil https://github.com/mutil is correct. WIth the current underline node-xmpp module. It is not easy to end the connection. sending reconnect:false does work, but it is not ideal, since we need reconnecting.
For this to get work, I need to hack this filehttps://github.com/astro/node-xmpp/blob/master/lib/xmpp/session.jsform node-xmpp.
adding it to not to reconnect after the .end() calls and do not accept messages after closed. So we need to fork node-xmpp and send him to get approved. In the meantime we can use the forked repo as the npm dependancy.
This week, I'm bit busy and I only can work on this in next week. If someone can patch node-xmpp. It would be great.
Thanks.
— Reply to this email directly or view it on GitHubhttps://github.com/arunoda/node-simple-xmpp/issues/12#issuecomment-14816939 .
@arunoda - Hi, did you patch that file, did it worked?
Any more ideas on this one ? What is the patch that works ?
Alright so I've done a bit of digging around, as I've run into the need for a graceful disconnect option. A warning, though, is that I'm incredibly new to both Node and socket manipulation. What I did was investigate both simple-xmpp and node-xmpp source files and came across and end() method in node-xmpp. I used the OP's code and combined it with the logic in the end() method, which resulted in _modding 'simple-xmpp.js'_ with the following function:
this.disconnect = function() {
$.ready(function() {
var stanza = new xmpp.Element('presence', { type: 'unavailable' });
stanza.c('status').t('Logged out');
conn.send(stanza);
});
var ref = this.conn.connection;
if (ref.socket.writable) {
if (ref.streamOpened) {
ref.socket.write('</stream:stream>');
delete ref.streamOpened;
} else {
ref.socket.end();
}
}
};
This appears to gracefully send a logout stanza and close the stream, and I no longer have stream:errors when trying to connect the client in quick succession. It appears to fire the xmpp 'close' event when run, and you can run it with xmpp.disconnect();
If someone more experienced than I finds an issue with this method, let me know~
This looks look to me. Would you care to submit a pull request? I will accept it.
I have opened multiple xmpp client connection,if i call xmpp.conn.end() all connection has been closed.Here i need to find logout user and close or disconnect that client connection via node ja application. how can i do that ?
once I create a client connection via new xmpp.SimpleXMPP() I can't disconnect it. and the socket stays open.
This is snippet from the code I added locally:
this.disconnect = function() { $.ready(function() { var stanza = new xmpp.Element('presence', { type: 'unavailable' }); stanza.c('status').t('Logged out'); conn.send(stanza); conn.end(); }); }; but there should be a solution for the presence keep alive function that runs with the setInterval