Add functionality to Socket.IO client

This commit is contained in:
aronmal 2022-10-28 22:21:55 +02:00
parent 9a5c0b20ba
commit 33106da88f
Signed by: aronmal
GPG key ID: 816B7707426FC612

View file

@ -1,8 +1,27 @@
import { io } from 'socket.io-client'; import { io } from 'socket.io-client';
function SocketIO() { function SocketIO() {
// const socket = io("wss://server-domain.com"); const socket = io("ws://localhost:5001");
const socket = io(); // The server URL will be deduced from the window.location object. socket.on('test2', (warst) => {
console.log('Test2:', warst, socket.id)
})
socket.on("connect", () => {
console.log(socket.connected); // true
setTimeout(() => {
socket.emit('test', "warst")
socket.emit('test', "tsra")
socket.emit('test', "1234")
// socket.disconnect()
}, 1000)
});
socket.on("test", () => {
console.log("Got test1234"); // false
});
socket.on("disconnect", () => {
console.log(socket.connected); // false
});
return ( return (
<div>SocketIO</div> <div>SocketIO</div>
) )