Presence API for PubNub Lua SDK

Presence enables you to track the online and offline status of users and devices in real time, and store custom state information. Presence provides authoritative information on:

  • When a user has joined or left a channel
  • Who, and how many, users are subscribed to a particular channel
  • Which channel(s) an individual user is subscribed to
  • Associated state information for these users

Here Now

Requires Presence add-on

This method requires that the Presence add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

You can obtain information about the current state of a channel including a list of unique user-ids currently subscribed to the channel and the total occupancy count of the channel by calling the here_now() function in your application.

Cache

This method has a 3 second response cache time.

Method(s)

To call Here Now you can use the following method(s) in the Lua SDK:

pubnub_obj:here_now(params)
ParameterTypeRequiredDescription
paramstableYesTable of here-now parameters. See Here Now Parameters for more details.

Here Now Parameters

PropertiesTypeRequiredDefaultDescription
channelstringOptionalnoneThe channel to get presence for - if not provided, get global presence.
callbackfunction(r)YesnoneThe function to call on success with result.
errorfunction(r)Optionalfunction(r) endThe function to call on failure, with result.

Basic Usage

Get a list of uuids subscribed to channel

pubnub_obj:here_now({
channel = "demo",
callback = function(response)
textout(response)
end,
error = function (response)
textout(response)
end
})

Where Now

Requires Presence add-on

This method requires that the Presence add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

You can obtain information about the current list of channels to which a UUID is subscribed to by calling the where_now() function in your application.

Timeout events

If the app is killed/crashes and restarted (or the page containing the PubNub instance is refreshed on the browser) within the heartbeat window no timeout event is generated.

Method(s)

To call where_now() you can use the following method(s) in the Lua SDK:

pubnub_obj:where_now(params)
ParameterTypeRequiredDescription
paramstableYesTable of where-now parameters. See Where Now Parameters for more details.

Where Now Parameters

PropertiesTypeRequiredDefaultDescription
UUIDstringOptionalUUID of the objectThe UUID to get presence for.
callbackfunction(r)YesnoneThe function to call on success with result.
errorfunction(r)Optionalfunction(r) endThe function to call on failure, with result.

Basic Usage

You simply need to define the uuid and the callback function to be used to send the data to as in the example below.

Get a list of channels a UUID is subscribed to

pubnub_obj:where_now({
callback = function(response)
textout(response)
end,
error = function (response)
textout(response)
end
})
Last updated on