Permalink
Browse files

add custom events

  • Loading branch information...
1 parent c1a1841 commit 32d891b60f2f8a911965dde6433017c39c1550f3 @maccman maccman committed Oct 17, 2010
Showing with 20 additions and 1 deletion.
  1. +1 −1 client/lib/juggernaut.rb
  2. +5 −0 lib/juggernaut/client.js
  3. +3 −0 lib/juggernaut/connection.js
  4. +11 −0 lib/juggernaut/events.js
View
2 client/lib/juggernaut.rb
@@ -12,7 +12,7 @@ def publish(channels, data, options = {})
end
def subscribe
- Redis.new(redis_options).subscribe(key(:subscribe), key(:unsubscribe)) do |on|
+ Redis.new(redis_options).subscribe("juggernaut:*") do |on|
on.message do |type, msg|
yield(type.gsub(/^juggernaut:/, "").to_sym, JSON.parse(msg))
end
View
5 lib/juggernaut/client.js
@@ -2,6 +2,7 @@ var sys = require("sys");
var SuperClass = require("superclass");
var Channel = require("./channel");
var JUtils = require("jutils");
+var Events = require("./events");
Client = module.exports = new SuperClass;
@@ -15,6 +16,10 @@ Client.include({
this.meta = value;
},
+ event: function(data){
+ Events.custom(this, data);
+ },
+
subscribe: function(name){
sys.log("Client subscribing to: " + name);
View
3 lib/juggernaut/connection.js
@@ -30,6 +30,9 @@ Connection.include({
case "meta":
this.client.setMeta(message.data);
break;
+ case "event":
+ this.client.event(message.data);
+ break;
default:
throw "Unknown type"
}
View
11 lib/juggernaut/events.js
@@ -31,4 +31,15 @@ Events.unsubscribe = function(channel, client) {
session_id: client.session_id
}
);
+};
+
+Events.custom = function(client, data) {
+ this.publish(
+ "custom",
+ {
+ meta: client.meta,
+ session_id: client.session_id,
+ data: data
+ }
+ );
};

0 comments on commit 32d891b

Please sign in to comment.