Skip to content

Commit

Permalink
adding index route. adding some socket stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
soldair committed Nov 10, 2012
1 parent ac49eb1 commit 22cc57e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
50 changes: 43 additions & 7 deletions index.js
Expand Up @@ -3,6 +3,7 @@ var tako = require('tako')
, packagejson = require('./package.json')
, oppressor = require('oppressor')
, path = require('path')
, fs = require('fs')
, EventEmitter = require('events').EventEmitter
;

Expand All @@ -14,11 +15,12 @@ module.exports = function(config){

config = config||{};

//
// create tako
//
var app = tako()

em.routes = function(){
//
// create tako
//
var app = tako()

//
// static content
Expand All @@ -28,9 +30,8 @@ module.exports = function(config){
//
// shim fake index
//
app.route('/',function(req,res){
res.end('yo yo homies');
});
var index = fs.readFileSync('./static/index.html');
app.route('/').html(index);

//
// add the bundle
Expand All @@ -53,12 +54,47 @@ module.exports = function(config){
app.route('/package').json(JSON.stringify(packagejson)+"\n");
};

em.sockets = {};

em.sockets = function(){
var z = this;
z.app.sockets.manager.settings['log level'] = 2;
z.app.sockets.on('connection',function(socket){
console.log('client connected! ',socket.id);

z.sockets[socket.id] = socket;

socket.on('disconnect',function(){
z.emit('disconnect',socket.id);
delete z.sockets[socket.id];
});

// who am i.
socket.emit('id',id);

z.emit('connection',socket);
});
};

em.observeSelf = function(){
var z = this;
z.on('disconnect',function(){
//z.app.socketsbroadcast('logout')
console.log('socket disconnected');
});
};

//
// listen.
//
em.listen = function(port,cb){
app.httpServer.listen(port,cb);
};

em.app = app;
em.observeSelf();
em.routes();
em.sockets();

return em;
}
Expand Down
1 change: 0 additions & 1 deletion server.js
Expand Up @@ -3,7 +3,6 @@ var config = require('./lib/config')

var port = config.port||process.env.PORT||8000;

console.log(config);

app.listen(port,function(){
console.log('server is listening. woooo! ',port);
Expand Down

0 comments on commit 22cc57e

Please sign in to comment.