mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-25 01:10:59 +00:00
add presence client behaviour callbacks
This commit is contained in:
parent
b8bbba8ecb
commit
a65c789748
4 changed files with 7 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue