
Build
9 min read
Apr 18, 2019
How to Build a Realtime Collaborative Spreadsheets App (Goog…
A tutorial on building an app allowing multiple users to edi…
"+s.innerHTML}}),t.addEventListener("keypress",function(e){13===(e.keyCode||e.charCode)&&n.publish({channel:u,message:t.value,x:t.value=""})})}()
Open the demo in multiple windows to simulate multiple users sending and receiving messages in realtime.
1. Start by copy and paste the code into your favorite text editor and save as a .html.
Enter Chat and press enter <div><input id=input placeholder="message" /></div> Chat Output <div id=box></div> <script src=https://cdn.pubnub.com/sdk/javascript/pubnub.4.28.2.min.js></script> <script> (function() { var pubnub = new PubNub({ publishKey: 'demo', subscribeKey: 'demo' }); function $(id) { return document.getElementById(id); } var box = $('box'), input = $('input'), channel = '10chat-demo'; 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 = '') }); } }); })(); </script>
2. Create an account from the PubNub Dashboard and replace the publish and subscribe keys in the code above with keys from your account. You can create an account for free.
3. Open the .html file in a web browser. You have now successfully sent your first PubNub message!
Once you’re sending and receiving messages, you can use PubNub Chat to build features into your chat like:
PubNub maintains 15+ synchronized global points of presence that can deliver messages to any device in under 100 milliseconds. PubNub supports over 70 SDKs and has features like Functions and Push Notifications and that you can take advantage of in your product.
A tutorial on building an app allowing multiple users to edi…
How to setup and send push notifications for iOS (APNS) and …
How to build a leaderboard for multiplayer games that update…