mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
In websocket-relay check if socket has closed before sending or closing.
This commit is contained in:
parent
d3f3cb7324
commit
cb605a909f
@ -80,20 +80,22 @@
|
||||
|
||||
(defmethod relay/close ::websocket [relay]
|
||||
(let [{::keys [socket timer]} relay]
|
||||
(try
|
||||
(.get (.sendClose socket WebSocket/NORMAL_CLOSURE "done"))
|
||||
(catch Exception e
|
||||
(prn 'on-send-close-error (:reason e))))
|
||||
(when (and socket (not (.isOutputClosed socket)))
|
||||
(try
|
||||
(.get (.sendClose socket WebSocket/NORMAL_CLOSURE "done"))
|
||||
(catch Exception e
|
||||
(prn 'on-send-close-error (:reason e)))))
|
||||
(when timer (.cancel timer))
|
||||
(assoc relay ::open? false ::socket nil)))
|
||||
|
||||
(defmethod relay/send ::websocket [relay message]
|
||||
(let [{::keys [socket url]} relay]
|
||||
(try
|
||||
(let [json (to-json message)]
|
||||
(println "sending to:" url " " json)
|
||||
(.sendText socket json true)
|
||||
(.request socket 1))
|
||||
(catch Exception e
|
||||
(prn 'send-to (.getMessage e))))))
|
||||
(when (and socket (not (.isOutputClosed socket)))
|
||||
(try
|
||||
(let [json (to-json message)]
|
||||
(println "sending to:" url " " json)
|
||||
(.sendText socket json true)
|
||||
(.request socket 1))
|
||||
(catch Exception e
|
||||
(prn 'send-to (.getMessage e)))))))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user