                 (throw t)))
         mtype (:type msg)
         data (:data msg)]
+    (maybe-deliver-blocking-call-result session msg)
     (when-let [error (:error msg)]
       (println "ERROR" msg))
     (case mtype

  (ws/send-msg (ssocket session)
               (json/generate-string {:type (name ptype)
                                      :data pdata})))

(defn on-connect
  [session _jetty-ws-session]

(defn connect
  "Connect to a room and yield a session."
  [room]
  (let [id-counter (AtomicLong.)
        session (atom { ;; Promise of an implementation-defined
                       ;; "socket" object we can send to or close.
                       :socket (promise)
                       ;; AtomicLong, source of unique IDs for packets.
                       :gen-unique-id #(str (.getAndIncrement id-counter))
                       ;; Registry of in-flight blocking calls, by packet-id.
                       :blocking-calls {}})
        socket (ws/connect
                (cm/address "euphoria.io" room)
                ;; Var indirection should allow code reloading during a session.
