Fork me on GitHub
#fulcro
<
2023-11-08
>
Eric Dvorsak23:11:53

One needs to dig into fulcro-websockets code to figure out that for a push handler such as:

(fws/fulcro-websocket-remote {:csrf-token token  :push-handler push-handler})                                                             
the server must use the topic :api/server-push:
((:send-fn  websockets) 6421 [:api/server-push :lasagna])

tony.kay00:11:19

(defstate websockets
  :start 
  (fws/start! (fws/make-websockets
                                 query-parser
                                 {:http-server-adapter (get-sch-adapter)
                                  :parser-accepts-env? true
                                  ;; See Sente for CSRF instructions. If you are using ring-defaults,
                                  ;; you will likely want {:csrf-token-fn :anti-forgery-token} here.
                                  :sente-options       {:csrf-token-fn nil}})))
and then you can use the protocols directly on websockets as the this.

Eric Dvorsak07:11:10

indeed thanks, although it should be (.push websockets cid :x {:value 1}) not (push websockets cid :x {:value 1}) right? I think that's the bit that confused me last time, was late and I haven't used a protocol for a year so I forgot about the . and since it wasn't there on the doc either I didn't manage to use push

tony.kay16:11:30

No you don't need a dot. You're thinking native OOP interop.

Eric Dvorsak16:11:41

True, not sure why .push works and not push for me

Eric Dvorsak16:11:34

brian.server-components.websockets> (push websockets 6421 :test {:type :topic-description :subject/id 481})
Syntax error compiling at (*cider-repl ~/brian:localhost:7888(clj)*:23279:37).
Unable to resolve symbol: push in this context
2023-11-09T16:53:11.953Z project2501 DEBUG [taoensso.sente:803] - [ws/on-msg] Server will auto-reply to ping from u_6421/c_d5b25c/n_9948cc
brian.server-components.websockets> (.push websockets 6421 :test {:type :topic-description :subject/id 481})
nil2023-11-09T16:53:14.949

tony.kay19:11:02

push has to be namespaced

tony.kay19:11:20

protocols declare function-like names within their namespace…again, not OOP interop. The .push is leveraging the fact that the protocol is being implemented by deftype, which does generate a class. Using the OOP interop means you’re actually kind of ignoring the protocol…for example, extend would not work with the interop

Eric Dvorsak19:11:02

Yeah I tried with fulcro.networking.websocket, didn't realize the protocol was defined in com.fulcrologic.fulcro.networking.websocket-protocols

Jakub Holý (HolyJak)21:11:28

WDYT about https://github.com/fulcrologic/fulcro-websockets/pull/9/files ? One thing I’d like to understand is what is the verb (in the examples :x ) in this context.

Eric Dvorsak23:11:37

Depends how you want to use the ws. I for instance didn’t really tried to understand how to get my Authn/authz work for using it as the main remote for pathom queries so it’s just there for server pushes. I have a case on the client Based on :x it let’s me know what to do with the message