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
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 """
TODO

View file

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

View file

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

View file

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