Presence API for PubNub Lua SDK
Presence enables you to track the online and offline status of users and devices in real time, as well as 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 Requires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
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.
Method(s)
To call Here Now
you can use the following method(s) in the Lua SDK:
pubnub_obj:here_now(params)
Parameter Type Required Description params
table Yes Table of here-now
parameters. See Here Now Parameters for more details.Properties Type Required Defaults Description 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 add-on Requires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
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.
Note
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)
Parameter Type Required Description params
table Yes Table of where-now parameters. See Where Now Parameters for more details. Properties Type Required Defaults Description 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
})