PubNub

Topics related to PubNub:

Getting started with PubNub

Hello World

<init> (i.e. require ("pubnub"))

Initialize an instance of PubNub to invoke operations.

ParameterDetails
publish_keyString - your publish key from your PubNub Admin Dashboard account
subscribe_keyString - your publish key from your PubNub Admin Dashboard account

subscribe

Subscribe to a channel(s) and provide a means to receive messages published to the channel(s).

ParameterDetails
channelString - channel name or comma-delimited list of channel names
messagefunction - the callback function that will receive messages published on the subscribe channels
connectfunction - the callback function that will be called when the subscription to the channels is successful

publish

Publish a message to a channel which will be received by subscribers on that channel.

ParameterDetails
channelString - channel name on which to send the message
messageString - The message to publish on the channel. JSON format is recommended (do not stringify; use the JSON object)

Access Manager

Presence

UUIDs

Stream Controller: Channel Groups

When using Channel Groups, you should not add or remove channels in your client side applications. This example shows adding channels to a channel group and subscribing to that channel group for simplicity sake. But in a real world scenario, you should have your server do all the add/remove of channels to/from channel groups. When you enable Access Manager, you will need the manage permission to add/remove channels to/from channel groups and you should never grant the manage permission to clients for security reasons. Only your server should be granted the manage permission.

Message Filtering

Stream Filter provides the ability to filter messages on the server before they are sent to a subscriber is a popular request. With the introduction of our v4.x SDKs, you now have the ability to do so using message meta data.

Storage & Playback

Simply enabling Storage & Playback add-on for your keys in the PubNub Admin Dashboard will result in all published messages on all channels to be stored. You can prevent a message from being stored by passing the storeInHistory parameter as false when the message is published, like this:

pubnub.publish(
    {
        message: { 
            'price': 8.07
        },
        channel: 'channel1',
        storeInHistory: false // override default storage options
    },
    function (status, response) {
        // log status & response to browser console
        console.log("STATUS  : " + console.log(JSON.stringify(status));
        console.log("RESPONSE: " + console.log(JSON.stringify(response));
    }
);

Otherwise, just omit the storeInHistory or set to true to store the message when it is published.

webhook

Channel Specific Callbacks for v4 SDKs