mazzie
Is it possible to create topics dynamically in Phoenix
I am new to Phoenix. I was wondering if it is possible to create topics dynamically in Phoenix.
From what I understood till now in Phoenix if a user joins a topic they get all the messages sent on that topic. What if I want add a functionality in which user can create own topic and then send messages on it. Is that possible ?
Marked As Solved
zinclozenge
You would need a macro that dynamically creates user_socket.ex based on input provided to the macro.
Also Liked
James-Byrne
Thats totally possible, so in the user_socket.ex file you add a room as "room:name:*". Just add whatever you want after the star when joining the channel and boom your off.
For example I have a team channel defined like :
channel("team:*", TpPhoenixWeb.RequestCounterChannel)
The user then joins a channel named "team:API_KEY_HERE" and only they can see what is broadcast there.
benwilson512
To be clear, what the macros in user_socket do is route topics that have a particular prefix to a particular channel module. You could make a generic one:
channel "generic:*", GenericChannel
Then you can put literally anything after generic:
axelson
I believe that you can meaningfully accomplish this task without creating a macro as specified by @benwilson512 above. And in general if you can accomplish something with just modules and functions then use that approach. Quoth the Elixir docs: “Macros should only be used as a last resort”.
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








