radar_client
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -0,1 +1,7 @@ | ||
### 0.8.1 | ||
- when using presence v1 (without message options) | ||
- internally use presence v2 for v1 | ||
- translate v2 results to v1 format | ||
- alloc/ready logs only print when actually allocing | ||
### 0.8.0 | ||
@@ -2,0 +8,0 @@ - radar bump to v0.8.0 |
@@ -90,7 +90,11 @@ (function(){function require(e,t){for(var n=[],r=e.split("/"),i,s,o=0;s=r[o++];)".."==s?n.pop():"."!=s&&n.push(s);n=n.join("/"),o=require,s=o.m[t||0],i=s[n+".js"]||s[n+"/index.js"]||s[n];if(s=i.c)i=o.m[t=s][e=i.m];return i.exports||i(i,i.exports={},function(n){return o("."!=n.charAt(0)?n:e+"/../"+n,t)}),i.exports}; | ||
Client.prototype.alloc = function(name, callback) { | ||
this.logger().info({ op: 'alloc', name: name }); | ||
var self = this; | ||
if(!this._users[name]) { | ||
this.logger().info('alloc: ', name); | ||
this.once('ready', function() { | ||
self.logger().info('ready: ', name); | ||
}); | ||
} | ||
this._users[name] = true; | ||
callback && this.once('ready', function() { | ||
this.logger().info('ready', name); | ||
if(self._users.hasOwnProperty(name)) { | ||
@@ -211,4 +215,23 @@ callback(); | ||
// but it is actually a "online" message. | ||
// So force v2 and translate the result to v1 format. | ||
if (name == 'sync' && !message.options && scope.match(/^presence.+/)) { | ||
this.once(scope, callback); | ||
message.options = { version: 2 }; | ||
this.when('get', function(message) { | ||
var value = {}, userId; | ||
if (!message || !message.to || message.to != scope) { | ||
return false; | ||
} | ||
for (userId in message.value) { | ||
if (message.value.hasOwnProperty(userId)) { | ||
value[userId] = message.value[userId].userType; | ||
} | ||
} | ||
message.value = value; | ||
message.op = 'online'; | ||
if(callback) { | ||
callback(message); | ||
} | ||
return true; | ||
}); | ||
} else { | ||
@@ -215,0 +238,0 @@ this.when('get', function(message) { |
@@ -50,7 +50,11 @@ var log = require('minilog')('radar_client'), | ||
Client.prototype.alloc = function(name, callback) { | ||
this.logger().info({ op: 'alloc', name: name }); | ||
var self = this; | ||
if(!this._users[name]) { | ||
this.logger().info('alloc: ', name); | ||
this.once('ready', function() { | ||
self.logger().info('ready: ', name); | ||
}); | ||
} | ||
this._users[name] = true; | ||
callback && this.once('ready', function() { | ||
this.logger().info('ready', name); | ||
if(self._users.hasOwnProperty(name)) { | ||
@@ -171,4 +175,23 @@ callback(); | ||
// but it is actually a "online" message. | ||
// So force v2 and translate the result to v1 format. | ||
if (name == 'sync' && !message.options && scope.match(/^presence.+/)) { | ||
this.once(scope, callback); | ||
message.options = { version: 2 }; | ||
this.when('get', function(message) { | ||
var value = {}, userId; | ||
if (!message || !message.to || message.to != scope) { | ||
return false; | ||
} | ||
for (userId in message.value) { | ||
if (message.value.hasOwnProperty(userId)) { | ||
value[userId] = message.value[userId].userType; | ||
} | ||
} | ||
message.value = value; | ||
message.op = 'online'; | ||
if(callback) { | ||
callback(message); | ||
} | ||
return true; | ||
}); | ||
} else { | ||
@@ -175,0 +198,0 @@ this.when('get', function(message) { |
{ | ||
"name": "radar_client", | ||
"description": "Realtime apps with a high level API based on engine.io", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"author": "Mikito Takada <mikito.takada@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -411,15 +411,27 @@ var assert = require('assert'), | ||
'without options on a presence': { | ||
'should listen for messages on the given scope': function() { | ||
var called = false, | ||
scope = 'presence:/test/account/1', | ||
callback = function() {}; | ||
'should force v2, translate result from v2 to v1': function(done) { | ||
var scope = 'presence:/test/account/1'; | ||
client.once = function(operation, fn) { | ||
called = true; | ||
assert.equal(scope, operation); | ||
assert.equal(fn, callback); | ||
}; | ||
client.sync(scope, function(m) { | ||
assert.deepEqual({ | ||
op: 'online', | ||
to: scope, | ||
value: { | ||
100: 2, | ||
200: 0 | ||
} | ||
}, m); | ||
done(); | ||
}); | ||
client.sync(scope, callback); | ||
assert.ok(called); | ||
//previous online emits should not affect the callback | ||
client.emit(scope, { op: 'online', to: scope, value: { 100: 2 } }); | ||
client.emit('get', { | ||
op: 'get', to: scope, | ||
value: { | ||
100: { userType: 2, clients: {} }, | ||
200: { userType: 0, clients: {} } | ||
} | ||
}); | ||
} | ||
@@ -426,0 +438,0 @@ } |
99752
2710