Socket.io in React.js. When a socket is sent, can I retrieve the sent object through the socket id?

Asked

Viewed 48 times

0

I am using socket.io on my system so that every time a user registers appear in real time on my screen. For this I am saving the socket in the mongoDB database, but it saves not only the connected user socket, but all sockets from the connection, (many)! Because of this I created a delete method so as not to overload my database, but since every time a socket is created every time a socket is deleted. With this I am causing a DDOS in my system by so many delete requests. I wonder if there is any way through the past socket, know if this socket is from a new user or just a "any" socket, since every second has a new socket.

Follow the code where I create the connection. I can create some if to know if the received socket is from a new user?

exports.setupWebsocket = (server) => {
  io = socketio(server);

  io.on("connection", async socket => {
    await sockets.create({ 
      id: socket.id,
    });
    
  });
};

Function that Emit the sockets when a user connects:

exports.sendMessage = (to, message, data) => {
  if(to) {
    to.forEach(connection => {
      io.to(connection.id).emit(message, data);
    });
  } else {
    //
  }
};
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.