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:
pubnub_obj:here_now(params)
Parameter | Description |
---|---|
params *Type: table | Table of here-now parameters. See Here Now Parameters for more details. |
Here now parameters
Parameter | Description |
---|---|
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
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.
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:
pubnub_obj:where_now(params)
Parameter | Description |
---|---|
params *Type: table | Table of where-now parameters. See Where Now Parameters for more details. |
Where now parameters
Parameter | Description |
---|---|
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
pubnub_obj:where_now({
callback = function(response)
textout(response)
end,
error = function (response)
textout(response)
end
})