Skip to content

pubnub/javascript

Folders and files

NameName
Last commit message
Last commit date
Feb 21, 2024
Feb 21, 2024
Aug 31, 2023
Feb 21, 2024
Feb 21, 2024
Feb 21, 2024
Aug 7, 2019
Jan 16, 2024
Jan 16, 2024
Apr 15, 2022
Nov 22, 2021
Apr 14, 2022
Feb 21, 2024
Feb 21, 2024
Oct 16, 2023
Feb 21, 2024
Jan 16, 2024
Jan 16, 2024
Feb 21, 2024
Apr 21, 2022
Oct 16, 2023
Apr 14, 2022
May 24, 2022

Repository files navigation

PubNub JavaScript SDK (V4)

Build Status Codacy Badge npm Bower Known Vulnerabilities

This is the official PubNub JavaScript SDK repository.

PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.

Get keys

You will need the publish and subscribe keys to authenticate your app. Get your keys from the Admin Portal.

Tutorial Video

Getting Started with PubNub JS SDK

Watch Getting Started with PubNub JS SDK on Dashcam

Configure PubNub

  1. Integrate the JavaScript SDK into your project:

  2. Configure your keys:

pubnub = new PubNub({
  publishKey : "myPublishKey",
  subscribeKey : "mySubscribeKey",
  uuid: "myUniqueUUID"
})

Add event listeners

pubnub.addListener({
  message: function (m) {
    // handle messages
  },
  presence: function (p) {
    // handle presence  
  },
  signal: function (s) {
    // handle signals
  },
  objects: (objectEvent) => {
    // handle objects
  },
  messageAction: function (ma) {
    // handle message actions
  },
  file: function (event) {
    // handle files  
  },
  status: function (s) {
  // handle status  
  },
});

Publish/subscribe

var publishPayload = {
    channel : "hello_world",
    message: {
        title: "greeting",
        description: "This is my first message!"
    }
}

pubnub.publish(publishPayload, function(status, response) {
    console.log(status, response);
})

pubnub.subscribe({
    channels: ["hello_world"]
});

Documentation

Support

If you need help or have a general question, contact support@pubnub.com.