Permalink
Browse files

fine-grained debugging

  • Loading branch information...
1 parent b0ba3a0 commit aa494538239f15d37508c100ba3e254834ed1e8e @cadorn cadorn committed Sep 26, 2012
Showing with 36 additions and 11 deletions.
  1. +4 −2 README.md
  2. +2 −1 demo/server.js
  3. +1 −1 demo/www/index.html
  4. +29 −7 server-plugin/www/client.js
View
@@ -43,8 +43,10 @@ Debugging:
debug: true
}
- (function() { require(["smith.io"], function (TRANSPORT) { TRANSPORT.setDebug(true); localStorage.debug = "*"; }); })()
- (function() { require(["smith.io"], function (TRANSPORT) { TRANSPORT.setDebug(false); localStorage.debug = ""; }); })()
+ (function() { require(["smith.io"], function (TRANSPORT) { TRANSPORT.setDebug(true, ["message", "engine.io"]); }); })()
+ (function() { require(["smith.io"], function (TRANSPORT) { TRANSPORT.setDebug(false); }); })()
+
+ # Reload Browser
License
View
@@ -30,7 +30,8 @@ exports.main = function main(host, port, callback) {
{
packagePath: "./../server-plugin",
messageRoute: /^\/transport\/ser[ver]+/,
- messagePath: "/transport/server"
+ messagePath: "/transport/server",
+ debug: true
},
{
provides: [],
View
@@ -13,7 +13,7 @@
{
"name": "engine.io",
"location": "engine.io",
- "main": "engine.io.js"
+ "main": "engine.io-dev.js"
},
{
"name": "smith.io",
@@ -168,11 +168,21 @@ define(function(require, exports, module) {
return transport;
}
- exports.setDebug = function(debug) {
+ exports.setDebug = function(debug, events) {
if (debugHandler !== null) {
- if (debug) return;
- return debugHandler.stop();
- } else if (!debug) return;
+ debugHandler.stop();
+ }
+ if (!debug) {
+ if (window.localStorage) {
+ localStorage.smithioDebug = "";
+ localStorage.debug = "";
+ }
+ return;
+ }
+ events = events || [];
+ if (window.localStorage) {
+ localStorage.smithioDebug = JSON.stringify([debug, events]);
+ }
debugHandler = {
transports: [],
handlers: [],
@@ -203,16 +213,24 @@ define(function(require, exports, module) {
transport.on("heartbeat", listeners["heartbeat"] = function(message) {
console.log("[smith.io:" + transport.getUri() + "] Heartbeat");
});
- transport.on("message", listeners["message"] = function(message) {
- console.log("[smith.io:" + transport.getUri() + "] Message", message);
- });
+ if (events.indexOf("message") !== -1) {
+ transport.on("message", listeners["message"] = function(message) {
+ console.log("[smith.io:" + transport.getUri() + "] Message", message);
+ });
+ }
transport.on("away", listeners["away"] = function() {
console.log("[smith.io:" + transport.getUri() + "] Away");
});
transport.on("back", listeners["back"] = function() {
console.log("[smith.io:" + transport.getUri() + "] Back");
});
+ if (events.indexOf("engine.io") !== -1) {
+ if (window.localStorage) {
+ localStorage.debug = "*";
+ }
+ }
+
debugHandler.transports.push(transport);
debugHandler.handlers.push({
unhook: function() {
@@ -234,4 +252,8 @@ define(function(require, exports, module) {
debugHandler.start();
}
+ if (window.localStorage && localStorage.smithioDebug) {
+ exports.setDebug.apply(null, JSON.parse(localStorage.smithioDebug));
+ }
+
});

0 comments on commit aa49453

Please sign in to comment.