diff --git a/lib/planningpoker/db.ex b/lib/planningpoker/db.ex index 0589b3c..1147a15 100644 --- a/lib/planningpoker/db.ex +++ b/lib/planningpoker/db.ex @@ -35,6 +35,11 @@ defmodule Planningpoker.Db do :ets.select(:players, match) end + def remove_player(player, room) do + :ets.delete(:players, {player, room}) + :ets.delete(:votes, {player, room}) + end + def clear_votes(room) do :ets.match_delete(:votes, {{:_, room}, :_}) votes = :ets.match(:votes, {{:_, room}, :"$1"}) diff --git a/lib/planningpoker_web/channels/room_channel.ex b/lib/planningpoker_web/channels/room_channel.ex index ff7904d..37400cf 100644 --- a/lib/planningpoker_web/channels/room_channel.ex +++ b/lib/planningpoker_web/channels/room_channel.ex @@ -49,4 +49,10 @@ defmodule PlanningpokerWeb.RoomChannel do def handle_in(_event, _data, socket) do {:noreply, socket} end + def terminate(reason, socket) do + Db.remove_player( + socket.assigns.player_id, + socket.assigns.room_id + ) + end end