Skip to content

Commit

Permalink
send-response
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Jun 25, 2024
1 parent cecec28 commit 49f0f04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
20 changes: 0 additions & 20 deletions src/modular/ws/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@
(doseq [uid uids]
(send! this uid data)))))

;; REPLY

(defn send-response [{:as ev-msg :keys [id ?data ring-req ?reply-fn uid send-fn]}
msg-type response]
;(let [session (:session ring-req)
;uid (:uid session)
; ]
;(when (nil? ?reply-fn)
; (warn "reply-fn is nil. the client did chose to use messenging communication istead of req-res communication."))
;(warn "ws/session: " session)
;(if (nil? uid)
; (warn "ws request uid is nil. ring-session not configured correctly.")
; (info "ws/uid: " uid))
(if (and msg-type response)
(cond
?reply-fn (?reply-fn [msg-type response])
uid (send-fn uid [msg-type response])
:else (error "Cannot send ws-response: neither ?reply-fn nor uid was set!"))
(error "Can not send ws-response - msg-type and response have to be set, msg-type:" msg-type "response: " response)))

;; WATCH

(defn connected-uids [this]
Expand Down
26 changes: 24 additions & 2 deletions src/modular/ws/msg_handler.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
(ns modular.ws.msg-handler
(:require
[taoensso.timbre :refer [tracef debug debugf info infof warn warnf error errorf]]
[modular.ws.core :refer [send-response]]))
[taoensso.timbre :refer [tracef debug debugf info infof warn warnf error errorf]]))

(defn ws-reply [{:keys [event id ?data ring-req ?reply-fn send-fn] :as req}
res]
(when ?reply-fn
(?reply-fn res)))

;; REPLY

(defn send-response [{:as ev-msg :keys [id ?data ring-req ?reply-fn uid send-fn]}
msg-type response]
;(let [session (:session ring-req)
;uid (:uid session)
; ]
;(when (nil? ?reply-fn)
; (warn "reply-fn is nil. the client did chose to use messenging communication istead of req-res communication."))
;(warn "ws/session: " session)
;(if (nil? uid)
; (warn "ws request uid is nil. ring-session not configured correctly.")
; (info "ws/uid: " uid))
(if (and msg-type response)
(cond
?reply-fn (?reply-fn [msg-type response])
uid (send-fn uid [msg-type response])
:else (error "Cannot send ws-response: neither ?reply-fn nor uid was set!"))
(error "Can not send ws-response - msg-type and response have to be set, msg-type:" msg-type "response: " response)))




(defmulti -event-msg-handler :id)

(defmethod -event-msg-handler :chsk/uidport-open
Expand Down

0 comments on commit 49f0f04

Please sign in to comment.