patched up page refresh when the process under debug restarts

This commit is contained in:
Danny Coates 2011-08-03 20:10:48 -07:00
Родитель 1e51bf9066
Коммит 41922a7266
2 изменённых файлов: 57 добавлений и 44 удалений

Просмотреть файл

@ -7,6 +7,7 @@ var Http = require('http'),
WEBROOT = require('path').join(__dirname, '../front-end'),
sessions = {},
config = {},
connectionTimeout,
webPort;
function serveStaticFiles(req, res) {
@ -23,12 +24,21 @@ function getSession(debuggerPort) {
if (!session) {
session = Session.create(debuggerPort, config);
sessions[debuggerPort] = session;
// TODO session on close
session.on('ws_closed', function () {
connectionTimeout = setTimeout(function () {
session.close();
}, 3000);
});
session.on('close', function () {
sessions[debuggerPort] = null;
});
session.attach();
}
return session;
}
function handleWebSocketConnection(conn) {
clearTimeout(connectionTimeout);
var port = getDebuggerPort(conn._req.url, config.debugPort);
getSession(port).join(conn);
}

Просмотреть файл

@ -271,49 +271,51 @@ exports.create = function(debuggerPort, config) {
});
}
function attach() {
debug = debugr.attachDebugger(debuggerPort);
debug.on('break', breakEvent);
debug.on('close', function() {
//TODO determine proper close behavior
debug = {
request: function() {
console.error('debugger not connected');
}
};
sendEvent('debuggerWasDisabled');
});
debug.on('connect', function() {
browserConnected();
});
debug.on('exception', function(msg) {
breakEvent(msg);
});
debug.on('error', function(e) {
sendEvent('showPanel', { name: 'console' });
var err = e.toString(), data;
if (err.match(/ECONNREFUSED/)) {
err += '\nIs node running with --debug port ' + debuggerPort + '?';
}
data = {
messageObj: {
source: 3,
type: 0,
level: 3,
line: 0,
url: '',
groupLevel: 7,
repeatCount: 1,
message: err
}
};
sendEvent('addConsoleMessage', data);
});
}
attach();
return Object.create(events.EventEmitter.prototype, {
attach: {
value: function()
{
var self = this;
debug = debugr.attachDebugger(debuggerPort);
debug.on('break', breakEvent);
debug.on('close', function() {
//TODO determine proper close behavior
debug = {
request: function() {
console.error('debugger not connected');
}
};
sendEvent('debuggerWasDisabled');
self.close();
});
debug.on('connect', function() {
browserConnected();
});
debug.on('exception', function(msg) {
breakEvent(msg);
});
debug.on('error', function(e) {
sendEvent('showPanel', { name: 'console' });
var err = e.toString(), data;
if (err.match(/ECONNREFUSED/)) {
err += '\nIs node running with --debug port ' + debuggerPort + '?';
}
data = {
messageObj: {
source: 3,
type: 0,
level: 3,
line: 0,
url: '',
groupLevel: 7,
repeatCount: 1,
message: err
}
};
sendEvent('addConsoleMessage', data);
});
}
},
close: {
value: function()
{
@ -326,7 +328,7 @@ exports.create = function(debuggerPort, config) {
//Backend
enableDebugger: {
value: function(always) {
attach();
this.attach();
}
},
dispatchOnInjectedScript: {
@ -950,6 +952,7 @@ exports.create = function(debuggerPort, config) {
});
conn.on('close', function() {
// TODO what to do here? set timeout to close debugger connection
self.emit('ws_closed');
conn = null;
});
browserConnected();