            (doto (js/Event. "figwheel.repl.connected" target)
              (gobj/add "data" {:url url}))))))
 
+(defn connection-closed! [url]
+  (when (= host-env :html)
+    (let [target (.. goog.global -document -body)]
+      (.dispatchEvent
+       target
+       (doto (js/Event. "figwheel.repl.disconnected" target)
+         (gobj/add "data" {:url url}))))))
+
 (defn get-websocket-class []
   (or
    (gobj/get goog.global "WebSocket")

           (msg-fn msg)
           (long-poll msg-fn connect-url'))
         (fn [e] ;; lost connection
           (http-connect connect-url'))))

(defn http-connect* [attempt connect-url']

           (msg-fn msg)
           (js/setTimeout #(poll msg-fn connect-url') 500))
         (fn [e] ;; lost connection
           (connection-closed! connect-url')
           (http-connect connect-url'))))

(defn long-poll [msg-fn connect-url']
