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

* required
ParameterDescription
publish_key
Type: string
Default:
none
The PubNub publish key.
subscribe_key *
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.
uuid *
Type: string
Default:
n/a
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