regex.sh
Pushing data from LiveView to Channel over PubSub?
I have a Channel on which the JavaScript front-end connects.
I have a LiveView UI from which the user can type messages and send them to JS UI (well, it can’t, which is the problem here).
My flow is as follows:
JS user ----> |subscribe to |
LV user ----> |same topic |
C = Channel
LV= LiveView
--> C) broadcast(some_message)
--> LV) handle_info(some_message)
--> LV) broadcast(reply_message)
--> C) handle_info(reply_message)
--> C) push(socket, reply_message) <-- !DOES NOT WORK
Is this even possible?
I saw this blog from Sophie DeBenedetto which leads me to think this doesn’t work (without Registry)
Any help?
Marked As Solved
regex.sh
but the devil is in the details of how your subscriptions and broadcasts are done.
Yup, devil was in the detail ![]()
I subscribed to topic outside “join” callback (I have send() for :after_join)
It now requires me to implement handle_out, which I did and push is working ![]()
Is handle_out normal for this sort of thing?
Current code (it’s currently WIP, so don’t judge haha)
I had subscribe in handle_info prior to this
def join("live-chat:room:" <> guest_id, %{"platformId" => platform_id}, socket) do
GuestChat.subscribe("live-chat:room:" <> guest_id)
send(self(), {:join_room, platform_id, guest_id})
{:ok, socket |> assign(:guest_id, guest_id)}
end
def handle_info({:join_room, platform_id, guest_id}, socket) do
GuestChat.broadcast("live-chat:room:" <> guest_id, "new_guest", %{uid: guest_id})
Presence.track(socket, "live-chat:room:" <> guest_id, %{guest_id: guest_id, platform_id: platform_id})
{:noreply, socket}
end
Also Liked
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








