             [org.httpkit.server :as http-kit-server]
             [clojure.core.match :refer [match]]
             [tango.import :as imp]
-            [ring.middleware.defaults :as defaults]))
+            [ring.middleware.defaults :as defaults]
+            [clojure.core.async
+             :as a
+             :refer [>! <! >!! <!! go chan buffer close! thread
+                     alts! alts!! timeout]]
+            ))
 
 (def memory-log (atom []))
 

  (swap! memory-log conj s))

(defn import-file [{:keys [content]}]
  ;; (println "-----------------")
  ;(println (str "import " content))
  ;(println (str (imp/dance-perfect-xml->data (imp/read-xml-string content)))
  ;(println "-----------------")
  (imp/dance-perfect-xml->data (imp/read-xml-string content))
  )

(defn event-msg-handler* [{:as ev-msg :keys [id ?data event ring-req]}]
  (do
    ;(logf (str "Event: " event))
    (println (str "Id: " (:uid (:session ring-req))))
    ;(println (str "Request : " ring-req))
    (match [id ?data]
           [:file/import xml]
           (chsk-send! (:uid (:session ring-req)) [:file/imported {:content (import-file xml)}])
           [:client/ping p] (chsk-send! 1 [:server/pong {:content 1}])
           :else (println (str "Event : " event)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Sente socket setup

  (def chsk-send!                    send-fn) ; ChannelSocket's send API fn
  (def connected-uids                connected-uids) ; Watchable, read-only atom
  )

(defn event-msg-handler* [{:as ev-msg :keys [id ?data event ring-req]}]
  (do
    ;(logf (str "Event: " event))
    (println (str "Id: " (:uid (:session ring-req))))
    ;(println (str "Request : " ring-req))
    ;(message-dispatch id ?data (:uid (:session ring-req)))
    (>!! message-chan {:topic id :payload ?data :sender (:uid (:session ring-req))})))

(defonce router_ (atom nil))

