use genserver pid or name in client API

This commit is contained in:
Berenice Medel Sánchez 2021-12-14 12:32:51 -06:00 committed by Chris McCord
parent 0bde8f40d6
commit 84d4eead7a

View file

@ -11,15 +11,20 @@ defmodule Phoenix.Presence.Client do
* `:client` - The required callback module * `:client` - The required callback module
""" """
def start_link(opts) do def start_link(opts) do
GenServer.start_link(__MODULE__, opts, name: PresenceClient) case Keyword.fetch(opts, :name) do
{:ok, name} ->
GenServer.start_link(__MODULE__, opts, name: name)
:error -> GenServer.start_link(__MODULE__, opts)
end
end end
def track(topic, key, meta) do def track(pid \\ PresenceClient, topic, key, meta) do
GenServer.call(PresenceClient, {:track, self(), topic, to_string(key), meta}) GenServer.call(pid, {:track, self(), topic, to_string(key), meta})
end end
def untrack(topic, key) do def untrack(pid \\ PresenceClient, topic, key) do
GenServer.call(PresenceClient, {:untrack, self(), topic, to_string(key)}) GenServer.call(pid, {:untrack, self(), topic, to_string(key)})
end end
def init(opts) do def init(opts) do