         (let [id (guid)]
           (.setItem js/localStorage user id)
           id)))))
-
-(declare send on-message on-open on-close)
 
 (defn build-socket [host port]
   (js/WebSocket. (str "ws://" host ":" port "/api/ws")))

                :data data
                :id (guid)
                :timestamp (.getTime (js/Date.))}]
    (if (and (:connected? @cat) (or (:identified? @cat) (= action "identify")))
      (do
        (log "sending" (clj->js params))
        (swap! cat update-in [:sent-messages] assoc (:id params) params)
        (.send (:socket @cat) (stringify params)))
      (do
        (log "enqueing")
        (swap! cat update-in [:queue] conj params)))))

(defn flush-queue [cat]
  (log "identified, flushing queue")

     (set-handlers! cat socket)
     cat)))

(defn do-send [cat params]
  (if (and (:connected? @cat) (or (:identified? @cat)
                                  (= (:action params) "identify")))
    (do
      (log "sending" (clj->js params))
      (swap! cat update-in [:sent-messages] assoc (:id params) params)
      (.send (:socket @cat) (stringify params)))
    (do
      (log "enqueing")
      (swap! cat update-in [:queue] conj params))))

(defn send [cat action data]
  (let [params {:api_key (:api-key @cat)
                :user (user)
