-
Notifications
You must be signed in to change notification settings - Fork 9
/
fxs.cljs
25 lines (24 loc) · 1.2 KB
/
fxs.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(ns clograms.fxs
(:require [re-frame.core :as re-frame]
[clograms.events :as events]
[cljs.core.async :as async]
[taoensso.sente :as sente :refer [cb-success?]])
(:require-macros [cljs.core.async.macros :as asyncm :refer [go-loop]]))
(re-frame/reg-fx
:start-websocket
(fn [{:keys [port]}]
(println "Starting websocket on port " port)
;; Read from websocket
(let [{:keys [chsk ch-recv send-fn state]} (sente/make-channel-socket-client! "/chsk"
nil
{:type :auto
:host "localhost"
:port port})] ; e/o #{:auto :ajax :ws}
(go-loop [{:keys [?data]} (async/<! ch-recv)]
(js/console.log "[WebSocket event]" ?data)
(let [[ev dat] ?data]
(case ev
:updates/datoms (re-frame/dispatch [::events/new-datoms dat])
nil))
(recur (async/<! ch-recv)))
(js/console.info "Websocket connection ready"))))