PageRenderTime 53ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/example/chat-ssl.html

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
HTML | 61 lines | 52 code | 9 blank | 0 comment | 0 complexity | 31978262d7e8a926dce775e6cb808760 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>socket.io client test</title>
  5. <script src="/json.js"></script> <!-- for ie -->
  6. <script src="/socket.io/socket.io.js"></script>
  7. </head>
  8. <body>
  9. <script>
  10. function message(obj){
  11. var el = document.createElement('p');
  12. if ('announcement' in obj) el.innerHTML = '<em>' + esc(obj.announcement) + '</em>';
  13. else if ('message' in obj) el.innerHTML = '<b>' + esc(obj.message[0]) + ':</b> ' + esc(obj.message[1]);
  14. document.getElementById('chat').appendChild(el);
  15. document.getElementById('chat').scrollTop = 1000000;
  16. }
  17. function send(){
  18. var val = document.getElementById('text').value;
  19. socket.send(val);
  20. message({ message: ['you', val] });
  21. document.getElementById('text').value = '';
  22. }
  23. function esc(msg){
  24. return msg.replace(/</g, '&lt;').replace(/>/g, '&gt;');
  25. };
  26. var socket = new io.Socket(null, {port: 443, secure: true, rememberTransport: false});
  27. socket.connect();
  28. socket.on('message', function(obj){
  29. if ('buffer' in obj){
  30. document.getElementById('form').style.display='block';
  31. document.getElementById('chat').innerHTML = '';
  32. for (var i in obj.buffer) message(obj.buffer[i]);
  33. } else message(obj);
  34. });
  35. </script>
  36. <h1>Sample chat client</h1>
  37. <div id="chat"><p>Connecting...</p></div>
  38. <form id="form" onsubmit="send(); return false">
  39. <input type="text" autocomplete="off" id="text"><input type="submit" value="Send">
  40. </form>
  41. <style>
  42. #chat { height: 300px; overflow: auto; width: 800px; border: 1px solid #eee; font: 13px Helvetica, Arial; }
  43. #chat p { padding: 8px; margin: 0; }
  44. #chat p:nth-child(odd) { background: #F6F6F6; }
  45. #form { width: 782px; background: #333; padding: 5px 10px; display: none; }
  46. #form input[type=text] { width: 700px; padding: 5px; background: #fff; border: 1px solid #fff; }
  47. #form input[type=submit] { cursor: pointer; background: #999; border: none; padding: 6px 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; margin-left: 5px; text-shadow: 0 1px 0 #fff; }
  48. #form input[type=submit]:hover { background: #A2A2A2; }
  49. #form input[type=submit]:active { position: relative; top: 2px; }
  50. </style>
  51. </body>
  52. </html>