Skip to content

Instantly share code, notes, and snippets.

@digitallysavvy
Created October 12, 2020 19:37
Show Gist options
  • Save digitallysavvy/fb536abf0058db1a187a1b6e4d221601 to your computer and use it in GitHub Desktop.
Save digitallysavvy/fb536abf0058db1a187a1b6e4d221601 to your computer and use it in GitHub Desktop.
a function that initializes a new PubNub client with a give Pub and Sub keys.
function initPubNub(pubKey, subKey, uid, channel) {
console.log(pubKey, subKey)
pubNub = new PubNub({
publishKey : pubKey,
subscribeKey : subKey,
uuid: uid,
logVerbosity: true,
ssl: true
});
pubNub.addListener({
status: function(statusEvent) {
if (statusEvent.category === "PNConnectedCategory") {
console.log('join success with UID: ' + UID);
}
},
message: function(msg) {
console.log(msg);
if (msg.message.uuid != UID) {
addRemoteMsg(msg.message.uuid, msg.message.description)
} else {
console.log('message sent successfully to channel');
}
},
presence: function(presenceEvent) {
// handle presence events
console.log('presence event: ' + JSON.stringify(presenceEvent));
}
})
console.log("Subscribing..");
// subscribe a pubNub Channel using the same name as our video chat
pubNub.subscribe({
channels: [channel]
});
channelName = channel;
UID = uid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment