(ns bombnet.web.ws (:require [cljs.core.async :refer [! chan]]) (:require-macros [cljs.core.async.macros :refer [go]])) (defn connect [room id] (let [in-ch (chan) out-ch (chan) host (.. js/window -location -host) socket (js/WebSocket. (str "ws://" host "/ws/" room "?" id))] (go (loop [] (.send socket (.stringify js/JSON (clj->js (! in-ch (js->clj (.parse js/JSON (.. message -data)) :keywordize-keys true))))) [in-ch out-ch])) (defn send! [[in out] msg] (go (>! out msg)))