I’m searching a way to subscribe on [external] websocket event stream and process incoming data.
what’s the correct approach?
This topic seems interesting: https://github.com/meh/elixir-socket/issues/19
PhoenixChannelClient seems like correct way to go, the only issue it’s phoenix-centered and can’t work with non-phoenix stream data
Please don’t hijack someone else’s thread. Moved to a new topic.
So you are looking to setup a websocket on a server to use a pre-existing non-phoenix-style socket API?
For note, Phoenix’s stream data is just JSON with a tag, pretty simple.
Yes, this way.
Phoenix’s stream data is just JSON with a tag, pretty simple.
As far as i understand,
- phoenix’s code is a server, not a client
- it still expects that “tag” or so. going to dig deeper, maybe https://github.com/ryo33/phoenix-channel-client can be re-purposed
Yep phoenix’s channels expect that tag and such, you will not use phoenix channels then, instead you will want to hook in to Cowboy’s Websocket stream, which is the really low level raw and fast websocket handler that phoenix uses. You will just register your own adjacent to Phoenix’s is the way with the lowest code count. You can also make your own ‘Socket’ handler in Phoenix as well, it has the ability, just not documented from what I’ve seen yet.
atm playing with https://hex.pm/packages/socket library. So good so far. The only issue is channel stability - wrapper should handle stuff like reconnects. Just hope someone already wrote one
As far as WebSocket clients, you have your connection level clients like gun and as you mentioned socket.
But as far as what I think you’re looking for you want something like websocket_client or WebSockex.
I may be a little partial to WebSockex because it’s my library, but I think it’s pretty good.
But it is still in a non-stable development cycle so the API is still changing.