Permalink
Browse files

Comet goes directly to hub

  • Loading branch information...
1 parent ba1028d commit 20d7f6cd65e2fc51d377e8cda7e9cd5067eda0c2 @kriszyp kriszyp committed May 19, 2010
Showing with 9 additions and 22 deletions.
  1. +9 −22 lib/jsgi/comet.js
View
@@ -4,7 +4,7 @@
*/
var defer = require("promise").defer,
- MethodNotAllowedError = require("perstore/errors").MethodNotAllowedError;
+ hub = require("../hub");
/**
* Comet JSGI app factory that allows data to be sent to clients
*/
@@ -51,7 +51,7 @@ exports.Connections = function(nextApp){
setInterval(function(){
var thresholdTime = new Date().getTime() - exports.expirationTime;
while(leastRecentlyUsed && !leastRecentlyUsed.onMessages && leastRecentlyUsed.lastTouched < thresholdTime){
- leastRecentlyUsed.onClose && leastRecentlyUsed.onClose();
+ leastRecentlyUsed.onclose && leastRecentlyUsed.onclose();
delete connections[leastRecentlyUsed.clientId];
leastRecentlyUsed = leastRecentlyUsed.next;
delete leastRecentlyUsed.previous;
@@ -81,7 +81,7 @@ exports.Broadcaster = function(path, subscriptionApp, nextApp){
return sendAllMessages();
}else{
var deferred = defer(function(){
- clientConnection.onClose && clientConnection.onClose();
+ clientConnection.onclose && clientConnection.onclose();
});
clientConnection.onMessages = function(message){
clientConnection.lastTouched = new Date().getTime();
@@ -114,28 +114,15 @@ exports.Subscriber = function(subscriptions, nextApp){
}
subscriptions = subscriptions || request.input;
clientConnection = request.clientConnection;
+ var clientHub = hub.fromClient(clientConnection.clientId);
subscriptions.forEach(function(subscription){
- var parts = subscription.split('/');
- var store = request.store;
- for(var i = 1; i < parts.length - 1; i++){
- // allow for nested stores by incrementally traversing into stores
- store = store.openObjectStore(decodeURIComponent(parts[i]));
- }
- if(!store.subscribe && !store.__noSuchMethod__){
- throw new MethodNotAllowedError("Can not subscribe to the " + subscription.substring(0, subscription.length - parts[i].length) + " store");
- }
- if(store.subscribe){
- var subscription = store.subscribe(parts[i], function(message){
- clientConnection.send(message);
- });
- clientConnection.onClose = subscription.unsubscribe;
- }
- else{
- store.__noSuchMethod__(method, [parts[i], subscriptionHandler]);
- }
+ var subscription = clientHub.subscribe(request.pathInfo, function(message){
+ clientConnection.send(message);
+ });
+ clientConnection.onclose = subscription.unsubscribe;
});
return response;
- //response.headers.link = '<' + path + '>; rel="monitor"'; // we will just define the relationship in the schema
+ //response.headers.link = '<' + path + '>; rel="hub"'; // we will just define the relationship in the schema
//return response;
};
};

0 comments on commit 20d7f6c

Please sign in to comment.