deepukjayan
Phoenix.socket - How to support wildcard topic
Is it possible to listen wildcard topic in a channel
# my_socket.ex
use Phoenix.Socket
## Channels
channel "*", AbcWeb.MyChannel #something of this sort?
First Post!
sb8244
Welcome to the forum!
Yes this is definitely supported by Phoenix Socket/Channel and is the same format you use. You do need to ensure that the wildcard is at the end of the string. So "users:*" is supported but "users:*:widgets" is not supported. Here’s a toy example of how you might do this.
socket.ex
channel "wild:*", HelloSocketsWeb.WildcardChannel
wildcard_channel.ex
def join("wild:" <> numbers, _payload, socket) do
if numbers_correct?(numbers) do
{:ok, socket}
else
{:error, %{}}
end
end
Most Liked
benwilson512
Yeah Phoenix Sockets are not the right answer here, even if you have a wildcard topic there is still a protocol channel clients are expected to follow. It sounds like you want to do a custom raw websocket connection. I found Phx_raws - Raw websocket on top of Phoenix not sure if it’s still up to date though.
sb8244
I would suggest trying to stick to cowboy as the WebSocket server if possible. It’s super stable and you’ll get more support for it if you run into issues (because Phoenix uses it). Ben’s link to phx_raws looks promising.
kokolegorille
Last Post!
lud
Well if you need to use Phoenix then you have no choice but use custom dispatch.
Now, you could also just use cowboy and not Phoenix at all.
Popular in Questions
Other popular 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
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









