freedom-social-xmpp
Advanced tools
Comparing version 0.3.12 to 0.3.13
@@ -40,3 +40,3 @@ /*jslint white:true,sloppy:true */ | ||
this.MAX_MS_WITHOUT_COMMUNICATION_ = 60000; | ||
this.MAX_MS_PING_REPSONSE_ = 10000; | ||
this.MAX_MS_PING_REPSONSE_ = 5000; | ||
@@ -183,10 +183,12 @@ // Metadata about the roster | ||
this.client.addListener('close', function(e) { | ||
// This may indicate a broken connection to XMPP. | ||
// TODO: handle this. | ||
this.logger.error('received unhandled close event', e); | ||
this.logger.error('received close event', e); | ||
if (this.status === 'ONLINE') { | ||
// Check if we are still online, otherwise log out. | ||
this.ping_(); | ||
} | ||
}.bind(this)); | ||
this.client.addListener('end', function(e) { | ||
this.logger.error('received end event, status: ' + this.status, e); | ||
if (this.status !== 'ONLINE') { | ||
// Reject login promise. | ||
if (this.status !== 'ONLINE' && this.client) { | ||
// Login is still pending, reject the login promise. | ||
this.logger.error('Received end event while logging in'); | ||
continuation(undefined, { | ||
@@ -196,3 +198,5 @@ errcode: 'LOGIN_FAILEDCONNECTION', | ||
}); | ||
} else { | ||
} else if (this.client) { | ||
// Got an 'end' event without logout having been called, call logout. | ||
this.logger.error('Received unexpected end event'); | ||
this.logout(); | ||
@@ -208,3 +212,3 @@ } | ||
*/ | ||
XMPPSocialProvider.prototype.clearCachedCredentials = function(continuation) { | ||
XMPPSocialProvider.prototype.clearCachedCredentials = function(continuation) { | ||
delete this.credentials; | ||
@@ -337,2 +341,13 @@ continuation(); | ||
if (msg.is('message') && msg.getChildText('body') && msg.attrs.type !== 'error') { | ||
if (!this.vCardStore.hasClient(msg.attrs.from)) { | ||
// If we don't already have a client for the message sender, create a | ||
// client with ONLINE_WITH_OTHER_APP. If we don't do this, we may emit | ||
// onClientState events without any status field. | ||
// See https://github.com/uProxy/uproxy/issues/892 for more info. | ||
// TODO: periodically re-sync the roster so we don't keep this client | ||
// ONLINE_WITH_OTHER_APP forever. | ||
// https://github.com/freedomjs/freedom-social-xmpp/issues/107 | ||
this.vCardStore.updateProperty( | ||
msg.attrs.from, 'status', 'ONLINE_WITH_OTHER_APP'); | ||
} | ||
this.sawClient(msg.attrs.from); | ||
@@ -339,0 +354,0 @@ // TODO: check the agent matches our resource Id so we don't pick up chats not directed |
@@ -35,2 +35,6 @@ /*globals freedom:true,setTimeout,window,VCardStore:true */ | ||
VCardStore.prototype.hasClient = function(user) { | ||
return this.clients[user] ? true : false; | ||
}; | ||
VCardStore.prototype.getClient = function(user) { | ||
@@ -50,3 +54,3 @@ var userid = new window.XMPP.JID(user).bare().toString(), state = { | ||
} | ||
return state; | ||
@@ -59,3 +63,3 @@ }; | ||
if (this.clients.hasOwnProperty(client)) { | ||
cards[client] = this.getClient(client); | ||
cards[client] = this.getClient(client); | ||
} | ||
@@ -70,3 +74,3 @@ } | ||
}; | ||
if (this.users[user]) { | ||
@@ -73,0 +77,0 @@ state.lastSeen = this.clients[user].lastSeen; |
{ | ||
"name": "freedom-social-xmpp", | ||
"description": "XMPP Social provider for freedomjs", | ||
"version": "0.3.12", | ||
"version": "0.3.13", | ||
"homepage": "http://freedomjs.org", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -24,2 +24,8 @@ describe("Tests for message batching in Social provider", function() { | ||
beforeEach(function() { | ||
var knownClients = { | ||
'Alice': {clientId: 'Alice', status: 'ONLINE'}, | ||
'Bob': {clientId: 'Bob', status: 'ONLINE'}, | ||
'myId': {clientId: 'myId', status: 'ONLINE'}, | ||
'fromId': {clientId: 'fromId', status: 'ONLINE'} | ||
}; | ||
spyOn(window, "VCardStore").and.returnValue({ | ||
@@ -29,8 +35,18 @@ loadCard: function() {}, | ||
onClientChange: function() {}, | ||
updateProperty: function() {}, | ||
updateProperty: function(clientId, property, value) { | ||
if (property == 'status') { | ||
knownClients[clientId] = {clientId: clientId, status: value}; | ||
} | ||
}, | ||
refreshContact: function() {}, | ||
getClient: function(clientId) { | ||
return { | ||
status: "ONLINE" | ||
}; | ||
// getClient defaults status=OFFLINE if the client is unknown | ||
if (knownClients[clientId]) { | ||
return knownClients[clientId]; | ||
} else { | ||
return {clientId: clientId, status: 'OFFLINE'}; | ||
} | ||
}, | ||
hasClient: function(clientId) { | ||
return knownClients[clientId] ? true : false; | ||
} | ||
@@ -43,2 +59,3 @@ }); | ||
xmppSocialProvider.client = xmppClient; | ||
xmppSocialProvider.id = 'myId'; | ||
xmppSocialProvider.loginOpts = {}; | ||
@@ -240,5 +257,4 @@ spyOn(xmppSocialProvider.client, 'send'); | ||
var fromClient = xmppSocialProvider.vCardStore.getClient('fromId'); | ||
var toClient = xmppSocialProvider.vCardStore.getClient('toId'); | ||
xmppSocialProvider.receiveMessage( | ||
fromClient, JSON.stringify(['abc', 'def'])); | ||
var toClient = xmppSocialProvider.vCardStore.getClient('myId'); | ||
xmppSocialProvider.receiveMessage('fromId', JSON.stringify(['abc', 'def'])); | ||
expect(xmppSocialProvider.dispatchEvent).toHaveBeenCalledWith( | ||
@@ -254,4 +270,4 @@ 'onMessage', {from: fromClient, to: toClient, message: 'abc'}); | ||
var fromClient = xmppSocialProvider.vCardStore.getClient('fromId'); | ||
var toClient = xmppSocialProvider.vCardStore.getClient('toId'); | ||
xmppSocialProvider.receiveMessage(fromClient, jsonString); | ||
var toClient = xmppSocialProvider.vCardStore.getClient('myId'); | ||
xmppSocialProvider.receiveMessage('fromId', jsonString); | ||
expect(xmppSocialProvider.dispatchEvent).toHaveBeenCalledWith( | ||
@@ -264,4 +280,4 @@ 'onMessage', {from: fromClient, to: toClient, message:jsonString}); | ||
var fromClient = xmppSocialProvider.vCardStore.getClient('fromId'); | ||
var toClient = xmppSocialProvider.vCardStore.getClient('toId'); | ||
xmppSocialProvider.receiveMessage(fromClient, 'hello'); | ||
var toClient = xmppSocialProvider.vCardStore.getClient('myId'); | ||
xmppSocialProvider.receiveMessage('fromId', 'hello'); | ||
expect(xmppSocialProvider.dispatchEvent).toHaveBeenCalledWith( | ||
@@ -271,3 +287,3 @@ 'onMessage', {from: fromClient, to: toClient, message: 'hello'}); | ||
it('end event rejects connect if not online', function() { | ||
it('end event rejects connect if logging in', function() { | ||
spyOn(window.XMPP, 'Client').and.returnValue(xmppClient); | ||
@@ -291,2 +307,31 @@ var continuationSpy = jasmine.createSpy('spy'); | ||
}); | ||
it('end event is ignored when user has logged out', function() { | ||
spyOn(window.XMPP, 'Client').and.returnValue(xmppClient); | ||
var continuationSpy = jasmine.createSpy('spy'); | ||
xmppSocialProvider.connect(continuationSpy); | ||
spyOn(xmppSocialProvider, 'logout'); | ||
xmppSocialProvider.client.events['online'](); | ||
expect(continuationSpy.calls.count()).toBe(1); | ||
xmppSocialProvider.logout(); | ||
expect(xmppSocialProvider.logout.calls.count()).toBe(1); | ||
expect(continuationSpy.calls.count()).toBe(1); | ||
}); | ||
it('creates ONLINE_WITH_OTHER_APP client for messages from unknown client', | ||
function() { | ||
spyOn(xmppSocialProvider, 'dispatchEvent'); | ||
var message = new window.XMPP.Element( | ||
'message', {type: 'chat', from: 'unknownClient'}) | ||
.c('body').t('hello').up().up(); | ||
xmppSocialProvider.onMessage(message); | ||
expect(xmppSocialProvider.dispatchEvent).toHaveBeenCalledWith( | ||
'onMessage', | ||
{ | ||
from: {clientId: 'unknownClient', status: 'ONLINE_WITH_OTHER_APP'}, | ||
to: {clientId: 'myId', status: 'ONLINE' }, | ||
message: 'hello' | ||
}); | ||
}); | ||
}); |
@@ -40,3 +40,3 @@ /*jslint white:true,sloppy:true */ | ||
this.MAX_MS_WITHOUT_COMMUNICATION_ = 60000; | ||
this.MAX_MS_PING_REPSONSE_ = 10000; | ||
this.MAX_MS_PING_REPSONSE_ = 5000; | ||
@@ -183,10 +183,12 @@ // Metadata about the roster | ||
this.client.addListener('close', function(e) { | ||
// This may indicate a broken connection to XMPP. | ||
// TODO: handle this. | ||
this.logger.error('received unhandled close event', e); | ||
this.logger.error('received close event', e); | ||
if (this.status === 'ONLINE') { | ||
// Check if we are still online, otherwise log out. | ||
this.ping_(); | ||
} | ||
}.bind(this)); | ||
this.client.addListener('end', function(e) { | ||
this.logger.error('received end event, status: ' + this.status, e); | ||
if (this.status !== 'ONLINE') { | ||
// Reject login promise. | ||
if (this.status !== 'ONLINE' && this.client) { | ||
// Login is still pending, reject the login promise. | ||
this.logger.error('Received end event while logging in'); | ||
continuation(undefined, { | ||
@@ -196,3 +198,5 @@ errcode: 'LOGIN_FAILEDCONNECTION', | ||
}); | ||
} else { | ||
} else if (this.client) { | ||
// Got an 'end' event without logout having been called, call logout. | ||
this.logger.error('Received unexpected end event'); | ||
this.logout(); | ||
@@ -208,3 +212,3 @@ } | ||
*/ | ||
XMPPSocialProvider.prototype.clearCachedCredentials = function(continuation) { | ||
XMPPSocialProvider.prototype.clearCachedCredentials = function(continuation) { | ||
delete this.credentials; | ||
@@ -337,2 +341,13 @@ continuation(); | ||
if (msg.is('message') && msg.getChildText('body') && msg.attrs.type !== 'error') { | ||
if (!this.vCardStore.hasClient(msg.attrs.from)) { | ||
// If we don't already have a client for the message sender, create a | ||
// client with ONLINE_WITH_OTHER_APP. If we don't do this, we may emit | ||
// onClientState events without any status field. | ||
// See https://github.com/uProxy/uproxy/issues/892 for more info. | ||
// TODO: periodically re-sync the roster so we don't keep this client | ||
// ONLINE_WITH_OTHER_APP forever. | ||
// https://github.com/freedomjs/freedom-social-xmpp/issues/107 | ||
this.vCardStore.updateProperty( | ||
msg.attrs.from, 'status', 'ONLINE_WITH_OTHER_APP'); | ||
} | ||
this.sawClient(msg.attrs.from); | ||
@@ -339,0 +354,0 @@ // TODO: check the agent matches our resource Id so we don't pick up chats not directed |
@@ -35,2 +35,6 @@ /*globals freedom:true,setTimeout,window,VCardStore:true */ | ||
VCardStore.prototype.hasClient = function(user) { | ||
return this.clients[user] ? true : false; | ||
}; | ||
VCardStore.prototype.getClient = function(user) { | ||
@@ -50,3 +54,3 @@ var userid = new window.XMPP.JID(user).bare().toString(), state = { | ||
} | ||
return state; | ||
@@ -59,3 +63,3 @@ }; | ||
if (this.clients.hasOwnProperty(client)) { | ||
cards[client] = this.getClient(client); | ||
cards[client] = this.getClient(client); | ||
} | ||
@@ -70,3 +74,3 @@ } | ||
}; | ||
if (this.users[user]) { | ||
@@ -73,0 +77,0 @@ state.lastSeen = this.clients[user].lastSeen; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
887149
26932