Skip to content

Commit b63adca

Browse files
committed
incremental work on websockets
1 parent 5115e19 commit b63adca

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/chatb0x/websockets.clj

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@
6060
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6161
;; Agent visitor handling
6262
(defn send-msg2 [client1 client2 msg]
63-
(do (send! client1 msg false)
64-
(send! client2 msg false)))
63+
(do (if client1
64+
(send! client1 msg false))
65+
(if client2
66+
(send! client2 msg false))))
6567

6668
(defn msg-init [client1 client2]
6769
"Send address of opposite end to both clients"
@@ -94,16 +96,23 @@
9496
(defn chat-ws [req]
9597
(with-channel req channel
9698
;; CONNECT
97-
(swap! ds-clients assoc channel {:name nil :email nil :room nil}) ;; Add to ds-clients
98-
(if (= ((:new-path req) "/agent-chat"))
99+
(println req)
100+
(if (contains? (get-in req [:session :cemerick.friend/identity :authentications nil :roles]) :chatb0x.user/agent)
99101
(do (println "Agent connected: " channel) ;; Agent
102+
(swap! ds-clients assoc channel {:name nil :email nil :room nil}) ;; Add to ds-clients
100103
(swap! ds-agents assoc channel {}))
101-
(let [agent (get-free-agent) ;; Visitor
102-
visitor channel]
103-
(println "Visitor connected: " channel)
104-
(ds-agents-add-visitor agent visitor)
105-
(ds-visitors-add visitor agent)
106-
(send! agent (generate-string {:visitor visitor}) false)))
104+
(let [ch-agent (get-free-agent) ;; Visitor
105+
ch-visitor channel
106+
vis-email (get-in req [:session :cemerick.friend/identity :authentications nil :username])
107+
agent-email "[email protected]"]
108+
(if (= ch-agent nil)
109+
(println "ERROR EVENTUALLY!!! no agents on, ignoring visitor!")
110+
(do (println "Visitor connected: " channel)
111+
(swap! ds-clients assoc ch-visitor {:name nil :email vis-email :room nil}) ;; Add to ds-clients
112+
(ds-agents-add-visitor ch-agent ch-visitor)
113+
(ds-visitors-add ch-visitor ch-agent)
114+
(send! ch-agent (generate-string {:visitor (str ch-visitor) :vis-email vis-email}) false)
115+
(send! ch-visitor (generate-string {:agent-email agent-email}) false)))))
107116
;; RECEIVE
108117
(on-receive channel (fn [data]
109118
(println "on-receive channel:" channel " data:" data)

0 commit comments

Comments
 (0)