Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>PubNub Tester</title>
- <script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.15.1.js"></script>
- </head>
- <body>
- <script type="text/javascript">
- // Initialize for Read Only Client
- console.log('init PubNub.');
- pubnub = new PubNub({
- publishKey: 'demo',
- subscribeKey: 'demo',
- uuid: 'myDemo'
- })
- console.log("addListener..");
- pubnub.addListener({
- status: function(statusEvent) {
- if (statusEvent.category === "PNConnectedCategory") {
- console.log("PNConnectedCategory..");
- publishSampleMessage();
- }
- },
- message: function(message) {
- console.log("New Message!!", message.message);
- },
- presence: function(presenceEvent) {
- // handle presence
- }
- })
- console.log("Subscribing..");
- pubnub.subscribe({
- channels: ['myDemo']
- });
- function publishSampleMessage() {
- console.log("Since we're publishing on subscribe connectEvent, we're sure we'll receive the following publish.");
- var publishConfig = {
- channel: "myDemo",
- message: "I'm here, I'm alive!!"
- }
- pubnub.publish(publishConfig, function(status, response) {
- console.log(status, response);
- })
- }
- function onClick() {
- publishSampleMessage();
- }
- </script>
- <button onclick="onClick()">start</button>
- </body>
- </html>
Add Comment
Please, Sign In to add comment