To send additional data on socket connection with JavaScript socket.io, we call the emit
function with the data.
For instance, we write
socket.on("connect", () => {
socket.emit("hello", data);
});
io.on("connection", (client) => {
client.on("hello", (data) => {});
});
to call emit
to emit the 'hello'
event with the data
we want to send to the client.