In the README, the use of the new channels is explained very well. Unfortunately, there is no real documentation on how to use phoenix just with normal websockets (without the channels). Even the api doc (http://api.phoenixframework.org/Phoenix.Socket.Handler.html) is incomplete and probably lacks examples to be easily understood. Could you add documentation for it or point me (and other users) to an explanation, if it already exists elsewhere? Thanks!
You can wire up a cowboy specific websocket handler with the following:
defmodule MyRouter do
use Phoenix.Router
dispatch_option "/ws", MyCowboyWebsocketHandler
end
defmodule MyCowboyWebsocketHandler do
@behaviour :cowboy_websocket_handler
# implement the cowboy websocket behavior
end
I tried this in my router, but always get error:
** (CompileError) web/router.ex:28: undefined function dispatch_option/2
What I doing wrong?
The dispatch_option option is gone. At this moment we don't allow use of the raw websockets. We could allow this though as an option you give directly to the webserver. Then you can manage things directly through cowboy.
@chrismccord do you want to bring this back in some way? My only requirement is that it is very clear it is a cowboy specific option.
@josevalim could you please tell me more about it? Is it possible in current version of phoenix?
No, it is not possible.
We don't currently support raw websocket connections. You can wire up your own Plug cowboy adapter options to make a regular cowboy_websocket_hander, but I don't have a link handy atm. Maybe a simple channel setup would work for your usecase?
@chrismccord no, phoenix channels does not work for me, I need raw websockets.
You can wire up your own Plug cowboy adapter options to make a regular cowboy_websocket_hander
This looks like a black magic for me. Could you please get me more info to get it done?
@arrowcircle https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/endpoint/cowboy_websocket.ex#L36 down are the functions you need to implement. And then you need to add to the dispatch option in the router and or endpoint? I will see if I can get an example up and running next weekend maybe.
@jeregrine Ok, I defined my custom websocket endpoint. But I have no idea how to add it to my app router. Any ideas?
@arrowcircle ahh looks like a recent change got rid of that configuration, I've made an issue to re-add it https://github.com/phoenixframework/phoenix/issues/573 if you'd like to take it in the mean time let me know. I will take a crack at finishing it tonight.
@jeregrine, Thanks! I am interested in using common websockets and phoenix pubsub internal mechanism.
@arrowcircle Can you give us more details on your use-case that channels doesn't provide? If you're wanting to hook into pubsub, it sounds like your websocket handler is starting to be a lot like channels.
@chrismccord exactly, I just cant use default channel responses with js lib I use thats why i want to make a custom endpoint with http api to it
@arrowcircle which library? We need examples of shimming phoenix into existing projects.
On Mon, Jan 5, 2015 at 3:12 PM, Oleg Bovykin [email protected]
wrote:
@chrismccord exactly, I just cant use default channel responses with js lib I use thats why i want to make a custom endpoint with http api to it
Reply to this email directly or view it on GitHub:
https://github.com/phoenixframework/phoenix/issues/234#issuecomment-68782253
I just cant use default channel responses with js lib I use thats why i want to make a custom endpoint with http api to it
It might be easier to shim on the client with phoenix.js -> your lib. We need to know more though to know for sure.
@chrismccord @jeregrine I writing an alternative backend for pusher.com library for learning purpose. I already made a partial functionality in erlang and now want to try elixir.
Sorry to necro this, I also need raw websockets to make an API that doesn't rely on having to install the phoenix.js library first (as that requires the developer to use babel and limits them to JavaScript only).
I also need raw websockets to make an API that doesn't rely on having to install the phoenix.js library first (as that requires the developer to use babel and limits them to JavaScript only).
To be clear, phoenix channels is transport agnostic and does not require javascript. See various third party channel adapters in Java, C#, objc, swift, etc.
Also phoenix.js does not rely on babel once built. We ship a precompiled version of phoenix.js that is already built, so babel is not required to use it.
Thanks for mentioning the other languages, this somehow slipped my mind.
I _could_ make a custom serializer as well but I really just need this one websocket to be a static URL anything can connect to and it doesn't need Phoenix.Channel either since all it does is forward messages from an AMQP queue to the websocket.
I finally found the documentation on how to use the cowboy router around the phoenix one which is a bit of a hassle, but works.
phoenix channels is transport agnostic
but this does require you to implement the channel adapters on the client side,
in my case, I have little control over the client and it uses the subprotocol headers to determine the message protocol, so support for normal web sockets would benefit me greatly
I set phx_raws up after a few hours of testing. I did not quite like setting up _cowboy_ manually so I got my way around it!
Hope this is as useful to you as it is to me. @gertjana @narrowtux @arrowcircle
That鈥檚 awesome!
Most helpful comment
I set phx_raws up after a few hours of testing. I did not quite like setting up _cowboy_ manually so I got my way around it!
Hope this is as useful to you as it is to me. @gertjana @narrowtux @arrowcircle