I want to find the socket instance using the socket id
I saw a solution on stackoverflow and tried it, but it didn't work. Make specific socket leave the room is in
exports.removeParticipant = ({ data }) => {
const { roomId, toBeRemovedSocketId } = data;
const roomFound = rooms.find((room) => room.id === roomId);
if (roomFound) {
const user = roomFound.connectedUsers.find(
(user) => user.socketId === toBeRemovedSocketId
);
/* Removing the user from the room.connectedUserArray . */
roomFound.connectedUsers = roomFound.connectedUsers.filter(
(user) => user.socketId !== toBeRemovedSocketId
);
//i tried this but it throws error
let socket = io.sockets.connected[toBeRemovedSocketId];
socket.leave(roomId);
}