Skip to content

Commit

Permalink
organizing app into public & server containers - moving socket to doo…
Browse files Browse the repository at this point in the history
…dle namespace
  • Loading branch information
Stephen Braitsch committed Jun 14, 2012
1 parent fbeb467 commit 38fcd21
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 92 deletions.
5 changes: 2 additions & 3 deletions app.js
Expand Up @@ -14,9 +14,8 @@ global.socket.set('transports', [ 'websocket', 'flashsocket', 'htmlfile', 'xhr-p

app.root = __dirname;

require('./app/core/config')(app, exp);
require('./app/router')(app);
require('./app/modules/doodle-socket');
require('./app/config')(app, exp);
require('./app/server/router')(app);

app.listen(8080, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
Expand Down
15 changes: 15 additions & 0 deletions app/config.js
@@ -0,0 +1,15 @@

module.exports = function(app, exp) {

app.configure(function(){
app.set('views', app.root + '/app/server/views');
app.set('view engine', 'jade');
app.set('view options', { doctype : 'html', pretty : true });
app.use(exp.bodyParser());
app.use(exp.methodOverride());
app.use(require('stylus').middleware({ src: app.root + '/app/public' }));
app.use(exp.static(app.root + '/app/server'));
app.use(exp.static(app.root + '/app/public'));
});

}
13 changes: 0 additions & 13 deletions app/core/config.js

This file was deleted.

21 changes: 0 additions & 21 deletions app/modules/doodle-socket.js

This file was deleted.

51 changes: 0 additions & 51 deletions app/modules/socket-manager.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
9 changes: 5 additions & 4 deletions app/js/canvas.js → app/public/js/canvas.js
Expand Up @@ -46,11 +46,12 @@ function iniDrawing()

function initSocket()
{
socket = io.connect();
socket.on('doodle-status', function (data) {
connections = data.connections;
socket = io.connect('/doodle');
socket.on('status', function (data) {
connections = data;
var i=0; for (p in connections) i++;
$('#connected').text(i + ' People Currently Connected');
var s = i > 1 ? ' are '+i+' People ' : ' is '+i+' Person ';
$('#connected').html('There '+s+' Currently Connected');
});
socket.on('draw-data', function (data) {
var k = connections[data.id];
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions app/server/modules/doodle-socket.js
@@ -0,0 +1,34 @@


module.exports = function()
{

var connections = { };

global.socket.of('/doodle').on('connection', function(socket) {
socket.on('draw-data', function(data) {
// append this socket's id so we know who is talking //
data.id = socket.id;
socket.broadcast.emit('draw-data', data);
});

function dispatchStatus()
{
brodcastMessage('status', connections);
}

function brodcastMessage(message, data)
{
// remove socket.emit if you don't want the sender to receive their own message //
socket.emit(message, data);
socket.broadcast.emit(message, data);
}

// handle connections & disconnections //
connections[socket.id] = {}; dispatchStatus();
socket.on('disconnect', function() {
delete connections[socket.id]; dispatchStatus();
});

});
}();
2 changes: 2 additions & 0 deletions app/router.js → app/server/router.js
@@ -1,4 +1,6 @@

require('./modules/doodle-socket');

module.exports = function(app) {

app.get('/', canvas);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 38fcd21

Please sign in to comment.