Advertisement
Guest User

Untitled

a guest
Jan 8th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Text Synchronization App</title>
  4. <script src="https://cdn.goinstant.net/v1/platform.min.js"></script>
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  6. </head>
  7. <body>
  8. <div>
  9. <input type="text" name="name" id="sync" />
  10. <script>
  11. $(document).ready(function () {
  12. // The connection url is provided to you by viewing the application from the
  13. // GoInstant dashboard. This url tells GoInstant where your application and
  14. // account are located in order to connect.
  15. var url = 'https://goinstant.net/my-account-name/helloworld';
  16.  
  17. goinstant.connect(url, function (err, connection, lobby) {
  18. if (err) {
  19. // Could not connect to GoInstant
  20. throw err;
  21. }
  22.  
  23. var name = lobby.key('name');
  24. var el = $('input[name="name"]');
  25.  
  26. // The listener will be invoked every time the value of name is changed
  27. // by another user
  28. name.on('set', function(value, context) {
  29. el.val(value);
  30. });
  31.  
  32. el.on('keyup', function() {
  33. name.set($(this).val());
  34. });
  35.  
  36. name.on('remove', function() {
  37. alert('Removed.');
  38. });
  39. });
  40. });
  41. </script>
  42. </div>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement