You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
853 B

4 years ago
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  5. <title>EventSource test</title>
  6. </head>
  7. <body>
  8. <h1>EventSource test</h1>
  9. <ul></ul>
  10. <script type="text/javascript">
  11. var logger = document.getElementsByTagName('ul')[0],
  12. socket = new EventSource('/');
  13. var log = function(text) {
  14. logger.innerHTML += '<li>' + text + '</li>';
  15. };
  16. socket.onopen = function() {
  17. log('OPEN');
  18. };
  19. socket.onmessage = function(event) {
  20. log('MESSAGE: ' + event.data);
  21. };
  22. socket.addEventListener('update', function(event) {
  23. log('UPDATE(' + event.lastEventId + '): ' + event.data);
  24. });
  25. socket.onerror = function(event) {
  26. log('ERROR: ' + event.message);
  27. };
  28. </script>
  29. </body>
  30. </html>