I am getting an error when using sente that results in failure while sending information from client to server or vice versa. The problem seems to be that the handshake fails with an error
cljs$core$ExceptionInfo
message: "Invalid event"
data: {:given "~:chsk/handshake", :errors {:wrong-type {…}}}
The successive ws/ping
also fail with the same error but with extra information,
sente.cljc:142 Uncaught #error {:message "Invalid event", :data {:given "~#'", :errors {:wrong-type
{…}[:expected :vector]
[:actual {:type #object[String], :value "~#'"}]
What might be the problem, my code seems okay and follows the default example in sente.
Expected behaviour:Sente would connect and i would be able to call send-fn
and send messages between the server and client, successfully.
Edit: Addition of code as suggested in the comments:
(require '[taoensso.sente.server-adapters.aleph :refer (get-sch-adapter)])
;; Create Websocket connection in server
(let [packer (sente-transit/get-transit-packer)
chsk-server (sente/make-channel-socket-server! (get-sch-adapter) {:packer packer
:csrf-token-fn nil})
{:keys [ch-recv send-fn connected-uids ajax-post-fn ajax-get-or-ws-handshake-fn]} chsk-server]
(def ring-ajax-post ajax-post-fn)
(def ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn)
(def ch-chsk ch-recv)
(def chsk-send! send-fn)
(def connected-uids connected-uids))
;; Start the web server
(defn start-web-server! [& [port]]
(stop-web-server!)
(let [port (or port default-port)
ring-handler (var main-ring-handler)
[port stop-fn]
(let [server (aleph/start-server ring-handler {:port port})
p (promise)]
(future @p)
[(aleph.netty/port server)
(fn [] (.close ^Closeable server) (deliver p nil))])
uri (format "http://localhost:%s/" port)]
(infof "Web server is running at `%s`" uri)
(reset! web-server_ {:port port :stop-fn stop-fn})
(try
(if (and (Desktop/isDesktopSupported)
(.isSupported (Desktop/getDesktop) Desktop$Action/BROWSE))
(.browse (Desktop/getDesktop) (URI. uri))
(.exec (Runtime/getRuntime) (str "xdg-open" uri)))
(Thread/sleep 7500)
(catch HeadlessException _))))
On the client side:
(let [packer (sente-transit/get-transit-packer)
{:keys [chsk ch-recv send-fn state]}
(sente/make-channel-socket-client! "/chsk"
{:type :auto
:packer packer})]
(def chsk chsk)
(def ch-chsk ch-recv)
(def chsk-send! send-fn)
(def chsk-state state))
;; start the router
(defn start-router! []
(stop-router!)
(reset! router_ (sente/start-client-chsk-router! ch-chsk event-msg-handler)))
EDIT, Addition
I have noted that the error only exists when i use the packer, (packers.transit/get-transit-packer)
and not :edn
Ran into this issue today coincidentally, so after this issue I was scratching my head a bit, could it be the library which hasn't seen much activity/is stable?
Nope. I simply forgot to include the
[com.cognitect/transit-cljs "0.8.256"]
cljs dependency!The example did warn: https://github.com/ptaoussanis/sente/blob/master/example-project/src/example/client.cljs#L47