 (defn shutdown-send-queue [tal-state]
   (remove-watch (:send-queue @tal-state) ::send-watcher))
 
-
-;; XXX: handle callbacks and timeouts
 ;; XXX: handle special messages from the server (ping, close)
 (defn consume-recv-queue [tal-state handler]
   (let [recv-queue (:recv-queue @tal-state)]

                                             (consume-recv-queue tal-state handler))))
    (consume-recv-queue tal-state handler)))

(defonce debug-ws (atom nil))

(defn init [url & {:keys [on-open on-close on-error]}]
  (let [ ;; creates class that will handle auto-reconnecting on failure
        w (goog.net.WebSocket.)
        _ (reset! debug-ws w)
        ch (async/chan (async/sliding-buffer 1024))
        send-queue (atom [])
        recv-queue (atom [])
        tal-state (atom {:ws w
                         :open? false
                         :send-queue send-queue
                         :recv-queue recv-queue

                              :closed? true
                              :close-code (.-code %)
                              :close-reason (.-reason %))
                       (js/clearInterval (:keep-alive-timer @tal-state))
                       (when (fn? on-close)
                         (on-close tal-state {:code (.-code %)
                                              :reason (.-reason %)}))))
