chronoscope/lib/chronoscope_web/live/index_live.ex

17 lines
393 B
Elixir

defmodule ChronoscopeWeb.IndexLive do
use ChronoscopeWeb, :live_view
alias Chronoscope.NTS
@topic "nts-servers"
def mount(_params, _session, socket) do
ChronoscopeWeb.Endpoint.subscribe(@topic)
{:ok, assign(socket, %{servers: NTS.list()})}
end
def handle_info(%{topic: @topic, payload: servers}, socket) do
{:noreply, assign(socket, %{servers: servers})}
end
end