Presence API for 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

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

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)
* required
ParameterDescription
params *
Type: table
Table of here-now parameters. See Here Now Parameters for more details.

Here Now Parameters

PropertiesTypeRequiredDefaultDescription
channel
string
Optional
none
The channel to get presence for - if not provided, get global presence.
callback
function(r)
Yes
none
The function to call on success with result.
error
function(r)
Optional
function(r) end
The 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

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

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)
* required
ParameterDescription
params *
Type: table
Table of where-now parameters. See Where Now Parameters for more details.

Where Now Parameters

PropertiesTypeRequiredDefaultDescription
UUID
string
Optional
UUID of the object
The UUID to get presence for.
callback
function(r)
Yes
none
The function to call on success with result.
error
function(r)
Optional
function(r) end
The 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