I
I
IDONTSUDO2020-05-11 15:34:16
Node.js
IDONTSUDO, 2020-05-11 15:34:16

How to move socket routing to a separate file?

io.on('connection', (socket) => {
  socket.on('INVENTORY_CONNECT', (data) => {
    socket.join(data);
  });
  socket.on('disconnect', (data) => {
    console.log('CLIENT DISCONECT');
  });
  socket.on('DRAG', (data) => {
    const { inventoryID, HTML_ID_ELEMENT,coords} = data;
    let msg = { HTML_ID_ELEMENT,coords };
    socket.broadcast.to(inventoryID).emit('CLEAR', msg);
  });
  socket.on('UNDO', (data) => {
    const { userInventoryId, Coords, activeElem } = data;
    let msg = {
      Coords,
      activeElem
    };
    socket.broadcast.to(userInventoryId).emit('UNDO', msg);
  });
});


There is such a code. How to move the routing control i.e. socket.on to a separate file? Without the fact that I'm resorting to namespace?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question