elixirphoenix-frameworkphoenix-channels

How to handle clients status in Phoenix Channel


I've just followed Phoenix Channel and Presence Documentation from their official site. Things work fine as it's described.

As Channel documentation, it has join callback so I can handle something when client joins specific topic. But why there's no leave callback what I think it should be exist?

I've googled some and found I could use Presence to track client status. It worked either but I don't need inform it to clients actually. If I tried to catch presence_diff event in handle_out callback of Channel, it was called multiple times as number of clients.

As Presence documentation says...

In case you want to use only a subset of the functionality provided by Phoenix.Presence, such as tracking processes but without broadcasting updates, we recommend that you look at the Phoenix.Tracker functionality from the phoenix_pubsub project

But, Phoenix.Tracker requires :pubsub_server property initially.

Here're my questions again.

  1. Why Phoenix.Channel does not implement leave-like callback.
  2. How Can I handle client status(join/leave) for specific topic.

Thanks in advance.


Solution

  • You do get messages when client leaves the channel.

    From the documentation for https://hexdocs.pm/phoenix/Phoenix.Channel.html#module-terminate

    Is there any reason this is not enough?