test.html 2.65 KB
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios@0.24.0/dist/axios.min.js"></script>
    <script src="https://cdn.socket.io/4.3.2/socket.io.min.js"
        integrity="sha384-KAZ4DtjNhLChOB/hxXuKqhMLYvx3b5MlT55xPEiNmREKRzeEm+RVPlTnAn0ajQNs"
        crossorigin="anonymous"></script>
</head>

<body>
    <input id="fileInput" type="file" />
    <script>
        // const eventSource = new EventSource("http://localhost:3000/sse/event");
        // console.log(22222222222222222,eventSource)
        // eventSource.onopen = function () {
        // console.log("连接成功"); 
        // };
        // eventSource.onerror = function (e,e1) {
        // console.log("error",JSON.stringify(e));

        // };
        // eventSource.onmessage = ({ data }) => {
        //     console.log(111,data)
        // };
        // const fileInput = document.querySelector('#fileInput');
        // // const chunkSize = 20 * 1024;
        // fileInput.onchange =  async function () {

        //     const file = fileInput.files[0];
        //     console.log(file);
        //     const data = new FormData();
        //     data.append('file', file);
        //     axios.post('http://localhost:3000/file/upload', data);
        // const chunks = [];
        // let startPos = 0;
        // while(startPos < file.size) {
        //     chunks.push(file.slice(startPos, startPos + chunkSize));
        //     startPos += chunkSize;
        // }

        // chunks.map((chunk, index) => {
        //     const data = new FormData();
        //     data.set('name', file.name + '-' + index)
        //     data.append('files', chunk);
        //     axios.post('http://localhost:3000/file/upload', data);
        // })

        // }

        const socket = io('http://192.168.1.129:8080',{
            auth: { token:'12`13`23',employeeId:Math.random()+'' },
        });
        socket.on('connect', function (a) {
            console.log('Connected');
            console.log(socket,a)
            //socket.emit('private', { test: 'test' });
            // socket.emit('system', 0, response =>
            //     console.log('Identity:', response),
            // );
        });
        socket.on('private', function (data) {
            console.log('event', data);
        });
        socket.on('system',function (data) {
            console.log('消息', data);
        });
        socket.on('disconnect', function () {
            console.log('Disconnected');
        });
    </script>
</body>

</html>