mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Add relay to websocket-relay callback function.
This commit is contained in:
parent
7587374a47
commit
bf8dda7ee1
@ -25,13 +25,14 @@
|
||||
(it "can send and receive"
|
||||
(pending "be nice to relay.damus.io")
|
||||
(let [chan (async/chan)
|
||||
recv-f (fn [msg] (async/>!! chan msg))
|
||||
recv-f (fn [relay msg] (async/>!! chan [relay msg]))
|
||||
relay (ws-relay/make "wss://relay.damus.io" recv-f)
|
||||
relay-open (relay/open relay)
|
||||
_ (relay/send relay-open ["test"])
|
||||
f-reply (future (async/<!! chan))
|
||||
reply (deref f-reply 1000 :timeout)
|
||||
[relay-r reply] (deref f-reply 1000 :timeout)
|
||||
_ (relay/close relay-open)]
|
||||
(should= relay relay-r )
|
||||
(should= ["NOTICE" "could not parse command"] reply)))
|
||||
)
|
||||
|
||||
|
@ -161,9 +161,13 @@
|
||||
(when-let [conn (get-in @relays [url :connection])]
|
||||
(.sendPing conn (ByteBuffer/allocate 4)))))
|
||||
|
||||
(defn handle-relay-message [relay message]
|
||||
(prn 'TILT))
|
||||
|
||||
(defn connect-to-relays []
|
||||
(doseq [url (keys @relays)]
|
||||
(let [relay-config (get @relays url)
|
||||
(let [relay (ws-relay/make url handle-relay-message)
|
||||
relay-config (get @relays url)
|
||||
should-connect? (or (:read relay-config) (:write relay-config))
|
||||
connection (if should-connect?
|
||||
(connect-to-relay url)
|
||||
|
@ -21,7 +21,7 @@
|
||||
(when last
|
||||
(try
|
||||
(let [envelope (json/read-str (.toString buffer))]
|
||||
(recv-f envelope))
|
||||
(recv-f relay envelope))
|
||||
(catch Exception e
|
||||
(prn 'onText url (.getMessage e))
|
||||
(prn (.toString buffer))))
|
||||
|
Loading…
Reference in New Issue
Block a user