PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›API Reference

lUA

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Message Persistence
    • Miscellaneous
  • Change Log
  • Feature Support
  • Platform Support

Presence API for PubNub Lua SDK

Presence enables you to track the online and offline status of users and devices in real time, as well as store custom state information. Presence provides authoritative information on:

  • When a user has joined or left a channel
  • Who, and how many, users are subscribed to a particular channel
  • Which channel(s) an individual user is subscribed to
  • Associated state information for these users

Here Now

Requires Presence add-on Requires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

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.

Method(s)

To call Here Now you can use the following method(s) in the Lua SDK:

  1. pubnub_obj:here_now(params)
    
    ParameterTypeRequiredDescription
    paramstableYesTable of here-now parameters. See Here Now Parameters for more details.

    Here Now Parameters:

    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.

Basic Usage

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 add-on Requires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

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.

Note

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.

Method(s)

To call where_now() you can use the following method(s) in the Lua SDK:

  1. pubnub_obj:where_now(params)
    
    ParameterTypeRequiredDescription
    paramstableYesTable of where-now parameters. See Where Now Parameters for more details.

    Where Now Parameters:

    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.

Basic Usage

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
})
← Publish & SubscribeMessage Persistence →
  • Here Now
    • Description
    • Method(s)
    • Basic Usage
  • Where Now
    • Description
    • Method(s)
    • Basic Usage
© PubNub Inc. - Privacy Policy