     super
     @readyState = false
     @localStore = {}
+    @localMethods = {}
     @token = ""
     @getKiteAddr()
 


  onMessage : (evt) ->
    try
      {id, result, error} = JSON.parse evt.data
      id = "#{id}"
      @localStore[id].call null, error, result

      delete @localStore[id]
    catch e
      console.log "error: ", e, evt.data

    # @websocket.close()

  onError : (evt) -> console.log "#{@kiteName}: Error #{evt.data}"


  call : (methodName, rest..., callback)->
    if not KD.isLoggedIn()
      return

    for method, param of rest[0]
      if typeof param is "function"
        console.log "ADDING FUNCTION", method, param
        @localMethods[method] = param


    id = Bongo.createId 12

