diff --git a/ui/lib/ui_web/controllers/page_controller.ex b/ui/lib/ui_web/controllers/page_controller.ex index 359098b..7bb9da1 100644 --- a/ui/lib/ui_web/controllers/page_controller.ex +++ b/ui/lib/ui_web/controllers/page_controller.ex @@ -10,8 +10,8 @@ defmodule UiWeb.PageController do render(conn, :instructions) end - def morse(%{remote_ip: ip} = conn, _params) do - ip = ip |> Tuple.to_list |> Enum.join(".") + def morse(conn, _params) do + ip = conn |> Plug.Conn.get_req_header("x-real-ip") |> hd() LiveView.Controller.live_render(conn, UiWeb.MorseLive, session: %{ip: ip}) end end diff --git a/ui/lib/ui_web/live/morse_live.ex b/ui/lib/ui_web/live/morse_live.ex index 20ba153..5831da5 100644 --- a/ui/lib/ui_web/live/morse_live.ex +++ b/ui/lib/ui_web/live/morse_live.ex @@ -13,9 +13,10 @@ defmodule UiWeb.MorseLive do end def handle_event("toggle_morse", _value, %{assigns: %{ip: ip}} = socket) do - if Morse.Server.in_progress?() and ip != "127.0.0.1" do + if not Morse.Server.in_progress?() and ip != "127.0.0.1" do spawn fn -> Ui.TelegramBot.message("#{ip} pressed the button!") end end + Morse.Server.toggle_morse() {:noreply, socket}