Presence Events in Beebotte

Presence detection in Beebotte provides an insight on resources subscriptions. It provides a real time stream of events to notify when:

  • A user subscribes to a resource (join event)
  • A user unsubscribes from a resource (leave event)
  • A user notifies about its presence (connected event)

Beebotte client side API makes it easy for a web page to listen to presence events of a resource by subscribing to that resource with the 'presence-' prefix.

You can subscribe to presence events of a resource as follows:

var bbt = new BBT('API_KEY', {auth_endpoint: 'authentication_URL'});
/* Subscribing to presence resource will automatically request read access permission */
bbt.subscribe({
  channel: 'presence-dev', //Note the 'presence-' prefix
  resource: 'res'
}, function(err, evt){
    /* Do something here */
});

The callback function has two parameters, the first indicates an error if it's not null, while the second is a JSON object with the following format:

  • channel: string
  • resource: string
  • data: object
    • event: one of ['join', 'leave', 'connected']

Beebotte considers presence events as private resources that require explicit authentication to get subscribed to. You must always provide an authentication end-point when initializing the BBT object if you consider subscribing to presence events.

You can unsubscribe from presence events of a resource as follows:

var bbt = new BBT('API_KEY', {auth_endpoint: 'authentication_URL'});
bbt.unsubscribe({channel: 'presence-dev', resource: 'res'});