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

require "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:

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

Configuration Parameters

PropertiesTypeRequiredDefaultDescription
publish_key
string
Optional (required only for publish)
none
The PubNub publish key.
subscribe_key
string
Yes
none
The PubNub subscribe key.
secret_key
string
Optional
none
The secret key.
auth_key
string
Optional
none
The auth key to access channels.
ssl
boolean
Optional
false
Whether to use SSL to connect to PubNub.
origin
string
Optional
ps.pndsn.com
The domain name to use to connect to PubNub.
uuid
string
Yes
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.

Basic Usage

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.

require "pubnub"

local pubnub_obj = pubnub.new({
publish_key = "demo",
subscribe_key = "demo",
secret_key = "demo",
ssl = false,
origin = "ps.pndsn.com"
})

Returns

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

Last updated on