Call broadcast function from app configured module.

This commit is contained in:
Pim Kunis 2019-08-24 16:01:49 +02:00
parent d6e877137f
commit fc54fa1761
7 changed files with 15 additions and 22 deletions

View file

@ -9,8 +9,7 @@ defmodule Ui.Application do
# List all child processes to be supervised
children = [
# Start the endpoint when the application starts
UiWeb.Endpoint,
Ui.SocketAPI
UiWeb.Endpoint
# Starts a worker by calling: Ui.Worker.start_link(arg)
# {Ui.Worker, arg},
]

View file

@ -1,18 +0,0 @@
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

View file

@ -30,4 +30,9 @@ defmodule UiWeb.UserSocket do
#
# Returning `nil` makes this socket anonymous.
def id(_socket), do: nil
def broadcast_progress(progress) do
IO.puts("in user socket!")
UiWeb.Endpoint.broadcast("morse:progress", "update", %{value: progress})
end
end

View file

@ -17,6 +17,7 @@ defmodule UiWeb.Endpoint do
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
IO.inspect code_reloading?
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader