taoensso / sente

Realtime web comms library for Clojure/Script
https://www.taoensso.com/sente
Eclipse Public License 1.0
1.73k stars 193 forks source link

Event router not dispatching to channel method, even though :chsk-recv sees a push #402

Closed njerig closed 2 years ago

njerig commented 2 years ago

I have the following event router definition on my client:

(defn event-msg-handler
    [{:as ev-msg :keys [id ?data event]}]
    (-event-msg-handler ev-msg))

(defmethod -event-msg-handler
    :default
    [{:as ev-msg :keys [event]}]
    (js/console.log "Unhandled event: %s" (str event)))

(defmethod -event-msg-handler :chsk/recv
    [{:as ev-msg :keys [?data]}]
    (js/console.log "Push event from server: %s" (str ?data)))

(defmethod -event-msg-handler :api/token
    [{:as ev-msg :keys [?data]}]
    (js/console.log "Received token from backend")
    (cookies/set! :token ?data {:max-age 3600 :secure? true :raw? true}))

My event router on my server is exactly the same, except for the :api/token defmethod, which is this:

(defmethod -event-msg-handler :api/token
    [{:as ev-msg :keys [?data ring-req]}]
    (let [uid (:uid (:session ring-req))
            status (:status ?data)]
        (when (= status :expired)
            (lm/refresh-token :spotify))
        (chsk-send! uid [:api/token (lm/oauth-token :spotify)])))

On the index page, I send {:status :ready} from client to server on the :api/token channel. I expected that, on reply from the server, my client :api/token method would be called. Instead, only the :chsk/recv method is called. Is this a bug?

ptaoussanis commented 2 years ago

@njerig Hi Njeri, please see the :wrap-recv-evs? config option