how to recieve socket io emit messages from client to server code example

Example 1: socket emit to specific room using nodejs socket.io

io.on('connection', socket => {  socket.on('disconnecting', () => {    const rooms = Object.keys(socket.rooms);    // the rooms array contains at least the socket ID  });  socket.on('disconnect', () => {    // socket.rooms === {}  });});

Example 2: socket emit to specific room using nodejs socket.io

io.on('connection', socket => {  socket.on('say to someone', (id, msg) => {    socket.to(id).emit('my message', msg);  });});