code: function Channel(session, wsConn) {
    DEBUG("new Channel()")
    this.session     = session
    this.wsConn      = wsConn
    this.agents      = new SMap()
    this.nextAgentID = session.nextAgentID
  
    this.session.addChannel(this)
  
    wsConn.addListener("message", onMessage)
    wsConn.addListener("close",   onClose)
    wsConn.addListener("error",   onError)
  
    var channel = this
  
    //-----------------------------------
    function onMessage(message) {
      if (message.type != "utf8") return
  
      DEBUGMSG("recv: " + message.utf8Data)
      message = JSON.parse(message.utf8Data)
  
      if      (message.type == "request")  session.onRequest(channel, message)
      else if (message.type == "response") session.onResponse(channel, message)
      else if (message.type == "event")    session.onEvent(channel, message)
    }
  
    //-----------------------------------
    function onClose() {
      DEBUG("channel.onClose()")
      channel.eachAgent(function(agent){
        agent.shutDown()
      })
  
      channel.session.delChannel(this)
    }
  
    //-----------------------------------
    function onError(err) {
      DEBUG("channel.onErr():" +  err)
  
      if (err.errno == "ECONNRESET") return
  
      console.log("websocket error: " + err)
      console.log(err.stack)
    }
  }
docs: ------------------------------------------------------------------------------