(defn
open
[{:keys [retry-count retried-count websocket-url build-id], :as opts}]
(if-let
[WebSocket (get-websocket-imp)]
(do
(utils/log :debug "Figwheel: trying to open cljs reload socket")
(let
[url
(str websocket-url (if build-id (str "/" build-id) ""))
socket
(WebSocket. url)]
(set!
(.-onmessage socket)
(fn
[msg-str]
(when-let
[msg (read-string (.-data msg-str))]
(#'handle-incoming-message msg))))
(set!
(.-onopen socket)
(fn
[x]
(reset! socket-atom socket)
(when
(utils/html-env?)
(.addEventListener js/window "beforeunload" close!))
(utils/log :debug "Figwheel: socket connection established")))
(set!
(.-onclose socket)
(fn
[x]
(let
[retried-count (or retried-count 0)]
(utils/debug-prn "Figwheel: socket closed or failed to open")
(when
(> retry-count retried-count)
(js/setTimeout
(fn [] (open (assoc opts :retried-count (inc retried-count))))
(min 10000 (+ 2000 (* 500 retried-count))))))))
(set!
(.-onerror socket)
(fn [x] (utils/debug-prn "Figwheel: socket error ")))
socket))
(utils/log
:debug
(if
(utils/node-env?)
"Figwheel: Can't start Figwheel!! Please make sure ws is installed\n do -> 'npm install ws'"
"Figwheel: Can't start Figwheel!! This browser doesn't support WebSockets"))))