Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.48 KB | None | 0 0
  1. <head>
  2.     <title>Greetings, program!</title>
  3.     <script src="/jquery-1.6.1.min.js"></script>
  4.     <script src="/Socket.IO/dist/socket.io.min.js"></script>
  5.     <script>
  6.         var App = {};
  7.  
  8.         App.handle = undefined;
  9.  
  10.         App.start = function()
  11.         {
  12.             App.socket.send('ping');
  13.             App.handle = setTimeout(App.start, 10000);
  14.             App.$button.html('Stop');
  15.         };
  16.  
  17.         App.stop = function()
  18.         {
  19.             App.handle = clearInterval(App.handle);
  20.             App.$button.html('Start');
  21.         };
  22.  
  23.         App.toggle = function()
  24.         {
  25.             if (App.handle === undefined)
  26.                 App.start()
  27.             else
  28.                 App.stop();
  29.         };
  30.  
  31.         $(document).ready(function() {
  32.             App.socket = io.connect( '/echo.sock'
  33.                                    , { "resource": "echo.sock"
  34.                                      , "transports": ["xhr-polling"]
  35.                                       }
  36.                                     );                                                    
  37.             App.socket.on('message', function (a,b,c) {
  38.                 console.log("got a message", a, b, c);
  39.             });
  40.             App.$messages = $('#messages');
  41.             App.$button = $('button');
  42.             App.$button.click(App.toggle);
  43.         });
  44.     </script>
  45. </head>
  46. <body>
  47.     Greetings, program!<br />
  48.     <button>Start</button>
  49.     <div id="messages"></div>
  50. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement