1234567891011121314151617181920212223 |
- <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
- <form action="/upload" method="post" enctype="multipart/form-data" id='form'>
- <input type="file" name="media" id='media'/>
- </form>
- <script>
- media.onchange = async () => {
- fetch('/upload', {
- method: "POST",
- headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
- body: new FormData(form)
- })
- }
- const socket = io()
- if (localStorage.authToken) socket.emit('jwt', localStorage.authToken)
- socket.on('jwt_ok', data => console.log(data))
- socket.on('jwt_fail', error => console.log(error))
- socket.on('msg', msg => console.log(msg))
- socket.on('chat', chat => console.log(chat))
- </script>
|