Why is Phoenix.Presence.list return an empty map?

I followed this guide to create a presence list of users and a topic that maintains a list of current users. This all works fine.

Now I want to to get the list of current users from another process.

I figured the below would work


But it just returns an empty map and I don’t really understand why… the topic name is certainly correct and the websockets show that there are users in the “site:users” topic, but Presence.list never returns anything…

Looking at the documentation Presence.list/2 it seems to require 2 arguments and you are not specifying the module.

Presence.list/1 is a callback (to be called by the generic Presence behaviour) - i.e. it is a function that your module has to implement (not call); though there could be a default implementation.

So what might be happening is that you are not accessing the module that is actually managing the specified topic.

Skimming over the article I suspect you need:

TestAppWeb.Presence.list(RoomChannel, "site:users")

Actually epic facepalm… I was using the wrong topic name… but your post did point me to trace the list/2 method to see how it was being called which pointed me to my error!

list/1 also works fine I guess it does have a default implementation.

1 Like