Skip to content
Browse files

Update simple-xmpp.js

Added the .disconnect method for graceful stream exiting
  • Loading branch information...
1 parent 6200e42 commit 29659743655663de4774f03f007e9cf335192566 @Frosthaven Frosthaven committed Oct 23, 2013
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/simple-xmpp.js
View
21 lib/simple-xmpp.js
@@ -214,6 +214,27 @@ function SimpleXMPP() {
// Options:
// * skipPresence - don't send initial empty <presence/> when connecting
//
+
+
+ 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.connect = function(params) {
config = params;

0 comments on commit 2965974

Please sign in to comment.
Something went wrong with that request. Please try again.