You all have known, used and loved our presence API. We understand that it's a very useful API, hence we added a bunch of new features to it.

The getAll() method

Many of you have played with the getAll() method to retrieve the usernames of all those users who are logged in to your application at a particular instance. But, what if you had a very interesting application with a large number of users and you are interested in knowing the online status of only a handful of them? Getting the status of all of them and then filtering out what interests us is such a pain and also a costly operation.

Hence, we have solved this issue by extending the getAll() method to do more than what it currently is capable of doing!

presence representation

As shown in the code snippet below, you can now use the getAll method to retrive both online and offline status of the users of your choice.

 client.presence.getAll(['Homer', 'Marge', 'Lisa'], (result) => {
         'Homer': true,
         'Marge': true,
         'Lisa': false

You would specify a list of usernames whose status you are interested to know and as a result of the above function, you would receive a boolean result for each of the users mentioned in the list, indicating whether they are currently online or offline in your application.

The subscribe() method

So, what's new with subscribe? Earlier, you could use subscribe to receive notifications about all the clients' login/logout activities. What if you were interested in only a particular client?

The subscribe() method now supports this as shown below:

client.presence.subscribe(username, presenceCallback)

As mentioned before, you can now provide a particular username in the subscribe method and the callback function is called only when this user logs in or logs out.

Have you always wanted this feature? Well, here you go!

Feel free to check out the complete guide if you wish to know more about presence in deepstream