Licenser
Plan old websockets in phoenix but without magic
Hi, I’m looking for a way to create a good old web socket and to send data from and to the browser. The result is going to end up in xterm.js (browser-based terminal), so the whole channels thing is out of the question (I don’t want to re-write xterm.js just to support channels).
I’ve tried phx_raws, but Phoenix still wants to mess with the messages the process gets and breaks stuff.
I’ve looked at overwriting HTTP: on the config, but that breaks the live reloader.
I’m quite lost here, I just want a good old WebSocket, the logic is super simple: if it receives {:binary, bla} from the socket, it calls a library, if it receives {:data, bla} it sends it to the socket. A bit auth sprinkled on it, and that’s it (literally a copy of this src/wiggle_console_h.erl · test · Project-FiFo / FiFo / wiggle · GitLab).
Any advice, am I missing a flag to turn off ‘magic’?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










Marked As Solved
sasajuric
You need to have something like this in you endpoint config:
Notes:
:devenvironmenthttpsconfig as well/insteadNow, you can use the standard cowboy handler, for example:
Also Liked
OvermindDL1
Phoenix’s websocket support is via an abstraction of ‘Channels’ and phoenix does not really have any websocket helpers itself.
Rather what you want, if you want raw websockets, is just to use the cowboy API underneath Phoenix directly. Phoenix tends to not rewrite anything into itself if one of it’s dependencies already handles it, and as cowboy handles raw websockets already then it does nothing special with it, just implement cowboy’s API and put cowboy in your supervision tree, hooking in phoenix in the right place too. There are docs, hmm… somewhere on how to do it, maybe someone will link them? Hard for me to google at moment… ^.^;
Licenser
Thank you
that does the trick!
sasajuric
Have you tried this? This allows you to specify custom Cowboy dispatch list, and then you should be able to handle websocket connections without using the channels protocol.
Last Post!
tmbb
You might be interested in this: PhoenixWS - Websockets over Phoenix Channels