|
33 | 33 | (def connected-uids connected-uids)) ; Watchable, read-only atom
|
34 | 34 |
|
35 | 35 | (defn- event-msg-handler
|
36 |
| - [{:as ev-msg :keys [ring-req event ?reply-fn]} _] |
37 |
| - (let [session (:session ring-req) |
38 |
| - [id data :as ev] event] |
| 36 | + [{:as ev-msg :keys [event ?reply-fn]}] |
| 37 | + (match event |
| 38 | + [:cmd/percolate params] (p/start-percolator params) |
| 39 | + [:cmd/query params] (do |
| 40 | + (log/info "Received query:" params) |
| 41 | + (let [res (p/query params)] ; TODO: put request msg on channel for async handling |
| 42 | + (chsk-send! (:uid params) [:tweet/prev-chunk res]))) |
| 43 | + [:cmd/missing params] (put! c/tweet-missing-chan params) |
| 44 | + [:chsk/ws-ping params] () ; currently just do nothing with ping (no logging either) |
| 45 | + :else (do (log/info "Unmatched event:" event) |
| 46 | + (when-not (:dummy-reply-fn? (meta ?reply-fn)) |
| 47 | + (?reply-fn {:umatched-event-as-echoed-from-from-server event}))))) |
39 | 48 |
|
40 |
| - (match [id data] |
41 |
| - ;; TODO: Match your events here, reply when appropriate <...> |
42 |
| - |
43 |
| - [:cmd/percolate params] |
44 |
| - (p/start-percolator params) |
45 |
| - |
46 |
| - [:cmd/query params] |
47 |
| - (do |
48 |
| - (log/info "Received query:" params) |
49 |
| - (let [res (p/query params)] |
50 |
| - ;(doseq [t res] (chsk-send! (:uid params) [:some/tweet (:_source t)])) |
51 |
| - (chsk-send! (:uid params) [:tweet/prev-chunk res]))) |
52 |
| - |
53 |
| - [:cmd/missing params] |
54 |
| - (put! c/tweet-missing-chan params) |
55 |
| - |
56 |
| - [:chsk/ws-ping params] |
57 |
| - () ; currently just do nothing with ping (no logging either) |
58 |
| - |
59 |
| - :else |
60 |
| - (do (log/info "Unmatched event:" ev) |
61 |
| - (when-not (:dummy-reply-fn? (meta ?reply-fn)) |
62 |
| - (?reply-fn {:umatched-event-as-echoed-from-from-server ev})))))) |
63 |
| - |
64 |
| -(defonce chsk-router (sente/start-chsk-router-loop! event-msg-handler ch-chsk)) |
| 49 | +(defonce chsk-router (sente/start-chsk-router! ch-chsk event-msg-handler)) |
65 | 50 |
|
66 | 51 | ;; loop for matching connected clients with percolation matches and delivering those on the appropriate socket
|
67 | 52 | (go
|
|
0 commit comments