Package Exports
- pubnub
- pubnub/dist/web/pubnub
- pubnub/dist/web/pubnub.js
- pubnub/dist/web/pubnub.min.js
- pubnub/lib/nativescript
- pubnub/lib/nativescript/index.js
- pubnub/lib/node/index.js
- pubnub/lib/react_native/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pubnub) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
PubNub JavaScript SDK (V4)
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.
Configure PubNub
Integrate the JavaScript SDK into your project:
- use
npm:npm install pubnub - or download one of our builds from our CDN:
- use
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
- Build your first realtime JS app with PubNub
- API reference for JavaScript (web)
- API reference for JavaScript (Node.js)
Support
If you need help or have a general question, contact support@pubnub.com.