Permalink
Browse files

THe notify.js and package.json files for node

  • Loading branch information...
gautamrege committed Jan 28, 2012
1 parent 7db4133 commit 25169ba0bcb168e8811c697a7907b9e9fe87189f
Showing with 43 additions and 0 deletions.
  1. +34 −0 notify.js
  2. +9 −0 package.json
View
@@ -0,0 +1,34 @@
+var express = require('express')
+ , app = express.createServer()
+ , io = require('socket.io').listen(app);
+
+
+app.use(express.bodyParser());
+app.listen(13002);
+
+var connections = {}
+
+/********** express.js routes ************/
+app.get('/', function (req, res) {
+ res.send(404);
+});
+
+app.post('/message/:action/:to', function (req, res) {
+ target = connections[req.params.to]
+ if (target) {
+ connections[req.params.to].emit(req.params.action, req.body);
+ res.send(200);
+ }
+ else
+ res.send(404);
+});
+
+/********** socket.io work ***************/
+io.sockets.on('connection', function(socket) {
+ socket.on('username', function(username) {
+ connections[username] = socket;
+ });
+
+});
+
+
View
@@ -0,0 +1,9 @@
+{
+ "name": "notify.js"
+ , "description": "Messaging service"
+ , "version": "0.0.1"
+ , "dependencies": {
+ "express": "2.3.11"
+ , "socket.io": "0.8.5"
+ }
+}

0 comments on commit 25169ba

Please sign in to comment.