Commits

Anonymous committed c909fe9

do not call conn.close() (its not yet implemented in TCPSocket).

add logging support.

  • Participants
  • Parent commits c8c2614
  • Branches 0.5

Comments (0)

Files changed (1)

daemon/orbited/static/protocols.local/irc/irc2.js

  * ©2008 The Orbited Project
  */
 
+// TODO DRY this by creating a common logging infrastructure (this is also on stomp.js)
+IRC_DEBUG = false;
+
+if (IRC_DEBUG && typeof(console)) {
+    function getIrcLogger(name) {
+        return {
+            debug: function() {
+                var args = Array.prototype.slice.call(arguments);
+                args.unshift(name, ": ");
+                console.debug.apply(console, args);
+            },
+            dir: function() {
+                console.debug(name, ":");
+                console.dir.apply(console, arguments);
+            }
+        };
+    }
+} else {
+    function getIrcLogger(name) {
+        return {
+            debug: function() {},
+            dir: function() {}
+        };
+    }
+}
+
 IRCClient = function() {
+    var log = getIrcLogger("IRCClient");
     var self = this
     var conn = null
     var buffer = ""
     self.onresponse = function(command) {}     // used for numerical replies
                             
     self.connect = function(hostname, port) {
+        log.debug("connect");
         conn = self._createTransport(hostname, port);
         conn.onopen = conn_opened
         conn.onclose = conn_closed
         return new TCPSocket(hostname, port);
     };
     self.close = function() {
-        conn.close()
+        log.debug("close");
+        // XXX there is no TCPSocket.close method... so I'm removing all
+        //     the listeners here (until this is fixed).
+        //conn.close()
+        conn.onopen = null;
+        conn.onclose = null;
+        conn.onread = null;
         self.onclose()
     }
     self.ident = function(nickname, modes, real_name) {
         self.onclose()
     }
     var conn_read = function(data) {
+        log.debug("data:");
+        log.debug(data);
         buffer += data
         parse_buffer()
     }
           var prefix = null;
         }
 
-        return {
+        var command = {
             prefix: prefix,
             type: args.shift(),
             args: args
         };
+        log.debug("command:");
+        log.dir(command);
+        return command;
     };
     var dispatch = function(line) {
         command = parse_command(line);
             //     but cannot send any arbitrary command
             self["on" + command.type](command);
         } else {
-            // TODO make this work with a logger instead:
-            console.debug("unhandled command received:");
-            console.dir(command);
+            log.debug("unhandled command received: ", command.type);
         }
     };
 };