   callbacks: {}
   id: 0
 
+  # TODO: refactor this
   listen: (f) ->
     return f?(@port) if @port?
     @server = net.createServer (c) =>

      line = (s) =>
        [type, data] = JSON.parse s
        if @handlers.hasOwnProperty type
          @handlers[type] data
        else if @callbacks.hasOwnProperty type
          @callbacks[type] data
          delete @callbacks[type]

      c.on 'end', =>
        @client = null
        @emitter.emit 'disconnected'
        @loading?.reset()
      # Data will be split into chunks, so we have to buffer it before parsing.
      buffer = ['']
      c.on 'data', (data) =>
