Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
(defproject org.httpkit/chat-websocket "1.0"
(defproject chat "1.0"
:description "Realtime chat by utilizing http-kit's websocket support"
:dependencies [[org.clojure/clojure "1.4.0"]
[ring/ring-core "1.1.6"]
[compojure "1.0.2"]
[org.clojure/data.json "0.1.2"]
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/clojurescript "1.10.597"]
[ring/ring-core "1.8.0"]
[ring/ring-defaults "0.3.2"]
[compojure "1.6.1"]
[org.clojure-android/data.json "0.2.6-SNAPSHOT"]
[org.clojure/tools.logging "0.2.3"]
[ch.qos.logback/logback-classic "1.0.1"]
[http-kit "2.1.5"]]
[http-kit "2.4.0-alpha4"]]
:warn-on-reflection true
:min-lein-version "2.0.0"
:main main
:test-paths ["test"]
:plugins [[lein-swank "1.4.4"]
[lein-cljsbuild "0.3.0"]]
:plugins [[lein-swank "1.4.5"]
[lein-cljsbuild "1.1.7"]]
:cljsbuild {
:builds [{:source-paths ["src-cljs"]
:compiler {:output-to "static/main.js"
Expand Down
1 change: 1 addition & 0 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CP="classes:$(lein classpath):examples/websocket/"
java -cp "$CP" \
clojure.main -m main

java -cp `lein classpath` clojure.main -e "(do (set! *warn-on-reflection* true) (require 'qbits.alia.async))"


# -Xdebug -Xrunjdwp:transport=dt_socket,address=9092,server=y,suspend=n \
8 changes: 4 additions & 4 deletions src-cljs/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(def i (js/$ "#i"))
(def history (js/$ "#history"))

(defn- now []
(defn- now []
(quot (.getTime (js/Date.)) 1000))

(def max-id (atom 0))
Expand All @@ -13,15 +13,15 @@
author (str "<span class=\"author\">" (.-author msg) "</span>: ")]
(.append history (str "<li>" author (.-msg msg) t "</li>"))))

(def conn
(def conn
(js/WebSocket. "ws://127.0.0.1:9899/ws"))

(set! (.-onopen conn)
(fn [e]
(.send conn
(.stringify js/JSON (js-obj "command" "getall")))))

(set! (.-onerror conn)
(set! (.-onerror conn)
(fn []
(js/alert "error")
(.log js/console js/arguments)))
Expand All @@ -45,6 +45,6 @@

(.click (js/$ "#send") send-to-server)

(.keyup (.focus i)
(.keyup (.focus i)
(fn [e]
(if (= (.-which e) 13) (send-to-server))))
4 changes: 2 additions & 2 deletions src/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[ring.middleware.file-info :only [wrap-file-info]]
[clojure.tools.logging :only [info]]
[clojure.data.json :only [json-str read-json]]
[ring.middleware.defaults :refer :all]
(compojure [core :only [defroutes GET POST]]
[route :only [files not-found]]
[handler :only [site]]
[route :only [not-found]])))

(defn- now [] (quot (System/currentTimeMillis) 1000))
Expand Down Expand Up @@ -60,5 +60,5 @@
resp)))

(defn -main [& args]
(run-server (-> #'chartrootm site wrap-request-logging) {:port 9899})
(run-server (-> #'chartrootm (wrap-defaults site-defaults) wrap-request-logging) {:port 9899})
(info "server started. http://127.0.0.1:9899"))