why deepstreamHub? compare us getting started faq
use cases
products
developers
company
blog contact

Methods

client.presence.subscribe(username, callback)

argument type optional description
username String true The name of the user that you want to subscribe to the online status of
callback Function false A function that will be called whenever an authenticated client logs in or out. Will be called with the users name and a boolean indicating whether they logged in or out

Subscribes to presence events of the user provided. If no username is provided, presence events of all clients are subscribed to.

client.presence.subscribe('Homer', (username, login) => {
  if (login === true) {
    // handle login
  } else {
    // handle logout
  }
})

client.presence.unsubscribe(username, callback)

argument type optional description
username String true The username of the client you wish to unsubscribe to presence events from
callback Function true The callback that was previously registered with subscribe. If the callback is omitted, all listeners for the event will be removed

Unsubscribes from presence and the client is no longer notified when other authenticated clients' login status changes.

client.presence.getAll(users, callback)

argument type optional description
users Array true An array of client usernames that you want the online status of
callback Function false A function that will be called with either an array of all connected clients' usernames, or a map of usernames and their login status

Queries for all connected clients.

client.presence.getAll((usernames) => {
  // ['Homer', 'Marge', 'Bart']
})

client.presence.getAll(['Homer', 'Marge', 'Lisa'], (users) => {
  // {
  //  "Homer": true,
  //  "Marge": true,
  //  "Lisa": false
  // }
})