I have an Elixir 1.54 and Phoenix umbrella app containing:
[AdminWeb]
[Admin]
[DisplayWeb]
The [AdminWeb] calls a function defined in [Admin] that pulls information from a
Database, then converts it to a list of maps and should broadcast it to DisplayWeb channel:
[AdminWeb] --> [Admin] --> [DisplayWeb]
The code in [Admin] looks like this:
# news.ex
def news_sort(id_list) do
news_payload = news_items_from_db() |> struct_to_map()
PubSub.broadcast(Admin.PubSub, "cast:news", news_payload)
end
The code in [DisplayWeb] looks like this:
#news_channel.ex
def join("cast:news", _payload, socket) do
self() |> send({:after_join, "cast:news"})
{:ok,socket}
end
def handle_info({:after_join, "cast:news"}, socket) do
broadcast!(socket, "newscast", %{data: news_payload})
{:noreply, socket}
end
The PubSub.broadcast
in [Admin] returns :ok message but the [DisplayWeb] does not receive any message. It neither works not returns any error message.
Please, what’s wrong with the code? What’s the right way to implement this solution?