mirror of
https://github.com/correl/planning-poker.git
synced 2024-11-25 19:19:53 +00:00
26 lines
693 B
Elixir
26 lines
693 B
Elixir
defmodule PlanningpokerWeb.RoomChannel do
|
|
use Phoenix.Channel
|
|
alias PlanningpokerWeb.Presence
|
|
|
|
def join("room:" <> room_id, params, socket) do
|
|
send(self(), :after_join)
|
|
{: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
|
|
push(socket, "presence_state", Presence.list(socket))
|
|
{:noreply, socket}
|
|
end
|
|
def handle_in("new_profile", %{"name" => name}, socket) do
|
|
{:ok, _} = Presence.track(
|
|
socket,
|
|
"player:#{socket.assigns.player_id}",
|
|
%{
|
|
name: name
|
|
}
|
|
)
|
|
{:noreply, socket}
|
|
end
|
|
end
|