Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #16: meeting title sync #38

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/server/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ACTIONS = {
DRAW: "draw",
RUN_CODE: "run_code",
OUTPUT: "output",
TITLE_CHANGE: "title_change",
};

module.exports = ACTIONS;
9 changes: 8 additions & 1 deletion apps/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getAllConnectedClients(roomId) {
socketId,
userName: userSocketMap[socketId],
};
},
}
);
}

Expand Down Expand Up @@ -107,6 +107,13 @@ io.on("connection", (socket) => {
socket.on(ACTIONS.CODE_CHANGE, ({ roomId, code }) => {
socket.in(roomId).emit(ACTIONS.CODE_CHANGE, { code });
});

socket.on(ACTIONS.TITLE_CHANGE, ({ roomId, title }) => {
// Broadcast the title change to all clients in the room, except the sender
socket.broadcast.to(roomId).emit(ACTIONS.TITLE_CHANGE, { title });
socket.in(roomId).emit(ACTIONS.TITLE_CHANGE, { title });
});

socket.on("disconnecting", () => {
const rooms = [...socket.rooms];
rooms.forEach((roomId) => {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ACTIONS = {
DRAW: "draw",
RUN_CODE: "run_code",
OUTPUT: "output",
TITLE_CHANGE: "title_change",
};

module.exports = ACTIONS;
25 changes: 23 additions & 2 deletions apps/web/src/components/MeetingTitle/MeetingTitle.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import React, { useEffect, useState } from "react";
import meetingpng from "../../pages/Assets/images/meeting-logo.png";
import ACTIONS from "../../Actions";
const date = new Date();

const MeetingTitle = () => {
const MeetingTitle = ({ socket, roomId }) => {
const [currentTime, setCurrentTime] = useState(new Date());
const [title, setTitle] = useState("Interview(Technical Round)");

useEffect(() => {
if (socket) {
// Listen for title updates from the server
socket.on(ACTIONS.TITLE_CHANGE, ({ title }) => {
setTitle(title); // Update the title with the new value
});
}
}, [socket, roomId]);

const handleTitleChange = (e) => {
const newTitle = e.target.textContent;
setTitle(newTitle);
if (socket && roomId) {
socket.emit(ACTIONS.TITLE_CHANGE, { roomId, title: newTitle });
}
};

useEffect(() => {
const timer = setInterval(() => {
Expand All @@ -25,9 +44,11 @@ const MeetingTitle = () => {
<div class="absolute w-0.5 h-[3vw] ml-[5.7vw] bg-lightergrey"></div>
<h1
contenteditable="true"
suppressContentEditableWarning={true}
onBlur={handleTitleChange}
className="absolute ml-[6.7vw] text-darkGrey top-[0.9vw] font-Inter text-[1.2vw] font-medium"
>
Interview(Technical Round)
{title}
</h1>
<h2 className="absolute py-1 text-gray-500 font-Inter text-[1.1vw] top-[2.7vw] text-DTgrey ml-[6.5vw] font-medium">
{" "}
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/pages/RoomPage/Room.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const options = {
"force new connection": true,
reconnectionAttempt: "Infinity",
timeout: 10000,
transports: ["websocket", 'polling'],
transports: ["websocket", "polling"],
cors: {
origin: '*', // Allow all origins
methods: ['GET', 'POST'],
origin: "*", // Allow all origins
methods: ["GET", "POST"],
credentials: true,
},
};
const server = 'localhost:4000';
const server = "localhost:4000";
const socket = io(server, options);

const Room = () => {
Expand Down Expand Up @@ -102,7 +102,7 @@ const Room = () => {
transition={{ duration: 1, type: "ease-in" }} // Change the transition type to "ease-in"
>
<Nav />
<MeetingTitle />
<MeetingTitle socket={socket} roomId={roomId} />
</motion.div>
<motion.div
initial={{ y: 1000 }}
Expand Down