add presence client behaviour callbacks

This commit is contained in:
Berenice Medel Sánchez 2021-12-16 12:30:21 -06:00 committed by Chris McCord
parent b8bbba8ecb
commit a65c789748
4 changed files with 7 additions and 7 deletions

View file

@ -1,6 +1,10 @@
defmodule Phoenix.Presence.Client do defmodule Phoenix.Presence.Client do
use GenServer use GenServer
@callback init(state :: term) :: {:ok, new_state :: term}
@callback handle_join(topic :: String.t(), key :: String.t(), meta :: [map()], state :: term) :: {:ok, term}
@callback handle_leave(topic :: String.t(), key :: String.t(), meta :: [map()], state :: term) :: {:ok, term}
@doc """ @doc """
TODO TODO

View file

@ -4,19 +4,17 @@ defmodule LiveBeats.PresenceClient do
@presence LiveBeatsWeb.Presence @presence LiveBeatsWeb.Presence
@pubsub LiveBeats.PubSub @pubsub LiveBeats.PubSub
def start_link(opts) do
Phoenix.Presence.Client.start_link(presence: @presence, client: __MODULE__)
end
def list(topic) do def list(topic) do
@presence.list(topic) @presence.list(topic)
end end
@impl Phoenix.Presence.Client
def init(_opts) do def init(_opts) do
# user-land state # user-land state
{:ok, %{}} {:ok, %{}}
end end
@impl Phoenix.Presence.Client
def handle_join(topic, key, _meta, state) do def handle_join(topic, key, _meta, state) do
active_users_topic = active_users_topic =
topic topic
@ -28,6 +26,7 @@ defmodule LiveBeats.PresenceClient do
{:ok, state} {:ok, state}
end end
@impl Phoenix.Presence.Client
def handle_leave(topic, key, _meta, state) do def handle_leave(topic, key, _meta, state) do
active_users_topic = active_users_topic =
topic topic

View file

@ -5,12 +5,10 @@ defmodule Phoenix.Presence.Client.Mock do
end end
def handle_join(_topic, _key, _meta, state) do def handle_join(_topic, _key, _meta, state) do
IO.inspect(:handle_join)
{:ok, state} {:ok, state}
end end
def handle_leave(_topic, _key, _meta, state) do def handle_leave(_topic, _key, _meta, state) do
IO.inspect(:handle_leave)
{:ok, state} {:ok, state}
end end

View file

@ -18,7 +18,6 @@ defmodule Phoenix.Presence.Client.PresenceMock do
@impl true @impl true
def handle_info(:quit, state) do def handle_info(:quit, state) do
IO.inspect(:quit)
{:stop, :normal, state} {:stop, :normal, state}
end end