diff --git a/src/clj/grub/core.clj b/src/clj/grub/core.clj index 7a92a07..2128331 100644 --- a/src/clj/grub/core.clj +++ b/src/clj/grub/core.clj @@ -29,7 +29,7 @@ (include-js @js-file)])) (defroutes routes - (GET "/ws" [] ws/websocket-handler) + (GET "/" [] ws/websocket-handler) (GET "/" [] (index-page)) (GET "*/src/cljs/grub/:file" [file] (resp/file-response file {:root "src/cljs/grub"})) (GET "/js/public/js/:file" [file] (resp/redirect (str "/js/" file))) diff --git a/src/clj/grub/websocket.clj b/src/clj/grub/websocket.clj index 1948630..dbade3c 100644 --- a/src/clj/grub/websocket.clj +++ b/src/clj/grub/websocket.clj @@ -50,7 +50,7 @@ (httpkit/send! ws-channel (str event)) (recur)))) -(defn setup-new-connection [ws-channel] +(defn set-up-new-connection [ws-channel] (let [[ws-channel-id client-chan] (add-connected-client! ws-channel)] (println "Client connected:" (.toString ws-channel) (str "(" ws-channel-id ")")) (println (count @connected-clients) "client(s) connected") @@ -59,7 +59,8 @@ (forward-other-events-to-client client-chan ws-channel))) (defn websocket-handler [request] - (httpkit/with-channel request ws-channel (setup-new-connection ws-channel))) + (when (:websocket? request) + (httpkit/with-channel request channel (set-up-new-connection channel)))) (defn get-other-client-channels [my-ws-channel-id] (-> @connected-clients diff --git a/src/cljs/grub/websocket.cljs b/src/cljs/grub/websocket.cljs index ccbc98f..bffe0c5 100644 --- a/src/cljs/grub/websocket.cljs +++ b/src/cljs/grub/websocket.cljs @@ -31,7 +31,7 @@ (defn get-remote-chan [to-remote] - (let [server-url (str "ws://" (.-host (.-location js/document)) "/ws") + (let [server-url (str "ws://" (.-host (.-location js/document))) handler (goog.events.EventHandler.) remote-events (chan)] (reset! websocket* (goog.net.WebSocket.))