Created
October 12, 2020 19:37
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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