2020-05-06 05:30:43 +00:00
|
|
|
defmodule PlanningpokerWeb.RoomChannel do
|
2020-05-08 03:43:02 +00:00
|
|
|
require Logger
|
2020-05-06 05:30:43 +00:00
|
|
|
use Phoenix.Channel
|
|
|
|
alias PlanningpokerWeb.Presence
|
2020-05-08 03:43:02 +00:00
|
|
|
alias Planningpoker.Db
|
2020-05-06 05:30:43 +00:00
|
|
|
|
|
|
|
def join("room:" <> room_id, params, socket) do
|
|
|
|
send(self(), :after_join)
|
2020-05-08 03:43:02 +00:00
|
|
|
Logger.debug "Proc: #{inspect self()}, Socket: #{inspect socket}"
|
2020-05-06 05:30:43 +00:00
|
|
|
{:ok, %{channel: room_id, topic: "Planning Poker"},
|
|
|
|
socket
|
|
|
|
|> assign(:room_id, room_id)
|
|
|
|
|> assign(:player_name, params["playerName"])}
|
|
|
|
end
|
|
|
|
def handle_info(:after_join, socket) do
|
2020-05-07 00:03:31 +00:00
|
|
|
push(socket, "presence_state", Presence.list(socket))
|
|
|
|
{:noreply, socket}
|
|
|
|
end
|
|
|
|
def handle_in("new_profile", %{"name" => name}, socket) do
|
2020-05-08 03:43:02 +00:00
|
|
|
Db.save_name(socket.assigns.player_id, name)
|
2020-05-06 05:30:43 +00:00
|
|
|
{:ok, _} = Presence.track(
|
|
|
|
socket,
|
2020-05-08 03:43:02 +00:00
|
|
|
socket.assigns.player_id,
|
|
|
|
%{}
|
2020-05-07 00:03:31 +00:00
|
|
|
)
|
2020-05-06 05:30:43 +00:00
|
|
|
{:noreply, socket}
|
|
|
|
end
|
|
|
|
end
|