Clear player data on socket closure

This commit is contained in:
Correl Roush 2020-05-24 00:06:47 -04:00
parent acf1f812c8
commit 2b804d30f7
2 changed files with 11 additions and 0 deletions

View file

@ -35,6 +35,11 @@ defmodule Planningpoker.Db do
:ets.select(:players, match) :ets.select(:players, match)
end end
def remove_player(player, room) do
:ets.delete(:players, {player, room})
:ets.delete(:votes, {player, room})
end
def clear_votes(room) do def clear_votes(room) do
:ets.match_delete(:votes, {{:_, room}, :_}) :ets.match_delete(:votes, {{:_, room}, :_})
votes = :ets.match(:votes, {{:_, room}, :"$1"}) votes = :ets.match(:votes, {{:_, room}, :"$1"})

View file

@ -49,4 +49,10 @@ defmodule PlanningpokerWeb.RoomChannel do
def handle_in(_event, _data, socket) do def handle_in(_event, _data, socket) do
{:noreply, socket} {:noreply, socket}
end end
def terminate(reason, socket) do
Db.remove_player(
socket.assigns.player_id,
socket.assigns.room_id
)
end
end end