From a2b21e300a9068100489cbf68b040159b945d483 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Thu, 1 Aug 2019 12:54:16 +0200 Subject: [PATCH] Fix UiWeb.Endpoint module not found in morse. --- morse/lib/morse/server.ex | 2 +- ui/lib/ui/application.ex | 3 ++- ui/lib/ui/socket_api.ex | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 ui/lib/ui/socket_api.ex diff --git a/morse/lib/morse/server.ex b/morse/lib/morse/server.ex index 10b768e..a76dae0 100644 --- a/morse/lib/morse/server.ex +++ b/morse/lib/morse/server.ex @@ -37,6 +37,6 @@ defmodule Morse.Server do end defp broadcast_progress(progress) do - UiWeb.Endpoint.broadcast("morse:progress", "update", %{value: progress}) + GenServer.cast(Ui.SocketAPI, {:broadcast_progress, progress}) end end diff --git a/ui/lib/ui/application.ex b/ui/lib/ui/application.ex index 2d39b6c..7bdd4f4 100644 --- a/ui/lib/ui/application.ex +++ b/ui/lib/ui/application.ex @@ -9,7 +9,8 @@ defmodule Ui.Application do # List all child processes to be supervised children = [ # Start the endpoint when the application starts - UiWeb.Endpoint + UiWeb.Endpoint, + Ui.SocketAPI # Starts a worker by calling: Ui.Worker.start_link(arg) # {Ui.Worker, arg}, ] diff --git a/ui/lib/ui/socket_api.ex b/ui/lib/ui/socket_api.ex new file mode 100644 index 0000000..20775e0 --- /dev/null +++ b/ui/lib/ui/socket_api.ex @@ -0,0 +1,18 @@ +defmodule Ui.SocketAPI do + use GenServer + + def start_link(_) do + GenServer.start_link(__MODULE__, nil, name: __MODULE__) + end + + @impl true + def init(state) do + {:ok, state} + end + + @impl true + def handle_cast({:broadcast_progress, progress}, state) do + UiWeb.Endpoint.broadcast("morse:progress", "update", %{value: progress}) + {:noreply, state} + end +end