I wanted to try out pubnub BLOCKS with a very contrived example. Essentially, I'm publishing a simple message from a client (using javascript sdk) to see if the BLOCK that I've set (or i "think" i've set) to that respective channel is listening...contrived example is failing thus far...
Steps
- Create an APP in pubnub to generate credentials.
- Included pubnub SDK in simple HTML file, initialized Pubnub, set event listener, and publish/subscribe methods. Set channel to 'hello-world' 2a. Published/Subscribed to messages successfully from different browser windows with .
- Went to pubnub debug console and set channel as 'hello-world' to see if messages from 'hello-world' channel would be broadcast and they were not.
- From the client, I console logged the object that is returned from messages and the channel is appearing as 'hello-world'..so this left me wondering, why aren't i seeing the messages registered in the pubnub debug console in the same hello-world channel ?
Particularly, my question is: how can i send messages to a pubnub BLOCK from a pubnub CLIENT and send messages from a pubnub BLOCK to a pubnub CLIENT ? or in other words, pub/sub a BLOCK with a CLIENT using the Javascript SDK ?
The simple.js for hello-world example code:
(function(){
var pubnub = new PubNub({ publishKey : 'p-key', subscribeKey : 's-key' });
function $(id) { return document.getElementById(id); }
var box = $('box'), input = $('input'), channel = 'hello-world';
pubnub.addListener({
message: function(obj) {
box.innerHTML = (''+obj.message).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML
}});
pubnub.subscribe({channels:[channel]});
input.addEventListener('keyup', function(e) {
if ((e.keyCode || e.charCode) === 13) {
pubnub.publish({channel : channel,message : input.value,x : (input.value='')});
}
});
})();