Merge remote-tracking branch 'refs/remotes/wlangstroth/socketio08' into socketio08

Conflicts:
	README.markdown
This commit is contained in:
Ali Asaria 2011-09-24 12:54:34 -04:00
commit 0e164fce74
7 changed files with 77 additions and 54 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ rsync.sh
*.swp
*.log
.monitor
node_modules/

View file

@ -40,20 +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
- connect
- (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.

View file

@ -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(){

View file

@ -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);
}
}

28
package.json Normal file
View file

@ -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"
}
}

View file

@ -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);
//
@ -127,7 +134,7 @@ function scrub( text ) {
joinRoom(client, message.data, function(clients) {
client.send( { action: 'roomAccept', data: '' } );
client.json.send( { action: 'roomAccept', data: '' } );
});
@ -278,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;
@ -333,7 +340,7 @@ function initClient ( client )
db.getAllCards( room , function (cards) {
client.send(
client.json.send(
{
action: 'initCards',
data: cards
@ -344,7 +351,7 @@ function initClient ( client )
db.getAllColumns ( room, function (columns) {
client.send(
client.json.send(
{
action: 'initColumns',
data: columns
@ -357,7 +364,7 @@ function initClient ( client )
if (theme == null) theme = 'bigcards';
client.send(
client.json.send(
{
action: 'changeTheme',
data: theme
@ -368,7 +375,7 @@ function initClient ( client )
db.getBoardSize( room, function(size) {
if (size != null) {
client.send(
client.json.send(
{
action: 'setBoardSize',
data: size
@ -383,18 +390,18 @@ 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++;
}
}
console.log('initialusers: ' + roommates);
client.send(
client.json.send(
{
action: 'initialUsers',
data: roommates
@ -409,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();
@ -417,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 ) {
@ -457,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);
}
@ -465,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);
}