index.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>
  5. Static File Index.HTML
  6. </title>
  7. <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
  8. <style>
  9. * {
  10. box-sizing: border-box;
  11. }
  12. .wrap {
  13. width: 800px;
  14. height: 600px;
  15. margin: 0 auto;
  16. }
  17. #chat {
  18. width: 100%;
  19. height: 100%;
  20. text-align: center;
  21. display: flex;
  22. flex-direction: column;
  23. overflow: scroll;
  24. }
  25. input {
  26. width: 200px;
  27. height: 40px;
  28. }
  29. button {
  30. width: 150px;
  31. height: 30px;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div id='formContainer'>
  37. </div>
  38. <div class="wrap">
  39. <input type="text" id="nick" placeholder="Nicename">
  40. <input type="text" id="message" placeholder="Message">
  41. <button id="send">ЖМИ</button>
  42. <div id="chat">
  43. </div>
  44. </div>
  45. <script>
  46. const socket = io('http://localhost:4000')
  47. // let out = document.querySelector('.chat')
  48. socket.on('msg', msg => chat.innerHTML += msg.nick + ': ' + msg.message + '</br>')
  49. send.onclick = () => socket.emit('msg', {nick: nick.value, message: message.value});
  50. </script>
  51. </body>
  52. </html>