Understanding websocket connections within liveview

Hey guys, trying to wrap my head around PubSub communication within liveview.

Here’s example

@impl true
  def mount(_params, _session, socket) do
    if connected?(socket) do
      MyappWeb.Endpoint.subscribe("updates-#{socket.assigns.current_user.id}")
    end

    {:ok, assign(socket, index_params: nil, current_page: :updates)}
  end

And then somewhere in code I do

MyappWeb.Endpoint.broarcast(...)

Does that mean that web socket broadcast would be working only within server, so it won’t be visible on browser?

MyAppWeb.Endpoint.subscribe will subscribe the current process, in this case the LiveView, to that topic and pick up any broadcasts. This alll happens on the server but can certainly be—and often are—triggered by client-side events. That is the LiveView model: we usually do the work on the server which is then sync’d with the client.

Yeah, thats what I though too, thanks for clarifying!