diff --git a/Backend/controllers/roomsControllers.js b/Backend/controllers/roomsControllers.js index 1639413..49ef79d 100644 --- a/Backend/controllers/roomsControllers.js +++ b/Backend/controllers/roomsControllers.js @@ -67,7 +67,8 @@ exports.joinRoom = async (req, res, next) => { let { roomId, userId } = req.body; let roomData = await room.findOne({ roomId - }); + }) + .populate("users.userId","userName"); if (!roomData) { return res.status(404).json({ message: "room not found" @@ -84,7 +85,8 @@ exports.joinRoom = async (req, res, next) => { await roomData.save(); return res.status(200).json({ - message: "room joined successfully" + message: "room joined successfully", + roomData }) } catch (error) { return res.status(500).json({ @@ -99,7 +101,7 @@ exports.getAllRooms = async (req, res, next) => { try { let allRooms = await room .find() - .populate("users.userId","userName") + .populate("users.userId","userName profile") let newAllRooms = []; for (let i = 0; i < allRooms.length; i++) { const room = allRooms[i]; diff --git a/Backend/server.js b/Backend/server.js index 53b5cfd..5fb36ac 100644 --- a/Backend/server.js +++ b/Backend/server.js @@ -38,6 +38,7 @@ mongoose.connect(process.env.MONGO_URI) .then(() => { const PORT = process.env.PORT || 4000; const server = app.listen(PORT); + console.log("db connected") const io = createSocketConnection(server, { cors: { origin: "*" @@ -48,6 +49,7 @@ mongoose.connect(process.env.MONGO_URI) // socket join room event socket.on("join_room",(roomId,userName) => { + console.log(roomId,userName); socket.join(roomId); socket.broadcast.to(roomId).emit("user_join",{ message:"a new user join the room!", diff --git a/Frontend/src/components/JoinCard.js b/Frontend/src/components/JoinCard.js index 9bf96fe..52f976d 100644 --- a/Frontend/src/components/JoinCard.js +++ b/Frontend/src/components/JoinCard.js @@ -22,8 +22,8 @@ const JoinCard = ({ roomId, name, room, noOfQuestions, range }) => { const handleClick = (roomId) => { console.log("clicked"); - socket.emit("join_room", (roomId, user.handle)); - console.log(roomId); + socket.emit("join_room", roomId, user.handle); + console.log("roomId - " + roomId,"user - " + user.handle ); navigate(`/room/${roomId}`) }; diff --git a/Frontend/src/pages/Home.js b/Frontend/src/pages/Home.js index db641c3..0acd621 100644 --- a/Frontend/src/pages/Home.js +++ b/Frontend/src/pages/Home.js @@ -100,7 +100,8 @@ export default function Home() { }, }); - socket.emit("join_room", (roomID, user.user.handle)); + console.log("roomId" + roomID, "user " +user.user.handle); + socket.emit("join_room", roomID, user.user.handle); setLoading(false);