Configuration API for Lua SDK

Complete Lua API reference for building real-time applications on PubNub, including basic usage and sample code.

Initialization​

Including the code​

1require "pubnub"

Description​

This function is used for initializing the PubNub Client API context. This function must be called before attempting to utilize any API functionality in order to establish account level credentials such as publish_key and subscribe_key.

Method(s)​

To Initialize PubNub you can use the following method(s) in the Lua SDK:

1pubnub_obj = pubnub.new(configuration)
required
configuration required#
Type: table
Table of initialization parameters (a kind of prototype to construct the PubNub object from). See Configuration Parameters for more details.

Configuration parameters​

required
publish_key#
Type: string
Default: none
The PubNub publish key.
subscribe_key required#
Type: string
Default: none
The PubNub subscribe key.
secret_key#
Type: string
Default: none
The secret key.
auth_key#
Type: string
Default: none
The auth key to access channels.
ssl#
Type: boolean
Default: false
Whether to use SSL to connect to PubNub.
origin#
Type: string
Default: ps.pndsn.com
The domain name to use to connect to PubNub.
To request a custom domain, contact support and follow the request process.
uuid required#
Type: string
Default: no default
UUID to use. You should set a unique UUID to identify the user or the device that connects to PubNub.

It's a UTF-8 encoded string of up to 92 alphanumeric characters.

If you don't set the UUID, you won't be able to connect to PubNub.

Sample code​

Initialize the PubNub client API​

Required UUID

Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the UUID, you won't be able to connect to PubNub.

1require "pubnub"
2
3local pubnub_obj = pubnub.new({
4 publish_key = "demo",
5 subscribe_key = "demo",
6 secret_key = "demo",
7 ssl = false,
8 origin = "ps.pndsn.com"
9})

Returns​

It returns the PubNub instance for invoking PubNub APIs like publish(), subscribe(), history(), here_now(), etc.

Was this page useful?

Last updated on