Connect WebSocket to origin server
This commit is contained in:
parent
d754955694
commit
6717854475
3 changed files with 4 additions and 7 deletions
|
@ -28,7 +28,7 @@
|
|||
:optimizations :whitespace
|
||||
:pretty-print true}
|
||||
:notify-command run-specs}
|
||||
:prod {:source-paths ["src/cljs" "src/prod"]
|
||||
:prod {:source-paths ["src/cljs"]
|
||||
:compiler {:output-to "public/js/grub.js"
|
||||
:optimizations :simple}}
|
||||
:test-commands {"test" run-specs}}})
|
||||
|
|
|
@ -15,10 +15,7 @@
|
|||
|
||||
(defn init []
|
||||
(view/init)
|
||||
(if-let [url (when grub.production grub.production/server-url)]
|
||||
(let [port grub.production/server-port]
|
||||
(ws/connect-to-server url port))
|
||||
(ws/connect-to-server "localhost" 3000))
|
||||
(ws/connect-to-server)
|
||||
(handle-grub-events))
|
||||
|
||||
(init)
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
(let [grub-event (cljs.reader/read-string (.-data event))]
|
||||
(go (>! outgoing-events grub-event))))))
|
||||
|
||||
(defn connect-to-server [url port]
|
||||
(let [full-url (str "ws://" url ":" port "/ws")]
|
||||
(defn connect-to-server []
|
||||
(let [full-url (str "ws://" (.-host (.-location js/document)) "/ws")]
|
||||
(reset! websocket* (js/WebSocket. full-url))
|
||||
(aset @websocket* "onopen" (fn [event] (log "Connected:" event)))
|
||||
(aset @websocket* "onclose" (fn [event] (log "Connection closed:" event)))
|
||||
|
|
Loading…
Reference in a new issue