Permalink
Browse files

wip

  • Loading branch information...
1 parent 8c1fb47 commit 17b350e0afa375584540f468d1ea742b19c395ee @c4milo committed May 14, 2012
Showing with 69 additions and 52 deletions.
  1. +11 −2 index.js
  2. +58 −50 webkit-devtools-agent.js
View
@@ -3,11 +3,13 @@ var fork = require('child_process').fork;
var child = fork('./webkit-devtools-agent.js', process.argv);
+initializeAgents();
+
child.on('message', function(message) {
var data = message.data;
switch(message.event) {
case 'connection':
- initializeAgents();
+ //initializeAgents();
break;
case 'method':
var id = data.id;
@@ -22,13 +24,17 @@ child.on('message', function(message) {
}
domain[method](params, function(result) {
- child.send({
+ var sent = child.send({
event: 'result',
data: {
id: id,
result: result
}
});
+ if (!sent) {
+ console.log('PUTA !!!');
+ console.log(result);
+ }
});
break;
}
@@ -67,4 +73,7 @@ child.on('exit', function(code, signal) {
//TODO: re-spawn it
});
+process.on('exit', function() {
+ child.kill('SIGTERM');
+});
View
@@ -1,68 +1,76 @@
var Debugger = require('./lib/debugger');
var WebSocketServer = require('ws').Server;
-var wss;
-var port = process.env.DEBUG_PORT || 9999;
-var host = process.env.DEBUG_HOST || '127.0.0.1';
+var DevToolsAgent = function() {
+ this.wss = null;
+ this.port = process.env.DEBUG_PORT || 9999;
+ this.host = process.env.DEBUG_HOST || '127.0.0.1';
+};
-function start() {
- wss = new WebSocketServer({
- port: port,
- host: host
+(function() {
+ var self = this;
+ process.on('SIGUSR2', function() {
+ if (self.wss) {
+ self.stop();
+ } else {
+ self.start();
+ }
});
- console.log('webkit-devtools-agent started on %s:%s', host, port);
+ process.on('uncaughtException', function (err) {
+ console.error('webkit-devtools-agent: uncaughtException: ');
+ console.error(err);
+ console.error(err.stack);
+ });
- wss.on('connection', function(socket) {
- process.send({
- event: 'connection'
+ this.start = function() {
+ this.wss = new WebSocketServer({
+ port: this.port,
+ host: this.host
});
- process.on('message', function(message) {
- var data = message.data;
+ console.log('webkit-devtools-agent started on %s:%s', host, port);
- switch(message.event) {
- case 'event':
- case 'result':
- socket.send(JSON.stringify(data));
- }
- });
+ this.wss.on('connection', function(socket) {
+ process.send({
+ event: 'connection'
+ });
- socket.on('message', function(message) {
- try {
- message = JSON.parse(message);
- } catch(e) {
- console.error(e);
- return;
- }
+ process.on('message', function(message) {
+ var data = message.data;
- process.send({
- event: 'method',
- data: message
+ switch(message.event) {
+ case 'event':
+ case 'result':
+ socket.send(JSON.stringify(data));
+ }
+ });
+
+ socket.on('message', function(message) {
+ try {
+ message = JSON.parse(message);
+ } catch(e) {
+ console.error(e);
+ return;
+ }
+
+ process.send({
+ event: 'method',
+ data: message
+ });
});
});
- });
-}
+ };
-function stop() {
- if (wss) {
- wss.close();
- wss = null;
- console.log('webkit-devtools-agent stopped');
- }
-}
+ this.stop = function() {
+ if (this.wss) {
+ this.wss.close();
+ this.wss = null;
+ console.log('webkit-devtools-agent stopped');
+ }
+ };
+}).call(DevToolsAgent.prototype);
-process.on('SIGUSR2', function() {
- if (wss) {
- stop();
- } else {
- start();
- }
-});
+module.exports = new DevToolsAgent();
-process.on('uncaughtException', function (err) {
- console.error('webkit-devtools-agent: uncaughtException: ');
- console.error(err);
- console.error(err.stack);
-});

0 comments on commit 17b350e

Please sign in to comment.