diff --git a/hookio/dummyServer.js b/hookio/dummyServer.js index e534469..ba6d1e2 100644 --- a/hookio/dummyServer.js +++ b/hookio/dummyServer.js @@ -3,7 +3,7 @@ io.sockets.on('connection', function (socket) { console.log("New connection!"); socket.on('test', function (data,ack) { console.log(data); - var testObject = {"testKey" : "testValue", "testArray": ["value1", "value2", "value3"], "testDic": {"key1":"value1","key2":"value2"}, "testMix":["one",{"twoDic":["one","two"]}]}; + var testObject = {"testKey" : "testValue", "testArray": ["value1", "value2", "value3"], "testDic": {"key1":"value1","key2":"value2"}, "testMix":["one",{"twoDic":[1,2,"2",2.0,2.1]}],"specialKey":"Ñoña-2_3"}; ack(testObject); console.log("I acked"); }); diff --git a/hookio/monkey/index.jade b/hookio/monkey/index.jade index cfd1a5e..5fb395f 100644 --- a/hookio/monkey/index.jade +++ b/hookio/monkey/index.jade @@ -13,6 +13,7 @@ html }); socket.on('announcement', function (msg) { + console.log("Received announcement"); $('#lines').append($('
').append($('').text(msg))); }); @@ -24,7 +25,7 @@ html }); socket.on('user message', function(data){ - message('cmd',data); + message('>',data); }); socket.on('execute', message); socket.on('reconnect', function () { @@ -59,18 +60,38 @@ html $('#send-message').submit(function () { var msg = $('#message').val(); - if(msg.charAt(0)!='/'){ - message('me', msg); - socket.emit('user message', msg); - } - else{ + if(msg.charAt(0)=='/'){ var i = msg.indexOf(' '); var data = {}; data['name'] = msg.substring(1,i); - data['payload'] = msg.substring(i); + var payload = msg.substring(i); + try{ + payload = jQuery.parseJSON(payload); + }catch(err){ + console.log("Not json"); + } + data['payload'] = payload; message('Exec:', msg); - socket.emit('command', data); - } + socket.emit('execute', data); + } + else if(msg.charAt(0)=='$'){ + var i = msg.indexOf(' '); + var data = msg.substring(1); + console.log("Client:"+data); + message("Client:"+data); + try{ + data = jQuery.parseJSON(data); + }catch(err){ + console.log("Not json"+err); + } + console.log("Client(final):"+JSON.stringify(data)); + socket.emit('client', data); + } + else{ + message('me', msg); + socket.emit('user message', msg); + } + clear(); $('#lines').get(0).scrollTop = 10000000; return false; diff --git a/hookio/monkey/monkey.js b/hookio/monkey/monkey.js index 10b915e..74f0c9c 100755 --- a/hookio/monkey/monkey.js +++ b/hookio/monkey/monkey.js @@ -5,7 +5,7 @@ var Hook = require('hook.io').Hook, app = express.createServer(), io = require('socket.io').listen(app); - app.configure(function () { +app.configure(function () { app.use(stylus.middleware({ src: __dirname + '/public', compile: compile })); app.use(express.static(__dirname + '/public')); app.set('views', __dirname); @@ -42,7 +42,7 @@ app.listen(3000, function () { console.log('app listening on http://' + addr.address + ':' + addr.port); }); -monkey.connect(1337); +monkey.listen(1337); var nicknames = {}; @@ -51,11 +51,26 @@ io.sockets.on('connection', function (socket) { socket.on('user message', function (data) { console.log(data); }); - socket.on('command', function (data,fn) { + socket.on('execute', function (data,fn) { var name = data['name']; var payload = data['payload']; console.log('Executing '+name+' with '+payload); - monkey.emit(name,payload,fn); + try{ + monkey.emit(name,payload,fn); + }catch(err){ + console.log("Error:"+err); + } + }); + socket.on('client', function(data,fn){ + var id = data['id']; + var name = data['name']; + var payload = data['payload']; + console.log('Clienting '+name+'@'+id+' with '+payload); + try{ + nicknames[id].emit(name,payload,fn); + }catch(err){ + console.log("Error:"+err); + } }); socket.on('nickname', function (nick, fn) { if (nicknames[nick]) { @@ -68,7 +83,7 @@ io.sockets.on('connection', function (socket) { }); socket.on('disconnect', function () { if (!socket.nickname) return; - delete nicknames[socket.nickname]; + delete nicknames[socket.nickname]; }); });