-
-
Save stephenlb/8030977 to your computer and use it in GitHub Desktop.
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
Enter Chat and press enter | |
<div><input id=input placeholder=you-chat-here /></div> | |
Chat Output | |
<div id=box></div> | |
<script src=http://cdn.pubnub.com/pubnub.min.js></script> | |
<script>(function(){ | |
var pubnub = PUBNUB.init({publish_key:'demo',subscribe_key:'demo',ssl:true}); | |
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chat'; | |
pubnub.subscribe({ | |
channel : channel, | |
callback : function(text) { box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML } | |
}); | |
PUBNUB.bind( 'keyup', input, function(e) { | |
(e.keyCode || e.charCode) === 13 && pubnub.publish({ | |
channel : channel, message : input.value, x : (input.value='') | |
}) | |
} ) | |
})()</script> |
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
// Send a message | |
pubnub.publish({ channel : 'chat', message : "hello!" }) |
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
// Receive messages | |
pubnub.subscribe({ channel : 'chat', message : fun }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example doesn't require you to specify publish_key or subscribe_key. I am guessing a lot of people around the world must be copy pasting this example to run it. Keeping it running to see if I catch some other peoples' messages as they run it :)
.. this is cool!