                                           assoc ::message msg)))
                          (remove-listener listen)))]
         (add-listener listener)
-        (channel-send
-         channel
-         (json/write-str (cond-> {:uuid uuid
-                                  :session-name (:session-name channel-data)
-                                  :op :eval
-                                  :code js}
-                           (:session-id channel-data)
-                           (assoc :session-id (:session-id channel-data)))))))
+        (connection-send
+         conn
+         (json/write-str
+          (assoc (select-keys conn [:session-id :session-name])
+                 :uuid uuid
+                 :op :eval
+                 :code js)))))
     prom))
 
 (let [timeout-val (Object.)]

    (message (cond-> (js->clj msg :keywordize-keys true)
               http-url (assoc :http-url http-url)))))

(defn fill-url-template [websocket-url']
  (if (= host-env :html)
      (-> websocket-url'
          (string/replace "[[client-hostname]]" js/location.hostname)
          (string/replace "[[client-port]]" js/location.port))
      websocket-url'))

(defn connect [& [websocket-url']]
  ;; TODO take care of forwarding print output to the connection
  (let [websocket (goog.net.WebSocket.)
        url (str (fill-url-template (or websocket-url' websocket-url))
                 (when-let [n (session-name)]
                   (str "?figwheelReplSessionName=" n)))]
    (patch-goog-base)
    (doto websocket
      (.addEventListener goog.net.WebSocket.EventType.MESSAGE

;; Websocket REPL
;; --------------------------------------------------------------

(goog-define connect-url "ws://localhost:3449/figwheel-connect")

(def state (atom {}))
(def storage (storage-factory/createHTML5SessionStorage "figwheel.repl"))
