ssl-event-index.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Demo Chat</title>
  5. <link href="bootstrap.css" rel="stylesheet">
  6. <style>
  7. body {
  8. padding:20px;
  9. }
  10. #console {
  11. height: 400px;
  12. overflow: auto;
  13. }
  14. .username-msg {color:orange;}
  15. .connect-msg {color:green;}
  16. .disconnect-msg {color:red;}
  17. .send-msg {color:#888}
  18. </style>
  19. <script src="js/socket.io/socket.io.js"></script>
  20. <script src="js/moment.min.js"></script>
  21. <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  22. <script>
  23. var userName = 'user' + Math.floor((Math.random()*1000)+1);
  24. var socket = io.connect('https://localhost:10443');
  25. socket.on('connect', function() {
  26. output('<span class="connect-msg">Client has connected to the server!</span>');
  27. });
  28. socket.on('chatevent', function(data) {
  29. output('<span class="username-msg">' + data.userName + ':</span> ' + data.message);
  30. });
  31. socket.on('disconnect', function() {
  32. output('<span class="disconnect-msg">The client has disconnected!</span>');
  33. });
  34. function sendDisconnect() {
  35. socket.disconnect();
  36. }
  37. function sendMessage() {
  38. var message = $('#msg').val();
  39. $('#msg').val('');
  40. socket.emit('chatevent', {userName: userName, message: message});
  41. }
  42. function output(message) {
  43. var currentTime = "<span class='time'>" + moment().format('HH:mm:ss.SSS') + "</span>";
  44. var element = $("<div>" + currentTime + " " + message + "</div>");
  45. $('#console').prepend(element);
  46. }
  47. $(document).keydown(function(e){
  48. if(e.keyCode == 13) {
  49. $('#send').click();
  50. }
  51. });
  52. </script>
  53. </head>
  54. <body>
  55. <h1>Netty-socketio Demo Chat</h1>
  56. <br/>
  57. <div id="console" class="well">
  58. </div>
  59. <form class="well form-inline" onsubmit="return false;">
  60. <input id="msg" class="input-xlarge" type="text" placeholder="Type something..."/>
  61. <button type="button" onClick="sendMessage()" class="btn" id="send">Send</button>
  62. <button type="button" onClick="sendDisconnect()" class="btn">Disconnect</button>
  63. </form>
  64. </body>
  65. </html>