try to fix websockets
This commit is contained in:
parent
17f2326b56
commit
cbe2b3a60b
3 changed files with 22 additions and 17 deletions
1
deps.edn
1
deps.edn
|
|
@ -15,6 +15,7 @@
|
||||||
com.github.seancorfield/next.jdbc {:mvn/version "1.3.894"}
|
com.github.seancorfield/next.jdbc {:mvn/version "1.3.894"}
|
||||||
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
|
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
|
||||||
metosin/muuntaja {:mvn/version "0.6.8"}
|
metosin/muuntaja {:mvn/version "0.6.8"}
|
||||||
|
ring/ring-core {:mvn/version "2.0.0-alpha1"}
|
||||||
ring/ring-defaults {:mvn/version "0.3.4"}
|
ring/ring-defaults {:mvn/version "0.3.4"}
|
||||||
org.clojure/clojure {:mvn/version "1.11.3"}
|
org.clojure/clojure {:mvn/version "1.11.3"}
|
||||||
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}
|
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
(ns com.score-the-pigs
|
(ns com.score-the-pigs
|
||||||
(:require
|
(:require
|
||||||
[clojure.pprint :as pp]
|
|
||||||
[clojure.test :as test]
|
[clojure.test :as test]
|
||||||
[com.biffweb :as biff]
|
[com.biffweb :as biff]
|
||||||
[com.score-the-pigs.app :as app]
|
[com.score-the-pigs.app :as app]
|
||||||
[com.score-the-pigs.middleware :as mid]
|
[com.score-the-pigs.middleware :as mid]
|
||||||
[com.score-the-pigs.ui :as ui]
|
[com.score-the-pigs.ui :as ui]
|
||||||
[migratus.core :as migratus]
|
|
||||||
[next.jdbc :as jdbc]
|
[next.jdbc :as jdbc]
|
||||||
[nrepl.cmdline :as nrepl-cmd]
|
[nrepl.cmdline :as nrepl-cmd]
|
||||||
[taoensso.telemere.timbre :as log])
|
[taoensso.telemere.timbre :as log])
|
||||||
|
|
@ -74,7 +72,6 @@
|
||||||
|
|
||||||
(defn start []
|
(defn start []
|
||||||
(let [new-system (reduce (fn [system component]
|
(let [new-system (reduce (fn [system component]
|
||||||
(pp/pprint system)
|
|
||||||
(log/info "starting:" (str component))
|
(log/info "starting:" (str component))
|
||||||
(component system))
|
(component system))
|
||||||
initial-system
|
initial-system
|
||||||
|
|
|
||||||
|
|
@ -120,18 +120,17 @@
|
||||||
|
|
||||||
(defn connect-ws [{:keys [path-params]
|
(defn connect-ws [{:keys [path-params]
|
||||||
:example/keys [chat-clients]}]
|
:example/keys [chat-clients]}]
|
||||||
|
|
||||||
(let [code (:code path-params)]
|
(let [code (:code path-params)]
|
||||||
{:status 101
|
(jetty/ws-upgrade-response
|
||||||
:headers {"upgrade" "websocket"
|
{:on-connect (fn [ws]
|
||||||
"connection" "upgrade"}
|
(swap! chat-clients assoc code ws))
|
||||||
:ws {:on-connect (fn [ws]
|
:on-close (fn [ws _status-code _reason]
|
||||||
(swap! chat-clients assoc code ws))
|
(swap! chat-clients
|
||||||
:on-close (fn [ws _status-code _reason]
|
(fn [chat-clients]
|
||||||
(swap! chat-clients
|
(let [chat-clients (update chat-clients code disj ws)]
|
||||||
(fn [chat-clients]
|
(cond-> chat-clients
|
||||||
(let [chat-clients (update chat-clients code disj ws)]
|
(empty? (get chat-clients code)) (dissoc code))))))})))
|
||||||
(cond-> chat-clients
|
|
||||||
(empty? (get chat-clients code)) (dissoc code))))))}}))
|
|
||||||
|
|
||||||
(def pig-position
|
(def pig-position
|
||||||
["jowler"
|
["jowler"
|
||||||
|
|
@ -300,7 +299,13 @@
|
||||||
(jdbc/execute! tx (sql/format
|
(jdbc/execute! tx (sql/format
|
||||||
{:update :player
|
{:update :player
|
||||||
:set {:game_score :round_score
|
:set {:game_score :round_score
|
||||||
:round_score 0}}))
|
:round_score 0}
|
||||||
|
:where [:and [:= :play_order current-player]
|
||||||
|
[:= :game_code :game-code]]}))
|
||||||
|
|
||||||
|
(jdbc/execute! tx (sql/format
|
||||||
|
{:update :player
|
||||||
|
:set {:round_score 0}}))
|
||||||
(jdbc/execute! tx next-player-query))
|
(jdbc/execute! tx next-player-query))
|
||||||
@update-display-table
|
@update-display-table
|
||||||
(now-playing next-player game-code ds)))
|
(now-playing next-player game-code ds)))
|
||||||
|
|
@ -310,8 +315,10 @@
|
||||||
(jdbc/with-transaction [tx ds]
|
(jdbc/with-transaction [tx ds]
|
||||||
(jdbc/execute! tx (sql/format
|
(jdbc/execute! tx (sql/format
|
||||||
{:update :player
|
{:update :player
|
||||||
:set {:game_score 0
|
:set {:game_score :round_score
|
||||||
:round_score 0}}))
|
:round_score 0}
|
||||||
|
:where [:and [:= :play_order current-player]
|
||||||
|
[:= :game_code :game-code]]}))
|
||||||
(jdbc/execute! tx next-player-query))
|
(jdbc/execute! tx next-player-query))
|
||||||
@update-display-table
|
@update-display-table
|
||||||
(now-playing next-player game-code ds))
|
(now-playing next-player game-code ds))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue