This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-27
Channels
- # announcements (1)
- # babashka (2)
- # beginners (64)
- # cider (1)
- # cljs-dev (49)
- # cljsrn (2)
- # clojure (49)
- # clojure-europe (3)
- # clojure-norway (1)
- # clojure-spec (7)
- # clojurescript (116)
- # conjure (3)
- # cursive (4)
- # datomic (1)
- # emacs (2)
- # fulcro (15)
- # graalvm (10)
- # kaocha (1)
- # leiningen (4)
- # meander (1)
- # music (1)
- # off-topic (7)
- # re-frame (37)
- # reagent (3)
- # releases (1)
- # rewrite-clj (6)
- # sci (4)
- # shadow-cljs (16)
- # sql (8)
- # tools-deps (16)
- # xtdb (5)
not sure of a better place to ask this, but any ideas why my sente client won’t connect?
(defn start-client! []
(let [client (sente/make-channel-socket-client!
"/ws"
{:host "10.0.2.2"
:port 8888})]
(def chsk (:chsk client))
(def ch-chsk (:ch-recv client))
(def chsk-send! (:send-fn client))
(def chsk-state (:state client))))
what kind of error are you getting?
client.core> @chsk-state
{:type :auto, :open? false, :ever-opened? false, :csrf-token {:host "192.168.1.51", :port 8888}, :last-ws-error {:udt 1593226359007, :ev #object[Event [object Object]]}, :last-close {:udt 1593226359008, :reason :downgrading-ws-to-ajax}, :last-ws-close {:udt 1593226359082, :ev #object[Event [object Object]], :clean? nil, :code nil, :reason nil}}
client.core> (start-client!)
#object[cljs.core.Atom {:val {:type :auto, :open? false, :ever-opened? false, :csrf-token {:host "192.168.1.51", :port 8888}}}]
based on the network traffic, it looks like my url is being constructed all weird, in the inspector, its trying to connect with
ws:///ws?client-id={guid}&csrf-token=….
what kind of emulator? android?
it should be
where are you seeing it show ws:///ws?client-id={guid}&csrf-token=….
?
where in the emulator?
switched to this
(let [client (sente/make-channel-socket-client!
"10.0.2.2:8888/ws"
{:host "10.0.2.2"
:port 8888})]
i'm assuming that if you do nc 127.0.0.1 8888
on your computer (not in the emulator), it connects to something?
do you get any exceptions?
it's just connecting and waiting
which means there's at least a server listening on that port
it's weird that there's no exceptions
if you run nc -l 8889
and then try to connect on port 8889, does anything show up in the terminal running nc -l 8889
?
oh, so there might be an exception, but just being ignored somewhere
the atom has information in it which seems to relate to an exception but i can’t get it out
{:type :auto, :open? false, :ever-opened? false, :csrf-token {:type :ws, :host "10.0.2.2", :port 8888}, :last-ws-error {:udt 1593228475869, :ev #object[Event [object Object]]}, :last-close {:udt 1593228475869, :reason :downgrading-ws-to-ajax}, :last-ws-close {:udt 1593228476043, :ev #object[Event [object Object]], :clean? nil, :code nil, :reason nil}, :udt-next-reconnect 1593228498545}
it definitely keeps trying to connect, i threw in debugging on the server and the requests are coming through, but nothing is happening
yea, if you're seeing the requests coming through
(let [chsk-server (sente/make-channel-socket-server! (get-sch-adapter) {})
{: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) ; ChannelSocket's receive channel
(def chsk-send! send-fn) ; ChannelSocket's send API fn
(def connected-uids connected-uids)) ; Watchable, read-only atom
(defmulti msg-handler :id)
(defmethod msg-handler :test [event]
(prn event))
(defmethod msg-handler :notification/register-device-token [{:keys [uid ?data] :as event}]
(prn "Received device token register request: " event))
(defn wrap-msg-handler
[event]
(try
(msg-handler event)
(catch Exception e
(timbre/error e))))
(defonce router_ (atom nil))
(defn stop-router! [] (when-let [stop-fn @router_] (stop-fn)))
(defn start-router! []
(stop-router!)
(reset! router_
(sente/start-server-chsk-router!
ch-chsk
wrap-msg-handler)))
you might be able to use:
(defn obj->clj [x]
(reduce (fn [r k] (assoc r k (gobject/get x k)))
{}
(js-keys x)))
to convert the event to a clj mapnothing seems off about the server, but I can't see that it's sending a message back to the client at any point
obj->clj
is a modified version of https://github.com/clojure/clojurescript/blob/r1.10.773-2-g946348da/src/main/cljs/cljs/core.cljs#L10796
for some reason, js->clj
will only convert js objects that return true for (identical? (type x) js/Object)
> {“message” “Expected HTTP 101 response but was ‘403 Forbidden’“, “eventPhase” 0, “cancelable” false, “currentTarget” nil, “BUBBLING_PHASE” 3, “composed” false, “cancelBubble” false, “isTrusted” false, “returnValue” true, “CAPTURING_PHASE” 1, “AT_TARGET” 2, “initEvent” #object[initEvent], “preventDefault” #object[preventDefault], “timeStamp” 1593228475869, “NONE” 0, “stopPropagation” #object[stopPropagation], “bubbles” false, “type” “error”, “stopImmediatePropagation” #object[stopImmediatePropagation], “target” #object[WebSocket [object Object]], “srcElement” #object[WebSocket [object Object]], “defaultPrevented” false, “composedPath” #object[composedPath]}
I did not expect that
hmmm, there's csrf token in the log you showed earlier. I wonder if the fact that the hostname is originally 10.0.2.2 and there's the emulator doing the NAT stuff is causing issues
now we’re getting somewhere, it was definitely me…
(GET "/ws" [req] (ws/ring-ajax-get-or-ws-handshake req))
was
(GET "/ws" [req] ws/ring-ajax-get-or-ws-handshake)
that's always where the bug hide!
Am looking for a guide to help me get started with ClojureScript and rapidly be productive. Will pay for the service. Need only a couple of hours of help. Anyone interested? <mailto:[email protected]|[email protected]> Need to see an example where JavaScript code calls a ClojureScript function, and a ClojureScript function calls a JavaScript library/file.
I think my most frequent bug is when JS interop becomes nil. I would use spec to check if the first element is not nil and if it is the interop :> check that the second element is not nil. Does it make sense? I am struggling to test views as well, I like the kamera solution but never had time to dig in into it.
Hello guys! Has somebody updated to Big Sur? I have a problem with shadow-cljs after update:
shadow-cljs - running: lein run -m shadow.cljs.cli --npm watch app
Syntax error (UnsatisfiedLinkError) compiling at (/private/var/folders/0x/d5945v_9115481gx0v74y87r0000gn/T/form-init6521250380523574093.clj:1:125).
Unable to load library 'Carbon': dlopen(libCarbon.dylib, 9): image not found
Hey @thheller!
I’ve dived a little deeper here and found an interesting thing. It seems that in new macOS the Carbon.framework
is broken (or most likely deleted). Its been deprecated for a while and now /System/Library/Frameworks/Carbon.framework
is only 18 megabytes instead of 138mb which it was before.
So, all the libraries using it are broken on Big Sur.
Including shadow-cljs, figwheel-main and everything that depends on https://github.com/gjoseph/BarbaryWatchService
you can try setting :fs-watch {:hawk false}
in shadow-cljs.edn
. maybe it loads then? hawk should only be loaded conditionally anyways and is only used on macos
How to configure project.clj to include /path/to/undo-manager.js, and then how to access creating an instance of UndoManager and then calling hasUndo() method from ClojureScript.
you might want to try shadow-cljs for this https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js
still working on my sente client, the two sides can connect, and the server receives messages from the client if sent any, but when i try to send messages to the client, messages don’t show up unless messages have been sent before my router is started. any messages sent after my router starts never print. any ideas?
(defn event-msg-handler
"Wraps `-event-msg-handler` with logging, error catching, etc."
[{:as ev-msg :keys [id ?data event]}]
(prn "here")
(prn ev-msg))
(defonce router_ (atom nil))
(defn stop-router! [] (when-let [stop-fn @router_] (stop-fn)))
(defn start-router! []
(stop-router!)
(reset! router_
(sente/start-client-chsk-router!
ch-chsk event-msg-handler)))
ultimately it seems like my async channel is not getting flushed somewhere or the channel is shutting down, i can’t tell. when i send my message server side via (chsk-send! "abc" [:notification/device-registered "abc"] {:flush? true})
and I’m not hooked up to the channel yet client-side, once i do spin up the sente router, it spits it and any other messages queued up out, but any additional messages are lost
is the router a server side thing or a client side thing?
how are you seeing the messages before your router is started?
> it spits it and any other messages queued up out, but any additional messages are lost what is "it"? are you seeing any messages on the client, or just sometimes?
how is the repl printing the messages?
i don't see any issues
what's the client environment like?
is it on android within a browser?
or within an android app running javascript?
if possible, I would try running the javascript on your local computer in Chrome or Firefox since they have pretty good inspectors
that can give you more information about what's happening with the websocket connection itself
I haven't used a cljs repl in a while, so I'm not sure
prn will print to the browser console though
and both chrome and firefox has inspectors that show websocket connections which includes their state and the messages that have been sent/received
from the browser? then it seems like you're all set
no, that’s what i mean by “it spitting out”, it works and prints to my repl, but only when i build up a queue then connect from the client
if i connect from the client, then send a message from the server, the message never shows up client side
what do you see in the inspector?
are the messages arriving? does the connection get closed?
looks like it could be as simple as I don't know my way around aaync well enough yet. it seems like the call to send is usually inside a go block but I tried my own attempt by literally just running the same send command inside a go from the server repl but it still didn't come through
if you could help me write what a call using a go block from the repl would look like, I'm stumped!
code inside a go block will just get executed in a green thread
i'm not sure if send has a return value, but you should be able to run it outside of a go block without issue
you can see more clearly the behavior of what’s happening here in the browser. the server starts talking immediately doing a handshake, and a few pings, but when i start the client router, nothing else is received from the server. it’s the same story for as long as the client’s router is up.
figured it out….it was the version of async…the sente version is seemingly incompatible with newer versions of async
that's a pretty tough bug. glad you figured out a solution!
thanks for the support @U7RJTCH6J!
Hi all! I was wondering if someone has implemented a mime-type check? Before the user uploads something to my S3 server, I would like to check if the file is valid or not. I was thinking about porting https://stackoverflow.com/a/29672957/681159 to cljs but was wondering if there’s another way. Thanks for your time!
Hey @thheller!
I’ve dived a little deeper here and found an interesting thing. It seems that in new macOS the Carbon.framework
is broken (or most likely deleted). Its been deprecated for a while and now /System/Library/Frameworks/Carbon.framework
is only 18 megabytes instead of 138mb which it was before.
So, all the libraries using it are broken on Big Sur.
Including shadow-cljs, figwheel-main and everything that depends on https://github.com/gjoseph/BarbaryWatchService