     (pr-str {:input text})
     #js {"content-type" "application/edn; charset=utf-8"}))
 
+;; :init
+;; :connecting
+;; :connected
+(defonce ws-status (volatile! :init))
+
+(declare ws-connect-impl)
+
 (defn ws-connect []
+  (when (= (@ws-status :init))
+    (ws-connect-impl)))
+
+(defn maybe-reconnect []
+  (when (and (not @stale-client-detected)
+             (not= @ws-status :init))
+    (vreset! ws-status :init)
+    (js/setTimeout ws-connect 3000)))
+
+(defn ws-connect-impl []
+  (vreset! ws-status :connecting)
   (try
     (let [print-fn
           cljs.core/*print-fn*

          (hud/connection-error (or @close-reason-ref "Connection closed!"))
          (vreset! socket-ref nil)
          (env/reset-print-fns!)
          ))

      (set! (.-onerror socket)
        (fn [e]
          (hud/connection-error "Connection failed!")
          (devtools-msg "websocket error" e))))
    (catch :default e
      (devtools-msg "WebSocket setup failed" e))))


      (set! (.-onopen socket)
        (fn [e]
          (vreset! ws-status :connected)
          (hud/connection-error-clear!)
          (vreset! close-reason-ref nil)
          ;; :module-format :js already patches provide
