Created
April 3, 2013 15:23
-
-
Save theterg/5302182 to your computer and use it in GitHub Desktop.
bugswarm helloworld example, cleaned up and demonstrating arbitrary key value
This file contains 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
<html> | |
<head> | |
<script type="text/javascript" src="http://cdn.buglabs.net/swarm/swarm-v0.4.0.js"></script> | |
</head> | |
<body> | |
<script> | |
/* Open this file twice or more and you should be able | |
to see presence in the developer console of your browser. */ | |
function onPresence(presence) { | |
console.log('presence -> ' + Date.now() + ':' + JSON.stringify(presence)); | |
} | |
function onMessage(message) { | |
console.log('message -> ' + Date.now() + ': ' + JSON.stringify(message)); | |
} | |
function onError(error) { | |
console.log('error! -> ' + JSON.stringify(error)); | |
} | |
SWARM.debug = true; | |
var timer; | |
SWARM.connect({ apikey: '63a0e565521670b1cf32040bf179e2f904146e81', | |
resource: '3602159efda226c136854b0e381b00fd49533fe8', | |
swarms: ['6c67d6493656d32698ec9f820feca33c38d9abf6'], | |
onmessage: onMessage, | |
onpresence: onPresence, | |
onerror: onError, | |
onconnect: | |
function onConnect() { | |
console.log('connected!'); | |
if(timer) { //Clears interval upon re-connection | |
clearInterval(timer); | |
} | |
timer = setInterval(function() { | |
var message = {}; | |
var myKey = 'gaylordfocker'; | |
message[myKey] = 'foo'; | |
SWARM.send(message); | |
}, 1000); | |
}}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment