Connect WebSocket to origin server

This commit is contained in:
Nicholas Kariniemi 2013-08-25 13:58:12 +03:00
parent d754955694
commit 6717854475
3 changed files with 4 additions and 7 deletions

View file

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

View file

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

View file

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