Permalink
Browse files

Switched to socket.io - fixes #56

thanks @guille @einaros for the hybi10 support!
  • Loading branch information...
1 parent 1dfa3bc commit ecc268efdcb2ea5717b9c22f14a026770ee0e947 @dannycoates dannycoates committed Sep 3, 2011
Showing with 33 additions and 25 deletions.
  1. +1 −0 .gitignore
  2. +2 −1 front-end/index.html
  3. +8 −8 front-end/node/Overrides.js
  4. +17 −9 lib/debug-server.js
  5. +4 −4 lib/session.js
  6. +1 −1 package.json
  7. +0 −2 readme.md
View
@@ -1,3 +1,4 @@
._*
node_modules
v8.log
+.DS_Store
@@ -28,7 +28,7 @@
<!DOCTYPE html>
<html class="node-inspector">
<head>
- <title>nodeJS Inspector</title>
+ <title>node inspector</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="audits.css">
<link rel="stylesheet" type="text/css" href="goToLineDialog.css">
@@ -151,6 +151,7 @@
<script type="text/javascript" src="ShortcutsHelp.js"></script>
<script type="text/javascript" src="HAREntry.js"></script>
<script type="text/javascript" src="CookieParser.js"></script>
+ <script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="node/Overrides.js"></script>
</head>
<body class="attached">
@@ -1,17 +1,17 @@
// Wire up websocket to talk to backend
WebInspector.loaded = function() {
- WebInspector.socket = new WebSocket("ws://" + window.location.host + '/debug?port=' + WebInspector.queryParamsObject.port);
- WebInspector.socket.onmessage = function(message) {
- if (message && message.data !== 'ping') {
- WebInspector_syncDispatch(message.data);
+ WebInspector.socket = io.connect("http://" + window.location.host + '/');
+ WebInspector.socket.on('message', function(message) {
+ if (message && message !== 'ping') {
+ WebInspector_syncDispatch(message);
}
- }
- WebInspector.socket.onerror = function(error) { console.error(error); }
- WebInspector.socket.onopen = function() {
+ });
+ WebInspector.socket.on('error', function(error) { console.error(error); });
+ WebInspector.socket.on('connect', function() {
InspectorFrontendHost.sendMessageToBackend = WebInspector.socket.send.bind(WebInspector.socket);
WebInspector.doLoadedDone();
- }
+ });
return;
};
View
@@ -1,6 +1,6 @@
var Http = require('http'),
EventEmitter = require('events').EventEmitter,
- WebSocket = require('websocket-server'),
+ io = require('socket.io'),
paperboy = require('paperboy'),
Session = require('./session'),
inherits = require('util').inherits,
@@ -11,7 +11,11 @@ var Http = require('http'),
webPort;
function serveStaticFiles(req, res) {
- req.url = req.url.replace(/^\/debug/, '/');
+ var re = /^\/debug/;
+ if (re.test(req.url)) {
+ config.debugPort = getDebuggerPort(req.url, config.debugPort);
+ req.url = req.url.replace(re, '/');
+ }
paperboy.deliver(WEBROOT, req, res);
}
@@ -37,10 +41,9 @@ function getSession(debuggerPort) {
return session;
}
-function handleWebSocketConnection(conn) {
+function handleWebSocketConnection(socket) {
clearTimeout(connectionTimeout);
- var port = getDebuggerPort(conn._req.url, config.debugPort);
- getSession(port).join(conn);
+ getSession(config.debugPort).join(socket);
}
function handleServerListening() {
@@ -57,10 +60,15 @@ inherits(DebugServer, EventEmitter);
DebugServer.prototype.start = function(options) {
config = options;
var httpServer = Http.createServer(serveStaticFiles);
- this.wsServer = WebSocket.createServer({ server: httpServer });
- this.wsServer.on('connection', handleWebSocketConnection);
- this.wsServer.on('listening', handleServerListening);
- this.wsServer.listen(config.webPort);
+ var ws = io.listen(httpServer);
+ ws.configure(function() {
+ ws.set('transports', ['websocket']);
+ ws.set('log level', 1);
+ });
+ ws.sockets.on('connection', handleWebSocketConnection);
+ this.wsServer = ws;
+ httpServer.on('listening', handleServerListening);
+ httpServer.listen(config.webPort);
}
DebugServer.prototype.close = function() {
View
@@ -215,7 +215,7 @@ exports.create = function(debuggerPort, config) {
function sendEvent(name, data) {
data = data || {};
if (conn) {
- conn.write(JSON.stringify({
+ conn.send(JSON.stringify({
type: 'event',
event: name,
data: data
@@ -226,7 +226,7 @@ exports.create = function(debuggerPort, config) {
function sendResponse(seq, success, data) {
data = data || {};
if (conn) {
- conn.write(JSON.stringify({
+ conn.send(JSON.stringify({
seq: seq,
success: success,
data: data
@@ -236,7 +236,7 @@ exports.create = function(debuggerPort, config) {
function sendPing() {
if (conn) {
- conn.write('ping');
+ conn.send('ping');
setTimeout(sendPing, 30000);
}
}
@@ -950,7 +950,7 @@ exports.create = function(debuggerPort, config) {
conn.on('message', function(data) {
self.handleRequest(data);
});
- conn.on('close', function() {
+ conn.on('disconnect', function() {
// TODO what to do here? set timeout to close debugger connection
self.emit('ws_closed');
conn = null;
View
@@ -12,7 +12,7 @@
"engines" : { "node": ">=0.3.0" },
"bin" : { "node-inspector" : "./bin/inspector.js" },
"dependencies": {
- "websocket-server": "~1.4",
+ "socket.io": "~0.8.2",
"paperboy": "~0.0.2"
}
}
View
@@ -9,8 +9,6 @@ Node Inspector is a debugger interface for nodeJS using the WebKit Web Inspector
* [npm](http://github.com/isaacs/npm)
* A WebKit based browser: Chrome, Safari, etc.
- > [**BROKEN** on Chrome 14+](https://github.com/dannycoates/node-inspector/issues/56)
-
* Optional [v8-profiler](http://github.com/dannycoates/v8-profiler) to use the profiles panel
### Install

0 comments on commit ecc268e

Please sign in to comment.