code: function Channel_connect(cb) {
    cb = utils.callOnce(cb)
  
    var websocket = new WebSocket(this._url, [this._protocol])
  
    websocket.addEventListener("open",    onOpen)
    websocket.addEventListener("message", onMessage)
    websocket.addEventListener("close",   onClose)
    websocket.addEventListener("error",   onError)
  
    var channel = this
  
    //-----------------------------------
    function onOpen() {
      channel._websocket = websocket
  
      cb(null)
    }
  
    //-----------------------------------
    function onMessage(event) {
      if (!channel._websocket) return
  
      var message = JSON.parse(event.data)
  
      channel.emit("message", message)
    }
  
    //-----------------------------------
    function onClose() {
      if (!channel._websocket) return
  
      channel._websocket = null
  
      channel.emit("close")
      cb(new Error("closed"))
    }
  
    //-----------------------------------
    function onError() {
      channel.emit("error", new Error("undisclosed error"))
    }
  
  }
docs: ------------------------------------------------------------------------------