I am trying to implement a livechat behavior that is supposed to process an incoming chat request by causing a little popup modal to appear and then redirect to a livechat modal which is intended to be a LiveView. As there is no conn, live_render cannot be used to mount the LiveView. Is there any other way I could implement this?
Hi @PaulRusuTibreanu can you elaborate which part you’re stuck on? Is it the “incoming chat request” bit?
Thanks for reaching out. No, it is the bit where the PubSub/GenServer is supposed to mount the LiveView. As far as I can tell, there is no direct way to mount without having a conn using live_render, thus an API call channelled through the router. Am I mistaken?
What does this mean? Connect the dots for me from the client’s browser to the genserver. How are they related?
A remote server receives a request from a remote client and sends an API call to the Phoenix server which then is to create a little notification box on all clients. As soon as one of those clients accepts the request, the two clients are supposed to be joined in a phoenix channel. (P.S.: The remote server is also a phoenix server).
Right so the easiest way to do this is for these clients who are gonna have the notification box to already be using liveview. Then their liveviews just subscribe to the pubsub topic, and create a notification box. If the clients are not connected to the phoenix server how would they get a notification?
Exactly, so that is why I was wondering how to mount the LiveView automatically, without a router call to it directly or indirectly (from a component that has to be called by a router call or a redirect).
I apologize if I am being obtuse but I don’t understand what you expect to be possible. No server in any language can make things happen on the client if the client is not connected.
You can use nested live_view… You cannot somehow magically create a live view upon receiving a message from pubsub.
The idea is to have a separate live_view responsible for chat or notifications. It could be mounted in the live layout. If You don’t have it You could always create and configure it. It’s not the default to have one in Phoenix 1.7 I think…
The disadvantage is it create one more process per client.