webpubsub-js
v1.0.10
Published
Publish & Subscribe Real-time Messaging with Webpubsub
Downloads
8
Maintainers
Readme
Webpubsub JavaScript SDK (V4)
This is the official Webpubsub JavaScript SDK repository.
Webpubsub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let Webpubsub 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 Webpubsub
Integrate the JavaScript SDK into your project:
- use
npm
:npm install webpubsub
- or download one of our builds from our CDN:
- https://cdn.webpubsub.com/sdk/javascript/webpubsub.7.0.1.js
- https://cdn.webpubsub.com/sdk/javascript/webpubsub.7.0.1.min.js
- use
Configure your keys:
webpubsub = new Webpubsub({
publishKey : "myPublishKey",
subscribeKey : "mySubscribeKey",
uuid: "myUniqueUUID"
})
Add event listeners
webpubsub.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!"
}
}
webpubsub.publish(publishPayload, function(status, response) {
console.log(status, response);
})
webpubsub.subscribe({
channels: ["hello_world"]
});
Documentation
- Build your first realtime JS app with Webpubsub
- API reference for JavaScript (web)
- API reference for JavaScript (Node.js)
Support
If you need help or have a general question, contact [email protected].