From 80b7547cfa4cfb76e58038a0a47316dcc7d13751 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Mon, 5 Sep 2011 21:24:26 -0400 Subject: [PATCH 1/8] add node_modules to gitignore, add package.json --- .gitignore | 3 ++- package.json | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 package.json diff --git a/.gitignore b/.gitignore index f56bae4..33bc5d2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ rsync.sh *.swp *.log -.monitor \ No newline at end of file +.monitor +node_modules/ diff --git a/package.json b/package.json new file mode 100644 index 0000000..e9d9976 --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "scrumblr", + "description": "Web-based simulation of a physical agile sprint board that supports real-time collaboration.", + "version": "0.1.0", + "repository": { + "url": "http://github.com/aliasaria/scrumblr" + }, + "author": "Ali Asaria", + "main": "server.js", + "directories": { + "lib": "lib/" + }, + "engines": { + "node": "0.4.7" + }, + "dependencies": { + "async": "0.1.x", + "connect": "1.7.x", + "redis-client": "0.3.x", + "redis": "0.6.x", + "sanitizer": "0.0.x", + "socket.io": "0.8.x", + "simplesets": "1.1.x", + "connect-redis":"1.0.x", + "express": "2.4.x", + "jade": "0.14.x" + } +} From 5c5ce328e688a8150b3968afb2c224fe15dc21ec Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Mon, 5 Sep 2011 21:27:22 -0400 Subject: [PATCH 2/8] update client script for new x.json.x syntax --- client/script.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/script.js b/client/script.js index 81d0594..9929466 100644 --- a/client/script.js +++ b/client/script.js @@ -5,9 +5,7 @@ var currentTheme = "bigcards"; var boardInitialized = false; -var socket = new io.Socket( ); -socket.connect(); - +var socket = io.connect(); //an action has happened, send it to the //server @@ -20,7 +18,7 @@ function sendAction(a, d) data: d } - socket.send ( message ); + socket.json.send ( message ); } socket.on('connect', function(){ From 453745dd4b2c099e1c34f8361b40823c245aea95 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Mon, 5 Sep 2011 21:31:45 -0400 Subject: [PATCH 3/8] use new configuration format --- server.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 25d9b34..b1f7cec 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,4 @@ var http = require('http'), - io = require('socket.io'), // for npm, otherwise use require('./path/to/socket.io') express = require('express'), connect = require('connect'); @@ -73,10 +72,18 @@ app.listen(process.argv[2] || 8124); var socketio_options = { transports: ['websocket', 'flashsocket', 'htmlfile', 'jsonp-polling'] }; - // socket.io SETUP -var socket = io.listen(app, socketio_options); -socket.on('connection', function(client){ +var io = require('socket.io').listen(app); +io.configure(function () { + io.set('transports', [ + 'websocket' + , 'flashsocket' + , 'htmlfile' +// , 'xhr-polling' + , 'jsonp-polling' + ]); +}); +io.sockets.on('connection', function (client) { // new client is here! //console.dir(client.request.headers); // From 2e7b58ae8543b665aa82ae3fe21da0eb5c9d0dd5 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Mon, 5 Sep 2011 21:34:44 -0400 Subject: [PATCH 4/8] update to new x.json.x syntax on server --- server.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index b1f7cec..9c46bf0 100644 --- a/server.js +++ b/server.js @@ -134,7 +134,7 @@ function scrub( text ) { joinRoom(client, message.data, function(clients) { - client.send( { action: 'roomAccept', data: '' } ); + client.json.send( { action: 'roomAccept', data: '' } ); }); @@ -340,7 +340,7 @@ function initClient ( client ) db.getAllCards( room , function (cards) { - client.send( + client.json.send( { action: 'initCards', data: cards @@ -351,7 +351,7 @@ function initClient ( client ) db.getAllColumns ( room, function (columns) { - client.send( + client.json.send( { action: 'initColumns', data: columns @@ -364,7 +364,7 @@ function initClient ( client ) if (theme == null) theme = 'bigcards'; - client.send( + client.json.send( { action: 'changeTheme', data: theme @@ -375,7 +375,7 @@ function initClient ( client ) db.getBoardSize( room, function(size) { if (size != null) { - client.send( + client.json.send( { action: 'setBoardSize', data: size @@ -401,7 +401,7 @@ function initClient ( client ) } console.log('initialusers: ' + roommates); - client.send( + client.json.send( { action: 'initialUsers', data: roommates From d03cc8ba383638e2d94b65db301c43f200f248c7 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Mon, 5 Sep 2011 22:17:30 -0400 Subject: [PATCH 5/8] sessionId to id --- server.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server.js b/server.js index 9c46bf0..17b8743 100644 --- a/server.js +++ b/server.js @@ -285,7 +285,7 @@ function scrub( text ) { var msg = {}; msg.action = 'nameChangeAnnounce'; - msg.data = { sid: client.sessionId, user_name: clean_message.data }; + msg.data = { sid: client.id, user_name: clean_message.data }; broadcastToRoom( client, msg ); break; @@ -390,11 +390,11 @@ function initClient ( client ) var j = 0; for (i in roommates_clients) { - if (roommates_clients[i].sessionId != client.sessionId) + if (roommates_clients[i].id != client.id) { roommates[j] = { - sid: roommates_clients[i].sessionId, - user_name: sids_to_user_names[roommates_clients[i].sessionId] + sid: roommates_clients[i].id, + user_name: sids_to_user_names[roommates_clients[i].id] }; j++; } @@ -416,7 +416,7 @@ function joinRoom (client, room, successFunction) { var msg = {}; msg.action = 'join-announce'; - msg.data = { sid: client.sessionId, user_name: client.user_name }; + msg.data = { sid: client.id, user_name: client.user_name }; rooms.add_to_room_and_announce(client, room, msg); successFunction(); @@ -424,13 +424,13 @@ function joinRoom (client, room, successFunction) function leaveRoom (client) { - console.log (client.sessionId + ' just left'); + console.log (client.id + ' just left'); var msg = {}; msg.action = 'leave-announce'; - msg.data = { sid: client.sessionId }; + msg.data = { sid: client.id }; rooms.remove_from_all_rooms_and_announce(client, msg); - delete sids_to_user_names[client.sessionId]; + delete sids_to_user_names[client.id]; } function broadcastToRoom ( client, message ) { @@ -464,7 +464,7 @@ function roundRand( max ) function getRoom( client , callback ) { room = rooms.get_room( client ); - //console.log( 'client: ' + client.sessionId + " is in " + room); + //console.log( 'client: ' + client.id + " is in " + room); callback(room); } @@ -472,7 +472,7 @@ function getRoom( client , callback ) function setUserName ( client, name ) { client.user_name = name; - sids_to_user_names[client.sessionId] = name; + sids_to_user_names[client.id] = name; console.log('sids to user names: '); console.dir(sids_to_user_names); } From 0a3b02cf7df12d3169f2e11928b3d30c20ccb966 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Tue, 6 Sep 2011 00:06:01 -0400 Subject: [PATCH 6/8] sessionId to id in lib/rooms.js --- lib/rooms.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/rooms.js b/lib/rooms.js index d52c5c0..8f67f1b 100644 --- a/lib/rooms.js +++ b/lib/rooms.js @@ -22,10 +22,10 @@ var sid_rooms = {}; // Add a client to a room and return the sid:client mapping. exports.add_to_room = function (client, room, callback) { - //console.log('Client ' + client.username + ' (' + client.sessionId + ') added to room ' + room); + //console.log('Client ' + client.username + ' (' + client.id + ') added to room ' + room); - if (!(sid_rooms.hasOwnProperty(client.sessionId))) sid_rooms[client.sessionId] = new sets.Set(); - sid_rooms[client.sessionId].add(room); + if (!(sid_rooms.hasOwnProperty(client.id))) sid_rooms[client.id] = new sets.Set(); + sid_rooms[client.id].add(room); if (!(rooms.hasOwnProperty(room))) rooms[room] = new sets.Set(); rooms[room].add(client); @@ -40,8 +40,8 @@ exports.add_to_room = function (client, room, callback) { // mapping for everybody in those rooms. exports.remove_from_all_rooms = function (client, callback) { var affected_clients = new sets.Set(); - if (sid_rooms.hasOwnProperty(client.sessionId)) { - var client_rooms = sid_rooms[client.sessionId].array(); + if (sid_rooms.hasOwnProperty(client.id)) { + var client_rooms = sid_rooms[client.id].array(); for (var i = 0; i < client_rooms.length; i++) { var room = client_rooms[i]; if (rooms.hasOwnProperty(room)) { @@ -61,8 +61,8 @@ exports.remove_from_all_rooms = function (client, callback) { } } } - console.log('Client ' + client.username + ' (' + client.sessionId + ') disconnected.'); - delete sid_rooms[client.sessionId]; + console.log('Client ' + client.username + ' (' + client.id + ') disconnected.'); + delete sid_rooms[client.id]; callback(affected_clients.array()); } @@ -122,9 +122,9 @@ exports.room_clients_other_than_me = function(room, client) { //gets the current room of the client (assumes one room -- will select first one if in multiple) exports.get_room = function (client) { - if (sid_rooms.hasOwnProperty(client.sessionId)) + if (sid_rooms.hasOwnProperty(client.id)) { - var client_rooms = sid_rooms[client.sessionId].array(); + var client_rooms = sid_rooms[client.id].array(); } if ( typeof(client_rooms) != undefined ) @@ -143,7 +143,7 @@ exports.add_to_room_and_announce = function (client, room, msg) { // Broadcast new-user notification for (var i = 0; i < clients.length; i++) { - if (clients[i].sessionId != client.sessionId) + if (clients[i].id != client.id) clients[i].send(msg); } }); @@ -170,7 +170,7 @@ exports.remove_from_all_rooms_and_announce = function (client, msg) { exports.remove_from_all_rooms(client, function(clients) { for (var i = 0; i < clients.length; i++) { - if (clients[i].sessionId != client.sessionId) + if (clients[i].id != client.id) clients[i].send(msg); } }); @@ -199,9 +199,9 @@ exports.broadcast_room = function(room, msg) { exports.broadcast_to_roommates = function (client, msg) { var roommates = new sets.Set(); - if (sid_rooms.hasOwnProperty(client.sessionId)) + if (sid_rooms.hasOwnProperty(client.id)) { - var client_rooms = sid_rooms[client.sessionId].array(); + var client_rooms = sid_rooms[client.id].array(); for (var i = 0; i < client_rooms.length; i++) { var room = client_rooms[i]; @@ -218,12 +218,12 @@ exports.broadcast_to_roommates = function (client, msg) { roommates.remove(client); roommates = roommates.array(); - console.log('client: ' + client.sessionId + " is broadcasting to: "); + console.log('client: ' + client.id + " is broadcasting to: "); for (var i = 0; i < roommates.length; i++) { - console.log(' - ' + roommates[i].sessionId); + console.log(' - ' + roommates[i].id); roommates[i].send(msg); } -} \ No newline at end of file +} From 6a8829aedcf98c0c2dc096614827154ccadaa7b1 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Tue, 6 Sep 2011 00:37:55 -0400 Subject: [PATCH 7/8] replace dependency list with npm install --- README.markdown | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/README.markdown b/README.markdown index 34db3ec..5d4754c 100644 --- a/README.markdown +++ b/README.markdown @@ -40,19 +40,9 @@ how to install and run on your own computer (linux/osx) ------------------------------------------------------- - install redis v2.2.2 -- install node.js >= 0.4.1 +- install node.js >= 0.4.7 - install npm -- install these npm packages: - - async - - express - - jade - - redis-client - - redis - - sanitizer - - socket.io@0.6.16 (you need to install a 0.6.x version of socket.io until the code is updated to work with the 0.7.x version) - - simplesets - - connect-redis - - (and perhaps more which you will notice when you try to start it) +- run `npm install` - now start redis ($ redis-server) - now start ($ node server.js 80) where "80" is the port you want it to run on. From 309cf806264f6b7ae26df8e0de79d4c747bf2efd Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Fri, 23 Sep 2011 09:12:46 -0400 Subject: [PATCH 8/8] use new-style .nodemonignore --- nodemon-ignore => .nodemonignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nodemon-ignore => .nodemonignore (100%) diff --git a/nodemon-ignore b/.nodemonignore similarity index 100% rename from nodemon-ignore rename to .nodemonignore