-
-
Save pblca/23d63b0339e03acbd151 to your computer and use it in GitHub Desktop.
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
<!-- 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> |
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
//Subscribe to the demo_tutorial channel with presence and state | |
PUBNUB_demo.subscribe({ | |
channel: 'demo_tutorial', | |
noheresync: true, | |
message: function(m){ | |
console.log(m); | |
}, | |
presence: function(m) { | |
console.log(m); | |
}, | |
state: { | |
name: 'presence-tutorial-user', | |
timestamp: new Date() | |
} | |
}); |
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
//Unsubcribe to the channel, also unsubscribes to presence event channel | |
PUBNUB_demo.unsubscribe({ | |
channel: 'demo_tutorial' | |
}); |
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
//See who the uuid's & state objects of those currently subscribed | |
PUBNUB_demo.here_now({ | |
channel: 'demo_tutorial', | |
state: true, | |
callback: function(msg) { | |
console.log(msg); | |
} | |
}); |
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
<html> | |
<head> | |
<title>Getting Started with PubNub Presence</title> | |
</head> | |
<body> | |
<script src="https://cdn.pubnub.com/pubnub.min.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
var PUBNUB_demo = PUBNUB.init({ | |
publish_key: 'demo', | |
subscribe_key: 'demo' | |
}); | |
PUBNUB_demo.subscribe({ | |
channel: 'demo_tutorial', | |
message: function(msg){ | |
console.log("message: ", msg); | |
}, | |
presence: function(msg) { | |
console.log("presence: ", msg); | |
}, | |
noheresync: true, | |
state: { | |
name: "User Name", | |
email: "[email protected]", | |
timestamp: new Date() | |
}, | |
connect: function() { | |
PUBNUB.here_now({ | |
channel: 'demo_tutorial', | |
state: true, | |
callback: function(msg) { | |
console.log("here_now(): ", msg); | |
} | |
}); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment