Created
October 9, 2014 20:59
-
-
Save fernandozamoraj/596b9cd61645be57e6dc to your computer and use it in GitHub Desktop.
Simple Example for Pubnub messagin
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
<!DOCTYPE html> | |
<!-- open up this same page in two instances of the brower that way you can see the message pop up in the other instances of the browser--> | |
<!-- make sure to add the jquery.js file to the same location as this file --> | |
<!-- Author: Fernando Zamora 9 October 2014 --> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Home</title> | |
<script src="jquery.js" type="text/javascript"></script> | |
<!-- Include the PubNub Library --> | |
<script src="https://cdn.pubnub.com/pubnub.min.js" type="text/javascript"></script> | |
<!-- Instantiate PubNub --> | |
<script type="text/javascript"> | |
var user = "larry"; | |
var PUBNUB_demo = PUBNUB.init({ | |
publish_key: 'demo', | |
subscribe_key: 'demo' | |
}); | |
</script> | |
<script type="text/javascript"> | |
PUBNUB_demo.subscribe({ | |
channel: 'demo_tutorial', | |
message: function(m){alert(m.name + " says: " + m.text)} | |
}); | |
</script> | |
</head> | |
<body> | |
<a class="confirmLink" href="#">Click here</a> | |
<!--this script place below the confirmLink so that binding will work --> | |
<script type="text/javascript"> | |
$(".confirmLink").click(function(e) { | |
e.preventDefault(); | |
confirmClick(); | |
}); | |
function confirmClick(){ | |
// Publish a simple message to the demo_tutorial channel | |
PUBNUB_demo.publish({ | |
channel: 'demo_tutorial', | |
message: {"text":"Hi!", "name":user} | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment