From 34083a8339889282e386d08391530cc3f47f14c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2EFernando=20S=C3=A1nchez?= Date: Fri, 25 May 2012 13:16:10 +0200 Subject: [PATCH] Changes to monkey, added scripts --- .gitignore | 2 +- executeWeb40.sh | 4 ++++ hookio/hooks/config.json | 1 + hookio/hooks/hookManager.coffee | 41 +++++++++++++++++++++++++++++++++ hookio/hooks/prueba.js | 3 +++ hookio/hooks/runAllHooks.sh | 11 +++++++-- hookio/monkey/monkey.js | 10 ++++---- install.sh | 4 ++++ package.json | 5 ++-- 9 files changed, 72 insertions(+), 9 deletions(-) create mode 100755 executeWeb40.sh create mode 100644 hookio/hooks/config.json create mode 100644 hookio/hooks/hookManager.coffee create mode 100644 hookio/hooks/prueba.js mode change 100644 => 100755 hookio/hooks/runAllHooks.sh diff --git a/.gitignore b/.gitignore index e6484b5..cc10f7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -tests +test configuration node_modules *.bak diff --git a/executeWeb40.sh b/executeWeb40.sh new file mode 100755 index 0000000..dc8dc6c --- /dev/null +++ b/executeWeb40.sh @@ -0,0 +1,4 @@ +#!/bin/bash +nodejs hookio/monkey/monkey.js > monkey.log & +hookio/hooks/runAllHooks.sh > hooks.log & +wait diff --git a/hookio/hooks/config.json b/hookio/hooks/config.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/hookio/hooks/config.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/hookio/hooks/hookManager.coffee b/hookio/hooks/hookManager.coffee new file mode 100644 index 0000000..6670842 --- /dev/null +++ b/hookio/hooks/hookManager.coffee @@ -0,0 +1,41 @@ +Web40Hook = require('hook.io-web40').Web40Hook + +stdin = process.openStdin(); +stdin.on 'data', (chunk) -> + killHook(chunk) + +killHook = (data)-> + hook.emit('kill',otherhooks[parseInt(data)], (res)-> + console.log('Killed the hook '+data) + otherhooks.splice(parseInt(data),1)) + +hook = new Web40Hook { name : 'hookManager' , silent : true} + + +otherhooks = [] + +hook.on '*::ready', -> + console.log 'listo' + +redraw = -> + process.stdout.write '\u001B[2J\u001B[0;0f' + process.stdout.write 'Hooks:\n' + for name,i in otherhooks + process.stdout.write '['+i+']: '+name+'\n' + +refresh = -> + otherhooks = [] + hook.emit 'ping', null, (name)-> + console.log('Reply by'+name) + setTimeout refresh, 2000 + +#//'\u001B[2J\u001B[0;0f' + +hook.on '*::pong', (data,fn) -> + console.log data.name+' replied' + if !(data.name in otherhooks) + otherhooks.push data.name + redraw() + +hook.connect() +refresh() diff --git a/hookio/hooks/prueba.js b/hookio/hooks/prueba.js new file mode 100644 index 0000000..71c710b --- /dev/null +++ b/hookio/hooks/prueba.js @@ -0,0 +1,3 @@ +var Web40Hook = require('./hook.io-web40').Web40; + +var Hook = new Web40Hook(); diff --git a/hookio/hooks/runAllHooks.sh b/hookio/hooks/runAllHooks.sh old mode 100644 new mode 100755 index 6070518..bb9d585 --- a/hookio/hooks/runAllHooks.sh +++ b/hookio/hooks/runAllHooks.sh @@ -1,5 +1,12 @@ #!/bin/bash -for i in `npm bin`/hookio-* +for i in $(ls `npm bin`/hookio-* 2> /dev/null) do - $i & + echo running $i + nodejs $i & done +for i in `ls | grep "hook.io-" 2>/dev/null` +do + echo running $i + nodejs $i/index.js & +done +wait diff --git a/hookio/monkey/monkey.js b/hookio/monkey/monkey.js index 74f0c9c..f5ea2f0 100755 --- a/hookio/monkey/monkey.js +++ b/hookio/monkey/monkey.js @@ -1,4 +1,4 @@ -var Hook = require('hook.io').Hook, +var Hook = require('hook.io-web40').Web40Hook, express = require('express'), stylus = require('stylus'), nib = require('nib'), @@ -27,7 +27,10 @@ app.configure(function () { */ var monkey = new Hook({ name: "monkey-hook", - debug: true + debug: true, + host: "0.0.0.0", + port: 1337 + }); monkey.on('hook::ready', function () { @@ -42,12 +45,11 @@ app.listen(3000, function () { console.log('app listening on http://' + addr.address + ':' + addr.port); }); -monkey.listen(1337); +monkey.listen(); var nicknames = {}; io.sockets.on('connection', function (socket) { - socket.emit('news', { hello: 'world' }); socket.on('user message', function (data) { console.log(data); }); diff --git a/install.sh b/install.sh index dd1ea53..4617220 100755 --- a/install.sh +++ b/install.sh @@ -11,6 +11,10 @@ function install_npm(){ } function install_node(){ echo "Instaling nodejs" + sudo apt-get install python-software-properties + sudo apt-add-repository ppa:chris-lea/node.js + sudo apt-get update + sudo apt-get install nodejs npm sudo apt-get install nodejs-dev #sudo sudo npm install hook.io #sudo npm install hookio/hooks/* diff --git a/package.json b/package.json index 7674b60..ad61cae 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "Web4.0", -"version" : "0.0.1", +"version" : "0.0.2", "dependencies":{ "socket.io":"*", "hook.io":"*", - "Hook.io-mailer":"git+https://github.com/balkian/Hookio-Mailer.git" + "Hook.io-mailer":"git+https://github.com/balkian/Hookio-Mailer.git", + "hook.io-web40": "*" } }