Instantly share code, notes, and snippets.

Embed
What would you like to do?
Getting Started Tutorial for Using PubNub with JavaScript
<!-- Include the PubNub Library -->
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<!-- Instantiate PubNub -->
<script type="text/javascript">
var PUBNUB_demo = PUBNUB.init({
publish_key: 'Your Publish Key Here',
subscribe_key: 'Your Subscribe Key Here'
});
</script>
// Publish a simple message to the demo_tutorial channel
PUBNUB_demo.publish({
channel: 'demo_tutorial',
message: {"color":"blue"}
});
//Subscribe to the demo_tutorial channel
PUBNUB_demo.subscribe({
channel: 'demo_tutorial',
message: function(m){console.log(m)}
});
<html>
<head>
<title>Getting Started With PubNub</title>
</head>
<body>
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<script charset="utf-8">
(function(){
var PUBNUB_demo = PUBNUB.init({
publish_key: 'demo',
subscribe_key: 'demo'
});
PUBNUB_demo.subscribe({
channel: 'demo_tutorial',
message: function(m){console.log(m)},
connect : publish
});
function publish() {
PUBNUB_demo.publish({
channel: 'demo_tutorial',
message: {"text":"Hey!"}
});
}
})();
</script>
</body>
</html>
@moonsirenz

This comment has been minimized.

Show comment
Hide comment
@moonsirenz

moonsirenz Sep 12, 2014

<script charset="utf-8"> (function(){ var PUBNUB_demo = PUBNUB.init({ publish_key: 'demo', subscribe_key: 'demo' }); PUBNUB_demo.subscribe({ channel: 'demo_tutorial', message: function(m){console.log(m)}, connect : publish }); function publish() { PUBNUB_demo.publish({ channel: 'demo_tutorial', message: {"text":"Hey!"} }); } })(); </script>

moonsirenz commented Sep 12, 2014

<script charset="utf-8"> (function(){ var PUBNUB_demo = PUBNUB.init({ publish_key: 'demo', subscribe_key: 'demo' }); PUBNUB_demo.subscribe({ channel: 'demo_tutorial', message: function(m){console.log(m)}, connect : publish }); function publish() { PUBNUB_demo.publish({ channel: 'demo_tutorial', message: {"text":"Hey!"} }); } })(); </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment