Open Licenser opened 6 years ago
I should follow up here the info I was missing here was:
defmodule Example.Endpoint do
use Phoenix.Endpoint, otp_app: :example
socket "/websockets", Example.Gateway
# ...
end
I can make a PR to include that in the readme but it might be simpler just to copy&paste that snippet :)
I agree a better example would help a lot, this is something I will tackle as I'm done with #1. 🙂
For the record and in the meantime, I would like to reference a topic you created on the forum that might be helpful for other devs to read - specifically the marked answer as it contains a nice example.
HI! which url is right? @Licenser
huh?
new Websocket("url")
var ws = new WebSocket("ws://localhost:4001/websockets")
and var ws = new WebSocket("ws://localhost:4001/websockets/websocket")
don't work.
@dcy this is what Phoenix sets as your socket path. It essentially joins the string given on the socket
macro and the atom provided on the transports
macro.
That-is, if you have socket "", Example.Gateway
and transports :gateway, ...
then your path would be an empty string joined with the stringified atom, thus /gateway
.
What's the diffrence between phx_raw and Custom dispatch options?
Essentially phx_raws serves as an utility for those who don't want to both have to add an own cowboy handler nor configure the dispatch options every time a socket is added or a new project to be started.
Besides, this follows Phoenix' semantics and uses its code - thus no functionality is re-implemented unnecessarily.
@dcy sorry I don't remember, I ended up using the custom dispatch as even with phx_raws phoenix kept messing with my code so I couldn't use it. (not phx_raw's fault!)
@dcy sorry I don't remember, I ended up using the custom dispatch as even with phx_raws phoenix kept messing with my code so I couldn't use it. (not phx_raw's fault!)
how did you do the dispatch to be compatible with existing Router/Endpoint in your project? can you share an example?
Hi first of all thanks for creating this, I was quite shocked to see that WebSockets are not supported in Phoenix and relieved to find this :D
That said for those of us less versed in Phoenix it would be really awesome to add a line or two how to add this to the routes.