LuaLua Presence API Reference for Realtime Apps

Go to Publish & Subscribe


Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-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.
To call Here Now you can use the following method(s) in the Lua SDK:
  1. ParameterTypeRequiredDescription
    paramstableYesTable of here-now parameters. See Here Now Parameters for more details.
    PropertiesTypeRequiredDefaultsDescription
    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.
pubnub_obj:here_now({
	channel = "demo",
	callback = function(response)
		textout(response)
	end,
	error = function (response)
		textout(response)
	end
})
Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-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.
 
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.
To call where_now() you can use the following method(s) in the Lua SDK:
  1. ParameterTypeRequiredDescription
    paramstableYesTable of where-now parameters. See Where Now Parameters for more details.
    PropertiesTypeRequiredDefaultsDescription
    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.
You simply need to define the uuid and the callback function to be used to send the data to as in the example below.
pubnub_obj:where_now({
    callback = function(response)
        textout(response)
    end,
    error = function (response)
        textout(response)
    end
})

Go to Storage and Playback