@@ -7,7 +7,7 @@ var app = require('http').createServer(handler)
77 , db = new mongo . Db ( 'daimio' , new mongo . Server ( 'localhost' , 27017 , { auto_reconnect : true } ) , { w : 0 } ) ;
88
99// io.set('log level', 0)
10-
10+
1111var D = require ( 'daimio' )
1212D . db = db
1313D . mongo = mongo
@@ -22,52 +22,52 @@ var onerror = function(err) {
2222 return console . log ( err )
2323} ;
2424
25- // Configure our HTTP server
25+ // Configure our HTTP server
2626function handler ( req , res ) {
2727 // if(/public\//.test(req.url)) { // public files
2828 // fileServer.serve(req, res);
2929 // res.end();
3030 // return;
3131 // }
32-
32+
3333 if ( req . url === '/favicon.ico' ) { // favicon
3434 res . writeHead ( 200 , { 'Content-Type' : 'image/x-icon' } ) ;
3535 res . end ( ) ;
3636 return ;
3737 }
38-
38+
3939 // if(req.method == 'POST') {
4040 // var body = '';
4141 // req.on('data', function (data) {
4242 // body += data;
4343 // if(body.length > 1e6) req.connection.destroy();
4444 // })
45- //
45+ //
4646 // req.on('end', function () {
4747 // var POST = qs.parse(body); // no multipart forms // POST["node[name]"]
48- //
48+ //
4949 // // HEY!! just bounce only bounce check header for ME
5050 // // then do like the DMG thing
51- //
52- //
51+ //
52+ //
5353 // global.output = [];
54- //
54+ //
5555 // // if(POST.daimio) {
5656 // // this_html += D.run(POST.daimio);
5757 // // TODO: allow text through here, not just json
58- // // }
59- //
58+ // // }
59+ //
6060 // res.writeHead(200, {"Content-Type": "application/json"});
61- //
61+ //
6262 // // D.add_global('POST', POST);
6363 // D.run(POST.daimio, function(value) {
6464 // res.end(JSON.stringify(global.output));
6565 // });
66- //
66+ //
6767 // });
6868 // return;
6969 // }
70-
70+
7171 res . writeHead ( 200 , { "Content-Type" : "text/html" } ) ;
7272 res . end ( html ) ;
7373}
@@ -76,49 +76,49 @@ function handler (req, res) {
7676db . open ( function ( err , db ) {
7777 if ( err ) return onerror ( 'DB refused to open: ' , err ) ;
7878
79- // console.log('connected!');
80-
79+ // console.log('connected!');
80+
8181 app . listen ( 8000 ) ;
82-
82+
8383 // io.on('connection', function (socket) {
8484 // socket.on('bounce', function (data) {
8585 // io.sockets.emit('bounced', data)
8686 // console.log(['bouncing', data])
8787 // })
8888 // })
89-
89+
9090} ) ;
9191
9292var last_user_id = 0
9393 // , password = 'kjh1234kljh1324uiyhiuhfs98dfosdfhk2j3hk2jhsdfya9sd8fyasdfjh2k3jh234239uvnm23'
9494
9595io . on ( 'connection' , function ( socket ) {
96- //
96+ //
9797 // socket.on('process', function (data) {
98- // if(!data.daimio)
98+ // if(!data.daimio)
9999 // return false
100- //
100+ //
101101 // D.run(data.daimio, function(value) { // TODO: add 'context' for run
102102 // io.sockets.emit('return', value) // TODO: return just to asker [maybe use jDaimio for this?]
103103 // })
104104 // })
105-
105+
106106 last_user_id += 1
107107 var user_id = last_user_id
108-
108+
109109 socket . on ( 'bounce' , function ( data ) {
110110 data . user = user_id
111111 io . sockets . emit ( 'bounced' , data )
112112 console . log ( [ 'bouncing' , data ] )
113113 } )
114-
114+
115115 socket . on ( 'disconnect' , function ( ) {
116116 io . sockets . emit ( 'disconnected' , { user : user_id } ) ;
117117 } ) ;
118-
118+
119119 io . sockets . emit ( 'connected' , { user : user_id } )
120-
120+
121121 for ( var i = 1 ; i < last_user_id ; i ++ ) {
122122 socket . emit ( 'add-user' , { user : i } )
123123 }
124- } )
124+ } )
0 commit comments