Presence API for Lua SDK

Presence lets you track who is online or offline and store custom state information. Presence shows:

  • When a user has joined or left a channel
  • How many users are subscribed to a particular channel (occupancy)
  • Which channels a user or device is subscribed to
  • Presence state associated with these users

Here now​

Requires Presence

This method requires that the Presence add-on is enabled for your key in the Admin Portal.

This method returns information about the current state of a channel, including a list of unique user IDs (universally unique identifiers, UUIDs) currently subscribed to the channel and the total occupancy count of the channel.

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:

1pubnub_obj:here_now(params)
* required
ParameterDescription
params *
Type: table
Table of here-now parameters. See Here Now Parameters for more details.

Here now parameters​

* required
ParameterDescription
channel
Type: string
Default:
none
The channel to get presence for - if not provided, get global presence.
callback *
Type: function(r)
Default:
none
The function to call on success with result.
error
Type: function(r)
Default:
function(r) end
The function to call on failure, with result.

Sample code​

Get a list of uuids subscribed to channel​

1pubnub_obj:here_now({
2 channel = "demo",
3 callback = function(response)
4 textout(response)
5 end,
6 error = function (response)
7 textout(response)
8 end
9})

Where now​

Requires Presence

This method requires that the Presence add-on is enabled for your key in the Admin Portal.

This method returns the list of channels a UUID is subscribed to.

Timeout events

If the app restarts (or the page refreshes) 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:

1pubnub_obj:where_now(params)
* required
ParameterDescription
params *
Type: table
Table of where-now parameters. See Where Now Parameters for more details.

Where now parameters​

* required
ParameterDescription
UUID
Type: string
Default:
UUID of the object
The UUID to get presence for.
callback *
Type: function(r)
Default:
none
The function to call on success with result.
error
Type: function(r)
Default:
function(r) end
The function to call on failure, with result.

Sample code​

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​

1pubnub_obj:where_now({
2 callback = function(response)
3 textout(response)
4 end,
5 error = function (response)
6 textout(response)
7 end
8})

Was this page useful?

Last updated on