Search code examples
pusher

how to get global presence for pusher


I'm building a chat application and I'd like to get a list of which of the people I'm following are online and what chat rooms they are in.

According to the pusher docs, the presence channels are per channel and

This is not the same as jabber style “which of my friends are online” presence. Pusher doesn’t offer anything out of the box for that use case right now.

https://pusher.com/docs/client_api_guide/client_presence_channels

So if I were to create this feature on pusher, should I just create a global channel and have everyone connect to that silently in the background to get a global presence - if so there is a 100 person limit to that so it wouldn't be feasible. Or should I just create a single channel per user and then let users subscribe to a channel per each person they are friends with (though that seems a bit inefficient)? Note that this is a one way people I am following relationship and not a 2-way friend relationship.


Solution

  • As you pointed out Presence channels are more for rooms of up to 100 users.

    Note: The thinking behind that is that a room with more than that isn't really a chat session. Hopefully this restriction will change in the future and it will increase the use case for presence channels.

    To get a count of the number of the users you follow who are online you'll need to ensure each user is subscribed to a user-specific channel (e.g. myUserId-channel or private-myUserId-channel if auth is required) and then query the Pusher HTTP API and check to see if a user-specific channel is occupied. If it is then that user is subscribed to the channel and thus online. See Querying Application Channels.

    For a more detailed description see Using presence for large groups of users.