File tree Expand file tree Collapse file tree 5 files changed +62
-0
lines changed Expand file tree Collapse file tree 5 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ pom.xml
2
+ * jar
3
+ /lib /
4
+ /classes /
5
+ .lein-failures
6
+ .lein-deps-sum
Original file line number Diff line number Diff line change
1
+ # ws-cljs
2
+
3
+ WebSocket & ClojureScript repository.
4
+
5
+ ## License
6
+
7
+ Copyright (C) 2011 FIXME
8
+
9
+ Distributed under the Eclipse Public License, the same as Clojure.
Original file line number Diff line number Diff line change
1
+ (defproject ws-cljs " 0.1-SNAPSHOT"
2
+ :description " WebSocket and ClojureScript gitorial"
3
+ :main " ws-cljs.core"
4
+ :dependencies [[org.clojure/clojure " 1.2.1" ]
5
+ [aleph " 0.2.0-alpha2" ]
6
+ [compojure " 0.6.5" ]
7
+ [hiccup " 0.3.6" ]]
8
+ :dev-dependencies [[slamhound " 1.2.0" ]])
Original file line number Diff line number Diff line change
1
+ (ns ws-cljs.core
2
+ (:use [aleph.http :only [start-http-server wrap-aleph-handler wrap-ring-handler]]
3
+ [compojure.core :only [GET defroutes ]]
4
+ [hiccup.page-helpers :only [html5 include-js]]
5
+ [lamina.core :only [channel map* receive siphon]]
6
+ [ring.middleware.file :only [wrap-file]])
7
+ (:require [compojure.route :as route]))
8
+
9
+ (def broadcast-channel (channel ))
10
+
11
+ (defn chat-handler [ch handshake]
12
+ (println " Connected " handshake)
13
+ (receive ch
14
+ (fn [name]
15
+ (println " Hello " name)
16
+ (siphon (map* #(str name " : " %) ch) broadcast-channel)
17
+ (siphon broadcast-channel ch))))
18
+
19
+ (defn layout [& content]
20
+ (html5 [:head [:title " new page" ] (include-js " js/ws-control.js" )]
21
+ [:body content]))
22
+
23
+ (defroutes my-app
24
+ (GET " /" [] (layout [:p " awesome!" ]))
25
+ (GET " /socket" [] (wrap-aleph-handler chat-handler))
26
+ (route/not-found (layout [:p " aww... this doesn't exist" ])))
27
+
28
+ (defn -main []
29
+ (start-http-server (-> my-app
30
+ (wrap-file " html" )
31
+ wrap-ring-handler) {:port 8080 :websocket true })
32
+ (println " server started" ))
33
+
Original file line number Diff line number Diff line change
1
+ (ns ws-cljs.test.core
2
+ (:use [ws-cljs.core])
3
+ (:use [clojure.test]))
4
+
5
+ (deftest replace-me ; ; FIXME: write
6
+ (is false " No tests have been written." ))
You can’t perform that action at this time.
0 commit comments