Example usage of `Phoenix.Presence.list/2`?

I’m trying to understand how to use Phoenix.Presence.list/2. It shows the arguments as module, topic.

My guess was that module should be the channel module, but when I call Phoenix.Presence.list(MyApp.MyChannel, "my_topic"), I get an ** (EXIT) no process error from GenServer.call.

I’m using Presence in the channel module the way the docs show, and I’m successfully getting presence_state and presence_diff messages in the browser.

My goal is to get a list of connected users for that topic so that I can send each one of them some data customized for their user id.

Am I using Phoenix.Presence.list/2 wrong?

1 Like

It’s referring to your app’s presence module. Phoenix.Presence.list(MyApp.Presence, "my_topic") should do the trick. But you can also just call MyApp.Presence.list("my_topic"), that function is inserted into your presence module in this macro.

2 Likes

Oh! Yes, that works. Thanks! :grinning:

I guess that implies that each topic needs a globally unique name, even though they’re handled by different channels. :thinking:

1 Like

Or you can use multiple presence modules too (don’t forget to register each) as I do. :slight_smile:

1 Like