deepukjayan

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

sb8244

Author of Real-Time Phoenix

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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

sb8244

Author of Real-Time Phoenix

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

kokolegorille

This might help You if You go the cowboy way…

Last Post!

lud

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.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New

We're in Beta

About us Mission Statement