Skip to content

Commit

Permalink
Merge pull request #49 from freedomjs/dborkan-fixes
Browse files Browse the repository at this point in the history
Set reconnect=true, add error trace to help detect disconnects
  • Loading branch information
dborkan committed Jun 18, 2014
2 parents 0a7a37a + 2f7a8f1 commit c3a1b2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "freedom-social-xmpp",
"description": "XMPP Social provider for freedomjs",
"version": "0.0.13",
"version": "0.0.14",
"homepage": "http://freedomjs.org",
"bugs": {
"url": "http://github.com/freedomjs/freedom-social-xmpp/issues",
Expand Down
22 changes: 20 additions & 2 deletions src/socialprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ XMPPSocialProvider.prototype.connect = function(continuation) {
xmlns: 'jabber:client',
jid: this.id,
disallowTLS: true,
preferred: 'PLAIN' //TODO: why doesn't DIGEST-MD5 work?
preferred: 'PLAIN', //TODO: why doesn't DIGEST-MD5 work?
reconnect: true // Automatically try reconnecting if disconnected.
};
for (key in this.credentials) {
if (this.credentials.hasOwnProperty(key)) {
Expand All @@ -145,7 +146,7 @@ XMPPSocialProvider.prototype.connect = function(continuation) {
}
this.client.addListener('online', this.onOnline.bind(this, continuation));
this.client.addListener('error', function(e) {
console.error(e.stack);
console.error('client.error: ', e.stack);
continuation(undefined, {
errcode: this.ERRCODE.LOGIN_FAILEDCONNECTION.errcode,
message: e.message
Expand All @@ -157,6 +158,23 @@ XMPPSocialProvider.prototype.connect = function(continuation) {
delete this.client;
}
}.bind(this));
this.client.addListener('offline', function(e) {
// TODO: tell users of the API that this client is now offline,
// either by emitting an onClientState with OFFLINE using:
// this.vCardStore.updateProperty(this.id, 'status', 'OFFLINE');
// or emit a new type of event, or invoke this.logout directly to
// clean things up.
console.error('received unhandled offline event', e);
});
this.client.addListener('close', function(e) {
// This may indicate a broken connection to XMPP.
// TODO: handle this.
console.error('received unhandled close event', e);
});
this.client.addListener('end', function(e) {
// TODO: figure out when this is fired and handle this.
console.error('received unhandled end event', e);
});
this.client.addListener('stanza', this.onMessage.bind(this));
};

Expand Down

0 comments on commit c3a1b2a

Please sign in to comment.