diff --git a/lib/chronoscope/application.ex b/lib/chronoscope/application.ex index f297711..1f35d3d 100644 --- a/lib/chronoscope/application.ex +++ b/lib/chronoscope/application.ex @@ -23,7 +23,7 @@ defmodule Chronoscope.Application do {Registry, [keys: :unique, name: Chronoscope.Gemini.Registry]}, # Start to serve requests, typically the last entry ChronoscopeWeb.Endpoint, - Chronoscope.Monitor + Chronoscope.ViewActivator ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/chronoscope/nts/client.ex b/lib/chronoscope/nts/client.ex index 2500e6e..b39fec9 100644 --- a/lib/chronoscope/nts/client.ex +++ b/lib/chronoscope/nts/client.ex @@ -77,7 +77,7 @@ defmodule Chronoscope.NTS.Client do if interval_surpassed?(now, state.last_key_establishment) do state |> Map.merge(current_data(state, now)) - |> tap(fn _ -> ChronoscopeWeb.Endpoint.broadcast(@topic, "", "") end) + |> tap(&ChronoscopeWeb.Endpoint.broadcast(@topic, "key-exchange", Map.delete(&1, :timer))) else state end diff --git a/lib/chronoscope/monitor.ex b/lib/chronoscope/view_activator.ex similarity index 95% rename from lib/chronoscope/monitor.ex rename to lib/chronoscope/view_activator.ex index 9ed2392..54b7fb5 100644 --- a/lib/chronoscope/monitor.ex +++ b/lib/chronoscope/view_activator.ex @@ -1,4 +1,4 @@ -defmodule Chronoscope.Monitor do +defmodule Chronoscope.ViewActivator do use GenServer require Logger diff --git a/lib/chronoscope_web/live/index_live.ex b/lib/chronoscope_web/live/index_live.ex index b385b06..1b72ddb 100644 --- a/lib/chronoscope_web/live/index_live.ex +++ b/lib/chronoscope_web/live/index_live.ex @@ -8,15 +8,20 @@ defmodule ChronoscopeWeb.IndexLive do def mount(_params, _session, socket) do ChronoscopeWeb.Endpoint.subscribe(@topic) - {:ok, assign(socket, %{servers: server_list()})} + {:ok, assign(socket, %{clients: client_list()})} end - def handle_info(%{topic: @topic}, socket) do - {:noreply, assign(socket, %{servers: server_list()})} + def handle_info(%{topic: @topic, event: "key-exchange", payload: client}, socket) do + {:noreply, update(socket, :clients, &update_client(&1, client))} end - defp server_list() do - Chronoscope.Monitor + defp update_client(client_list, client) do + # todo - use a map instead of list for fast lookups? + Enum.map(client_list, &if(client.server == &1.server, do: client, else: &1)) + end + + defp client_list() do + Chronoscope.ViewActivator |> GenServer.call(:get_nts_servers) |> NTS.list_clients() end diff --git a/lib/chronoscope_web/live/index_live.html.heex b/lib/chronoscope_web/live/index_live.html.heex index 9ca85be..de4f785 100644 --- a/lib/chronoscope_web/live/index_live.html.heex +++ b/lib/chronoscope_web/live/index_live.html.heex @@ -32,12 +32,12 @@ - - <% {status, response} = server.key_establishment_response %> + + <% {status, response} = client.key_establishment_response %> <%= if (status == :ok) do %> - <%= server.server.host %>:<%= server.server.port %> + <%= client.server.host %>:<%= client.server.port %> <%= status %> @@ -68,12 +68,12 @@ <%= response.cert_expiration |> DateTime.from_iso8601 |> then(fn {:ok, dt, _} -> Calendar.strftime(dt, "%Y-%m-%d %H:%M:%SZ") end)%> - <%= server.last_key_establishment |> Calendar.strftime("%Y-%m-%d %H:%M:%SZ") %> + <%= client.last_key_establishment |> Calendar.strftime("%Y-%m-%d %H:%M:%SZ") %> <% else %> - <%= server.server.host %>:<%= server.server.port %> + <%= client.server.host %>:<%= client.server.port %> @@ -91,7 +91,7 @@ - <%= - server.last_key_establishment |> Calendar.strftime("%Y-%m-%d %H:%M:%SZ") + client.last_key_establishment |> Calendar.strftime("%Y-%m-%d %H:%M:%SZ") %> <% end %>