@kenny: It has worked any solution?
@niwinz: Right. The problem with those solutions is that they both put the static assets under route. I do not want the assets to be under a route. I want the static assets to be located at / or the root.
oh
I missed that part, sorry.
The last solution should work for you I think.
In any case just now I'm doing some work in cartacumba so I'm going to create a test case for that
@kenny: https://github.com/funcool/catacumba/commit/6525077b2851403fb6bb86cf88e8b18a2ecc47ec
this can be done with the catacumba 0.10.x
and it works as expected
Awesome!
The catacumba 0.11.x will expose a simple way to serve yourself files in a efficient way 😉
Even better :simple_smile:
On a separate note.. Is there a way to add a on-closed handler to a postal socket?
hmm postal socket is just a normal websocket with simple encode/decode middleware, and websockets expose a ctrl channel that can be listen for client close messages
in the same way as you get in
and out
channel, you can obtain the ctrl
So when ctrl closes the websocket has been closed?
ctrl will populated with [:close]
or [:error]
and inmediatelly closed
In any case, does not tie your code to the values in ctrl channel
are subject to change (I don't like the current value)
consider that if a message received in ctrl channel
the user has closed the connection
Got it
Maybe in the future on-error and on-close functions can be passed to the postal socket
function ?
hmm nice idea
(defn subscribe-to-events
{:handler-type :catacumba/websocket}
[{:keys [in out ctrl]}]
(let [ch (ws/subscribe)]
(go-loop []
(let [[v p] (a/alts! [ctrl ch in])]
(cond
;; RECEIVING MESSAGES FROM FRONT
(= p in)
(do ws/dispatch v)
;; NORMALLY CAUSE FRONT HAS CLOSED
(= p ctrl)
(do
(println "closed")
(a/close! ch))
;; SENDING MESSAGES TO SUBSCRIBERS
(= p ch)
(do
(>! out v)
(recur)))))))
this is a simple example
What is ws/subscribe?
this code is out of context
the subscribe is part of the logic from where I have extracted the code...
Oh I see. It's just a channel you use to send messages from other places.
yes 😛
is just a "event bus" or "pubsub"
https://github.com/funcool/catacumba/blob/master/examples/postal-chat/src/clj/compchat/core.clj#L59
Here an other example
Cool thanks!
As far as I can see, you are using postal, I really appreciate some feedback/comments/opinons about it 😛
I really like the higher level of abstraction so I don't need to worry about the nitty gritty parts of client-server communication
I also really like the stream model. Have you considered writing a version of beicon for clj so that you can use streams on both sides of the postal api?
\o/
You are not the first one that ask for clj version of beicon
The problem with streams is its backpressure support
In client side, streams are used because backpressure in js is not very important (and ws does not has clear access for proper handling it)
but in server side is very important
but is more "complicated" in term of syntax handle properly backpressure with streams in backend
and channels handles that much better
this is the main reason because core.async is used in the backend
But I'll spend some time in research in the posibility to build beicon for clj
I also prefer the stream approach over core.async
Right. Yeah I also like the stream approach. I end up with cleaner code.
At this moment the core.async method is more "production" ready because it handles backpresure apropriatelly and allows not send/receive messages that client/server can't process.
Yeah. I'll keep using core.async for now :simple_smile:
Does closing ctrl on the server also close the websocket connection?
It looks like it does. Just verifying that everything actually got closed..
the recommended is closing the out
closing the out
channel is way to do it.
Okay