Fix UiWeb.Endpoint module not found in morse.

This commit is contained in:
Pim Kunis 2019-08-01 12:54:16 +02:00
parent 3432ef75b2
commit a2b21e300a
3 changed files with 21 additions and 2 deletions

View file

@ -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

View file

@ -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},
]

18
ui/lib/ui/socket_api.ex Normal file
View file

@ -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