Skip to content

Commit

Permalink
[#247] Experimental: catch js/require failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Jul 16, 2016
1 parent a743e2b commit 8de1d28
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/taoensso/sente.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,23 @@

:handled)))

#?(:cljs
(def ^:private ?node-npm-websocket
"nnil iff the websocket npm library[1] is available.
Easiest way to install:
1. Add the lein-npm[2] plugin to your `project.clj`,
2. Add: `:npm {:dependencies [[websocket \"1.0.23\"]]}`
[1] Ref. https://www.npmjs.com/package/websocket
[2] Ref. https://github.com/RyanMcG/lein-npm"
(when (and node-target? (exists? js/require))
(try
(js/require "websocket")
;; In particular, catch 'UnableToResolveError'
(catch :default e
;; (errorf e "Unable to load npm websocket lib")
nil)))))

#?(:cljs
(defrecord ChWebSocket
;; WebSocket-only IChSocket implementation
Expand Down Expand Up @@ -932,12 +949,10 @@

(-chsk-connect! [chsk]
(when-let [WebSocket
(if node-target?
(when (exists? js/require)
(enc/oget (js/require "websocket") "w3cwebsocket"))
(or
(enc/oget js/window "WebSocket")
(enc/oget js/window "MozWebSocket")))]
(or
(enc/oget ?node-npm-websocket "w3cwebsocket")
(enc/oget js/window "WebSocket")
(enc/oget js/window "MozWebSocket"))]

(let [retry-id (enc/uuid-str)
connect-fn
Expand Down

0 comments on commit 8de1d28

Please sign in to comment.