Permalink
Browse files

nicer syntax for setting up listeners and installing

  • Loading branch information...
1 parent 1a6a712 commit a60e894ac86614c9d3308446fcfd788d0727c74a @substack committed Jun 23, 2012
Showing with 31 additions and 4 deletions.
  1. +2 −3 example/invert/server.js
  2. +28 −1 index.js
  3. +1 −0 package.json
View
@@ -6,8 +6,7 @@ var es = require('event-stream');
var server = http.createServer(ecstatic);
server.listen(9999);
-var sock = shoe.createServer();
-sock.on('connection', function (stream) {
+var sock = shoe(function (stream) {
var iv = setInterval(function () {
stream.write(Math.floor(Math.random() * 2));
}, 250);
@@ -18,4 +17,4 @@ sock.on('connection', function (stream) {
stream.pipe(process.stdout, { end : false });
});
-sock.installHandlers(server, { prefix : '/invert' });
+sock.install(server, '/invert');
View
@@ -1 +1,28 @@
-module.exports = require('sockjs');
+var sockjs = require('sockjs');
+
+exports = module.exports = function (opts, cb) {
+ if (typeof opts === 'function') {
+ cb = opts;
+ opts = {};
+ }
+ var server = sockjs.createServer();
+ if (typeof cb === 'function') {
+ server.on('connection', cb);
+ }
+ server.install = function (httpServer, hopts) {
+ if (hopts && hopts.listen && !httpServer.listen) {
+ httpServer = arguments[1];
+ hopts = arguments[0];
+ }
+ if (typeof hopts === 'string') {
+ hopts = { prefix : hopts };
+ }
+ server.installHandlers(httpServer, hopts);
+ };
+
+ return server;
+};
+
+Object.keys(sockjs).forEach(function (key) {
+ exports[key] = sockjs[key];
+});
View
@@ -3,6 +3,7 @@
"version" : "0.0.0",
"description" : "streaming sockjs for node and the browser",
"main" : "index.js",
+ "browserify" : "browser.js",
"directories" : {
"example" : "example"
},

0 comments on commit a60e894

Please sign in to comment.