index.html 798 B

1234567891011121314151617181920212223
  1. <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
  2. <form action="/upload" method="post" enctype="multipart/form-data" id='form'>
  3. <input type="file" name="media" id='media'/>
  4. </form>
  5. <script>
  6. media.onchange = async () => {
  7. fetch('/upload', {
  8. method: "POST",
  9. headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
  10. body: new FormData(form)
  11. })
  12. }
  13. const socket = io()
  14. if (localStorage.authToken) socket.emit('jwt', localStorage.authToken)
  15. socket.on('jwt_ok', data => console.log(data))
  16. socket.on('jwt_fail', error => console.log(error))
  17. socket.on('msg', msg => console.log(msg))
  18. socket.on('chat', chat => console.log(chat))
  19. </script>