Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created April 3, 2019 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajb413/a641900abdb8d6b0bb1bc333ff29a858 to your computer and use it in GitHub Desktop.
Save ajb413/a641900abdb8d6b0bb1bc333ff29a858 to your computer and use it in GitHub Desktop.
helping dev
const pubnub = new PubNub({
publishKey : 'pub-c-0b42108c-8179-4742-9914-0ef70a1fded7',
subscribeKey : 'sub-c-0a75a202-345d-11e9-a629-42eced6f83cd'
});
pubnub.addListener({
status: function(statusEvent) {
if (statusEvent.category === "PNConnectedCategory") {
publishSampleMessage();
}
},
message: function(msg) {
console.log(msg.message.title);
console.log(msg.message.description);
},
presence: function(presenceEvent) {
// handle presence
}
});
console.log("Subscribing..");
pubnub.subscribe({
channels: ['iotchannel']
});
function publish(channel, message) {
let publishConfig = {
channel,
message
}
pubnub.publish(publishConfig, function(status, response) {
console.log(status, response);
});
}
function publishSampleMessage() {
let message = {
title: "greeting",
description: "Game is now running!"
}
let channel = "iotchannel";
publish(channel, message);
console.log("Game is now running.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment