Add relay to websocket-relay callback function.

This commit is contained in:
Robert C. Martin 2023-01-17 08:15:35 -06:00
parent 7587374a47
commit bf8dda7ee1
3 changed files with 9 additions and 4 deletions

View File

@ -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)))
)

View File

@ -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)

View File

@ -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))))